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))
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)
16 ATTRIB(XonoticListBox, alphaBG, float, 0)
17 ENDCLASS(XonoticCreditsList)
18 entity makeXonoticCreditsList();
22 entity makeXonoticCreditsList()
25 me = spawnXonoticCreditsList();
26 me.configureXonoticCreditsList(me);
29 void XonoticCreditsList_configureXonoticCreditsList(entity me)
31 me.configureXonoticListBox(me);
33 me.bufferIndex = buf_load(language_filename("xonotic-credits.txt"));
34 if(me.bufferIndex < 0)
35 me.bufferIndex = buf_load("xonotic-credits.txt");
36 me.nItems = buf_getsize(me.bufferIndex);
38 void XonoticCreditsList_destroy(entity me)
40 buf_del(me.bufferIndex);
42 void XonoticCreditsList_draw(entity me)
47 me.scrollPos = bound(0, (time - me.scrolling) * me.itemHeight, me.nItems * me.itemHeight - 1);
48 i = min(me.selectedItem, floor((me.scrollPos + 1) / me.itemHeight - 1));
49 i = max(i, ceil(me.scrollPos / me.itemHeight));
50 me.setSelected(me, i);
52 SUPER(XonoticCreditsList).draw(me);
54 void XonoticCreditsList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
56 SUPER(XonoticCreditsList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
58 me.realFontSize_y = me.fontSize / (absSize_y * me.itemHeight);
59 me.realFontSize_x = me.fontSize / (absSize_x * (1 - me.controlWidth));
60 me.realUpperMargin = 0.5 * (1 - me.realFontSize_y);
62 void XonoticCreditsList_drawListBoxItem(entity me, float i, vector absSize, float isSelected)
64 // layout: Ping, Credits name, Map name, NP, TP, MP
69 s = bufstr_get(me.bufferIndex, i);
71 if(substring(s, 0, 2) == "**")
73 s = substring(s, 2, strlen(s) - 2);
74 theColor = SKINCOLOR_CREDITS_TITLE;
75 theAlpha = SKINALPHA_CREDITS_TITLE;
77 else if(substring(s, 0, 1) == "*")
79 s = substring(s, 1, strlen(s) - 1);
80 theColor = SKINCOLOR_CREDITS_FUNCTION;
81 theAlpha = SKINALPHA_CREDITS_FUNCTION;
85 theColor = SKINCOLOR_CREDITS_PERSON;
86 theAlpha = SKINALPHA_CREDITS_PERSON;
89 draw_CenterText(me.realUpperMargin * eY + 0.5 * eX, s, me.realFontSize, theColor, theAlpha, 0);
92 float XonoticCreditsList_keyDown(entity me, float key, float ascii, float shift)
95 me.dragScrollTimer = time;
97 if(key == K_PGUP || key == K_KP_PGUP)
98 me.scrollPos = max(me.scrollPos - 0.5, 0);
99 else if(key == K_PGDN || key == K_KP_PGDN)
100 me.scrollPos = min(me.scrollPos + 0.5, me.nItems * me.itemHeight - 1);
101 else if(key == K_UPARROW || key == K_KP_UPARROW)
102 me.scrollPos = max(me.scrollPos - me.itemHeight, 0);
103 else if(key == K_DOWNARROW || key == K_KP_DOWNARROW)
104 me.scrollPos = min(me.scrollPos + me.itemHeight, me.nItems * me.itemHeight - 1);
106 return SUPER(XonoticCreditsList).keyDown(me, key, ascii, shift);
108 i = min(me.selectedItem, floor((me.scrollPos + 1) / me.itemHeight - 1));
109 i = max(i, ceil(me.scrollPos / me.itemHeight));
110 me.setSelected(me, i);