Xonotic
hudskinlist.qc File Reference
#include "hudskinlist.qh"
#include "inputbox.qh"
+ Include dependency graph for hudskinlist.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void getAllHUDSkins (entity me, int sortbuf)
 
void getHUDSkinFiles (entity me, int sortbuf, string subdir)
 
void HUDSkinList_Filter_Change (entity box, entity me)
 
void HUDSkinList_Refresh_Click (entity btn, entity me)
 
void HUDSkinList_SavedName_Change (entity box, entity me)
 
entity makeXonoticHUDSkinList ()
 
void SaveHUDSkin_Click (entity btn, entity me)
 
void SetHUDSkin_Click (entity btn, entity me)
 
void XonoticHUDSkinList_configureXonoticHUDSkinList (entity me)
 
void XonoticHUDSkinList_destroy (entity me)
 
void XonoticHUDSkinList_doubleClickListBoxItem (entity me, float i, vector where)
 
void XonoticHUDSkinList_draw (entity me)
 
void XonoticHUDSkinList_drawListBoxItem (entity me, int i, vector absSize, bool isSelected, bool isFocused)
 
void XonoticHUDSkinList_getHUDSkins (entity me)
 
string XonoticHUDSkinList_hudskinAuthor (entity me, float i)
 
string XonoticHUDSkinList_hudskinName (entity me, float i)
 
string XonoticHUDSkinList_hudskinPath (entity me, float i)
 
string XonoticHUDSkinList_hudskinTitle (entity me, float i)
 
float XonoticHUDSkinList_keyDown (entity me, float scan, float ascii, float shift)
 
