Xonotic
playlist.qc File Reference
#include "playlist.qh"
+ Include dependency graph for playlist.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

entity makeXonoticPlayList ()
 
void NextSound_Click (entity btn, entity me)
 
void PauseSound_Click (entity btn, entity me)
 
void PlayList_Remove (entity btn, entity me)
 
void PlayList_Remove_All (entity btn, entity me)
 
void PrevSound_Click (entity btn, entity me)
 
void StartSound_Click (entity btn, entity me)
 
void StopSound_Click (entity btn, entity me)
 
void XonoticPlayList_addToPlayList (entity me, string track)
 
void XonoticPlayList_configureXonoticPlayList (entity me)
 
void XonoticPlayList_doubleClickListBoxItem (entity me, float i, vector where)
 
void XonoticPlayList_draw (entity me)
 
void XonoticPlayList_drawListBoxItem (entity me, int i, vector absSize, bool isSelected, bool isFocused)
 
float XonoticPlayList_keyDown (entity me, float scan, float ascii, float shift)
 
float XonoticPlayList_mouseDrag (entity me, vector pos)
 
void XonoticPlayList_pauseSound (entity me)
 
void XonoticPlayList_removeSelectedFromPlayList (entity me)
 
void XonoticPlayList_resizeNotify (entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
 
void XonoticPlayList_resumeSound (entity me)
 
void XonoticPlayList_startSound (entity me, float offset)
 
void XonoticPlayList_stopSound (entity me)
 

Function Documentation

◆ makeXonoticPlayList()

entity makeXonoticPlayList ( )

Definition at line 3 of file playlist.qc.

References entity(), and NEW.

4 {
5  entity me;
6  me = NEW(XonoticPlayList);
7  me.configureXonoticPlayList(me);
8  return me;
9 }
#define NEW(cname,...)
Definition: oo.qh:105
entity() spawn
+ Here is the call graph for this function:

◆ NextSound_Click()

void NextSound_Click ( entity  btn,
entity  me 
)

Definition at line 222 of file playlist.qc.

223 {
224  me.startSound(me, +1);
225 }

◆ PauseSound_Click()

void PauseSound_Click ( entity  btn,
entity  me 
)

Definition at line 243 of file playlist.qc.

244 {
245  me.pauseSound(me);
246 }

◆ PlayList_Remove()

void PlayList_Remove ( entity  btn,
entity  me 
)

Definition at line 92 of file playlist.qc.

93 {
94  me.removeSelectedFromPlayList(me);
95 }

◆ PlayList_Remove_All()

void PlayList_Remove_All ( entity  btn,
entity  me 
)

Definition at line 97 of file playlist.qc.

References cvar_set().

98 {
99  cvar_set("music_playlist_list0", "");
100  me.stopSound(me);
101  me.selectedItem = 0;
102 }
+ Here is the call graph for this function:

◆ PrevSound_Click()

void PrevSound_Click ( entity  btn,
entity  me 
)

Definition at line 217 of file playlist.qc.

218 {
219  me.startSound(me, -1);
220 }

◆ StartSound_Click()

void StartSound_Click ( entity  btn,
entity  me 
)

Definition at line 212 of file playlist.qc.

213 {
214  me.startSound(me, 0);
215 }

◆ StopSound_Click()

void StopSound_Click ( entity  btn,
entity  me 
)

Definition at line 174 of file playlist.qc.

175 {
176  me.stopSound(me);
177 }

◆ XonoticPlayList_addToPlayList()

void XonoticPlayList_addToPlayList ( entity  me,
string  track 
)

Definition at line 35 of file playlist.qc.

References argv(), cvar_set(), cvar_string(), strcat(), and tokenize_console.

36 {
37  me.nItems = tokenize_console(cvar_string("music_playlist_list0"));
38  if(me.nItems == 0)
39  {
40  cvar_set("music_playlist_list0", track);
41  return;
42  }
43  float i;
44  for(i = 0; i < me.nItems; ++i)
45  {
46  if(argv(i) == track)
47  return; // track is already in playlist
48  }
49  cvar_set("music_playlist_list0", strcat(cvar_string("music_playlist_list0"), " ", track));
50 }
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
#define tokenize_console
Definition: dpextensions.qh:24
+ Here is the call graph for this function:

◆ XonoticPlayList_configureXonoticPlayList()

void XonoticPlayList_configureXonoticPlayList ( entity  me)

Definition at line 11 of file playlist.qc.

References cvar_string(), and tokenize_console.

12 {
13  me.nItems = tokenize_console(cvar_string("music_playlist_list0"));
14  me.configureXonoticListBox(me);
15 }
#define tokenize_console
Definition: dpextensions.qh:24
+ Here is the call graph for this function:

◆ XonoticPlayList_doubleClickListBoxItem()

void XonoticPlayList_doubleClickListBoxItem ( entity  me,
float  i,
vector  where 
)

Definition at line 248 of file playlist.qc.

249 {
250  me.startSound(me, 0);
251 }

◆ XonoticPlayList_draw()

void XonoticPlayList_draw ( entity  me)

Definition at line 126 of file playlist.qc.

References cvar(), cvar_string(), SUPER, and tokenize_console.

127 {
128  me.nItems = tokenize_console(cvar_string("music_playlist_list0"));
129  if(cvar("music_playlist_index") == 0 || cvar("music_playlist_index") == 999)
130  me.playingTrack = cvar("music_playlist_current0");
131  else
132  me.playingTrack = -1;
133  SUPER(XonoticPlayList).draw(me);
134 }
#define SUPER(cname)
Definition: oo.qh:219
#define tokenize_console
Definition: dpextensions.qh:24
+ Here is the call graph for this function:

◆ XonoticPlayList_drawListBoxItem()

void XonoticPlayList_drawListBoxItem ( entity  me,
int  i,
vector  absSize,
bool  isSelected,
bool  isFocused 
)

Definition at line 136 of file playlist.qc.

References argv(), cvar(), draw_CenterText(), draw_Fill(), draw_Text(), draw_TextShortenToWidth(), eX, eY, ftos(), getFadedAlpha(), and time.

137 {
138  string s;
139  if(isSelected)
140  draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
141  else if(isFocused)
142  {
143  me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
144  draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
145  }
146 
147  if(i == me.playingTrack)
148  {
149  float f = cvar("music_playlist_sampleposition0");
150  // display Play symbol: Unicode char U+25B6: Black Right-Pointing Triangle
151  if(f <= 0 || (((time * 2) & 1) && f > 0))
152  draw_Text(me.realUpperMargin * eY + (me.columnNumberOrigin + me.columnNumberSize) * eX, "\xE2\x96\xB6", me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
153  }
154 
155  s = ftos(i+1);
156  draw_CenterText(me.realUpperMargin * eY + (me.columnNumberOrigin + 0.5 * me.columnNumberSize) * eX, s, me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
157 
158  s = draw_TextShortenToWidth(argv(i), me.columnNameSize, 0, me.realFontSize);
159  draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
160 }
const vector eY
Definition: vector.qh:45
const vector eX
Definition: vector.qh:44
float time
Definition: csprogsdefs.qc:16
+ Here is the call graph for this function:

◆ XonoticPlayList_keyDown()

float XonoticPlayList_keyDown ( entity  me,
float  scan,
float  ascii,
float  shift 
)

Definition at line 253 of file playlist.qc.

References K_BACKSPACE, K_DEL, K_ENTER, K_KP_DEL, K_KP_ENTER, K_MOUSE3, K_SPACE, and SUPER.

254 {
255  if(scan == K_ENTER || scan == K_KP_ENTER) {
256  me.startSound(me, 0);
257  return 1;
258  }
259  else if(scan == K_SPACE) {
260  me.pauseSound(me);
261  return 1;
262  }
263  else if(scan == K_DEL || scan == K_KP_DEL || scan == K_BACKSPACE || scan == K_MOUSE3) {
264  me.removeSelectedFromPlayList(me);
265  return 1;
266  }
267  else
268  return SUPER(XonoticPlayList).keyDown(me, scan, ascii, shift);
269 }
float K_DEL
Definition: keycodes.qc:38
float K_MOUSE3
Definition: keycodes.qc:131
float K_SPACE
Definition: keycodes.qc:10
float K_KP_ENTER
Definition: keycodes.qc:74
#define SUPER(cname)
Definition: oo.qh:219
float K_BACKSPACE
Definition: keycodes.qc:14
float K_ENTER
Definition: keycodes.qc:8
float K_KP_DEL
Definition: keycodes.qc:68

◆ XonoticPlayList_mouseDrag()

float XonoticPlayList_mouseDrag ( entity  me,
vector  pos 
)

Definition at line 104 of file playlist.qc.

References cvar(), cvar_set(), cvar_string(), ftos(), SUPER, and swapInPriorityList().

105 {
106  float f, i;
107  i = me.selectedItem;
108  f = SUPER(XonoticPlayList).mouseDrag(me, pos);
109 
110  if(me.pressed != 1) // don't change priority if the person is just scrolling
111  {
112  if(me.selectedItem != i)
113  {
114  cvar_set("music_playlist_list0", swapInPriorityList(cvar_string("music_playlist_list0"), me.selectedItem, i));
115  float c = cvar("music_playlist_current0");
116  if(c == i)
117  cvar_set("music_playlist_current0", ftos(me.selectedItem));
118  else if(c == me.selectedItem)
119  cvar_set("music_playlist_current0", ftos(i));
120  }
121  }
122 
123  return f;
124 }
#define SUPER(cname)
Definition: oo.qh:219
string swapInPriorityList(string order, float i, float j)
Definition: util.qc:540
+ Here is the call graph for this function:

◆ XonoticPlayList_pauseSound()

void XonoticPlayList_pauseSound ( entity  me)

Definition at line 234 of file playlist.qc.

References cvar(), and localcmd.

235 {
236  // PAUSE: list 0 is disabled by setting the index to 999
237  // (we know the track is paused because the engine sets sampleposition0 to remember current position)
238  if(cvar("music_playlist_index") == 0)
239  localcmd("\nmusic_playlist_index 999\n");
240  else me.resumeSound(me);
241 }
+ Here is the call graph for this function:

◆ XonoticPlayList_removeSelectedFromPlayList()

void XonoticPlayList_removeSelectedFromPlayList ( entity  me)

Definition at line 52 of file playlist.qc.

References argv(), cvar(), cvar_set(), cvar_string(), ftos(), strcat(), strlen(), substring(), and tokenize_console.

53 {
54  float i, cpt = false;
55  string s = "";
56  me.nItems = tokenize_console(cvar_string("music_playlist_list0"));
57  if(me.nItems == 0)
58  return;
59  for(i = 0; i < me.nItems; ++i)
60  {
61  if(i == me.selectedItem)
62  {
63  if(i == me.nItems - 1)
64  me.setSelected(me, me.selectedItem - 1);
65  if(cvar("music_playlist_index") == 0 || cvar("music_playlist_index") == 999)
66  {
67  if(cvar("music_playlist_current0") == i)
68  cpt = true; // current playing track (we can't start next track here because startSound calls tokenize_console)
69  else if(cvar("music_playlist_current0") > i)
70  cvar_set("music_playlist_current0", ftos(cvar("music_playlist_current0") - 1));
71  }
72  continue;
73  }
74  s = strcat(s, " ", argv(i));
75  }
76  // we must stop the current playing track if it has been removed
77  // otherwise pause/play button will resume from another track
78  if(s == "")
79  {
80  cvar_set("music_playlist_list0", "");
81  if(cpt)
82  me.stopSound(me);
83  }
84  else
85  {
86  cvar_set("music_playlist_list0", substring(s, 1, strlen(s))); // remove initial space
87  if(cpt)
88  me.startSound(me, 0);
89  }
90 }
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
#define tokenize_console
Definition: dpextensions.qh:24
+ Here is the call graph for this function:

◆ XonoticPlayList_resizeNotify()

void XonoticPlayList_resizeNotify ( entity  me,
vector  relOrigin,
vector  relSize,
vector  absOrigin,
vector  absSize 
)

Definition at line 17 of file playlist.qc.

References SUPER.

18 {
19  me.itemAbsSize = '0 0 0';
20  SUPER(XonoticPlayList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
21 
22  me.itemAbsSize.y = absSize.y * me.itemHeight;
23  me.itemAbsSize.x = absSize.x * (1 - me.controlWidth);
24  me.realFontSize.y = me.fontSize / me.itemAbsSize.y;
25  me.realFontSize.x = me.fontSize / me.itemAbsSize.x;
26  me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
27 
28  me.columnNumberOrigin = 0;
29  me.columnNumberSize = 3 * me.realFontSize.x;
30 
31  me.columnNameOrigin = me.columnNumberSize + me.realFontSize.x;
32  me.columnNameSize = 1 - me.columnNameOrigin - me.realFontSize.x;
33 }
#define SUPER(cname)
Definition: oo.qh:219

◆ XonoticPlayList_resumeSound()

void XonoticPlayList_resumeSound ( entity  me)

Definition at line 227 of file playlist.qc.

References cvar(), and localcmd.

228 {
229  // RESUME: list 0 is enabled by setting the index to 0
230  // (we reset sampleposition0 to 0 to mark the track as in playing back state)
231  if(cvar("music_playlist_index") == 999)
232  localcmd("\nmusic_playlist_index 0; wait; music_playlist_sampleposition0 0\n");
233 }
+ Here is the call graph for this function:

◆ XonoticPlayList_startSound()

void XonoticPlayList_startSound ( entity  me,
float  offset 
)

Definition at line 179 of file playlist.qc.

References bound(), cvar(), cvar_set(), cvar_string(), ftos(), localcmd, and tokenize_console.

180 {
181  float f;
182  me.nItems = tokenize_console(cvar_string("music_playlist_list0"));
183  if(offset)
184  {
185  if(cvar("music_playlist_index") == -1)
186  return;
187  f = bound(0, cvar("music_playlist_current0") + offset, me.nItems - 1);
188  if(f == cvar("music_playlist_current0"))
189  return;
190  }
191  else
192  {
193  f = me.selectedItem;
194  // if it was paused then resume
195  if(f == cvar("music_playlist_current0"))
196  if(cvar("music_playlist_index") == 999)
197  {
198  me.resumeSound(me);
199  return;
200  }
201  // if it was not paused then proceed with restart
202  }
203 
204  // START: list 0 is disabled by setting the index to 999
205  // we set current0 to the selected track and sampleposition0 to 0 to forget the position that the engine saves in this frame (for this reason we need to wait a frame)
206  // then we switch back to list 0
207  cvar_set("music_playlist_index", "999");
208  cvar_set("music_playlist_current0", ftos(f));
209  localcmd("\nwait; music_playlist_sampleposition0 0; wait; music_playlist_index 0\n");
210 }
#define tokenize_console
Definition: dpextensions.qh:24
+ Here is the call graph for this function:

◆ XonoticPlayList_stopSound()

void XonoticPlayList_stopSound ( entity  me)

Definition at line 162 of file playlist.qc.

References cvar(), cvar_set(), and localcmd.

163 {
164  // STOP: list 0 is disabled by setting the index to -1
165  // we set sampleposition0 to 0 to forget the position that the engine saves in this frame (for this reason we need to wait a frame)
166  if(cvar("music_playlist_index") == 0 || cvar("music_playlist_index") == 999)
167  {
168  cvar_set("music_playlist_index", "-1");
169  localcmd("\nwait; music_playlist_sampleposition0 0\n");
170  localcmd("\ndefer 3 \"cd play $menu_cdtrack\"\n");
171  }
172 }
+ Here is the call graph for this function: