restore set outfit

This commit is contained in:
Henrique Santiago 2012-01-03 18:41:00 -02:00
parent 26800dfe2a
commit 01a2e3a636
9 changed files with 60 additions and 39 deletions

View File

@ -15,4 +15,5 @@ Module
onLoad: | onLoad: |
require 'game' require 'game'
return true require 'thing'
return true

19
modules/game/thing.lua Normal file
View File

@ -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

View File

@ -35,20 +35,7 @@ function Inventory.onInventoryItemMousePress(itemWidget, mousePos, mouseButton)
local item = itemWidget:getItem() local item = itemWidget:getItem()
if not item then return end if not item then return end
local menu = createWidget('PopupMenu') item:createMenu(mousePos)
-- 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)
end end
connect(Game, { onLogin = Inventory.create, connect(Game, { onLogin = Inventory.create,

View File

@ -97,6 +97,9 @@ void Game::processTextMessage(int type, const std::string& message)
void Game::processInventoryChange(int slot, const ItemPtr& item) void Game::processInventoryChange(int slot, const ItemPtr& item)
{ {
if(item)
item->setPosition(Position(65535, slot, 0));
g_lua.callGlobalField("Game","onInventoryChange", slot, item); 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; // thing is at map
TilePtr tile = nullptr; if(thing->getPosition().x != 65535) {
int stackpos = -1; Position tilePos = thing->getPosition();
TilePtr tile = nullptr;
int stackpos = -1;
while(true) { while(true) {
tile = g_map.getTile(tilePos); tile = g_map.getTile(tilePos);
stackpos = tile->getLookStackpos(); stackpos = tile->getLookStackpos();
if(stackpos != -1 || tilePos.z >= Map::MAX_Z) if(stackpos != -1 || tilePos.z >= Map::MAX_Z)
break; break;
tilePos.coveredDown(); tilePos.coveredDown();
}
ThingPtr lookThing = tile->getThing(stackpos);
if(lookThing)
m_protocolGame->sendLookAt(tilePos, lookThing->getId(), stackpos);
} }
// thing is at inventory
ThingPtr thing = tile->getThing(stackpos); else
if(thing) m_protocolGame->sendLookAt(thing->getPosition(), thing->getId(), 0);
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);
} }
void Game::talkChannel(int channelType, int channelId, const std::string& message) void Game::talkChannel(int channelType, int channelId, const std::string& message)

View File

@ -48,8 +48,7 @@ public:
void walk(Otc::Direction direction); void walk(Otc::Direction direction);
void turn(Otc::Direction direction); void turn(Otc::Direction direction);
void lookAtMap(const Position& position); void look(const ThingPtr& thing);
void lookAtInventory(int thingId, Otc::InventorySlots 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();

View File

@ -133,6 +133,14 @@ ThingPtr Tile::getThing(int stackPos)
return nullptr; return nullptr;
} }
ThingPtr Tile::getTopThing()
{
if(isEmpty())
return nullptr;
return m_things[m_things.size() - 1];
}
ThingPtr Tile::removeThing(int stackPos) ThingPtr Tile::removeThing(int stackPos)
{ {
ThingPtr oldObject; ThingPtr oldObject;

View File

@ -39,6 +39,7 @@ public:
ThingPtr addThing(const ThingPtr& thing, int stackPos = -1); ThingPtr addThing(const ThingPtr& thing, int stackPos = -1);
ThingPtr getThing(int stackPos); ThingPtr getThing(int stackPos);
ThingPtr getTopThing();
ThingPtr removeThing(int stackPos); ThingPtr removeThing(int stackPos);
ThingPtr removeThing(const ThingPtr& thing); ThingPtr removeThing(const ThingPtr& thing);

View File

@ -38,6 +38,7 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassMemberFunction<Thing>("getId", &Thing::getId); 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);
g_lua.bindClassMemberFunction<Thing>("asLocalPlayer", &Thing::asLocalPlayer);
g_lua.registerClass<Creature, Thing>(); g_lua.registerClass<Creature, Thing>();
g_lua.bindClassMemberFunction("setOutfit", &Creature::setOutfit); 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>("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.bindClassStaticFunction<Game>("look", std::bind(&Game::look, &g_game, _1));
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>);

View File

@ -90,9 +90,11 @@ bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button)
//tile->useItem(); //tile->useItem();
if(button == Fw::MouseLeftButton) { if(button == Fw::MouseLeftButton) {
g_game.look(tile->getThing(0));
} }
else if(button == Fw::MouseRightButton) { else if(button == Fw::MouseRightButton) {
//g_game.lookAtMap(tilePos);
g_lua.callGlobalField("Thing","createMenu", tile->getTopThing(), mousePos);
} }
return true; return true;