remove lambdas
This commit is contained in:
parent
451719479b
commit
08b6563fd5
|
@ -79,6 +79,7 @@ windows:
|
||||||
text edits:
|
text edits:
|
||||||
default:
|
default:
|
||||||
default size: [86, 16]
|
default size: [86, 16]
|
||||||
|
font: tibia-10px-antialised
|
||||||
text margin: 2
|
text margin: 2
|
||||||
bordered image:
|
bordered image:
|
||||||
left border: [308,97,1,1]
|
left border: [308,97,1,1]
|
||||||
|
|
|
@ -29,8 +29,6 @@
|
||||||
|
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
typedef std::function<void (void)> Callback;
|
|
||||||
|
|
||||||
class Task {
|
class Task {
|
||||||
public:
|
public:
|
||||||
inline Task(const Callback& _callback) : ticks(0), callback(_callback) { }
|
inline Task(const Callback& _callback) : ticks(0), callback(_callback) { }
|
||||||
|
|
|
@ -27,8 +27,6 @@
|
||||||
#include "textures.h"
|
#include "textures.h"
|
||||||
#include "graphics.h"
|
#include "graphics.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Font::calculateGlyphsWidthsAutomatically(const Size& glyphSize)
|
void Font::calculateGlyphsWidthsAutomatically(const Size& glyphSize)
|
||||||
{
|
{
|
||||||
int numHorizontalGlyphs = m_texture->getSize().width() / glyphSize.width();
|
int numHorizontalGlyphs = m_texture->getSize().width() / glyphSize.width();
|
||||||
|
|
|
@ -64,8 +64,11 @@ typedef int8_t int8;
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
|
#include <boost/bind.hpp>
|
||||||
#define foreach BOOST_FOREACH
|
#define foreach BOOST_FOREACH
|
||||||
|
|
||||||
|
typedef std::function<void()> Callback;
|
||||||
|
|
||||||
// yaml
|
// yaml
|
||||||
#include <yaml-cpp/yaml.h>
|
#include <yaml-cpp/yaml.h>
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,6 @@
|
||||||
#include "uielement.h"
|
#include "uielement.h"
|
||||||
#include "graphics/borderedimage.h"
|
#include "graphics/borderedimage.h"
|
||||||
|
|
||||||
typedef std::function<void()> Callback;
|
|
||||||
|
|
||||||
class UIButton : public UIElement
|
class UIButton : public UIElement
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -45,7 +43,7 @@ public:
|
||||||
|
|
||||||
UI::EButtonState getState() { return m_state; }
|
UI::EButtonState getState() { return m_state; }
|
||||||
|
|
||||||
void onClick(const Callback& callback) { m_buttonClickCallback = callback; }
|
void setOnClick(const Callback& callback) { m_buttonClickCallback = callback; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_text;
|
std::string m_text;
|
||||||
|
|
|
@ -45,6 +45,8 @@ void UILabelSkin::load(const YAML::Node& node)
|
||||||
|
|
||||||
void UILabelSkin::draw(UIElement *element)
|
void UILabelSkin::draw(UIElement *element)
|
||||||
{
|
{
|
||||||
|
UIElementSkin::draw(element);
|
||||||
|
|
||||||
UILabel *label = static_cast<UILabel*>(element);
|
UILabel *label = static_cast<UILabel*>(element);
|
||||||
|
|
||||||
m_font->renderText(label->getText(), label->getRect(), ALIGN_TOP_LEFT, m_textColor);
|
m_font->renderText(label->getText(), label->getRect(), ALIGN_TOP_LEFT, m_textColor);
|
||||||
|
|
|
@ -25,26 +25,12 @@
|
||||||
#include "uitextedit.h"
|
#include "uitextedit.h"
|
||||||
#include "graphics/fonts.h"
|
#include "graphics/fonts.h"
|
||||||
|
|
||||||
UITextEdit::UITextEdit(Font* font) :
|
UITextEdit::UITextEdit() :
|
||||||
UIElement(UI::TextEdit),
|
UIElement(UI::TextEdit),
|
||||||
m_cursorPos(0),
|
m_cursorPos(0),
|
||||||
m_startRenderPos(0),
|
m_startRenderPos(0)
|
||||||
m_font(font)
|
|
||||||
{
|
{
|
||||||
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)
|
void UITextEdit::onInputEvent(const InputEvent& event)
|
||||||
|
|
|
@ -33,12 +33,10 @@ class Font;
|
||||||
class UITextEdit : public UIElement
|
class UITextEdit : public UIElement
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UITextEdit(Font *font = NULL);
|
UITextEdit();
|
||||||
|
|
||||||
void onInputEvent(const InputEvent& event);
|
void onInputEvent(const InputEvent& event);
|
||||||
|
|
||||||
void render();
|
|
||||||
|
|
||||||
void clearText();
|
void clearText();
|
||||||
void setText(const std::string& text);
|
void setText(const std::string& text);
|
||||||
const std::string& getText() const { return m_text; }
|
const std::string& getText() const { return m_text; }
|
||||||
|
@ -57,7 +55,6 @@ private:
|
||||||
uint m_cursorPos;
|
uint m_cursorPos;
|
||||||
int m_startRenderPos;
|
int m_startRenderPos;
|
||||||
std::string m_text;
|
std::string m_text;
|
||||||
Font *m_font;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr<UITextEdit> UITextEditPtr;
|
typedef std::shared_ptr<UITextEdit> UITextEditPtr;
|
||||||
|
|
|
@ -23,4 +23,35 @@
|
||||||
|
|
||||||
|
|
||||||
#include "uitexteditskin.h"
|
#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<UITextEdit*>(element);
|
||||||
|
m_font->renderText(textEdit->getText(), textEdit->getRect(), ALIGN_TOP_LEFT, m_textColor);
|
||||||
|
}
|
||||||
|
|
|
@ -29,12 +29,24 @@
|
||||||
#include "uiconstants.h"
|
#include "uiconstants.h"
|
||||||
#include "uielementskin.h"
|
#include "uielementskin.h"
|
||||||
|
|
||||||
|
class Font;
|
||||||
|
|
||||||
class UITextEditSkin : public UIElementSkin
|
class UITextEditSkin : public UIElementSkin
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UITextEditSkin(const std::string& name) :
|
UITextEditSkin(const std::string& name) :
|
||||||
UIElementSkin(name, UI::TextEdit) { }
|
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
|
#endif // UITEXTEDITSKIN_H
|
||||||
|
|
|
@ -115,9 +115,7 @@ int main(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
std::shared_ptr<MenuState> initialState(new MenuState);
|
std::shared_ptr<MenuState> initialState(new MenuState);
|
||||||
//std::shared_ptr<TestState> initialState(new TestState);
|
//std::shared_ptr<TestState> initialState(new TestState);
|
||||||
g_dispatcher.addTask([&initialState]{
|
g_dispatcher.addTask(boost::bind(&Engine::changeState, &g_engine, initialState.get()));
|
||||||
g_engine.changeState(initialState.get());
|
|
||||||
});
|
|
||||||
|
|
||||||
Platform::showWindow();
|
Platform::showWindow();
|
||||||
//Platform::hideMouseCursor();
|
//Platform::hideMouseCursor();
|
||||||
|
|
|
@ -42,17 +42,10 @@ void MenuState::onEnter()
|
||||||
UIContainerPtr mainMenuPanel = UILoader::loadFile("ui/mainMenu.yml")->asUIContainer();
|
UIContainerPtr mainMenuPanel = UILoader::loadFile("ui/mainMenu.yml")->asUIContainer();
|
||||||
|
|
||||||
UIButtonPtr button = std::static_pointer_cast<UIButton>(mainMenuPanel->getChildById("exitGameButton"));
|
UIButtonPtr button = std::static_pointer_cast<UIButton>(mainMenuPanel->getChildById("exitGameButton"));
|
||||||
button->onClick([this]{
|
button->setOnClick(boost::bind(&MenuState::onClose, this));
|
||||||
this->onClose();
|
|
||||||
});
|
|
||||||
|
|
||||||
button = std::static_pointer_cast<UIButton>(mainMenuPanel->getChildById("enterGameButton"));
|
button = std::static_pointer_cast<UIButton>(mainMenuPanel->getChildById("enterGameButton"));
|
||||||
button->onClick([mainMenuPanel]{
|
button->setOnClick(boost::bind(&MenuState::enterGameButton_clicked, this));
|
||||||
UIElementPtr window = UIContainer::getRootContainer()->getChildById("enterGameWindow");
|
|
||||||
if(!window)
|
|
||||||
window = UILoader::loadFile("ui/enterGameWindow.yml");
|
|
||||||
mainMenuPanel->setEnabled(false);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuState::onLeave()
|
void MenuState::onLeave()
|
||||||
|
@ -89,3 +82,12 @@ void MenuState::render()
|
||||||
texCoords.moveBottomRight(texSize.toPoint());
|
texCoords.moveBottomRight(texSize.toPoint());
|
||||||
g_graphics.drawTexturedRect(Rect(0, 0, screenSize), m_background, texCoords);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ public:
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createMainMenu();
|
void enterGameButton_clicked();
|
||||||
|
|
||||||
UIPanelPtr m_menuPanel;
|
UIPanelPtr m_menuPanel;
|
||||||
TexturePtr m_background;
|
TexturePtr m_background;
|
||||||
|
|
|
@ -36,11 +36,13 @@ ProtocolTibia87::ProtocolTibia87()
|
||||||
|
|
||||||
void ProtocolTibia87::begin()
|
void ProtocolTibia87::begin()
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
connect("icechaw.otland.net", 7171,
|
connect("icechaw.otland.net", 7171,
|
||||||
[this](){
|
[this](){
|
||||||
this->afterConnect();
|
this->afterConnect();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProtocolTibia87::login(const std::string& account, const std::string& password)
|
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->setMessageLength(m_notEncriptedLen + 128);
|
||||||
networkMessage->updateHeaderLength();
|
networkMessage->updateHeaderLength();
|
||||||
|
|
||||||
|
/*
|
||||||
send(networkMessage,
|
send(networkMessage,
|
||||||
[this](){
|
[this](){
|
||||||
this->afterSendAccount();
|
this->afterSendAccount();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProtocolTibia87::afterConnect()
|
void ProtocolTibia87::afterConnect()
|
||||||
|
@ -87,11 +91,13 @@ void ProtocolTibia87::afterConnect()
|
||||||
|
|
||||||
void ProtocolTibia87::afterSendAccount()
|
void ProtocolTibia87::afterSendAccount()
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
recv(
|
recv(
|
||||||
[this](NetworkMessagePtr networkMessage){
|
[this](NetworkMessagePtr networkMessage){
|
||||||
this->parseCharacterList(networkMessage);
|
this->parseCharacterList(networkMessage);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProtocolTibia87::onError(const boost::system::error_code& error, const std::string& msg)
|
void ProtocolTibia87::onError(const boost::system::error_code& error, const std::string& msg)
|
||||||
|
|
Loading…
Reference in New Issue