Skip to content
Snippets Groups Projects
Commit c5969966 authored by dg's avatar dg
Browse files

Improves character name dialog

git-svn-id: http://svn.net-core.org/repos/t-engine4@1301 51575b47-30f0-44d4-a5cc-537603b46e54
parent 2740e9b4
No related branches found
No related tags found
No related merge requests found
......@@ -20,40 +20,92 @@
require "engine.class"
local Module = require "engine.Module"
local Dialog = require "engine.Dialog"
local Button = require "engine.Button"
local TextBox = require "engine.TextBox"
module(..., package.seeall, class.inherit(engine.Dialog))
function _M:init(runmod)
engine.Dialog.init(self, "Enter your character's name?", 300, 100)
engine.Dialog.init(self, "Enter your character's name?", 320, 110)
self.runmod = runmod
self.name = ""
self:keyCommands({
_RETURN = function()
if self.name:len() >= 2 then
game:unregisterDialog(self)
Module:instanciate(self.runmod, self.name, true)
_DELETE = function()
if self.controls[self.state] and self.controls[self.state].delete then
self.controls[self.state]:delete()
end
end,
_TAB = function()
self.state = self:changeFocus(true)
end,
_DOWN = function()
self.state = self:changeFocus(true)
end,
_UP = function()
self.state = self:changeFocus(false)
end,
_RIGHT = function()
if self.state ~= "" and self.controls[self.state] and self.controls[self.state].moveRight then
self.controls[self.state]:moveRight(1)
else
self.state = self:changeFocus(true)
end
end,
_LEFT = function()
if self.state ~= "" and self.controls[self.state] and self.controls[self.state].moveLeft then
self.controls[self.state]:moveLeft(1)
else
engine.Dialog:simplePopup("Error", "Character name must be between 2 and 25 characters.")
self.state = self:changeFocus(false)
end
end,
_BACKSPACE = function()
self.name = self.name:sub(1, self.name:len() - 1)
if self.state ~= "" and self.controls[self.state] and self.controls[self.state].type=="TextBox" then
self.controls[self.state]:backSpace()
end
end,
__TEXTINPUT = function(c)
if self.name:len() < 25 then
self.name = self.name .. c
self.changed = true
if self.state ~= "" and self.controls[self.state] and self.controls[self.state].type=="TextBox" then
self.controls[self.state]:textInput(c)
end
end,
},{
_RETURN = function()
if self.state ~= "" and self.controls[self.state] and self.controls[self.state].type=="Button" then
self.controls[self.state]:fct()
elseif self.state ~= "" and self.controls[self.state] and self.controls[self.state].type=="TextBox" then
self:okclick()
end
end,
}, {
EXIT = function()
game:unregisterDialog(self)
game:bindKeysToStep()
end
})
self:mouseZones{}
self:addControl(TextBox.new({name="name",title="Name:",min=2, max=25, x=10, y=5, w=290, h=30}, self, self.font, "name"))
self:addControl(Button.new("ok", "Ok", 50, 45, 50, 30, self, self.font, function() self:okclick() end))
self:addControl(Button.new("cancel", "Cancel", 220, 45, 50, 30, self, self.font, function() self:cancelclick() end))
self:focusControl("name")
end
function _M:okclick()
local results = self:databind()
self.name = results.name
if self.name:len() >= 2 then
game:unregisterDialog(self)
Module:instanciate(self.runmod, self.name, true)
else
engine.Dialog:simplePopup("Error", "Character name must be between 2 and 25 characters.")
end
end
function _M:cancelclick()
self.key:triggerVirtual("EXIT")
end
function _M:drawDialog(s, w, h)
s:drawColorStringCentered(self.font, "Enter your characters name:", 2, 2, self.iw - 2, self.ih - 2 - self.font:lineSkip())
s:drawColorStringCentered(self.font, self.name, 2, 2 + self.font:lineSkip(), self.iw - 2, self.ih - 2 - self.font:lineSkip())
-- s:drawColorStringCentered(self.font, "Enter your characters name:", 2, 2, self.iw - 2, self.ih - 2 - self.font:lineSkip())
-- s:drawColorStringCentered(self.font, self.name, 2, 2 + self.font:lineSkip(), self.iw - 2, self.ih - 2 - self.font:lineSkip())
self:drawControls(s)
end
......@@ -78,7 +78,7 @@ function _M:init(dialogdef, profile_help_text)
self.controls[self.state]:fct()
end
end,
}, {
}, {
EXIT = function()
game:unregisterDialog(self)
game:selectStepProfile()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment