]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/demolist.c
Fix stupid spacing in demolist.c
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / demolist.c
1 #ifdef INTERFACE
2 CLASS(XonoticDemoList) EXTENDS(XonoticListBox)
3         METHOD(XonoticDemoList, configureXonoticDemoList, void(entity))
4         ATTRIB(XonoticDemoList, rowsPerItem, float, 1)
5         METHOD(XonoticDemoList, resizeNotify, void(entity, vector, vector, vector, vector))
6         METHOD(XonoticDemoList, drawListBoxItem, void(entity, float, vector, float))
7         METHOD(XonoticDemoList, getDemos, void(entity))
8         METHOD(XonoticDemoList, startDemo, void(entity))        
9         METHOD(XonoticDemoList, demoName, string(entity, float))
10         METHOD(XonoticDemoList, clickListBoxItem, void(entity, float, vector))
11         METHOD(XonoticDemoList, keyDown, float(entity, float, float, float))
12         METHOD(XonoticDemoList, destroy, void(entity))
13         METHOD(XonoticDemoList, showNotify, void(entity))
14         ATTRIB(XonoticDemoList, listDemo, float, -1)
15         ATTRIB(XonoticDemoList, realFontSize, vector, '0 0 0')
16         ATTRIB(XonoticDemoList, columnNameOrigin, float, 0)
17         ATTRIB(XonoticDemoList, columnNameSize, float, 0)
18         ATTRIB(XonoticDemoList, realUpperMargin, float, 0)
19         ATTRIB(XonoticDemoList, origin, vector, '0 0 0')
20         ATTRIB(XonoticDemoList, itemAbsSize, vector, '0 0 0')
21         ATTRIB(XonoticDemoList, lastClickedDemo, float, -1)
22         ATTRIB(XonoticDemoList, lastClickedTime, float, 0)
23         ATTRIB(XonoticDemoList, filterString, string, string_null)      
24 ENDCLASS(XonoticDemoList)
25
26 entity makeXonoticDemoList();
27 void StartDemo_Click(entity btn, entity me);
28 void TimeDemo_Click(entity btn, entity me);
29 void DemoList_Filter_Change(entity box, entity me);
30 #endif
31
32 #ifdef IMPLEMENTATION
33
34 entity makeXonoticDemoList()
35 {
36         entity me;
37         me = spawnXonoticDemoList();
38         me.configureXonoticDemoList(me);
39         return me;
40 }
41
42 void XonoticDemoList_configureXonoticDemoList(entity me)
43 {
44         me.configureXonoticListBox(me);
45         me.getDemos(me);        
46 }
47
48 string XonoticDemoList_demoName(entity me, float i )
49 {
50         string s;
51         s = search_getfilename(me.listDemo, i);
52         s = substring(s, 6, strlen(s) - 6 - 4);  // demos/, .dem
53         return s;
54 }
55
56
57 void XonoticDemoList_getDemos(entity me)
58 {
59         string s;
60         
61         if(me.filterString)
62                 //subdirectory in filterString allowed  
63                 s=strcat("demos/*", me.filterString, "*.dem");          
64         else
65                 s="demos/*.dem";
66         
67         //dprint("Search demos with the pattern ", s, "\n");    
68         if(me.listDemo >= 0)
69                 search_end(me.listDemo);
70                 
71         me.listDemo = search_begin(s, FALSE, TRUE);
72
73         if(me.listDemo < 0)
74                 me.nItems=0;
75         else
76                 me.nItems=search_getsize(me.listDemo);                          
77 }
78
79 void XonoticDemoList_destroy(entity me)
80 {
81         search_end(me.listDemo);
82 }
83
84 void XonoticDemoList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
85 {
86         me.itemAbsSize = '0 0 0';
87         SUPER(XonoticDemoList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
88
89         me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize_y * me.itemHeight));
90         me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize_x * (1 - me.controlWidth)));
91         me.realUpperMargin = 0.5 * (1 - me.realFontSize_y);
92
93         me.columnNameOrigin = me.realFontSize_x;
94         me.columnNameSize = 1 - 2 * me.realFontSize_x;
95 }
96
97 void XonoticDemoList_drawListBoxItem(entity me, float i, vector absSize, float isSelected)
98 {
99         string s;
100         if(isSelected)
101                 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
102                 
103         s = me.demoName(me,i);
104         s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize);
105         draw_Text(me.realUpperMargin * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);           
106 }
107
108 void XonoticDemoList_showNotify(entity me)
109 {
110         me.getDemos(me);
111 }
112
113 void DemoList_Filter_Change(entity box, entity me)
114 {       
115         if(me.filterString)
116                 strunzone(me.filterString);
117         
118         if(box.text != "")
119                 me.filterString = strzone(box.text);
120         else
121                 me.filterString = string_null;
122                 
123         me.getDemos(me);
124 }
125
126 void XonoticDemoList_startDemo(entity me)
127 {
128         string s;
129         s = me.demoName(me,me.selectedItem);
130         localcmd("playdemo demos/", s, ".dem\nwait\ntogglemenu\n");     
131 }
132
133 void StartDemo_Click(entity btn, entity me)
134 {
135         me.startDemo(me);
136 }
137
138 void TimeDemo_Click(entity btn, entity me)
139 {
140         string s;
141         s = me.demoName(me,me.selectedItem);
142         localcmd("timedemo demos/", s, ".dem\nwait\ntogglemenu\n");     
143 }
144
145 void XonoticDemoList_clickListBoxItem(entity me, float i, vector where)
146 {
147         if(i == me.lastClickedDemo)
148                 if(time < me.lastClickedTime + 0.3)
149                 {
150                         // DOUBLE CLICK!
151                         me.setSelected(me, i);
152                         me.startDemo(me);
153                 }
154         me.lastClickedDemo = i;
155         me.lastClickedTime = time;
156 }
157
158 float XonoticDemoList_keyDown(entity me, float scan, float ascii, float shift)
159 {
160         if(scan == K_ENTER || scan == K_KP_ENTER) {
161                 me.startDemo(me);
162                 return 1;
163         }
164         else
165                 return SUPER(XonoticDemoList).keyDown(me, scan, ascii, shift);
166 }
167 #endif
168