X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fmenu%2Fxonotic%2Fhudskinlist.qc;h=66c96046d88e9e4a2b156b2ed2d149188613ab22;hb=45dfc727cef14412598d619e1704d1b70dc64b64;hp=bfe003ef5a981ad51e5d4c0dc2f827de61fba2d2;hpb=84e8fbd195ec01bcfff5d0789587ba6320150a72;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/menu/xonotic/hudskinlist.qc b/qcsrc/menu/xonotic/hudskinlist.qc index bfe003ef5..66c96046d 100644 --- a/qcsrc/menu/xonotic/hudskinlist.qc +++ b/qcsrc/menu/xonotic/hudskinlist.qc @@ -1,45 +1,6 @@ -#ifndef HUDSKINLIST_H -#define HUDSKINLIST_H -#include "listbox.qc" -CLASS(XonoticHUDSkinList, XonoticListBox) - METHOD(XonoticHUDSkinList, configureXonoticHUDSkinList, void(entity)); - ATTRIB(XonoticHUDSkinList, rowsPerItem, float, 1) - METHOD(XonoticHUDSkinList, resizeNotify, void(entity, vector, vector, vector, vector)); - METHOD(XonoticHUDSkinList, draw, void(entity)); - METHOD(XonoticHUDSkinList, drawListBoxItem, void(entity, int, vector, bool, bool)); - METHOD(XonoticHUDSkinList, getHUDSkins, void(entity)); - METHOD(XonoticHUDSkinList, setHUDSkin, void(entity)); - METHOD(XonoticHUDSkinList, hudskinName, string(entity, float)); - METHOD(XonoticHUDSkinList, hudskinPath, string(entity, float)); - METHOD(XonoticHUDSkinList, doubleClickListBoxItem, void(entity, float, vector)); - METHOD(XonoticHUDSkinList, keyDown, float(entity, float, float, float)); - METHOD(XonoticHUDSkinList, destroy, void(entity)); - METHOD(XonoticHUDSkinList, showNotify, void(entity)); - - ATTRIB(XonoticHUDSkinList, listHUDSkin, float, -1) - ATTRIB(XonoticHUDSkinList, realFontSize, vector, '0 0 0') - ATTRIB(XonoticHUDSkinList, columnNameOrigin, float, 0) - ATTRIB(XonoticHUDSkinList, columnNameSize, float, 0) - ATTRIB(XonoticHUDSkinList, realUpperMargin, float, 0) - ATTRIB(XonoticHUDSkinList, origin, vector, '0 0 0') - ATTRIB(XonoticHUDSkinList, itemAbsSize, vector, '0 0 0') - - ATTRIB(XonoticHUDSkinList, filterString, string, string_null) - ATTRIB(XonoticHUDSkinList, delayedRefreshTime, float, 0) -ENDCLASS(XonoticHUDSkinList) - -#ifndef IMPLEMENTATION -// public: -entity hudskinlist; -entity makeXonoticHUDSkinList(); -void SaveHUDSkin_Click(entity btn, entity me); -void SetHUDSkin_Click(entity btn, entity me); -#endif -void HUDSkinList_Refresh_Click(entity btn, entity me); -void HUDSkinList_Filter_Change(entity box, entity me); -#endif - -#ifdef IMPLEMENTATION +#include "hudskinlist.qh" + +#include "inputbox.qh" entity makeXonoticHUDSkinList() { @@ -52,12 +13,14 @@ entity makeXonoticHUDSkinList() void XonoticHUDSkinList_configureXonoticHUDSkinList(entity me) { me.configureXonoticListBox(me); - me.getHUDSkins(me); + me.nItems = 0; } const float HUDSKINPARM_NAME = 0; const float HUDSKINPARM_PATH = 1; -const float HUDSKINPARM_COUNT = 2; +const float HUDSKINPARM_TITLE = 2; +const float HUDSKINPARM_AUTHOR = 3; +const float HUDSKINPARM_COUNT = 4; string XonoticHUDSkinList_hudskinName(entity me, float i) { return bufstr_get(me.listHUDSkin, i * HUDSKINPARM_COUNT + HUDSKINPARM_NAME); @@ -66,8 +29,17 @@ string XonoticHUDSkinList_hudskinPath(entity me, float i) { return bufstr_get(me.listHUDSkin, i * HUDSKINPARM_COUNT + HUDSKINPARM_PATH); } +string XonoticHUDSkinList_hudskinTitle(entity me, float i) +{ + return bufstr_get(me.listHUDSkin, i * HUDSKINPARM_COUNT + HUDSKINPARM_TITLE); +} +string XonoticHUDSkinList_hudskinAuthor(entity me, float i) +{ + return bufstr_get(me.listHUDSkin, i * HUDSKINPARM_COUNT + HUDSKINPARM_AUTHOR); +} -void getAllHUDSkins(entity me, string subdir) +// subdir can be a regular expression +void getHUDSkinFiles(entity me, int sortbuf, string subdir) { string s; if(me.filterString) @@ -75,26 +47,73 @@ void getAllHUDSkins(entity me, string subdir) else s = "*"; s = strcat(subdir, "hud_", s, ".cfg"); - float strlen_subdir = strlen(subdir); - string zoned_subdir = strzone(subdir); - float list, i, n; - list = search_begin(s, false, true); + int list = search_begin(s, false, true); if(list >= 0) { - n = search_getsize(list); - int bufsize = buf_getsize(me.listHUDSkin); - for(i = 0; i < n; ++i) + int n = search_getsize(list); + for(int i = 0; i < n; ++i) { - bufstr_set(me.listHUDSkin, bufsize + i * HUDSKINPARM_COUNT + HUDSKINPARM_PATH, zoned_subdir); - s = search_getfilename(list, i); // get initial full file name - s = substring(s, strlen_subdir + 4, (strlen(s) - strlen_subdir - 4 - 4)); // remove "hud_" prefix and ".cfg" suffix - bufstr_set(me.listHUDSkin, bufsize + i * HUDSKINPARM_COUNT + HUDSKINPARM_NAME, s); + string s = search_getfilename(list, i); + int subdir_ofs = strstrofs(s, "/", 0); + if(subdir_ofs >= 0) + { + int ofs = subdir_ofs; + while(ofs != -1) + { + subdir_ofs = ofs; + ofs = strstrofs(s, "/", subdir_ofs + 1); + } + } + + if(subdir_ofs == -1) + bufstr_add(sortbuf, s, true); + 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 + bufstr_add(sortbuf, strcat(filename, "/", subdir), true); + } } search_end(list); } - if(zoned_subdir) - strunzone(zoned_subdir); +} + +void getAllHUDSkins(entity me, int sortbuf) +{ + int n = buf_getsize(sortbuf); + 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) + { + 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 + 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) + continue; + while((s = fgets(fh)) && substring(s, 0, 2) == "//") + { + tokenize_console(substring(s, 2, -1)); + if(argv(0) == "title") + bufstr_set(me.listHUDSkin, i * HUDSKINPARM_COUNT + HUDSKINPARM_TITLE, argv(1)); + else if(argv(0) == "author") + bufstr_set(me.listHUDSkin, i * HUDSKINPARM_COUNT + HUDSKINPARM_AUTHOR, argv(1)); + } + fclose(fh); + } } void XonoticHUDSkinList_getHUDSkins(entity me) @@ -107,8 +126,12 @@ void XonoticHUDSkinList_getHUDSkins(entity me) me.nItems = 0; return; } - getAllHUDSkins(me, ""); - getAllHUDSkins(me, "data/"); + int sortbuf = buf_create(); + getHUDSkinFiles(me, sortbuf, ""); + getHUDSkinFiles(me, sortbuf, "data/"); + buf_sort(sortbuf, 128, 0); + getAllHUDSkins(me, sortbuf); + buf_del(sortbuf); me.nItems = buf_getsize(me.listHUDSkin) / HUDSKINPARM_COUNT; } @@ -133,7 +156,7 @@ void XonoticHUDSkinList_resizeNotify(entity me, vector relOrigin, vector relSize void XonoticHUDSkinList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused) { - string s; + string s, s2; if(isSelected) draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED); else if(isFocused) @@ -142,7 +165,12 @@ void XonoticHUDSkinList_drawListBoxItem(entity me, int i, vector absSize, bool i draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha); } - s = me.hudskinName(me,i); + s = me.hudskinTitle(me, i); + if(s == "") + s = me.hudskinName(me, i); + s2 = me.hudskinAuthor(me, i); + 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); } @@ -158,6 +186,17 @@ void HUDSkinList_Refresh_Click(entity btn, entity me) me.setSelected(me, 0); //always select the first element after a list update } +void HUDSkinList_SavedName_Change(entity box, entity me) +{ + if(me.savedName) + strunzone(me.savedName); + + if(box.text != "") + me.savedName = strzone(box.text); + else + me.savedName = string_null; +} + void HUDSkinList_Filter_Change(entity box, entity me) { if(me.filterString) @@ -178,7 +217,10 @@ void HUDSkinList_Filter_Change(entity box, entity me) void SaveHUDSkin_Click(entity btn, entity me) { - localcmd("hud save myconfig\n"); + string s = me.savedName; + if(s == "") + s = "myconfig"; + localcmd(sprintf("hud save \"%s\"\n", s)); me.delayedRefreshTime = time + 1; } @@ -195,7 +237,7 @@ void XonoticHUDSkinList_draw(entity me) void XonoticHUDSkinList_setHUDSkin(entity me) { string cfg = strcat(me.hudskinPath(me, me.selectedItem), "hud_", me.hudskinName(me, me.selectedItem), ".cfg"); - localcmd("exec ", cfg, "\n"); + localcmd("exec \"", cfg, "\"\n"); } void SetHUDSkin_Click(entity btn, entity me) @@ -221,5 +263,3 @@ float XonoticHUDSkinList_keyDown(entity me, float scan, float ascii, float shift return SUPER(XonoticHUDSkinList).keyDown(me, scan, ascii, shift); } } -#endif -