Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
playerlist.qc
Go to the documentation of this file.
1#include "playerlist.qh"
2
4
5const int PLAYERPARM_SCORE = 0;
6const int PLAYERPARM_PING = 1;
7const int PLAYERPARM_TEAM = 2;
8const int PLAYERPARM_NAME = 3;
9const int PLAYERPARM_COUNT = 4;
10
12{
13 entity me;
15 me.configureXonoticListBox(me);
16 return me;
17}
18
20{
21 int i;
22 int buf = buf_create();
23
24 me.nItems = tokenizebyseparator(plist, "\n");
25 for(i = 0; i < me.nItems; ++i)
26 {
27 bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_NAME, argv(i)); // -666 100 "^4Xon ^2Player"
28 }
29
30 for(i = 0; i < me.nItems; ++i)
31 {
32 string name = bufstr_get(buf, i * PLAYERPARM_COUNT + PLAYERPARM_NAME);
33 int n = tokenize_console(name);
34
35 bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_SCORE, argv(0)); // -666
36 bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_PING, argv(1)); // 100
37 if(n == PLAYERPARM_COUNT)
38 {
39 bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_TEAM, argv(2)); // 0 for spec, else 1, 2, 3, 4
40 bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_NAME, argv(3)); // ^4Xon ^2Player
41 }
42 else
43 {
44 bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_TEAM, "-1");
45 bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_NAME, argv(2)); // ^4Xon ^2Player
46 }
47 }
48 me.playerList = buf;
49}
50
51string XonoticPlayerList_getPlayerList(entity me, float i, float key)
52{
53 return bufstr_get(me.playerList, i * PLAYERPARM_COUNT + key);
54}
55
56void XonoticPlayerList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
57{
58 me.itemAbsSize = '0 0 0';
59 SUPER(XonoticPlayerList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
60
61 me.itemAbsSize.y = absSize.y * me.itemHeight;
62 me.itemAbsSize.x = absSize.x * (1 - me.controlWidth);
63 me.realFontSize.y = me.fontSize / me.itemAbsSize.y;
64 me.realFontSize.x = me.fontSize / me.itemAbsSize.x;
65 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
66
67 // this list does 1 char left and right margin
68 me.columnScoreSize = 5 * me.realFontSize.x;
69 me.columnNameSize = 1 - 3 * me.realFontSize.x - me.columnScoreSize;
70
71 me.columnScoreOrigin = me.realFontSize.x;
72 me.columnNameOrigin = me.columnScoreOrigin + me.columnScoreSize + me.realFontSize.x;
73}
74
75void XonoticPlayerList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
76{
77 float t = stof(me.getPlayerList(me, i, PLAYERPARM_TEAM));
78
79 vector rgb = SKINCOLOR_TEXT;
80 if(t == 1)
81 rgb = colormapPaletteColor(4, 0);
82 else if(t == 2)
83 rgb = colormapPaletteColor(13, 0);
84 else if(t == 3)
85 rgb = colormapPaletteColor(12, 0);
86 else if(t == 4)
87 rgb = colormapPaletteColor(9, 0);
88
89 string name = me.getPlayerList(me, i, PLAYERPARM_NAME);
90 string score = me.getPlayerList(me, i, PLAYERPARM_SCORE);
91 string ping = me.getPlayerList(me, i, PLAYERPARM_PING);
92
93 bool is_bot = (ping == "0");
94 bool is_spectator = false;
95 if(substring(score, strlen(score) - 10, 10) == ":spectator")
96 {
97 is_spectator = true;
98 }
99 else
100 {
101 if((t = strstrofs(score, ":", 0)) >= 0)
102 score = substring(score, 0, t);
103 if((t = strstrofs(score, ",", 0)) >= 0)
104 score = substring(score, 0, t);
105
106 if(stof(score) == FRAGS_SPECTATOR)
107 is_spectator = true;
108 }
109
110 if(is_bot)
111 name = cons("^9(bot)^7", name);
112
113 if (is_spectator)
114 {
115 score = _("spectator");
116 rgb = '0.3 0.3 0.3';
117 }
118
119 name = draw_TextShortenToWidth(name, me.columnNameSize, 1, me.realFontSize);
120 draw_Text(me.realUpperMargin2 * eY + me.columnNameOrigin * eX, name, me.realFontSize, '1 1 1', 1, 1);
121
122 score = draw_TextShortenToWidth(score, me.columnScoreSize, 0, me.realFontSize);
123 float score_ofs = me.columnScoreSize - draw_TextWidth(score, 1, me.realFontSize);
124 draw_Text(me.realUpperMargin2 * eY + (me.columnScoreOrigin + score_ofs) * eX, score, me.realFontSize, rgb, 1, 0);
125}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
float ping
Definition main.qh:169
#define colormapPaletteColor(c, isPants)
Definition color.qh:5
const int FRAGS_SPECTATOR
Definition constants.qh:4
#define strstrofs
#define strlen
#define tokenize_console
#define tokenizebyseparator
#define buf_create
string draw_TextShortenToWidth(string theText, float maxWidth, float ICanHasKallerz, vector SizeThxBye)
Definition draw.qc:377
void draw_Text(vector theOrigin, string theText, vector theSize, vector theColor, float theAlpha, float ICanHasKallerz)
Definition draw.qc:282
float draw_TextWidth(string theText, float ICanHasKallerz, vector SizeThxBye)
Definition draw.qc:304
string name
Definition menu.qh:30
float stof(string val,...)
string substring(string s, float start, float length)
string argv(float n)
#define NEW(cname,...)
Definition oo.qh:117
#define SUPER(cname)
Definition oo.qh:231
const int PLAYERPARM_NAME
Definition playerlist.qc:8
const int PLAYERPARM_PING
Definition playerlist.qc:6
string XonoticPlayerList_getPlayerList(entity me, float i, float key)
Definition playerlist.qc:51
float realUpperMargin2
Definition playerlist.qc:3
const int PLAYERPARM_TEAM
Definition playerlist.qc:7
entity makeXonoticPlayerList()
Definition playerlist.qc:11
const int PLAYERPARM_SCORE
Definition playerlist.qc:5
const int PLAYERPARM_COUNT
Definition playerlist.qc:9
void XonoticPlayerList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
Definition playerlist.qc:75
void XonoticPlayerList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
Definition playerlist.qc:56
void XonoticPlayerList_setPlayerList(entity me, string plist)
Definition playerlist.qc:19
vector
Definition self.qh:92
ERASEABLE string cons(string a, string b)
Definition string.qh:276
const vector eY
Definition vector.qh:45
const vector eX
Definition vector.qh:44