look on items
This commit is contained in:
parent
7c28297397
commit
9fbdf3f5cb
|
@ -131,4 +131,4 @@ KeyboardShiftModifier = 4
|
|||
MouseNoButton = 0
|
||||
MouseLeftButton = 1
|
||||
MouseRightButton = 2
|
||||
MouseMidButton = 3
|
||||
MouseMidButton = 3
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -35,6 +35,7 @@ void OTClient::registerLuaFunctions()
|
|||
g_lua.registerClass<ProtocolGame, Protocol>();
|
||||
|
||||
g_lua.registerClass<Thing>();
|
||||
g_lua.bindClassMemberFunction<Thing>("getId", &Thing::getId);
|
||||
g_lua.bindClassMemberFunction<Thing>("getType", &Thing::getType);
|
||||
g_lua.bindClassMemberFunction<Thing>("isContainer", &Thing::isContainer);
|
||||
|
||||
|
@ -55,6 +56,7 @@ void OTClient::registerLuaFunctions()
|
|||
g_lua.bindClassStaticFunction<Game>("isOnline", std::bind(&Game::isOnline, &g_game));
|
||||
g_lua.bindClassStaticFunction<Game>("openOutfitWindow", std::bind(&Game::openOutfitWindow, &g_game));
|
||||
g_lua.bindClassStaticFunction<Game>("setOutfit", std::bind(&Game::setOutfit, &g_game, _1));
|
||||
g_lua.bindClassStaticFunction<Game>("lookAtInventory", std::bind(&Game::lookAtInventory, &g_game, _1, _2));
|
||||
|
||||
g_lua.registerClass<UIItem, UIWidget>();
|
||||
g_lua.bindClassStaticFunction<UIItem>("create", &UIItem::create<UIItem>);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue