diff --git a/data/skins/tibiaskin.yml b/data/skins/tibiaskin.yml index 19926768..959ab27d 100644 --- a/data/skins/tibiaskin.yml +++ b/data/skins/tibiaskin.yml @@ -79,6 +79,7 @@ windows: text edits: default: default size: [86, 16] + font: tibia-10px-antialised text margin: 2 bordered image: left border: [308,97,1,1] diff --git a/src/framework/core/dispatcher.h b/src/framework/core/dispatcher.h index 6fa2f558..7be2ff9f 100644 --- a/src/framework/core/dispatcher.h +++ b/src/framework/core/dispatcher.h @@ -29,8 +29,6 @@ #include -typedef std::function Callback; - class Task { public: inline Task(const Callback& _callback) : ticks(0), callback(_callback) { } diff --git a/src/framework/graphics/font.cpp b/src/framework/graphics/font.cpp index f2816751..8cb6dec2 100644 --- a/src/framework/graphics/font.cpp +++ b/src/framework/graphics/font.cpp @@ -27,8 +27,6 @@ #include "textures.h" #include "graphics.h" - - void Font::calculateGlyphsWidthsAutomatically(const Size& glyphSize) { int numHorizontalGlyphs = m_texture->getSize().width() / glyphSize.width(); diff --git a/src/framework/prerequisites.h b/src/framework/prerequisites.h index 224fb6e7..b68b4197 100644 --- a/src/framework/prerequisites.h +++ b/src/framework/prerequisites.h @@ -64,8 +64,11 @@ typedef int8_t int8; #include #include #include +#include #define foreach BOOST_FOREACH +typedef std::function Callback; + // yaml #include diff --git a/src/framework/ui/uibutton.h b/src/framework/ui/uibutton.h index b8fabbed..c21cd4c0 100644 --- a/src/framework/ui/uibutton.h +++ b/src/framework/ui/uibutton.h @@ -29,8 +29,6 @@ #include "uielement.h" #include "graphics/borderedimage.h" -typedef std::function Callback; - class UIButton : public UIElement { public: @@ -45,7 +43,7 @@ public: UI::EButtonState getState() { return m_state; } - void onClick(const Callback& callback) { m_buttonClickCallback = callback; } + void setOnClick(const Callback& callback) { m_buttonClickCallback = callback; } private: std::string m_text; diff --git a/src/framework/ui/uilabelskin.cpp b/src/framework/ui/uilabelskin.cpp index 9a957418..3fe9fa04 100644 --- a/src/framework/ui/uilabelskin.cpp +++ b/src/framework/ui/uilabelskin.cpp @@ -45,6 +45,8 @@ void UILabelSkin::load(const YAML::Node& node) void UILabelSkin::draw(UIElement *element) { + UIElementSkin::draw(element); + UILabel *label = static_cast(element); m_font->renderText(label->getText(), label->getRect(), ALIGN_TOP_LEFT, m_textColor); diff --git a/src/framework/ui/uitextedit.cpp b/src/framework/ui/uitextedit.cpp index b756eb42..f35c01ea 100644 --- a/src/framework/ui/uitextedit.cpp +++ b/src/framework/ui/uitextedit.cpp @@ -25,26 +25,12 @@ #include "uitextedit.h" #include "graphics/fonts.h" -UITextEdit::UITextEdit(Font* font) : +UITextEdit::UITextEdit() : UIElement(UI::TextEdit), m_cursorPos(0), - m_startRenderPos(0), - m_font(font) + m_startRenderPos(0) { - if(!font) - m_font = g_fonts.get("tibia-10px-antialised"); -} - -void UITextEdit::render() -{ - UIElement::render(); - - Rect textRect = getRect(); - textRect.setLeft(textRect.left() + 2); - textRect.setRight(textRect.right() - 2); - // render text - m_font->renderText(m_text, textRect, ALIGN_LEFT, Color(0xFFBFBFBF), Point(m_startRenderPos, 0), m_cursorPos); } void UITextEdit::onInputEvent(const InputEvent& event) diff --git a/src/framework/ui/uitextedit.h b/src/framework/ui/uitextedit.h index 6d952b12..2dd7a269 100644 --- a/src/framework/ui/uitextedit.h +++ b/src/framework/ui/uitextedit.h @@ -33,12 +33,10 @@ class Font; class UITextEdit : public UIElement { public: - UITextEdit(Font *font = NULL); + UITextEdit(); void onInputEvent(const InputEvent& event); - void render(); - void clearText(); void setText(const std::string& text); const std::string& getText() const { return m_text; } @@ -57,7 +55,6 @@ private: uint m_cursorPos; int m_startRenderPos; std::string m_text; - Font *m_font; }; typedef std::shared_ptr UITextEditPtr; diff --git a/src/framework/ui/uitexteditskin.cpp b/src/framework/ui/uitexteditskin.cpp index 33d422db..97888cda 100644 --- a/src/framework/ui/uitexteditskin.cpp +++ b/src/framework/ui/uitexteditskin.cpp @@ -23,4 +23,35 @@ #include "uitexteditskin.h" +#include "uitextedit.h" +#include "graphics/fonts.h" +void UITextEditSkin::load(const YAML::Node& node) +{ + UIElementSkin::load(node); + std::string tmp; + + if(node.FindValue("font")) { + node["font"] >> tmp; + m_font = g_fonts.get(tmp); + } else + m_font = g_fonts.getDefaultFont(); + + if(node.FindValue("text color")) + node["text color"] >> m_textColor; + else + m_textColor = Color::white; + + if(node.FindValue("text margin")) + node["text margin"] >> m_textMargin; + else + m_textMargin = 2; +} + +void UITextEditSkin::draw(UIElement* element) +{ + UIElementSkin::draw(element); + + UITextEdit *textEdit = static_cast(element); + m_font->renderText(textEdit->getText(), textEdit->getRect(), ALIGN_TOP_LEFT, m_textColor); +} diff --git a/src/framework/ui/uitexteditskin.h b/src/framework/ui/uitexteditskin.h index 29433158..33527fc2 100644 --- a/src/framework/ui/uitexteditskin.h +++ b/src/framework/ui/uitexteditskin.h @@ -29,12 +29,24 @@ #include "uiconstants.h" #include "uielementskin.h" +class Font; + class UITextEditSkin : public UIElementSkin { public: UITextEditSkin(const std::string& name) : UIElementSkin(name, UI::TextEdit) { } + void load(const YAML::Node& node); + void draw(UIElement *element); + + Font *getFont() const { return m_font; } + int getTextMargin() const { return m_textMargin; } + +private: + Font *m_font; + int m_textMargin; + Color m_textColor; }; #endif // UITEXTEDITSKIN_H diff --git a/src/main.cpp b/src/main.cpp index d2ae7282..91a78949 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -115,9 +115,7 @@ int main(int argc, const char *argv[]) { std::shared_ptr initialState(new MenuState); //std::shared_ptr initialState(new TestState); - g_dispatcher.addTask([&initialState]{ - g_engine.changeState(initialState.get()); - }); + g_dispatcher.addTask(boost::bind(&Engine::changeState, &g_engine, initialState.get())); Platform::showWindow(); //Platform::hideMouseCursor(); diff --git a/src/menustate.cpp b/src/menustate.cpp index 6178af56..56aeda96 100644 --- a/src/menustate.cpp +++ b/src/menustate.cpp @@ -42,17 +42,10 @@ void MenuState::onEnter() UIContainerPtr mainMenuPanel = UILoader::loadFile("ui/mainMenu.yml")->asUIContainer(); UIButtonPtr button = std::static_pointer_cast(mainMenuPanel->getChildById("exitGameButton")); - button->onClick([this]{ - this->onClose(); - }); + button->setOnClick(boost::bind(&MenuState::onClose, this)); button = std::static_pointer_cast(mainMenuPanel->getChildById("enterGameButton")); - button->onClick([mainMenuPanel]{ - UIElementPtr window = UIContainer::getRootContainer()->getChildById("enterGameWindow"); - if(!window) - window = UILoader::loadFile("ui/enterGameWindow.yml"); - mainMenuPanel->setEnabled(false); - }); + button->setOnClick(boost::bind(&MenuState::enterGameButton_clicked, this)); } void MenuState::onLeave() @@ -89,3 +82,12 @@ void MenuState::render() texCoords.moveBottomRight(texSize.toPoint()); g_graphics.drawTexturedRect(Rect(0, 0, screenSize), m_background, texCoords); } + +void MenuState::enterGameButton_clicked() +{ + UIElementPtr window = UIContainer::getRootContainer()->getChildById("enterGameWindow"); + if(!window) + window = UILoader::loadFile("ui/enterGameWindow.yml"); + window->getParent()->setEnabled(false); +} + diff --git a/src/menustate.h b/src/menustate.h index 1069d336..1f3c35f8 100644 --- a/src/menustate.h +++ b/src/menustate.h @@ -46,7 +46,7 @@ public: void render(); private: - void createMainMenu(); + void enterGameButton_clicked(); UIPanelPtr m_menuPanel; TexturePtr m_background; diff --git a/src/net/protocoltibia87.cpp b/src/net/protocoltibia87.cpp index d7f2f83b..64603a04 100644 --- a/src/net/protocoltibia87.cpp +++ b/src/net/protocoltibia87.cpp @@ -36,11 +36,13 @@ ProtocolTibia87::ProtocolTibia87() void ProtocolTibia87::begin() { + /* connect("icechaw.otland.net", 7171, [this](){ this->afterConnect(); } ); + */ } void ProtocolTibia87::login(const std::string& account, const std::string& password) @@ -73,11 +75,13 @@ void ProtocolTibia87::sendAccount(const std::string& account, const std::string& networkMessage->setMessageLength(m_notEncriptedLen + 128); networkMessage->updateHeaderLength(); + /* send(networkMessage, [this](){ this->afterSendAccount(); } ); + */ } void ProtocolTibia87::afterConnect() @@ -87,11 +91,13 @@ void ProtocolTibia87::afterConnect() void ProtocolTibia87::afterSendAccount() { + /* recv( [this](NetworkMessagePtr networkMessage){ this->parseCharacterList(networkMessage); } ); + */ } void ProtocolTibia87::onError(const boost::system::error_code& error, const std::string& msg)