Skip to content

Commit

Permalink
Create basic Map Editor GUI (#7295)
Browse files Browse the repository at this point in the history
  • Loading branch information
Districh-ru authored Jul 5, 2023
1 parent 2bc797c commit b4fd72b
Show file tree
Hide file tree
Showing 41 changed files with 1,589 additions and 567 deletions.
6 changes: 6 additions & 0 deletions VisualStudio/fheroes2/sources.props
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@
<ClCompile Include="src\fheroes2\dialog\dialog_selectscenario.cpp" />
<ClCompile Include="src\fheroes2\dialog\dialog_system_options.cpp" />
<ClCompile Include="src\fheroes2\dialog\dialog_thievesguild.cpp" />
<ClCompile Include="src\fheroes2\editor\editor_interface.cpp" />
<ClCompile Include="src\fheroes2\editor\editor_interface_panel.cpp" />
<ClCompile Include="src\fheroes2\editor\editor_mainmenu.cpp" />
<ClCompile Include="src\fheroes2\game\difficulty.cpp" />
<ClCompile Include="src\fheroes2\game\fheroes2.cpp" />
Expand All @@ -127,6 +129,7 @@
<ClCompile Include="src\fheroes2\game\game_video.cpp" />
<ClCompile Include="src\fheroes2\game\highscores.cpp" />
<ClCompile Include="src\fheroes2\gui\cursor.cpp" />
<ClCompile Include="src\fheroes2\gui\interface_base.cpp" />
<ClCompile Include="src\fheroes2\gui\interface_border.cpp" />
<ClCompile Include="src\fheroes2\gui\interface_buttons.cpp" />
<ClCompile Include="src\fheroes2\gui\interface_cpanel.cpp" />
Expand Down Expand Up @@ -300,6 +303,8 @@
<ClInclude Include="src\fheroes2\dialog\dialog_selectscenario.h" />
<ClInclude Include="src\fheroes2\dialog\dialog_system_options.h" />
<ClInclude Include="src\fheroes2\editor\editor.h" />
<ClInclude Include="src\fheroes2\editor\editor_interface.h" />
<ClInclude Include="src\fheroes2\editor\editor_interface_panel.h" />
<ClInclude Include="src\fheroes2\game\difficulty.h" />
<ClInclude Include="src\fheroes2\game\game.h" />
<ClInclude Include="src\fheroes2\game\game_credits.h" />
Expand All @@ -316,6 +321,7 @@
<ClInclude Include="src\fheroes2\game\game_video_type.h" />
<ClInclude Include="src\fheroes2\game\highscores.h" />
<ClInclude Include="src\fheroes2\gui\cursor.h" />
<ClInclude Include="src\fheroes2\gui\interface_base.h" />
<ClInclude Include="src\fheroes2\gui\interface_border.h" />
<ClInclude Include="src\fheroes2\gui\interface_buttons.h" />
<ClInclude Include="src\fheroes2\gui\interface_cpanel.h" />
Expand Down
31 changes: 16 additions & 15 deletions src/fheroes2/ai/ai_hero_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "game_interface.h"
#include "game_static.h"
#include "heroes.h"
#include "interface_base.h"
#include "interface_gamearea.h"
#include "kingdom.h"
#include "localevent.h"
Expand Down Expand Up @@ -226,7 +227,7 @@ namespace

if ( AIHeroesShowAnimation( hero, AIGetAllianceColors() ) ) {
if ( centerOn != nullptr ) {
Interface::Basic::Get().GetGameArea().SetCenter( *centerOn );
Interface::AdventureMap::Get().getGameArea().SetCenter( *centerOn );
}

if ( playSound ) {
Expand Down Expand Up @@ -783,7 +784,7 @@ namespace
hero.GetPath().Reset();

if ( AIHeroesShowAnimation( hero, AIGetAllianceColors() ) ) {
Interface::Basic::Get().GetGameArea().SetCenter( hero.GetCenter() );
Interface::AdventureMap::Get().getGameArea().SetCenter( hero.GetCenter() );
hero.FadeIn();
}

Expand Down Expand Up @@ -849,7 +850,7 @@ namespace
AIWhirlpoolTroopLoseEffect( hero );

if ( AIHeroesShowAnimation( hero, AIGetAllianceColors() ) ) {
Interface::Basic::Get().GetGameArea().SetCenter( hero.GetCenter() );
Interface::AdventureMap::Get().getGameArea().SetCenter( hero.GetCenter() );
hero.FadeIn();
}

Expand Down Expand Up @@ -1449,7 +1450,7 @@ namespace
const fheroes2::Point offset( Maps::GetPoint( dst_index ) - hero.GetCenter() );

if ( AIHeroesShowAnimation( hero, AIGetAllianceColors() ) ) {
Interface::Basic::Get().GetGameArea().SetCenter( hero.GetCenter() );
Interface::AdventureMap::Get().getGameArea().SetCenter( hero.GetCenter() );
hero.FadeOut( offset );
}

Expand Down Expand Up @@ -1487,7 +1488,7 @@ namespace
hero.GetPath().Reset();

if ( AIHeroesShowAnimation( hero, AIGetAllianceColors() ) ) {
Interface::Basic::Get().GetGameArea().SetCenter( prevPos );
Interface::AdventureMap::Get().getGameArea().SetCenter( prevPos );
hero.FadeIn( offset );
}

Expand Down Expand Up @@ -1844,8 +1845,8 @@ namespace AI
if ( path.isValid() ) {
hero.SetMove( true );

Interface::Basic & basicInterface = Interface::Basic::Get();
Interface::GameArea & gameArea = basicInterface.GetGameArea();
Interface::AdventureMap & adventureMapInterface = Interface::AdventureMap::Get();
Interface::GameArea & gameArea = adventureMapInterface.getGameArea();

const Settings & conf = Settings::Get();

Expand Down Expand Up @@ -1890,10 +1891,10 @@ namespace AI
// Update Adventure Map objects' animation.
Game::updateAdventureMapAnimationIndex();

basicInterface.Redraw( Interface::REDRAW_GAMEAREA );
adventureMapInterface.redraw( Interface::REDRAW_GAMEAREA );

// If this assertion blows up it means that we are holding a RedrawLocker lock for rendering which should not happen.
assert( basicInterface.GetRedrawMask() == 0 );
assert( adventureMapInterface.getRedrawMask() == 0 );

display.render();
}
Expand Down Expand Up @@ -1959,10 +1960,10 @@ namespace AI
Game::updateAdventureMapAnimationIndex();
}

basicInterface.Redraw( Interface::REDRAW_GAMEAREA );
adventureMapInterface.redraw( Interface::REDRAW_GAMEAREA );

// If this assertion blows up it means that we are holding a RedrawLocker lock for rendering which should not happen.
assert( basicInterface.GetRedrawMask() == 0 );
assert( adventureMapInterface.getRedrawMask() == 0 );

display.render();
}
Expand Down Expand Up @@ -2010,7 +2011,7 @@ namespace AI
#endif

if ( AIHeroesShowAnimation( hero, AIGetAllianceColors() ) ) {
Interface::Basic::Get().GetGameArea().SetCenter( hero.GetCenter() );
Interface::AdventureMap::Get().getGameArea().SetCenter( hero.GetCenter() );
hero.FadeOut();
}

Expand All @@ -2019,7 +2020,7 @@ namespace AI
hero.GetPath().Reset();

if ( AIHeroesShowAnimation( hero, AIGetAllianceColors() ) ) {
Interface::Basic::Get().GetGameArea().SetCenter( hero.GetCenter() );
Interface::AdventureMap::Get().getGameArea().SetCenter( hero.GetCenter() );
hero.FadeIn();
}

Expand All @@ -2046,7 +2047,7 @@ namespace AI
}

if ( AIHeroesShowAnimation( hero, AIGetAllianceColors() ) ) {
Interface::Basic::Get().GetGameArea().SetCenter( hero.GetCenter() );
Interface::AdventureMap::Get().getGameArea().SetCenter( hero.GetCenter() );
hero.FadeOut();
}

Expand All @@ -2055,7 +2056,7 @@ namespace AI
hero.GetPath().Reset();

if ( AIHeroesShowAnimation( hero, AIGetAllianceColors() ) ) {
Interface::Basic::Get().GetGameArea().SetCenter( hero.GetCenter() );
Interface::AdventureMap::Get().getGameArea().SetCenter( hero.GetCenter() );
hero.FadeIn();
}

Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/ai/normal/ai_normal_hero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2084,7 +2084,7 @@ namespace AI
const int monsterStrengthMultiplierCount = 2;
const double monsterStrengthMultipliers[monsterStrengthMultiplierCount] = { ARMY_ADVANTAGE_MEDIUM, ARMY_ADVANTAGE_SMALL };

Interface::StatusWindow & status = Interface::Basic::Get().GetStatusWindow();
Interface::StatusWindow & status = Interface::AdventureMap::Get().getStatusWindow();

uint32_t currentProgressValue = startProgressValue;

Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/ai/normal/ai_normal_kingdom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ namespace AI
}

