From: TimePath Date: Mon, 17 Aug 2015 04:46:34 +0000 (+1000) Subject: Enable any entity to control how it looks in the menu X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=5be6b13ef2f121d126e8971ce35607d6f39f59cd;p=xonotic%2Fxonotic-data.pk3dir.git Enable any entity to control how it looks in the menu --- diff --git a/qcsrc/common/mapinfo.qh b/qcsrc/common/mapinfo.qh index f2f5b5c283..b8efb9d90c 100644 --- a/qcsrc/common/mapinfo.qh +++ b/qcsrc/common/mapinfo.qh @@ -19,6 +19,13 @@ CLASS(Gametype, Object) ATTRIB(Gametype, model2, string, string_null) /** game type description */ ATTRIB(Gametype, gametype_description, string, string_null) + + METHOD(Gametype, describe, string(entity this)) + string Gametype_describe(entity this) { return this.gametype_description; } + + METHOD(Gametype, display, void(entity this, void(string name, string icon) returns)) + void Gametype_display(entity this, void(string, string) returns) { returns(this.message, strcat("gametype_", this.mdl)); } + CONSTRUCTOR(Gametype, string hname, string sname, string g_name, bool gteamplay, string defaults, string gdescription) { CONSTRUCT(Gametype); diff --git a/qcsrc/common/oo.qh b/qcsrc/common/oo.qh index b2131b1d1b..b7ed3bbe2e 100644 --- a/qcsrc/common/oo.qh +++ b/qcsrc/common/oo.qh @@ -117,7 +117,8 @@ STATIC_INIT(RegisterClasses) { RegisterClasses(); } #define spawn_1(this) #define _vtbl NULL CLASS(Object, ); - ATTRIB(Object, description, string, string_null) + METHOD(Object, describe, string(entity this)) + METHOD(Object, display, void(entity this, void(string name, string icon) returns)) ENDCLASS(Object) #undef spawn_static #undef spawn_1 diff --git a/qcsrc/menu/xonotic/dialog_media_guide.qc b/qcsrc/menu/xonotic/dialog_media_guide.qc index 5b6a91d97f..fcc2719faa 100644 --- a/qcsrc/menu/xonotic/dialog_media_guide.qc +++ b/qcsrc/menu/xonotic/dialog_media_guide.qc @@ -53,7 +53,10 @@ CLASS(DebugSource, DataSource) if (strstrofs(sprintf("entity %i", e), DebugSource_activeFilter, 0) < 0) continue; if (idx++ == i) break; } - if (returns) returns(sprintf("entity %i", e), ""); + if (returns) { + if (e.display) e.display(e, returns); + else returns(sprintf("entity %i", e), ""); + } return e; } METHOD(DebugSource, reload, int(string)) @@ -71,11 +74,10 @@ ENDCLASS(DebugSource) #include "../../common/mapinfo.qh" CLASS(GametypeSource, DataSource) - .string mdl, message; METHOD(GametypeSource, getEntry, entity(int, void(string, string))) entity GametypeSource_getEntry(int i, void(string, string) returns) { entity e = MAPINFO_TYPES[i]; - if (returns) returns(e.message, strcat("gametype_", e.mdl)); + if (returns) e.display(e, returns); return e; } METHOD(GametypeSource, reload, int(string)) @@ -194,10 +196,9 @@ void XonoticGuideTab_entryChangeNotify(entity, entity this) entity desc = this.descriptionPane; entity entries = this.entryList; entity e = entries.source.getEntry(entries.selectedItem, func_null); - string s = e.description; - string s2 = s ? s : _("No description"); - if (cvar("developer")) { if (!s) s2 = sprintf("entity %i\n%s", e, s2); } - desc.setDescription(desc, s2); + string s = e.describe ? e.describe(e) : _("No description"); + if (cvar("developer")) { s = sprintf("entity %i\n%s", e, s); } + desc.setDescription(desc, s); } #endif