From 5f988d331ec6b8a929fcba1f7b5ad8a7fb2148a3 Mon Sep 17 00:00:00 2001 From: otta8634 Date: Mon, 16 Dec 2024 17:58:22 +0800 Subject: [PATCH] Reformat code It looked too crammed before. Used mostly Allman style as per CONTRIBUTING.md. --- .../xonotic/dialog_multiplayer_media_guide.qc | 15 ++++-- qcsrc/menu/xonotic/guide/description.qh | 14 +++-- qcsrc/menu/xonotic/guide/entries.qc | 51 +++++++++++-------- qcsrc/menu/xonotic/guide/guide.qh | 37 ++++++++++---- qcsrc/menu/xonotic/guide/topics.qc | 8 +-- 5 files changed, 83 insertions(+), 42 deletions(-) diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_media_guide.qc b/qcsrc/menu/xonotic/dialog_multiplayer_media_guide.qc index 4ff36c5f6..c65e56822 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_media_guide.qc +++ b/qcsrc/menu/xonotic/dialog_multiplayer_media_guide.qc @@ -51,8 +51,16 @@ void XonoticGuideTab_topicChangeNotify(entity, entity this) int i = topics.selectedItem; int idx = 0; entity found = NULL; - #define TOPIC(src, name, icon) if (idx++ == i) { static entity e; if (!e) e = src; found = e; break; } - do { TOPICS(TOPIC); } while (0); + #define TOPIC(src, name, icon) \ + if (idx++ == i) \ + { \ + static entity e; \ + if (!e) e = src; \ + found = e; \ + break; \ + } + do { TOPICS(TOPIC); } + while (0); #undef TOPIC entries.source = found; entries.refilter(entries); @@ -65,6 +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")) { s = sprintf("entity %i\n%s", e, s); } + if (cvar("developer")) + s = sprintf("entity %i\n%s", e, s); desc.setDescription(desc, s); } diff --git a/qcsrc/menu/xonotic/guide/description.qh b/qcsrc/menu/xonotic/guide/description.qh index a4c203383..a7f150109 100644 --- a/qcsrc/menu/xonotic/guide/description.qh +++ b/qcsrc/menu/xonotic/guide/description.qh @@ -27,17 +27,21 @@ CLASS(XonoticGuideDescription, XonoticListBox) void XonoticGuideDescription_setDescription(entity this, string desc) { string current = this.description; - if (current && current != desc) strunzone(current); + if (current && current != desc) + strunzone(current); this.description = strzone(desc); string currentWrapped = this.descriptionWrapped; - if (currentWrapped) strunzone(currentWrapped); + if (currentWrapped) + strunzone(currentWrapped); string wrapped = ""; - for (int i = 0, n = tokenizebyseparator(desc, "\n"); i < n; ++i) { + for (int i = 0, n = tokenizebyseparator(desc, "\n"); i < n; ++i) + { string line = ""; - for (getWrappedLine_remaining = argv(i); getWrappedLine_remaining; ) { + for (getWrappedLine_remaining = argv(i); getWrappedLine_remaining; ) + { string s = getWrappedLine(1, this.realFontSize, draw_TextWidth_WithColors); - line = sprintf("%s\n%s", line, s); + line = strcat(line, "\n", s); } wrapped = strcat(wrapped, line); } diff --git a/qcsrc/menu/xonotic/guide/entries.qc b/qcsrc/menu/xonotic/guide/entries.qc index a5430314d..f09210db8 100644 --- a/qcsrc/menu/xonotic/guide/entries.qc +++ b/qcsrc/menu/xonotic/guide/entries.qc @@ -16,18 +16,22 @@ void XonoticEntryList_drawListBoxItem(entity this, int i, vector absSize, bool i if (!this.source.getEntry(this.source, i, XonoticEntryList_cb)) return; string name = XonoticEntryList_cb_name; string icon = XonoticEntryList_cb_icon; - if (isSelected) { + if (isSelected) draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED); - } else if (isFocused) { + else if (isFocused) + { this.focusedItemAlpha = getFadedAlpha(this.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED); draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, this.focusedItemAlpha); } vector sz = draw_PictureSize(icon); - if (!sz) sz = '1 1 0'; + if (!sz) + sz = '1 1 0'; float szr = sz.x / sz.y; - if (strstrofs(icon, "map", 0) >= 0) szr = 4 / 3; + if (strstrofs(icon, "map", 0) >= 0) + szr = 4 / 3; float asr = this.itemAbsSize.x / this.itemAbsSize.y; - sz.y = 1; sz.x = szr / asr; + sz.y = 1; + sz.x = szr / asr; draw_Picture('0 0 0', icon, sz, '1 1 1', SKINALPHA_LISTBOX_SELECTED); string s = draw_TextShortenToWidth(strdecolorize(name), 1 - sz.x - 2 * this.realFontSize.x, 0, this.realFontSize); draw_Text(this.realUpperMargin1 * eY + (sz.x + 0.5 * this.realFontSize.x) * eX, s, this.realFontSize, '1 1 1', SKINALPHA_TEXT, 0); @@ -35,28 +39,36 @@ void XonoticEntryList_drawListBoxItem(entity this, int i, vector absSize, bool i METHOD(XonoticEntryList, keyDown, float(entity this, float scan, float ascii, float shift)) { - if (this.nItems <= 0) { + if (this.nItems <= 0) return SUPER(XonoticEntryList).keyDown(this, scan, ascii, shift); - } else if ((ascii >= 32 || scan == K_BACKSPACE) && this.source.indexOf) { + else if ((ascii >= 32 || scan == K_BACKSPACE) && this.source.indexOf) + { string save; - if (scan == K_BACKSPACE) { + if (scan == K_BACKSPACE) save = substring(this.typeToSearchString, 0, strlen(this.typeToSearchString) - 1); - } else { + else + { string ch = chr(ascii); save = (time > this.typeToSearchTime) ? ch : strcat(this.typeToSearchString, ch); } - if (this.typeToSearchString) strunzone(this.typeToSearchString); + if (this.typeToSearchString) + strunzone(this.typeToSearchString); this.typeToSearchString = strzone(save); this.typeToSearchTime = time + 0.5; - if (strlen(this.typeToSearchString)) { + if (strlen(this.typeToSearchString)) + { int idx = this.source.indexOf(this.source, this.typeToSearchString); - if (idx >= 0) this.setSelected(this, idx); + if (idx >= 0) + this.setSelected(this, idx); } - } else if (shift & S_CTRL && scan == 'f') { + } + else if (shift & S_CTRL && scan == 'f') this.parent.setFocus(this.parent, this.stringFilterBox); - } else if (shift & S_CTRL && scan == 'u') { + else if (shift & S_CTRL && scan == 'u') + { this.stringFilterBox.setText(this.stringFilterBox, ""); - if (this.stringFilter) strunzone(this.stringFilter); + if (this.stringFilter) + strunzone(this.stringFilter); this.stringFilter = string_null; this.refilter(this); } @@ -65,16 +77,15 @@ METHOD(XonoticEntryList, keyDown, float(entity this, float scan, float ascii, fl void XonoticEntryList_refilter(entity this) { - if (!this.source) { + if (!this.source) + { this.nItems = 0; return; } this.nItems = this.source.reload(this.source, this.stringFilter); - for (int i = 0, n = this.nItems; i < n; ++i) { - if (this.source.getEntry(this.source, i, XonoticEntryList_cb)) { + for (int i = 0, n = this.nItems; i < n; ++i) + if (this.source.getEntry(this.source, i, XonoticEntryList_cb)) draw_PreloadPicture(XonoticEntryList_cb_icon); - } - } } void XonoticEntryList_resizeNotify(entity this, vector relOrigin, vector relSize, vector absOrigin, vector absSize) diff --git a/qcsrc/menu/xonotic/guide/guide.qh b/qcsrc/menu/xonotic/guide/guide.qh index de9257a2e..2bf2aa556 100644 --- a/qcsrc/menu/xonotic/guide/guide.qh +++ b/qcsrc/menu/xonotic/guide/guide.qh @@ -22,10 +22,17 @@ 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; } + #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"); + if (returns) + returns("undefined", "undefined"); return DataSource_false; } METHOD(TopicSource, reload, int(TopicSource this, string filter)) { @@ -48,9 +55,10 @@ CLASS(DebugSource, DataSource) if (it.instanceOfDataSource) continue; if (it.classname == "Object") continue; if (it.classname == "vtbl") continue; - if (!tail) { + if (!tail) tail = head = it; - } else { + else + { tail.nextdebug = it; tail = it; } @@ -61,18 +69,21 @@ CLASS(DebugSource, DataSource) 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) { + 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); + 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) { + for (e = find_debug(); e; e = e.nextdebug) + { if (strstrofs(sprintf("entity %i", e), DebugSource_activeFilter, 0) < 0) continue; idx++; } @@ -96,7 +107,8 @@ STATIC_INIT_LATE(arr##_MENU) \ CLASS(id, DataSource) \ METHOD(id, getEntry, entity(id this, int i, void(string, string) returns)) { \ entity e = AL_gete(arr##_MENU, i); \ - if (returns) e.display(e, returns); \ + if (returns) \ + e.display(e, returns); \ return e; \ } \ METHOD(id, reload, int(id this, string filter)) { return arr##_MENU_COUNT; } \ @@ -133,10 +145,12 @@ 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; + 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); + if (returns) + returns(MapInfo_Map_titlestring, img); MapInfo_ClearTemps(); return DataSource_true; } @@ -146,7 +160,8 @@ CLASS(MapSource, DataSource) } METHOD(MapSource, reload, int(MapSource this, string s)) { _MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, 0, 0); - if (s) MapInfo_FilterString(s); + if (s) + MapInfo_FilterString(s); return MapInfo_count; } METHOD(MapSource, destroy, void(MapSource this)) { MapInfo_Shutdown(); } diff --git a/qcsrc/menu/xonotic/guide/topics.qc b/qcsrc/menu/xonotic/guide/topics.qc index 9d1453dce..0e693dc94 100644 --- a/qcsrc/menu/xonotic/guide/topics.qc +++ b/qcsrc/menu/xonotic/guide/topics.qc @@ -19,9 +19,10 @@ void XonoticTopicList_drawListBoxItem(entity this, int i, vector absSize, bool i if (!this.source.getEntry(this.source, i, XonoticTopicList_cb)) return; string icon = XonoticTopicList_cb_icon; string name = XonoticTopicList_cb_name; - if (isSelected) { + if (isSelected) draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED); - } else if (isFocused) { + else if (isFocused) + { this.focusedItemAlpha = getFadedAlpha(this.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED); draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, this.focusedItemAlpha); } @@ -37,7 +38,8 @@ void XonoticTopicList_drawListBoxItem(entity this, int i, vector absSize, bool i bool XonoticTopicList_keyDown(entity this, float scan, float ascii, float shift) { - if (scan == K_ENTER || scan == K_KP_ENTER) { + if (scan == K_ENTER || scan == K_KP_ENTER) + { m_play_click_sound(MENU_SOUND_EXECUTE); return true; } -- 2.39.2