From b7e47345558559f6f391508cc445b94c7106751e Mon Sep 17 00:00:00 2001 From: terencehill Date: Sat, 25 Aug 2018 20:43:30 +0200 Subject: [PATCH] Fix buttons for previous and next campaign not working --- qcsrc/menu/xonotic/campaign.qc | 19 ++++++++----------- qcsrc/menu/xonotic/campaign.qh | 2 ++ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/qcsrc/menu/xonotic/campaign.qc b/qcsrc/menu/xonotic/campaign.qc index 90221cdf8..a3ad36355 100644 --- a/qcsrc/menu/xonotic/campaign.qc +++ b/qcsrc/menu/xonotic/campaign.qc @@ -57,7 +57,7 @@ void XonoticCampaignList_configureXonoticCampaignList(entity me) me.configureXonoticListBox(me); me.campaignGlob = search_begin("maps/campaign*.txt", true, true); me.loadCvars(me); - me.campaignGo(me, 0); // takes care of enabling/disabling buttons too + me.campaignGo(me, 0); // it makes work buttons too } void XonoticCampaignList_destroy(entity me) @@ -96,12 +96,9 @@ void XonoticCampaignList_saveCvars(entity me) void XonoticCampaignList_campaignGo(entity me, float step) { - float canNext, canPrev; string s; float i, j, n; - canNext = canPrev = 0; - if(me.campaignGlob >= 0) { n = search_getsize(me.campaignGlob); @@ -136,15 +133,10 @@ void XonoticCampaignList_campaignGo(entity me, float step) s = substring(s, 13, strlen(s) - 17); cvar_set("g_campaign_name", s); me.loadCvars(me); - canNext = (j != n - 1); - canPrev = (j != 0); + me.hasNextCampaign = (j != n - 1); + me.hasPrevCampaign = (j != 0); } } - - if(me.buttonNext) - me.buttonNext.disabled = !canNext; - if(me.buttonPrev) - me.buttonPrev.disabled = !canPrev; } void MultiCampaign_Next(entity btn, entity me) @@ -158,6 +150,11 @@ void MultiCampaign_Prev(entity btn, entity me) void XonoticCampaignList_draw(entity me) { + if(me.buttonNext) + me.buttonNext.disabled = !me.hasNextCampaign; + if(me.buttonPrev) + me.buttonPrev.disabled = !me.hasPrevCampaign; + if(cvar(me.cvarName) != me.campaignIndex || cvar_string("g_campaign_name") != campaign_name) me.loadCvars(me); SUPER(XonoticCampaignList).draw(me); diff --git a/qcsrc/menu/xonotic/campaign.qh b/qcsrc/menu/xonotic/campaign.qh index 784926f7d..298e27587 100644 --- a/qcsrc/menu/xonotic/campaign.qh +++ b/qcsrc/menu/xonotic/campaign.qh @@ -34,6 +34,8 @@ CLASS(XonoticCampaignList, XonoticListBox) ATTRIB(XonoticCampaignList, cvarName, string); METHOD(XonoticCampaignList, loadCvars, void(entity)); METHOD(XonoticCampaignList, saveCvars, void(entity)); + ATTRIB(XonoticCampaignList, hasNextCampaign, bool, false); + ATTRIB(XonoticCampaignList, hasPrevCampaign, bool, false); ATTRIB(XonoticCampaignList, buttonNext, entity); ATTRIB(XonoticCampaignList, buttonPrev, entity); -- 2.39.2