Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add return to main menu and play map buttons to the editor #9512

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
125 changes: 84 additions & 41 deletions src/fheroes2/editor/editor_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include <string>
#include <vector>

#include "agg_image.h"
#include "artifact.h"
#include "audio_manager.h"
#include "color.h"
Expand Down Expand Up @@ -86,6 +85,7 @@
#include "ui_map_object.h"
#include "ui_text.h"
#include "ui_tool.h"
#include "ui_window.h"
#include "view_world.h"
#include "world.h"
#include "world_object_uid.h"
Expand Down Expand Up @@ -1120,35 +1120,62 @@ namespace Interface

fheroes2::GameMode EditorInterface::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 );

const Settings & conf = Settings::Get();
const bool isEvilInterface = conf.isEvilInterfaceEnabled();

fheroes2::Sprite mainMenuReleased;
fheroes2::Sprite mainMenuPressed;
fheroes2::getTextAdaptedButton( mainMenuReleased, mainMenuPressed, gettext_noop( "MAIN\nMENU" ),
isEvilInterface ? ICN::EMPTY_EVIL_BUTTON : ICN::EMPTY_GOOD_BUTTON, isEvilInterface ? ICN::STONEBAK_EVIL : ICN::STONEBAK );
fheroes2::Sprite playMapReleased;
fheroes2::Sprite playMapPressed;
fheroes2::getTextAdaptedButton( playMapReleased, playMapPressed, gettext_noop( "PLAY\nMAP" ), isEvilInterface ? ICN::EMPTY_EVIL_BUTTON : ICN::EMPTY_GOOD_BUTTON,
isEvilInterface ? ICN::STONEBAK_EVIL : ICN::STONEBAK );
Districh-ru marked this conversation as resolved.
Show resolved Hide resolved

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() - fheroes2::borderWidthPx ) / 2,
( display.height() - background.height() + fheroes2::borderWidthPx ) / 2 );
fheroes2::ImageRestorer back( display, rb.x, rb.y, background.width(), background.height() );
fheroes2::Blit( background, display, rb.x, rb.y );
const fheroes2::Size dialogActiveSize = { 193 + mainMenuReleased.width() + playMapReleased.width(), 204 };
const int32_t totalDialogWidth = dialogActiveSize.width + 32;
const int32_t totalDialogHeight = dialogActiveSize.height + 32;

// Prepare restorer of the adventure map for when save feedback dialog is shown.
fheroes2::ImageRestorer back( display, ( display.width() - totalDialogWidth ) / 2 - fheroes2::borderWidthPx, ( display.height() - totalDialogHeight ) / 2,
totalDialogWidth + fheroes2::borderWidthPx, totalDialogHeight + fheroes2::borderWidthPx );

fheroes2::StandardWindow background( dialogActiveSize.width, dialogActiveSize.height, true, display );
const fheroes2::Rect roi = background.activeArea();

fheroes2::Button buttonNew( roi.x + 62, roi.y + 31, isEvilInterface ? ICN::BUTTON_NEW_MAP_EVIL : ICN::BUTTON_NEW_MAP_GOOD, 0, 1 );
fheroes2::Button buttonLoad( roi.x + 195, roi.y + 31, isEvilInterface ? ICN::BUTTON_LOAD_MAP_EVIL : ICN::BUTTON_LOAD_MAP_GOOD, 0, 1 );
fheroes2::Button buttonSave( roi.x + 62, roi.y + 107, isEvilInterface ? ICN::BUTTON_SAVE_MAP_EVIL : ICN::BUTTON_SAVE_MAP_GOOD, 0, 1 );
fheroes2::Button buttonQuit( roi.x + 195, roi.y + 107, isEvilInterface ? ICN::BUTTON_QUIT_EVIL : ICN::BUTTON_QUIT_GOOD, 0, 1 );
fheroes2::Button buttonCancel( roi.x + 128, roi.y + 184, isEvilInterface ? ICN::BUTTON_SMALL_CANCEL_EVIL : ICN::BUTTON_SMALL_CANCEL_GOOD, 0, 1 );

