Xonotic
languagelist.qc
Go to the documentation of this file.
1 #include "languagelist.qh"
2 
3 #include "../item/modalcontroller.qh"
4 #include "mainwindow.qh"
5 
6 const float LANGPARM_ID = 0;
7 const float LANGPARM_NAME = 1;
8 const float LANGPARM_NAME_LOCALIZED = 2;
9 const float LANGPARM_PERCENTAGE = 3;
10 const float LANGPARM_COUNT = 4;
11 
13 {
14  entity me;
16  me.configureXonoticLanguageList(me);
17  return me;
18 }
19 
21 {
22  me.configureXonoticListBox(me);
23  me.getLanguages(me);
24  me.loadCvars(me);
25 }
26 
27 void XonoticLanguageList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
28 {
29  if(isSelected)
30  draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
31  else if(isFocused)
32  {
33  me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
34  draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
35  }
36 
37  string p = me.languageParameter(me, i, LANGPARM_PERCENTAGE);
38  float alpha_factor = 1;
39  if (p != "")
40  {
41  float percent = stof(p);
42  if (percent >= 90)
43  alpha_factor = 1;
44  else if (percent >= 50)
45  alpha_factor = 0.65;
46  else
47  alpha_factor = 0.3;
48  }
49  else
50  p = "\xE2\x9C\x94"; // Unicode Character 'HEAVY CHECK MARK' (U+2714)
51 
52  string s = me.languageParameter(me, i, LANGPARM_NAME_LOCALIZED);
53 
54  vector save_fontscale = draw_fontscale;
55  float f = draw_CondensedFontFactor(s, false, me.realFontSize, 1);
56  draw_fontscale.x *= f;
57  vector fs = me.realFontSize;
58  fs.x *= f;
59  draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, fs, SKINCOLOR_TEXT * alpha_factor, SKINALPHA_TEXT, 0);
60  draw_fontscale = save_fontscale;
61 
62  if(p != "")
63  {
64  vector save_fontscale = draw_fontscale;
65  float f = draw_CondensedFontFactor(p, false, me.realFontSize, 1);
66  draw_fontscale.x *= f;
67  vector fs = me.realFontSize;
68  fs.x *= f;
69  float x_ofs = me.columnPercentageOrigin + (me.columnPercentageSize - draw_TextWidth(p, 0, fs));
70  draw_Text(me.realUpperMargin * eY + x_ofs * eX, p, fs, SKINCOLOR_TEXT, SKINALPHA_TEXT * alpha_factor, 0);
71  draw_fontscale = save_fontscale;
72  }
73 }
74 
75 void XonoticLanguageList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
76 {
77  SUPER(XonoticLanguageList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
78  me.realFontSize_y = me.fontSize / (absSize.y * me.itemHeight);
79  me.realFontSize_x = me.fontSize / (absSize.x * (1 - me.controlWidth));
80  me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
81  me.columnPercentageSize = me.realFontSize.x * 3;
82  me.columnPercentageOrigin = 1 - me.columnPercentageSize;
83  me.columnNameOrigin = 0;
84  me.columnNameSize = me.columnPercentageOrigin;
85 }
86 
88 {
89  SUPER(XonoticLanguageList).setSelected(me, i);
90  me.saveCvars(me);
91 }
92 
94 {
95  string s;
96  float i, n;
97  s = cvar_string("_menu_prvm_language");
98  n = me.nItems;
99 
100  // default to English
101  for(i = 0; i < n; ++i)
102  {
103  if(me.languageParameter(me, i, LANGPARM_ID) == "en")
104  {
105  SUPER(XonoticLanguageList).setSelected(me, i);
106  break;
107  }
108  }
109 
110  // otherwise, find the language
111  for(i = 0; i < n; ++i)
112  {
113  if(me.languageParameter(me, i, LANGPARM_ID) == s)
114  {
115  SUPER(XonoticLanguageList).setSelected(me, i);
116  break;
117  }
118  }
119 
120  // save it off (turning anything unknown into "en")
121  me.saveCvars(me);
122 }
123 
125 {
126  cvar_set("_menu_prvm_language", me.languageParameter(me, me.selectedItem, LANGPARM_ID));
127 }
128 
130 {
132  me.setLanguage(me);
133 }
134 
135 float XonoticLanguageList_keyDown(entity me, float scan, float ascii, float shift)
136 {
137  if(scan == K_ENTER || scan == K_KP_ENTER)
138  {
140  me.setLanguage(me);
141  return 1;
142  }
143  else
144  return SUPER(XonoticLanguageList).keyDown(me, scan, ascii, shift);
145 }
146 
148 {
149  buf_del(me.languagelist);
150 }
151 
153 {
154  float buf, i, n, fh;
155  string s;
156 
157  buf = buf_create();
158 
159  fh = fopen("languages.txt", FILE_READ);
160  i = 0;
161  while((s = fgets(fh)))
162  {
163  n = tokenize_console(s);
164  if(n < 3)
165  continue;
166  bufstr_set(buf, i * LANGPARM_COUNT + LANGPARM_ID, argv(0));
167  bufstr_set(buf, i * LANGPARM_COUNT + LANGPARM_NAME, argv(1));
168  bufstr_set(buf, i * LANGPARM_COUNT + LANGPARM_NAME_LOCALIZED, argv(2));
169  string percent = argv(3);
170  if(percent && percent != "100%")
171  bufstr_set(buf, i * LANGPARM_COUNT + LANGPARM_PERCENTAGE, percent);
172  ++i;
173  }
174  fclose(fh);
175 
176  me.languagelist = buf;
177  me.nItems = i;
178 }
179 
181 {
182  if(prvm_language != cvar_string("_menu_prvm_language"))
183  {
184  if(!(gamestatus & GAME_CONNECTED))
185  localcmd("\nprvm_language \"$_menu_prvm_language\"; menu_restart; menu_cmd languageselect\n");
186  else
187  DialogOpenButton_Click(me, main.languageWarningDialog);
188  }
189 }
190 
191 string XonoticLanguageList_languageParameter(entity me, float i, float key)
192 {
193  return bufstr_get(me.languagelist, i * LANGPARM_COUNT + key);
194 }
195 
197 {
198  me.setLanguage(me);
199 }
void XonoticLanguageList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
Definition: languagelist.qc:27
const vector eY
Definition: vector.qh:45
#define NEW(cname,...)
Definition: oo.qh:105
void XonoticLanguageList_saveCvars(entity me)
float XonoticLanguageList_keyDown(entity me, float scan, float ascii, float shift)
entity() spawn
void XonoticLanguageList_destroy(entity me)
void DialogOpenButton_Click(entity button, entity tab)
const float FILE_READ
Definition: csprogsdefs.qc:231
const float LANGPARM_COUNT
Definition: languagelist.qc:10
string XonoticLanguageList_languageParameter(entity me, float i, float key)
void SetLanguage_Click(entity btn, entity me)
float K_KP_ENTER
Definition: keycodes.qc:74
#define SUPER(cname)
Definition: oo.qh:219
const float LANGPARM_ID
Definition: languagelist.qc:6
#define buf_create
Definition: dpextensions.qh:63
const float LANGPARM_NAME_LOCALIZED
Definition: languagelist.qc:8
const float LANGPARM_NAME
Definition: languagelist.qc:7
void XonoticLanguageList_getLanguages(entity me)
entity makeXonoticLanguageList()
Definition: languagelist.qc:12
void XonoticLanguageList_loadCvars(entity me)
Definition: languagelist.qc:93
void XonoticLanguageList_setLanguage(entity me)
void XonoticLanguageList_doubleClickListBoxItem(entity me, float i, vector where)
vector(float skel, float bonenum) _skel_get_boneabs_hidden
#define tokenize_console
Definition: dpextensions.qh:24
string prvm_language
Definition: i18n.qh:8
void XonoticLanguageList_setSelected(entity me, float i)
Definition: languagelist.qc:87
const vector eX
Definition: vector.qh:44
float K_ENTER
Definition: keycodes.qc:8
void XonoticLanguageList_configureXonoticLanguageList(entity me)
Definition: languagelist.qc:20
const float LANGPARM_PERCENTAGE
Definition: languagelist.qc:9
void XonoticLanguageList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
Definition: languagelist.qc:75