Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to Canary #2

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assembly/elements/BoxButton.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
10 changes: 1 addition & 9 deletions assembly/elements/Label.ts
Original file line number Diff line number Diff line change
@@ -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 "../../codegen/ui/UiPanel";
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;

Expand Down
4 changes: 2 additions & 2 deletions assembly/elements/NotchedBox.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Color from "../types/Color";
import Element from "../types/Element";
import DynamicElement from "../types/DynamicElement";
import UiPanel from "../../codegen/ui/UiPanel";
import Vector2 from "../../codegen/types/Vector2";
import UiPanel from "../types/UiPanel";
import Vector2 from "../types/Vector2";

export default class NotchedBox extends Element implements DynamicElement {
notch1: Vector2 = new Vector2(0.0, 0.0);
Expand Down
2 changes: 1 addition & 1 deletion assembly/elements/RoundButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
38 changes: 26 additions & 12 deletions assembly/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,21 @@ 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 "../codegen/ui/UiPanel";
import UiPanel from "./types/UiPanel";

import MenuList from "./menus/MenuList";

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);
this.menu_list.show();

panel.setColor(0, 0, 0, 0);
// this.elements = new Container(panel);
Expand Down Expand Up @@ -64,7 +62,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);
Expand All @@ -75,15 +73,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);
Expand All @@ -96,6 +89,27 @@ export class PanelImpl extends Element {
}
}

export function handleMessage(message: string): void {
main_panel.handleMessage(message);
export function bind_panel(panel: UiPanel): PanelImpl {
main_panel = new PanelImpl(panel);
return main_panel;
}

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);
}
2 changes: 1 addition & 1 deletion assembly/menus/BoxList.ts
Original file line number Diff line number Diff line change
@@ -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<BoxButton> {
Expand Down
2 changes: 1 addition & 1 deletion assembly/menus/CharacterInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
102 changes: 0 additions & 102 deletions assembly/menus/Console.ts

This file was deleted.

2 changes: 1 addition & 1 deletion assembly/menus/MenuList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
17 changes: 11 additions & 6 deletions assembly/menus/PlayerMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
}
}
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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];
Expand All @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion assembly/types/Container.ts
Original file line number Diff line number Diff line change
@@ -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<ElementType extends DynamicElement> extends Element implements DynamicElement {
elements: Array<ElementType> = [];
Expand Down
Loading