MinecraftConsoles/Minecraft.Client/Common/UI/UIScene_CreateWorldMenu.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

110 lines
3.3 KiB
C++

#pragma once
#include "IUIScene_StartGame.h"
class UIScene_CreateWorldMenu : public IUIScene_StartGame
{
private:
enum EControls
{
eControl_EditWorldName,
eControl_TexturePackList,
eControl_GameModeToggle,
eControl_Difficulty,
eControl_MoreOptions,
eControl_NewWorld,
eControl_OnlineGame,
};
static int m_iDifficultyTitleSettingA[4];
wstring m_worldName;
wstring m_seed;
UIControl m_controlMainPanel;
UIControl_Label m_labelWorldName;
UIControl_Button m_buttonGamemode, m_buttonMoreOptions, m_buttonCreateWorld;
UIControl_TextInput m_editWorldName;
UIControl_Slider m_sliderDifficulty;
UIControl_CheckBox m_checkboxOnline;
UIControl_BitmapIcon m_bitmapIcon, m_bitmapComparison;
UI_BEGIN_MAP_ELEMENTS_AND_NAMES(IUIScene_StartGame)
UI_MAP_ELEMENT( m_controlMainPanel, "MainPanel" )
UI_BEGIN_MAP_CHILD_ELEMENTS( m_controlMainPanel )
UI_MAP_ELEMENT( m_labelWorldName, "WorldName")
UI_MAP_ELEMENT( m_editWorldName, "EditWorldName")
UI_MAP_ELEMENT( m_texturePackList, "TexturePackSelector")
UI_MAP_ELEMENT( m_buttonGamemode, "GameModeToggle")
UI_MAP_ELEMENT( m_checkboxOnline, "CheckboxOnline")
UI_MAP_ELEMENT( m_buttonMoreOptions, "MoreOptions")
UI_MAP_ELEMENT( m_buttonCreateWorld, "NewWorld")
UI_MAP_ELEMENT( m_sliderDifficulty, "Difficulty")
UI_END_MAP_CHILD_ELEMENTS()
UI_END_MAP_ELEMENTS_AND_NAMES()
bool m_bGameModeCreative;
int m_iGameModeId;
bool m_bMultiplayerAllowed;
DLCPack * m_pDLCPack;
bool m_bRebuildTouchBoxes;
public:
UIScene_CreateWorldMenu(int iPad, void *initData, UILayer *parentLayer);
virtual ~UIScene_CreateWorldMenu();
virtual void updateTooltips();
virtual void updateComponents();
virtual EUIScene getSceneType() { return eUIScene_CreateWorldMenu;}
virtual void handleDestroy();
virtual void tick();
virtual UIControl* GetMainPanel();
virtual void handleTouchBoxRebuild();
protected:
// TODO: This should be pure virtual in this class
virtual wstring getMoviePath();
virtual void handleTimerComplete(int id);
virtual void handleGainFocus(bool navBack);
public:
// INPUT
virtual void handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled);
#ifdef _WINDOWS64
virtual void getDirectEditInputs(vector<UIControl_TextInput*> &inputs);
virtual void onDirectEditFinished(UIControl_TextInput *input, UIControl_TextInput::EDirectEditResult result);
#endif
private:
void StartSharedLaunchFlow();
bool IsLocalMultiplayerAvailable();
#ifdef _DURANGO
static void checkPrivilegeCallback(LPVOID lpParam, bool hasPrivilege, int iPad);
#endif
protected:
static int KeyboardCompleteWorldNameCallback(LPVOID lpParam,const bool bRes);
void handlePress(F64 controlId, F64 childId);
void handleSliderMove(F64 sliderId, F64 currentValue);
static void CreateGame(UIScene_CreateWorldMenu* pClass, DWORD dwLocalUsersMask);
static int ConfirmCreateReturned(void *pParam,int iPad,C4JStorage::EMessageResult result);
static int StartGame_SignInReturned(void *pParam,bool bContinue, int iPad);
static int MustSignInReturnedPSN(void *pParam,int iPad,C4JStorage::EMessageResult result);
#ifdef __ORBIS__
//static int PSPlusReturned(void *pParam,int iPad,C4JStorage::EMessageResult result);
static int ContinueOffline(void *pParam,int iPad,C4JStorage::EMessageResult result);
#endif
virtual void checkStateAndStartGame();
};