From 236da32c4948da0da0b3b6bd237f556d6eaad64a Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Tue, 27 Mar 2012 13:28:10 +0300 Subject: [PATCH] Configurable movie/ROM paths --- include/plat-wxwidgets/platform.hpp | 1 + src/core/mainloop.cpp | 3 + src/plat-wxwidgets/editor-paths.cpp | 112 ++++++++++++++++++++++++++++++++++++ src/plat-wxwidgets/mainwindow.cpp | 71 +++++++++++++++++++---- src/plat-wxwidgets/romselect.cpp | 60 +++++++++++++++++-- 5 files changed, 231 insertions(+), 16 deletions(-) create mode 100644 src/plat-wxwidgets/editor-paths.cpp diff --git a/include/plat-wxwidgets/platform.hpp b/include/plat-wxwidgets/platform.hpp index c0096d8c..f6597425 100644 --- a/include/plat-wxwidgets/platform.hpp +++ b/include/plat-wxwidgets/platform.hpp @@ -32,6 +32,7 @@ void wxeditor_axes_display(wxWindow* parent); void wxeditor_authors_display(wxWindow* parent); void wxeditor_settings_display(wxWindow* parent); void wxeditor_hotkeys_display(wxWindow* parent); +void wxeditor_paths_display(wxWindow* parent); std::string wxeditor_keyselect(wxWindow* parent, bool clearable); void wxeditor_screen_display(wxWindow* parent, double& horiz, double& vert, int& flags); diff --git a/src/core/mainloop.cpp b/src/core/mainloop.cpp index 9cd9ec72..5e255122 100644 --- a/src/core/mainloop.cpp +++ b/src/core/mainloop.cpp @@ -94,8 +94,11 @@ public: void set(const std::string& value) throw(std::bad_alloc, std::runtime_error) { + if(value != "") { _firmwarepath = value; default_firmware = false; + } else + blank(); } std::string get() throw(std::bad_alloc) diff --git a/src/plat-wxwidgets/editor-paths.cpp b/src/plat-wxwidgets/editor-paths.cpp new file mode 100644 index 00000000..217313ee --- /dev/null +++ b/src/plat-wxwidgets/editor-paths.cpp @@ -0,0 +1,112 @@ +#include "plat-wxwidgets/platform.hpp" +#include "core/settings.hpp" +#include "library/string.hpp" + +#include +#include +#include +#include +#include +#include + +#include +#include + +#define FIRMWAREPATH "firmwarepath" +#define ROMPATH "rompath" +#define MOVIEPATH "moviepath" + +class wxeditor_paths : public wxDialog +{ +public: + wxeditor_paths(wxWindow* parent); + ~wxeditor_paths(); + bool ShouldPreventAppExit() const; + void on_cancel(wxCommandEvent& e); + void on_ok(wxCommandEvent& e); +private: + wxButton* okbutton; + wxButton* cancel; + wxTextCtrl* rompath; + wxTextCtrl* moviepath; + wxTextCtrl* firmwarepath; +}; + +wxeditor_paths::wxeditor_paths(wxWindow* parent) + : wxDialog(parent, wxID_ANY, wxT("lsnes: Paths"), wxDefaultPosition, wxSize(-1, -1)) +{ + std::string cur_rompath, cur_moviepath, cur_firmwarepath; + runemufn([&cur_firmwarepath, &cur_moviepath, &cur_rompath]() { + cur_firmwarepath = setting::get(FIRMWAREPATH); + cur_rompath = setting::get(ROMPATH); + cur_moviepath = setting::get(MOVIEPATH); + }); + + Centre(); + wxFlexGridSizer* top_s = new wxFlexGridSizer(2, 1, 0, 0); + SetSizer(top_s); + + wxFlexGridSizer* t_s = new wxFlexGridSizer(3, 2, 0, 0); + t_s->Add(new wxStaticText(this, wxID_ANY, wxT("ROMs:")), 0, wxGROW); + t_s->Add(rompath = new wxTextCtrl(this, wxID_ANY, towxstring(cur_rompath), wxDefaultPosition, wxSize(400, -1)), + 1, wxGROW); + t_s->Add(new wxStaticText(this, wxID_ANY, wxT("Movies:")), 0, wxGROW); + t_s->Add(moviepath = new wxTextCtrl(this, wxID_ANY, towxstring(cur_moviepath), wxDefaultPosition, + wxSize(400, -1)), 1, wxGROW); + t_s->Add(new wxStaticText(this, wxID_ANY, wxT("Firmware:")), 0, wxGROW); + t_s->Add(firmwarepath = new wxTextCtrl(this, wxID_ANY, towxstring(cur_firmwarepath), wxDefaultPosition, + wxSize(400, -1)), 1, wxGROW); + top_s->Add(t_s); + + wxBoxSizer* pbutton_s = new wxBoxSizer(wxHORIZONTAL); + pbutton_s->AddStretchSpacer(); + pbutton_s->Add(okbutton = new wxButton(this, wxID_OK, wxT("OK")), 0, wxGROW); + pbutton_s->Add(cancel = new wxButton(this, wxID_CANCEL, wxT("Cancel")), 0, wxGROW); + okbutton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_paths::on_ok), NULL, this); + cancel->Connect(wxEVT_COMMAND_BUTTON_CLICKED, + wxCommandEventHandler(wxeditor_paths::on_cancel), NULL, this); + top_s->Add(pbutton_s, 0, wxGROW); + + t_s->SetSizeHints(this); + top_s->SetSizeHints(this); + Fit(); +} + +wxeditor_paths::~wxeditor_paths() +{ +} + +bool wxeditor_paths::ShouldPreventAppExit() const +{ + return false; +} + +void wxeditor_paths::on_cancel(wxCommandEvent& e) +{ + EndModal(wxID_CANCEL); +} + +void wxeditor_paths::on_ok(wxCommandEvent& e) +{ + std::string cur_rompath = tostdstring(rompath->GetValue()); + std::string cur_moviepath = tostdstring(moviepath->GetValue()); + std::string cur_firmwarepath = tostdstring(firmwarepath->GetValue()); + runemufn([cur_firmwarepath, cur_moviepath, cur_rompath]() { + setting::set(ROMPATH, cur_rompath); + setting::set(MOVIEPATH, cur_moviepath); + setting::set(FIRMWAREPATH, cur_firmwarepath); + }); + EndModal(wxID_OK); +} + +void wxeditor_paths_display(wxWindow* parent) +{ + modal_pause_holder hld; + wxDialog* editor; + try { + editor = new wxeditor_paths(parent); + editor->ShowModal(); + } catch(...) { + } + editor->Destroy(); +} diff --git a/src/plat-wxwidgets/mainwindow.cpp b/src/plat-wxwidgets/mainwindow.cpp index df1a02f9..b459de43 100644 --- a/src/plat-wxwidgets/mainwindow.cpp +++ b/src/plat-wxwidgets/mainwindow.cpp @@ -79,7 +79,8 @@ enum wxID_SHOW_STATUS, wxID_SET_SPEED, wxID_SET_VOLUME, - wxID_SET_SCREEN + wxID_SET_SCREEN, + wxID_SET_PATHS }; @@ -423,6 +424,52 @@ namespace { runuifun([ahmenu]() { ahmenu->reconfigure(); }); } + + + class movie_path_setting : public setting + { + public: + movie_path_setting() : setting("moviepath") { _moviepath = "."; default_movie = true; } + void blank() throw(std::bad_alloc, std::runtime_error) + { + _moviepath = "."; + default_movie = true; + } + + bool is_set() throw() + { + return !default_movie; + } + + void set(const std::string& value) throw(std::bad_alloc, std::runtime_error) + { + if(value != "") { + _moviepath = value; + default_movie = false; + } else + blank(); + } + + std::string get() throw(std::bad_alloc) + { + return _moviepath; + } + + operator std::string() throw(std::bad_alloc) + { + return _moviepath; + } + private: + std::string _moviepath; + bool default_movie; + } moviepath_setting; + + std::string movie_path() + { + std::string x; + runemufn([&x]() { x = setting::get("moviepath"); }); + return x; + } } void boot_emulator(loaded_rom& rom, moviefile& movie) @@ -671,7 +718,6 @@ wxwin_mainwindow::wxwin_mainwindow() menu_start(wxT("Settings")); menu_entry(wxID_EDIT_AXES, wxT("Configure axes")); menu_entry(wxID_EDIT_SETTINGS, wxT("Configure settings")); - menu_entry(wxID_EDIT_HOTKEYS, wxT("Configure hotkeys")); menu_entry(wxID_EDIT_KEYBINDINGS, wxT("Configure keybindings")); menu_entry(wxID_EDIT_ALIAS, wxT("Configure aliases")); menu_entry(wxID_EDIT_JUKEBOX, wxT("Configure jukebox")); @@ -679,6 +725,8 @@ wxwin_mainwindow::wxwin_mainwindow() menu_entry_check(wxID_SHOW_STATUS, wxT("Show status panel")); menu_entry(wxID_SET_SPEED, wxT("Set speed")); menu_entry(wxID_SET_SCREEN, wxT("Set screen scaling")); + menu_entry(wxID_SET_PATHS, wxT("Set paths")); + menu_entry(wxID_EDIT_HOTKEYS, wxT("Configure hotkeys")); menu_check(wxID_SHOW_STATUS, true); if(platform::sound_initialized()) { //Sound menu: (ACFOS)EHU @@ -787,31 +835,31 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e) platform::queue("cancel-saves"); return; case wxID_LOAD_MOVIE: - platform::queue("load-movie " + pick_file(this, "Load Movie", ".")); + platform::queue("load-movie " + pick_file(this, "Load Movie", movie_path())); return; case wxID_LOAD_STATE: - platform::queue("load " + pick_file(this, "Load State", ".")); + platform::queue("load " + pick_file(this, "Load State", movie_path())); return; case wxID_LOAD_STATE_RO: - platform::queue("load-readonly " + pick_file(this, "Load State (Read-Only)", ".")); + platform::queue("load-readonly " + pick_file(this, "Load State (Read-Only)", movie_path())); return; case wxID_LOAD_STATE_RW: - platform::queue("load-state " + pick_file(this, "Load State (Read-Write)", ".")); + platform::queue("load-state " + pick_file(this, "Load State (Read-Write)", movie_path())); return; case wxID_LOAD_STATE_P: - platform::queue("load-preserve " + pick_file(this, "Load State (Preserve)", ".")); + platform::queue("load-preserve " + pick_file(this, "Load State (Preserve)", movie_path())); return; case wxID_REWIND_MOVIE: platform::queue("rewind-movie"); return; case wxID_SAVE_MOVIE: - platform::queue("save-movie " + pick_file(this, "Save Movie", ".")); + platform::queue("save-movie " + pick_file(this, "Save Movie", movie_path())); return; case wxID_SAVE_STATE: - platform::queue("save-state " + pick_file(this, "Save State", ".")); + platform::queue("save-state " + pick_file(this, "Save State", movie_path())); return; case wxID_SAVE_SCREENSHOT: - platform::queue("take-screenshot " + pick_file(this, "Save State", ".")); + platform::queue("take-screenshot " + pick_file(this, "Save Screenshot", movie_path())); return; case wxID_RUN_SCRIPT: platform::queue("run-script " + pick_file_member(this, "Select Script", ".")); @@ -1043,5 +1091,8 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e) case wxID_SET_SCREEN: wxeditor_screen_display(this, horizontal_multiplier, vertical_multiplier, libswscale_flags); return; + case wxID_SET_PATHS: + wxeditor_paths_display(this); + return; }; } diff --git a/src/plat-wxwidgets/romselect.cpp b/src/plat-wxwidgets/romselect.cpp index 0c599063..328d2fa1 100644 --- a/src/plat-wxwidgets/romselect.cpp +++ b/src/plat-wxwidgets/romselect.cpp @@ -6,6 +6,7 @@ #include "core/moviedata.hpp" #include "core/framerate.hpp" +#include "core/settings.hpp" #include "library/zip.hpp" #include "plat-wxwidgets/platform.hpp" @@ -276,6 +277,50 @@ namespace private: wxTextCtrl* ctrl; }; + + class rom_path_setting : public setting + { + public: + rom_path_setting() : setting("rompath") { _rompath = "."; default_rom = true; } + void blank() throw(std::bad_alloc, std::runtime_error) + { + _rompath = "."; + default_rom = true; + } + + bool is_set() throw() + { + return !default_rom; + } + + void set(const std::string& value) throw(std::bad_alloc, std::runtime_error) + { + if(value != "") { + _rompath = value; + default_rom = false; + } else + blank(); + } + + std::string get() throw(std::bad_alloc) + { + return _rompath; + } + + operator std::string() throw(std::bad_alloc) + { + return _rompath; + } + private: + std::string _rompath; + bool default_rom; + } rompath_setting; + + std::string rom_path() + { + //This is pre-boot, so read directly. + return setting::get("rompath"); + } } @@ -317,7 +362,7 @@ wxwin_romselect::wxwin_romselect() romgrid->Add(rom_label[i] = new wxStaticText(this, wxID_ANY, wxT("")), 0, wxGROW); romgrid->Add(rom_name[i] = new wxTextCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(500, -1)), 1, wxGROW); - romgrid->Add(rom_change[i] = new wxButton(this, ROM_SELECTS_BASE + i, wxT("...")), 0, wxGROW); + romgrid->Add(rom_change[i] = new wxButton(this, ROM_SELECTS_BASE + i, wxT("Pick")), 0, wxGROW); rom_name[i]->Connect(wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler(wxwin_romselect::on_filename_change), NULL, this); rom_change[i]->Connect(wxEVT_COMMAND_BUTTON_CLICKED, @@ -384,7 +429,7 @@ void wxwin_romselect::on_ask_rom_filename(wxCommandEvent& e) { try { std::string fname = pick_file_member(this, "Choose " + tostdstring( - rom_label[e.GetId() - ROM_SELECTS_BASE]->GetLabel()), "."); + rom_label[e.GetId() - ROM_SELECTS_BASE]->GetLabel()), rom_path()); wxTextCtrl* textbox = rom_name[e.GetId() - ROM_SELECTS_BASE]; if(textbox) textbox->SetValue(towxstring(fname)); @@ -502,7 +547,7 @@ wxwin_patch::wxwin_patch(loaded_rom& rom) patchsel->Add(new wxStaticText(this, wxID_ANY, wxT("File:")), 0, wxGROW); patchsel->Add(patchfile = new wxTextCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(500, -1)), 1, wxGROW); - patchsel->Add(choosefile = new wxButton(this, wxID_ANY, wxT("...")), 0, wxGROW); + patchsel->Add(choosefile = new wxButton(this, wxID_ANY, wxT("Pick")), 0, wxGROW); patchfile->Connect(wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler(wxwin_patch::on_patchfile_change), NULL, this); choosefile->Connect(wxEVT_COMMAND_BUTTON_CLICKED, @@ -548,7 +593,7 @@ wxwin_patch::wxwin_patch(loaded_rom& rom) void wxwin_patch::on_ask_patchfile(wxCommandEvent& e) { try { - std::string fname = pick_file_member(this, "Choose patch file", "."); + std::string fname = pick_file_member(this, "Choose patch file", rom_path()); patchfile->SetValue(towxstring(fname)); on_patchfile_change(e); } catch(canceled_exception& e) { @@ -680,7 +725,9 @@ wxwin_project::wxwin_project(loaded_rom& rom) wxFlexGridSizer* fileblock = new wxFlexGridSizer(1, 2, 0, 0); fileblock->Add(savefile = new wxTextCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(500, -1)), 1, wxGROW); - fileblock->Add(ask_savefile = new wxButton(this, ASK_FILENAME_BUTTON, wxT("...")), 0, wxGROW); + savefile->SetDropTarget(new textboxloadfilename(savefile)); + + fileblock->Add(ask_savefile = new wxButton(this, ASK_FILENAME_BUTTON, wxT("Pick")), 0, wxGROW); savefile->Connect(wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler(wxwin_project::on_filename_change), NULL, this); ask_savefile->Connect(wxEVT_COMMAND_BUTTON_CLICKED, @@ -712,7 +759,8 @@ wxwin_project::wxwin_project(loaded_rom& rom) wxFlexGridSizer* fileblock2 = new wxFlexGridSizer(1, 2, 0, 0); fileblock2->Add(sram_files[i] = new wxTextCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(500, -1)), 1, wxGROW); - fileblock2->Add(sram_choosers[i] = new wxButton(this, ASK_SRAMS_BASE + idx, wxT("...")), 0, wxGROW); + sram_files[i]->SetDropTarget(new textboxloadfilename(sram_files[i])); + fileblock2->Add(sram_choosers[i] = new wxButton(this, ASK_SRAMS_BASE + idx, wxT("Pick")), 0, wxGROW); sram_files[i]->Connect(wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler(wxwin_project::on_filename_change), NULL, this); sram_choosers[i]->Connect(wxEVT_COMMAND_BUTTON_CLICKED, -- 2.11.4.GIT