restore set outfit
This commit is contained in:
parent
26800dfe2a
commit
01a2e3a636
|
@ -15,4 +15,5 @@ Module
|
|||
|
||||
onLoad: |
|
||||
require 'game'
|
||||
return true
|
||||
require 'thing'
|
||||
return true
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
-- public functions
|
||||
function Thing:createMenu(menuPosition)
|
||||
local menu = createWidget('PopupMenu')
|
||||
menu:addOption('Look', function() Game.look(self) end)
|
||||
|
||||
-- Open or Use, depending if thing is a container
|
||||
if self:isContainer() then
|
||||
menu:addOption('Open', function() print('open') end)
|
||||
else
|
||||
menu:addOption('Use', function() print('use') end)
|
||||
end
|
||||
|
||||
if self:asLocalPlayer() then
|
||||
menu:addOption('Set Outfit', function() Game.openOutfitWindow() end)
|
||||
end
|
||||
|
||||
menu:display(menuPosition)
|
||||
end
|
|
@ -35,20 +35,7 @@ function Inventory.onInventoryItemMousePress(itemWidget, mousePos, mouseButton)
|
|||
local item = itemWidget:getItem()
|
||||
if not item then return end
|
||||
|
||||
local menu = createWidget('PopupMenu')
|
||||
|
||||
-- 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
|
||||
menu:addOption('Use', function() print('use') end)
|
||||
end
|
||||
menu:display(mousePos)
|
||||
item:createMenu(mousePos)
|
||||
end
|
||||
|
||||
connect(Game, { onLogin = Inventory.create,
|
||||
|
|
|
@ -97,6 +97,9 @@ void Game::processTextMessage(int type, const std::string& message)
|
|||
|
||||
void Game::processInventoryChange(int slot, const ItemPtr& item)
|
||||
{
|
||||
if(item)
|
||||
item->setPosition(Position(65535, slot, 0));
|
||||
|
||||
g_lua.callGlobalField("Game","onInventoryChange", slot, item);
|
||||
}
|
||||
|
||||
|
@ -156,30 +159,30 @@ void Game::turn(Otc::Direction direction)
|
|||
}
|
||||
}
|
||||
|
||||
void Game::lookAtMap(const Position& position)
|
||||
void Game::look(const ThingPtr& thing)
|
||||
{
|
||||
Position tilePos = position;
|
||||
TilePtr tile = nullptr;
|
||||
int stackpos = -1;
|
||||
// thing is at map
|
||||
if(thing->getPosition().x != 65535) {
|
||||
Position tilePos = thing->getPosition();
|
||||
TilePtr tile = nullptr;
|
||||
int stackpos = -1;
|
||||
|
||||
while(true) {
|
||||
tile = g_map.getTile(tilePos);
|
||||
stackpos = tile->getLookStackpos();
|
||||
if(stackpos != -1 || tilePos.z >= Map::MAX_Z)
|
||||
break;
|
||||
while(true) {
|
||||
tile = g_map.getTile(tilePos);
|
||||
stackpos = tile->getLookStackpos();
|
||||
if(stackpos != -1 || tilePos.z >= Map::MAX_Z)
|
||||
break;
|
||||
|
||||
tilePos.coveredDown();
|
||||
tilePos.coveredDown();
|
||||
}
|
||||
|
||||
ThingPtr lookThing = tile->getThing(stackpos);
|
||||
if(lookThing)
|
||||
m_protocolGame->sendLookAt(tilePos, lookThing->getId(), stackpos);
|
||||
}
|
||||
|
||||
ThingPtr thing = tile->getThing(stackpos);
|
||||
if(thing)
|
||||
m_protocolGame->sendLookAt(tilePos, thing->getId(), stackpos);
|
||||
}
|
||||
|
||||
void Game::lookAtInventory(int thingId, Otc::InventorySlots slot)
|
||||
{
|
||||
Position pos = Position(0xffff, slot, 0);
|
||||
m_protocolGame->sendLookAt(pos, thingId, 0);
|
||||
// thing is at inventory
|
||||
else
|
||||
m_protocolGame->sendLookAt(thing->getPosition(), thing->getId(), 0);
|
||||
}
|
||||
|
||||
void Game::talkChannel(int channelType, int channelId, const std::string& message)
|
||||
|
|
|
@ -48,8 +48,7 @@ public:
|
|||
|
||||
void walk(Otc::Direction direction);
|
||||
void turn(Otc::Direction direction);
|
||||
void lookAtMap(const Position& position);
|
||||
void lookAtInventory(int thingId, Otc::InventorySlots slot);
|
||||
void look(const ThingPtr& thing);
|
||||
void talkChannel(int channelType, int channelId, const std::string& message);
|
||||
void talkPrivate(int channelType, const std::string& receiver, const std::string& message);
|
||||
void openOutfitWindow();
|
||||
|
|
|
@ -133,6 +133,14 @@ ThingPtr Tile::getThing(int stackPos)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
ThingPtr Tile::getTopThing()
|
||||
{
|
||||
if(isEmpty())
|
||||
return nullptr;
|
||||
|
||||
return m_things[m_things.size() - 1];
|
||||
}
|
||||
|
||||
ThingPtr Tile::removeThing(int stackPos)
|
||||
{
|
||||
ThingPtr oldObject;
|
||||
|
|
|
@ -39,6 +39,7 @@ public:
|
|||
|
||||
ThingPtr addThing(const ThingPtr& thing, int stackPos = -1);
|
||||
ThingPtr getThing(int stackPos);
|
||||
ThingPtr getTopThing();
|
||||
ThingPtr removeThing(int stackPos);
|
||||
ThingPtr removeThing(const ThingPtr& thing);
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ void OTClient::registerLuaFunctions()
|
|||
g_lua.bindClassMemberFunction<Thing>("getId", &Thing::getId);
|
||||
g_lua.bindClassMemberFunction<Thing>("getType", &Thing::getType);
|
||||
g_lua.bindClassMemberFunction<Thing>("isContainer", &Thing::isContainer);
|
||||
g_lua.bindClassMemberFunction<Thing>("asLocalPlayer", &Thing::asLocalPlayer);
|
||||
|
||||
g_lua.registerClass<Creature, Thing>();
|
||||
g_lua.bindClassMemberFunction("setOutfit", &Creature::setOutfit);
|
||||
|
@ -56,7 +57,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.bindClassStaticFunction<Game>("look", std::bind(&Game::look, &g_game, _1));
|
||||
|
||||
g_lua.registerClass<UIItem, UIWidget>();
|
||||
g_lua.bindClassStaticFunction<UIItem>("create", &UIItem::create<UIItem>);
|
||||
|
|
|
@ -90,9 +90,11 @@ bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button)
|
|||
//tile->useItem();
|
||||
|
||||
if(button == Fw::MouseLeftButton) {
|
||||
g_game.look(tile->getThing(0));
|
||||
}
|
||||
else if(button == Fw::MouseRightButton) {
|
||||
//g_game.lookAtMap(tilePos);
|
||||
|
||||
g_lua.callGlobalField("Thing","createMenu", tile->getTopThing(), mousePos);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue