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{
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
45string 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
109void 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
127void 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
168float 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}
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:377
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:1106
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:104
void SetSkin_Click(entity btn, entity me)
Definition skinlist.qc:157
float XonoticSkinList_keyDown(entity me, float scan, float ascii, float shift)
Definition skinlist.qc:168
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:162
entity makeXonoticSkinList()
Definition skinlist.qc:9
void XonoticSkinList_setSkin(entity me)
Definition skinlist.qc:151
void XonoticSkinList_loadCvars(entity me)
Definition skinlist.qc:24
void XonoticSkinList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
Definition skinlist.qc:127
void XonoticSkinList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
Definition skinlist.qc:109
void XonoticSkinList_configureXonoticSkinList(entity me)
Definition skinlist.qc:17
void XonoticSkinList_getSkins(entity me)
Definition skinlist.qc:50
const float SKINPARM_PREVIEW
Definition skinlist.qc:6
void XonoticSkinList_saveCvars(entity me)
Definition skinlist.qc:40
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:45
const vector eY
Definition vector.qh:45
const vector eX
Definition vector.qh:44