mirror of
				https://github.com/tobspr/shapez.io.git
				synced 2025-06-13 13:04:03 +00:00 
			
		
		
		
	Show available upgrade count in toolbar
This commit is contained in:
		
							parent
							
								
									3de5d45ad8
								
							
						
					
					
						commit
						e43a22b56d
					
				| @ -91,5 +91,40 @@ | ||||
|             left: 50%; | ||||
|             transform: translateX(-50%); | ||||
|         } | ||||
| 
 | ||||
|         &:not(.hasBadge) .badge { | ||||
|             display: none; | ||||
|         } | ||||
| 
 | ||||
|         &.hasBadge { | ||||
|             @include InlineAnimation(1s ease-in-out infinite) { | ||||
|                 50% { | ||||
|                     transform: scale(1.04); | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             .badge { | ||||
|                 position: absolute; | ||||
|                 @include S(bottom, -12px); | ||||
|                 left: 50%; | ||||
|                 transform: translateX(-50%); | ||||
| 
 | ||||
|                 background: #333; | ||||
|                 @include PlainText; | ||||
|                 display: flex; | ||||
|                 justify-content: center; | ||||
|                 align-items: center; | ||||
|                 @include S(min-width, 5px); | ||||
|                 @include S(height, 10px); | ||||
|                 @include S(padding, 1px, 3px, 2px); | ||||
|                 @include S(border-radius, 4px); | ||||
|                 border: #{D(1px)} solid #fff; | ||||
|                 @include InlineAnimation(1s ease-in-out infinite) { | ||||
|                     50% { | ||||
|                         transform: translateX(-50%) scale(1.05); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -160,6 +160,19 @@ | ||||
|                     pointer-events: none; | ||||
|                     opacity: 0.3; | ||||
|                 } | ||||
| 
 | ||||
|                 &.buyable { | ||||
|                     @include InlineAnimation(1s ease-in-out infinite) { | ||||
|                         0% { | ||||
|                         } | ||||
| 
 | ||||
|                         50% { | ||||
|                             background-color: lighten($colorGreenBright, 10); | ||||
|                         } | ||||
|                         100% { | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             &.maxLevel { | ||||
|  | ||||
| @ -196,6 +196,20 @@ export class HubGoals extends BasicSerializableObject { | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Returns the number of available upgrades | ||||
|      * @returns {number} | ||||
|      */ | ||||
|     getAvailableUpgradeCount() { | ||||
|         let count = 0; | ||||
|         for (const upgradeId in UPGRADES) { | ||||
|             if (this.canUnlockUpgrade(upgradeId)) { | ||||
|                 ++count; | ||||
|             } | ||||
|         } | ||||
|         return count; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Tries to unlock the given upgrade | ||||
|      * @param {string} upgradeId | ||||
|  | ||||
| @ -1,5 +1,5 @@ | ||||
| import { BaseHUDPart } from "../base_hud_part"; | ||||
| import { makeDiv } from "../../../core/utils"; | ||||
| import { makeDiv, randomInt } from "../../../core/utils"; | ||||
| 
 | ||||
| export class HUDGameMenu extends BaseHUDPart { | ||||
|     initialize() {} | ||||
| @ -12,6 +12,7 @@ export class HUDGameMenu extends BaseHUDPart { | ||||
|                 label: "Upgrades", | ||||
|                 handler: () => this.root.hud.parts.shop.show(), | ||||
|                 keybinding: "menu_open_shop", | ||||
|                 badge: () => this.root.hubGoals.getAvailableUpgradeCount(), | ||||
|             }, | ||||
|             { | ||||
|                 id: "stats", | ||||
| @ -21,7 +22,10 @@ export class HUDGameMenu extends BaseHUDPart { | ||||
|             }, | ||||
|         ]; | ||||
| 
 | ||||
|         buttons.forEach(({ id, label, handler, keybinding }) => { | ||||
|         /** @type {Array<{ badge: function, button: HTMLElement, badgeElement: HTMLElement, lastRenderAmount: number }>} */ | ||||
|         this.badgesToUpdate = []; | ||||
| 
 | ||||
|         buttons.forEach(({ id, label, handler, keybinding, badge }) => { | ||||
|             const button = document.createElement("button"); | ||||
|             button.setAttribute("data-button-id", id); | ||||
|             this.element.appendChild(button); | ||||
| @ -32,6 +36,16 @@ export class HUDGameMenu extends BaseHUDPart { | ||||
|                 binding.add(handler); | ||||
|                 binding.appendLabelToElement(button); | ||||
|             } | ||||
| 
 | ||||
|             if (badge) { | ||||
|                 const badgeElement = makeDiv(button, null, ["badge"]); | ||||
|                 this.badgesToUpdate.push({ | ||||
|                     badge, | ||||
|                     lastRenderAmount: 0, | ||||
|                     button, | ||||
|                     badgeElement, | ||||
|                 }); | ||||
|             } | ||||
|         }); | ||||
| 
 | ||||
|         const menuButtons = makeDiv(this.element, null, ["menuButtons"]); | ||||
| @ -40,4 +54,18 @@ export class HUDGameMenu extends BaseHUDPart { | ||||
|         this.sfxButton = makeDiv(menuButtons, null, ["button", "sfx"]); | ||||
|         this.settingsButton = makeDiv(menuButtons, null, ["button", "settings"]); | ||||
|     } | ||||
| 
 | ||||
|     update() { | ||||
|         for (let i = 0; i < this.badgesToUpdate.length; ++i) { | ||||
|             const { badge, button, badgeElement, lastRenderAmount } = this.badgesToUpdate[i]; | ||||
|             const amount = badge(); | ||||
|             if (lastRenderAmount !== amount) { | ||||
|                 if (amount > 0) { | ||||
|                     badgeElement.innerText = amount; | ||||
|                 } | ||||
|                 this.badgesToUpdate[i].lastRenderAmount = amount; | ||||
|                 button.classList.toggle("hasBadge", amount > 0); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user