void XonoticHUDSkinList_resizeNotify (entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
 
void XonoticHUDSkinList_setHUDSkin (entity me)
 
void XonoticHUDSkinList_showNotify (entity me)
 

Variables

const float HUDSKINPARM_AUTHOR = 3
 
const float HUDSKINPARM_COUNT = 4
 
const float HUDSKINPARM_NAME = 0
 
const float HUDSKINPARM_PATH = 1
 
const float HUDSKINPARM_TITLE = 2
 

Function Documentation

◆ getAllHUDSkins()

void getAllHUDSkins ( entity  me,
int  sortbuf 
)

Definition at line 83 of file hudskinlist.qc.

References argv(), fclose(), fgets(), FILE_READ, fopen(), HUDSKINPARM_AUTHOR, HUDSKINPARM_COUNT, HUDSKINPARM_NAME, HUDSKINPARM_PATH, HUDSKINPARM_TITLE, strcat(), strlen(), strstrofs, substring(), and tokenize_console.

Referenced by XonoticHUDSkinList_getHUDSkins().

84 {
85  int n = buf_getsize(sortbuf);
86  for(int i = 0; i < n; ++i)
87  {
88  string entry = bufstr_get(sortbuf, i);
89  int ofs = strstrofs(entry, "/", 0);
90  string s = "";
91  string filename = entry;
92  if(ofs >= 0)
93  {
94  s = substring(entry, ofs + 1, -1); // skip initial "/"
95  s = strcat(s, "/");
96  bufstr_set(me.listHUDSkin, i * HUDSKINPARM_COUNT + HUDSKINPARM_PATH, s);
97  filename = strcat(s, substring(entry, 0, ofs));
98  }
99  else
100  ofs = strlen(entry);
101  s = substring(entry, 4, ofs - 4 - 4); // remove "hud_" prefix and ".cfg" suffix
102  bufstr_set(me.listHUDSkin, i * HUDSKINPARM_COUNT + HUDSKINPARM_NAME, s);
103 
104  int fh = fopen(filename, FILE_READ);
105  if(fh < 0)
106  continue;
107  while((s = fgets(fh)) && substring(s, 0, 2) == "//")
108  {
109  tokenize_console(substring(s, 2, -1));
110  if(argv(0) == "title")
111  bufstr_set(me.listHUDSkin, i * HUDSKINPARM_COUNT + HUDSKINPARM_TITLE, argv(1));
112  else if(argv(0) == "author")
113  bufstr_set(me.listHUDSkin, i * HUDSKINPARM_COUNT + HUDSKINPARM_AUTHOR, argv(1));
114  }
115  fclose(fh);
116  }
117 }
const float HUDSKINPARM_PATH
Definition: hudskinlist.qc:20
const float HUDSKINPARM_NAME
Definition: hudskinlist.qc:19
const float FILE_READ
Definition: csprogsdefs.qc:231
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
const float HUDSKINPARM_AUTHOR
Definition: hudskinlist.qc:22
#define strstrofs
Definition: dpextensions.qh:42
#define tokenize_console
Definition: dpextensions.qh:24
const float HUDSKINPARM_TITLE
Definition: hudskinlist.qc:21
const float HUDSKINPARM_COUNT
Definition: hudskinlist.qc:23
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getHUDSkinFiles()

void getHUDSkinFiles ( entity  me,
int  sortbuf,
string  subdir 
)

Definition at line 42 of file hudskinlist.qc.

References search_begin(), search_end(), search_getfilename(), search_getsize(), strcat(), strstrofs, and substring().

Referenced by XonoticHUDSkinList_getHUDSkins().

43 {
44  string s;
45  if(me.filterString)
46  s = me.filterString;
47  else
48  s = "*";
49  s = strcat(subdir, "hud_", s, ".cfg");
50 
51  int list = search_begin(s, false, true);
52  if(list >= 0)
53  {
54  int n = search_getsize(list);
55  for(int i = 0; i < n; ++i)
56  {
57  string s = search_getfilename(list, i);
58  int subdir_ofs = strstrofs(s, "/", 0);
59  if(subdir_ofs >= 0)
60  {
61  int ofs = subdir_ofs;
62  while(ofs != -1)
63  {
64  subdir_ofs = ofs;
65  ofs = strstrofs(s, "/", subdir_ofs + 1);
66  }
67  }
68 
69  if(subdir_ofs == -1)
70  bufstr_add(sortbuf, s, true);
71  else
72  {
73  subdir = substring(s, 0, subdir_ofs);
74  string filename = substring(s, subdir_ofs + 1, -1);
75  // invert path and filename position so we can sort sortbuf by filename
76  bufstr_add(sortbuf, strcat(filename, "/", subdir), true);
77  }
78  }
79  search_end(list);
80  }
81 }
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
#define strstrofs
Definition: dpextensions.qh:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HUDSkinList_Filter_Change()

void HUDSkinList_Filter_Change ( entity  box,
entity  me 
)

Definition at line 199 of file hudskinlist.qc.

References strcat(), strfree, strstrofs, and strzone().

200 {
201  strfree(me.filterString);
202 
203  if(box.text != "")
204  {
205  if (strstrofs(box.text, "*", 0) >= 0 || strstrofs(box.text, "?", 0) >= 0)
206  me.filterString = strzone(box.text);
207  else
208  me.filterString = strzone(strcat("*", box.text, "*"));
209  }
210 
211  me.getHUDSkins(me);
212 }
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
#define strstrofs
Definition: dpextensions.qh:42
#define strfree(this)
Definition: string.qh:56
+ Here is the call graph for this function:

◆ HUDSkinList_Refresh_Click()

void HUDSkinList_Refresh_Click ( entity  btn,
entity  me 
)

Definition at line 185 of file hudskinlist.qc.

Referenced by XonoticHUDSkinList_draw().

186 {
187  me.getHUDSkins(me);
188  me.setSelected(me, 0); //always select the first element after a list update
189 }
+ Here is the caller graph for this function:

◆ HUDSkinList_SavedName_Change()

void HUDSkinList_SavedName_Change ( entity  box,
entity  me 
)

Definition at line 191 of file hudskinlist.qc.

References strfree, and strzone().

192 {
193  strfree(me.savedName);
194 
195  if(box.text != "")
196  me.savedName = strzone(box.text);
197 }
#define strfree(this)
Definition: string.qh:56
+ Here is the call graph for this function:

◆ makeXonoticHUDSkinList()

entity makeXonoticHUDSkinList ( )

Definition at line 5 of file hudskinlist.qc.

References entity(), and NEW.

Referenced by XonoticHUDExitDialog_fill().

6 {
7  entity me;
9  me.configureXonoticHUDSkinList(me);
10  return me;
11 }
#define NEW(cname,...)
Definition: oo.qh:105
entity() spawn
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SaveHUDSkin_Click()

void SaveHUDSkin_Click ( entity  btn,
entity  me 
)

Definition at line 214 of file hudskinlist.qc.

References localcmd, and time.

215 {
216  string s = me.savedName;
217  if(s == "")
218  s = "myconfig";
219  localcmd(sprintf("hud save \"%s\"\n", s));
220  me.delayedRefreshTime = time + 1;
221 }
float time
Definition: csprogsdefs.qc:16

◆ SetHUDSkin_Click()

void SetHUDSkin_Click ( entity  btn,
entity  me 
)

Definition at line 239 of file hudskinlist.qc.

240 {
241  me.setHUDSkin(me);
242 }

◆ XonoticHUDSkinList_configureXonoticHUDSkinList()

void XonoticHUDSkinList_configureXonoticHUDSkinList ( entity  me)

Definition at line 13 of file hudskinlist.qc.

14 {
15  me.configureXonoticListBox(me);
16  me.nItems = 0;
17 }

◆ XonoticHUDSkinList_destroy()

void XonoticHUDSkinList_destroy ( entity  me)

Definition at line 138 of file hudskinlist.qc.

139 {
140  if(me.nItems > 0)
141  buf_del(me.listHUDSkin);
142 }

◆ XonoticHUDSkinList_doubleClickListBoxItem()

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

Definition at line 244 of file hudskinlist.qc.

References m_play_click_sound(), and MENU_SOUND_EXECUTE.

245 {
247  me.setHUDSkin(me);
248 }
+ Here is the call graph for this function:

◆ XonoticHUDSkinList_draw()

void XonoticHUDSkinList_draw ( entity  me)

Definition at line 223 of file hudskinlist.qc.

References HUDSkinList_Refresh_Click(), NULL, SUPER, and time.

224 {
225  if(me.delayedRefreshTime > 0 && me.delayedRefreshTime < time)
226  {
228  me.delayedRefreshTime = 0;
229  }
230  SUPER(XonoticHUDSkinList).draw(me);
231 }
#define SUPER(cname)
Definition: oo.qh:219
#define NULL
Definition: post.qh:17
void HUDSkinList_Refresh_Click(entity btn, entity me)
Definition: hudskinlist.qc:185
float time
Definition: csprogsdefs.qc:16
+ Here is the call graph for this function:

◆ XonoticHUDSkinList_drawListBoxItem()

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

Definition at line 159 of file hudskinlist.qc.

References draw_Fill(), draw_Text(), draw_TextShortenToWidth(), draw_TextWidth(), eX, eY, getFadedAlpha(), s2, and strcat().

160 {
161  string s, s2;
162  if(isSelected)
163  draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
164  else if(isFocused)
165  {
166  me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
167  draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
168  }
169 
170  s = me.hudskinTitle(me, i);
171  if(s == "")
172  s = me.hudskinName(me, i);
173  s2 = me.hudskinAuthor(me, i);
174  if(s2 != "")
175  s = strcat(s, " (", s2, ")");
176  s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize);
177  draw_Text(me.realUpperMargin * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, SKINCOLOR_TEXT, SKINALPHA_TEXT, 1);
178 }
const vector eY
Definition: vector.qh:45
spree_inf s1 s2 s3loc s2 spree_inf s1 s2 s3loc s2 spree_inf s1 s2 s3loc s2 s1 s2loc s1 s2loc s1 s2loc s1 s2loc s1 s2loc s1 s2loc s1 s2loc s1 s2 f1 f1points s1 s2
Definition: all.inc:438
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
const vector eX
Definition: vector.qh:44
+ Here is the call graph for this function:

