mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-20 15:36:18 +00:00
🆙 Fix screen offset being stale after resize
This commit is contained in:
@@ -85,6 +85,7 @@ export const MainView: FC<{}> = props =>
|
|||||||
<AnimatePresence>
|
<AnimatePresence>
|
||||||
{ landingViewVisible &&
|
{ landingViewVisible &&
|
||||||
<motion.div
|
<motion.div
|
||||||
|
className="w-full h-full"
|
||||||
initial={ { opacity: 0 }}
|
initial={ { opacity: 0 }}
|
||||||
animate={ { opacity: 1 }}
|
animate={ { opacity: 1 }}
|
||||||
exit={ { opacity: 0 }}>
|
exit={ { opacity: 0 }}>
|
||||||
|
|||||||
@@ -83,27 +83,36 @@ export const HotelView: FC<{}> = props =>
|
|||||||
|
|
||||||
if(!container) return;
|
if(!container) return;
|
||||||
|
|
||||||
const viewportWidth = window.innerWidth;
|
const centerView = () =>
|
||||||
const viewportHeight = window.innerHeight - 55;
|
|
||||||
|
|
||||||
const lobbyEl = container.querySelector<HTMLElement>('.nitro-hotel-view-lobby');
|
|
||||||
|
|
||||||
if(lobbyEl)
|
|
||||||
{
|
{
|
||||||
const containerRect = container.getBoundingClientRect();
|
const viewportWidth = window.innerWidth;
|
||||||
const lobbyRect = lobbyEl.getBoundingClientRect();
|
const viewportHeight = window.innerHeight - 55;
|
||||||
|
|
||||||
const lobbyCenterX = (lobbyRect.left - containerRect.left) + container.scrollLeft + lobbyRect.width / 2;
|
const lobbyEl = container.querySelector<HTMLElement>('.nitro-hotel-view-lobby');
|
||||||
const lobbyCenterY = (lobbyRect.top - containerRect.top) + container.scrollTop + lobbyRect.height / 2;
|
|
||||||
|
|
||||||
container.scrollLeft = Math.max(0, lobbyCenterX - viewportWidth / 2);
|
if(lobbyEl)
|
||||||
container.scrollTop = Math.max(0, lobbyCenterY - viewportHeight / 2);
|
{
|
||||||
}
|
const containerRect = container.getBoundingClientRect();
|
||||||
else
|
const lobbyRect = lobbyEl.getBoundingClientRect();
|
||||||
{
|
|
||||||
container.scrollLeft = Math.max(0, (2600 - viewportWidth) / 2);
|
const lobbyCenterX = (lobbyRect.left - containerRect.left) + container.scrollLeft + lobbyRect.width / 2;
|
||||||
container.scrollTop = Math.max(0, (1425 - viewportHeight) / 2);
|
const lobbyCenterY = (lobbyRect.top - containerRect.top) + container.scrollTop + lobbyRect.height / 2;
|
||||||
}
|
|
||||||
|
container.scrollLeft = Math.max(0, lobbyCenterX - viewportWidth / 2);
|
||||||
|
container.scrollTop = Math.max(0, lobbyCenterY - viewportHeight / 2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
container.scrollLeft = Math.max(0, (2600 - viewportWidth) / 2);
|
||||||
|
container.scrollTop = Math.max(0, (1425 - viewportHeight) / 2);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
centerView();
|
||||||
|
|
||||||
|
window.addEventListener('resize', centerView);
|
||||||
|
|
||||||
|
return () => window.removeEventListener('resize', centerView);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleMouseDown = (e: React.MouseEvent<HTMLDivElement>) =>
|
const handleMouseDown = (e: React.MouseEvent<HTMLDivElement>) =>
|
||||||
|
|||||||
@@ -43,10 +43,11 @@ export const RoomView: FC<{}> = (props) =>
|
|||||||
<AnimatePresence>
|
<AnimatePresence>
|
||||||
{
|
{
|
||||||
<motion.div
|
<motion.div
|
||||||
|
className="w-full h-full"
|
||||||
initial={ { opacity: 0 }}
|
initial={ { opacity: 0 }}
|
||||||
animate={ { opacity: 1 }}
|
animate={ { opacity: 1 }}
|
||||||
exit={ { opacity: 0 }}>
|
exit={ { opacity: 0 }}>
|
||||||
<div ref={ elementRef } className="w-100 h-100">
|
<div ref={ elementRef } className="w-full h-full">
|
||||||
{ roomSession instanceof RoomSession &&
|
{ roomSession instanceof RoomSession &&
|
||||||
<>
|
<>
|
||||||
<RoomWidgetsView />
|
<RoomWidgetsView />
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { ColorConverter, GetRenderer, GetRoomEngine, GetStage, IRoomSession, NitroAdjustmentFilter, NitroSprite, NitroTexture, RoomBackgroundColorEvent, RoomEngineEvent, RoomEngineObjectEvent, RoomGeometry, RoomId, RoomObjectCategory, RoomObjectHSLColorEnabledEvent, RoomObjectOperationType, RoomSessionEvent, RoomVariableEnum, Vector3d } from '@nitrots/nitro-renderer';
|
import { ColorConverter, GetRenderer, GetRoomEngine, GetStage, IRoomSession, NitroAdjustmentFilter, NitroSprite, NitroTexture, RoomBackgroundColorEvent, RoomEngineEvent, RoomEngineObjectEvent, RoomGeometry, RoomId, RoomObjectCategory, RoomObjectHSLColorEnabledEvent, RoomObjectOperationType, RoomSessionEvent, RoomVariableEnum, Vector3d } from '@nitrots/nitro-renderer';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useBetween } from 'use-between';
|
import { useBetween } from 'use-between';
|
||||||
import { CanManipulateFurniture, DispatchUiEvent, GetRoomSession, InitializeRoomInstanceRenderingCanvas, IsFurnitureSelectionDisabled, ProcessRoomObjectOperation, RoomWidgetUpdateBackgroundColorPreviewEvent, RoomWidgetUpdateRoomObjectEvent, SetActiveRoomId, StartRoomSession } from '../../api';
|
import { CanManipulateFurniture, DispatchUiEvent, GetRoomSession, IsFurnitureSelectionDisabled, ProcessRoomObjectOperation, RoomWidgetUpdateBackgroundColorPreviewEvent, RoomWidgetUpdateRoomObjectEvent, SetActiveRoomId, StartRoomSession } from '../../api';
|
||||||
import { useNitroEvent, useUiEvent } from '../events';
|
import { useNitroEvent, useUiEvent } from '../events';
|
||||||
|
|
||||||
const useRoomState = () =>
|
const useRoomState = () =>
|
||||||
@@ -253,15 +253,20 @@ const useRoomState = () =>
|
|||||||
|
|
||||||
const resize = (event: UIEvent) =>
|
const resize = (event: UIEvent) =>
|
||||||
{
|
{
|
||||||
const width = Math.floor(window.innerWidth);
|
const newWidth = Math.floor(window.innerWidth);
|
||||||
const height = Math.floor(window.innerHeight);
|
const newHeight = Math.floor(window.innerHeight);
|
||||||
|
|
||||||
renderer.resize(width, height, window.devicePixelRatio);
|
const offsetX = canvas.screenOffsetX - (newWidth - canvas.width) / 2;
|
||||||
|
const offsetY = canvas.screenOffsetY - (newHeight - canvas.height) / 2;
|
||||||
|
|
||||||
background.width = width;
|
renderer.resize(newWidth, newHeight, window.devicePixelRatio);
|
||||||
background.height = height;
|
|
||||||
|
|
||||||
InitializeRoomInstanceRenderingCanvas(width, height, 1);
|
background.width = newWidth;
|
||||||
|
background.height = newHeight;
|
||||||
|
|
||||||
|
canvas.initialize(newWidth, newHeight);
|
||||||
|
canvas.screenOffsetX = ~~offsetX;
|
||||||
|
canvas.screenOffsetY = ~~offsetY;
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener('resize', resize);
|
window.addEventListener('resize', resize);
|
||||||
|
|||||||
Reference in New Issue
Block a user