From 31bc740f4b8d84cc5de89546dd443ae6777b20f0 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Wed, 15 Jul 2015 19:08:45 +0200 Subject: [PATCH] Fix focusing issues with controls and cheat console --- src/object/robotmain.cpp | 5 ++++- src/script/script.cpp | 10 +++++----- src/ui/displayinfo.cpp | 2 +- src/ui/editvalue.cpp | 11 +++++++++-- src/ui/editvalue.h | 3 +++ src/ui/interface.cpp | 17 ++++++++++++++++- src/ui/interface.h | 2 ++ src/ui/maindialog.cpp | 6 +++--- src/ui/studio.cpp | 4 ++-- 9 files changed, 45 insertions(+), 15 deletions(-) diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index dc6e5af3..6f4e098f 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -711,7 +711,7 @@ bool CRobotMain::ProcessEvent(Event &event) Ui::CEdit* pe = static_cast(m_interface->SearchControl(EVENT_CMD)); if (pe == nullptr) return false; pe->SetState(Ui::STATE_VISIBLE); - pe->SetFocus(true); + m_interface->SetFocus(pe); if (m_phase == PHASE_SIMUL) ChangePause(PAUSE_CHEAT); m_cmdEdit = true; } @@ -732,6 +732,9 @@ bool CRobotMain::ProcessEvent(Event &event) return false; } + if (event.type == EVENT_KEY_DOWN && m_cmdEdit) + return false; // cheat console active, so ignore keys + // Management of the speed change. if (event.type == EVENT_SPEED) SetSpeed(1.0f); diff --git a/src/script/script.cpp b/src/script/script.cpp index 34e34251..f8e59e16 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -109,7 +109,7 @@ void CScript::PutScript(Ui::CEdit* edit, const char* name) edit->SetCursor(m_cursor2, m_cursor1); edit->ShowSelect(); } - edit->SetFocus(true); + m_interface->SetFocus(edit); } // The script takes a paved text. @@ -132,7 +132,7 @@ bool CScript::GetScript(Ui::CEdit* edit) { edit->SetCursor(m_cursor2, m_cursor1); edit->ShowSelect(); - edit->SetFocus(true); + m_interface->SetFocus(edit); return false; } @@ -140,7 +140,7 @@ bool CScript::GetScript(Ui::CEdit* edit) { edit->SetCursor(m_cursor2, m_cursor1); edit->ShowSelect(); - edit->SetFocus(true); + m_interface->SetFocus(edit); return false; } @@ -912,7 +912,7 @@ void CScript::New(Ui::CEdit* edit, const char* name) edit->SetCursor(cursor2, cursor1); edit->ShowSelect(); - edit->SetFocus(true); + m_interface->SetFocus(edit); sf = m_main->GetScriptFile(); if ( sf[0] != 0 ) // Load an empty program specific? @@ -973,7 +973,7 @@ void CScript::New(Ui::CEdit* edit, const char* name) cursor2 = cursor1; edit->SetCursor(cursor2, cursor1); edit->ShowSelect(); - edit->SetFocus(true); + m_interface->SetFocus(edit); } } diff --git a/src/ui/displayinfo.cpp b/src/ui/displayinfo.cpp index a3e09387..2cbbf7f7 100644 --- a/src/ui/displayinfo.cpp +++ b/src/ui/displayinfo.cpp @@ -384,7 +384,7 @@ void CDisplayInfo::StartDisplayInfo(std::string filename, int index, bool bSoluc edit->HyperHome(filename.c_str()); edit->SetEditCap(false); // just to see! edit->SetHighlightCap(false); - edit->SetFocus(true); + m_interface->SetFocus(edit); ViewDisplayInfo(); diff --git a/src/ui/editvalue.cpp b/src/ui/editvalue.cpp index 676f2a6b..3d12792b 100644 --- a/src/ui/editvalue.cpp +++ b/src/ui/editvalue.cpp @@ -25,7 +25,7 @@ #include "ui/edit.h" #include "ui/button.h" - +#include "ui/interface.h" @@ -42,6 +42,8 @@ CEditValue::CEditValue() : CControl () m_stepValue = 0.1f; // 10% m_minValue = 0.0f; // 0% m_maxValue = 1.0f; // 100% + + m_interface = nullptr; } // Object's destructor. @@ -228,7 +230,7 @@ void CEditValue::HiliteValue(const Event &event) } m_edit->SetCursor(pos, 0); - m_edit->SetFocus(true); + m_interface->SetFocus(m_edit); Event newEvent = event; newEvent.type = EVENT_FOCUS; @@ -370,5 +372,10 @@ float CEditValue::GetMaxValue() return m_maxValue; } +void CEditValue::SetInterface(CInterface* interface) +{ + m_interface = interface; +} + } diff --git a/src/ui/editvalue.h b/src/ui/editvalue.h index 3011d556..af9bea0f 100644 --- a/src/ui/editvalue.h +++ b/src/ui/editvalue.h @@ -72,10 +72,13 @@ public: void SetMaxValue(float value); float GetMaxValue(); + void SetInterface(Ui::CInterface* interface); + protected: void MoveAdjust(); void HiliteValue(const Event &event); + Ui::CInterface* m_interface; Ui::CEdit* m_edit; Ui::CButton* m_buttonUp; Ui::CButton* m_buttonDown; diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index bd25bee1..bd59852a 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -181,7 +181,9 @@ CEdit* CInterface::CreateEdit(Math::Point pos, Math::Point dim, int icon, EventT CEditValue* CInterface::CreateEditValue(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) { - return CreateControl(pos, dim, icon, eventMsg); + CEditValue* ev = CreateControl(pos, dim, icon, eventMsg); + ev->SetInterface(this); + return ev; } // Creates a new lift. @@ -332,5 +334,18 @@ void CInterface::Draw() } } +void CInterface::SetFocus(CControl* control) +{ + for (int i = 0; i < MAXCONTROL; i++) + { + if (m_table[i] != nullptr) + { + bool focus = m_table[i] == control; + m_table[i]->SetFocus(focus); + } + } +} + + } // namespace Ui diff --git a/src/ui/interface.h b/src/ui/interface.h index f3e81bbe..3747d3e0 100644 --- a/src/ui/interface.h +++ b/src/ui/interface.h @@ -89,6 +89,8 @@ public: void Draw(); + void SetFocus(CControl* control); + protected: int GetNextFreeControl(); template inline T* CreateControl(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index fa5b8051..501e209f 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -430,7 +430,7 @@ void CMainDialog::ChangePhase(Phase phase) } pe->SetText(name.c_str()); pe->SetCursor(name.length(), 0); - pe->SetFocus(true); + m_interface->SetFocus(pe); pos.x = 380.0f/640.0f; pos.y = 320.0f/480.0f; @@ -3624,7 +3624,7 @@ void CMainDialog::NameCreate() m_sound->Play(SOUND_TZOING); pe->SetText(name); pe->SetCursor(strlen(name), 0); - pe->SetFocus(true); + m_interface->SetFocus(pe); return; } @@ -4011,7 +4011,7 @@ void CMainDialog::IOReadName() pe->SetText(name); pe->SetCursor(strlen(name), 0); - pe->SetFocus(true); + m_interface->SetFocus(pe); } // Updates the list of games recorded on disk. diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp index ada6f81d..3b55591f 100644 --- a/src/ui/studio.cpp +++ b/src/ui/studio.cpp @@ -1168,7 +1168,7 @@ void CStudio::StartDialog(StudioDialog type) } pe->SetCursor(999, 0); // selects all - pe->SetFocus(true); + m_interface->SetFocus(pe); } m_main->SetSatComLock(true); // impossible to use the SatCom @@ -1430,7 +1430,7 @@ void CStudio::UpdateChangeList() name = name.substr(0, name.find_first_of("\t")); SetFilenameField(pe, name); pe->SetCursor(999, 0); // selects all - pe->SetFocus(true); + m_interface->SetFocus(pe); UpdateDialogAction(); }