2 CLASS(XonoticSkinList) EXTENDS(XonoticListBox)
3 METHOD(XonoticSkinList, configureXonoticSkinList, void(entity))
4 ATTRIB(XonoticSkinList, rowsPerItem, float, 4)
5 METHOD(XonoticSkinList, resizeNotify, void(entity, vector, vector, vector, vector))
6 METHOD(XonoticSkinList, drawListBoxItem, void(entity, float, vector, float))
7 METHOD(XonoticSkinList, getSkins, void(entity))
8 METHOD(XonoticSkinList, setSkin, void(entity))
9 METHOD(XonoticSkinList, loadCvars, void(entity))
10 METHOD(XonoticSkinList, saveCvars, void(entity))
11 METHOD(XonoticSkinList, skinParameter, string(entity, float, float))
12 METHOD(XonoticSkinList, clickListBoxItem, void(entity, float, vector))
13 METHOD(XonoticSkinList, keyDown, float(entity, float, float, float))
14 METHOD(XonoticSkinList, destroy, void(entity))
16 ATTRIB(XonoticSkinList, skinlist, float, -1)
17 ATTRIB(XonoticSkinList, realFontSize, vector, '0 0 0')
18 ATTRIB(XonoticSkinList, columnPreviewOrigin, float, 0)
19 ATTRIB(XonoticSkinList, columnPreviewSize, float, 0)
20 ATTRIB(XonoticSkinList, columnNameOrigin, float, 0)
21 ATTRIB(XonoticSkinList, columnNameSize, float, 0)
22 ATTRIB(XonoticSkinList, realUpperMargin1, float, 0)
23 ATTRIB(XonoticSkinList, realUpperMargin2, float, 0)
24 ATTRIB(XonoticSkinList, origin, vector, '0 0 0')
25 ATTRIB(XonoticSkinList, itemAbsSize, vector, '0 0 0')
27 ATTRIB(XonoticSkinList, lastClickedSkin, float, -1)
28 ATTRIB(XonoticSkinList, lastClickedTime, float, 0)
30 ATTRIB(XonoticSkinList, name, string, "skinselector")
31 ENDCLASS(XonoticSkinList)
33 entity makeXonoticSkinList();
34 void SetSkin_Click(entity btn, entity me);
39 #define SKINPARM_NAME 0
40 #define SKINPARM_TITLE 1
41 #define SKINPARM_AUTHOR 2
42 #define SKINPARM_PREVIEW 3
43 #define SKINPARM_COUNT 4
45 entity makeXonoticSkinList()
48 me = spawnXonoticSkinList();
49 me.configureXonoticSkinList(me);
53 void XonoticSkinList_configureXonoticSkinList(entity me)
55 me.configureXonoticListBox(me);
60 void XonoticSkinList_loadCvars(entity me)
64 s = cvar_string("menu_skin");
66 for(i = 0; i < n; ++i)
68 if(me.skinParameter(me, i, SKINPARM_NAME) == s)
76 void XonoticSkinList_saveCvars(entity me)
78 cvar_set("menu_skin", me.skinParameter(me, me.selectedItem, SKINPARM_NAME));
81 string XonoticSkinList_skinParameter(entity me, float i, float key)
83 return bufstr_get(me.skinlist, i * SKINPARM_COUNT + key);
86 void XonoticSkinList_getSkins(entity me)
88 float glob, buf, i, n, fh;
92 glob = search_begin("gfx/menu/*/skinvalues.txt", TRUE, TRUE);
100 n = search_getsize(glob);
101 for(i = 0; i < n; ++i)
103 s = search_getfilename(glob, i);
104 bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_NAME, substring(s, 9, strlen(s) - 24)); // the * part
105 bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_TITLE, "<TITLE>");
106 bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_AUTHOR, "<AUTHOR>");
107 bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_PREVIEW, strcat("/gfx/menu/", substring(s, 9, strlen(s) - 24), "/skinpreview"));
108 fh = fopen(s, FILE_READ);
111 print("Warning: can't open skinvalues.txt file\n");
114 while((s = fgets(fh)))
116 // these two are handled by skinlist.qc
117 if(substring(s, 0, 6) == "title ")
118 bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_TITLE, substring(s, 6, strlen(s) - 6));
119 else if(substring(s, 0, 7) == "author ")
120 bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_AUTHOR, substring(s, 7, strlen(s) - 7));
131 void XonoticSkinList_destroy(entity me)
133 buf_del(me.skinlist);
136 void XonoticSkinList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
138 me.itemAbsSize = '0 0 0';
139 SUPER(XonoticSkinList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
141 me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize_y * me.itemHeight));
142 me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize_x * (1 - me.controlWidth)));
143 me.realUpperMargin1 = 0.5 * (1 - 2.5 * me.realFontSize_y);
144 me.realUpperMargin2 = me.realUpperMargin1 + 1.5 * me.realFontSize_y;
146 me.columnPreviewOrigin = 0;
147 me.columnPreviewSize = me.itemAbsSize_y / me.itemAbsSize_x * 4 / 3;
148 me.columnNameOrigin = me.columnPreviewOrigin + me.columnPreviewSize + me.realFontSize_x;
149 me.columnNameSize = 1 - me.columnPreviewSize - 2 * me.realFontSize_x;
152 void XonoticSkinList_drawListBoxItem(entity me, float i, vector absSize, float isSelected)
157 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
159 s = me.skinParameter(me, i, SKINPARM_PREVIEW);
160 draw_Picture(me.columnPreviewOrigin * eX, s, me.columnPreviewSize * eX + eY, '1 1 1', 1);
162 s = me.skinParameter(me, i, SKINPARM_NAME);
163 s = strcat(s, ": ", me.skinParameter(me, i, SKINPARM_TITLE));
164 s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize);
165 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);
167 s = me.skinParameter(me, i, SKINPARM_AUTHOR);
168 s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize);
169 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);
172 void XonoticSkinList_setSkin(entity me)
175 localcmd("\nmenu_restart\ntogglemenu\ndefer 0.1 \"menu_cmd skinselect\"\n");
178 void SetSkin_Click(entity btn, entity me)
183 void XonoticSkinList_clickListBoxItem(entity me, float i, vector where)
185 if(i == me.lastClickedSkin)
186 if(time < me.lastClickedTime + 0.3)
189 me.setSelected(me, i);
192 me.lastClickedSkin = i;
193 me.lastClickedTime = time;
196 float XonoticSkinList_keyDown(entity me, float scan, float ascii, float shift)
198 if(scan == K_ENTER || scan == K_KP_ENTER) {
203 return SUPER(XonoticSkinList).keyDown(me, scan, ascii, shift);