Gubailovo
Well-Known Member
- Joined
- Dec 19, 2013
- Messages
- 407
- Solutions
- 2
- Reaction score
- 62
I have a character manager in the client. It creates characters on the account and saves it to the database. But with a log out, he rolls it back.
Lua:
NewCharacter = { }
local protocolCreate
local loadBox
-- consts
SEX_MALE = 0
SEX_FEMALE = 1
-- Filter Settings
local filters = {
sex = SEX_MALE
}
-- private functions
local function onError(protocol, message, errorCode)
if loadBox then
loadBox:destroy()
loadBox = nil
end
if not errorCode then
NewCharacter.clearCharNameField()
end
local errorBox = displayErrorBox(tr('Create Error'), message)
connect(errorBox, { onOk = NewCharacter.show })
end
local function onCharacterList(protocol, characters, account, otui)
loadBox:destroy()
loadBox = nil
for _, characterInfo in pairs(characters) do
if characterInfo.previewState and characterInfo.previewState ~= PreviewState.Default then
characterInfo.worldName = characterInfo.worldName .. ', Preview'
end
end
CharacterList.create(characters, account, otui)
CharacterList.show()
end
function NewCharacter.clearCharNameField()
newCharacterWin:getChildById('characterNameTextEdit'):clearText()
newCharacterWin:getChildById('characterNameTextEdit'):focus()
end
-- public functions
function NewCharacter.init()
newCharacterWin = g_ui.displayUI('newcharacterwin')
sexBoxMale = newCharacterWin:getChildById('sexBoxMale')
sexBoxFemale = newCharacterWin:getChildById('sexBoxFemale')
sexRadioGroup = UIRadioGroup.create()
sexRadioGroup:addWidget(sexBoxMale)
sexRadioGroup:addWidget(sexBoxFemale)
sexRadioGroup:selectWidget(sexBoxMale)
sexRadioGroup.onSelectionChange = toggleFilter
--if g_app.isRunning() and g_game.isOnline() then
-- newCharacterWin:show()
--end
end
function toggleFilter(widget, selectedWidget)
if widget == sexRadioGroup then
local boxId = selectedWidget:getId()
if boxId == 'sexBoxMale' then
filters.sex = SEX_MALE
elseif boxId == 'sexBoxFemale' then
filters.sex = SEX_FEMALE
end
end
end
function NewCharacter.show()
if loadBox or errorBox or not newCharacterWin then return end
CharacterList.hide(false)
newCharacterWin:show()
newCharacterWin:raise()
newCharacterWin:focus()
end
function NewCharacter.hide()
newCharacterWin:hide()
if CharacterList and not g_game.isOnline() then
CharacterList.show()
end
end
function NewCharacter.terminate()
newCharacterWin:destroy()
newCharacterWin = nil
NewCharacter = nil
end
function NewCharacter.doCreateChar()
newCharacterWin:hide()
local characterName = newCharacterWin:getChildById('characterNameTextEdit'):getText()
local isMan = newCharacterWin:getChildById('sexBoxMale'):isChecked()
local characterSex = 0
if isMan then
characterSex = 1
end
protocolCreate = ProtocolLogin.create()
protocolCreate.onLoginError = onError
protocolCreate.onCharacterList = onCharacterList
loadBox = displayCancelBox(tr('Please wait'), tr('Create a character...'))
connect(loadBox, { onCancel = function(msgbox)
loadBox = nil
protocolCreate:cancelLogin()
NewCharacter.show()
end })
if modules.game_things.isLoaded() then
protocolCreate:createChar(G.host, G.port, G.account, G.password, characterName, characterSex)
else
loadBox:destroy()
loadBox = nil
NewCharacter.show()
end
end