]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu-div0test/nexuiz/credits.c
fix some window titles
[divverent/nexuiz.git] / data / qcsrc / menu-div0test / nexuiz / credits.c
1 #ifdef INTERFACE
2 CLASS(NexuizCreditsList) EXTENDS(NexuizListBox)
3         METHOD(NexuizCreditsList, configureNexuizCreditsList, void(entity))
4         ATTRIB(NexuizCreditsList, rowsPerItem, float, 1)
5         METHOD(NexuizCreditsList, draw, void(entity))
6         METHOD(NexuizCreditsList, drawListBoxItem, void(entity, float, vector, float))
7         METHOD(NexuizCreditsList, resizeNotify, void(entity, vector, vector, vector, vector))
8         METHOD(NexuizCreditsList, keyDown, float(entity, float, float, float))
9
10         ATTRIB(NexuizCreditsList, realFontSize, vector, '0 0 0')
11         ATTRIB(NexuizCreditsList, realUpperMargin, float, 0)
12         ATTRIB(NexuizCreditsList, bufferIndex, float, 0)
13         ATTRIB(NexuizCreditsList, scrolling, float, 0)
14 ENDCLASS(NexuizCreditsList)
15 entity makeNexuizCreditsList();
16 #endif
17
18 #ifdef IMPLEMENTATION
19 float SLIST_FIELD_CNAME;
20 float SLIST_FIELD_PING;
21 float SLIST_FIELD_GAME;
22 float SLIST_FIELD_MOD;
23 float SLIST_FIELD_MAP;
24 float SLIST_FIELD_NAME;
25 float SLIST_FIELD_MAXPLAYERS;
26 float SLIST_FIELD_NUMPLAYERS;
27 float SLIST_FIELD_NUMHUMANS;
28 float SLIST_FIELD_NUMBOTS;
29 float SLIST_FIELD_PROTOCOL;
30 float SLIST_FIELD_FREESLOTS;
31 void CreditsList_UpdateFieldIDs()
32 {
33         SLIST_FIELD_CNAME = gethostcacheindexforkey( "cname" );
34         SLIST_FIELD_PING = gethostcacheindexforkey( "ping" );
35         SLIST_FIELD_GAME = gethostcacheindexforkey( "game" );
36         SLIST_FIELD_MOD = gethostcacheindexforkey( "mod" );
37         SLIST_FIELD_MAP = gethostcacheindexforkey( "map" );
38         SLIST_FIELD_NAME = gethostcacheindexforkey( "name" );
39         SLIST_FIELD_MAXPLAYERS = gethostcacheindexforkey( "maxplayers" );
40         SLIST_FIELD_NUMPLAYERS = gethostcacheindexforkey( "numplayers" );
41         SLIST_FIELD_NUMHUMANS = gethostcacheindexforkey( "numhumans" );
42         SLIST_FIELD_NUMBOTS = gethostcacheindexforkey( "numbots" );
43         SLIST_FIELD_PROTOCOL = gethostcacheindexforkey( "protocol" );
44         SLIST_FIELD_FREESLOTS = gethostcacheindexforkey( "freeslots" );
45 }
46
47 entity makeNexuizCreditsList()
48 {
49         entity me;
50         me = spawnNexuizCreditsList();
51         me.configureNexuizCreditsList(me);
52         return me;
53 }
54 void configureNexuizCreditsListNexuizCreditsList(entity me)
55 {
56         me.configureNexuizListBox(me);
57         // load the file
58         me.bufferIndex = buf_load("nexuiz-credits.txt");
59         me.nItems = buf_getsize(me.bufferIndex);
60 }
61 void drawNexuizCreditsList(entity me)
62 {
63         float i;
64         if(me.scrolling && time > me.scrolling)
65         {
66                 me.scrollPos = min(me.scrollPos + frametime * me.itemHeight, me.nItems * me.itemHeight - 1);
67                 i = min(me.selectedItem, floor((me.scrollPos + 1) / me.itemHeight - 1));
68                 i = max(i, ceil(me.scrollPos / me.itemHeight));
69                 me.setSelected(me, i);
70         }
71         drawListBox(me);
72 }
73 void resizeNotifyNexuizCreditsList(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
74 {
75         resizeNotifyNexuizListBox(me, relOrigin, relSize, absOrigin, absSize);
76
77         me.realFontSize_y = me.fontSize / (absSize_y * me.itemHeight);
78         me.realFontSize_x = me.fontSize / (absSize_x * (1 - me.controlWidth));
79         me.realUpperMargin = 0.5 * (1 - me.realFontSize_y);
80 }
81 void drawListBoxItemNexuizCreditsList(entity me, float i, vector absSize, float isSelected)
82 {
83         // layout: Ping, Credits name, Map name, NP, TP, MP
84         string s;
85         float theAlpha;
86         vector theColor;
87
88         s = bufstr_get(me.bufferIndex, i);
89
90         if(substring(s, 0, 2) == "**")
91         {
92                 s = substring(s, 2, strlen(s) - 2);
93                 theColor = SKINCOLOR_CREDITS_TITLE;
94                 theAlpha = SKINALPHA_CREDITS_TITLE;
95         }
96         else if(substring(s, 0, 1) == "*")
97         {
98                 s = substring(s, 1, strlen(s) - 1);
99                 theColor = SKINCOLOR_CREDITS_FUNCTION;
100                 theAlpha = SKINALPHA_CREDITS_FUNCTION;
101         }
102         else
103         {
104                 theColor = SKINCOLOR_CREDITS_PERSON;
105                 theAlpha = SKINALPHA_CREDITS_PERSON;
106         }
107
108         draw_CenterText(me.realUpperMargin * eY + 0.5 * eX, s, me.realFontSize, theColor, theAlpha, 0);
109 }
110
111 float keyDownNexuizCreditsList(entity me, float scan, float ascii, float shift)
112 {
113         float i;
114         me.dragScrollTimer = 0;
115         me.scrolling = 0;
116
117         if(scan == K_PGUP)
118                 me.scrollPos = max(me.scrollPos - 0.5, 0);
119         else if(scan == K_PGDN)
120                 me.scrollPos = min(me.scrollPos + 0.5, me.nItems * me.itemHeight - 1);
121         else if(scan == K_UPARROW)
122                 me.scrollPos = max(me.scrollPos - me.itemHeight, 0);
123         else if(scan == K_DOWNARROW)
124                 me.scrollPos = min(me.scrollPos + me.itemHeight, me.nItems * me.itemHeight - 1);
125         else
126                 return keyDownListBox(me, scan, ascii, shift);
127
128         i = min(me.selectedItem, floor((me.scrollPos + 1) / me.itemHeight - 1));
129         i = max(i, ceil(me.scrollPos / me.itemHeight));
130         me.setSelected(me, i);
131
132         return 1;
133 }
134 #endif