menu working, still need to fix size and add events
This commit is contained in:
parent
01a2e3a636
commit
7c4191b1e6
|
@ -5,14 +5,51 @@ function Thing:createMenu(menuPosition)
|
|||
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)
|
||||
if not self:asCreature() then
|
||||
if self:isContainer() then
|
||||
menu:addOption('Open', function() print('open') end)
|
||||
else
|
||||
if self:isMultiUse() then
|
||||
menu:addOption('Use with ...', function() print('use with...') end)
|
||||
else
|
||||
menu:addOption('Use', function() Game.use(self) end)
|
||||
end
|
||||
end
|
||||
|
||||
if self:isRotateable() then
|
||||
menu:addOption('Rotate', function() print('rotate') end)
|
||||
end
|
||||
|
||||
menu:addSeparator()
|
||||
|
||||
if not self:isNotMoveable() and self:isPickupable() then
|
||||
menu:addOption('Trade with ...', function() print('trade with') end)
|
||||
end
|
||||
|
||||
else
|
||||
menu:addOption('Use', function() print('use') end)
|
||||
end
|
||||
|
||||
if self:asLocalPlayer() then
|
||||
menu:addOption('Set Outfit', function() Game.openOutfitWindow() end)
|
||||
menu:addSeparator()
|
||||
|
||||
if self:asLocalPlayer() then
|
||||
menu:addOption('Set Outfit', function() Game.openOutfitWindow() end)
|
||||
else
|
||||
-- todo: check for stop attack/follow
|
||||
menu:addOption('Attack', function() print('attack') end)
|
||||
menu:addOption('Follow', function() print('follow') end)
|
||||
|
||||
if self:asPlayer() then
|
||||
menu:addSeparator()
|
||||
menu:addOption('Message to ' .. self:asCreature():getName(), function() print('message') end)
|
||||
menu:addOption('Add to VIP list', function() print('vip') end)
|
||||
menu:addOption('Ignore ' .. self:asCreature():getName(), function() print('ignore') end)
|
||||
menu:addOption('Invite to Party', function() print('invite to party') end)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
menu:addSeparator()
|
||||
menu:addOption('Copy Name', function() print('copy name') end)
|
||||
|
||||
end
|
||||
|
||||
menu:display(menuPosition)
|
||||
|
|
|
@ -185,6 +185,20 @@ void Game::look(const ThingPtr& thing)
|
|||
m_protocolGame->sendLookAt(thing->getPosition(), thing->getId(), 0);
|
||||
}
|
||||
|
||||
void Game::use(const ThingPtr& thing)
|
||||
{
|
||||
// thing is at map
|
||||
if(thing->getPosition().x != 65535) {
|
||||
TilePtr tile = g_map.getTile(thing->getPosition());
|
||||
int stackpos = tile->getThingStackpos(thing);
|
||||
if(stackpos != -1)
|
||||
m_protocolGame->sendUseItem(thing->getPosition(), thing->getId(), stackpos, 0);
|
||||
}
|
||||
// thing is at inventory
|
||||
else
|
||||
m_protocolGame->sendUseItem(thing->getPosition(), thing->getId(), 0, 0); // last 0 has something to do with container
|
||||
}
|
||||
|
||||
void Game::talkChannel(int channelType, int channelId, const std::string& message)
|
||||
{
|
||||
if(!m_online)
|
||||
|
|
|
@ -49,6 +49,7 @@ public:
|
|||
void walk(Otc::Direction direction);
|
||||
void turn(Otc::Direction direction);
|
||||
void look(const ThingPtr& thing);
|
||||
void use(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();
|
||||
|
|
|
@ -82,3 +82,23 @@ bool Thing::isContainer()
|
|||
{
|
||||
return m_type->properties[ThingType::IsContainer];
|
||||
}
|
||||
|
||||
bool Thing::isMultiUse()
|
||||
{
|
||||
return m_type->properties[ThingType::IsMultiUse];
|
||||
}
|
||||
|
||||
bool Thing::isRotateable()
|
||||
{
|
||||
return m_type->properties[ThingType::IsRotateable];
|
||||
}
|
||||
|
||||
bool Thing::isNotMoveable()
|
||||
{
|
||||
return m_type->properties[ThingType::IsNotMovable];
|
||||
}
|
||||
|
||||
bool Thing::isPickupable()
|
||||
{
|
||||
return m_type->properties[ThingType::IsPickupable];
|
||||
}
|
||||
|
|
|
@ -67,6 +67,10 @@ public:
|
|||
virtual StaticTextPtr asStaticText() { return nullptr; }
|
||||
|
||||
bool isContainer();
|
||||
bool isMultiUse();
|
||||
bool isRotateable();
|
||||
bool isNotMoveable();
|
||||
bool isPickupable();
|
||||
|
||||
protected:
|
||||
void internalDraw(const Point& p, int layer);
|
||||
|
|
|
@ -62,14 +62,14 @@ struct ThingType
|
|||
IsFluidContainer,
|
||||
IsFluid,
|
||||
NotWalkable,
|
||||
NotMovable,
|
||||
IsNotMovable,
|
||||
BlockProjectile,
|
||||
NotPathable,
|
||||
Pickupable,
|
||||
IsPickupable,
|
||||
IsHangable,
|
||||
HookSouth,
|
||||
HookEast,
|
||||
IsRotable,
|
||||
IsRotateable,
|
||||
HasLight,
|
||||
DontHide,
|
||||
IsTranslucent,
|
||||
|
|
|
@ -133,6 +133,14 @@ ThingPtr Tile::getThing(int stackPos)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
int Tile::getThingStackpos(const ThingPtr& thing)
|
||||
{
|
||||
for(uint stackpos = 0; stackpos < m_things.size(); ++stackpos)
|
||||
if(thing == m_things[stackpos])
|
||||
return stackpos;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ThingPtr Tile::getTopThing()
|
||||
{
|
||||
if(isEmpty())
|
||||
|
@ -262,83 +270,3 @@ bool Tile::isEmpty()
|
|||
{
|
||||
return m_things.size() == 0;
|
||||
}
|
||||
|
||||
/*bool Tile::canAttack()
|
||||
{
|
||||
return hasCreature();
|
||||
}
|
||||
|
||||
bool Tile::canFollow()
|
||||
{
|
||||
return hasCreature();
|
||||
}
|
||||
|
||||
bool Tile::canCopyName()
|
||||
{
|
||||
return hasCreature();
|
||||
}*/
|
||||
|
||||
// TODO:
|
||||
/*
|
||||
|
||||
Get menu options
|
||||
|
||||
|
||||
if creature:
|
||||
Look
|
||||
-----
|
||||
Attack
|
||||
Follow
|
||||
-----
|
||||
Copy Name
|
||||
|
||||
if item:
|
||||
Look
|
||||
Use (if not container)
|
||||
Open (if container)
|
||||
Use with ... (if multiuse?)
|
||||
Rotate (if rotable)
|
||||
-----
|
||||
Trade with ... (if pickupable?)
|
||||
|
||||
if player:
|
||||
Look
|
||||
-----
|
||||
Attack
|
||||
Follow
|
||||
-----
|
||||
Message to NAME
|
||||
Add to VIP list
|
||||
Ignore NAME
|
||||
Invite to Party
|
||||
-----
|
||||
Report Offense
|
||||
-----
|
||||
Copy Name
|
||||
|
||||
if localplayer:
|
||||
Look
|
||||
-----
|
||||
Set Outfit
|
||||
-----
|
||||
Copy Name
|
||||
*/
|
||||
|
||||
void Tile::useItem()
|
||||
{
|
||||
// Get top item of stack priority 2 (do a function to do this later)
|
||||
ThingPtr thing;
|
||||
int lastStackpos = -1;
|
||||
for(int stackPos = 0; stackPos < (int)m_things.size(); ++stackPos) {
|
||||
int otherPriority = m_things[stackPos]->getStackPriority();
|
||||
if(otherPriority == 2) {
|
||||
thing = m_things[stackPos];
|
||||
lastStackpos = stackPos;
|
||||
}
|
||||
}
|
||||
|
||||
if(lastStackpos != -1) {
|
||||
// use this
|
||||
g_game.getProtocolGame()->sendUseItem(m_position, thing->getId(), lastStackpos, 0); // 0 has something to do with container
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ public:
|
|||
|
||||
ThingPtr addThing(const ThingPtr& thing, int stackPos = -1);
|
||||
ThingPtr getThing(int stackPos);
|
||||
int getThingStackpos(const ThingPtr& thing);
|
||||
ThingPtr getTopThing();
|
||||
ThingPtr removeThing(int stackPos);
|
||||
ThingPtr removeThing(const ThingPtr& thing);
|
||||
|
|
|
@ -38,9 +38,16 @@ 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>("isMultiUse", &Thing::isMultiUse);
|
||||
g_lua.bindClassMemberFunction<Thing>("isRotateable", &Thing::isRotateable);
|
||||
g_lua.bindClassMemberFunction<Thing>("isNotMoveable", &Thing::isNotMoveable);
|
||||
g_lua.bindClassMemberFunction<Thing>("isPickupable", &Thing::isPickupable);
|
||||
g_lua.bindClassMemberFunction<Thing>("asCreature", &Thing::asCreature);
|
||||
g_lua.bindClassMemberFunction<Thing>("asPlayer", &Thing::asPlayer);
|
||||
g_lua.bindClassMemberFunction<Thing>("asLocalPlayer", &Thing::asLocalPlayer);
|
||||
|
||||
g_lua.registerClass<Creature, Thing>();
|
||||
g_lua.bindClassMemberFunction("getName", &Creature::getName);
|
||||
g_lua.bindClassMemberFunction("setOutfit", &Creature::setOutfit);
|
||||
g_lua.bindClassMemberFunction("getOutfit", &Creature::getOutfit);
|
||||
|
||||
|
@ -58,6 +65,7 @@ void OTClient::registerLuaFunctions()
|
|||
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>("look", std::bind(&Game::look, &g_game, _1));
|
||||
g_lua.bindClassStaticFunction<Game>("use", std::bind(&Game::use, &g_game, _1));
|
||||
|
||||
g_lua.registerClass<UIItem, UIWidget>();
|
||||
g_lua.bindClassStaticFunction<UIItem>("create", &UIItem::create<UIItem>);
|
||||
|
|
Loading…
Reference in New Issue