Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: teeworlds/teeworlds
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: cf79fcc86893
Choose a base ref
...
head repository: teeworlds/teeworlds
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: efecf3371de4
Choose a head ref
  • 6 commits
  • 1 file changed
  • 2 contributors

Commits on Nov 1, 2018

  1. Copy the full SHA
    06c0c1a View commit details

Commits on Nov 2, 2018

  1. Copy the full SHA
    61f4654 View commit details

Commits on Nov 15, 2018

  1. Merge with master

    Dune-jr committed Nov 15, 2018
    Copy the full SHA
    250a4c9 View commit details
  2. Fix up&down key behavior for the server browser scrollbars, make UI c…

    …ode more readable, clean up useless parts and convoluted computations.
    Dune-jr committed Nov 15, 2018
    Copy the full SHA
    7f725f1 View commit details
  3. Copy the full SHA
    085fbd8 View commit details

Commits on Nov 16, 2018

  1. Merge pull request #1598 from Dune-jr/fix-browserscroll

    Fix server&friend browser spacing and scrolling
    oy authored Nov 16, 2018

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    efecf33 View commit details
Showing with 69 additions and 87 deletions.
  1. +69 −87 src/game/client/components/menus_browser.cpp
156 changes: 69 additions & 87 deletions src/game/client/components/menus_browser.cpp
Original file line number Diff line number Diff line change
@@ -1069,8 +1069,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
RenderTools()->DrawUIRect(&Rect, vec4(0.0f, 0.0f, 0.0f, 0.05f), CUI::CORNER_ALL, 5.0f);
}

