1 #include "playerlist.qh"
3 .float realUpperMargin2;
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;
11 entity makeXonoticPlayerList()
14 me = NEW(XonoticPlayerList);
15 me.configureXonoticListBox(me);
19 void XonoticPlayerList_setPlayerList(entity me, string plist)
22 int buf = buf_create();
24 me.nItems = tokenizebyseparator(plist, "\n");
25 for(i = 0; i < me.nItems; ++i)
27 bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_NAME, argv(i)); // -666 100 "^4Xon ^2Player"
30 for(i = 0; i < me.nItems; ++i)
32 string name = bufstr_get(buf, i * PLAYERPARM_COUNT + PLAYERPARM_NAME);
33 int n = tokenize_console(name);
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)
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
44 bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_TEAM, "-1");
45 bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_NAME, argv(2)); // ^4Xon ^2Player
51 string XonoticPlayerList_getPlayerList(entity me, float i, float key)
53 return bufstr_get(me.playerList, i * PLAYERPARM_COUNT + key);
56 void XonoticPlayerList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
58 me.itemAbsSize = '0 0 0';
59 SUPER(XonoticPlayerList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
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);
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;
71 me.columnScoreOrigin = me.realFontSize.x;
72 me.columnNameOrigin = me.columnScoreOrigin + me.columnScoreSize + me.realFontSize.x;
75 void XonoticPlayerList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
77 float t = stof(me.getPlayerList(me, i, PLAYERPARM_TEAM));
79 vector rgb = SKINCOLOR_TEXT;
81 rgb = colormapPaletteColor(4, 0);
83 rgb = colormapPaletteColor(13, 0);
85 rgb = colormapPaletteColor(12, 0);
87 rgb = colormapPaletteColor(9, 0);
89 string name = me.getPlayerList(me, i, PLAYERPARM_NAME);
90 string score = me.getPlayerList(me, i, PLAYERPARM_SCORE);
92 bool is_spectator = false;
93 if(substring(score, strlen(score) - 10, 10) == ":spectator")
99 if((t = strstrofs(score, ":", 0)) >= 0)
100 score = substring(score, 0, t);
101 if((t = strstrofs(score, ",", 0)) >= 0)
102 score = substring(score, 0, t);
104 if(stof(score) == FRAGS_SPECTATOR)
110 score = _("spectator");
114 name = draw_TextShortenToWidth(name, me.columnNameSize, 1, me.realFontSize);
115 draw_Text(me.realUpperMargin2 * eY + me.columnNameOrigin * eX, name, me.realFontSize, '1 1 1', 1, 1);
117 score = draw_TextShortenToWidth(score, me.columnScoreSize, 0, me.realFontSize);
118 float score_ofs = me.columnScoreSize - draw_TextWidth(score, 1, me.realFontSize);
119 draw_Text(me.realUpperMargin2 * eY + (me.columnScoreOrigin + score_ofs) * eX, score, me.realFontSize, rgb, 1, 0);