From: Mario Date: Mon, 4 Jan 2016 11:48:46 +0000 (+0000) Subject: Merge branch 'terencehill/menu_optimization' into 'master' X-Git-Tag: xonotic-v0.8.2~1286 X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=commitdiff_plain;h=692cb758fe8f25fa078bfd5885333ee031885600;hp=f099f166c5d50cebd0b7083a31ccf26e3df213b7 Merge branch 'terencehill/menu_optimization' into 'master' Menu optimization List of demos, screenshots, music tracks and player models (current player model image too) are now loaded on display, previously both on start (2 times due to a bug) and on display List of cvars and keybinds are now loaded only on display (previously only on start) Implementation changes: * Removed an unnecessary showNotify call for every item when building up the menu (caused to load many file lists twice) * Added SUPER(XonoticCvarsDialog).showNotify(me); in the implementation of showNotify for dialogs so that showNotify gets called for every item in the dialog (e.g. for the cvarlist in the "Advanced Settings" dialog) See merge request !263 --- diff --git a/qcsrc/menu/item/container.qc b/qcsrc/menu/item/container.qc index 23857dcead..17412cd0fb 100644 --- a/qcsrc/menu/item/container.qc +++ b/qcsrc/menu/item/container.qc @@ -302,7 +302,10 @@ other.parent = me; other.Container_origin = theOrigin; other.Container_size = theSize; - me.setAlphaOf(me, other, theAlpha); + + // don't call setAlphaOf, it would uneccessarily trigger showNotify + //me.setAlphaOf(me, other, theAlpha); + other.Container_alpha = theAlpha; entity l; l = me.lastChild; diff --git a/qcsrc/menu/item/listbox.qc b/qcsrc/menu/item/listbox.qc index 7f303fda7a..d6ea7d8595 100644 --- a/qcsrc/menu/item/listbox.qc +++ b/qcsrc/menu/item/listbox.qc @@ -43,7 +43,7 @@ ATTRIB(ListBox, colorF, vector, '1 1 1') ATTRIB(ListBox, tolerance, vector, '0 0 0') // drag tolerance ATTRIB(ListBox, scrollbarWidth, float, 0) // pixels - ATTRIB(ListBox, nItems, float, 42) + ATTRIB(ListBox, nItems, float, 42) // FIXME: why?!? ATTRIB(ListBox, itemHeight, float, 0) ATTRIB(ListBox, colorBG, vector, '0 0 0') ATTRIB(ListBox, alphaBG, float, 0) diff --git a/qcsrc/menu/xonotic/cvarlist.qc b/qcsrc/menu/xonotic/cvarlist.qc index 8323221daf..11e88a4e68 100644 --- a/qcsrc/menu/xonotic/cvarlist.qc +++ b/qcsrc/menu/xonotic/cvarlist.qc @@ -7,6 +7,7 @@ CLASS(XonoticCvarList, XonoticListBox) METHOD(XonoticCvarList, drawListBoxItem, void(entity, int, vector, bool, bool)); METHOD(XonoticCvarList, resizeNotify, void(entity, vector, vector, vector, vector)); METHOD(XonoticCvarList, keyDown, float(entity, float, float, float)); + METHOD(XonoticCvarList, showNotify, void(entity)); METHOD(XonoticCvarList, destroy, void(entity)); @@ -53,10 +54,18 @@ entity makeXonoticCvarList() void XonoticCvarList_configureXonoticCvarList(entity me) { me.configureXonoticListBox(me); - me.handle = buf_create(); + me.nItems = 0; +} +void XonoticCvarList_showNotify(entity me) +{ + bool force_initial_selection = false; + if(me.handle >= 0 && me.nItems <= 0) // me.handle not loaded yet? + force_initial_selection = true; buf_cvarlist(me.handle, "", "_"); me.nItems = buf_getsize(me.handle); + if(force_initial_selection) + me.setSelected(me, 0); } void XonoticCvarList_destroy(entity me) { @@ -151,8 +160,6 @@ void XonoticCvarList_resizeNotify(entity me, vector relOrigin, vector relSize, v me.columnValueSize = me.realFontSize.x * 20; me.columnNameSize = 1 - me.columnValueSize - me.realFontSize.x; me.columnValueOrigin = me.columnNameOrigin + me.columnNameSize + me.realFontSize.x; - - me.setSelected(me, me.selectedItem); } void XonoticCvarList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused) { diff --git a/qcsrc/menu/xonotic/demolist.qc b/qcsrc/menu/xonotic/demolist.qc index 2459d7ca1e..9f8978c14b 100644 --- a/qcsrc/menu/xonotic/demolist.qc +++ b/qcsrc/menu/xonotic/demolist.qc @@ -48,7 +48,7 @@ entity makeXonoticDemoList() void XonoticDemoList_configureXonoticDemoList(entity me) { me.configureXonoticListBox(me); - me.getDemos(me); + me.nItems = 0; } string XonoticDemoList_demoName(entity me, float i) diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.qc b/qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.qc index a411a8a7f3..e90a909595 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.qc +++ b/qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.qc @@ -20,6 +20,7 @@ ENDCLASS(XonoticMutatorsDialog) #ifdef IMPLEMENTATION void XonoticMutatorsDialog_showNotify(entity me) { + SUPER(XonoticMutatorsDialog).showNotify(me); loadAllCvars(me); } diff --git a/qcsrc/menu/xonotic/dialog_settings_misc_cvars.qc b/qcsrc/menu/xonotic/dialog_settings_misc_cvars.qc index 6ace10c124..8a2d489a0b 100644 --- a/qcsrc/menu/xonotic/dialog_settings_misc_cvars.qc +++ b/qcsrc/menu/xonotic/dialog_settings_misc_cvars.qc @@ -15,6 +15,7 @@ ENDCLASS(XonoticCvarsDialog) #ifdef IMPLEMENTATION void XonoticCvarsDialog_showNotify(entity me) { + SUPER(XonoticCvarsDialog).showNotify(me); loadAllCvars(me); } void XonoticCvarsDialog_fill(entity me) // in this dialog, use SKINCOLOR_CVARLIST_CONTROLS to color ALL controls diff --git a/qcsrc/menu/xonotic/dialog_teamselect.qc b/qcsrc/menu/xonotic/dialog_teamselect.qc index 3b624e2ad0..9185a1f6ea 100644 --- a/qcsrc/menu/xonotic/dialog_teamselect.qc +++ b/qcsrc/menu/xonotic/dialog_teamselect.qc @@ -32,6 +32,7 @@ entity makeTeamButton(string theName, vector theColor, string commandtheName) void XonoticTeamSelectDialog_showNotify(entity me) { + SUPER(XonoticTeamSelectDialog).showNotify(me); float teams, nTeams; teams = cvar("_teams_available"); nTeams = 0; diff --git a/qcsrc/menu/xonotic/hudskinlist.qc b/qcsrc/menu/xonotic/hudskinlist.qc index 736ee0a6ed..b3bdc62433 100644 --- a/qcsrc/menu/xonotic/hudskinlist.qc +++ b/qcsrc/menu/xonotic/hudskinlist.qc @@ -56,7 +56,7 @@ entity makeXonoticHUDSkinList() void XonoticHUDSkinList_configureXonoticHUDSkinList(entity me) { me.configureXonoticListBox(me); - me.getHUDSkins(me); + me.nItems = 0; } const float HUDSKINPARM_NAME = 0; diff --git a/qcsrc/menu/xonotic/keybinder.qc b/qcsrc/menu/xonotic/keybinder.qc index 4f1c74e815..9ce18c6b0a 100644 --- a/qcsrc/menu/xonotic/keybinder.qc +++ b/qcsrc/menu/xonotic/keybinder.qc @@ -7,9 +7,11 @@ CLASS(XonoticKeyBinder, XonoticListBox) METHOD(XonoticKeyBinder, drawListBoxItem, void(entity, int, vector, bool, bool)); METHOD(XonoticKeyBinder, doubleClickListBoxItem, void(entity, float, vector)); METHOD(XonoticKeyBinder, resizeNotify, void(entity, vector, vector, vector, vector)); + METHOD(XonoticKeyBinder, showNotify, void(entity)); METHOD(XonoticKeyBinder, setSelected, void(entity, float)); METHOD(XonoticKeyBinder, keyDown, float(entity, float, float, float)); METHOD(XonoticKeyBinder, keyGrabbed, void(entity, float, float)); + METHOD(XonoticKeyBinder, destroy, void(entity)); ATTRIB(XonoticKeyBinder, realFontSize, vector, '0 0 0') ATTRIB(XonoticKeyBinder, realUpperMargin, float, 0) @@ -18,6 +20,7 @@ CLASS(XonoticKeyBinder, XonoticListBox) ATTRIB(XonoticKeyBinder, columnKeysOrigin, float, 0) ATTRIB(XonoticKeyBinder, columnKeysSize, float, 0) + METHOD(XonoticKeyBinder, loadKeyBinds, void(entity)); ATTRIB(XonoticKeyBinder, previouslySelected, int, -1) ATTRIB(XonoticKeyBinder, inMouseHandler, float, 0) ATTRIB(XonoticKeyBinder, userbindEditButton, entity, NULL) @@ -165,10 +168,7 @@ void replace_bind(string from, string to) void XonoticKeyBinder_configureXonoticKeyBinder(entity me) { me.configureXonoticListBox(me); - if(Xonotic_KeyBinds_Count < 0) - Xonotic_KeyBinds_Read(); - me.nItems = Xonotic_KeyBinds_Count; - me.setSelected(me, 0); + me.nItems = 0; // TEMP: Xonotic 0.1 to later replace_bind("impulse 1", "weapon_group_1"); @@ -182,6 +182,21 @@ void XonoticKeyBinder_configureXonoticKeyBinder(entity me) replace_bind("impulse 9", "weapon_group_9"); replace_bind("impulse 14", "weapon_group_0"); } +void XonoticKeyBinder_loadKeyBinds(entity me) +{ + bool force_initial_selection = false; + if(Xonotic_KeyBinds_Count < 0) // me.handle not loaded yet? + force_initial_selection = true; + Xonotic_KeyBinds_Read(); + me.nItems = Xonotic_KeyBinds_Count; + if(force_initial_selection) + me.setSelected(me, 0); +} +void XonoticKeyBinder_showNotify(entity me) +{ + me.destroy(me); + me.loadKeyBinds(me); +} void XonoticKeyBinder_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize) { SUPER(XonoticKeyBinder).resizeNotify(me, relOrigin, relSize, absOrigin, absSize); @@ -194,9 +209,6 @@ void XonoticKeyBinder_resizeNotify(entity me, vector relOrigin, vector relSize, me.columnKeysSize = me.realFontSize.x * 12; me.columnFunctionSize = 1 - me.columnKeysSize - 2 * me.realFontSize.x; me.columnKeysOrigin = me.columnFunctionOrigin + me.columnFunctionSize + me.realFontSize.x; - - if(me.userbindEditButton) - me.userbindEditButton.disabled = (substring(Xonotic_KeyBinds_Descriptions[me.selectedItem], 0, 1) != "$"); } void KeyBinder_Bind_Change(entity btn, entity me) { @@ -256,6 +268,22 @@ void XonoticKeyBinder_keyGrabbed(entity me, int key, bool ascii) localcmd("-zoom\n"); // to make sure we aren't in togglezoom'd state cvar_set("_hud_showbinds_reload", "1"); } +void XonoticKeyBinder_destroy(entity me) +{ + if(Xonotic_KeyBinds_Count < 0) + return; + + for(int i = 0; i < MAX_KEYBINDS; ++i) + { + if(Xonotic_KeyBinds_Functions[i]) + strunzone(Xonotic_KeyBinds_Functions[i]); + Xonotic_KeyBinds_Functions[i] = string_null; + if(Xonotic_KeyBinds_Descriptions[i]) + strunzone(Xonotic_KeyBinds_Descriptions[i]); + Xonotic_KeyBinds_Descriptions[i] = string_null; + } + Xonotic_KeyBinds_Count = 0; +} void XonoticKeyBinder_editUserbind(entity me, string theName, string theCommandPress, string theCommandRelease) { string func, descr; diff --git a/qcsrc/menu/xonotic/playermodel.qc b/qcsrc/menu/xonotic/playermodel.qc index 5d58a1b03e..3af8238ddd 100644 --- a/qcsrc/menu/xonotic/playermodel.qc +++ b/qcsrc/menu/xonotic/playermodel.qc @@ -3,6 +3,7 @@ #include "image.qc" CLASS(XonoticPlayerModelSelector, XonoticImage) METHOD(XonoticPlayerModelSelector, configureXonoticPlayerModelSelector, void(entity)); + METHOD(XonoticPlayerModelSelector, loadModels, void(entity)); METHOD(XonoticPlayerModelSelector, loadCvars, void(entity)); METHOD(XonoticPlayerModelSelector, saveCvars, void(entity)); METHOD(XonoticPlayerModelSelector, draw, void(entity)); @@ -49,16 +50,19 @@ const float BUFMODELS_COUNT = 5; void XonoticPlayerModelSelector_configureXonoticPlayerModelSelector(entity me) { - float sortbuf, glob, i; + me.configureXonoticImage(me, string_null, -1); +} + +void XonoticPlayerModelSelector_loadModels(entity me) +{ + int i; string fn; - glob = search_begin(language_filename(get_model_datafilename(string_null, -1, "txt")), true, true); + float glob = search_begin(language_filename(get_model_datafilename(string_null, -1, "txt")), true, true); if (glob < 0) return; - me.configureXonoticImage(me, string_null, -1); - - sortbuf = buf_create(); + float sortbuf = buf_create(); for(i = 0; i < search_getsize(glob); ++i) { // select model #i! @@ -103,10 +107,14 @@ void XonoticPlayerModelSelector_configureXonoticPlayerModelSelector(entity me) me.loadCvars(me); // this will select the initial model, depending on the current cvars me.go(me, 0); // this will set the vars for the selected model } + void XonoticPlayerModelSelector_destroy(entity me) { - buf_del(me.bufModels); - me.bufModels = -1; + if(me.bufModels >= 0) + { + buf_del(me.bufModels); + me.bufModels = -1; + } } void XonoticPlayerModelSelector_loadCvars(entity me) @@ -222,6 +230,6 @@ void XonoticPlayerModelSelector_showNotify(entity me) { // Reinitialize self. me.destroy(me); - me.configureXonoticPlayerModelSelector(me); + me.loadModels(me); } #endif diff --git a/qcsrc/menu/xonotic/screenshotlist.qc b/qcsrc/menu/xonotic/screenshotlist.qc index 6655e8a62c..900c446f31 100644 --- a/qcsrc/menu/xonotic/screenshotlist.qc +++ b/qcsrc/menu/xonotic/screenshotlist.qc @@ -58,7 +58,7 @@ entity makeXonoticScreenshotList() void XonoticScreenshotList_configureXonoticScreenshotList(entity me) { me.configureXonoticListBox(me); - me.getScreenshots(me); + me.nItems = 0; } string XonoticScreenshotList_screenshotName(entity me, float i) diff --git a/qcsrc/menu/xonotic/soundlist.qc b/qcsrc/menu/xonotic/soundlist.qc index 159cd76c53..961c5b00be 100644 --- a/qcsrc/menu/xonotic/soundlist.qc +++ b/qcsrc/menu/xonotic/soundlist.qc @@ -7,13 +7,13 @@ CLASS(XonoticSoundList, XonoticListBox) METHOD(XonoticSoundList, resizeNotify, void(entity, vector, vector, vector, vector)); METHOD(XonoticSoundList, drawListBoxItem, void(entity, int, vector, bool, bool)); METHOD(XonoticSoundList, getSounds, void(entity)); - METHOD(XonoticSoundList, soundName, string(entity, float)); - METHOD(XonoticSoundList, doubleClickListBoxItem, void(entity, float, vector)); + METHOD(XonoticSoundList, soundName, string(entity, int)); + METHOD(XonoticSoundList, doubleClickListBoxItem, void(entity, int, vector)); METHOD(XonoticSoundList, keyDown, float(entity, float, float, float)); METHOD(XonoticSoundList, destroy, void(entity)); METHOD(XonoticSoundList, showNotify, void(entity)); - ATTRIB(XonoticSoundList, listSound, float, -1) + ATTRIB(XonoticSoundList, listSound, int, -1) ATTRIB(XonoticSoundList, realFontSize, vector, '0 0 0') ATTRIB(XonoticSoundList, columnNameOrigin, float, 0) ATTRIB(XonoticSoundList, columnNameSize, float, 0) @@ -48,10 +48,10 @@ entity makeXonoticSoundList() void XonoticSoundList_configureXonoticSoundList(entity me) { me.configureXonoticListBox(me); - me.getSounds(me); + me.nItems = 0; } -string XonoticSoundList_soundName(entity me, float i ) +string XonoticSoundList_soundName(entity me, int i) { string s; s = search_getfilename(me.listSound, i); @@ -75,10 +75,7 @@ void XonoticSoundList_getSounds(entity me) me.listSound = search_begin(s, false, true); - if(me.listSound < 0) - me.nItems=0; - else - me.nItems=search_getsize(me.listSound); + me.nItems = (me.listSound < 0) ? 0 : search_getsize(me.listSound); } void XonoticSoundList_destroy(entity me) @@ -114,7 +111,7 @@ void XonoticSoundList_drawListBoxItem(entity me, int i, vector absSize, bool isS draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha); } - s = me.soundName(me,i); + s = me.soundName(me, i); if(s == cvar_string("menu_cdtrack")) // current menu track draw_CenterText((me.columnNumberOrigin + 0.5 * me.columnNumberSize) * eX + me.realUpperMargin * eY, "[C]", me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0); else if(s == cvar_defstring("menu_cdtrack")) // default menu track @@ -131,7 +128,7 @@ void XonoticSoundList_showNotify(entity me) void SoundList_Menu_Track_Change(entity box, entity me) { - cvar_set("menu_cdtrack", me.soundName(me,me.selectedItem)); + cvar_set("menu_cdtrack", me.soundName(me, me.selectedItem)); } void SoundList_Menu_Track_Reset(entity box, entity me) @@ -159,12 +156,12 @@ void SoundList_Add(entity box, entity me) void SoundList_Add_All(entity box, entity me) { - float i; + int i; for(i = 0; i < me.nItems; ++i) me.playlist.addToPlayList(me.playlist, me.soundName(me, i)); } -void XonoticSoundList_doubleClickListBoxItem(entity me, float i, vector where) +void XonoticSoundList_doubleClickListBoxItem(entity me, int i, vector where) { me.playlist.addToPlayList(me.playlist, me.soundName(me, i)); }