Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "files.h"
#include "globals.h"
#include "s25util/file_handle.h"
#include <libsiedler2/ArchivItem_Ini.h>
#include <libsiedler2/libsiedler2.h>
#include <boost/filesystem.hpp>
#include <boost/nowide/cstdio.hpp>
#include <boost/program_options.hpp>
Expand Down Expand Up @@ -156,6 +158,32 @@ void CGame::delMapObj()
MapObj.reset();
}

void CGame::LoadSettings()
{
const bfs::path settingsPath = RTTRCONFIG.ExpandPath("<RTTR_USERDATA>/s25edit.ini");
libsiedler2::Archiv settings;
if(libsiedler2::Load(settingsPath, settings) != 0)
return;
const auto* ini = dynamic_cast<const libsiedler2::ArchivItem_Ini*>(settings.find("editor"));
if(!ini)
return;
GameResolution.x = ini->getValue("width", static_cast<int>(GameResolution.x));
GameResolution.y = ini->getValue("height", static_cast<int>(GameResolution.y));
fullscreen = ini->getValue("fullscreen", fullscreen);
}

void CGame::SaveSettings() const
{
libsiedler2::Archiv settings;
settings.push(std::make_unique<libsiedler2::ArchivItem_Ini>("editor"));
auto& ini = dynamic_cast<libsiedler2::ArchivItem_Ini&>(*settings.find("editor"));
ini.setValue("width", GameResolution.x);
ini.setValue("height", GameResolution.y);
ini.setValue("fullscreen", static_cast<int>(fullscreen));
const bfs::path settingsPath = RTTRCONFIG.ExpandPath("<RTTR_USERDATA>/s25edit.ini");
libsiedler2::Write(settingsPath, settings);
}

void CGame::GameLoop()
{
for(auto&& callback : Callbacks)
Expand Down Expand Up @@ -309,6 +337,7 @@ int main(int argc, char* argv[])
auto s2 = std::make_unique<CGame>(
Extent(programOptions["width"].as<unsigned>(), programOptions["height"].as<unsigned>()),
programOptions["fullscreen"].as<bool>());
s2->LoadSettings();
result = s2->Execute();
} catch(...)
{
Expand Down
3 changes: 3 additions & 0 deletions CGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class CGame
void RecreateDisplayResources();

public:
void LoadSettings();
void SaveSettings() const;

CGame(Extent GameResolution_, bool fullscreen_);
~CGame();

Expand Down
3 changes: 3 additions & 0 deletions CGame_Event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ void CGame::EventHandling(SDL_Event* Event)
case SDLK_RETURN:
case SDLK_KP_ENTER:
if(Event->key.keysym.mod & KMOD_ALT)
{
fullscreen = !fullscreen;
SaveSettings();
}
break;

#ifdef _ADMINMODE
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ELSE()
ENDIF()

add_executable(s25edit ${MAIN_SOURCES} ${CIO_SOURCES} ${icon_RC})
target_link_libraries(s25edit PRIVATE SGE rttrConfig s25Common gamedata endian::static Boost::nowide PUBLIC Boost::disable_autolinking Boost::program_options)
target_link_libraries(s25edit PRIVATE SGE rttrConfig s25Common gamedata siedler2 endian::static Boost::nowide PUBLIC Boost::disable_autolinking Boost::program_options)
target_include_directories(s25edit PRIVATE include)
target_compile_features(s25edit PRIVATE cxx_std_17)

Expand Down
15 changes: 12 additions & 3 deletions callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ void callback::submenuOptions(int Param)
SELECTBOX_1920_1400,
SELECTBOX_1920_1440,
SELECTBOX_2048_1152,
SELECTBOX_2048_1536
SELECTBOX_2048_1536,
SELECTBOX_3840_2160
};

switch(Param)
Expand All @@ -251,9 +252,9 @@ void callback::submenuOptions(int Param)
if(ButtonFullscreen)
SubMenu->delButton(ButtonFullscreen);
ButtonFullscreen =
SubMenu->addButton(submenuOptions, FULLSCREEN, (int)(global::s2->GameResolution.x / 2 - 100), 190, 200,
SubMenu->addButton(submenuOptions, FULLSCREEN, (int)(global::s2->GameResolution.x / 2 - 100), 410, 200,
20, BUTTON_RED1, (global::s2->fullscreen ? "WINDOW" : "FULLSCREEN"));
SelectBoxRes = SubMenu->addSelectBox(ButtonFullscreen->getPos() - Point16(0, 120), Extent16(200, 110),
SelectBoxRes = SubMenu->addSelectBox(ButtonFullscreen->getPos() - Point16(0, 340), Extent16(200, 330),
FontSize::Medium, FontColor::Yellow, BUTTON_GREY);
SelectBoxRes->addOption("800 x 600 (SVGA)", submenuOptions, SELECTBOX_800_600);
SelectBoxRes->addOption("832 x 624 (Half Megapixel)", submenuOptions, SELECTBOX_832_624);
Expand Down Expand Up @@ -297,6 +298,7 @@ void callback::submenuOptions(int Param)
SelectBoxRes->addOption("1920 x 1440", submenuOptions, SELECTBOX_1920_1440);
SelectBoxRes->addOption("2048 x 1152 (QWXGA)", submenuOptions, SELECTBOX_2048_1152);
SelectBoxRes->addOption("2048 x 1536 (SUXGA)", submenuOptions, SELECTBOX_2048_1536);
SelectBoxRes->addOption("3840 x 2160 (4K UHD)", submenuOptions, SELECTBOX_3840_2160);
break;

case MAINMENU:
Expand All @@ -317,6 +319,7 @@ void callback::submenuOptions(int Param)

case GRAPHICS_CHANGE:
assert(SubMenu);
global::s2->SaveSettings();
SubMenu->setWaste();
TextResolution = nullptr;
ButtonFullscreen = nullptr;
Expand Down Expand Up @@ -577,6 +580,12 @@ void callback::submenuOptions(int Param)
submenuOptions(GRAPHICS_CHANGE);
break;

case SELECTBOX_3840_2160:
global::s2->GameResolution.x = 3840;
global::s2->GameResolution.y = 2160;
submenuOptions(GRAPHICS_CHANGE);
break;

default: break;
}
}
Expand Down