]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/guide/description.qh
1e8b6ea7ca808d1e437aaa8ca632911104f92bd8
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / guide / description.qh
1 #pragma once
2
3 #include <menu/xonotic/listbox.qh>
4 CLASS(XonoticGuideDescription, XonoticListBox)
5         ATTRIB(XonoticGuideDescription, rowsPerItem, float, 1);
6         ATTRIB(XonoticGuideDescription, selectionDoesntMatter, bool, true);
7
8     METHOD(XonoticGuideDescription, setDescription, void(entity, string));
9     ATTRIB(XonoticGuideDescription, description, string, string_null);
10
11         METHOD(XonoticGuideDescription, resizeNotify, void(entity this, vector relOrigin, vector relSize, vector absOrigin, vector absSize)) {
12         SUPER(XonoticGuideDescription).resizeNotify(this, relOrigin, relSize, absOrigin, absSize);
13
14         this.realFontSize_y = this.fontSize / (absSize.y * this.itemHeight);
15         this.realFontSize_x = this.fontSize / (absSize.x * (1 - this.controlWidth));
16         this.realUpperMargin = 0.5 * (1 - this.realFontSize.y);
17         this.setDescription(this, this.description);
18     }
19
20     INIT(XonoticGuideDescription) {
21         this.configureXonoticListBox(this);
22     }
23
24     ATTRIB(XonoticGuideDescription, descriptionWrapped, string, string_null);
25     void XonoticGuideDescription_setDescription(entity this, string desc)
26     {
27         string current = this.description;
28         if (current && current != desc) strunzone(current);
29         this.description = strzone(desc);
30
31         string currentWrapped = this.descriptionWrapped;
32         if (currentWrapped) strunzone(currentWrapped);
33         string wrapped = "";
34         for (int i = 0, n = tokenizebyseparator(desc, "\n"); i < n; ++i) {
35             string line = "";
36             for (getWrappedLine_remaining = argv(i); getWrappedLine_remaining; ) {
37                 string s = getWrappedLine(1, this.realFontSize, draw_TextWidth_WithColors);
38                 line = sprintf("%s\n%s", line, s);
39             }
40             wrapped = strcat(wrapped, line);
41         }
42         this.descriptionWrapped = strzone(wrapped);
43
44         this.nItems = tokenizebyseparator(wrapped, "\n");
45     }
46
47     METHOD(XonoticGuideDescription, drawListBoxItem, void(entity this, int i, vector absSize, bool isSelected, bool isFocused)) {
48         tokenizebyseparator(this.descriptionWrapped, "\n");
49         draw_Text(this.realUpperMargin * eY, argv(i), this.realFontSize, '1 1 1', 1, 0);
50     }
51 ENDCLASS(XonoticGuideDescription)