diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..40ad553c --- /dev/null +++ b/LICENSE @@ -0,0 +1,17 @@ +“Commons Clause” License Condition v1.0 + +The Software is provided to you by the Licensor under the License, as defined below, subject to the following condition. + +Without limiting other conditions in the License, the grant of rights under the License will not include, and the License does not grant to you, the right to Sell the Software. + +For purposes of the foregoing, “Sell” means practicing any or all of the rights granted to you under the License to provide to third parties, for a fee or other consideration (including without limitation fees for hosting or consulting/ support services related to the Software), a product or service whose value derives, entirely or substantially, from the functionality of the Software. Any license notice or attribution required by the License must also include this Commons Clause License Condition notice. + + + +Copyright 2020 Tobias Springer + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, BUT NOT sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/gulp/package.json b/gulp/package.json index 3cb8ae15..9e39962a 100644 --- a/gulp/package.json +++ b/gulp/package.json @@ -110,6 +110,7 @@ "speed-measure-webpack-plugin": "^1.3.1", "strip-json-comments": "^3.0.1", "trim": "^0.0.1", - "webpack-stream": "^5.1.0" + "webpack-stream": "^5.1.0", + "yaml-loader": "^0.6.0" } } diff --git a/gulp/webpack.config.js b/gulp/webpack.config.js index f3bdb601..026ec55e 100644 --- a/gulp/webpack.config.js +++ b/gulp/webpack.config.js @@ -108,6 +108,11 @@ module.exports = ({ watch = false, standalone = false }) => { }, }, }, + { + test: /\.ya?ml$/, + type: "json", // Required by Webpack v4 + use: "yaml-loader", + }, ], }, output: { diff --git a/gulp/webpack.production.config.js b/gulp/webpack.production.config.js index fab5dbeb..27a8370b 100644 --- a/gulp/webpack.production.config.js +++ b/gulp/webpack.production.config.js @@ -269,6 +269,11 @@ module.exports = ({ test: /\.md$/, use: ["html-loader", "markdown-loader"], }, + { + test: /\.ya?ml$/, + type: "json", // Required by Webpack v4 + use: "yaml-loader", + }, ], }, }; diff --git a/gulp/yarn.lock b/gulp/yarn.lock index 702d54b9..093c8d54 100644 --- a/gulp/yarn.lock +++ b/gulp/yarn.lock @@ -14068,6 +14068,19 @@ yallist@^3.0.0, yallist@^3.0.2, yallist@^3.0.3: resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.0.3.tgz#b4b049e314be545e3ce802236d6cd22cd91c3de9" integrity sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A== +yaml-loader@^0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/yaml-loader/-/yaml-loader-0.6.0.tgz#fe1c48b9f4803dace55a59a1474e790ba6ab1b48" + integrity sha512-1bNiLelumURyj+zvVHOv8Y3dpCri0F2S+DCcmps0pA1zWRLjS+FhZQg4o3aUUDYESh73+pKZNI18bj7stpReow== + dependencies: + loader-utils "^1.4.0" + yaml "^1.8.3" + +yaml@^1.8.3: + version "1.10.0" + resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.0.tgz#3b593add944876077d4d683fee01081bd9fff31e" + integrity sha512-yr2icI4glYaNG+KWONODapy2/jDdMSDnrONSjblABjD9B4Z5LgiircSt8m8sRZFNi08kG9Sm0uSHtEmP3zaEGg== + yargs-parser@^13.0.0, yargs-parser@^13.1.0: version "13.1.1" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-13.1.1.tgz#d26058532aa06d365fe091f6a1fc06b2f7e5eca0" diff --git a/res/ui/icons/notification_saved.png b/res/ui/icons/notification_saved.png new file mode 100644 index 00000000..de7096a4 Binary files /dev/null and b/res/ui/icons/notification_saved.png differ diff --git a/res/ui/icons/notification_success.png b/res/ui/icons/notification_success.png new file mode 100644 index 00000000..123619d5 Binary files /dev/null and b/res/ui/icons/notification_success.png differ diff --git a/res/ui/icons/notification_upgrade.png b/res/ui/icons/notification_upgrade.png new file mode 100644 index 00000000..9d98cd90 Binary files /dev/null and b/res/ui/icons/notification_upgrade.png differ diff --git a/res/ui/vignette.lossless.png b/res/ui/vignette.lossless.png index 26f05296..b7bb65ac 100644 Binary files a/res/ui/vignette.lossless.png and b/res/ui/vignette.lossless.png differ diff --git a/src/css/common.scss b/src/css/common.scss index c0a305aa..ee646730 100644 --- a/src/css/common.scss +++ b/src/css/common.scss @@ -87,11 +87,6 @@ body { // } } -// Dirty hack -* { - @include TextShadow3DImpl; -} - img { -webkit-touch-callout: none; /* prevent callout to copy image, etc when tap to hold */ } diff --git a/src/css/icons.scss b/src/css/icons.scss index fa124f67..4e6e779b 100644 --- a/src/css/icons.scss +++ b/src/css/icons.scss @@ -20,3 +20,10 @@ $upgrades: belt, miner, painting, processors; background-image: uiResource("res/ui/upgrades/#{$upgrade}.png") !important; } } + +$icons: notification_saved, notification_success, notification_upgrade; +@each $icon in $icons { + [data-icon="icons/#{$icon}.png"] { + background-image: uiResource("res/ui/icons/#{$icon}.png") !important; + } +} diff --git a/src/css/ingame_hud/notifications.scss b/src/css/ingame_hud/notifications.scss new file mode 100644 index 00000000..36e56e28 --- /dev/null +++ b/src/css/ingame_hud/notifications.scss @@ -0,0 +1,44 @@ +#ingame_HUD_Notifications { + position: absolute; + @include S(bottom, 60px); + @include S(right, 10px); + + .notification { + background: rgba(#333438, 0.8); + @include S(border-radius, 2px); + @include S(margin-top, 3px); + color: #fff; + @include PlainText; + @include S(padding, 7px, 10px); + @include S(width, 200px); + + &[data-icon] { + @include S(background-position-x, 8px); + background-position-y: center; + @include S(padding-left, 35px); + background-repeat: no-repeat; + @include S(background-size, 15px); + } + + transform-origin: 100% 50%; + + @include InlineAnimation(5s ease-in-out) { + 0% { + opacity: 1; + } + + 87% { + opacity: 1; + transform: scale(1); + } + 95% { + transform: scale(1.05); + } + + 100% { + opacity: 0; + transform: scale(0.5); + } + } + } +} diff --git a/src/css/main.scss b/src/css/main.scss index 9b2bbe54..c2668158 100644 --- a/src/css/main.scss +++ b/src/css/main.scss @@ -36,11 +36,13 @@ @import "ingame_hud/vignette_overlay"; @import "ingame_hud/statistics"; @import "ingame_hud/pinned_shapes"; +@import "ingame_hud/notifications"; // Z-Index $elements: ingame_Canvas, ingame_VignetteOverlay, ingame_HUD_building_placer, ingame_HUD_PinnedShapes, - ingame_HUD_buildings_toolbar, ingame_HUD_GameMenu, ingame_HUD_KeybindingOverlay, ingame_HUD_Shop, - ingame_HUD_Statistics, ingame_HUD_BetaOverlay, ingame_HUD_MassSelector, ingame_HUD_UnlockNotification; + ingame_HUD_buildings_toolbar, ingame_HUD_GameMenu, ingame_HUD_KeybindingOverlay, ingame_HUD_Notifications, + ingame_HUD_Shop, ingame_HUD_Statistics, ingame_HUD_BetaOverlay, ingame_HUD_MassSelector, + ingame_HUD_UnlockNotification; $zindex: 100; diff --git a/src/css/mixins.scss b/src/css/mixins.scss index 9881ffea..311c176d 100644 --- a/src/css/mixins.scss +++ b/src/css/mixins.scss @@ -253,38 +253,9 @@ button, } @mixin TextShadow3D($color: rgb(222, 234, 238), $borderColor: #000) { - // @if $borderColor != #000 { - // @include TextShadow3DImpl($color: $color, $borderColor: $borderColor); - // } color: $color; } -@mixin TextShadow3DImpl( - $color: rgb(222, 234, 238), - $scale: 1, - $additionalShadowAlpha: 1, - $borderColor: #222428 -) { - // color: $text3dColor; - - $borderColor: rgba(15, 18, 23, 0.9); - - // $shadowColor: darken($color, 40%); - - $border: 0.07em; - $borderMid: $border * 1.14; - - $drop1: $borderMid + 0.02; - $drop2: $borderMid + 0.06em; - - // text-shadow: #{$border} #{$border} 0 $borderColor, #{-$border} #{$border} 0 $borderColor, #{$border} #{-$border} 0 $borderColor, - // #{-$border} #{-$border} 0 $borderColor, 0 #{$borderMid} 0 $borderColor, 0 #{-$borderMid} 0 $borderColor, - // #{$borderMid} 0 0 $borderColor, #{-$borderMid} 0 0 $borderColor, 0 #{$drop1} 0 $borderColor, #{$borderMid} #{$drop1} 0 $borderColor, - // #{-$borderMid} #{$drop1} 0 $borderColor, 0 #{$drop2} 0 $borderColor, #{$borderMid} #{$drop2} 0 $borderColor, - // #{-$borderMid} #{$drop2} 0 $borderColor, -0.2em 0.13em 0 rgba(#111, 0.25); // 0px 0.07em 0px $shadowColor, - // 0px 0.15em 0.09em rgba(#333539, $additionalShadowAlpha);; -} - // ---------------------------------------- /* Shine animation prefab, useful for buttons etc. Adds a bright shine which moves over the button like a reflection. Performance heavy. */ diff --git a/src/js/game/hud/hud.js b/src/js/game/hud/hud.js index 7f71872a..2dacb3cb 100644 --- a/src/js/game/hud/hud.js +++ b/src/js/game/hud/hud.js @@ -19,6 +19,7 @@ import { HUDStatistics } from "./parts/statistics"; import { MetaBuilding } from "../meta_building"; import { HUDPinnedShapes } from "./parts/pinned_shapes"; import { ShapeDefinition } from "../shape_definition"; +import { HUDNotifications, enumNotificationType } from "./parts/notifications"; export class GameHUD { /** @@ -51,12 +52,15 @@ export class GameHUD { pinnedShapes: new HUDPinnedShapes(this.root), + notifications: new HUDNotifications(this.root), + // betaOverlay: new HUDBetaOverlay(this.root), }; this.signals = { selectedPlacementBuildingChanged: /** @type {TypedSignal<[MetaBuilding|null]>} */ (new Signal()), shapePinRequested: /** @type {TypedSignal<[ShapeDefinition, number]>} */ (new Signal()), + notification: /** @type {TypedSignal<[string, enumNotificationType]>} */ (new Signal()), }; if (!IS_MOBILE) { diff --git a/src/js/game/hud/parts/game_menu.js b/src/js/game/hud/parts/game_menu.js index d00a22e4..0a80af16 100644 --- a/src/js/game/hud/parts/game_menu.js +++ b/src/js/game/hud/parts/game_menu.js @@ -1,6 +1,7 @@ import { BaseHUDPart } from "../base_hud_part"; import { makeDiv, randomInt } from "../../../core/utils"; import { SOUNDS } from "../../../platform/sound"; +import { enumNotificationType } from "./notifications"; export class HUDGameMenu extends BaseHUDPart { initialize() {} @@ -14,6 +15,10 @@ export class HUDGameMenu extends BaseHUDPart { handler: () => this.root.hud.parts.shop.show(), keybinding: "menu_open_shop", badge: () => this.root.hubGoals.getAvailableUpgradeCount(), + notification: /** @type {[string, enumNotificationType]} */ ([ + "A new upgrade is available!", + enumNotificationType.upgrade, + ]), }, { id: "stats", @@ -23,10 +28,16 @@ export class HUDGameMenu extends BaseHUDPart { }, ]; - /** @type {Array<{ badge: function, button: HTMLElement, badgeElement: HTMLElement, lastRenderAmount: number }>} */ + /** @type {Array<{ + * badge: function, + * button: HTMLElement, + * badgeElement: HTMLElement, + * lastRenderAmount: number, + * notification: [string, enumNotificationType] + * }>} */ this.badgesToUpdate = []; - buttons.forEach(({ id, label, handler, keybinding, badge }) => { + buttons.forEach(({ id, label, handler, keybinding, badge, notification }) => { const button = document.createElement("button"); button.setAttribute("data-button-id", id); this.element.appendChild(button); @@ -45,6 +56,7 @@ export class HUDGameMenu extends BaseHUDPart { lastRenderAmount: 0, button, badgeElement, + notification, }); } }); @@ -68,8 +80,9 @@ export class HUDGameMenu extends BaseHUDPart { update() { let playSound = false; + let notifications = new Set(); for (let i = 0; i < this.badgesToUpdate.length; ++i) { - const { badge, button, badgeElement, lastRenderAmount } = this.badgesToUpdate[i]; + const { badge, button, badgeElement, lastRenderAmount, notification } = this.badgesToUpdate[i]; const amount = badge(); if (lastRenderAmount !== amount) { if (amount > 0) { @@ -78,6 +91,9 @@ export class HUDGameMenu extends BaseHUDPart { // Check if the badge increased if (amount > lastRenderAmount) { playSound = true; + if (notification) { + notifications.add(notification); + } } this.badgesToUpdate[i].lastRenderAmount = amount; button.classList.toggle("hasBadge", amount > 0); @@ -87,6 +103,9 @@ export class HUDGameMenu extends BaseHUDPart { if (playSound) { this.root.soundProxy.playUi(SOUNDS.badgeNotification); } + notifications.forEach(([notification, type]) => { + this.root.hud.signals.notification.dispatch(notification, type); + }); } onGameSaved() { diff --git a/src/js/game/hud/parts/mass_selector.js b/src/js/game/hud/parts/mass_selector.js index ed9a8aa7..f54d1e3c 100644 --- a/src/js/game/hud/parts/mass_selector.js +++ b/src/js/game/hud/parts/mass_selector.js @@ -13,13 +13,18 @@ const logger = createLogger("hud/mass_selector"); export class HUDMassSelector extends BaseHUDPart { createElements(parent) { + const removalKeybinding = this.root.gameState.keyActionMapper + .getBinding("confirm_mass_delete") + .getKeyCodeString(); + const abortKeybinding = this.root.gameState.keyActionMapper.getBinding("back").getKeyCodeString(); + this.element = makeDiv( parent, "ingame_HUD_MassSelector", [], ` - Press DEL to remove selected buildings - and ESC to cancel. + Press ${removalKeybinding} to remove selected buildings + and ${abortKeybinding} to cancel. ` ); } diff --git a/src/js/game/hud/parts/notifications.js b/src/js/game/hud/parts/notifications.js new file mode 100644 index 00000000..eee61b8e --- /dev/null +++ b/src/js/game/hud/parts/notifications.js @@ -0,0 +1,52 @@ +import { BaseHUDPart } from "../base_hud_part"; +import { makeDiv } from "../../../core/utils"; + +/** @enum {string} */ +export const enumNotificationType = { + saved: "saved", + upgrade: "upgrade", + success: "success", +}; + +export class HUDNotifications extends BaseHUDPart { + createElements(parent) { + this.element = makeDiv(parent, "ingame_HUD_Notifications", [], ``); + } + + initialize() { + this.root.hud.signals.notification.add(this.onNotification, this); + + /** @type {Array<{ element: HTMLElement, expireAt: number}>} */ + this.notificationElements = []; + + // Automatic notifications + this.root.signals.gameSaved.add(() => + this.onNotification("Your game has been saved.", enumNotificationType.saved) + ); + } + + /** + * @param {string} message + * @param {enumNotificationType} type + */ + onNotification(message, type) { + const element = makeDiv(this.element, null, ["notification", "type-" + type], message); + element.setAttribute("data-icon", "icons/notification_" + type + ".png"); + + this.notificationElements.push({ + element, + expireAt: this.root.time.realtimeNow() + 5, + }); + } + + update() { + const now = this.root.time.realtimeNow(); + for (let i = 0; i < this.notificationElements.length; ++i) { + const handle = this.notificationElements[i]; + if (handle.expireAt <= now) { + handle.element.remove(); + this.notificationElements.splice(i, 1); + } + } + } +} diff --git a/src/js/game/key_action_mapper.js b/src/js/game/key_action_mapper.js index e557f0d8..fdadfb99 100644 --- a/src/js/game/key_action_mapper.js +++ b/src/js/game/key_action_mapper.js @@ -29,7 +29,7 @@ export const defaultKeybindings = { menu_open_shop: { keyCode: key("F") }, menu_open_stats: { keyCode: key("G") }, - confirm_mass_delete: { keyCode: 46 }, // DEL + confirm_mass_delete: { keyCode: key("X") }, // DEL toggle_hud: { keyCode: 113 }, // F2 }, diff --git a/src/js/translations/en.yaml b/src/js/translations/en.yaml new file mode 100644 index 00000000..e69de29b