]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu/nexuiz/playerlist.c
Ronans server info dialog
[divverent/nexuiz.git] / data / qcsrc / menu / nexuiz / playerlist.c
1 #ifdef INTERFACE
2 CLASS(NexuizPlayerList) EXTENDS(NexuizListBox)
3         ATTRIB(NexuizPlayerList, rowsPerItem, float, 1)
4         METHOD(NexuizPlayerList, resizeNotify, void(entity, vector, vector, vector, vector))
5         METHOD(NexuizPlayerList, drawListBoxItem, void(entity, float, vector, float))
6         ATTRIB(NexuizPlayerList, realFontSize, vector, '0 0 0')
7         ATTRIB(NexuizPlayerList, columnNameOrigin, float, 0)
8         ATTRIB(NexuizPlayerList, columnNameSize, float, 0)
9         ATTRIB(NexuizPlayerList, realUpperMargin, float, 0)
10         ATTRIB(NexuizPlayerList, origin, vector, '0 0 0')
11         ATTRIB(NexuizPlayerList, itemAbsSize, vector, '0 0 0')
12         METHOD(NexuizPlayerList, setPlayerList, void(entity, string))
13         METHOD(NexuizPlayerList, getPlayerList, string(entity, float, float))
14         ATTRIB(NexuizPlayerList, playerList, float, -1)
15 ENDCLASS(NexuizPlayerList)
16 entity makeNexuizPlayerList();
17 #endif
18
19 #ifdef IMPLEMENTATION
20
21 #define PLAYERPARM_SCORE 0
22 #define PLAYERPARM_PING 1
23 #define PLAYERPARM_NAME 2
24 #define PLAYERPARM_COUNT 3
25
26 entity makeNexuizPlayerList()
27 {
28         entity me;
29         me = spawnNexuizPlayerList();
30         me.configureNexuizListBox(me);
31         return me;
32 }
33
34 void setPlayerListNexuizPlayerList(entity me, string plist)
35 {
36         dprint(plist,"------------\n");
37
38         float buf,i;
39         string s;
40
41         buf = buf_create();
42         me.nItems = tokenizebyseparator(plist, "\n");
43         for(i = 0; i < me.nItems; ++i)
44         {
45                 bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_NAME, argv(i)); // -666 100 "^4Nex ^2Player"
46         }
47
48         for(i = 0; i < me.nItems; ++i)
49         {
50                 s = bufstr_get(buf, i * PLAYERPARM_COUNT + PLAYERPARM_NAME);
51                 tokenize_sane(s);
52                 bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_SCORE, argv(0)); // -666
53                 bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_PING,  argv(1)); // 100
54                 bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_NAME,  argv(2)); // ^4Nex ^2Player
55         }
56         me.playerList = buf;
57 }
58
59 string getPlayerListNexuizPlayerList(entity me, float i, float key)
60 {
61         return bufstr_get(me.playerList, i * PLAYERPARM_COUNT + key);
62 }
63
64 void resizeNotifyNexuizPlayerList(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
65 {
66         me.origin = absOrigin;
67         me.itemAbsSize = '0 0 0';
68         resizeNotifyNexuizListBox(me, relOrigin, relSize, absOrigin, absSize);
69
70         me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize_y * me.itemHeight));
71         me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize_x * (1 - me.controlWidth)));
72         me.realUpperMargin = 0.5 * (1 - me.realFontSize_y);
73
74         me.columnNameOrigin = me.realFontSize_x;
75         me.columnNameSize = 1 - 2 * me.realFontSize_x;
76 }
77
78 void drawListBoxItemNexuizPlayerList(entity me, float i, vector absSize, float isSelected)
79 {
80         string s, ch, ch2;
81         float maxTextLen, textLen;
82         float j;
83         vector theOrigin, theSize, theColor;
84         float theAlpha;
85         float brightness;
86
87
88         s = me.getPlayerList(me, i, PLAYERPARM_NAME);
89         maxTextLen = strlen(draw_TextShortenToWidth(strdecolorize(s), 0.95 * me.columnNameSize / me.realFontSize_x, 0));
90         brightness = cvar("r_textbrightness");
91         theOrigin = me.realUpperMargin * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0) * me.realFontSize_x)) * eX ;
92         theSize = me.realFontSize;
93         theColor = '1 1 1';
94         theAlpha = 1;
95
96         for(j = 0; j < strlen(s); ++j)
97         {
98                 ch = substring(s, j, 1);
99                 if(ch == "^")
100                 {
101                         ch2 = substring(s, j+1, 1);
102                         if(ch2 == "0" || stof(ch2))// digit?
103                         {
104                                 switch(stof(ch2))
105                                 {
106                                         case 0: theColor = '0 0 0'; theAlpha = 1; break;
107                                         case 1: theColor = '1 0 0'; theAlpha = 1; break;
108                                         case 2: theColor = '0 1 0'; theAlpha = 1; break;
109                                         case 3: theColor = '1 1 0'; theAlpha = 1; break;
110                                         case 4: theColor = '0 0 1'; theAlpha = 1; break;
111                                         case 5: theColor = '0 1 1'; theAlpha = 1; break;
112                                         case 6: theColor = '1 0 1'; theAlpha = 1; break;
113                                         case 7: theColor = '1 1 1'; theAlpha = 1; break;
114                                         case 8: theColor = '1 1 1'; theAlpha = 0.5; break;
115                                         case 9: theColor = '0.5 0.5 0.5'; theAlpha = 1; break;
116                                 }
117                                 theColor = theColor * (1 - brightness) + brightness * '1 1 1';
118                                 ++j;
119                                 continue;
120                         }
121                 }
122
123                 if (textLen < maxTextLen)
124                 {
125                         draw_Text(theOrigin, ch, theSize, theColor, theAlpha, 0);
126                         theOrigin += eX * draw_TextWidth(ch, 0) * me.realFontSize_x;
127                         ++textLen;
128                 }
129                 else
130                 {
131                         draw_Text(theOrigin, "...", theSize, theColor, theAlpha, 0);
132                         break;
133                 }
134         }
135 }
136
137 #endif