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 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(language_filename(s), FILE_READ);
114 print("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 ")
121 bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_TITLE, substring(s, 6, strlen(s) - 6));
122 else if(substring(s, 0, 7) == "author ")
123 bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_AUTHOR, substring(s, 7, strlen(s) - 7));
134 void XonoticSkinList_destroy(entity me)
136 buf_del(me.skinlist);
139 void XonoticSkinList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
141 me.itemAbsSize = '0 0 0';
142 SUPER(XonoticSkinList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
144 me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize_y * me.itemHeight));
145 me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize_x * (1 - me.controlWidth)));
146 me.realUpperMargin1 = 0.5 * (1 - 2.5 * me.realFontSize_y);
147 me.realUpperMargin2 = me.realUpperMargin1 + 1.5 * me.realFontSize_y;
149 me.columnPreviewOrigin = 0;
150 me.columnPreviewSize = me.itemAbsSize_y / me.itemAbsSize_x * 4 / 3;
151 me.columnNameOrigin = me.columnPreviewOrigin + me.columnPreviewSize + me.realFontSize_x;
152 me.columnNameSize = 1 - me.columnPreviewSize - 2 * me.realFontSize_x;
155 void XonoticSkinList_drawListBoxItem(entity me, float i, vector absSize, float isSelected)
160 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
162 s = me.skinParameter(me, i, SKINPARM_PREVIEW);
163 draw_Picture(me.columnPreviewOrigin * eX, s, me.columnPreviewSize * eX + eY, '1 1 1', 1);
165 s = me.skinParameter(me, i, SKINPARM_TITLE);
166 s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize);
167 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);
169 s = me.skinParameter(me, i, SKINPARM_AUTHOR);
170 s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize);
171 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);
174 void XonoticSkinList_setSkin(entity me)
177 localcmd("\nmenu_restart\nmenu_cmd skinselect\n");
180 void SetSkin_Click(entity btn, entity me)
185 void XonoticSkinList_clickListBoxItem(entity me, float i, vector where)
187 if(i == me.lastClickedSkin)
188 if(time < me.lastClickedTime + 0.3)
191 me.setSelected(me, i);
194 me.lastClickedSkin = i;
195 me.lastClickedTime = time;
198 float XonoticSkinList_keyDown(entity me, float scan, float ascii, float shift)
200 if(scan == K_ENTER || scan == K_KP_ENTER) {
205 return SUPER(XonoticSkinList).keyDown(me, scan, ascii, shift);