pc/scenario editor: add a basic preferences's menu.

This commit is contained in:
ALONSO Laurent
2022-07-15 15:53:23 +02:00
committed by Celtic Minstrel
parent d83139eaa0
commit 26d2328fe7
11 changed files with 165 additions and 11 deletions

View File

@@ -10,6 +10,7 @@
#include "gfx/render_shapes.hpp"
#include "gfx/render_image.hpp"
#include "fileio/resmgr/res_image.hpp"
#include "dialogxml/widgets/led.hpp"
#include "dialogxml/widgets/message.hpp"
#include "mathutil.hpp"
#ifndef MSBUILD_GITREV

View File

@@ -52,6 +52,7 @@ short current_active_pc = 0;
/* Mac stuff globals */
bool All_Done = false;
bool changed_display_mode = false;
sf::RenderWindow mainPtr;
sf::View mainView;
fs::path file_in_mem;
@@ -65,10 +66,15 @@ void handle_one_event(const sf::Event&);
void redraw_everything();
void Handle_Activate();
void Mouse_Pressed(const sf::Event&);
void init_main_window(sf::RenderWindow&, sf::View&);
void adjust_window(sf::RenderWindow&, sf::View&);
sf::FloatRect compute_viewport(const sf::RenderWindow&, float ui_scale);
bool verify_restore_quit(std::string dlog);
void set_up_apple_events(int argc, char* argv[]);
void pick_preferences();
void save_prefs();
bool prefs_event_filter (cDialog& me, std::string id, eKeyMod);
extern bool cur_scen_is_mac;
extern fs::path progDir;
short specials_res_id;
@@ -79,8 +85,8 @@ int main(int argc, char* argv[]) {
try {
init_directories(argv[0]);
sync_prefs();
init_main_window(mainPtr, mainView);
init_menubar();
adjust_window(mainPtr, mainView);
//init_menubar();
init_fileio();
init_main_buttons();
Set_up_win();
@@ -137,7 +143,7 @@ sf::FloatRect compute_viewport(const sf::RenderWindow& mainPtr, float ui_scale)
return viewport;
}
void init_main_window (sf::RenderWindow& mainPtr, sf::View& mainView) {
void adjust_window (sf::RenderWindow& mainPtr, sf::View& mainView) {
float ui_scale = get_float_pref("UIScale", 1.0);
@@ -167,6 +173,8 @@ void init_main_window (sf::RenderWindow& mainPtr, sf::View& mainView) {
const ImageRsrc& icon = ResMgr::graphics.get("icon", true);
mainPtr.setIcon(icon->getSize().x, icon->getSize().y, icon->copyToImage().getPixelsPtr());
#endif
init_menubar();
}
void handle_events() {
@@ -174,6 +182,11 @@ void handle_events() {
cFramerateLimiter fps_limiter;
while(!All_Done) {
if(changed_display_mode) {
changed_display_mode = false;
adjust_window(mainPtr, mainView);
}
#ifdef __APPLE__
if (menuChoiceId>=0) {
handle_menu_choice(eMenu(menuChoiceId));
@@ -273,7 +286,10 @@ void handle_menu_choice(eMenu item_hit) {
if(verify_restore_quit("save-close"))
file_in_mem = "";
break;
case eMenu::QUIT:
case eMenu::PREFS:
pick_preferences();
break;
case eMenu::QUIT: // quit case eMenu::QUIT:
All_Done = verify_restore_quit("save-quit");
break;
case eMenu::EDIT_GOLD:
@@ -480,3 +496,49 @@ void display_skills(eSkill skill,cDialog* parent) {
skillDlog.run();
}
void save_prefs(){
bool success = sync_prefs();
if(!success){
showWarning("There was a problem writing to the preferences file. When the character editor is next run the preferences will revert to their previously set values.","Should you manage to resolve the problem without closing the program, simply open the preferences screen and click \"OK\" to try again.");
}
}
bool prefs_event_filter (cDialog& me, std::string id, eKeyMod) {
bool did_cancel = false;
if(id == "okay") {
me.toast(true);
} else if(id == "cancel") {
me.toast(false);
did_cancel = true;
}
if(!did_cancel) {
cLed& ui_scale = dynamic_cast<cLed&>(me["scaleui"]);
if(ui_scale.getState() == led_off)
set_pref("UIScale", 1.0);
else if(ui_scale.getState() == led_red)
set_pref("UIScale", 2.0);
set_pref("PlaySounds", dynamic_cast<cLed&>(me["nosound"]).getState() == led_off);
}
save_prefs();
return true;
}
void pick_preferences() {
set_cursor(sword_curs);
cDialog prefsDlog(*ResMgr::dialogs.get("pref-character"));
prefsDlog.attachClickHandlers(&prefs_event_filter, {"okay", "cancel"});
float ui_scale = get_float_pref("UIScale", 1.0);
dynamic_cast<cLed&>(prefsDlog["scaleui"]).setState(ui_scale == 1.0 ? led_off : (ui_scale == 2.0 ? led_red : led_green));
dynamic_cast<cLed&>(prefsDlog["nosound"]).setState(get_bool_pref("PlaySounds", true) ? led_off : led_red);
prefsDlog.run();
if(get_float_pref("UIScale") != ui_scale)
changed_display_mode = true;
}

View File

@@ -40,6 +40,7 @@ void OpenBoEPCEditMenu::add_persistent_menu_items(tgui::MenuBar::Ptr& menubar) c
{ { "File", "Save Game Ctrl-S" }, eMenu::FILE_SAVE },
{ { "File", "Save As... Ctrl-Shift-S" }, eMenu::FILE_SAVE_AS },
{ { "File", "Revert to Saved" }, eMenu::FILE_REVERT },
{ { "File", "Preferences" }, eMenu::PREFS },
{ { "File", "Quit Ctrl-Q" }, eMenu::QUIT },
{ { "Party", "Edit Gold" }, eMenu::EDIT_GOLD },

View File

@@ -17,7 +17,7 @@ bool menuBarProcessEvent(const sf::Event&);
void drawMenuBar();
enum class eMenu {
NONE, ABOUT, QUIT,
NONE, ABOUT, PREFS, QUIT,
FILE_OPEN, FILE_CLOSE, FILE_SAVE, FILE_SAVE_AS, FILE_REVERT, HELP_TOC,
// Edit Party menu
EDIT_GOLD, EDIT_FOOD, EDIT_ALCHEMY,

View File

@@ -65,6 +65,7 @@ void init_menubar() {
MenuHandler* handler = [[[MenuHandler alloc] init] retain];
setMenuCallback([apple_menu itemWithTitle: @"About BoE Character Editor"], handler, @selector(menuChoice:), int(eMenu::ABOUT));
setMenuCallback([apple_menu itemWithTitle: @"Preferences…"], handler, @selector(menuChoice:), int(eMenu::PREFS));
setMenuCallback([apple_menu itemWithTitle: @"Quit BoE Character Editor"], handler, @selector(menuChoice:), int(eMenu::QUIT));
setMenuCallback([[[menu_bar_handle itemWithTitle: @"Help"] submenu] itemAtIndex: 0], handler, @selector(menuChoice:), int(eMenu::HELP_TOC));