|
|
|
@@ -18,12 +18,15 @@
|
|
|
|
|
#include "scen.keydlgs.hpp"
|
|
|
|
|
#include "mathutil.hpp"
|
|
|
|
|
#include "fileio/fileio.hpp"
|
|
|
|
|
#include "dialogxml/widgets/button.hpp"
|
|
|
|
|
#include "dialogxml/widgets/led.hpp"
|
|
|
|
|
#include "dialogxml/widgets/scrollbar.hpp"
|
|
|
|
|
#include "tools/winutil.hpp"
|
|
|
|
|
#include "tools/cursors.hpp"
|
|
|
|
|
#include "dialogxml/dialogs/strdlog.hpp"
|
|
|
|
|
#include "dialogxml/dialogs/choicedlog.hpp"
|
|
|
|
|
#include "scen.menus.hpp"
|
|
|
|
|
#include "fileio/resmgr/res_dialog.hpp"
|
|
|
|
|
#include "fileio/resmgr/res_image.hpp"
|
|
|
|
|
#include "tools/prefs.hpp"
|
|
|
|
|
#include "tools/framerate_limiter.hpp"
|
|
|
|
@@ -37,6 +40,7 @@ short menuChoiceId=-1;
|
|
|
|
|
|
|
|
|
|
/* Globals */
|
|
|
|
|
bool All_Done = false;
|
|
|
|
|
bool changed_display_mode = false;
|
|
|
|
|
sf::RenderWindow mainPtr;
|
|
|
|
|
sf::View mainView;
|
|
|
|
|
cTown* town = nullptr;
|
|
|
|
@@ -63,9 +67,12 @@ void redraw_everything();
|
|
|
|
|
void Mouse_Pressed(const sf::Event&);
|
|
|
|
|
void close_program();
|
|
|
|
|
void ding();
|
|
|
|
|
void init_main_window(sf::RenderWindow&, sf::View&);
|
|
|
|
|
void adjust_windows(sf::RenderWindow&, sf::View&);
|
|
|
|
|
sf::FloatRect compute_viewport(const sf::RenderWindow&, float ui_scale);
|
|
|
|
|
|
|
|
|
|
void pick_preferences();
|
|
|
|
|
void save_prefs();
|
|
|
|
|
|
|
|
|
|
cScenario scenario;
|
|
|
|
|
rectangle right_sbar_rect;
|
|
|
|
|
extern rectangle terrain_buttons_rect;
|
|
|
|
@@ -153,7 +160,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_windows (sf::RenderWindow & mainPtr, sf::View & mainView) {
|
|
|
|
|
|
|
|
|
|
// TODO: things might still be broken when upscaled.
|
|
|
|
|
// translate_mouse_coordinates has been applied in some places but more work might be needed.
|
|
|
|
@@ -186,13 +193,14 @@ 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 init_scened(int argc, char* argv[]) {
|
|
|
|
|
init_directories(argv[0]);
|
|
|
|
|
sync_prefs();
|
|
|
|
|
init_main_window(mainPtr, mainView);
|
|
|
|
|
init_menubar();
|
|
|
|
|
adjust_windows(mainPtr, mainView);
|
|
|
|
|
//init_menubar();
|
|
|
|
|
init_shaders();
|
|
|
|
|
init_tiling();
|
|
|
|
|
init_snd_tool();
|
|
|
|
@@ -232,6 +240,11 @@ void handle_events() {
|
|
|
|
|
cFramerateLimiter fps_limiter;
|
|
|
|
|
|
|
|
|
|
while(!All_Done) {
|
|
|
|
|
if(changed_display_mode) {
|
|
|
|
|
changed_display_mode = false;
|
|
|
|
|
adjust_windows(mainPtr, mainView);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
|
if (menuChoiceId>=0) {
|
|
|
|
|
handle_menu_choice(eMenu(menuChoiceId));
|
|
|
|
@@ -357,6 +370,9 @@ void handle_menu_choice(eMenu item_hit) {
|
|
|
|
|
undo_list.clear();
|
|
|
|
|
update_edit_menu();
|
|
|
|
|
break;
|
|
|
|
|
case eMenu::PREFS:
|
|
|
|
|
pick_preferences();
|
|
|
|
|
break;
|
|
|
|
|
case eMenu::QUIT: // quit
|
|
|
|
|
if(!save_check("save-before-quit"))
|
|
|
|
|
break;
|
|
|
|
@@ -641,6 +657,51 @@ void handle_menu_choice(eMenu item_hit) {
|
|
|
|
|
redraw_screen();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void save_prefs(){
|
|
|
|
|
bool success = sync_prefs();
|
|
|
|
|
if(!success){
|
|
|
|
|
showWarning("There was a problem writing to the preferences file. When the Scenerio 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.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static 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-scenario"));
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Mouse_Pressed(const sf::Event & event) {
|
|
|
|
|
location mousePos { translate_mouse_coordinates({event.mouseButton.x, event.mouseButton.y}) };
|
|
|
|
|
handle_action(mousePos,event);
|
|
|
|
|