4 CLASS(XonoticSkinList, XonoticListBox)
5 METHOD(XonoticSkinList, configureXonoticSkinList, void(entity));
6 ATTRIB(XonoticSkinList, rowsPerItem, float, 4)
7 METHOD(XonoticSkinList, resizeNotify, void(entity, vector, vector, vector, vector));
8 METHOD(XonoticSkinList, drawListBoxItem, void(entity, int, vector, bool, bool));
9 METHOD(XonoticSkinList, getSkins, void(entity));
10 METHOD(XonoticSkinList, setSkin, void(entity));
11 METHOD(XonoticSkinList, loadCvars, void(entity));
12 METHOD(XonoticSkinList, saveCvars, void(entity));
13 METHOD(XonoticSkinList, skinParameter, string(entity, float, float));
14 METHOD(XonoticSkinList, doubleClickListBoxItem, void(entity, float, vector));
15 METHOD(XonoticSkinList, keyDown, float(entity, float, float, float));
16 METHOD(XonoticSkinList, destroy, void(entity));
18 ATTRIB(XonoticSkinList, skinlist, float, -1)
19 ATTRIB(XonoticSkinList, realFontSize, vector, '0 0 0')
20 ATTRIB(XonoticSkinList, columnPreviewOrigin, float, 0)
21 ATTRIB(XonoticSkinList, columnPreviewSize, float, 0)
22 ATTRIB(XonoticSkinList, columnNameOrigin, float, 0)
23 ATTRIB(XonoticSkinList, columnNameSize, float, 0)
24 ATTRIB(XonoticSkinList, realUpperMargin1, float, 0)
25 ATTRIB(XonoticSkinList, realUpperMargin2, float, 0)
26 ATTRIB(XonoticSkinList, origin, vector, '0 0 0')
27 ATTRIB(XonoticSkinList, itemAbsSize, vector, '0 0 0')
29 ATTRIB(XonoticSkinList, name, string, "skinselector")
30 ENDCLASS(XonoticSkinList)
32 entity makeXonoticSkinList();
33 void SetSkin_Click(entity btn, entity me);
38 const float SKINPARM_NAME = 0;
39 const float SKINPARM_TITLE = 1;
40 const float SKINPARM_AUTHOR = 2;
41 const float SKINPARM_PREVIEW = 3;
42 const float SKINPARM_COUNT = 4;
44 entity makeXonoticSkinList()
47 me = NEW(XonoticSkinList);
48 me.configureXonoticSkinList(me);
52 void XonoticSkinList_configureXonoticSkinList(entity me)
54 me.configureXonoticListBox(me);
59 void XonoticSkinList_loadCvars(entity me)
63 s = cvar_string("menu_skin");
65 for(i = 0; i < n; ++i)
67 if(me.skinParameter(me, i, SKINPARM_NAME) == s)
69 me.setSelected(me, i);
75 void XonoticSkinList_saveCvars(entity me)
77 cvar_set("menu_skin", me.skinParameter(me, me.selectedItem, SKINPARM_NAME));
80 string XonoticSkinList_skinParameter(entity me, float i, float key)
82 return bufstr_get(me.skinlist, i * SKINPARM_COUNT + key);
85 void XonoticSkinList_getSkins(entity me)
87 float glob, buf, i, n, fh;
91 glob = search_begin("gfx/menu/*/skinvalues.txt", true, true);
99 n = search_getsize(glob);
100 for(i = 0; i < n; ++i)
102 s = search_getfilename(glob, i);
103 name = substring(s, 9, strlen(s) - 24); // the * part
104 bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_NAME, name);
105 bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_TITLE, _("<TITLE>"));
106 bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_AUTHOR, _("<AUTHOR>"));
107 if(draw_PictureSize(strcat("/gfx/menu/", substring(s, 9, strlen(s) - 24), "/skinpreview")) == '0 0 0')
108 bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_PREVIEW, "nopreview_menuskin");
110 bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_PREVIEW, strcat("/gfx/menu/", substring(s, 9, strlen(s) - 24), "/skinpreview"));
111 fh = fopen(s, FILE_READ);
114 LOG_INFO("Warning: can't open skinvalues.txt file\n");
117 while((s = fgets(fh)))
119 // these two are handled by skinlist.qc
120 if(substring(s, 0, 6) == "title ")
122 if (name == cvar_defstring("menu_skin"))
123 bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_TITLE, strcat(substring(s, 6, strlen(s) - 6), " (", _("Default"), ")"));
125 bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_TITLE, substring(s, 6, strlen(s) - 6));
127 else if(substring(s, 0, 7) == "author ")
128 bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_AUTHOR, substring(s, 7, strlen(s) - 7));
139 void XonoticSkinList_destroy(entity me)
141 buf_del(me.skinlist);
144 void XonoticSkinList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
146 me.itemAbsSize = '0 0 0';
147 SUPER(XonoticSkinList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
149 me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize.y * me.itemHeight));
150 me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize.x * (1 - me.controlWidth)));
151 me.realUpperMargin1 = 0.5 * (1 - 2.5 * me.realFontSize.y);
152 me.realUpperMargin2 = me.realUpperMargin1 + 1.5 * me.realFontSize.y;
154 me.columnPreviewOrigin = 0;
155 me.columnPreviewSize = me.itemAbsSize.y / me.itemAbsSize.x * 4 / 3;
156 me.columnNameOrigin = me.columnPreviewOrigin + me.columnPreviewSize + me.realFontSize.x;
157 me.columnNameSize = 1 - me.columnPreviewSize - 2 * me.realFontSize.x;
160 void XonoticSkinList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
165 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
168 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
169 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
172 s = me.skinParameter(me, i, SKINPARM_PREVIEW);
173 draw_Picture(me.columnPreviewOrigin * eX, s, me.columnPreviewSize * eX + eY, '1 1 1', 1);
175 s = me.skinParameter(me, i, SKINPARM_TITLE);
176 s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize);
177 draw_Text(me.realUpperMargin1 * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, SKINCOLOR_SKINLIST_TITLE, SKINALPHA_TEXT, 0);
179 s = me.skinParameter(me, i, SKINPARM_AUTHOR);
180 s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize);
181 draw_Text(me.realUpperMargin2 * eY + (me.columnNameOrigin + 1.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, SKINCOLOR_SKINLIST_AUTHOR, SKINALPHA_TEXT, 0);
184 void XonoticSkinList_setSkin(entity me)
187 localcmd("\nmenu_restart\nmenu_cmd skinselect\n");
190 void SetSkin_Click(entity btn, entity me)
195 void XonoticSkinList_doubleClickListBoxItem(entity me, float i, vector where)
197 m_play_click_sound(MENU_SOUND_EXECUTE);
201 float XonoticSkinList_keyDown(entity me, float scan, float ascii, float shift)
203 if(scan == K_ENTER || scan == K_KP_ENTER)
205 m_play_click_sound(MENU_SOUND_EXECUTE);
210 return SUPER(XonoticSkinList).keyDown(me, scan, ascii, shift);