// display important messages in the middle of the screen so no
// users misses it
// display important messages in the middle of the screen so no user misses it
{
CUIRect MsgBox = View;
MsgBox.y += View.h/3;
@@ -1090,24 +1089,23 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
NumServers += m_lFilters[i].NumSortedServers();

int NumFilters = m_lFilters.size();
float ListHeight = (NumServers+(NumFilters-1)) * ms_aBrowserCols[0].m_Rect.h + NumFilters * 20.0f;
float ListHeight = NumServers * ms_ListheaderHeight; // add server list height
ListHeight += NumFilters * SpacingH; // add filters
ListHeight += (NumFilters) * ButtonHeight;// add filters spacing

//int Num = (int)((ListHeight-View.h)/ms_aBrowserCols[0].m_Rect.h))+1;
//int Num = (int)(View.h/ms_aBrowserCols[0].m_Rect.h) + 1;
// float LineH = ms_aBrowserCols[0].m_Rect.h;
float LineH = ms_ListheaderHeight;
static int s_ScrollBar = 0;
static float s_ScrollValue = 0;

Scroll.HMargin(5.0f, &Scroll);
s_ScrollValue = DoScrollbarV(&s_ScrollBar, &Scroll, s_ScrollValue);

int ScrollNum = (int)((ListHeight-View.h)/ms_aBrowserCols[0].m_Rect.h)+(m_SidebarActive?1:4);
// (int)+1 is to keep the first item right on top
// but it doesn't work because of filters, we should detect & remove the filters that are displayed beforehand
int ScrollNum = ceil((ListHeight-View.h)/LineH);
if(ScrollNum > 0)
{
/*if(m_ScrollOffset)
{
s_ScrollValue = (float)(m_ScrollOffset)/ScrollNum;
m_ScrollOffset = 0;
}*/
if(Input()->KeyPress(KEY_MOUSE_WHEEL_UP) && UI()->MouseInside(&View))
s_ScrollValue -= 3.0f/ScrollNum;
if(Input()->KeyPress(KEY_MOUSE_WHEEL_DOWN) && UI()->MouseInside(&View))
@@ -1116,77 +1114,71 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
else
ScrollNum = 0;

int SelectedFilter = m_SelectedServer.m_Filter;
int SelectedIndex = m_SelectedServer.m_Index;
int SelectedFilter;
for(SelectedFilter = 0; SelectedFilter < m_lFilters.size(); SelectedFilter++)
if(m_lFilters[SelectedFilter].Extended())
break;
if(SelectedFilter == m_lFilters.size()) // no selected filter found
SelectedFilter = 0;

if(SelectedFilter > -1)
{
int NewIndex = -1;
int NewFilter = SelectedFilter;
bool CtrlPressed = Input()->KeyIsPressed(KEY_LCTRL) || Input()->KeyIsPressed(KEY_RCTRL);
if(m_DownArrowPressed)
{
NewIndex = SelectedIndex + 1;
if(NewIndex >= m_lFilters[SelectedFilter].NumSortedServers())
if(!CtrlPressed)
{
// try to move to next filter
for(int j = SelectedFilter+1; j < m_lFilters.size(); j++)
{
CBrowserFilter *pFilter = &m_lFilters[j];
if(pFilter->Extended() && pFilter->NumSortedServers())
{
NewFilter = j;
NewIndex = 0;
break;
}
}
NewIndex = SelectedIndex + 1;
// if(NewIndex >= NumServers)
if(NewIndex >= m_lFilters[SelectedFilter].NumSortedServers())
NewIndex = m_lFilters[SelectedFilter].NumSortedServers() - 1;
}
else if(SelectedFilter + 1 < m_lFilters.size())
{
// move to next filter
NewFilter = SelectedFilter + 1;
NewIndex = 0;
}
}
else if(m_UpArrowPressed)
{
NewIndex = SelectedIndex - 1;
if(NewIndex < 0)
if(!CtrlPressed)
{
// try to move to prev filter
for(int j = SelectedFilter-1; j >= 0; j--)
{
CBrowserFilter *pFilter = &m_lFilters[j];
if(pFilter->Extended() && pFilter->NumSortedServers())
{
NewFilter = j;
NewIndex = pFilter->NumSortedServers()-1;
break;
}
}
NewIndex = SelectedIndex - 1;
if(NewIndex < 0)
NewIndex = 0;
}
else if(SelectedFilter - 1 >= 0)
{
// move to previous filter
NewFilter = SelectedFilter - 1;
NewIndex = 0;
}
}
if(NewFilter != SelectedFilter)
{
m_lFilters[NewFilter].Switch();
m_lFilters[SelectedFilter].Switch();
}

if(NewIndex > -1 && NewIndex < m_lFilters[NewFilter].NumSortedServers())
{
// get index depending on all filters
int TotalIndex = 0;
int Filter = 0;
while(Filter != NewFilter)
float CurViewY = (s_ScrollValue*ScrollNum*LineH);
float IndexY = NewIndex*LineH + (NewFilter+1)*(SpacingH+ButtonHeight); // this represents the Y position of the selected line

// Selected line = [IndexY,IndexY+LineH] must be in screen = [CurViewY,CurViewY+View.h].
if(IndexY < CurViewY) // scroll up
{
CBrowserFilter *pFilter = &m_lFilters[Filter];
if(pFilter->Extended())
TotalIndex += m_lFilters[Filter].NumSortedServers();
Filter++;
int NumScrolls = ceil((CurViewY-IndexY)/LineH);
s_ScrollValue -= NumScrolls/((float)ScrollNum);
}
TotalIndex += NewIndex+1;

//scroll
float IndexY = View.y - s_ScrollValue*ScrollNum*ms_aBrowserCols[0].m_Rect.h + TotalIndex*ms_aBrowserCols[0].m_Rect.h + Filter*ms_aBrowserCols[0].m_Rect.h + Filter*20.0f;
int Scroll = View.y > IndexY ? -1 : View.y+View.h < IndexY+ms_aBrowserCols[0].m_Rect.h ? 1 : 0;
if(Scroll)
if(IndexY+LineH > CurViewY+View.h) // scroll down
{
if(Scroll < 0)
{
int NumScrolls = (View.y-IndexY+ms_aBrowserCols[0].m_Rect.h-1.0f)/ms_aBrowserCols[0].m_Rect.h;
s_ScrollValue -= (1.0f/ScrollNum)*NumScrolls;
}
else
{
int NumScrolls = (IndexY+ms_aBrowserCols[0].m_Rect.h-(View.y+View.h)+ms_aBrowserCols[0].m_Rect.h-1.0f)/ms_aBrowserCols[0].m_Rect.h;
s_ScrollValue += (1.0f/ScrollNum)*NumScrolls;
}
int NumScrolls = ceil( ((IndexY+LineH)-(CurViewY+View.h)) / LineH);
s_ScrollValue += NumScrolls/((float)ScrollNum);
}

m_SelectedServer.m_Filter = NewFilter;
@@ -1204,7 +1196,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
UI()->ClipEnable(&View);

CUIRect OriginalView = View;
View.y -= s_ScrollValue*ScrollNum*ms_aBrowserCols[0].m_Rect.h;
View.y -= s_ScrollValue*ScrollNum*LineH;

int NumPlayers = ServerBrowser()->NumPlayers();

@@ -1486,7 +1478,7 @@ void CMenus::RenderDetailInfo(CUIRect View, const CServerInfo *pInfo)
void CMenus::RenderDetailScoreboard(CUIRect View, const CServerInfo *pInfo, int Column)
{
// server scoreboard
CUIRect ServerHeader;
// CUIRect ServerHeader;
CTextCursor Cursor;
const float FontSize = 10.0f;
int ActColumn = 0;
@@ -1935,24 +1927,18 @@ void CMenus::RenderServerbrowserFriendList(CUIRect View)
}
}

float ListHeight = ms_aBrowserCols[0].m_Rect.h + NumEntries * 20.0f + ClanEntries * 20.0f;
float ListHeight = (NumEntries+ClanEntries) * ms_ListheaderHeight;

//int Num = (int)((ListHeight-View.h)/ms_aBrowserCols[0].m_Rect.h))+1;
//int Num = (int)(View.h/ms_aBrowserCols[0].m_Rect.h) + 1;
float LineH = ms_aFriendCols[0].m_Rect.h;
static int s_ScrollBar = 0;
static float s_ScrollValue = 0;

Scroll.HMargin(5.0f, &Scroll);
s_ScrollValue = DoScrollbarV(&s_ScrollBar, &Scroll, s_ScrollValue);

int ScrollNum = (int)((ListHeight - View.h) / ms_aBrowserCols[0].m_Rect.h) + 1;
int ScrollNum = (int)((ListHeight - View.h) / LineH) + 1;
if(ScrollNum > 0)
{
/*if(m_ScrollOffset)
{
s_ScrollValue = (float)(m_ScrollOffset) / ScrollNum;
m_ScrollOffset = 0;
}*/
if(Input()->KeyPress(KEY_MOUSE_WHEEL_UP) && UI()->MouseInside(&View))
s_ScrollValue -= 3.0f / ScrollNum;
if(Input()->KeyPress(KEY_MOUSE_WHEEL_DOWN) && UI()->MouseInside(&View))
@@ -1980,20 +1966,16 @@ void CMenus::RenderServerbrowserFriendList(CUIRect View)
if(NewIndex > -1 && NewIndex < NumEntries)
{
//scroll
float IndexY = View.y - s_ScrollValue * ScrollNum*ms_aFriendCols[0].m_Rect.h + NewIndex * ms_aFriendCols[0].m_Rect.h;
int Scroll = View.y > IndexY ? -1 : View.y + View.h < IndexY + ms_aFriendCols[0].m_Rect.h ? 1 : 0;
if(Scroll)
float IndexY = View.y - s_ScrollValue*ScrollNum*LineH + NewIndex*LineH;
if(View.y > IndexY) // scroll up
{
if(Scroll < 0)
{
int NumScrolls = (View.y - IndexY + ms_aFriendCols[0].m_Rect.h - 1.0f) / ms_aFriendCols[0].m_Rect.h;
s_ScrollValue -= (1.0f / ScrollNum)*NumScrolls;
}
else
{
int NumScrolls = (IndexY + ms_aFriendCols[0].m_Rect.h - (View.y + View.h) + ms_aFriendCols[0].m_Rect.h - 1.0f) / ms_aFriendCols[0].m_Rect.h;
s_ScrollValue += (1.0f / ScrollNum)*NumScrolls;
}
int NumScrolls = ceil((View.y - IndexY) / LineH);
s_ScrollValue -= NumScrolls/((float)ScrollNum);
}
if(View.y + View.h < IndexY + LineH) // scroll down
{
int NumScrolls = ceil((IndexY + LineH - (View.y + View.h)) / LineH);
s_ScrollValue += NumScrolls/((float)ScrollNum);
}

m_FriendlistSelectedIndex = NewIndex;
@@ -2024,7 +2006,7 @@ void CMenus::RenderServerbrowserFriendList(CUIRect View)
UI()->ClipEnable(&View);

CUIRect OriginalView = View;
View.y -= s_ScrollValue * ScrollNum*ms_aFriendCols[0].m_Rect.h;
View.y -= s_ScrollValue * ScrollNum*LineH;

int Items = 0;
for(int i = 0; i < NumFriends; i++)