From 6e529a9d7410f8afb15970f3d801379e62dd1206 Mon Sep 17 00:00:00 2001 From: Aelita4 Date: Tue, 6 Feb 2024 18:19:36 +0100 Subject: [PATCH] Add tooltip to resourcebar --- src/components/ResourceBar.astro | 81 ++++++++++++++++++++++---------- src/lib/lang/en/resourcebar.json | 6 +-- 2 files changed, 59 insertions(+), 28 deletions(-) diff --git a/src/components/ResourceBar.astro b/src/components/ResourceBar.astro index f095923..384b8fd 100644 --- a/src/components/ResourceBar.astro +++ b/src/components/ResourceBar.astro @@ -4,8 +4,10 @@ import { getUserResources } from '../lib/utils/resourceManager'; import { getHighestWeightedLanguage, getLocales } from '../lib/lang/langDriver'; import resourceTypes from '../lib/data/resources.json'; +import format from '../lib/utils/format'; const resourceLang = await getLocales(getHighestWeightedLanguage(Astro.request.headers.get('accept-language')), 'resources'); +const resBarLang = await getLocales(getHighestWeightedLanguage(Astro.request.headers.get('accept-language')), 'resourcebar'); const resources = await getUserResources(new ObjectId(Astro.cookies.get('userid')?.value ?? '')); @@ -23,7 +25,11 @@ for(const key in resources) {
{resourceArray.map(res => -
x.name === res.name)?.type ?? "solid"} style={(resourceTypes.find(x => x.name === res.name)?.type ?? "solid") === "solid" ? "" : "display: none;"}> +
x.name === res.name)?.type ?? "solid"} + data-res-amount={res.amount} + style={(resourceTypes.find(x => x.name === res.name)?.type ?? "solid") === "solid" ? "" : "display: none;"} + >
x.name === res.name)?.icon ?? "#"} alt={res.name} />
@@ -31,6 +37,11 @@ for(const key in resources) {
{resourceLang[`Label_${res.name}`]}
{res.amount}
+
+
{resBarLang['Label_avaliable']} - {res.amount.toString()}
+
{resBarLang['Label_production']} - {'69'}
+
{resBarLang['Label_capacity']} - {'21372137'}
+
)}
@@ -75,6 +86,7 @@ for(const key in resources) { display: flex; flex-direction: row; padding-left: 15px; + position: relative; } .resourcebar-item-icon { @@ -102,36 +114,55 @@ for(const key in resources) { .resourcebar-item-amount { font-size: 1.2em; } + +.resourcebar-item .resourcebar-item-tooltip { + position: absolute; + background-color: gray; + margin-top: 70px; + width: 150%; + border-radius: 10px; + transition: opacity 1s; + opacity: 0; +} + +.resourcebar-item:hover .resourcebar-item-tooltip { + opacity: 1; +}