Add interaction between edit grid and inventory
This commit is contained in:
parent
469121e18a
commit
986c0479f1
9 changed files with 51 additions and 14 deletions
|
@ -3,6 +3,7 @@ import GuiElement from './element.mjs';
|
|||
import GuiItemButton from './item.mjs';
|
||||
import {state} from '../game/index.mjs';
|
||||
import * as edit from '../game/edit.mjs';
|
||||
import * as inventory from './inventory.mjs';
|
||||
|
||||
export default class GuiEdit extends GuiElement {
|
||||
constructor(x, y, w = 100, h = 30) {
|
||||
|
@ -11,6 +12,7 @@ export default class GuiEdit extends GuiElement {
|
|||
this.tileWidth = 0;
|
||||
this.tileHeight = 0;
|
||||
this.active = false;
|
||||
this.guiInventory = null;
|
||||
}
|
||||
|
||||
updateTiles() {
|
||||
|
@ -71,5 +73,6 @@ export default class GuiEdit extends GuiElement {
|
|||
}
|
||||
|
||||
this.updateTiles();
|
||||
this.guiInventory.updateTiles();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,8 @@ export default class GuiInventory extends GuiElement {
|
|||
|
||||
let el = new GuiItemButton(tile, onclick, ex, ey, ew, eh, {
|
||||
padding: 0.1,
|
||||
selected: selected
|
||||
selected: selected,
|
||||
quantity: tile.quantity
|
||||
});
|
||||
|
||||
this.append(el);
|
||||
|
|
|
@ -2,16 +2,18 @@ import * as gui from './index.mjs';
|
|||
import GuiButton from './button.mjs';
|
||||
|
||||
export default class GuiItemButton extends GuiButton {
|
||||
constructor(tile, onclick, x, y, w = 50, h = 50, { padding, selected } = {
|
||||
padding: 0,
|
||||
selected: false
|
||||
}) {
|
||||
constructor(tile, onclick, x, y, w = 50, h = 50, {
|
||||
padding = 0,
|
||||
selected = false,
|
||||
quantity = 1,
|
||||
} = {}) {
|
||||
super(null, onclick, x, y, w, h);
|
||||
this.module = tile.module;
|
||||
this.image = tile.image;
|
||||
this.type = 'itemButton';
|
||||
this.padding = padding;
|
||||
this.selected = selected;
|
||||
this.quantity = quantity
|
||||
}
|
||||
|
||||
click() {
|
||||
|
|
|
@ -39,6 +39,10 @@ export class Rect {
|
|||
return [this.x, this.y, this.w, this.h];
|
||||
}
|
||||
|
||||
get end() {
|
||||
return [this.x + this.w, this.y + this.h];
|
||||
}
|
||||
|
||||
get center() {
|
||||
return [this.x + this.w / 2, this.y + this.h / 2];
|
||||
}
|
||||
|
|
|
@ -60,5 +60,7 @@ export function game() {
|
|||
inventory.x += 10;
|
||||
inventory.y += 10;
|
||||
|
||||
edit.guiInventory = inventory;
|
||||
|
||||
return shadow;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue