]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/textbox.qc
Revert "Fixed timer in unlimited warmup"
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / textbox.qc
1 #include "textbox.qh"
2 #include "../item/label.qh"
3
4 entity makeXonoticTextBox()
5 {
6         entity me;
7         me = NEW(XonoticTextBox);
8         me.configureXonoticListBox(me);
9         return me;
10 }
11
12 void XonoticTextBox_destroy(entity me)
13 {
14         if (me.stringList >= 0)
15         {
16                 buf_del(me.stringList);
17                 me.stringList = -1;
18         }
19 }
20
21 void XonoticTextBox_setText(entity me, string text)
22 {
23         if (me.stringList >= 0)
24         {
25                 buf_del(me.stringList);
26                 me.stringList = -1;
27         }
28
29         int buf;
30         int line = 0;
31
32         string t;
33
34         buf = buf_create();
35         for (int i = 0, n = tokenizebyseparator(text, "\n"); i < n; ++i)
36         {
37                 t = substring(argv(i), 0, -1);
38                 getWrappedLine_remaining = t;
39                 while (getWrappedLine_remaining)
40                 {
41                         t = getWrappedLine(1, me.realFontSize, draw_TextWidth_WithColors);
42                         bufstr_set(buf, line, t);
43                         line++;
44                 }
45         }
46
47         me.stringList = buf;
48         me.nItems = line+1;
49 }
50
51 string XonoticTextBox_getTextBoxLine(entity me, int i)
52 {
53         if (me.stringList >= 0)
54         {
55                 return bufstr_get(me.stringList, i);
56         }
57         return string_null;
58 }
59
60 // mostly copied from playerlist
61 // FIXME: is this really needed
62 void XonoticTextBox_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
63 {
64         me.itemAbsSize = '0 0 0';
65         SUPER(XonoticTextBox).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
66
67         me.itemAbsSize.y = absSize.y * me.itemHeight;
68         me.itemAbsSize.x = absSize.x * (1 - me.controlWidth);
69         me.realFontSize.y = me.fontSize / me.itemAbsSize.y;
70         me.realFontSize.x = me.fontSize / me.itemAbsSize.x;
71         string temp = string_null;
72         for (int i = 0; i < me.nItems; ++i)
73         {
74                 if (!temp)
75                 {
76                         temp = me.getTextBoxLine(me, i);
77                 }
78                 else
79                 {
80                         temp = strcat(temp, "\n", me.getTextBoxLine(me, i));
81                 }
82         }
83         me.setText(me, temp);
84 }
85
86 void XonoticTextBox_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
87 {
88         string s = me.getTextBoxLine(me, i);
89         draw_Text(vec2(0, 0), s, me.realFontSize, me.colorL, me.alpha, true);
90 }