diff --git a/VisualStudio/fheroes2/sources.props b/VisualStudio/fheroes2/sources.props index 4cda29e1a4f..dc47a462609 100644 --- a/VisualStudio/fheroes2/sources.props +++ b/VisualStudio/fheroes2/sources.props @@ -104,6 +104,8 @@ + + @@ -127,6 +129,7 @@ + @@ -300,6 +303,8 @@ + + @@ -316,6 +321,7 @@ + diff --git a/src/fheroes2/ai/ai_hero_action.cpp b/src/fheroes2/ai/ai_hero_action.cpp index 23522225cfa..ec825f58241 100644 --- a/src/fheroes2/ai/ai_hero_action.cpp +++ b/src/fheroes2/ai/ai_hero_action.cpp @@ -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" @@ -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 ) { @@ -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(); } @@ -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(); } @@ -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 ); } @@ -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 ); } @@ -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(); @@ -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(); } @@ -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(); } @@ -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(); } @@ -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(); } @@ -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(); } @@ -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(); } diff --git a/src/fheroes2/ai/normal/ai_normal_hero.cpp b/src/fheroes2/ai/normal/ai_normal_hero.cpp index a8fe063d5ad..f4ca63dafaf 100644 --- a/src/fheroes2/ai/normal/ai_normal_hero.cpp +++ b/src/fheroes2/ai/normal/ai_normal_hero.cpp @@ -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; diff --git a/src/fheroes2/ai/normal/ai_normal_kingdom.cpp b/src/fheroes2/ai/normal/ai_normal_kingdom.cpp index c71ad94eecb..d95d45598c2 100644 --- a/src/fheroes2/ai/normal/ai_normal_kingdom.cpp +++ b/src/fheroes2/ai/normal/ai_normal_kingdom.cpp @@ -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 ); diff --git a/src/fheroes2/dialog/dialog_file.cpp b/src/fheroes2/dialog/dialog_file.cpp index be27c227c98..1e1e7b6b3f7 100644 --- a/src/fheroes2/dialog/dialog_file.cpp +++ b/src/fheroes2/dialog/dialog_file.cpp @@ -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; } @@ -98,7 +98,7 @@ 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; } } @@ -106,10 +106,10 @@ fheroes2::GameMode Dialog::FileOptions() // 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; } diff --git a/src/fheroes2/dialog/dialog_quickinfo.cpp b/src/fheroes2/dialog/dialog_quickinfo.cpp index dfeaa32c8c5..9f80e4bae6b 100644 --- a/src/fheroes2/dialog/dialog_quickinfo.cpp +++ b/src/fheroes2/dialog/dialog_quickinfo.cpp @@ -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" @@ -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(); } @@ -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(); } @@ -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 ); @@ -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 { diff --git a/src/fheroes2/dialog/dialog_system_options.cpp b/src/fheroes2/dialog/dialog_system_options.cpp index a56c0d81451..135178b02bb 100644 --- a/src/fheroes2/dialog/dialog_system_options.cpp +++ b/src/fheroes2/dialog/dialog_system_options.cpp @@ -18,6 +18,8 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include "dialog_system_options.h" + #include #include #include @@ -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" @@ -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; @@ -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; diff --git a/src/fheroes2/editor/editor_interface.cpp b/src/fheroes2/editor/editor_interface.cpp new file mode 100644 index 00000000000..f5a4b97b4f8 --- /dev/null +++ b/src/fheroes2/editor/editor_interface.cpp @@ -0,0 +1,507 @@ +/*************************************************************************** + * fheroes2: https://github.com/ihhub/fheroes2 * + * Copyright (C) 2023 * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "editor_interface.h" + +#include +#include + +#include "agg_image.h" +#include "audio_manager.h" +#include "cursor.h" +#include "dialog.h" +#include "game.h" +#include "game_delays.h" +#include "game_hotkeys.h" +#include "gamedefs.h" +#include "heroes.h" +#include "icn.h" +#include "image.h" +#include "interface_base.h" +#include "interface_border.h" +#include "interface_gamearea.h" +#include "interface_radar.h" +#include "interface_status.h" +#include "localevent.h" +#include "maps_tiles.h" +#include "math_base.h" +#include "mp2.h" +#include "screen.h" +#include "settings.h" +#include "translations.h" +#include "ui_button.h" +#include "ui_dialog.h" +#include "ui_tool.h" +#include "view_world.h" +#include "world.h" + +class Castle; + +namespace Interface +{ + Interface::Editor::Editor() + : _editorPanel( *this ) + { + Editor::reset(); + } + + void Editor::reset() + { + const fheroes2::Display & display = fheroes2::Display::instance(); + + const int32_t xOffset = display.width() - BORDERWIDTH - RADARWIDTH; + _radar.SetPos( xOffset, BORDERWIDTH ); + + if ( display.height() > display.DEFAULT_HEIGHT + BORDERWIDTH ) { + _editorPanel.setPos( xOffset, _radar.GetArea().y + _radar.GetArea().height + BORDERWIDTH ); + _statusWindow.SetPos( xOffset, _editorPanel.getRect().y + _editorPanel.getRect().height ); + } + else { + _editorPanel.setPos( xOffset, _radar.GetArea().y + _radar.GetArea().height ); + } + + const fheroes2::Point prevCenter = _gameArea.getCurrentCenterInPixels(); + const fheroes2::Rect prevRoi = _gameArea.GetROI(); + + _gameArea.SetAreaPosition( BORDERWIDTH, BORDERWIDTH, display.width() - RADARWIDTH - 3 * BORDERWIDTH, display.height() - 2 * BORDERWIDTH ); + + const fheroes2::Rect newRoi = _gameArea.GetROI(); + + _gameArea.SetCenterInPixels( prevCenter + fheroes2::Point( newRoi.x + newRoi.width / 2, newRoi.y + newRoi.height / 2 ) + - fheroes2::Point( prevRoi.x + prevRoi.width / 2, prevRoi.y + prevRoi.height / 2 ) ); + } + + void Editor::redraw( const uint32_t force /* = 0 */ ) + { + const fheroes2::Display & display = fheroes2::Display::instance(); + + const uint32_t combinedRedraw = _redraw | force; + + if ( combinedRedraw & REDRAW_GAMEAREA ) { + // Render all except the fog. + _gameArea.Redraw( fheroes2::Display::instance(), LEVEL_OBJECTS | LEVEL_HEROES | LEVEL_ROUTES ); + + // TODO:: Render horizontal and vertical map tiles scale and highlight with yellow text cursor position. + } + + if ( combinedRedraw & ( REDRAW_RADAR_CURSOR | REDRAW_RADAR ) ) { + // Render the mini-map without fog. + _radar.redrawForEditor( combinedRedraw & REDRAW_RADAR ); + } + + if ( combinedRedraw & REDRAW_BORDER ) { + // Game border for the View World are the same as for the Map Editor. + GameBorderRedraw( true ); + } + + if ( combinedRedraw & REDRAW_PANEL ) { + _editorPanel._redraw(); + } + + if ( ( combinedRedraw & REDRAW_STATUS ) && ( display.height() > display.DEFAULT_HEIGHT + BORDERWIDTH ) ) { + // Currently the Adventure Map status is rendered to fill the space under the Editor buttons on high resolutions. + // TODO: Make special status for Editor to display some map info, e.g. object properties under the cursor (castle garrison, amount of resources, etc.) + // TODO: Decide where to output the status for low resolutions (reduce the number of displayed buttons - put some into sub-menu). + _statusWindow._redraw(); + } + + _redraw = 0; + } + + Interface::Editor & Interface::Editor::Get() + { + static Editor editorInterface; + return editorInterface; + } + + fheroes2::GameMode Interface::Editor::startEdit() + { + reset(); + + // Stop all sounds and music. + AudioManager::ResetAudio(); + + const Settings & conf = Settings::Get(); + + _radar.Build(); + _radar.SetHide( false ); + + fheroes2::GameMode res = fheroes2::GameMode::CANCEL; + + _gameArea.SetUpdateCursor(); + + setRedraw( REDRAW_GAMEAREA | REDRAW_RADAR | REDRAW_PANEL | REDRAW_STATUS | REDRAW_BORDER ); + + int32_t fastScrollRepeatCount = 0; + const int32_t fastScrollStartThreshold = 2; + + bool isCursorOverGamearea = false; + + const std::vector delayTypes = { Game::MAPS_DELAY }; + + LocalEvent & le = LocalEvent::Get(); + Cursor & cursor = Cursor::Get(); + + while ( res == fheroes2::GameMode::CANCEL ) { + if ( !le.HandleEvents( Game::isDelayNeeded( delayTypes ), true ) ) { + if ( EventExit() == fheroes2::GameMode::QUIT_GAME ) { + res = fheroes2::GameMode::QUIT_GAME; + break; + } + continue; + } + + // Process hot-keys. + if ( le.KeyPress() ) { + // adventure map control + if ( HotKeyPressEvent( Game::HotKeyEvent::MAIN_MENU_QUIT ) || HotKeyPressEvent( Game::HotKeyEvent::DEFAULT_CANCEL ) ) { + res = EventExit(); + } + // TODO: remove this 'if defined' when Editor is ready for release. +#if defined( WITH_DEBUG ) + else if ( HotKeyPressEvent( Game::HotKeyEvent::EDITOR_NEW_MAP_MENU ) ) { + res = eventNewMap(); + } +#endif + else if ( HotKeyPressEvent( Game::HotKeyEvent::WORLD_SAVE_GAME ) ) { + fheroes2::showStandardTextMessage( _( "Warning!" ), "The Map Editor is still in development. Save function is not implemented yet.", Dialog::OK ); + } + else if ( HotKeyPressEvent( Game::HotKeyEvent::MAIN_MENU_LOAD_GAME ) ) { + res = eventLoadMap(); + } + else if ( HotKeyPressEvent( Game::HotKeyEvent::WORLD_FILE_OPTIONS ) ) { + res = eventFileDialog(); + } + else if ( HotKeyPressEvent( Game::HotKeyEvent::WORLD_SCENARIO_INFORMATION ) ) { + // TODO: Make the scenario info editor. + Dialog::GameInfo(); + } + else if ( HotKeyPressEvent( Game::HotKeyEvent::WORLD_VIEW_WORLD ) ) { + eventViewWorld(); + } + // map scrolling control + else if ( HotKeyPressEvent( Game::HotKeyEvent::WORLD_SCROLL_LEFT ) ) { + _gameArea.SetScroll( SCROLL_LEFT ); + } + else if ( HotKeyPressEvent( Game::HotKeyEvent::WORLD_SCROLL_RIGHT ) ) { + _gameArea.SetScroll( SCROLL_RIGHT ); + } + else if ( HotKeyPressEvent( Game::HotKeyEvent::WORLD_SCROLL_UP ) ) { + _gameArea.SetScroll( SCROLL_TOP ); + } + else if ( HotKeyPressEvent( Game::HotKeyEvent::WORLD_SCROLL_DOWN ) ) { + _gameArea.SetScroll( SCROLL_BOTTOM ); + } + // default action + else if ( HotKeyPressEvent( Game::HotKeyEvent::WORLD_DEFAULT_ACTION ) ) { + fheroes2::showStandardTextMessage( _( "Warning!" ), "The Map Editor is still in development. No actions are available yet.", Dialog::OK ); + } + // open focus + else if ( HotKeyPressEvent( Game::HotKeyEvent::WORLD_OPEN_FOCUS ) ) { + fheroes2::showStandardTextMessage( _( "Warning!" ), "The Map Editor is still in development. Open focused object dialog is not implemented yet.", + Dialog::OK ); + } + } + + if ( res != fheroes2::GameMode::CANCEL ) { + break; + } + + if ( fheroes2::cursor().isFocusActive() && !_gameArea.isDragScroll() && !_radar.isDragRadar() && ( conf.ScrollSpeed() != SCROLL_SPEED_NONE ) ) { + int scrollPosition = SCROLL_NONE; + + if ( isScrollLeft( le.GetMouseCursor() ) ) + scrollPosition |= SCROLL_LEFT; + else if ( isScrollRight( le.GetMouseCursor() ) ) + scrollPosition |= SCROLL_RIGHT; + if ( isScrollTop( le.GetMouseCursor() ) ) + scrollPosition |= SCROLL_TOP; + else if ( isScrollBottom( le.GetMouseCursor() ) ) + scrollPosition |= SCROLL_BOTTOM; + + if ( scrollPosition != SCROLL_NONE ) { + if ( Game::validateAnimationDelay( Game::SCROLL_START_DELAY ) && ( fastScrollRepeatCount < fastScrollStartThreshold ) ) { + ++fastScrollRepeatCount; + } + + if ( fastScrollRepeatCount >= fastScrollStartThreshold ) { + _gameArea.SetScroll( scrollPosition ); + } + } + else { + fastScrollRepeatCount = 0; + } + } + else { + fastScrollRepeatCount = 0; + } + + isCursorOverGamearea = false; + + // cursor is over the radar + if ( le.MouseCursor( _radar.GetRect() ) ) { + if ( Cursor::POINTER != cursor.Themes() ) { + cursor.SetThemes( Cursor::POINTER ); + } + if ( !_gameArea.isDragScroll() ) { + _radar.QueueEventProcessing(); + } + } + // cursor is over the game area + else if ( le.MouseCursor( _gameArea.GetROI() ) && !_gameArea.NeedScroll() ) { + isCursorOverGamearea = true; + } + // cursor is over the buttons area + else if ( le.MouseCursor( _editorPanel.getRect() ) ) { + if ( Cursor::POINTER != cursor.Themes() ) { + cursor.SetThemes( Cursor::POINTER ); + } + if ( !_gameArea.NeedScroll() ) { + res = _editorPanel.queueEventProcessing(); + } + } + // cursor is somewhere else + else if ( !_gameArea.NeedScroll() ) { + if ( Cursor::POINTER != cursor.Themes() ) { + cursor.SetThemes( Cursor::POINTER ); + } + _gameArea.ResetCursorPosition(); + } + + // gamearea + if ( !_gameArea.NeedScroll() ) { + if ( !_radar.isDragRadar() ) { + _gameArea.QueueEventProcessing( isCursorOverGamearea ); + } + else if ( !le.MousePressLeft() ) { + _radar.QueueEventProcessing(); + } + } + + // fast scroll + if ( Game::validateAnimationDelay( Game::SCROLL_DELAY ) && ( _gameArea.NeedScroll() || _gameArea.needDragScrollRedraw() ) ) { + if ( ( isScrollLeft( le.GetMouseCursor() ) || isScrollRight( le.GetMouseCursor() ) || isScrollTop( le.GetMouseCursor() ) + || isScrollBottom( le.GetMouseCursor() ) ) + && !_gameArea.isDragScroll() ) { + cursor.SetThemes( _gameArea.GetScrollCursor() ); + } + + _gameArea.Scroll(); + + _redraw |= REDRAW_GAMEAREA | REDRAW_RADAR_CURSOR; + } + + // Render map only if the turn is not over. + if ( res == fheroes2::GameMode::CANCEL ) { + // map objects animation + if ( Game::validateAnimationDelay( Game::MAPS_DELAY ) ) { + Game::updateAdventureMapAnimationIndex(); + _redraw |= REDRAW_GAMEAREA; + } + + if ( needRedraw() ) { + redraw(); + + // If this assertion blows up it means that we are holding a RedrawLocker lock for rendering which should not happen. + assert( getRedrawMask() == 0 ); + + validateFadeInAndRender(); + } + } + } + + Game::setDisplayFadeIn(); + + fheroes2::fadeOutDisplay(); + + return res; + } + + fheroes2::GameMode Editor::eventLoadMap() + { + return Dialog::YES + == fheroes2::showStandardTextMessage( "", _( "Are you sure you want to load a new map? (Any unsaved changes to the current map will be lost.)" ), + Dialog::YES | Dialog::NO ) + ? fheroes2::GameMode::EDITOR_LOAD_MAP + : fheroes2::GameMode::CANCEL; + } + + fheroes2::GameMode Editor::eventNewMap() + { + return Dialog::YES + == fheroes2::showStandardTextMessage( "", _( "Are you sure you want to create a new map? (Any unsaved changes to the current map will be lost.)" ), + Dialog::YES | Dialog::NO ) + ? fheroes2::GameMode::EDITOR_NEW_MAP + : fheroes2::GameMode::CANCEL; + } + + fheroes2::GameMode Editor::eventFileDialog() + { + const bool isEvilInterface = Settings::Get().isEvilInterfaceEnabled(); + const int cpanbkg = isEvilInterface ? ICN::CPANBKGE : ICN::CPANBKG; + const fheroes2::Sprite & background = fheroes2::AGG::GetICN( cpanbkg, 0 ); + + const CursorRestorer cursorRestorer( true, Cursor::POINTER ); + + fheroes2::Display & display = fheroes2::Display::instance(); + + // Since the original image contains shadow it is important to remove it from calculation of window's position. + const fheroes2::Point rb( ( display.width() - background.width() - BORDERWIDTH ) / 2, ( display.height() - background.height() + BORDERWIDTH ) / 2 ); + fheroes2::ImageRestorer back( display, rb.x, rb.y, background.width(), background.height() ); + fheroes2::Blit( background, display, rb.x, rb.y ); + + // TODO: Make Evil interface for New/Load/Save Map buttons. + fheroes2::Button buttonNew( rb.x + 62, rb.y + 31, ICN::ECPANEL, 0, 1 ); + fheroes2::Button buttonLoad( rb.x + 195, rb.y + 31, ICN::ECPANEL, 2, 3 ); + fheroes2::Button buttonSave( rb.x + 62, rb.y + 107, ICN::ECPANEL, 4, 5 ); + fheroes2::Button buttonQuit( rb.x + 195, rb.y + 107, isEvilInterface ? ICN::BUTTON_QUIT_EVIL : ICN::BUTTON_QUIT_GOOD, 0, 1 ); + fheroes2::Button buttonCancel( rb.x + 128, rb.y + 184, isEvilInterface ? ICN::BUTTON_SMALL_CANCEL_EVIL : ICN::BUTTON_SMALL_CANCEL_GOOD, 0, 1 ); + + buttonNew.draw(); + buttonLoad.draw(); + buttonSave.draw(); + buttonQuit.draw(); + buttonCancel.draw(); + + display.render( back.rect() ); + + fheroes2::GameMode result = fheroes2::GameMode::QUIT_GAME; + + LocalEvent & le = LocalEvent::Get(); + + while ( le.HandleEvents() ) { + le.MousePressLeft( buttonNew.area() ) ? buttonNew.drawOnPress() : buttonNew.drawOnRelease(); + le.MousePressLeft( buttonLoad.area() ) ? buttonLoad.drawOnPress() : buttonLoad.drawOnRelease(); + le.MousePressLeft( buttonSave.area() ) ? buttonSave.drawOnPress() : buttonSave.drawOnRelease(); + le.MousePressLeft( buttonQuit.area() ) ? buttonQuit.drawOnPress() : buttonQuit.drawOnRelease(); + le.MousePressLeft( buttonCancel.area() ) ? buttonCancel.drawOnPress() : buttonCancel.drawOnRelease(); + + // TODO: remove this 'if defined' when Editor is ready for release. +#if defined( WITH_DEBUG ) + if ( le.MouseClickLeft( buttonNew.area() ) || Game::HotKeyPressEvent( Game::HotKeyEvent::EDITOR_NEW_MAP_MENU ) ) { +#else + if ( le.MouseClickLeft( buttonNew.area() ) ) { +#endif + if ( eventNewMap() == fheroes2::GameMode::EDITOR_NEW_MAP ) { + result = fheroes2::GameMode::EDITOR_NEW_MAP; + break; + } + } + else if ( le.MouseClickLeft( buttonLoad.area() ) || Game::HotKeyPressEvent( Game::HotKeyEvent::MAIN_MENU_LOAD_GAME ) ) { + if ( eventLoadMap() == fheroes2::GameMode::EDITOR_LOAD_MAP ) { + result = fheroes2::GameMode::EDITOR_LOAD_MAP; + break; + } + } + else if ( le.MouseClickLeft( buttonSave.area() ) || Game::HotKeyPressEvent( Game::HotKeyEvent::WORLD_SAVE_GAME ) ) { + back.restore(); + + fheroes2::showStandardTextMessage( _( "Warning!" ), "The Map Editor is still in development. Save function is not implemented yet.", Dialog::OK ); + + break; + } + else if ( le.MouseClickLeft( buttonQuit.area() ) || Game::HotKeyPressEvent( Game::HotKeyEvent::MAIN_MENU_QUIT ) ) { + if ( EventExit() == fheroes2::GameMode::QUIT_GAME ) { + result = fheroes2::GameMode::QUIT_GAME; + break; + } + } + else if ( le.MouseClickLeft( buttonCancel.area() ) || Game::HotKeyCloseWindow() ) { + result = fheroes2::GameMode::CANCEL; + break; + } + else if ( le.MousePressRight( buttonNew.area() ) ) { + fheroes2::showStandardTextMessage( _( "New Map" ), _( "Create a new map, either from scratch or using the random map generator." ), Dialog::ZERO ); + } + else if ( le.MousePressRight( buttonLoad.area() ) ) { + fheroes2::showStandardTextMessage( _( "Load Map" ), _( "Load an existing map." ), Dialog::ZERO ); + } + else if ( le.MousePressRight( buttonSave.area() ) ) { + fheroes2::showStandardTextMessage( _( "Save Map" ), _( "Save the current map." ), Dialog::ZERO ); + } + else if ( le.MousePressRight( buttonQuit.area() ) ) { + fheroes2::showStandardTextMessage( _( "Quit" ), _( "Quit out of the map editor." ), Dialog::ZERO ); + } + else if ( le.MousePressRight( buttonCancel.area() ) ) { + fheroes2::showStandardTextMessage( _( "Cancel" ), _( "Exit this menu without doing anything." ), Dialog::ZERO ); + } + } + + // restore background + back.restore(); + display.render( back.rect() ); + + return result; + } + + void Editor::eventViewWorld() + { + // TODO: Make proper borders restoration for low height resolutions, like for hide interface mode. + ViewWorld::ViewWorldWindow( 0, ViewWorldMode::ViewAll, *this ); + } + void Editor::mouseCursorAreaClickLeft( const int32_t tileIndex ) + { + const Maps::Tiles & tile = world.GetTiles( tileIndex ); + + Heroes * otherHero = tile.GetHeroes(); + if ( otherHero ) { + // TODO: Make hero edit dialog: like Battle only dialog, but only for one hero. + Game::OpenHeroesDialog( *otherHero, true, true ); + } + + Castle * otherCastle = world.getCastle( tile.GetCenter() ); + if ( otherCastle ) { + // TODO: Make Castle edit dialog: like original build dialog. + Game::OpenCastleDialog( *otherCastle ); + } + } + void Editor::mouseCursorAreaPressRight( const int32_t tileIndex ) const + { + const Maps::Tiles & tile = world.GetTiles( tileIndex ); + + switch ( tile.GetObject() ) { + case MP2::OBJ_NON_ACTION_CASTLE: + case MP2::OBJ_CASTLE: { + const Castle * castle = world.getCastle( tile.GetCenter() ); + + if ( castle ) { + Dialog::QuickInfo( *castle ); + } + else { + Dialog::QuickInfo( tile ); + } + + break; + } + case MP2::OBJ_HEROES: { + const Heroes * heroes = tile.GetHeroes(); + + if ( heroes ) { + Dialog::QuickInfo( *heroes ); + } + + break; + } + default: + Dialog::QuickInfo( tile ); + break; + } + } +} diff --git a/src/fheroes2/editor/editor_interface.h b/src/fheroes2/editor/editor_interface.h new file mode 100644 index 00000000000..272b9a6f6c7 --- /dev/null +++ b/src/fheroes2/editor/editor_interface.h @@ -0,0 +1,57 @@ +/*************************************************************************** + * fheroes2: https://github.com/ihhub/fheroes2 * + * Copyright (C) 2023 * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#pragma once + +#include + +#include "editor_interface_panel.h" +#include "game_mode.h" +#include "interface_base.h" + +namespace Interface +{ + class Editor final : public BaseInterface + { + public: + static Editor & Get(); + + void redraw( const uint32_t force = 0 ) override; + + // Regenerates the game area and updates the panel positions depending on the UI settings + void reset() override; + + // Start Map Editor interface main function. + fheroes2::GameMode startEdit(); + + static fheroes2::GameMode eventLoadMap(); + static fheroes2::GameMode eventNewMap(); + static fheroes2::GameMode eventFileDialog(); + void eventViewWorld(); + + void mouseCursorAreaClickLeft( const int32_t tileIndex ) override; + void mouseCursorAreaPressRight( const int32_t tileIndex ) const override; + + private: + Editor(); + + EditorPanel _editorPanel; + }; +} diff --git a/src/fheroes2/editor/editor_interface_panel.cpp b/src/fheroes2/editor/editor_interface_panel.cpp new file mode 100644 index 00000000000..956687b879e --- /dev/null +++ b/src/fheroes2/editor/editor_interface_panel.cpp @@ -0,0 +1,229 @@ +/*************************************************************************** + * fheroes2: https://github.com/ihhub/fheroes2 * + * Copyright (C) 2023 * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "editor_interface_panel.h" + +#include + +#include "agg_image.h" +#include "dialog.h" +#include "dialog_system_options.h" +#include "editor_interface.h" +#include "icn.h" +#include "image.h" +#include "interface_base.h" +#include "localevent.h" +#include "screen.h" +#include "translations.h" +#include "ui_button.h" +#include "ui_dialog.h" + +namespace Interface +{ + EditorPanel::EditorPanel( Editor & interface_ ) + : _interface( interface_ ) + { + int32_t icnIndex = 0; + + for ( fheroes2::Button & button : _instrumentButtons ) { + button.setICNInfo( ICN::EDITBTNS, icnIndex, icnIndex + 1 ); + icnIndex += 2; + } + + _buttonMagnify.setICNInfo( ICN::EDITBTNS, 12, 13 ); + _buttonUndo.setICNInfo( ICN::EDITBTNS, 14, 15 ); + _buttonNew.setICNInfo( ICN::EDITBTNS, 16, 17 ); + _buttonSpecs.setICNInfo( ICN::EDITBTNS, 18, 19 ); + _buttonFile.setICNInfo( ICN::EDITBTNS, 20, 21 ); + _buttonSystem.setICNInfo( ICN::EDITBTNS, 22, 23 ); + + _instrumentButtons.front().press(); + } + + void EditorPanel::setPos( const int32_t displayX, int32_t displayY ) + { + int32_t offsetX = displayX; + + for ( uint8_t i = 0; i < instrumentsCount; ++i ) { + _instrumentButtons[i].setPosition( offsetX, displayY ); + _instrumentButtonsRect[i] = _instrumentButtons[i].area(); + + // We have 3 buttons in a row. + if ( ( i + 1 ) % 3 == 0 ) { + offsetX = displayX; + displayY += _instrumentButtonsRect[i].height; + } + else { + offsetX += _instrumentButtonsRect[i].width; + } + } + + _rectInstruments + = { _instrumentButtonsRect.front().x, _instrumentButtonsRect.front().y, + _instrumentButtonsRect.back().x + _instrumentButtonsRect.back().width - _instrumentButtonsRect.front().x, displayY - _instrumentButtonsRect.front().y }; + + // Instrument panel. + const fheroes2::Sprite & instrumentPanel = fheroes2::AGG::GetICN( ICN::EDITPANL, _selectedInstrument ); + _rectInstrumentPanel = { displayX, displayY, instrumentPanel.width(), instrumentPanel.height() }; + + // System buttons top row. + displayY += _rectInstrumentPanel.height; + _buttonMagnify.setPosition( displayX, displayY ); + _rectMagnify = _buttonMagnify.area(); + + _buttonUndo.setPosition( _rectMagnify.x + _rectMagnify.width, displayY ); + _rectUndo = _buttonUndo.area(); + + _buttonNew.setPosition( _rectUndo.x + _rectUndo.width, displayY ); + _rectNew = _buttonNew.area(); + + // System buttons bottom row. + displayY += _rectMagnify.height; + + _buttonSpecs.setPosition( displayX, displayY ); + _rectSpecs = _buttonSpecs.area(); + + _buttonFile.setPosition( _rectSpecs.x + _rectSpecs.width, displayY ); + _rectFile = _buttonFile.area(); + + _buttonSystem.setPosition( _rectFile.x + _rectFile.width, displayY ); + _rectSystem = _buttonSystem.area(); + + _rectEditorPanel + = { _rectInstruments.x, _rectInstruments.y, _rectSystem.x + _rectSystem.width - _rectInstruments.x, _rectSystem.y + _rectSystem.height - _rectInstruments.y }; + } + + void EditorPanel::setRedraw() const + { + _interface.setRedraw( REDRAW_PANEL ); + } + + void EditorPanel::_redraw() const + { + for ( const fheroes2::Button & button : _instrumentButtons ) { + button.draw(); + } + + const fheroes2::Sprite & instrumentPanel = fheroes2::AGG::GetICN( ICN::EDITPANL, _selectedInstrument ); + fheroes2::Copy( instrumentPanel, 0, 0, fheroes2::Display::instance(), _rectEditorPanel.x, _rectInstruments.y + _rectInstruments.height, instrumentPanel.width(), + instrumentPanel.height() ); + + _buttonMagnify.draw(); + _buttonUndo.draw(); + _buttonNew.draw(); + _buttonSpecs.draw(); + _buttonFile.draw(); + _buttonSystem.draw(); + } + + fheroes2::GameMode EditorPanel::queueEventProcessing() + { + LocalEvent & le = LocalEvent::Get(); + fheroes2::GameMode res = fheroes2::GameMode::CANCEL; + + if ( le.MousePressLeft( _rectInstruments ) ) { + for ( uint8_t i = 0; i < instrumentsCount; ++i ) { + if ( le.MousePressLeft( _instrumentButtonsRect[i] ) ) { + if ( _instrumentButtons[i].drawOnPress() ) { + _selectedInstrument = i; + setRedraw(); + } + } + else { + _instrumentButtons[i].drawOnRelease(); + } + } + } + + le.MousePressLeft( _rectMagnify ) ? _buttonMagnify.drawOnPress() : _buttonMagnify.drawOnRelease(); + le.MousePressLeft( _rectUndo ) ? _buttonUndo.drawOnPress() : _buttonUndo.drawOnRelease(); + le.MousePressLeft( _rectNew ) ? _buttonNew.drawOnPress() : _buttonNew.drawOnRelease(); + le.MousePressLeft( _rectSpecs ) ? _buttonSpecs.drawOnPress() : _buttonSpecs.drawOnRelease(); + le.MousePressLeft( _rectFile ) ? _buttonFile.drawOnPress() : _buttonFile.drawOnRelease(); + le.MousePressLeft( _rectSystem ) ? _buttonSystem.drawOnPress() : _buttonSystem.drawOnRelease(); + + if ( le.MouseClickLeft( _rectMagnify ) ) { + _interface.eventViewWorld(); + } + else if ( le.MouseClickLeft( _rectUndo ) ) { + fheroes2::showStandardTextMessage( _( "Warning!" ), "The Map Editor is still in development. This function is not available yet.", Dialog::OK ); + } + else if ( le.MouseClickLeft( _rectNew ) ) { + res = Editor::eventNewMap(); + } + else if ( le.MouseClickLeft( _rectSpecs ) ) { + // TODO: Make the scenario info editor. + Dialog::GameInfo(); + } + else if ( le.MouseClickLeft( _rectFile ) ) { + res = Interface::Editor::eventFileDialog(); + } + else if ( le.MouseClickLeft( _rectSystem ) ) { + // Replace this with Editor options dialog. + fheroes2::showSystemOptionsDialog(); + } + + if ( le.MousePressRight( _rectInstrumentPanel ) || le.MouseClickLeft( _rectInstrumentPanel ) ) { + // TODO: Implement instrument and brush select. + fheroes2::showStandardTextMessage( _( "Warning!" ), "The Map Editor is still in development. This panel is currently not functional.", + le.MousePressRight() ? Dialog::ZERO : Dialog::OK ); + } + + if ( le.MousePressRight( _instrumentButtonsRect[0] ) ) { + fheroes2::showStandardTextMessage( _( "Terrain Mode" ), _( "Used to draw the underlying grass, dirt, water, etc. on the map." ), Dialog::ZERO ); + } + else if ( le.MousePressRight( _instrumentButtonsRect[1] ) ) { + fheroes2::showStandardTextMessage( _( "Object Mode" ), _( "Used to place objects (mountains, trees, treasure, etc.) on the map." ), Dialog::ZERO ); + } + else if ( le.MousePressRight( _instrumentButtonsRect[2] ) ) { + fheroes2::showStandardTextMessage( _( "Detail Mode" ), _( "Used for special editing of monsters, heroes and towns." ), Dialog::ZERO ); + } + else if ( le.MousePressRight( _instrumentButtonsRect[3] ) ) { + fheroes2::showStandardTextMessage( _( "Stream Mode" ), _( "Allows you to draw streams by clicking and dragging." ), Dialog::ZERO ); + } + else if ( le.MousePressRight( _instrumentButtonsRect[4] ) ) { + fheroes2::showStandardTextMessage( _( "Road Mode" ), _( "Allows you to draw roads by clicking and dragging." ), Dialog::ZERO ); + } + else if ( le.MousePressRight( _instrumentButtonsRect[5] ) ) { + fheroes2::showStandardTextMessage( _( "Erase Mode" ), _( "Used to erase objects off the map." ), Dialog::ZERO ); + } + else if ( le.MousePressRight( _rectMagnify ) ) { + fheroes2::showStandardTextMessage( _( "Magnify" ), _( "Change between zoom and normal view." ), Dialog::ZERO ); + } + else if ( le.MousePressRight( _rectUndo ) ) { + fheroes2::showStandardTextMessage( _( "Undo" ), _( "Undo your last action. Press again to redo the action." ), Dialog::ZERO ); + } + else if ( le.MousePressRight( _rectNew ) ) { + fheroes2::showStandardTextMessage( _( "New Map" ), _( "Create a new map either from scratch or using the random map generator." ), Dialog::ZERO ); + } + else if ( le.MousePressRight( _rectSpecs ) ) { + fheroes2::showStandardTextMessage( _( "Specifications" ), _( "Edit map title, description, and other general information." ), Dialog::ZERO ); + } + else if ( le.MousePressRight( _rectFile ) ) { + fheroes2::showStandardTextMessage( _( "File Options" ), _( "Open the file options menu, where you can save or load maps, or quit out of the editor." ), + Dialog::ZERO ); + } + else if ( le.MousePressRight( _rectSystem ) ) { + fheroes2::showStandardTextMessage( _( "System Options" ), _( "View the editor system options, which let you customize the editor." ), Dialog::ZERO ); + } + + return res; + } +} diff --git a/src/fheroes2/editor/editor_interface_panel.h b/src/fheroes2/editor/editor_interface_panel.h new file mode 100644 index 00000000000..cde43327c2b --- /dev/null +++ b/src/fheroes2/editor/editor_interface_panel.h @@ -0,0 +1,86 @@ +/*************************************************************************** + * fheroes2: https://github.com/ihhub/fheroes2 * + * Copyright (C) 2023 * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#pragma once + +#include +#include + +#include "game_mode.h" +#include "math_base.h" +#include "ui_button.h" + +namespace Interface +{ + class Editor; + + class EditorPanel + { + public: + explicit EditorPanel( Editor & interface_ ); + + ~EditorPanel() = default; + + const fheroes2::Rect & getRect() const + { + return _rectEditorPanel; + } + + // Set Editor panel positions on screen. + void setPos( const int32_t displayX, int32_t displayY ); + + // Set flag to redraw Editor buttons panel on the next interface render. + void setRedraw() const; + + fheroes2::GameMode queueEventProcessing(); + + // Do not call this method directly, use Interface::Editor::redraw() instead. + // The name of this method starts from _ on purpose to do not mix with other public methods. + void _redraw() const; + + private: + Editor & _interface; + + // Index of selected Map Editor instrument. + uint8_t _selectedInstrument{ 0 }; + const static uint8_t instrumentsCount = 6; + + std::array _instrumentButtons; + std::array _instrumentButtonsRect; + + fheroes2::Button _buttonMagnify; + fheroes2::Button _buttonUndo; + fheroes2::Button _buttonNew; + fheroes2::Button _buttonSpecs; + fheroes2::Button _buttonFile; + fheroes2::Button _buttonSystem; + + fheroes2::Rect _rectMagnify; + fheroes2::Rect _rectUndo; + fheroes2::Rect _rectNew; + fheroes2::Rect _rectSpecs; + fheroes2::Rect _rectFile; + fheroes2::Rect _rectSystem; + + fheroes2::Rect _rectInstruments; + fheroes2::Rect _rectInstrumentPanel; + fheroes2::Rect _rectEditorPanel; + }; +} diff --git a/src/fheroes2/editor/editor_mainmenu.cpp b/src/fheroes2/editor/editor_mainmenu.cpp index 26fe6874352..dc0628515a9 100644 --- a/src/fheroes2/editor/editor_mainmenu.cpp +++ b/src/fheroes2/editor/editor_mainmenu.cpp @@ -32,6 +32,8 @@ #include "dialog.h" #include "dialog_selectscenario.h" #include "editor.h" +#include "editor_interface.h" +#include "game.h" #include "game_hotkeys.h" #include "game_mainmenu_ui.h" #include "game_mode.h" @@ -47,6 +49,8 @@ #include "translations.h" #include "ui_button.h" #include "ui_dialog.h" +#include "ui_tool.h" +#include "world.h" namespace { @@ -245,8 +249,15 @@ namespace Editor le.MousePressLeft( cancel.area() ) ? cancel.drawOnPress() : cancel.drawOnRelease(); if ( le.MouseClickLeft( scratchMap.area() ) ) { - if ( selectMapSize() != Maps::ZERO ) { - showWIPInfo(); + const Maps::mapsize_t mapSize = selectMapSize(); + if ( mapSize != Maps::ZERO ) { + // TODO: Put this call to the 'world' instance to a separate '.cpp' file were will be all map editing functions. + world.NewMaps( mapSize, mapSize ); + + fheroes2::fadeOutDisplay(); + Game::setDisplayFadeIn(); + + return Interface::Editor::Get().startEdit(); } return fheroes2::GameMode::EDITOR_NEW_MAP; } diff --git a/src/fheroes2/game/game_interface.cpp b/src/fheroes2/game/game_interface.cpp index b761d1c635e..96cc0806195 100644 --- a/src/fheroes2/game/game_interface.cpp +++ b/src/fheroes2/game/game_interface.cpp @@ -31,30 +31,32 @@ #include "game.h" #include "game_delays.h" #include "game_hotkeys.h" +#include "gamedefs.h" #include "icn.h" #include "image.h" #include "interface_border.h" +#include "interface_gamearea.h" +#include "interface_radar.h" +#include "interface_status.h" #include "localevent.h" #include "maps.h" +#include "math_base.h" +#include "screen.h" #include "settings.h" #include "ui_button.h" #include "ui_tool.h" #include "world.h" -Interface::Basic::Basic() - : gameArea( *this ) - , radar( *this ) - , iconsPanel( *this ) +Interface::AdventureMap::AdventureMap() + : iconsPanel( *this ) , buttonsArea( *this ) - , statusWindow( *this ) , controlPanel( *this ) - , redraw( 0 ) , _lockRedraw( false ) { - Reset(); + AdventureMap::reset(); } -void Interface::Basic::Reset() +void Interface::AdventureMap::reset() { const fheroes2::Display & display = fheroes2::Display::instance(); @@ -74,96 +76,96 @@ void Interface::Basic::Reset() auto isPosValid = []( const fheroes2::Point & pos ) { return pos.x >= 0 && pos.y >= 0; }; if ( isPosValid( radrPos ) && isPosValid( bttnPos ) && isPosValid( iconPos ) && isPosValid( statPos ) ) { - radar.SetPos( radrPos.x, radrPos.y ); + _radar.SetPos( radrPos.x, radrPos.y ); iconsPanel.SetPos( iconPos.x, iconPos.y ); buttonsArea.SetPos( bttnPos.x, bttnPos.y ); - statusWindow.SetPos( statPos.x, statPos.y ); + _statusWindow.SetPos( statPos.x, statPos.y ); } else { - radar.SetPos( 0, 0 ); + _radar.SetPos( 0, 0 ); // It's OK to use display.width() for the X coordinate here, panel will be docked to the right edge - iconsPanel.SetPos( display.width(), radar.GetRect().y + radar.GetRect().height ); + iconsPanel.SetPos( display.width(), _radar.GetRect().y + _radar.GetRect().height ); buttonsArea.SetPos( display.width(), iconsPanel.GetRect().y + iconsPanel.GetRect().height ); - statusWindow.SetPos( display.width(), buttonsArea.GetRect().y + buttonsArea.GetRect().height ); + _statusWindow.SetPos( display.width(), buttonsArea.GetRect().y + buttonsArea.GetRect().height ); } } else { const int32_t px = display.width() - BORDERWIDTH - RADARWIDTH; - radar.SetPos( px, BORDERWIDTH ); - iconsPanel.SetPos( px, radar.GetArea().y + radar.GetArea().height + BORDERWIDTH ); + _radar.SetPos( px, BORDERWIDTH ); + iconsPanel.SetPos( px, _radar.GetArea().y + _radar.GetArea().height + BORDERWIDTH ); buttonsArea.SetPos( px, iconsPanel.GetArea().y + iconsPanel.GetArea().height + BORDERWIDTH ); - statusWindow.SetPos( px, buttonsArea.GetArea().y + buttonsArea.GetArea().height ); + _statusWindow.SetPos( px, buttonsArea.GetArea().y + buttonsArea.GetArea().height ); } - const fheroes2::Point prevCenter = gameArea.getCurrentCenterInPixels(); - const fheroes2::Rect prevRoi = gameArea.GetROI(); + const fheroes2::Point prevCenter = _gameArea.getCurrentCenterInPixels(); + const fheroes2::Rect prevRoi = _gameArea.GetROI(); - gameArea.generate( { display.width(), display.height() }, isHideInterface ); + _gameArea.generate( { display.width(), display.height() }, isHideInterface ); - const fheroes2::Rect newRoi = gameArea.GetROI(); + const fheroes2::Rect newRoi = _gameArea.GetROI(); - gameArea.SetCenterInPixels( prevCenter + fheroes2::Point( newRoi.x + newRoi.width / 2, newRoi.y + newRoi.height / 2 ) - - fheroes2::Point( prevRoi.x + prevRoi.width / 2, prevRoi.y + prevRoi.height / 2 ) ); + _gameArea.SetCenterInPixels( prevCenter + fheroes2::Point( newRoi.x + newRoi.width / 2, newRoi.y + newRoi.height / 2 ) + - fheroes2::Point( prevRoi.x + prevRoi.width / 2, prevRoi.y + prevRoi.height / 2 ) ); } -Interface::Basic & Interface::Basic::Get() +Interface::AdventureMap & Interface::AdventureMap::Get() { - static Basic basic; + static AdventureMap basic; return basic; } -void Interface::Basic::Redraw( const uint32_t force /* = 0 */ ) +void Interface::AdventureMap::redraw( const uint32_t force /* = 0 */ ) { if ( _lockRedraw ) { - SetRedraw( force ); + setRedraw( force ); return; } const Settings & conf = Settings::Get(); - const uint32_t combinedRedraw = redraw | force; + const uint32_t combinedRedraw = _redraw | force; const bool hideInterface = conf.isHideInterfaceEnabled(); if ( combinedRedraw & REDRAW_GAMEAREA ) { - gameArea.Redraw( fheroes2::Display::instance(), LEVEL_ALL ); + _gameArea.Redraw( fheroes2::Display::instance(), LEVEL_ALL ); if ( hideInterface && conf.ShowControlPanel() ) { - controlPanel.Redraw(); + controlPanel._redraw(); } } if ( ( hideInterface && conf.ShowRadar() ) || ( combinedRedraw & ( REDRAW_RADAR_CURSOR | REDRAW_RADAR ) ) ) { // Redraw radar map only if `REDRAW_RADAR` is set. - radar.Redraw( combinedRedraw & REDRAW_RADAR ); + _radar._redraw( combinedRedraw & REDRAW_RADAR ); } if ( ( hideInterface && conf.ShowIcons() ) || ( combinedRedraw & REDRAW_ICONS ) ) { - iconsPanel.Redraw(); + iconsPanel._redraw(); } else if ( combinedRedraw & REDRAW_HEROES ) { - iconsPanel.RedrawIcons( ICON_HEROES ); + iconsPanel._redrawIcons( ICON_HEROES ); } else if ( combinedRedraw & REDRAW_CASTLES ) { - iconsPanel.RedrawIcons( ICON_CASTLES ); + iconsPanel._redrawIcons( ICON_CASTLES ); } if ( ( hideInterface && conf.ShowButtons() ) || ( combinedRedraw & REDRAW_BUTTONS ) ) { - buttonsArea.Redraw(); + buttonsArea._redraw(); } if ( ( hideInterface && conf.ShowStatus() ) || ( combinedRedraw & REDRAW_STATUS ) ) { - statusWindow.Redraw(); + _statusWindow._redraw(); } if ( combinedRedraw & REDRAW_BORDER ) { GameBorderRedraw( false ); } - redraw = 0; + _redraw = 0; } -int32_t Interface::Basic::GetDimensionDoorDestination( const int32_t from, const int32_t distance, const bool water ) +int32_t Interface::AdventureMap::GetDimensionDoorDestination( const int32_t from, const int32_t distance, const bool water ) { fheroes2::Display & display = fheroes2::Display::instance(); @@ -175,8 +177,8 @@ int32_t Interface::Basic::GetDimensionDoorDestination( const int32_t from, const const bool isStatusVisible = conf.ShowStatus(); const bool isControlPanelVisible = conf.ShowControlPanel(); - const fheroes2::Rect & radarRect = radar.GetRect(); - const fheroes2::Rect & radarArea = radar.GetArea(); + const fheroes2::Rect & radarRect = _radar.GetRect(); + const fheroes2::Rect & radarArea = _radar.GetArea(); fheroes2::Button buttonExit( radarArea.x + 32, radarArea.y + radarArea.height - 37, ( isEvilInterface ? ICN::LGNDXTRE : ICN::LGNDXTRA ), 4, 5 ); @@ -190,11 +192,11 @@ int32_t Interface::Basic::GetDimensionDoorDestination( const int32_t from, const buttonExit.draw(); }; - const fheroes2::Rect & gameAreaROI = gameArea.GetROI(); + const fheroes2::Rect & gameAreaROI = _gameArea.GetROI(); const bool isFadingEnabled = ( gameAreaROI.width > TILEWIDTH * distance ) || ( gameAreaROI.height > TILEWIDTH * distance ); const fheroes2::Rect spellROI = [this, from, distance, isHideInterface, &gameAreaROI]() -> fheroes2::Rect { - const fheroes2::Point heroPos = gameArea.GetRelativeTilePosition( Maps::GetPoint( from ) ); + const fheroes2::Point heroPos = _gameArea.GetRelativeTilePosition( Maps::GetPoint( from ) ); const int32_t x = heroPos.x - TILEWIDTH * ( distance / 2 ); const int32_t y = heroPos.y - TILEWIDTH * ( distance / 2 ); @@ -213,7 +215,7 @@ int32_t Interface::Basic::GetDimensionDoorDestination( const int32_t from, const conf.SetShowStatus( false ); conf.SetShowControlPanel( false ); - Redraw( REDRAW_GAMEAREA ); + redraw( REDRAW_GAMEAREA ); } if ( isFadingEnabled ) { @@ -253,7 +255,7 @@ int32_t Interface::Basic::GetDimensionDoorDestination( const int32_t from, const } } else if ( gameAreaROI & mp ) { - const int32_t dst = gameArea.GetValidTileIdFromPoint( mp ); + const int32_t dst = _gameArea.GetValidTileIdFromPoint( mp ); bool valid = ( dst >= 0 ); @@ -279,7 +281,7 @@ int32_t Interface::Basic::GetDimensionDoorDestination( const int32_t from, const if ( Game::validateAnimationDelay( Game::MAPS_DELAY ) ) { Game::updateAdventureMapAnimationIndex(); - Redraw( REDRAW_GAMEAREA ); + redraw( REDRAW_GAMEAREA ); if ( isFadingEnabled ) { InvertedShadow( display, gameAreaROI, spellROI, 5, 9 ); @@ -294,7 +296,7 @@ int32_t Interface::Basic::GetDimensionDoorDestination( const int32_t from, const } if ( isFadingEnabled ) { - SetRedraw( REDRAW_GAMEAREA ); + setRedraw( REDRAW_GAMEAREA ); } if ( isHideInterface ) { @@ -303,10 +305,10 @@ int32_t Interface::Basic::GetDimensionDoorDestination( const int32_t from, const conf.SetShowStatus( isStatusVisible ); conf.SetShowControlPanel( isControlPanelVisible ); - SetRedraw( REDRAW_ICONS | REDRAW_BUTTONS | REDRAW_STATUS | REDRAW_GAMEAREA ); + setRedraw( REDRAW_ICONS | REDRAW_BUTTONS | REDRAW_STATUS | REDRAW_GAMEAREA ); } - Redraw( REDRAW_RADAR_CURSOR ); + redraw( REDRAW_RADAR_CURSOR ); display.render(); return returnValue; diff --git a/src/fheroes2/game/game_interface.h b/src/fheroes2/game/game_interface.h index da670c6b7c3..a8666322475 100644 --- a/src/fheroes2/game/game_interface.h +++ b/src/fheroes2/game/game_interface.h @@ -27,16 +27,11 @@ #include #include "game_mode.h" -#include "gamedefs.h" +#include "interface_base.h" #include "interface_buttons.h" #include "interface_cpanel.h" -#include "interface_gamearea.h" #include "interface_icons.h" -#include "interface_radar.h" -#include "interface_status.h" -#include "math_base.h" #include "players.h" -#include "screen.h" class Castle; class Heroes; @@ -59,28 +54,11 @@ namespace GameFocus namespace Interface { - enum redraw_t : uint32_t - { - // To render the cursor over the previously generated radar map image. - REDRAW_RADAR_CURSOR = 0x01, - // To render radar map fully or in ROI and then the cursor over it. - REDRAW_RADAR = 0x02, - REDRAW_HEROES = 0x04, - REDRAW_CASTLES = 0x08, - REDRAW_BUTTONS = 0x10, - REDRAW_STATUS = 0x20, - REDRAW_BORDER = 0x40, - REDRAW_GAMEAREA = 0x80, - - REDRAW_ICONS = REDRAW_HEROES | REDRAW_CASTLES, - REDRAW_ALL = 0xFF - }; - Castle * GetFocusCastle(); Heroes * GetFocusHeroes(); int GetFocusType(); - class Basic + class AdventureMap final : public BaseInterface { public: // This class is used to lock rendering of Basic class. This is useful when we have to generate only a single frame. @@ -88,10 +66,10 @@ namespace Interface class RedrawLocker { public: - explicit RedrawLocker( Basic & basic ) - : _basic( basic ) + explicit RedrawLocker( AdventureMap & interface_ ) + : _interface( interface_ ) { - _basic._lockRedraw = true; + _interface._lockRedraw = true; } RedrawLocker( const RedrawLocker & ) = delete; @@ -102,79 +80,25 @@ namespace Interface ~RedrawLocker() { - _basic._lockRedraw = false; + _interface._lockRedraw = false; } private: - Basic & _basic; + AdventureMap & _interface; }; - static Basic & Get(); - - bool NeedRedraw() const - { - return redraw != 0; - } - - void SetRedraw( const uint32_t r ) - { - redraw |= r; - } + static AdventureMap & Get(); - uint32_t GetRedrawMask() const - { - return redraw; - } - - void Redraw( const uint32_t force = 0 ); - - static bool isScrollLeft( const fheroes2::Point & cursorPos ) - { - return cursorPos.x < BORDERWIDTH; - } - - static bool isScrollRight( const fheroes2::Point & cursorPos ) - { - const fheroes2::Display & display = fheroes2::Display::instance(); - - return cursorPos.x >= display.width() - BORDERWIDTH; - } - - static bool isScrollTop( const fheroes2::Point & cursorPos ) - { - return cursorPos.y < BORDERWIDTH; - } - - static bool isScrollBottom( const fheroes2::Point & cursorPos ) - { - const fheroes2::Display & display = fheroes2::Display::instance(); - - return cursorPos.y >= display.height() - BORDERWIDTH; - } + void redraw( const uint32_t force = 0 ) override; int32_t GetDimensionDoorDestination( const int32_t from, const int32_t distance, const bool water ); - GameArea & GetGameArea() - { - return gameArea; - } - - Radar & GetRadar() - { - return radar; - } - IconsPanel & GetIconsPanel() { return iconsPanel; } - StatusWindow & GetStatusWindow() - { - return statusWindow; - } - - ControlPanel & GetControlPanel() + ControlPanel & getControlPanel() { return controlPanel; } @@ -209,22 +133,21 @@ namespace Interface void EventViewWorld(); fheroes2::GameMode EventFileDialog() const; fheroes2::GameMode EventEndTurn() const; - static fheroes2::GameMode EventExit(); fheroes2::GameMode EventDigArtifact(); void EventKeyArrowPress( int direct ); fheroes2::GameMode StartGame(); - void MouseCursorAreaClickLeft( const int32_t tileIndex ); - void MouseCursorAreaPressRight( int32_t ) const; + void mouseCursorAreaClickLeft( const int32_t tileIndex ) override; + void mouseCursorAreaPressRight( const int32_t tileIndex ) const override; static int GetCursorTileIndex( int32_t dstIndex ); // Regenerates the game area and updates the panel positions depending on the UI settings - void Reset(); + void reset() override; private: - Basic(); + AdventureMap(); static int GetCursorFocusCastle( const Castle & castle, const Maps::Tiles & tile ); static int GetCursorFocusHeroes( const Heroes & hero, const Maps::Tiles & tile ); @@ -235,18 +158,10 @@ namespace Interface fheroes2::GameMode HumanTurn( const bool isload ); - // If display fade-in state is set reset it to false and fade-in the full display image. Otherwise render full display image without fade-in. - void validateFadeInAndRender(); - - GameArea gameArea; - Radar radar; IconsPanel iconsPanel; ButtonsArea buttonsArea; - StatusWindow statusWindow; ControlPanel controlPanel; - uint32_t redraw; - bool _lockRedraw; }; } diff --git a/src/fheroes2/game/game_mainmenu.cpp b/src/fheroes2/game/game_mainmenu.cpp index b3aab64dec3..16ce7ca24d0 100644 --- a/src/fheroes2/game/game_mainmenu.cpp +++ b/src/fheroes2/game/game_mainmenu.cpp @@ -298,7 +298,7 @@ fheroes2::GameMode Game::MainMenu( bool isFirstGameRun ) while ( true ) { if ( !le.HandleEvents( true, true ) ) { - if ( Interface::Basic::EventExit() == fheroes2::GameMode::QUIT_GAME ) { + if ( Interface::AdventureMap::EventExit() == fheroes2::GameMode::QUIT_GAME ) { break; } else { @@ -355,7 +355,7 @@ fheroes2::GameMode Game::MainMenu( bool isFirstGameRun ) } if ( HotKeyPressEvent( HotKeyEvent::MAIN_MENU_QUIT ) || HotKeyPressEvent( HotKeyEvent::DEFAULT_CANCEL ) || le.MouseClickLeft( buttonQuit.area() ) ) { - if ( Interface::Basic::EventExit() == fheroes2::GameMode::QUIT_GAME ) { + if ( Interface::AdventureMap::EventExit() == fheroes2::GameMode::QUIT_GAME ) { return fheroes2::GameMode::QUIT_GAME; } } diff --git a/src/fheroes2/game/game_scenarioinfo.cpp b/src/fheroes2/game/game_scenarioinfo.cpp index 4f53b204579..4f18ed1fa52 100644 --- a/src/fheroes2/game/game_scenarioinfo.cpp +++ b/src/fheroes2/game/game_scenarioinfo.cpp @@ -266,7 +266,7 @@ namespace LocalEvent & le = LocalEvent::Get(); while ( true ) { if ( !le.HandleEvents( true, true ) ) { - if ( Interface::Basic::EventExit() == fheroes2::GameMode::QUIT_GAME ) { + if ( Interface::AdventureMap::EventExit() == fheroes2::GameMode::QUIT_GAME ) { fheroes2::fadeOutDisplay(); return fheroes2::GameMode::QUIT_GAME; diff --git a/src/fheroes2/game/game_startgame.cpp b/src/fheroes2/game/game_startgame.cpp index f93df868838..fc600884a2f 100644 --- a/src/fheroes2/game/game_startgame.cpp +++ b/src/fheroes2/game/game_startgame.cpp @@ -53,6 +53,7 @@ #include "heroes.h" #include "icn.h" #include "image.h" +#include "interface_base.h" #include "interface_buttons.h" #include "interface_cpanel.h" #include "interface_gamearea.h" @@ -152,7 +153,7 @@ fheroes2::GameMode Game::StartGame() if ( !conf.LoadedGameVersion() ) GameOver::Result::Get().Reset(); - return Interface::Basic::Get().StartGame(); + return Interface::AdventureMap::Get().StartGame(); } void Game::DialogPlayers( int color, std::string title, std::string message ) @@ -237,23 +238,23 @@ void Game::OpenCastleDialog( Castle & castle, bool updateFocus /* = true */, con // If Castle dialog background was not rendered than we have opened it from other dialog (Kingdom Overview) // and there is no need update Adventure map interface at this time. if ( renderBackgroundDialog ) { - Interface::Basic & basicInterface = Interface::Basic::Get(); + Interface::AdventureMap & adventureMapInterface = Interface::AdventureMap::Get(); if ( updateFocus ) { if ( heroCountBefore < myKingdom.GetHeroes().size() ) { - basicInterface.SetFocus( myKingdom.GetHeroes()[heroCountBefore], false ); + adventureMapInterface.SetFocus( myKingdom.GetHeroes()[heroCountBefore], false ); } else if ( it != myCastles.end() ) { Heroes * heroInCastle = world.GetTiles( ( *it )->GetIndex() ).GetHeroes(); if ( heroInCastle == nullptr ) { - basicInterface.SetFocus( *it ); + adventureMapInterface.SetFocus( *it ); } else { - basicInterface.SetFocus( heroInCastle, false ); + adventureMapInterface.SetFocus( heroInCastle, false ); } } else { - basicInterface.ResetFocus( GameFocus::HEROES, false ); + adventureMapInterface.ResetFocus( GameFocus::HEROES, false ); } } else { @@ -262,7 +263,7 @@ void Game::OpenCastleDialog( Castle & castle, bool updateFocus /* = true */, con } // The castle garrison can change - basicInterface.RedrawFocus(); + adventureMapInterface.RedrawFocus(); // Fade-in game screen only for 640x480 resolution. if ( fheroes2::Display::instance().isDefaultSize() ) { @@ -280,7 +281,7 @@ void Game::OpenHeroesDialog( Heroes & hero, bool updateFocus, const bool renderB // setup cursor const CursorRestorer cursorRestorer( true, Cursor::POINTER ); - Interface::Basic & basicInterface = Interface::Basic::Get(); + Interface::AdventureMap & adventureMapInterface = Interface::AdventureMap::Get(); const KingdomHeroes & myHeroes = hero.GetKingdom().GetHeroes(); KingdomHeroes::const_iterator it = std::find( myHeroes.begin(), myHeroes.end(), &hero ); @@ -319,7 +320,7 @@ void Game::OpenHeroesDialog( Heroes & hero, bool updateFocus, const bool renderB // Check if this dialog is not opened from the other dialog and we will be exiting to the Adventure map. if ( renderBackgroundDialog ) { // Redraw Adventure map with hidden hero path. - basicInterface.Redraw( Interface::REDRAW_GAMEAREA ); + adventureMapInterface.redraw( Interface::REDRAW_GAMEAREA ); // Fade-in game screen only for 640x480 resolution. if ( isDefaultScreenSize ) { @@ -350,15 +351,15 @@ void Game::OpenHeroesDialog( Heroes & hero, bool updateFocus, const bool renderB if ( renderBackgroundDialog ) { if ( updateFocus ) { if ( it != myHeroes.end() ) { - basicInterface.SetFocus( *it, false ); + adventureMapInterface.SetFocus( *it, false ); } else { - basicInterface.ResetFocus( GameFocus::HEROES, false ); + adventureMapInterface.ResetFocus( GameFocus::HEROES, false ); } } // The hero's army can change - basicInterface.RedrawFocus(); + adventureMapInterface.RedrawFocus(); // Fade-in game screen only for 640x480 resolution. if ( needFade && renderBackgroundDialog && isDefaultScreenSize ) { @@ -422,7 +423,7 @@ void ShowWarningLostTownsDialog() } } -int Interface::Basic::GetCursorFocusCastle( const Castle & castle, const Maps::Tiles & tile ) +int Interface::AdventureMap::GetCursorFocusCastle( const Castle & castle, const Maps::Tiles & tile ) { switch ( tile.GetObject() ) { case MP2::OBJ_NON_ACTION_CASTLE: @@ -453,7 +454,7 @@ int Interface::Basic::GetCursorFocusCastle( const Castle & castle, const Maps::T return Cursor::POINTER; } -int Interface::Basic::GetCursorFocusShipmaster( const Heroes & hero, const Maps::Tiles & tile ) +int Interface::AdventureMap::GetCursorFocusShipmaster( const Heroes & hero, const Maps::Tiles & tile ) { const bool isWater = tile.isWater(); @@ -523,7 +524,7 @@ int Interface::Basic::GetCursorFocusShipmaster( const Heroes & hero, const Maps: return Cursor::POINTER; } -int Interface::Basic::GetCursorFocusHeroes( const Heroes & hero, const Maps::Tiles & tile ) +int Interface::AdventureMap::GetCursorFocusHeroes( const Heroes & hero, const Maps::Tiles & tile ) { if ( hero.Modes( Heroes::ENABLEMOVE ) ) { return Cursor::Get().Themes(); @@ -615,7 +616,7 @@ int Interface::Basic::GetCursorFocusHeroes( const Heroes & hero, const Maps::Til return Cursor::POINTER; } -int Interface::Basic::GetCursorTileIndex( int32_t dstIndex ) +int Interface::AdventureMap::GetCursorTileIndex( int32_t dstIndex ) { if ( !Maps::isValidAbsIndex( dstIndex ) ) { return Cursor::POINTER; @@ -641,19 +642,19 @@ int Interface::Basic::GetCursorTileIndex( int32_t dstIndex ) return Cursor::POINTER; } -fheroes2::GameMode Interface::Basic::StartGame() +fheroes2::GameMode Interface::AdventureMap::StartGame() { Settings & conf = Settings::Get(); - Reset(); + reset(); - radar.Build(); - radar.SetHide( true ); + _radar.Build(); + _radar.SetHide( true ); iconsPanel.HideIcons( ICON_ANY ); - statusWindow.Reset(); + _statusWindow.Reset(); // Prepare for render the whole game interface with adventure map filled with fog as it was not uncovered by 'updateMapFogDirections()'. - Redraw( REDRAW_GAMEAREA | REDRAW_RADAR | REDRAW_ICONS | REDRAW_BUTTONS | REDRAW_STATUS | REDRAW_BORDER ); + redraw( REDRAW_GAMEAREA | REDRAW_RADAR | REDRAW_ICONS | REDRAW_BUTTONS | REDRAW_STATUS | REDRAW_BORDER ); bool loadedFromSave = conf.LoadedGameVersion(); bool skipTurns = loadedFromSave; @@ -714,8 +715,8 @@ fheroes2::GameMode Interface::Basic::StartGame() if ( kingdom.isPlay() ) { DEBUG_LOG( DBG_GAME, DBG_INFO, world.DateString() << ", color: " << Color::String( playerColor ) << ", resource: " << kingdom.GetFunds().String() ) - radar.SetHide( true ); - radar.SetRedraw( REDRAW_RADAR_CURSOR ); + _radar.SetHide( true ); + _radar.SetRedraw( REDRAW_RADAR_CURSOR ); switch ( kingdom.GetControl() ) { case CONTROL_HUMAN: @@ -724,13 +725,13 @@ fheroes2::GameMode Interface::Basic::StartGame() if ( isHotSeatGame ) { iconsPanel.HideIcons( ICON_ANY ); - statusWindow.Reset(); + _statusWindow.Reset(); // Fully update fog directions in Hot Seat mode to cover the map with fog on player change. // TODO: Cover the Adventure map area with fog sprites without rendering the "Game Area" for player change. Maps::Tiles::updateFogDirectionsInArea( { 0, 0 }, { world.w(), world.h() }, Color::NONE ); - Redraw( REDRAW_GAMEAREA | REDRAW_ICONS | REDRAW_BUTTONS | REDRAW_STATUS ); + redraw( REDRAW_GAMEAREA | REDRAW_ICONS | REDRAW_BUTTONS | REDRAW_STATUS ); validateFadeInAndRender(); @@ -768,18 +769,18 @@ fheroes2::GameMode Interface::Basic::StartGame() conf.SetCurrentColor( playerColor ); - statusWindow.Reset(); - statusWindow.SetState( StatusType::STATUS_AITURN ); + _statusWindow.Reset(); + _statusWindow.SetState( StatusType::STATUS_AITURN ); #if defined( WITH_DEBUG ) if ( player->isAIAutoControlMode() ) { // If player gave control to AI we show the radar image and update it fully at the start of player's turn. - radar.SetHide( false ); - radar.SetRedraw( REDRAW_RADAR ); + _radar.SetHide( false ); + _radar.SetRedraw( REDRAW_RADAR ); } #endif - Redraw(); + redraw(); validateFadeInAndRender(); // In Hot Seat mode there could be different alliances so we have to update fog directions for some cases. @@ -862,7 +863,7 @@ fheroes2::GameMode Interface::Basic::StartGame() return res; } -fheroes2::GameMode Interface::Basic::HumanTurn( const bool isload ) +fheroes2::GameMode Interface::AdventureMap::HumanTurn( const bool isload ) { if ( isload ) { updateFocus(); @@ -871,9 +872,9 @@ fheroes2::GameMode Interface::Basic::HumanTurn( const bool isload ) ResetFocus( GameFocus::FIRSTHERO, false ); } - radar.SetHide( false ); - statusWindow.Reset(); - gameArea.SetUpdateCursor(); + _radar.SetHide( false ); + _statusWindow.Reset(); + _gameArea.SetUpdateCursor(); const Settings & conf = Settings::Get(); if ( conf.IsGameType( Game::TYPE_HOTSEAT ) ) { @@ -883,7 +884,7 @@ fheroes2::GameMode Interface::Basic::HumanTurn( const bool isload ) Interface::GameArea::updateMapFogDirections(); } - Redraw( REDRAW_GAMEAREA | REDRAW_RADAR | REDRAW_ICONS | REDRAW_BUTTONS | REDRAW_STATUS | REDRAW_BORDER ); + redraw( REDRAW_GAMEAREA | REDRAW_RADAR | REDRAW_ICONS | REDRAW_BUTTONS | REDRAW_STATUS | REDRAW_BORDER ); validateFadeInAndRender(); @@ -905,7 +906,7 @@ fheroes2::GameMode Interface::Basic::HumanTurn( const bool isload ) } ); // The amount of the kingdom resources has changed, the status window needs to be updated - Redraw( REDRAW_STATUS ); + redraw( REDRAW_STATUS ); fheroes2::Display::instance().render(); if ( conf.isAutoSaveAtBeginningOfTurnEnabled() ) { @@ -951,7 +952,7 @@ fheroes2::GameMode Interface::Basic::HumanTurn( const bool isload ) } // pending timer events - statusWindow.TimerEventProcessing(); + _statusWindow.TimerEventProcessing(); // hotkeys if ( le.KeyPress() ) { @@ -1038,13 +1039,13 @@ fheroes2::GameMode Interface::Basic::HumanTurn( const bool isload ) EventKeyArrowPress( Direction::BOTTOM_RIGHT ); // map scrolling control else if ( HotKeyPressEvent( Game::HotKeyEvent::WORLD_SCROLL_LEFT ) ) - gameArea.SetScroll( SCROLL_LEFT ); + _gameArea.SetScroll( SCROLL_LEFT ); else if ( HotKeyPressEvent( Game::HotKeyEvent::WORLD_SCROLL_RIGHT ) ) - gameArea.SetScroll( SCROLL_RIGHT ); + _gameArea.SetScroll( SCROLL_RIGHT ); else if ( HotKeyPressEvent( Game::HotKeyEvent::WORLD_SCROLL_UP ) ) - gameArea.SetScroll( SCROLL_TOP ); + _gameArea.SetScroll( SCROLL_TOP ); else if ( HotKeyPressEvent( Game::HotKeyEvent::WORLD_SCROLL_DOWN ) ) - gameArea.SetScroll( SCROLL_BOTTOM ); + _gameArea.SetScroll( SCROLL_BOTTOM ); // default action else if ( HotKeyPressEvent( Game::HotKeyEvent::WORLD_DEFAULT_ACTION ) ) res = EventDefaultAction( res ); @@ -1057,7 +1058,7 @@ fheroes2::GameMode Interface::Basic::HumanTurn( const bool isload ) break; } - if ( fheroes2::cursor().isFocusActive() && !gameArea.isDragScroll() && !radar.isDragRadar() && ( conf.ScrollSpeed() != SCROLL_SPEED_NONE ) ) { + if ( fheroes2::cursor().isFocusActive() && !_gameArea.isDragScroll() && !_radar.isDragRadar() && ( conf.ScrollSpeed() != SCROLL_SPEED_NONE ) ) { int scrollPosition = SCROLL_NONE; if ( isScrollLeft( le.GetMouseCursor() ) ) @@ -1077,7 +1078,7 @@ fheroes2::GameMode Interface::Basic::HumanTurn( const bool isload ) } if ( fastScrollRepeatCount >= fastScrollStartThreshold ) { - gameArea.SetScroll( scrollPosition ); + _gameArea.SetScroll( scrollPosition ); } } else { @@ -1105,10 +1106,10 @@ fheroes2::GameMode Interface::Basic::HumanTurn( const bool isload ) } } // cursor is over the status window - else if ( ( !isHiddenInterface || conf.ShowStatus() ) && le.MouseCursor( statusWindow.GetRect() ) ) { + else if ( ( !isHiddenInterface || conf.ShowStatus() ) && le.MouseCursor( _statusWindow.GetRect() ) ) { if ( Cursor::POINTER != cursor.Themes() ) cursor.SetThemes( Cursor::POINTER ); - statusWindow.QueueEventProcessing(); + _statusWindow.QueueEventProcessing(); } // cursor is over the buttons area else if ( ( !isHiddenInterface || conf.ShowButtons() ) && le.MouseCursor( buttonsArea.GetRect() ) ) { @@ -1124,11 +1125,11 @@ fheroes2::GameMode Interface::Basic::HumanTurn( const bool isload ) iconsPanel.QueueEventProcessing(); } // cursor is over the radar - else if ( ( !isHiddenInterface || conf.ShowRadar() ) && le.MouseCursor( radar.GetRect() ) ) { + else if ( ( !isHiddenInterface || conf.ShowRadar() ) && le.MouseCursor( _radar.GetRect() ) ) { if ( Cursor::POINTER != cursor.Themes() ) cursor.SetThemes( Cursor::POINTER ); - if ( !gameArea.isDragScroll() ) - radar.QueueEventProcessing(); + if ( !_gameArea.isDragScroll() ) + _radar.QueueEventProcessing(); } // cursor is over the control panel else if ( isHiddenInterface && conf.ShowControlPanel() && le.MouseCursor( controlPanel.GetArea() ) ) { @@ -1137,22 +1138,22 @@ fheroes2::GameMode Interface::Basic::HumanTurn( const bool isload ) res = controlPanel.QueueEventProcessing(); } // cursor is over the game area - else if ( le.MouseCursor( gameArea.GetROI() ) && !gameArea.NeedScroll() ) { + else if ( le.MouseCursor( _gameArea.GetROI() ) && !_gameArea.NeedScroll() ) { isCursorOverGamearea = true; } // cursor is somewhere else - else if ( !gameArea.NeedScroll() ) { + else if ( !_gameArea.NeedScroll() ) { if ( Cursor::POINTER != cursor.Themes() ) cursor.SetThemes( Cursor::POINTER ); - gameArea.ResetCursorPosition(); + _gameArea.ResetCursorPosition(); } // gamearea - if ( !gameArea.NeedScroll() && !isMovingHero ) { - if ( !radar.isDragRadar() ) - gameArea.QueueEventProcessing( isCursorOverGamearea ); + if ( !_gameArea.NeedScroll() && !isMovingHero ) { + if ( !_radar.isDragRadar() ) + _gameArea.QueueEventProcessing( isCursorOverGamearea ); else if ( !le.MousePressLeft() ) - radar.QueueEventProcessing(); + _radar.QueueEventProcessing(); } if ( prevIsCursorOverButtons && !isCursorOverButtons ) { @@ -1172,8 +1173,8 @@ fheroes2::GameMode Interface::Basic::HumanTurn( const bool isload ) if ( heroAnimationFrameCount > 0 ) { const int32_t heroMovementSkipValue = Game::HumanHeroAnimSkip(); - gameArea.ShiftCenter( { heroAnimationOffset.x * heroMovementSkipValue, heroAnimationOffset.y * heroMovementSkipValue } ); - gameArea.SetRedraw(); + _gameArea.ShiftCenter( { heroAnimationOffset.x * heroMovementSkipValue, heroAnimationOffset.y * heroMovementSkipValue } ); + _gameArea.SetRedraw(); if ( heroAnimationOffset != fheroes2::Point() ) { Game::EnvironmentSoundMixer(); @@ -1200,9 +1201,9 @@ fheroes2::GameMode Interface::Basic::HumanTurn( const bool isload ) if ( hero->isMoveEnabled() ) { if ( hero->Move( 10 == conf.HeroesMoveSpeed() ) ) { // Do not generate a frame as we are going to do it later. - Interface::Basic::RedrawLocker redrawLocker( Interface::Basic::Get() ); + Interface::AdventureMap::RedrawLocker redrawLocker( Interface::AdventureMap::Get() ); - gameArea.SetCenter( hero->GetCenter() ); + _gameArea.SetCenter( hero->GetCenter() ); ResetFocus( GameFocus::HEROES, true ); RedrawFocus(); @@ -1217,12 +1218,12 @@ fheroes2::GameMode Interface::Basic::HumanTurn( const bool isload ) const fheroes2::Point movement( hero->MovementDirection() ); if ( movement != fheroes2::Point() ) { // don't waste resources for no movement // Do not generate a frame as we are going to do it later. - Interface::Basic::RedrawLocker redrawLocker( Interface::Basic::Get() ); + Interface::AdventureMap::RedrawLocker redrawLocker( Interface::AdventureMap::Get() ); const int32_t heroMovementSkipValue = Game::HumanHeroAnimSkip(); heroAnimationOffset = movement; - gameArea.ShiftCenter( movement ); + _gameArea.ShiftCenter( movement ); Game::SetUpdateSoundsOnFocusUpdate( false ); ResetFocus( GameFocus::HEROES, true ); @@ -1238,7 +1239,7 @@ fheroes2::GameMode Interface::Basic::HumanTurn( const bool isload ) } } - gameArea.SetRedraw(); + _gameArea.SetRedraw(); } isMovingHero = true; @@ -1256,7 +1257,7 @@ fheroes2::GameMode Interface::Basic::HumanTurn( const bool isload ) hero->SetMove( false ); - gameArea.SetUpdateCursor(); + _gameArea.SetUpdateCursor(); } } } @@ -1267,18 +1268,18 @@ fheroes2::GameMode Interface::Basic::HumanTurn( const bool isload ) } // fast scroll - if ( ( gameArea.NeedScroll() && !isMovingHero ) || gameArea.needDragScrollRedraw() ) { + if ( ( _gameArea.NeedScroll() && !isMovingHero ) || _gameArea.needDragScrollRedraw() ) { if ( Game::validateAnimationDelay( Game::SCROLL_DELAY ) ) { if ( ( isScrollLeft( le.GetMouseCursor() ) || isScrollRight( le.GetMouseCursor() ) || isScrollTop( le.GetMouseCursor() ) || isScrollBottom( le.GetMouseCursor() ) ) - && !gameArea.isDragScroll() ) { - cursor.SetThemes( gameArea.GetScrollCursor() ); + && !_gameArea.isDragScroll() ) { + cursor.SetThemes( _gameArea.GetScrollCursor() ); } - gameArea.Scroll(); + _gameArea.Scroll(); - gameArea.SetRedraw(); - radar.SetRedraw( REDRAW_RADAR_CURSOR ); + _gameArea.SetRedraw(); + _radar.SetRedraw( REDRAW_RADAR_CURSOR ); } } @@ -1292,14 +1293,14 @@ fheroes2::GameMode Interface::Basic::HumanTurn( const bool isload ) // map objects animation if ( Game::validateAnimationDelay( Game::MAPS_DELAY ) ) { Game::updateAdventureMapAnimationIndex(); - gameArea.SetRedraw(); + _gameArea.SetRedraw(); } - if ( NeedRedraw() ) { - Redraw(); + if ( needRedraw() ) { + redraw(); // If this assertion blows up it means that we are holding a RedrawLocker lock for rendering which should not happen. - assert( GetRedrawMask() == 0 ); + assert( getRedrawMask() == 0 ); validateFadeInAndRender(); } @@ -1310,7 +1311,7 @@ fheroes2::GameMode Interface::Basic::HumanTurn( const bool isload ) if ( GetFocusHeroes() ) { GetFocusHeroes()->ShowPath( false ); - SetRedraw( REDRAW_GAMEAREA ); + setRedraw( REDRAW_GAMEAREA ); } if ( myKingdom.isPlay() ) { @@ -1336,19 +1337,7 @@ fheroes2::GameMode Interface::Basic::HumanTurn( const bool isload ) return res; } -void Interface::Basic::validateFadeInAndRender() -{ - if ( Game::validateDisplayFadeIn() ) { - fheroes2::fadeInDisplay(); - - SetRedraw( REDRAW_GAMEAREA ); - } - else { - fheroes2::Display::instance().render(); - } -} - -void Interface::Basic::MouseCursorAreaClickLeft( const int32_t tileIndex ) +void Interface::AdventureMap::mouseCursorAreaClickLeft( const int32_t tileIndex ) { Heroes * focusedHero = GetFocusHeroes(); const Maps::Tiles & tile = world.GetTiles( tileIndex ); @@ -1428,17 +1417,17 @@ void Interface::Basic::MouseCursorAreaClickLeft( const int32_t tileIndex ) } } -void Interface::Basic::MouseCursorAreaPressRight( int32_t index_maps ) const +void Interface::AdventureMap::mouseCursorAreaPressRight( const int32_t tileIndex ) const { Heroes * hero = GetFocusHeroes(); if ( hero && hero->isMoveEnabled() ) { hero->SetMove( false ); - Cursor::Get().SetThemes( GetCursorTileIndex( index_maps ) ); + Cursor::Get().SetThemes( GetCursorTileIndex( tileIndex ) ); } else { const Settings & conf = Settings::Get(); - const Maps::Tiles & tile = world.GetTiles( index_maps ); + const Maps::Tiles & tile = world.GetTiles( tileIndex ); DEBUG_LOG( DBG_DEVEL, DBG_INFO, std::endl << tile.String() ) diff --git a/src/fheroes2/gui/interface_base.cpp b/src/fheroes2/gui/interface_base.cpp new file mode 100644 index 00000000000..a97cbef91a2 --- /dev/null +++ b/src/fheroes2/gui/interface_base.cpp @@ -0,0 +1,48 @@ +/*************************************************************************** + * fheroes2: https://github.com/ihhub/fheroes2 * + * Copyright (C) 2023 * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "interface_base.h" + +#include "game.h" +#include "ui_tool.h" + +namespace Interface +{ + BaseInterface::BaseInterface() + : _gameArea( *this ) + , _radar( *this ) + , _statusWindow( *this ) + { + // Do nothing; + } + + void Interface::BaseInterface::validateFadeInAndRender() + { + if ( Game::validateDisplayFadeIn() ) { + fheroes2::fadeInDisplay(); + + setRedraw( REDRAW_GAMEAREA ); + } + else { + fheroes2::Display::instance().render(); + } + } + +} diff --git a/src/fheroes2/gui/interface_base.h b/src/fheroes2/gui/interface_base.h new file mode 100644 index 00000000000..71d6a95868c --- /dev/null +++ b/src/fheroes2/gui/interface_base.h @@ -0,0 +1,141 @@ +/*************************************************************************** + * fheroes2: https://github.com/ihhub/fheroes2 * + * Copyright (C) 2023 * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#pragma once + +#include + +#include "game_mode.h" +#include "gamedefs.h" +#include "interface_gamearea.h" +#include "interface_radar.h" +#include "interface_status.h" +#include "math_base.h" +#include "screen.h" + +namespace Interface +{ + enum Redraw : uint32_t + { + // The next values are base for game/editor. + + // To render the cursor over the previously generated radar map image. + REDRAW_RADAR_CURSOR = 0x01, + // To render radar map fully or in ROI and then the cursor over it. + REDRAW_RADAR = 0x02, + REDRAW_BORDER = 0x04, + REDRAW_GAMEAREA = 0x08, + REDRAW_STATUS = 0x10, + + // The next values are base for game (Adventure Map) interface. + REDRAW_HEROES = 0x20, + REDRAW_CASTLES = 0x40, + REDRAW_BUTTONS = 0x80, + + REDRAW_ICONS = REDRAW_HEROES | REDRAW_CASTLES, + + // The next value is base for Map Editor interface. + REDRAW_PANEL = 0x100, + + REDRAW_ALL = 0x1FF + }; + + class BaseInterface + { + public: + virtual ~BaseInterface() = default; + + virtual void redraw( const uint32_t force ) = 0; + + bool needRedraw() const + { + return _redraw != 0; + } + + void setRedraw( const uint32_t r ) + { + _redraw |= r; + } + + uint32_t getRedrawMask() const + { + return _redraw; + } + + static bool isScrollLeft( const fheroes2::Point & cursorPos ) + { + return cursorPos.x < BORDERWIDTH; + } + + static bool isScrollRight( const fheroes2::Point & cursorPos ) + { + const fheroes2::Display & display = fheroes2::Display::instance(); + + return cursorPos.x >= display.width() - BORDERWIDTH; + } + + static bool isScrollTop( const fheroes2::Point & cursorPos ) + { + return cursorPos.y < BORDERWIDTH; + } + + static bool isScrollBottom( const fheroes2::Point & cursorPos ) + { + const fheroes2::Display & display = fheroes2::Display::instance(); + + return cursorPos.y >= display.height() - BORDERWIDTH; + } + + GameArea & getGameArea() + { + return _gameArea; + } + + Radar & getRadar() + { + return _radar; + } + + StatusWindow & getStatusWindow() + { + return _statusWindow; + } + + static fheroes2::GameMode EventExit(); + + virtual void mouseCursorAreaClickLeft( const int32_t tileIndex ) = 0; + virtual void mouseCursorAreaPressRight( const int32_t tileIndex ) const = 0; + + // Regenerates the game area and updates the panel positions depending on the UI settings + virtual void reset() = 0; + + protected: + BaseInterface(); + + // If display fade-in state is set reset it to false and fade-in the full display image. Otherwise render full display image without fade-in. + void validateFadeInAndRender(); + + GameArea _gameArea; + Radar _radar; + StatusWindow _statusWindow; + + uint32_t _redraw{ 0 }; + }; +} diff --git a/src/fheroes2/gui/interface_buttons.cpp b/src/fheroes2/gui/interface_buttons.cpp index 346eeee8198..cf112c5be92 100644 --- a/src/fheroes2/gui/interface_buttons.cpp +++ b/src/fheroes2/gui/interface_buttons.cpp @@ -30,6 +30,7 @@ #include "game_interface.h" #include "heroes.h" #include "icn.h" +#include "interface_base.h" #include "kingdom.h" #include "localevent.h" #include "route.h" @@ -38,7 +39,7 @@ #include "ui_dialog.h" #include "world.h" -Interface::ButtonsArea::ButtonsArea( Basic & basic ) +Interface::ButtonsArea::ButtonsArea( AdventureMap & basic ) : BorderWindow( { 0, 0, 144, 72 } ) , interface( basic ) {} @@ -53,7 +54,7 @@ void Interface::ButtonsArea::SavePosition() void Interface::ButtonsArea::SetRedraw() const { - interface.SetRedraw( REDRAW_BUTTONS ); + interface.setRedraw( REDRAW_BUTTONS ); } void Interface::ButtonsArea::SetPos( int32_t ox, int32_t oy ) @@ -105,7 +106,7 @@ void Interface::ButtonsArea::SetPos( int32_t ox, int32_t oy ) systemRect = buttonSystem.area(); } -void Interface::ButtonsArea::Redraw() +void Interface::ButtonsArea::_redraw() { const Settings & conf = Settings::Get(); diff --git a/src/fheroes2/gui/interface_buttons.h b/src/fheroes2/gui/interface_buttons.h index 7cb7a1c9ae9..c9cb95ce3a4 100644 --- a/src/fheroes2/gui/interface_buttons.h +++ b/src/fheroes2/gui/interface_buttons.h @@ -1,6 +1,6 @@ /*************************************************************************** * fheroes2: https://github.com/ihhub/fheroes2 * - * Copyright (C) 2019 - 2022 * + * Copyright (C) 2019 - 2023 * * * * Free Heroes2 Engine: http://sourceforge.net/projects/fheroes2 * * Copyright (C) 2009 by Andrey Afletdinov * @@ -33,12 +33,12 @@ namespace Interface { - class Basic; + class AdventureMap; class ButtonsArea final : public BorderWindow { public: - explicit ButtonsArea( Basic & ); + explicit ButtonsArea( AdventureMap & ); ButtonsArea( const ButtonsArea & ) = delete; ~ButtonsArea() override = default; @@ -52,15 +52,14 @@ namespace Interface fheroes2::GameMode QueueEventProcessing(); void ResetButtons(); - private: - friend Basic; + // Do not call this method directly, use Interface::AdventureMap::redraw() instead to avoid issues in the "no interface" mode. + // The name of this method starts from _ on purpose to do not mix with other public methods. + void _redraw(); - // Do not call this method directly, use Interface::Basic::Redraw() instead - // to avoid issues in the "no interface" mode - void Redraw(); + private: void SetButtonStatus(); - Basic & interface; + AdventureMap & interface; fheroes2::Button buttonNextHero; fheroes2::Button buttonMovement; diff --git a/src/fheroes2/gui/interface_cpanel.cpp b/src/fheroes2/gui/interface_cpanel.cpp index e579d5fbf46..e2f8ffbe4af 100644 --- a/src/fheroes2/gui/interface_cpanel.cpp +++ b/src/fheroes2/gui/interface_cpanel.cpp @@ -1,6 +1,6 @@ /*************************************************************************** * fheroes2: https://github.com/ihhub/fheroes2 * - * Copyright (C) 2019 - 2022 * + * Copyright (C) 2019 - 2023 * * * * Free Heroes2 Engine: http://sourceforge.net/projects/fheroes2 * * Copyright (C) 2009 by Andrey Afletdinov * @@ -21,18 +21,19 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include "interface_cpanel.h" + #include #include "agg_image.h" #include "game_interface.h" #include "icn.h" #include "image.h" -#include "interface_cpanel.h" #include "localevent.h" #include "screen.h" #include "settings.h" -Interface::ControlPanel::ControlPanel( Basic & basic ) +Interface::ControlPanel::ControlPanel( AdventureMap & basic ) : interface( basic ) { width = 180; @@ -82,7 +83,7 @@ void Interface::ControlPanel::SetPos( int32_t ox, int32_t oy ) rt_end.y = y; } -void Interface::ControlPanel::Redraw() const +void Interface::ControlPanel::_redraw() const { assert( _buttons ); diff --git a/src/fheroes2/gui/interface_cpanel.h b/src/fheroes2/gui/interface_cpanel.h index be46854fb1b..48273774170 100644 --- a/src/fheroes2/gui/interface_cpanel.h +++ b/src/fheroes2/gui/interface_cpanel.h @@ -1,6 +1,6 @@ /*************************************************************************** * fheroes2: https://github.com/ihhub/fheroes2 * - * Copyright (C) 2019 - 2022 * + * Copyright (C) 2019 - 2023 * * * * Free Heroes2 Engine: http://sourceforge.net/projects/fheroes2 * * Copyright (C) 2009 by Andrey Afletdinov * @@ -37,12 +37,12 @@ namespace fheroes2 namespace Interface { - class Basic; + class AdventureMap; class ControlPanel final : protected fheroes2::Rect { public: - explicit ControlPanel( Basic & ); + explicit ControlPanel( AdventureMap & ); ControlPanel( const ControlPanel & ) = delete; ~ControlPanel() = default; @@ -55,14 +55,12 @@ namespace Interface const fheroes2::Rect & GetArea() const; - private: - friend Basic; - - // Do not call this method directly, use Interface::Basic::Redraw() instead - // to avoid issues in the "no interface" mode - void Redraw() const; + // Do not call this method directly, use Interface::AdventureMap::redraw() instead to avoid issues in the "no interface" mode. + // The name of this method starts from _ on purpose to do not mix with other public methods. + void _redraw() const; - Basic & interface; + private: + AdventureMap & interface; // We do not want to make a copy of images but to store just references to them. struct Buttons diff --git a/src/fheroes2/gui/interface_events.cpp b/src/fheroes2/gui/interface_events.cpp index c5f8565f368..df7707a5b8a 100644 --- a/src/fheroes2/gui/interface_events.cpp +++ b/src/fheroes2/gui/interface_events.cpp @@ -42,6 +42,7 @@ #include "game_over.h" #include "heroes.h" #include "image.h" +#include "interface_base.h" #include "interface_buttons.h" #include "interface_gamearea.h" #include "interface_icons.h" @@ -69,7 +70,7 @@ #include "view_world.h" #include "world.h" -void Interface::Basic::ShowPathOrStartMoveHero( Heroes * hero, const int32_t destinationIdx ) +void Interface::AdventureMap::ShowPathOrStartMoveHero( Heroes * hero, const int32_t destinationIdx ) { if ( hero == nullptr || !Maps::isValidAbsIndex( destinationIdx ) ) { return; @@ -84,7 +85,7 @@ void Interface::Basic::ShowPathOrStartMoveHero( Heroes * hero, const int32_t des DEBUG_LOG( DBG_GAME, DBG_TRACE, hero->GetName() << ", distance: " << world.getDistance( *hero, destinationIdx ) << ", route: " << path.String() ) - gameArea.SetRedraw(); + _gameArea.SetRedraw(); buttonsArea.SetRedraw(); } // Start the hero's movement @@ -96,7 +97,7 @@ void Interface::Basic::ShowPathOrStartMoveHero( Heroes * hero, const int32_t des } } -void Interface::Basic::MoveHeroFromArrowKeys( Heroes & hero, const int direction ) +void Interface::AdventureMap::MoveHeroFromArrowKeys( Heroes & hero, const int direction ) { const int32_t heroIndex = hero.GetIndex(); @@ -114,7 +115,7 @@ void Interface::Basic::MoveHeroFromArrowKeys( Heroes & hero, const int direction ShowPathOrStartMoveHero( &hero, dstIndex ); } -void Interface::Basic::EventNextHero() +void Interface::AdventureMap::EventNextHero() { const Kingdom & myKingdom = world.GetKingdom( Settings::Get().CurrentColor() ); const KingdomHeroes & myHeroes = myKingdom.GetHeroes(); @@ -152,7 +153,7 @@ void Interface::Basic::EventNextHero() RedrawFocus(); } -void Interface::Basic::EventContinueMovement() const +void Interface::AdventureMap::EventContinueMovement() const { Heroes * hero = GetFocusHeroes(); @@ -161,7 +162,7 @@ void Interface::Basic::EventContinueMovement() const } } -void Interface::Basic::EventKingdomInfo() const +void Interface::AdventureMap::EventKingdomInfo() const { Kingdom & myKingdom = world.GetKingdom( Settings::Get().CurrentColor() ); myKingdom.openOverviewDialog(); @@ -169,7 +170,7 @@ void Interface::Basic::EventKingdomInfo() const iconsPanel.SetRedraw(); } -void Interface::Basic::EventCastSpell() +void Interface::AdventureMap::EventCastSpell() { Heroes * hero = GetFocusHeroes(); if ( hero == nullptr ) { @@ -177,8 +178,8 @@ void Interface::Basic::EventCastSpell() } // Center on the hero before opening the spell book - gameArea.SetCenter( hero->GetCenter() ); - Redraw( REDRAW_GAMEAREA | REDRAW_RADAR_CURSOR ); + _gameArea.SetCenter( hero->GetCenter() ); + redraw( REDRAW_GAMEAREA | REDRAW_RADAR_CURSOR ); const Spell spell = hero->OpenSpellBook( SpellBook::Filter::ADVN, true, false, nullptr ); if ( spell.isValid() ) { @@ -191,7 +192,7 @@ void Interface::Basic::EventCastSpell() } } -fheroes2::GameMode Interface::Basic::EventEndTurn() const +fheroes2::GameMode Interface::AdventureMap::EventEndTurn() const { const Kingdom & myKingdom = world.GetKingdom( Settings::Get().CurrentColor() ); @@ -207,7 +208,7 @@ fheroes2::GameMode Interface::Basic::EventEndTurn() const return fheroes2::GameMode::CANCEL; } -fheroes2::GameMode Interface::Basic::EventAdventureDialog() +fheroes2::GameMode Interface::AdventureMap::EventAdventureDialog() { switch ( Dialog::AdventureOptions( GameFocus::HEROES == GetFocusType() ) ) { case Dialog::WORLD: @@ -231,22 +232,22 @@ fheroes2::GameMode Interface::Basic::EventAdventureDialog() return fheroes2::GameMode::CANCEL; } -void Interface::Basic::EventViewWorld() +void Interface::AdventureMap::EventViewWorld() { ViewWorld::ViewWorldWindow( Settings::Get().CurrentColor(), ViewWorldMode::OnlyVisible, *this ); } -fheroes2::GameMode Interface::Basic::EventFileDialog() const +fheroes2::GameMode Interface::AdventureMap::EventFileDialog() const { return Dialog::FileOptions(); } -void Interface::Basic::EventSystemDialog() const +void Interface::AdventureMap::EventSystemDialog() const { fheroes2::showSystemOptionsDialog(); } -fheroes2::GameMode Interface::Basic::EventExit() +fheroes2::GameMode Interface::BaseInterface::EventExit() { if ( Dialog::YES & fheroes2::showStandardTextMessage( "", _( "Are you sure you want to quit?" ), Dialog::YES | Dialog::NO ) ) return fheroes2::GameMode::QUIT_GAME; @@ -254,7 +255,7 @@ fheroes2::GameMode Interface::Basic::EventExit() return fheroes2::GameMode::CANCEL; } -void Interface::Basic::EventNextTown() +void Interface::AdventureMap::EventNextTown() { Kingdom & myKingdom = world.GetKingdom( Settings::Get().CurrentColor() ); KingdomCastles & myCastles = myKingdom.GetCastles(); @@ -274,14 +275,14 @@ void Interface::Basic::EventNextTown() } } -fheroes2::GameMode Interface::Basic::EventNewGame() const +fheroes2::GameMode Interface::AdventureMap::EventNewGame() const { return Dialog::YES == fheroes2::showStandardTextMessage( "", _( "Are you sure you want to restart? (Your current game will be lost.)" ), Dialog::YES | Dialog::NO ) ? fheroes2::GameMode::NEW_GAME : fheroes2::GameMode::CANCEL; } -fheroes2::GameMode Interface::Basic::EventSaveGame() const +fheroes2::GameMode Interface::AdventureMap::EventSaveGame() const { while ( true ) { const std::string filename = Dialog::SelectFileSave(); @@ -304,7 +305,7 @@ fheroes2::GameMode Interface::Basic::EventSaveGame() const } } -fheroes2::GameMode Interface::Basic::EventLoadGame() const +fheroes2::GameMode Interface::AdventureMap::EventLoadGame() const { return Dialog::YES == fheroes2::showStandardTextMessage( "", _( "Are you sure you want to load a new game? (Your current game will be lost.)" ), @@ -313,12 +314,12 @@ fheroes2::GameMode Interface::Basic::EventLoadGame() const : fheroes2::GameMode::CANCEL; } -void Interface::Basic::EventPuzzleMaps() const +void Interface::AdventureMap::EventPuzzleMaps() const { world.GetKingdom( Settings::Get().CurrentColor() ).PuzzleMaps().ShowMapsDialog(); } -fheroes2::GameMode Interface::Basic::EventScenarioInformation() +fheroes2::GameMode Interface::AdventureMap::EventScenarioInformation() { if ( Settings::Get().isCampaignGameType() ) { fheroes2::Display & display = fheroes2::Display::instance(); @@ -350,19 +351,19 @@ fheroes2::GameMode Interface::Basic::EventScenarioInformation() return fheroes2::GameMode::CANCEL; } -void Interface::Basic::EventSwitchHeroSleeping() +void Interface::AdventureMap::EventSwitchHeroSleeping() { Heroes * hero = GetFocusHeroes(); if ( hero ) { hero->Modes( Heroes::SLEEPER ) ? hero->ResetModes( Heroes::SLEEPER ) : hero->SetModes( Heroes::SLEEPER ); - SetRedraw( REDRAW_HEROES ); + setRedraw( REDRAW_HEROES ); buttonsArea.SetRedraw(); } } -fheroes2::GameMode Interface::Basic::EventDigArtifact() +fheroes2::GameMode Interface::AdventureMap::EventDigArtifact() { Heroes * hero = GetFocusHeroes(); if ( hero == nullptr ) { @@ -421,7 +422,7 @@ fheroes2::GameMode Interface::Basic::EventDigArtifact() fheroes2::showStandardTextMessage( "", _( "Nothing here. Where could it be?" ), Dialog::OK ); } - Redraw( REDRAW_HEROES ); + redraw( REDRAW_HEROES ); fheroes2::Display::instance().render(); // check if the game is over due to conditions related to the ultimate artifact @@ -433,7 +434,7 @@ fheroes2::GameMode Interface::Basic::EventDigArtifact() return fheroes2::GameMode::CANCEL; } -fheroes2::GameMode Interface::Basic::EventDefaultAction( const fheroes2::GameMode gameMode ) +fheroes2::GameMode Interface::AdventureMap::EventDefaultAction( const fheroes2::GameMode gameMode ) { Heroes * hero = GetFocusHeroes(); @@ -463,7 +464,7 @@ fheroes2::GameMode Interface::Basic::EventDefaultAction( const fheroes2::GameMod return gameMode; } -void Interface::Basic::EventOpenFocus() const +void Interface::AdventureMap::EventOpenFocus() const { if ( GetFocusHeroes() ) Game::OpenHeroesDialog( *GetFocusHeroes(), true, true ); @@ -471,30 +472,30 @@ void Interface::Basic::EventOpenFocus() const Game::OpenCastleDialog( *GetFocusCastle() ); } -void Interface::Basic::EventSwitchShowRadar() const +void Interface::AdventureMap::EventSwitchShowRadar() const { Settings & conf = Settings::Get(); if ( conf.isHideInterfaceEnabled() ) { if ( conf.ShowRadar() ) { conf.SetShowRadar( false ); - gameArea.SetRedraw(); + _gameArea.SetRedraw(); } else { conf.SetShowRadar( true ); - radar.SetRedraw( REDRAW_RADAR ); + _radar.SetRedraw( REDRAW_RADAR ); } } } -void Interface::Basic::EventSwitchShowButtons() const +void Interface::AdventureMap::EventSwitchShowButtons() const { Settings & conf = Settings::Get(); if ( conf.isHideInterfaceEnabled() ) { if ( conf.ShowButtons() ) { conf.SetShowButtons( false ); - gameArea.SetRedraw(); + _gameArea.SetRedraw(); } else { conf.SetShowButtons( true ); @@ -503,30 +504,30 @@ void Interface::Basic::EventSwitchShowButtons() const } } -void Interface::Basic::EventSwitchShowStatus() const +void Interface::AdventureMap::EventSwitchShowStatus() const { Settings & conf = Settings::Get(); if ( conf.isHideInterfaceEnabled() ) { if ( conf.ShowStatus() ) { conf.SetShowStatus( false ); - gameArea.SetRedraw(); + _gameArea.SetRedraw(); } else { conf.SetShowStatus( true ); - statusWindow.SetRedraw(); + _statusWindow.SetRedraw(); } } } -void Interface::Basic::EventSwitchShowIcons() const +void Interface::AdventureMap::EventSwitchShowIcons() const { Settings & conf = Settings::Get(); if ( conf.isHideInterfaceEnabled() ) { if ( conf.ShowIcons() ) { conf.SetShowIcons( false ); - gameArea.SetRedraw(); + _gameArea.SetRedraw(); } else { conf.SetShowIcons( true ); @@ -535,17 +536,17 @@ void Interface::Basic::EventSwitchShowIcons() const } } -void Interface::Basic::EventSwitchShowControlPanel() const +void Interface::AdventureMap::EventSwitchShowControlPanel() const { Settings & conf = Settings::Get(); if ( conf.isHideInterfaceEnabled() ) { conf.SetShowControlPanel( !conf.ShowControlPanel() ); - gameArea.SetRedraw(); + _gameArea.SetRedraw(); } } -void Interface::Basic::EventKeyArrowPress( int dir ) +void Interface::AdventureMap::EventKeyArrowPress( int dir ) { Heroes * hero = GetFocusHeroes(); @@ -556,32 +557,32 @@ void Interface::Basic::EventKeyArrowPress( int dir ) // scroll map switch ( dir ) { case Direction::TOP_LEFT: - gameArea.SetScroll( SCROLL_TOP ); - gameArea.SetScroll( SCROLL_LEFT ); + _gameArea.SetScroll( SCROLL_TOP ); + _gameArea.SetScroll( SCROLL_LEFT ); break; case Direction::TOP: - gameArea.SetScroll( SCROLL_TOP ); + _gameArea.SetScroll( SCROLL_TOP ); break; case Direction::TOP_RIGHT: - gameArea.SetScroll( SCROLL_TOP ); - gameArea.SetScroll( SCROLL_RIGHT ); + _gameArea.SetScroll( SCROLL_TOP ); + _gameArea.SetScroll( SCROLL_RIGHT ); break; case Direction::RIGHT: - gameArea.SetScroll( SCROLL_RIGHT ); + _gameArea.SetScroll( SCROLL_RIGHT ); break; case Direction::BOTTOM_RIGHT: - gameArea.SetScroll( SCROLL_BOTTOM ); - gameArea.SetScroll( SCROLL_RIGHT ); + _gameArea.SetScroll( SCROLL_BOTTOM ); + _gameArea.SetScroll( SCROLL_RIGHT ); break; case Direction::BOTTOM: - gameArea.SetScroll( SCROLL_BOTTOM ); + _gameArea.SetScroll( SCROLL_BOTTOM ); break; case Direction::BOTTOM_LEFT: - gameArea.SetScroll( SCROLL_BOTTOM ); - gameArea.SetScroll( SCROLL_LEFT ); + _gameArea.SetScroll( SCROLL_BOTTOM ); + _gameArea.SetScroll( SCROLL_LEFT ); break; case Direction::LEFT: - gameArea.SetScroll( SCROLL_LEFT ); + _gameArea.SetScroll( SCROLL_LEFT ); break; default: break; diff --git a/src/fheroes2/gui/interface_focus.cpp b/src/fheroes2/gui/interface_focus.cpp index 611208dbdf9..29ccd807878 100644 --- a/src/fheroes2/gui/interface_focus.cpp +++ b/src/fheroes2/gui/interface_focus.cpp @@ -31,6 +31,7 @@ #include "game.h" #include "game_interface.h" #include "heroes.h" +#include "interface_base.h" #include "interface_gamearea.h" #include "interface_icons.h" #include "interface_status.h" @@ -41,7 +42,7 @@ #include "settings.h" #include "world.h" -void Interface::Basic::SetFocus( Heroes * hero, const bool retainScrollBarPosition ) +void Interface::AdventureMap::SetFocus( Heroes * hero, const bool retainScrollBarPosition ) { assert( hero != nullptr ); @@ -67,14 +68,14 @@ void Interface::Basic::SetFocus( Heroes * hero, const bool retainScrollBarPositi hero->ShowPath( true ); focus.Set( hero ); - Redraw( REDRAW_BUTTONS ); + redraw( REDRAW_BUTTONS ); if ( !retainScrollBarPosition ) { iconsPanel.Select( hero ); } - gameArea.SetCenter( hero->GetCenter() ); - statusWindow.SetState( StatusType::STATUS_ARMY ); + _gameArea.SetCenter( hero->GetCenter() ); + _statusWindow.SetState( StatusType::STATUS_ARMY ); const int heroIndex = hero->GetIndex(); if ( Game::UpdateSoundsOnFocusUpdate() && heroIndex >= 0 ) { @@ -83,7 +84,7 @@ void Interface::Basic::SetFocus( Heroes * hero, const bool retainScrollBarPositi } } -void Interface::Basic::SetFocus( Castle * castle ) +void Interface::AdventureMap::SetFocus( Castle * castle ) { assert( castle != nullptr ); @@ -103,11 +104,11 @@ void Interface::Basic::SetFocus( Castle * castle ) focus.Set( castle ); - Redraw( REDRAW_BUTTONS ); + redraw( REDRAW_BUTTONS ); iconsPanel.Select( castle ); - gameArea.SetCenter( castle->GetCenter() ); - statusWindow.SetState( StatusType::STATUS_FUNDS ); + _gameArea.SetCenter( castle->GetCenter() ); + _statusWindow.SetState( StatusType::STATUS_FUNDS ); if ( Game::UpdateSoundsOnFocusUpdate() ) { Game::EnvironmentSoundMixer(); @@ -115,7 +116,7 @@ void Interface::Basic::SetFocus( Castle * castle ) } } -void Interface::Basic::updateFocus() +void Interface::AdventureMap::updateFocus() { Player * player = Settings::Get().GetPlayers().GetCurrent(); @@ -141,7 +142,7 @@ void Interface::Basic::updateFocus() } } -void Interface::Basic::ResetFocus( const int priority, const bool retainScrollBarPosition ) +void Interface::AdventureMap::ResetFocus( const int priority, const bool retainScrollBarPosition ) { Player * player = Settings::Get().GetPlayers().GetCurrent(); if ( player == nullptr ) { @@ -236,7 +237,7 @@ Heroes * Interface::GetFocusHeroes() return player ? player->GetFocus().GetHeroes() : nullptr; } -void Interface::Basic::RedrawFocus() +void Interface::AdventureMap::RedrawFocus() { int type = GetFocusType(); @@ -258,12 +259,12 @@ void Interface::Basic::RedrawFocus() iconsPanel.SetRedraw(); } - SetRedraw( REDRAW_GAMEAREA | REDRAW_RADAR_CURSOR ); + setRedraw( REDRAW_GAMEAREA | REDRAW_RADAR_CURSOR ); if ( type == FOCUS_HEROES ) iconsPanel.SetRedraw( ICON_HEROES ); else if ( type == FOCUS_CASTLE ) iconsPanel.SetRedraw( ICON_CASTLES ); - statusWindow.SetRedraw(); + _statusWindow.SetRedraw(); } diff --git a/src/fheroes2/gui/interface_gamearea.cpp b/src/fheroes2/gui/interface_gamearea.cpp index bc76f5ea5d3..577f5716176 100644 --- a/src/fheroes2/gui/interface_gamearea.cpp +++ b/src/fheroes2/gui/interface_gamearea.cpp @@ -42,6 +42,7 @@ #include "ground.h" #include "heroes.h" #include "icn.h" +#include "interface_base.h" #include "interface_cpanel.h" #include "localevent.h" #include "logging.h" @@ -308,8 +309,8 @@ namespace } } -Interface::GameArea::GameArea( Basic & basic ) - : interface( basic ) +Interface::GameArea::GameArea( BaseInterface & interface ) + : _interface( interface ) , _minLeftOffset( 0 ) , _maxLeftOffset( 0 ) , _minTopOffset( 0 ) @@ -738,7 +739,7 @@ void Interface::GameArea::Redraw( fheroes2::Image & dst, int flag, bool isPuzzle } } } - else + else { #endif // redraw fog if ( renderFog ) { @@ -761,6 +762,9 @@ void Interface::GameArea::Redraw( fheroes2::Image & dst, int flag, bool isPuzzle } } } +#ifdef WITH_DEBUG + } +#endif updateObjectAnimationInfo(); } @@ -805,7 +809,7 @@ void Interface::GameArea::Scroll() void Interface::GameArea::SetRedraw() const { - interface.SetRedraw( REDRAW_GAMEAREA ); + _interface.setRedraw( REDRAW_GAMEAREA ); } fheroes2::Image Interface::GameArea::GenerateUltimateArtifactAreaSurface( const int32_t index, const fheroes2::Point & offset ) @@ -819,7 +823,7 @@ fheroes2::Image Interface::GameArea::GenerateUltimateArtifactAreaSurface( const result.reset(); // Make a temporary copy - GameArea gamearea = Basic::Get().GetGameArea(); + GameArea gamearea = AdventureMap::Get().getGameArea(); gamearea.SetAreaPosition( 0, 0, result.width(), result.height() ); @@ -933,7 +937,7 @@ void Interface::GameArea::QueueEventProcessing( bool isCursorOverGamearea ) // change cursor if need if ( ( updateCursor || index != _prevIndexPos ) && isCursorOverGamearea ) { - Cursor::Get().SetThemes( Interface::Basic::GetCursorTileIndex( index ) ); + Cursor::Get().SetThemes( Interface::AdventureMap::GetCursorTileIndex( index ) ); _prevIndexPos = index; updateCursor = false; } @@ -943,7 +947,7 @@ void Interface::GameArea::QueueEventProcessing( bool isCursorOverGamearea ) return; const Settings & conf = Settings::Get(); - if ( conf.isHideInterfaceEnabled() && conf.ShowControlPanel() && le.MouseCursor( interface.GetControlPanel().GetArea() ) ) + if ( conf.isHideInterfaceEnabled() && conf.ShowControlPanel() && le.MouseCursor( Interface::AdventureMap::Get().getControlPanel().GetArea() ) ) return; const fheroes2::Point tileOffset = _topLeftTileOffset + mousePosition - _windowROI.getPosition(); @@ -953,9 +957,9 @@ void Interface::GameArea::QueueEventProcessing( bool isCursorOverGamearea ) const fheroes2::Rect tileROI( tilePos.x, tilePos.y, TILEWIDTH, TILEWIDTH ); if ( le.MouseClickLeft( tileROI ) ) - interface.MouseCursorAreaClickLeft( index ); + _interface.mouseCursorAreaClickLeft( index ); else if ( le.MousePressRight( tileROI ) && isCursorOverGamearea ) - interface.MouseCursorAreaPressRight( index ); + _interface.mouseCursorAreaPressRight( index ); } fheroes2::Point Interface::GameArea::_getStartTileId() const @@ -1055,11 +1059,11 @@ void Interface::GameArea::runSingleObjectAnimation( const std::shared_ptrisAnimationCompleted() ) { if ( Game::validateAnimationDelay( Game::HEROES_PICKUP_DELAY ) ) { - basicInterface.Redraw( Interface::REDRAW_GAMEAREA ); + adventureMapInterface.redraw( Interface::REDRAW_GAMEAREA ); display.render(); } } diff --git a/src/fheroes2/gui/interface_gamearea.h b/src/fheroes2/gui/interface_gamearea.h index 71735d554e3..2fd5ccf1c47 100644 --- a/src/fheroes2/gui/interface_gamearea.h +++ b/src/fheroes2/gui/interface_gamearea.h @@ -37,7 +37,7 @@ namespace Interface { - class Basic; + class BaseInterface; enum ScrollingType { @@ -150,7 +150,7 @@ namespace Interface class GameArea { public: - explicit GameArea( Basic & basic ); + explicit GameArea( BaseInterface & interface ); GameArea( const GameArea & ) = default; GameArea( GameArea && ) = delete; @@ -262,7 +262,7 @@ namespace Interface } private: - Basic & interface; + BaseInterface & _interface; fheroes2::Rect _windowROI; // visible to draw area of World Map in pixels fheroes2::Point _topLeftTileOffset; // offset of tiles to be drawn (from here we can find any tile ID) diff --git a/src/fheroes2/gui/interface_icons.cpp b/src/fheroes2/gui/interface_icons.cpp index c44ce50baf7..0cee53f463f 100644 --- a/src/fheroes2/gui/interface_icons.cpp +++ b/src/fheroes2/gui/interface_icons.cpp @@ -31,6 +31,7 @@ #include "heroes.h" #include "heroes_base.h" #include "icn.h" +#include "interface_base.h" #include "kingdom.h" #include "maps.h" #include "screen.h" @@ -126,12 +127,12 @@ void Interface::CastleIcons::RedrawBackground( const fheroes2::Point & pos ) void Interface::CastleIcons::ActionCurrentUp() { - Interface::Basic::Get().SetFocus( GetCurrent() ); + Interface::AdventureMap::Get().SetFocus( GetCurrent() ); } void Interface::CastleIcons::ActionCurrentDn() { - Interface::Basic::Get().SetFocus( GetCurrent() ); + Interface::AdventureMap::Get().SetFocus( GetCurrent() ); } void Interface::CastleIcons::ActionListDoubleClick( CASTLE & item ) @@ -144,7 +145,7 @@ void Interface::CastleIcons::ActionListDoubleClick( CASTLE & item ) void Interface::CastleIcons::ActionListSingleClick( CASTLE & item ) { if ( item ) { - Interface::Basic & I = Interface::Basic::Get(); + Interface::AdventureMap & I = Interface::AdventureMap::Get(); I.SetFocus( item ); I.RedrawFocus(); @@ -219,12 +220,12 @@ void Interface::HeroesIcons::RedrawBackground( const fheroes2::Point & pos ) void Interface::HeroesIcons::ActionCurrentUp() { - Interface::Basic::Get().SetFocus( GetCurrent(), false ); + Interface::AdventureMap::Get().SetFocus( GetCurrent(), false ); } void Interface::HeroesIcons::ActionCurrentDn() { - Interface::Basic::Get().SetFocus( GetCurrent(), false ); + Interface::AdventureMap::Get().SetFocus( GetCurrent(), false ); } void Interface::HeroesIcons::ActionListDoubleClick( HEROES & item ) @@ -237,7 +238,7 @@ void Interface::HeroesIcons::ActionListDoubleClick( HEROES & item ) void Interface::HeroesIcons::ActionListSingleClick( HEROES & item ) { if ( item ) { - Interface::Basic & I = Interface::Basic::Get(); + Interface::AdventureMap & I = Interface::AdventureMap::Get(); I.SetFocus( item, false ); I.RedrawFocus(); @@ -295,7 +296,7 @@ void Interface::HeroesIcons::SetPos( int32_t px, int32_t py ) } } -Interface::IconsPanel::IconsPanel( Basic & basic ) +Interface::IconsPanel::IconsPanel( AdventureMap & basic ) : BorderWindow( { 0, 0, 144, 128 } ) , interface( basic ) , castleIcons( 4, sfMarker ) @@ -320,16 +321,16 @@ void Interface::IconsPanel::SetRedraw( const icons_t type ) const if ( IconsBar::IsVisible() ) { switch ( type ) { case ICON_HEROES: - interface.SetRedraw( REDRAW_HEROES ); + interface.setRedraw( REDRAW_HEROES ); break; case ICON_CASTLES: - interface.SetRedraw( REDRAW_CASTLES ); + interface.setRedraw( REDRAW_CASTLES ); break; default: break; } - interface.SetRedraw( REDRAW_ICONS ); + interface.setRedraw( REDRAW_ICONS ); } } @@ -361,7 +362,7 @@ void Interface::IconsPanel::SetPos( int32_t ox, int32_t oy ) castleIcons.SetPos( rect.x + 72, rect.y ); } -void Interface::IconsPanel::Redraw() +void Interface::IconsPanel::_redraw() { // is visible if ( IconsBar::IsVisible() ) { @@ -455,7 +456,7 @@ void Interface::IconsPanel::ShowIcons( const icons_t type ) castleIcons.SetShow( true ); } -void Interface::IconsPanel::RedrawIcons( const icons_t type ) +void Interface::IconsPanel::_redrawIcons( const icons_t type ) { if ( type & ICON_HEROES ) heroesIcons.Redraw(); diff --git a/src/fheroes2/gui/interface_icons.h b/src/fheroes2/gui/interface_icons.h index 000c2d9cc99..a159b2e742b 100644 --- a/src/fheroes2/gui/interface_icons.h +++ b/src/fheroes2/gui/interface_icons.h @@ -1,6 +1,6 @@ /*************************************************************************** * fheroes2: https://github.com/ihhub/fheroes2 * - * Copyright (C) 2019 - 2022 * + * Copyright (C) 2019 - 2023 * * * * Free Heroes2 Engine: http://sourceforge.net/projects/fheroes2 * * Copyright (C) 2009 by Andrey Afletdinov * @@ -44,7 +44,7 @@ enum icons_t namespace Interface { - class Basic; + class AdventureMap; using HEROES = Heroes *; using CASTLE = Castle *; @@ -163,7 +163,7 @@ namespace Interface class IconsPanel final : public BorderWindow { public: - explicit IconsPanel( Basic & basic ); + explicit IconsPanel( AdventureMap & basic ); IconsPanel( const IconsPanel & ) = delete; ~IconsPanel() override = default; @@ -185,15 +185,14 @@ namespace Interface void HideIcons( const icons_t type ); void ShowIcons( const icons_t type ); - private: - friend Basic; - - // Do not call these methods directly, use Interface::Basic::Redraw() instead - // to avoid issues in the "no interface" mode - void Redraw(); - void RedrawIcons( const icons_t type ); + // Do not call this method directly, use Interface::AdventureMap::redraw() instead to avoid issues in the "no interface" mode. + // The name of this method starts from _ on purpose to do not mix with other public methods. + void _redraw(); + // The name of this method starts from _ on purpose to do not mix with other public methods. + void _redrawIcons( const icons_t type ); - Basic & interface; + private: + AdventureMap & interface; fheroes2::Image sfMarker; diff --git a/src/fheroes2/gui/interface_radar.cpp b/src/fheroes2/gui/interface_radar.cpp index 377b8479d69..9e539f4cc64 100644 --- a/src/fheroes2/gui/interface_radar.cpp +++ b/src/fheroes2/gui/interface_radar.cpp @@ -31,11 +31,11 @@ #include "castle.h" #include "color.h" #include "dialog.h" -#include "game_interface.h" #include "gamedefs.h" #include "ground.h" #include "heroes.h" #include "icn.h" +#include "interface_base.h" #include "interface_gamearea.h" #include "localevent.h" #include "maps.h" @@ -142,10 +142,10 @@ namespace } } -Interface::Radar::Radar( Basic & basic ) +Interface::Radar::Radar( BaseInterface & interface ) : BorderWindow( { 0, 0, RADARWIDTH, RADARWIDTH } ) , _radarType( RadarType::WorldMap ) - , _interface( basic ) + , _interface( interface ) { // Radar image can not be transparent so we disable the transform layer to speed up rendering. _map._disableTransformLayer(); @@ -200,7 +200,7 @@ void Interface::Radar::SetRedraw( const uint32_t redrawMode ) const // Only radar redraws are allowed here. assert( ( redrawMode & ~( REDRAW_RADAR_CURSOR | REDRAW_RADAR ) ) == 0 ); - _interface.SetRedraw( redrawMode ); + _interface.setRedraw( redrawMode ); } void Interface::Radar::SetRenderArea( const fheroes2::Rect & roi ) @@ -213,7 +213,7 @@ void Interface::Radar::SetRenderArea( const fheroes2::Rect & roi ) } } -void Interface::Radar::Redraw( const bool redrawMapObjects ) +void Interface::Radar::_redraw( const bool redrawMapObjects ) { const Settings & conf = Settings::Get(); if ( conf.isHideInterfaceEnabled() ) { @@ -267,6 +267,20 @@ void Interface::Radar::RedrawForViewWorld( const ViewWorld::ZoomROIs & roi, cons RedrawCursor( &roiInTiles ); } +void Interface::Radar::redrawForEditor( const bool renderMapObjects ) +{ + _cursorArea.hide(); + + if ( renderMapObjects ) { + RedrawObjects( 0, ViewWorldMode::ViewAll ); + const fheroes2::Rect & rect = GetArea(); + fheroes2::Copy( _map, 0, 0, fheroes2::Display::instance(), rect.x, rect.y, _map.width(), _map.height() ); + } + + _cursorArea.show(); + RedrawCursor(); +} + void Interface::Radar::RedrawObjects( const int32_t playerColor, const ViewWorldMode flags ) { #ifdef WITH_DEBUG @@ -415,7 +429,7 @@ void Interface::Radar::RedrawCursor( const fheroes2::Rect * roiRectangle /* =nul return; } - const fheroes2::Rect & viewableWorldArea = ( roiRectangle == nullptr ) ? _interface.GetGameArea().GetVisibleTileROI() : *roiRectangle; + const fheroes2::Rect & viewableWorldArea = ( roiRectangle == nullptr ) ? _interface.getGameArea().GetVisibleTileROI() : *roiRectangle; if ( ( viewableWorldArea.width > worldSize.width ) && ( viewableWorldArea.height > worldSize.height ) ) { // We hide the cursor if the whole map is displayed. @@ -457,7 +471,7 @@ void Interface::Radar::QueueEventProcessing() // Move border window if ( conf.ShowRadar() && BorderWindow::QueueEventProcessing() ) { _cursorArea.hide(); - _interface.SetRedraw( REDRAW_RADAR_CURSOR ); + _interface.setRedraw( REDRAW_RADAR_CURSOR ); } else if ( le.MouseCursor( rect ) ) { // move cursor @@ -466,13 +480,13 @@ void Interface::Radar::QueueEventProcessing() const fheroes2::Point & pt = le.GetMouseCursor(); if ( rect & pt ) { - GameArea & gamearea = _interface.GetGameArea(); + GameArea & gamearea = _interface.getGameArea(); fheroes2::Rect visibleROI( gamearea.GetVisibleTileROI() ); const fheroes2::Point prev( visibleROI.x, visibleROI.y ); gamearea.SetCenter( { ( pt.x - rect.x ) * world.w() / rect.width, ( pt.y - rect.y ) * world.h() / rect.height } ); visibleROI = gamearea.GetVisibleTileROI(); if ( prev.x != visibleROI.x || prev.y != visibleROI.y ) { - _interface.SetRedraw( REDRAW_RADAR_CURSOR ); + _interface.setRedraw( REDRAW_RADAR_CURSOR ); gamearea.SetRedraw(); } } diff --git a/src/fheroes2/gui/interface_radar.h b/src/fheroes2/gui/interface_radar.h index ed4675fd0a7..46bbff24c2e 100644 --- a/src/fheroes2/gui/interface_radar.h +++ b/src/fheroes2/gui/interface_radar.h @@ -40,12 +40,12 @@ namespace fheroes2 namespace Interface { - class Basic; + class BaseInterface; class Radar final : public BorderWindow { public: - explicit Radar( Basic & ); + explicit Radar( BaseInterface & interface ); // Creates a radar with a fixed position at the top right of the screen, // based on an existing radar and suitable for the View World window Radar( const Radar & radar, const fheroes2::Display & display ); @@ -57,7 +57,7 @@ namespace Interface void SetPos( int32_t ox, int32_t oy ) override; - // Set the render redraw flag from Interface::redraw_t enumeration: + // Set the render redraw flag from Interface::Redraw enumeration: // - 'REDRAW_RADAR' - to redraw the radar map image fully or in ROI and render the cursor over it. // - 'REDRAW_RADAR_CURSOR' - to render the previously generated radar map image and the cursor over it. void SetRedraw( const uint32_t redrawMode ) const; @@ -66,6 +66,7 @@ namespace Interface void SetRenderArea( const fheroes2::Rect & roi ); void Build(); void RedrawForViewWorld( const ViewWorld::ZoomROIs & roi, ViewWorldMode mode, const bool renderMapObjects ); + void redrawForEditor( const bool renderMapObjects ); void SetHide( bool f ) { @@ -80,9 +81,11 @@ namespace Interface return _mouseDraggingMovement; } - private: - friend Basic; + // Do not call this method directly, use Interface::AdventureMap::redraw() instead to avoid issues in the "no interface" mode. + // The name of this method starts from _ on purpose to do not mix with other public methods. + void _redraw( const bool redrawMapObjects ); + private: enum class RadarType : char { WorldMap, @@ -92,14 +95,11 @@ namespace Interface void SavePosition() override; void SetZoom(); - // Do not call this method directly, use Interface::Basic::Redraw() instead - // to avoid issues in the "no interface" mode - void Redraw( const bool redrawMapObjects ); void RedrawObjects( const int32_t playerColor, const ViewWorldMode flags ); void RedrawCursor( const fheroes2::Rect * roiRectangle = nullptr ); RadarType _radarType; - Basic & _interface; + BaseInterface & _interface; fheroes2::Image _map{ RADARWIDTH, RADARWIDTH }; fheroes2::MovableSprite _cursorArea; diff --git a/src/fheroes2/gui/interface_status.cpp b/src/fheroes2/gui/interface_status.cpp index e2a8e36c473..6d05a6020ac 100644 --- a/src/fheroes2/gui/interface_status.cpp +++ b/src/fheroes2/gui/interface_status.cpp @@ -21,6 +21,8 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include "interface_status.h" + #include #include @@ -36,7 +38,7 @@ #include "heroes.h" #include "icn.h" #include "image.h" -#include "interface_status.h" +#include "interface_base.h" #include "kingdom.h" #include "localevent.h" #include "math_base.h" @@ -54,9 +56,9 @@ namespace const uint32_t resourceWindowExpireTime = 2500; } -Interface::StatusWindow::StatusWindow( Basic & basic ) +Interface::StatusWindow::StatusWindow( BaseInterface & interface ) : BorderWindow( { 0, 0, 144, 72 } ) - , interface( basic ) + , _interface( interface ) , _state( StatusType::STATUS_UNKNOWN ) , lastResource( Resource::UNKNOWN ) , countLastResource( 0 ) @@ -81,7 +83,7 @@ void Interface::StatusWindow::SavePosition() void Interface::StatusWindow::SetRedraw() const { - interface.SetRedraw( REDRAW_STATUS ); + _interface.setRedraw( REDRAW_STATUS ); } void Interface::StatusWindow::SetPos( int32_t ox, int32_t oy ) @@ -106,7 +108,7 @@ void Interface::StatusWindow::SetState( const StatusType status ) } } -void Interface::StatusWindow::Redraw() const +void Interface::StatusWindow::_redraw() const { const Settings & conf = Settings::Get(); if ( conf.isHideInterfaceEnabled() && !conf.ShowStatus() ) { @@ -479,12 +481,12 @@ void Interface::StatusWindow::DrawAITurnProgress( const uint32_t progressValue ) turn_progress = progressValue; - interface.SetRedraw( REDRAW_STATUS ); + _interface.setRedraw( REDRAW_STATUS ); if ( Game::validateAnimationDelay( Game::MAPS_DELAY ) ) { Game::updateAdventureMapAnimationIndex(); - interface.Redraw( REDRAW_GAMEAREA ); + _interface.redraw( REDRAW_GAMEAREA ); fheroes2::Display::instance().render(); } } diff --git a/src/fheroes2/gui/interface_status.h b/src/fheroes2/gui/interface_status.h index b8a0b3cddc9..fba87d89584 100644 --- a/src/fheroes2/gui/interface_status.h +++ b/src/fheroes2/gui/interface_status.h @@ -1,6 +1,6 @@ /*************************************************************************** * fheroes2: https://github.com/ihhub/fheroes2 * - * Copyright (C) 2019 - 2022 * + * Copyright (C) 2019 - 2023 * * * * Free Heroes2 Engine: http://sourceforge.net/projects/fheroes2 * * Copyright (C) 2009 by Andrey Afletdinov * @@ -31,7 +31,7 @@ namespace Interface { - class Basic; + class BaseInterface; enum class StatusType : int { @@ -46,7 +46,7 @@ namespace Interface class StatusWindow final : public BorderWindow { public: - explicit StatusWindow( Basic & basic ); + explicit StatusWindow( BaseInterface & interface ); StatusWindow( const StatusWindow & ) = delete; ~StatusWindow() override = default; @@ -67,12 +67,11 @@ namespace Interface void QueueEventProcessing(); void TimerEventProcessing(); - private: - friend Basic; + // Do not call this method directly, use Interface::AdventureMap::redraw() instead to avoid issues in the "no interface" mode. + // The name of this method starts from _ on purpose to do not mix with other public methods. + void _redraw() const; - // Do not call this method directly, use Interface::Basic::Redraw() instead - // to avoid issues in the "no interface" mode - void Redraw() const; + private: void DrawKingdomInfo( int oh = 0 ) const; void DrawDayInfo( int oh = 0 ) const; void DrawArmyInfo( int oh = 0 ) const; @@ -80,7 +79,7 @@ namespace Interface void DrawBackground() const; void DrawAITurns() const; - Basic & interface; + BaseInterface & _interface; StatusType _state; int lastResource; diff --git a/src/fheroes2/heroes/heroes_action.cpp b/src/fheroes2/heroes/heroes_action.cpp index ffd6c0bb782..055a87ace11 100644 --- a/src/fheroes2/heroes/heroes_action.cpp +++ b/src/fheroes2/heroes/heroes_action.cpp @@ -50,6 +50,7 @@ #include "heroes.h" #include "icn.h" #include "image.h" +#include "interface_base.h" #include "interface_gamearea.h" #include "interface_radar.h" #include "interface_status.h" @@ -206,15 +207,15 @@ namespace hero.FadeOut(); hero.SetFreeman( reason ); - Interface::Basic & I = Interface::Basic::Get(); + Interface::AdventureMap & I = Interface::AdventureMap::Get(); if ( !hero.GetKingdom().isLoss() ) { // If the enemy is not vanquished we update only position of defeated hero on radar to remove hero mark. const fheroes2::Point heroPosition = hero.GetCenter(); - I.GetRadar().SetRenderArea( { heroPosition.x, heroPosition.y, 1, 1 } ); + I.getRadar().SetRenderArea( { heroPosition.x, heroPosition.y, 1, 1 } ); } // If the enemy is vanquished we do not set radar ROI and fully redraw the radar map image as there might be color reset of enemy's objects. - I.SetRedraw( Interface::REDRAW_RADAR ); + I.setRedraw( Interface::REDRAW_RADAR ); } void RecruitMonsterFromTile( Heroes & hero, Maps::Tiles & tile, const std::string & msg, const Troop & troop, bool remove ) @@ -230,7 +231,7 @@ namespace setMonsterCountOnTile( tile, 0 ); - Interface::Basic::Get().GetGameArea().runSingleObjectAnimation( + Interface::AdventureMap::Get().getGameArea().runSingleObjectAnimation( std::make_shared( tile.GetObjectUID(), tile.GetIndex(), tile.GetObject() ) ); } else { @@ -242,7 +243,7 @@ namespace hero.GetArmy().JoinTroop( troop.GetMonster(), recruit, false ); - Interface::Basic::Get().SetRedraw( Interface::REDRAW_STATUS ); + Interface::AdventureMap::Get().setRedraw( Interface::REDRAW_STATUS ); } } } @@ -281,7 +282,7 @@ namespace weakestTroop->SetCount( newCount ); } - Interface::Basic::Get().SetRedraw( Interface::REDRAW_STATUS ); + Interface::AdventureMap::Get().setRedraw( Interface::REDRAW_STATUS ); } } @@ -290,7 +291,7 @@ namespace Maps::Tiles & tile = world.GetTiles( dst_index ); Troop troop = getTroopFromTile( tile ); - Interface::Basic & I = Interface::Basic::Get(); + Interface::AdventureMap & I = Interface::AdventureMap::Get(); bool destroy = false; @@ -323,7 +324,7 @@ namespace if ( Dialog::YES == Dialog::ArmyJoinFree( troop ) ) { hero.GetArmy().JoinTroop( troop ); - I.SetRedraw( Interface::REDRAW_STATUS ); + I.setRedraw( Interface::REDRAW_STATUS ); destroy = true; } else { @@ -342,7 +343,7 @@ namespace hero.GetArmy().JoinTroop( troop.GetMonster(), join.monsterCount, false ); hero.GetKingdom().OddFundsResource( Funds( Resource::GOLD, joiningCost ) ); - I.SetRedraw( Interface::REDRAW_STATUS ); + I.setRedraw( Interface::REDRAW_STATUS ); destroy = true; } else { @@ -365,7 +366,7 @@ namespace // Set the hero's attacked monster tile index and immediately redraw game area to show an attacking sprite for this monster hero.SetAttackedMonsterTileIndex( dst_index ); - I.Redraw( Interface::REDRAW_GAMEAREA ); + I.redraw( Interface::REDRAW_GAMEAREA ); Army army( tile ); @@ -412,7 +413,7 @@ namespace setMonsterCountOnTile( tile, 0 ); - Interface::Basic::Get().GetGameArea().runSingleObjectAnimation( + Interface::AdventureMap::Get().getGameArea().runSingleObjectAnimation( std::make_shared( tile.GetObjectUID(), tile.GetIndex(), tile.GetObject() ) ); } @@ -459,17 +460,17 @@ namespace castle->Scout(); - Interface::Basic & I = Interface::Basic::Get(); + Interface::AdventureMap & I = Interface::AdventureMap::Get(); // If the enemy is not vanquished we update only the area around the castle on radar. if ( !enemyKingdom.isLoss() ) { const int32_t scoutRange = static_cast( GameStatic::getFogDiscoveryDistance( GameStatic::FogDiscoveryType::CASTLE ) ); const fheroes2::Point castlePosition = Maps::GetPoint( dstIndex ); - I.GetRadar().SetRenderArea( { castlePosition.x - scoutRange, castlePosition.y - scoutRange, 2 * scoutRange + 1, 2 * scoutRange + 1 } ); + I.getRadar().SetRenderArea( { castlePosition.x - scoutRange, castlePosition.y - scoutRange, 2 * scoutRange + 1, 2 * scoutRange + 1 } ); } // Otherwise we fully redraw the radar map image as there might be color reset of enemy's objects. - I.SetRedraw( Interface::REDRAW_CASTLES | Interface::REDRAW_RADAR ); + I.setRedraw( Interface::REDRAW_CASTLES | Interface::REDRAW_RADAR ); }; Army & army = castle->GetActualArmy(); @@ -602,9 +603,9 @@ namespace hero.Move2Dest( dst_index ); // Update the radar map image before changing the direction of the hero. - Interface::Basic & I = Interface::Basic::Get(); - I.GetRadar().SetRenderArea( hero.GetScoutRoi() ); - I.Redraw( Interface::REDRAW_RADAR ); + Interface::AdventureMap & I = Interface::AdventureMap::Get(); + I.getRadar().SetRenderArea( hero.GetScoutRoi() ); + I.redraw( Interface::REDRAW_RADAR ); // Set the direction of the hero to the one of the boat as the boat does not move when boarding it hero.setDirection( boatDirection ); @@ -637,9 +638,9 @@ namespace hero.FadeIn( offset ); // Clear hero position marker from the boat and scout the area on radar after disembarking. - Interface::Basic & I = Interface::Basic::Get(); - I.GetRadar().SetRenderArea( hero.GetScoutRoi() ); - I.SetRedraw( Interface::REDRAW_RADAR ); + Interface::AdventureMap & I = Interface::AdventureMap::Get(); + I.getRadar().SetRenderArea( hero.GetScoutRoi() ); + I.setRedraw( Interface::REDRAW_RADAR ); hero.GetPath().Reset(); hero.ActionNewPosition( true ); @@ -651,7 +652,7 @@ namespace { Maps::Tiles & tile = world.GetTiles( dst_index ); - Interface::Basic & I = Interface::Basic::Get(); + Interface::AdventureMap & I = Interface::AdventureMap::Get(); if ( objectType == MP2::OBJ_BOTTLE ) { const MapSign * sign = dynamic_cast( world.GetMapObject( dst_index ) ); @@ -669,8 +670,8 @@ namespace else { const auto resource = funds.getFirstValidResource(); - I.GetStatusWindow().SetResource( resource.first, resource.second ); - I.SetRedraw( Interface::REDRAW_STATUS ); + I.getStatusWindow().SetResource( resource.first, resource.second ); + I.setRedraw( Interface::REDRAW_STATUS ); } hero.GetKingdom().AddFundsResource( funds ); @@ -678,15 +679,15 @@ namespace Game::PlayPickupSound(); - I.GetGameArea().runSingleObjectAnimation( std::make_shared( tile.GetObjectUID(), tile.GetIndex(), tile.GetObject() ) ); + I.getGameArea().runSingleObjectAnimation( std::make_shared( tile.GetObjectUID(), tile.GetIndex(), tile.GetObject() ) ); resetObjectInfoOnTile( tile ); if ( objectType == MP2::OBJ_RESOURCE ) { // Update the position of picked up resource on radar to remove its mark. const fheroes2::Point resourcePosition = Maps::GetPoint( dst_index ); - I.GetRadar().SetRenderArea( { resourcePosition.x, resourcePosition.y, 1, 1 } ); - I.SetRedraw( Interface::REDRAW_RADAR ); + I.getRadar().SetRenderArea( { resourcePosition.x, resourcePosition.y, 1, 1 } ); + I.setRedraw( Interface::REDRAW_RADAR ); } DEBUG_LOG( DBG_GAME, DBG_INFO, hero.GetName() ) @@ -887,7 +888,7 @@ namespace Game::PlayPickupSound(); - Interface::Basic::Get().GetGameArea().runSingleObjectAnimation( + Interface::AdventureMap::Get().getGameArea().runSingleObjectAnimation( std::make_shared( tile.GetObjectUID(), tile.GetIndex(), tile.GetObject() ) ); resetObjectInfoOnTile( tile ); @@ -1510,7 +1511,7 @@ namespace Game::PlayPickupSound(); - Interface::Basic::Get().GetGameArea().runSingleObjectAnimation( + Interface::AdventureMap::Get().getGameArea().runSingleObjectAnimation( std::make_shared( tile.GetObjectUID(), tile.GetIndex(), tile.GetObject() ) ); resetObjectInfoOnTile( tile ); @@ -1685,17 +1686,17 @@ namespace if ( result && hero.PickupArtifact( art ) ) { Game::PlayPickupSound(); - Interface::Basic & I = Interface::Basic::Get(); + Interface::AdventureMap & I = Interface::AdventureMap::Get(); - I.GetGameArea().runSingleObjectAnimation( std::make_shared( tile.GetObjectUID(), tile.GetIndex(), tile.GetObject() ) ); + I.getGameArea().runSingleObjectAnimation( std::make_shared( tile.GetObjectUID(), tile.GetIndex(), tile.GetObject() ) ); resetObjectInfoOnTile( tile ); const fheroes2::Point artifactPosition = Maps::GetPoint( dst_index ); // Update the position of picked up artifact on radar to remove its mark. - I.GetRadar().SetRenderArea( { artifactPosition.x, artifactPosition.y, 1, 1 } ); - I.SetRedraw( Interface::REDRAW_RADAR ); + I.getRadar().SetRenderArea( { artifactPosition.x, artifactPosition.y, 1, 1 } ); + I.setRedraw( Interface::REDRAW_RADAR ); } } @@ -1801,7 +1802,7 @@ namespace Game::PlayPickupSound(); - Interface::Basic::Get().GetGameArea().runSingleObjectAnimation( + Interface::AdventureMap::Get().getGameArea().runSingleObjectAnimation( std::make_shared( tile.GetObjectUID(), tile.GetIndex(), tile.GetObject() ) ); resetObjectInfoOnTile( tile ); @@ -1858,13 +1859,13 @@ namespace hero.Move2Dest( index_to ); // Clear the previous hero position - Interface::Basic & I = Interface::Basic::Get(); - I.GetRadar().SetRenderArea( { fromPoint.x, fromPoint.y, 1, 1 } ); - I.Redraw( Interface::REDRAW_RADAR ); + Interface::AdventureMap & I = Interface::AdventureMap::Get(); + I.getRadar().SetRenderArea( { fromPoint.x, fromPoint.y, 1, 1 } ); + I.redraw( Interface::REDRAW_RADAR ); - I.GetGameArea().SetCenter( hero.GetCenter() ); - I.GetRadar().SetRenderArea( hero.GetScoutRoi() ); - I.SetRedraw( Interface::REDRAW_GAMEAREA | Interface::REDRAW_RADAR ); + I.getGameArea().SetCenter( hero.GetCenter() ); + I.getRadar().SetRenderArea( hero.GetScoutRoi() ); + I.setRedraw( Interface::REDRAW_GAMEAREA | Interface::REDRAW_RADAR ); AudioManager::PlaySound( M82::KILLFADE ); hero.GetPath().Hide(); @@ -1898,13 +1899,13 @@ namespace hero.Move2Dest( index_to ); // Clear the previous hero position - Interface::Basic & I = Interface::Basic::Get(); - I.GetRadar().SetRenderArea( { fromPoint.x, fromPoint.y, 1, 1 } ); - I.Redraw( Interface::REDRAW_RADAR ); + Interface::AdventureMap & I = Interface::AdventureMap::Get(); + I.getRadar().SetRenderArea( { fromPoint.x, fromPoint.y, 1, 1 } ); + I.redraw( Interface::REDRAW_RADAR ); - I.GetGameArea().SetCenter( hero.GetCenter() ); - I.GetRadar().SetRenderArea( hero.GetScoutRoi() ); - I.SetRedraw( Interface::REDRAW_GAMEAREA | Interface::REDRAW_RADAR ); + I.getGameArea().SetCenter( hero.GetCenter() ); + I.getRadar().SetRenderArea( hero.GetScoutRoi() ); + I.setRedraw( Interface::REDRAW_GAMEAREA | Interface::REDRAW_RADAR ); AudioManager::PlaySound( M82::KILLFADE ); hero.GetPath().Hide(); @@ -1952,11 +1953,11 @@ namespace break; } - Interface::Basic & I = Interface::Basic::Get(); + Interface::AdventureMap & I = Interface::AdventureMap::Get(); // Update the object on radar. - I.GetRadar().SetRenderArea( radarRoi ); - I.Redraw( Interface::REDRAW_GAMEAREA | Interface::REDRAW_RADAR ); + I.getRadar().SetRenderArea( radarRoi ); + I.redraw( Interface::REDRAW_GAMEAREA | Interface::REDRAW_RADAR ); }; auto removeObjectProtection = [&tile]() { @@ -2112,11 +2113,11 @@ namespace const fheroes2::Point tilePoint = Maps::GetPoint( dstIndex ); const fheroes2::Rect radarRoi( tilePoint.x - 1, tilePoint.y - 1, 3, 2 ); - Interface::Basic & I = Interface::Basic::Get(); + Interface::AdventureMap & I = Interface::AdventureMap::Get(); // Update the object on radar. - I.GetRadar().SetRenderArea( radarRoi ); - I.Redraw( Interface::REDRAW_GAMEAREA | Interface::REDRAW_RADAR ); + I.getRadar().SetRenderArea( radarRoi ); + I.redraw( Interface::REDRAW_GAMEAREA | Interface::REDRAW_RADAR ); Dialog::Message( MP2::StringObject( objectType ), _( "You beat the Ghosts and are able to restore the mine to production." ), Font::BIG, Dialog::OK ); } @@ -2163,7 +2164,7 @@ namespace setMonsterCountOnTile( tile, 0 ); hero.GetArmy().JoinTroop( troop ); - Interface::Basic::Get().SetRedraw( Interface::REDRAW_STATUS ); + Interface::AdventureMap::Get().setRedraw( Interface::REDRAW_STATUS ); } } } @@ -2420,11 +2421,11 @@ namespace const int32_t scoutRange = static_cast( GameStatic::getFogDiscoveryDistance( GameStatic::FogDiscoveryType::OBSERVATION_TOWER ) ); Maps::ClearFog( dst_index, scoutRange, hero.GetColor() ); - Interface::Basic & I = Interface::Basic::Get(); + Interface::AdventureMap & I = Interface::AdventureMap::Get(); const fheroes2::Point towerPosition = Maps::GetPoint( dst_index ); const fheroes2::Rect towerRoi( towerPosition.x - scoutRange, towerPosition.y - scoutRange, 2 * scoutRange + 1, 2 * scoutRange + 1 ); - I.GetRadar().SetRenderArea( towerRoi ); - I.SetRedraw( Interface::REDRAW_RADAR ); + I.getRadar().SetRenderArea( towerRoi ); + I.setRedraw( Interface::REDRAW_RADAR ); } void ActionToArtesianSpring( Heroes & hero, const MP2::MapObjectType objectType, int32_t dst_index ) @@ -2666,8 +2667,8 @@ namespace // Fully update fog directions and redraw radar and game area. Interface::GameArea::updateMapFogDirections(); - Interface::Basic & I = Interface::Basic::Get(); - I.SetRedraw( Interface::REDRAW_GAMEAREA | Interface::REDRAW_RADAR ); + Interface::AdventureMap & I = Interface::AdventureMap::Get(); + I.setRedraw( Interface::REDRAW_GAMEAREA | Interface::REDRAW_RADAR ); } } else { @@ -3220,7 +3221,7 @@ namespace _( "In a dazzling display of daring, you break into the local jail and free the hero imprisoned there, who, in return, pledges loyalty to your cause." ), Font::BIG, Dialog::OK ); - Interface::Basic::Get().GetGameArea().runSingleObjectAnimation( + Interface::AdventureMap::Get().getGameArea().runSingleObjectAnimation( std::make_shared( tile.GetObjectUID(), tile.GetIndex(), tile.GetObject() ) ); // TODO: add hero fading in animation together with jail animation. @@ -3252,7 +3253,7 @@ namespace const MapsIndexes eyeMagiIndexes = Maps::GetObjectPositions( MP2::OBJ_EYE_OF_MAGI, true ); if ( !eyeMagiIndexes.empty() ) { - Interface::Basic & I = Interface::Basic::Get(); + Interface::AdventureMap & I = Interface::AdventureMap::Get(); fheroes2::Display & display = fheroes2::Display::instance(); @@ -3263,12 +3264,12 @@ namespace const fheroes2::Point eyePosition = Maps::GetPoint( eyeIndex ); - I.GetGameArea().SetCenter( eyePosition ); + I.getGameArea().SetCenter( eyePosition ); const fheroes2::Rect eyeRoi( eyePosition.x - scoutRange, eyePosition.y - scoutRange, 2 * scoutRange + 1, 2 * scoutRange + 1 ); - I.GetRadar().SetRenderArea( eyeRoi ); - I.Redraw( Interface::REDRAW_GAMEAREA | Interface::REDRAW_RADAR ); + I.getRadar().SetRenderArea( eyeRoi ); + I.redraw( Interface::REDRAW_GAMEAREA | Interface::REDRAW_RADAR ); display.render(); @@ -3279,15 +3280,15 @@ namespace if ( Game::validateAnimationDelay( Game::MAPS_DELAY ) ) { ++delay; Game::updateAdventureMapAnimationIndex(); - I.Redraw( Interface::REDRAW_GAMEAREA ); + I.redraw( Interface::REDRAW_GAMEAREA ); display.render(); } } } - I.GetGameArea().SetCenter( hero.GetCenter() ); - I.SetRedraw( Interface::REDRAW_GAMEAREA | Interface::REDRAW_RADAR_CURSOR ); + I.getGameArea().SetCenter( hero.GetCenter() ); + I.setRedraw( Interface::REDRAW_GAMEAREA | Interface::REDRAW_RADAR_CURSOR ); display.render(); } @@ -3448,7 +3449,7 @@ namespace AudioManager::PlaySound( M82::KILLFADE ); - Interface::Basic::Get().GetGameArea().runSingleObjectAnimation( + Interface::AdventureMap::Get().getGameArea().runSingleObjectAnimation( std::make_shared( tile.GetObjectUID(), tile.GetIndex(), tile.GetObject() ) ); } else { @@ -3481,7 +3482,7 @@ namespace void Heroes::ScoutRadar() const { - Interface::Basic & I = Interface::Basic::Get(); + Interface::AdventureMap & I = Interface::AdventureMap::Get(); #if defined( WITH_DEBUG ) if ( GetColor() != Color::NONE ) { @@ -3493,14 +3494,14 @@ void Heroes::ScoutRadar() const if ( !player->isAIAutoControlMode() ) { #endif - I.GetRadar().SetRenderArea( GetScoutRoi() ); + I.getRadar().SetRenderArea( GetScoutRoi() ); #if defined( WITH_DEBUG ) } } #endif - I.SetRedraw( Interface::REDRAW_RADAR ); + I.setRedraw( Interface::REDRAW_RADAR ); } void Heroes::Action( int tileIndex ) @@ -3514,7 +3515,7 @@ void Heroes::Action( int tileIndex ) ~FocusUpdater() { - Interface::Basic & I = Interface::Basic::Get(); + Interface::AdventureMap & I = Interface::AdventureMap::Get(); I.ResetFocus( GameFocus::HEROES, true ); I.RedrawFocus(); @@ -3530,7 +3531,7 @@ void Heroes::Action( int tileIndex ) focusUpdater = std::make_unique(); if ( isAIControlledForHumanPlayer ) { - Interface::Basic::Get().SetFocus( this, false ); + Interface::AdventureMap::Get().SetFocus( this, false ); } } @@ -3557,10 +3558,10 @@ void Heroes::Action( int tileIndex ) // Most likely there will be some action, immediately center the map on the hero to avoid subsequent minor screen movements if ( Modes( ACTION ) ) { - Interface::Basic & I = Interface::Basic::Get(); + Interface::AdventureMap & I = Interface::AdventureMap::Get(); - I.GetGameArea().SetCenter( GetCenter() ); - I.Redraw( Interface::REDRAW_GAMEAREA | Interface::REDRAW_RADAR_CURSOR | Interface::REDRAW_HEROES ); + I.getGameArea().SetCenter( GetCenter() ); + I.redraw( Interface::REDRAW_GAMEAREA | Interface::REDRAW_RADAR_CURSOR | Interface::REDRAW_HEROES ); } switch ( objectType ) { diff --git a/src/fheroes2/heroes/heroes_move.cpp b/src/fheroes2/heroes/heroes_move.cpp index 0b7243eea0f..e3cd537ba98 100644 --- a/src/fheroes2/heroes/heroes_move.cpp +++ b/src/fheroes2/heroes/heroes_move.cpp @@ -43,6 +43,7 @@ #include "heroes.h" #include "icn.h" #include "image.h" +#include "interface_base.h" #include "interface_gamearea.h" #include "kingdom.h" #include "localevent.h" @@ -492,7 +493,7 @@ bool Heroes::isInVisibleMapArea() const { // TODO: this is not entirely correct. Consider a hero being outside the visible are but his shadow is still inside. The visible tile ROI should be extended by // TODO: at least 1 tile in each direction. - return Interface::Basic::Get().GetGameArea().GetVisibleTileROI() & GetCenter(); + return Interface::AdventureMap::Get().getGameArea().GetVisibleTileROI() & GetCenter(); } bool Heroes::isInDeepOcean() const @@ -907,8 +908,8 @@ void Heroes::FadeOut( const fheroes2::Point & offset ) const if ( !isInVisibleMapArea() ) return; - Interface::Basic & iface = Interface::Basic::Get(); - Interface::GameArea & gamearea = iface.GetGameArea(); + Interface::AdventureMap & iface = Interface::AdventureMap::Get(); + Interface::GameArea & gamearea = iface.getGameArea(); int multiplier = std::max( offset.x < 0 ? -offset.x : offset.x, offset.y < 0 ? -offset.y : offset.y ); if ( multiplier < 1 ) @@ -927,7 +928,7 @@ void Heroes::FadeOut( const fheroes2::Point & offset ) const gamearea.ShiftCenter( offset ); } - iface.Redraw( Interface::REDRAW_GAMEAREA ); + iface.redraw( Interface::REDRAW_GAMEAREA ); display.render(); _alphaValue -= 8 * multiplier; @@ -942,8 +943,8 @@ void Heroes::FadeIn( const fheroes2::Point & offset ) const if ( !isInVisibleMapArea() ) return; - Interface::Basic & iface = Interface::Basic::Get(); - Interface::GameArea & gamearea = iface.GetGameArea(); + Interface::AdventureMap & iface = Interface::AdventureMap::Get(); + Interface::GameArea & gamearea = iface.getGameArea(); int multiplier = std::max( offset.x < 0 ? -offset.x : offset.x, offset.y < 0 ? -offset.y : offset.y ); if ( multiplier < 1 ) @@ -962,7 +963,7 @@ void Heroes::FadeIn( const fheroes2::Point & offset ) const gamearea.ShiftCenter( offset ); } - iface.Redraw( Interface::REDRAW_GAMEAREA ); + iface.redraw( Interface::REDRAW_GAMEAREA ); display.render(); _alphaValue += 8 * multiplier; diff --git a/src/fheroes2/heroes/heroes_spell.cpp b/src/fheroes2/heroes/heroes_spell.cpp index b275a6f06ac..a2ed328f1cb 100644 --- a/src/fheroes2/heroes/heroes_spell.cpp +++ b/src/fheroes2/heroes/heroes_spell.cpp @@ -42,6 +42,7 @@ #include "heroes.h" #include "icn.h" #include "image.h" +#include "interface_base.h" #include "interface_gamearea.h" #include "interface_icons.h" #include "interface_list.h" @@ -205,15 +206,15 @@ namespace { assert( castle != nullptr ); - Interface::Basic & I = Interface::Basic::Get(); + Interface::AdventureMap & I = Interface::AdventureMap::Get(); const fheroes2::Point fromPosition = hero.GetCenter(); // Position of Hero on radar before casting the spell to clear it after casting. const fheroes2::Rect fromRoi( fromPosition.x, fromPosition.y, 1, 1 ); // Before casting the spell, make sure that the game area is centered on the hero - I.GetGameArea().SetCenter( fromPosition ); - I.Redraw( Interface::REDRAW_GAMEAREA | Interface::REDRAW_RADAR_CURSOR ); + I.getGameArea().SetCenter( fromPosition ); + I.redraw( Interface::REDRAW_GAMEAREA | Interface::REDRAW_RADAR_CURSOR ); const int32_t dst = castle->GetIndex(); assert( Maps::isValidAbsIndex( dst ) ); @@ -225,15 +226,15 @@ namespace hero.Move2Dest( dst ); // Clear previous hero position on radar. - I.GetRadar().SetRenderArea( fromRoi ); + I.getRadar().SetRenderArea( fromRoi ); - I.Redraw( Interface::REDRAW_RADAR ); + I.redraw( Interface::REDRAW_RADAR ); - I.GetGameArea().SetCenter( hero.GetCenter() ); + I.getGameArea().SetCenter( hero.GetCenter() ); // Update radar image in scout area around Hero after teleport. - I.GetRadar().SetRenderArea( hero.GetScoutRoi() ); - I.SetRedraw( Interface::REDRAW_GAMEAREA | Interface::REDRAW_RADAR ); + I.getRadar().SetRenderArea( hero.GetScoutRoi() ); + I.setRedraw( Interface::REDRAW_GAMEAREA | Interface::REDRAW_RADAR ); AudioManager::PlaySound( M82::KILLFADE ); hero.FadeIn(); @@ -246,37 +247,37 @@ namespace bool ActionSpellViewMines() { - ViewWorld::ViewWorldWindow( Settings::Get().CurrentColor(), ViewWorldMode::ViewMines, Interface::Basic::Get() ); + ViewWorld::ViewWorldWindow( Settings::Get().CurrentColor(), ViewWorldMode::ViewMines, Interface::AdventureMap::Get() ); return true; } bool ActionSpellViewResources() { - ViewWorld::ViewWorldWindow( Settings::Get().CurrentColor(), ViewWorldMode::ViewResources, Interface::Basic::Get() ); + ViewWorld::ViewWorldWindow( Settings::Get().CurrentColor(), ViewWorldMode::ViewResources, Interface::AdventureMap::Get() ); return true; } bool ActionSpellViewArtifacts() { - ViewWorld::ViewWorldWindow( Settings::Get().CurrentColor(), ViewWorldMode::ViewArtifacts, Interface::Basic::Get() ); + ViewWorld::ViewWorldWindow( Settings::Get().CurrentColor(), ViewWorldMode::ViewArtifacts, Interface::AdventureMap::Get() ); return true; } bool ActionSpellViewTowns() { - ViewWorld::ViewWorldWindow( Settings::Get().CurrentColor(), ViewWorldMode::ViewTowns, Interface::Basic::Get() ); + ViewWorld::ViewWorldWindow( Settings::Get().CurrentColor(), ViewWorldMode::ViewTowns, Interface::AdventureMap::Get() ); return true; } bool ActionSpellViewHeroes() { - ViewWorld::ViewWorldWindow( Settings::Get().CurrentColor(), ViewWorldMode::ViewHeroes, Interface::Basic::Get() ); + ViewWorld::ViewWorldWindow( Settings::Get().CurrentColor(), ViewWorldMode::ViewHeroes, Interface::AdventureMap::Get() ); return true; } bool ActionSpellViewAll() { - ViewWorld::ViewWorldWindow( Settings::Get().CurrentColor(), ViewWorldMode::ViewAll, Interface::Basic::Get() ); + ViewWorld::ViewWorldWindow( Settings::Get().CurrentColor(), ViewWorldMode::ViewAll, Interface::AdventureMap::Get() ); return true; } @@ -306,7 +307,7 @@ namespace Maps::Tiles & tileSource = world.GetTiles( boatSource ); - Interface::GameArea & gameArea = Interface::Basic::Get().GetGameArea(); + Interface::GameArea & gameArea = Interface::AdventureMap::Get().getGameArea(); gameArea.runSingleObjectAnimation( std::make_shared( tileSource.GetObjectUID(), boatSource, MP2::OBJ_BOAT ) ); Maps::Tiles & tileDest = world.GetTiles( boatDestination ); @@ -320,15 +321,15 @@ namespace bool ActionSpellDimensionDoor( Heroes & hero ) { - Interface::Basic & I = Interface::Basic::Get(); + Interface::AdventureMap & I = Interface::AdventureMap::Get(); const fheroes2::Point fromPosition = hero.GetCenter(); // Position of Hero on radar before casting the spell to clear it after casting. const fheroes2::Rect fromRoi( fromPosition.x, fromPosition.y, 1, 1 ); // Before casting the spell, make sure that the game area is centered on the hero - I.GetGameArea().SetCenter( hero.GetCenter() ); - I.Redraw( Interface::REDRAW_GAMEAREA | Interface::REDRAW_RADAR_CURSOR ); + I.getGameArea().SetCenter( hero.GetCenter() ); + I.redraw( Interface::REDRAW_GAMEAREA | Interface::REDRAW_RADAR_CURSOR ); const int32_t src = hero.GetIndex(); assert( Maps::isValidAbsIndex( src ) ); @@ -347,15 +348,15 @@ namespace hero.Move2Dest( dst ); // Clear previous hero position on radar. - I.GetRadar().SetRenderArea( fromRoi ); + I.getRadar().SetRenderArea( fromRoi ); - I.Redraw( Interface::REDRAW_RADAR ); + I.redraw( Interface::REDRAW_RADAR ); - I.GetGameArea().SetCenter( hero.GetCenter() ); + I.getGameArea().SetCenter( hero.GetCenter() ); // Update radar image in scout area around Hero after teleport. - I.GetRadar().SetRenderArea( hero.GetScoutRoi() ); - I.SetRedraw( Interface::REDRAW_GAMEAREA | Interface::REDRAW_RADAR ); + I.getRadar().SetRenderArea( hero.GetScoutRoi() ); + I.setRedraw( Interface::REDRAW_GAMEAREA | Interface::REDRAW_RADAR ); AudioManager::PlaySound( M82::KILLFADE ); hero.FadeIn(); @@ -567,11 +568,11 @@ namespace tile.removeOwnershipFlag( MP2::OBJ_MINES ); // Update the color of haunted mine on radar. - Interface::Basic & I = Interface::Basic::Get(); + Interface::AdventureMap & I = Interface::AdventureMap::Get(); const fheroes2::Point heroPosition = hero.GetCenter(); - I.GetRadar().SetRenderArea( { heroPosition.x - 1, heroPosition.y - 1, 3, 2 } ); + I.getRadar().SetRenderArea( { heroPosition.x - 1, heroPosition.y - 1, 3, 2 } ); - I.SetRedraw( Interface::REDRAW_RADAR ); + I.setRedraw( Interface::REDRAW_RADAR ); } world.GetCapturedObject( tile.GetIndex() ).GetTroop().Set( Monster( spell ), count ); diff --git a/src/fheroes2/kingdom/kingdom.cpp b/src/fheroes2/kingdom/kingdom.cpp index 3568b6d35a3..c9d477bf965 100644 --- a/src/fheroes2/kingdom/kingdom.cpp +++ b/src/fheroes2/kingdom/kingdom.cpp @@ -307,7 +307,7 @@ void Kingdom::AddHeroes( Heroes * hero ) const Player * player = Settings::Get().GetPlayers().GetCurrent(); if ( player && player->isColor( GetColor() ) && player->isControlHuman() ) - Interface::Basic::Get().GetIconsPanel().ResetIcons( ICON_HEROES ); + Interface::AdventureMap::Get().GetIconsPanel().ResetIcons( ICON_HEROES ); AI::Get().HeroesAdd( *hero ); } @@ -347,7 +347,7 @@ void Kingdom::AddCastle( const Castle * castle ) const Player * player = Settings::Get().GetPlayers().GetCurrent(); if ( player && player->isColor( GetColor() ) ) - Interface::Basic::Get().GetIconsPanel().ResetIcons( ICON_CASTLES ); + Interface::AdventureMap::Get().GetIconsPanel().ResetIcons( ICON_CASTLES ); AI::Get().CastleAdd( *castle ); } diff --git a/src/fheroes2/kingdom/kingdom_overview.cpp b/src/fheroes2/kingdom/kingdom_overview.cpp index 7ffbb551e04..b0a92e2076a 100644 --- a/src/fheroes2/kingdom/kingdom_overview.cpp +++ b/src/fheroes2/kingdom/kingdom_overview.cpp @@ -871,9 +871,9 @@ void Kingdom::openOverviewDialog() // - hero hired -> hero icon list is updated // So, it's equivalent to check if hero list changed if ( listHeroes.Refresh( heroes ) ) { - worldMapRedrawMask |= Interface::Basic::Get().GetRedrawMask(); + worldMapRedrawMask |= Interface::AdventureMap::Get().getRedrawMask(); // redraw the main game window on screen, which will also erase current kingdom window - Interface::Basic::Get().Redraw(); + Interface::AdventureMap::Get().redraw(); // redraw Kingdom window from scratch, because it's now invalid background.render(); fheroes2::Blit( fheroes2::AGG::GetICN( ICN::OVERBACK, 0 ), display, cur_pt.x, cur_pt.y ); @@ -903,6 +903,6 @@ void Kingdom::openOverviewDialog() if ( worldMapRedrawMask != 0 ) { // Force redraw of all UI elements that changed, that were masked by Kingdom window - Interface::Basic::Get().SetRedraw( worldMapRedrawMask ); + Interface::AdventureMap::Get().setRedraw( worldMapRedrawMask ); } } diff --git a/src/fheroes2/kingdom/puzzle.cpp b/src/fheroes2/kingdom/puzzle.cpp index 8b769417c93..94410bf2458 100644 --- a/src/fheroes2/kingdom/puzzle.cpp +++ b/src/fheroes2/kingdom/puzzle.cpp @@ -42,6 +42,7 @@ #include "gamedefs.h" #include "icn.h" #include "image.h" +#include "interface_base.h" #include "interface_gamearea.h" #include "interface_radar.h" #include "localevent.h" @@ -153,7 +154,7 @@ namespace const bool isEvilInterface = Settings::Get().isEvilInterfaceEnabled(); - const Interface::Radar & radar = Interface::Basic::Get().GetRadar(); + const Interface::Radar & radar = Interface::AdventureMap::Get().getRadar(); const fheroes2::Rect & radarArea = radar.GetArea(); fheroes2::ImageRestorer back( display, BORDERWIDTH, BORDERWIDTH, sf.width(), sf.height() ); @@ -196,7 +197,7 @@ namespace { fheroes2::Display & display = fheroes2::Display::instance(); - const fheroes2::Rect & gameArea = Interface::Basic::Get().GetGameArea().GetROI(); + const fheroes2::Rect & gameArea = Interface::AdventureMap::Get().getGameArea().GetROI(); const fheroes2::StandardWindow border( gameArea.x + ( gameArea.width - sf.width() ) / 2, gameArea.y + ( gameArea.height - sf.height() ) / 2, sf.width(), sf.height(), false ); @@ -218,7 +219,7 @@ namespace fheroes2::Blit( background, display, blitArea.x, blitArea.y ); - const Interface::Radar & radar = Interface::Basic::Get().GetRadar(); + const Interface::Radar & radar = Interface::AdventureMap::Get().getRadar(); const fheroes2::Rect & radarRect = radar.GetRect(); const fheroes2::Rect & radarArea = radar.GetArea(); diff --git a/src/fheroes2/kingdom/view_world.cpp b/src/fheroes2/kingdom/view_world.cpp index 4506662c632..25d041adc15 100644 --- a/src/fheroes2/kingdom/view_world.cpp +++ b/src/fheroes2/kingdom/view_world.cpp @@ -37,6 +37,7 @@ #include "heroes.h" #include "icn.h" #include "image.h" +#include "interface_base.h" #include "interface_border.h" #include "interface_gamearea.h" #include "interface_radar.h" @@ -85,7 +86,7 @@ namespace // based on given zoom level and initial center fheroes2::Rect computeROI( const fheroes2::Point & centerInPixel, const ZoomLevel zoomLevel ) { - const fheroes2::Rect sizeInPixels = Interface::Basic::Get().GetGameArea().GetROI(); + const fheroes2::Rect sizeInPixels = Interface::AdventureMap::Get().getGameArea().GetROI(); // how many pixels from "world map" we can see in "view world" window, given current zoom const int32_t pixelsW = sizeInPixels.width * TILEWIDTH / tileSizePerZoomLevel[static_cast( zoomLevel )]; @@ -215,7 +216,7 @@ namespace fheroes2::Image temporaryImg( redrawAreaWidth, redrawAreaHeight ); temporaryImg._disableTransformLayer(); - Interface::GameArea gamearea = Interface::Basic::Get().GetGameArea(); + Interface::GameArea gamearea = Interface::AdventureMap::Get().getGameArea(); gamearea.SetAreaPosition( 0, 0, redrawAreaWidth, redrawAreaHeight ); int32_t drawingFlags = Interface::RedrawLevelType::LEVEL_ALL & ~Interface::RedrawLevelType::LEVEL_ROUTES; @@ -254,7 +255,7 @@ namespace fheroes2::Display & display = fheroes2::Display::instance(); const fheroes2::Image & image = cache.cachedImages[static_cast( ROI._zoomLevel )]; - const fheroes2::Rect roiScreen = Interface::Basic::Get().GetGameArea().GetROI(); + const fheroes2::Rect roiScreen = Interface::AdventureMap::Get().getGameArea().GetROI(); const int32_t offsetPixelsX = tileSizePerZoomLevel[static_cast( ROI._zoomLevel )] * ROI.GetROIinPixels().x / TILEWIDTH; const int32_t offsetPixelsY = tileSizePerZoomLevel[static_cast( ROI._zoomLevel )] * ROI.GetROIinPixels().y / TILEWIDTH; @@ -569,7 +570,7 @@ fheroes2::Rect ViewWorld::ZoomROIs::GetROIinTiles() const return result; } -void ViewWorld::ViewWorldWindow( const int32_t color, const ViewWorldMode mode, Interface::Basic & interface ) +void ViewWorld::ViewWorldWindow( const int32_t color, const ViewWorldMode mode, Interface::BaseInterface & interface ) { fheroes2::Display & display = fheroes2::Display::instance(); @@ -597,7 +598,7 @@ void ViewWorld::ViewWorldWindow( const int32_t color, const ViewWorldMode mode, // the map generation in the World View mode heavily depends on the existing game area if ( isHideInterface ) { conf.setHideInterface( false ); - interface.Reset(); + interface.reset(); } // setup cursor @@ -606,9 +607,9 @@ void ViewWorld::ViewWorldWindow( const int32_t color, const ViewWorldMode mode, LocalEvent::PauseCycling(); // Creates fixed radar on top-right, suitable for the View World window - Interface::Radar radar( interface.GetRadar(), fheroes2::Display::instance() ); + Interface::Radar radar( interface.getRadar(), fheroes2::Display::instance() ); - const Interface::GameArea gameArea = interface.GetGameArea(); + const Interface::GameArea gameArea = interface.getGameArea(); const fheroes2::Rect worldMapROI = gameArea.GetVisibleTileROI(); const fheroes2::Rect visibleScreenInPixels = gameArea.GetROI(); @@ -736,7 +737,7 @@ void ViewWorld::ViewWorldWindow( const int32_t color, const ViewWorldMode mode, // Don't forget to reset the interface settings back if necessary if ( isHideInterface ) { conf.setHideInterface( true ); - interface.Reset(); + interface.reset(); } else { radar.SetRedraw( Interface::REDRAW_RADAR_CURSOR ); diff --git a/src/fheroes2/kingdom/view_world.h b/src/fheroes2/kingdom/view_world.h index c4fd3e13931..49225414e82 100644 --- a/src/fheroes2/kingdom/view_world.h +++ b/src/fheroes2/kingdom/view_world.h @@ -29,7 +29,7 @@ namespace Interface { - class Basic; + class BaseInterface; } enum class ViewWorldMode : int32_t @@ -48,7 +48,7 @@ enum class ViewWorldMode : int32_t class ViewWorld { public: - static void ViewWorldWindow( const int32_t color, const ViewWorldMode mode, Interface::Basic & interface ); + static void ViewWorldWindow( const int32_t color, const ViewWorldMode mode, Interface::BaseInterface & interface ); struct ZoomROIs {