From 93110736af5aaf01b85a34b241c2968db043b493 Mon Sep 17 00:00:00 2001 From: wertiop Date: Tue, 6 Aug 2024 16:18:56 +0100 Subject: [PATCH] feat(hud customizer): Add resizing --- layout/hud/hud.xml | 2 +- scripts/hud/customizer.ts | 266 +++++++++++++++++++++++--------------- styles/hud/hud.scss | 13 +- 3 files changed, 167 insertions(+), 114 deletions(-) diff --git a/layout/hud/hud.xml b/layout/hud/hud.xml index fc9228be..46dfa83f 100644 --- a/layout/hud/hud.xml +++ b/layout/hud/hud.xml @@ -28,7 +28,7 @@ - + diff --git a/scripts/hud/customizer.ts b/scripts/hud/customizer.ts index b50461d5..a6ba7f6b 100644 --- a/scripts/hud/customizer.ts +++ b/scripts/hud/customizer.ts @@ -40,6 +40,29 @@ namespace HudCustomizer { TOP_LEFT: 8 }; + enum DragMode { + MOVE = 0, + RESIZE_TOP = 1, + RESIZE_TOP_RIGHT = 2, + RESIZE_RIGHT = 3, + RESIZE_BOTTOM_RIGHT = 4, + RESIZE_BOTTOM = 5, + RESIZE_BOTTOM_LEFT = 6, + RESIZE_LEFT = 7, + RESIZE_TOP_LEFT = 8 + } + + const resizeVector: ReadonlyMap, [number, number]> = new Map([ + [DragMode.RESIZE_TOP, [0, -1]], + [DragMode.RESIZE_TOP_RIGHT, [1, -1]], + [DragMode.RESIZE_RIGHT, [1, 0]], + [DragMode.RESIZE_BOTTOM_RIGHT, [1, 1]], + [DragMode.RESIZE_BOTTOM, [0, 1]], + [DragMode.RESIZE_BOTTOM_LEFT, [-1, 1]], + [DragMode.RESIZE_LEFT, [-1, 0]], + [DragMode.RESIZE_TOP_LEFT, [-1, -1]] + ]); + // Tuple of X, Y axis snaps respectively const DEFAULT_SNAP_MODES: Snaps = [SnapMode.OFF, SnapMode.OFF]; const DEFAULT_GRID_SIZE = 5; @@ -48,6 +71,7 @@ namespace HudCustomizer { components: { [id: string]: { position: LayoutUtil.Position; + size: LayoutUtil.Size; snaps: [number, number]; }; }; @@ -60,6 +84,7 @@ namespace HudCustomizer { panel: Panel; snaps: Snaps; position: LayoutUtil.Position; + size: LayoutUtil.Size; properties?: Record; } @@ -133,8 +158,7 @@ namespace HudCustomizer { virtualName: $