// reset indicator
Interface::StatusWindow & status = Interface::Basic::Get().GetStatusWindow();
Interface::StatusWindow & status = Interface::AdventureMap::Get().getStatusWindow();
status.DrawAITurnProgress( 0 );

AudioManager::PlayMusicAsync( MUS::COMPUTER_TURN, Music::PlaybackMode::RESUME_AND_PLAY_INFINITE );
Expand Down
8 changes: 4 additions & 4 deletions src/fheroes2/dialog/dialog_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fheroes2::GameMode Dialog::FileOptions()
le.MousePressLeft( buttonCancel.area() ) ? buttonCancel.drawOnPress() : buttonCancel.drawOnRelease();

if ( le.MouseClickLeft( buttonNew.area() ) || Game::HotKeyPressEvent( Game::HotKeyEvent::MAIN_MENU_NEW_GAME ) ) {
if ( Interface::Basic::Get().EventNewGame() == fheroes2::GameMode::NEW_GAME ) {
if ( Interface::AdventureMap::Get().EventNewGame() == fheroes2::GameMode::NEW_GAME ) {
result = fheroes2::GameMode::NEW_GAME;
break;
}
Expand All @@ -98,18 +98,18 @@ fheroes2::GameMode Dialog::FileOptions()
fheroes2::Text( _( "No save files to load." ), fheroes2::FontType::normalWhite() ), Dialog::OK );
}
else {
result = Interface::Basic::Get().EventLoadGame();
result = Interface::AdventureMap::Get().EventLoadGame();
break;
}
}
else if ( le.MouseClickLeft( buttonSave.area() ) || Game::HotKeyPressEvent( Game::HotKeyEvent::WORLD_SAVE_GAME ) ) {
// Special case: since we show a window about file saving we don't want to display the current dialog anymore.
back.restore();

return Interface::Basic::Get().EventSaveGame();
return Interface::AdventureMap::Get().EventSaveGame();
}
else if ( le.MouseClickLeft( buttonQuit.area() ) || Game::HotKeyPressEvent( Game::HotKeyEvent::MAIN_MENU_QUIT ) ) {
if ( Interface::Basic::EventExit() == fheroes2::GameMode::QUIT_GAME ) {
if ( Interface::AdventureMap::EventExit() == fheroes2::GameMode::QUIT_GAME ) {
result = fheroes2::GameMode::QUIT_GAME;
break;
}
Expand Down
21 changes: 12 additions & 9 deletions src/fheroes2/dialog/dialog_quickinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "heroes_base.h"
#include "icn.h"
#include "image.h"
#include "interface_base.h"
#include "interface_gamearea.h"
#include "kingdom.h"
#include "localevent.h"
Expand Down Expand Up @@ -89,17 +90,17 @@ namespace
RadarUpdater( const bool performUpdate, const fheroes2::Point & updatedPosition, const fheroes2::Rect & areaToRestore )
: _performUpdate( performUpdate )
, _updatedPosition( updatedPosition )
, _prevPosition( Interface::Basic::Get().GetGameArea().getCurrentCenterInPixels() )
, _prevPosition( Interface::AdventureMap::Get().getGameArea().getCurrentCenterInPixels() )
, _restorer( fheroes2::Display::instance(), areaToRestore.x, areaToRestore.y, areaToRestore.width, areaToRestore.height )
{
if ( !_performUpdate || _updatedPosition == _prevPosition ) {
return;
}

Interface::Basic & iface = Interface::Basic::Get();
Interface::AdventureMap & iface = Interface::AdventureMap::Get();

iface.GetGameArea().SetCenter( updatedPosition );
iface.Redraw( Interface::REDRAW_RADAR_CURSOR );
iface.getGameArea().SetCenter( updatedPosition );
iface.redraw( Interface::REDRAW_RADAR_CURSOR );

_restorer.restore();
}
Expand All @@ -110,10 +111,10 @@ namespace
return;
}

Interface::Basic & iface = Interface::Basic::Get();
Interface::AdventureMap & iface = Interface::AdventureMap::Get();

iface.GetGameArea().SetCenterInPixels( _prevPosition );
iface.Redraw( Interface::REDRAW_RADAR_CURSOR );
iface.getGameArea().SetCenterInPixels( _prevPosition );
iface.redraw( Interface::REDRAW_RADAR_CURSOR );

_restorer.restore();
}
Expand Down Expand Up @@ -399,7 +400,7 @@ namespace
const int32_t mx = ( ( mp.x - BORDERWIDTH ) / TILEWIDTH ) * TILEWIDTH;
const int32_t my = ( ( mp.y - BORDERWIDTH ) / TILEWIDTH ) * TILEWIDTH;

const Interface::GameArea & gamearea = Interface::Basic::Get().GetGameArea();
const Interface::GameArea & gamearea = Interface::AdventureMap::Get().getGameArea();
const fheroes2::Rect & ar = gamearea.GetROI();

int32_t xpos = mx + TILEWIDTH - ( imageBox.width() / 2 );
Expand Down Expand Up @@ -564,7 +565,9 @@ void Dialog::QuickInfo( const Maps::Tiles & tile )

std::string infoString;

if ( tile.isFog( Settings::Get().CurrentColor() ) ) {
const int32_t playerColor = Settings::Get().CurrentColor();

if ( ( playerColor != 0 ) && tile.isFog( playerColor ) ) {
infoString = _( "Uncharted Territory" );
}
else {
Expand Down
18 changes: 10 additions & 8 deletions src/fheroes2/dialog/dialog_system_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/

#include "dialog_system_options.h"

#include <algorithm>
#include <cassert>
#include <cstdint>
Expand All @@ -28,13 +30,13 @@
#include "cursor.h"
#include "dialog_audio.h"
#include "dialog_hotkeys.h"
#include "dialog_system_options.h"
#include "game_delays.h"
#include "game_hotkeys.h"
#include "game_interface.h"
#include "gamedefs.h"
#include "icn.h"
#include "image.h"
#include "interface_base.h"
#include "localevent.h"
#include "math_base.h"
#include "screen.h"
Expand Down Expand Up @@ -416,9 +418,9 @@ namespace fheroes2
conf.setEvilInterface( !conf.isEvilInterfaceEnabled() );
saveConfiguration = true;

Interface::Basic & basicInterface = Interface::Basic::Get();
basicInterface.Reset();
basicInterface.Redraw( Interface::REDRAW_ALL );
Interface::AdventureMap & adventureMapInterface = Interface::AdventureMap::Get();
adventureMapInterface.reset();
adventureMapInterface.redraw( Interface::REDRAW_ALL );

action = DialogAction::Open;
break;
Expand All @@ -427,13 +429,13 @@ namespace fheroes2
conf.setHideInterface( !conf.isHideInterfaceEnabled() );
saveConfiguration = true;

Interface::Basic & basicInterface = Interface::Basic::Get();
basicInterface.Reset();
Interface::AdventureMap & adventureMapInterface = Interface::AdventureMap::Get();
adventureMapInterface.reset();

// We need to redraw radar first due to the nature of restorers. Only then we can redraw everything.
// And we do a full radar redraw as it could be hidden in "Hide Interface" mode so it was not updated.
basicInterface.Redraw( Interface::REDRAW_RADAR );
basicInterface.Redraw( Interface::REDRAW_ALL & ~( Interface::REDRAW_RADAR_CURSOR | Interface::REDRAW_RADAR ) );
adventureMapInterface.redraw( Interface::REDRAW_RADAR );
adventureMapInterface.redraw( Interface::REDRAW_ALL & ~( Interface::REDRAW_RADAR_CURSOR | Interface::REDRAW_RADAR ) );

action = DialogAction::Open;
break;
Expand Down
Loading

0 comments on commit b4fd72b

Please sign in to comment.