Map: map picker popup with preview images grouped by region, remembers last map

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Maaxxs 2026-09-21 19:54:53 +02:00
parent 1c9634b5d3
commit d74f64cbc0
14 changed files with 266 additions and 74 deletions

View file

@ -19,14 +19,13 @@
<!-- UI Overlay --> <!-- UI Overlay -->
<div id="ui-overlay"> <div id="ui-overlay">
<!-- Title bar with map selector --> <!-- Kartenwahl: Knopf mit aktueller Karte, oeffnet die Auswahl mit Vorschaubildern -->
<header id="title-bar" class="panel"> <header id="title-bar" class="panel">
<h1>Aion 2</h1> <button type="button" id="map-picker-btn" aria-haspopup="dialog" title="Karte wechseln">
<div class="map-selector-container"> <span class="map-picker-label">Karte</span>
<select id="map-select" aria-label="Select map"> <strong id="map-current-name">Lädt …</strong>
<option value="">Loading maps...</option> <span class="map-picker-chevron" aria-hidden="true">▾</span>
</select> </button>
</div>
</header> </header>
<!-- Zoom controls --> <!-- Zoom controls -->
@ -129,6 +128,17 @@
<div class="category"></div> <div class="category"></div>
</div> </div>
<!-- Kartenauswahl mit Vorschaubildern (data/previews, nur die Karte ohne Markierungen) -->
<div id="map-picker" class="hidden" role="dialog" aria-modal="true" aria-labelledby="map-picker-title">
<div class="map-picker-panel panel">
<div class="map-picker-head">
<h2 id="map-picker-title">Karte wählen</h2>
<button type="button" id="map-picker-close" aria-label="Schließen">✕</button>
</div>
<div id="map-picker-list"></div>
</div>
</div>
<!-- Eingabedialog fuer Namen, Beschreibungen und Beschriftungen --> <!-- Eingabedialog fuer Namen, Beschreibungen und Beschriftungen -->
<div id="tactic-dialog" class="hidden"> <div id="tactic-dialog" class="hidden">
<form class="panel" id="td-form"> <form class="panel" id="td-form">

View file

