From 5c4203b7474df0fba76c78e4a65c26392b7c93ae Mon Sep 17 00:00:00 2001 From: Learath Date: Mon, 8 Oct 2018 18:38:22 +0300 Subject: [PATCH 1/3] Reset scroll when search text changes. Fix #1331 --- src/game/editor/editor.cpp | 4 ++++ src/game/editor/editor.h | 1 + 2 files changed, 5 insertions(+) diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index d1d6422db..9e841df15 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -4126,6 +4126,7 @@ void CEditor::RenderFileDialog() static float s_SearchBoxID = 0; UI()->DoLabel(&FileBoxLabel, "Search:", 10.0f, -1, -1); + str_copy(m_aFileDialogPrevSearchText, m_aFileDialogSearchText, sizeof(m_aFileDialogPrevSearchText)); DoEditBox(&s_SearchBoxID, &FileBox, m_aFileDialogSearchText, sizeof(m_aFileDialogSearchText), 10.0f, &s_SearchBoxID,false,CUI::CORNER_L); // clearSearchbox button @@ -4139,6 +4140,9 @@ void CEditor::RenderFileDialog() UI()->SetActiveItem(&s_SearchBoxID); } } + + if(str_comp(m_aFileDialogPrevSearchText, m_aFileDialogSearchText)) + m_FileDialogScrollValue = 0.0f; } int Num = (int)(View.h/17.0f)+1; diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index 2fb11ec80..768caa60f 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -840,6 +840,7 @@ public: char m_aFileDialogCurrentFolder[MAX_PATH_LENGTH]; char m_aFileDialogCurrentLink[MAX_PATH_LENGTH]; char m_aFileDialogSearchText[64]; + char m_aFileDialogPrevSearchText[64]; char *m_pFileDialogPath; bool m_aFileDialogActivate; int m_FileDialogFileType; From ad566aa15898a4b93b46ac4225348fb503019127 Mon Sep 17 00:00:00 2001 From: Learath Date: Mon, 8 Oct 2018 18:39:23 +0300 Subject: [PATCH 2/3] Consider the search text when counting elements --- src/game/editor/editor.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 9e841df15..259fd6138 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -4150,7 +4150,17 @@ void CEditor::RenderFileDialog() Scroll.HMargin(5.0f, &Scroll); m_FileDialogScrollValue = UiDoScrollbarV(&ScrollBar, &Scroll, m_FileDialogScrollValue); - int ScrollNum = m_FileList.size()-Num+1; + int ScrollNum = 0; + for(int i = 0; i < m_FileList.size(); i++) + { + if(!m_aFileDialogSearchText[0] || str_find_nocase(m_FileList[i].m_aName, m_aFileDialogSearchText)) + { + AddFileDialogEntry(i, &View); + ScrollNum++; + } + } + ScrollNum -= Num - 1; + if(ScrollNum > 0) { if(Input()->KeyPress(KEY_MOUSE_WHEEL_UP)) @@ -4161,6 +4171,7 @@ void CEditor::RenderFileDialog() else ScrollNum = 0; + if(m_FilesSelectedIndex > -1) { for(int i = 0; i < Input()->NumEvents(); i++) @@ -4254,10 +4265,6 @@ void CEditor::RenderFileDialog() // set clipping UI()->ClipEnable(&View); - for(int i = 0; i < m_FileList.size(); i++) - if(!m_aFileDialogSearchText[0] || str_find_nocase (m_FileList[i].m_aName, m_aFileDialogSearchText)) - AddFileDialogEntry(i, &View); - // disable clipping again UI()->ClipDisable(); From 4fedd9102061ee311075d305af69fa991fe67b19 Mon Sep 17 00:00:00 2001 From: Learath Date: Mon, 8 Oct 2018 19:07:25 +0300 Subject: [PATCH 3/3] Arrow keys should account for visibility --- src/game/editor/editor.cpp | 26 ++++++++++++++++++++++++-- src/game/editor/editor.h | 1 + 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 259fd6138..25836912d 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -4153,9 +4153,11 @@ void CEditor::RenderFileDialog() int ScrollNum = 0; for(int i = 0; i < m_FileList.size(); i++) { + m_FileList[i].m_IsVisible = false; if(!m_aFileDialogSearchText[0] || str_find_nocase(m_FileList[i].m_aName, m_aFileDialogSearchText)) { AddFileDialogEntry(i, &View); + m_FileList[i].m_IsVisible = true; ScrollNum++; } } @@ -4171,6 +4173,10 @@ void CEditor::RenderFileDialog() else ScrollNum = 0; + if(!m_FileList[m_FilesSelectedIndex].m_IsVisible) + { + m_FilesSelectedIndex = 0; + } if(m_FilesSelectedIndex > -1) { @@ -4179,8 +4185,24 @@ void CEditor::RenderFileDialog() int NewIndex = -1; if(Input()->GetEvent(i).m_Flags&IInput::FLAG_PRESS) { - if(Input()->GetEvent(i).m_Key == KEY_DOWN) NewIndex = m_FilesSelectedIndex + 1; - if(Input()->GetEvent(i).m_Key == KEY_UP) NewIndex = m_FilesSelectedIndex - 1; + if(Input()->GetEvent(i).m_Key == KEY_DOWN) + { + for(NewIndex = m_FilesSelectedIndex + 1; NewIndex < m_FileList.size(); NewIndex++) + { + if(m_FileList[NewIndex].m_IsVisible) + break; + } + dbg_msg("DEBUG", "NewIndex='%d'", NewIndex); + } + if(Input()->GetEvent(i).m_Key == KEY_UP) + { + for(NewIndex = m_FilesSelectedIndex - 1; NewIndex >= 0; NewIndex--) + { + if(m_FileList[NewIndex].m_IsVisible) + break; + } + dbg_msg("DEBUG", "NewIndex='%d'", NewIndex); + } } if(NewIndex > -1 && NewIndex < m_FileList.size()) { diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index 768caa60f..d13758349 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -859,6 +859,7 @@ public: bool m_IsDir; bool m_IsLink; int m_StorageType; + bool m_IsVisible; bool operator<(const CFilelistItem &Other) { return !str_comp(m_aFilename, "..") ? true : !str_comp(Other.m_aFilename, "..") ? false : m_IsDir && !Other.m_IsDir ? true : !m_IsDir && Other.m_IsDir ? false :