add chat buffer

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

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

@ -2,10 +2,26 @@ Chat = {}
-- private variables
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
function Chat.create()
chatPanel = loadUI("/chat/chat.otui", Game.gameBottomPanel)
chatBuffer = chatPanel:getChildById('chatBuffer')
end
function Chat.destroy()
@ -16,4 +32,5 @@ end
-- hooked events
connect(Game, { onLogin = Chat.create,
onLogout = Chat.destroy })
onLogout = Chat.destroy,
onCreatureSpeak = onCreatureSpeak})

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

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

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

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

@ -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;

@ -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());
}
}

@ -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

@ -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.")) {

@ -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)

@ -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();

Loading…
Cancel
Save