◆ XonoticHUDSkinList_getHUDSkins()

void XonoticHUDSkinList_getHUDSkins ( entity  me)

Definition at line 119 of file hudskinlist.qc.

References buf_create, getAllHUDSkins(), getHUDSkinFiles(), and HUDSKINPARM_COUNT.

120 {
121  if (me.listHUDSkin >= 0)
122  buf_del(me.listHUDSkin);
123  me.listHUDSkin = buf_create();
124  if (me.listHUDSkin < 0)
125  {
126  me.nItems = 0;
127  return;
128  }
129  int sortbuf = buf_create();
130  getHUDSkinFiles(me, sortbuf, "");
131  getHUDSkinFiles(me, sortbuf, "data/");
132  buf_sort(sortbuf, 128, 0);
133  getAllHUDSkins(me, sortbuf);
134  buf_del(sortbuf);
135  me.nItems = buf_getsize(me.listHUDSkin) / HUDSKINPARM_COUNT;
136 }
void getHUDSkinFiles(entity me, int sortbuf, string subdir)
Definition: hudskinlist.qc:42
#define buf_create
Definition: dpextensions.qh:63
const float HUDSKINPARM_COUNT
Definition: hudskinlist.qc:23
void getAllHUDSkins(entity me, int sortbuf)
Definition: hudskinlist.qc:83
+ Here is the call graph for this function:

◆ XonoticHUDSkinList_hudskinAuthor()

string XonoticHUDSkinList_hudskinAuthor ( entity  me,
float  i 
)

Definition at line 36 of file hudskinlist.qc.

References HUDSKINPARM_AUTHOR, and HUDSKINPARM_COUNT.

37 {
38  return bufstr_get(me.listHUDSkin, i * HUDSKINPARM_COUNT + HUDSKINPARM_AUTHOR);
39 }
const float HUDSKINPARM_AUTHOR
Definition: hudskinlist.qc:22
const float HUDSKINPARM_COUNT
Definition: hudskinlist.qc:23

◆ XonoticHUDSkinList_hudskinName()

string XonoticHUDSkinList_hudskinName ( entity  me,
float  i 
)

Definition at line 24 of file hudskinlist.qc.

