Add start of ship editing

This commit is contained in:
asraelite 2018-03-04 16:49:42 +00:00
parent d85338d9f2
commit b88c0eb358
18 changed files with 288 additions and 100 deletions

View file

@ -8,4 +8,9 @@ export default class GuiButton extends GuiElement {
this.text = text;
this.onclick = onclick;
}
click() {
if (this.options.draw)
this.onclick();
}
}

View file

@ -1,7 +1,8 @@
import {Rect} from './misc.mjs';
const defaultOptions = {
draw: true // Whether the element itself will be rendered.
draw: true, // Whether the element itself will be rendered.
drawChildren: true // Whether children will be rendered.
}
export default class GuiElement extends Rect {
@ -15,9 +16,14 @@ export default class GuiElement extends Rect {
this.options = Object.assign({}, defaultOptions, options);
}
tick() {
tickElement() {
this.tickMouse();
this.children.forEach(c => c.tick());
this.tick();
this.children.forEach(c => c.tickElement());
}
tick() {
}
append(element) {

View file

@ -11,7 +11,7 @@ export function init() {
}
export function tick() {
root.tick();
root.tickElement();
}
export function changeView(view) {

View file

@ -11,10 +11,11 @@ export class Rect {
this.mouseHeld = false;
}
click() {}
tickMouse() {
if (this.mouseHeld == true && !input.mouse.held[0] && this.mouseOver)
if (this.onclick !== null)
this.onclick();
this.click();
if (!this.mouseHeld && input.mouse.pressed[0] && this.mouseOver)
this.mouseHeld = true;
if (!input.mouse.held[0])

View file

@ -5,6 +5,7 @@ import GuiFrame from './frame.mjs';
import GuiImage from './image.mjs';
import GuiButton from './button.mjs';
import * as events from '../game/events.mjs';
import {state} from '../game/index.mjs';
export function root() {
return new GuiFrame(0, 0, canvas.width, canvas.height, {
@ -36,6 +37,14 @@ export function title() {
export function game() {
let shadow = root();
let edit = new GuiButton('Edit rocket', events.editShip, 0, 0, 200);
shadow.append(edit);
edit.posRelative({ x: 0.5, xc: 0.5, y: 1 });
edit.y -= 45;
edit.tick = () => {
edit.options.draw = state.landed && !state.editing;
}
return shadow;
}