MinecraftConsoles/Minecraft.Client/Common/UI/UIScene_LaunchMoreOptionsMenu.h
MrTheShy 8b23c71b93 Fix TextInput bugs and refactor direct edit handling into UIScene base class
The fake cursor character (_) used for SWFs without m_mcCaret was leaking
into saved sign and anvil text. This happened because setLabel() with
instant=false only updates the C++-side cache, deferring the Flash write
to the next control tick. Any getLabel() call before that tick reads the
old Flash value still containing the underscore. Fixed by passing
instant=true in confirmDirectEdit, cancelDirectEdit, and the Enter key
path inside tickDirectEdit, so the cleaned text hits Flash immediately.

Mouse hover over TextInput controls (world name, anvil name, seed field)
was not showing the yellow highlight border. The hover code used
IggyPlayerSetFocusRS which sets Iggy's internal dispatch focus but does
not trigger Flash's ChangeState callback, so no visual feedback appeared.
Buttons worked fine because Iggy draws its own focus ring on them, but
TextInput relies entirely on ChangeState(0) for the yellow border.
Switched to SetFocusToElement which goes through the Flash-side SetFocus
path, then immediately call setCaretVisible(false) to suppress the
blinking caret that comes with focus. No visual flicker since rendering
happens after both tickInput and scene tick complete.

While direct editing, mouse hover was able to move focus away to other
TextInputs on the same scene (most noticeably on the sign editor, where
hovering a different line would steal focus from the line being typed).
Added an isDirectEditBlocking() check in the hover path to skip focus
changes when any input on the scene is actively being edited.

The Done button in SignEntryMenu was unresponsive to mouse clicks during
direct editing. The root cause is execution order: handleMouseClick runs
before handleInput in the frame. The base handleMouseClick found the Done
button and called handlePress, but handlePress bailed out because of the
isDirectEditing guard. The click was marked consumed, so handleInput
never saw it. Fixed by overriding handleMouseClick in SignEntryMenu to
detect the Done button hit while editing and confirm + close directly.

Added click-outside-to-deselect for anvil and world name text inputs.
Both scenes previously required Enter to confirm the edit, which felt
wrong. Now clicking anywhere outside the text field bounds confirms the
current text, matching standard UI behavior.

The anvil menu now updates the item name in real time while typing, like
Java edition. Previously the name was only applied on Enter, so the
repair cost display was stale until confirmation.

The biggest change is structural: every scene that used direct editing
(AnvilMenu, CreateWorldMenu, SignEntryMenu, LaunchMoreOptionsMenu,
DebugCreateSchematic, DebugSetCamera) had its own copy of the same
boilerplate -- tickDirectEdit loops in tick(), click-outside hit testing
in handleMouseClick(), cooldown guard checks in handleInput/handlePress,
and result dispatch with switch/if chains. This was around 200 lines of
near-identical code scattered across 6 files, each with its own slight
variations and its own bugs waiting to happen.

Pulled all of it into UIScene with two virtual methods: getDirectEditInputs()
where scenes register their text inputs, and onDirectEditFinished() where
they handle confirmed/cancelled results. The base class tick() drives
tickDirectEdit on all registered inputs, handleMouseClick() does the
click-outside-to-deselect hit test generically using panel offsets, and
isDirectEditBlocking() replaces all the inline cooldown checks. Scenes
now just override those two methods and get everything for free.

Also removed the m_activeDirectEditControl enum tracking from the debug
scenes (DebugCreateSchematic, DebugSetCamera) since the base class
handles lifecycle tracking through the controls themselves.
2026-03-06 16:15:24 +01:00

172 lines
6.2 KiB
C++

