mirror of
https://github.com/edubart/otclient.git
synced 2025-10-16 12:34:55 +02:00
add menu example in playerground module
This commit is contained in:
@@ -48,6 +48,8 @@ void LuaInterface::registerFunctions()
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getSize", &UIWidget::getSize);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("setSize", &UIWidget::resize);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getPosition", &UIWidget::getPosition);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getX", &UIWidget::getX);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getY", &UIWidget::getY);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("moveTo", &UIWidget::moveTo);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("moveChildToIndex", &UIWidget::moveChildToIndex);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getParent", &UIWidget::getParent);
|
||||
@@ -59,6 +61,7 @@ void LuaInterface::registerFunctions()
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getOpacity", &UIWidget::getOpacity);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("setOpacity", &UIWidget::setOpacity);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("setStyle", &UIWidget::setStyle);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("applyStyle", &UIWidget::applyStyle);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getStyle", &UIWidget::getStyle);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getMarginTop", &UIWidget::getMarginTop);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("setMarginTop", &UIWidget::setMarginTop);
|
||||
|
@@ -252,6 +252,29 @@ void push_luavalue(const OTMLNodePtr& node)
|
||||
g_lua.pushNil();
|
||||
}
|
||||
|
||||
bool luavalue_cast(int index, OTMLNodePtr& node)
|
||||
{
|
||||
node = OTMLNode::create();
|
||||
node->setUnique(true);
|
||||
if(g_lua.isTable(index)) {
|
||||
g_lua.pushNil();
|
||||
while(g_lua.next(index < 0 ? index-1 : index)) {
|
||||
std::string cnodeName = g_lua.toString(-2);
|
||||
if(g_lua.isTable()) {
|
||||
OTMLNodePtr cnode;
|
||||
if(luavalue_cast(-1, node)) {
|
||||
cnode->setTag(cnodeName);
|
||||
node->addChild(cnode);
|
||||
}
|
||||
} else
|
||||
node->writeAt(cnodeName, g_lua.toString());
|
||||
g_lua.pop();
|
||||
}
|
||||
} else
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// object ptr
|
||||
bool luavalue_cast(int index, LuaObjectPtr& obj) {
|
||||
if(g_lua.isUserdata(index)) {
|
||||
|
@@ -70,6 +70,7 @@ bool luavalue_cast(int index, Size& size);
|
||||
|
||||
// otml nodes
|
||||
void push_luavalue(const OTMLNodePtr& node);
|
||||
bool luavalue_cast(int index, OTMLNodePtr& node);
|
||||
|
||||
// enum
|
||||
template<class T>
|
||||
|
@@ -75,8 +75,10 @@ void UIWidget::setup()
|
||||
void UIWidget::destroy()
|
||||
{
|
||||
// remove itself from parent
|
||||
if(UIWidgetPtr parent = getParent())
|
||||
parent->removeChild(asUIWidget());
|
||||
if(UIWidgetPtr parent = getParent()) {
|
||||
if(parent->hasChild(asUIWidget()))
|
||||
parent->removeChild(asUIWidget());
|
||||
}
|
||||
setVisible(false);
|
||||
setEnabled(false);
|
||||
}
|
||||
@@ -680,10 +682,10 @@ void UIWidget::updateState(Fw::WidgetState state)
|
||||
|
||||
updateStyle();
|
||||
|
||||
if(state == Fw::FocusState)
|
||||
onFocusChange(newStatus, m_lastFocusReason);
|
||||
else if(state == Fw::HoverState)
|
||||
onHoverChange(newStatus);
|
||||
if(state == Fw::FocusState) {
|
||||
g_dispatcher.addEvent(std::bind(&UIWidget::onFocusChange, asUIWidget(), newStatus, m_lastFocusReason));
|
||||
} else if(state == Fw::HoverState)
|
||||
g_dispatcher.addEvent(std::bind(&UIWidget::onHoverChange, asUIWidget(), newStatus));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -884,6 +886,7 @@ void UIWidget::onStyleApply(const OTMLNodePtr& styleNode)
|
||||
anchorLayout->addAnchor(asUIWidget(), anchoredEdge, hookedWidgetId, hookedEdge);
|
||||
}
|
||||
} else if(node->tag() == "onClick" ||
|
||||
node->tag() == "onMousePress" ||
|
||||
node->tag() == "onHoverChange") {
|
||||
g_lua.loadFunction(node->value(), "@" + node->source() + "[" + node->tag() + "]");
|
||||
luaSetField(node->tag());
|
||||
|
Reference in New Issue
Block a user