Xonotic
languagelist.qc File Reference
#include "languagelist.qh"
#include "../item/modalcontroller.qh"
#include "mainwindow.qh"
+ Include dependency graph for languagelist.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

entity makeXonoticLanguageList ()
 
void SetLanguage_Click (entity btn, entity me)
 
void XonoticLanguageList_configureXonoticLanguageList (entity me)
 
void XonoticLanguageList_destroy (entity me)
 
void XonoticLanguageList_doubleClickListBoxItem (entity me, float i, vector where)
 
void XonoticLanguageList_drawListBoxItem (entity me, int i, vector absSize, bool isSelected, bool isFocused)
 
void XonoticLanguageList_getLanguages (entity me)
 
float XonoticLanguageList_keyDown (entity me, float scan, float ascii, float shift)
 
string XonoticLanguageList_languageParameter (entity me, float i, float key)
 
void XonoticLanguageList_loadCvars (entity me)
 
void XonoticLanguageList_resizeNotify (entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
 
void XonoticLanguageList_saveCvars (entity me)
 
void XonoticLanguageList_setLanguage (entity me)
 
void XonoticLanguageList_setSelected (entity me, float i)
 

Variables

const float LANGPARM_COUNT = 4
 
const float LANGPARM_ID = 0
 
const float LANGPARM_NAME = 1
 
const float LANGPARM_NAME_LOCALIZED = 2
 
const float LANGPARM_PERCENTAGE = 3
 

Function Documentation

◆ makeXonoticLanguageList()

entity makeXonoticLanguageList ( )

Definition at line 12 of file languagelist.qc.

References entity(), and NEW.

13 {
14  entity me;
16  me.configureXonoticLanguageList(me);
17  return me;
18 }
#define NEW(cname,...)
Definition: oo.qh:105
entity() spawn
+ Here is the call graph for this function:

◆ SetLanguage_Click()

void SetLanguage_Click ( entity  btn,
entity  me 
)

Definition at line 196 of file languagelist.qc.

197 {
198  me.setLanguage(me);
199 }

◆ XonoticLanguageList_configureXonoticLanguageList()

void XonoticLanguageList_configureXonoticLanguageList ( entity  me)

Definition at line 20 of file languagelist.qc.

21 {
22  me.configureXonoticListBox(me);
23  me.getLanguages(me);
24  me.loadCvars(me);
25 }

◆ XonoticLanguageList_destroy()

void XonoticLanguageList_destroy ( entity  me)

Definition at line 147 of file languagelist.qc.

148 {
149  buf_del(me.languagelist);
150 }

◆ XonoticLanguageList_doubleClickListBoxItem()

void XonoticLanguageList_doubleClickListBoxItem ( entity  me,
float  i,
vector  where 
)

Definition at line 129 of file languagelist.qc.

References m_play_click_sound(), and MENU_SOUND_EXECUTE.

130 {
132  me.setLanguage(me);
133 }
+ Here is the call graph for this function:

◆ XonoticLanguageList_drawListBoxItem()

void XonoticLanguageList_drawListBoxItem ( entity  me,
int  i,
vector  absSize,
bool  isSelected,
bool  isFocused 
)

Definition at line 27 of file languagelist.qc.

References draw_CondensedFontFactor(), draw_Fill(), draw_fontscale, draw_Text(), draw_TextWidth(), eX, eY, getFadedAlpha(), LANGPARM_NAME_LOCALIZED, LANGPARM_PERCENTAGE, stof(), and vector().

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 }
const vector eY
Definition: vector.qh:45
const float LANGPARM_NAME_LOCALIZED
Definition: languagelist.qc:8
vector(float skel, float bonenum) _skel_get_boneabs_hidden
const vector eX
Definition: vector.qh:44
const float LANGPARM_PERCENTAGE
Definition: languagelist.qc:9
+ Here is the call graph for this function:

◆ XonoticLanguageList_getLanguages()

void XonoticLanguageList_getLanguages ( entity  me)

Definition at line 152 of file languagelist.qc.

