Xonotic
skinlist.qc
Go to the documentation of this file.
1 #include "skinlist.qh"
2 
3 const float SKINPARM_NAME = 0;
4 const float SKINPARM_TITLE = 1;
5 const float SKINPARM_AUTHOR = 2;
6 const float SKINPARM_PREVIEW = 3;
7 const float SKINPARM_COUNT = 4;
8 
10 {
11  entity me;
12  me = NEW(XonoticSkinList);
13  me.configureXonoticSkinList(me);
14  return me;
15 }
16 
18 {
19  me.configureXonoticListBox(me);
20  me.getSkins(me);
21  me.loadCvars(me);
22 }
23 
25 {
26  string s;
27  float i, n;
28  s = cvar_string("menu_skin");
29  n = me.nItems;
30  for(i = 0; i < n; ++i)
31  {
32  if(me.skinParameter(me, i, SKINPARM_NAME) == s)
33  {
34  me.setSelected(me, i);
35  break;
36  }
37  }
38 }
39 
41 {
42  cvar_set("menu_skin", me.skinParameter(me, me.selectedItem, SKINPARM_NAME));
43 }
44 
45 string XonoticSkinList_skinParameter(entity me, float i, float key)
46 {
47  return bufstr_get(me.skinlist, i * SKINPARM_COUNT + key);
48 }
49 
51 {
52  float glob, buf, i, n, fh;
53  string s, name;
54 
55  buf = buf_create();
56  glob = search_begin("gfx/menu/*/skinvalues.txt", true, true);
57  if(glob < 0)
58  {
59  me.skinlist = buf;
60  me.nItems = 0;
61  return;
62  }
63 
64  n = search_getsize(glob);
65  for(i = 0; i < n; ++i)
66  {
67  s = search_getfilename(glob, i);
68  name = substring(s, 9, strlen(s) - 24); // the * part
69  bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_NAME, name);
70  bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_TITLE, _("<TITLE>"));
71  bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_AUTHOR, _("<AUTHOR>"));
72  if(draw_PictureSize(strcat("/gfx/menu/", substring(s, 9, strlen(s) - 24), "/skinpreview")) == '0 0 0')
73  bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_PREVIEW, "nopreview_menuskin");
74  else
75  bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_PREVIEW, strcat("/gfx/menu/", substring(s, 9, strlen(s) - 24), "/skinpreview"));
76  fh = fopen(s, FILE_READ);
77  if(fh < 0)
78  {
79  LOG_INFO("Warning: can't open skinvalues.txt file");
80  continue;
81  }
82  while((s = fgets(fh)))
83  {
84  // these two are handled by skinlist.qc
85  if(substring(s, 0, 6) == "title ")
86  {
87  if (name == cvar_defstring("menu_skin"))
88  bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_TITLE, strcat(substring(s, 6, strlen(s) - 6), " (", _("Default"), ")"));
89  else
90  bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_TITLE, substring(s, 6, strlen(s) - 6));
91  }
92  else if(substring(s, 0, 7) == "author ")
93  bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_AUTHOR, substring(s, 7, strlen(s) - 7));
94  }
95  fclose(fh);
96  }
97 
98  search_end(glob);
99 
100  me.skinlist = buf;
101  me.nItems = n;
102 }
103 
105 {
106  buf_del(me.skinlist);
107 }
108 
109 void XonoticSkinList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
110 {
111  me.itemAbsSize = '0 0 0';
112  SUPER(XonoticSkinList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
113 
114  me.itemAbsSize.y = absSize.y * me.itemHeight;
115  me.itemAbsSize.x = absSize.x * (1 - me.controlWidth);
116  me.realFontSize.y = me.fontSize / me.itemAbsSize.y;
117  me.realFontSize.x = me.fontSize / me.itemAbsSize.x;
118  me.realUpperMargin1 = 0.5 * (1 - 2.5 * me.realFontSize.y);
119  me.realUpperMargin2 = me.realUpperMargin1 + 1.5 * me.realFontSize.y;
120 
121  me.columnPreviewOrigin = 0;
122  me.columnPreviewSize = me.itemAbsSize.y / me.itemAbsSize.x * 4 / 3;
123  me.columnNameOrigin = me.columnPreviewOrigin + me.columnPreviewSize + me.realFontSize.x;
124  me.columnNameSize = 1 - me.columnPreviewSize - 2 * me.realFontSize.x;
125 }
126 
127 void XonoticSkinList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
128 {
129  string s;
130 
131  if(isSelected)
132  draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
133  else if(isFocused)
134  {
135  me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
136  draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
137  }
138 
139  s = me.skinParameter(me, i, SKINPARM_PREVIEW);
140  draw_Picture(me.columnPreviewOrigin * eX, s, me.columnPreviewSize * eX + eY, '1 1 1', 1);
141 
142  s = me.skinParameter(me, i, SKINPARM_TITLE);
143  s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize);
144  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);
145 
146  s = me.skinParameter(me, i, SKINPARM_AUTHOR);
147  s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize);
148  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);
149 }
150 
152 {
153  me.saveCvars(me);
154  localcmd("\nmenu_restart\nmenu_cmd skinselect\n");
155 }
156 
158 {
159  me.setSkin(me);
160 }
161 
163 {
165  me.setSkin(me);
166 }
167 
168 float XonoticSkinList_keyDown(entity me, float scan, float ascii, float shift)
169 {
170  if(scan == K_ENTER || scan == K_KP_ENTER)
171  {
173  me.setSkin(me);
174  return 1;
175  }
176  else
177  return SUPER(XonoticSkinList).keyDown(me, scan, ascii, shift);
178 }
const vector eY
Definition: vector.qh:45
#define NEW(cname,...)
Definition: oo.qh:105
float XonoticSkinList_keyDown(entity me, float scan, float ascii, float shift)
Definition: skinlist.qc:168
entity() spawn
const float FILE_READ
Definition: csprogsdefs.qc:231
void XonoticSkinList_destroy(entity me)
Definition: skinlist.qc:104
void XonoticSkinList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
Definition: skinlist.qc:127
float K_KP_ENTER
Definition: keycodes.qc:74
#define SUPER(cname)
Definition: oo.qh:219
#define buf_create
Definition: dpextensions.qh:63
void SetSkin_Click(entity btn, entity me)
Definition: skinlist.qc:157
const float SKINPARM_TITLE
Definition: skinlist.qc:4
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 SKINPARM_COUNT
Definition: skinlist.qc:7
void XonoticSkinList_setSkin(entity me)
Definition: skinlist.qc:151
void XonoticSkinList_getSkins(entity me)
Definition: skinlist.qc:50
#define LOG_INFO(...)
Definition: log.qh:70
void XonoticSkinList_configureXonoticSkinList(entity me)
Definition: skinlist.qc:17
void XonoticSkinList_doubleClickListBoxItem(entity me, float i, vector where)
Definition: skinlist.qc:162
void XonoticSkinList_loadCvars(entity me)
Definition: skinlist.qc:24
vector(float skel, float bonenum) _skel_get_boneabs_hidden
string XonoticSkinList_skinParameter(entity me, float i, float key)
Definition: skinlist.qc:45
entity makeXonoticSkinList()
Definition: skinlist.qc:9
void XonoticSkinList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
Definition: skinlist.qc:109
const float SKINPARM_PREVIEW
Definition: skinlist.qc:6
const vector eX
Definition: vector.qh:44
void XonoticSkinList_saveCvars(entity me)
Definition: skinlist.qc:40
float K_ENTER
Definition: keycodes.qc:8
const float SKINPARM_NAME
Definition: skinlist.qc:3
const float SKINPARM_AUTHOR
Definition: skinlist.qc:5