creature square init, inventory improvements

This commit is contained in:
Henrique 2011-11-13 20:23:21 -02:00
parent 5f34648c0e
commit fd80589c7b
7 changed files with 91 additions and 25 deletions

View File

@ -29,7 +29,7 @@ function Inventory.destroy()
end end
-- hooked events -- hooked events
function Game.onInventoryChange(slot, item) function Inventory.onInventoryChange(slot, item)
local slotId local slotId
if slot == InventorySlotHead then if slot == InventorySlotHead then
slotId = 'head' slotId = 'head'
@ -57,5 +57,18 @@ function Game.onInventoryChange(slot, item)
itemWidget:setItem(item) itemWidget:setItem(item)
end end
function Inventory.onFreeCapacityChange(freeCapacity)
local widget = window:getChildById('capacity')
widget:setText("Cap:\n" .. freeCapacity)
end
function Inventory.onSoulChange(soul)
local widget = window:getChildById('soul')
widget:setText("Soul:\n" .. soul)
end
connect(Game, { onLogin = Inventory.create, connect(Game, { onLogin = Inventory.create,
onLogout = Inventory.destroy }) onLogout = Inventory.destroy,
onInventoryChange = Inventory.onInventoryChange,
onFreeCapacityChange = Inventory.onFreeCapacityChange,
onSoulChange = Inventory.onSoulChange })

View File

@ -15,57 +15,83 @@ UIWindow
id: armor id: armor
anchors.top: prev.bottom anchors.top: prev.bottom
anchors.horizontalCenter: prev.horizontalCenter anchors.horizontalCenter: prev.horizontalCenter
margin.top: 10 margin.top: 5
Item Item
id: legs id: legs
anchors.top: prev.bottom anchors.top: prev.bottom
anchors.horizontalCenter: prev.horizontalCenter anchors.horizontalCenter: prev.horizontalCenter
margin.top: 10 margin.top: 5
Item Item
id: feet id: feet
anchors.top: prev.bottom anchors.top: prev.bottom
anchors.horizontalCenter: prev.horizontalCenter anchors.horizontalCenter: prev.horizontalCenter
margin.top: 10 margin.top: 5
Item Item
id: necklace id: necklace
anchors.top: parent.top anchors.top: parent.top
anchors.right: head.left anchors.right: head.left
margin.top: 15 margin.top: 10
margin.right: 10 margin.right: 5
Item Item
id: left id: left
anchors.top: prev.bottom anchors.top: prev.bottom
anchors.horizontalCenter: prev.horizontalCenter anchors.horizontalCenter: prev.horizontalCenter
margin.top: 10 margin.top: 5
Item Item
id: ring id: ring
anchors.top: prev.bottom anchors.top: prev.bottom
anchors.horizontalCenter: prev.horizontalCenter anchors.horizontalCenter: prev.horizontalCenter
margin.top: 10 margin.top: 5
Item Item
id: backpack id: backpack
anchors.top: parent.top anchors.top: parent.top
anchors.left: head.right anchors.left: head.right
margin.top: 15 margin.top: 10
margin.left: 10 margin.left: 5
Item Item
id: right id: right
anchors.top: prev.bottom anchors.top: prev.bottom
anchors.horizontalCenter: prev.horizontalCenter anchors.horizontalCenter: prev.horizontalCenter
margin.top: 10 margin.top: 5
Item Item
id: ammo id: ammo
anchors.top: prev.bottom anchors.top: prev.bottom
anchors.horizontalCenter: prev.horizontalCenter anchors.horizontalCenter: prev.horizontalCenter
margin.top: 10 margin.top: 5
Label
id: soul
anchors.top: ring.bottom
anchors.bottom: feet.bottom
anchors.left: ring.left
anchors.right: ring.right
margin.top: 5
align: center
border-image:
source: /core_styles/images/panel_flat.png
border: 4
Label
id: capacity
anchors.top: ammo.bottom
anchors.bottom: feet.bottom
anchors.left: ammo.left
anchors.right: ammo.right
margin.top: 5
align: center
border-image:
source: /core_styles/images/panel_flat.png
border: 4

View File

