From 9b2d71f6d88d9defa49d463535060829ba628fbd Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Mon, 30 May 2011 22:55:34 -0300 Subject: [PATCH] protocol via script --- data/modules/mainmenu/entergamewindow.yml | 1 + data/modules/mainmenu/menustate.lua | 37 +++++++++++++++++++++ data/modules/messagebox/messagebox.lua | 37 +++++++++++++++++---- src/framework/net/protocol.h | 7 +++- src/framework/script/luafunctions.cpp | 39 +++++++++++++++++++++++ src/framework/script/luafunctions.h | 4 +++ src/framework/script/scriptable.cpp | 6 ++-- src/framework/script/scriptable.h | 2 +- src/framework/ui/uibutton.cpp | 2 +- src/framework/ui/uielement.cpp | 2 +- src/framework/ui/uitextedit.h | 2 +- src/protocollogin.cpp | 7 ++-- src/protocollogin.h | 2 ++ 13 files changed, 132 insertions(+), 16 deletions(-) diff --git a/data/modules/mainmenu/entergamewindow.yml b/data/modules/mainmenu/entergamewindow.yml index 228d342b..5a20fcd8 100644 --- a/data/modules/mainmenu/entergamewindow.yml +++ b/data/modules/mainmenu/entergamewindow.yml @@ -43,6 +43,7 @@ window#enterGameWindow anchors.bottom: parent.bottom margin.bottom: 10 margin.right: 66 + onClick: enterGame_onOkClicked() button#cancelButton text: Cancel diff --git a/data/modules/mainmenu/menustate.lua b/data/modules/mainmenu/menustate.lua index fb8929c1..017ae584 100644 --- a/data/modules/mainmenu/menustate.lua +++ b/data/modules/mainmenu/menustate.lua @@ -12,6 +12,43 @@ function onApplicationClose() App.exit() end +function enterGame_onOkClicked() + local enterGameWindow = UI.getRootContainer():child("enterGameWindow") + enterGameWindow.visible = false + + local loadMessageBox = messageBox("Please wait", "Connecting..") + loadMessageBox.onDestroy = function() + --TODO: cancel protocol + enterGameWindow.visible = true + protocolLogin = nil + end + + protocolLogin = ProtocolLogin.new() + protocolLogin.onError = function(error) + loadMessageBox.onDestroy = nil + loadMessageBox:destroy() + local msgBox = messageBox("Login Error", error) + msgBox.onDestroy = function() + enterGameWindow.visible = true + end + protocolLogin = nil + end + protocolLogin.onMotd = function(motd) + loadMessageBox.onDestroy = nil + loadMessageBox:destroy() + local msgBox = messageBox("Message of the day", motd) + msgBox.onDestroy = function() + enterGameWindow.visible = true + end + protocolLogin = nil + end + + local account = enterGameWindow:child("accountNameTextEdit").text + local password = enterGameWindow:child("passwordTextEdit").text + + protocolLogin:login(account, password) +end + -- here is where everything starts if not initialStateLoaded then onEnterMenuState() diff --git a/data/modules/messagebox/messagebox.lua b/data/modules/messagebox/messagebox.lua index f4f67e14..01386656 100644 --- a/data/modules/messagebox/messagebox.lua +++ b/data/modules/messagebox/messagebox.lua @@ -1,11 +1,34 @@ -function autoDestroyParent() - self.parent:destroy() +MessageBox = {} +MessageBox.__index = MessageBox + +function MessageBox.create(title, text) + local msgBox = {} + setmetatable(msgBox, MessageBox) + + local window = UI.load("messagebox.yml") + window.locked = true + window.title = title + window:child("textLabel").text = text + window:child("okButton").onClick = function() + self.parent:destroy() + end + window.onDestroy = function() + if msgBox.onDestroy then + msgBox.onDestroy() + end + end + + msgBox.window = window + return msgBox +end + +function MessageBox:destroy() + if self.window then + self.window:destroy() + self.window = nil + end end function messageBox(title, text) - local msgBox = UI.load("messagebox.yml") - msgBox.locked = true - msgBox.title = title - msgBox:child("textLabel").text = text - msgBox:child("okButton").onClick = autoDestroyParent + return MessageBox.create(title, text) end diff --git a/src/framework/net/protocol.h b/src/framework/net/protocol.h index 9801e89c..46155a70 100644 --- a/src/framework/net/protocol.h +++ b/src/framework/net/protocol.h @@ -28,6 +28,7 @@ #include #include #include +#include