Ivan Savenko 2 лет назад
Родитель
Сommit
46931a0ecf
5 измененных файлов с 22 добавлено и 32 удалено
  1. 1 1
      client/battle/BattleInterfaceClasses.cpp
  2. 2 2
      lib/CTownHandler.cpp
  3. 1 12
      lib/CTownHandler.h
  4. 16 17
      lib/Rect.cpp
  5. 2 0
      lib/Rect.h

+ 1 - 1
client/battle/BattleInterfaceClasses.cpp

@@ -308,7 +308,7 @@ void BattleHero::clickRight(tribool down, bool previousState)
 		return;
 
 	Point windowPosition;
-	windowPosition.x = (!defender) ? owner.fieldController->pos.topLeft().x + 1 : owner.fieldController->pos.topRight().x - 79;
+	windowPosition.x = (!defender) ? owner.fieldController->pos.left() + 1 : owner.fieldController->pos.right() - 79;
 	windowPosition.y = owner.fieldController->pos.y + 135;
 
 	InfoAboutHero targetHero;

+ 2 - 2
lib/CTownHandler.cpp

@@ -776,9 +776,9 @@ void CTownHandler::loadTownHall(CTown &town, const JsonNode & source)
 	}
 }
 
-CTown::ClientInfo::Point JsonToPoint(const JsonNode & node)
+Point JsonToPoint(const JsonNode & node)
 {
-	CTown::ClientInfo::Point ret;
+	Point ret;
 	ret.x = static_cast<si32>(node["x"].Float());
 	ret.y = static_cast<si32>(node["y"].Float());
 	return ret;

+ 1 - 12
lib/CTownHandler.h

@@ -20,6 +20,7 @@
 #include "LogicalExpression.h"
 #include "battle/BattleHex.h"
 #include "HeroBonus.h"
+#include "Point.h"
 
 VCMI_LIB_NAMESPACE_BEGIN
 
@@ -279,18 +280,6 @@ public:
 	// Client-only data. Should be moved away from lib
 	struct ClientInfo
 	{
-		struct Point
-		{
-			si32 x;
-			si32 y;
-
-			template <typename Handler> void serialize(Handler &h, const int version)
-			{
-				h & x;
-				h & y;
-			}
-		};
-
 		//icons [fort is present?][build limit reached?] -> index of icon in def files
 		int icons[2][2];
 		std::string iconSmall[2][2]; /// icon names used during loading

+ 16 - 17
lib/Rect.cpp

@@ -17,17 +17,16 @@ VCMI_LIB_NAMESPACE_BEGIN
 Rect Rect::include(const Rect & other) const
 {
 	Point topLeft{
-		std::min(this->topLeft().x, other.topLeft().x),
-		std::min(this->topLeft().y, other.topLeft().y)
+		std::min(this->left(), other.left()),
+		std::min(this->top(), other.top())
 	};
 
 	Point bottomRight{
-		std::max(this->bottomRight().x, other.bottomRight().x),
-		std::max(this->bottomRight().y, other.bottomRight().y)
+		std::max(this->right(), other.right()),
+		std::max(this->bottom(), other.bottom())
 	};
 
 	return Rect(topLeft, bottomRight - topLeft);
-
 }
 
 Rect Rect::createCentered( const Point & around, const Point & dimensions )
@@ -48,19 +47,19 @@ Rect Rect::createCentered( const Rect & rect, const Point & dimensions)
 bool Rect::intersectionTest(const Rect & other) const
 {
 	// this rect is above other rect
-	if(this->bottomLeft().y < other.topLeft().y)
+	if(this->bottom() < other.top())
 		return false;
 
 	// this rect is below other rect
-	if(this->topLeft().y > other.bottomLeft().y )
+	if(this->top() > other.bottom() )
 		return false;
 
 	// this rect is to the left of other rect
-	if(this->topRight().x < other.topLeft().x)
+	if(this->right() < other.left())
 		return false;
 
 	// this rect is to the right of other rect
-	if(this->topLeft().x > other.topRight().x)
+	if(this->left() > other.right())
 		return false;
 
 	return true;
@@ -72,19 +71,19 @@ bool Rect::intersectionTest(const Rect & other) const
 bool Rect::intersectionTest(const Point & line1, const Point & line2) const
 {
 	// check whether segment is located to the left of our rect
-	if (line1.x < topLeft().x && line2.x < topLeft().x)
+	if (line1.x < left() && line2.x < left())
 		return false;
 
 	// check whether segment is located to the right of our rect
-	if (line1.x > bottomRight().x && line2.x > bottomRight().x)
+	if (line1.x > right() && line2.x > right())
 		return false;
 
 	// check whether segment is located on top of our rect
-	if (line1.y < topLeft().y && line2.y < topLeft().y)
+	if (line1.y < top() && line2.y < top())
 		return false;
 
 	// check whether segment is located below of our rect
-	if (line1.y > bottomRight().y && line2.y > bottomRight().y)
+	if (line1.y > bottom() && line2.y > bottom())
 		return false;
 
 	Point vector { line2.x - line1.x, line2.y - line1.y};
@@ -113,13 +112,13 @@ Rect Rect::intersect(const Rect & other) const
 	if(intersectionTest(other))
 	{
 		Point topLeft{
-			std::max(this->topLeft().x, other.topLeft().x),
-			std::max(this->topLeft().y, other.topLeft().y)
+			std::max(this->left(), other.left()),
+			std::max(this->top(), other.top())
 		};
 
 		Point bottomRight{
-			std::min(this->bottomRight().x, other.bottomRight().x),
-			std::min(this->bottomRight().y, other.bottomRight().y)
+			std::min(this->right(), other.right()),
+			std::min(this->bottom(), other.bottom())
 		};
 
 		return Rect(topLeft, bottomRight - topLeft);

+ 2 - 0
lib/Rect.h

@@ -149,6 +149,8 @@ public:
 	{
 		h & x;
 		h & y;
+		h & w;
+		h & h;
 	}
 };