@ -18,6 +18,18 @@ const CONFIG = {
TILES_DIR: 'data/tiles', TILES_DIR: 'data/tiles',
MARKERS_DIR: 'data/markers', MARKERS_DIR: 'data/markers',
ICONS_DIR: 'data/icons', ICONS_DIR: 'data/icons',
// Vorschaubilder der Kartenauswahl - bewusst ausserhalb von data/ (das kommt per FTP),
// damit sie mit dem Code ausgeliefert werden.
PREVIEWS_DIR: 'previews',
DEFAULT_MAP: 'verteron',
// Gebiete der Kartenauswahl in dieser Reihenfolge, Karten darin ebenfalls sortiert.
// Karten, die hier fehlen, landen unter "Weitere".
MAP_ZONES: [
{ name: 'Elysea', maps: ['poeta', 'verteron', 'elthen'] },
{ name: 'Asmodae', maps: ['ishalgen', 'altgard', 'morheim'] },
{ name: 'Abyss', maps: ['abyss-reshanta-a', 'abyss-reshanta-b', 'chaotic-middle-reshanta', 'chaotic-upper-reshanta'] },
],
// Local maps list (generated by download scripts to avoid CORS) // Local maps list (generated by download scripts to avoid CORS)
MAPS_LIST: 'data/maps.json', MAPS_LIST: 'data/maps.json',

View file

@ -10,7 +10,10 @@ class MapController {
// DOM elements // DOM elements
this.canvas = document.getElementById('map-canvas'); this.canvas = document.getElementById('map-canvas');
this.mapSelect = document.getElementById('map-select'); this.mapPicker = document.getElementById('map-picker');
this.mapPickerList = document.getElementById('map-picker-list');
this.mapPickerBtn = document.getElementById('map-picker-btn');
this.mapCurrentName = document.getElementById('map-current-name');
this.categoriesList = document.getElementById('categories-list'); this.categoriesList = document.getElementById('categories-list');
this.zoomLevelEl = document.getElementById('zoom-level'); this.zoomLevelEl = document.getElementById('zoom-level');
this.loadingOverlay = document.getElementById('loading-overlay'); this.loadingOverlay = document.getElementById('loading-overlay');
@ -36,11 +39,17 @@ class MapController {
// Discover available maps // Discover available maps
await this.discoverMaps(); await this.discoverMaps();
// Load first map by default // Zuletzt gewaehlte Karte, sonst die Standardkarte, sonst die erste
if (this.mapData.maps.length > 0) { if (this.mapData.maps.length > 0) {
const firstMap = this.mapData.maps[0]; let saved = null;
this.mapSelect.value = firstMap.slug; try {
await this.loadMap(firstMap.slug); saved = localStorage.getItem('lumina_map');
} catch (e) {
saved = null;
}
const has = slug => this.mapData.maps.some(m => m.slug === slug);
const slug = has(saved) ? saved : (has(CONFIG.DEFAULT_MAP) ? CONFIG.DEFAULT_MAP : this.mapData.maps[0].slug);
await this.loadMap(slug);
} }
} catch (e) { } catch (e) {
console.error('Failed to initialize:', e); console.error('Failed to initialize:', e);
@ -80,36 +89,80 @@ class MapController {
} }
/** /**
* Populate the map selection dropdown * Kartenauswahl aufbauen: pro Gebiet eine Reihe Karten mit Vorschaubild.
*/ */
populateMapSelector() { populateMapSelector() {
const maps = this.mapData.maps; const maps = this.mapData.maps;
this.mapPickerList.textContent = '';
if (maps.length === 0) { if (maps.length === 0) {
this.mapSelect.innerHTML = '<option value="">No maps available</option>'; this.mapCurrentName.textContent = 'Keine Karten';
return; return;
} }
// Group by zone // Nach den Gebieten aus CONFIG.MAP_ZONES ordnen (maps.json kennt keine Gebiete).
let html = '';
const zones = {}; const zones = {};
for (const zone of CONFIG.MAP_ZONES) {
for (const map of maps) { const zoneMaps = zone.maps.map(slug => maps.find(m => m.slug === slug)).filter(Boolean);
if (!zones[map.zone]) { if (zoneMaps.length) zones[zone.name] = zoneMaps;
zones[map.zone] = [];
}
zones[map.zone].push(map);
} }
const assigned = new Set(CONFIG.MAP_ZONES.flatMap(zone => zone.maps));
const rest = maps.filter(m => !assigned.has(m.slug));
if (rest.length) zones['Weitere'] = rest;
for (const [zoneName, zoneMaps] of Object.entries(zones)) { for (const [zoneName, zoneMaps] of Object.entries(zones)) {
html += `<optgroup label="${zoneName}">`; const section = document.createElement('section');
for (const map of zoneMaps) { section.className = 'map-picker-zone';
html += `<option value="${map.slug}">${map.name}</option>`; const heading = document.createElement('h3');
} heading.textContent = zoneName;
html += '</optgroup>'; const grid = document.createElement('div');
} grid.className = 'map-picker-grid';
this.mapSelect.innerHTML = html; for (const map of zoneMaps) {
const card = document.createElement('button');
card.type = 'button';
card.className = 'map-card';
card.dataset.slug = map.slug;
const img = document.createElement('img');
img.src = `${CONFIG.PREVIEWS_DIR}/${map.slug}.webp`;
img.alt = '';
// Nicht lazy: die zehn kleinen Vorschauen (~300 KB) laden gleich mit, damit sie
// beim Oeffnen der Auswahl sofort da sind.
img.decoding = 'async';
img.onerror = () => img.remove();
const name = document.createElement('span');
name.className = 'map-card-name';
name.textContent = map.name;
card.append(img, name);
card.addEventListener('click', () => {
this.closeMapPicker();
if (map.slug !== this.mapData.currentMap?.slug) {
this.loadMap(map.slug);
}
});
grid.appendChild(card);
}
section.append(heading, grid);
this.mapPickerList.appendChild(section);
}
}
openMapPicker() {
this.mapPickerList.querySelectorAll('.map-card').forEach(card => {
card.classList.toggle('active', card.dataset.slug === this.mapData.currentMap?.slug);
});
this.mapPicker.classList.remove('hidden');
const active = this.mapPickerList.querySelector('.map-card.active') || this.mapPickerList.querySelector('.map-card');
if (active) active.focus();
}
closeMapPicker() {
this.mapPicker.classList.add('hidden');
this.mapPickerBtn.focus();
} }
/** /**
@ -123,6 +176,12 @@ class MapController {
const mapInfo = this.mapData.setCurrentMap(slug); const mapInfo = this.mapData.setCurrentMap(slug);
if (!mapInfo) throw new Error(`Map ${slug} not found`); if (!mapInfo) throw new Error(`Map ${slug} not found`);
this.mapCurrentName.textContent = mapInfo.name;
try {
localStorage.setItem('lumina_map', slug);
} catch (e) {
// ohne Speicher eben jedes Mal die Standardkarte
}
// Load tile manifest // Load tile manifest
await this.tileService.loadManifest(slug); await this.tileService.loadManifest(slug);
@ -300,13 +359,18 @@ class MapController {
* Setup all event listeners * Setup all event listeners
*/ */
setupEventListeners() { setupEventListeners() {
// Map selection change // Kartenauswahl: Knopf oeffnet das Popup, Klick daneben / X / Esc schliesst es
this.mapSelect.addEventListener('change', (e) => { this.mapPickerBtn.addEventListener('click', () => this.openMapPicker());
const slug = e.target.value; document.getElementById('map-picker-close').addEventListener('click', () => this.closeMapPicker());
if (slug) { this.mapPicker.addEventListener('click', (e) => {
this.loadMap(slug); if (e.target === this.mapPicker) this.closeMapPicker();
}
}); });
window.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && !this.mapPicker.classList.contains('hidden')) {
e.stopPropagation();
this.closeMapPicker();
}
}, true);
// Alle Kategorien auf einmal ein- bzw. ausblenden // Alle Kategorien auf einmal ein- bzw. ausblenden
document.getElementById('btn-show-all').addEventListener('click', () => this.setAllCategories(true)); document.getElementById('btn-show-all').addEventListener('click', () => this.setAllCategories(true));

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

View file

@ -84,38 +84,154 @@ canvas:active {
backdrop-filter: blur(10px); backdrop-filter: blur(10px);
} }
/* Title bar */ /* Kartenwahl oben mittig: Knopf mit dem Namen der aktuellen Karte */
#title-bar { #title-bar {
position: absolute; position: absolute;
top: 16px; top: 16px;
left: 50%; left: 50%;
transform: translateX(-50%); transform: translateX(-50%);
padding: 12px 24px; padding: 4px;
text-align: center;
} }
#title-bar h1 { #map-picker-btn {
font-size: 24px; display: flex;
align-items: baseline;
gap: 10px;
padding: 9px 16px;
background: transparent;
border: 1px solid transparent;
border-radius: 6px;
}
#map-picker-btn:hover {
background: rgba(255, 215, 0, 0.08);
border-color: rgba(255, 215, 0, 0.4);
}
.map-picker-label {
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
color: var(--text-secondary);
}
#map-current-name {
font-size: 17px;
color: var(--accent-gold); color: var(--accent-gold);
text-shadow: 0 0 10px rgba(255, 215, 0, 0.5); white-space: nowrap;
margin-bottom: 8px;
} }
.map-selector-container select { .map-picker-chevron {
background: rgba(30, 30, 60, 0.9); color: var(--text-secondary);
border: 1px solid var(--border-color); font-size: 13px;
color: var(--text-primary); }
padding: 8px 12px;
border-radius: 4px; /* Popup mit Vorschaubildern der Karten */
#map-picker {
position: absolute;
inset: 0;
z-index: 2500;
display: flex;
align-items: center;
justify-content: center;
padding: 24px;
background: rgba(0, 0, 0, 0.6);
backdrop-filter: blur(4px);
animation: map-picker-fade 0.2s ease;
}
.map-picker-panel {
width: min(960px, 100%);
max-height: 100%;
display: flex;
flex-direction: column;
padding: 18px 20px 20px;
border-color: rgba(255, 215, 0, 0.35);
box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}
.map-picker-head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
}
.map-picker-head h2 {
font-size: 18px;
color: var(--accent-gold);
}
#map-picker-close {
padding: 4px 10px;
font-size: 14px; font-size: 14px;
min-width: 250px;
cursor: pointer;
} }
.map-selector-container select:hover { #map-picker-list {
border-color: var(--accent-gold); overflow-y: auto;
min-height: 0;
padding-right: 4px;
} }
.map-picker-zone + .map-picker-zone { margin-top: 16px; }
.map-picker-zone h3 {
margin-bottom: 8px;
font-size: 12px;
letter-spacing: 0.08em;
text-transform: uppercase;
color: var(--text-secondary);
}
.map-picker-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
gap: 12px;
}
.map-card {
display: flex;
flex-direction: column;
padding: 0;
overflow: hidden;
background: rgba(30, 30, 50, 0.9);
border: 2px solid var(--border-color);
border-radius: 10px;
text-align: left;
transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.map-card:hover,
.map-card:focus-visible {
transform: translateY(-3px);
border-color: var(--accent-gold);
box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
outline: none;
}
.map-card.active {
border-color: var(--accent-gold);
box-shadow: 0 0 0 2px rgba(255, 215, 0, 0.25);
}
.map-card img {
display: block;
width: 100%;
aspect-ratio: 1;
object-fit: cover;
background: #e1d2bf;
}
.map-card-name {
padding: 8px 10px;
font-size: 13px;
font-weight: 600;
}
.map-card.active .map-card-name { color: var(--accent-gold); }
@keyframes map-picker-fade { from { opacity: 0; } to { opacity: 1; } }
/* Zoom controls */ /* Zoom controls */
#zoom-controls { #zoom-controls {
position: absolute; position: absolute;
@ -756,14 +872,6 @@ button.tp-item.active {
transform: none; transform: none;
} }
#title-bar h1 {
font-size: 18px;
margin-bottom: 6px;
}
.map-selector-container select {
min-width: 180px;
}
} }
/* Handy: Fenster schmal und kompakt, damit von der Karte etwas uebrig bleibt. */ /* Handy: Fenster schmal und kompakt, damit von der Karte etwas uebrig bleibt. */
@ -772,27 +880,25 @@ button.tp-item.active {
top: 8px; top: 8px;
left: 8px; left: 8px;
right: 64px; right: 64px;
padding: 6px 8px; padding: 2px;
display: flex;
align-items: center;
gap: 8px;
} }
#title-bar h1 { #map-picker-btn {
font-size: 15px; width: 100%;
margin-bottom: 0; padding: 7px 10px;
} }
.map-selector-container { #map-current-name {
flex: 1; flex: 1;
min-width: 0; min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
font-size: 15px;
} }
.map-selector-container select { #map-picker { padding: 10px; }
width: 100%; .map-picker-panel { padding: 14px; }
min-width: 0; .map-picker-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
padding: 6px 8px;
}
#zoom-controls { #zoom-controls {
top: 8px; top: 8px;