fheroes2::Button buttonNew( rb.x + 62, rb.y + 31, isEvilInterface ? ICN::BUTTON_NEW_MAP_EVIL : ICN::BUTTON_NEW_MAP_GOOD, 0, 1 );
fheroes2::Button buttonLoad( rb.x + 195, rb.y + 31, isEvilInterface ? ICN::BUTTON_LOAD_MAP_EVIL : ICN::BUTTON_LOAD_MAP_GOOD, 0, 1 );
fheroes2::Button buttonSave( rb.x + 62, rb.y + 107, isEvilInterface ? ICN::BUTTON_SAVE_MAP_EVIL : ICN::BUTTON_SAVE_MAP_GOOD, 0, 1 );
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 );
const fheroes2::Point buttonOffsets = { 30, 15 };
background.renderButton( buttonNew, isEvilInterface ? ICN::BUTTON_NEW_MAP_EVIL : ICN::BUTTON_NEW_MAP_GOOD, 0, 1, buttonOffsets,
fheroes2::StandardWindow::Padding::TOP_LEFT );
background.renderButton( buttonLoad, isEvilInterface ? ICN::BUTTON_LOAD_MAP_EVIL : ICN::BUTTON_LOAD_MAP_GOOD, 0, 1, { 0, buttonOffsets.y },
fheroes2::StandardWindow::Padding::TOP_CENTER );
background.renderButton( buttonSave, isEvilInterface ? ICN::BUTTON_SAVE_MAP_EVIL : ICN::BUTTON_SAVE_MAP_GOOD, 0, 1, { buttonOffsets.x, buttonOffsets.y },
fheroes2::StandardWindow::Padding::CENTER_LEFT );
background.renderButton( buttonQuit, isEvilInterface ? ICN::BUTTON_QUIT_EVIL : ICN::BUTTON_QUIT_GOOD, 0, 1, { buttonOffsets.x, buttonOffsets.y },
fheroes2::StandardWindow::Padding::CENTER_RIGHT );
background.renderButton( buttonCancel, isEvilInterface ? ICN::BUTTON_SMALL_CANCEL_EVIL : ICN::BUTTON_SMALL_CANCEL_GOOD, 0, 1, { 0, 11 },
fheroes2::StandardWindow::Padding::BOTTOM_CENTER );

buttonNew.draw();
buttonLoad.draw();
buttonSave.draw();
buttonQuit.draw();
buttonCancel.draw();
fheroes2::ButtonSprite buttonMainMenu( roi.x + ( roi.width - mainMenuReleased.width() ) / 2,
roi.y + ( roi.height - mainMenuReleased.height() ) / 2 + buttonOffsets.y, mainMenuReleased, mainMenuPressed );
fheroes2::addGradientShadow( mainMenuReleased, display, buttonMainMenu.area().getPosition(), { -5, 5 } );

display.render( back.rect() );
fheroes2::ButtonSprite buttonPlayMap( roi.x + roi.width - playMapReleased.width() - buttonOffsets.x, roi.y + buttonOffsets.y, playMapReleased, playMapPressed );
fheroes2::addGradientShadow( playMapReleased, display, buttonPlayMap.area().getPosition(), { -5, 5 } );

fheroes2::GameMode result = fheroes2::GameMode::CANCEL;
buttonPlayMap.draw();
buttonMainMenu.draw();

display.render( background.totalArea() );

LocalEvent & le = LocalEvent::Get();

Expand All @@ -1158,35 +1185,53 @@ namespace Interface
buttonSave.drawOnState( le.isMouseLeftButtonPressedInArea( buttonSave.area() ) );
buttonQuit.drawOnState( le.isMouseLeftButtonPressedInArea( buttonQuit.area() ) );
buttonCancel.drawOnState( le.isMouseLeftButtonPressedInArea( buttonCancel.area() ) );
buttonMainMenu.drawOnState( le.isMouseLeftButtonPressedInArea( buttonMainMenu.area() ) );
buttonPlayMap.drawOnState( le.isMouseLeftButtonPressedInArea( buttonPlayMap.area() ) );

