From 166ef92970b88830ac21a587c70fa3a34fcc9209 Mon Sep 17 00:00:00 2001
From: Mittanicz <49088589+Mittanicz@users.noreply.github.com>
Date: Mon, 24 Mar 2025 18:34:27 +0100
Subject: [PATCH] Create base components button, modal .. (#331)
Create base components with shared styles, as start of make ui better.
For now shoul look same but underhood new copoments are used.
This should be first PR that handle this and many more comes. I am in
rush due conflict with other ppl, but should work as i tested.
Testing again and look at structure
Main goal i have global css not scope in component die loading times and
size of elements. (Modal due nature of lit and shadow dom is exception,
maybe later find better way).
Documenting the components will happen later as base components
establish their usage.
---
src/client/HelpModal.ts | 736 +++++++-----------
src/client/HostLobbyModal.ts | 736 ++++++------------
src/client/JoinPrivateLobbyModal.ts | 350 ++-------
src/client/Main.ts | 2 +
src/client/SinglePlayerModal.ts | 587 +++++---------
.../components/baseComponents/Button.ts | 35 +
src/client/components/baseComponents/Modal.ts | 93 +++
src/client/index.html | 95 ++-
src/client/styles.css | 562 +++++++++++++
tsconfig.jest.json | 1 +
webpack.config.js | 98 ++-
11 files changed, 1544 insertions(+), 1751 deletions(-)
create mode 100644 src/client/components/baseComponents/Button.ts
create mode 100644 src/client/components/baseComponents/Modal.ts
diff --git a/src/client/HelpModal.ts b/src/client/HelpModal.ts
index 0dec60f7f..e49513845 100644
--- a/src/client/HelpModal.ts
+++ b/src/client/HelpModal.ts
@@ -1,500 +1,290 @@
-import { LitElement, css, html } from "lit";
-import { customElement, state } from "lit/decorators.js";
+import { LitElement, html } from "lit";
+import { customElement, query } from "lit/decorators.js";
import "./components/Difficulties";
import "./components/Maps";
@customElement("help-modal")
export class HelpModal extends LitElement {
- @state() private isModalOpen = false;
-
- // Added #helpModal infront of everything to prevent leaks of css in other elements outside this one
- private styles = css`
- .radial-menu-image {
- width: 211px;
- height: 200px;
- }
-
- #helpModal.modal-overlay {
- display: none;
- position: fixed;
- z-index: 1000;
- left: 0;
- top: 0;
- width: 100%;
- height: 100%;
- background-color: rgba(0, 0, 0, 0.5);
- overflow-y: auto;
- display: flex;
- align-items: center;
- justify-content: center;
- }
-
- #helpModal .modal-content {
- background-color: rgb(35 35 35 / 0.8);
- -webkit-backdrop-filter: blur(12px);
- backdrop-filter: blur(12px);
- color: white;
- padding: 20px;
- border-radius: 8px;
- width: 80%;
- max-width: 1280px;
- max-height: 80vh;
- overflow-y: auto;
- box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
- border: 1px solid rgba(255, 255, 255, 0.2);
- backdrop-filter: blur(8px);
- position: relative;
- }
-
- #helpModal .title {
- font-size: 28px;
- color: #fff;
- font-weight: 600;
- display: flex;
- align-items: center;
- justify-content: center;
- padding: 0 0 0 20px;
- }
-
- #helpModal .close {
- position: sticky;
- top: 0px;
- right: 0px;
- color: #aaa;
- float: right;
- font-size: 28px;
- font-weight: bold;
- cursor: pointer;
- }
-
- #helpModal .close:hover,
- #helpModal .close:focus {
- color: white;
- text-decoration: none;
- cursor: pointer;
- }
-
- #helpModal table {
- border-collapse: collapse;
- }
-
- #helpModal table,
- #helpModal table th,
- #helpModal table td {
- border: 1px solid rgb(255 255 255 / 0.2);
- }
-
- #helpModal table th,
- #helpModal table td {
- padding: 8px 16px;
- }
-
- #helpModal table td:first-of-type {
- text-align: center;
- }
-
- #helpModal .icon {
- background-color: white;
- width: 32px;
- height: 32px;
- }
-
- #helpModal .city-icon {
- -webkit-mask: url(/images/CityIconWhite.svg) no-repeat center / cover;
- mask: url(/images/CityIconWhite.svg) no-repeat center / cover;
- }
-
- #helpModal .defense-post-icon {
- -webkit-mask: url(/images/ShieldIconWhite.svg) no-repeat center / cover;
- mask: url(/images/ShieldIconWhite.svg) no-repeat center / cover;
- }
-
- #helpModal .port-icon {
- -webkit-mask: url(/images/PortIcon.svg) no-repeat center / cover;
- mask: url(/images/PortIcon.svg) no-repeat center / cover;
- }
-
- #helpModal .warship-icon {
- -webkit-mask: url(/images/BattleshipIconWhite.svg) no-repeat center /
- cover;
- mask: url(/images/BattleshipIconWhite.svg) no-repeat center / cover;
- }
-
- #helpModal .missile-silo-icon {
- -webkit-mask: url(/images/MissileSiloIconWhite.svg) no-repeat center /
- cover;
- mask: url(/images/MissileSiloIconWhite.svg) no-repeat center / cover;
- }
-
- #helpModal .sam-launcher-icon {
- -webkit-mask: url(/images/SamLauncherIconWhite.svg) no-repeat center /
- cover;
- mask: url(/images/SamLauncherIconWhite.svg) no-repeat center / cover;
- }
-
- #helpModal .atom-bomb-icon {
- -webkit-mask: url(/images/NukeIconWhite.svg) no-repeat center / cover;
- mask: url(/images/NukeIconWhite.svg) no-repeat center / cover;
- }
-
- #helpModal .hydrogen-bomb-icon {
- -webkit-mask: url(/images/MushroomCloudIconWhite.svg) no-repeat center /
- cover;
- mask: url(/images/MushroomCloudIconWhite.svg) no-repeat center / cover;
- }
-
- #helpModal .mirv-icon {
- -webkit-mask: url(/images/MIRVIcon.svg) no-repeat center / cover;
- mask: url(/images/MIRVIcon.svg) no-repeat center / cover;
- }
-
- #helpModal .target-icon {
- -webkit-mask: url(/images/TargetIcon.svg) no-repeat center / cover;
- mask: url(/images/TargetIcon.svg) no-repeat center / cover;
- }
-
- #helpModal .alliance-icon {
- -webkit-mask: url(/images/AllianceIconWhite.svg) no-repeat center / cover;
- mask: url(/images/AllianceIconWhite.svg) no-repeat center / cover;
- }
-
- #helpModal .emoji-icon {
- -webkit-mask: url(/images/EmojiIconWhite.svg) no-repeat center / cover;
- mask: url(/images/EmojiIconWhite.svg) no-repeat center / cover;
- }
-
- #helpModal .betray-icon {
- -webkit-mask: url(/images/TraitorIconWhite.svg) no-repeat center / cover;
- mask: url(/images/TraitorIconWhite.svg) no-repeat center / cover;
- }
-
- #helpModal .donate-icon {
- -webkit-mask: url(/images/DonateIconWhite.svg) no-repeat center / cover;
- mask: url(/images/DonateIconWhite.svg) no-repeat center / cover;
- }
-
- #helpModal .build-icon {
- -webkit-mask: url(/images/BuildIconWhite.svg) no-repeat center / cover;
- mask: url(/images/BuildIconWhite.svg) no-repeat center / cover;
- }
-
- #helpModal .info-icon {
- -webkit-mask: url(/images/InfoIcon.svg) no-repeat center / cover;
- mask: url(/images/InfoIcon.svg) no-repeat center / cover;
- }
-
- #helpModal .boat-icon {
- -webkit-mask: url(/images/BoatIcon.svg) no-repeat center / cover;
- mask: url(/images/BoatIcon.svg) no-repeat center / cover;
- }
-
- #helpModal .cancel-icon {
- -webkit-mask: url(/images/XIcon.svg) no-repeat center / cover;
- mask: url(/images/XIcon.svg) no-repeat center / cover;
- }
-
- @media screen and (max-width: 768px) {
- #helpModal .modal-content {
- max-height: 90vh;
- max-width: 100vw;
- width: 100%;
- }
- `;
+ @query("o-modal") private modalEl!: HTMLElement & {
+ open: () => void;
+ close: () => void;
+ };
createRenderRoot() {
- // Disable shadow DOM to allow Tailwind classes to work
return this;
}
render() {
return html`
-
-
-
-
- ×
+
+
+
Hotkeys
+
+
+
+
Key
+
Action
+
+
+
+
+
Space
+
Alternate view (terrain/countries)
+
+
+
Shift + left click
+
Attack (when left click is set to open menu)
+
+
+
Ctrl + left click
+
Open build menu
+
+
+
C
+
Center camera on player
+
+
+
Q / E
+
Zoom out/in
+
+
+
W / A / S / D
+
Move camera
+
+
+
1 / 2
+
Decrease/Increase attack ratio
+
+
+
Shift + scroll down / scroll up
+
Decrease/Increase attack ratio
+
+
+
ALT + R
+
Reset graphics
+
+
+
+
+
+
+
Game UI
+
-
Hotkeys
-
-
-
-
Key
-
Action
-
-
-
-
-
Space
-
Alternate view (terrain/countries)
-
-
-
Shift + left click
-
Attack (when left click is set to open menu)
-
-
-
Ctrl + left click
-
Open build menu
-
-
-
C
-
Center camera on player
-
-
-
Q / E
-
Zoom out/in
-
-
-
W / A / S / D
-
Move camera
-
-
-
1 / 2
-
Decrease/Increase attack ratio
-
-
-
Shift + scroll down / scroll up
-
Decrease/Increase attack ratio
-
-
-
ALT + R
-
Reset graphics
-
-
-
+
Leaderboard
+
-
-
-
-
Game UI
-
-
-
Leaderboard
-
-
-
-
Shows the top players of the game and their names, % owned land and gold.
-
-
-
-
-
-
-
-
Control panel
-
-
-
-
The control panel contains the following elements:
-
-
Pop - The amount of units you have, your max population and the rate at which you gain them.
-
Gold - The amount of gold you have and the rate at which you gain it.
-
Troops and Workers - The amount of allocated troops and workers. Troops are used to attack or defend against attacks. Workers are used to generate gold. You can adjust the number of troops and workers using the slider.
-
Attack ratio - The amount of troops that will be used when you attack. You can adjust the attack ratio using the slider.
-
-
-
-
-
-
-
-
-
Options
-
-
-
-
The following elements can be found inside:
-
-
Pause/Unpause the game - Only available in single player mode.
-
Timer - Time passed since the start of the game.
-
Exit button.
-
Settings - Open the settings menu. Inside you can toggle the Alternate View, Dark Mode, Emojis and action on left click.
-
-
-
-
-
-
-
Radial menu
-
-
-
-
-
Right clicking (or touch on mobile) opens the radial menu. From there you can:
-
-
- Open the build menu.
-
- - Open the Info menu.
-
- Send a boat to attack at the selected location (only available if you have access to water).
-
- Close the menu.
-
-
-
-
-
-
-
Info menu
-
-
-
Enemy info panel
-
-
-
-
- Contains information such for the selected player name, gold, troops, and if the player is a traitor. Traitor is a player who betrayed and attacked a player who was in an alliance with them. The icons below represent the following interactions:
-
-
-
- Place a target mark on the player, marking it for all allies, used to coordinate attacks.
-
- Send an alliance request to the player. Allies can share resources and troops, but can't attack each other.
-
- Send an emoji to the player.
-
-
-
-
-
-
-
-
-
Ally info panel
-
-
-
-
- When you ally with a player, the following new icons become available:
-
-
-
- Betray your ally, ending the alliance. You will now have a permanent icon stuck next to your name. Bots are less likely to ally with you and players will think twice before doing so.
-
- Donate some of your troops to your ally. Used when they're low on troops and are being attacked, or when they need that extra power to crush an enemy.
-
-
-
-
-
-
-
-
-
Build menu
-
-
-
-
Name
-
Icon
-
Description
-
-
-
-
-
City
-
-
- Increases your max population. Useful when you can't
- expand your territory or you're about to hit your
- population limit.
-
-
-
-
Defense Post
-
-
- Increases defenses around nearby borders. Attacks from
- enemies are slower and have more casualties.
-
-
-
-
Port
-
-
- Automatically sends trade ships between ports of your
- country and other countries (except if you clicked "stop
- trade" on them or they clicked "stop trade on you"), giving
- gold to both sides. Allows building Battleships. Can only
- be built near water.
-
-
-
-
Warship
-
-
- Patrols in an area, capturing trade ships and destroying
- enemy Warships and Boats. Spawns from the nearest Port and
- patrols the area you first clicked to build it.
-
-
-
-
Missile Silo
-
-
Allows launching missiles.
-
-
-
SAM Launcher
-
-
Has a 75% chance to intercept enemy missiles in it's 100 pixel range.
- The SAM has a 7.5 second cooldown and can not intercept MIRVs.
-
-
-
Atom Bomb
-
-
Small explosive bomb that destroys territory, buildings, ships and boats. Spawns from the nearest Missile Silo and lands in the area you first clicked to build it.
-
-
-
Hydrogen Bomb
-
-
Large explosive bomb. Spawns from the nearest Missile Silo and lands in the area you first clicked to build it.
-
-
-
MIRV
-
-
The most powerful bomb in the game. Splits up into smaller bombs that will cover a huge range of territory. Only damages the player that you first clicked on to build it. Spawns from the nearest Missile Silo and lands in the area you first clicked to build it.
-
-
-
-
-
-
-
-
-
Player icons
-
Examples of some of the ingame icons you will encounter and what they mean:
-
-
-
Crown - This is the number 1 player in the leaderboard
-
-
-
-
-
Crossed swords - Traitor. This player attacked an ally.
-
-
-
-
-
Handshake - Ally. This player is your ally.
-
-
+
Shows the top players of the game and their names, % owned land and gold.
-
-
+
+
+
+
+
+
Control panel
+
+
+
+
The control panel contains the following elements:
+
+
Pop - The amount of units you have, your max population and the rate at which you gain them.
+
Gold - The amount of gold you have and the rate at which you gain it.
+
Troops and Workers - The amount of allocated troops and workers. Troops are used to attack or defend against attacks. Workers are used to generate gold. You can adjust the number of troops and workers using the slider.
+
Attack ratio - The amount of troops that will be used when you attack. You can adjust the attack ratio using the slider.
+
+
+
+
+
+
+
+
+
Options
+
+
+
+
The following elements can be found inside:
+
+
Pause/Unpause the game - Only available in single player mode.
+
Timer - Time passed since the start of the game.
+
Exit button.
+
Settings - Open the settings menu. Inside you can toggle the Alternate View, Dark Mode, Emojis and action on left click.
+
+
+
+
+
+
+
Radial menu
+
+
+
+
+
Right clicking (or touch on mobile) opens the radial menu. From there you can:
+
+
- Open the build menu.
+
+ - Open the Info menu.
+
- Send a boat to attack at the selected location (only available if you have access to water).
+
- Close the menu.
+
+
+
+
+
+
+
+
Info menu
+
+
+
Enemy info panel
+
+
+
+
+ Contains information such for the selected player name, gold, troops, and if the player is a traitor. Traitor is a player who betrayed and attacked a player who was in an alliance with them. The icons below represent the following interactions:
+
+
+
- Place a target mark on the player, marking it for all allies, used to coordinate attacks.
+
- Send an alliance request to the player. Allies can share resources and troops, but can't attack each other.
+
- Send an emoji to the player.
+
+
+
+
+
+
+
+
+
Ally info panel
+
+
+
+
+ When you ally with a player, the following new icons become available:
+
+
+
- Betray your ally, ending the alliance. You will now have a permanent icon stuck next to your name. Bots are less likely to ally with you and players will think twice before doing so.
+
- Donate some of your troops to your ally. Used when they're low on troops and are being attacked, or when they need that extra power to crush an enemy.
+
+
+
+
+
+
+
+
+
Build menu
+
+
+
+
Name
+
Icon
+
Description
+
+
+
+
+
City
+
+
+ Increases your max population. Useful when you can't
+ expand your territory or you're about to hit your
+ population limit.
+
+
+
+
Defense Post
+
+
+ Increases defenses around nearby borders. Attacks from
+ enemies are slower and have more casualties.
+
+
+
+
Port
+
+
+ Automatically sends trade ships between ports of your
+ country and other countries (except if you clicked "stop
+ trade" on them or they clicked "stop trade on you"), giving
+ gold to both sides. Allows building Battleships. Can only
+ be built near water.
+
+
+
+
Warship
+
+
+ Patrols in an area, capturing trade ships and destroying
+ enemy Warships and Boats. Spawns from the nearest Port and
+ patrols the area you first clicked to build it.
+
+
+
+
Missile Silo
+
+
Allows launching missiles.
+
+
+
SAM Launcher
+
+
Has a 75% chance to intercept enemy missiles in it's 100 pixel range.
+ The SAM has a 7.5 second cooldown and can not intercept MIRVs.
+
+
+
Atom Bomb
+
+
Small explosive bomb that destroys territory, buildings, ships and boats. Spawns from the nearest Missile Silo and lands in the area you first clicked to build it.
+
+
+
Hydrogen Bomb
+
+
Large explosive bomb. Spawns from the nearest Missile Silo and lands in the area you first clicked to build it.
+
+
+
MIRV
+
+
The most powerful bomb in the game. Splits up into smaller bombs that will cover a huge range of territory. Only damages the player that you first clicked on to build it. Spawns from the nearest Missile Silo and lands in the area you first clicked to build it.
+
+
+
+
+
+
+
+
+
Player icons
+
Examples of some of the ingame icons you will encounter and what they mean:
+
+
+
Crown - This is the number 1 player in the leaderboard
+
+
+
+
+
Crossed swords - Traitor. This player attacked an ally.