diff --git a/data/modules/mainmenu/infowindow.yml b/data/modules/mainmenu/infowindow.yml index a27d6970..fc93346c 100644 --- a/data/modules/mainmenu/infowindow.yml +++ b/data/modules/mainmenu/infowindow.yml @@ -15,14 +15,14 @@ window#infoWindow: margin.left: 18 label#infoLabel: - size: [208, 84] align: center text: |- OTClient Version 0.2.0 Created by edubart - anchors.left: parent.left + anchors.horizontalCenter: parent.horizontalCenter anchors.top: parent.top + margin.top: 20 lineDecoration#bottomSeparator: size: [190,2] diff --git a/data/modules/mainmenu/mainmenu.yml b/data/modules/mainmenu/mainmenu.yml index cc651ea3..ea230339 100644 --- a/data/modules/mainmenu/mainmenu.yml +++ b/data/modules/mainmenu/mainmenu.yml @@ -28,6 +28,7 @@ panel#background: anchors.top: parent.top anchors.horizontalCenter: parent.horizontalCenter margin.top: 46 + onClick: messageBox("Error", "Not implemented yet") button#optionsButton: text: Options diff --git a/data/modules/messagebox/messagebox.lua b/data/modules/messagebox/messagebox.lua new file mode 100644 index 00000000..a8e48ce1 --- /dev/null +++ b/data/modules/messagebox/messagebox.lua @@ -0,0 +1,12 @@ +function messageBox(title, text) + local messageBoxWindow = loadUI("modules/messagebox/messagebox.yml") + local messageBoxLabel = messageBoxWindow:getChildByID("messageBoxLabel") + local messageBoxOkButton = messageBoxWindow:getChildByID("messageBoxOkButton") + local uiRoot = messageBoxWindow:getParent() + uiRoot:lock(messageBox) + messageBoxWindow:setTitle(text) + messageBoxLabel:setText(text) + messageBoxWindow:setSize(messageBoxLabel:getSize() + Size{20, 20}) + messageBox:setOnDestroy(function() uiRoot:unlock() end) + messageBoxOkButton:setOnClick(function() messageBoxWindow:destroy() end) +end \ No newline at end of file diff --git a/data/modules/messagebox/messagebox.yml b/data/modules/messagebox/messagebox.yml new file mode 100644 index 00000000..072a402f --- /dev/null +++ b/data/modules/messagebox/messagebox.yml @@ -0,0 +1,18 @@ +window#messageBoxWindow: + size: [236, 78] + anchors.horizontalCenter: parent.horizontalCenter + anchors.verticalCenter: parent.verticalCenter + + + label#messageBoxLabel: + anchors.horizontalCenter: parent.horizontalCenter + anchors.top: parent.top + margin.top: 27 + + button#messageBoxOkButton: + text: Ok + size: [43, 20] + anchors.right: parent.right + anchors.bottom: parent.bottom + margin.bottom: 10 + margin.right: 10 \ No newline at end of file diff --git a/src/framework/core/dispatcher.cpp b/src/framework/core/dispatcher.cpp index 83b6d1fe..53153f84 100644 --- a/src/framework/core/dispatcher.cpp +++ b/src/framework/core/dispatcher.cpp @@ -50,41 +50,3 @@ void Dispatcher::addTask(const SimpleCallback& callback) { m_taskList.push(new Task(callback)); } - -/* - * #include -#include -#include -#include - -Dispatcher g_dispatcher; - -void Dispatcher::poll() -{ - if(!m_taskList.empty()) { - auto it = m_taskList.begin(); - m_taskList.erase(it); - (*it)(); - } - - while(!m_scheduledTaskList.empty()) { - ScheduledTask *task = m_scheduledTaskList.top(); - if(g_engine.getCurrentFrameTicks() < task->ticks) - break; - m_scheduledTaskList.pop(); - - task->callback(); - delete task; - } -} - -void Dispatcher::scheduleTask(const SimpleCallback& callback, int delay) -{ - m_scheduledTaskList.push(new ScheduledTask(g_engine.getCurrentFrameTicks() + delay, callback)); -} - -void Dispatcher::addTask(const SimpleCallback& callback) -{ - m_taskList.push_back(callback); -} -*/ \ No newline at end of file diff --git a/src/framework/core/dispatcher.h b/src/framework/core/dispatcher.h index 90b16aa7..5287860c 100644 --- a/src/framework/core/dispatcher.h +++ b/src/framework/core/dispatcher.h @@ -61,39 +61,4 @@ private: extern Dispatcher g_dispatcher; -/* - * class ScheduledTask { -public: - inline ScheduledTask(const SimpleCallback& _callback) : ticks(0), callback(_callback) { } - inline ScheduledTask(int _ticks, const SimpleCallback& _callback) : ticks(_ticks), callback(_callback) { } - inline bool operator<(const ScheduledTask& other) const { return ticks > other.ticks; } - int ticks; - SimpleCallback callback; -}; - -class lessScheduledTask : public std::binary_function { -public: - bool operator()(ScheduledTask*& t1,ScheduledTask*& t2) { return (*t1) < (*t2); } -}; - -class Dispatcher -{ -public: - Dispatcher() { } - - /// Execute scheduled events - void poll(); - - /// Add an event - void addTask(const SimpleCallback& callback); - - /// Schedula an event - void scheduleTask(const SimpleCallback& callback, int delay); - -private: - std::vector m_taskList; - std::priority_queue, lessScheduledTask> m_scheduledTaskList; -}; - -extern Dispatcher g_dispatcher;*/ #endif // DISPATCHER_H diff --git a/src/framework/ui/uilabel.cpp b/src/framework/ui/uilabel.cpp index d79a161b..d4a8f7cf 100644 --- a/src/framework/ui/uilabel.cpp +++ b/src/framework/ui/uilabel.cpp @@ -24,3 +24,10 @@ #include #include + +void UILabel::setText(const std::string& text) +{ + m_text = text; + // text size changed, reaplly skin + getSkin()->apply(this); +} diff --git a/src/framework/ui/uilabel.h b/src/framework/ui/uilabel.h index 7a79e9b6..3666ca99 100644 --- a/src/framework/ui/uilabel.h +++ b/src/framework/ui/uilabel.h @@ -37,7 +37,7 @@ public: m_align(ALIGN_TOP_LEFT), m_color(Color::white) { } - void setText(const std::string& text) { m_text = text; } + void setText(const std::string& text); const std::string& getText() const { return m_text; } void setAlign(int align) { m_align = align; } diff --git a/src/framework/ui/uiloader.cpp b/src/framework/ui/uiloader.cpp index 4bc41f8d..667ef7b7 100644 --- a/src/framework/ui/uiloader.cpp +++ b/src/framework/ui/uiloader.cpp @@ -151,24 +151,6 @@ void UILoader::loadElements(const UIElementPtr& parent, const YAML::Node& node) void UILoader::loadElement(const UIElementPtr& element, const YAML::Node& node) { - // load specific element type - if(element->getElementType() == UI::Button) - loadButton(boost::static_pointer_cast(element), node); - else if(element->getElementType() == UI::Window) { - UIWindowPtr window = boost::static_pointer_cast(element); - window->setTitle(node["title"].Read()); - } - else if(element->getElementType() == UI::Label) { - UILabelPtr label = boost::static_pointer_cast(element); - label->setText(node["text"].Read()); - if(node.FindValue("align")) { - std::string alignDesc; - node["align"] >> alignDesc; - if(alignDesc == "center") - label->setAlign(ALIGN_CENTER); - } - } - // set element skin if(node.FindValue("skin")) { if(node["skin"].GetType() == YAML::CT_SCALAR) { @@ -249,6 +231,26 @@ void UILoader::loadElement(const UIElementPtr& element, const YAML::Node& node) } else throw YAML::Exception(cnode.GetMark(), "failed to parse lua script"); } + + // load specific element type + if(element->getElementType() == UI::Button) + loadButton(boost::static_pointer_cast(element), node); + else if(element->getElementType() == UI::Window) { + UIWindowPtr window = boost::static_pointer_cast(element); + if(node.FindValue("title")) + window->setTitle(node["title"].Read()); + } + else if(element->getElementType() == UI::Label) { + UILabelPtr label = boost::static_pointer_cast(element); + if(node.FindValue("text")) + label->setText(node["text"].Read()); + if(node.FindValue("align")) { + std::string alignDesc; + node["align"] >> alignDesc; + if(alignDesc == "center") + label->setAlign(ALIGN_CENTER); + } + } } void UILoader::loadElementAnchor(const UIElementPtr& element, EAnchorType type, const YAML::Node& node)