References argv(), buf_create, fclose(), fgets(), FILE_READ, fopen(), LANGPARM_COUNT, LANGPARM_ID, LANGPARM_NAME, LANGPARM_NAME_LOCALIZED, LANGPARM_PERCENTAGE, and tokenize_console.

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 }
const float FILE_READ
Definition: csprogsdefs.qc:231
const float LANGPARM_COUNT
Definition: languagelist.qc:10
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
#define tokenize_console
Definition: dpextensions.qh:24
const float LANGPARM_PERCENTAGE
Definition: languagelist.qc:9
+ Here is the call graph for this function:

◆ XonoticLanguageList_keyDown()

float XonoticLanguageList_keyDown ( entity  me,
float  scan,
float  ascii,
float  shift 
)

Definition at line 135 of file languagelist.qc.

References K_ENTER, K_KP_ENTER, m_play_click_sound(), MENU_SOUND_EXECUTE, and SUPER.

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 }
float K_KP_ENTER
Definition: keycodes.qc:74
#define SUPER(cname)
Definition: oo.qh:219
float K_ENTER
Definition: keycodes.qc:8
+ Here is the call graph for this function:

◆ XonoticLanguageList_languageParameter()

string XonoticLanguageList_languageParameter ( entity  me,
float  i,
float  key 
)

Definition at line 191 of file languagelist.qc.

References LANGPARM_COUNT.

192 {
193  return bufstr_get(me.languagelist, i * LANGPARM_COUNT + key);
194 }
const float LANGPARM_COUNT
Definition: languagelist.qc:10

◆ XonoticLanguageList_loadCvars()

void XonoticLanguageList_loadCvars ( entity  me)

Definition at line 93 of file languagelist.qc.

References cvar_string(), LANGPARM_ID, and SUPER.

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 }
#define SUPER(cname)
Definition: oo.qh:219
const float LANGPARM_ID
Definition: languagelist.qc:6
+ Here is the call graph for this function:

◆ XonoticLanguageList_resizeNotify()

void XonoticLanguageList_resizeNotify ( entity  me,
vector  relOrigin,
vector  relSize,
vector  absOrigin,
vector  absSize 
)

Definition at line 75 of file languagelist.qc.

References SUPER.

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 }
#define SUPER(cname)
Definition: oo.qh:219

◆ XonoticLanguageList_saveCvars()

void XonoticLanguageList_saveCvars ( entity  me)

Definition at line 124 of file languagelist.qc.

References cvar_set(), and LANGPARM_ID.

125 {
126  cvar_set("_menu_prvm_language", me.languageParameter(me, me.selectedItem, LANGPARM_ID));
127 }
const float LANGPARM_ID
Definition: languagelist.qc:6
+ Here is the call graph for this function:

◆ XonoticLanguageList_setLanguage()

void XonoticLanguageList_setLanguage ( entity  me)

Definition at line 180 of file languagelist.qc.

References cvar_string(), DialogOpenButton_Click(), GAME_CONNECTED, gamestatus, localcmd, main, and prvm_language.

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 }
void DialogOpenButton_Click(entity button, entity tab)
string prvm_language
Definition: i18n.qh:8
+ Here is the call graph for this function:

◆ XonoticLanguageList_setSelected()

void XonoticLanguageList_setSelected ( entity  me,
float  i 
)

Definition at line 87 of file languagelist.qc.

References SUPER.

88 {
89  SUPER(XonoticLanguageList).setSelected(me, i);
90  me.saveCvars(me);
91 }
#define SUPER(cname)
Definition: oo.qh:219

Variable Documentation

◆ LANGPARM_COUNT

const float LANGPARM_COUNT = 4

◆ LANGPARM_ID

const float LANGPARM_ID = 0

◆ LANGPARM_NAME

const float LANGPARM_NAME = 1

Definition at line 7 of file languagelist.qc.

Referenced by XonoticLanguageList_getLanguages().

◆ LANGPARM_NAME_LOCALIZED

const float LANGPARM_NAME_LOCALIZED = 2

◆ LANGPARM_PERCENTAGE

const float LANGPARM_PERCENTAGE = 3