mirror of
https://github.com/edubart/otclient.git
synced 2025-10-15 12:04:55 +02:00
rework and classic controls
This commit is contained in:
@@ -238,6 +238,24 @@ CreaturePtr Tile::getTopCreature()
|
||||
return creature;
|
||||
}
|
||||
|
||||
ThingPtr Tile::getTopMultiUseThing()
|
||||
{
|
||||
// this is related to classic controls, getting top item, forceuse or creature
|
||||
if(isEmpty())
|
||||
return nullptr;
|
||||
|
||||
for(uint i = 0; i < m_things.size(); ++i) {
|
||||
ThingPtr thing = m_things[i];
|
||||
if(thing->isForceUse() || (!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop())) {
|
||||
if(i > 0 && thing->isFluid())
|
||||
return m_things[i-1];
|
||||
return thing;
|
||||
}
|
||||
}
|
||||
|
||||
return m_things[0];
|
||||
}
|
||||
|
||||
bool Tile::isWalkable()
|
||||
{
|
||||
if(!getGround())
|
||||
|
@@ -48,6 +48,7 @@ public:
|
||||
ThingPtr getTopLookThing();
|
||||
ThingPtr getTopUseThing();
|
||||
CreaturePtr getTopCreature();
|
||||
ThingPtr getTopMultiUseThing();
|
||||
|
||||
const Position& getPos() { return m_position; }
|
||||
int getDrawElevation() { return m_drawElevation; }
|
||||
|
@@ -152,6 +152,7 @@ void OTClient::registerLuaFunctions()
|
||||
g_lua.bindClassMemberFunction<Tile>("getTopLookThing", &Tile::getTopLookThing);
|
||||
g_lua.bindClassMemberFunction<Tile>("getTopUseThing", &Tile::getTopUseThing);
|
||||
g_lua.bindClassMemberFunction<Tile>("getTopCreature", &Tile::getTopCreature);
|
||||
g_lua.bindClassMemberFunction<Tile>("getTopMultiUseThing", &Tile::getTopMultiUseThing);
|
||||
g_lua.bindClassMemberFunction<Tile>("getPos", &Tile::getPos);
|
||||
g_lua.bindClassMemberFunction<Tile>("getDrawElevation", &Tile::getDrawElevation);
|
||||
g_lua.bindClassMemberFunction<Tile>("getCreatures", &Tile::getCreatures);
|
||||
|
@@ -24,29 +24,14 @@
|
||||
#include <framework/otml/otml.h>
|
||||
#include <framework/graphics/graphics.h>
|
||||
|
||||
UICreature::UICreature()
|
||||
{
|
||||
m_creatureMargin = 0;
|
||||
}
|
||||
|
||||
void UICreature::render()
|
||||
{
|
||||
renderSelf();
|
||||
|
||||
if(m_creature) {
|
||||
g_painter.setColor(Fw::white);
|
||||
m_creature->draw(m_rect.bottomRight() - Point(32, 32) + m_creatureMargin, m_rect);
|
||||
m_creature->draw(m_rect.bottomRight() - Point(32, 32) + Point(m_paddingLeft, m_paddingTop), m_rect);
|
||||
}
|
||||
|
||||
renderChildren();
|
||||
}
|
||||
|
||||
void UICreature::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
|
||||
{
|
||||
for(OTMLNodePtr node : styleNode->children()) {
|
||||
if(node->tag() == "creature-margin")
|
||||
m_creatureMargin = node->value<int>();
|
||||
}
|
||||
|
||||
UIWidget::onStyleApply(styleName, styleNode);
|
||||
}
|
||||
|
@@ -30,19 +30,14 @@
|
||||
class UICreature : public UIWidget
|
||||
{
|
||||
public:
|
||||
UICreature();
|
||||
void render();
|
||||
|
||||
void setCreature(const CreaturePtr& creature) { m_creature = creature; }
|
||||
|
||||
CreaturePtr getCreature() { return m_creature; }
|
||||
|
||||
protected:
|
||||
virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
|
||||
|
||||
private:
|
||||
CreaturePtr m_creature;
|
||||
int m_creatureMargin;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -27,7 +27,6 @@
|
||||
|
||||
UIItem::UIItem()
|
||||
{
|
||||
m_itemMargin = 0;
|
||||
m_font = g_fonts.getFont("verdana-11px-rounded");
|
||||
}
|
||||
|
||||
@@ -36,7 +35,7 @@ void UIItem::render()
|
||||
renderSelf();
|
||||
|
||||
if(m_item) {
|
||||
Point topLeft = m_rect.bottomRight() - Point(32, 32) + m_itemMargin;
|
||||
Point topLeft = m_rect.bottomRight() - Point(32, 32) + Point(m_paddingLeft, m_paddingTop);
|
||||
|
||||
g_painter.setColor(Fw::white);
|
||||
m_item->draw(topLeft, m_rect);
|
||||
@@ -49,13 +48,3 @@ void UIItem::render()
|
||||
|
||||
renderChildren();
|
||||
}
|
||||
|
||||
void UIItem::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
|
||||
{
|
||||
for(OTMLNodePtr node : styleNode->children()) {
|
||||
if(node->tag() == "item margin")
|
||||
m_itemMargin = node->value<int>();
|
||||
}
|
||||
|
||||
UIWidget::onStyleApply(styleName, styleNode);
|
||||
}
|
||||
|
@@ -36,12 +36,8 @@ public:
|
||||
void setItem(const ItemPtr& item) { m_item = item; }
|
||||
ItemPtr getItem() { return m_item; }
|
||||
|
||||
protected:
|
||||
virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
|
||||
|
||||
private:
|
||||
ItemPtr m_item;
|
||||
int m_itemMargin;
|
||||
FontPtr m_font;
|
||||
};
|
||||
|
||||
|
@@ -27,11 +27,6 @@
|
||||
#include <framework/graphics/graphics.h>
|
||||
#include <otclient/core/localplayer.h>
|
||||
|
||||
UIMap::UIMap()
|
||||
{
|
||||
m_mapMargin = 0;
|
||||
}
|
||||
|
||||
void UIMap::render()
|
||||
{
|
||||
renderSelf();
|
||||
@@ -43,16 +38,6 @@ void UIMap::render()
|
||||
renderChildren();
|
||||
}
|
||||
|
||||
void UIMap::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
|
||||
{
|
||||
for(OTMLNodePtr node : styleNode->children()) {
|
||||
if(node->tag() == "map margin")
|
||||
m_mapMargin = node->value<int>();
|
||||
}
|
||||
|
||||
UIWidget::onStyleApply(styleName, styleNode);
|
||||
}
|
||||
|
||||
TilePtr UIMap::getTile(const Point& mousePos)
|
||||
{
|
||||
if(!m_mapRect.contains(mousePos))
|
||||
@@ -96,7 +81,11 @@ TilePtr UIMap::getTile(const Point& mousePos)
|
||||
|
||||
void UIMap::onGeometryChange(const Rect& oldRect, const Rect& newRect)
|
||||
{
|
||||
Rect mapRect = newRect.expanded(-m_mapMargin-1);
|
||||
Rect mapRect = newRect.expanded(-1);
|
||||
mapRect.addTop(m_paddingTop);
|
||||
mapRect.addLeft(m_paddingLeft);
|
||||
mapRect.addBottom(-m_paddingBottom);
|
||||
mapRect.addRight(-m_paddingRight);
|
||||
Size mapSize(g_map.getVibibleSize().width() * Map::NUM_TILE_PIXELS, g_map.getVibibleSize().height() * Map::NUM_TILE_PIXELS);
|
||||
mapSize.scale(mapRect.size(), Fw::KeepAspectRatio);
|
||||
|
||||
|
@@ -30,17 +30,14 @@
|
||||
class UIMap : public UIWidget
|
||||
{
|
||||
public:
|
||||
UIMap();
|
||||
void render();
|
||||
|
||||
TilePtr getTile(const Point& mousePos);
|
||||
|
||||
protected:
|
||||
virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
|
||||
virtual void onGeometryChange(const Rect& oldRect, const Rect& newRect);
|
||||
|
||||
private:
|
||||
int m_mapMargin;
|
||||
Rect m_mapRect;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user