menu open or use for backpacks

This commit is contained in:
Henrique Santiago 2012-01-02 21:08:04 -02:00
parent 7fc4ebd89e
commit 7c28297397
4 changed files with 28 additions and 4 deletions

View File

@ -64,9 +64,24 @@ function Inventory.onSoulChange(soul)
end
function Inventory.onInventoryItemMousePress(itemWidget, mousePos, mouseButton)
if mouseButton ~= MouseRightButton then
return
end
local item = itemWidget:getItem()
if not item then
return
end
local menu = UIPopupMenu.create()
menu:addOption('Look', function() print('look') end)
menu:addOption('Use', function() print('use') end)
if item:isContainer() then
menu:addOption('Open', function() print('open') end)
else
menu:addOption('Use', function() print('use') end)
end
menu:display(mousePos)
end

View File

@ -31,7 +31,7 @@ Thing::Thing() : m_id(0)
m_yPattern = 0;
m_zPattern = 0;
m_animation = 0;
m_type = g_thingsType.getEmptyThingType();
m_type = getType();
}
void Thing::internalDraw(const Point& p, int layer)
@ -77,3 +77,8 @@ ThingType *Thing::getType()
{
return g_thingsType.getEmptyThingType();
}
bool Thing::isContainer()
{
return m_type->properties[ThingType::IsContainer];
}

View File

@ -66,6 +66,8 @@ public:
virtual AnimatedTextPtr asAnimatedText() { return nullptr; }
virtual StaticTextPtr asStaticText() { return nullptr; }
bool isContainer();
protected:
void internalDraw(const Point& p, int layer);

View File

@ -35,14 +35,16 @@ void OTClient::registerLuaFunctions()
g_lua.registerClass<ProtocolGame, Protocol>();
g_lua.registerClass<Thing>();
g_lua.bindClassMemberFunction<Thing>("getType", &Thing::getType);
g_lua.bindClassMemberFunction<Thing>("isContainer", &Thing::isContainer);
g_lua.registerClass<Creature>();
g_lua.registerClass<Creature, Thing>();
g_lua.bindClassMemberFunction("setOutfit", &Creature::setOutfit);
g_lua.bindClassMemberFunction("getOutfit", &Creature::getOutfit);
g_lua.registerClass<Player, Creature>();
g_lua.registerClass<LocalPlayer, Player>();
g_lua.registerClass<Item>();
g_lua.registerClass<Item, Thing>();
g_lua.registerClass<Tile>();
g_lua.registerClass<Map>();