thing menu improvements

master
Henrique Santiago 13 years ago
parent 215d426b42
commit 478e55e658

@ -1,47 +1,51 @@
-- public functions -- public functions
function Thing:createMenu(menuPosition) function Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
local menu = createWidget('PopupMenu') local menu = createWidget('PopupMenu')
menu:addOption('Look', function() Game.look(self) end)
if lookThing then
menu:addOption('Look', function() Game.look(lookThing) end)
end
-- Open or Use, depending if thing is a container -- Open or Use, depending if thing is a container
if not self:asCreature() then if useThing then
if self:isContainer() then if useThing:isContainer() then
menu:addOption('Open', function() print('open') end) menu:addOption('Open', function() print('open') end)
else else
if self:isMultiUse() then if useThing:isMultiUse() then
menu:addOption('Use with ...', function() print('use with...') end) menu:addOption('Use with ...', function() print('use with...') end)
else else
menu:addOption('Use', function() Game.use(self) end) menu:addOption('Use', function() Game.use(useThing) end)
end end
end end
if self:isRotateable() then if useThing:isRotateable() then
menu:addOption('Rotate', function() print('rotate') end) menu:addOption('Rotate', function() Game.rotate(useThing) end)
end end
menu:addSeparator() menu:addSeparator()
if not self:isNotMoveable() and self:isPickupable() then if not useThing:isNotMoveable() and useThing:isPickupable() then
menu:addOption('Trade with ...', function() print('trade with') end) menu:addOption('Trade with ...', function() print('trade with') end)
end end
end
else if creatureThing then
menu:addSeparator() menu:addSeparator()
if self:asLocalPlayer() then if creatureThing:asLocalPlayer() then
menu:addOption('Set Outfit', function() Game.openOutfitWindow() end) menu:addOption('Set Outfit', function() Game.openOutfitWindow() end)
else else
-- todo: check for stop attack/follow -- todo: check for stop attack/follow
menu:addOption('Attack', function() print('attack') end) menu:addOption('Attack', function() Game.attack(creatureThing) end)
menu:addOption('Follow', function() print('follow') end) menu:addOption('Follow', function() Game.follow(creatureThing)end)
if self:asPlayer() then if creatureThing:asPlayer() then
menu:addSeparator() menu:addSeparator()
menu:addOption('Message to ' .. self:asCreature():getName(), function() print('message') end) menu:addOption('Message to ' .. creatureThing:getName(), function() print('message') end)
menu:addOption('Add to VIP list', function() print('vip') end) menu:addOption('Add to VIP list', function() print('vip') end)
menu:addOption('Ignore ' .. self:asCreature():getName(), function() print('ignore') end) menu:addOption('Ignore ' .. creatureThing:getName(), function() print('ignore') end)
menu:addOption('Invite to Party', function() print('invite to party') end) menu:addOption('Invite to Party', function() print('invite to party') end)
end end

@ -35,7 +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
item:createMenu(mousePos) Game.createThingMenu(mousePos, item, item, nil)
end end
connect(Game, { onLogin = Inventory.create, connect(Game, { onLogin = Inventory.create,

@ -161,42 +161,60 @@ void Game::turn(Otc::Direction direction)
void Game::look(const ThingPtr& thing) void Game::look(const ThingPtr& thing)
{ {
// thing is at map if(!m_online || !thing)
if(thing->getPos().x != 65535) { return;
Position tilePos = thing->getPos();
TilePtr tile = nullptr; int stackpos = getThingStackpos(thing);
int stackpos = -1; if(stackpos != -1)
m_protocolGame->sendLookAt(thing->getPos(), thing->getId(), stackpos);
while(true) {
tile = g_map.getTile(tilePos);
stackpos = tile->getLookStackpos();
if(stackpos != -1 || tilePos.z >= Map::MAX_Z)
break;
tilePos.coveredDown();
}
ThingPtr lookThing = tile->getThing(stackpos);
if(lookThing)
m_protocolGame->sendLookAt(tilePos, lookThing->getId(), stackpos);
}
// thing is at inventory
else
m_protocolGame->sendLookAt(thing->getPos(), thing->getId(), 0);
} }
void Game::use(const ThingPtr& thing) void Game::use(const ThingPtr& thing)
{
if(!m_online || !thing)
return;
int stackpos = getThingStackpos(thing);
if(stackpos != -1)
m_protocolGame->sendUseItem(thing->getPos(), thing->getId(), stackpos, 0);// last 0 has something to do with container
}
void Game::attack(const CreaturePtr& creature)
{
if(!m_online || !creature)
return;
m_protocolGame->sendAttack(creature->getId());
}
void Game::follow(const CreaturePtr& creature)
{
if(!m_online || !creature)
return;
m_protocolGame->sendFollow(creature->getId());
}
void Game::rotate(const ThingPtr& thing)
{
if(!m_online || !thing)
return;
int stackpos = getThingStackpos(thing);
if(stackpos != -1)
m_protocolGame->sendRotateItem(thing->getPos(), thing->getId(), stackpos);
}
int Game::getThingStackpos(const ThingPtr& thing)
{ {
// thing is at map // thing is at map
if(thing->getPos().x != 65535) { if(thing->getPos().x != 65535) {
TilePtr tile = g_map.getTile(thing->getPos()); TilePtr tile = g_map.getTile(thing->getPos());
int stackpos = tile->getThingStackpos(thing); return tile->getThingStackpos(thing);
if(stackpos != -1)
m_protocolGame->sendUseItem(thing->getPos(), thing->getId(), stackpos, 0);
} }
// thing is at inventory
else // thing is at container or inventory
m_protocolGame->sendUseItem(thing->getPos(), thing->getId(), 0, 0); // last 0 has something to do with container return 0;
} }
void Game::talkChannel(int channelType, int channelId, const std::string& message) void Game::talkChannel(int channelType, int channelId, const std::string& message)

@ -50,10 +50,14 @@ public:
void turn(Otc::Direction direction); void turn(Otc::Direction direction);
void look(const ThingPtr& thing); void look(const ThingPtr& thing);
void use(const ThingPtr& thing); void use(const ThingPtr& thing);
void attack(const CreaturePtr& creature);
void follow(const CreaturePtr& creature);
void rotate(const ThingPtr& thing);
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();
void setOutfit(const Outfit& outfit); void setOutfit(const Outfit& outfit);
int getThingStackpos(const ThingPtr& thing);
bool isOnline() { return m_online; } bool isOnline() { return m_online; }

@ -323,6 +323,9 @@ void Map::removeThing(const ThingPtr& thing)
TilePtr Map::getTile(const Position& pos) TilePtr Map::getTile(const Position& pos)
{ {
if(!pos.isValid())
return nullptr;
TilePtr& tile = m_tiles[pos]; TilePtr& tile = m_tiles[pos];
if(!tile) if(!tile)
tile = TilePtr(new Tile(pos)); tile = TilePtr(new Tile(pos));

@ -78,11 +78,36 @@ ThingType *Thing::getType()
return g_thingsType.getEmptyThingType(); return g_thingsType.getEmptyThingType();
} }
bool Thing::isGround()
{
return m_type->properties[ThingType::IsGround];
}
bool Thing::isGroundBorder()
{
return m_type->properties[ThingType::IsGroundBorder];
}
bool Thing::isOnBottom()
{
return m_type->properties[ThingType::IsOnBottom];
}
bool Thing::isOnTop()
{
return m_type->properties[ThingType::IsOnTop];
}
bool Thing::isContainer() bool Thing::isContainer()
{ {
return m_type->properties[ThingType::IsContainer]; return m_type->properties[ThingType::IsContainer];
} }
bool Thing::isForceUse()
{
return m_type->properties[ThingType::IsForceUse];
}
bool Thing::isMultiUse() bool Thing::isMultiUse()
{ {
return m_type->properties[ThingType::IsMultiUse]; return m_type->properties[ThingType::IsMultiUse];
@ -102,3 +127,8 @@ bool Thing::isPickupable()
{ {
return m_type->properties[ThingType::IsPickupable]; return m_type->properties[ThingType::IsPickupable];
} }
bool Thing::ignoreLook()
{
return m_type->properties[ThingType::IgnoreLook];
}

@ -66,11 +66,17 @@ public:
virtual AnimatedTextPtr asAnimatedText() { return nullptr; } virtual AnimatedTextPtr asAnimatedText() { return nullptr; }
virtual StaticTextPtr asStaticText() { return nullptr; } virtual StaticTextPtr asStaticText() { return nullptr; }
bool isGround();
bool isGroundBorder();
bool isOnBottom();
bool isOnTop();
bool isContainer(); bool isContainer();
bool isForceUse();
bool isMultiUse(); bool isMultiUse();
bool isRotateable(); bool isRotateable();
bool isNotMoveable(); bool isNotMoveable();
bool isPickupable(); bool isPickupable();
bool ignoreLook();
protected: protected:
void internalDraw(const Point& p, int layer); void internalDraw(const Point& p, int layer);

@ -197,15 +197,57 @@ ItemPtr Tile::getGround()
return nullptr; return nullptr;
} }
int Tile::getLookStackpos() ThingPtr Tile::getTopLookThing()
{ {
ThingPtr retThing;
// check if there is any lookable object in this tile
for(int i = m_things.size() - 1; i >= 0; --i) { for(int i = m_things.size() - 1; i >= 0; --i) {
ThingType *type = m_things[i]->getType(); ThingPtr thing = m_things[i];
if(!type->properties[ThingType::IgnoreLook] && if(!thing->ignoreLook() && (!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop()))
(type->properties[ThingType::IsGround] || type->properties[ThingType::IsGroundBorder] || type->properties[ThingType::IsOnBottom] || type->properties[ThingType::IsOnTop])) return thing;
return i; else if(!thing->ignoreLook())
retThing = thing;
} }
return -1;
// return this, it it is lookable.
if(retThing)
return retThing;
// if not, check on under tile
Position tilePos = m_position;
tilePos.coveredDown();
TilePtr tile = g_map.getTile(tilePos);
if(tile)
return tile->getTopLookThing();
return nullptr;
}
ThingPtr Tile::getTopUseThing()
{
if(isEmpty())
return nullptr;
for(int i = m_things.size() - 1; i >= 0; --i) {
ThingPtr thing = m_things[i];
if(thing->isForceUse() || (!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop()))
return thing;
}
return m_things[0];
}
CreaturePtr Tile::getTopCreature()
{
CreaturePtr creature;
for(int i = m_things.size() - 1; i >= 0; --i) {
ThingPtr thing = m_things[i];
if(thing->asLocalPlayer()) // return local player if there aint no other creature.
creature = thing->asCreature();
else if(thing->asCreature() && !thing->asLocalPlayer())
return thing->asCreature();
}
return creature;
} }
bool Tile::isWalkable() bool Tile::isWalkable()

@ -44,11 +44,15 @@ public:
ThingPtr removeThing(int stackPos); ThingPtr removeThing(int stackPos);
ThingPtr removeThing(const ThingPtr& thing); ThingPtr removeThing(const ThingPtr& thing);
ThingPtr getTopLookThing();
ThingPtr getTopUseThing();
CreaturePtr getTopCreature();
const Position& getPos() { return m_position; } const Position& getPos() { return m_position; }
int getDrawElevation() { return m_drawElevation; } int getDrawElevation() { return m_drawElevation; }
std::vector<CreaturePtr> getCreatures(); std::vector<CreaturePtr> getCreatures();
ItemPtr getGround(); ItemPtr getGround();
int getLookStackpos();
bool isWalkable(); bool isWalkable();
bool isFullGround(); bool isFullGround();
bool isFullyOpaque(); bool isFullyOpaque();

@ -66,6 +66,9 @@ void OTClient::registerLuaFunctions()
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>("look", std::bind(&Game::look, &g_game, _1)); g_lua.bindClassStaticFunction<Game>("look", std::bind(&Game::look, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("use", std::bind(&Game::use, &g_game, _1)); g_lua.bindClassStaticFunction<Game>("use", std::bind(&Game::use, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("attack", std::bind(&Game::attack, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("follow", std::bind(&Game::follow, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("rotate", std::bind(&Game::rotate, &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>);

@ -79,7 +79,7 @@ bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button)
tilePos.perspectiveUp(tilePos.z - firstFloor); tilePos.perspectiveUp(tilePos.z - firstFloor);
for(int i = firstFloor; i <= Map::MAX_Z; i++) { for(int i = firstFloor; i <= Map::MAX_Z; i++) {
tile = g_map.getTile(tilePos); tile = g_map.getTile(tilePos);
if(!tile->isEmpty()) if(!tile || !tile->isEmpty())
break; break;
tilePos.coveredDown(); tilePos.coveredDown();
} }
@ -87,14 +87,12 @@ bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button)
if(!tile || tile->isEmpty()) if(!tile || tile->isEmpty())
return true; return true;
//tile->useItem();
if(button == Fw::MouseLeftButton) { if(button == Fw::MouseLeftButton) {
g_game.look(tile->getThing(0)); g_game.look(tile->getTopLookThing());
} }
else if(button == Fw::MouseRightButton) { else if(button == Fw::MouseRightButton) {
g_lua.callGlobalField("Thing","createMenu", tile->getTopThing(), mousePos); g_lua.callGlobalField("Game","createThingMenu", mousePos, tile->getTopLookThing(), tile->getTopUseThing(), tile->getTopCreature());
} }
return true; return true;

Loading…
Cancel
Save