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 privateTab = Console.getTab(receiver)
if privateTab == nil then
Console.addTab(receiver)
Console.addTab(receiver, true)
end
end

View File

@ -7,10 +7,9 @@ local inventoryButton
-- public functions
function Inventory.init()
connect(g_game, { onGameEnd = Inventory.clear,
onInventoryChange = Inventory.onInventoryChange,
onFreeCapacityChange = Inventory.onFreeCapacityChange,
onSoulChange = Inventory.onSoulChange })
connect(LocalPlayer, { onInventoryChange = Inventory.onInventoryChange,
onFreeCapacityChange = Inventory.onFreeCapacityChange })
connect(g_game, { onGameEnd = Inventory.clear })
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:setOn(true)
if g_game.isOnline() then
Inventory.reload()
end
Inventory.refresh()
end
function Inventory.terminate()
connect(g_game, { onGameEnd = Inventory.clear,
onInventoryChange = Inventory.onInventoryChange,
onFreeCapacityChange = Inventory.onFreeCapacityChange,
onSoulChange = Inventory.onSoulChange })
disconnect(LocalPlayer, { onInventoryChange = Inventory.onInventoryChange,
onFreeCapacityChange = Inventory.onFreeCapacityChange })
disconnect(g_game, { onGameEnd = Inventory.clear })
Keyboard.unbindKeyDown('Ctrl+I')
@ -42,30 +38,29 @@ function Inventory.terminate()
Inventory = nil
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()
local visible = not inventoryWindow:isExplicitlyVisible()
inventoryWindow:setVisible(visible)
inventoryButton:setOn(visible)
end
function Inventory.clear()
end
function Inventory.reload()
end
-- hooked events
function Inventory.onInventoryChange(slot, item)
function Inventory.onInventoryChange(player, slot, item)
local itemWidget = inventoryPanel:getChildById('slot' .. slot)
itemWidget:setItem(item)
end
function Inventory.onFreeCapacityChange(freeCapacity)
function Inventory.onFreeCapacityChange(player, freeCapacity)
local widget = inventoryPanel:getChildById('capacity')
widget:setText("Cap:\n" .. freeCapacity)
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
local minimapWidget
local minimapButton
local DEFAULT_ZOOM = 45
-- private functions
function onMinimapMouseRelease(self, mousePosition, mouseButton)
@ -40,6 +41,8 @@ function Minimap.init()
minimapWidget.onMouseRelease = onMinimapMouseRelease
minimapWidget.onMouseWheel = onMinimapMouseWheel
minimapWidget:hide()
Minimap.reset()
end
function Minimap.terminate()
@ -61,7 +64,9 @@ function Minimap.toggle()
end
function Minimap.reset()
minimapWidget:followCreature(g_game.getLocalPlayer())
for i=1,10 do minimapWidget:zoomOut() end
local player = g_game.getLocalPlayer()
if not player then return end
minimapWidget:followCreature(player)
minimapWidget:setZoom(DEFAULT_ZOOM)
end

View File

@ -39,6 +39,8 @@ function Skills.init()
skillsButton = TopMenu.addGameToggleButton('skillsButton', tr('Skills') .. ' (Ctrl+S)', 'skills.png', Skills.toggle)
skillsButton:setOn(true)
Keyboard.bindKeyDown('Ctrl+S', Skills.toggle)
Skills.refresh()
end
function Skills.terminate()
@ -63,6 +65,24 @@ function Skills.terminate()
Skills = nil
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()
local visible = not skillsWindow:isExplicitlyVisible()
skillsWindow:setVisible(visible)

View File

@ -15,6 +15,8 @@ function VipList.init()
vipWindow = displayUI('viplist.otui', GameInterface.getLeftPanel())
vipButton = TopMenu.addGameToggleButton('vipListButton', tr('VIP list'), 'viplist.png', VipList.toggle)
vipButton:setOn(true)
VipList.refresh()
end
function VipList.terminate()
@ -30,6 +32,13 @@ function VipList.terminate()
VipList = nil
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()
local vipList = vipWindow:getChildById('contentsPanel')
vipList:destroyChildren()

View File

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

View File

@ -55,6 +55,7 @@ void Game::resetGameStates()
container->close();
}
m_containers.clear();
m_vips.clear();
m_worldName = "";
}
@ -241,7 +242,7 @@ void Game::processInventoryChange(int slot, const ItemPtr& item)
if(item)
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)
@ -288,11 +289,13 @@ void Game::processCloseChannel(int channelId)
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);
}
void Game::processVipStateChange(uint id, bool online)
{
std::get<1>(m_vips[id]) = online;
g_lua.callGlobalField("g_game", "onVipStateChange", id, online);
}

View File

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

View File

@ -284,3 +284,13 @@ void LocalPlayer::setStamina(double stamina)
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 setStamina(double stamina);
void setKnown(bool known) { m_known = known; }
void setInventoryItem(Otc::Inventory inventory, const ItemPtr& item);
int getStates() { return m_states; }
int getSkillLevel(Otc::Skill skill) { return m_skillsLevel[skill]; }
@ -66,6 +67,7 @@ public:
double getMagicLevelPercent() { return m_magicLevelPercent; }
double getSoul() { return m_soul; }
double getStamina() { return m_stamina; }
ItemPtr getInventoryItem(Otc::Inventory inventory) { return m_inventoryItems[inventory]; }
bool isKnown() { return m_known; }
bool isPreWalking() { return m_preWalking; }
@ -92,6 +94,7 @@ private:
bool m_walkLocked;
Position m_lastPrewalkDestionation;
Timer m_walkLockTimer;
ItemPtr m_inventoryItems[Otc::LastInventory];
std::array<int, Otc::LastSkill> m_skillsLevel;
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", "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", "getVips", std::bind(&Game::getVips, &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", "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>("setStamina", &LocalPlayer::setStamina);
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>("getSkillLevel", &LocalPlayer::getSkillLevel);
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>("getSoul", &LocalPlayer::getSoul);
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>("isPreWalking", &LocalPlayer::isPreWalking);
g_lua.bindClassMemberFunction<LocalPlayer>("asLocalPlayer", &LocalPlayer::asLocalPlayer);

View File

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