Fix pipboy position

See #3
This commit is contained in:
Alexander Batalov 2022-05-21 02:29:59 +03:00
parent 6c4927b129
commit 73d624a46c
3 changed files with 20 additions and 6 deletions

View File

@ -4618,3 +4618,14 @@ int screenGetHeight()
// TODO: Make it on par with _yres. // TODO: Make it on par with _yres.
return rectGetHeight(&_scr_size); return rectGetHeight(&_scr_size);
} }
void mouseGetPositionInWindow(int win, int* x, int* y)
{
mouseGetPosition(x, y);
Window* window = windowGetWindow(win);
if (window != NULL) {
*x -= window->rect.left;
*y -= window->rect.top;
}
}

View File

@ -636,5 +636,6 @@ bool _vcr_load_record(STRUCT_51E2F0* ptr, File* stream);
int screenGetWidth(); int screenGetWidth();
int screenGetHeight(); int screenGetHeight();
void mouseGetPositionInWindow(int win, int* x, int* y);
#endif /* CORE_H */ #endif /* CORE_H */

View File

@ -220,7 +220,7 @@ int pipboyOpen(bool forceRest)
return -1; return -1;
} }
mouseGetPosition(&gPipboyPreviousMouseX, &gPipboyPreviousMouseY); mouseGetPositionInWindow(gPipboyWindow, &gPipboyPreviousMouseX, &gPipboyPreviousMouseY);
gPipboyLastEventTimestamp = _get_time(); gPipboyLastEventTimestamp = _get_time();
while (true) { while (true) {
@ -231,7 +231,7 @@ int pipboyOpen(bool forceRest)
forceRest = false; forceRest = false;
} }
mouseGetPosition(&gPipboyMouseX, &gPipboyMouseY); mouseGetPositionInWindow(gPipboyWindow, &gPipboyMouseX, &gPipboyMouseY);
if (keyCode != -1 || gPipboyMouseX != gPipboyPreviousMouseX || gPipboyMouseY != gPipboyPreviousMouseY) { if (keyCode != -1 || gPipboyMouseX != gPipboyPreviousMouseX || gPipboyMouseY != gPipboyPreviousMouseY) {
gPipboyLastEventTimestamp = _get_time(); gPipboyLastEventTimestamp = _get_time();
@ -242,7 +242,7 @@ int pipboyOpen(bool forceRest)
pipboyRenderScreensaver(); pipboyRenderScreensaver();
gPipboyLastEventTimestamp = _get_time(); gPipboyLastEventTimestamp = _get_time();
mouseGetPosition(&gPipboyPreviousMouseX, &gPipboyPreviousMouseY); mouseGetPositionInWindow(gPipboyWindow, &gPipboyPreviousMouseX, &gPipboyPreviousMouseY);
} }
} }
@ -341,7 +341,9 @@ int pipboyWindowInit(bool forceRest)
return -1; return -1;
} }
gPipboyWindow = windowCreate(0, 0, PIPBOY_WINDOW_WIDTH, PIPBOY_WINDOW_HEIGHT, _colorTable[0], WINDOW_FLAG_0x10); int pipboyWindowX = (screenGetWidth() - PIPBOY_WINDOW_WIDTH) / 2;
int pipboyWindowY = (screenGetHeight() - PIPBOY_WINDOW_HEIGHT) / 2;
gPipboyWindow = windowCreate(pipboyWindowX, pipboyWindowY, PIPBOY_WINDOW_WIDTH, PIPBOY_WINDOW_HEIGHT, _colorTable[0], WINDOW_FLAG_0x10);
if (gPipboyWindow == -1) { if (gPipboyWindow == -1) {
debugPrint("\n** Error opening pipboy window! **\n"); debugPrint("\n** Error opening pipboy window! **\n");
for (int index = 0; index < PIPBOY_FRM_COUNT; index++) { for (int index = 0; index < PIPBOY_FRM_COUNT; index++) {
@ -2001,7 +2003,7 @@ int pipboyRenderScreensaver()
{ {
PipboyBomb bombs[PIPBOY_BOMB_COUNT]; PipboyBomb bombs[PIPBOY_BOMB_COUNT];
mouseGetPosition(&gPipboyPreviousMouseX, &gPipboyPreviousMouseY); mouseGetPositionInWindow(gPipboyWindow, &gPipboyPreviousMouseX, &gPipboyPreviousMouseY);
for (int index = 0; index < PIPBOY_BOMB_COUNT; index += 1) { for (int index = 0; index < PIPBOY_BOMB_COUNT; index += 1) {
bombs[index].field_10 = 0; bombs[index].field_10 = 0;
@ -2032,7 +2034,7 @@ int pipboyRenderScreensaver()
while (true) { while (true) {
unsigned int time = _get_time(); unsigned int time = _get_time();
mouseGetPosition(&gPipboyMouseX, &gPipboyMouseY); mouseGetPositionInWindow(gPipboyWindow, &gPipboyMouseX, &gPipboyMouseY);
if (_get_input() != -1 || gPipboyPreviousMouseX != gPipboyMouseX || gPipboyPreviousMouseY != gPipboyMouseY) { if (_get_input() != -1 || gPipboyPreviousMouseX != gPipboyMouseX || gPipboyPreviousMouseY != gPipboyMouseY) {
break; break;
} }