Xonotic
playerlist.qc
Go to the documentation of this file.
1 #include "playerlist.qh"
2 
4 
5 const int PLAYERPARM_SCORE = 0;
6 const int PLAYERPARM_PING = 1;
7 const int PLAYERPARM_TEAM = 2;
8 const int PLAYERPARM_NAME = 3;
9 const int PLAYERPARM_COUNT = 4;
10 
12 {
13  entity me;
14  me = NEW(XonoticPlayerList);
15  me.configureXonoticListBox(me);
16  return me;
17 }
18 
20 {
21  int buf,i,n;
22  string s;
23 
24  buf = buf_create();
25  me.nItems = tokenizebyseparator(plist, "\n");
26  for(i = 0; i < me.nItems; ++i)
27  {
28  bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_NAME, argv(i)); // -666 100 "^4Nex ^2Player"
29  }
30 
31  for(i = 0; i < me.nItems; ++i)
32  {
33  s = bufstr_get(buf, i * PLAYERPARM_COUNT + PLAYERPARM_NAME);
34  n = tokenize_console(s);
35 
36  if(n == PLAYERPARM_COUNT)
37  {
38  bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_SCORE, argv(0)); // -666
39  bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_PING, argv(1)); // 100
40  bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_TEAM, argv(2)); // 0 for spec, else 1, 2, 3, 4
41  bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_NAME, argv(3)); // ^4Nex ^2Player
42  }
43  else
44  {
45  bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_SCORE, argv(0)); // -666
46  bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_PING, argv(1)); // 100
47  bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_TEAM, "-1");
48  bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_NAME, argv(2)); // ^4Nex ^2Player
49  }
50  }
51  me.playerList = buf;
52 }
53 
54 string XonoticPlayerList_getPlayerList(entity me, float i, float key)
55 {
56  return bufstr_get(me.playerList, i * PLAYERPARM_COUNT + key);
57 }
58 
59 void XonoticPlayerList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
60 {
61  me.itemAbsSize = '0 0 0';
62  SUPER(XonoticPlayerList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
63 
64  me.itemAbsSize.y = absSize.y * me.itemHeight;
65  me.itemAbsSize.x = absSize.x * (1 - me.controlWidth);
66  me.realFontSize.y = me.fontSize / me.itemAbsSize.y;
67  me.realFontSize.x = me.fontSize / me.itemAbsSize.x;
68  me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
69 
70  // this list does 1 char left and right margin
71  me.columnScoreSize = 5 * me.realFontSize.x;
72  me.columnNameSize = 1 - 3 * me.realFontSize.x - me.columnScoreSize;
73 
74  me.columnNameOrigin = me.realFontSize.x;
75  me.columnScoreOrigin = me.columnNameOrigin + me.columnNameSize + me.realFontSize.x;
76 }
77 
78 void XonoticPlayerList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
79 {
80  string s;
81  string score;
82  float t;
83  vector rgb;
84 
85  t = stof(me.getPlayerList(me, i, PLAYERPARM_TEAM));
86  if(t == 1)
87  rgb = colormapPaletteColor(4, 0);
88  else if(t == 2)
89  rgb = colormapPaletteColor(13, 0);
90  else if(t == 3)
91  rgb = colormapPaletteColor(12, 0);
92  else if(t == 4)
93  rgb = colormapPaletteColor(9, 0);
94  else
95  rgb = SKINCOLOR_TEXT;
96 
97  s = me.getPlayerList(me, i, PLAYERPARM_NAME);
98  score = me.getPlayerList(me, i, PLAYERPARM_SCORE);
99 
100  if(substring(score, strlen(score) - 10, 10) == ":spectator")
101  {
102  score = _("spectator");
103  }
104  else
105  {
106  if((t = strstrofs(score, ":", 0)) >= 0)
107  score = substring(score, 0, t);
108  if((t = strstrofs(score, ",", 0)) >= 0)
109  score = substring(score, 0, t);
110 
111  if(stof(score) == FRAGS_SPECTATOR)
112  score = _("spectator");
113  }
114 
115  s = draw_TextShortenToWidth(s, me.columnNameSize, 1, me.realFontSize);
116  draw_Text(me.realUpperMargin2 * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 1, me.realFontSize))) * eX, s, me.realFontSize, '1 1 1', 1, 1);
117 
118  score = draw_TextShortenToWidth(score, me.columnScoreSize, 0, me.realFontSize);
119  draw_Text(me.realUpperMargin2 * eY + (me.columnScoreOrigin + 1.00 * (me.columnScoreSize - draw_TextWidth(score, 1, me.realFontSize))) * eX, score, me.realFontSize, rgb, 1, 0);
120 }
const vector eY
Definition: vector.qh:45
#define NEW(cname,...)
Definition: oo.qh:105
string XonoticPlayerList_getPlayerList(entity me, float i, float key)
Definition: playerlist.qc:54
entity() spawn
entity makeXonoticPlayerList()
Definition: playerlist.qc:11
const int PLAYERPARM_PING
Definition: playerlist.qc:6
const int PLAYERPARM_NAME
Definition: playerlist.qc:8
#define SUPER(cname)
Definition: oo.qh:219
#define buf_create
Definition: dpextensions.qh:63
void XonoticPlayerList_setPlayerList(entity me, string plist)
Definition: playerlist.qc:19
#define strstrofs
Definition: dpextensions.qh:42
const int PLAYERPARM_COUNT
Definition: playerlist.qc:9
float realUpperMargin2
Definition: playerlist.qc:3
const int PLAYERPARM_SCORE
Definition: playerlist.qc:5
vector(float skel, float bonenum) _skel_get_boneabs_hidden
#define tokenize_console
Definition: dpextensions.qh:24
const vector eX
Definition: vector.qh:44
const int PLAYERPARM_TEAM
Definition: playerlist.qc:7
const int FRAGS_SPECTATOR
Definition: constants.qh:4
#define tokenizebyseparator
Definition: dpextensions.qh:21
void XonoticPlayerList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
Definition: playerlist.qc:59
void XonoticPlayerList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
Definition: playerlist.qc:78
#define colormapPaletteColor(c, isPants)
Definition: color.qh:5