]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/playerlist.c
Merge remote branch 'origin/terencehill/powerups_respawntime_fix'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / playerlist.c
1 #ifdef INTERFACE
2 CLASS(XonoticPlayerList) EXTENDS(XonoticListBox)
3         ATTRIB(XonoticPlayerList, rowsPerItem, float, 1)
4         METHOD(XonoticPlayerList, resizeNotify, void(entity, vector, vector, vector, vector))
5         METHOD(XonoticPlayerList, drawListBoxItem, void(entity, float, vector, float))
6         ATTRIB(XonoticPlayerList, realFontSize, vector, '0 0 0')
7         ATTRIB(XonoticPlayerList, columnNameOrigin, float, 0)
8         ATTRIB(XonoticPlayerList, columnNameSize, float, 0)
9         ATTRIB(XonoticPlayerList, columnScoreOrigin, float, 0)
10         ATTRIB(XonoticPlayerList, columnScoreSize, float, 0)
11         ATTRIB(XonoticPlayerList, realUpperMargin, float, 0)
12         ATTRIB(XonoticPlayerList, origin, vector, '0 0 0')
13         ATTRIB(XonoticPlayerList, itemAbsSize, vector, '0 0 0')
14         METHOD(XonoticPlayerList, setPlayerList, void(entity, string))
15         METHOD(XonoticPlayerList, getPlayerList, string(entity, float, float))
16         ATTRIB(XonoticPlayerList, playerList, float, -1)
17 ENDCLASS(XonoticPlayerList)
18 entity makeXonoticPlayerList();
19 #endif
20
21 #ifdef IMPLEMENTATION
22
23 #define PLAYERPARM_SCORE 0
24 #define PLAYERPARM_PING 1
25 #define PLAYERPARM_TEAM 2
26 #define PLAYERPARM_NAME 3
27 #define PLAYERPARM_COUNT 4
28
29 entity makeXonoticPlayerList()
30 {
31         entity me;
32         me = spawnXonoticPlayerList();
33         me.configureXonoticListBox(me);
34         return me;
35 }
36
37 void XonoticPlayerList_setPlayerList(entity me, string plist)
38 {
39         float buf,i,n;
40         string s;
41
42         buf = buf_create();
43         me.nItems = tokenizebyseparator(plist, "\n");
44         for(i = 0; i < me.nItems; ++i)
45         {
46                 bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_NAME, argv(i)); // -666 100 "^4Nex ^2Player"
47         }
48
49         for(i = 0; i < me.nItems; ++i)
50         {
51                 s = bufstr_get(buf, i * PLAYERPARM_COUNT + PLAYERPARM_NAME);
52                 n = tokenize_console(s);
53
54                 if(n == 4)
55                 {
56                         bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_SCORE, argv(0)); // -666
57                         bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_PING,  argv(1)); // 100
58                         bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_TEAM,  argv(2)); // 0 for spec, else 1, 2, 3, 4
59                         bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_NAME,  argv(3)); // ^4Nex ^2Player
60                 }
61                 else
62                 {
63                         bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_SCORE, argv(0)); // -666
64                         bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_PING,  argv(1)); // 100
65                         bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_TEAM,  "-1");
66                         bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_NAME,  argv(2)); // ^4Nex ^2Player
67                 }
68         }
69         me.playerList = buf;
70 }
71
72 string XonoticPlayerList_getPlayerList(entity me, float i, float key)
73 {
74         return bufstr_get(me.playerList, i * PLAYERPARM_COUNT + key);
75 }
76
77 void XonoticPlayerList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
78 {
79         me.itemAbsSize = '0 0 0';
80         SUPER(XonoticPlayerList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
81
82         me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize_y * me.itemHeight));
83         me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize_x * (1 - me.controlWidth)));
84         me.realUpperMargin = 0.5 * (1 - me.realFontSize_y);
85
86         // this list does 1 char left and right margin
87         me.columnScoreSize = 5 * me.realFontSize_x;
88         me.columnNameSize = 1 - 3 * me.realFontSize_x - me.columnScoreSize;
89
90         me.columnNameOrigin = me.realFontSize_x;
91         me.columnScoreOrigin = me.columnNameOrigin + me.columnNameSize + me.realFontSize_x;
92 }
93
94 void XonoticPlayerList_drawListBoxItem(entity me, float i, vector absSize, float isSelected)
95 {
96         string s;
97         string score;
98         float t;
99         vector rgb;
100
101         t = stof(me.getPlayerList(me, i, PLAYERPARM_TEAM));
102         if(t == 1)
103                 rgb = colormapPaletteColor(4, 0);
104         else if(t == 2)
105                 rgb = colormapPaletteColor(13, 0);
106         else if(t == 3)
107                 rgb = colormapPaletteColor(12, 0);
108         else if(t == 4)
109                 rgb = colormapPaletteColor(9, 0);
110         else
111                 rgb = '1 1 1';
112         
113         s = me.getPlayerList(me, i, PLAYERPARM_NAME);
114         score = me.getPlayerList(me, i, PLAYERPARM_SCORE);
115
116         if(substring(score, strlen(score) - 10, 10) == ":spectator")
117         {
118                 score = _("spectator");
119         }
120         else
121         {
122                 if((t = strstrofs(score, ":", 0)) >= 0)
123                         score = substring(score, 0, t);
124                 if((t = strstrofs(score, ",", 0)) >= 0)
125                         score = substring(score, 0, t);
126                         
127                 if(stof(score) == -666)
128                         score = _("spectator");
129         }
130
131         s = draw_TextShortenToWidth(s, me.columnNameSize, 1, me.realFontSize);
132         score = draw_TextShortenToWidth(score, me.columnScoreSize, 0, me.realFontSize);
133
134         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);
135         draw_Text(me.realUpperMargin2 * eY + (me.columnScoreOrigin + 1.00 * (me.columnScoreSize - draw_TextWidth(score, 1, me.realFontSize))) * eX, score, me.realFontSize, rgb, 1, 0);
136 }
137
138 #endif