From ace2aa4718c97de48d361a65ff33c3a2da738ed3 Mon Sep 17 00:00:00 2001 From: tsa96 Date: Thu, 8 Aug 2024 15:45:35 +0100 Subject: [PATCH] chore: undo weird method reorder Reordering this methods is making it very hard to review, if you're gonna do something like this, please commit separately so the diff isn't as mangled! --- scripts/hud/customizer.ts | 132 +++++++++++++++++++------------------- 1 file changed, 66 insertions(+), 66 deletions(-) diff --git a/scripts/hud/customizer.ts b/scripts/hud/customizer.ts index e44f2f86..70e8b6c3 100644 --- a/scripts/hud/customizer.ts +++ b/scripts/hud/customizer.ts @@ -351,6 +351,50 @@ namespace HudCustomizer { $.UnregisterEventHandler('DragStart', panels.virtual, dragStartHandle); } + function onComponentMouseOver(component: Component) { + if (activeComponent && activeComponent === component) return; + + activeComponent?.panel.RemoveClass('hud-customizable--active'); + + activeComponent = component; + + activeComponent.panel.AddClass('hud-customizable--active'); + + const [position, size] = LayoutUtil.getPositionAndSize(component.panel); + + // Set the virtual panel's position and size to the component we just hovered over + LayoutUtil.setPositionAndSize(panels.virtual, position, size); + + updateResizeKnobs(position, size); + + // This is going to be weird to localise, but I guess we could do it, probably in V2 when we can + // define the locale string in the `customisable` XML property. + panels.virtualName.text = activeComponent.panel.id; + // TODO: This text looks TERRIBLE. Better to just have a constant size text for every component + // place text above component (left-aligned) + const stupidFontSizeThing = Math.min( + LayoutUtil.getHeight(activeComponent.panel) / 2, + LayoutUtil.getWidth(activeComponent.panel) / 2 + ); + + panels.virtualName.style.fontSize = stupidFontSizeThing; + + snaps[0][activeComponent.snaps[0]].button.SetSelected(true); + snaps[1][activeComponent.snaps[1]].button.SetSelected(true); + + if (dragStartHandle) { + $.UnregisterEventHandler('DragStart', panels.virtual, dragStartHandle); + } + if (dragEndHandle) { + $.UnregisterEventHandler('DragEnd', panels.virtual, dragEndHandle); + } + + dragStartHandle = $.RegisterEventHandler('DragStart', panels.virtual, (...args) => + onStartDrag(DragMode.MOVE, panels.virtual, ...args) + ); + dragEndHandle = $.RegisterEventHandler('DragEnd', panels.virtual, () => onEndDrag()); + } + function onStartDrag(mode, displayPanel, _source, callback) { if (!activeComponent) return; @@ -367,28 +411,6 @@ namespace HudCustomizer { callback.removePositionBeforeDrop = false; } - function onEndDrag() { - if (!activeComponent) return; - - onDragThink(); - - $.UnregisterEventHandler('HudThink', $.GetContextPanel(), onThinkHandle); - - LayoutUtil.setPositionAndSize(panels.virtual, activeComponent.position, activeComponent.size); - updateResizeKnobs(activeComponent.position, activeComponent.size); - - activeComponent.panel.RemoveClass('hud-customizable--dragging'); - panels.virtual.RemoveClass('hud-customizer-virtual--dragging'); - - activeGridlines?.forEach((line) => line?.panel.RemoveClass('hud-customizer__gridline--highlight')); - activeGridlines = [undefined, undefined]; - - // TODO: this is just for testing - save(); - - dragMode = undefined; - } - function onDragThink() { if (!activeComponent || dragMode === undefined) return; @@ -452,6 +474,28 @@ namespace HudCustomizer { LayoutUtil.setPositionAndSize(activeComponent.panel, activeComponent.position, activeComponent.size); } + function onEndDrag() { + if (!activeComponent) return; + + onDragThink(); + + $.UnregisterEventHandler('HudThink', $.GetContextPanel(), onThinkHandle); + + LayoutUtil.setPositionAndSize(panels.virtual, activeComponent.position, activeComponent.size); + updateResizeKnobs(activeComponent.position, activeComponent.size); + + activeComponent.panel.RemoveClass('hud-customizable--dragging'); + panels.virtual.RemoveClass('hud-customizer-virtual--dragging'); + + activeGridlines?.forEach((line) => line?.panel.RemoveClass('hud-customizer__gridline--highlight')); + activeGridlines = [undefined, undefined]; + + // TODO: this is just for testing + save(); + + dragMode = undefined; + } + function updateResizeKnobs(position, size) { const width = size[0]; const height = size[1]; @@ -498,50 +542,6 @@ namespace HudCustomizer { } } - function onComponentMouseOver(component: Component) { - if (activeComponent && activeComponent === component) return; - - activeComponent?.panel.RemoveClass('hud-customizable--active'); - - activeComponent = component; - - activeComponent.panel.AddClass('hud-customizable--active'); - - const [position, size] = LayoutUtil.getPositionAndSize(component.panel); - - // Set the virtual panel's position and size to the component we just hovered over - LayoutUtil.setPositionAndSize(panels.virtual, position, size); - - updateResizeKnobs(position, size); - - // This is going to be weird to localise, but I guess we could do it, probably in V2 when we can - // define the locale string in the `customisable` XML property. - panels.virtualName.text = activeComponent.panel.id; - // TODO: This text looks TERRIBLE. Better to just have a constant size text for every component - // place text above component (left-aligned) - const stupidFontSizeThing = Math.min( - LayoutUtil.getHeight(activeComponent.panel) / 2, - LayoutUtil.getWidth(activeComponent.panel) / 2 - ); - - panels.virtualName.style.fontSize = stupidFontSizeThing; - - snaps[0][activeComponent.snaps[0]].button.SetSelected(true); - snaps[1][activeComponent.snaps[1]].button.SetSelected(true); - - if (dragStartHandle) { - $.UnregisterEventHandler('DragStart', panels.virtual, dragStartHandle); - } - if (dragEndHandle) { - $.UnregisterEventHandler('DragEnd', panels.virtual, dragEndHandle); - } - - dragStartHandle = $.RegisterEventHandler('DragStart', panels.virtual, (...args) => - onStartDrag(DragMode.MOVE, panels.virtual, ...args) - ); - dragEndHandle = $.RegisterEventHandler('DragEnd', panels.virtual, () => onEndDrag()); - } - function getNearestGridLine(axis: Axis, sizeFactor: number): Gridline { const isX = axis === Axis.X;