This commit is contained in:
Learath2 2018-02-13 03:44:43 +01:00
parent c0fa444f3a
commit 8cfebaa0b2
3 changed files with 19 additions and 6 deletions

View file

@ -87,7 +87,7 @@ class CMenus : public CComponent
int ItemsPerRow, int SelectedIndex, float ScrollValue);
CListboxItem UiDoListboxNextItem(const void *pID, bool Selected = false, bool KeyEvents = true);
CListboxItem UiDoListboxNextRow();
int UiDoListboxEnd(float *pScrollValue, bool *pItemActivated);
int UiDoListboxEnd(float *pScrollValue, bool *pItemActivated, bool *pListBoxActive = 0);
//static void demolist_listdir_callback(const char *name, int is_dir, void *user);
//static void demolist_list_callback(const CUIRect *rect, int index, void *user);

View file

@ -457,6 +457,7 @@ static int gs_ListBoxNumItems;
static int gs_ListBoxItemsPerRow;
static float gs_ListBoxScrollValue;
static bool gs_ListBoxItemActivated;
static bool gs_ListBoxClicked;
void CMenus::UiDoListboxStart(const void *pID, const CUIRect *pRect, float RowHeight, const char *pTitle, const char *pBottomText, int NumItems,
int ItemsPerRow, int SelectedIndex, float ScrollValue)
@ -497,6 +498,7 @@ void CMenus::UiDoListboxStart(const void *pID, const CUIRect *pRect, float RowHe
gs_ListBoxDoneEvents = 0;
gs_ListBoxScrollValue = ScrollValue;
gs_ListBoxItemActivated = false;
gs_ListBoxClicked = false;
// do the scrollbar
View.HSplitTop(gs_ListBoxRowHeight, &Row, 0);
@ -591,8 +593,10 @@ CMenus::CListboxItem CMenus::UiDoListboxNextItem(const void *pId, bool Selected,
CListboxItem Item = UiDoListboxNextRow();
if(Item.m_Visible && UI()->DoButtonLogic(pId, "", gs_ListBoxSelectedIndex == gs_ListBoxItemIndex, &Item.m_HitRect))
if(Item.m_Visible && UI()->DoButtonLogic(pId, "", gs_ListBoxSelectedIndex == gs_ListBoxItemIndex, &Item.m_HitRect)){
gs_ListBoxClicked = true;
gs_ListBoxNewSelected = ThisItemIndex;
}
// process input, regard selected index
if(gs_ListBoxSelectedIndex == ThisItemIndex)
@ -601,7 +605,6 @@ CMenus::CListboxItem CMenus::UiDoListboxNextItem(const void *pId, bool Selected,
{
gs_ListBoxDoneEvents = 1;
if(m_EnterPressed || (UI()->ActiveItem() == pId && Input()->MouseDoubleClick()))
{
gs_ListBoxItemActivated = true;
@ -661,13 +664,15 @@ CMenus::CListboxItem CMenus::UiDoListboxNextItem(const void *pId, bool Selected,
return Item;
}
int CMenus::UiDoListboxEnd(float *pScrollValue, bool *pItemActivated)
int CMenus::UiDoListboxEnd(float *pScrollValue, bool *pItemActivated, bool *pListBoxActive)
{
UI()->ClipDisable();
if(pScrollValue)
*pScrollValue = gs_ListBoxScrollValue;
if(pItemActivated)
*pItemActivated = gs_ListBoxItemActivated;
if(pListBoxActive)
*pListBoxActive = gs_ListBoxClicked;
return gs_ListBoxNewSelected;
}

View file

@ -330,6 +330,10 @@ void CMenus::RenderSettingsPlayer(CUIRect MainView)
m_NeedSendinfo = true;
}
static bool s_ListBoxUsed = false;
if(UI()->ActiveItem() == Clan || UI()->ActiveItem() == Name)
s_ListBoxUsed = false;
// country flag selector
MainView.HSplitTop(20.0f, 0, &MainView);
static float s_ScrollValue = 0.0f;
@ -342,7 +346,7 @@ void CMenus::RenderSettingsPlayer(CUIRect MainView)
if(pEntry->m_CountryCode == *Country)
OldSelected = i;
CListboxItem Item = UiDoListboxNextItem(&pEntry->m_CountryCode, OldSelected == i);
CListboxItem Item = UiDoListboxNextItem(&pEntry->m_CountryCode, OldSelected == i, s_ListBoxUsed);
if(Item.m_Visible)
{
CUIRect Label;
@ -358,7 +362,11 @@ void CMenus::RenderSettingsPlayer(CUIRect MainView)
}
}
const int NewSelected = UiDoListboxEnd(&s_ScrollValue, 0);
bool Clicked = false;
const int NewSelected = UiDoListboxEnd(&s_ScrollValue, 0, &Clicked);
if(Clicked)
s_ListBoxUsed = true;
if(OldSelected != NewSelected)
{
*Country = m_pClient->m_pCountryFlags->GetByIndex(NewSelected)->m_CountryCode;