add chat buffer

This commit is contained in:
Eduardo Bart
2011-11-03 21:34:32 -02:00
parent 6aadf896da
commit 39c62942cf
12 changed files with 81 additions and 22 deletions

View File

@@ -25,12 +25,14 @@
#include "declarations.h"
#include <framework/luascript/luaobject.h>
#include <framework/otml/declarations.h>
class UILayout : public LuaObject
{
public:
UILayout(UIWidgetPtr parentWidget) : m_parentWidget(parentWidget) { }
virtual void applyStyle(const OTMLNodePtr& styleNode) { }
virtual void update() = 0;
virtual void addWidget(const UIWidgetPtr& widget) = 0;
virtual void removeWidget(const UIWidgetPtr& widget) = 0;

View File

@@ -22,10 +22,22 @@
#include "uiverticallayout.h"
#include "uiwidget.h"
#include <framework/otml/otml.h>
UIVerticalLayout::UIVerticalLayout(UIWidgetPtr parentWidget)
: UILayout(parentWidget)
{
m_alignBottom = false;
}
void UIVerticalLayout::applyStyle(const OTMLNodePtr& styleNode)
{
UILayout::applyStyle(styleNode);
for(const OTMLNodePtr& node : styleNode->children()) {
if(node->tag() == "align bottom")
m_alignBottom = node->value<bool>();
}
}
void UIVerticalLayout::update()
@@ -39,10 +51,14 @@ void UIVerticalLayout::update()
return first->getY() < second->getY();
});
Point pos = parentWidget->getPosition();
if(m_alignBottom)
std::reverse(widgets.begin(), widgets.end());
Point pos = (m_alignBottom) ? parentWidget->getRect().bottomLeft() : parentWidget->getPosition();
for(const UIWidgetPtr& widget : widgets) {
Size size = widget->getSize();
pos.y += widget->getMarginTop();
pos.y += (m_alignBottom) ? -(widget->getMarginBottom()+widget->getHeight()) : widget->getMarginTop();
if(widget->isSizeFixed()) {
pos.x = parentWidget->getX() + (parentWidget->getWidth() - (widget->getMarginLeft() + widget->getWidth() + widget->getMarginRight()))/2;
pos.x = std::max(pos.x, parentWidget->getX());
@@ -51,7 +67,7 @@ void UIVerticalLayout::update()
pos.x = std::max(pos.x, parentWidget->getX() + (parentWidget->getWidth() - size.width())/2);
}
widget->setRect(Rect(pos, size));
pos.y += widget->getHeight() + widget->getMarginBottom();
pos.y += (m_alignBottom) ? -widget->getMarginTop() : (widget->getHeight() + widget->getMarginBottom());
}
}

View File

@@ -30,9 +30,13 @@ class UIVerticalLayout : public UILayout
public:
UIVerticalLayout(UIWidgetPtr parentWidget);
virtual void applyStyle(const OTMLNodePtr& styleNode);
virtual void update();
virtual void addWidget(const UIWidgetPtr& widget);
virtual void removeWidget(const UIWidgetPtr& widget);
private:
bool m_alignBottom;
};
#endif

View File

@@ -101,7 +101,7 @@ void UIWidget::renderChildren()
// draw children
for(const UIWidgetPtr& child : m_children) {
// render only visible children with a valid rect
if(child->isExplicitlyVisible() && child->getRect().isValid()) {
if(child->isExplicitlyVisible() && child->getRect().isValid() && child->getRect().intersects(m_rect)) {
// store current graphics opacity
int oldOpacity = g_graphics.getOpacity();
@@ -802,11 +802,24 @@ void UIWidget::onStyleApply(const OTMLNodePtr& styleNode)
else if(node->tag() == "layout") {
// layout is set only once
assert(!m_layout);
if(node->value() == "verticalBox") {
setLayout(UILayoutPtr(new UIVerticalLayout(asUIWidget())));
} else if(node->value() == "anchor") {
setLayout(UILayoutPtr(new UIAnchorLayout(asUIWidget())));
}
std::string layoutType;
if(node->hasValue())
layoutType = node->value();
else
layoutType = node->valueAt("type");
UILayoutPtr layout;
if(layoutType == "verticalBox")
layout = UILayoutPtr(new UIVerticalLayout(asUIWidget()));
else if(layoutType == "anchor")
layout = UILayoutPtr(new UIAnchorLayout(asUIWidget()));
else
throw OTMLException(node, "cannot determine layout type");
if(node->hasChildren())
layout->applyStyle(node);
setLayout(layout);
}
// anchors
else if(boost::starts_with(node->tag(), "anchors.")) {

View File

@@ -663,7 +663,7 @@ void ProtocolGame::parsePlayerSkills(InputMessage& msg)
}
g_dispatcher.addEvent([=] {
g_lua.callGlobalField("Game", "setSkill", skill, values[Otc::SkillLevel], values[Otc::SkillPercent]);
g_lua.callGlobalField("Game", "onSkillUpdate", skill, values[Otc::SkillLevel], values[Otc::SkillPercent]);
});
}
}
@@ -711,7 +711,10 @@ void ProtocolGame::parseCreatureSpeak(InputMessage& msg)
}
std::string message = msg.getString(); // message
logDebug(name, "[", level, "]: ", message);
g_dispatcher.addEvent([=] {
g_lua.callGlobalField("Game", "onCreatureSpeak", name, level, type, message);
});
}
void ProtocolGame::parseChannelList(InputMessage& msg)

View File

@@ -148,7 +148,7 @@ void OTClient::run()
render();
// render fps
defaultFont->renderText(fpsText, Point(g_graphics.getScreenSize().width() - fpsTextSize.width() - 10, 38));
defaultFont->renderText(fpsText, Point(g_graphics.getScreenSize().width() - fpsTextSize.width() - 70, 10));
// render end
g_graphics.endRender();