Skip to content

Commit

Permalink
Add inventory tab icons
Browse files Browse the repository at this point in the history
  • Loading branch information
alesan99 committed Nov 23, 2023
1 parent e6404e2 commit cee7940
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 16 deletions.
Binary file added website/assets/gui/items.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions website/game/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ function loadGameAssets() {

// MENUS
IMG.menu = new RenderImage("assets/gui/menu.png")
IMG.items = new RenderImage("assets/gui/items.png")
SPRITE.items = new Sprite(IMG.items, 6,1, 30,30, 0,0, 1,1)

// Chicken Customization
HEADOFFSET = [ // Center of chicken head where hat should be placed
Expand Down
12 changes: 6 additions & 6 deletions website/game/menu/customization.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ MENUS["customization"] = new class extends Menu {
this.openTimer = 0

this.buttons = {}
this.buttons["confirm"] = new Button("Confirm", ()=>{closeMenu()}, null, 665,399, 100,32)
this.buttons["close"] = new Button("X", ()=>{closeMenu()}, null, 740,128, 32,32)

// Profile loading from local browser storage (NOT from server)
this.buttons["load"] = new Button("Load", ()=>{
Expand Down Expand Up @@ -41,11 +41,11 @@ MENUS["customization"] = new class extends Menu {
this.tab = "allTab"
this.inventory = []
this.buttons["allTab"] = new Button("All", ()=>{this.filterInventory("all"); this.buttons[this.tab].selected=false; this.tab = "allTab"; this.buttons[this.tab].selected=true}, null, 476,150, 46,34)
this.buttons["headTab"] = new Button("H", ()=>{this.filterInventory("head"); this.buttons[this.tab].selected=false; this.tab = "headTab"; this.buttons[this.tab].selected=true}, null, 522,150, 34,34)
this.buttons["faceTab"] = new Button("F", ()=>{this.filterInventory("face"); this.buttons[this.tab].selected=false; this.tab = "faceTab"; this.buttons[this.tab].selected=true}, null, 522+34*1,150, 34,34)
this.buttons["bodyTab"] = new Button("B", ()=>{this.filterInventory("body"); this.buttons[this.tab].selected=false; this.tab = "bodyTab"; this.buttons[this.tab].selected=true}, null, 522+34*2,150, 34,34)
this.buttons["furnitureTab"] = new Button("FT", ()=>{this.filterInventory("furniture"); this.buttons[this.tab].selected=false; this.tab = "furnitureTab"; this.buttons[this.tab].selected=true}, null, 522+34*3,150, 34,34)
this.buttons["itemTab"] = new Button("I", ()=>{this.filterInventory("item"); this.buttons[this.tab].selected=false; this.tab = "itemTab"; this.buttons[this.tab].selected=true}, null, 522+34*4,150, 34,34)
this.buttons["headTab"] = new Button("H", ()=>{this.filterInventory("head"); this.buttons[this.tab].selected=false; this.tab = "headTab"; this.buttons[this.tab].selected=true}, {icon:IMG.items, iconFrame:SPRITE.items.getFrame(0)}, 522,150, 34,34)
this.buttons["faceTab"] = new Button("F", ()=>{this.filterInventory("face"); this.buttons[this.tab].selected=false; this.tab = "faceTab"; this.buttons[this.tab].selected=true}, {icon:IMG.items, iconFrame:SPRITE.items.getFrame(1)}, 522+34*1,150, 34,34)
this.buttons["bodyTab"] = new Button("B", ()=>{this.filterInventory("body"); this.buttons[this.tab].selected=false; this.tab = "bodyTab"; this.buttons[this.tab].selected=true}, {icon:IMG.items, iconFrame:SPRITE.items.getFrame(2)}, 522+34*2,150, 34,34)
this.buttons["furnitureTab"] = new Button("FT", ()=>{this.filterInventory("furniture"); this.buttons[this.tab].selected=false; this.tab = "furnitureTab"; this.buttons[this.tab].selected=true}, {icon:IMG.items, iconFrame:SPRITE.items.getFrame(3)}, 522+34*3,150, 34,34)
this.buttons["itemTab"] = new Button("I", ()=>{this.filterInventory("item"); this.buttons[this.tab].selected=false; this.tab = "itemTab"; this.buttons[this.tab].selected=true}, {icon:IMG.items, iconFrame:SPRITE.items.getFrame(4)}, 522+34*4,150, 34,34)
this.filterInventory("all")
this.buttons["allTab"].selected = true

Expand Down
18 changes: 14 additions & 4 deletions website/game/menu/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ class Button {
this.label = label;
if (graphic) {
// If specified, render image for button with frames
this.image = graphic.image;
this.frames = graphic.frames;
if (graphic.image) {
this.image = graphic.image;
this.frames = graphic.frames;
}
if (graphic.icon) {
this.icon = graphic.icon;
this.iconFrame = graphic.iconFrame;
}
if (graphic.visible != null) {
this.visible = graphic.visible;
}
Expand Down Expand Up @@ -83,8 +89,12 @@ class Button {
DRAW.rectangle(this.x, this.y, this.w, this.h, "line");
}

// Label
if (this.label) {
if (this.icon) {
// Icon
DRAW.setColor(255,255,255,1)
DRAW.image(this.icon,this.iconFrame, this.x+this.w/2, this.y+this.h/2, 0, 1,1, 0.5,0.5)
} else if (this.label) {
// Label
DRAW.setFont(FONT.guiLabel)
DRAW.setColor(112, 50, 16,1)
DRAW.text(this.label, this.x+this.w/2, this.y+this.h/2+7, "center")
Expand Down
30 changes: 24 additions & 6 deletions website/game/menu/shop.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ MENUS["shop"] = new class extends Menu {
this.openTimer = 0

this.buttons = {}
this.buttons[0] = new Button("X", ()=>{closeMenu()}, null, 740,128, 32,32)
this.buttons["close"] = new Button("X", ()=>{closeMenu()}, null, 740,128, 32,32)

this.name = config.name || ""
this.items = config.items || {} // {category: {itemId: price}}
Expand All @@ -19,11 +19,27 @@ MENUS["shop"] = new class extends Menu {
this.tab = "allTab"
this.inventory = []
this.buttons["allTab"] = new Button("All", ()=>{this.filterInventory("all"); this.buttons[this.tab].selected=false; this.tab = "allTab"; this.buttons[this.tab].selected=true}, null, 265,150, 46,34)
this.buttons["headTab"] = new Button("H", ()=>{this.filterInventory("head"); this.buttons[this.tab].selected=false; this.tab = "headTab"; this.buttons[this.tab].selected=true}, null, 311,150, 34,34)
this.buttons["faceTab"] = new Button("F", ()=>{this.filterInventory("face"); this.buttons[this.tab].selected=false; this.tab = "faceTab"; this.buttons[this.tab].selected=true}, null, 311+34*1,150, 34,34)
this.buttons["bodyTab"] = new Button("B", ()=>{this.filterInventory("body"); this.buttons[this.tab].selected=false; this.tab = "bodyTab"; this.buttons[this.tab].selected=true}, null, 311+34*2,150, 34,34)
this.buttons["furnitureTab"] = new Button("FT", ()=>{this.filterInventory("furniture"); this.buttons[this.tab].selected=false; this.tab = "furnitureTab"; this.buttons[this.tab].selected=true}, null, 311+34*3,150, 34,34)
this.buttons["itemTab"] = new Button("I", ()=>{this.filterInventory("item"); this.buttons[this.tab].selected=false; this.tab = "itemTab"; this.buttons[this.tab].selected=true}, null, 311+34*4,150, 34,34)
let i = 0
if (this.items["head"]) { // Only enable tab if selling items in this category
this.buttons["headTab"] = new Button("H", ()=>{this.filterInventory("head"); this.buttons[this.tab].selected=false; this.tab = "headTab"; this.buttons[this.tab].selected=true}, {icon:IMG.items, iconFrame:SPRITE.items.getFrame(0)}, 311+34*i,150, 34,34)
i++
}
if (this.items["face"]) { // Only enable tab if selling items in this category
this.buttons["faceTab"] = new Button("F", ()=>{this.filterInventory("face"); this.buttons[this.tab].selected=false; this.tab = "faceTab"; this.buttons[this.tab].selected=true}, {icon:IMG.items, iconFrame:SPRITE.items.getFrame(1)}, 311+34*i,150, 34,34)
i++
}
if (this.items["body"]) { // Only enable tab if selling items in this category
this.buttons["bodyTab"] = new Button("B", ()=>{this.filterInventory("body"); this.buttons[this.tab].selected=false; this.tab = "bodyTab"; this.buttons[this.tab].selected=true}, {icon:IMG.items, iconFrame:SPRITE.items.getFrame(2)}, 311+34*i,150, 34,34)
i++
}
if (this.items["furniture"]) { // Only enable tab if selling items in this category
this.buttons["furnitureTab"] = new Button("FT", ()=>{this.filterInventory("furniture"); this.buttons[this.tab].selected=false; this.tab = "furnitureTab"; this.buttons[this.tab].selected=true}, {icon:IMG.items, iconFrame:SPRITE.items.getFrame(3)}, 311+34*i,150, 34,34)
i++
}
if (this.items["item"]) { // Only enable tab if selling items in this category
this.buttons["itemTab"] = new Button("I", ()=>{this.filterInventory("item"); this.buttons[this.tab].selected=false; this.tab = "itemTab"; this.buttons[this.tab].selected=true}, {icon:IMG.items, iconFrame:SPRITE.items.getFrame(4)}, 311+34*i,150, 34,34)
i++
}
this.filterInventory("all")
this.buttons["allTab"].selected = true

Expand Down Expand Up @@ -131,6 +147,8 @@ MENUS["shop"] = new class extends Menu {
DRAW.text(this.selectedItemDescription[i], 553, 242 + i * 20, "left")
}
}
} else {
DRAW.text("Select an item.", 553, 210, "left")
}

// Render all buttons
Expand Down

0 comments on commit cee7940

Please sign in to comment.