]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Fix buttons for previous and next campaign not working
authorterencehill <piuntn@gmail.com>
Sat, 25 Aug 2018 18:43:30 +0000 (20:43 +0200)
committerterencehill <piuntn@gmail.com>
Sat, 25 Aug 2018 18:43:30 +0000 (20:43 +0200)
qcsrc/menu/xonotic/campaign.qc
qcsrc/menu/xonotic/campaign.qh

index 90221cdf85a43e2731905fe35664ddd57e2440b5..a3ad36355d9cece13deb37c750054cfe8794d0d2 100644 (file)
@@ -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);
index 784926f7df8636cd58d8513a24e5aed8b0dc475c..298e27587466697572311d048684b11a2dc21db9 100644 (file)
@@ -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);