References HUDSKINPARM_COUNT, and HUDSKINPARM_NAME.

25 {
26  return bufstr_get(me.listHUDSkin, i * HUDSKINPARM_COUNT + HUDSKINPARM_NAME);
27 }
const float HUDSKINPARM_NAME
Definition: hudskinlist.qc:19
const float HUDSKINPARM_COUNT
Definition: hudskinlist.qc:23

◆ XonoticHUDSkinList_hudskinPath()

string XonoticHUDSkinList_hudskinPath ( entity  me,
float  i 
)

Definition at line 28 of file hudskinlist.qc.

References HUDSKINPARM_COUNT, and HUDSKINPARM_PATH.

29 {
30  return bufstr_get(me.listHUDSkin, i * HUDSKINPARM_COUNT + HUDSKINPARM_PATH);
31 }
const float HUDSKINPARM_PATH
Definition: hudskinlist.qc:20
const float HUDSKINPARM_COUNT
Definition: hudskinlist.qc:23

◆ XonoticHUDSkinList_hudskinTitle()

string XonoticHUDSkinList_hudskinTitle ( entity  me,
float  i 
)

Definition at line 32 of file hudskinlist.qc.

References HUDSKINPARM_COUNT, and HUDSKINPARM_TITLE.

33 {
34  return bufstr_get(me.listHUDSkin, i * HUDSKINPARM_COUNT + HUDSKINPARM_TITLE);
35 }
const float HUDSKINPARM_TITLE
Definition: hudskinlist.qc:21
const float HUDSKINPARM_COUNT
Definition: hudskinlist.qc:23

◆ XonoticHUDSkinList_keyDown()

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

Definition at line 250 of file hudskinlist.qc.

References K_ENTER, K_KP_ENTER, and SUPER.

251 {
252  if(scan == K_ENTER || scan == K_KP_ENTER)
253  {
254  me.setHUDSkin(me);
255  return 1;
256  }
257  else
258  {
259  return SUPER(XonoticHUDSkinList).keyDown(me, scan, ascii, shift);
260  }
261 }
float K_KP_ENTER
Definition: keycodes.qc:74
#define SUPER(cname)
Definition: oo.qh:219
float K_ENTER
Definition: keycodes.qc:8

◆ XonoticHUDSkinList_resizeNotify()

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

Definition at line 144 of file hudskinlist.qc.

References SUPER.

145 {
146  me.itemAbsSize = '0 0 0';
147  SUPER(XonoticHUDSkinList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
148 
149  me.itemAbsSize.y = absSize.y * me.itemHeight;
150  me.itemAbsSize.x = absSize.x * (1 - me.controlWidth);
151  me.realFontSize.y = me.fontSize / me.itemAbsSize.y;
152  me.realFontSize.x = me.fontSize / me.itemAbsSize.x;
153  me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
154 
155  me.columnNameOrigin = me.realFontSize.x;
156  me.columnNameSize = 1 - 2 * me.realFontSize.x;
157 }
#define SUPER(cname)
Definition: oo.qh:219

◆ XonoticHUDSkinList_setHUDSkin()

void XonoticHUDSkinList_setHUDSkin ( entity  me)

Definition at line 233 of file hudskinlist.qc.

References localcmd, and strcat().

234 {
235  string cfg = strcat(me.hudskinPath(me, me.selectedItem), "hud_", me.hudskinName(me, me.selectedItem), ".cfg");
236  localcmd("exec \"", cfg, "\"\n");
237 }
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
+ Here is the call graph for this function:

◆ XonoticHUDSkinList_showNotify()

void XonoticHUDSkinList_showNotify ( entity  me)

Definition at line 180 of file hudskinlist.qc.

181 {
182  me.getHUDSkins(me);
183 }

Variable Documentation

◆ HUDSKINPARM_AUTHOR

const float HUDSKINPARM_AUTHOR = 3

Definition at line 22 of file hudskinlist.qc.

Referenced by getAllHUDSkins(), and XonoticHUDSkinList_hudskinAuthor().

◆ HUDSKINPARM_COUNT

◆ HUDSKINPARM_NAME

const float HUDSKINPARM_NAME = 0

Definition at line 19 of file hudskinlist.qc.

Referenced by getAllHUDSkins(), and XonoticHUDSkinList_hudskinName().

◆ HUDSKINPARM_PATH

const float HUDSKINPARM_PATH = 1

Definition at line 20 of file hudskinlist.qc.

Referenced by getAllHUDSkins(), and XonoticHUDSkinList_hudskinPath().

◆ HUDSKINPARM_TITLE

const float HUDSKINPARM_TITLE = 2

Definition at line 21 of file hudskinlist.qc.

Referenced by getAllHUDSkins(), and XonoticHUDSkinList_hudskinTitle().