- Joined
- Jul 18, 2010
- Messages
- 2,377
Introduction
Editboxes are single line text frames beeing editable by players. There are 4 predefined mainframe Editboxes in the default fdfs, but 2 of them are basicly "equal" to some other one.
An Editbox is used to let the player type in text. There are 2 events for editboxes handling text input:
In both events one uses
Outside of this events one would need
- BattleNetEditBoxTemplate (same values as "StandardEditBoxTemplate")
- StandardEditBoxTemplate
- StandardDecoratedEditBoxTemplate (same values as "EscMenuEditBoxTemplate")
- EscMenuEditBoxTemplate
An Editbox is used to let the player type in text. There are 2 events for editboxes handling text input:
Code:
FRAMEEVENT_EDITBOX_TEXT_CHANGED
FRAMEEVENT_EDITBOX_ENTER
BlzGetTriggerFrameText
to get the text GetTriggerPlayer
has inside its box during the event this text is synced.BlzGetTriggerFrameText
length won't exceed 255. Text after the 255. position is not contained inside BlzGetTriggerFrameText
.FRAMEEVENT_EDITBOX_ENTER
, when the local player gave the editbox focus and presses enter/return. The currently local text in the editbox will be BlzGetTriggerFrameText
.FRAMEEVENT_EDITBOX_TEXT_CHANGED
, when for the local player the text of the editbox changed. Happens on adding/Removing Text by player or by code (Setting the text synced will evoke one event for each player). This event will happen quite often.Outside of this events one would need
BlzFrameGetText
to get the text, but BlzFrameGetText
returns for each player the text he currently has in his editbox -> is not synced in multiplayer. Therefore one has to sync it using the frameevents.Example
Thats our Lua code for the demo. It Loads the custom tocFile, creates a frame of name "EscMenuEditBoxTemplate" and registeres 2 events to that frame. Also when the local player has its keyboard focus on the editbox and presses enter/return, its current insert text will be shown in the message frame and that message is saved in the gui variable udg_UserInput[playerIndex].
This Trigger executes the loading and creation functions.
Lua:
function LoadToc()
BlzLoadTOCFile("war3mapimported\\so.toc")
end
function EditBoxEnter()
print("EditBoxEnter:")
print(BlzGetTriggerFrameText())
print(GetPlayerName(GetTriggerPlayer()))
udg_UserInput[GetConvertedPlayerId(GetTriggerPlayer())] = BlzGetTriggerFrameText() --save the text of the local player in a synced manner.
end
function TEXT_CHANGED()
--print("TEXT_CHANGED")
--print(BlzGetTriggerFrameText())
--print(GetPlayerName(GetTriggerPlayer()))
end
function CreateBox()
local editbox = BlzCreateFrame("EscMenuEditBoxTemplate", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0),0,0) --create the box
local eventHandler
BlzFrameSetAbsPoint(editbox, FRAMEPOINT_CENTER, 0.4, 0.3) -- pos the box
BlzFrameSetSize(editbox, 0.2, 0.03) --set the boxs size
eventHandler = CreateTrigger() --Create the FRAMEEVENT_EDITBOX_ENTER trigger
TriggerAddAction(eventHandler, EditBoxEnter)
BlzTriggerRegisterFrameEvent(eventHandler, editbox, FRAMEEVENT_EDITBOX_ENTER)
eventHandler = CreateTrigger() --Create the FRAMEEVENT_EDITBOX_TEXT_CHANGED trigger
TriggerAddAction(eventHandler, TEXT_CHANGED)
BlzTriggerRegisterFrameEvent(eventHandler, editbox, FRAMEEVENT_EDITBOX_TEXT_CHANGED)
end
-
Init
-
Events
-
Map initialization
-
-
Conditions
-
Actions
-
Custom script: LoadToc()
-
Custom script: CreateBox()
-
-
-
Press Esc
-
Events
-
Player - Player 1 (Red) skips a cinematic sequence
-
Player - Player 2 (Blue) skips a cinematic sequence
-
-
Conditions
-
Actions
-
Custom script: print(BlzFrameGetText(BlzGetFrameByName("EscMenuEditBoxTemplate",0)))
-
-
Text Limits
One might want to limit the amount of Text the player can put into the editbox, one can set such a limit by code quite simple. The native one uses is
After using
As said above it does not make much sense to allow a limit above 255 when the text has to be used inside Events in a synced manner.
An editbox can containt 4096 chars, if that amount is exceeded, it becomes invisible.(KeepVary)
On default an editbox uses an TextSizeLimit of -256 which allows any amount of input, but regardless of allowed input only 255 are useable inside the events.
One can read the current limit with
The Editbox inputtext will be in one line even with a bigger height.
Inside FDF one can add an EditTextFrame to an Editbox to change the font of the input text.
BlzFrameSetTextSizeLimit takes framehandle frame, integer size
.After using
BlzFrameSetTextSizeLimit(editbox, 10)
the editbox can only contain 10 chars.As said above it does not make much sense to allow a limit above 255 when the text has to be used inside Events in a synced manner.
An editbox can containt 4096 chars, if that amount is exceeded, it becomes invisible.(KeepVary)
On default an editbox uses an TextSizeLimit of -256 which allows any amount of input, but regardless of allowed input only 255 are useable inside the events.
One can read the current limit with
BlzFrameGetTextSizeLimit(editbox)
.The Editbox inputtext will be in one line even with a bigger height.
Inside FDF one can add an EditTextFrame to an Editbox to change the font of the input text.
Code:
EditTextFrame "SaveGameFileEditBoxText",
Frame "TEXT" "SaveGameFileEditBoxText" INHERITS "EscMenuEditBoxTextTemplate" {
}
Other UI-Frame Tutorials
The following links might provide more insight into this subject.
UI: Change Lumber Text
[JASS/AI] - UI: Create a TextButton
[JASS/AI] - UI: Positionate Frames (important)
UI: toc-Files
UI: Reading a FDF
UI - The concept of Parent-Frames
[JASS/AI] - UI: FrameEvents and FrameTypes
UI: Frames and Tooltips
[JASS/AI] - UI: Creating a Bar
UI - Simpleframes
UI: What are BACKDROPs?
UI: GLUEBUTTON
UI: TEXTAREA the scrolling Text Frame
UI: EditBox - Text Input
[JASS/AI] - UI: Creating a Cam control
UI: Showing 3 Multiboards
UI: OriginFrames
Default Names for BlzGetFrameByName (Access to Existing game-Frames)
[JASS/AI] - UI: List - Default MainFrames (built in CreateAble)
UI: Change Lumber Text
[JASS/AI] - UI: Create a TextButton
[JASS/AI] - UI: Positionate Frames (important)
UI: toc-Files
UI: Reading a FDF
UI - The concept of Parent-Frames
[JASS/AI] - UI: FrameEvents and FrameTypes
UI: Frames and Tooltips
[JASS/AI] - UI: Creating a Bar
UI - Simpleframes
UI: What are BACKDROPs?
UI: GLUEBUTTON
UI: TEXTAREA the scrolling Text Frame
UI: EditBox - Text Input
[JASS/AI] - UI: Creating a Cam control
UI: Showing 3 Multiboards
UI: OriginFrames
Default Names for BlzGetFrameByName (Access to Existing game-Frames)
[JASS/AI] - UI: List - Default MainFrames (built in CreateAble)
Attachments
Last edited by a moderator: