finally reloadable vip, skills, inventory, chat and minimap

This commit is contained in:
Eduardo Bart 2012-04-27 03:30:54 -03:00
parent d0b839a4eb
commit ceb051cb75
12 changed files with 98 additions and 28 deletions

View File

@ -113,7 +113,7 @@ end
local function onOpenPrivateChannel(receiver) local function onOpenPrivateChannel(receiver)
local privateTab = Console.getTab(receiver) local privateTab = Console.getTab(receiver)
if privateTab == nil then if privateTab == nil then
Console.addTab(receiver) Console.addTab(receiver, true)
end end
end end

View File

@ -7,10 +7,9 @@ local inventoryButton
-- public functions -- public functions
function Inventory.init() function Inventory.init()
connect(g_game, { onGameEnd = Inventory.clear, connect(LocalPlayer, { onInventoryChange = Inventory.onInventoryChange,
onInventoryChange = Inventory.onInventoryChange, onFreeCapacityChange = Inventory.onFreeCapacityChange })
onFreeCapacityChange = Inventory.onFreeCapacityChange, connect(g_game, { onGameEnd = Inventory.clear })
onSoulChange = Inventory.onSoulChange })
Keyboard.bindKeyDown('Ctrl+I', Inventory.toggle) Keyboard.bindKeyDown('Ctrl+I', Inventory.toggle)
@ -20,16 +19,13 @@ function Inventory.init()
inventoryButton = TopMenu.addGameToggleButton('inventoryButton', tr('Inventory') .. ' (Ctrl+I)', 'inventory.png', Inventory.toggle) inventoryButton = TopMenu.addGameToggleButton('inventoryButton', tr('Inventory') .. ' (Ctrl+I)', 'inventory.png', Inventory.toggle)
inventoryButton:setOn(true) inventoryButton:setOn(true)
if g_game.isOnline() then Inventory.refresh()
Inventory.reload()
end
end end
function Inventory.terminate() function Inventory.terminate()
connect(g_game, { onGameEnd = Inventory.clear, disconnect(LocalPlayer, { onInventoryChange = Inventory.onInventoryChange,
onInventoryChange = Inventory.onInventoryChange, onFreeCapacityChange = Inventory.onFreeCapacityChange })
onFreeCapacityChange = Inventory.onFreeCapacityChange, disconnect(g_game, { onGameEnd = Inventory.clear })
onSoulChange = Inventory.onSoulChange })
Keyboard.unbindKeyDown('Ctrl+I') Keyboard.unbindKeyDown('Ctrl+I')
@ -42,30 +38,29 @@ function Inventory.terminate()
Inventory = nil Inventory = nil
end end
function Inventory.refresh()
local player = g_game.getLocalPlayer()
if not player then return end
for i=1,10 do
Inventory.onInventoryChange(player, i, player:getInventoryItem(i))
end
end
function Inventory.toggle() function Inventory.toggle()
local visible = not inventoryWindow:isExplicitlyVisible() local visible = not inventoryWindow:isExplicitlyVisible()
inventoryWindow:setVisible(visible) inventoryWindow:setVisible(visible)
inventoryButton:setOn(visible) inventoryButton:setOn(visible)
end end
function Inventory.clear()
end
function Inventory.reload()
end
-- hooked events -- hooked events
function Inventory.onInventoryChange(slot, item) function Inventory.onInventoryChange(player, slot, item)
local itemWidget = inventoryPanel:getChildById('slot' .. slot) local itemWidget = inventoryPanel:getChildById('slot' .. slot)
itemWidget:setItem(item) itemWidget:setItem(item)
end end
function Inventory.onFreeCapacityChange(freeCapacity) function Inventory.onFreeCapacityChange(player, freeCapacity)
local widget = inventoryPanel:getChildById('capacity') local widget = inventoryPanel:getChildById('capacity')
widget:setText("Cap:\n" .. freeCapacity) widget:setText("Cap:\n" .. freeCapacity)
end end
function Inventory.onSoulChange(soul)
local widget = inventoryPanel:getChildById('soul')
widget:setText("Soul:\n" .. soul)
end

View File

@ -3,6 +3,7 @@ Minimap = {}
-- private variables -- private variables
local minimapWidget local minimapWidget
local minimapButton local minimapButton
local DEFAULT_ZOOM = 45
-- private functions -- private functions
function onMinimapMouseRelease(self, mousePosition, mouseButton) function onMinimapMouseRelease(self, mousePosition, mouseButton)
@ -40,6 +41,8 @@ function Minimap.init()
minimapWidget.onMouseRelease = onMinimapMouseRelease minimapWidget.onMouseRelease = onMinimapMouseRelease
minimapWidget.onMouseWheel = onMinimapMouseWheel minimapWidget.onMouseWheel = onMinimapMouseWheel
minimapWidget:hide() minimapWidget:hide()
Minimap.reset()
end end
function Minimap.terminate() function Minimap.terminate()
@ -61,7 +64,9 @@ function Minimap.toggle()
end end
function Minimap.reset() function Minimap.reset()
minimapWidget:followCreature(g_game.getLocalPlayer()) local player = g_game.getLocalPlayer()
for i=1,10 do minimapWidget:zoomOut() end if not player then return end
minimapWidget:followCreature(player)
minimapWidget:setZoom(DEFAULT_ZOOM)
end end

View File

@ -39,6 +39,8 @@ function Skills.init()
skillsButton = TopMenu.addGameToggleButton('skillsButton', tr('Skills') .. ' (Ctrl+S)', 'skills.png', Skills.toggle) skillsButton = TopMenu.addGameToggleButton('skillsButton', tr('Skills') .. ' (Ctrl+S)', 'skills.png', Skills.toggle)
skillsButton:setOn(true) skillsButton:setOn(true)
Keyboard.bindKeyDown('Ctrl+S', Skills.toggle) Keyboard.bindKeyDown('Ctrl+S', Skills.toggle)
Skills.refresh()
end end
function Skills.terminate() function Skills.terminate()
@ -63,6 +65,24 @@ function Skills.terminate()
Skills = nil Skills = nil
end end
function Skills.refresh()
local player = g_game.getLocalPlayer()
if not player then return end
Skills.onExperienceChange(player, player:getExperience())
Skills.onLevelChange(player, player:getLevel(), player:getLevelPercent())
Skills.onHealthChange(player, player:getHealth(), player:getMaxHealth())
Skills.onManaChange(player, player:getMana(), player:getMaxMana())
Skills.onSoulChange(player, player:getSoul())
Skills.onFreeCapacityChange(player, player:getFreeCapacity())
Skills.onStaminaChange(player, player:getStamina())
Skills.onMagicLevelChange(player, player:getMagicLevel(), player:getMagicLevelPercent())
for i=0,6 do
Skills.onSkillChange(player, i, player:getSkillLevel(i), player:getSkillLevelPercent(i))
end
end
function Skills.toggle() function Skills.toggle()
local visible = not skillsWindow:isExplicitlyVisible() local visible = not skillsWindow:isExplicitlyVisible()
skillsWindow:setVisible(visible) skillsWindow:setVisible(visible)

View File

@ -15,6 +15,8 @@ function VipList.init()
vipWindow = displayUI('viplist.otui', GameInterface.getLeftPanel()) vipWindow = displayUI('viplist.otui', GameInterface.getLeftPanel())
vipButton = TopMenu.addGameToggleButton('vipListButton', tr('VIP list'), 'viplist.png', VipList.toggle) vipButton = TopMenu.addGameToggleButton('vipListButton', tr('VIP list'), 'viplist.png', VipList.toggle)
vipButton:setOn(true) vipButton:setOn(true)
VipList.refresh()
end end
function VipList.terminate() function VipList.terminate()
@ -30,6 +32,13 @@ function VipList.terminate()
VipList = nil VipList = nil
end end
function VipList.refresh()
VipList.clear()
for id,vip in pairs(g_game.getVips()) do
VipList.onAddVip(id, unpack(vip))
end
end
function VipList.clear() function VipList.clear()
local vipList = vipWindow:getChildById('contentsPanel') local vipList = vipWindow:getChildById('contentsPanel')
vipList:destroyChildren() vipList:destroyChildren()

View File

@ -154,6 +154,21 @@ namespace Otc
LastSkill LastSkill
}; };
enum Inventory {
NoInventory = 0,
Head,
Neck,
Bag,
Armor,
RightHand,
LeftHand,
Legs,
Feet,
Ring,
Ammo,
LastInventory
};
enum Direction { enum Direction {
North = 0, North = 0,
East, East,

View File

@ -55,6 +55,7 @@ void Game::resetGameStates()
container->close(); container->close();
} }
m_containers.clear(); m_containers.clear();
m_vips.clear();
m_worldName = ""; m_worldName = "";
} }
@ -241,7 +242,7 @@ void Game::processInventoryChange(int slot, const ItemPtr& item)
if(item) if(item)
item->setPosition(Position(65535, slot, 0)); item->setPosition(Position(65535, slot, 0));
g_lua.callGlobalField("g_game","onInventoryChange", slot, item); m_localPlayer->setInventoryItem((Otc::Inventory)slot, item);
} }
void Game::processCreatureMove(const CreaturePtr& creature, const Position& oldPos, const Position& newPos) void Game::processCreatureMove(const CreaturePtr& creature, const Position& oldPos, const Position& newPos)
@ -288,11 +289,13 @@ void Game::processCloseChannel(int channelId)
void Game::processVipAdd(uint id, const std::string& name, bool online) void Game::processVipAdd(uint id, const std::string& name, bool online)
{ {
m_vips[id] = Vip(name, online);
g_lua.callGlobalField("g_game", "onAddVip", id, name, online); g_lua.callGlobalField("g_game", "onAddVip", id, name, online);
} }
void Game::processVipStateChange(uint id, bool online) void Game::processVipStateChange(uint id, bool online)
{ {
std::get<1>(m_vips[id]) = online;
g_lua.callGlobalField("g_game", "onVipStateChange", id, online); g_lua.callGlobalField("g_game", "onVipStateChange", id, online);
} }

View File

@ -29,6 +29,8 @@
#include <otclient/core/outfit.h> #include <otclient/core/outfit.h>
#include <framework/core/timer.h> #include <framework/core/timer.h>
typedef std::tuple<std::string, bool> Vip;
class Game class Game
{ {
public: public:
@ -221,6 +223,7 @@ public:
ContainerPtr getContainer(int index) { return m_containers[index]; } ContainerPtr getContainer(int index) { return m_containers[index]; }
std::map<int, ContainerPtr> getContainers() { return m_containers; } std::map<int, ContainerPtr> getContainers() { return m_containers; }
std::map<int, Vip> getVips() { return m_vips; }
CreaturePtr getAttackingCreature() { return m_attackingCreature; } CreaturePtr getAttackingCreature() { return m_attackingCreature; }
CreaturePtr getFollowingCreature() { return m_followingCreature; } CreaturePtr getFollowingCreature() { return m_followingCreature; }
int getServerBeat() { return m_serverBeat; } int getServerBeat() { return m_serverBeat; }
@ -238,6 +241,8 @@ private:
CreaturePtr m_followingCreature; CreaturePtr m_followingCreature;
ProtocolGamePtr m_protocolGame; ProtocolGamePtr m_protocolGame;
std::map<int, ContainerPtr> m_containers; std::map<int, ContainerPtr> m_containers;
std::map<int, Vip> m_vips;
bool m_dead; bool m_dead;
int m_serverBeat; int m_serverBeat;
Otc::FightModes m_fightMode; Otc::FightModes m_fightMode;

View File

@ -284,3 +284,13 @@ void LocalPlayer::setStamina(double stamina)
callLuaField("onStaminaChange", stamina, oldStamina); callLuaField("onStaminaChange", stamina, oldStamina);
} }
} }
void LocalPlayer::setInventoryItem(Otc::Inventory inventory, const ItemPtr& item)
{
if(m_inventoryItems[inventory] != item) {
ItemPtr oldItem = m_inventoryItems[inventory];
m_inventoryItems[inventory] = item;
callLuaField("onInventoryChange", inventory, item, oldItem);
}
}

View File

@ -50,6 +50,7 @@ public:
void setSoul(double soul); void setSoul(double soul);
void setStamina(double stamina); void setStamina(double stamina);
void setKnown(bool known) { m_known = known; } void setKnown(bool known) { m_known = known; }
void setInventoryItem(Otc::Inventory inventory, const ItemPtr& item);
int getStates() { return m_states; } int getStates() { return m_states; }
int getSkillLevel(Otc::Skill skill) { return m_skillsLevel[skill]; } int getSkillLevel(Otc::Skill skill) { return m_skillsLevel[skill]; }
@ -66,6 +67,7 @@ public:
double getMagicLevelPercent() { return m_magicLevelPercent; } double getMagicLevelPercent() { return m_magicLevelPercent; }
double getSoul() { return m_soul; } double getSoul() { return m_soul; }
double getStamina() { return m_stamina; } double getStamina() { return m_stamina; }
ItemPtr getInventoryItem(Otc::Inventory inventory) { return m_inventoryItems[inventory]; }
bool isKnown() { return m_known; } bool isKnown() { return m_known; }
bool isPreWalking() { return m_preWalking; } bool isPreWalking() { return m_preWalking; }
@ -92,6 +94,7 @@ private:
bool m_walkLocked; bool m_walkLocked;
Position m_lastPrewalkDestionation; Position m_lastPrewalkDestionation;
Timer m_walkLockTimer; Timer m_walkLockTimer;
ItemPtr m_inventoryItems[Otc::LastInventory];
std::array<int, Otc::LastSkill> m_skillsLevel; std::array<int, Otc::LastSkill> m_skillsLevel;
std::array<int, Otc::LastSkill> m_skillsLevelPercent; std::array<int, Otc::LastSkill> m_skillsLevelPercent;

View File

@ -151,6 +151,7 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassStaticFunction("g_game", "isFollowing", std::bind(&Game::isFollowing, &g_game)); g_lua.bindClassStaticFunction("g_game", "isFollowing", std::bind(&Game::isFollowing, &g_game));
g_lua.bindClassStaticFunction("g_game", "getContainer", std::bind(&Game::getContainer, &g_game, std::placeholders::_1)); g_lua.bindClassStaticFunction("g_game", "getContainer", std::bind(&Game::getContainer, &g_game, std::placeholders::_1));
g_lua.bindClassStaticFunction("g_game", "getContainers", std::bind(&Game::getContainers, &g_game)); g_lua.bindClassStaticFunction("g_game", "getContainers", std::bind(&Game::getContainers, &g_game));
g_lua.bindClassStaticFunction("g_game", "getVips", std::bind(&Game::getVips, &g_game));
g_lua.bindClassStaticFunction("g_game", "getAttackingCreature", std::bind(&Game::getAttackingCreature, &g_game)); g_lua.bindClassStaticFunction("g_game", "getAttackingCreature", std::bind(&Game::getAttackingCreature, &g_game));
g_lua.bindClassStaticFunction("g_game", "getFollowingCreature", std::bind(&Game::getFollowingCreature, &g_game)); g_lua.bindClassStaticFunction("g_game", "getFollowingCreature", std::bind(&Game::getFollowingCreature, &g_game));
g_lua.bindClassStaticFunction("g_game", "getServerBeat", std::bind(&Game::getServerBeat, &g_game)); g_lua.bindClassStaticFunction("g_game", "getServerBeat", std::bind(&Game::getServerBeat, &g_game));
@ -272,6 +273,7 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassMemberFunction<LocalPlayer>("setSoul", &LocalPlayer::setSoul); g_lua.bindClassMemberFunction<LocalPlayer>("setSoul", &LocalPlayer::setSoul);
g_lua.bindClassMemberFunction<LocalPlayer>("setStamina", &LocalPlayer::setStamina); g_lua.bindClassMemberFunction<LocalPlayer>("setStamina", &LocalPlayer::setStamina);
g_lua.bindClassMemberFunction<LocalPlayer>("setKnown", &LocalPlayer::setKnown); g_lua.bindClassMemberFunction<LocalPlayer>("setKnown", &LocalPlayer::setKnown);
g_lua.bindClassMemberFunction<LocalPlayer>("setInventoryItem", &LocalPlayer::setInventoryItem);
g_lua.bindClassMemberFunction<LocalPlayer>("getStates", &LocalPlayer::getStates); g_lua.bindClassMemberFunction<LocalPlayer>("getStates", &LocalPlayer::getStates);
g_lua.bindClassMemberFunction<LocalPlayer>("getSkillLevel", &LocalPlayer::getSkillLevel); g_lua.bindClassMemberFunction<LocalPlayer>("getSkillLevel", &LocalPlayer::getSkillLevel);
g_lua.bindClassMemberFunction<LocalPlayer>("getSkillLevelPercent", &LocalPlayer::getSkillLevelPercent); g_lua.bindClassMemberFunction<LocalPlayer>("getSkillLevelPercent", &LocalPlayer::getSkillLevelPercent);
@ -287,6 +289,7 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassMemberFunction<LocalPlayer>("getMagicLevelPercent", &LocalPlayer::getMagicLevelPercent); g_lua.bindClassMemberFunction<LocalPlayer>("getMagicLevelPercent", &LocalPlayer::getMagicLevelPercent);
g_lua.bindClassMemberFunction<LocalPlayer>("getSoul", &LocalPlayer::getSoul); g_lua.bindClassMemberFunction<LocalPlayer>("getSoul", &LocalPlayer::getSoul);
g_lua.bindClassMemberFunction<LocalPlayer>("getStamina", &LocalPlayer::getStamina); g_lua.bindClassMemberFunction<LocalPlayer>("getStamina", &LocalPlayer::getStamina);
g_lua.bindClassMemberFunction<LocalPlayer>("getInventoryItem", &LocalPlayer::getInventoryItem);
g_lua.bindClassMemberFunction<LocalPlayer>("isKnown", &LocalPlayer::isKnown); g_lua.bindClassMemberFunction<LocalPlayer>("isKnown", &LocalPlayer::isKnown);
g_lua.bindClassMemberFunction<LocalPlayer>("isPreWalking", &LocalPlayer::isPreWalking); g_lua.bindClassMemberFunction<LocalPlayer>("isPreWalking", &LocalPlayer::isPreWalking);
g_lua.bindClassMemberFunction<LocalPlayer>("asLocalPlayer", &LocalPlayer::asLocalPlayer); g_lua.bindClassMemberFunction<LocalPlayer>("asLocalPlayer", &LocalPlayer::asLocalPlayer);

View File

@ -36,6 +36,7 @@ UIMap::UIMap()
m_aspectRatio = 0.0f; m_aspectRatio = 0.0f;
m_maxZoomIn = 3; m_maxZoomIn = 3;
m_maxZoomOut = 512; m_maxZoomOut = 512;
m_mapRect.resize(1,1);
g_map.addMapView(m_mapView); g_map.addMapView(m_mapView);
} }
@ -58,7 +59,8 @@ void UIMap::drawSelf()
bool UIMap::setZoom(int zoom) bool UIMap::setZoom(int zoom)
{ {
//TODO m_zoom = std::min(std::max(zoom, m_maxZoomIn), m_maxZoomOut);
updateVisibleDimension();
return false; return false;
} }