1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00

Fixed achievement ingame empty space

This commit is contained in:
DJ1TJOO 2021-03-13 21:46:04 +01:00
parent db8cd2cd77
commit e5dfa08212
3 changed files with 47 additions and 30 deletions

View File

@ -8,6 +8,10 @@
backdrop-filter: blur(D(1px)); backdrop-filter: blur(D(1px));
.stats ~ .achievements {
grid-column: 1;
}
> button, > button,
> .button { > .button {
@include PlainText; @include PlainText;
@ -38,7 +42,7 @@
@include DarkThemeInvert; @include DarkThemeInvert;
&.achievements { &.achievements {
grid-column: 1; grid-column: 3;
& { & {
/* @load-async */ /* @load-async */
background-image: uiResource("icons/achievements.png"); background-image: uiResource("icons/achievements.png");

View File

@ -18,8 +18,13 @@ export class DynamicDomAttach {
* @param {string=} param2.attachClass If set, attaches a class while the element is visible * @param {string=} param2.attachClass If set, attaches a class while the element is visible
* @param {boolean=} param2.trackHover If set, attaches the 'hovered' class if the cursor is above the element. Useful * @param {boolean=} param2.trackHover If set, attaches the 'hovered' class if the cursor is above the element. Useful
* for fading out the element if its below the cursor for example. * for fading out the element if its below the cursor for example.
* @param {boolean=} param2.prepend If set, adds the element before other childs
*/ */
constructor(root, element, { timeToKeepSeconds = 0, attachClass = null, trackHover = false } = {}) { constructor(
root,
element,
{ timeToKeepSeconds = 0, attachClass = null, trackHover = false, prepend = false } = {}
) {
/** @type {GameRoot} */ /** @type {GameRoot} */
this.root = root; this.root = root;
@ -34,6 +39,8 @@ export class DynamicDomAttach {
this.timeToKeepSeconds = timeToKeepSeconds; this.timeToKeepSeconds = timeToKeepSeconds;
this.lastVisibleTime = 0; this.lastVisibleTime = 0;
this.prepend = prepend;
// We start attached, so detach the node first // We start attached, so detach the node first
this.attached = true; this.attached = true;
this.internalDetach(); this.internalDetach();
@ -55,7 +62,8 @@ export class DynamicDomAttach {
*/ */
internalAttach() { internalAttach() {
if (!this.attached) { if (!this.attached) {
this.parent.appendChild(this.element); if (this.prepend) this.parent.insertBefore(this.element, this.parent.firstChild);
else this.parent.appendChild(this.element);
assert(this.element.parentElement === this.parent, "Invalid parent #1"); assert(this.element.parentElement === this.parent, "Invalid parent #1");
this.attached = true; this.attached = true;
} }

View File

@ -25,6 +25,7 @@ export class HUDGameMenu extends BaseHUDPart {
]), ]),
visible: () => visible: () =>
!this.root.app.settings.getAllSettings().offerHints || this.root.hubGoals.level >= 3, !this.root.app.settings.getAllSettings().offerHints || this.root.hubGoals.level >= 3,
domAttachSettings: {},
}, },
{ {
id: "stats", id: "stats",
@ -33,6 +34,7 @@ export class HUDGameMenu extends BaseHUDPart {
keybinding: KEYMAPPINGS.ingame.menuOpenStats, keybinding: KEYMAPPINGS.ingame.menuOpenStats,
visible: () => visible: () =>
!this.root.app.settings.getAllSettings().offerHints || this.root.hubGoals.level >= 3, !this.root.app.settings.getAllSettings().offerHints || this.root.hubGoals.level >= 3,
domAttachSettings: { prepend: true },
}, },
{ {
id: "achievements", id: "achievements",
@ -40,6 +42,7 @@ export class HUDGameMenu extends BaseHUDPart {
handler: () => this.root.hud.parts.achievements.show(), handler: () => this.root.hud.parts.achievements.show(),
keybinding: KEYMAPPINGS.ingame.menuOpenAchievements, keybinding: KEYMAPPINGS.ingame.menuOpenAchievements,
visible: () => !(this.root.achievementProxy.provider instanceof NoAchievementProvider), visible: () => !(this.root.achievementProxy.provider instanceof NoAchievementProvider),
domAttachSettings: {},
}, },
]; ];
@ -60,37 +63,39 @@ export class HUDGameMenu extends BaseHUDPart {
* }>} */ * }>} */
this.visibilityToUpdate = []; this.visibilityToUpdate = [];
buttons.forEach(({ id, label, handler, keybinding, badge, notification, visible }) => { buttons.forEach(
const button = document.createElement("button"); ({ id, label, handler, keybinding, badge, notification, visible, domAttachSettings }) => {
button.classList.add(id); const button = document.createElement("button");
this.element.appendChild(button); button.classList.add(id);
this.trackClicks(button, handler); this.element.appendChild(button);
this.trackClicks(button, handler);
if (keybinding) { if (keybinding) {
const binding = this.root.keyMapper.getBinding(keybinding); const binding = this.root.keyMapper.getBinding(keybinding);
binding.add(handler); binding.add(handler);
} }
if (visible) { if (visible) {
this.visibilityToUpdate.push({ this.visibilityToUpdate.push({
button, button,
condition: visible, condition: visible,
domAttach: new DynamicDomAttach(this.root, button), domAttach: new DynamicDomAttach(this.root, button, domAttachSettings),
}); });
} }
if (badge) { if (badge) {
const badgeElement = makeDiv(button, null, ["badge"]); const badgeElement = makeDiv(button, null, ["badge"]);
this.badgesToUpdate.push({ this.badgesToUpdate.push({
badge, badge,
lastRenderAmount: 0, lastRenderAmount: 0,
button, button,
badgeElement, badgeElement,
notification, notification,
condition: visible, condition: visible,
}); });
}
} }
}); );
this.saveButton = makeDiv(this.element, null, ["button", "save", "animEven"]); this.saveButton = makeDiv(this.element, null, ["button", "save", "animEven"]);
this.settingsButton = makeDiv(this.element, null, ["button", "settings"]); this.settingsButton = makeDiv(this.element, null, ["button", "settings"]);