5 CLASS(XonoticSkinList, XonoticListBox)
6 METHOD(XonoticSkinList, configureXonoticSkinList, void(entity));
7 ATTRIB(XonoticSkinList, rowsPerItem, float, 4)
8 METHOD(XonoticSkinList, resizeNotify, void(entity, vector, vector, vector, vector));
9 METHOD(XonoticSkinList, drawListBoxItem, void(entity, int, vector, bool, bool));
10 METHOD(XonoticSkinList, getSkins, void(entity));
11 METHOD(XonoticSkinList, setSkin, void(entity));
12 METHOD(XonoticSkinList, loadCvars, void(entity));
13 METHOD(XonoticSkinList, saveCvars, void(entity));
14 METHOD(XonoticSkinList, skinParameter, string(entity, float, float));
15 METHOD(XonoticSkinList, doubleClickListBoxItem, void(entity, float, vector));
16 METHOD(XonoticSkinList, keyDown, float(entity, float, float, float));
17 METHOD(XonoticSkinList, destroy, void(entity));
19 ATTRIB(XonoticSkinList, skinlist, float, -1)
20 ATTRIB(XonoticSkinList, realFontSize, vector, '0 0 0')
21 ATTRIB(XonoticSkinList, columnPreviewOrigin, float, 0)
22 ATTRIB(XonoticSkinList, columnPreviewSize, float, 0)
23 ATTRIB(XonoticSkinList, columnNameOrigin, float, 0)
24 ATTRIB(XonoticSkinList, columnNameSize, float, 0)
25 ATTRIB(XonoticSkinList, realUpperMargin1, float, 0)
26 ATTRIB(XonoticSkinList, realUpperMargin2, float, 0)
27 ATTRIB(XonoticSkinList, origin, vector, '0 0 0')
28 ATTRIB(XonoticSkinList, itemAbsSize, vector, '0 0 0')
30 ATTRIB(XonoticSkinList, name, string, "skinselector")
31 ENDCLASS(XonoticSkinList)
33 entity makeXonoticSkinList();
34 void SetSkin_Click(entity btn, entity me);
39 const float SKINPARM_NAME = 0;
40 const float SKINPARM_TITLE = 1;
41 const float SKINPARM_AUTHOR = 2;
42 const float SKINPARM_PREVIEW = 3;
43 const float SKINPARM_COUNT = 4;
45 entity makeXonoticSkinList()
48 me = NEW(XonoticSkinList);
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)
70 me.setSelected(me, i);
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 name = substring(s, 9, strlen(s) - 24); // the * part
105 bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_NAME, name);
106 bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_TITLE, _("<TITLE>"));
107 bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_AUTHOR, _("<AUTHOR>"));
108 if(draw_PictureSize(strcat("/gfx/menu/", substring(s, 9, strlen(s) - 24), "/skinpreview")) == '0 0 0')
109 bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_PREVIEW, "nopreview_menuskin");
111 bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_PREVIEW, strcat("/gfx/menu/", substring(s, 9, strlen(s) - 24), "/skinpreview"));
112 fh = fopen(s, FILE_READ);
115 LOG_INFO("Warning: can't open skinvalues.txt file\n");
118 while((s = fgets(fh)))
120 // these two are handled by skinlist.qc
121 if(substring(s, 0, 6) == "title ")
123 if (name == cvar_defstring("menu_skin"))
124 bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_TITLE, strcat(substring(s, 6, strlen(s) - 6), " (", _("Default"), ")"));
126 bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_TITLE, substring(s, 6, strlen(s) - 6));
128 else if(substring(s, 0, 7) == "author ")
129 bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_AUTHOR, substring(s, 7, strlen(s) - 7));
140 void XonoticSkinList_destroy(entity me)
142 buf_del(me.skinlist);
145 void XonoticSkinList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
147 me.itemAbsSize = '0 0 0';
148 SUPER(XonoticSkinList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
150 me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize.y * me.itemHeight));
151 me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize.x * (1 - me.controlWidth)));
152 me.realUpperMargin1 = 0.5 * (1 - 2.5 * me.realFontSize.y);
153 me.realUpperMargin2 = me.realUpperMargin1 + 1.5 * me.realFontSize.y;
155 me.columnPreviewOrigin = 0;
156 me.columnPreviewSize = me.itemAbsSize.y / me.itemAbsSize.x * 4 / 3;
157 me.columnNameOrigin = me.columnPreviewOrigin + me.columnPreviewSize + me.realFontSize.x;
158 me.columnNameSize = 1 - me.columnPreviewSize - 2 * me.realFontSize.x;
161 void XonoticSkinList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
166 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
169 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
170 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
173 s = me.skinParameter(me, i, SKINPARM_PREVIEW);
174 draw_Picture(me.columnPreviewOrigin * eX, s, me.columnPreviewSize * eX + eY, '1 1 1', 1);
176 s = me.skinParameter(me, i, SKINPARM_TITLE);
177 s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize);
178 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);
180 s = me.skinParameter(me, i, SKINPARM_AUTHOR);
181 s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize);
182 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);
185 void XonoticSkinList_setSkin(entity me)
188 localcmd("\nmenu_restart\nmenu_cmd skinselect\n");
191 void SetSkin_Click(entity btn, entity me)
196 void XonoticSkinList_doubleClickListBoxItem(entity me, float i, vector where)
198 m_play_click_sound(MENU_SOUND_EXECUTE);
202 float XonoticSkinList_keyDown(entity me, float scan, float ascii, float shift)
204 if(scan == K_ENTER || scan == K_KP_ENTER)
206 m_play_click_sound(MENU_SOUND_EXECUTE);
211 return SUPER(XonoticSkinList).keyDown(me, scan, ascii, shift);