From 9fbdf3f5cb20e0dc7d5443ff52a503fb924bf08f Mon Sep 17 00:00:00 2001 From: Henrique Santiago Date: Mon, 2 Jan 2012 22:10:39 -0200 Subject: [PATCH] look on items --- modules/core_scripts/const.lua | 2 +- modules/game_inventory/inventory.lua | 51 ++++------------------- modules/game_inventory/inventory.otui | 50 +++++++++++++--------- modules/game_textmessage/textmessage.otui | 2 +- src/otclient/core/game.cpp | 8 +++- src/otclient/core/game.h | 3 +- src/otclient/core/map.cpp | 2 +- src/otclient/core/thing.cpp | 2 +- src/otclient/core/thing.h | 4 +- src/otclient/luafunctions.cpp | 2 + src/otclient/net/protocolgameparse.cpp | 2 +- src/otclient/ui/uimap.cpp | 2 +- 12 files changed, 58 insertions(+), 72 deletions(-) diff --git a/modules/core_scripts/const.lua b/modules/core_scripts/const.lua index 2783a32d..47fed839 100644 --- a/modules/core_scripts/const.lua +++ b/modules/core_scripts/const.lua @@ -131,4 +131,4 @@ KeyboardShiftModifier = 4 MouseNoButton = 0 MouseLeftButton = 1 MouseRightButton = 2 -MouseMidButton = 3 \ No newline at end of file +MouseMidButton = 3 diff --git a/modules/game_inventory/inventory.lua b/modules/game_inventory/inventory.lua index be2b6ee5..becdfffe 100644 --- a/modules/game_inventory/inventory.lua +++ b/modules/game_inventory/inventory.lua @@ -3,17 +3,6 @@ Inventory = {} -- private variables local window = nil -local InventorySlotHead = 1 -local InventorySlotNecklace = 2 -local InventorySlotBackpack = 3 -local InventorySlotArmor = 4 -local InventorySlotRight = 5 -local InventorySlotLeft = 6 -local InventorySlotLegs = 7 -local InventorySlotFeet = 8 -local InventorySlotRing = 9 -local InventorySlotAmmo = 10 - -- public functions function Inventory.create() window = UI.display('inventory.otui', { parent = Game.gameRightPanel }) @@ -26,30 +15,7 @@ end -- hooked events function Inventory.onInventoryChange(slot, item) - local slotId - if slot == InventorySlotHead then - slotId = 'head' - elseif slot == InventorySlotNecklace then - slotId = 'necklace' - elseif slot == InventorySlotBackpack then - slotId = 'backpack' - elseif slot == InventorySlotArmor then - slotId = 'armor' - elseif slot == InventorySlotRight then - slotId = 'right' - elseif slot == InventorySlotLeft then - slotId = 'left' - elseif slot == InventorySlotLegs then - slotId = 'legs' - elseif slot == InventorySlotFeet then - slotId = 'feet' - elseif slot == InventorySlotRing then - slotId = 'ring' - elseif slot == InventorySlotAmmo then - slotId = 'ammo' - end - - local itemWidget = window:getChildById(slotId) + local itemWidget = window:getChildById('slot' .. slot) itemWidget:setItem(item) end @@ -64,18 +30,19 @@ function Inventory.onSoulChange(soul) end function Inventory.onInventoryItemMousePress(itemWidget, mousePos, mouseButton) - if mouseButton ~= MouseRightButton then - return - end + if mouseButton ~= MouseRightButton then return end local item = itemWidget:getItem() - if not item then - return - end + if not item then return end local menu = UIPopupMenu.create() - menu:addOption('Look', function() print('look') end) + -- Look + local itemId = item:getId() + local slotId = tonumber(itemWidget:getId():sub(5)) + menu:addOption('Look', function() Game.lookAtInventory(itemId, slotId) end) + + -- Open or Use, depending if thing is a container if item:isContainer() then menu:addOption('Open', function() print('open') end) else diff --git a/modules/game_inventory/inventory.otui b/modules/game_inventory/inventory.otui index cc544d11..39b8e11f 100644 --- a/modules/game_inventory/inventory.otui +++ b/modules/game_inventory/inventory.otui @@ -10,72 +10,82 @@ UIWindow move-policy: free updated InvetoryItem - id: head + // head + id: slot1 anchors.top: parent.top anchors.horizontalCenter: parent.horizontalCenter InvetoryItem - id: armor + // armor + id: slot4 anchors.top: prev.bottom anchors.horizontalCenter: prev.horizontalCenter margin-top: 5 InvetoryItem - id: legs + // legs + id: slot7 anchors.top: prev.bottom anchors.horizontalCenter: prev.horizontalCenter margin-top: 5 InvetoryItem - id: feet + // feet + id: slot8 anchors.top: prev.bottom anchors.horizontalCenter: prev.horizontalCenter margin-top: 5 InvetoryItem - id: necklace + // necklace + id: slot2 anchors.top: parent.top - anchors.right: head.left + anchors.right: slot1.left margin-top: 10 margin-right: 5 InvetoryItem - id: left + // left + id: slot6 anchors.top: prev.bottom anchors.horizontalCenter: prev.horizontalCenter margin-top: 5 InvetoryItem - id: ring + // ring + id: slot9 anchors.top: prev.bottom anchors.horizontalCenter: prev.horizontalCenter margin-top: 5 InvetoryItem - id: backpack + // backpack + id: slot3 anchors.top: parent.top - anchors.left: head.right + anchors.left: slot1.right margin-top: 10 margin-left: 5 InvetoryItem - id: right + // right + id: slot5 anchors.top: prev.bottom anchors.horizontalCenter: prev.horizontalCenter margin-top: 5 InvetoryItem - id: ammo + // ammo + id: slot10 anchors.top: prev.bottom anchors.horizontalCenter: prev.horizontalCenter margin-top: 5 Label id: soul - anchors.top: ring.bottom - anchors.bottom: feet.bottom - anchors.left: ring.left - anchors.right: ring.right + anchors.top: slot9.bottom + anchors.bottom: slot8.bottom + anchors.left: slot9.left + anchors.right: slot9.right margin-top: 5 text-align: center @@ -86,10 +96,10 @@ UIWindow Label id: capacity - anchors.top: ammo.bottom - anchors.bottom: feet.bottom - anchors.left: ammo.left - anchors.right: ammo.right + anchors.top: slot10.bottom + anchors.bottom: slot8.bottom + anchors.left: slot10.left + anchors.right: slot10.right margin-top: 5 text-align: center diff --git a/modules/game_textmessage/textmessage.otui b/modules/game_textmessage/textmessage.otui index f1281196..2b1717ba 100644 --- a/modules/game_textmessage/textmessage.otui +++ b/modules/game_textmessage/textmessage.otui @@ -1,6 +1,6 @@ CenterLabel < Label font: verdana-11px-rounded - height: 16 + height: 64 text-align: center anchors.verticalCenter: parent.verticalCenter anchors.left: parent.left diff --git a/src/otclient/core/game.cpp b/src/otclient/core/game.cpp index 6af322f1..2c97d1ad 100644 --- a/src/otclient/core/game.cpp +++ b/src/otclient/core/game.cpp @@ -156,7 +156,7 @@ void Game::turn(Otc::Direction direction) } } -void Game::look(const Position& position) +void Game::lookAtMap(const Position& position) { Position tilePos = position; TilePtr tile = nullptr; @@ -176,6 +176,12 @@ void Game::look(const Position& position) m_protocolGame->sendLookAt(tilePos, thing->getId(), stackpos); } +void Game::lookAtInventory(int thingId, int slot) +{ + Position pos = Position(0xffff, slot, 0); + m_protocolGame->sendLookAt(pos, thingId, 0); +} + void Game::talkChannel(int channelType, int channelId, const std::string& message) { if(!m_online) diff --git a/src/otclient/core/game.h b/src/otclient/core/game.h index e06ff65c..4906ec47 100644 --- a/src/otclient/core/game.h +++ b/src/otclient/core/game.h @@ -48,7 +48,8 @@ public: void walk(Otc::Direction direction); void turn(Otc::Direction direction); - void look(const Position& position); + void lookAtMap(const Position& position); + void lookAtInventory(int thingId, int slot); void talkChannel(int channelType, int channelId, const std::string& message); void talkPrivate(int channelType, const std::string& receiver, const std::string& message); void openOutfitWindow(); diff --git a/src/otclient/core/map.cpp b/src/otclient/core/map.cpp index 4cac2dc6..1a7ebd66 100644 --- a/src/otclient/core/map.cpp +++ b/src/otclient/core/map.cpp @@ -342,7 +342,7 @@ void Map::addCreature(const CreaturePtr& creature) CreaturePtr Map::getCreatureById(uint32 id) { - if(g_game.getLocalPlayer() && g_game.getLocalPlayer()->getId() == id) + if(g_game.getLocalPlayer() && (uint32)g_game.getLocalPlayer()->getId() == id) return g_game.getLocalPlayer(); return m_creatures[id]; } diff --git a/src/otclient/core/thing.cpp b/src/otclient/core/thing.cpp index e630d2e8..5b694900 100644 --- a/src/otclient/core/thing.cpp +++ b/src/otclient/core/thing.cpp @@ -52,7 +52,7 @@ void Thing::internalDraw(const Point& p, int layer) } } -void Thing::setId(uint32 id) +void Thing::setId(int id) { m_id = id; m_type = getType(); diff --git a/src/otclient/core/thing.h b/src/otclient/core/thing.h index d32bad55..befb8004 100644 --- a/src/otclient/core/thing.h +++ b/src/otclient/core/thing.h @@ -43,10 +43,10 @@ public: virtual void draw(const Point& p) = 0; - void setId(uint32 id); + void setId(int id); virtual void setPosition(const Position& position) { m_position = position; } - uint32 getId() const { return m_id; } + int getId() const { return m_id; } Position getPosition() const { return m_position; } int getStackPriority(); virtual ThingType *getType(); diff --git a/src/otclient/luafunctions.cpp b/src/otclient/luafunctions.cpp index 3deca1ae..4046f467 100644 --- a/src/otclient/luafunctions.cpp +++ b/src/otclient/luafunctions.cpp @@ -35,6 +35,7 @@ void OTClient::registerLuaFunctions() g_lua.registerClass(); g_lua.registerClass(); + g_lua.bindClassMemberFunction("getId", &Thing::getId); g_lua.bindClassMemberFunction("getType", &Thing::getType); g_lua.bindClassMemberFunction("isContainer", &Thing::isContainer); @@ -55,6 +56,7 @@ void OTClient::registerLuaFunctions() g_lua.bindClassStaticFunction("isOnline", std::bind(&Game::isOnline, &g_game)); g_lua.bindClassStaticFunction("openOutfitWindow", std::bind(&Game::openOutfitWindow, &g_game)); g_lua.bindClassStaticFunction("setOutfit", std::bind(&Game::setOutfit, &g_game, _1)); + g_lua.bindClassStaticFunction("lookAtInventory", std::bind(&Game::lookAtInventory, &g_game, _1, _2)); g_lua.registerClass(); g_lua.bindClassStaticFunction("create", &UIItem::create); diff --git a/src/otclient/net/protocolgameparse.cpp b/src/otclient/net/protocolgameparse.cpp index 23fc1449..eb10ff75 100644 --- a/src/otclient/net/protocolgameparse.cpp +++ b/src/otclient/net/protocolgameparse.cpp @@ -1083,7 +1083,7 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg) g_map.removeCreatureById(removeId); - if(id == m_localPlayer->getId()) + if(id == (uint32)m_localPlayer->getId()) creature = m_localPlayer->asCreature(); else if(id >= Otc::PlayerStartId && id < Otc::PlayerEndId) creature = PlayerPtr(new Player)->asCreature(); diff --git a/src/otclient/ui/uimap.cpp b/src/otclient/ui/uimap.cpp index 798441bb..2bdefb6f 100644 --- a/src/otclient/ui/uimap.cpp +++ b/src/otclient/ui/uimap.cpp @@ -92,7 +92,7 @@ bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button) if(button == Fw::MouseLeftButton) { } else if(button == Fw::MouseRightButton) { - g_game.look(tilePos); + //g_game.lookAtMap(tilePos); } return true;