From: otta8634 Date: Mon, 16 Dec 2024 10:53:31 +0000 (+0800) Subject: Relocate methods to .qc files from .qh X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=e8b3a7dc787a962b1b1cf943d634f15fb641f7b9;p=xonotic%2Fxonotic-data.pk3dir.git Relocate methods to .qc files from .qh Also replaced cvar("developer"). --- diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_media_guide.qc b/qcsrc/menu/xonotic/dialog_multiplayer_media_guide.qc index c65e56822..5faa81d5b 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_media_guide.qc +++ b/qcsrc/menu/xonotic/dialog_multiplayer_media_guide.qc @@ -73,7 +73,7 @@ void XonoticGuideTab_entryChangeNotify(entity, entity this) entity entries = this.entryList; entity e = entries.source.getEntry(entries.source, entries.selectedItem, func_null); string s = e.describe(e); - if (cvar("developer")) + if (gamestatus & GAME_DEVELOPER) s = sprintf("entity %i\n%s", e, s); desc.setDescription(desc, s); } diff --git a/qcsrc/menu/xonotic/guide/description.qc b/qcsrc/menu/xonotic/guide/description.qc index 35068c1e5..ae81664e2 100644 --- a/qcsrc/menu/xonotic/guide/description.qc +++ b/qcsrc/menu/xonotic/guide/description.qc @@ -1 +1,43 @@ #include "description.qh" + +void XonoticGuideDescription_drawListBoxItem(entity this, int i, vector absSize, bool isSelected, bool isFocused) +{ + tokenizebyseparator(this.descriptionWrapped, "\n"); + draw_Text(this.realUpperMargin * eY, argv(i), this.realFontSize, '1 1 1', 1, 0); +} + +void XonoticGuideDescription_setDescription(entity this, string desc) +{ + string current = this.description; + if (current && current != desc) + strunzone(current); + this.description = strzone(desc); + + string currentWrapped = this.descriptionWrapped; + if (currentWrapped) + strunzone(currentWrapped); + string wrapped = ""; + for (int i = 0, n = tokenizebyseparator(desc, "\n"); i < n; ++i) + { + string line = ""; + for (getWrappedLine_remaining = argv(i); getWrappedLine_remaining; ) + { + string s = getWrappedLine(1, this.realFontSize, draw_TextWidth_WithColors); + line = strcat(line, "\n", s); + } + wrapped = strcat(wrapped, line); + } + this.descriptionWrapped = strzone(wrapped); + + this.nItems = tokenizebyseparator(wrapped, "\n"); +} + +void XonoticGuideDescription_resizeNotify(entity this, vector relOrigin, vector relSize, vector absOrigin, vector absSize) +{ + SUPER(XonoticGuideDescription).resizeNotify(this, relOrigin, relSize, absOrigin, absSize); + + this.realFontSize_y = this.fontSize / (absSize.y * this.itemHeight); + this.realFontSize_x = this.fontSize / (absSize.x * (1 - this.controlWidth)); + this.realUpperMargin = 0.5 * (1 - this.realFontSize.y); + this.setDescription(this, this.description); +} diff --git a/qcsrc/menu/xonotic/guide/description.qh b/qcsrc/menu/xonotic/guide/description.qh index a7f150109..81e9644d0 100644 --- a/qcsrc/menu/xonotic/guide/description.qh +++ b/qcsrc/menu/xonotic/guide/description.qh @@ -6,52 +6,14 @@ CLASS(XonoticGuideDescription, XonoticListBox) ATTRIB(XonoticGuideDescription, realUpperMargin, float, 0); ATTRIB(XonoticGuideDescription, rowsPerItem, float, 1); ATTRIB(XonoticGuideDescription, selectionDoesntMatter, bool, true); - - METHOD(XonoticGuideDescription, setDescription, void(entity, string)); ATTRIB(XonoticGuideDescription, description, string, string_null); + ATTRIB(XonoticGuideDescription, descriptionWrapped, string, string_null); - METHOD(XonoticGuideDescription, resizeNotify, void(entity this, vector relOrigin, vector relSize, vector absOrigin, vector absSize)) { - SUPER(XonoticGuideDescription).resizeNotify(this, relOrigin, relSize, absOrigin, absSize); - - this.realFontSize_y = this.fontSize / (absSize.y * this.itemHeight); - this.realFontSize_x = this.fontSize / (absSize.x * (1 - this.controlWidth)); - this.realUpperMargin = 0.5 * (1 - this.realFontSize.y); - this.setDescription(this, this.description); - } + METHOD(XonoticGuideDescription, drawListBoxItem, void(entity, int, vector, bool, bool)); + METHOD(XonoticGuideDescription, setDescription, void(entity, string)); + METHOD(XonoticGuideDescription, resizeNotify, void(entity, vector, vector, vector, vector)); INIT(XonoticGuideDescription) { this.configureXonoticListBox(this); } - - ATTRIB(XonoticGuideDescription, descriptionWrapped, string, string_null); - void XonoticGuideDescription_setDescription(entity this, string desc) - { - string current = this.description; - if (current && current != desc) - strunzone(current); - this.description = strzone(desc); - - string currentWrapped = this.descriptionWrapped; - if (currentWrapped) - strunzone(currentWrapped); - string wrapped = ""; - for (int i = 0, n = tokenizebyseparator(desc, "\n"); i < n; ++i) - { - string line = ""; - for (getWrappedLine_remaining = argv(i); getWrappedLine_remaining; ) - { - string s = getWrappedLine(1, this.realFontSize, draw_TextWidth_WithColors); - line = strcat(line, "\n", s); - } - wrapped = strcat(wrapped, line); - } - this.descriptionWrapped = strzone(wrapped); - - this.nItems = tokenizebyseparator(wrapped, "\n"); - } - - METHOD(XonoticGuideDescription, drawListBoxItem, void(entity this, int i, vector absSize, bool isSelected, bool isFocused)) { - tokenizebyseparator(this.descriptionWrapped, "\n"); - draw_Text(this.realUpperMargin * eY, argv(i), this.realFontSize, '1 1 1', 1, 0); - } ENDCLASS(XonoticGuideDescription) diff --git a/qcsrc/menu/xonotic/guide/entries.qc b/qcsrc/menu/xonotic/guide/entries.qc index f09210db8..5d7fe8e96 100644 --- a/qcsrc/menu/xonotic/guide/entries.qc +++ b/qcsrc/menu/xonotic/guide/entries.qc @@ -5,7 +5,8 @@ #include string XonoticEntryList_cb_name, XonoticEntryList_cb_icon; -void XonoticEntryList_cb(string _name, string _icon) { +void XonoticEntryList_cb(string _name, string _icon) +{ XonoticEntryList_cb_name = _name; XonoticEntryList_cb_icon = _icon; } diff --git a/qcsrc/menu/xonotic/guide/guide.qc b/qcsrc/menu/xonotic/guide/guide.qc index ca61a6011..5723211f8 100644 --- a/qcsrc/menu/xonotic/guide/guide.qc +++ b/qcsrc/menu/xonotic/guide/guide.qc @@ -1 +1,100 @@ #include "guide.qh" + +METHOD(TopicSource, getEntry, entity(TopicSource this, int i, void(string, string) returns)) +{ + int idx = 0; + #define TOPIC(src, name, icon) \ + if (idx++ == i) \ + { \ + if (returns) \ + returns(name, icon); \ + return DataSource_true; \ + } + TOPICS(TOPIC); + #undef TOPIC + if (returns) + returns("undefined", "undefined"); + return DataSource_false; +} +METHOD(TopicSource, reload, int(TopicSource this, string filter)) +{ + int n = 0; + #define TOPIC(src, name, icon) n++; + TOPICS(TOPIC); + #undef TOPIC + return n; +} + +entity DebugSource_find_debug() +{ + entity head = NULL, tail = NULL; + for (entity it = NULL; (it = nextent(it)); ) { + if (!it.instanceOfObject) continue; + if (it.instanceOfGameItem) continue; + if (it.instanceOfAnimHost) continue; + if (it.instanceOfDataSource) continue; + if (it.classname == "Object") continue; + if (it.classname == "vtbl") continue; + if (!tail) + tail = head = it; + else + { + tail.nextdebug = it; + tail = it; + } + } + return head; +} +METHOD(DebugSource, getEntry, entity(DebugSource this, int i, void(string, string) returns)) +{ + int idx = 0; + entity e; + for (e = DebugSource_find_debug(); e; e = e.nextdebug) + { + if (strstrofs(sprintf("entity %i", e), DebugSource_activeFilter, 0) < 0) continue; + if (idx++ == i) break; + } + if (returns) + e.display(e, returns); + return e; +} +METHOD(DebugSource, reload, int(DebugSource this, string filter)) +{ + DebugSource_activeFilter = filter; + int idx = 0; + entity e; + for (e = DebugSource_find_debug(); e; e = e.nextdebug) + { + if (strstrofs(sprintf("entity %i", e), DebugSource_activeFilter, 0) < 0) continue; + idx++; + } + return idx; +} + +METHOD(MapSource, getEntry, entity(MapSource this, int i, void(string, string) returns)) +{ + if (!MapInfo_Get_ByID(i)) + return DataSource_false; + string path = strcat("/maps/", MapInfo_Map_bspname); + string img = draw_PictureSize(path) ? path : "nopreview_map"; + if (returns) + returns(MapInfo_Map_titlestring, img); + MapInfo_ClearTemps(); + return DataSource_true; +} +METHOD(MapSource, indexOf, int(MapSource this, string s)) +{ + MapInfo_FindName(s); + return MapInfo_FindName_firstResult; +} +METHOD(MapSource, reload, int(MapSource this, string s)) +{ + _MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, 0, 0); + if (s) + MapInfo_FilterString(s); + return MapInfo_count; +} +METHOD(MapSource, destroy, void(MapSource this)) +{ + MapInfo_Shutdown(); +} diff --git a/qcsrc/menu/xonotic/guide/guide.qh b/qcsrc/menu/xonotic/guide/guide.qh index 2bf2aa556..b1f36ec58 100644 --- a/qcsrc/menu/xonotic/guide/guide.qh +++ b/qcsrc/menu/xonotic/guide/guide.qh @@ -17,78 +17,18 @@ X(NEW(TurretSource), _("Turrets"), "gametype_as") \ X(NEW(MutatorSource), _("Mutators"), "gametype_nb") \ X(NEW(MapSource), _("Maps"), "gametype_ctf") \ - if (cvar("developer")) X(NEW(DebugSource), _("Debug"), "gametype_ons") \ + if (gamestatus & GAME_DEVELOPER) X(NEW(DebugSource), _("Debug"), "gametype_ons") \ /**/ CLASS(TopicSource, DataSource) - METHOD(TopicSource, getEntry, entity(TopicSource this, int i, void(string, string) returns)) { - int idx = 0; - #define TOPIC(src, name, icon) \ - if (idx++ == i) \ - { \ - if (returns) \ - returns(name, icon); \ - return DataSource_true; \ - } - TOPICS(TOPIC); - #undef TOPIC - if (returns) - returns("undefined", "undefined"); - return DataSource_false; - } - METHOD(TopicSource, reload, int(TopicSource this, string filter)) { - int n = 0; - #define TOPIC(src, name, icon) n++; - TOPICS(TOPIC); - #undef TOPIC - return n; - } + METHOD(TopicSource, getEntry, entity(TopicSource this, int i, void(string, string) returns)); + METHOD(TopicSource, reload, int(TopicSource this, string filter)); ENDCLASS(TopicSource) CLASS(DebugSource, DataSource) .entity nextdebug; - entity find_debug() { - entity head = NULL, tail = NULL; - for (entity it = NULL; (it = nextent(it)); ) { - if (!it.instanceOfObject) continue; - if (it.instanceOfGameItem) continue; - if (it.instanceOfAnimHost) continue; - if (it.instanceOfDataSource) continue; - if (it.classname == "Object") continue; - if (it.classname == "vtbl") continue; - if (!tail) - tail = head = it; - else - { - tail.nextdebug = it; - tail = it; - } - } - return head; - } string DebugSource_activeFilter = ""; - METHOD(DebugSource, getEntry, entity(DebugSource this, int i, void(string, string) returns)) { - int idx = 0; - entity e; - for (e = find_debug(); e; e = e.nextdebug) - { - if (strstrofs(sprintf("entity %i", e), DebugSource_activeFilter, 0) < 0) continue; - if (idx++ == i) break; - } - if (returns) - e.display(e, returns); - return e; - } - METHOD(DebugSource, reload, int(DebugSource this, string filter)) { - DebugSource_activeFilter = filter; - int idx = 0; - entity e; - for (e = find_debug(); e; e = e.nextdebug) - { - if (strstrofs(sprintf("entity %i", e), DebugSource_activeFilter, 0) < 0) continue; - idx++; - } - return idx; - } + METHOD(DebugSource, getEntry, entity(DebugSource this, int i, void(string, string) returns)); + METHOD(DebugSource, reload, int(DebugSource this, string filter)); ENDCLASS(DebugSource) .bool m_hidden; @@ -144,25 +84,8 @@ REGISTRY_SOURCE(TurretSource, Turrets) REGISTRY_SOURCE(MutatorSource, Mutators) CLASS(MapSource, DataSource) - METHOD(MapSource, getEntry, entity(MapSource this, int i, void(string, string) returns)) { - if (!MapInfo_Get_ByID(i)) - return DataSource_false; - string path = strcat("/maps/", MapInfo_Map_bspname); - string img = draw_PictureSize(path) ? path : "nopreview_map"; - if (returns) - returns(MapInfo_Map_titlestring, img); - MapInfo_ClearTemps(); - return DataSource_true; - } - METHOD(MapSource, indexOf, int(MapSource this, string s)) { - MapInfo_FindName(s); - return MapInfo_FindName_firstResult; - } - METHOD(MapSource, reload, int(MapSource this, string s)) { - _MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, 0, 0); - if (s) - MapInfo_FilterString(s); - return MapInfo_count; - } - METHOD(MapSource, destroy, void(MapSource this)) { MapInfo_Shutdown(); } + METHOD(MapSource, getEntry, entity(MapSource this, int i, void(string, string) returns)); + METHOD(MapSource, indexOf, int(MapSource this, string s)); + METHOD(MapSource, reload, int(MapSource this, string s)); + METHOD(MapSource, destroy, void(MapSource)); ENDCLASS(MapSource) diff --git a/qcsrc/menu/xonotic/guide/pages.qc b/qcsrc/menu/xonotic/guide/pages.qc index e79aed7ef..1b15398b5 100644 --- a/qcsrc/menu/xonotic/guide/pages.qc +++ b/qcsrc/menu/xonotic/guide/pages.qc @@ -1 +1,10 @@ #include "pages.qh" + +METHOD(GuidePage, describe, string(GuidePage this)) +{ + return this.m_description; +} +METHOD(GuidePage, display, void(GuidePage this, void(string name, string icon) returns)) +{ + returns(this.m_title, "nopreview_map"); +} diff --git a/qcsrc/menu/xonotic/guide/pages.qh b/qcsrc/menu/xonotic/guide/pages.qh index 78030ea40..b11cb9fb8 100644 --- a/qcsrc/menu/xonotic/guide/pages.qh +++ b/qcsrc/menu/xonotic/guide/pages.qh @@ -4,16 +4,15 @@ CLASS(GuidePage, Object); ATTRIB(GuidePage, m_id, int, 0); ATTRIB(GuidePage, m_title, string, ""); ATTRIB(GuidePage, m_description, string, ""); - METHOD(GuidePage, describe, string(GuidePage this)) { - return this.m_description; - } - METHOD(GuidePage, display, void(GuidePage this, void(string name, string icon) returns)) { - returns(this.m_title, "nopreview_map"); - } + + METHOD(GuidePage, describe, string(GuidePage)); + METHOD(GuidePage, display, void(GuidePage this, void(string name, string icon) returns)); + CONSTRUCTOR(GuidePage, string _title) { CONSTRUCT(GuidePage); this.m_title = _title; } + ENDCLASS(GuidePage) REGISTRY(GuidePages, 16) diff --git a/qcsrc/menu/xonotic/guide/topics.qc b/qcsrc/menu/xonotic/guide/topics.qc index 0e693dc94..369509f9f 100644 --- a/qcsrc/menu/xonotic/guide/topics.qc +++ b/qcsrc/menu/xonotic/guide/topics.qc @@ -8,7 +8,8 @@ void XonoticTopicList_clickListBoxItem(entity this, float i, vector where) } string XonoticTopicList_cb_name, XonoticTopicList_cb_icon; -void XonoticTopicList_cb(string _name, string _icon) { +void XonoticTopicList_cb(string _name, string _icon) +{ XonoticTopicList_cb_name = _name; XonoticTopicList_cb_icon = _icon; }