From 1c9e2099ed400519428c8a9698a4f3999596a0ab Mon Sep 17 00:00:00 2001 From: marceline-cramer Date: Tue, 22 Jun 2021 09:31:21 -0600 Subject: [PATCH 01/14] Add initial UiPanel.d.ts --- assembly/types/UiPanel.d.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 assembly/types/UiPanel.d.ts diff --git a/assembly/types/UiPanel.d.ts b/assembly/types/UiPanel.d.ts new file mode 100644 index 0000000..4f90ed8 --- /dev/null +++ b/assembly/types/UiPanel.d.ts @@ -0,0 +1,19 @@ +@unmanaged declare class UiPanel { + @external("", "UiPanel_getWidth") + getWidth(): f32 + + @external("", "UiPanel_getHeight") + getHeight(): f32 + + @external("", "UiPanel_setSize") + setSize(width: f32, height: f32): void + + @external("", "UiPanel_setColor") + setColor(r: f32, g: f32, b: f32, a: f32): void + + @external("", "UiPanel_drawTriangle") + drawTriangle(x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, r: f32, g: f32, b: f32, a: f32) +} + +export default UiPanel; + From 11f72d41126e0d3ecf01151be3993078636fba27 Mon Sep 17 00:00:00 2001 From: marceline-cramer Date: Tue, 22 Jun 2021 09:31:34 -0600 Subject: [PATCH 02/14] Use internal UiPanel in Element --- assembly/types/Element.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assembly/types/Element.ts b/assembly/types/Element.ts index 549571f..76f1e91 100644 --- a/assembly/types/Element.ts +++ b/assembly/types/Element.ts @@ -1,5 +1,5 @@ import Color from "./Color"; -import UiPanel from "../../codegen/ui/UiPanel"; +import UiPanel from "./UiPanel"; export default class Element { constructor(public panel: UiPanel) {} From b0b465486b1a900e95ce1e9dcba51259fccf8687 Mon Sep 17 00:00:00 2001 From: marceline-cramer Date: Tue, 22 Jun 2021 09:33:10 -0600 Subject: [PATCH 03/14] Revert "Use core drawCircle() and drawRing() functions" This reverts commit 0eded1f43e4ae01b606068461b52b34c8ff3eb41. Add Vector2.ts --- assembly/types/Element.ts | 64 ++++++++++++++++++++++++--- assembly/types/Vector2.ts | 91 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+), 7 deletions(-) create mode 100644 assembly/types/Vector2.ts diff --git a/assembly/types/Element.ts b/assembly/types/Element.ts index 76f1e91..d3b1dd6 100644 --- a/assembly/types/Element.ts +++ b/assembly/types/Element.ts @@ -1,20 +1,70 @@ import Color from "./Color"; import UiPanel from "./UiPanel"; +import Vector2 from "./Vector2"; export default class Element { constructor(public panel: UiPanel) {} drawCircle(x: f64, y: f64, radius: f64, color: Color): void { - this.panel.drawCircle(x, y, radius, color.r, color.g, color.b, color.a); - return; + let center = new Vector2(x, y); + let last_spoke = new Vector2(radius + x, y); + let delta: f64 = Math.PI / 16.0; + let limit: f64 = Math.PI * 2.0 + delta; + for (let theta = delta; theta < limit; theta += delta) { + let new_spoke = new Vector2( + Math.cos(theta) * radius, + Math.sin(theta) * radius); + new_spoke.add(center); + + this.panel.drawTriangle( + x, y, + last_spoke.x, last_spoke.y, + new_spoke.x, new_spoke.y, + color.r, color.g, color.b, color.a); + + last_spoke = new_spoke; + } } drawCircleOutline(x: f64, y: f64, radius: f64, thickness: f64, color: Color): void { - let half_thickness = thickness / 2.0; - let inner_radius = radius - half_thickness; - let outer_radius = radius + half_thickness; - this.panel.drawRing(x, y, inner_radius, outer_radius, color.r, color.g, color.b, color.a); - return; + let center = new Vector2(x, y); + let last_spoke = new Vector2(radius + x, y); + let delta: f64 = Math.PI / 64.0; + let limit: f64 = Math.PI * 2.0 + delta; + + let last_theta: f64 = 0; + for (let theta = delta; theta < limit; theta += delta) { + let new_spoke = new Vector2( + Math.cos(theta) * radius, + Math.sin(theta) * radius); + + let new_spoke2 = new Vector2( + Math.cos(theta) * (radius + thickness), + Math.sin(theta) * (radius + thickness)); + + let last_spoke2 = new Vector2( + Math.cos(last_theta) * (radius + thickness), + Math.sin(last_theta) * (radius + thickness)); + + new_spoke.add(center); + new_spoke2.add(center); + last_spoke2.add(center); + + this.panel.drawTriangle( + new_spoke2.x, new_spoke2.y, + last_spoke.x, last_spoke.y, + new_spoke.x, new_spoke.y, + color.r, color.g, color.b, color.a); + + this.panel.drawTriangle( + new_spoke2.x, new_spoke2.y, + last_spoke2.x, last_spoke2.y, + last_spoke.x, last_spoke.y, + color.r, color.g, color.b, color.a); + + last_spoke = new_spoke; + last_theta = theta; + } } drawRect(x: f64, y: f64, w: f64, h: f64, color: Color): void { diff --git a/assembly/types/Vector2.ts b/assembly/types/Vector2.ts new file mode 100644 index 0000000..01efe91 --- /dev/null +++ b/assembly/types/Vector2.ts @@ -0,0 +1,91 @@ +// Mondradiko scripting API - AssemblyScript bindings +// https://mondradiko.github.io/ + +export default class Vector2 { + /** + * Instantiation + */ + + constructor(public x: f64, public y: f64) {} + + clone(): Vector2 { return new Vector2(this.x, this.y); } + + static readonly Zero: Vector2 = new Vector2(0.0, 0.0); + + /** + * Vector properties + */ + + squaredLength(): f64 { + return this.dot(this); + } + + length(): f64 { + return Math.sqrt(this.squaredLength()); + } + + /** + * Vector operations + */ + + normalize(): void { + this.scale(1.0 / this.length()); + } + + /** + * Vector-to-vector arithmetic + */ + + add(other: Vector2): void { + this.x += other.x; + this.y += other.y; + } + + sub(other: Vector2): void { + this.x -= other.x; + this.y -= other.y; + } + + mul(other: Vector2): void { + this.x *= other.x; + this.y *= other.y; + } + + div(other: Vector2): void { + this.x /= other.x; + this.y /= other.y; + } + + /** + * Vector-to-scalar arithmetic + */ + + scale(s: f64): void { + this.x *= s; + this.y *= s; + } + + set(s: f64): void { + this.x = s; + this.y = s; + } + + /** + * Vector-to-vector math + */ + + dot(other: Vector2): f64 { + return this.x * other.x + this.y * other.y; + } + + squaredDistance(other: Vector2): f64 { + const x = this.x - other.x; + const y = this.y - other.y; + + return x * x + y * y; + } + + distance(other: Vector2): f64 { + return Math.sqrt(this.squaredDistance(other)); + } +} From e3d754e56f246a81cdb9f8038d75bd9ce9bbbe17 Mon Sep 17 00:00:00 2001 From: marceline-cramer Date: Tue, 22 Jun 2021 09:47:37 -0600 Subject: [PATCH 04/14] Add void return type to UiPanel_drawTriangle --- assembly/types/UiPanel.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assembly/types/UiPanel.d.ts b/assembly/types/UiPanel.d.ts index 4f90ed8..bc8efaa 100644 --- a/assembly/types/UiPanel.d.ts +++ b/assembly/types/UiPanel.d.ts @@ -12,7 +12,7 @@ setColor(r: f32, g: f32, b: f32, a: f32): void @external("", "UiPanel_drawTriangle") - drawTriangle(x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, r: f32, g: f32, b: f32, a: f32) + drawTriangle(x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, r: f32, g: f32, b: f32, a: f32): void } export default UiPanel; From 29b30214c87a2d86b66a702c1d97128786677316 Mon Sep 17 00:00:00 2001 From: marceline-cramer Date: Tue, 22 Jun 2021 09:51:50 -0600 Subject: [PATCH 05/14] Replace legacy codegen/UiPanel with new UiPanel --- assembly/elements/BoxButton.ts | 2 +- assembly/elements/Label.ts | 2 +- assembly/elements/NotchedBox.ts | 2 +- assembly/elements/RoundButton.ts | 2 +- assembly/index.ts | 4 ++-- assembly/menus/BoxList.ts | 2 +- assembly/menus/CharacterInfo.ts | 2 +- assembly/menus/Console.ts | 2 +- assembly/menus/MenuList.ts | 2 +- assembly/menus/PlayerMenu.ts | 2 +- assembly/types/Container.ts | 2 +- 11 files changed, 12 insertions(+), 12 deletions(-) diff --git a/assembly/elements/BoxButton.ts b/assembly/elements/BoxButton.ts index ab72536..2ae9930 100644 --- a/assembly/elements/BoxButton.ts +++ b/assembly/elements/BoxButton.ts @@ -1,7 +1,7 @@ import Color from "../types/Color"; import Element from "../types/Element"; import DynamicElement from "../types/DynamicElement"; -import UiPanel from "../../codegen/ui/UiPanel"; +import UiPanel from "../types/UiPanel"; import ColorAnimation from "../types/ColorAnimation"; import Theme from "../types/Theme"; import Animation from "../types/Animation"; diff --git a/assembly/elements/Label.ts b/assembly/elements/Label.ts index 8057498..715c658 100644 --- a/assembly/elements/Label.ts +++ b/assembly/elements/Label.ts @@ -2,7 +2,7 @@ import Color from "../types/Color"; import Element from "../types/Element"; import DynamicElement from "../types/DynamicElement"; import GlyphStyle from "../../codegen/ui/GlyphStyle"; -import UiPanel from "../../codegen/ui/UiPanel"; +import UiPanel from "../types/UiPanel"; export default class Label extends Element implements DynamicElement { w: f64; diff --git a/assembly/elements/NotchedBox.ts b/assembly/elements/NotchedBox.ts index af1a265..9c1a5f0 100644 --- a/assembly/elements/NotchedBox.ts +++ b/assembly/elements/NotchedBox.ts @@ -1,7 +1,7 @@ import Color from "../types/Color"; import Element from "../types/Element"; import DynamicElement from "../types/DynamicElement"; -import UiPanel from "../../codegen/ui/UiPanel"; +import UiPanel from "../types/UiPanel"; import Vector2 from "../../codegen/types/Vector2"; export default class NotchedBox extends Element implements DynamicElement { diff --git a/assembly/elements/RoundButton.ts b/assembly/elements/RoundButton.ts index 3b1fc93..0106e67 100644 --- a/assembly/elements/RoundButton.ts +++ b/assembly/elements/RoundButton.ts @@ -2,7 +2,7 @@ import Color from "../types/Color"; import Element from "../types/Element"; import DynamicElement from "../types/DynamicElement"; import Theme from "../types/Theme"; -import UiPanel from "../../codegen/ui/UiPanel"; +import UiPanel from "../types/UiPanel"; import ColorAnimation from "../types/ColorAnimation"; import Animation from "../types/Animation"; import { AnimationTimingFunction } from "../types/Animation"; diff --git a/assembly/index.ts b/assembly/index.ts index 0e7d4f6..5ea426a 100644 --- a/assembly/index.ts +++ b/assembly/index.ts @@ -8,7 +8,7 @@ import Container from "./types/Container"; import RoundButton from "./elements/RoundButton"; import Theme from "./types/Theme"; import Console from "./menus/Console"; -import UiPanel from "../codegen/ui/UiPanel"; +import UiPanel from "./types/UiPanel"; import MenuList from "./menus/MenuList"; @@ -64,7 +64,7 @@ export class PanelImpl extends Element { } onDeselect(x: f64, y: f64): void { - if (this.mouse_down_time < 0.2 && + if (this.mouse_down_time < 0.2 && Math.abs(this.mouse_down_x - x) < 0.05 && Math.abs(this.mouse_down_y - y) < 0.05 ) { this.menu_list.onSelect(x, y); diff --git a/assembly/menus/BoxList.ts b/assembly/menus/BoxList.ts index aeef615..228da74 100644 --- a/assembly/menus/BoxList.ts +++ b/assembly/menus/BoxList.ts @@ -1,5 +1,5 @@ import Container from "../types/Container"; -import UiPanel from "../../codegen/ui/UiPanel"; +import UiPanel from "../types/UiPanel"; import BoxButton from "../elements/BoxButton"; export default class BoxList extends Container { diff --git a/assembly/menus/CharacterInfo.ts b/assembly/menus/CharacterInfo.ts index dcc7b4e..04ab28f 100644 --- a/assembly/menus/CharacterInfo.ts +++ b/assembly/menus/CharacterInfo.ts @@ -2,7 +2,7 @@ import Container from "../types/Container"; import NotchedBox from "../elements/NotchedBox"; import RoundButton from "../elements/RoundButton"; import Theme from "../types/Theme"; -import UiPanel from "../../codegen/ui/UiPanel"; +import UiPanel from "../types/UiPanel"; import Element from "../types/Element"; import DynamicElement from "../types/DynamicElement"; diff --git a/assembly/menus/Console.ts b/assembly/menus/Console.ts index b7467a3..1d3e6b8 100644 --- a/assembly/menus/Console.ts +++ b/assembly/menus/Console.ts @@ -1,6 +1,6 @@ import GlyphStyle from "../../codegen/ui/GlyphStyle"; import DynamicElement from "../types/DynamicElement"; -import UiPanel from "../../codegen/ui/UiPanel"; +import UiPanel from "../types/UiPanel"; class QueuedMessage implements DynamicElement { lifespan: f64 = 5.0; diff --git a/assembly/menus/MenuList.ts b/assembly/menus/MenuList.ts index d82bc5a..236b2b3 100644 --- a/assembly/menus/MenuList.ts +++ b/assembly/menus/MenuList.ts @@ -3,7 +3,7 @@ import Element from "../types/Element"; import NotchedBox from "../elements/NotchedBox"; import RoundButton from "../elements/RoundButton"; import Theme from "../types/Theme"; -import UiPanel from "../../codegen/ui/UiPanel"; +import UiPanel from "../types/UiPanel"; import CharacterInfo from "./CharacterInfo"; import PlayerMenu from "./PlayerMenu"; import TimerCallback from "../types/TimerCallback"; diff --git a/assembly/menus/PlayerMenu.ts b/assembly/menus/PlayerMenu.ts index 52ae51c..e1bfcb2 100644 --- a/assembly/menus/PlayerMenu.ts +++ b/assembly/menus/PlayerMenu.ts @@ -3,7 +3,7 @@ import RoundButton from "../elements/RoundButton"; import Element from "../types/Element"; import Theme from "../types/Theme"; import BoxList from "./BoxList"; -import UiPanel from "../../codegen/ui/UiPanel"; +import UiPanel from "../types/UiPanel"; import BoxButton from "../elements/BoxButton"; import DynamicElement from "../types/DynamicElement"; import TimerCallback from "../types/TimerCallback"; diff --git a/assembly/types/Container.ts b/assembly/types/Container.ts index 1477133..7eb2648 100644 --- a/assembly/types/Container.ts +++ b/assembly/types/Container.ts @@ -1,6 +1,6 @@ import Element from "./Element"; import DynamicElement from "./DynamicElement"; -import UiPanel from "../../codegen/ui/UiPanel"; +import UiPanel from "../types/UiPanel"; export default class Container extends Element implements DynamicElement { elements: Array = []; From 777ed2e202e517cd7e51fcbf2c8a1ae99326381b Mon Sep 17 00:00:00 2001 From: marceline-cramer Date: Tue, 22 Jun 2021 10:03:53 -0600 Subject: [PATCH 06/14] Add wrapper code for UiPanel to convert types --- assembly/types/UiPanel.d.ts | 19 ------------------- assembly/types/UiPanel.ts | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 19 deletions(-) delete mode 100644 assembly/types/UiPanel.d.ts create mode 100644 assembly/types/UiPanel.ts diff --git a/assembly/types/UiPanel.d.ts b/assembly/types/UiPanel.d.ts deleted file mode 100644 index bc8efaa..0000000 --- a/assembly/types/UiPanel.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -@unmanaged declare class UiPanel { - @external("", "UiPanel_getWidth") - getWidth(): f32 - - @external("", "UiPanel_getHeight") - getHeight(): f32 - - @external("", "UiPanel_setSize") - setSize(width: f32, height: f32): void - - @external("", "UiPanel_setColor") - setColor(r: f32, g: f32, b: f32, a: f32): void - - @external("", "UiPanel_drawTriangle") - drawTriangle(x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, r: f32, g: f32, b: f32, a: f32): void -} - -export default UiPanel; - diff --git a/assembly/types/UiPanel.ts b/assembly/types/UiPanel.ts new file mode 100644 index 0000000..870176d --- /dev/null +++ b/assembly/types/UiPanel.ts @@ -0,0 +1,36 @@ +declare function UiPanel_getWidth(self: UiPanel): f32 +declare function UiPanel_getHeight(self: UiPanel): f32 +declare function UiPanel_setSize(self: UiPanel, width: f32, height: f32): void +declare function UiPanel_setColor(self: UiPanel, r: f32, g: f32, b: f32, a: f32): void +declare function UiPanel_drawTriangle(self: UiPanel, x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, r: f32, g: f32, b: f32, a: f32): void + +@unmanaged class UiPanel { + getWidth(): f32 { + return UiPanel_getWidth(this); + } + + getHeight(): f32 { + return UiPanel_getHeight(this); + } + + setSize(width: f32, height: f32): void { + UiPanel_setSize(this, width, height); + } + + setColor(r: f32, g: f32, b: f32, a: f32): void { + UiPanel_setColor(this, r, g, b, a); + } + + drawTriangle(x1: f64, y1: f64, + x2: f64, y2: f64, + x3: f64, y3: f64, + r: f64, g: f64, b: f64, a: f64): void { + UiPanel_drawTriangle(this, x1 as f32, y1 as f32, + x2 as f32, y2 as f32, + x3 as f32, y3 as f32, + r as f32, g as f32, b as f32, a as f32); + } +} + +export default UiPanel; + From 7011e479b97bd01821ea73fb3b9b4710b57543a4 Mon Sep 17 00:00:00 2001 From: marceline-cramer Date: Tue, 22 Jun 2021 10:05:41 -0600 Subject: [PATCH 07/14] Remove Console --- assembly/index.ts | 12 ----- assembly/menus/Console.ts | 102 -------------------------------------- 2 files changed, 114 deletions(-) delete mode 100644 assembly/menus/Console.ts diff --git a/assembly/index.ts b/assembly/index.ts index 5ea426a..6182457 100644 --- a/assembly/index.ts +++ b/assembly/index.ts @@ -7,7 +7,6 @@ import Label from "./elements/Label"; import Container from "./types/Container"; import RoundButton from "./elements/RoundButton"; import Theme from "./types/Theme"; -import Console from "./menus/Console"; import UiPanel from "./types/UiPanel"; import MenuList from "./menus/MenuList"; @@ -16,14 +15,12 @@ let main_panel: PanelImpl; export class PanelImpl extends Element { menu_list: MenuList; - console: Console; is_showing_menu: bool constructor(panel: UiPanel) { super(panel); this.menu_list = new MenuList(panel); - this.console = new Console(panel); panel.setColor(0, 0, 0, 0); // this.elements = new Container(panel); @@ -75,15 +72,10 @@ export class PanelImpl extends Element { } } - handleMessage(message: string): void { - this.console.print(message); - } - update(dt: f64): void { this.mouse_down_time += dt; // this.elements.update(dt); this.menu_list.update(dt); - this.console.update(dt); // this.drawCircleOutline(-0.25, 0, 0.115, 0.003, this.primary); // this.drawCircle(-0.25, 0, 0.1, this.primary); @@ -95,7 +87,3 @@ export class PanelImpl extends Element { // this.panel.drawTriangle(-0.38, 0, -0.44, 0.035, -0.44, -0.035, this.white.r, this.white.g, this.white.b, this.white.a); } } - -export function handleMessage(message: string): void { - main_panel.handleMessage(message); -} diff --git a/assembly/menus/Console.ts b/assembly/menus/Console.ts deleted file mode 100644 index 1d3e6b8..0000000 --- a/assembly/menus/Console.ts +++ /dev/null @@ -1,102 +0,0 @@ -import GlyphStyle from "../../codegen/ui/GlyphStyle"; -import DynamicElement from "../types/DynamicElement"; -import UiPanel from "../types/UiPanel"; - -class QueuedMessage implements DynamicElement { - lifespan: f64 = 5.0; - fade_duration: f64 = 0.25; - - max_height: f64 = 0.05; - height: f64 = this.max_height; - - constructor(public text: string, public style: GlyphStyle, public offset_x: f64, offset_y: f64) { - this.style.setColor(1.0, 1.0, 1.0, 1.0); - this.style.setText(this.text); - this.setOffset(offset_y); - } - - update(dt: f64): bool { - this.lifespan -= dt; - - if (this.lifespan < this.fade_duration) { - let alpha: f64 = this.lifespan / this.fade_duration; - this.style.setColor(1.0, 1.0, 1.0, alpha); - this.height = this.lifespan * this.max_height / this.fade_duration; - } - - return this.lifespan > 0.0; - } - - onSelect(x: f64, y: f64): bool { - return false; - } - - isInBounds(x: f64, y: f64): bool { - return false; - } - - setOffset(offset_y: f64): void { - this.style.setOffset(this.offset_x, offset_y); - } - - animateIn(): void { - //TODO - } -} - -export default class Console { - style_pool: Array = []; - log_bottom: f64 = -0.45; - last_message: f64 = 0.0; - elements: Array = []; - - constructor(public panel: UiPanel) {} - - update(dt: f64): bool { - this.last_message -= dt; - this.log_bottom = -0.45; - - let i: i32 = 0; - - while (i < this.elements.length) { - let message = this.elements[i]; - - if (message.update(dt)) { - this.log_bottom += message.height; - message.setOffset(this.log_bottom); - i++; - } else { - message.style.setText(""); - this.style_pool.push(message.style); - this.elements.splice(i, 1); - } - } - - return i > 0; - } - - print(message: string): void { - let style: GlyphStyle; - - if (this.style_pool.length > 0) { - style = this.style_pool.pop(); - } else { - style = this.panel.createGlyphStyle(); - } - - let offset_x = -0.45 * this.panel.getWidth(); - - let new_message = new QueuedMessage(message, style, offset_x, this.log_bottom); - this.elements.push(new_message); - this.log_bottom += new_message.height; - - this.last_message += 0.5; - if (this.last_message > 0.0) { - if (this.last_message > 5.0) { - this.last_message = 5.0; - } - - new_message.lifespan += this.last_message; - } - } -} From 76e7885074844af7b631262da6af67fb38b468b8 Mon Sep 17 00:00:00 2001 From: marceline-cramer Date: Tue, 22 Jun 2021 10:07:26 -0600 Subject: [PATCH 08/14] Remove codegen symbolic link --- codegen | 1 - 1 file changed, 1 deletion(-) delete mode 120000 codegen diff --git a/codegen b/codegen deleted file mode 120000 index bcbb96e..0000000 --- a/codegen +++ /dev/null @@ -1 +0,0 @@ -/home/mars/Code/mondradiko/builddir/codegen \ No newline at end of file From 2697104d53f424ed3b7c056b8fb0e2fb95760750 Mon Sep 17 00:00:00 2001 From: marceline-cramer Date: Tue, 22 Jun 2021 10:09:11 -0600 Subject: [PATCH 09/14] Remove remaining codegen usage --- assembly/elements/Label.ts | 8 -------- assembly/elements/NotchedBox.ts | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/assembly/elements/Label.ts b/assembly/elements/Label.ts index 715c658..a7dc822 100644 --- a/assembly/elements/Label.ts +++ b/assembly/elements/Label.ts @@ -1,25 +1,17 @@ import Color from "../types/Color"; import Element from "../types/Element"; import DynamicElement from "../types/DynamicElement"; -import GlyphStyle from "../../codegen/ui/GlyphStyle"; import UiPanel from "../types/UiPanel"; export default class Label extends Element implements DynamicElement { w: f64; h: f64; - style: GlyphStyle; - constructor(panel: UiPanel, public text: string, public x: f64, public y: f64, public color: Color) { super(panel); - this.style = panel.createGlyphStyle(); - this.style.setText(text); - this.style.setColor(0.0, 0.0, 0.0, 1.0); - this.style.setOffset(this.x, this.y); - this.w = text.length * 0.0375; this.h = 0.05; diff --git a/assembly/elements/NotchedBox.ts b/assembly/elements/NotchedBox.ts index 9c1a5f0..7f82f67 100644 --- a/assembly/elements/NotchedBox.ts +++ b/assembly/elements/NotchedBox.ts @@ -2,7 +2,7 @@ import Color from "../types/Color"; import Element from "../types/Element"; import DynamicElement from "../types/DynamicElement"; import UiPanel from "../types/UiPanel"; -import Vector2 from "../../codegen/types/Vector2"; +import Vector2 from "../types/Vector2"; export default class NotchedBox extends Element implements DynamicElement { notch1: Vector2 = new Vector2(0.0, 0.0); From 7a18b9f79cdb28ce597fb27d8ddff32af7b9db30 Mon Sep 17 00:00:00 2001 From: marceline-cramer Date: Tue, 22 Jun 2021 10:12:06 -0600 Subject: [PATCH 10/14] Fix API module names --- assembly/types/UiPanel.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/assembly/types/UiPanel.ts b/assembly/types/UiPanel.ts index 870176d..a224a72 100644 --- a/assembly/types/UiPanel.ts +++ b/assembly/types/UiPanel.ts @@ -1,7 +1,16 @@ +@external("", "UiPanel_getWidth") declare function UiPanel_getWidth(self: UiPanel): f32 + +@external("", "UiPanel_getHeight") declare function UiPanel_getHeight(self: UiPanel): f32 + +@external("", "UiPanel_setSize") declare function UiPanel_setSize(self: UiPanel, width: f32, height: f32): void + +@external("", "UiPanel_setColor") declare function UiPanel_setColor(self: UiPanel, r: f32, g: f32, b: f32, a: f32): void + +@external("", "UiPanel_drawTriangle") declare function UiPanel_drawTriangle(self: UiPanel, x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, r: f32, g: f32, b: f32, a: f32): void @unmanaged class UiPanel { From 90eeab6c4f36fa1cdac1698a1d5f3bbaf0abccd3 Mon Sep 17 00:00:00 2001 From: marceline-cramer Date: Tue, 22 Jun 2021 10:13:05 -0600 Subject: [PATCH 11/14] Add bind_panel --- assembly/index.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/assembly/index.ts b/assembly/index.ts index 6182457..3cc9916 100644 --- a/assembly/index.ts +++ b/assembly/index.ts @@ -87,3 +87,7 @@ export class PanelImpl extends Element { // this.panel.drawTriangle(-0.38, 0, -0.44, 0.035, -0.44, -0.035, this.white.r, this.white.g, this.white.b, this.white.a); } } + +export function bind_panel(panel: UiPanel): PanelImpl { + return new PanelImpl(panel); +} From 72220b1100d2f60cbe1f3d0b618673e0d3504501 Mon Sep 17 00:00:00 2001 From: marceline-cramer Date: Thu, 24 Jun 2021 02:20:27 -0600 Subject: [PATCH 12/14] Add update callback and fix binding --- assembly/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/assembly/index.ts b/assembly/index.ts index 3cc9916..e7cb18c 100644 --- a/assembly/index.ts +++ b/assembly/index.ts @@ -21,6 +21,7 @@ export class PanelImpl extends Element { super(panel); this.menu_list = new MenuList(panel); + this.menu_list.show(); panel.setColor(0, 0, 0, 0); // this.elements = new Container(panel); @@ -89,5 +90,10 @@ export class PanelImpl extends Element { } export function bind_panel(panel: UiPanel): PanelImpl { - return new PanelImpl(panel); + main_panel = new PanelImpl(panel); + return main_panel; +} + +export function update(dt: f32): void { + main_panel.update(dt as f32); } From 8bf6c8ec460fa5816995ee4f8918242d20fe7f23 Mon Sep 17 00:00:00 2001 From: marceline-cramer Date: Sun, 27 Jun 2021 00:18:08 -0600 Subject: [PATCH 13/14] Add exported input callbacks --- assembly/index.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/assembly/index.ts b/assembly/index.ts index e7cb18c..bf45bb5 100644 --- a/assembly/index.ts +++ b/assembly/index.ts @@ -97,3 +97,19 @@ export function bind_panel(panel: UiPanel): PanelImpl { export function update(dt: f32): void { main_panel.update(dt as f32); } + +export function on_hover(self: PanelImpl, x: f32, y: f32): void { + self.onHover(x, y); +} + +export function on_select(self: PanelImpl, x: f32, y: f32): void { + self.onSelect(x, y); +} + +export function on_drag(self: PanelImpl, x: f32, y: f32): void { + self.onDrag(x, y); +} + +export function on_deselect(self: PanelImpl, x: f32, y: f32): void { + self.onDeselect(x, y); +} From 4b553a3ef34033884728068d9e1c7df988edcde6 Mon Sep 17 00:00:00 2001 From: Turtle1331 Date: Fri, 2 Jul 2021 03:43:38 -0700 Subject: [PATCH 14/14] Fix findNearestButton() behavior on no buttons --- assembly/menus/PlayerMenu.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/assembly/menus/PlayerMenu.ts b/assembly/menus/PlayerMenu.ts index e1bfcb2..afe415b 100644 --- a/assembly/menus/PlayerMenu.ts +++ b/assembly/menus/PlayerMenu.ts @@ -92,9 +92,12 @@ export default class PlayerMenu extends Element implements DynamicElement { btn.setVisualStatus(2); } this.scroll_velocity /= 1.02; - if (Math.abs(this.scroll_velocity) < 0.0003 || Math.abs(this.findNearestButton().y - this.notch_y) > this.space * 2) { - this.selectClosest(); - this.scroll_velocity = 0; + let closest = this.findNearestButton(); + if (closest != null) { + if (Math.abs(this.scroll_velocity) < 0.0003 || Math.abs(closest.y - this.notch_y) > this.space * 2) { + this.selectClosest(); + this.scroll_velocity = 0; + } } } @@ -209,6 +212,7 @@ export default class PlayerMenu extends Element implements DynamicElement { } this.wrapAroundBoxes(); let closest = this.findNearestButton(); + if (closest == null) return; for (let i = 0; i < this.boxes.elements.length; i++) { let btn = this.boxes.elements[i]; if (btn == closest) { @@ -230,6 +234,7 @@ export default class PlayerMenu extends Element implements DynamicElement { selectClosest(): void { let closest = this.findNearestButton(); + if (closest == null) return; let delta = closest.y - this.notch_y + this.space / 2; for (let i = 0; i < this.boxes.elements.length; i++) { let btn = this.boxes.elements[i]; @@ -245,8 +250,8 @@ export default class PlayerMenu extends Element implements DynamicElement { } } - findNearestButton(): BoxButton { - let closest: BoxButton = this.boxes.elements[0]; + findNearestButton(): BoxButton | null { + let closest: BoxButton | null = null; let closest_distance: f64 = -1; for (let i = 0; i < this.boxes.elements.length; i++) { let btn = this.boxes.elements[i];