Added custom window positioning, sizing, and added configuration file loading before the game window is constructed .

This commit is contained in:
sigonasr2 2024-02-19 22:37:56 -06:00
parent 92f488986e
commit bf33ad79c9
10 changed files with 54 additions and 36 deletions

View File

@ -2280,7 +2280,28 @@ int main()
{ {
{ {
AiL demo; AiL demo;
if (demo.Construct(WINDOW_SIZE.x, WINDOW_SIZE.y, 4, 4))
#pragma region Load Window Settings
utils::datafile loadSystemFile;
std::string loadSystemFilename="save_file_path"_S+"system.conf";
vi2d windowPosConf={30,30};
vi2d windowSizeConf=WINDOW_SIZE;
bool fullscreenConf=false;
if(std::filesystem::exists(loadSystemFilename)){
utils::datafile::Read(loadSystemFile,loadSystemFilename);
if(loadSystemFile.HasProperty("Window Pos")){
GameSettings::SetWindowPos({loadSystemFile["Window Pos"].GetInt(0),loadSystemFile["Window Pos"].GetInt(1)});
windowPosConf={loadSystemFile["Window Pos"].GetInt(0),loadSystemFile["Window Pos"].GetInt(1)};
}
if(loadSystemFile.HasProperty("Window Size"))windowSizeConf={loadSystemFile["Window Size"].GetInt(0),loadSystemFile["Window Size"].GetInt(1)};
if(loadSystemFile.HasProperty("Fullscreen"))fullscreenConf=loadSystemFile["Fullscreen"].GetBool();
}
#pragma endregion
if (demo.Construct(windowPosConf.x, windowPosConf.y, windowSizeConf.x, windowSizeConf.y, WINDOW_SIZE.x, WINDOW_SIZE.y, 4, 4, fullscreenConf))
demo.Start(); demo.Start();
} }

View File

@ -42,6 +42,7 @@ bool GameSettings::screenShake=true;
bool GameSettings::rumble=true; bool GameSettings::rumble=true;
bool GameSettings::terrainCollisionBoxes=true; bool GameSettings::terrainCollisionBoxes=true;
bool GameSettings::keyboardAutoAim=false; bool GameSettings::keyboardAutoAim=false;
vi2d GameSettings::windowPos{30,30};
const bool GameSettings::ScreenShakeEnabled(){ const bool GameSettings::ScreenShakeEnabled(){
return screenShake; return screenShake;
@ -55,6 +56,9 @@ const bool GameSettings::TerrainCollisionBoxesEnabled(){
const bool GameSettings::KeyboardAutoAimEnabled(){ const bool GameSettings::KeyboardAutoAimEnabled(){
return keyboardAutoAim; return keyboardAutoAim;
} }
const vi2d GameSettings::GetWindowPos(){
return windowPos;
}
void GameSettings::SetScreenShake(bool screenShakeEnabled){ void GameSettings::SetScreenShake(bool screenShakeEnabled){
screenShake=screenShakeEnabled; screenShake=screenShakeEnabled;
@ -68,3 +72,6 @@ void GameSettings::SetTerrainCollisionBoxes(bool terrainCollisionBoxesEnabled){
void GameSettings::SetKeyboardAutoAim(bool autoAimEnabled){ void GameSettings::SetKeyboardAutoAim(bool autoAimEnabled){
keyboardAutoAim=autoAimEnabled; keyboardAutoAim=autoAimEnabled;
} }
void GameSettings::SetWindowPos(vi2d windowPos){
GameSettings::windowPos=windowPos;
}

View File

@ -37,18 +37,23 @@ All rights reserved.
#pragma endregion #pragma endregion
#pragma once #pragma once
#include "olcUTIL_Geometry2D.h"
class GameSettings{ class GameSettings{
static bool screenShake; static bool screenShake;
static bool rumble; static bool rumble;
static bool terrainCollisionBoxes; static bool terrainCollisionBoxes;
static bool keyboardAutoAim; static bool keyboardAutoAim;
static vi2d windowPos;
public: public:
static const bool ScreenShakeEnabled(); static const bool ScreenShakeEnabled();
static const bool RumbleEnabled(); static const bool RumbleEnabled();
static const bool TerrainCollisionBoxesEnabled(); static const bool TerrainCollisionBoxesEnabled();
static const bool KeyboardAutoAimEnabled(); static const bool KeyboardAutoAimEnabled();
static const vi2d GetWindowPos();
static void SetScreenShake(bool screenShakeEnabled); static void SetScreenShake(bool screenShakeEnabled);
static void SetRumble(bool rumbleEnabled); static void SetRumble(bool rumbleEnabled);
static void SetTerrainCollisionBoxes(bool terrainCollisionBoxesEnabled); static void SetTerrainCollisionBoxes(bool terrainCollisionBoxesEnabled);
static void SetKeyboardAutoAim(bool autoAimEnabled); static void SetKeyboardAutoAim(bool autoAimEnabled);
static void SetWindowPos(vi2d windowPos);
}; };

View File

@ -129,7 +129,6 @@ const void SaveFile::SaveGame(){
saveFile["Controller Rumble"].SetBool(GameSettings::RumbleEnabled()); saveFile["Controller Rumble"].SetBool(GameSettings::RumbleEnabled());
saveFile["Terrain Collision Boxes"].SetBool(GameSettings::TerrainCollisionBoxesEnabled()); saveFile["Terrain Collision Boxes"].SetBool(GameSettings::TerrainCollisionBoxesEnabled());
saveFile["Keyboard Auto-Aim"].SetBool(GameSettings::KeyboardAutoAimEnabled()); saveFile["Keyboard Auto-Aim"].SetBool(GameSettings::KeyboardAutoAimEnabled());
saveFile["Fullscreen"].SetBool(game->IsFullscreen());
#pragma region Save Keyboard/Controller mappings #pragma region Save Keyboard/Controller mappings
//NOTE: We are shadowing code from InputKeyboardWindow! If at some point the retrival method for getting input displays changes, we likely will be changing the code here as well! //NOTE: We are shadowing code from InputKeyboardWindow! If at some point the retrival method for getting input displays changes, we likely will be changing the code here as well!
@ -161,6 +160,7 @@ const void SaveFile::SaveGame(){
saveSystemFile["Window Pos"].SetInt(game->GetActualWindowPos().y,1); saveSystemFile["Window Pos"].SetInt(game->GetActualWindowPos().y,1);
saveSystemFile["Window Size"].SetInt(game->GetWindowSize().x,0); saveSystemFile["Window Size"].SetInt(game->GetWindowSize().x,0);
saveSystemFile["Window Size"].SetInt(game->GetWindowSize().y,1); saveSystemFile["Window Size"].SetInt(game->GetWindowSize().y,1);
saveSystemFile["Fullscreen"].SetBool(game->IsFullscreen());
#pragma endregion #pragma endregion
utils::datafile::Write(saveFile,"save_file_path"_S+std::format("save.{:04}",saveFileID)); utils::datafile::Write(saveFile,"save_file_path"_S+std::format("save.{:04}",saveFileID));
@ -243,10 +243,8 @@ const void SaveFile::SaveGame(){
void SaveFile::LoadFile(){ void SaveFile::LoadFile(){
utils::datafile loadFile; utils::datafile loadFile;
utils::datafile loadSystemFile;
std::string loadFilename="save_file_path"_S+std::format("save.{:04}",saveFileID); std::string loadFilename="save_file_path"_S+std::format("save.{:04}",saveFileID);
std::string loadSystemFilename="save_file_path"_S+"system.conf";
if(std::filesystem::exists(loadFilename)){ if(std::filesystem::exists(loadFilename)){
utils::datafile::Read(loadFile,"save_file_path"_S+std::format("save.{:04}",saveFileID)); utils::datafile::Read(loadFile,"save_file_path"_S+std::format("save.{:04}",saveFileID));
@ -299,7 +297,6 @@ void SaveFile::LoadFile(){
if(loadFile.HasProperty("Controller Rumble"))GameSettings::SetRumble(loadFile["Controller Rumble"].GetBool()); if(loadFile.HasProperty("Controller Rumble"))GameSettings::SetRumble(loadFile["Controller Rumble"].GetBool());
if(loadFile.HasProperty("Terrain Collision Boxes"))GameSettings::SetTerrainCollisionBoxes(loadFile["Terrain Collision Boxes"].GetBool()); if(loadFile.HasProperty("Terrain Collision Boxes"))GameSettings::SetTerrainCollisionBoxes(loadFile["Terrain Collision Boxes"].GetBool());
if(loadFile.HasProperty("Keyboard Auto-Aim"))GameSettings::SetKeyboardAutoAim(loadFile["Keyboard Auto-Aim"].GetBool()); if(loadFile.HasProperty("Keyboard Auto-Aim"))GameSettings::SetKeyboardAutoAim(loadFile["Keyboard Auto-Aim"].GetBool());
if(loadFile.HasProperty("Fullscreen"))game->SetFullscreen(loadFile["Fullscreen"].GetBool(),{});
#pragma region Load Keyboard/Controller mappings #pragma region Load Keyboard/Controller mappings
//NOTE: We are shadowing code from InputKeyboardWindow! If at some point the retrival method for getting input displays changes, we likely will be changing the code here as well! //NOTE: We are shadowing code from InputKeyboardWindow! If at some point the retrival method for getting input displays changes, we likely will be changing the code here as well!
@ -341,14 +338,6 @@ void SaveFile::LoadFile(){
} }
#pragma endregion #pragma endregion
#pragma region Load System Settings
if(std::filesystem::exists(loadSystemFilename)){
utils::datafile::Read(loadSystemFile,loadSystemFilename);
if(loadSystemFile.HasProperty("Window Pos"))game->SetWindowPos({loadSystemFile["Window Pos"].GetInt(0),loadSystemFile["Window Pos"].GetInt(1)});
if(loadSystemFile.HasProperty("Window Size"))game->SetWindowSize({loadSystemFile["Window Size"].GetInt(0),loadSystemFile["Window Size"].GetInt(1)});
}
#pragma endregion
GameState::ChangeState(States::OVERWORLD_MAP,0.5f); GameState::ChangeState(States::OVERWORLD_MAP,0.5f);
}else{ }else{
std::cout<<std::format("WARNING! File {} does not exist for loading!","save_file_path"_S+std::format("save.{:04}",saveFileID))<<std::endl; std::cout<<std::format("WARNING! File {} does not exist for loading!","save_file_path"_S+std::format("save.{:04}",saveFileID))<<std::endl;

View File

@ -115,9 +115,12 @@ void Menu::InitializeSettingsWindow(){
settingsWindow->ADD("Keyboard Play Auto-Aim Label",MenuLabel)(geom2d::rect<float>{{windowSize.x/2+22.f,104},{windowSize.x/2-24.f,16.f}},"Aim Assist\n(No Mouse Players)",1.f,ComponentAttr::SHADOW|ComponentAttr::LEFT_ALIGN)END; settingsWindow->ADD("Keyboard Play Auto-Aim Label",MenuLabel)(geom2d::rect<float>{{windowSize.x/2+22.f,104},{windowSize.x/2-24.f,16.f}},"Aim Assist\n(No Mouse Players)",1.f,ComponentAttr::SHADOW|ComponentAttr::LEFT_ALIGN)END;
#ifndef __EMSCRIPTEN__ #ifndef __EMSCRIPTEN__
settingsWindow->ADD("Fullscreen Toggle Checkbox",Checkbox)(geom2d::rect<float>{{windowSize.x/2+4.f,124},{16.f,16.f}},[](ToggleFuncData data){ settingsWindow->ADD("Fullscreen Toggle Checkbox",Checkbox)(geom2d::rect<float>{{windowSize.x/2+4.f,124},{16.f,16.f}},[](ToggleFuncData data){
game->SetFullscreen(data.checked,{}); if(data.checked){ //When going to fullscreen mode, the windowed mode positioning needs to be saved to be restored later.
GameSettings::SetWindowPos(game->GetActualWindowPos());
}
game->SetFullscreen(data.checked,GameSettings::GetWindowPos());
return true; return true;
},false)END; },game->IsFullscreen())END;
settingsWindow->ADD("Fullscreen Toggle Label",MenuLabel)(geom2d::rect<float>{{windowSize.x/2+22.f,124},{windowSize.x/2-24.f,16.f}},"Fullscreen",1.f,ComponentAttr::SHADOW|ComponentAttr::LEFT_ALIGN)END; settingsWindow->ADD("Fullscreen Toggle Label",MenuLabel)(geom2d::rect<float>{{windowSize.x/2+22.f,124},{windowSize.x/2-24.f,16.f}},"Fullscreen",1.f,ComponentAttr::SHADOW|ComponentAttr::LEFT_ALIGN)END;
#endif #endif

View File

@ -7,14 +7,14 @@ January 1st
- Track items used during a stage, on death, restore the loadout item quantities used. - Track items used during a stage, on death, restore the loadout item quantities used.
- Add screen shake and rumble as a toggle.
- Fullscreen toggle
> Implement fullscreen capabilities for the PGE.
- Toggle between Playstation / Xbox controller gamepad displays - Toggle between Playstation / Xbox controller gamepad displays
- Rebind FACELEFT/FACERIGHT menu keys (as they are used constantly throughout menus and would need to be rebinded if the player wants). (Or make confirm/back not rebindable) - Rebind FACELEFT/FACERIGHT menu keys (as they are used constantly throughout menus and would need to be rebinded if the player wants). (Or make confirm/back not rebindable)
Open window to the correct position/size at the beginning of the game if possible.
Input HElper disappearing? (Possibly on loads)
Boss
January 31st January 31st
============ ============
@ -32,8 +32,6 @@ January 31st
- Auto aim causes retreat-type moves to aim away from the auto target, and prefer the direction the player's moving in. - Auto aim causes retreat-type moves to aim away from the auto target, and prefer the direction the player's moving in.
- Save window position and size
- Condense stage track (loading times) - Condense stage track (loading times)
- If you enter the keyboard config menu and press a controller button, it cancels the request. If you enter the controller config menu and press a keyboard/mouse button, it also cancels the request. - If you enter the keyboard config menu and press a controller button, it cancels the request. If you enter the controller config menu and press a keyboard/mouse button, it also cancels the request.

View File

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 3 #define VERSION_MINOR 3
#define VERSION_PATCH 0 #define VERSION_PATCH 0
#define VERSION_BUILD 7370 #define VERSION_BUILD 7382
#define stringify(a) stringify_(a) #define stringify(a) stringify_(a)
#define stringify_(a) #a #define stringify_(a) #a

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.10.1" class="Map" orientation="orthogonal" renderorder="left-down" width="250" height="177" tilewidth="4" tileheight="4" infinite="0" nextlayerid="5" nextobjectid="19"> <map version="1.10" tiledversion="1.10.2" class="Map" orientation="orthogonal" renderorder="left-down" width="250" height="177" tilewidth="4" tileheight="4" infinite="0" nextlayerid="5" nextobjectid="19">
<properties> <properties>
<property name="Background Music" propertytype="BGM" value="overworld"/> <property name="Background Music" propertytype="BGM" value="overworld"/>
<property name="Level Type" propertytype="LevelType" value="World Map"/> <property name="Level Type" propertytype="LevelType" value="World Map"/>
@ -679,7 +679,6 @@
</object> </object>
<object id="18" name="Boss B-I" type="StagePlate" x="192" y="516" width="32" height="24"> <object id="18" name="Boss B-I" type="StagePlate" x="192" y="516" width="32" height="24">
<properties> <properties>
<property name="Connection 1 - North" type="object" value="0"/>
<property name="Map" propertytype="Level" value="BOSS_1_B"/> <property name="Map" propertytype="Level" value="BOSS_1_B"/>
<property name="Type" propertytype="StageType" value="BOSS"/> <property name="Type" propertytype="StageType" value="BOSS"/>
<property name="Unlock Condition" propertytype="Level" value="CAMPAIGN_1_B1"/> <property name="Unlock Condition" propertytype="Level" value="CAMPAIGN_1_B1"/>

View File

@ -990,7 +990,7 @@ namespace olc
PixelGameEngine(); PixelGameEngine();
virtual ~PixelGameEngine(); virtual ~PixelGameEngine();
public: public:
olc::rcode Construct(int32_t screen_w, int32_t screen_h, int32_t pixel_w, int32_t pixel_h, olc::rcode Construct(int32_t window_x, int32_t window_y, int32_t window_w, int32_t window_h, int32_t screen_w, int32_t screen_h, int32_t pixel_w, int32_t pixel_h,
bool full_screen = false, bool vsync = false, bool cohesion = false); bool full_screen = false, bool vsync = false, bool cohesion = false);
olc::rcode Start(); olc::rcode Start();
@ -2089,13 +2089,14 @@ namespace olc
{} {}
olc::rcode PixelGameEngine::Construct(int32_t screen_w, int32_t screen_h, int32_t pixel_w, int32_t pixel_h, bool full_screen, bool vsync, bool cohesion) olc::rcode PixelGameEngine::Construct(int32_t window_x, int32_t window_y, int32_t window_w, int32_t window_h, int32_t screen_w, int32_t screen_h, int32_t pixel_w, int32_t pixel_h, bool full_screen, bool vsync, bool cohesion)
{ {
bPixelCohesion = cohesion; bPixelCohesion = cohesion;
vScreenSize = { screen_w, screen_h }; vScreenSize = { screen_w, screen_h };
vInvScreenSize = { 1.0f / float(screen_w), 1.0f / float(screen_h) }; vInvScreenSize = { 1.0f / float(screen_w), 1.0f / float(screen_h) };
vWindowPos = {window_x,window_y};
vPixelSize = { pixel_w, pixel_h }; vPixelSize = { pixel_w, pixel_h };
vWindowSize = vScreenSize * vPixelSize; vWindowSize = {window_w,window_h};
bFullScreen = full_screen; bFullScreen = full_screen;
bEnableVSYNC = vsync; bEnableVSYNC = vsync;
vPixel = 2.0f / vScreenSize; vPixel = 2.0f / vScreenSize;
@ -2128,7 +2129,7 @@ namespace olc
if (platform->ApplicationStartUp() != olc::OK) return olc::FAIL; if (platform->ApplicationStartUp() != olc::OK) return olc::FAIL;
// Construct the window // Construct the window
if (platform->CreateWindowPane({ 30,30 }, vWindowSize, bFullScreen) != olc::OK) return olc::FAIL; if (platform->CreateWindowPane(vWindowPos, vWindowSize, bFullScreen) != olc::OK) return olc::FAIL;
olc_UpdateWindowSize(vWindowSize.x, vWindowSize.y); olc_UpdateWindowSize(vWindowSize.x, vWindowSize.y);
// Start the thread // Start the thread
@ -4530,7 +4531,6 @@ namespace olc
void PixelGameEngine::olc_UpdateActualWindowPos(int32_t x, int32_t y){ void PixelGameEngine::olc_UpdateActualWindowPos(int32_t x, int32_t y){
vActualWindowPos = { x, y }; vActualWindowPos = { x, y };
std::cout<<vActualWindowPos<<std::endl;
} }
void PixelGameEngine::olc_UpdateMouseWheel(int32_t delta) void PixelGameEngine::olc_UpdateMouseWheel(int32_t delta)
@ -6424,9 +6424,6 @@ namespace olc
virtual void SetWindowPos(vi2d pos)override{ virtual void SetWindowPos(vi2d pos)override{
if(!ptrPGE->IsFullscreen()){ if(!ptrPGE->IsFullscreen()){
RECT rWndRect = { 0, 0, ptrPGE->GetWindowSize().x, ptrPGE->GetWindowSize().y }; RECT rWndRect = { 0, 0, ptrPGE->GetWindowSize().x, ptrPGE->GetWindowSize().y };
DWORD dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
DWORD dwStyle = WS_CAPTION | WS_SYSMENU | WS_VISIBLE | WS_THICKFRAME;
WINDOWPLACEMENT placement;
int width = rWndRect.right - rWndRect.left; int width = rWndRect.right - rWndRect.left;
int height = rWndRect.bottom - rWndRect.top; int height = rWndRect.bottom - rWndRect.top;
MoveWindow(olc_hWnd,pos.x, pos.y, width, height,true); MoveWindow(olc_hWnd,pos.x, pos.y, width, height,true);
@ -6580,7 +6577,6 @@ namespace olc
X11::XVisualInfo* olc_VisualInfo; X11::XVisualInfo* olc_VisualInfo;
X11::Colormap olc_ColourMap; X11::Colormap olc_ColourMap;
X11::XSetWindowAttributes olc_SetWindowAttribs; X11::XSetWindowAttributes olc_SetWindowAttribs;
vi2d desiredPos{30,30};
public: public:
virtual olc::rcode ApplicationStartUp() override virtual olc::rcode ApplicationStartUp() override
@ -7168,7 +7164,7 @@ namespace olc {
if (platform->ApplicationStartUp() != olc::OK) return olc::FAIL; if (platform->ApplicationStartUp() != olc::OK) return olc::FAIL;
// Construct the window // Construct the window
if (platform->CreateWindowPane({ 30,30 }, vWindowSize, bFullScreen) != olc::OK) return olc::FAIL; if (platform->CreateWindowPane(vWindowPos, vWindowSize, bFullScreen) != olc::OK) return olc::FAIL;
olc_UpdateWindowSize(vWindowSize.x, vWindowSize.y); olc_UpdateWindowSize(vWindowSize.x, vWindowSize.y);
if (platform->ThreadStartUp() == olc::FAIL) return olc::FAIL; if (platform->ThreadStartUp() == olc::FAIL) return olc::FAIL;
@ -7633,7 +7629,7 @@ namespace olc
if (platform->ApplicationStartUp() != olc::OK) return olc::FAIL; if (platform->ApplicationStartUp() != olc::OK) return olc::FAIL;
// Construct the window // Construct the window
if (platform->CreateWindowPane({ 30,30 }, vWindowSize, bFullScreen) != olc::OK) return olc::FAIL; if (platform->CreateWindowPane(vWindowPos, vWindowSize, bFullScreen) != olc::OK) return olc::FAIL;
olc_UpdateWindowSize(vWindowSize.x, vWindowSize.y); olc_UpdateWindowSize(vWindowSize.x, vWindowSize.y);
// Some implementations may form an event loop here // Some implementations may form an event loop here