Implemented window position and size loading and saving. Release Build 7370.

pull/35/head
sigonasr2 12 months ago
parent c56253c4cf
commit 5d7b342c51
  1. 13
      Adventures in Lestoria/SaveFile.cpp
  2. 2
      Adventures in Lestoria/Version.h
  3. 30
      Adventures in Lestoria/olcPixelGameEngine.h
  4. BIN
      x64/Release/Adventures in Lestoria.exe

@ -82,6 +82,7 @@ const size_t SaveFile::GetOnlineSaveFileCount(){
const void SaveFile::SaveGame(){
std::filesystem::create_directories("save_file_path"_S);
utils::datafile saveFile;
utils::datafile saveSystemFile;
utils::datafile::INITIAL_SETUP_COMPLETE=false;
for(size_t itemCount=0;auto&item:Inventory::GetInventory()){
saveFile["Items"][std::format("Item[{}]",itemCount)]["Amt"].SetInt(item->Amt());
@ -154,7 +155,15 @@ const void SaveFile::SaveGame(){
}
#pragma endregion
#pragma region Save System Settings
saveSystemFile["Window Pos"].SetInt(game->GetActualWindowPos().x,0);
saveSystemFile["Window Pos"].SetInt(game->GetActualWindowPos().y,1);
saveSystemFile["Window Size"].SetInt(game->GetWindowSize().x,0);
saveSystemFile["Window Size"].SetInt(game->GetWindowSize().y,1);
#pragma endregion
utils::datafile::Write(saveFile,"save_file_path"_S+std::format("save.{:04}",saveFileID));
utils::datafile::Write(saveSystemFile,"save_file_path"_S+"system.conf");
utils::datafile metadata;
if(onlineMode){
if(std::filesystem::exists("save_file_path"_S+"metadata.dat"+"_online")){
@ -334,8 +343,8 @@ void SaveFile::LoadFile(){
#pragma region Load System Settings
if(std::filesystem::exists(loadSystemFilename)){
utils::datafile::Read(loadSystemFile,loadSystemFilename);
//if(loadSystemFile.HasProperty("Window Pos"))
//if(loadSystemFile.HasProperty("Window Size"))
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

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

@ -1062,6 +1062,8 @@ namespace olc
const bool IsMouseInsideWindow() const;
// Gets Actual Window pos
const olc::vi2d& GetWindowPos() const;
// Gets the upper-left corner of the window to include window decorations/borders.
const olc::vi2d& GetActualWindowPos() const;
// Gets Actual Window size
const olc::vi2d& GetWindowSize() const;
// Gets pixel scale
@ -1310,6 +1312,7 @@ namespace olc
olc::vi2d vMouseWindowPos = { 0, 0 };
int32_t nMouseWheelDeltaCache = 0;
olc::vi2d vWindowPos = { 0, 0 };
olc::vi2d vActualWindowPos = { 0, 0 };
olc::vi2d vWindowSize = { 0, 0 };
olc::vi2d vViewPos = { 0, 0 };
olc::vi2d vViewSize = { 0,0 };
@ -1382,6 +1385,7 @@ namespace olc
void olc_UpdateMouse(int32_t x, int32_t y);
void olc_UpdateMouseWheel(int32_t delta);
void olc_UpdateWindowPos(int32_t x, int32_t y);
void olc_UpdateActualWindowPos(int32_t x, int32_t y);
void olc_UpdateWindowSize(int32_t x, int32_t y);
void olc_UpdateViewport();
void olc_ConstructFontSheet();
@ -2263,6 +2267,9 @@ namespace olc
const olc::vi2d& PixelGameEngine::GetWindowPos() const
{ return vWindowPos; }
const olc::vi2d& PixelGameEngine::GetActualWindowPos() const
{ return vActualWindowPos; }
const olc::vi2d& PixelGameEngine::GetWindowSize() const
{ return vWindowSize; }
@ -4521,6 +4528,11 @@ namespace olc
vWindowPos = { x, y };
}
void PixelGameEngine::olc_UpdateActualWindowPos(int32_t x, int32_t y){
vActualWindowPos = { x, y };
std::cout<<vActualWindowPos<<std::endl;
}
void PixelGameEngine::olc_UpdateMouseWheel(int32_t delta)
{ nMouseWheelDeltaCache += delta; }
@ -6414,7 +6426,7 @@ namespace olc
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;
AdjustWindowRectEx(&rWndRect, dwStyle, FALSE, dwExStyle);
WINDOWPLACEMENT placement;
int width = rWndRect.right - rWndRect.left;
int height = rWndRect.bottom - rWndRect.top;
MoveWindow(olc_hWnd,pos.x, pos.y, width, height,true);
@ -6427,9 +6439,10 @@ namespace olc
DWORD dwStyle = WS_CAPTION | WS_SYSMENU | WS_VISIBLE | WS_THICKFRAME;
WINDOWPLACEMENT placement;
GetWindowPlacement(olc_hWnd,&placement);
AdjustWindowRectEx(&rWndRect, dwStyle, FALSE, dwExStyle);
int width = rWndRect.right - rWndRect.left;
int height = rWndRect.bottom - rWndRect.top;
MoveWindow(olc_hWnd,placement.rcNormalPosition.left, placement.rcNormalPosition.top, width*ptrPGE->GetPixelSize().x, height*ptrPGE->GetPixelSize().y,true);
MoveWindow(olc_hWnd,placement.rcNormalPosition.left, placement.rcNormalPosition.top, width, height,true);
}
}
@ -6448,6 +6461,7 @@ namespace olc
struct tagPOINT p{0,0};
//Update mouse positions and states outside the window.
GetCursorPos(&p);
ptrPGE->olc_UpdateMouse(p.x-ptrPGE->GetWindowPos().x,p.y-ptrPGE->GetWindowPos().y);
ptrPGE->olc_UpdateMouseState(0,GetAsyncKeyState(VK_LBUTTON)>>7);
ptrPGE->olc_UpdateMouseState(1,GetAsyncKeyState(VK_RBUTTON)>>7);
@ -6475,6 +6489,12 @@ namespace olc
uint16_t x = lParam & 0xFFFF; uint16_t y = (lParam >> 16) & 0xFFFF;
int16_t ix = *(int16_t*)&x; int16_t iy = *(int16_t*)&y;
ptrPGE->olc_UpdateWindowPos(ix, iy);
//HACK ALERT! GetWindowPos() actually returns (0,0) for the canvas and not the window border, so to compensate we have to move down by the border amount.
WINDOWPLACEMENT placement;
GetWindowPlacement(hWnd,&placement);
ptrPGE->olc_UpdateActualWindowPos(placement.rcNormalPosition.left, placement.rcNormalPosition.top);
return 0;
}
case WM_SIZE: ptrPGE->olc_UpdateWindowSize(lParam & 0xFFFF, (lParam >> 16) & 0xFFFF); return 0;
@ -6706,7 +6726,7 @@ namespace olc
virtual void SetWindowSize(vi2d size)override{
if(!ptrPGE->IsFullscreen()){
XMapWindow(olc_Display, olc_Window);
XResizeWindow(olc_Display, olc_Window, size.x*ptrPGE->GetPixelSize().x, size.y*ptrPGE->GetPixelSize().y);
XResizeWindow(olc_Display, olc_Window, size.x, size.y);
}
}
@ -6765,12 +6785,14 @@ namespace olc
XWindowAttributes gwa;
XGetWindowAttributes(olc_Display, olc_Window, &gwa);
ptrPGE->olc_UpdateWindowPos(gwa.x, gwa.y);
ptrPGE->olc_UpdateActualWindowPos(gwa.x, gwa.y);
ptrPGE->olc_UpdateWindowSize(gwa.width, gwa.height);
}
else if (xev.type == ConfigureNotify)
{
XConfigureEvent xce = xev.xconfigure;
ptrPGE->olc_UpdateWindowPos(xce.x, xce.y);
ptrPGE->olc_UpdateActualWindowPos(xce.x, xce.y);
ptrPGE->olc_UpdateWindowSize(xce.width, xce.height);
}
else if (xev.type == KeyPress)
@ -7532,12 +7554,14 @@ namespace olc
virtual olc::rcode StartSystemEventLoop() override
{
ptrPGE->olc_UpdateWindowPos(EM_ASM_INT({return Module.canvas.getBoundingClientRect().left}),EM_ASM_INT({return Module.canvas.getBoundingClientRect().top}));
ptrPGE->olc_UpdateActualWindowPos(EM_ASM_INT({return Module.canvas.getBoundingClientRect().left}),EM_ASM_INT({return Module.canvas.getBoundingClientRect().top}));
return olc::OK;
}
virtual olc::rcode HandleSystemEvent() override
{
ptrPGE->olc_UpdateWindowPos(EM_ASM_INT({return Module.canvas.getBoundingClientRect().left}),EM_ASM_INT({return Module.canvas.getBoundingClientRect().top}));
ptrPGE->olc_UpdateActualWindowPos(EM_ASM_INT({return Module.canvas.getBoundingClientRect().left}),EM_ASM_INT({return Module.canvas.getBoundingClientRect().top}));
return olc::OK;
}

Loading…
Cancel
Save