addremove vip and look improvements

This commit is contained in:
Henrique Santiago 2012-01-04 12:30:28 -02:00
parent f16318e80a
commit a73908fbbe
11 changed files with 66 additions and 9 deletions

View File

@ -44,7 +44,7 @@ function Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
if creatureThing:asPlayer() then if creatureThing:asPlayer() then
menu:addSeparator() menu:addSeparator()
menu:addOption('Message to ' .. creatureThing: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() Game.addVip(creatureThing:getName()) end)
menu:addOption('Ignore ' .. creatureThing: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

View File

@ -43,5 +43,16 @@ function Game.onVipStateChange(id, online)
label.vipOnline = online label.vipOnline = online
end end
function VipList.onVipListLabelMousePress(widget, mousePos, mouseButton)
if mouseButton ~= MouseRightButton then return end
local vipList = vipWindow:getChildById('vipList')
local menu = createWidget('PopupMenu')
menu:addOption('Remove from VIP list', function() if widget then Game.removeVip(widget:getId():sub(4)) vipList:removeChild(widget) end end)
menu:display(mousePos)
end
connect(Game, { onLogin = VipList.create, connect(Game, { onLogin = VipList.create,
onLogout = VipList.destroy }) onLogout = VipList.destroy })

View File

@ -1,6 +1,7 @@
VipListLabel < GameLabel VipListLabel < GameLabel
font: verdana-11px-monochrome font: verdana-11px-monochrome
margin-left: 5 margin-left: 5
&onMousePress: VipList.onVipListLabelMousePress
MiniWindow MiniWindow
id: vipWindow id: vipWindow

View File

@ -235,10 +235,32 @@ void Game::talkPrivate(int channelType, const std::string& receiver, const std::
void Game::openOutfitWindow() void Game::openOutfitWindow()
{ {
if(!m_online)
return;
m_protocolGame->sendGetOutfit(); m_protocolGame->sendGetOutfit();
} }
void Game::setOutfit(const Outfit& outfit) void Game::setOutfit(const Outfit& outfit)
{ {
if(!m_online)
return;
m_protocolGame->sendSetOutfit(outfit); m_protocolGame->sendSetOutfit(outfit);
} }
void Game::addVip(const std::string& name)
{
if(!m_online || name.empty())
return;
m_protocolGame->sendAddVip(name);
}
void Game::removeVip(int playerId)
{
if(!m_online)
return;
m_protocolGame->sendRemoveVip(playerId);
}

View File

@ -57,6 +57,8 @@ public:
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);
void addVip(const std::string& name);
void removeVip(int playerId);
int getThingStackpos(const ThingPtr& thing); int getThingStackpos(const ThingPtr& thing);
bool isOnline() { return m_online; } bool isOnline() { return m_online; }

View File

@ -288,6 +288,24 @@ bool Tile::isLookPossible()
return true; return true;
} }
bool Tile::isClickable()
{
bool hasGround = false, hasOnBottom = false, hasIgnoreLook = false;
for(const ThingPtr& thing : m_things) {
ThingType *type = thing->getType();
if(type->properties[ThingType::IsGround])
hasGround = true;
if(type->properties[ThingType::IsOnBottom])
hasOnBottom = true;
if(type->properties[ThingType::IgnoreLook])
hasIgnoreLook = true;
if((hasGround || hasOnBottom) && !hasIgnoreLook)
return true;
}
return false;
}
bool Tile::hasCreature() bool Tile::hasCreature()
{ {
for(const ThingPtr& thing : m_things) for(const ThingPtr& thing : m_things)

View File

@ -59,8 +59,7 @@ public:
bool isLookPossible(); bool isLookPossible();
bool hasCreature(); bool hasCreature();
bool isEmpty(); bool isEmpty();
bool isClickable();
void useItem();
TilePtr asTile() { return std::static_pointer_cast<Tile>(shared_from_this()); } TilePtr asTile() { return std::static_pointer_cast<Tile>(shared_from_this()); }

View File

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

@ -96,7 +96,7 @@ public:
void sendGetOutfit(); void sendGetOutfit();
void sendSetOutfit(const Outfit& outfit); void sendSetOutfit(const Outfit& outfit);
void sendAddVip(const std::string& name); void sendAddVip(const std::string& name);
void sendRemoveVip(int id); void sendRemoveVip(int playerId);
void sendGetQuestLog(); void sendGetQuestLog();
void sendGetQuestLine(int questId); void sendGetQuestLine(int questId);

View File

@ -555,11 +555,11 @@ void ProtocolGame::sendAddVip(const std::string& name)
send(oMsg); send(oMsg);
} }
void ProtocolGame::sendRemoveVip(int id) void ProtocolGame::sendRemoveVip(int playerId)
{ {
OutputMessage oMsg; OutputMessage oMsg;
oMsg.addU8(Otc::ClientRemoveBuddy); oMsg.addU8(Otc::ClientRemoveBuddy);
oMsg.addU32(id); oMsg.addU32(playerId);
send(oMsg); send(oMsg);
} }

View File

@ -74,17 +74,19 @@ bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button)
// Get tile // Get tile
TilePtr tile = nullptr; TilePtr tile = nullptr;
// We must check every floor, from top to bottom // We must check every floor, from top to bottom to check for a clickable tile
int firstFloor = g_map.getFirstVisibleFloor(); int firstFloor = g_map.getFirstVisibleFloor();
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 && !tile->isEmpty() && tile->getGround()) if(tile && tile->isClickable())
break; break;
tilePos.coveredDown(); tilePos.coveredDown();
} }
if(!tile || tile->isEmpty()) // todo: get creature, using walkOffset etc.
if(!tile || !tile->isClickable())
return true; return true;
if(button == Fw::MouseLeftButton) { if(button == Fw::MouseLeftButton) {