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