]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/xonotic/hudskinlist.qc
take3: format 903 files
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / hudskinlist.qc
index 66c96046d88e9e4a2b156b2ed2d149188613ab22..2cf647f215e509e0c11bb158776414967be7425d 100644 (file)
@@ -42,34 +42,30 @@ string XonoticHUDSkinList_hudskinAuthor(entity me, float i)
 void getHUDSkinFiles(entity me, int sortbuf, string subdir)
 {
        string s;
-       if(me.filterString)
+       if (me.filterString) {
                s = me.filterString;
-       else
+       } else {
                s = "*";
+       }
        s = strcat(subdir, "hud_", s, ".cfg");
 
        int list = search_begin(s, false, true);
-       if(list >= 0)
-       {
+       if (list >= 0) {
                int n = search_getsize(list);
-               for(int i = 0; i < n; ++i)
-               {
+               for (int i = 0; i < n; ++i) {
                        string s = search_getfilename(list, i);
                        int subdir_ofs = strstrofs(s, "/", 0);
-                       if(subdir_ofs >= 0)
-                       {
+                       if (subdir_ofs >= 0) {
                                int ofs = subdir_ofs;
-                               while(ofs != -1)
-                               {
+                               while (ofs != -1) {
                                        subdir_ofs = ofs;
                                        ofs = strstrofs(s, "/", subdir_ofs + 1);
                                }
                        }
 
-                       if(subdir_ofs == -1)
+                       if (subdir_ofs == -1) {
                                bufstr_add(sortbuf, s, true);
-                       else
-                       {
+                       } else {
                                subdir = substring(s, 0, subdir_ofs);
                                string filename = substring(s, subdir_ofs + 1, -1);
                                // invert path and filename position so we can sort sortbuf by filename
@@ -83,34 +79,33 @@ void getHUDSkinFiles(entity me, int sortbuf, string subdir)
 void getAllHUDSkins(entity me, int sortbuf)
 {
        int n = buf_getsize(sortbuf);
-       for(int i = 0; i < n; ++i)
-       {
+       for (int i = 0; i < n; ++i) {
                string entry = bufstr_get(sortbuf, i);
                int ofs = strstrofs(entry, "/", 0);
                string s = "";
                string filename = entry;
-               if(ofs >= 0)
-               {
+               if (ofs >= 0) {
                        s = substring(entry, ofs + 1, -1); // skip initial "/"
                        s = strcat(s, "/");
                        bufstr_set(me.listHUDSkin, i * HUDSKINPARM_COUNT + HUDSKINPARM_PATH, s);
                        filename = strcat(s, substring(entry, 0, ofs));
-               }
-               else
+               } else {
                        ofs = strlen(entry);
+               }
                s = substring(entry, 4, ofs - 4 - 4); // remove "hud_" prefix and ".cfg" suffix
                bufstr_set(me.listHUDSkin, i * HUDSKINPARM_COUNT + HUDSKINPARM_NAME, s);
 
                int fh = fopen(filename, FILE_READ);
-               if(fh < 0)
+               if (fh < 0) {
                        continue;
-               while((s = fgets(fh)) && substring(s, 0, 2) == "//")
-               {
+               }
+               while ((s = fgets(fh)) && substring(s, 0, 2) == "//") {
                        tokenize_console(substring(s, 2, -1));
-                       if(argv(0) == "title")
+                       if (argv(0) == "title") {
                                bufstr_set(me.listHUDSkin, i * HUDSKINPARM_COUNT + HUDSKINPARM_TITLE, argv(1));
-                       else if(argv(0) == "author")
+                       } else if (argv(0) == "author") {
                                bufstr_set(me.listHUDSkin, i * HUDSKINPARM_COUNT + HUDSKINPARM_AUTHOR, argv(1));
+                       }
                }
                fclose(fh);
        }
@@ -118,11 +113,11 @@ void getAllHUDSkins(entity me, int sortbuf)
 
 void XonoticHUDSkinList_getHUDSkins(entity me)
 {
-       if (me.listHUDSkin >= 0)
+       if (me.listHUDSkin >= 0) {
                buf_del(me.listHUDSkin);
+       }
        me.listHUDSkin = buf_create();
-       if (me.listHUDSkin < 0)
-       {
+       if (me.listHUDSkin < 0) {
                me.nItems = 0;
                return;
        }
@@ -137,8 +132,9 @@ void XonoticHUDSkinList_getHUDSkins(entity me)
 
 void XonoticHUDSkinList_destroy(entity me)
 {
-       if(me.nItems > 0)
+       if (me.nItems > 0) {
                buf_del(me.listHUDSkin);
+       }
 }
 
 void XonoticHUDSkinList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
@@ -157,20 +153,21 @@ void XonoticHUDSkinList_resizeNotify(entity me, vector relOrigin, vector relSize
 void XonoticHUDSkinList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
 {
        string s, s2;
-       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);
        }
 
        s = me.hudskinTitle(me, i);
-       if(s == "")
+       if (s == "") {
                s = me.hudskinName(me, i);
+       }
        s2 = me.hudskinAuthor(me, i);
-       if(s2 != "")
+       if (s2 != "") {
                s = strcat(s, " (", s2, ")");
+       }
        s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize);
        draw_Text(me.realUpperMargin * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, SKINCOLOR_TEXT, SKINALPHA_TEXT, 1);
 }
@@ -183,34 +180,37 @@ void XonoticHUDSkinList_showNotify(entity me)
 void HUDSkinList_Refresh_Click(entity btn, entity me)
 {
        me.getHUDSkins(me);
-       me.setSelected(me, 0); //always select the first element after a list update
+       me.setSelected(me, 0); // always select the first element after a list update
 }
 
 void HUDSkinList_SavedName_Change(entity box, entity me)
 {
-       if(me.savedName)
+       if (me.savedName) {
                strunzone(me.savedName);
+       }
 
-       if(box.text != "")
+       if (box.text != "") {
                me.savedName = strzone(box.text);
-       else
+       } else {
                me.savedName = string_null;
+       }
 }
 
 void HUDSkinList_Filter_Change(entity box, entity me)
 {
-       if(me.filterString)
+       if (me.filterString) {
                strunzone(me.filterString);
+       }
 
-       if(box.text != "")
-       {
-               if (strstrofs(box.text, "*", 0) >= 0 || strstrofs(box.text, "?", 0) >= 0)
+       if (box.text != "") {
+               if (strstrofs(box.text, "*", 0) >= 0 || strstrofs(box.text, "?", 0) >= 0) {
                        me.filterString = strzone(box.text);
-               else
+               } else {
                        me.filterString = strzone(strcat("*", box.text, "*"));
-       }
-       else
+               }
+       } else {
                me.filterString = string_null;
+       }
 
        me.getHUDSkins(me);
 }
@@ -218,16 +218,16 @@ void HUDSkinList_Filter_Change(entity box, entity me)
 void SaveHUDSkin_Click(entity btn, entity me)
 {
        string s = me.savedName;
-       if(s == "")
+       if (s == "") {
                s = "myconfig";
+       }
        localcmd(sprintf("hud save \"%s\"\n", s));
        me.delayedRefreshTime = time + 1;
 }
 
 void XonoticHUDSkinList_draw(entity me)
 {
-       if(me.delayedRefreshTime > 0 && me.delayedRefreshTime < time)
-       {
+       if (me.delayedRefreshTime > 0 && me.delayedRefreshTime < time) {
                HUDSkinList_Refresh_Click(NULL, me);
                me.delayedRefreshTime = 0;
        }
@@ -253,13 +253,10 @@ void XonoticHUDSkinList_doubleClickListBoxItem(entity me, float i, vector where)
 
 float XonoticHUDSkinList_keyDown(entity me, float scan, float ascii, float shift)
 {
-       if(scan == K_ENTER || scan == K_KP_ENTER)
-       {
+       if (scan == K_ENTER || scan == K_KP_ENTER) {
                me.setHUDSkin(me);
                return 1;
-       }
-       else
-       {
+       } else {
                return SUPER(XonoticHUDSkinList).keyDown(me, scan, ascii, shift);
        }
 }