look on items
This commit is contained in:
parent
7c28297397
commit
9fbdf3f5cb
|
@ -131,4 +131,4 @@ KeyboardShiftModifier = 4
|
||||||
MouseNoButton = 0
|
MouseNoButton = 0
|
||||||
MouseLeftButton = 1
|
MouseLeftButton = 1
|
||||||
MouseRightButton = 2
|
MouseRightButton = 2
|
||||||
MouseMidButton = 3
|
MouseMidButton = 3
|
||||||
|
|
|
@ -3,17 +3,6 @@ Inventory = {}
|
||||||
-- private variables
|
-- private variables
|
||||||
local window = nil
|
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
|
-- public functions
|
||||||
function Inventory.create()
|
function Inventory.create()
|
||||||
window = UI.display('inventory.otui', { parent = Game.gameRightPanel })
|
window = UI.display('inventory.otui', { parent = Game.gameRightPanel })
|
||||||
|
@ -26,30 +15,7 @@ end
|
||||||
|
|
||||||
-- hooked events
|
-- hooked events
|
||||||
function Inventory.onInventoryChange(slot, item)
|
function Inventory.onInventoryChange(slot, item)
|
||||||
local slotId
|
local itemWidget = window:getChildById('slot' .. slot)
|
||||||
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)
|
|
||||||
itemWidget:setItem(item)
|
itemWidget:setItem(item)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -64,18 +30,19 @@ function Inventory.onSoulChange(soul)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Inventory.onInventoryItemMousePress(itemWidget, mousePos, mouseButton)
|
function Inventory.onInventoryItemMousePress(itemWidget, mousePos, mouseButton)
|
||||||
if mouseButton ~= MouseRightButton then
|
if mouseButton ~= MouseRightButton then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local item = itemWidget:getItem()
|
local item = itemWidget:getItem()
|
||||||
if not item then
|
if not item then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local menu = UIPopupMenu.create()
|
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
|
if item:isContainer() then
|
||||||
menu:addOption('Open', function() print('open') end)
|
menu:addOption('Open', function() print('open') end)
|
||||||
else
|
else
|
||||||
|
|
|
@ -10,72 +10,82 @@ UIWindow
|
||||||
move-policy: free updated
|
move-policy: free updated
|
||||||
|
|
||||||
InvetoryItem
|
InvetoryItem
|
||||||
id: head
|
// head
|
||||||
|
id: slot1
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
|
||||||
InvetoryItem
|
InvetoryItem
|
||||||
id: armor
|
// armor
|
||||||
|
id: slot4
|
||||||
anchors.top: prev.bottom
|
anchors.top: prev.bottom
|
||||||
anchors.horizontalCenter: prev.horizontalCenter
|
anchors.horizontalCenter: prev.horizontalCenter
|
||||||
margin-top: 5
|
margin-top: 5
|
||||||
|
|
||||||
InvetoryItem
|
InvetoryItem
|
||||||
id: legs
|
// legs
|
||||||
|
id: slot7
|
||||||
anchors.top: prev.bottom
|
anchors.top: prev.bottom
|
||||||
anchors.horizontalCenter: prev.horizontalCenter
|
anchors.horizontalCenter: prev.horizontalCenter
|
||||||
margin-top: 5
|
margin-top: 5
|
||||||
|
|
||||||
InvetoryItem
|
InvetoryItem
|
||||||
id: feet
|
// feet
|
||||||
|
id: slot8
|
||||||
anchors.top: prev.bottom
|
anchors.top: prev.bottom
|
||||||
anchors.horizontalCenter: prev.horizontalCenter
|
anchors.horizontalCenter: prev.horizontalCenter
|
||||||
margin-top: 5
|
margin-top: 5
|
||||||
|
|
||||||
InvetoryItem
|
InvetoryItem
|
||||||
id: necklace
|
// necklace
|
||||||
|
id: slot2
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.right: head.left
|
anchors.right: slot1.left
|
||||||
margin-top: 10
|
margin-top: 10
|
||||||
margin-right: 5
|
margin-right: 5
|
||||||
|
|
||||||
InvetoryItem
|
InvetoryItem
|
||||||
id: left
|
// left
|
||||||
|
id: slot6
|
||||||
anchors.top: prev.bottom
|
anchors.top: prev.bottom
|
||||||
anchors.horizontalCenter: prev.horizontalCenter
|
anchors.horizontalCenter: prev.horizontalCenter
|
||||||
margin-top: 5
|
margin-top: 5
|
||||||
|
|
||||||
InvetoryItem
|
InvetoryItem
|
||||||
id: ring
|
// ring
|
||||||
|
id: slot9
|
||||||
anchors.top: prev.bottom
|
anchors.top: prev.bottom
|
||||||
anchors.horizontalCenter: prev.horizontalCenter
|
anchors.horizontalCenter: prev.horizontalCenter
|
||||||
margin-top: 5
|
margin-top: 5
|
||||||
|
|
||||||
InvetoryItem
|
InvetoryItem
|
||||||
id: backpack
|
// backpack
|
||||||
|
id: slot3
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.left: head.right
|
anchors.left: slot1.right
|
||||||
margin-top: 10
|
margin-top: 10
|
||||||
margin-left: 5
|
margin-left: 5
|
||||||
|
|
||||||
InvetoryItem
|
InvetoryItem
|
||||||
id: right
|
// right
|
||||||
|
id: slot5
|
||||||
anchors.top: prev.bottom
|
anchors.top: prev.bottom
|
||||||
anchors.horizontalCenter: prev.horizontalCenter
|
anchors.horizontalCenter: prev.horizontalCenter
|
||||||
margin-top: 5
|
margin-top: 5
|
||||||
|
|
||||||
InvetoryItem
|
InvetoryItem
|
||||||
id: ammo
|
// ammo
|
||||||
|
id: slot10
|
||||||
anchors.top: prev.bottom
|
anchors.top: prev.bottom
|
||||||
anchors.horizontalCenter: prev.horizontalCenter
|
anchors.horizontalCenter: prev.horizontalCenter
|
||||||
margin-top: 5
|
margin-top: 5
|
||||||
|
|
||||||
Label
|
Label
|
||||||
id: soul
|
id: soul
|
||||||
anchors.top: ring.bottom
|
anchors.top: slot9.bottom
|
||||||
anchors.bottom: feet.bottom
|
anchors.bottom: slot8.bottom
|
||||||
anchors.left: ring.left
|
anchors.left: slot9.left
|
||||||
anchors.right: ring.right
|
anchors.right: slot9.right
|
||||||
margin-top: 5
|
margin-top: 5
|
||||||
|
|
||||||
text-align: center
|
text-align: center
|
||||||
|
@ -86,10 +96,10 @@ UIWindow
|
||||||
|
|
||||||
Label
|
Label
|
||||||
id: capacity
|
id: capacity
|
||||||
anchors.top: ammo.bottom
|
anchors.top: slot10.bottom
|
||||||
anchors.bottom: feet.bottom
|
anchors.bottom: slot8.bottom
|
||||||
anchors.left: ammo.left
|
anchors.left: slot10.left
|
||||||
anchors.right: ammo.right
|
anchors.right: slot10.right
|
||||||
margin-top: 5
|
margin-top: 5
|
||||||
|
|
||||||
text-align: center
|
text-align: center
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
CenterLabel < Label
|
CenterLabel < Label
|
||||||
font: verdana-11px-rounded
|
font: verdana-11px-rounded
|
||||||
height: 16
|
height: 64
|
||||||
text-align: center
|
text-align: center
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
anchors.left: parent.left
|
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;
|
Position tilePos = position;
|
||||||
TilePtr tile = nullptr;
|
TilePtr tile = nullptr;
|
||||||
|
@ -176,6 +176,12 @@ void Game::look(const Position& position)
|
||||||
m_protocolGame->sendLookAt(tilePos, thing->getId(), stackpos);
|
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)
|
void Game::talkChannel(int channelType, int channelId, const std::string& message)
|
||||||
{
|
{
|
||||||
if(!m_online)
|
if(!m_online)
|
||||||
|
|
|
@ -48,7 +48,8 @@ public:
|
||||||
|
|
||||||
void walk(Otc::Direction direction);
|
void walk(Otc::Direction direction);
|
||||||
void turn(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 talkChannel(int channelType, int channelId, const std::string& message);
|
||||||
void talkPrivate(int channelType, const std::string& receiver, const std::string& message);
|
void talkPrivate(int channelType, const std::string& receiver, const std::string& message);
|
||||||
void openOutfitWindow();
|
void openOutfitWindow();
|
||||||
|
|
|
@ -342,7 +342,7 @@ void Map::addCreature(const CreaturePtr& creature)
|
||||||
|
|
||||||
CreaturePtr Map::getCreatureById(uint32 id)
|
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 g_game.getLocalPlayer();
|
||||||
return m_creatures[id];
|
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_id = id;
|
||||||
m_type = getType();
|
m_type = getType();
|
||||||
|
|
|
@ -43,10 +43,10 @@ public:
|
||||||
|
|
||||||
virtual void draw(const Point& p) = 0;
|
virtual void draw(const Point& p) = 0;
|
||||||
|
|
||||||
void setId(uint32 id);
|
void setId(int id);
|
||||||
virtual void setPosition(const Position& position) { m_position = position; }
|
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; }
|
Position getPosition() const { return m_position; }
|
||||||
int getStackPriority();
|
int getStackPriority();
|
||||||
virtual ThingType *getType();
|
virtual ThingType *getType();
|
||||||
|
|
|
@ -35,6 +35,7 @@ void OTClient::registerLuaFunctions()
|
||||||
g_lua.registerClass<ProtocolGame, Protocol>();
|
g_lua.registerClass<ProtocolGame, Protocol>();
|
||||||
|
|
||||||
g_lua.registerClass<Thing>();
|
g_lua.registerClass<Thing>();
|
||||||
|
g_lua.bindClassMemberFunction<Thing>("getId", &Thing::getId);
|
||||||
g_lua.bindClassMemberFunction<Thing>("getType", &Thing::getType);
|
g_lua.bindClassMemberFunction<Thing>("getType", &Thing::getType);
|
||||||
g_lua.bindClassMemberFunction<Thing>("isContainer", &Thing::isContainer);
|
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>("isOnline", std::bind(&Game::isOnline, &g_game));
|
||||||
g_lua.bindClassStaticFunction<Game>("openOutfitWindow", std::bind(&Game::openOutfitWindow, &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>("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.registerClass<UIItem, UIWidget>();
|
||||||
g_lua.bindClassStaticFunction<UIItem>("create", &UIItem::create<UIItem>);
|
g_lua.bindClassStaticFunction<UIItem>("create", &UIItem::create<UIItem>);
|
||||||
|
|
|
@ -1083,7 +1083,7 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg)
|
||||||
|
|
||||||
g_map.removeCreatureById(removeId);
|
g_map.removeCreatureById(removeId);
|
||||||
|
|
||||||
if(id == m_localPlayer->getId())
|
if(id == (uint32)m_localPlayer->getId())
|
||||||
creature = m_localPlayer->asCreature();
|
creature = m_localPlayer->asCreature();
|
||||||
else if(id >= Otc::PlayerStartId && id < Otc::PlayerEndId)
|
else if(id >= Otc::PlayerStartId && id < Otc::PlayerEndId)
|
||||||
creature = PlayerPtr(new Player)->asCreature();
|
creature = PlayerPtr(new Player)->asCreature();
|
||||||
|
|
|
@ -92,7 +92,7 @@ bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button)
|
||||||
if(button == Fw::MouseLeftButton) {
|
if(button == Fw::MouseLeftButton) {
|
||||||
}
|
}
|
||||||
else if(button == Fw::MouseRightButton) {
|
else if(button == Fw::MouseRightButton) {
|
||||||
g_game.look(tilePos);
|
//g_game.lookAtMap(tilePos);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue