]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/xonotic/campaign.qc
take3: format 903 files
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / campaign.qc
index cb418a4e1834fcce6076672f337e818fef681ca5..a095323acb41c5544eab879889a0f38f4790c1e9 100644 (file)
@@ -11,37 +11,35 @@ void rewrapCampaign(float w, float l0, float emptyheight, vector theFontSize)
        int n;
        float l;
        string r, s;
-       for(i = 0; i < campaign_entries; ++i)
-       {
+       for (i = 0; i < campaign_entries; ++i) {
                l = l0;
-               if(campaign_longdesc_wrapped[i])
+               if (campaign_longdesc_wrapped[i]) {
                        strunzone(campaign_longdesc_wrapped[i]);
+               }
                n = tokenizebyseparator(campaign_longdesc[i], "\n");
                r = "";
-               for(j = 0; j < n; ++j)
-               {
+               for (j = 0; j < n; ++j) {
                        s = argv(j);
-                       if(s == "")
-                       {
+                       if (s == "") {
                                l -= emptyheight;
                                r = strcat(r, "\n");
                                continue;
                        }
 
                        getWrappedLine_remaining = s;
-                       while(getWrappedLine_remaining)
-                       {
+                       while (getWrappedLine_remaining) {
                                s = getWrappedLine(w, theFontSize, draw_TextWidth_WithoutColors);
-                               if(--l < 0) goto toolong;
+                               if (--l < 0) { goto toolong; }
                                r = strcat(r, s, "\n");
                        }
                }
                goto nottoolong;
-LABEL(toolong)
-               while(substring(r, strlen(r) - 1, 1) == "\n")
+               LABEL(toolong)
+               while (substring(r, strlen(r) - 1, 1) == "\n") {
                        r = substring(r, 0, strlen(r) - 1);
+               }
                r = strcat(r, "...\n");
-LABEL(nottoolong)
+               LABEL(nottoolong)
                campaign_longdesc_wrapped[i] = strzone(substring(r, 0, strlen(r) - 1));
        }
 }
@@ -63,17 +61,20 @@ void XonoticCampaignList_configureXonoticCampaignList(entity me)
 
 void XonoticCampaignList_destroy(entity me)
 {
-       if(me.campaignGlob >= 0)
+       if (me.campaignGlob >= 0) {
                search_end(me.campaignGlob);
+       }
 }
 
 void XonoticCampaignList_loadCvars(entity me)
 {
        // read campaign cvars
-       if(campaign_name)
+       if (campaign_name) {
                strunzone(campaign_name);
-       if(me.cvarName)
+       }
+       if (me.cvarName) {
                strunzone(me.cvarName);
+       }
        campaign_name = strzone(cvar_string("g_campaign_name"));
        me.cvarName = strzone(strcat("g_campaign", campaign_name, "_index"));
        registercvar(me.cvarName, "", 0); // saved by server QC anyway
@@ -81,14 +82,17 @@ void XonoticCampaignList_loadCvars(entity me)
        CampaignFile_Load(0, CAMPAIGN_MAX_ENTRIES);
        me.campaignIndex = bound(0, cvar(me.cvarName), campaign_entries);
        cvar_set(me.cvarName, ftos(me.campaignIndex));
-       if(me.columnNameSize)
+       if (me.columnNameSize) {
                rewrapCampaign(me.columnNameSize, me.rowsPerItem - 3, me.emptyLineHeight, me.realFontSize);
+       }
        me.nItems = min(me.campaignIndex + 2, campaign_entries);
        me.setSelected(me, min(me.campaignIndex, me.nItems - 1));
-       if(me.nItems - 1 > me.campaignIndex)
+       if (me.nItems - 1 > me.campaignIndex) {
                me.scrollToItem(me, me.nItems - 1);
-       if(me.labelTitle)
+       }
+       if (me.labelTitle) {
                me.labelTitle.setText(me.labelTitle, campaign_title);
+       }
 }
 
 void XonoticCampaignList_saveCvars(entity me)
@@ -107,36 +111,33 @@ void XonoticCampaignList_campaignGo(entity me, float step)
 
        canNext = canPrev = 0;
 
-       if(me.campaignGlob >= 0)
-       {
+       if (me.campaignGlob >= 0) {
                n = search_getsize(me.campaignGlob);
-               if(n > 0)
-               {
+               if (n > 0) {
                        j = -1;
                        s = strcat("maps/campaign", campaign_name, ".txt");
-                       for(i = 0; i < n; ++i)
-                       {
-                               if(search_getfilename(me.campaignGlob, i) == s)
+                       for (i = 0; i < n; ++i) {
+                               if (search_getfilename(me.campaignGlob, i) == s) {
                                        j = i;
+                               }
                        }
-                       if(j < 0)
-                       {
+                       if (j < 0) {
                                s = strcat("maps/campaign", cvar_defstring("g_campaign_name"), ".txt");
-                               for(i = 0; i < n; ++i)
-                               {
-                                       if(search_getfilename(me.campaignGlob, i) == s)
+                               for (i = 0; i < n; ++i) {
+                                       if (search_getfilename(me.campaignGlob, i) == s) {
                                                j = i;
+                                       }
                                }
                        }
-                       if(j < 0)
-                       {
-                               if(step >= 0)
+                       if (j < 0) {
+                               if (step >= 0) {
                                        j = 0;
-                               else
+                               } else {
                                        j = n - 1;
-                       }
-                       else
+                               }
+                       } else {
                                j = mod(j + step, n);
+                       }
                        s = search_getfilename(me.campaignGlob, j);
                        s = substring(s, 13, strlen(s) - 17);
                        cvar_set("g_campaign_name", s);
@@ -146,10 +147,12 @@ void XonoticCampaignList_campaignGo(entity me, float step)
                }
        }
 
-       if(me.buttonNext)
+       if (me.buttonNext) {
                me.buttonNext.disabled = !canNext;
-       if(me.buttonPrev)
+       }
+       if (me.buttonPrev) {
                me.buttonPrev.disabled = !canPrev;
+       }
 }
 
 void MultiCampaign_Next(entity btn, entity me)
@@ -163,8 +166,9 @@ void MultiCampaign_Prev(entity btn, entity me)
 
 void XonoticCampaignList_draw(entity me)
 {
-       if(cvar(me.cvarName) != me.campaignIndex || cvar_string("g_campaign_name") != campaign_name)
+       if (cvar(me.cvarName) != me.campaignIndex || cvar_string("g_campaign_name") != campaign_name) {
                me.loadCvars(me);
+       }
        SUPER(XonoticCampaignList).draw(me);
 }
 
@@ -203,63 +207,60 @@ void XonoticCampaignList_drawListBoxItem(entity me, int i, vector absSize, bool
        float j, n;
        vector o;
 
-       if(i < me.campaignIndex)
-       {
+       if (i < me.campaignIndex) {
                theAlpha = SKINALPHA_CAMPAIGN_SELECTABLE;
                theColor = SKINCOLOR_CAMPAIGN_SELECTABLE;
-       }
-       else if(i == me.campaignIndex)
-       {
+       } else if (i == me.campaignIndex) {
                theAlpha = SKINALPHA_CAMPAIGN_CURRENT;
                theColor = SKINCOLOR_CAMPAIGN_CURRENT;
-       }
-       else
-       {
+       } else {
                theAlpha = SKINALPHA_CAMPAIGN_FUTURE;
                theColor = SKINCOLOR_CAMPAIGN_FUTURE;
        }
 
-       if(isSelected)
+       if (isSelected) {
                draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
-       else if(isFocused)
-       {
+       } else if (isFocused) {
                me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
                draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
        }
 
-       if(draw_PictureSize(strcat("/maps/", campaign_mapname[i])) == '0 0 0')
+       if (draw_PictureSize(strcat("/maps/", campaign_mapname[i])) == '0 0 0') {
                draw_Picture(me.columnPreviewOrigin * eX, "nopreview_map", me.columnPreviewSize * eX + eY, '1 1 1', theAlpha);
-       else
+       } else {
                draw_Picture(me.columnPreviewOrigin * eX, strcat("/maps/", campaign_mapname[i]), me.columnPreviewSize * eX + eY, '1 1 1', theAlpha);
+       }
 
-       if(i < me.campaignIndex)
+       if (i < me.campaignIndex) {
                draw_Picture(me.checkMarkOrigin, "checkmark", me.checkMarkSize, '1 1 1', 1);
-       if(i <= me.campaignIndex)
+       }
+       if (i <= me.campaignIndex) {
                s = campaign_shortdesc[i]; // fteqcc sucks
-       else
+       } else {
                s = "???";
-       s = draw_TextShortenToWidth(sprintf(_("Level %d: %s"), i+1, s), me.columnNameSize, 0, me.realFontSize);
+       }
+       s = draw_TextShortenToWidth(sprintf(_("Level %d: %s"), i + 1, s), me.columnNameSize, 0, me.realFontSize);
        draw_Text(me.realUpperMargin1 * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, theColor, theAlpha, 0);
 
-       if(i <= me.campaignIndex)
-       {
+       if (i <= me.campaignIndex) {
                s = campaign_longdesc_wrapped[i];
                n = tokenizebyseparator(s, "\n");
                o = me.realUpperMargin2 * eY + me.columnNameOrigin * eX;
-               for(j = 0; j < n; ++j)
-                       if(argv(j) != "")
-                       {
+               for (j = 0; j < n; ++j) {
+                       if (argv(j) != "") {
                                draw_Text(o, argv(j), me.realFontSize, theColor, theAlpha * SKINALPHA_CAMPAIGN_DESCRIPTION, 0);
                                o.y += me.realFontSize.y;
-                       }
-                       else
+                       } else {
                                o.y += me.realFontSize.y * me.emptyLineHeight;
+                       }
+               }
        }
 }
 void CampaignList_LoadMap(entity btn, entity me)
 {
-       if(me.selectedItem >= me.nItems || me.selectedItem < 0)
+       if (me.selectedItem >= me.nItems || me.selectedItem < 0) {
                return;
+       }
        CampaignSetup(me.selectedItem);
 }
 
@@ -271,9 +272,10 @@ void XonoticCampaignList_setSelected(entity me, float i)
 
 float XonoticCampaignList_keyDown(entity me, float scan, float ascii, float shift)
 {
-       if(scan == K_ENTER || scan == K_SPACE || scan == K_KP_ENTER)
+       if (scan == K_ENTER || scan == K_SPACE || scan == K_KP_ENTER) {
                CampaignList_LoadMap(me, me);
-       else
+       } else {
                return SUPER(XonoticCampaignList).keyDown(me, scan, ascii, shift);
+       }
        return 1;
 }