Skip to content

Commit

Permalink
Improved FlxInputText (#3219)
Browse files Browse the repository at this point in the history
* Initial text input implementation

* Fix code climate?

* Add missing FLX_MOUSE check

* Add multiline variable
- Regenerate text graphic when `passwordMode` changes

* Place caret at closest character to mouse

* Selection boxes + selected text color
- Add `setSelection()` function
- `FlxInputText` variables are now destroyed properly

* Implement text selection with mouse & text scrolling
- Added `scrollH`, `scrollV`, `bottomScrollV`, `maxScrollH` & `maxScrollV` variables
- Return end of text if character isn't found at position

* Fix selection not working correctly when mouse is out of bounds
- Selection boxes are now clipped inside the text bounds
- Simplified getting the Y offset of a line

* Mouse wheel scrolling
- Fix scrollV not being able to be modified directly

* Implemented double press and dragging
- Selection sprites now just change their color instead of making new graphics
- scrollH can now be modified properly as well
- Word wrap no longer changes with multiline (multiline only affects adding new lines)

* Action callbacks

* Fix "final" keyword screwing up code climate

* Various fixes & improvements
- Caret is now positioned properly with different alignments
- Caret is now clipped inside the text bounds
- Caret is now automatically resized when changing `bold`, `font`, `italic`, `size` or `systemFont` variables
- Fixed crash when pressing down a key while there isn't a focused input text
- Fixed selected text format overwriting the border color
- Fixed caret not being visible when text is empty
- Fixed selection boxes sometimes not being updated immediately
- Added `useSelectedTextFormat` variable
- Double press check is now when the mouse is released (same as OpenFL)

* Add `forceCase` and filterMode`
- Moved action callback types to an enum abstract

* Added background for text input
- Added `focusGained` and `focusLost` callbacks
- Fixed selection boxes not being clipped properly when they're compeletely out of bounds

* Some improvements
- Added bounds check while changing `caretIndex`, `caretWidth`, `fieldBorderThickness` and `maxLength`
- FlxInputText is now single-line by default
- Fixed text scroll being reset while moving selection with mouse
- Caret index now starts at the end of the text if focus is enabled through code
- Background now gets regenerated in `regenGraphic` instead of instantly after changing a related variable

* Added `editable` and selectable` variables
- Added change and scroll action callbacks
- Made `replaceSelectedText()` public

* Flixel hotkeys (volume & debugger) are now disabled while inputting text
- Fixed space not being inputted on HTML5

* Caret flashing timer
- Fixed text going out of bounds when enabling multiline without a field height set
- Last click time for double click now resets if the mouse clicked on something else

* Optimized selection box sprites (only visible lines are accounted for now)
- Fixed untypeable characters being added to text input on Flash

* Various fixes for Flash
- Fixed text selection and caret positioning on Flash
- Copy, cut, paste and select all commands now work on Flash
- Fixed horizontal scroll not being set automatically on Flash
- Moved to using Flash's `TextEvent.TEXT_INPUT` event (does not dispatch with invalid characters)

* Fixed text selection and scrolling on other platforms

* Fixed text selection with word wrapping enabled

* Added touch support
- Now uses `window.setTextInputRect()` to prevent keyboard overlay from blocking the text field
- Fixed pointer position being inaccurate with camera scrolling
- Fixed `getCharBoundaries()` not giving the correct Y position

* Added documentation
- Fixed not being able to add text if the field starts out empty
- Fixed the caret being the wrong size if the text field is empty
- Fixed the background not being resized when auto size is enabled
- Changing `customFilterPattern` now automatically sets `filterMode` to `CUSTOM_FILTER`
- Renamed `_lastClickTime` to `_lastPressTime`

* Add documentation to `multiline` variable
- Remove setting `_autoHeight` to false after setting multiline to true as its no longer needed

* Add `mouseWheelEnabled` variable
- Remove unneeded `selectable` comment

* Replaced `PREVIOUS_LINE` and `NEXT_LINE` with `WORD_LEFT` and `WORD_RIGHT`
- Ctrl + Up/Down now dispatches `LINE_LEFT` or `LINE_RIGHT` instead of `HOME` or `END`
- Renamed `LINE_BEGINNING` and `LINE_END` to `LINE_LEFT` and `LINE_RIGHT`

* Various fixes
- Clip rect should now work properly
- Fixed caret showing up after changing `text` through code
- Focus will not be removed due to clicking outside of the text field if it has been granted via code in the same frame
- Caret will no longer be visible if the text field isn't editable
- Fixed some html5 tests not compiling on CI

* Various more fixes
- Fixed crash from recursive calls to `regenBackground()` due to `clipSprite()`
- Fixed crash from `pointer.getWorldPosition()`
- Fixed background not being updated after changing text format
- Moved caret sprite regeneration to `regenGraphic()`

* Move input text "frontend" to a manager plugin

* Fixed missing rename

* Replace `callback` with `onTextChange` and `onScrollChange` signals
- Replace `focusGained` and `focusLost` with `onFocusChange` signal
- Renamed filter mode options and added `CHARS` option
- Removed `customFilterPattern` as its now defined in the enum itself

* Move `ENTER_ACTION` over to `onEnter`

* Implement `destroy()` for FlxInputTextManager
- Add `unregisterAll()` to FlxInputTextManager

* add onTypingAction

* allow custom manager

* add setManager

* remove focus setter for setFocus

* better destroy/init

* use case ifs

* improve mac key behavior

* fix selection start/end issue

* remove set_hasFocus for startFocus and endFocus

* use final signals

* let openfl handle maxChars

* inline setters remove redundancies

* simplify caret blink

---------

Co-authored-by: George FunBook <[email protected]>
  • Loading branch information
Starmapo and Geokureli committed Aug 6, 2024
1 parent 64967e3 commit 94dbde5
Show file tree
Hide file tree
Showing 6 changed files with 2,668 additions and 15 deletions.
10 changes: 5 additions & 5 deletions flixel/FlxG.hx
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package flixel;

import openfl.Lib;
import openfl.display.DisplayObject;
import openfl.display.Stage;
import openfl.display.StageDisplayState;
import openfl.net.URLRequest;
import flixel.effects.postprocess.PostProcess;
import flixel.math.FlxMath;
import flixel.math.FlxRandom;
Expand All @@ -28,6 +23,11 @@ import flixel.system.scaleModes.RatioScaleMode;
import flixel.util.FlxCollision;
import flixel.util.FlxSave;
import flixel.util.typeLimit.NextState;
import openfl.Lib;
import openfl.display.DisplayObject;
import openfl.display.Stage;
import openfl.display.StageDisplayState;
import openfl.net.URLRequest;
#if FLX_TOUCH
import flixel.input.touch.FlxTouchManager;
#end
Expand Down
10 changes: 7 additions & 3 deletions flixel/input/keyboard/FlxKeyboard.hx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package flixel.input.keyboard;

#if FLX_KEYBOARD
import openfl.events.KeyboardEvent;
import flixel.FlxG;
import flixel.input.FlxInput;
import flixel.system.replay.CodeValuePair;
import flixel.text.FlxInputText;
import openfl.events.KeyboardEvent;

/**
* Keeps track of what keys are pressed and how with handy Bools or strings.
Expand Down Expand Up @@ -101,7 +102,7 @@ class FlxKeyboard extends FlxKeyManager<FlxKey, FlxKeyList>

// Debugger toggle
#if FLX_DEBUG
if (FlxG.game.debugger != null && inKeyArray(FlxG.debugger.toggleKeys, event))
if (FlxG.game.debugger != null && inKeyArray(FlxG.debugger.toggleKeys, event) && !FlxInputText.globalManager.isTyping)
{
FlxG.debugger.visible = !FlxG.debugger.visible;
}
Expand All @@ -114,7 +115,10 @@ class FlxKeyboard extends FlxKeyManager<FlxKey, FlxKeyList>

// Attempted to cancel the replay?
#if FLX_RECORD
if (FlxG.game.replaying && !inKeyArray(FlxG.debugger.toggleKeys, event) && inKeyArray(FlxG.vcr.cancelKeys, event))
if (FlxG.game.replaying
&& !inKeyArray(FlxG.debugger.toggleKeys, event)
&& inKeyArray(FlxG.vcr.cancelKeys, event)
&& !FlxInputText.globalManager.isTyping)
{
FlxG.vcr.cancelReplay();
}
Expand Down
3 changes: 3 additions & 0 deletions flixel/system/frontEnds/PluginFrontEnd.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package flixel.system.frontEnds;

import flixel.input.mouse.FlxMouseEvent;
import flixel.input.mouse.FlxMouseEventManager;
import flixel.text.FlxInputText;
import flixel.text.FlxInputTextManager;
import flixel.tweens.FlxTween;
import flixel.util.FlxStringUtil;
import flixel.util.FlxTimer;
Expand Down Expand Up @@ -138,6 +140,7 @@ class PluginFrontEnd
addPlugin(FlxTimer.globalManager = new FlxTimerManager());
addPlugin(FlxTween.globalManager = new FlxTweenManager());
addPlugin(FlxMouseEvent.globalManager = new FlxMouseEventManager());
addPlugin(FlxInputText.globalManager = new FlxInputTextManager());
}

/**
Expand Down
18 changes: 11 additions & 7 deletions flixel/system/frontEnds/SoundFrontEnd.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import flixel.FlxG;
import flixel.group.FlxGroup;
import flixel.input.keyboard.FlxKey;
import flixel.math.FlxMath;
import flixel.system.FlxAssets;
import flixel.sound.FlxSound;
import flixel.sound.FlxSoundGroup;
import flixel.system.FlxAssets;
import flixel.system.ui.FlxSoundTray;
import flixel.text.FlxInputText;
import flixel.util.FlxSignal;
import openfl.Assets;
import openfl.media.Sound;
Expand Down Expand Up @@ -394,12 +395,15 @@ class SoundFrontEnd
list.update(elapsed);

#if FLX_KEYBOARD
if (FlxG.keys.anyJustReleased(muteKeys))
toggleMuted();
else if (FlxG.keys.anyJustReleased(volumeUpKeys))
changeVolume(0.1);
else if (FlxG.keys.anyJustReleased(volumeDownKeys))
changeVolume(-0.1);
if (!FlxInputText.globalManager.isTyping)
{
if (FlxG.keys.anyJustReleased(muteKeys))
toggleMuted();
else if (FlxG.keys.anyJustReleased(volumeUpKeys))
changeVolume(0.1);
else if (FlxG.keys.anyJustReleased(volumeDownKeys))
changeVolume(-0.1);
}
#end
}

Expand Down
Loading

0 comments on commit 94dbde5

Please sign in to comment.