X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fmenu%2Fxonotic%2Fserverlist.qc;h=021e9765119d7bf70861a5cdccca8d99c1108280;hp=5e6a567b6af907de399757b63a265675d265d340;hb=0c5b06b8592d343353d624764c6b440edb44ebc3;hpb=1b0decb9afb829407eae763b3053a122e2ae3de6 diff --git a/qcsrc/menu/xonotic/serverlist.qc b/qcsrc/menu/xonotic/serverlist.qc index 5e6a567b6..021e97651 100644 --- a/qcsrc/menu/xonotic/serverlist.qc +++ b/qcsrc/menu/xonotic/serverlist.qc @@ -6,6 +6,36 @@ #include "dialog_multiplayer_join_serverinfo.qh" #include +void SL_ProcessCategoryOverrides(.string override_field_string, .float override_field) +{ + string s; + for (int i = 0; i < category_ent_count; ++i) + { + s = categories[i].override_field_string; + if (s != "" && s != categories[i].cat_name) + { + int catnum = 0; + for (int x = 0; x < category_ent_count; ++x) + { + if(categories[x].cat_name == s) + { + catnum = x + 1; + break; + } + } + if (catnum) + { + strfree(categories[i].override_field_string); + categories[i].override_field = catnum; + continue; + } + LOG_INFOF("RegisterSLCategories(): Improper override '%s' for category '%s'!", s, categories[i].cat_name); + } + strfree(categories[i].override_field_string); + categories[i].override_field = 0; + } +} + void RegisterSLCategories() { entity cat; @@ -20,44 +50,8 @@ void RegisterSLCategories() SLIST_CATEGORIES #undef SLIST_CATEGORY - int i, x, catnum; - string s; - - #define PROCESS_OVERRIDE(override_string,override_field) \ - for(i = 0; i < category_ent_count; ++i) \ - { \ - s = categories[i].override_string; \ - if((s != "") && (s != categories[i].cat_name)) \ - { \ - catnum = 0; \ - for(x = 0; x < category_ent_count; ++x) \ - { if(categories[x].cat_name == s) { \ - catnum = (x+1); \ - break; \ - } } \ - if(catnum) \ - { \ - strunzone(categories[i].override_string); \ - categories[i].override_string = string_null; \ - categories[i].override_field = catnum; \ - continue; \ - } \ - else \ - { \ - LOG_INFOF( \ - "RegisterSLCategories(): Improper override '%s' for category '%s'!", \ - s, \ - categories[i].cat_name \ - ); \ - } \ - } \ - strunzone(categories[i].override_string); \ - categories[i].override_string = string_null; \ - categories[i].override_field = 0; \ - } - PROCESS_OVERRIDE(cat_enoverride_string, cat_enoverride) - PROCESS_OVERRIDE(cat_dioverride_string, cat_dioverride) - #undef PROCESS_OVERRIDE + SL_ProcessCategoryOverrides(cat_enoverride_string, cat_enoverride); + SL_ProcessCategoryOverrides(cat_dioverride_string, cat_dioverride); } // Supporting Functions @@ -308,9 +302,7 @@ void XonoticServerList_setSelected(entity me, int i) if(gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT) != me.nItems) return; // sorry, it would be wrong - if(me.selectedServer) - strunzone(me.selectedServer); - me.selectedServer = strzone(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem)); + strcpy(me.selectedServer, gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem)); me.ipAddressBox.setText(me.ipAddressBox, me.selectedServer); me.ipAddressBox.cursorPos = strlen(me.selectedServer); @@ -549,9 +541,10 @@ void XonoticServerList_draw(entity me) } else { me.nItems = gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT); } - me.connectButton.disabled = ((me.nItems == 0) && (me.ipAddressBox.text == "")); - me.infoButton.disabled = ((me.nItems == 0) || !owned); - me.favoriteButton.disabled = ((me.nItems == 0) && (me.ipAddressBox.text == "")); + me.connectButton.disabled = (me.lockedSelectedItem || (me.nItems == 0 && me.ipAddressBox.text == "")); + //me.disconnectButton.disabled = (!(gamestatus & (GAME_ISSERVER | GAME_CONNECTED))); + me.infoButton.disabled = (me.lockedSelectedItem || me.nItems == 0 || !owned); + me.favoriteButton.disabled = (me.lockedSelectedItem || (me.nItems == 0 && me.ipAddressBox.text == "")); if(me.lockedSelectedItem) { @@ -559,9 +552,7 @@ void XonoticServerList_draw(entity me) { if(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem) != me.selectedServer) { - if(me.selectedServer) - strunzone(me.selectedServer); - me.selectedServer = strzone(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem)); + strcpy(me.selectedServer, gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem)); } found = true; } @@ -586,9 +577,7 @@ void XonoticServerList_draw(entity me) // selected server disappeared, select the last server (scrolling to it) if(me.selectedItem >= me.nItems) SUPER(XonoticServerList).setSelected(me, me.nItems - 1); - if(me.selectedServer) - strunzone(me.selectedServer); - me.selectedServer = strzone(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem)); + strcpy(me.selectedServer, gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem)); } } @@ -666,12 +655,9 @@ void ServerList_TypeSort_Click(entity btn, entity me) } void ServerList_Filter_Change(entity box, entity me) { - if(me.filterString) - strunzone(me.filterString); + strfree(me.filterString); if(box.text != "") me.filterString = strzone(box.text); - else - me.filterString = string_null; me.refreshServerList(me, REFRESHSERVERLIST_REFILTER); me.ipAddressBox.setText(me.ipAddressBox, ""); @@ -717,9 +703,7 @@ void XonoticServerList_setSortOrder(entity me, int fld, int direction) me.sortButton4.forcePressed = 0; me.sortButton5.forcePressed = (fld == SLIST_FIELD_NUMHUMANS); me.selectedItem = 0; - if(me.selectedServer) - strunzone(me.selectedServer); - me.selectedServer = string_null; + strfree(me.selectedServer); me.refreshServerList(me, REFRESHSERVERLIST_REFILTER); } void XonoticServerList_positionSortButton(entity me, entity btn, float theOrigin, float theSize, string theTitle, void(entity, entity) theFunc) @@ -775,11 +759,10 @@ void XonoticServerList_resizeNotify(entity me, vector relOrigin, vector relSize, } void ServerList_Connect_Click(entity btn, entity me) { - localcmd(sprintf("connect %s\n", - ((me.ipAddressBox.text != "") ? - me.ipAddressBox.text : me.selectedServer - ) - )); + if (me.lockedSelectedItem) + return; + string sv = (me.ipAddressBox.text != "") ? me.ipAddressBox.text : me.selectedServer; + localcmd(sprintf("connect %s\n", sv)); } void ServerList_Favorite_Click(entity btn, entity this) { @@ -820,7 +803,7 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is vector oldscale = draw_scale; vector oldshift = draw_shift; #define SET_YRANGE(start,end) \ - draw_scale = boxToGlobalSize(eX * 1 + eY * (end - start), oldscale); \ + draw_scale = boxToGlobalSize(eX + eY * (end - start), oldscale); \ draw_shift = boxToGlobal(eY * start, oldshift, oldscale); for (j = 0; j < category_draw_count; ++j) { @@ -857,7 +840,7 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is } } - if(isSelected) + if(isSelected && !me.lockedSelectedItem) draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED); else if(isFocused) { @@ -1112,11 +1095,6 @@ float XonoticServerList_mouseMove(entity me, vector pos) bool XonoticServerList_keyDown(entity me, int scan, bool ascii, bool shift) { - vector org, sz; - - org = boxToGlobal(eY * (me.selectedItem * me.itemHeight - me.scrollPos), me.origin, me.size); - sz = boxToGlobalSize(eY * me.itemHeight + eX * (1 - me.controlWidth), me.size); - if(scan == K_ENTER || scan == K_KP_ENTER) { ServerList_Connect_Click(NULL, me); @@ -1126,6 +1104,8 @@ bool XonoticServerList_keyDown(entity me, int scan, bool ascii, bool shift) { if(me.nItems != 0) { + vector org = boxToGlobal(eY * (me.selectedItem * me.itemHeight - me.scrollPos), me.origin, me.size); + vector sz = boxToGlobalSize(eY * me.itemHeight + eX * (1 - me.controlWidth), me.size); m_play_click_sound(MENU_SOUND_OPEN); main.serverInfoDialog.loadServerInfo(main.serverInfoDialog, me.selectedItem); DialogOpenButton_Click_withCoords(me, main.serverInfoDialog, org, sz);