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