Commit f1bc4f39 authored by Mario's avatar Mario

Merge branch 'terencehill/menu_listbox_changes' into 'master'

Menu listbox changes

Menu listbox changes:
* scrolling with mouse wheel / scrollbar no longer changes the current selection
* scrolling and selection changes are now smooth
* FIX: remove highlighting from the focused item when the cursor is moved to the scrollbar area
* FIX: Highlight the focused item even while scrolling
* stats list no longer shows a selected item as it's useless
* servers list no longer automatically scroll at the beginning following the first seen server


See merge request !150
parents ab15353d 9b1e1352
This diff is collapsed.
......@@ -129,8 +129,9 @@ void XonoticCampaignList_loadCvars(entity me)
if(me.columnNameSize)
rewrapCampaign(me.columnNameSize, me.rowsPerItem - 3, me.emptyLineHeight, me.realFontSize);
me.nItems = min(me.campaignIndex + 2, campaign_entries);
me.selectedItem = min(me.campaignIndex, me.nItems - 1);
me.scrollPos = me.nItems * me.itemHeight - 1;
me.setSelected(me, min(me.campaignIndex, me.nItems - 1));
if(me.nItems - 1 > me.campaignIndex)
me.scrollToItem(me, me.nItems - 1);
if(me.labelTitle)
me.labelTitle.setText(me.labelTitle, campaign_title);
}
......
......@@ -9,6 +9,7 @@ CLASS(XonoticCreditsList, XonoticListBox)
METHOD(XonoticCreditsList, resizeNotify, void(entity, vector, vector, vector, vector))
METHOD(XonoticCreditsList, keyDown, float(entity, float, float, float))
METHOD(XonoticCreditsList, destroy, void(entity))
ATTRIB(XonoticCreditsList, selectionDoesntMatter, bool, true)
ATTRIB(XonoticCreditsList, realFontSize, vector, '0 0 0')
ATTRIB(XonoticCreditsList, realUpperMargin, float, 0)
......@@ -41,13 +42,10 @@ void XonoticCreditsList_destroy(entity me)
}
void XonoticCreditsList_draw(entity me)
{
float i;
if(me.scrolling)
{
me.scrollPos = bound(0, (time - me.scrolling) * me.itemHeight, me.nItems * me.itemHeight - 1);
i = min(me.selectedItem, floor((me.scrollPos + 1) / me.itemHeight - 1));
i = max(i, ceil(me.scrollPos / me.itemHeight));
me.setSelected(me, i);
me.scrollPosTarget = me.scrollPos;
}
SUPER(XonoticCreditsList).draw(me);
}
......@@ -91,24 +89,7 @@ void XonoticCreditsList_drawListBoxItem(entity me, int i, vector absSize, bool i
float XonoticCreditsList_keyDown(entity me, float key, float ascii, float shift)
{
float i;
me.dragScrollTimer = time;
me.scrolling = 0;
if(key == K_PGUP || key == K_KP_PGUP)
me.scrollPos = max(me.scrollPos - 0.5, 0);
else if(key == K_PGDN || key == K_KP_PGDN)
me.scrollPos = min(me.scrollPos + 0.5, me.nItems * me.itemHeight - 1);
else if(key == K_UPARROW || key == K_KP_UPARROW)
me.scrollPos = max(me.scrollPos - me.itemHeight, 0);
else if(key == K_DOWNARROW || key == K_KP_DOWNARROW)
me.scrollPos = min(me.scrollPos + me.itemHeight, me.nItems * me.itemHeight - 1);
else
return SUPER(XonoticCreditsList).keyDown(me, key, ascii, shift);
i = min(me.selectedItem, floor((me.scrollPos + 1) / me.itemHeight - 1));
i = max(i, ceil(me.scrollPos / me.itemHeight));
me.setSelected(me, i);
return 1;
return SUPER(XonoticCreditsList).keyDown(me, key, ascii, shift);
}
#endif
......@@ -133,7 +133,6 @@ void XonoticSingleplayerDialog_fill(entity me)
me.campaignBox.buttonNext = btnNext;
me.campaignBox.buttonPrev = btnPrev;
me.campaignBox.labelTitle = lblTitle;
me.campaignBox.campaignGo(me.campaignBox, 0);
me.gotoRC(me, me.rows - 2, 0);
me.TD(me, 1, 2, e = makeXonoticTextLabel(0.5, _("Campaign Difficulty:")));
......
......@@ -121,17 +121,17 @@ void XonoticLanguageList_loadCvars(entity me)
{
if(me.languageParameter(me, i, LANGPARM_ID) == "en")
{
me.selectedItem = i;
SUPER(XonoticLanguageList).setSelected(me, i);
break;
}
}
// otherwise, find the language
// otherwise, find the language
for(i = 0; i < n; ++i)
{
if(me.languageParameter(me, i, LANGPARM_ID) == s)
{
me.selectedItem = i;
SUPER(XonoticLanguageList).setSelected(me, i);
break;
}
}
......
......@@ -17,6 +17,7 @@ CLASS(XonoticPlayerList, XonoticListBox)
METHOD(XonoticPlayerList, setPlayerList, void(entity, string))
METHOD(XonoticPlayerList, getPlayerList, string(entity, float, float))
ATTRIB(XonoticPlayerList, playerList, float, -1)
ATTRIB(XonoticPlayerList, selectionDoesntMatter, bool, true)
ENDCLASS(XonoticPlayerList)
entity makeXonoticPlayerList();
#endif
......
......@@ -29,7 +29,6 @@ CLASS(XonoticScreenshotList, XonoticListBox)
ATTRIB(XonoticScreenshotList, newScreenshotTime, float, 0)
ATTRIB(XonoticScreenshotList, newSlideShowScreenshotTime, float, 0)
ATTRIB(XonoticScreenshotList, prevSelectedItem, float, 0)
ATTRIB(XonoticScreenshotList, screenshotBrowserDialog, entity, NULL)
ATTRIB(XonoticScreenshotList, screenshotPreview, entity, NULL)
......@@ -152,13 +151,12 @@ void XonoticScreenshotList_setSelected(entity me, float i)
{
if (me.newSlideShowScreenshotTime)
me.startSlideShow(me);
me.prevSelectedItem = me.selectedItem;
float selectedItem_save = me.selectedItem;
SUPER(XonoticScreenshotList).setSelected(me, i);
if (me.pressed && me.selectedItem != me.prevSelectedItem)
if (me.pressed && me.selectedItem != selectedItem_save)
{
// while dragging the scrollbar (or an item)
// for a smooth mouse movement do not load immediately the new selected images
me.newScreenshotTime = time + 0.22; // dragging an item we need a delay > 0.2 (from listbox: me.dragScrollTimer = time + 0.2;)
// avoid immediate image loading on quick repeated selection changes
me.newScreenshotTime = time + 0.22;
}
else if (time > me.newScreenshotTime)
{
......@@ -296,8 +294,6 @@ float XonoticScreenshotList_keyDown(entity me, float scan, float ascii, float sh
me.startScreenshot(me);
return 1;
}
if(scan == K_MWHEELUP || scan == K_MWHEELDOWN)
me.newScreenshotTime = time + 0.2;
return SUPER(XonoticScreenshotList).keyDown(me, scan, ascii, shift);
}
#endif
......@@ -27,6 +27,7 @@ CLASS(XonoticServerList, XonoticListBox)
ATTRIB(XonoticServerList, columnTypeSize, float, 0)
ATTRIB(XonoticServerList, columnPlayersOrigin, float, 0)
ATTRIB(XonoticServerList, columnPlayersSize, float, 0)
ATTRIB(XonoticServerList, lockedSelectedItem, bool, true) // initially keep selected the first item of the list, avoiding an unwanted scrolling
ATTRIB(XonoticServerList, selectedServer, string, string_null) // to restore selected server when needed
METHOD(XonoticServerList, setSelected, void(entity, float))
......@@ -460,6 +461,7 @@ void XonoticServerList_configureXonoticServerList(entity me)
}
void XonoticServerList_setSelected(entity me, int i)
{
me.lockedSelectedItem = false;
//int save = me.selectedItem;
SUPER(XonoticServerList).setSelected(me, i);
/*
......@@ -717,12 +719,26 @@ void XonoticServerList_draw(entity me)
me.infoButton.disabled = ((me.nItems == 0) || !owned);
me.favoriteButton.disabled = ((me.nItems == 0) && (me.ipAddressBox.text == ""));
if(me.selectedServer)
if(me.lockedSelectedItem)
{
if(me.nItems > 0)
{
if(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem) != me.selectedServer)
{
if(me.selectedServer)
strunzone(me.selectedServer);
me.selectedServer = strzone(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem));
}
found = true;
}
}
else if(me.selectedServer)
{
for(i = 0; i < me.nItems; ++i)
{
if(gethostcachestring(SLIST_FIELD_CNAME, i) == me.selectedServer)
{
// don't follow the selected item with SUPER(XonoticServerList).setSelected(me, i);
me.selectedItem = i;
found = true;
break;
......@@ -733,8 +749,9 @@ void XonoticServerList_draw(entity me)
{
if(me.nItems > 0)
{
// selected server disappeared, select the last server (scrolling to it)
if(me.selectedItem >= me.nItems)
me.selectedItem = me.nItems - 1;
SUPER(XonoticServerList).setSelected(me, me.nItems - 1);
if(me.selectedServer)
strunzone(me.selectedServer);
me.selectedServer = strzone(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem));
......
......@@ -66,7 +66,7 @@ void XonoticSkinList_loadCvars(entity me)
{
if(me.skinParameter(me, i, SKINPARM_NAME) == s)
{
me.selectedItem = i;
me.setSelected(me, i);
break;
}
}
......
......@@ -14,6 +14,7 @@ CLASS(XonoticStatsList, XonoticListBox)
METHOD(XonoticStatsList, keyDown, float(entity, float, float, float))
METHOD(XonoticStatsList, destroy, void(entity))
METHOD(XonoticStatsList, showNotify, void(entity))
ATTRIB(XonoticStatsList, selectionDoesntMatter, bool, true)
ATTRIB(XonoticStatsList, listStats, float, -1)
ATTRIB(XonoticStatsList, realFontSize, vector, '0 0 0')
......@@ -317,9 +318,7 @@ void XonoticStatsList_resizeNotify(entity me, vector relOrigin, vector relSize,
void XonoticStatsList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
{
if(isSelected)
draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
else if(isFocused)
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);
......
......@@ -46,7 +46,7 @@ void WeaponsList_MoveUp_Click(entity box, entity me)
if(me.selectedItem > 0)
{
cvar_set("cl_weaponpriority", swapInPriorityList(cvar_string("cl_weaponpriority"), me.selectedItem - 1, me.selectedItem));
me.selectedItem -= 1;
me.setSelected(me, me.selectedItem - 1);
}
}
void WeaponsList_MoveDown_Click(entity box, entity me)
......@@ -54,7 +54,7 @@ void WeaponsList_MoveDown_Click(entity box, entity me)
if(me.selectedItem < me.nItems - 1)
{
cvar_set("cl_weaponpriority", swapInPriorityList(cvar_string("cl_weaponpriority"), me.selectedItem, me.selectedItem + 1));
me.selectedItem += 1;
me.setSelected(me, me.selectedItem + 1);
}
}
void XonoticWeaponsList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment