Skip to content

Commit

Permalink
Add more game options for the Editor (#9506)
Browse files Browse the repository at this point in the history
  • Loading branch information
ihhub authored Jan 29, 2025
1 parent bc60f22 commit b808340
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 78 deletions.
80 changes: 5 additions & 75 deletions src/fheroes2/dialog/dialog_interface_settings.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***************************************************************************
* fheroes2: https://github.com/ihhub/fheroes2 *
* Copyright (C) 2023 - 2024 *
* Copyright (C) 2023 - 2025 *
* *
* 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 *
Expand All @@ -20,7 +20,6 @@

#include "dialog_interface_settings.h"

#include <cassert>
#include <cstdint>
#include <string>
#include <utility>
Expand Down Expand Up @@ -60,23 +59,6 @@ namespace
const fheroes2::Rect cursorTypeRoi{ optionOffset.x, optionOffset.y + offsetBetweenOptions.height, optionWindowSize, optionWindowSize };
const fheroes2::Rect scrollSpeedRoi{ optionOffset.x + offsetBetweenOptions.width, optionOffset.y + offsetBetweenOptions.height, optionWindowSize, optionWindowSize };

void drawInterfaceType( const fheroes2::Rect & optionRoi )
{
const Settings & conf = Settings::Get();
const bool isEvilInterface = conf.isEvilInterfaceEnabled();
const fheroes2::Sprite & interfaceThemeIcon = fheroes2::AGG::GetICN( ICN::SPANEL, isEvilInterface ? 17 : 16 );

std::string value;
if ( isEvilInterface ) {
value = _( "Evil" );
}
else {
value = _( "Good" );
}

fheroes2::drawOption( optionRoi, interfaceThemeIcon, _( "Interface Type" ), std::move( value ), fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW );
}

void drawInterfacePresence( const fheroes2::Rect & optionRoi )
{
// Interface show/hide state.
Expand All @@ -97,58 +79,6 @@ namespace
fheroes2::drawOption( optionRoi, interfaceStateIcon, _( "Interface" ), std::move( value ), fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW );
}

void drawCursorType( const fheroes2::Rect & optionRoi )
{
if ( Settings::Get().isMonochromeCursorEnabled() ) {
fheroes2::drawOption( optionRoi, fheroes2::AGG::GetICN( ICN::SPANEL, 20 ), _( "Mouse Cursor" ), _( "Black & White" ),
fheroes2::UiOptionTextWidth::THREE_ELEMENTS_ROW );
}
else {
fheroes2::drawOption( optionRoi, fheroes2::AGG::GetICN( ICN::SPANEL, 21 ), _( "Mouse Cursor" ), _( "Color" ),
fheroes2::UiOptionTextWidth::THREE_ELEMENTS_ROW );
}
}

void drawScrollSpeed( const fheroes2::Rect & optionRoi )
{
const Settings & conf = Settings::Get();
const int scrollSpeed = conf.ScrollSpeed();
int32_t scrollSpeedIconIcn = ICN::UNKNOWN;
uint32_t scrollSpeedIconId = 0;
std::string scrollSpeedName;

if ( scrollSpeed == SCROLL_SPEED_NONE ) {
scrollSpeedName = _( "Off" );
scrollSpeedIconIcn = ICN::SPANEL;
scrollSpeedIconId = 9;
}
else if ( scrollSpeed == SCROLL_SPEED_SLOW ) {
scrollSpeedName = _( "Slow" );
scrollSpeedIconIcn = ICN::CSPANEL;
scrollSpeedIconId = 0;
}
else if ( scrollSpeed == SCROLL_SPEED_NORMAL ) {
scrollSpeedName = _( "Normal" );
scrollSpeedIconIcn = ICN::CSPANEL;
scrollSpeedIconId = 0;
}
else if ( scrollSpeed == SCROLL_SPEED_FAST ) {
scrollSpeedName = _( "Fast" );
scrollSpeedIconIcn = ICN::CSPANEL;
scrollSpeedIconId = 1;
}
else if ( scrollSpeed == SCROLL_SPEED_VERY_FAST ) {
scrollSpeedName = _( "Very Fast" );
scrollSpeedIconIcn = ICN::CSPANEL;
scrollSpeedIconId = 2;
}

assert( scrollSpeedIconIcn != ICN::UNKNOWN );

const fheroes2::Sprite & scrollSpeedIcon = fheroes2::AGG::GetICN( scrollSpeedIconIcn, scrollSpeedIconId );
fheroes2::drawOption( optionRoi, scrollSpeedIcon, _( "Scroll Speed" ), std::move( scrollSpeedName ), fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW );
}

SelectedWindow showConfigurationWindow( bool & saveConfiguration )
{
fheroes2::Display & display = fheroes2::Display::instance();
Expand All @@ -175,11 +105,11 @@ namespace
const fheroes2::Rect windowCursorTypeRoi( cursorTypeRoi + windowRoi.getPosition() );
const fheroes2::Rect windowScrollSpeedRoi( scrollSpeedRoi + windowRoi.getPosition() );

const auto drawOptions = [&windowInterfaceTypeRoi, &windowInterfacePresenceRoi, &windowCursorTypeRoi, &windowScrollSpeedRoi]() {
drawInterfaceType( windowInterfaceTypeRoi );
const auto drawOptions = [&conf, &windowInterfaceTypeRoi, &windowInterfacePresenceRoi, &windowCursorTypeRoi, &windowScrollSpeedRoi]() {
drawInterfaceType( windowInterfaceTypeRoi, conf.isEvilInterfaceEnabled() );
drawInterfacePresence( windowInterfacePresenceRoi );
drawCursorType( windowCursorTypeRoi );
drawScrollSpeed( windowScrollSpeedRoi );
drawCursorType( windowCursorTypeRoi, conf.isMonochromeCursorEnabled() );
drawScrollSpeed( windowScrollSpeedRoi, conf.ScrollSpeed() );
};

drawOptions();
Expand Down
78 changes: 76 additions & 2 deletions src/fheroes2/editor/editor_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ namespace
Animation,
Passabiility,
UpdateSettings,
InterfaceType,
CursorType,
UpdateScrollSpeed,
IncreaseScrollSpeed,
DecreaseScrollSpeed,
Close
};

Expand All @@ -76,6 +81,11 @@ namespace
const fheroes2::Rect animationRoi{ optionOffset.x + offsetBetweenOptions.width, optionOffset.y + offsetBetweenOptions.height, optionWindowSize, optionWindowSize };
const fheroes2::Rect passabilityRoi{ optionOffset.x + offsetBetweenOptions.width * 2, optionOffset.y + offsetBetweenOptions.height, optionWindowSize,
optionWindowSize };
const fheroes2::Rect interfaceTypeRoi{ optionOffset.x, optionOffset.y + offsetBetweenOptions.height * 2, optionWindowSize, optionWindowSize };
const fheroes2::Rect cursorTypeRoi{ optionOffset.x + offsetBetweenOptions.width, optionOffset.y + offsetBetweenOptions.height * 2, optionWindowSize,
optionWindowSize };
const fheroes2::Rect scrollSpeedRoi{ optionOffset.x + offsetBetweenOptions.width * 2, optionOffset.y + offsetBetweenOptions.height * 2, optionWindowSize,
optionWindowSize };

void drawLanguage( const fheroes2::Rect & optionRoi )
{
Expand Down Expand Up @@ -127,7 +137,7 @@ namespace
{
fheroes2::Display & display = fheroes2::Display::instance();

fheroes2::StandardWindow background( 289, 272, true, display );
fheroes2::StandardWindow background( 289, 382, true, display );

const fheroes2::Rect windowRoi = background.activeArea();

Expand All @@ -137,14 +147,23 @@ namespace
const fheroes2::Rect windowHotKeyRoi( hotKeyRoi + windowRoi.getPosition() );
const fheroes2::Rect windowAnimationRoi( animationRoi + windowRoi.getPosition() );
const fheroes2::Rect windowPassabilityRoi( passabilityRoi + windowRoi.getPosition() );
const fheroes2::Rect windowInterfaceTypeRoi( interfaceTypeRoi + windowRoi.getPosition() );
const fheroes2::Rect windowCursorTypeRoi( cursorTypeRoi + windowRoi.getPosition() );
const fheroes2::Rect windowScrollSpeedRoi( scrollSpeedRoi + windowRoi.getPosition() );

const auto drawOptions = [&windowLanguageRoi, &windowGraphicsRoi, &windowAudioRoi, &windowHotKeyRoi, &windowAnimationRoi, &windowPassabilityRoi,
&windowInterfaceTypeRoi, &windowCursorTypeRoi, &windowScrollSpeedRoi]() {
const Settings & conf = Settings::Get();

const auto drawOptions = [&windowLanguageRoi, &windowGraphicsRoi, &windowAudioRoi, &windowHotKeyRoi, &windowAnimationRoi, &windowPassabilityRoi]() {
drawLanguage( windowLanguageRoi );
drawGraphics( windowGraphicsRoi );
drawAudioOptions( windowAudioRoi );
drawHotKeyOptions( windowHotKeyRoi );
drawAnimationOptions( windowAnimationRoi );
drawPassabilityOptions( windowPassabilityRoi );
drawInterfaceType( windowInterfaceTypeRoi, conf.isEvilInterfaceEnabled() );
drawCursorType( windowCursorTypeRoi, conf.isMonochromeCursorEnabled() );
drawScrollSpeed( windowScrollSpeedRoi, conf.ScrollSpeed() );
};

drawOptions();
Expand Down Expand Up @@ -183,6 +202,21 @@ namespace
if ( le.MouseClickLeft( windowPassabilityRoi ) ) {
return DialogAction::Passabiility;
}
if ( le.MouseClickLeft( windowInterfaceTypeRoi ) ) {
return DialogAction::InterfaceType;
}
if ( le.MouseClickLeft( windowCursorTypeRoi ) ) {
return DialogAction::CursorType;
}
if ( le.MouseClickLeft( windowScrollSpeedRoi ) ) {
return DialogAction::UpdateScrollSpeed;
}
if ( le.isMouseWheelUpInArea( windowScrollSpeedRoi ) ) {
return DialogAction::IncreaseScrollSpeed;
}
if ( le.isMouseWheelDownInArea( windowScrollSpeedRoi ) ) {
return DialogAction::DecreaseScrollSpeed;
}

if ( le.isMouseRightButtonPressedInArea( windowLanguageRoi ) ) {
fheroes2::showStandardTextMessage( _( "Select Game Language" ), _( "Change the language of the game." ), 0 );
Expand All @@ -202,6 +236,15 @@ namespace
else if ( le.isMouseRightButtonPressedInArea( windowPassabilityRoi ) ) {
fheroes2::showStandardTextMessage( _( "Passability" ), _( "Toggle display of objects' passability." ), 0 );
}
else if ( le.isMouseRightButtonPressedInArea( windowInterfaceTypeRoi ) ) {
fheroes2::showStandardTextMessage( _( "Interface Type" ), _( "Toggle the type of interface you want to use." ), 0 );
}
else if ( le.isMouseRightButtonPressedInArea( windowCursorTypeRoi ) ) {
fheroes2::showStandardTextMessage( _( "Mouse Cursor" ), _( "Toggle colored cursor on or off. This is only an aesthetic choice." ), 0 );
}
if ( le.isMouseRightButtonPressedInArea( windowScrollSpeedRoi ) ) {
fheroes2::showStandardTextMessage( _( "Scroll Speed" ), _( "Sets the speed at which you scroll the window." ), 0 );
}
else if ( le.isMouseRightButtonPressedInArea( buttonOk.area() ) ) {
fheroes2::showStandardTextMessage( _( "Okay" ), _( "Exit this menu." ), 0 );
}
Expand Down Expand Up @@ -302,6 +345,37 @@ namespace Editor

redrawEditor();

action = DialogAction::Configuration;
break;
case DialogAction::InterfaceType:
conf.setEvilInterface( !conf.isEvilInterfaceEnabled() );
rebuildEditor();
saveConfiguration = true;

action = DialogAction::Configuration;
break;
case DialogAction::CursorType:
conf.setMonochromeCursor( !conf.isMonochromeCursorEnabled() );
saveConfiguration = true;

action = DialogAction::Configuration;
break;
case DialogAction::UpdateScrollSpeed:
conf.SetScrollSpeed( ( conf.ScrollSpeed() + 1 ) % ( SCROLL_SPEED_VERY_FAST + 1 ) );
saveConfiguration = true;

action = DialogAction::Configuration;
break;
case DialogAction::IncreaseScrollSpeed:
conf.SetScrollSpeed( conf.ScrollSpeed() + 1 );
saveConfiguration = true;

action = DialogAction::Configuration;
break;
case DialogAction::DecreaseScrollSpeed:
conf.SetScrollSpeed( conf.ScrollSpeed() - 1 );
saveConfiguration = true;

action = DialogAction::Configuration;
break;
default:
Expand Down
70 changes: 70 additions & 0 deletions src/fheroes2/gui/ui_option_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@

#include "ui_option_item.h"

#include <cassert>
#include <cstdint>
#include <utility>

#include "agg_image.h"
#include "icn.h"
#include "image.h"
#include "screen.h"
#include "settings.h"
#include "translations.h"
#include "ui_text.h"

namespace
Expand All @@ -51,4 +56,69 @@ namespace fheroes2
Blit( icon, 0, 0, display, optionRoi.x, optionRoi.y, icon.width(), icon.height() );
fheroes2::addGradientShadow( icon, display, { optionRoi.x, optionRoi.y }, { -5, 5 } );
}

void drawScrollSpeed( const fheroes2::Rect & optionRoi, const int speed )
{
int32_t scrollSpeedIconIcn = ICN::UNKNOWN;
uint32_t scrollSpeedIconId = 0;
std::string scrollSpeedName;

if ( speed == SCROLL_SPEED_NONE ) {
scrollSpeedName = _( "Off" );
scrollSpeedIconIcn = ICN::SPANEL;
scrollSpeedIconId = 9;
}
else if ( speed == SCROLL_SPEED_SLOW ) {
scrollSpeedName = _( "Slow" );
scrollSpeedIconIcn = ICN::CSPANEL;
scrollSpeedIconId = 0;
}
else if ( speed == SCROLL_SPEED_NORMAL ) {
scrollSpeedName = _( "Normal" );
scrollSpeedIconIcn = ICN::CSPANEL;
scrollSpeedIconId = 0;
}
else if ( speed == SCROLL_SPEED_FAST ) {
scrollSpeedName = _( "Fast" );
scrollSpeedIconIcn = ICN::CSPANEL;
scrollSpeedIconId = 1;
}
else if ( speed == SCROLL_SPEED_VERY_FAST ) {
scrollSpeedName = _( "Very Fast" );
scrollSpeedIconIcn = ICN::CSPANEL;
scrollSpeedIconId = 2;
}

assert( scrollSpeedIconIcn != ICN::UNKNOWN );

const fheroes2::Sprite & scrollSpeedIcon = fheroes2::AGG::GetICN( scrollSpeedIconIcn, scrollSpeedIconId );
fheroes2::drawOption( optionRoi, scrollSpeedIcon, _( "Scroll Speed" ), std::move( scrollSpeedName ), fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW );
}

void drawInterfaceType( const fheroes2::Rect & optionRoi, const bool isEvilInterface )
{
const fheroes2::Sprite & interfaceThemeIcon = fheroes2::AGG::GetICN( ICN::SPANEL, isEvilInterface ? 17 : 16 );

std::string value;
if ( isEvilInterface ) {
value = _( "Evil" );
}
else {
value = _( "Good" );
}

fheroes2::drawOption( optionRoi, interfaceThemeIcon, _( "Interface Type" ), std::move( value ), fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW );
}

void drawCursorType( const fheroes2::Rect & optionRoi, const bool isMonochromeCursor )
{
if ( isMonochromeCursor ) {
fheroes2::drawOption( optionRoi, fheroes2::AGG::GetICN( ICN::SPANEL, 20 ), _( "Mouse Cursor" ), _( "Black & White" ),
fheroes2::UiOptionTextWidth::THREE_ELEMENTS_ROW );
}
else {
fheroes2::drawOption( optionRoi, fheroes2::AGG::GetICN( ICN::SPANEL, 21 ), _( "Mouse Cursor" ), _( "Color" ),
fheroes2::UiOptionTextWidth::THREE_ELEMENTS_ROW );
}
}
}
8 changes: 7 additions & 1 deletion src/fheroes2/gui/ui_option_item.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***************************************************************************
* fheroes2: https://github.com/ihhub/fheroes2 *
* Copyright (C) 2022 *
* Copyright (C) 2022 - 2025 *
* *
* 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 *
Expand Down Expand Up @@ -36,4 +36,10 @@ namespace fheroes2
class Sprite;

void drawOption( const Rect & optionRoi, const Sprite & icon, std::string titleText, std::string valueText, const int32_t textMaxWidth );

void drawScrollSpeed( const fheroes2::Rect & optionRoi, const int speed );

void drawInterfaceType( const fheroes2::Rect & optionRoi, const bool isEvilInterface );

void drawCursorType( const fheroes2::Rect & optionRoi, const bool isMonochromeCursor );
}

0 comments on commit b808340

Please sign in to comment.