add chat buffer

master
Eduardo Bart 13 years ago
parent 6aadf896da
commit 39c62942cf

@ -10,4 +10,5 @@ console history
console text selection console text selection
console scrolling console scrolling
padding padding
remember password/account remember password/account
move fps to a module

@ -2,10 +2,26 @@ Chat = {}
-- private variables -- private variables
local chatPanel local chatPanel
local chatBuffer
-- private functions
local function onCreatureSpeak(name, level, msgtype, message)
style = 'ChatLabel'
if name and level > 0 then
message = name .. ' [' .. level .. ']: ' .. message
style = 'YellowChatLabel'
end
local label = UILabel.create()
label:setStyle(style)
label:setText(message)
chatBuffer:addChild(label)
end
-- public functions -- public functions
function Chat.create() function Chat.create()
chatPanel = loadUI("/chat/chat.otui", Game.gameBottomPanel) chatPanel = loadUI("/chat/chat.otui", Game.gameBottomPanel)
chatBuffer = chatPanel:getChildById('chatBuffer')
end end
function Chat.destroy() function Chat.destroy()
@ -16,4 +32,5 @@ end
-- hooked events -- hooked events
connect(Game, { onLogin = Chat.create, connect(Game, { onLogin = Chat.create,
onLogout = Chat.destroy }) onLogout = Chat.destroy,
onCreatureSpeak = onCreatureSpeak})

@ -1,6 +1,9 @@
ChatLabel < UILabel ChatLabel < UILabel
font: verdana-11px-monochrome font: verdana-11px-antialised
height: 16 height: 14
YellowChatLabel < ChatLabel
color: yellow
Panel Panel
id: chatPanel id: chatPanel
@ -11,12 +14,14 @@ Panel
anchors.top: parent.top anchors.top: parent.top
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
anchors.bottom: next.top anchors.bottom: chatLineEdit.top
margin.right: 6 margin.right: 6
margin.left: 6 margin.left: 6
margin.bottom: 2 margin.bottom: 2
margin.top: 6 margin.top: 6
layout: verticalBox layout:
type: verticalBox
align bottom: true
focusable: false focusable: false
LineEdit LineEdit

@ -13,7 +13,7 @@ UIWidget
InterfacePanel2 InterfacePanel2
id: bottomPanel id: bottomPanel
height: 140 height: 144
anchors.left: parent.left anchors.left: parent.left
anchors.right: rightPanel.left anchors.right: rightPanel.left
anchors.bottom: parent.bottom anchors.bottom: parent.bottom

@ -40,7 +40,7 @@ function Skills.destroy()
end end
-- hooked events -- hooked events
function Game.setSkill(id, level, percent) function Game.onSkillUpdate(id, level, percent)
local skillPanel = skillWindow:getChildById('skillPanel') local skillPanel = skillWindow:getChildById('skillPanel')
local levelLabel = skillPanel:getChildById('skillLevelId' .. (id + 1)) local levelLabel = skillPanel:getChildById('skillLevelId' .. (id + 1))

@ -10,5 +10,3 @@ Module
onLoad: | onLoad: |
require 'skills' require 'skills'
return true return true

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

@ -22,10 +22,22 @@
#include "uiverticallayout.h" #include "uiverticallayout.h"
#include "uiwidget.h" #include "uiwidget.h"
#include <framework/otml/otml.h>
UIVerticalLayout::UIVerticalLayout(UIWidgetPtr parentWidget) UIVerticalLayout::UIVerticalLayout(UIWidgetPtr parentWidget)
: UILayout(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() void UIVerticalLayout::update()
@ -39,10 +51,14 @@ void UIVerticalLayout::update()
return first->getY() < second->getY(); 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) { for(const UIWidgetPtr& widget : widgets) {
Size size = widget->getSize(); Size size = widget->getSize();
pos.y += widget->getMarginTop(); pos.y += (m_alignBottom) ? -(widget->getMarginBottom()+widget->getHeight()) : widget->getMarginTop();
if(widget->isSizeFixed()) { if(widget->isSizeFixed()) {
pos.x = parentWidget->getX() + (parentWidget->getWidth() - (widget->getMarginLeft() + widget->getWidth() + widget->getMarginRight()))/2; pos.x = parentWidget->getX() + (parentWidget->getWidth() - (widget->getMarginLeft() + widget->getWidth() + widget->getMarginRight()))/2;
pos.x = std::max(pos.x, parentWidget->getX()); 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); pos.x = std::max(pos.x, parentWidget->getX() + (parentWidget->getWidth() - size.width())/2);
} }
widget->setRect(Rect(pos, size)); widget->setRect(Rect(pos, size));
pos.y += widget->getHeight() + widget->getMarginBottom(); pos.y += (m_alignBottom) ? -widget->getMarginTop() : (widget->getHeight() + widget->getMarginBottom());
} }
} }

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

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

@ -663,7 +663,7 @@ void ProtocolGame::parsePlayerSkills(InputMessage& msg)
} }
g_dispatcher.addEvent([=] { 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 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) void ProtocolGame::parseChannelList(InputMessage& msg)

@ -148,7 +148,7 @@ void OTClient::run()
render(); render();
// render fps // 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 // render end
g_graphics.endRender(); g_graphics.endRender();

Loading…
Cancel
Save