#pragma once
#include "UIScene.h"
class UIScene_LaunchMoreOptionsMenu : public UIScene
{
private:
static const int TAB_WORLD_OPTIONS = 0;
static const int TAB_GAME_OPTIONS = 1;
enum EControls
{
// Add all checkboxes at the start as they also index into a checkboxes array
eLaunchCheckbox_Online,
eLaunchCheckbox_InviteOnly,
eLaunchCheckbox_AllowFoF,
eLaunchCheckbox_PVP,
eLaunchCheckbox_TrustSystem,
eLaunchCheckbox_FireSpreads,
eLaunchCheckbox_TNT,
eLaunchCheckbox_HostPrivileges,
eLaunchCheckbox_ResetNether,
eLaunchCheckbox_Structures,
eLaunchCheckbox_FlatWorld,
eLaunchCheckbox_BonusChest,
eLaunchCheckbox_DisableSaving,
eLaunchCheckbox_WorldResizeType,
eLaunchCheckbox_KeepInventory,
eLaunchCheckbox_MobSpawning,
eLaunchCheckbox_MobLoot,
eLaunchCheckbox_MobGriefing,
eLaunchCheckbox_TileDrops,
eLaunchCheckbox_NaturalRegeneration,
eLaunchCheckbox_DayLightCycle,
eLaunchCheckboxes_Count,
eControl_EditSeed,
eControl_WorldSize,
eControl_WorldResize,
eControl_Count
};
#ifdef __PSVITA__
enum ETouchInput
{
ETouchInput_TabWorld = eControl_Count,
ETouchInput_TabGame,
ETouchInput_Count
};
UIControl_Touch m_TouchTabWorld, m_TouchTabGame;
UIControl m_controlWorldPanel, m_controlGamePanel;
#endif
UIControl m_gameOptions, m_worldOptions;
UIControl_CheckBox m_checkboxes[eLaunchCheckboxes_Count];
UIControl_Label m_labelWorldOptions, m_labelGameOptions, m_labelDescription;
UIControl_HTMLLabel m_labelDescription_GameOptions, m_labelDescription_WorldOptions;
UIControl_Label m_labelSeed, m_labelRandomSeed, m_labelWorldSize, m_labelWorldResize;
UIControl_TextInput m_editSeed;
UIControl_Slider m_sliderWorldSize;
UIControl_Slider m_sliderWorldResize;
IggyName m_funcSetMenuType, m_funcChangeTab, m_funcSetDescription;
UI_BEGIN_MAP_ELEMENTS_AND_NAMES(UIScene)
UI_MAP_ELEMENT( m_labelGameOptions, "LabelGame")
UI_MAP_ELEMENT( m_labelWorldOptions, "LabelWorld")
UI_MAP_ELEMENT( m_gameOptions, "GameOptions")
UI_BEGIN_MAP_CHILD_ELEMENTS(m_gameOptions)
#ifdef __PSVITA__
UI_MAP_ELEMENT( m_TouchTabGame, "TouchTabGame" )
#endif
UI_MAP_ELEMENT( m_labelDescription_GameOptions, "Description_GameOptions")
UI_MAP_ELEMENT( m_checkboxes[eLaunchCheckbox_Online], "CheckboxOnline")
UI_MAP_ELEMENT( m_checkboxes[eLaunchCheckbox_InviteOnly], "CheckboxInviteOnly")
UI_MAP_ELEMENT( m_checkboxes[eLaunchCheckbox_AllowFoF], "CheckboxAllowFoF")
UI_MAP_ELEMENT( m_checkboxes[eLaunchCheckbox_PVP], "CheckboxPVP")
UI_MAP_ELEMENT( m_checkboxes[eLaunchCheckbox_HostPrivileges], "CheckboxHostPrivileges")
UI_MAP_ELEMENT( m_checkboxes[eLaunchCheckbox_DayLightCycle], "CheckboxDayLightCycle")
UI_MAP_ELEMENT( m_checkboxes[eLaunchCheckbox_KeepInventory], "CheckboxKeepInventory")
UI_MAP_ELEMENT( m_checkboxes[eLaunchCheckbox_MobSpawning], "CheckboxMobSpawning")
UI_MAP_ELEMENT( m_checkboxes[eLaunchCheckbox_MobGriefing], "CheckboxMobGriefing")
UI_MAP_ELEMENT( m_checkboxes[eLaunchCheckbox_MobLoot], "CheckboxMobLoot")
UI_MAP_ELEMENT( m_checkboxes[eLaunchCheckbox_TileDrops], "CheckboxTileDrops")
UI_MAP_ELEMENT( m_checkboxes[eLaunchCheckbox_NaturalRegeneration], "CheckboxNaturalRegeneration")
UI_END_MAP_CHILD_ELEMENTS()
UI_MAP_ELEMENT(m_worldOptions, "WorldOptions")
UI_BEGIN_MAP_CHILD_ELEMENTS(m_worldOptions)
#ifdef __PSVITA__
UI_MAP_ELEMENT( m_TouchTabWorld, "TouchTabWorld" )
#endif
UI_MAP_ELEMENT( m_labelDescription_WorldOptions, "Description_WorldOptions")
UI_MAP_ELEMENT( m_labelSeed, "Seed")
UI_MAP_ELEMENT( m_editSeed, "EditSeed")
UI_MAP_ELEMENT( m_labelRandomSeed, "RandomSeed")
UI_MAP_ELEMENT( m_labelWorldSize, "WorldSize")
UI_MAP_ELEMENT( m_sliderWorldSize, "WorldSizeSlider")
UI_MAP_ELEMENT( m_checkboxes[eLaunchCheckbox_Structures], "CheckboxStructures")
UI_MAP_ELEMENT( m_checkboxes[eLaunchCheckbox_BonusChest], "CheckboxBonusChest")
UI_MAP_ELEMENT( m_checkboxes[eLaunchCheckbox_FlatWorld], "CheckboxFlatWorld")
UI_MAP_ELEMENT( m_checkboxes[eLaunchCheckbox_ResetNether], "CheckboxResetNether")
UI_MAP_ELEMENT( m_checkboxes[eLaunchCheckbox_DisableSaving], "CheckboxDisableSaving")
UI_MAP_ELEMENT( m_checkboxes[eLaunchCheckbox_TrustSystem], "CheckboxTrustSystem")
UI_MAP_ELEMENT( m_checkboxes[eLaunchCheckbox_FireSpreads], "CheckboxFireSpreads")
UI_MAP_ELEMENT( m_checkboxes[eLaunchCheckbox_TNT], "CheckboxTNT")
UI_MAP_ELEMENT( m_labelWorldResize, "ResizeLabel")
UI_MAP_ELEMENT( m_sliderWorldResize, "ChangeWorldSizeSlider")
UI_MAP_ELEMENT( m_checkboxes[eLaunchCheckbox_WorldResizeType], "CheckboxResizeType")
UI_END_MAP_CHILD_ELEMENTS()
UI_MAP_NAME( m_funcChangeTab, L"ChangeTab")
UI_MAP_NAME( m_funcSetMenuType, L"SetMenuType")
UI_END_MAP_ELEMENTS_AND_NAMES()
LaunchMoreOptionsMenuInitData *m_params;
bool m_bMultiplayerAllowed;
bool m_bIgnoreInput;
int m_tabIndex;
public:
UIScene_LaunchMoreOptionsMenu(int iPad, void *initData, UILayer *parentLayer);
virtual void updateTooltips();
virtual void updateComponents();
virtual EUIScene getSceneType() { return eUIScene_LaunchMoreOptionsMenu;}
protected:
// TODO: This should be pure virtual in this class
virtual wstring getMoviePath();
public:
virtual void tick();
virtual void handleDestroy();
#ifdef _WINDOWS64
virtual void getDirectEditInputs(vector<UIControl_TextInput*> &inputs);
virtual void onDirectEditFinished(UIControl_TextInput *input, UIControl_TextInput::EDirectEditResult result);
#endif
// INPUT
virtual void handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled);
virtual void handleFocusChange(F64 controlId, F64 childId);
virtual void handleTimerComplete(int id);
static int KeyboardCompleteSeedCallback(LPVOID lpParam,const bool bRes);
virtual void handlePress(F64 controlId, F64 childId);
virtual void handleSliderMove(F64 sliderId, F64 currentValue);
protected:
void handleCheckboxToggled(F64 controlId, bool selected);
private:
bool m_bUpdateCheats; // If true, update cheats on next tick
void UpdateCheats();
bool m_bUpdateOnline; // If true, update online settings on next tick
void UpdateOnline();
#ifdef __PSVITA__
virtual void handleTouchInput(unsigned int iPad, S32 x, S32 y, int iId, bool bPressed, bool bRepeat, bool bReleased);
#endif //__PSVITA__
#if defined(__PSVITA__) || defined(_WINDOWS64)
virtual UIControl* GetMainPanel();
#endif
};