]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/credits.qc
0d04daf589d02df1ea920d8416f2b040464d596b
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / credits.qc
1 #ifndef CREDITS_H
2 #define CREDITS_H
3 CLASS(XonoticCreditsList, XonoticListBox)
4         METHOD(XonoticCreditsList, configureXonoticCreditsList, void(entity))
5         ATTRIB(XonoticCreditsList, rowsPerItem, float, 1)
6         METHOD(XonoticCreditsList, draw, void(entity))
7         METHOD(XonoticCreditsList, drawListBoxItem, void(entity, float, vector, float))
8         METHOD(XonoticCreditsList, resizeNotify, void(entity, vector, vector, vector, vector))
9         METHOD(XonoticCreditsList, keyDown, float(entity, float, float, float))
10         METHOD(XonoticCreditsList, destroy, void(entity))
11
12         ATTRIB(XonoticCreditsList, realFontSize, vector, '0 0 0')
13         ATTRIB(XonoticCreditsList, realUpperMargin, float, 0)
14         ATTRIB(XonoticCreditsList, bufferIndex, float, 0)
15         ATTRIB(XonoticCreditsList, scrolling, float, 0)
16
17         ATTRIB(XonoticCreditsList, alphaBG, float, 0)
18 ENDCLASS(XonoticCreditsList)
19 entity makeXonoticCreditsList();
20 #endif
21
22 #ifdef IMPLEMENTATION
23 entity makeXonoticCreditsList()
24 {
25         entity me;
26         me = NEW(XonoticCreditsList);
27         me.configureXonoticCreditsList(me);
28         return me;
29 }
30 void XonoticCreditsList_configureXonoticCreditsList(entity me)
31 {
32         me.configureXonoticListBox(me);
33         // load the file
34         me.bufferIndex = buf_load(language_filename("xonotic-credits.txt"));
35         me.nItems = buf_getsize(me.bufferIndex);
36 }
37 void XonoticCreditsList_destroy(entity me)
38 {
39         buf_del(me.bufferIndex);
40 }
41 void XonoticCreditsList_draw(entity me)
42 {
43         float i;
44         if(me.scrolling)
45         {
46                 me.scrollPos = bound(0, (time - me.scrolling) * me.itemHeight, me.nItems * me.itemHeight - 1);
47                 i = min(me.selectedItem, floor((me.scrollPos + 1) / me.itemHeight - 1));
48                 i = max(i, ceil(me.scrollPos / me.itemHeight));
49                 me.setSelected(me, i);
50         }
51         SUPER(XonoticCreditsList).draw(me);
52 }
53 void XonoticCreditsList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
54 {
55         SUPER(XonoticCreditsList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
56
57         me.realFontSize_y = me.fontSize / (absSize.y * me.itemHeight);
58         me.realFontSize_x = me.fontSize / (absSize.x * (1 - me.controlWidth));
59         me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
60 }
61 void XonoticCreditsList_drawListBoxItem(entity me, float i, vector absSize, float isSelected)
62 {
63         // layout: Ping, Credits name, Map name, NP, TP, MP
64         string s;
65         float theAlpha;
66         vector theColor;
67
68         s = bufstr_get(me.bufferIndex, i);
69
70         if(substring(s, 0, 2) == "**")
71         {
72                 s = substring(s, 2, strlen(s) - 2);
73                 theColor = SKINCOLOR_CREDITS_TITLE;
74                 theAlpha = SKINALPHA_CREDITS_TITLE;
75         }
76         else if(substring(s, 0, 1) == "*")
77         {
78                 s = substring(s, 1, strlen(s) - 1);
79                 theColor = SKINCOLOR_CREDITS_FUNCTION;
80                 theAlpha = SKINALPHA_CREDITS_FUNCTION;
81         }
82         else
83         {
84                 theColor = SKINCOLOR_CREDITS_PERSON;
85                 theAlpha = SKINALPHA_CREDITS_PERSON;
86         }
87
88         draw_CenterText(me.realUpperMargin * eY + 0.5 * eX, s, me.realFontSize, theColor, theAlpha, 0);
89 }
90
91 float XonoticCreditsList_keyDown(entity me, float key, float ascii, float shift)
92 {
93         float i;
94         me.dragScrollTimer = time;
95         me.scrolling = 0;
96         if(key == K_PGUP || key == K_KP_PGUP)
97                 me.scrollPos = max(me.scrollPos - 0.5, 0);
98         else if(key == K_PGDN || key == K_KP_PGDN)
99                 me.scrollPos = min(me.scrollPos + 0.5, me.nItems * me.itemHeight - 1);
100         else if(key == K_UPARROW || key == K_KP_UPARROW)
101                 me.scrollPos = max(me.scrollPos - me.itemHeight, 0);
102         else if(key == K_DOWNARROW || key == K_KP_DOWNARROW)
103                 me.scrollPos = min(me.scrollPos + me.itemHeight, me.nItems * me.itemHeight - 1);
104         else
105                 return SUPER(XonoticCreditsList).keyDown(me, key, ascii, shift);
106
107         i = min(me.selectedItem, floor((me.scrollPos + 1) / me.itemHeight - 1));
108         i = max(i, ceil(me.scrollPos / me.itemHeight));
109         me.setSelected(me, i);
110
111         return 1;
112 }
113 #endif