]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/credits.qc
Merge branch 'master' into Mario/minigames_merge
[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         ATTRIB(XonoticCreditsList, selectionDoesntMatter, bool, true)
13
14         ATTRIB(XonoticCreditsList, realFontSize, vector, '0 0 0')
15         ATTRIB(XonoticCreditsList, realUpperMargin, float, 0)
16         ATTRIB(XonoticCreditsList, bufferIndex, float, 0)
17         ATTRIB(XonoticCreditsList, scrolling, float, 0)
18
19         ATTRIB(XonoticCreditsList, alphaBG, float, 0)
20 ENDCLASS(XonoticCreditsList)
21 entity makeXonoticCreditsList();
22 #endif
23
24 #ifdef IMPLEMENTATION
25 entity makeXonoticCreditsList()
26 {
27         entity me;
28         me = NEW(XonoticCreditsList);
29         me.configureXonoticCreditsList(me);
30         return me;
31 }
32 void XonoticCreditsList_configureXonoticCreditsList(entity me)
33 {
34         me.configureXonoticListBox(me);
35         // load the file
36         me.bufferIndex = buf_load(language_filename("xonotic-credits.txt"));
37         me.nItems = buf_getsize(me.bufferIndex);
38 }
39 void XonoticCreditsList_destroy(entity me)
40 {
41         buf_del(me.bufferIndex);
42 }
43 void XonoticCreditsList_draw(entity me)
44 {
45         if(me.scrolling)
46         {
47                 me.scrollPos = bound(0, (time - me.scrolling) * me.itemHeight, me.nItems * me.itemHeight - 1);
48                 me.scrollPosTarget = me.scrollPos;
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, int i, vector absSize, bool isSelected, bool isFocused)
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         me.scrolling = 0;
93         return SUPER(XonoticCreditsList).keyDown(me, key, ascii, shift);
94 }
95 #endif