From 9740d24a293ef77dba6411fc617e6d40a6e088df Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Fri, 13 Jan 2012 20:42:49 +0200 Subject: [PATCH] wxwidgets: Allow editing jukebox from the GUI --- include/core/mainloop.hpp | 1 + include/plat-wxwidgets/window_mainwindow.hpp | 1 + src/core/mainloop.cpp | 8 +++++ src/plat-wxwidgets/mainwindow.cpp | 49 +++++++++++++++++++++++++++- 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/include/core/mainloop.hpp b/include/core/mainloop.hpp index bb2ceda2..beaed31c 100644 --- a/include/core/mainloop.hpp +++ b/include/core/mainloop.hpp @@ -11,6 +11,7 @@ void main_loop(struct loaded_rom& rom, struct moviefile& settings, bool load_has_to_succeed = false) throw(std::bad_alloc, std::runtime_error); std::vector get_jukebox_names(); +void set_jukebox_names(const std::vector& newj); void update_movie_state(); #endif \ No newline at end of file diff --git a/include/plat-wxwidgets/window_mainwindow.hpp b/include/plat-wxwidgets/window_mainwindow.hpp index f58b169f..761bf10c 100644 --- a/include/plat-wxwidgets/window_mainwindow.hpp +++ b/include/plat-wxwidgets/window_mainwindow.hpp @@ -38,6 +38,7 @@ public: void handle_menu_click(wxCommandEvent& e); void menu_edit_keybindings(wxCommandEvent& e); void menu_edit_aliases(wxCommandEvent& e); + void menu_edit_jukebox(wxCommandEvent& e); void menu_edit_memorywatch(wxCommandEvent& e); void menu_save_memorywatch(wxCommandEvent& e); void menu_load_memorywatch(wxCommandEvent& e); diff --git a/src/core/mainloop.cpp b/src/core/mainloop.cpp index 6f5dc3d8..7eb693a0 100644 --- a/src/core/mainloop.cpp +++ b/src/core/mainloop.cpp @@ -798,6 +798,14 @@ std::vector get_jukebox_names() return save_jukebox; } +void set_jukebox_names(const std::vector& newj) +{ + save_jukebox = newj; + if(save_jukebox_pointer >= save_jukebox.size()) + save_jukebox_pointer = 0; + update_movie_state(); +} + void main_loop(struct loaded_rom& rom, struct moviefile& initial, bool load_has_to_succeed) throw(std::bad_alloc, std::runtime_error) { diff --git a/src/plat-wxwidgets/mainwindow.cpp b/src/plat-wxwidgets/mainwindow.cpp index 6fdf790d..0bbb4ab0 100644 --- a/src/plat-wxwidgets/mainwindow.cpp +++ b/src/plat-wxwidgets/mainwindow.cpp @@ -20,6 +20,7 @@ #include "plat-wxwidgets/menu_dump.hpp" #include "plat-wxwidgets/platform.hpp" #include "plat-wxwidgets/window_mainwindow.hpp" +#include "plat-wxwidgets/window_status.hpp" #define MAXCONTROLLERS MAX_PORTS * MAX_CONTROLLERS_PER_PORT @@ -66,7 +67,8 @@ enum wxID_LOAD_MEMORYWATCH, wxID_DUMP_FIRST, wxID_DUMP_LAST = wxID_DUMP_FIRST + 1023, - wxID_REWIND_MOVIE + wxID_REWIND_MOVIE, + wxID_EDIT_JUKEBOX }; @@ -829,6 +831,7 @@ wxwin_mainwindow::wxwin_mainwindow() menu_entry(wxID_EDIT_SETTINGS, wxT("Configure settings")); menu_entry(wxID_EDIT_KEYBINDINGS, wxT("Configure keybindings")); menu_entry(wxID_EDIT_ALIAS, wxT("Configure aliases")); + menu_entry(wxID_EDIT_JUKEBOX, wxT("Configure jukebox")); if(platform::sound_initialized()) { //Sound menu: (ACFOS)EHU menu_start(wxT("S&ound")); @@ -1011,6 +1014,9 @@ void wxwin_mainwindow::handle_menu_click(wxCommandEvent& e) case wxID_EDIT_ALIAS: menu_edit_aliases(e); break; + case wxID_EDIT_JUKEBOX: + menu_edit_jukebox(e); + break; case wxID_EDIT_MEMORYWATCH: menu_edit_memorywatch(e); break; @@ -1094,6 +1100,8 @@ void wxwin_mainwindow::menu_edit_keybindings(wxCommandEvent& e) platform::set_modal_pause(false); } +void strip_CR(std::string& x) throw(std::bad_alloc); + void wxwin_mainwindow::menu_edit_aliases(wxCommandEvent& e) { platform::set_modal_pause(true); @@ -1145,6 +1153,45 @@ void wxwin_mainwindow::menu_edit_aliases(wxCommandEvent& e) platform::set_modal_pause(false); } +void wxwin_mainwindow::menu_edit_jukebox(wxCommandEvent& e) +{ + platform::set_modal_pause(true); + std::string x; + std::vector new_jukebox; + runemufn([&x]() { + for(auto i : get_jukebox_names()) + x = x + i + "\n"; + }); + + wxTextEntryDialog* dialog = new wxTextEntryDialog(this, wxT("List jukebox entries"), wxT("Configure jukebox"), + towxstring(x), wxOK | wxCANCEL | wxCENTRE | wxTE_MULTILINE); + if(dialog->ShowModal() == wxID_CANCEL) { + dialog->Destroy(); + platform::set_modal_pause(false); + return; + } + x = tostdstring(dialog->GetValue()); + dialog->Destroy(); + + while(x != "") { + size_t split = x.find_first_of("\n"); + std::string l; + if(split < x.length()) { + l = x.substr(0, split); + x = x.substr(split + 1); + } else { + l = x; + x = ""; + } + strip_CR(l); + if(l != "") + new_jukebox.push_back(l); + } + runemufn([&new_jukebox]() { set_jukebox_names(new_jukebox); }); + status_window->notify_update(); + platform::set_modal_pause(false); +} + void wxwin_mainwindow::menu_load_memorywatch(wxCommandEvent& e) { platform::set_modal_pause(true); -- 2.11.4.GIT