From 585cfddca2d13d5df58455c3241c608b22aa90a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20Sch=C3=BCrz?= Date: Fri, 17 Jan 2025 23:10:09 +0100 Subject: [PATCH] Change default screen resolution based on device type --- packages/core/src/OsucadGameBase.ts | 17 +++++++---- .../multiplayer/MultiplayerCursorOverlay.ts | 30 +++++++++++-------- .../graphics/cursor/DefaultCursorContainer.ts | 4 +-- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/packages/core/src/OsucadGameBase.ts b/packages/core/src/OsucadGameBase.ts index b8318dea..ab930214 100644 --- a/packages/core/src/OsucadGameBase.ts +++ b/packages/core/src/OsucadGameBase.ts @@ -1,5 +1,5 @@ import type { Container, Drawable, PIXIRenderer, ReadonlyDependencyContainer } from '@osucad/framework'; -import { AudioManager, Axes, Box, DependencyContainer, Game, IRenderer, provide, resolved } from '@osucad/framework'; +import { AudioManager, Axes, Box, DependencyContainer, Game, IRenderer, isMobile, provide, resolved, Vec2 } from '@osucad/framework'; import { OsucadIcons } from '@osucad/resources'; import { RenderTarget } from 'pixi.js'; import { AudioMixer } from './audio/AudioMixer'; @@ -38,6 +38,16 @@ export abstract class OsucadGameBase extends Game implements IResourcesProvider @provide(ColorProvider) colors = new ColorProvider(); + protected getTargetDrawSize() { + if (isMobile.phone) + return new Vec2(540, 400); + + if (isMobile.any) + return new Vec2(640, 640); + + return new Vec2(960, 768); + } + protected override load(dependencies: ReadonlyDependencyContainer) { super.load(dependencies); @@ -58,10 +68,7 @@ export abstract class OsucadGameBase extends Game implements IResourcesProvider }), new SafeAreaContainer({ child: new ScalingContainer({ - desiredSize: { - x: 960, - y: 768, - }, + desiredSize: this.getTargetDrawSize(), fit: Fit.Fill, child: new PerformanceOverlay({ child: new EditorActionContainer({ diff --git a/packages/core/src/editor/multiplayer/MultiplayerCursorOverlay.ts b/packages/core/src/editor/multiplayer/MultiplayerCursorOverlay.ts index 0d5ea5c5..f8cfcd1f 100644 --- a/packages/core/src/editor/multiplayer/MultiplayerCursorOverlay.ts +++ b/packages/core/src/editor/multiplayer/MultiplayerCursorOverlay.ts @@ -2,8 +2,8 @@ import type { InputManager, ReadonlyDependencyContainer } from '@osucad/framewor import type { CursorPosition } from '@osucad/multiplayer'; import type { ConnectedUser } from './ConnectedUsers'; import type { MultiplayerCursorArea } from './MultiplayerCursorArea'; -import { Anchor, Axes, CompositeDrawable, Container, DrawableSprite, MouseButton, ProxyDrawable, resolved, Vec2 } from '@osucad/framework'; -import { getIcon } from '@osucad/resources'; +import { Axes, BindableBoolean, CompositeDrawable, Container, MouseButton, ProxyDrawable, resolved, Vec2 } from '@osucad/framework'; +import { DefaultCursor } from '../../graphics/cursor/DefaultCursorContainer'; import { MultiplayerClient } from './MultiplayerClient'; export class MultiplayerCursorOverlay extends CompositeDrawable { @@ -120,20 +120,15 @@ class MultiplayerCursor extends CompositeDrawable { ) { super(); - this.addInternal(new Container({ - scale: 0.5, - children: [ - new DrawableSprite({ - texture: getIcon('select'), - anchor: Anchor.TopLeft, - x: -5, - y: -4, - color: this.user.clientInfo.color, - }), - ], + this.addInternal(this.#cursor = new DefaultCursor().with({ + color: user.clientInfo.color, })); } + readonly #cursor: DefaultCursor; + + buttonPressed = new BindableBoolean(); + protected override loadComplete() { super.loadComplete(); @@ -143,6 +138,13 @@ class MultiplayerCursor extends CompositeDrawable { if (key === 'cursor') this.updatePosition(); }); + + this.buttonPressed.bindValueChanged((e) => { + if (e.value) + this.#cursor.animateMouseDown(); + else + this.#cursor.animateMouseUp(); + }, true); } #targetPosition = new Vec2(); @@ -150,6 +152,8 @@ class MultiplayerCursor extends CompositeDrawable { updatePosition() { const { cursor } = this.user.presence; + this.buttonPressed.value = cursor?.pressed ?? false; + if (!cursor) { this.fadeOut(); this.setActiveArea(null); diff --git a/packages/core/src/graphics/cursor/DefaultCursorContainer.ts b/packages/core/src/graphics/cursor/DefaultCursorContainer.ts index d306c11b..699ded42 100644 --- a/packages/core/src/graphics/cursor/DefaultCursorContainer.ts +++ b/packages/core/src/graphics/cursor/DefaultCursorContainer.ts @@ -49,7 +49,7 @@ export class DefaultCursor extends CompositeDrawable { this.animateMouseUp(); } - protected animateMouseDown() { + animateMouseDown() { this.#sprite.scaleTo(0.8, 1000, EasingFunction.OutQuart); this.#sprite.moveTo(new Vec2(-5, -4), 1000, EasingFunction.OutQuart); @@ -57,7 +57,7 @@ export class DefaultCursor extends CompositeDrawable { this.#shadow.moveTo(new Vec2(-5, -2), 1000, EasingFunction.OutQuart); } - protected animateMouseUp() { + animateMouseUp() { this.#sprite.scaleTo(1, 200, EasingFunction.OutBack); this.#sprite.moveTo(new Vec2(-4, -3), 200, EasingFunction.OutBack);