1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Fixed world view mode

This commit is contained in:
Ivan Savenko 2023-05-05 21:50:20 +03:00
parent 5ae507505a
commit 8e320d8454
7 changed files with 116 additions and 92 deletions

View File

@ -54,7 +54,6 @@ CAdventureMapInterface::CAdventureMapInterface():
shortcuts = std::make_shared<AdventureMapShortcuts>(*this);
widget = std::make_shared<CAdventureMapWidget>(shortcuts);
widget->setState(EAdventureState::MAKING_TURN);
shortcuts->setState(EAdventureState::MAKING_TURN);
widget->getMapView()->onViewMapActivated();
}
@ -149,7 +148,7 @@ void CAdventureMapInterface::handleMapScrollingUpdate()
uint32_t scrollSpeedPixels = settings["adventure"]["scrollSpeedPixels"].Float();
uint32_t scrollDistance = scrollSpeedPixels * timePassed / 1000;
bool scrollingActive = !GH.isKeyboardCtrlDown() && isActive() && widget->getState() == EAdventureState::MAKING_TURN;
bool scrollingActive = !GH.isKeyboardCtrlDown() && isActive() && shortcuts->optionInMapView();
Point cursorPosition = GH.getCursorPosition();
Point scrollDirection;
@ -275,7 +274,6 @@ void CAdventureMapInterface::onMapTilesChanged(boost::optional<std::unordered_se
void CAdventureMapInterface::onHotseatWaitStarted(PlayerColor playerID)
{
onCurrentPlayerChanged(playerID);
widget->setState(EAdventureState::HOTSEAT_WAIT);
shortcuts->setState(EAdventureState::HOTSEAT_WAIT);
}
@ -301,12 +299,10 @@ void CAdventureMapInterface::adjustActiveness(bool aiTurnStart)
if (aiTurnStart)
{
widget->setState(EAdventureState::ENEMY_TURN);
shortcuts->setState(EAdventureState::ENEMY_TURN);
}
else
{
widget->setState(EAdventureState::MAKING_TURN);
shortcuts->setState(EAdventureState::MAKING_TURN);
}
@ -329,7 +325,6 @@ void CAdventureMapInterface::onPlayerTurnStarted(PlayerColor playerID)
{
onCurrentPlayerChanged(playerID);
widget->setState(EAdventureState::MAKING_TURN);
shortcuts->setState(EAdventureState::MAKING_TURN);
if(LOCPLINT->cb->getCurrentPlayer() == LOCPLINT->playerID
|| settings["session"]["spectate"].Bool())
@ -406,7 +401,7 @@ const CGObjectInstance* CAdventureMapInterface::getActiveObject(const int3 &mapP
void CAdventureMapInterface::onTileLeftClicked(const int3 &mapPos)
{
if(widget->getState() != EAdventureState::MAKING_TURN)
if(!shortcuts->optionInMapView())
return;
//FIXME: this line breaks H3 behavior for Dimension Door
@ -497,7 +492,7 @@ void CAdventureMapInterface::onTileLeftClicked(const int3 &mapPos)
void CAdventureMapInterface::onTileHovered(const int3 &mapPos)
{
if(widget->getState() != EAdventureState::MAKING_TURN)
if(!shortcuts->optionInMapView())
return;
//may occur just at the start of game (fake move before full intiialization)
@ -664,7 +659,7 @@ void CAdventureMapInterface::showMoveDetailsInStatusbar(const CGHeroInstance & h
void CAdventureMapInterface::onTileRightClicked(const int3 &mapPos)
{
if(widget->getState() != EAdventureState::MAKING_TURN)
if(!shortcuts->optionInMapView())
return;
if(spellBeingCasted)
@ -702,16 +697,16 @@ void CAdventureMapInterface::enterCastingMode(const CSpell * sp)
Settings config = settings.write["session"]["showSpellRange"];
config->Bool() = true;
widget->setState(EAdventureState::CASTING_SPELL);
shortcuts->setState(EAdventureState::CASTING_SPELL);
widget->updateActiveState();
}
void CAdventureMapInterface::exitCastingMode()
{
assert(spellBeingCasted);
spellBeingCasted = nullptr;
widget->setState(EAdventureState::MAKING_TURN);
shortcuts->setState(EAdventureState::MAKING_TURN);
widget->updateActiveState();
Settings config = settings.write["session"]["showSpellRange"];
config->Bool() = false;
@ -749,15 +744,15 @@ const IShipyard * CAdventureMapInterface::ourInaccessibleShipyard(const CGObject
void CAdventureMapInterface::hotkeyExitWorldView()
{
widget->setState(EAdventureState::MAKING_TURN);
shortcuts->setState(EAdventureState::MAKING_TURN);
widget->updateActiveState();
widget->getMapView()->onViewMapActivated();
}
void CAdventureMapInterface::openWorldView(int tileSize)
{
widget->setState(EAdventureState::WORLD_VIEW);
shortcuts->setState(EAdventureState::WORLD_VIEW);
widget->updateActiveState();
widget->getMapView()->onViewWorldActivated(tileSize);
}
@ -785,14 +780,12 @@ void CAdventureMapInterface::hotkeySwitchMapLevel()
void CAdventureMapInterface::onScreenResize()
{
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
EAdventureState oldState = widget->getState();
widget.reset();
pos.x = pos.y = 0;
pos.w = GH.screenDimensions().x;
pos.h = GH.screenDimensions().y;
widget = std::make_shared<CAdventureMapWidget>(shortcuts);
widget->setState(oldState);
widget->getMapView()->onViewMapActivated();
widget->setPlayer(currentPlayerID);

View File

@ -33,8 +33,7 @@
#include "../../lib/filesystem/ResourceID.h"
CAdventureMapWidget::CAdventureMapWidget( std::shared_ptr<AdventureMapShortcuts> shortcuts )
: state(EAdventureState::NOT_INITIALIZED)
, shortcuts(shortcuts)
: shortcuts(shortcuts)
, mapLevel(0)
{
pos.x = pos.y = 0;
@ -173,6 +172,7 @@ std::shared_ptr<CIntObject> CAdventureMapWidget::buildMapButton(const JsonNode &
auto button = std::make_shared<CButton>(position.topLeft(), image, help, 0, EShortcut::NONE, playerColored);
loadButtonBorderColor(button, input["borderColor"]);
loadButtonHotkey(button, input["hotkey"]);
return button;
@ -210,7 +210,11 @@ std::shared_ptr<CIntObject> CAdventureMapWidget::buildMapContainer(const JsonNod
addWidget(entry["name"].String(), widget);
result->ownedChildren.push_back(widget);
result->addChild(widget.get(), false);
if (std::dynamic_pointer_cast<CLabel>(widget) || std::dynamic_pointer_cast<CLabelGroup>(widget))
result->addChild(widget.get(), true);
else
result->addChild(widget.get(), false);
}
subwidgetSizes.pop_back();
@ -378,21 +382,6 @@ void CAdventureMapWidget::setPlayerChildren(CIntObject * widget, const PlayerCol
redraw();
}
void CAdventureMapWidget::setState(EAdventureState newState)
{
state = newState;
if(newState == EAdventureState::WORLD_VIEW)
widget<CIntObject>("worldViewContainer")->enable();
else
widget<CIntObject>("worldViewContainer")->disable();
}
EAdventureState CAdventureMapWidget::getState()
{
return state;
}
CAdventureMapIcon::CAdventureMapIcon(const Point & position, std::shared_ptr<CAnimation> animation, size_t index, size_t iconsPerPlayer)
: index(index)
, iconsPerPlayer(iconsPerPlayer)
@ -432,9 +421,15 @@ void CAdventureMapWidget::updateActiveStateChildden(CIntObject * widget)
if (container->disableCondition == "mapLayerUnderground")
container->setEnabled(!shortcuts->optionMapLevelSurface());
if (container->disableCondition == "mapViewMode")
container->setEnabled(shortcuts->optionInWorldView());
if (container->disableCondition == "worldViewMode")
container->setEnabled(!shortcuts->optionInWorldView());
updateActiveStateChildden(container);
}
}
}

View File

@ -23,7 +23,6 @@ enum class EAdventureState;
/// Internal class of AdventureMapInterface that contains actual UI elements
class CAdventureMapWidget : public InterfaceObjectConfigurable
{
EAdventureState state;
int mapLevel;
/// temporary stack of sizes of currently building widgets
std::vector<Rect> subwidgetSizes;
@ -75,8 +74,6 @@ public:
std::shared_ptr<CInfoBar> getInfoBar();
void setPlayer(const PlayerColor & player);
void setState(EAdventureState newState);
EAdventureState getState();
void onMapViewMoved(const Rect & visibleArea, int mapLevel);
void updateActiveState();

View File

@ -253,7 +253,7 @@ void CIntObject::addChild(CIntObject * child, bool adjustPosition)
children.push_back(child);
child->parent_m = this;
if(adjustPosition)
child->pos += pos.topLeft();
child->moveBy(pos.topLeft(), adjustPosition);
if (!active && child->active)
child->deactivate();

View File

@ -325,11 +325,21 @@ std::shared_ptr<CButton> InterfaceObjectConfigurable::buildButton(const JsonNode
button->setImageOrder(imgOrder[0].Integer(), imgOrder[1].Integer(), imgOrder[2].Integer(), imgOrder[3].Integer());
}
loadButtonBorderColor(button, config["borderColor"]);
loadButtonCallback(button, config["callback"]);
loadButtonHotkey(button, config["hotkey"]);
return button;
}
void InterfaceObjectConfigurable::loadButtonBorderColor(std::shared_ptr<CButton> button, const JsonNode & config) const
{
if (config.isNull())
return;
auto color = readColor(config);
button->setBorderColor(color);
}
void InterfaceObjectConfigurable::loadButtonCallback(std::shared_ptr<CButton> button, const JsonNode & config) const
{
if(config.isNull())

View File

@ -77,6 +77,7 @@ protected:
void loadButtonCallback(std::shared_ptr<CButton> button, const JsonNode & config) const;
void loadButtonHotkey(std::shared_ptr<CButton> button, const JsonNode & config) const;
void loadButtonBorderColor(std::shared_ptr<CButton> button, const JsonNode & config) const;
//basic widgets
std::shared_ptr<CPicture> buildPicture(const JsonNode &) const;

View File

@ -434,11 +434,19 @@
},
]
},
// Infobar
{
"type": "adventureInfobar",
"name": "infoBar",
"type": "adventureMapContainer",
"name" : "adventureInfobarContainer",
"hideWhen" : "worldViewMode",
"area": { "bottom": 44, "right" : 19, "width" : 175, "height" : 168 }
"items" : [
// Infobar
{
"type": "adventureInfobar",
"name": "infoBar",
"area": { "bottom": 0, "top" : 0, "left" : 0, "right" : 0 }
}
]
},
// Status bar
{
@ -454,58 +462,64 @@
"image" : "AResBar.pcx",
"area": { "bottom" : 3, "right" : 3, "height" : 22, "width" : 794 },
"wood" : { "x" : 36, "y" : 2 },
"mercury" : { "x" : 120, "y" : 2 },
"ore" : { "x" : 204, "y" : 2 },
"sulfur" : { "x" : 288, "y" : 2 },
"crystal" : { "x" : 372, "y" : 2 },
"gems" : { "x" : 456, "y" : 2 },
"gold" : { "x" : 540, "y" : 2 },
"date" : { "x" : 615, "y" : 2 }
"wood" : { "x" : 37, "y" : 3 },
"mercury" : { "x" : 121, "y" : 3 },
"ore" : { "x" : 205, "y" : 3 },
"sulfur" : { "x" : 289, "y" : 3 },
"crystal" : { "x" : 373, "y" : 3 },
"gems" : { "x" : 457, "y" : 3 },
"gold" : { "x" : 541, "y" : 3 },
"date" : { "x" : 619, "y" : 3 }
},
// World view mode widgets
{
"type": "adventureMapContainer",
"name" : "worldViewContainer",
"hideWhen" : "mapViewMode",
"area": { "top": 195, "right" : 4, "width" : 190, "height" : 381 },
"area": { "top": 195, "right" : 3, "width" : 190, "bottom" : 26 },
"items" : [
{
"type": "adventureMapImage",
"name": "worldViewBackground",
"image" : "VWorld.pcx",
"area": { "top" : 0, "left": 0, "width" : 48, "height" : 192 },
"area": { "left" : 0, "right" : 0, "top" : 0, "height" : 381 },
"sourceArea": { "left" : 0, "right" : 0, "top" : 0, "bottom" : 0 }
},
{
"type": "adventureMapButton",
"name": "worldViewZoom1",
"image" : "VWMAG1.DEF",
"hotkey": "adventureViewWorld1",
"area": { "top" : 23, "left": 1, "width" : 60, "height" : 32 }
},
{
"type": "adventureMapButton",
"name": "worldViewZoom2",
"image" : "VWMAG2.DEF",
"hotkey": "adventureViewWorld2",
"area": { "top" : 23, "left": 64, "width" : 60, "height" : 32 }
},
{
"type": "adventureMapButton",
"name": "worldViewZoom4",
"image" : "VWMAG4.DEF",
"area": { "top" : 23, "left": 1, "width" : 60, "height" : 32 }
"hotkey": "adventureViewWorld4",
"area": { "top" : 23, "left": 128, "width" : 60, "height" : 32 }
},
{
"type": "adventureMapButton",
"name": "worldViewSurface",
"image" : "IAM003.DEF",
"hotkey": "adventureToggleMapLevel",
"playerColored" : true,
"area": { "top" : 79, "left": 343, "width" : 32, "height" : 32 }
},
{
"type": "adventureMapButton",
"name": "worldViewPuzzle",
"borderColor" : "gold",
"image" : "VWPUZ.DEF",
"hotkey": "adventureViewPuzzle",
"area": { "top" : 343, "left": 5, "width" : 66, "height" : 32 }
},
{
@ -513,13 +527,16 @@
"name": "worldViewUnderground",
"image" : "IAM010.DEF",
"playerColored" : true,
"hotkey": "adventureToggleMapLevel",
"area": { "top" : 343, "left": 79, "width" : 32, "height" : 32 }
},
{
"type": "adventureMapButton",
"name": "worldViewExit",
"image" : "IOK6432.DEF",
"area": { "top" : 343, "left": 117, "width" : 66, "height" : 32 }
"borderColor" : "gold",
"image" : "IOKAY32.DEF",
"hotkey": "adventureExitWorldView",
"area": { "top" : 343, "left": 119, "width" : 66, "height" : 32 }
},
// World view - objects icons
{
@ -528,7 +545,7 @@
"image" : "VwSymbol.def",
"index" : 0,
"perPlayer" : 19,
"area": { "top" : 66, "left": 12, "width" : 32, "height" : 32 }
"area": { "top" : 59, "left": 5, "width" : 32, "height" : 32 }
},
{
"type": "adventureMapIcon",
@ -536,7 +553,7 @@
"image" : "VwSymbol.def",
"index" : 1,
"perPlayer" : 19,
"area": { "top" : 86, "left": 12, "width" : 32, "height" : 32 }
"area": { "top" : 79, "left": 5, "width" : 32, "height" : 32 }
},
{
"type": "adventureMapIcon",
@ -544,7 +561,7 @@
"image" : "VwSymbol.def",
"index" : 2,
"perPlayer" : 19,
"area": { "top" : 106, "left": 12, "width" : 32, "height" : 32 }
"area": { "top" : 99, "left": 5, "width" : 32, "height" : 32 }
},
{
"type": "adventureMapIcon",
@ -552,7 +569,7 @@
"image" : "VwSymbol.def",
"index" : 3,
"perPlayer" : 19,
"area": { "top" : 126, "left": 12, "width" : 32, "height" : 32 }
"area": { "top" : 119, "left": 5, "width" : 32, "height" : 32 }
},
{
"type": "adventureMapIcon",
@ -560,7 +577,7 @@
"image" : "VwSymbol.def",
"index" : 4,
"perPlayer" : 19,
"area": { "top" : 146, "left": 12, "width" : 32, "height" : 32 }
"area": { "top" : 139, "left": 5, "width" : 32, "height" : 32 }
},
// World view - mines icons
@ -570,7 +587,7 @@
"image" : "VwSymbol.def",
"index" : 5,
"perPlayer" : 19,
"area": { "top" : 190, "left": 12, "width" : 32, "height" : 32 }
"area": { "top" : 183, "left": 5, "width" : 32, "height" : 32 }
},
{
"type": "adventureMapIcon",
@ -578,7 +595,7 @@
"image" : "VwSymbol.def",
"index" : 6,
"perPlayer" : 19,
"area": { "top" : 210, "left": 12, "width" : 32, "height" : 32 }
"area": { "top" : 203, "left": 5, "width" : 32, "height" : 32 }
},
{
"type": "adventureMapIcon",
@ -586,7 +603,7 @@
"image" : "VwSymbol.def",
"index" : 7,
"perPlayer" : 19,
"area": { "top" : 230, "left": 12, "width" : 32, "height" : 32 }
"area": { "top" : 223, "left": 5, "width" : 32, "height" : 32 }
},
{
"type": "adventureMapIcon",
@ -594,7 +611,7 @@
"image" : "VwSymbol.def",
"index" : 8,
"perPlayer" : 19,
"area": { "top" : 250, "left": 12, "width" : 32, "height" : 32 }
"area": { "top" : 243, "left": 5, "width" : 32, "height" : 32 }
},
{
"type": "adventureMapIcon",
@ -602,7 +619,7 @@
"image" : "VwSymbol.def",
"index" : 9,
"perPlayer" : 19,
"area": { "top" : 270, "left": 12, "width" : 32, "height" : 32 }
"area": { "top" : 263, "left": 5, "width" : 32, "height" : 32 }
},
{
"type": "adventureMapIcon",
@ -610,7 +627,7 @@
"image" : "VwSymbol.def",
"index" : 10,
"perPlayer" : 19,
"area": { "top" : 290, "left": 12, "width" : 32, "height" : 32 }
"area": { "top" : 283, "left": 5, "width" : 32, "height" : 32 }
},
{
"type": "adventureMapIcon",
@ -618,7 +635,7 @@
"image" : "VwSymbol.def",
"index" : 11,
"perPlayer" : 19,
"area": { "top" : 310, "left": 12, "width" : 32, "height" : 32 }
"area": { "top" : 303, "left": 5, "width" : 32, "height" : 32 }
},
// World view - resources icons
@ -628,7 +645,7 @@
"image" : "VwSymbol.def",
"index" : 12,
"perPlayer" : 19,
"area": { "top" : 190, "left": 160, "width" : 32, "height" : 32 }
"area": { "top" : 183, "left": 154, "width" : 32, "height" : 32 }
},
{
"type": "adventureMapIcon",
@ -636,7 +653,7 @@
"image" : "VwSymbol.def",
"index" : 13,
"perPlayer" : 19,
"area": { "top" : 210, "left": 160, "width" : 32, "height" : 32 }
"area": { "top" : 203, "left": 154, "width" : 32, "height" : 32 }
},
{
"type": "adventureMapIcon",
@ -644,7 +661,7 @@
"image" : "VwSymbol.def",
"index" : 14,
"perPlayer" : 19,
"area": { "top" : 230, "left": 160, "width" : 32, "height" : 32 }
"area": { "top" : 223, "left": 154, "width" : 32, "height" : 32 }
},
{
"type": "adventureMapIcon",
@ -652,7 +669,7 @@
"image" : "VwSymbol.def",
"index" : 15,
"perPlayer" : 19,
"area": { "top" : 250, "left": 160, "width" : 32, "height" : 32 }
"area": { "top" : 243, "left": 154, "width" : 32, "height" : 32 }
},
{
"type": "adventureMapIcon",
@ -660,7 +677,7 @@
"image" : "VwSymbol.def",
"index" : 16,
"perPlayer" : 19,
"area": { "top" : 270, "left": 160, "width" : 32, "height" : 32 }
"area": { "top" : 263, "left": 154, "width" : 32, "height" : 32 }
},
{
"type": "adventureMapIcon",
@ -668,7 +685,7 @@
"image" : "VwSymbol.def",
"index" : 17,
"perPlayer" : 19,
"area": { "top" : 290, "left": 160, "width" : 32, "height" : 32 }
"area": { "top" : 283, "left": 154, "width" : 32, "height" : 32 }
},
{
"type": "adventureMapIcon",
@ -676,7 +693,7 @@
"image" : "VwSymbol.def",
"index" : 18,
"perPlayer" : 19,
"area": { "top" : 310, "left": 160, "width" : 32, "height" : 32 }
"area": { "top" : 303, "left": 154, "width" : 32, "height" : 32 }
},
{
@ -685,25 +702,25 @@
"font": "big",
"alignment": "center",
"color": "yellow",
"position": {"x": 100, "y": 10},
"position": {"x": 94, "y": 11},
"text": "core.genrltxt.611"
},
{
"name": "worldViewLabelMine",
"type": "label",
"font": "calisto",
"alignment": "center",
"color": "yellow",
"position": {"x": 10, "y": 175},
"alignment": "left",
"color": "white",
"position": {"x": 7, "y": 173},
"text": "core.genrltxt.617"
},
{
"name": "worldViewLabelResource",
"type": "label",
"font": "calisto",
"alignment": "center",
"color": "yellow",
"position": {"x": 185, "y": 185},
"alignment": "right",
"color": "white",
"position": {"x": 185, "y": 190},
"text": "core.genrltxt.618"
},
{
@ -715,23 +732,23 @@
"items":
[
{
"position": {"x": 45, "y": 70},
"position": {"x": 43, "y": 66},
"text": "core.genrltxt.612"
},
{
"position": {"x": 45, "y": 90},
"position": {"x": 43, "y": 86},
"text": "core.genrltxt.613"
},
{
"position": {"x": 45, "y": 110},
"position": {"x": 43, "y": 106},
"text": "core.genrltxt.614"
},
{
"position": {"x": 45, "y": 130},
"position": {"x": 43, "y": 126},
"text": "core.genrltxt.615"
},
{
"position": {"x": 45, "y": 150},
"position": {"x": 43, "y": 146},
"text": "core.genrltxt.616"
}
]
@ -745,31 +762,42 @@
"items":
[
{
"position": {"x": 100, "y": 200},
"position": {"x": 101, "y": 198},
"text": "core.genrltxt.619"
},
{
"position": {"x": 100, "y": 220},
"position": {"x": 101, "y": 218},
"text": "core.genrltxt.620"
},
{
"position": {"x": 100, "y": 240},
"position": {"x": 101, "y": 238},
"text": "core.genrltxt.621"
},
{
"position": {"x": 100, "y": 260},
"position": {"x": 101, "y": 258},
"text": "core.genrltxt.622"
},
{
"position": {"x": 100, "y": 280},
"position": {"x": 101, "y": 278},
"text": "core.genrltxt.623"
},
{
"position": {"x": 100, "y": 300},
"position": {"x": 101, "y": 298},
"text": "core.genrltxt.624"
},
{
"position": {"x": 101, "y": 318},
"text": "core.genrltxt.625"
}
]
},
}
{
"type": "adventureMapImage",
"name" : "backgroundBelowWorldView",
"image" : "DiBoxBck.pcx",
"area": { "top": 381, "bottom" : 0, "left" : 0, "right" : 0 },
"sourceArea": { "left" : 0, "top" : 0, "width" : 256, "height" : 256 }
}
]
},
// GEMS - set of images with different image for each player