Skip to content

Commit

Permalink
Fix ExpandBarter and DIALOG_SCRN_BACKGROUND conflict (closes #544)
Browse files Browse the repository at this point in the history
  • Loading branch information
phobos2077 committed Jun 1, 2024
1 parent 002dfa6 commit 6b8613a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
21 changes: 15 additions & 6 deletions sfall/HRP/Dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

long mapWinW = fo::var::getInt(FO_VAR_buf_width_2) / 2;
long mapWinH = fo::var::getInt(FO_VAR_buf_length_2) / 2;
fitRectH += fo::func::GNW_find(fo::var::interfaceWindow)->height;
}

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;
Expand Down Expand Up @@ -274,4 +277,10 @@ void Dialog::init() {
}
}

void Dialog::SetDialogExpandedHeight(long height) {
assert(height >= 0);

dialogExpandedHeight = height;
}

}
2 changes: 2 additions & 0 deletions sfall/HRP/Dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Dialog {

static bool DIALOG_SCRN_ART_FIX;
static bool DIALOG_SCRN_BACKGROUND;

static void SetDialogExpandedHeight(long height);
};

}
6 changes: 6 additions & 0 deletions sfall/Modules/Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "LoadGameHook.h"
#include "Worldmap.h"

#include "..\HRP\Dialog.h"
#include "..\HRP\InterfaceBar.h"
#include "..\HRP\viewmap\EdgeClipping.h"

Expand Down Expand Up @@ -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<DWORD>(dialogWindowHeight, { // Game dialog BG window height (for Y calculation only)
Expand Down

0 comments on commit 6b8613a

Please sign in to comment.