2 CLASS(XonoticLanguageList) EXTENDS(XonoticListBox)
3 METHOD(XonoticLanguageList, configureXonoticLanguageList, void(entity))
4 ATTRIB(XonoticLanguageList, rowsPerItem, float, 1)
5 METHOD(XonoticLanguageList, drawListBoxItem, void(entity, float, vector, float))
6 METHOD(XonoticLanguageList, resizeNotify, void(entity, vector, vector, vector, vector))
7 METHOD(XonoticLanguageList, setSelected, void(entity, float))
8 METHOD(XonoticLanguageList, loadCvars, void(entity))
9 METHOD(XonoticLanguageList, saveCvars, void(entity))
11 ATTRIB(XonoticLanguageList, realFontSize, vector, '0 0 0')
12 ATTRIB(XonoticLanguageList, realUpperMargin, float, 0)
13 ATTRIB(XonoticLanguageList, columnNameOrigin, float, 0)
14 ATTRIB(XonoticLanguageList, columnNameSize, float, 0)
15 ATTRIB(XonoticLanguageList, columnPercentageOrigin, float, 0)
16 ATTRIB(XonoticLanguageList, columnPercentageSize, float, 0)
18 METHOD(XonoticLanguageList, clickListBoxItem, void(entity, float, vector)) // double click handling
19 METHOD(XonoticLanguageList, keyDown, float(entity, float, float, float)) // enter handling
20 ATTRIB(XonoticLanguageList, lastClickedLanguage, float, -1)
21 ATTRIB(XonoticLanguageList, lastClickedTime, float, 0)
23 METHOD(XonoticLanguageList, destroy, void(entity))
25 ATTRIB(XonoticLanguageList, languagelist, float, -1)
26 METHOD(XonoticLanguageList, getLanguages, void(entity))
27 METHOD(XonoticLanguageList, setLanguage, void(entity))
28 METHOD(XonoticLanguageList, languageParameter, string(entity, float, float))
30 ATTRIB(XonoticLanguageList, name, string, "languageselector") // change this to make it noninteractive (for first run dialog)
31 ENDCLASS(XonoticLanguageList)
33 entity makeXonoticLanguageList();
34 void SetLanguage_Click(entity btn, entity me);
40 #define LANGPARM_NAME 1
41 #define LANGPARM_NAME_LOCALIZED 2
42 #define LANGPARM_PERCENTAGE 3
43 #define LANGPARM_COUNT 4
45 entity makeXonoticLanguageList()
48 me = spawnXonoticLanguageList();
49 me.configureXonoticLanguageList(me);
53 void XonoticLanguageList_configureXonoticLanguageList(entity me)
55 me.configureXonoticListBox(me);
60 void XonoticLanguageList_drawListBoxItem(entity me, float i, vector absSize, float isSelected)
64 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
66 s = me.languageParameter(me, i, LANGPARM_NAME_LOCALIZED);
67 s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize);
68 draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
70 p = me.languageParameter(me, i, LANGPARM_PERCENTAGE);
73 p = draw_TextShortenToWidth(p, me.columnPercentageSize, 0, me.realFontSize);
74 draw_Text(me.realUpperMargin * eY + (me.columnPercentageOrigin + (me.columnPercentageSize - draw_TextWidth(p, 0, me.realFontSize))) * eX, p, me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
78 void XonoticLanguageList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
80 SUPER(XonoticLanguageList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
81 me.realFontSize_y = me.fontSize / (absSize_y * me.itemHeight);
82 me.realFontSize_x = me.fontSize / (absSize_x * (1 - me.controlWidth));
83 me.realUpperMargin = 0.5 * (1 - me.realFontSize_y);
84 me.columnPercentageSize = me.realFontSize_x * 3;
85 me.columnPercentageOrigin = 1 - me.columnPercentageSize;
86 me.columnNameOrigin = 0;
87 me.columnNameSize = me.columnPercentageOrigin;
90 void XonoticLanguageList_setSelected(entity me, float i)
92 SUPER(XonoticLanguageList).setSelected(me, i);
96 void XonoticLanguageList_loadCvars(entity me)
100 s = cvar_string("_menu_prvm_language");
103 // default to English
104 for(i = 0; i < n; ++i)
106 if(me.languageParameter(me, i, LANGPARM_ID) == "en")
113 // otherwise, find the language
114 for(i = 0; i < n; ++i)
116 if(me.languageParameter(me, i, LANGPARM_ID) == s)
123 // save it off (turning anything unknown into "en")
127 void XonoticLanguageList_saveCvars(entity me)
129 cvar_set("_menu_prvm_language", me.languageParameter(me, me.selectedItem, LANGPARM_ID));
132 void XonoticLanguageList_clickListBoxItem(entity me, float i, vector where)
134 if(i == me.lastClickedLanguage)
135 if(time < me.lastClickedTime + 0.3)
138 me.setSelected(me, i);
141 me.lastClickedLanguage = i;
142 me.lastClickedTime = time;
145 float XonoticLanguageList_keyDown(entity me, float scan, float ascii, float shift)
147 if(scan == K_ENTER || scan == K_KP_ENTER) {
152 return SUPER(XonoticLanguageList).keyDown(me, scan, ascii, shift);
155 void XonoticLanguageList_destroy(entity me)
157 buf_del(me.languagelist);
160 void XonoticLanguageList_getLanguages(entity me)
167 fh = fopen("languages.txt", FILE_READ);
169 while((s = fgets(fh)))
171 n = tokenize_console(s);
174 bufstr_set(buf, i * LANGPARM_COUNT + LANGPARM_ID, argv(0));
175 bufstr_set(buf, i * LANGPARM_COUNT + LANGPARM_NAME, argv(1));
176 float k = strstrofs(argv(2), "(", 0);
178 if(substring(argv(2), strlen(argv(2)) - 1, 1) == ")")
180 string percent = substring(argv(2), k + 1, -2);
181 if(percent != "100%")
182 bufstr_set(buf, i * LANGPARM_COUNT + LANGPARM_PERCENTAGE, percent);
184 bufstr_set(buf, i * LANGPARM_COUNT + LANGPARM_NAME_LOCALIZED, (k < 0) ? argv(2) : substring(argv(2), 0, k - 1));
189 me.languagelist = buf;
193 void XonoticLanguageList_setLanguage(entity me)
195 if(prvm_language != cvar_string("_menu_prvm_language"))
197 if(!(gamestatus & GAME_CONNECTED))
198 localcmd("\nprvm_language \"$_menu_prvm_language\"; menu_restart; menu_cmd languageselect\n");
200 DialogOpenButton_Click(me, main.languageWarningDialog);
204 string XonoticLanguageList_languageParameter(entity me, float i, float key)
206 return bufstr_get(me.languagelist, i * LANGPARM_COUNT + key);
209 void SetLanguage_Click(entity btn, entity me)