mirror of
https://github.com/edubart/otclient.git
synced 2025-12-02 16:06:51 +01:00
ctrl+g kinda working, but login/logout events still need a remake
This commit is contained in:
@@ -59,8 +59,18 @@ void LuaInterface::registerFunctions()
|
||||
g_lua.bindClassMemberFunction<UIWidget>("setMarginLeft", &UIWidget::setMarginLeft);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getMarginRight", &UIWidget::getMarginRight);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("setMarginRight", &UIWidget::setMarginRight);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("isVisible", &UIWidget::isVisible);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("isHidden", &UIWidget::isHidden);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("isHovered", &UIWidget::isHovered);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("isFocused", &UIWidget::isFocused);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("isPressed", &UIWidget::isPressed);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("isEnabled", &UIWidget::isEnabled);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("isDisabled", &UIWidget::isDisabled);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("isActive", &UIWidget::isActive);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("hide", &UIWidget::hide);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("show", &UIWidget::show);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("lock", &UIWidget::lock);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("unlock", &UIWidget::unlock);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getChildById", &UIWidget::getChildById);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getChildByIndex", &UIWidget::getChildByIndex);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getChildCount", &UIWidget::getChildCount);
|
||||
@@ -72,6 +82,7 @@ void LuaInterface::registerFunctions()
|
||||
g_lua.bindClassMemberFunction<UIWidget>("focusNextChild", &UIWidget::focusNextChild);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("focusPreviousChild", &UIWidget::focusPreviousChild);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("lockChild", &UIWidget::lockChild);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("unlockChild", &UIWidget::unlockChild);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("updateLayout", &UIWidget::updateLayout);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("updateParentLayout", &UIWidget::updateParentLayout);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("destroy", &UIWidget::destroy);
|
||||
|
||||
@@ -775,6 +775,16 @@ void LuaInterface::getGlobal(const std::string& key)
|
||||
lua_getglobal(L, key.c_str());
|
||||
}
|
||||
|
||||
void LuaInterface::getGlobalField(const std::string& globalKey, const std::string& fieldKey)
|
||||
{
|
||||
getGlobal(globalKey);
|
||||
if(!isNil()) {
|
||||
assert(isTable() || isUserdata());
|
||||
getField(fieldKey);
|
||||
remove(-2);
|
||||
}
|
||||
}
|
||||
|
||||
void LuaInterface::setGlobal(const std::string& key)
|
||||
{
|
||||
assert(hasIndex(-1));
|
||||
|
||||
@@ -164,6 +164,12 @@ public:
|
||||
/// prevents new variables in this new environment to be set on the global environment
|
||||
void newEnvironment();
|
||||
|
||||
template<typename... T>
|
||||
int callGlobalField(const std::string& global, const std::string& field, const T&... args);
|
||||
|
||||
template<typename R, typename... T>
|
||||
R callGlobalField(const std::string& global, const std::string& field, const T&... args);
|
||||
|
||||
private:
|
||||
/// Load scripts requested by lua 'require'
|
||||
static int luaScriptLoader(lua_State* L);
|
||||
@@ -221,6 +227,7 @@ public:
|
||||
void setEnv(int index = -2);
|
||||
|
||||
void getGlobal(const std::string& key);
|
||||
void getGlobalField(const std::string& globalKey, const std::string& fieldKey);
|
||||
void setGlobal(const std::string& key);
|
||||
|
||||
void rawGet(int index = -1);
|
||||
@@ -347,4 +354,27 @@ T LuaInterface::castValue(int index) {
|
||||
return o;
|
||||
}
|
||||
|
||||
template<typename... T>
|
||||
int LuaInterface::callGlobalField(const std::string& global, const std::string& field, const T&... args) {
|
||||
g_lua.getGlobalField(global, field);
|
||||
if(!g_lua.isNil()) {
|
||||
g_lua.polymorphicPush(args...);
|
||||
return g_lua.protectedCall(sizeof...(args));
|
||||
} else
|
||||
g_lua.pop(1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename R, typename... T>
|
||||
R LuaInterface::callGlobalField(const std::string& global, const std::string& field, const T&... args) {
|
||||
R result;
|
||||
int rets = callGlobalField(global, field, args...);
|
||||
if(rets > 0) {
|
||||
assert(rets == 1);
|
||||
result = g_lua.polymorphicPop<R>();
|
||||
} else
|
||||
result = R();
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -188,13 +188,7 @@ UIWidgetPtr UIManager::loadWidgetFromOTML(const OTMLNodePtr& widgetNode, const U
|
||||
std::string widgetType = styleNode->valueAt("__widgetType");
|
||||
|
||||
// call widget creation from lua
|
||||
//g_lua.getGlobalField(widgetType, "create");
|
||||
g_lua.getGlobal(widgetType);
|
||||
g_lua.getField("create");
|
||||
g_lua.remove(-2);
|
||||
g_lua.protectedCall(0, 1);
|
||||
|
||||
UIWidgetPtr widget = g_lua.polymorphicPop<UIWidgetPtr>();
|
||||
UIWidgetPtr widget = g_lua.callGlobalField<UIWidgetPtr>(widgetType, "create");
|
||||
if(parent)
|
||||
parent->addChild(widget);
|
||||
|
||||
|
||||
@@ -167,6 +167,18 @@ void UIWidget::setRect(const Rect& rect)
|
||||
m_updateEventScheduled = true;
|
||||
}
|
||||
|
||||
void UIWidget::lock()
|
||||
{
|
||||
if(UIWidgetPtr parent = getParent())
|
||||
parent->lockChild(asUIWidget());
|
||||
}
|
||||
|
||||
void UIWidget::unlock()
|
||||
{
|
||||
if(UIWidgetPtr parent = getParent())
|
||||
parent->unlockChild(asUIWidget());
|
||||
}
|
||||
|
||||
bool UIWidget::isVisible()
|
||||
{
|
||||
if(!m_visible)
|
||||
@@ -365,8 +377,11 @@ void UIWidget::removeChild(const UIWidgetPtr& child)
|
||||
auto it = std::find(m_children.begin(), m_children.end(), child);
|
||||
if(it != m_children.end()) {
|
||||
// defocus if needed
|
||||
if(m_focusedChild == child)
|
||||
bool focusAnother = false;
|
||||
if(m_focusedChild == child) {
|
||||
focusChild(nullptr, Fw::ActiveFocusReason);
|
||||
focusAnother = true;
|
||||
}
|
||||
|
||||
// unlock child if it was locked
|
||||
unlockChild(child);
|
||||
@@ -381,6 +396,9 @@ void UIWidget::removeChild(const UIWidgetPtr& child)
|
||||
|
||||
// update child states
|
||||
child->updateStates();
|
||||
|
||||
if(focusAnother)
|
||||
focusPreviousChild(Fw::ActiveFocusReason);
|
||||
} else
|
||||
logError("attempt to remove an unknown child from a UIWidget");
|
||||
}
|
||||
|
||||
@@ -73,6 +73,8 @@ public:
|
||||
void show() { setVisible(true); }
|
||||
void disable() { setEnabled(false); }
|
||||
void enable() { setEnabled(true); }
|
||||
void lock();
|
||||
void unlock();
|
||||
|
||||
bool isActive() const { return hasState(Fw::ActiveState); }
|
||||
bool isEnabled() const { return !hasState(Fw::DisabledState); }
|
||||
@@ -81,6 +83,7 @@ public:
|
||||
bool isHovered() const { return hasState(Fw::HoverState); }
|
||||
bool isPressed() const { return hasState(Fw::PressedState); }
|
||||
bool isVisible();
|
||||
bool isHidden() { return !isVisible(); }
|
||||
bool isExplicitlyEnabled() const { return m_enabled; }
|
||||
bool isExplicitlyVisible() const { return m_visible; }
|
||||
bool isFocusable() const { return m_focusable; }
|
||||
@@ -143,9 +146,6 @@ public:
|
||||
UIWidgetPtr asUIWidget() { return std::static_pointer_cast<UIWidget>(shared_from_this()); }
|
||||
|
||||
private:
|
||||
void internalDestroy();
|
||||
void internalDestroyCheck();
|
||||
|
||||
bool m_updateEventScheduled;
|
||||
|
||||
protected:
|
||||
|
||||
Reference in New Issue
Block a user