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