Implement Reachmap Color and Opacity Options (#9877)

Co-authored-by: Descacharrado <Luis_koopa@hotmail.com>
Co-authored-by: Gunter Labes <soliton@wesnoth.org>
Co-authored-by: Charles Dang <exodia339@gmail.com>
This commit is contained in:
ForestDragon 2025-02-15 07:39:49 +03:00 committed by GitHub
parent ad65966cc2
commit 93509c8499
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 622 additions and 10 deletions

View File

@ -54,6 +54,7 @@ test_gui2/modal_dialog_test_prompt
test_gui2/modal_dialog_test_simple_item_selector
test_gui2/modal_dialog_test_screenshot_notification
test_gui2/modal_dialog_test_select_orb_colors
test_gui2/modal_dialog_test_reachmap_options
test_gui2/modal_dialog_test_statistics_dialog
test_gui2/modal_dialog_test_surrender_quit
test_gui2/modal_dialog_test_theme_list

View File

@ -137,6 +137,12 @@
type=custom
[/advanced_preference]
[advanced_preference]
field=reach_map
name= _ "Customize Reach Map (Unit Movement UI)"
type=custom
[/advanced_preference]
[advanced_preference]
field=logging
name= _ "Logging"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 433 B

After

Width:  |  Height:  |  Size: 8.0 KiB

View File

@ -58,6 +58,8 @@
moved_orb_color="red"
partial_orb_color="brightorange"
unmoved_orb_color="brightgreen"
reach_map_color="teal"
reach_map_enemy_color="red"
[/colors]
[images]

View File

@ -0,0 +1,193 @@
#textdomain wesnoth-lib
###
### Reach Map Options
###
#define _GUI_REACHMAP_COLOR_CELL PURPOSE COLOR
[column]
border = "left,right,bottom"
border_size = 5
[toggle_button]
id = "reachmap_{PURPOSE}_{COLOR}"
definition = "reachmap_color"
icon = "{COLOR}"
[/toggle_button]
[/column]
#enddef
#define _GUI_REACHMAP_COLOR_ROW PURPOSE
[grid]
id = "reachmap_{PURPOSE}_selection"
[row]
#different color order compared to the orb color menu, putting the default color on the left
{_GUI_REACHMAP_COLOR_CELL {PURPOSE} teal}
{_GUI_REACHMAP_COLOR_CELL {PURPOSE} white}
{_GUI_REACHMAP_COLOR_CELL {PURPOSE} lightblue}
{_GUI_REACHMAP_COLOR_CELL {PURPOSE} red}
{_GUI_REACHMAP_COLOR_CELL {PURPOSE} gold}
{_GUI_REACHMAP_COLOR_CELL {PURPOSE} brightgreen}
{_GUI_REACHMAP_COLOR_CELL {PURPOSE} brightorange}
{_GUI_REACHMAP_COLOR_CELL {PURPOSE} darkred}
{_GUI_REACHMAP_COLOR_CELL {PURPOSE} orange}
{_GUI_REACHMAP_COLOR_CELL {PURPOSE} green}
[/row]
[/grid]
#enddef
#define _GUI_REACHMAP_OPACITY_SLIDER_ROW PURPOSE LABEL
[row]
[column]
horizontal_grow = true
[grid]
[row]
[column]
grow_factor = 0
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
label = {LABEL}
[/label]
[/column]
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_grow = true
[slider]
id = "reachmap_opacity_{PURPOSE}"
definition = "default"
minimum_value = 0
maximum_value = 100
step_size = 1
[/slider]
[/column]
[/row]
[/grid]
[/column]
[/row]
#enddef
[window]
id = "reachmap_options"
description = "Reach Map Options"
[resolution]
definition = "default"
click_dismiss = true
maximum_width = 600
maximum_height = 600
[tooltip]
id = "tooltip"
[/tooltip]
[helptip]
id = "tooltip"
[/helptip]
[grid]
[row]
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "title"
label = _ "Reach Map Options"
[/label]
[/column]
[/row]
[row]
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "default"
label = _ "Highlight Color"
[/label]
[/column]
[/row]
[row]
[column]
horizontal_alignment = "left"
{_GUI_REACHMAP_COLOR_ROW standard_color}
[/column]
[/row]
{GUI_FILLER_ROW HEIGHT=15}
[row]
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "default"
label = _ "Enemy Highlight Color"
[/label]
[/column]
[/row]
[row]
[column]
horizontal_alignment = "left"
{_GUI_REACHMAP_COLOR_ROW enemy_color}
[/column]
[/row]
{GUI_FILLER_ROW HEIGHT=15}
{_GUI_REACHMAP_OPACITY_SLIDER_ROW border _"Border Opacity:"}
{_GUI_REACHMAP_OPACITY_SLIDER_ROW tint _"Tint Opacity:"}
{GUI_FILLER_ROW HEIGHT=15}
[row]
[column]
horizontal_grow = true
[grid]
[row]
[column]
horizontal_alignment = "left"
grow_factor = 1
border = "all"
border_size = 5
[button]
id = "reachmap_defaults"
definition = "default"
label = _ "Defaults"
[/button]
[/column]
[column]
horizontal_alignment = "right"
grow_factor = 0
border = "all"
border_size = 5
[button]
id = "ok"
definition = "default"
label = _ "OK"
[/button]
[/column]
[column]
horizontal_alignment = "right"
grow_factor = 0
border = "all"
border_size = 5
[button]
id = "cancel"
definition = "default"
label = _ "Cancel"
[/button]
[/column]
[/row]
[/grid]
[/column]
[/row]
[/grid]
[/resolution]
[/window]

View File

@ -0,0 +1,111 @@
#textdomain wesnoth-lib
###
### Definition of a selectable orb button.
###
#define _GUI_ICON SIZE STATE
[image]
x = 0
y = 0
w = {SIZE}
h = {SIZE}
name = "('buttons/misc/orb[state].png~RC(magenta>[icon])' where state = '{STATE}')"
[/image]
#enddef
#define _GUI_RESOLUTION RESOLUTION SIZE
[resolution]
{RESOLUTION}
min_width = {SIZE}
min_height = {SIZE}
default_width = {SIZE}
default_height = {SIZE}
max_width = {SIZE}
max_height = {SIZE}
text_extra_width = 0
text_font_size = 0
[state]
[enabled]
[draw]
{_GUI_ICON ({SIZE}) ()}
[/draw]
[/enabled]
[disabled]
[draw]
{_GUI_ICON ({SIZE}) ()}
[/draw]
[/disabled]
[focused]
[draw]
{_GUI_ICON ({SIZE}) (-active)}
[/draw]
[/focused]
[/state]
###
### Selected
###
[state]
[enabled]
[draw]
[image]
x = 0
y = 0
w = {SIZE}
h = {SIZE}
name = "buttons/misc/orb-pressed-bg.png"
[/image]
{_GUI_ICON ({SIZE}) (-pressed)}
[/draw]
[/enabled]
[disabled]
[draw]
[image]
x = 0
y = 0
w = {SIZE}
h = {SIZE}
name = "buttons/misc/orb-pressed-bg.png"
[/image]
{_GUI_ICON ({SIZE}) (-pressed)}
[/draw]
[/disabled]
[focused]
[draw]
[image]
x = 0
y = 0
w = {SIZE}
h = {SIZE}
name = "buttons/misc/orb-pressed-bg-active.png"
[/image]
{_GUI_ICON ({SIZE}) (-active)}
[/draw]
[/focused]
[/state]
[/resolution]
#enddef
[toggle_button_definition]
id = "reachmap_color"
description = "This toggle button is meant to be used in the reach map options dialog."
{_GUI_RESOLUTION () 30 }
[/toggle_button_definition]
#undef _GUI_RESOLUTION
#undef _GUI_ICON

View File

@ -50,6 +50,8 @@
{SIMPLE_KEY show_partial_orb bool}
{SIMPLE_KEY show_status_on_ally_orb bool}
{SIMPLE_KEY show_unmoved_orb bool}
{SIMPLE_KEY reach_map_border_opacity int}
{SIMPLE_KEY reach_map_tint_opacity int}
[tag]
name="server"
max=infinite
@ -64,6 +66,8 @@
{SIMPLE_KEY moved_orb_color string}
{SIMPLE_KEY partial_orb_color string}
{SIMPLE_KEY unmoved_orb_color string}
{SIMPLE_KEY reach_map_color string}
{SIMPLE_KEY reach_map_enemy_color string}
[/tag]
[tag]
name="images"

View File

@ -719,6 +719,8 @@
<Unit filename="../../src/gui/dialogs/outro.hpp" />
<Unit filename="../../src/gui/dialogs/preferences_dialog.cpp" />
<Unit filename="../../src/gui/dialogs/preferences_dialog.hpp" />
<Unit filename="../../src/gui/dialogs/reachmap_options.cpp" />
<Unit filename="../../src/gui/dialogs/reachmap_options.hpp" />
<Unit filename="../../src/gui/dialogs/screenshot_notification.cpp" />
<Unit filename="../../src/gui/dialogs/screenshot_notification.hpp" />
<Unit filename="../../src/gui/dialogs/select_orb_colors.cpp" />

View File

@ -19,6 +19,7 @@
04C748F7835C62498D27442D /* edit_pbl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6FA542D78393E8FF067775DA /* edit_pbl.cpp */; };
04DC4E59AEDBC1A0AFDCA8CC /* units_dialog.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CAF74C3AB8D456EA3E756396 /* units_dialog.cpp */; };
0554467DB5FE99D85ABCDCA0 /* edit_pbl_translation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00574699A982AA23F12B39E0 /* edit_pbl_translation.cpp */; };
08964907BF0C2F261FC984DC /* reachmap_options.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 231C4A6BB2F1A717F0D6E2E2 /* reachmap_options.hpp */; };
0DA840E1AD033775DD626F42 /* markup.hpp in Headers */ = {isa = PBXBuildFile; fileRef = D7B540678519F0EBD7C19A17 /* markup.hpp */; };
1234567890ABCDEF12345678 /* file_progress.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1234567890ABCDEF12345680 /* file_progress.cpp */; };
1234567890ABCDEF12345679 /* file_progress.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1234567890ABCDEF12345680 /* file_progress.cpp */; };
@ -644,7 +645,9 @@
62D24F2F1519982500350848 /* editor_toolkit.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 62D24F2B1519982500350848 /* editor_toolkit.cpp */; };
62D24F321519987400350848 /* context_manager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 62D24F311519987400350848 /* context_manager.cpp */; };
62D24F351519995200350848 /* palette_manager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 62D24F341519995200350848 /* palette_manager.cpp */; };
63B0402A889C6663911DC677 /* reachmap_options.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 231C4A6BB2F1A717F0D6E2E2 /* reachmap_options.hpp */; };
6A1F44688986D07EB5DBEF75 /* gui_test_dialog.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 0110429EAA81AED07D53B749 /* gui_test_dialog.hpp */; };
6C4A4F7982769422C51DC3E6 /* reachmap_options.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 85514A7D81C52A912FF68AEB /* reachmap_options.cpp */; };
6D574EACA3483ABEE72819F0 /* statistics_record.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27764FB68F02032F1C0B6748 /* statistics_record.cpp */; };
77D94146A5FA29849D1A9BD8 /* multiline_text.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0B0F48CE9CF65D9813BE6CDC /* multiline_text.cpp */; };
7A0347D48BDB52B1430D9E79 /* migrate_version_selection.hpp in Headers */ = {isa = PBXBuildFile; fileRef = B3DE4F95AF72C6F6BC37E695 /* migrate_version_selection.hpp */; };
@ -1310,6 +1313,7 @@
E60E437B8712EC8D22CA2608 /* addon_server_info.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 1E364CB2B7C9E22650753C72 /* addon_server_info.hpp */; };
E6CF415F9FD04C35A55FB24D /* scroll_text.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 755D4555A1DEA29125E7F338 /* scroll_text.cpp */; };
E79249078ACE777D1E219DED /* choose_addon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20E644DC98F26C756364EC2C /* choose_addon.cpp */; };
E875402885AA34096C34E3B0 /* reachmap_options.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 85514A7D81C52A912FF68AEB /* reachmap_options.cpp */; };
EBB44A70837B84A928CB6424 /* edit_pbl_translation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00574699A982AA23F12B39E0 /* edit_pbl_translation.cpp */; };
EC0341E11ECF46FE000F2E2B /* config_attribute_value.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC0341DF1ECF46FE000F2E2B /* config_attribute_value.cpp */; };
EC0341E21ECF4712000F2E2B /* config_attribute_value.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC0341DF1ECF46FE000F2E2B /* config_attribute_value.cpp */; };
@ -1600,6 +1604,7 @@
1C58BBDF21822A930078D25A /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; };
1E364CB2B7C9E22650753C72 /* addon_server_info.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = addon_server_info.hpp; path = addon_server_info.hpp; sourceTree = "<group>"; };
20E644DC98F26C756364EC2C /* choose_addon.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = choose_addon.cpp; sourceTree = "<group>"; };
231C4A6BB2F1A717F0D6E2E2 /* reachmap_options.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = reachmap_options.hpp; path = reachmap_options.hpp; sourceTree = "<group>"; };
26A04033A9545CFE8A226FBD /* test_schema_self_validator.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = test_schema_self_validator.cpp; sourceTree = "<group>"; };
27764FB68F02032F1C0B6748 /* statistics_record.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = statistics_record.cpp; sourceTree = "<group>"; };
2AC74C76BE76F62C771A81E1 /* test_lua_ptr.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = test_lua_ptr.cpp; sourceTree = "<group>"; };
@ -2203,6 +2208,7 @@
7CF14AB694764953E2CB3AF7 /* test_schema_validator.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = test_schema_validator.cpp; sourceTree = "<group>"; };
7FBD4033B4B52E9424819B5F /* gui_test_dialog.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = gui_test_dialog.cpp; sourceTree = "<group>"; };
84234C54BB84519421FD4136 /* general.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = general.cpp; sourceTree = "<group>"; };
85514A7D81C52A912FF68AEB /* reachmap_options.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = reachmap_options.cpp; path = reachmap_options.cpp; sourceTree = "<group>"; };
875E45698F8A8D5B750E7317 /* combobox.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = combobox.cpp; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
8D1107320486CEB800E47090 /* The Battle for Wesnoth.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "The Battle for Wesnoth.app"; sourceTree = BUILT_PRODUCTS_DIR; };
@ -3856,6 +3862,8 @@
46F92CF62174F6A300602C1C /* wml_message.hpp */,
CAF74C3AB8D456EA3E756396 /* units_dialog.cpp */,
8DAD49C8B52CC4E4FD686A60 /* units_dialog.hpp */,
85514A7D81C52A912FF68AEB /* reachmap_options.cpp */,
231C4A6BB2F1A717F0D6E2E2 /* reachmap_options.hpp */,
);
path = dialogs;
sourceTree = "<group>";
@ -5193,6 +5201,7 @@
F7524948ADF9BC097E6D8DBC /* charconv.hpp in Headers */,
00424091A60B5901585B212F /* units_dialog.hpp in Headers */,
48C54CF8AD9615C43EB823E7 /* addon_server_info.hpp in Headers */,
08964907BF0C2F261FC984DC /* reachmap_options.hpp in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -5217,6 +5226,7 @@
92644A76AAB2F29A77107DC0 /* charconv.hpp in Headers */,
96D34041A501AB7F5B7AD596 /* units_dialog.hpp in Headers */,
E60E437B8712EC8D22CA2608 /* addon_server_info.hpp in Headers */,
63B0402A889C6663911DC677 /* reachmap_options.hpp in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -5953,6 +5963,7 @@
99494BD0ABBAE79FB3814E00 /* charconv.cpp in Sources */,
04DC4E59AEDBC1A0AFDCA8CC /* units_dialog.cpp in Sources */,
DA2B4478B9C7AB102479C322 /* addon_server_info.cpp in Sources */,
6C4A4F7982769422C51DC3E6 /* reachmap_options.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -6626,6 +6637,7 @@
355942A786D57DD0A6A93E2A /* units_dialog.cpp in Sources */,
52074B55B6C7AC8A1AE8BEA8 /* addon_server_info.cpp in Sources */,
144E49509EAC409649899BD4 /* test_lua_ptr.cpp in Sources */,
E875402885AA34096C34E3B0 /* reachmap_options.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -248,6 +248,7 @@ gui/dialogs/preferences_dialog.cpp
gui/dialogs/prompt.cpp
gui/dialogs/screenshot_notification.cpp
gui/dialogs/select_orb_colors.cpp
gui/dialogs/reachmap_options.cpp
gui/dialogs/server_info_dialog.cpp
gui/dialogs/simple_item_selector.cpp
gui/dialogs/sp_options_configure.cpp

View File

@ -125,6 +125,13 @@ bool show_partial_orb;
bool show_status_on_ally_orb;
bool show_unmoved_orb;
//
// Reach map opacity variables
//
int reach_map_border_opacity;
int reach_map_tint_opacity;
//
// Music constants
//
@ -159,6 +166,8 @@ std::string enemy_orb_color;
std::string moved_orb_color;
std::string partial_orb_color;
std::string unmoved_orb_color;
std::string reach_map_color;
std::string reach_map_enemy_color;
std::string default_color_list;
} // namespace colors
@ -298,11 +307,13 @@ void load_config(const config &v)
if(auto i = v.optional_child("colors")){
using namespace game_config::colors;
moved_orb_color = i["moved_orb_color"].str();
unmoved_orb_color = i["unmoved_orb_color"].str();
partial_orb_color = i["partial_orb_color"].str();
enemy_orb_color = i["enemy_orb_color"].str();
ally_orb_color = i["ally_orb_color"].str();
moved_orb_color = i["moved_orb_color"].str();
unmoved_orb_color = i["unmoved_orb_color"].str();
partial_orb_color = i["partial_orb_color"].str();
enemy_orb_color = i["enemy_orb_color"].str();
ally_orb_color = i["ally_orb_color"].str();
reach_map_color = i["reach_map_color"].str();
reach_map_enemy_color = i["reach_map_enemy_color"].str();
} // colors
show_ally_orb = v["show_ally_orb"].to_bool(true);
@ -373,6 +384,8 @@ void load_config(const config &v)
shroud_prefix = v["shroud_prefix"].str();
fog_prefix = v["fog_prefix"].str();
reach_map_prefix = v["reach_map_prefix"].str();
reach_map_border_opacity = v["reach_map_border_opacity"].to_int(100);
reach_map_tint_opacity = v["reach_map_tint_opacity"].to_int(50);//tint is at 50% by default instead of 100% to allow players to make it more opaque than normal
add_color_info(game_config_view::wrap(v), true);

View File

@ -87,6 +87,8 @@ namespace game_config
extern std::string moved_orb_color;
extern std::string partial_orb_color;
extern std::string unmoved_orb_color;
extern std::string reach_map_color;
extern std::string reach_map_enemy_color;
extern std::string default_color_list;
} // colors
@ -97,6 +99,8 @@ namespace game_config
extern bool show_partial_orb;
extern bool show_status_on_ally_orb;
extern bool show_unmoved_orb;
extern int reach_map_border_opacity;
extern int reach_map_tint_opacity;
namespace images {
extern std::string game_title,

View File

@ -270,8 +270,11 @@ void game_display::draw_hex(const map_location& loc)
// Draw reach_map information.
if(!is_shrouded && !reach_map_.empty() && reach_map_.find(loc) != reach_map_.end()) {
// draw the blue tint below units and high terrain graphics
drawing_buffer_add(drawing_layer::reachmap_highlight, loc, [tex = image::get_texture(game_config::reach_map_prefix + ".png", image::HEXED)](const rect& dest) {
// draw the reachmap tint below units and high terrain graphics
std::string color = prefs::get().reach_map_color();
std::string tint_opacity = std::to_string(prefs::get().reach_map_tint_opacity());
drawing_buffer_add(drawing_layer::reachmap_highlight, loc, [tex = image::get_texture(game_config::reach_map_prefix + ".png~RC(magenta>"+color+")~O("+tint_opacity+"%)", image::HEXED)](const rect& dest) {
draw::blit(tex, dest);
});
// We remove the reachmap border mask of the hovered hex to avoid weird interactions with other visual objects.
@ -716,10 +719,15 @@ std::vector<texture> game_display::get_reachmap_images(const map_location& loc)
std::string suffix;
std::string name;
stream << *image_prefix_;
std::string color = prefs::get().reach_map_color();
std::string enemy_color = prefs::get().reach_map_enemy_color();
std::string border_opacity = std::to_string(prefs::get().reach_map_border_opacity());
if(tiles[i] == ENEMY) {
suffix = ".png~RC(magenta>red)";
suffix = ".png~RC(magenta>"+enemy_color+")~O("+border_opacity+"%)";
} else {
suffix = ".png~RC(magenta>teal)";
suffix = ".png~RC(magenta>"+color+")~O("+border_opacity+"%)";
}
for(int cap2 = 0; tiles[i] != REACH && cap2 != 6; i = (i + 1) % 6, ++cap2) {

View File

@ -38,6 +38,7 @@
#include "gui/dialogs/log_settings.hpp"
#include "gui/dialogs/multiplayer/mp_alerts_options.hpp"
#include "gui/dialogs/select_orb_colors.hpp"
#include "gui/dialogs/reachmap_options.hpp"
#include "gui/dialogs/title_screen.hpp"
#include "gui/dialogs/game_version_dialog.hpp"
@ -1086,6 +1087,8 @@ void preferences_dialog::on_advanced_prefs_list_select(listbox& list)
gui2::dialogs::log_settings::display();
} else if(pref.field == "orb_color") {
gui2::dialogs::select_orb_colors::display();
} else if(pref.field == "reach_map") {
gui2::dialogs::reachmap_options::display();
} else {
WRN_GUI_L << "Invalid or unimplemented custom advanced prefs option: " << pref.field;
}

View File

@ -0,0 +1,120 @@
/*
Copyright (C) 2023 - 2024
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
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.
See the COPYING file for more details.
*/
#define GETTEXT_DOMAIN "wesnoth-lib"
#include "gui/dialogs/reachmap_options.hpp"
#include "gui/auxiliary/iterator/iterator.hpp"
#include "gui/core/event/dispatcher.hpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/grid.hpp"
#include "gui/widgets/toggle_button.hpp"
#include "gui/widgets/window.hpp"
#include "gui/widgets/slider.hpp"
#include "game_config.hpp"
#include "preferences/preferences.hpp"
#include <functional>
namespace gui2::dialogs
{
namespace
{
std::string get_reachmap_widget_prefix(const std::string& base_id)
{
return "reachmap_" + base_id + "_";
}
} // namespace
REGISTER_DIALOG(reachmap_options)
reachmap_options::reachmap_options()
: modal_dialog(window_id())
{
}
void reachmap_options::pre_show()
{
setup_reachmap_group("standard_color", prefs::get().reach_map_color());
setup_reachmap_group("enemy_color", prefs::get().reach_map_enemy_color());
//set the sliders to the current value of opacity settings
find_widget<slider>("reachmap_opacity_border").set_value(prefs::get().reach_map_border_opacity());
find_widget<slider>("reachmap_opacity_tint").set_value(prefs::get().reach_map_tint_opacity());
connect_signal_mouse_left_click(
find_widget<button>("reachmap_defaults"), std::bind(&reachmap_options::reset_reachmap_callback, this));
}
void reachmap_options::post_show()
{
if(get_retval() != retval::OK) {
return;
}
//set the colors and opacity based on selected options:
prefs::get().set_reach_map_color(groups_["standard_color"].get_active_member_value());
prefs::get().set_reach_map_enemy_color(groups_["enemy_color"].get_active_member_value());
prefs::get().set_reach_map_border_opacity(find_widget<slider>("reachmap_opacity_border").get_value());
prefs::get().set_reach_map_tint_opacity(find_widget<slider>("reachmap_opacity_tint").get_value());
}
void reachmap_options::setup_reachmap_group(const std::string& base_id, const std::string& initial)
{
//
// Set up the toggle group.
//
group<std::string>& group = groups_[base_id];
// Grid containing each color option toggle.
const std::string prefix = get_reachmap_widget_prefix(base_id);
grid& selection = find_widget<grid>(prefix + "selection");
for(iteration::bottom_up_iterator<true, false, true> iter(selection); !iter.at_end(); ++iter) {
if(toggle_button* button = dynamic_cast<toggle_button*>(iter.get())) {
const std::string& id = button->id();
group.add_member(button, id.substr(prefix.size()));
}
}
group.set_member_states(initial);
}
void reachmap_options::reset_reachmap_group(const std::string& base_id, const std::string& initial)
{
groups_[base_id].set_member_states(initial);
}
void reachmap_options::reset_reachmap_slider(const std::string& base_id, const int& initial)
{
find_widget<slider>(base_id).set_value(initial);
}
void reachmap_options::reset_reachmap_callback()
{
reset_reachmap_group("standard_color", game_config::colors::reach_map_color);
reset_reachmap_group("enemy_color", game_config::colors::reach_map_enemy_color);
reset_reachmap_slider("reachmap_opacity_border", game_config::reach_map_border_opacity);
reset_reachmap_slider("reachmap_opacity_tint", game_config::reach_map_tint_opacity);
}
} // namespace gui2::dialogs

View File

@ -0,0 +1,60 @@
/*
Copyright (C) 2023 - 2024
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
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.
See the COPYING file for more details.
*/
#pragma once
#include "gui/dialogs/modal_dialog.hpp"
#include "gui/widgets/group.hpp"
#include <map>
namespace gui2::dialogs
{
class reachmap_options : public modal_dialog
{
public:
reachmap_options();
DEFINE_SIMPLE_DISPLAY_WRAPPER(reachmap_options)
private:
/**
* Sets up the checkbox and row of color buttons for the one-color options, including
* connecting the callbacks for user interaction.
*
* @param base_id which group of checkboxes and buttons to affect
* @param initial which color to select (input only)
*/
void setup_reachmap_group(const std::string& base_id, const std::string& initial);
/**
* Change the UI's ticked/unticked state. Neither sets up nor triggers callbacks.
*/
void reset_reachmap_group(const std::string& base_id, const std::string& initial);
void reset_reachmap_slider(const std::string& base_id, const int& initial);
void reset_reachmap_callback();
std::map<std::string, group<std::string>> groups_;
virtual void pre_show() override;
virtual void post_show() override;
virtual const std::string& window_id() const override;
};
} // namespace gui2::dialogs

View File

@ -580,6 +580,45 @@ std::string prefs::partial_color() {
void prefs::set_partial_color(const std::string& color_id) {
preferences_[prefs_list::partial_orb_color] = color_id;
}
std::string prefs::reach_map_color() {
std::string reachmap_color = preferences_[prefs_list::reach_map_color].str();
if (reachmap_color.empty())
return game_config::colors::reach_map_color;
return fix_orb_color_name(reachmap_color);
}
void prefs::set_reach_map_color(const std::string& color_id) {
preferences_[prefs_list::reach_map_color] = color_id;
}
std::string prefs::reach_map_enemy_color() {
std::string reachmap_enemy_color = preferences_[prefs_list::reach_map_enemy_color].str();
if (reachmap_enemy_color.empty())
return game_config::colors::reach_map_enemy_color;
return fix_orb_color_name(reachmap_enemy_color);
}
void prefs::set_reach_map_enemy_color(const std::string& color_id) {
preferences_[prefs_list::reach_map_enemy_color] = color_id;
}
int prefs::reach_map_border_opacity()
{
return preferences_[prefs_list::reach_map_border_opacity].to_int();
}
void prefs::set_reach_map_border_opacity(const int new_opacity)
{
preferences_[prefs_list::reach_map_border_opacity] = new_opacity;
}
int prefs::reach_map_tint_opacity()
{
return preferences_[prefs_list::reach_map_tint_opacity].to_int();
}
void prefs::set_reach_map_tint_opacity(const int new_opacity)
{
preferences_[prefs_list::reach_map_tint_opacity] = new_opacity;
}
point prefs::resolution()
{

View File

@ -313,6 +313,18 @@ public:
std::string moved_color();
void set_moved_color(const std::string& color_id);
std::string reach_map_color();
void set_reach_map_color(const std::string& color_id);
std::string reach_map_enemy_color();
void set_reach_map_enemy_color(const std::string& color_id);
int reach_map_border_opacity();
void set_reach_map_border_opacity(const int new_opacity);
int reach_map_tint_opacity();
void set_reach_map_tint_opacity(const int new_opacity);
int scroll_speed();
void set_scroll_speed(const int scroll);
@ -816,6 +828,10 @@ private:
prefs_list::animate_map,
prefs_list::animate_water,
prefs_list::addon_icons,
prefs_list::reach_map_border_opacity,
prefs_list::reach_map_tint_opacity,
prefs_list::reach_map_color,
prefs_list::reach_map_enemy_color,
};
static constexpr std::array synced_children_{
prefs_list::acquaintance,

View File

@ -324,6 +324,14 @@ struct preferences_list_defines
ADDPREF(server_message_notif)
/** whether to show the enabled server message sound or notification in the lobby as well */
ADDPREF(server_message_lobby)
/** opacity of the reach map border, 100 being 100% of the original image opacity, 0 being invisible */
ADDPREF(reach_map_border_opacity)
/** the color of the reach map */
ADDPREF(reach_map_color)
/** the color of tile borders of the reach map that are next to an enemy */
ADDPREF(reach_map_enemy_color)
/** opacity of the reach map tint, 100 being 100% of the original image opacity, 0 being invisible */
ADDPREF(reach_map_tint_opacity)
/** whether to play a sound when the game is ready to be started */
ADDPREF(ready_for_start_sound)
/** whether to show a notification when the game is ready to be started */
@ -563,7 +571,11 @@ struct preferences_list_defines
game_created_sound,
game_created_notif,
game_created_lobby,
addon_icons
addon_icons,
reach_map_border_opacity,
reach_map_tint_opacity,
reach_map_color,
reach_map_enemy_color
)
};
using prefs_list = string_enums::enum_base<preferences_list_defines>;

View File

@ -102,6 +102,7 @@
#include "gui/dialogs/prompt.hpp"
#include "gui/dialogs/screenshot_notification.hpp"
#include "gui/dialogs/select_orb_colors.hpp"
#include "gui/dialogs/reachmap_options.hpp"
#include "gui/dialogs/simple_item_selector.hpp"
#include "gui/dialogs/sp_options_configure.hpp"
#include "gui/dialogs/statistics_dialog.hpp"
@ -587,6 +588,10 @@ BOOST_AUTO_TEST_CASE(modal_dialog_test_select_orb_colors)
{
test<select_orb_colors>();
}
BOOST_AUTO_TEST_CASE(modal_dialog_test_reachmap_options)
{
test<reachmap_options>();
}
BOOST_AUTO_TEST_CASE(modal_dialog_test_statistics_dialog)
{
test<statistics_dialog>();