remove code from uimap to lua

This commit is contained in:
Henrique Santiago 2012-01-09 16:06:16 -02:00
parent b00076bcb9
commit 4bfd335c98
5 changed files with 27 additions and 20 deletions

View File

@ -17,3 +17,4 @@ Module
require 'game' require 'game'
require 'thing' require 'thing'
require 'creature' require 'creature'
require 'map'

16
modules/game/map.lua Normal file
View File

@ -0,0 +1,16 @@
function UIMap:onMousePress(mousePos, mouseButton)
local tile = self:getTile(mousePos)
if not tile then return false end
if not Options.classicControl then
if mouseButton == MouseRightButton then
Game.createThingMenu(mousePos, tile:getTopLookThing(), tile:getTopUseThing(), tile:getTopCreature())
return true
end
end
return false
end

View File

@ -201,6 +201,7 @@ void OTClient::registerLuaFunctions()
g_lua.registerClass<UIMap, UIWidget>(); g_lua.registerClass<UIMap, UIWidget>();
g_lua.bindClassStaticFunction<UIMap>("create", []{ return UIMapPtr(new UIMap); } ); g_lua.bindClassStaticFunction<UIMap>("create", []{ return UIMapPtr(new UIMap); } );
g_lua.bindClassMemberFunction<UIMap>("getTile", &UIMap::getTile);
g_lua.registerClass<UIGame, UIWidget>(); g_lua.registerClass<UIGame, UIWidget>();
g_lua.bindClassStaticFunction<UIGame>("create", []{ return UIGamePtr(new UIGame); } ); g_lua.bindClassStaticFunction<UIGame>("create", []{ return UIGamePtr(new UIGame); } );

View File

@ -25,9 +25,7 @@
#include <otclient/core/map.h> #include <otclient/core/map.h>
#include <framework/otml/otml.h> #include <framework/otml/otml.h>
#include <framework/graphics/graphics.h> #include <framework/graphics/graphics.h>
#include <otclient/core/tile.h>
#include <otclient/core/localplayer.h> #include <otclient/core/localplayer.h>
#include <otclient/core/effect.h>
UIMap::UIMap() UIMap::UIMap()
{ {
@ -55,16 +53,18 @@ void UIMap::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleN
UIWidget::onStyleApply(styleName, styleNode); UIWidget::onStyleApply(styleName, styleNode);
} }
bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button) TilePtr UIMap::getTile(const Point& mousePos)
{ {
if(!m_mapRect.contains(mousePos)) if(!m_mapRect.contains(mousePos))
return UIWidget::onMousePress(mousePos, button); return nullptr;
// Get tile position // Get tile position
Point relativeStretchMousePos = mousePos - m_mapRect.topLeft(); Point relativeStretchMousePos = mousePos - m_mapRect.topLeft();
LocalPlayerPtr localPlayer = g_game.getLocalPlayer(); LocalPlayerPtr localPlayer = g_game.getLocalPlayer();
if(localPlayer) if(localPlayer)
relativeStretchMousePos += localPlayer->getWalkOffset(); relativeStretchMousePos += localPlayer->getWalkOffset();
Size mapSize(g_map.getVibibleSize().width() * Map::NUM_TILE_PIXELS, g_map.getVibibleSize().height() * Map::NUM_TILE_PIXELS); Size mapSize(g_map.getVibibleSize().width() * Map::NUM_TILE_PIXELS, g_map.getVibibleSize().height() * Map::NUM_TILE_PIXELS);
PointF stretchFactor(m_mapRect.width() / (float)mapSize.width(), m_mapRect.height() / (float)mapSize.height()); PointF stretchFactor(m_mapRect.width() / (float)mapSize.width(), m_mapRect.height() / (float)mapSize.height());
@ -89,21 +89,9 @@ bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button)
// todo: get creature, using walkOffset etc. // todo: get creature, using walkOffset etc.
if(!tile || !tile->isClickable()) if(!tile || !tile->isClickable())
return true; return nullptr;
if(button == Fw::MouseLeftButton) { return tile;
g_game.look(tile->getTopLookThing());
EffectPtr effect = EffectPtr(new Effect);
static int id = 0;
effect->setId(id++);
g_map.addThing(effect, tilePos);
}
else if(button == Fw::MouseRightButton) {
g_lua.callGlobalField("Game","createThingMenu", mousePos, tile->getTopLookThing(), tile->getTopUseThing(), tile->getTopCreature());
}
return true;
} }
void UIMap::onGeometryChange(const Rect& oldRect, const Rect& newRect) void UIMap::onGeometryChange(const Rect& oldRect, const Rect& newRect)

View File

@ -25,6 +25,7 @@
#include "declarations.h" #include "declarations.h"
#include <framework/ui/uiwidget.h> #include <framework/ui/uiwidget.h>
#include <otclient/core/tile.h>
class UIMap : public UIWidget class UIMap : public UIWidget
{ {
@ -32,9 +33,10 @@ public:
UIMap(); UIMap();
void render(); void render();
TilePtr getTile(const Point& mousePos);
protected: protected:
virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode); virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button);
virtual void onGeometryChange(const Rect& oldRect, const Rect& newRect); virtual void onGeometryChange(const Rect& oldRect, const Rect& newRect);
private: private:
@ -43,4 +45,3 @@ private:
}; };
#endif #endif