Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
demolist.qc
Go to the documentation of this file.
1#include "demolist.qh"
2
3#include "inputbox.qh"
4
6{
8 me.configureXonoticDemoList(me);
9 return me;
10}
11
13{
14 me.configureXonoticListBox(me);
15 me.nItems = 0;
16}
17
19{
20 string s = bufstr_get(me.listDemo, i);
21
22 if(substring(s, 0, 1) == "/")
23 s = substring(s, 1, strlen(s) - 1); // remove the first forward slash
24
25 return s;
26}
27
28// if subdir is true look in subdirectories too (1 level)
29void getDemos_for_ext(entity me, string ext, float subdir)
30{
31 string s;
32 if (subdir)
33 s="demos/*/";
34 else
35 s="demos/";
36 if(me.filterString)
37 s=strcat(s, me.filterString, ext);
38 else
39 s=strcat(s, "*", ext);
40
41 float list, i, n;
42 list = search_begin(s, false, true);
43 if(list >= 0)
44 {
45 n = search_getsize(list);
46 for(i = 0; i < n; ++i)
47 {
48 s = search_getfilename(list, i); // get initial full file name
49 s = substring(s, 6, (strlen(s) - 6 - 4)); // remove "demos/" prefix and ".dem" suffix
50 s = strdecolorize(s); // remove any pre-existing colors
51 if(subdir)
52 {
53 s = strreplace("/", "^7/", s); // clear colors at the forward slash
54 s = strcat("/", rgb_to_hexcolor(SKINCOLOR_DEMOLIST_SUBDIR), s); // add a forward slash for sorting, then color
55 bufstr_add(me.listDemo, s, true);
56 }
57 else { bufstr_add(me.listDemo, s, true); }
58 }
59 search_end(list);
60 }
61
62 if (subdir)
63 getDemos_for_ext(me, ext, false);
64}
65
67{
68 if (me.listDemo >= 0)
69 buf_del(me.listDemo);
70 me.listDemo = buf_create();
71 if (me.listDemo < 0)
72 {
73 me.nItems = 0;
74 return;
75 }
76 getDemos_for_ext(me, ".dem", true);
77 me.nItems = buf_getsize(me.listDemo);
78 if(me.nItems > 0)
79 buf_sort(me.listDemo, 128, false);
80}
81
83{
84 if(me.nItems > 0)
85 buf_del(me.listDemo);
86}
87
88void XonoticDemoList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
89{
90 me.itemAbsSize = '0 0 0';
91 SUPER(XonoticDemoList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
92
93 me.itemAbsSize.y = absSize.y * me.itemHeight;
94 me.itemAbsSize.x = absSize.x * (1 - me.controlWidth);
95 me.realFontSize.y = me.fontSize / me.itemAbsSize.y;
96 me.realFontSize.x = me.fontSize / me.itemAbsSize.x;
97 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
98
99 me.columnNameOrigin = me.realFontSize.x;
100 me.columnNameSize = 1 - 2 * me.realFontSize.x;
101}
102
103void XonoticDemoList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
104{
105 string s;
106 if(isSelected)
107 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
108 else if(isFocused)
109 {
110 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
111 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
112 }
113
114 s = me.demoName(me,i);
115 s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize);
116 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);
117}
118
120{
121 me.getDemos(me);
122}
123
125{
126 me.getDemos(me);
127 me.setSelected(me, 0); //always select the first element after a list update
128}
129
131{
132 strfree(me.filterString);
133
134 if(box.text != "")
135 {
136 if (strstrofs(box.text, "*", 0) >= 0 || strstrofs(box.text, "?", 0) >= 0)
137 me.filterString = strzone(box.text);
138 else
139 me.filterString = strzone(strcat("*", box.text, "*"));
140 }
141 else
142 me.filterString = string_null;
143
144 me.getDemos(me);
145}
146
148{
149 string s = me.demoName(me, me.selectedItem);
150 s = strdecolorize(s);
151
152 localcmd("togglemenu 0; playdemo \"demos/", s, ".dem\"\n");
153}
154
156{
157 string s = me.demoName(me, me.selectedItem);
158 s = strdecolorize(s);
159
160 localcmd("togglemenu 0; timedemo \"demos/", s, ".dem\"\n");
161}
162
164{
165 if(!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER))) // we're not in a match, lets watch the demo
166 {
167 me.startDemo(me);
168 }
169 else // already in a match, player has to confirm
170 {
172 me,
173 main.demostartconfirmDialog,
174 boxToGlobal(eY * (me.selectedItem * me.itemHeight - me.scrollPos), me.origin, me.size),
175 boxToGlobalSize(eY * me.itemHeight + eX * (1 - me.controlWidth), me.size)
176 );
177 }
178}
179
184
185float XonoticDemoList_keyDown(entity me, float scan, float ascii, float shift)
186{
187 if(scan == K_ENTER || scan == K_KP_ENTER)
188 {
190 return 1;
191 }
192 else
193 {
194 return SUPER(XonoticDemoList).keyDown(me, scan, ascii, shift);
195 }
196}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
ERASEABLE string rgb_to_hexcolor(vector rgb)
Definition color.qh:183
void XonoticDemoList_timeDemo(entity me)
Definition demolist.qc:155
entity makeXonoticDemoList()
Definition demolist.qc:5
void XonoticDemoList_destroy(entity me)
Definition demolist.qc:82
void XonoticDemoList_doubleClickListBoxItem(entity me, float i, vector where)
Definition demolist.qc:180
void DemoConfirm_ListClick_Check_Gamestatus(entity me)
Definition demolist.qc:163
void XonoticDemoList_showNotify(entity me)
Definition demolist.qc:119
string XonoticDemoList_demoName(entity me, float i)
Definition demolist.qc:18
void XonoticDemoList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
Definition demolist.qc:88
void getDemos_for_ext(entity me, string ext, float subdir)
Definition demolist.qc:29
void XonoticDemoList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
Definition demolist.qc:103
float XonoticDemoList_keyDown(entity me, float scan, float ascii, float shift)
Definition demolist.qc:185
void XonoticDemoList_startDemo(entity me)
Definition demolist.qc:147
void DemoList_Filter_Change(entity box, entity me)
Definition demolist.qc:130
void XonoticDemoList_getDemos(entity me)
Definition demolist.qc:66
void DemoList_Refresh_Click(entity btn, entity me)
Definition demolist.qc:124
void XonoticDemoList_configureXonoticDemoList(entity me)
Definition demolist.qc:12
#define strstrofs
#define strlen
#define buf_create
float K_ENTER
Definition keycodes.qc:8
float K_KP_ENTER
Definition keycodes.qc:74
#define main
Definition _all.inc:202
string draw_TextShortenToWidth(string theText, float maxWidth, float ICanHasKallerz, vector SizeThxBye)
Definition draw.qc:378
void draw_Text(vector theOrigin, string theText, vector theSize, vector theColor, float theAlpha, float ICanHasKallerz)
Definition draw.qc:282
float draw_TextWidth(string theText, float ICanHasKallerz, vector SizeThxBye)
Definition draw.qc:304
vector boxToGlobalSize(vector v, vector theScale)
Definition draw.qc:53
vector boxToGlobal(vector v, vector theOrigin, vector theScale)
Definition draw.qc:45
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
const int GAME_ISSERVER
Definition menu.qh:11
const int GAME_CONNECTED
Definition menu.qh:12
int gamestatus
Definition menu.qh:16
void localcmd(string command,...)
string substring(string s, float start, float length)
string search_getfilename(float handle, float num)
float search_getsize(float handle)
float search_begin(string pattern, float caseinsensitive, float quiet)
string strzone(string s)
void search_end(float handle)
void DialogOpenButton_Click_withCoords(entity button, entity tab, vector theOrigin, vector theSize)
string string_null
Definition nil.qh:9
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
#define strfree(this)
Definition string.qh:59
const vector eY
Definition vector.qh:45
const vector eX
Definition vector.qh:44