From 9159e14895bd84997bef4e7e2233d3acfb16c9ea Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Wed, 16 Nov 2011 16:59:55 -0200 Subject: [PATCH] implement auto login and remember password --- modules/core/ext/string.lua | 14 +++++++++++- modules/entergame/characterlist.otui | 16 +++++++++++-- modules/entergame/entergame.lua | 28 ++++++++++++++++++++++- modules/entergame/entergame.otui | 10 +++++--- src/framework/luascript/luavaluecasts.cpp | 2 -- src/framework/ui/uiwidget.cpp | 2 +- 6 files changed, 62 insertions(+), 10 deletions(-) diff --git a/modules/core/ext/string.lua b/modules/core/ext/string.lua index 5675152e..18c56379 100644 --- a/modules/core/ext/string.lua +++ b/modules/core/ext/string.lua @@ -10,5 +10,17 @@ function string:split(sep) end function string:starts(start) - return self:sub(1, #start) == start + return self:sub(1, #start) == start end + +function string.trim(str) + return str:match'^%s*(.*%S)' or '' +end + +function toboolean(str) + str = string.trim(str) + if str == '1' or str == 'true' then + return true + end + return false +end \ No newline at end of file diff --git a/modules/entergame/characterlist.otui b/modules/entergame/characterlist.otui index f92438a5..f0e18eaf 100644 --- a/modules/entergame/characterlist.otui +++ b/modules/entergame/characterlist.otui @@ -15,7 +15,7 @@ CharacterListLabel < Label MainWindow id: charactersWindow title: Character List - size: 250 250 + size: 250 248 onEnter: CharacterList.doLogin() onEscape: CharacterList.destroy() @@ -35,11 +35,12 @@ MainWindow Free Account anchors.left: parent.left anchors.right: parent.right - anchors.bottom: next.top + anchors.bottom: separator.top margin.left: 16 margin.bottom: 5 HorizontalSeparator + id: separator anchors.left: parent.left anchors.right: parent.right anchors.bottom: next.top @@ -47,6 +48,17 @@ MainWindow margin.right: 16 margin.bottom: 10 + CheckBox + id: charAutoLoginBox + text: Auto login + tooltip: Auto login selected character on next charlist load + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: next.top + margin.bottom: 6 + margin.left: 18 + margin.right: 18 + Button id: buttonOk text: Ok diff --git a/modules/entergame/entergame.lua b/modules/entergame/entergame.lua index 03bb6350..ed9b0dfb 100644 --- a/modules/entergame/entergame.lua +++ b/modules/entergame/entergame.lua @@ -10,7 +10,7 @@ local motdMessage local function onError(protocol, error) loadBox:destroy() local errorBox = displayErrorBox('Login Error', error) - errorBox.onOk = EnterGame.create + errorBox.onOk = EnterGame.show end local function onMotd(protocol, motd) @@ -20,6 +20,17 @@ local function onMotd(protocol, motd) end local function onCharacterList(protocol, characters, premDays) + if enterGame:getChildById('rememberPasswordBox'):isChecked() then + Configs.set('account', EnterGame.account) + Configs.set('password', EnterGame.password) + Configs.set('autologin', tostring(enterGame:getChildById('autoLoginBox'):isChecked())) + else + Configs.set('account', nil) + Configs.set('password', nil) + enterGame:getChildById('accountNameLineEdit'):clearText() + enterGame:getChildById('accountPasswordLineEdit'):clearText() + end + loadBox:destroy() CharacterList.create(characters, premDays) @@ -35,6 +46,21 @@ end -- public functions function EnterGame.create() enterGame = UI.loadAndDisplay('/entergame/entergame.otui') + + local account = Configs.get('account') + local password = Configs.get('password') + local autologin = toboolean(Configs.get('autologin')) + + enterGame:getChildById('accountNameLineEdit'):setText(account) + enterGame:getChildById('accountPasswordLineEdit'):setText(password) + + if #account > 0 then + enterGame:getChildById('rememberPasswordBox'):setChecked(true) + if autologin then + enterGame:getChildById('autoLoginBox'):setChecked(true) + addEvent(EnterGame.doLogin) + end + end end function EnterGame.destroy() diff --git a/modules/entergame/entergame.otui b/modules/entergame/entergame.otui index 1c821fa5..3b1916c1 100644 --- a/modules/entergame/entergame.otui +++ b/modules/entergame/entergame.otui @@ -14,7 +14,6 @@ MainWindow LineEdit id: accountNameLineEdit - text: otclient0 anchors.left: parent.left anchors.right: parent.right anchors.top: prev.bottom @@ -30,7 +29,6 @@ MainWindow PasswordLineEdit id: accountPasswordLineEdit - text: 123456 anchors.left: parent.left anchors.right: parent.right anchors.top: prev.bottom @@ -41,17 +39,23 @@ MainWindow CheckBox id: rememberPasswordBox text: Remember password - checked: true + tooltip: Remember account and password when starts otclient anchors.left: parent.left anchors.right: parent.right anchors.top: prev.bottom margin.top: 10 margin.left: 18 margin.right: 18 + @onCheckChange: | + function(self, checked) + self:getParent():getChildById('autoLoginBox'):setEnabled(checked) + end CheckBox id: autoLoginBox + enabled: false text: Auto login + tooltip: Open charlist automatically when starting otclient anchors.left: parent.left anchors.right: parent.right anchors.top: prev.bottom diff --git a/src/framework/luascript/luavaluecasts.cpp b/src/framework/luascript/luavaluecasts.cpp index 2287b485..54185cbd 100644 --- a/src/framework/luascript/luavaluecasts.cpp +++ b/src/framework/luascript/luavaluecasts.cpp @@ -92,8 +92,6 @@ void push_luavalue(const std::string& str) bool luavalue_cast(int index, std::string& str) { str = g_lua.toString(index); - if(str.empty() && g_lua.isString(index) && !g_lua.isNil()) - return false; return true; } diff --git a/src/framework/ui/uiwidget.cpp b/src/framework/ui/uiwidget.cpp index 6a20b5e2..539c6031 100644 --- a/src/framework/ui/uiwidget.cpp +++ b/src/framework/ui/uiwidget.cpp @@ -361,7 +361,7 @@ void UIWidget::addChild(const UIWidgetPtr& child) auto self = asUIWidget(); g_dispatcher.addEvent([self,child]() { // always focus new child - if(child->isFocusable() && child->isExplicitlyVisible() && child->isExplicitlyEnabled()) + if(child->getParent() == self && child->isFocusable() && child->isExplicitlyVisible() && child->isExplicitlyEnabled()) self->focusChild(child, Fw::ActiveFocusReason); });