@ -35,6 +35,7 @@
Creature::Creature() : Thing() Creature::Creature() : Thing()
{ {
m_healthPercent = 0; m_healthPercent = 0;
m_showSquareColor = false;
m_direction = Otc::South; m_direction = Otc::South;
m_walking = false; m_walking = false;
@ -46,6 +47,12 @@ void Creature::draw(const Point& p)
{ {
const ThingType& type = getType(); const ThingType& type = getType();
// TODO: activate on attack, follow, discover how 'attacked' works
if(m_showSquareColor) {
g_graphics.bindColor(Outfit::getColor(m_squareColor));
g_graphics.drawBoundingRect(Rect(p + m_walkOffset - 8, Size(32, 32)), 2);
}
// Render creature // Render creature
for(m_yPattern = 0; m_yPattern < type.dimensions[ThingType::PatternY]; m_yPattern++) { for(m_yPattern = 0; m_yPattern < type.dimensions[ThingType::PatternY]; m_yPattern++) {
@ -54,6 +61,7 @@ void Creature::draw(const Point& p)
continue; continue;
// draw white item // draw white item
g_graphics.bindColor(Fw::white);
internalDraw(p + m_walkOffset, 0); internalDraw(p + m_walkOffset, 0);
// draw mask if exists // draw mask if exists

View File

@ -46,6 +46,7 @@ public:
void setShield(uint8 shield) { m_shield = shield; } void setShield(uint8 shield) { m_shield = shield; }
void setEmblem(uint8 emblem) { m_emblem = emblem; } void setEmblem(uint8 emblem) { m_emblem = emblem; }
void setImpassable(bool impassable) { m_impassable = impassable; } void setImpassable(bool impassable) { m_impassable = impassable; }
void setSquareColor(uint8 squareColor) { m_squareColor = squareColor; }
std::string getName() { return m_name; } std::string getName() { return m_name; }
uint8 getHealthPercent() { return m_healthPercent; } uint8 getHealthPercent() { return m_healthPercent; }
@ -81,6 +82,8 @@ protected:
uint8 m_shield; uint8 m_shield;
uint8 m_emblem; uint8 m_emblem;
bool m_impassable; bool m_impassable;
uint8 m_squareColor;
bool m_showSquareColor;
FontPtr m_informationFont; FontPtr m_informationFont;
Color m_informationColor; Color m_informationColor;

View File

@ -22,7 +22,7 @@
#include "outfit.h" #include "outfit.h"
Color Outfit::internalGetColor(int color) Color Outfit::getColor(int color)
{ {
if(color >= HSI_H_STEPS * HSI_SI_VALUES) if(color >= HSI_H_STEPS * HSI_SI_VALUES)
color = 0; color = 0;

View File

@ -33,11 +33,13 @@ class Outfit
}; };
public: public:
static Color getColor(int color);
void setType(int type) { m_type = type; } void setType(int type) { m_type = type; }
void setHead(int head) { m_head = internalGetColor(head); } void setHead(int head) { m_head = getColor(head); }
void setBody(int body) { m_body = internalGetColor(body); } void setBody(int body) { m_body = getColor(body); }
void setLegs(int legs) { m_legs = internalGetColor(legs); } void setLegs(int legs) { m_legs = getColor(legs); }
void setFeet(int feet) { m_feet = internalGetColor(feet); } void setFeet(int feet) { m_feet = getColor(feet); }
void setAddons(int addons) { m_addons = addons; } void setAddons(int addons) { m_addons = addons; }
int getType() { return m_type; } int getType() { return m_type; }
@ -48,8 +50,6 @@ public:
int getAddons() { return m_addons; } int getAddons() { return m_addons; }
private: private:
Color internalGetColor(int color);
int m_type, m_addons; int m_type, m_addons;
Color m_head, m_body, m_legs, m_feet; Color m_head, m_body, m_legs, m_feet;
}; };

View File

@ -546,8 +546,12 @@ void ProtocolGame::parseDistanceMissile(InputMessage& msg)
void ProtocolGame::parseCreatureSquare(InputMessage& msg) void ProtocolGame::parseCreatureSquare(InputMessage& msg)
{ {
msg.getU32(); // creatureId uint32 id = msg.getU32();
msg.getU8(); // color uint8 color = msg.getU8();
CreaturePtr creature = g_map.getCreatureById(id);
if(creature)
creature->setSquareColor(color);
} }
void ProtocolGame::parseCreatureHealth(InputMessage& msg) void ProtocolGame::parseCreatureHealth(InputMessage& msg)
@ -649,10 +653,16 @@ void ProtocolGame::parsePlayerStats(InputMessage& msg)
g_lua.callGlobalField("Game", "onHealthChange", m_localPlayer->getStatistic(Otc::Health), m_localPlayer->getStatistic(Otc::MaxHealth)); g_lua.callGlobalField("Game", "onHealthChange", m_localPlayer->getStatistic(Otc::Health), m_localPlayer->getStatistic(Otc::MaxHealth));
}); });
m_localPlayer->setStatistic(Otc::FreeCapacity, msg.getU32()); m_localPlayer->setStatistic(Otc::FreeCapacity, msg.getU32() / 100.0);
g_dispatcher.addEvent([=] {
g_lua.callGlobalField("Game", "onFreeCapacityChange", m_localPlayer->getStatistic(Otc::FreeCapacity));
});
m_localPlayer->setStatistic(Otc::Experience, msg.getU32()); m_localPlayer->setStatistic(Otc::Experience, msg.getU32());
m_localPlayer->setStatistic(Otc::Level, msg.getU16()); m_localPlayer->setStatistic(Otc::Level, msg.getU16());
m_localPlayer->setStatistic(Otc::LevelPercent, msg.getU8()); m_localPlayer->setStatistic(Otc::LevelPercent, msg.getU8());
m_localPlayer->setStatistic(Otc::Mana, msg.getU16()); m_localPlayer->setStatistic(Otc::Mana, msg.getU16());
m_localPlayer->setStatistic(Otc::MaxMana, msg.getU16()); m_localPlayer->setStatistic(Otc::MaxMana, msg.getU16());
@ -662,7 +672,13 @@ void ProtocolGame::parsePlayerStats(InputMessage& msg)
m_localPlayer->setStatistic(Otc::MagicLevel, msg.getU8()); m_localPlayer->setStatistic(Otc::MagicLevel, msg.getU8());
m_localPlayer->setStatistic(Otc::MagicLevelPercent, msg.getU8()); m_localPlayer->setStatistic(Otc::MagicLevelPercent, msg.getU8());
m_localPlayer->setStatistic(Otc::Soul, msg.getU8()); m_localPlayer->setStatistic(Otc::Soul, msg.getU8());
g_dispatcher.addEvent([=] {
g_lua.callGlobalField("Game", "onSoulChange", m_localPlayer->getStatistic(Otc::Soul));
});
m_localPlayer->setStatistic(Otc::Stamina, msg.getU16()); m_localPlayer->setStatistic(Otc::Stamina, msg.getU16());
} }