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));
.stats ~ .achievements {
grid-column: 1;
}
> button,
> .button {
@include PlainText;
@ -38,7 +42,7 @@
@include DarkThemeInvert;
&.achievements {
grid-column: 1;
grid-column: 3;
& {
/* @load-async */
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 {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.
* @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} */
this.root = root;
@ -34,6 +39,8 @@ export class DynamicDomAttach {
this.timeToKeepSeconds = timeToKeepSeconds;
this.lastVisibleTime = 0;
this.prepend = prepend;
// We start attached, so detach the node first
this.attached = true;
this.internalDetach();
@ -55,7 +62,8 @@ export class DynamicDomAttach {
*/
internalAttach() {
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");
this.attached = true;
}

View File

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