6837: Fix editor hotkeys triggering while some editboxes are active r=def- a=Robyt3

Replace `CEditor::m_EditBoxActive` which only works with editboxes created from the editor with `CLineInput::GetActiveInput` which also works for editboxes which are created by generic UI functions, e.g. the value selector editboxes of color pickers.

## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
This commit is contained in:
bors[bot] 2023-07-12 23:20:50 +00:00 committed by GitHub
commit 573d9cabbe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 72 additions and 73 deletions

View file

@ -317,16 +317,12 @@ void CEditor::EnvelopeEval(int TimeOffsetMillis, int Env, ColorRGBA &Channels, v
bool CEditor::DoEditBox(CLineInput *pLineInput, const CUIRect *pRect, float FontSize, int Corners, const char *pToolTip) bool CEditor::DoEditBox(CLineInput *pLineInput, const CUIRect *pRect, float FontSize, int Corners, const char *pToolTip)
{ {
if(UI()->LastActiveItem() == pLineInput)
m_EditBoxActive = 2;
UpdateTooltip(pLineInput, pRect, pToolTip); UpdateTooltip(pLineInput, pRect, pToolTip);
return UI()->DoEditBox(pLineInput, pRect, FontSize, Corners); return UI()->DoEditBox(pLineInput, pRect, FontSize, Corners);
} }
bool CEditor::DoClearableEditBox(CLineInput *pLineInput, const CUIRect *pRect, float FontSize, int Corners, const char *pToolTip) bool CEditor::DoClearableEditBox(CLineInput *pLineInput, const CUIRect *pRect, float FontSize, int Corners, const char *pToolTip)
{ {
if(UI()->LastActiveItem() == pLineInput)
m_EditBoxActive = 2;
UpdateTooltip(pLineInput, pRect, pToolTip); UpdateTooltip(pLineInput, pRect, pToolTip);
return UI()->DoClearableEditBox(pLineInput, pRect, FontSize, Corners); return UI()->DoClearableEditBox(pLineInput, pRect, FontSize, Corners);
} }
@ -912,7 +908,7 @@ void CEditor::DoToolbarLayers(CUIRect ToolBar)
const bool ShiftPressed = Input()->ShiftIsPressed(); const bool ShiftPressed = Input()->ShiftIsPressed();
// handle shortcut for info button // handle shortcut for info button
if(m_Dialog == DIALOG_NONE && m_EditBoxActive == 0 && Input()->KeyPress(KEY_I) && ModPressed && !ShiftPressed) if(m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && Input()->KeyPress(KEY_I) && ModPressed && !ShiftPressed)
{ {
if(m_ShowTileInfo == SHOW_TILE_HEXADECIMAL) if(m_ShowTileInfo == SHOW_TILE_HEXADECIMAL)
m_ShowTileInfo = SHOW_TILE_DECIMAL; m_ShowTileInfo = SHOW_TILE_DECIMAL;
@ -924,14 +920,14 @@ void CEditor::DoToolbarLayers(CUIRect ToolBar)
} }
// handle shortcut for hex button // handle shortcut for hex button
if(m_Dialog == DIALOG_NONE && m_EditBoxActive == 0 && Input()->KeyPress(KEY_I) && ModPressed && ShiftPressed) if(m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && Input()->KeyPress(KEY_I) && ModPressed && ShiftPressed)
{ {
m_ShowTileInfo = m_ShowTileInfo == SHOW_TILE_HEXADECIMAL ? SHOW_TILE_OFF : SHOW_TILE_HEXADECIMAL; m_ShowTileInfo = m_ShowTileInfo == SHOW_TILE_HEXADECIMAL ? SHOW_TILE_OFF : SHOW_TILE_HEXADECIMAL;
m_ShowEnvelopePreview = SHOWENV_NONE; m_ShowEnvelopePreview = SHOWENV_NONE;
} }
// handle shortcut for unused button // handle shortcut for unused button
if(m_Dialog == DIALOG_NONE && m_EditBoxActive == 0 && Input()->KeyPress(KEY_U) && ModPressed) if(m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && Input()->KeyPress(KEY_U) && ModPressed)
m_AllowPlaceUnusedTiles = !m_AllowPlaceUnusedTiles; m_AllowPlaceUnusedTiles = !m_AllowPlaceUnusedTiles;
CUIRect TB_Top, TB_Bottom; CUIRect TB_Top, TB_Bottom;
@ -945,7 +941,7 @@ void CEditor::DoToolbarLayers(CUIRect ToolBar)
TB_Top.VSplitLeft(40.0f, &Button, &TB_Top); TB_Top.VSplitLeft(40.0f, &Button, &TB_Top);
static int s_HqButton = 0; static int s_HqButton = 0;
if(DoButton_Editor(&s_HqButton, "HD", m_ShowDetail, &Button, 0, "[ctrl+h] Toggle High Detail") || if(DoButton_Editor(&s_HqButton, "HD", m_ShowDetail, &Button, 0, "[ctrl+h] Toggle High Detail") ||
(m_Dialog == DIALOG_NONE && m_EditBoxActive == 0 && Input()->KeyPress(KEY_H) && ModPressed)) (m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && Input()->KeyPress(KEY_H) && ModPressed))
{ {
m_ShowDetail = !m_ShowDetail; m_ShowDetail = !m_ShowDetail;
} }
@ -956,7 +952,7 @@ void CEditor::DoToolbarLayers(CUIRect ToolBar)
TB_Top.VSplitLeft(40.0f, &Button, &TB_Top); TB_Top.VSplitLeft(40.0f, &Button, &TB_Top);
static int s_AnimateButton = 0; static int s_AnimateButton = 0;
if(DoButton_Editor(&s_AnimateButton, "Anim", m_Animate, &Button, 0, "[ctrl+m] Toggle animation") || if(DoButton_Editor(&s_AnimateButton, "Anim", m_Animate, &Button, 0, "[ctrl+m] Toggle animation") ||
(m_Dialog == DIALOG_NONE && m_EditBoxActive == 0 && Input()->KeyPress(KEY_M) && ModPressed)) (m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && Input()->KeyPress(KEY_M) && ModPressed))
{ {
m_AnimateStart = time_get(); m_AnimateStart = time_get();
m_Animate = !m_Animate; m_Animate = !m_Animate;
@ -968,7 +964,7 @@ void CEditor::DoToolbarLayers(CUIRect ToolBar)
TB_Top.VSplitLeft(40.0f, &Button, &TB_Top); TB_Top.VSplitLeft(40.0f, &Button, &TB_Top);
static int s_ProofButton = 0; static int s_ProofButton = 0;
if(DoButton_Ex(&s_ProofButton, "Proof", m_ProofBorders != PROOF_BORDER_OFF, &Button, 0, "[ctrl+p] Toggles proof borders. These borders represent what a player maximum can see.", IGraphics::CORNER_L) || if(DoButton_Ex(&s_ProofButton, "Proof", m_ProofBorders != PROOF_BORDER_OFF, &Button, 0, "[ctrl+p] Toggles proof borders. These borders represent what a player maximum can see.", IGraphics::CORNER_L) ||
(m_Dialog == DIALOG_NONE && m_EditBoxActive == 0 && Input()->KeyPress(KEY_P) && ModPressed)) (m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && Input()->KeyPress(KEY_P) && ModPressed))
{ {
m_ProofBorders = m_ProofBorders == PROOF_BORDER_OFF ? PROOF_BORDER_INGAME : PROOF_BORDER_OFF; m_ProofBorders = m_ProofBorders == PROOF_BORDER_OFF ? PROOF_BORDER_INGAME : PROOF_BORDER_OFF;
} }
@ -997,7 +993,7 @@ void CEditor::DoToolbarLayers(CUIRect ToolBar)
TB_Top.VSplitLeft(40.0f, &Button, &TB_Top); TB_Top.VSplitLeft(40.0f, &Button, &TB_Top);
static int s_GridButton = 0; static int s_GridButton = 0;
if(DoButton_Editor(&s_GridButton, "Grid", m_GridActive, &Button, 0, "[ctrl+g] Toggle Grid") || if(DoButton_Editor(&s_GridButton, "Grid", m_GridActive, &Button, 0, "[ctrl+g] Toggle Grid") ||
(m_Dialog == DIALOG_NONE && m_EditBoxActive == 0 && Input()->KeyPress(KEY_G) && ModPressed && !ShiftPressed)) (m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && Input()->KeyPress(KEY_G) && ModPressed && !ShiftPressed))
{ {
m_GridActive = !m_GridActive; m_GridActive = !m_GridActive;
} }
@ -1037,7 +1033,7 @@ void CEditor::DoToolbarLayers(CUIRect ToolBar)
// flip buttons // flip buttons
TB_Top.VSplitLeft(25.0f, &Button, &TB_Top); TB_Top.VSplitLeft(25.0f, &Button, &TB_Top);
static int s_FlipXButton = 0; static int s_FlipXButton = 0;
if(DoButton_FontIcon(&s_FlipXButton, FONT_ICON_ARROWS_LEFT_RIGHT, Enabled, &Button, 0, "[N] Flip brush horizontal", IGraphics::CORNER_L) || (Input()->KeyPress(KEY_N) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) if(DoButton_FontIcon(&s_FlipXButton, FONT_ICON_ARROWS_LEFT_RIGHT, Enabled, &Button, 0, "[N] Flip brush horizontal", IGraphics::CORNER_L) || (Input()->KeyPress(KEY_N) && m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr))
{ {
for(auto &pLayer : m_Brush.m_vpLayers) for(auto &pLayer : m_Brush.m_vpLayers)
pLayer->BrushFlipX(); pLayer->BrushFlipX();
@ -1045,7 +1041,7 @@ void CEditor::DoToolbarLayers(CUIRect ToolBar)
TB_Top.VSplitLeft(25.0f, &Button, &TB_Top); TB_Top.VSplitLeft(25.0f, &Button, &TB_Top);
static int s_FlipyButton = 0; static int s_FlipyButton = 0;
if(DoButton_FontIcon(&s_FlipyButton, FONT_ICON_ARROWS_UP_DOWN, Enabled, &Button, 0, "[M] Flip brush vertical", IGraphics::CORNER_R) || (Input()->KeyPress(KEY_M) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) if(DoButton_FontIcon(&s_FlipyButton, FONT_ICON_ARROWS_UP_DOWN, Enabled, &Button, 0, "[M] Flip brush vertical", IGraphics::CORNER_R) || (Input()->KeyPress(KEY_M) && m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr))
{ {
for(auto &pLayer : m_Brush.m_vpLayers) for(auto &pLayer : m_Brush.m_vpLayers)
pLayer->BrushFlipY(); pLayer->BrushFlipY();
@ -1066,7 +1062,7 @@ void CEditor::DoToolbarLayers(CUIRect ToolBar)
} }
static int s_CcwButton = 0; static int s_CcwButton = 0;
if(DoButton_FontIcon(&s_CcwButton, FONT_ICON_ARROW_ROTATE_LEFT, Enabled, &Button, 0, "[R] Rotates the brush counter clockwise", IGraphics::CORNER_ALL) || (Input()->KeyPress(KEY_R) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) if(DoButton_FontIcon(&s_CcwButton, FONT_ICON_ARROW_ROTATE_LEFT, Enabled, &Button, 0, "[R] Rotates the brush counter clockwise", IGraphics::CORNER_ALL) || (Input()->KeyPress(KEY_R) && m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr))
{ {
for(auto &pLayer : m_Brush.m_vpLayers) for(auto &pLayer : m_Brush.m_vpLayers)
pLayer->BrushRotate(-s_RotationAmount / 360.0f * pi * 2); pLayer->BrushRotate(-s_RotationAmount / 360.0f * pi * 2);
@ -1077,7 +1073,7 @@ void CEditor::DoToolbarLayers(CUIRect ToolBar)
TB_Top.VSplitLeft(25.0f, &Button, &TB_Top); TB_Top.VSplitLeft(25.0f, &Button, &TB_Top);
static int s_CwButton = 0; static int s_CwButton = 0;
if(DoButton_FontIcon(&s_CwButton, FONT_ICON_ARROW_ROTATE_RIGHT, Enabled, &Button, 0, "[T] Rotates the brush clockwise", IGraphics::CORNER_ALL) || (Input()->KeyPress(KEY_T) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) if(DoButton_FontIcon(&s_CwButton, FONT_ICON_ARROW_ROTATE_RIGHT, Enabled, &Button, 0, "[T] Rotates the brush clockwise", IGraphics::CORNER_ALL) || (Input()->KeyPress(KEY_T) && m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr))
{ {
for(auto &pLayer : m_Brush.m_vpLayers) for(auto &pLayer : m_Brush.m_vpLayers)
pLayer->BrushRotate(s_RotationAmount / 360.0f * pi * 2); pLayer->BrushRotate(s_RotationAmount / 360.0f * pi * 2);
@ -1158,7 +1154,7 @@ void CEditor::DoToolbarLayers(CUIRect ToolBar)
else else
FocusButtonChecked = 1; FocusButtonChecked = 1;
} }
if(DoButton_Editor(&s_RefocusButton, "Refocus", FocusButtonChecked, &Button, 0, "[HOME] Restore map focus") || (m_Dialog == DIALOG_NONE && m_EditBoxActive == 0 && Input()->KeyPress(KEY_HOME))) if(DoButton_Editor(&s_RefocusButton, "Refocus", FocusButtonChecked, &Button, 0, "[HOME] Restore map focus") || (m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && Input()->KeyPress(KEY_HOME)))
{ {
if(m_ProofBorders == PROOF_BORDER_MENU) if(m_ProofBorders == PROOF_BORDER_MENU)
{ {
@ -1216,7 +1212,7 @@ void CEditor::DoToolbarLayers(CUIRect ToolBar)
TB_Bottom.VSplitLeft(60.0f, &Button, &TB_Bottom); TB_Bottom.VSplitLeft(60.0f, &Button, &TB_Bottom);
static int s_ModifierButton = 0; static int s_ModifierButton = 0;
if(DoButton_Ex(&s_ModifierButton, pButtonName, 0, &Button, 0, s_aButtonTooltip, IGraphics::CORNER_ALL) || (m_Dialog == DIALOG_NONE && m_EditBoxActive == 0 && ModPressed && Input()->KeyPress(KEY_T))) if(DoButton_Ex(&s_ModifierButton, pButtonName, 0, &Button, 0, s_aButtonTooltip, IGraphics::CORNER_ALL) || (m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && ModPressed && Input()->KeyPress(KEY_T)))
{ {
static SPopupMenuId s_PopupModifierId; static SPopupMenuId s_PopupModifierId;
if(!UI()->IsPopupOpen(&s_PopupModifierId)) if(!UI()->IsPopupOpen(&s_PopupModifierId))
@ -1242,12 +1238,12 @@ void CEditor::DoToolbarLayers(CUIRect ToolBar)
if(pLayer->m_Type == LAYERTYPE_QUADS) if(pLayer->m_Type == LAYERTYPE_QUADS)
{ {
Invoked = DoButton_Editor(&s_AddItemButton, "Add Quad", 0, &Button, 0, "[ctrl+q] Add a new quad") || Invoked = DoButton_Editor(&s_AddItemButton, "Add Quad", 0, &Button, 0, "[ctrl+q] Add a new quad") ||
(m_Dialog == DIALOG_NONE && m_EditBoxActive == 0 && Input()->KeyPress(KEY_Q) && ModPressed); (m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && Input()->KeyPress(KEY_Q) && ModPressed);
} }
else if(pLayer->m_Type == LAYERTYPE_SOUNDS) else if(pLayer->m_Type == LAYERTYPE_SOUNDS)
{ {
Invoked = DoButton_Editor(&s_AddItemButton, "Add Sound", 0, &Button, 0, "[ctrl+q] Add a new sound source") || Invoked = DoButton_Editor(&s_AddItemButton, "Add Sound", 0, &Button, 0, "[ctrl+q] Add a new sound source") ||
(m_Dialog == DIALOG_NONE && m_EditBoxActive == 0 && Input()->KeyPress(KEY_Q) && ModPressed); (m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && Input()->KeyPress(KEY_Q) && ModPressed);
} }
if(Invoked) if(Invoked)
@ -1258,7 +1254,7 @@ void CEditor::DoToolbarLayers(CUIRect ToolBar)
pGroup->Mapping(aMapping); pGroup->Mapping(aMapping);
int x = aMapping[0] + (aMapping[2] - aMapping[0]) / 2; int x = aMapping[0] + (aMapping[2] - aMapping[0]) / 2;
int y = aMapping[1] + (aMapping[3] - aMapping[1]) / 2; int y = aMapping[1] + (aMapping[3] - aMapping[1]) / 2;
if(m_Dialog == DIALOG_NONE && m_EditBoxActive == 0 && Input()->KeyPress(KEY_Q) && ModPressed) if(m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && Input()->KeyPress(KEY_Q) && ModPressed)
{ {
x += UI()->MouseWorldX() - (m_WorldOffsetX * pGroup->m_ParallaxX / 100) - pGroup->m_OffsetX; x += UI()->MouseWorldX() - (m_WorldOffsetX * pGroup->m_ParallaxX / 100) - pGroup->m_OffsetX;
y += UI()->MouseWorldY() - (m_WorldOffsetY * pGroup->m_ParallaxY / 100) - pGroup->m_OffsetY; y += UI()->MouseWorldY() - (m_WorldOffsetY * pGroup->m_ParallaxY / 100) - pGroup->m_OffsetY;
@ -1292,7 +1288,7 @@ void CEditor::DoToolbarLayers(CUIRect ToolBar)
TB_Bottom.VSplitLeft(65.0f, &Button, &TB_Bottom); TB_Bottom.VSplitLeft(65.0f, &Button, &TB_Bottom);
static int s_BrushDrawModeButton = 0; static int s_BrushDrawModeButton = 0;
if(DoButton_Editor(&s_BrushDrawModeButton, "Destructive", m_BrushDrawDestructive, &Button, 0, "[ctrl+d] Toggle brush draw mode") || if(DoButton_Editor(&s_BrushDrawModeButton, "Destructive", m_BrushDrawDestructive, &Button, 0, "[ctrl+d] Toggle brush draw mode") ||
(m_Dialog == DIALOG_NONE && m_EditBoxActive == 0 && Input()->KeyPress(KEY_D) && ModPressed && !ShiftPressed)) (m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && Input()->KeyPress(KEY_D) && ModPressed && !ShiftPressed))
m_BrushDrawDestructive = !m_BrushDrawDestructive; m_BrushDrawDestructive = !m_BrushDrawDestructive;
TB_Bottom.VSplitLeft(5.0f, &Button, &TB_Bottom); TB_Bottom.VSplitLeft(5.0f, &Button, &TB_Bottom);
} }
@ -1313,7 +1309,7 @@ void CEditor::DoToolbarSounds(CUIRect ToolBar)
ToolBarBottom.VSplitLeft(ToolBarBottom.h, &Button, &ToolBarBottom); ToolBarBottom.VSplitLeft(ToolBarBottom.h, &Button, &ToolBarBottom);
static int s_PlayStopButton; static int s_PlayStopButton;
if(DoButton_FontIcon(&s_PlayStopButton, Sound()->IsPlaying(pSelectedSound->m_SoundID) ? FONT_ICON_STOP : FONT_ICON_PLAY, 0, &Button, 0, "Play/stop audio preview", IGraphics::CORNER_ALL) || if(DoButton_FontIcon(&s_PlayStopButton, Sound()->IsPlaying(pSelectedSound->m_SoundID) ? FONT_ICON_STOP : FONT_ICON_PLAY, 0, &Button, 0, "Play/stop audio preview", IGraphics::CORNER_ALL) ||
(m_Dialog == DIALOG_NONE && m_EditBoxActive == 0 && Input()->KeyPress(KEY_SPACE))) (m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && Input()->KeyPress(KEY_SPACE)))
{ {
if(Sound()->IsPlaying(pSelectedSound->m_SoundID)) if(Sound()->IsPlaying(pSelectedSound->m_SoundID))
Sound()->Stop(pSelectedSound->m_SoundID); Sound()->Stop(pSelectedSound->m_SoundID);
@ -2313,7 +2309,7 @@ void CEditor::DoMapEditor(CUIRect View)
// render all good stuff // render all good stuff
if(!m_ShowPicker) if(!m_ShowPicker)
{ {
if(m_Dialog == DIALOG_NONE && m_EditBoxActive == 0 && Input()->ShiftIsPressed() && !Input()->ModifierIsPressed() && Input()->KeyPress(KEY_G)) if(m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && Input()->ShiftIsPressed() && !Input()->ModifierIsPressed() && Input()->KeyPress(KEY_G))
{ {
const bool AnyHidden = const bool AnyHidden =
!m_Map.m_pGameLayer->m_Visible || !m_Map.m_pGameLayer->m_Visible ||
@ -2909,7 +2905,7 @@ void CEditor::DoMapEditor(CUIRect View)
UI()->SetActiveItem(nullptr); UI()->SetActiveItem(nullptr);
} }
} }
if(!Input()->ShiftIsPressed() && !Input()->ModifierIsPressed() && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0) if(!Input()->ShiftIsPressed() && !Input()->ModifierIsPressed() && m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr)
{ {
float PanSpeed = 64.0f; float PanSpeed = 64.0f;
if(Input()->KeyPress(KEY_A)) if(Input()->KeyPress(KEY_A))
@ -3837,7 +3833,7 @@ void CEditor::RenderLayers(CUIRect LayersBox)
UI()->SetActiveItem(s_pDraggedButton); UI()->SetActiveItem(s_pDraggedButton);
} }
if(Input()->KeyPress(KEY_DOWN) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0 && s_Operation == OP_NONE) if(Input()->KeyPress(KEY_DOWN) && m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && s_Operation == OP_NONE)
{ {
if(Input()->ShiftIsPressed()) if(Input()->ShiftIsPressed())
{ {
@ -3869,7 +3865,7 @@ void CEditor::RenderLayers(CUIRect LayersBox)
} }
s_ScrollToSelectionNext = true; s_ScrollToSelectionNext = true;
} }
if(Input()->KeyPress(KEY_UP) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0 && s_Operation == OP_NONE) if(Input()->KeyPress(KEY_UP) && m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && s_Operation == OP_NONE)
{ {
if(Input()->ShiftIsPressed()) if(Input()->ShiftIsPressed())
{ {
@ -4285,7 +4281,7 @@ void CEditor::RenderImagesList(CUIRect ToolBox)
ToolBox.y += ScrollOffset.y; ToolBox.y += ScrollOffset.y;
bool ScrollToSelection = false; bool ScrollToSelection = false;
if(m_Dialog == DIALOG_NONE && m_EditBoxActive == 0 && !m_Map.m_vpImages.empty()) if(m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && !m_Map.m_vpImages.empty())
{ {
if(Input()->KeyPress(KEY_DOWN)) if(Input()->KeyPress(KEY_DOWN))
{ {
@ -4459,7 +4455,7 @@ void CEditor::RenderSounds(CUIRect ToolBox)
ToolBox.y += ScrollOffset.y; ToolBox.y += ScrollOffset.y;
bool ScrollToSelection = false; bool ScrollToSelection = false;
if(m_Dialog == DIALOG_NONE && m_EditBoxActive == 0 && !m_Map.m_vpSounds.empty()) if(m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && !m_Map.m_vpSounds.empty())
{ {
if(Input()->KeyPress(KEY_DOWN)) if(Input()->KeyPress(KEY_DOWN))
{ {
@ -5321,11 +5317,11 @@ void CEditor::RenderModebar(CUIRect View)
static int s_ModeButton = 0; static int s_ModeButton = 0;
const int MouseButton = DoButton_Ex(&s_ModeButton, pModeLabel, 0, &ModeButton, 0, "Switch between images, sounds and layers management.", IGraphics::CORNER_T, 10.0f); const int MouseButton = DoButton_Ex(&s_ModeButton, pModeLabel, 0, &ModeButton, 0, "Switch between images, sounds and layers management.", IGraphics::CORNER_T, 10.0f);
if(MouseButton == 2 || (Input()->KeyPress(KEY_LEFT) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) if(MouseButton == 2 || (Input()->KeyPress(KEY_LEFT) && m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr))
{ {
m_Mode = (m_Mode + NUM_MODES - 1) % NUM_MODES; m_Mode = (m_Mode + NUM_MODES - 1) % NUM_MODES;
} }
else if(MouseButton == 1 || (Input()->KeyPress(KEY_RIGHT) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) else if(MouseButton == 1 || (Input()->KeyPress(KEY_RIGHT) && m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr))
{ {
m_Mode = (m_Mode + 1) % NUM_MODES; m_Mode = (m_Mode + 1) % NUM_MODES;
} }
@ -6245,14 +6241,11 @@ void CEditor::Render()
// reset tip // reset tip
m_pTooltip = nullptr; m_pTooltip = nullptr;
if(m_EditBoxActive)
--m_EditBoxActive;
// render checker // render checker
RenderBackground(View, m_CheckerTexture, 32.0f, 1.0f); RenderBackground(View, m_CheckerTexture, 32.0f, 1.0f);
CUIRect MenuBar, ModeBar, ToolBar, StatusBar, ExtraEditor, ToolBox; CUIRect MenuBar, ModeBar, ToolBar, StatusBar, ExtraEditor, ToolBox;
m_ShowPicker = Input()->KeyIsPressed(KEY_SPACE) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0 && UI()->LastActiveItem() != &m_SettingsCommandInput && m_vSelectedLayers.size() == 1; m_ShowPicker = Input()->KeyIsPressed(KEY_SPACE) && m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && m_vSelectedLayers.size() == 1;
if(m_GuiActive) if(m_GuiActive)
{ {
@ -6280,9 +6273,9 @@ void CEditor::Render()
if(m_Mode == MODE_LAYERS) if(m_Mode == MODE_LAYERS)
DoMapEditor(View); DoMapEditor(View);
// do zooming if(m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr)
if(m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)
{ {
// handle zoom hotkeys
if(Input()->KeyPress(KEY_KP_MINUS)) if(Input()->KeyPress(KEY_KP_MINUS))
ChangeZoom(50.0f); ChangeZoom(50.0f);
if(Input()->KeyPress(KEY_KP_PLUS)) if(Input()->KeyPress(KEY_KP_PLUS))
@ -6293,13 +6286,10 @@ void CEditor::Render()
m_EditorOffsetY = 0; m_EditorOffsetY = 0;
SetZoom(100.0f); SetZoom(100.0f);
} }
}
// handle brush save/load hotkeys
for(int i = KEY_1; i <= KEY_0; i++) for(int i = KEY_1; i <= KEY_0; i++)
{ {
if(m_Dialog != DIALOG_NONE || m_EditBoxActive != 0)
break;
if(Input()->KeyPress(i)) if(Input()->KeyPress(i))
{ {
int Slot = i - KEY_1; int Slot = i - KEY_1;
@ -6335,6 +6325,7 @@ void CEditor::Render()
} }
} }
} }
}
float Brightness = 0.25f; float Brightness = 0.25f;
@ -6360,7 +6351,7 @@ void CEditor::Render()
else if(m_Mode == MODE_SOUNDS) else if(m_Mode == MODE_SOUNDS)
DoToolbarSounds(ToolBar); DoToolbarSounds(ToolBar);
if(m_Dialog == DIALOG_NONE && m_EditBoxActive == 0) if(m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr)
{ {
const bool ModPressed = Input()->ModifierIsPressed(); const bool ModPressed = Input()->ModifierIsPressed();
const bool ShiftPressed = Input()->ShiftIsPressed(); const bool ShiftPressed = Input()->ShiftIsPressed();
@ -7099,6 +7090,17 @@ void CEditor::HandleCursorMovement()
} }
} }
void CEditor::DispatchInputEvents()
{
for(size_t i = 0; i < Input()->NumEvents(); i++)
{
const IInput::CEvent &Event = Input()->GetEvent(i);
if(!Input()->IsEventValid(Event))
continue;
UI()->OnInput(Event);
}
}
void CEditor::HandleAutosave() void CEditor::HandleAutosave()
{ {
const float Time = Client()->GlobalTime(); const float Time = Client()->GlobalTime();
@ -7213,6 +7215,7 @@ void CEditor::OnUpdate()
} }
HandleCursorMovement(); HandleCursorMovement();
DispatchInputEvents();
HandleAutosave(); HandleAutosave();
HandleWriterFinishJobs(); HandleWriterFinishJobs();
} }
@ -7222,7 +7225,7 @@ void CEditor::OnRender()
UI()->ResetMouseSlow(); UI()->ResetMouseSlow();
// toggle gui // toggle gui
if(m_Dialog == DIALOG_NONE && m_EditBoxActive == 0 && Input()->KeyPress(KEY_TAB)) if(m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && Input()->KeyPress(KEY_TAB))
m_GuiActive = !m_GuiActive; m_GuiActive = !m_GuiActive;
if(Input()->KeyPress(KEY_F10)) if(Input()->KeyPress(KEY_F10))
@ -7236,9 +7239,6 @@ void CEditor::OnRender()
ms_pUiGotContext = nullptr; ms_pUiGotContext = nullptr;
UI()->StartCheck(); UI()->StartCheck();
for(size_t i = 0; i < Input()->NumEvents(); i++)
UI()->OnInput(Input()->GetEvent(i));
UI()->Update(m_MouseX, m_MouseY, m_MouseDeltaX, m_MouseDeltaY, m_MouseWorldX, m_MouseWorldY); UI()->Update(m_MouseX, m_MouseY, m_MouseDeltaX, m_MouseDeltaY, m_MouseWorldX, m_MouseWorldY);
Render(); Render();

View file

@ -776,7 +776,6 @@ public:
m_Mode = MODE_LAYERS; m_Mode = MODE_LAYERS;
m_Dialog = 0; m_Dialog = 0;
m_EditBoxActive = 0;
m_pTooltip = nullptr; m_pTooltip = nullptr;
m_GridActive = false; m_GridActive = false;
@ -880,6 +879,7 @@ public:
void ResetIngameMoved() override { m_IngameMoved = false; } void ResetIngameMoved() override { m_IngameMoved = false; }
void HandleCursorMovement(); void HandleCursorMovement();
void DispatchInputEvents();
void HandleAutosave(); void HandleAutosave();
bool PerformAutosave(); bool PerformAutosave();
void HandleWriterFinishJobs(); void HandleWriterFinishJobs();
@ -932,7 +932,6 @@ public:
int m_Mode; int m_Mode;
int m_Dialog; int m_Dialog;
int m_EditBoxActive;
const char *m_pTooltip; const char *m_pTooltip;
bool m_GridActive; bool m_GridActive;