]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/guide/tab.qh
3c0b637a80c5beb2f2057f292abfb9c997b14286
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / guide / tab.qh
1 #pragma once
2
3 #include <common/items/item.qh>
4 #include <menu/anim/animhost.qh>
5 #include <menu/xonotic/datasource.qh>
6
7 #define TOPICS(X) \
8     X(NEW(FreetextSource),  _("Guide"),     "gametype_tdm") \
9     X(NEW(GametypeSource),  _("Gametypes"), "gametype_dm") \
10     X(NEW(WeaponSource),    _("Weapons"),   "gametype_ka") \
11     X(NEW(ItemSource),      _("Items"),     "gametype_kh") \
12     X(NEW(BuffSource),      _("Buffs"),     "gametype_dom") \
13     X(NEW(NadeSource),      _("Nades"),     "gametype_ft") \
14     X(NEW(MonsterSource),   _("Monsters"),  "gametype_lms") \
15     X(NEW(VehicleSource),   _("Vehicles"),  "gametype_rc") \
16     X(NEW(TurretSource),    _("Turrets"),   "gametype_as") \
17     X(NEW(MutatorSource),   _("Mutators"),  "gametype_nb") \
18     X(NEW(MapSource),       _("Maps"),      "gametype_ctf") \
19     if (cvar("developer")) X(NEW(DebugSource), _("Debug"), "gametype_ons") \
20     /**/
21 CLASS(TopicSource, DataSource)
22     METHOD(TopicSource, getEntry, entity(TopicSource this, int i, void(string, string) returns)) {
23         int idx = 0;
24         #define TOPIC(src, name, icon) if (idx++ == i) { if (returns) returns(name, icon); return DataSource_true; }
25         TOPICS(TOPIC);
26         #undef TOPIC
27         if (returns) returns("undefined", "undefined");
28         return DataSource_false;
29     }
30     METHOD(TopicSource, reload, int(TopicSource this, string filter)) {
31         int n = 0;
32         #define TOPIC(src, name, icon) n++;
33         TOPICS(TOPIC);
34         #undef TOPIC
35         return n;
36     }
37 ENDCLASS(TopicSource)
38
39 CLASS(DebugSource, DataSource)
40     .entity nextdebug;
41     entity find_debug() {
42         entity head = NULL, tail = NULL;
43         for (entity it = NULL; (it = nextent(it)); ) {
44             if (!it.instanceOfObject) continue;
45             if (it.instanceOfGameItem) continue;
46             if (it.instanceOfAnimHost) continue;
47             if (it.instanceOfDataSource) continue;
48             if (it.classname == "Object") continue;
49             if (it.classname == "vtbl") continue;
50             if (!tail) {
51                 tail = head = it;
52             } else {
53                 tail.nextdebug = it;
54                 tail = it;
55             }
56         }
57         return head;
58     }
59     string DebugSource_activeFilter = "";
60     METHOD(DebugSource, getEntry, entity(DebugSource this, int i, void(string, string) returns)) {
61         int idx = 0;
62         entity e;
63         for (e = find_debug(); e; e = e.nextdebug) {
64             if (strstrofs(sprintf("entity %i", e), DebugSource_activeFilter, 0) < 0) continue;
65             if (idx++ == i) break;
66         }
67         if (returns) e.display(e, returns);
68         return e;
69     }
70     METHOD(DebugSource, reload, int(DebugSource this, string filter)) {
71         DebugSource_activeFilter = filter;
72         int idx = 0;
73         entity e;
74         for (e = find_debug(); e; e = e.nextdebug) {
75             if (strstrofs(sprintf("entity %i", e), DebugSource_activeFilter, 0) < 0) continue;
76             idx++;
77         }
78         return idx;
79     }
80 ENDCLASS(DebugSource)
81
82 #define REGISTRY_SOURCE(id, arr) \
83 CLASS(id, DataSource) \
84     METHOD(id, getEntry, entity(id this, int i, void(string, string) returns)) { \
85         entity e = _R_GET(_##arr, i); \
86         if (returns) e.display(e, returns); \
87         return e; \
88     } \
89     METHOD(id, reload, int(id this, string filter)) { return arr##_COUNT; } \
90 ENDCLASS(id)
91
92 #include "pages.qh"
93 REGISTRY_SOURCE(FreetextSource, GuidePages)
94
95 #include <common/mapinfo.qh>
96 REGISTRY_SOURCE(GametypeSource, Gametypes)
97
98 #include <common/items/all.qh>
99 REGISTRY_SOURCE(ItemSource, Items)
100
101 #include <common/mutators/mutator/buffs/buffs.qh>
102 REGISTRY_SOURCE(BuffSource, Buffs)
103
104 #include <common/mutators/mutator/nades/nades.qh>
105 REGISTRY_SOURCE(NadeSource, Nades)
106
107 #include <common/weapons/all.qh>
108 REGISTRY_SOURCE(WeaponSource, Weapons)
109
110 #include <common/monsters/all.qh>
111 REGISTRY_SOURCE(MonsterSource, Monsters)
112
113 #include <common/vehicles/all.qh>
114 REGISTRY_SOURCE(VehicleSource, Vehicles)
115
116 #include <common/turrets/all.qh>
117 REGISTRY_SOURCE(TurretSource, Turrets)
118
119 #include <common/mutators/base.qh>
120 REGISTRY_SOURCE(MutatorSource, Mutators)
121
122 CLASS(MapSource, DataSource)
123     METHOD(MapSource, getEntry, entity(MapSource this, int i, void(string, string) returns)) {
124         if (!MapInfo_Get_ByID(i)) return DataSource_false;
125         string path = strcat("/maps/", MapInfo_Map_bspname);
126         string img = draw_PictureSize(path) ? path : "nopreview_map";
127         if (returns) returns(MapInfo_Map_titlestring, img);
128         MapInfo_ClearTemps();
129         return DataSource_true;
130     }
131     METHOD(MapSource, indexOf, int(MapSource this, string s)) {
132         MapInfo_FindName(s);
133         return MapInfo_FindName_firstResult;
134     }
135     METHOD(MapSource, reload, int(MapSource this, string s)) {
136         _MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, 0, 0);
137         if (s) MapInfo_FilterString(s);
138         return MapInfo_count;
139     }
140     METHOD(MapSource, destroy, void(MapSource this)) { MapInfo_Shutdown(); }
141 ENDCLASS(MapSource)
142
143 #include "topics.qh"
144 #include "entries.qh"
145 #include "description.qh"
146 #include <menu/xonotic/tab.qh>
147 CLASS(XonoticGuideTab, XonoticTab)
148     ATTRIB(XonoticGuideTab, rows, float, 21);
149     ATTRIB(XonoticGuideTab, columns, float, 6);
150         ATTRIB(XonoticGuideTab, intendedWidth, float, 1);
151     METHOD(XonoticGuideTab, fill, void(entity));
152     METHOD(XonoticGuideTab, topicChangeNotify, void(entity, entity));
153     METHOD(XonoticGuideTab, entryChangeNotify, void(entity, entity));
154
155     ATTRIB(XonoticGuideTab, controlledTextbox, entity);
156     ATTRIB(XonoticGuideTab, topicList, entity, NEW(XonoticTopicList, NEW(TopicSource)));
157     ATTRIB(XonoticGuideTab, entryList, entity, NEW(XonoticEntryList, NULL));
158     ATTRIB(XonoticGuideTab, descriptionPane, entity, NEW(XonoticGuideDescription));
159
160     INIT(XonoticGuideTab) {
161         this.configureDialog(this);
162     }
163 ENDCLASS(XonoticGuideTab)