From 6b8613a91f04dc1bbda8f1cec209a665bf5d9153 Mon Sep 17 00:00:00 2001 From: phobos2077 Date: Sat, 1 Jun 2024 20:27:57 +0200 Subject: [PATCH] Fix ExpandBarter and DIALOG_SCRN_BACKGROUND conflict (closes #544) --- sfall/HRP/Dialog.cpp | 21 +++++++++++++++------ sfall/HRP/Dialog.h | 2 ++ sfall/Modules/Interface.cpp | 6 ++++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/sfall/HRP/Dialog.cpp b/sfall/HRP/Dialog.cpp index adce5efa..fb162059 100644 --- a/sfall/HRP/Dialog.cpp +++ b/sfall/HRP/Dialog.cpp @@ -30,19 +30,22 @@ bool Dialog::DIALOG_SCRN_BACKGROUND = false; static long xPosition; static long yPosition; +static long dialogExpandedHeight = 0; static long __fastcall CreateWinDialog(long height, long yPos, long xPos, long color, long flags) { + long fitRectW = fo::var::getInt(FO_VAR_buf_width_2); + long fitRectH = fo::var::getInt(FO_VAR_buf_length_2); + if (Dialog::DIALOG_SCRN_BACKGROUND) { fo::func::win_hide(fo::var::getInt(FO_VAR_display_win)); IFaceBar::Hide(); - yPos += 50; + + fitRectH += fo::func::GNW_find(fo::var::interfaceWindow)->height; } - long mapWinW = fo::var::getInt(FO_VAR_buf_width_2) / 2; - long mapWinH = fo::var::getInt(FO_VAR_buf_length_2) / 2; - - xPos += mapWinW - (width / 2); // xPos:0 - yPos += mapWinH - (height / 2); // yPos:0 = 480 - art_frame_length + long expandedHeight = dialogExpandedHeight > 0 ? dialogExpandedHeight : height; + xPos += (fitRectW - width) / 2; // xPos:0 + yPos += (fitRectH - expandedHeight) / 2; // yPos:0 = 480 - art_frame_length if (yPos < 0) yPos = 0; yPosition = yPos; @@ -274,4 +277,10 @@ void Dialog::init() { } } +void Dialog::SetDialogExpandedHeight(long height) { + assert(height >= 0); + + dialogExpandedHeight = height; +} + } diff --git a/sfall/HRP/Dialog.h b/sfall/HRP/Dialog.h index b72dbee7..6a15bb79 100644 --- a/sfall/HRP/Dialog.h +++ b/sfall/HRP/Dialog.h @@ -15,6 +15,8 @@ public: static bool DIALOG_SCRN_ART_FIX; static bool DIALOG_SCRN_BACKGROUND; + + static void SetDialogExpandedHeight(long height); }; } diff --git a/sfall/Modules/Interface.cpp b/sfall/Modules/Interface.cpp index 80ddb064..89d4910b 100644 --- a/sfall/Modules/Interface.cpp +++ b/sfall/Modules/Interface.cpp @@ -27,6 +27,7 @@ #include "LoadGameHook.h" #include "Worldmap.h" +#include "..\HRP\Dialog.h" #include "..\HRP\InterfaceBar.h" #include "..\HRP\viewmap\EdgeClipping.h" @@ -1291,7 +1292,12 @@ static void ExpandedBarterPatch() { if (HRP::Setting::VersionIsValid) { // HRP overrides window creation code setup_inventory, so need to write correct max Y value into HRP itself. SafeWrite32(HRP::Setting::GetAddress(0x1001220C), 470 + extraBarterHeight); + // Vertical offset in DialogWinSetup() when main screen is disabled (DIALOG_SCRN_BACKGROUND = 1). + SafeWrite32(HRP::Setting::GetAddress(0x1001228F), dialogWindowHeight / 2); + // Window height for passing to AdjustWinPosToGame function that calculates x & y. + SafeWrite32(HRP::Setting::GetAddress(0x100122C3), dialogWindowHeight); } else { + HRP::Dialog::SetDialogExpandedHeight(dialogWindowHeight); SafeWrite32(0x46EDD4, 470 + extraBarterHeight); // Trade window max Y = Y pos + height = 290 + 180 = 470 } SafeWriteBatch(dialogWindowHeight, { // Game dialog BG window height (for Y calculation only)