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