Pārlūkot izejas kodu

shortcut market + boat

Laserlicht 1 mēnesi atpakaļ
vecāks
revīzija
d58d963874

+ 25 - 2
client/adventureMap/AdventureMapShortcuts.cpp

@@ -36,6 +36,7 @@
 #include "../../lib/texts/CGeneralTextHandler.h"
 #include "../../lib/mapObjects/CGHeroInstance.h"
 #include "../../lib/mapObjects/CGTownInstance.h"
+#include "../../lib/mapObjects/MiscObjects.h"
 #include "../../lib/mapping/CMap.h"
 #include "../../lib/pathfinder/CGPathNode.h"
 #include "../../lib/mapObjectConstructors/CObjectClassesHandler.h"
@@ -100,7 +101,7 @@ std::vector<AdventureMapShortcutState> AdventureMapShortcuts::getShortcuts()
 		{ EShortcut::ADVENTURE_VIEW_PUZZLE,      optionSidePanelActive(),[this]() { this->viewPuzzleMap(); } },
 		{ EShortcut::ADVENTURE_VISIT_OBJECT,     optionCanVisitObject(), [this]() { this->visitObject(); } },
 		{ EShortcut::ADVENTURE_VIEW_SELECTED,    optionInMapView(),      [this]() { this->openObject(); } },
-		{ EShortcut::ADVENTURE_MARKETPLACE,      optionInMapView(),      [this]() { this->showMarketplace(); } },
+		{ EShortcut::ADVENTURE_MARKETPLACE,      optionMarketplace(),    [this]() { this->showMarketplace(); } },
 		{ EShortcut::ADVENTURE_ZOOM_IN,          optionSidePanelActive(),[this]() { this->zoom(+10); } },
 		{ EShortcut::ADVENTURE_ZOOM_OUT,         optionSidePanelActive(),[this]() { this->zoom(-10); } },
 		{ EShortcut::ADVENTURE_ZOOM_RESET,       optionSidePanelActive(),[this]() { this->zoom( 0); } },
@@ -641,7 +642,7 @@ bool AdventureMapShortcuts::optionInWorldView()
 
 bool AdventureMapShortcuts::optionSidePanelActive()
 {
-return state == EAdventureState::MAKING_TURN || state == EAdventureState::WORLD_VIEW;
+	return state == EAdventureState::MAKING_TURN || state == EAdventureState::WORLD_VIEW;
 }
 
 bool AdventureMapShortcuts::optionMapScrollingActive()
@@ -653,3 +654,25 @@ bool AdventureMapShortcuts::optionMapViewActive()
 {
 	return state == EAdventureState::MAKING_TURN || state == EAdventureState::WORLD_VIEW || state == EAdventureState::CASTING_SPELL;
 }
+
+bool AdventureMapShortcuts::optionMarketplace()
+{
+	if(state != EAdventureState::MAKING_TURN)
+		return false;
+	for(const CGTownInstance *t : GAME->interface()->cb->getTownsInfo())
+		if(t->hasBuilt(BuildingID::MARKETPLACE))
+			return true;
+	return false;
+}
+
+bool AdventureMapShortcuts::optionHeroGround()
+{
+	const CGHeroInstance *hero = GAME->interface()->localState->getCurrentHero();
+	return optionInMapView() && hero && !hero->inBoat();
+}
+
+bool AdventureMapShortcuts::optionHeroBoat(EPathfindingLayer layer)
+{
+	const CGHeroInstance *hero = GAME->interface()->localState->getCurrentHero();
+	return optionInMapView() && hero && hero->inBoat() && hero->getBoat()->layer == layer;
+}

+ 5 - 0
client/adventureMap/AdventureMapShortcuts.h

@@ -10,6 +10,8 @@
 
 #pragma once
 
+#include "../lib/constants/EntityIdentifiers.h"
+
 VCMI_LIB_NAMESPACE_BEGIN
 class Point;
 class Rect;
@@ -98,6 +100,9 @@ public:
 	bool optionSidePanelActive();
 	bool optionMapScrollingActive();
 	bool optionMapViewActive();
+	bool optionMarketplace();
+	bool optionHeroGround();
+	bool optionHeroBoat(EPathfindingLayer layer);
 
 	void setState(EAdventureState newState);
 	EAdventureState getState() const;

+ 12 - 3
client/adventureMap/AdventureMapWidget.cpp

@@ -398,7 +398,7 @@ void CAdventureMapOverlayWidget::show(Canvas & to)
 	CIntObject::showAll(to);
 }
 
-void AdventureMapWidget::updateActiveStateChildden(CIntObject * widget)
+void AdventureMapWidget::updateActiveStateChildren(CIntObject * widget)
 {
 	for(auto & entry : widget->children)
 	{
@@ -414,6 +414,15 @@ void AdventureMapWidget::updateActiveStateChildden(CIntObject * widget)
 			if (container->disableCondition == "heroSleeping")
 				container->setEnabled(shortcuts->optionHeroSleeping());
 
+			if (container->disableCondition == "heroGround")
+				container->setEnabled(shortcuts->optionHeroGround());
+
+			if (container->disableCondition == "heroBoat")
+				container->setEnabled(shortcuts->optionHeroBoat(EPathfindingLayer::SAIL));
+
+			if (container->disableCondition == "heroAirship")
+				container->setEnabled(shortcuts->optionHeroBoat(EPathfindingLayer::AIR));
+
 			if (container->disableCondition == "mapLayerSurface")
 				container->setEnabled(shortcuts->optionMapLevel() == 0);
 
@@ -429,14 +438,14 @@ void AdventureMapWidget::updateActiveStateChildden(CIntObject * widget)
 			if (container->disableCondition == "worldViewMode")
 				container->setEnabled(!shortcuts->optionInWorldView());
 
-			updateActiveStateChildden(container);
+			updateActiveStateChildren(container);
 		}
 	}
 }
 
 void AdventureMapWidget::updateActiveState()
 {
-	updateActiveStateChildden(this);
+	updateActiveStateChildren(this);
 
 	for (auto entry: shortcuts->getShortcuts())
 		setShortcutBlocked(entry.shortcut, !entry.isEnabled);

+ 1 - 1
client/adventureMap/AdventureMapWidget.h

@@ -57,7 +57,7 @@ class AdventureMapWidget : public InterfaceObjectConfigurable
 	std::shared_ptr<CIntObject> buildTexturePlayerColored(const JsonNode &);
 
 	void setPlayerChildren(CIntObject * widget, const PlayerColor & player);
-	void updateActiveStateChildden(CIntObject * widget);
+	void updateActiveStateChildren(CIntObject * widget);
 public:
 	explicit AdventureMapWidget( std::shared_ptr<AdventureMapShortcuts> shortcuts );