]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/soundlist.qc
Sort menu classes
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / soundlist.qc
1 #ifndef SOUNDLIST_H
2 #define SOUNDLIST_H
3 CLASS(XonoticSoundList, XonoticListBox)
4         METHOD(XonoticSoundList, configureXonoticSoundList, void(entity))
5         ATTRIB(XonoticSoundList, rowsPerItem, float, 1)
6         METHOD(XonoticSoundList, resizeNotify, void(entity, vector, vector, vector, vector))
7         METHOD(XonoticSoundList, drawListBoxItem, void(entity, float, vector, float))
8         METHOD(XonoticSoundList, getSounds, void(entity))
9         METHOD(XonoticSoundList, soundName, string(entity, float))
10         METHOD(XonoticSoundList, doubleClickListBoxItem, void(entity, float, vector))
11         METHOD(XonoticSoundList, keyDown, float(entity, float, float, float))
12         METHOD(XonoticSoundList, destroy, void(entity))
13         METHOD(XonoticSoundList, showNotify, void(entity))
14
15         ATTRIB(XonoticSoundList, listSound, float, -1)
16         ATTRIB(XonoticSoundList, realFontSize, vector, '0 0 0')
17         ATTRIB(XonoticSoundList, columnNameOrigin, float, 0)
18         ATTRIB(XonoticSoundList, columnNameSize, float, 0)
19         ATTRIB(XonoticSoundList, columnNumberOrigin, float, 0)
20         ATTRIB(XonoticSoundList, columnNumberSize, float, 0)
21         ATTRIB(XonoticSoundList, realUpperMargin, float, 0)
22         ATTRIB(XonoticSoundList, origin, vector, '0 0 0')
23         ATTRIB(XonoticSoundList, itemAbsSize, vector, '0 0 0')
24
25         ATTRIB(XonoticSoundList, filterString, string, string_null)
26         ATTRIB(XonoticSoundList, playlist, entity, world)
27 ENDCLASS(XonoticSoundList)
28
29 entity makeXonoticSoundList();
30 void SoundList_Filter_Change(entity box, entity me);
31 void SoundList_Add(entity box, entity me);
32 void SoundList_Add_All(entity box, entity me);
33 void SoundList_Menu_Track_Change(entity box, entity me);
34 void SoundList_Menu_Track_Reset(entity box, entity me);
35 #endif
36
37 #ifdef IMPLEMENTATION
38
39 entity makeXonoticSoundList()
40 {
41         entity me;
42         me = NEW(XonoticSoundList);
43         me.configureXonoticSoundList(me);
44         return me;
45 }
46
47 void XonoticSoundList_configureXonoticSoundList(entity me)
48 {
49         me.configureXonoticListBox(me);
50         me.getSounds(me);
51 }
52
53 string XonoticSoundList_soundName(entity me, float i )
54 {
55         string s;
56         s = search_getfilename(me.listSound, i);
57         s = substring(s, 15, strlen(s) - 15 - 4);  // sound/cdtracks/, .ogg
58         return s;
59 }
60
61
62 void XonoticSoundList_getSounds(entity me)
63 {
64         string s;
65
66         if(me.filterString)
67                 //subdirectory in filterString allowed
68                 s = strcat("sound/cdtracks/*", me.filterString, "*.ogg");
69         else
70                 s = "sound/cdtracks/*.ogg";
71
72         if(me.listSound >= 0)
73                 search_end(me.listSound);
74
75         me.listSound = search_begin(s, false, true);
76
77         if(me.listSound < 0)
78                 me.nItems=0;
79         else
80                 me.nItems=search_getsize(me.listSound);
81 }
82
83 void XonoticSoundList_destroy(entity me)
84 {
85         if(me.listSound >= 0)
86                 search_end(me.listSound);
87 }
88
89 void XonoticSoundList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
90 {
91         me.itemAbsSize = '0 0 0';
92         SUPER(XonoticSoundList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
93
94         me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize.y * me.itemHeight));
95         me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize.x * (1 - me.controlWidth)));
96         me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
97
98         me.columnNumberOrigin = 0;
99         me.columnNumberSize = me.realFontSize.x * 3;
100
101         me.columnNameOrigin = me.columnNumberSize;
102         me.columnNameSize = 1 - me.columnNameOrigin - me.realFontSize.x;
103 }
104
105 void XonoticSoundList_drawListBoxItem(entity me, float i, vector absSize, float isSelected)
106 {
107         string s;
108         if(isSelected)
109                 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
110
111         s = me.soundName(me,i);
112         if(s == cvar_string("menu_cdtrack")) // current menu track
113                 draw_CenterText((me.columnNumberOrigin + 0.5 * me.columnNumberSize) * eX + me.realUpperMargin * eY, "[C]", me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
114         else if(s == cvar_defstring("menu_cdtrack")) // default menu track
115                 draw_CenterText((me.columnNumberOrigin + 0.5 * me.columnNumberSize) * eX + me.realUpperMargin * eY, "[D]", me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
116
117         s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize);
118         draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
119 }
120
121 void XonoticSoundList_showNotify(entity me)
122 {
123         me.getSounds(me);
124 }
125
126 void SoundList_Menu_Track_Change(entity box, entity me)
127 {
128         cvar_set("menu_cdtrack", me.soundName(me,me.selectedItem));
129 }
130
131 void SoundList_Menu_Track_Reset(entity box, entity me)
132 {
133         cvar_set("menu_cdtrack", cvar_defstring("menu_cdtrack"));
134 }
135
136 void SoundList_Filter_Change(entity box, entity me)
137 {
138         if(me.filterString)
139                 strunzone(me.filterString);
140
141         if(box.text != "")
142                 me.filterString = strzone(box.text);
143         else
144                 me.filterString = string_null;
145
146         me.getSounds(me);
147 }
148
149 void SoundList_Add(entity box, entity me)
150 {
151         me.playlist.addToPlayList(me.playlist, me.soundName(me, me.selectedItem));
152 }
153
154 void SoundList_Add_All(entity box, entity me)
155 {
156         float i;
157         for(i = 0; i < me.nItems; ++i)
158                 me.playlist.addToPlayList(me.playlist, me.soundName(me, i));
159 }
160
161 void XonoticSoundList_doubleClickListBoxItem(entity me, float i, vector where)
162 {
163         me.playlist.addToPlayList(me.playlist, me.soundName(me, i));
164 }
165
166 float XonoticSoundList_keyDown(entity me, float scan, float ascii, float shift)
167 {
168         if(scan == K_ENTER || scan == K_KP_ENTER || scan == K_SPACE) {
169                 me.playlist.addToPlayList(me.playlist, me.soundName(me, me.selectedItem));
170                 return 1;
171         }
172         else
173                 return SUPER(XonoticSoundList).keyDown(me, scan, ascii, shift);
174 }
175 #endif
176