1 #include "soundlist.qh"
5 CLASS(XonoticSoundList, XonoticListBox)
6 METHOD(XonoticSoundList, configureXonoticSoundList, void(entity));
7 ATTRIB(XonoticSoundList, rowsPerItem, float, 1)
8 METHOD(XonoticSoundList, resizeNotify, void(entity, vector, vector, vector, vector));
9 METHOD(XonoticSoundList, drawListBoxItem, void(entity, int, vector, bool, bool));
10 METHOD(XonoticSoundList, getSounds, void(entity));
11 METHOD(XonoticSoundList, soundName, string(entity, int));
12 METHOD(XonoticSoundList, doubleClickListBoxItem, void(entity, int, vector));
13 METHOD(XonoticSoundList, keyDown, float(entity, float, float, float));
14 METHOD(XonoticSoundList, destroy, void(entity));
15 METHOD(XonoticSoundList, showNotify, void(entity));
17 ATTRIB(XonoticSoundList, listSound, int, -1)
18 ATTRIB(XonoticSoundList, realFontSize, vector, '0 0 0')
19 ATTRIB(XonoticSoundList, columnNameOrigin, float, 0)
20 ATTRIB(XonoticSoundList, columnNameSize, float, 0)
21 ATTRIB(XonoticSoundList, columnNumberOrigin, float, 0)
22 ATTRIB(XonoticSoundList, columnNumberSize, float, 0)
23 ATTRIB(XonoticSoundList, realUpperMargin, float, 0)
24 ATTRIB(XonoticSoundList, origin, vector, '0 0 0')
25 ATTRIB(XonoticSoundList, itemAbsSize, vector, '0 0 0')
27 ATTRIB(XonoticSoundList, filterString, string, string_null)
28 ATTRIB(XonoticSoundList, playlist, entity, NULL)
29 ENDCLASS(XonoticSoundList)
31 entity makeXonoticSoundList();
32 void SoundList_Filter_Change(entity box, entity me);
33 void SoundList_Add(entity box, entity me);
34 void SoundList_Add_All(entity box, entity me);
35 void SoundList_Menu_Track_Change(entity box, entity me);
36 void SoundList_Menu_Track_Reset(entity box, entity me);
41 entity makeXonoticSoundList()
44 me = NEW(XonoticSoundList);
45 me.configureXonoticSoundList(me);
49 void XonoticSoundList_configureXonoticSoundList(entity me)
51 me.configureXonoticListBox(me);
55 string XonoticSoundList_soundName(entity me, int i)
58 s = search_getfilename(me.listSound, i);
59 s = substring(s, 15, strlen(s) - 15 - 4); // sound/cdtracks/, .ogg
64 void XonoticSoundList_getSounds(entity me)
69 //subdirectory in filterString allowed
70 s = strcat("sound/cdtracks/*", me.filterString, "*.ogg");
72 s = "sound/cdtracks/*.ogg";
75 search_end(me.listSound);
77 me.listSound = search_begin(s, false, true);
79 me.nItems = (me.listSound < 0) ? 0 : search_getsize(me.listSound);
82 void XonoticSoundList_destroy(entity me)
85 search_end(me.listSound);
88 void XonoticSoundList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
90 me.itemAbsSize = '0 0 0';
91 SUPER(XonoticSoundList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
93 me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize.y * me.itemHeight));
94 me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize.x * (1 - me.controlWidth)));
95 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
97 me.columnNumberOrigin = 0;
98 me.columnNumberSize = me.realFontSize.x * 3;
100 me.columnNameOrigin = me.columnNumberSize;
101 me.columnNameSize = 1 - me.columnNameOrigin - me.realFontSize.x;
104 void XonoticSoundList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
108 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
111 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
112 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
115 s = me.soundName(me, i);
116 if(s == cvar_string("menu_cdtrack")) // current menu track
117 draw_CenterText((me.columnNumberOrigin + 0.5 * me.columnNumberSize) * eX + me.realUpperMargin * eY, "[C]", me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
118 else if(s == cvar_defstring("menu_cdtrack")) // default menu track
119 draw_CenterText((me.columnNumberOrigin + 0.5 * me.columnNumberSize) * eX + me.realUpperMargin * eY, "[D]", me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
121 s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize);
122 draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
125 void XonoticSoundList_showNotify(entity me)
130 void SoundList_Menu_Track_Change(entity box, entity me)
132 cvar_set("menu_cdtrack", me.soundName(me, me.selectedItem));
135 void SoundList_Menu_Track_Reset(entity box, entity me)
137 cvar_set("menu_cdtrack", cvar_defstring("menu_cdtrack"));
140 void SoundList_Filter_Change(entity box, entity me)
143 strunzone(me.filterString);
146 me.filterString = strzone(box.text);
148 me.filterString = string_null;
153 void SoundList_Add(entity box, entity me)
155 me.playlist.addToPlayList(me.playlist, me.soundName(me, me.selectedItem));
158 void SoundList_Add_All(entity box, entity me)
161 for(i = 0; i < me.nItems; ++i)
162 me.playlist.addToPlayList(me.playlist, me.soundName(me, i));
165 void XonoticSoundList_doubleClickListBoxItem(entity me, int i, vector where)
167 me.playlist.addToPlayList(me.playlist, me.soundName(me, i));
170 float XonoticSoundList_keyDown(entity me, float scan, float ascii, float shift)
172 if(scan == K_ENTER || scan == K_KP_ENTER || scan == K_SPACE) {
173 me.playlist.addToPlayList(me.playlist, me.soundName(me, me.selectedItem));
177 return SUPER(XonoticSoundList).keyDown(me, scan, ascii, shift);