From fd80589c7be5e433ca19126eff4104904cfbd9ea Mon Sep 17 00:00:00 2001 From: Henrique Date: Sun, 13 Nov 2011 20:23:21 -0200 Subject: [PATCH] creature square init, inventory improvements --- modules/inventory/inventory.lua | 17 ++++++++- modules/inventory/inventory.otui | 52 +++++++++++++++++++------- src/otclient/core/creature.cpp | 8 ++++ src/otclient/core/creature.h | 3 ++ src/otclient/core/outfit.cpp | 2 +- src/otclient/core/outfit.h | 12 +++--- src/otclient/net/protocolgameparse.cpp | 22 +++++++++-- 7 files changed, 91 insertions(+), 25 deletions(-) diff --git a/modules/inventory/inventory.lua b/modules/inventory/inventory.lua index 3b236fe1..b9a551cf 100644 --- a/modules/inventory/inventory.lua +++ b/modules/inventory/inventory.lua @@ -29,7 +29,7 @@ function Inventory.destroy() end -- hooked events -function Game.onInventoryChange(slot, item) +function Inventory.onInventoryChange(slot, item) local slotId if slot == InventorySlotHead then slotId = 'head' @@ -57,5 +57,18 @@ function Game.onInventoryChange(slot, item) itemWidget:setItem(item) 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, - onLogout = Inventory.destroy }) + onLogout = Inventory.destroy, + onInventoryChange = Inventory.onInventoryChange, + onFreeCapacityChange = Inventory.onFreeCapacityChange, + onSoulChange = Inventory.onSoulChange }) diff --git a/modules/inventory/inventory.otui b/modules/inventory/inventory.otui index 892ab678..b245dc4d 100644 --- a/modules/inventory/inventory.otui +++ b/modules/inventory/inventory.otui @@ -15,57 +15,83 @@ UIWindow id: armor anchors.top: prev.bottom anchors.horizontalCenter: prev.horizontalCenter - margin.top: 10 + margin.top: 5 Item id: legs anchors.top: prev.bottom anchors.horizontalCenter: prev.horizontalCenter - margin.top: 10 + margin.top: 5 Item id: feet anchors.top: prev.bottom anchors.horizontalCenter: prev.horizontalCenter - margin.top: 10 + margin.top: 5 Item id: necklace anchors.top: parent.top anchors.right: head.left - margin.top: 15 - margin.right: 10 + margin.top: 10 + margin.right: 5 Item id: left anchors.top: prev.bottom anchors.horizontalCenter: prev.horizontalCenter - margin.top: 10 + margin.top: 5 Item id: ring anchors.top: prev.bottom anchors.horizontalCenter: prev.horizontalCenter - margin.top: 10 + margin.top: 5 Item id: backpack anchors.top: parent.top anchors.left: head.right - margin.top: 15 - margin.left: 10 + margin.top: 10 + margin.left: 5 Item id: right anchors.top: prev.bottom anchors.horizontalCenter: prev.horizontalCenter - margin.top: 10 + margin.top: 5 Item id: ammo anchors.top: prev.bottom 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 diff --git a/src/otclient/core/creature.cpp b/src/otclient/core/creature.cpp index 8ff82a3f..2e08c7ae 100644 --- a/src/otclient/core/creature.cpp +++ b/src/otclient/core/creature.cpp @@ -35,6 +35,7 @@ Creature::Creature() : Thing() { m_healthPercent = 0; + m_showSquareColor = false; m_direction = Otc::South; m_walking = false; @@ -46,6 +47,12 @@ void Creature::draw(const Point& p) { 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 for(m_yPattern = 0; m_yPattern < type.dimensions[ThingType::PatternY]; m_yPattern++) { @@ -54,6 +61,7 @@ void Creature::draw(const Point& p) continue; // draw white item + g_graphics.bindColor(Fw::white); internalDraw(p + m_walkOffset, 0); // draw mask if exists diff --git a/src/otclient/core/creature.h b/src/otclient/core/creature.h index 78d707ae..c471c112 100644 --- a/src/otclient/core/creature.h +++ b/src/otclient/core/creature.h @@ -46,6 +46,7 @@ public: void setShield(uint8 shield) { m_shield = shield; } void setEmblem(uint8 emblem) { m_emblem = emblem; } void setImpassable(bool impassable) { m_impassable = impassable; } + void setSquareColor(uint8 squareColor) { m_squareColor = squareColor; } std::string getName() { return m_name; } uint8 getHealthPercent() { return m_healthPercent; } @@ -81,6 +82,8 @@ protected: uint8 m_shield; uint8 m_emblem; bool m_impassable; + uint8 m_squareColor; + bool m_showSquareColor; FontPtr m_informationFont; Color m_informationColor; diff --git a/src/otclient/core/outfit.cpp b/src/otclient/core/outfit.cpp index 3dc25e0c..57c42224 100644 --- a/src/otclient/core/outfit.cpp +++ b/src/otclient/core/outfit.cpp @@ -22,7 +22,7 @@ #include "outfit.h" -Color Outfit::internalGetColor(int color) +Color Outfit::getColor(int color) { if(color >= HSI_H_STEPS * HSI_SI_VALUES) color = 0; diff --git a/src/otclient/core/outfit.h b/src/otclient/core/outfit.h index 0e51069e..2dfb79e1 100644 --- a/src/otclient/core/outfit.h +++ b/src/otclient/core/outfit.h @@ -33,11 +33,13 @@ class Outfit }; public: + static Color getColor(int color); + void setType(int type) { m_type = type; } - void setHead(int head) { m_head = internalGetColor(head); } - void setBody(int body) { m_body = internalGetColor(body); } - void setLegs(int legs) { m_legs = internalGetColor(legs); } - void setFeet(int feet) { m_feet = internalGetColor(feet); } + void setHead(int head) { m_head = getColor(head); } + void setBody(int body) { m_body = getColor(body); } + void setLegs(int legs) { m_legs = getColor(legs); } + void setFeet(int feet) { m_feet = getColor(feet); } void setAddons(int addons) { m_addons = addons; } int getType() { return m_type; } @@ -48,8 +50,6 @@ public: int getAddons() { return m_addons; } private: - Color internalGetColor(int color); - int m_type, m_addons; Color m_head, m_body, m_legs, m_feet; }; diff --git a/src/otclient/net/protocolgameparse.cpp b/src/otclient/net/protocolgameparse.cpp index 00876153..dd75f6c4 100644 --- a/src/otclient/net/protocolgameparse.cpp +++ b/src/otclient/net/protocolgameparse.cpp @@ -546,8 +546,12 @@ void ProtocolGame::parseDistanceMissile(InputMessage& msg) void ProtocolGame::parseCreatureSquare(InputMessage& msg) { - msg.getU32(); // creatureId - msg.getU8(); // color + uint32 id = msg.getU32(); + uint8 color = msg.getU8(); + + CreaturePtr creature = g_map.getCreatureById(id); + if(creature) + creature->setSquareColor(color); } 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)); }); - 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::Level, msg.getU16()); m_localPlayer->setStatistic(Otc::LevelPercent, msg.getU8()); + m_localPlayer->setStatistic(Otc::Mana, 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::MagicLevelPercent, 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()); }