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