if ( le.MouseClickLeft( buttonNew.area() ) || Game::HotKeyPressEvent( Game::HotKeyEvent::EDITOR_NEW_MAP_MENU ) ) {
if ( eventNewMap() == fheroes2::GameMode::EDITOR_NEW_MAP ) {
result = fheroes2::GameMode::EDITOR_NEW_MAP;
break;
return fheroes2::GameMode::EDITOR_NEW_MAP;
}
}
else if ( le.MouseClickLeft( buttonLoad.area() ) || Game::HotKeyPressEvent( Game::HotKeyEvent::MAIN_MENU_LOAD_GAME ) ) {
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;
return fheroes2::GameMode::EDITOR_LOAD_MAP;
}
}
else if ( le.MouseClickLeft( buttonSave.area() ) || Game::HotKeyPressEvent( Game::HotKeyEvent::WORLD_SAVE_GAME ) ) {
if ( le.MouseClickLeft( buttonSave.area() ) || Game::HotKeyPressEvent( Game::HotKeyEvent::WORLD_SAVE_GAME ) ) {
// Special case: since we show a window about file saving we don't want to display the current dialog anymore.
back.restore();

display.render( background.totalArea() );
Get().saveMapToFile();

break;
return fheroes2::GameMode::CANCEL;
}

if ( le.MouseClickLeft( buttonQuit.area() ) || Game::HotKeyPressEvent( Game::HotKeyEvent::MAIN_MENU_QUIT ) ) {
if ( EventExit() == fheroes2::GameMode::QUIT_GAME ) {
result = fheroes2::GameMode::QUIT_GAME;
break;
return fheroes2::GameMode::QUIT_GAME;
}
}
else if ( le.MouseClickLeft( buttonCancel.area() ) || Game::HotKeyCloseWindow() ) {
break;
if ( le.MouseClickLeft( buttonMainMenu.area() ) || Game::HotKeyPressEvent( Game::HotKeyEvent::EDITOR_TO_GAME_MAIN_MENU ) ) {
if ( fheroes2::showStandardTextMessage( _( "Main Menu" ), _( "Do you wish to return to the game's Main Menu? All unsaved changes will be lost." ),
Dialog::YES | Dialog::NO )
== Dialog::YES ) {
return fheroes2::GameMode::MAIN_MENU;
}
}
if ( le.MouseClickLeft( buttonPlayMap.area() ) ) {
// The map either hasn't been saved to a file or there aren't any human-playable colors.
if ( !conf.getCurrentMapInfo().name.empty() && conf.getCurrentMapInfo().colorsAvailableForHumans > 0 ) {
if ( fheroes2::showStandardTextMessage( _( "Play Map" ), _( "Do you wish to leave the editor and play the current map?" ), Dialog::YES | Dialog::NO )
zenseii marked this conversation as resolved.
Show resolved Hide resolved
zenseii marked this conversation as resolved.
Show resolved Hide resolved
== Dialog::YES ) {
return fheroes2::GameMode::NEW_STANDARD;
}
}
else {
fheroes2::showStandardTextMessage( _( "Invalid Map" ), _( "This map is not valid. Try to save the latest changes." ), Dialog::OK );
zenseii marked this conversation as resolved.
Show resolved Hide resolved
}
}
if ( le.MouseClickLeft( buttonCancel.area() ) || Game::HotKeyCloseWindow() ) {
return fheroes2::GameMode::CANCEL;
}

if ( le.isMouseRightButtonPressedInArea( buttonNew.area() ) ) {
Expand All @@ -1203,16 +1248,14 @@ namespace Interface
else if ( le.isMouseRightButtonPressedInArea( buttonQuit.area() ) ) {
fheroes2::showStandardTextMessage( _( "Quit" ), _( "Quit out of the map editor." ), Dialog::ZERO );
}
else if ( le.isMouseRightButtonPressedInArea( buttonMainMenu.area() ) ) {
fheroes2::showStandardTextMessage( _( "Main Menu" ), _( "Return to the game's Main Menu." ), Dialog::ZERO );
}
zenseii marked this conversation as resolved.
Show resolved Hide resolved
else if ( le.isMouseRightButtonPressedInArea( buttonCancel.area() ) ) {
fheroes2::showStandardTextMessage( _( "Cancel" ), _( "Exit this menu without doing anything." ), Dialog::ZERO );
}
}

// restore background
back.restore();
display.render( back.rect() );

return result;
return fheroes2::GameMode::CANCEL;
}

void EditorInterface::eventViewWorld()
Expand Down
4 changes: 2 additions & 2 deletions src/fheroes2/game/game_scenarioinfo.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***************************************************************************
* fheroes2: https://github.com/ihhub/fheroes2 *
* Copyright (C) 2019 - 2024 *
* Copyright (C) 2019 - 2025 *
* *
* Free Heroes2 Engine: http://sourceforge.net/projects/fheroes2 *
* Copyright (C) 2009 by Andrey Afletdinov <[email protected]> *
Expand Down Expand Up @@ -312,7 +312,7 @@ namespace
}
levelCursor.redraw();

display.render();
fheroes2::validateFadeInAndRender();

fheroes2::GameMode result = fheroes2::GameMode::QUIT_GAME;

Expand Down
Loading