2011-07-13 23:12:36 +02:00
|
|
|
#include <global.h>
|
2011-07-17 02:13:53 +02:00
|
|
|
#include <script/scriptfunctions.h>
|
|
|
|
#include <script/scriptcontext.h>
|
2011-04-22 00:44:30 +02:00
|
|
|
#include <core/engine.h>
|
|
|
|
#include <core/resources.h>
|
|
|
|
#include <ui/ui.h>
|
2011-05-02 06:13:57 +02:00
|
|
|
#include <core/dispatcher.h>
|
2011-05-31 03:55:34 +02:00
|
|
|
#include "../../protocollogin.h"
|
2011-04-22 00:44:30 +02:00
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
#include <boost/algorithm/string.hpp>
|
2011-04-22 00:44:30 +02:00
|
|
|
|
2011-05-01 20:47:35 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2011-07-17 08:56:57 +02:00
|
|
|
// App
|
2011-05-01 20:47:35 +02:00
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
int lua_App_exit() {
|
2011-04-22 00:44:30 +02:00
|
|
|
g_engine.stop();
|
2011-07-17 08:56:57 +02:00
|
|
|
return 0;
|
2011-04-22 00:44:30 +02:00
|
|
|
}
|
|
|
|
|
2011-05-01 20:47:35 +02:00
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
|
2011-05-01 20:47:35 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2011-07-17 08:56:57 +02:00
|
|
|
// UI
|
2011-05-01 20:47:35 +02:00
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
int lua_UI_load() {
|
2011-04-22 00:44:30 +02:00
|
|
|
UIContainerPtr parent;
|
2011-07-17 08:56:57 +02:00
|
|
|
if(g_lua.getStackSize() > 1)
|
2011-05-01 20:47:35 +02:00
|
|
|
parent = boost::dynamic_pointer_cast<UIContainer>(g_lua.popClassInstance());
|
2011-07-17 08:56:57 +02:00
|
|
|
else
|
2011-05-01 20:47:35 +02:00
|
|
|
parent = UIContainer::getRoot();
|
2011-04-22 20:48:02 +02:00
|
|
|
|
2011-05-01 20:47:35 +02:00
|
|
|
std::string uiFile = g_lua.popString();
|
2011-04-22 20:48:02 +02:00
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
if(!boost::ends_with(uiFile, ".otml"))
|
|
|
|
uiFile.append(".otml");
|
|
|
|
|
2011-04-22 20:48:02 +02:00
|
|
|
UIElementPtr element;
|
2011-07-17 08:56:57 +02:00
|
|
|
if(parent) {
|
2011-05-21 20:15:46 +02:00
|
|
|
element = g_uiLoader.loadFromFile(uiFile.c_str(), parent);
|
2011-07-17 08:56:57 +02:00
|
|
|
if(!element) {
|
|
|
|
g_lua.reportFuncErrorWithTraceback("failed to load UI");
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
g_lua.reportFuncErrorWithTraceback("invalid parent container");
|
2011-04-22 20:48:02 +02:00
|
|
|
|
2011-05-01 20:47:35 +02:00
|
|
|
g_lua.pushClassInstance(element);
|
2011-04-22 00:44:30 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
int lua_UI_getRootContainer() {
|
2011-05-01 20:47:35 +02:00
|
|
|
UIContainerPtr rootContainer = UIContainer::getRoot();
|
|
|
|
g_lua.pushClassInstance(rootContainer);
|
2011-04-22 00:44:30 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-05-01 20:47:35 +02:00
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
|
2011-05-01 20:47:35 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// UIElement
|
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
UIElementPtr lua_createUIElement(UI::ElementType elementType)
|
2011-04-22 15:49:46 +02:00
|
|
|
{
|
2011-07-17 08:56:57 +02:00
|
|
|
std::string id;
|
|
|
|
UIContainerPtr parent;
|
|
|
|
|
|
|
|
if(g_lua.getStackSize() > 1)
|
|
|
|
parent = boost::dynamic_pointer_cast<UIContainer>(g_lua.popClassInstance());
|
|
|
|
|
|
|
|
if(g_lua.getStackSize() > 0) {
|
|
|
|
if(g_lua.isString())
|
|
|
|
id = g_lua.popString();
|
|
|
|
else
|
|
|
|
parent = boost::dynamic_pointer_cast<UIContainer>(g_lua.popClassInstance());
|
|
|
|
}
|
|
|
|
|
|
|
|
UIElementPtr element;
|
|
|
|
switch(elementType) {
|
|
|
|
case UI::Element:
|
|
|
|
element = UIElementPtr(new UIElement);
|
|
|
|
break;
|
|
|
|
case UI::Container:
|
|
|
|
element = UIElementPtr(new UIContainer);
|
|
|
|
break;
|
|
|
|
case UI::Label:
|
|
|
|
element = UIElementPtr(new UILabel);
|
|
|
|
break;
|
|
|
|
case UI::Button:
|
|
|
|
element = UIElementPtr(new UIButton);
|
|
|
|
break;
|
|
|
|
case UI::TextEdit:
|
|
|
|
element = UIElementPtr(new UITextEdit);
|
|
|
|
break;
|
|
|
|
case UI::Window:
|
|
|
|
element = UIElementPtr(new UIWindow);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(element) {
|
|
|
|
if(!id.empty())
|
|
|
|
element->setId(id);
|
|
|
|
|
|
|
|
if(parent)
|
|
|
|
parent->addChild(element);
|
|
|
|
|
|
|
|
element->applyDefaultSkin();
|
|
|
|
}
|
|
|
|
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
|
|
|
int lua_UIElement_new() {
|
|
|
|
g_lua.pushClassInstance(lua_createUIElement(UI::Element));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int lua_UIElement_getId() {
|
2011-05-03 00:48:41 +02:00
|
|
|
if(UIElementPtr element = boost::dynamic_pointer_cast<UIElement>(g_lua.popClassInstance()))
|
|
|
|
g_lua.pushString(element->getId());
|
|
|
|
else
|
|
|
|
g_lua.pushNil();
|
2011-04-22 15:49:46 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
int lua_UIElement_setId() {
|
2011-05-03 00:48:41 +02:00
|
|
|
std::string id = g_lua.popString();
|
|
|
|
if(UIElementPtr element = boost::dynamic_pointer_cast<UIElement>(g_lua.popClassInstance()))
|
|
|
|
element->setId(id);
|
2011-07-17 08:56:57 +02:00
|
|
|
return 0;
|
2011-05-03 00:48:41 +02:00
|
|
|
}
|
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
int lua_UIElement_isEnabled() {
|
2011-05-03 00:48:41 +02:00
|
|
|
if(UIElementPtr element = boost::dynamic_pointer_cast<UIElement>(g_lua.popClassInstance()))
|
|
|
|
g_lua.pushBoolean(element->isEnabled());
|
2011-05-01 20:47:35 +02:00
|
|
|
else
|
2011-05-03 00:48:41 +02:00
|
|
|
g_lua.pushNil();
|
2011-04-23 05:28:23 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
int lua_UIElement_setEnabled() {
|
2011-05-03 00:48:41 +02:00
|
|
|
bool enabled = g_lua.popBoolean();
|
2011-05-01 20:47:35 +02:00
|
|
|
if(UIElementPtr element = boost::dynamic_pointer_cast<UIElement>(g_lua.popClassInstance()))
|
2011-05-03 00:48:41 +02:00
|
|
|
element->setEnabled(enabled);
|
2011-07-17 08:56:57 +02:00
|
|
|
return 0;
|
2011-05-03 00:48:41 +02:00
|
|
|
}
|
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
int lua_UIElement_isVisible() {
|
2011-05-03 00:48:41 +02:00
|
|
|
if(UIElementPtr element = boost::dynamic_pointer_cast<UIElement>(g_lua.popClassInstance()))
|
|
|
|
g_lua.pushBoolean(element->isVisible());
|
2011-05-01 20:47:35 +02:00
|
|
|
else
|
|
|
|
g_lua.pushNil();
|
2011-04-23 05:28:23 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
int lua_UIElement_setVisible() {
|
2011-05-03 00:48:41 +02:00
|
|
|
bool visible = g_lua.popBoolean();
|
2011-05-01 20:47:35 +02:00
|
|
|
if(UIElementPtr element = boost::dynamic_pointer_cast<UIElement>(g_lua.popClassInstance()))
|
2011-05-03 00:48:41 +02:00
|
|
|
element->setVisible(visible);
|
2011-07-17 08:56:57 +02:00
|
|
|
return 0;
|
2011-04-22 15:49:46 +02:00
|
|
|
}
|
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
int lua_UIElement_isFocused() {
|
2011-05-03 00:48:41 +02:00
|
|
|
if(UIElementPtr element = boost::dynamic_pointer_cast<UIElement>(g_lua.popClassInstance()))
|
|
|
|
g_lua.pushBoolean(element->isFocused());
|
|
|
|
else
|
|
|
|
g_lua.pushNil();
|
|
|
|
return 1;
|
|
|
|
}
|
2011-05-01 20:47:35 +02:00
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
int lua_UIElement_setFocused() {
|
2011-05-03 00:48:41 +02:00
|
|
|
bool focused = g_lua.popBoolean();
|
|
|
|
if(UIElementPtr element = boost::dynamic_pointer_cast<UIElement>(g_lua.popClassInstance()))
|
|
|
|
element->setFocused(focused);
|
2011-07-17 08:56:57 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int lua_UIElement_getWidth() {
|
|
|
|
if(UIElementPtr element = boost::dynamic_pointer_cast<UIElement>(g_lua.popClassInstance()))
|
|
|
|
g_lua.pushInteger(element->getWidth());
|
|
|
|
else
|
|
|
|
g_lua.pushInteger(0);
|
2011-05-03 00:48:41 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2011-05-01 20:47:35 +02:00
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
int lua_UIElement_setWidth() {
|
|
|
|
int width = g_lua.popInteger();
|
|
|
|
if(UIElementPtr element = boost::dynamic_pointer_cast<UIElement>(g_lua.popClassInstance()))
|
|
|
|
element->setWidth(width);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int lua_UIElement_getHeight() {
|
|
|
|
if(UIElementPtr element = boost::dynamic_pointer_cast<UIElement>(g_lua.popClassInstance()))
|
|
|
|
g_lua.pushInteger(element->getHeight());
|
|
|
|
else
|
|
|
|
g_lua.pushInteger(0);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int lua_UIElement_setHeight() {
|
|
|
|
int height = g_lua.popInteger();
|
|
|
|
if(UIElementPtr element = boost::dynamic_pointer_cast<UIElement>(g_lua.popClassInstance()))
|
|
|
|
element->setHeight(height);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int lua_UIElement_getParent() {
|
2011-05-03 00:48:41 +02:00
|
|
|
if(UIElementPtr element = boost::dynamic_pointer_cast<UIElement>(g_lua.popClassInstance()))
|
|
|
|
g_lua.pushClassInstance(element->getParent());
|
2011-04-22 15:49:46 +02:00
|
|
|
else
|
2011-05-01 20:47:35 +02:00
|
|
|
g_lua.pushNil();
|
2011-04-22 00:44:30 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
int lua_UIElement_setParent() {
|
2011-05-03 00:48:41 +02:00
|
|
|
UIContainerPtr parent = boost::dynamic_pointer_cast<UIContainer>(g_lua.popClassInstance());
|
|
|
|
if(UIElementPtr element = boost::dynamic_pointer_cast<UIElement>(g_lua.popClassInstance()))
|
|
|
|
element->setParent(parent);
|
2011-07-17 08:56:57 +02:00
|
|
|
return 0;
|
2011-05-03 00:48:41 +02:00
|
|
|
}
|
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
int lua_UIElement_setLocked() {
|
|
|
|
bool locked = true;
|
|
|
|
if(g_lua.getStackSize() > 1)
|
|
|
|
locked = g_lua.popBoolean();
|
|
|
|
|
2011-05-01 20:47:35 +02:00
|
|
|
if(UIElementPtr element = boost::dynamic_pointer_cast<UIElement>(g_lua.popClassInstance())) {
|
2011-05-02 06:13:57 +02:00
|
|
|
if(UIContainerPtr container = element->getParent()) {
|
|
|
|
if(locked)
|
|
|
|
container->lockElement(element);
|
|
|
|
else
|
|
|
|
container->unlockElement(element);
|
2011-07-17 08:56:57 +02:00
|
|
|
} else
|
|
|
|
g_lua.reportFuncErrorWithTraceback("locking failed, element has no parent");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int lua_UIElement_setMargin() {
|
|
|
|
int top = 0, right = 0, bottom = 0, left = 0;
|
|
|
|
if(g_lua.getStackSize() == 5) {
|
|
|
|
left = g_lua.popInteger();
|
|
|
|
bottom = g_lua.popInteger();
|
|
|
|
right = g_lua.popInteger();
|
|
|
|
top = g_lua.popInteger();
|
|
|
|
} else if(g_lua.getStackSize() == 3) {
|
|
|
|
left = right = g_lua.popInteger();
|
|
|
|
top = bottom = g_lua.popInteger();
|
|
|
|
} else if(g_lua.getStackSize() == 2) {
|
|
|
|
top = right = bottom = left = g_lua.popInteger();
|
2011-05-01 20:47:35 +02:00
|
|
|
} else {
|
2011-07-17 08:56:57 +02:00
|
|
|
g_lua.reportFuncErrorWithTraceback("invalid number of arguments");
|
2011-05-01 20:47:35 +02:00
|
|
|
}
|
2011-07-17 08:56:57 +02:00
|
|
|
|
|
|
|
if(UIElementPtr element = boost::dynamic_pointer_cast<UIElement>(g_lua.popClassInstance()))
|
|
|
|
element->setMargin(top, right, bottom, left);
|
|
|
|
return 0;
|
2011-05-01 20:47:35 +02:00
|
|
|
}
|
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
int lua_UIElement_destroy() {
|
2011-05-03 00:48:41 +02:00
|
|
|
if(UIElementPtr element = boost::dynamic_pointer_cast<UIElement>(g_lua.popClassInstance()))
|
2011-05-09 22:38:01 +02:00
|
|
|
element->destroyLater();
|
2011-07-17 02:13:53 +02:00
|
|
|
g_dispatcher.addTask(boost::bind(&ScriptContext::collectGarbage, &g_lua));
|
2011-07-17 08:56:57 +02:00
|
|
|
return 0;
|
2011-05-03 00:48:41 +02:00
|
|
|
}
|
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
int lua_UIElement_centerIn() {
|
|
|
|
std::string targetId;
|
|
|
|
if(g_lua.isString())
|
|
|
|
targetId = g_lua.popString();
|
|
|
|
else if(UIElementPtr target = boost::dynamic_pointer_cast<UIElement>(g_lua.popClassInstance()))
|
|
|
|
targetId = target->getId();
|
|
|
|
|
|
|
|
if(UIElementPtr element = boost::dynamic_pointer_cast<UIElement>(g_lua.popClassInstance()))
|
|
|
|
element->centerIn(targetId);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int lua_UIElement_addAnchor() {
|
|
|
|
AnchorPoint targetEdge = (AnchorPoint)g_lua.popInteger();
|
|
|
|
|
|
|
|
std::string targetId;
|
|
|
|
if(g_lua.isString())
|
|
|
|
targetId = g_lua.popString();
|
|
|
|
else if(UIElementPtr target = boost::dynamic_pointer_cast<UIElement>(g_lua.popClassInstance()))
|
|
|
|
targetId = target->getId();
|
|
|
|
|
|
|
|
AnchorPoint anchoredEdge = (AnchorPoint)g_lua.popInteger();
|
|
|
|
|
|
|
|
if(UIElementPtr element = boost::dynamic_pointer_cast<UIElement>(g_lua.popClassInstance()))
|
|
|
|
element->addAnchor(anchoredEdge, AnchorLine(targetId, targetEdge));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-03 00:48:41 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// UIContainer
|
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
int lua_UIContainer_new() {
|
|
|
|
g_lua.pushClassInstance(lua_createUIElement(UI::Container));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int lua_UIContainer_child() {
|
2011-05-03 00:48:41 +02:00
|
|
|
std::string id = g_lua.popString();
|
|
|
|
if(UIContainerPtr container = boost::dynamic_pointer_cast<UIContainer>(g_lua.popClassInstance()))
|
|
|
|
g_lua.pushClassInstance(container->getChildById(id));
|
|
|
|
else
|
|
|
|
g_lua.pushNil();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
int lua_UIContainer_getChildren() {
|
2011-05-03 00:48:41 +02:00
|
|
|
if(UIContainerPtr container = boost::dynamic_pointer_cast<UIContainer>(g_lua.popClassInstance())) {
|
|
|
|
g_lua.newTable();
|
|
|
|
foreach(const UIElementPtr& child, container->getChildren()) {
|
|
|
|
g_lua.pushClassInstance(child);
|
|
|
|
if(child->getId().length())
|
|
|
|
g_lua.setField(child->getId());
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
g_lua.pushNil();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
int lua_UIContainer_addChild() {
|
|
|
|
UIElementPtr child = boost::dynamic_pointer_cast<UIElement>(g_lua.popClassInstance());
|
|
|
|
UIContainerPtr container = boost::dynamic_pointer_cast<UIContainer>(g_lua.popClassInstance());
|
|
|
|
if(container && child)
|
|
|
|
container->addChild(child);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-05-01 20:47:35 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// UILabel
|
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
int lua_UILabel_new() {
|
|
|
|
g_lua.pushClassInstance(lua_createUIElement(UI::Label));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int lua_UILabel_setText() {
|
2011-05-01 20:47:35 +02:00
|
|
|
std::string text = g_lua.popString();
|
|
|
|
if(UILabelPtr label = boost::dynamic_pointer_cast<UILabel>(g_lua.popClassInstance()))
|
|
|
|
label->setText(text);
|
2011-07-17 08:56:57 +02:00
|
|
|
return 0;
|
2011-05-01 20:47:35 +02:00
|
|
|
}
|
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
int lua_UILabel_getText() {
|
2011-05-01 20:47:35 +02:00
|
|
|
if(UILabelPtr label = boost::dynamic_pointer_cast<UILabel>(g_lua.popClassInstance()))
|
|
|
|
g_lua.pushString(label->getText());
|
2011-04-22 15:49:46 +02:00
|
|
|
else
|
2011-05-01 20:47:35 +02:00
|
|
|
g_lua.pushNil();
|
2011-04-22 15:49:46 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-05-31 03:55:34 +02:00
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
|
2011-05-31 03:55:34 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2011-07-17 08:56:57 +02:00
|
|
|
// UIButton
|
2011-05-31 03:55:34 +02:00
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
int lua_UIButton_new() {
|
|
|
|
g_lua.pushClassInstance(lua_createUIElement(UI::Button));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int lua_UIButton_setText() {
|
|
|
|
std::string text = g_lua.popString();
|
|
|
|
if(UIButtonPtr button = boost::dynamic_pointer_cast<UIButton>(g_lua.popClassInstance()))
|
|
|
|
button->setText(text);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int lua_UIButton_getText() {
|
|
|
|
if(UIButtonPtr button = boost::dynamic_pointer_cast<UIButton>(g_lua.popClassInstance()))
|
|
|
|
g_lua.pushString(button->getText());
|
|
|
|
else
|
|
|
|
g_lua.pushNil();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// UITextEdit
|
|
|
|
|
|
|
|
int lua_UITextEdit_new() {
|
|
|
|
g_lua.pushClassInstance(lua_createUIElement(UI::TextEdit));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int lua_UITextEdit_setText() {
|
2011-05-31 03:55:34 +02:00
|
|
|
std::string text = g_lua.popString();
|
|
|
|
if(UITextEditPtr textEdit = boost::dynamic_pointer_cast<UITextEdit>(g_lua.popClassInstance()))
|
|
|
|
textEdit->setText(text);
|
2011-07-17 08:56:57 +02:00
|
|
|
return 0;
|
2011-05-31 03:55:34 +02:00
|
|
|
}
|
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
int lua_UITextEdit_getText() {
|
2011-05-31 03:55:34 +02:00
|
|
|
if(UITextEditPtr textEdit = boost::dynamic_pointer_cast<UITextEdit>(g_lua.popClassInstance()))
|
|
|
|
g_lua.pushString(textEdit->getText());
|
|
|
|
else
|
|
|
|
g_lua.pushNil();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
|
|
|
|
|
2011-05-01 20:47:35 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// UIWindow
|
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
int lua_UIWindow_new() {
|
|
|
|
g_lua.pushClassInstance(lua_createUIElement(UI::Window));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int lua_UIWindow_setTitle() {
|
2011-05-01 20:47:35 +02:00
|
|
|
std::string title = g_lua.popString();
|
|
|
|
if(UIWindowPtr window = boost::dynamic_pointer_cast<UIWindow>(g_lua.popClassInstance()))
|
|
|
|
window->setTitle(title);
|
2011-07-17 08:56:57 +02:00
|
|
|
return 0;
|
2011-04-22 15:49:46 +02:00
|
|
|
}
|
2011-04-22 00:44:30 +02:00
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
int lua_UIWindow_getTitle() {
|
2011-05-01 20:47:35 +02:00
|
|
|
if(UIWindowPtr window = boost::dynamic_pointer_cast<UIWindow>(g_lua.popClassInstance()))
|
|
|
|
g_lua.pushString(window->getTitle());
|
|
|
|
else
|
|
|
|
g_lua.pushNil();
|
2011-04-22 00:44:30 +02:00
|
|
|
return 1;
|
2011-04-22 15:49:46 +02:00
|
|
|
}
|
2011-07-17 08:56:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void registerScriptFunctions()
|
|
|
|
{
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// App
|
|
|
|
g_lua.registerModule("App");
|
|
|
|
// App.exit()
|
|
|
|
g_lua.registerMemberFunction("exit", &lua_App_exit);
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// UI
|
|
|
|
g_lua.registerClass("UI");
|
|
|
|
// UI.load(file, [parent])
|
|
|
|
g_lua.registerMemberFunction("load", &lua_UI_load);
|
|
|
|
// UI.getRootContainer()
|
|
|
|
g_lua.registerMemberFunction("getRootContainer", &lua_UI_getRootContainer);
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// UIElement
|
|
|
|
g_lua.registerClass("UIElement");
|
|
|
|
// (UIElement) UIElement.new([UIContainer parent], [string id])
|
|
|
|
g_lua.registerMemberFunction("new", &lua_UIElement_new);
|
|
|
|
// (string) UIElement.id
|
|
|
|
g_lua.registerMemberField("id", &lua_UIElement_getId, &lua_UIElement_setId);
|
|
|
|
// (boolean) UIElement.enabled
|
|
|
|
g_lua.registerMemberField("enabled", &lua_UIElement_isEnabled, &lua_UIElement_setEnabled);
|
|
|
|
// (boolean UIElement.visible
|
|
|
|
g_lua.registerMemberField("visible", &lua_UIElement_isVisible, &lua_UIElement_setVisible);
|
|
|
|
// (boolean UIElement.focused
|
|
|
|
g_lua.registerMemberField("focused", &lua_UIElement_isFocused, &lua_UIElement_setFocused);
|
|
|
|
// (integer) UIElement.width
|
|
|
|
g_lua.registerMemberField("width", &lua_UIElement_getWidth, &lua_UIElement_setWidth);
|
|
|
|
// (integer) UIElement.height
|
|
|
|
g_lua.registerMemberField("height", &lua_UIElement_getHeight, &lua_UIElement_setHeight);
|
|
|
|
// (UIContainer UIElement.parent
|
|
|
|
g_lua.registerMemberField("parent", &lua_UIElement_getParent, &lua_UIElement_setParent);
|
|
|
|
// element:setLocked(boolean locked)
|
|
|
|
g_lua.registerMemberFunction("setLocked", &lua_UIElement_setLocked);
|
|
|
|
// element:setMargin(int all)
|
|
|
|
// element:setMargin(int vertical, int horizontal)
|
|
|
|
// element:setMargin(int top, right, bottom, left)
|
|
|
|
g_lua.registerMemberFunction("setMargin", &lua_UIElement_setMargin);
|
|
|
|
// element:destroy()
|
|
|
|
g_lua.registerMemberFunction("destroy", &lua_UIElement_destroy);
|
|
|
|
// element:centerIn(UIContainer target)
|
|
|
|
g_lua.registerMemberFunction("centerIn", &lua_UIElement_centerIn);
|
|
|
|
// element:addAnchor(AnchorPoint anchoredEdge, UIElement target, AnchorPoint targetEdge)
|
|
|
|
// element:addAnchor(AnchorPoint anchoredEdge, string targetId, AnchorPoint targetEdge)
|
|
|
|
g_lua.registerMemberFunction("addAnchor", &lua_UIElement_addAnchor);
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// UIContainer
|
|
|
|
g_lua.registerClass("UIContainer", "UIElement");
|
|
|
|
// UIContainer.new([UIContainer parent], [string id])
|
|
|
|
g_lua.registerMemberFunction("new", &lua_UIContainer_new);
|
|
|
|
// container:child(string id)
|
|
|
|
g_lua.registerMemberFunction("child", &lua_UIContainer_child);
|
|
|
|
// (table) container:children()
|
|
|
|
g_lua.registerMemberFunction("children", &lua_UIContainer_getChildren);
|
|
|
|
// container:addChild(UIElement child)
|
|
|
|
g_lua.registerMemberFunction("addChild", &lua_UIContainer_addChild);
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// UILabel
|
|
|
|
g_lua.registerClass("UILabel", "UIElement");
|
|
|
|
// UILabel.new([UIContainer parent], [string id])
|
|
|
|
g_lua.registerMemberFunction("new", &lua_UILabel_new);
|
|
|
|
// label.text
|
|
|
|
g_lua.registerMemberField("text", &lua_UILabel_getText, &lua_UILabel_setText);
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// UIButton
|
|
|
|
g_lua.registerClass("UIButton", "UIElement");
|
|
|
|
// UIButton.new([UIContainer parent], [string id])
|
|
|
|
g_lua.registerMemberFunction("new", &lua_UIButton_new);
|
|
|
|
// button.text
|
|
|
|
g_lua.registerMemberField("text", &lua_UIButton_getText, &lua_UIButton_setText);
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// UITextEdit
|
|
|
|
g_lua.registerClass("UITextEdit", "UIElement");
|
|
|
|
// UITextEdit.new([UIContainer parent], [string id])
|
|
|
|
g_lua.registerMemberFunction("new", &lua_UITextEdit_new);
|
|
|
|
// textEdit.text
|
|
|
|
g_lua.registerMemberField("text", &lua_UITextEdit_getText, &lua_UITextEdit_setText);
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// UIWindow
|
|
|
|
g_lua.registerClass("UIWindow", "UIContainer");
|
|
|
|
// UIWindow.new([UIContainer parent], [string id])
|
|
|
|
g_lua.registerMemberFunction("new", &lua_UIWindow_new);
|
|
|
|
// window.title
|
|
|
|
g_lua.registerMemberField("title", &lua_UIWindow_getTitle, &lua_UIWindow_setTitle);
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Protocol
|
|
|
|
g_lua.registerClass("ProtocolLogin");
|
|
|
|
g_lua.registerMemberFunction("new", []{
|
|
|
|
g_lua.pushClassInstance(ScriptObjectPtr(new ProtocolLogin));
|
|
|
|
return 1;
|
|
|
|
});
|
|
|
|
g_lua.registerMemberFunction("login", []{
|
|
|
|
std::string accountPassword = g_lua.popString();
|
|
|
|
std::string accountName = g_lua.popString();
|
|
|
|
if(ProtocolLoginPtr protocolLogin = boost::dynamic_pointer_cast<ProtocolLogin>(g_lua.popClassInstance()))
|
|
|
|
protocolLogin->login(accountName, accountPassword);
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
g_lua.registerMemberFunction("cancel", []{
|
|
|
|
//TODO: this func
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|