mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-31 15:32:45 +00:00
Update and document Lua Text and TextEdit widget types, fix some issues with Lua UI
This commit is contained in:
parent
7f4d4c0d70
commit
581c3f4882
@ -3,6 +3,7 @@
|
|||||||
#include <components/lua_ui/layers.hpp>
|
#include <components/lua_ui/layers.hpp>
|
||||||
#include <components/lua_ui/content.hpp>
|
#include <components/lua_ui/content.hpp>
|
||||||
#include <components/lua_ui/registerscriptsettings.hpp>
|
#include <components/lua_ui/registerscriptsettings.hpp>
|
||||||
|
#include <components/lua_ui/alignment.hpp>
|
||||||
|
|
||||||
#include "context.hpp"
|
#include "context.hpp"
|
||||||
#include "actions.hpp"
|
#include "actions.hpp"
|
||||||
@ -239,6 +240,12 @@ namespace MWLua
|
|||||||
typeTable.set(it.second, it.first);
|
typeTable.set(it.second, it.first);
|
||||||
api["TYPE"] = LuaUtil::makeReadOnly(typeTable);
|
api["TYPE"] = LuaUtil::makeReadOnly(typeTable);
|
||||||
|
|
||||||
|
api["ALIGNMENT"] = LuaUtil::makeReadOnly(context.mLua->tableFromPairs<std::string_view, LuaUi::Alignment>({
|
||||||
|
{ "Start", LuaUi::Alignment::Start },
|
||||||
|
{ "Center", LuaUi::Alignment::Center },
|
||||||
|
{ "End", LuaUi::Alignment::End }
|
||||||
|
}));
|
||||||
|
|
||||||
api["registerSettingsPage"] = &LuaUi::registerSettingsPage;
|
api["registerSettingsPage"] = &LuaUi::registerSettingsPage;
|
||||||
|
|
||||||
return LuaUtil::makeReadOnly(api);
|
return LuaUtil::makeReadOnly(api);
|
||||||
|
@ -166,7 +166,7 @@ add_component_dir (queries
|
|||||||
|
|
||||||
add_component_dir (lua_ui
|
add_component_dir (lua_ui
|
||||||
registerscriptsettings scriptsettings
|
registerscriptsettings scriptsettings
|
||||||
properties widget element util layers content
|
properties widget element util layers content alignment
|
||||||
adapter text textedit window image container
|
adapter text textedit window image container
|
||||||
)
|
)
|
||||||
|
|
||||||
|
18
components/lua_ui/alignment.cpp
Normal file
18
components/lua_ui/alignment.cpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#include "alignment.hpp"
|
||||||
|
|
||||||
|
namespace LuaUi
|
||||||
|
{
|
||||||
|
MyGUI::Align alignmentToMyGui(Alignment horizontal, Alignment vertical)
|
||||||
|
{
|
||||||
|
MyGUI::Align align(MyGUI::Align::Center);
|
||||||
|
if (horizontal == Alignment::Start)
|
||||||
|
align |= MyGUI::Align::Left;
|
||||||
|
if (horizontal == Alignment::End)
|
||||||
|
align |= MyGUI::Align::Right;
|
||||||
|
if (horizontal == Alignment::Start)
|
||||||
|
align |= MyGUI::Align::Top;
|
||||||
|
if (horizontal == Alignment::End)
|
||||||
|
align |= MyGUI::Align::Bottom;
|
||||||
|
return align;
|
||||||
|
}
|
||||||
|
}
|
18
components/lua_ui/alignment.hpp
Normal file
18
components/lua_ui/alignment.hpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#ifndef OPENMW_LUAUI_ALIGNMENT
|
||||||
|
#define OPENMW_LUAUI_ALIGNMENT
|
||||||
|
|
||||||
|
#include <MyGUI_Align.h>
|
||||||
|
|
||||||
|
namespace LuaUi
|
||||||
|
{
|
||||||
|
enum class Alignment
|
||||||
|
{
|
||||||
|
Start = 0,
|
||||||
|
Center = 1,
|
||||||
|
End = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
MyGUI::Align alignmentToMyGui(Alignment horizontal, Alignment vertical);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // !OPENMW_LUAUI_PROPERTIES
|
@ -10,8 +10,8 @@ namespace LuaUi
|
|||||||
MYGUI_RTTI_DERIVED(LuaContainer)
|
MYGUI_RTTI_DERIVED(LuaContainer)
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void updateChildren() override;
|
void updateChildren() override;
|
||||||
virtual MyGUI::IntSize childScalingSize() override;
|
MyGUI::IntSize childScalingSize() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateSizeToFit();
|
void updateSizeToFit();
|
||||||
|
@ -130,6 +130,8 @@ namespace LuaUi
|
|||||||
|
|
||||||
void updateWidget(WidgetExtension* ext, const sol::table& layout)
|
void updateWidget(WidgetExtension* ext, const sol::table& layout)
|
||||||
{
|
{
|
||||||
|
ext->resetSlot(); // otherwise if template gets changed, all non-template children will get destroyed
|
||||||
|
|
||||||
ext->setLayout(layout);
|
ext->setLayout(layout);
|
||||||
ext->setExternal(layout.get<sol::object>(LayoutKeys::external));
|
ext->setExternal(layout.get<sol::object>(LayoutKeys::external));
|
||||||
setTemplate(ext, layout.get<sol::object>(LayoutKeys::templateLayout));
|
setTemplate(ext, layout.get<sol::object>(LayoutKeys::templateLayout));
|
||||||
|
@ -19,9 +19,9 @@ namespace LuaUi
|
|||||||
|
|
||||||
// mCoord could be zero, prevent division by 0
|
// mCoord could be zero, prevent division by 0
|
||||||
// use arbitrary large numbers to prevent performance issues
|
// use arbitrary large numbers to prevent performance issues
|
||||||
if (mTileSize.width == 0)
|
if (mTileSize.width <= 0)
|
||||||
mTileSize.width = 1e7;
|
mTileSize.width = 1e7;
|
||||||
if (mTileSize.height == 0)
|
if (mTileSize.height <= 0)
|
||||||
mTileSize.height = 1e7;
|
mTileSize.height = 1e7;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ namespace LuaUi
|
|||||||
LuaImage();
|
LuaImage();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void updateProperties() override;
|
void updateProperties() override;
|
||||||
LuaTileRect* mTileRect;
|
LuaTileRect* mTileRect;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <osg/Vec2>
|
#include <osg/Vec2>
|
||||||
|
|
||||||
#include <components/lua/luastate.hpp>
|
#include <components/lua/luastate.hpp>
|
||||||
|
#include <components/misc/color.hpp>
|
||||||
|
|
||||||
namespace LuaUi
|
namespace LuaUi
|
||||||
{
|
{
|
||||||
@ -18,6 +19,12 @@ namespace LuaUi
|
|||||||
std::is_same<T, MyGUI::FloatSize>();
|
std::is_same<T, MyGUI::FloatSize>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr bool isMyGuiColor()
|
||||||
|
{
|
||||||
|
return std::is_same<T, MyGUI::Colour>();
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T, typename LuaT>
|
template <typename T, typename LuaT>
|
||||||
sol::optional<T> parseValue(
|
sol::optional<T> parseValue(
|
||||||
sol::object table,
|
sol::object table,
|
||||||
@ -41,6 +48,8 @@ namespace LuaUi
|
|||||||
LuaT luaT = opt.as<LuaT>();
|
LuaT luaT = opt.as<LuaT>();
|
||||||
if constexpr (isMyGuiVector<T>())
|
if constexpr (isMyGuiVector<T>())
|
||||||
return T(luaT.x(), luaT.y());
|
return T(luaT.x(), luaT.y());
|
||||||
|
else if constexpr (isMyGuiColor<T>())
|
||||||
|
return T(luaT.r(), luaT.g(), luaT.b(), luaT.a());
|
||||||
else
|
else
|
||||||
return luaT;
|
return luaT;
|
||||||
}
|
}
|
||||||
@ -53,6 +62,8 @@ namespace LuaUi
|
|||||||
{
|
{
|
||||||
if constexpr (isMyGuiVector<T>())
|
if constexpr (isMyGuiVector<T>())
|
||||||
return parseValue<T, osg::Vec2f>(table, field, errorPrefix);
|
return parseValue<T, osg::Vec2f>(table, field, errorPrefix);
|
||||||
|
else if constexpr (isMyGuiColor<T>())
|
||||||
|
return parseValue<T, Misc::Color>(table, field, errorPrefix);
|
||||||
else
|
else
|
||||||
return parseValue<T, T>(table, field, errorPrefix);
|
return parseValue<T, T>(table, field, errorPrefix);
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,40 @@
|
|||||||
|
|
||||||
#include "text.hpp"
|
#include "text.hpp"
|
||||||
|
|
||||||
|
#include "alignment.hpp"
|
||||||
|
|
||||||
namespace LuaUi
|
namespace LuaUi
|
||||||
{
|
{
|
||||||
LuaText::LuaText()
|
LuaText::LuaText()
|
||||||
: mAutoSized(true)
|
: mAutoSized(true)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void LuaText::initialize()
|
||||||
{
|
{
|
||||||
changeWidgetSkin("NormalText");
|
changeWidgetSkin("SandText");
|
||||||
|
setEditStatic(true);
|
||||||
|
setVisibleHScroll(false);
|
||||||
|
setVisibleVScroll(false);
|
||||||
|
|
||||||
|
WidgetExtension::initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaText::updateProperties()
|
void LuaText::updateProperties()
|
||||||
{
|
{
|
||||||
setCaption(propertyValue("caption", std::string()));
|
|
||||||
mAutoSized = propertyValue("autoSize", true);
|
mAutoSized = propertyValue("autoSize", true);
|
||||||
|
|
||||||
|
setCaption(propertyValue("text", std::string()));
|
||||||
|
setFontHeight(propertyValue("textSize", 10));
|
||||||
|
setTextColour(propertyValue("textColor", MyGUI::Colour(0, 0, 0, 1)));
|
||||||
|
setEditMultiLine(propertyValue("multiline", false));
|
||||||
|
setEditWordWrap(propertyValue("wordWrap", false));
|
||||||
|
|
||||||
|
Alignment horizontal(propertyValue("textAlignH", Alignment::Start));
|
||||||
|
Alignment vertical(propertyValue("textAlignV", Alignment::Start));
|
||||||
|
setTextAlign(alignmentToMyGui(horizontal, vertical));
|
||||||
|
|
||||||
|
setTextShadow(propertyValue("textShadow", false));
|
||||||
|
setTextShadowColour(propertyValue("textShadowColor", MyGUI::Colour(0, 0, 0, 1)));
|
||||||
|
|
||||||
WidgetExtension::updateProperties();
|
WidgetExtension::updateProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,26 +1,27 @@
|
|||||||
#ifndef OPENMW_LUAUI_TEXT
|
#ifndef OPENMW_LUAUI_TEXT
|
||||||
#define OPENMW_LUAUI_TEXT
|
#define OPENMW_LUAUI_TEXT
|
||||||
|
|
||||||
#include <MyGUI_TextBox.h>
|
#include <MyGUI_EditBox.h>
|
||||||
|
|
||||||
#include "widget.hpp"
|
#include "widget.hpp"
|
||||||
|
|
||||||
namespace LuaUi
|
namespace LuaUi
|
||||||
{
|
{
|
||||||
class LuaText : public MyGUI::TextBox, public WidgetExtension
|
class LuaText : public MyGUI::EditBox, public WidgetExtension
|
||||||
{
|
{
|
||||||
MYGUI_RTTI_DERIVED(LuaText)
|
MYGUI_RTTI_DERIVED(LuaText)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LuaText();
|
LuaText();
|
||||||
virtual void updateProperties() override;
|
void initialize() override;
|
||||||
|
void updateProperties() override;
|
||||||
void setCaption(const MyGUI::UString& caption) override;
|
void setCaption(const MyGUI::UString& caption) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool mAutoSized;
|
bool mAutoSized;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual MyGUI::IntSize calculateSize() override;
|
MyGUI::IntSize calculateSize() override;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,43 @@
|
|||||||
#include "textedit.hpp"
|
#include "textedit.hpp"
|
||||||
|
|
||||||
|
#include "alignment.hpp"
|
||||||
|
|
||||||
namespace LuaUi
|
namespace LuaUi
|
||||||
{
|
{
|
||||||
|
void LuaTextEdit::initialize()
|
||||||
|
{
|
||||||
|
changeWidgetSkin("LuaTextEdit");
|
||||||
|
|
||||||
|
eventEditTextChange += MyGUI::newDelegate(this, &LuaTextEdit::textChange);
|
||||||
|
|
||||||
|
WidgetExtension::initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LuaTextEdit::deinitialize()
|
||||||
|
{
|
||||||
|
eventEditTextChange -= MyGUI::newDelegate(this, &LuaTextEdit::textChange);
|
||||||
|
WidgetExtension::deinitialize();
|
||||||
|
}
|
||||||
|
|
||||||
void LuaTextEdit::updateProperties()
|
void LuaTextEdit::updateProperties()
|
||||||
{
|
{
|
||||||
setCaption(propertyValue("caption", std::string()));
|
setCaption(propertyValue("text", std::string()));
|
||||||
|
setFontHeight(propertyValue("textSize", 10));
|
||||||
|
setTextColour(propertyValue("textColor", MyGUI::Colour(0, 0, 0, 1)));
|
||||||
|
setEditMultiLine(propertyValue("multiline", false));
|
||||||
|
setEditWordWrap(propertyValue("wordWrap", false));
|
||||||
|
|
||||||
|
Alignment horizontal(propertyValue("textAlignH", Alignment::Start));
|
||||||
|
Alignment vertical(propertyValue("textAlignV", Alignment::Start));
|
||||||
|
setTextAlign(alignmentToMyGui(horizontal, vertical));
|
||||||
|
|
||||||
|
setEditStatic(propertyValue("readOnly", false));
|
||||||
|
|
||||||
WidgetExtension::updateProperties();
|
WidgetExtension::updateProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LuaTextEdit::textChange(MyGUI::EditBox*)
|
||||||
|
{
|
||||||
|
triggerEvent("textChanged", sol::make_object(lua(), getCaption().asUTF8()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,13 @@ namespace LuaUi
|
|||||||
{
|
{
|
||||||
MYGUI_RTTI_DERIVED(LuaTextEdit)
|
MYGUI_RTTI_DERIVED(LuaTextEdit)
|
||||||
|
|
||||||
virtual void updateProperties() override;
|
protected:
|
||||||
|
void initialize() override;
|
||||||
|
void deinitialize() override;
|
||||||
|
void updateProperties() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void textChange(MyGUI::EditBox*);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,14 +10,13 @@
|
|||||||
namespace LuaUi
|
namespace LuaUi
|
||||||
{
|
{
|
||||||
WidgetExtension::WidgetExtension()
|
WidgetExtension::WidgetExtension()
|
||||||
: mForcedCoord()
|
: mLua(nullptr)
|
||||||
, mAbsoluteCoord()
|
|
||||||
, mRelativeCoord()
|
|
||||||
, mAnchor()
|
|
||||||
, mLua(nullptr)
|
|
||||||
, mWidget(nullptr)
|
, mWidget(nullptr)
|
||||||
, mSlot(this)
|
, mSlot(this)
|
||||||
, mLayout(sol::nil)
|
, mLayout(sol::nil)
|
||||||
|
, mProperties(sol::nil)
|
||||||
|
, mTemplateProperties(sol::nil)
|
||||||
|
, mExternal(sol::nil)
|
||||||
, mParent(nullptr)
|
, mParent(nullptr)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@ -80,16 +79,22 @@ namespace LuaUi
|
|||||||
ext->updateCoord();
|
ext->updateCoord();
|
||||||
}
|
}
|
||||||
|
|
||||||
WidgetExtension* WidgetExtension::findFirst(std::string_view flagName)
|
void WidgetExtension::attachTemplate(WidgetExtension* ext)
|
||||||
|
{
|
||||||
|
ext->widget()->attachToWidget(widget());
|
||||||
|
ext->updateCoord();
|
||||||
|
}
|
||||||
|
|
||||||
|
WidgetExtension* WidgetExtension::findDeep(std::string_view flagName)
|
||||||
{
|
{
|
||||||
if (externalValue(flagName, false))
|
|
||||||
return this;
|
|
||||||
for (WidgetExtension* w : mChildren)
|
for (WidgetExtension* w : mChildren)
|
||||||
{
|
{
|
||||||
WidgetExtension* result = w->findFirst(flagName);
|
WidgetExtension* result = w->findDeep(flagName);
|
||||||
if (result != nullptr)
|
if (result != nullptr)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
if (externalValue(flagName, false))
|
||||||
|
return this;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,11 +106,11 @@ namespace LuaUi
|
|||||||
w->findAll(flagName, result);
|
w->findAll(flagName, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
WidgetExtension* WidgetExtension::findFirstInTemplates(std::string_view flagName)
|
WidgetExtension* WidgetExtension::findDeepInTemplates(std::string_view flagName)
|
||||||
{
|
{
|
||||||
for (WidgetExtension* w : mTemplateChildren)
|
for (WidgetExtension* w : mTemplateChildren)
|
||||||
{
|
{
|
||||||
WidgetExtension* result = w->findFirst(flagName);
|
WidgetExtension* result = w->findDeep(flagName);
|
||||||
if (result != nullptr)
|
if (result != nullptr)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -163,7 +168,7 @@ namespace LuaUi
|
|||||||
for (size_t i = 0; i < children.size(); ++i)
|
for (size_t i = 0; i < children.size(); ++i)
|
||||||
{
|
{
|
||||||
mTemplateChildren[i] = children[i];
|
mTemplateChildren[i] = children[i];
|
||||||
mTemplateChildren[i]->widget()->attachToWidget(mWidget);
|
attachTemplate(mTemplateChildren[i]);
|
||||||
}
|
}
|
||||||
updateTemplate();
|
updateTemplate();
|
||||||
}
|
}
|
||||||
@ -171,9 +176,11 @@ namespace LuaUi
|
|||||||
void WidgetExtension::updateTemplate()
|
void WidgetExtension::updateTemplate()
|
||||||
{
|
{
|
||||||
WidgetExtension* oldSlot = mSlot;
|
WidgetExtension* oldSlot = mSlot;
|
||||||
mSlot = findFirstInTemplates("slot");
|
WidgetExtension* slot = findDeepInTemplates("slot");
|
||||||
if (mSlot == nullptr)
|
if (slot == nullptr)
|
||||||
mSlot = this;
|
mSlot = this;
|
||||||
|
else
|
||||||
|
mSlot = slot->mSlot;
|
||||||
if (mSlot != oldSlot)
|
if (mSlot != oldSlot)
|
||||||
for (WidgetExtension* w : mChildren)
|
for (WidgetExtension* w : mChildren)
|
||||||
attach(w);
|
attach(w);
|
||||||
@ -281,7 +288,7 @@ namespace LuaUi
|
|||||||
|
|
||||||
MyGUI::IntSize WidgetExtension::childScalingSize()
|
MyGUI::IntSize WidgetExtension::childScalingSize()
|
||||||
{
|
{
|
||||||
return widget()->getSize();
|
return mSlot->widget()->getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WidgetExtension::triggerEvent(std::string_view name, const sol::object& argument = sol::nil) const
|
void WidgetExtension::triggerEvent(std::string_view name, const sol::object& argument = sol::nil) const
|
||||||
|
@ -50,6 +50,7 @@ namespace LuaUi
|
|||||||
|
|
||||||
const sol::table& getLayout() { return mLayout; }
|
const sol::table& getLayout() { return mLayout; }
|
||||||
void setLayout(const sol::table& layout) { mLayout = layout; }
|
void setLayout(const sol::table& layout) { mLayout = layout; }
|
||||||
|
void resetSlot() { mSlot = this; }
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T externalValue(std::string_view name, const T& defaultValue)
|
T externalValue(std::string_view name, const T& defaultValue)
|
||||||
@ -80,13 +81,14 @@ namespace LuaUi
|
|||||||
return parseProperty(mProperties, mTemplateProperties, name, defaultValue);
|
return parseProperty(mProperties, mTemplateProperties, name, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
WidgetExtension* findFirstInTemplates(std::string_view flagName);
|
WidgetExtension* findDeepInTemplates(std::string_view flagName);
|
||||||
std::vector<WidgetExtension*> findAllInTemplates(std::string_view flagName);
|
std::vector<WidgetExtension*> findAllInTemplates(std::string_view flagName);
|
||||||
|
|
||||||
virtual void updateTemplate();
|
virtual void updateTemplate();
|
||||||
virtual void updateProperties();
|
virtual void updateProperties();
|
||||||
virtual void updateChildren() {};
|
virtual void updateChildren() {};
|
||||||
|
|
||||||
|
lua_State* lua() { return mLua; }
|
||||||
void triggerEvent(std::string_view name, const sol::object& argument) const;
|
void triggerEvent(std::string_view name, const sol::object& argument) const;
|
||||||
|
|
||||||
// offsets the position and size, used only in C++ widget code
|
// offsets the position and size, used only in C++ widget code
|
||||||
@ -114,8 +116,9 @@ namespace LuaUi
|
|||||||
WidgetExtension* mParent;
|
WidgetExtension* mParent;
|
||||||
|
|
||||||
void attach(WidgetExtension* ext);
|
void attach(WidgetExtension* ext);
|
||||||
|
void attachTemplate(WidgetExtension* ext);
|
||||||
|
|
||||||
WidgetExtension* findFirst(std::string_view name);
|
WidgetExtension* findDeep(std::string_view name);
|
||||||
void findAll(std::string_view flagName, std::vector<WidgetExtension*>& result);
|
void findAll(std::string_view flagName, std::vector<WidgetExtension*>& result);
|
||||||
|
|
||||||
void updateChildrenCoord();
|
void updateChildrenCoord();
|
||||||
|
@ -5,10 +5,7 @@
|
|||||||
namespace LuaUi
|
namespace LuaUi
|
||||||
{
|
{
|
||||||
LuaWindow::LuaWindow()
|
LuaWindow::LuaWindow()
|
||||||
: mCaption()
|
: mCaption(nullptr)
|
||||||
, mPreviousMouse()
|
|
||||||
, mChangeScale()
|
|
||||||
, mMoveResize()
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void LuaWindow::updateTemplate()
|
void LuaWindow::updateTemplate()
|
||||||
@ -20,7 +17,7 @@ namespace LuaUi
|
|||||||
}
|
}
|
||||||
mActionWidgets.clear();
|
mActionWidgets.clear();
|
||||||
|
|
||||||
WidgetExtension* captionWidget = findFirstInTemplates("caption");
|
WidgetExtension* captionWidget = findDeepInTemplates("caption");
|
||||||
mCaption = dynamic_cast<LuaText*>(captionWidget);
|
mCaption = dynamic_cast<LuaText*>(captionWidget);
|
||||||
|
|
||||||
if (mCaption)
|
if (mCaption)
|
||||||
|
@ -14,8 +14,8 @@ namespace LuaUi
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
LuaWindow();
|
LuaWindow();
|
||||||
virtual void updateTemplate() override;
|
void updateTemplate() override;
|
||||||
virtual void updateProperties() override;
|
void updateProperties() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LuaText* mCaption;
|
LuaText* mCaption;
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
User interface reference
|
User interface reference
|
||||||
========================
|
========================
|
||||||
|
|
||||||
.. toctree::
|
|
||||||
:hidden:
|
|
||||||
|
|
||||||
widgets/widget
|
|
||||||
|
|
||||||
Layouts
|
Layouts
|
||||||
-------
|
-------
|
||||||
|
|
||||||
@ -79,103 +74,57 @@ Events
|
|||||||
Widget types
|
Widget types
|
||||||
------------
|
------------
|
||||||
|
|
||||||
.. list-table::
|
.. toctree::
|
||||||
:widths: 30 70
|
:maxdepth: 1
|
||||||
|
|
||||||
* - :ref:`Widget`
|
Widget: Base widget type, all the other widgets inherit its properties and events. <widgets/widget>
|
||||||
- Base widget type, all the other widget inherit its properties and events.
|
Text: Displays text. <widgets/text>
|
||||||
* - `Text`
|
TextEdit: Accepts text input from the user. <widgets/textedit>
|
||||||
- Displays text.
|
|
||||||
* - EditText
|
|
||||||
- Accepts text input from the user.
|
|
||||||
* - Window
|
|
||||||
- Can be moved and resized by the user.
|
|
||||||
|
|
||||||
Example
|
Example
|
||||||
-------
|
-------
|
||||||
|
|
||||||
*scripts/requirePassword.lua*
|
*scripts/clock.lua*
|
||||||
|
|
||||||
.. code-block:: Lua
|
.. code-block:: Lua
|
||||||
|
|
||||||
local core = require('openmw.core')
|
local ui = require('openmw.ui')
|
||||||
local async = require('openmw.async')
|
local util = require('openmw.util')
|
||||||
local ui = require('openmw.ui')
|
local calendar = require('openmw_aux.calendar')
|
||||||
local v2 = require('openmw.util').vector2
|
local time = require('openmw_aux.time')
|
||||||
|
|
||||||
local layout = {
|
local element = ui.create {
|
||||||
layers = 'Windows',
|
-- important not to forget the layer
|
||||||
type = ui.TYPE.Window,
|
-- by default widgets are not attached to any layer and are not visible
|
||||||
template = { skin = 'MW_Window' }, -- TODO: replace all skins here when they are re-implemented in Lua
|
layer = 'HUD',
|
||||||
props = {
|
type = ui.TYPE.Text,
|
||||||
size = v2(200, 250),
|
props = {
|
||||||
-- put the window in the middle of the screen
|
-- position in the top right corner
|
||||||
relativePosition = v2(0.5, 0.5),
|
relativePosition = util.vector2(1, 0),
|
||||||
anchor = v2(0.5, 0.5),
|
-- position is for the top left corner of the widget by default
|
||||||
},
|
-- change it to align exactly to the top right corner of the screen
|
||||||
content = ui.content {
|
anchor = util.vector2(1, 0),
|
||||||
{
|
text = calendar.formatGameTime('%H:%M'),
|
||||||
type = ui.TYPE.Text,
|
textSize = 24,
|
||||||
template = { skin = 'SandText' },
|
-- default black text color isn't always visible
|
||||||
props = {
|
textColor = util.color.rgb(0, 1, 0),
|
||||||
caption = 'Input password',
|
},
|
||||||
relativePosition = v2(0.5, 0),
|
}
|
||||||
anchor = v2(0.5, 0),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name = 'input',
|
|
||||||
type = ui.TYPE.TextEdit,
|
|
||||||
template = { skin = "MW_TextEdit" },
|
|
||||||
props = {
|
|
||||||
caption = '',
|
|
||||||
relativePosition = v2(0.5, 0.5),
|
|
||||||
anchor = v2(0.5, 0.5),
|
|
||||||
size = v2(125, 50),
|
|
||||||
},
|
|
||||||
events = {}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name = 'submit',
|
|
||||||
type = ui.TYPE.Text, -- TODO: replace with button when implemented
|
|
||||||
template = { skin = "MW_Button" },
|
|
||||||
props = {
|
|
||||||
caption = 'Submit',
|
|
||||||
-- position at the bottom
|
|
||||||
relativePosition = v2(0.5, 1.0),
|
|
||||||
anchor = v2(0.5, 1.0),
|
|
||||||
autoSize = false,
|
|
||||||
size = v2(75, 50),
|
|
||||||
},
|
|
||||||
events = {},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
local element = nil
|
local function updateTime()
|
||||||
|
-- formatGameTime uses current time by default
|
||||||
|
-- otherwise we could get it by calling `core.getGameTime()`
|
||||||
|
element.layout.props.text = calendar.formatGameTime('%H:%M')
|
||||||
|
-- the layout changes won't affect the widget unless we request an update
|
||||||
|
element:update()
|
||||||
|
end
|
||||||
|
|
||||||
local input = layout.content.input
|
-- we are showing game time in hours and minutes
|
||||||
-- TODO: replace with a better event when TextEdit is finished
|
-- so no need to update more often than ones a game minute
|
||||||
input.events.textInput = async:callback(function(text)
|
time.runRepeatedly(updateTime, 1 * time.minute, { type = time.GameTime })
|
||||||
input.props.caption = input.props.caption .. text
|
|
||||||
end)
|
|
||||||
|
|
||||||
local submit = layout.content.submit
|
*clock.omwscripts*
|
||||||
submit.events.mouseClick = async:callback(function()
|
|
||||||
if input.props.caption == 'very secret password' then
|
|
||||||
if element then
|
|
||||||
element:destroy()
|
|
||||||
end
|
|
||||||
else
|
|
||||||
print('wrong password', input.props.caption)
|
|
||||||
core.quit()
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
element = ui.create(layout)
|
|
||||||
|
|
||||||
*requirePassword.omwscripts*
|
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
PLAYER: scripts/requirePassword.lua
|
PLAYER: scripts/clock.lua
|
||||||
|
44
docs/source/reference/lua-scripting/widgets/text.rst
Normal file
44
docs/source/reference/lua-scripting/widgets/text.rst
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
Text Widget
|
||||||
|
===========
|
||||||
|
|
||||||
|
Properties
|
||||||
|
----------
|
||||||
|
|
||||||
|
.. list-table::
|
||||||
|
:header-rows: 1
|
||||||
|
:widths: 20 20 60
|
||||||
|
|
||||||
|
* - name
|
||||||
|
- type (default value)
|
||||||
|
- description
|
||||||
|
* - autoSize
|
||||||
|
- boolean (true)
|
||||||
|
- | Adjusts this widget's size to fit the text exactly.
|
||||||
|
| Ignores `size` and `relativeSize`.
|
||||||
|
* - text
|
||||||
|
- string ('')
|
||||||
|
- The text to display.
|
||||||
|
* - textSize
|
||||||
|
- number (10)
|
||||||
|
- The size of the text.
|
||||||
|
* - textColor
|
||||||
|
- util.color (0, 0, 0, 1)
|
||||||
|
- The color of the text.
|
||||||
|
* - multiline
|
||||||
|
- boolean (false)
|
||||||
|
- Whether to render text on multiple lines.
|
||||||
|
* - wordWrap
|
||||||
|
- boolean (false)
|
||||||
|
- Whether to break text into lines to fit the widget's width.
|
||||||
|
* - textAlignH
|
||||||
|
- ui.ALIGNMENT (Start)
|
||||||
|
- Horizontal alignment of the text.
|
||||||
|
* - textAlignV
|
||||||
|
- ui.ALIGNMENT (Start)
|
||||||
|
- Vertical alignment of the text.
|
||||||
|
* - textShadow
|
||||||
|
- boolean (false)
|
||||||
|
- Whether to render a shadow behind the text.
|
||||||
|
* - textShadowColor
|
||||||
|
- util.color (0, 0, 0, 1)
|
||||||
|
- The color of the text shadow.
|
51
docs/source/reference/lua-scripting/widgets/textedit.rst
Normal file
51
docs/source/reference/lua-scripting/widgets/textedit.rst
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
TextEdit Widget
|
||||||
|
===============
|
||||||
|
|
||||||
|
Properties
|
||||||
|
----------
|
||||||
|
|
||||||
|
.. list-table::
|
||||||
|
:header-rows: 1
|
||||||
|
:widths: 20 20 60
|
||||||
|
|
||||||
|
* - name
|
||||||
|
- type (default value)
|
||||||
|
- description
|
||||||
|
* - text
|
||||||
|
- string ('')
|
||||||
|
- The text to display.
|
||||||
|
* - textSize
|
||||||
|
- number (10)
|
||||||
|
- The size of the text.
|
||||||
|
* - textColor
|
||||||
|
- util.color (0, 0, 0, 1)
|
||||||
|
- The color of the text.
|
||||||
|
* - multiline
|
||||||
|
- boolean (false)
|
||||||
|
- Whether to render text on multiple lines.
|
||||||
|
* - wordWrap
|
||||||
|
- boolean (false)
|
||||||
|
- Whether to break text into lines to fit the widget's width.
|
||||||
|
* - textAlignH
|
||||||
|
- ui.ALIGNMENT (Start)
|
||||||
|
- Horizontal alignment of the text.
|
||||||
|
* - textAlignV
|
||||||
|
- ui.ALIGNMENT (Start)
|
||||||
|
- Vertical alignment of the text.
|
||||||
|
* - readOnly
|
||||||
|
- boolean (false)
|
||||||
|
- Whether the text can be edited.
|
||||||
|
|
||||||
|
Events
|
||||||
|
------
|
||||||
|
|
||||||
|
.. list-table::
|
||||||
|
:header-rows: 1
|
||||||
|
:widths: 20 20 60
|
||||||
|
|
||||||
|
* - name
|
||||||
|
- first argument type
|
||||||
|
- description
|
||||||
|
* - textChanged
|
||||||
|
- string
|
||||||
|
- Displayed text changed (e. g. by user input)
|
@ -6,18 +6,32 @@
|
|||||||
-- local ui = require('openmw.ui')
|
-- local ui = require('openmw.ui')
|
||||||
|
|
||||||
---
|
---
|
||||||
-- @field [parent=#ui] #WIDGET_TYPE WIDGET_TYPE
|
-- Widget types
|
||||||
|
-- @field [parent=#ui] #TYPE TYPE
|
||||||
|
|
||||||
|
---
|
||||||
|
-- Alignment values (left to right, top to bottom)
|
||||||
|
-- @field [parent=#ui] #ALIGNMENT ALIGNMENT
|
||||||
|
|
||||||
---
|
---
|
||||||
-- Tools for working with layers
|
-- Tools for working with layers
|
||||||
-- @field [parent=#ui] #Layers layers
|
-- @field [parent=#ui] #Layers layers
|
||||||
|
|
||||||
---
|
---
|
||||||
-- @type WIDGET_TYPE
|
-- All available widget types
|
||||||
-- @field [parent=#WIDGET_TYPE] Widget Base widget type
|
-- @type TYPE
|
||||||
-- @field [parent=#WIDGET_TYPE] Text Display text
|
-- @field Widget Base widget type
|
||||||
-- @field [parent=#WIDGET_TYPE] TextEdit Accepts user text input
|
-- @field Text Display text
|
||||||
-- @field [parent=#WIDGET_TYPE] Window Can be moved and resized by the user
|
-- @field TextEdit Accepts user text input
|
||||||
|
-- @field Window Can be moved and resized by the user
|
||||||
|
|
||||||
|
---
|
||||||
|
-- Alignment values (details depend on the specific property).
|
||||||
|
-- For horizontal alignment the order is left to right, for vertical alignment the order is top to bottom.
|
||||||
|
-- @type ALIGNMENT
|
||||||
|
-- @field Start
|
||||||
|
-- @field Center
|
||||||
|
-- @field End
|
||||||
|
|
||||||
---
|
---
|
||||||
-- Shows given message at the bottom of the screen.
|
-- Shows given message at the bottom of the screen.
|
||||||
|
@ -43,6 +43,7 @@ set(MYGUI_FILES
|
|||||||
openmw_journal.layout
|
openmw_journal.layout
|
||||||
openmw_journal.skin.xml
|
openmw_journal.skin.xml
|
||||||
openmw_layers.xml
|
openmw_layers.xml
|
||||||
|
openmw_lua.xml
|
||||||
openmw_list.skin.xml
|
openmw_list.skin.xml
|
||||||
openmw_mainmenu.layout
|
openmw_mainmenu.layout
|
||||||
openmw_mainmenu.skin.xml
|
openmw_mainmenu.skin.xml
|
||||||
|
@ -15,8 +15,4 @@
|
|||||||
<Resource type="ResourceSkin" name="ImageBox" size="16 16">
|
<Resource type="ResourceSkin" name="ImageBox" size="16 16">
|
||||||
<BasisSkin type="MainSkin" offset="0 0 16 16"/>
|
<BasisSkin type="MainSkin" offset="0 0 16 16"/>
|
||||||
</Resource>
|
</Resource>
|
||||||
|
|
||||||
<Resource type="ResourceSkin" name="LuaImage">
|
|
||||||
<BasisSkin type="LuaTileRect"/>
|
|
||||||
</Resource>
|
|
||||||
</MyGUI>
|
</MyGUI>
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
<List file="openmw_layers.xml" />
|
<List file="openmw_layers.xml" />
|
||||||
<List file="openmw_pointer.xml" />
|
<List file="openmw_pointer.xml" />
|
||||||
<List file="openmw_settings.xml" />
|
<List file="openmw_settings.xml" />
|
||||||
|
<List file="openmw_lua.xml" />
|
||||||
</MyGUI>
|
</MyGUI>
|
||||||
</MyGUI>
|
</MyGUI>
|
||||||
|
|
||||||
|
15
files/mygui/openmw_lua.xml
Normal file
15
files/mygui/openmw_lua.xml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<MyGUI type="Resource" version="1.1">
|
||||||
|
<Resource type="ResourceSkin" name="LuaImage">
|
||||||
|
<BasisSkin type="LuaTileRect"/>
|
||||||
|
</Resource>
|
||||||
|
|
||||||
|
<Resource type="ResourceSkin" name="LuaTextEdit" size="512 20">
|
||||||
|
<Property key="FontName" value="Default"/>
|
||||||
|
<Property key="TextAlign" value="Left VCenter"/>
|
||||||
|
<Property key="TextColour" value="#{fontcolour=normal}"/>
|
||||||
|
|
||||||
|
<Child type="TextBox" skin="MW_TextEditClient" offset="0 0 502 20" align="Stretch" name="Client"/>
|
||||||
|
</Resource>
|
||||||
|
</MyGUI>
|
Loading…
x
Reference in New Issue
Block a user