New "Karte" tab: a tiled zoom/pan map of the game world with a category sidebar (groups, per-category marker counts, show all / hide all, search) and marker popups, plus tactic layers drawn on top of it. Markers are placed by clicking the map (map.manage) and live in freely editable two-level categories, each with its own emoji and colour. A tactic (map.tactics) is a separate drawing layer that can be toggled on and off: rally points, dashed routes, areas and text notes in any colour, finished by double click, an explicit button or Enter, removed by clicking them. Coordinates are stored as a fraction of the map's width/height rather than in pixels, so re-tiling the map at a different resolution never moves anything. The map data lives entirely in the website database - the Discord bot is not involved. tools/make_map_tiles.php slices a high-resolution image into the zoom pyramid locally; the resulting folder is uploaded by FTP and picked up automatically, one region per folder. Leaflet 1.9.4 is vendored under assets/vendor/ so there is still no CDN and no build step. New permissions map.view / map.manage / map.tactics and four new tables - existing installs have to add both once (see README). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
356 lines
20 KiB
PHP
356 lines
20 KiB
PHP
<?php
|
||
require_once __DIR__ . '/includes/bootstrap.php';
|
||
require_once __DIR__ . '/includes/map.php';
|
||
require_permission('map.view');
|
||
|
||
$canManageMap = user_has_permission('map.manage');
|
||
$canEditTactics = user_has_permission('map.tactics');
|
||
|
||
$maps = map_available();
|
||
$mapKey = (string) ($_GET['map'] ?? '');
|
||
if ($mapKey === '' || !isset($maps[$mapKey])) {
|
||
$mapKey = (string) array_key_first($maps);
|
||
}
|
||
|
||
$manifest = $maps[$mapKey] ?? null;
|
||
$categoryTree = $manifest ? map_category_tree($mapKey) : [];
|
||
$markers = $manifest ? map_markers($mapKey) : [];
|
||
$tactics = $manifest ? map_tactics($mapKey) : [];
|
||
|
||
// Flache Kategorienliste fuer die Auswahlfelder im Marker-Formular.
|
||
$flatCategories = [];
|
||
foreach ($categoryTree as $group) {
|
||
foreach ($group['children'] as $child) {
|
||
$flatCategories[] = [
|
||
'id' => (int) $child['id'],
|
||
'name' => (string) $child['name'],
|
||
'group' => (string) $group['name'],
|
||
'icon' => (string) $child['icon'],
|
||
'color' => (string) $child['color'],
|
||
];
|
||
}
|
||
}
|
||
|
||
$totalMarkers = count($markers);
|
||
|
||
$pageTitle = 'Karte';
|
||
$containerWide = true;
|
||
include __DIR__ . '/includes/header.php';
|
||
?>
|
||
<?php if (!$manifest): ?>
|
||
<div class="panel">
|
||
<h1>Taktikkarte</h1>
|
||
<p class="text-muted">
|
||
Es ist noch keine Karte hinterlegt. Die Karte wird als Kachel-Pyramide ausgeliefert
|
||
(mehrere Zoomstufen), damit sie auch nah herangezoomt scharf bleibt.
|
||
</p>
|
||
<h2>Karte einrichten</h2>
|
||
<ol class="map-setup-steps">
|
||
<li>Ein möglichst hoch aufgelöstes Bild der Region besorgen (z.B. ein eigener Screenshot der Ingame-Karte).</li>
|
||
<li>Lokal einmal das Kachel-Script laufen lassen:<br>
|
||
<code>php tools/make_map_tiles.php verteron "C:\Pfad\zu\verteron.png" --name="Verteron"</code></li>
|
||
<li>Den erzeugten Ordner <code>assets/uploads/maps/verteron/</code> per FTP hochladen.</li>
|
||
</ol>
|
||
<p class="text-muted">
|
||
Danach erscheint die Karte hier automatisch - mehrere Regionen nebeneinander funktionieren
|
||
genauso, jeder Unterordner mit einer <code>tiles.json</code> wird zu einer eigenen Karte.
|
||
</p>
|
||
</div>
|
||
<?php else: ?>
|
||
<div class="map-page"
|
||
data-map-key="<?= e($mapKey) ?>"
|
||
data-can-manage="<?= $canManageMap ? '1' : '0' ?>"
|
||
data-can-tactics="<?= $canEditTactics ? '1' : '0' ?>">
|
||
|
||
<div class="map-sidebar">
|
||
<div class="map-sidebar-head">
|
||
<?php if (count($maps) > 1): ?>
|
||
<select class="map-select" id="map-select">
|
||
<?php foreach ($maps as $key => $available): ?>
|
||
<option value="<?= e($key) ?>" <?= $key === $mapKey ? 'selected' : '' ?>><?= e((string) $available['name']) ?></option>
|
||
<?php endforeach; ?>
|
||
</select>
|
||
<?php else: ?>
|
||
<h1><?= e((string) $manifest['name']) ?></h1>
|
||
<?php endif; ?>
|
||
<input type="text" id="map-search" placeholder="Suchen …" autocomplete="off">
|
||
<div class="map-bulk-actions">
|
||
<button type="button" class="button-secondary" id="map-show-all">Alle einblenden</button>
|
||
<button type="button" class="button-secondary" id="map-hide-all">Alle ausblenden</button>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="map-tabs">
|
||
<button type="button" class="map-tab active" data-panel="markers">Marker <span class="map-tab-count"><?= $totalMarkers ?></span></button>
|
||
<button type="button" class="map-tab" data-panel="tactics">Taktiken <span class="map-tab-count"><?= count($tactics) ?></span></button>
|
||
</div>
|
||
|
||
<div class="map-panel" data-panel="markers">
|
||
<?php if (empty($categoryTree)): ?>
|
||
<div class="map-empty">
|
||
<p class="text-muted">Noch keine Kategorien angelegt.</p>
|
||
<?php if ($canManageMap): ?>
|
||
<button type="button" class="button-success" id="map-seed-categories">Standard-Kategorien anlegen</button>
|
||
<p class="text-muted map-hint">Legt eine Gliederung nach Orten, Ressourcen, NPCs, Quests und Monstern an, die ihr danach frei anpassen könnt.</p>
|
||
<?php endif; ?>
|
||
</div>
|
||
<?php else: ?>
|
||
<div class="map-category-tree" id="map-category-tree">
|
||
<?php foreach ($categoryTree as $group): ?>
|
||
<div class="map-group" data-group-id="<?= (int) $group['id'] ?>">
|
||
<div class="map-group-head">
|
||
<button type="button" class="map-group-toggle" aria-expanded="true">
|
||
<?= icon('chevron-down') ?>
|
||
</button>
|
||
<label class="map-group-label">
|
||
<input type="checkbox" class="map-group-checkbox" checked>
|
||
<span class="map-group-icon"><?= e((string) $group['icon']) ?></span>
|
||
<span class="map-group-name"><?= e((string) $group['name']) ?></span>
|
||
</label>
|
||
<span class="map-count"><?= (int) $group['total_count'] ?></span>
|
||
<?php if ($canManageMap && (int) $group['id'] > 0): ?>
|
||
<button type="button" class="icon-button map-category-edit"
|
||
data-category-id="<?= (int) $group['id'] ?>"
|
||
data-parent-id="0"
|
||
data-name="<?= e((string) $group['name']) ?>"
|
||
data-icon="<?= e((string) $group['icon']) ?>"
|
||
data-color="<?= e((string) $group['color']) ?>"
|
||
title="Gruppe bearbeiten"><?= icon('edit') ?></button>
|
||
<?php endif; ?>
|
||
</div>
|
||
<div class="map-group-children">
|
||
<?php foreach ($group['children'] as $child): ?>
|
||
<div class="map-category" data-category-id="<?= (int) $child['id'] ?>" data-name="<?= e((string) $child['name']) ?>">
|
||
<label class="map-category-label">
|
||
<input type="checkbox" class="map-category-checkbox" value="<?= (int) $child['id'] ?>" checked>
|
||
<span class="map-category-icon" style="background: <?= e((string) $child['color']) ?>;"><?= e((string) $child['icon']) ?></span>
|
||
<span class="map-category-name"><?= e((string) $child['name']) ?></span>
|
||
</label>
|
||
<span class="map-count"><?= (int) $child['marker_count'] ?></span>
|
||
<?php if ($canManageMap): ?>
|
||
<button type="button" class="icon-button map-category-edit"
|
||
data-category-id="<?= (int) $child['id'] ?>"
|
||
data-parent-id="<?= (int) $group['id'] ?>"
|
||
data-name="<?= e((string) $child['name']) ?>"
|
||
data-icon="<?= e((string) $child['icon']) ?>"
|
||
data-color="<?= e((string) $child['color']) ?>"
|
||
title="Kategorie bearbeiten"><?= icon('edit') ?></button>
|
||
<?php endif; ?>
|
||
</div>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
</div>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
<?php if ($canManageMap): ?>
|
||
<button type="button" class="button-secondary map-add-category" id="map-add-category">+ Kategorie</button>
|
||
<?php endif; ?>
|
||
<?php endif; ?>
|
||
</div>
|
||
|
||
<div class="map-panel" data-panel="tactics" hidden>
|
||
<?php if (empty($tactics)): ?>
|
||
<p class="text-muted" id="map-tactics-empty">Noch keine Taktiken angelegt.</p>
|
||
<?php endif; ?>
|
||
<div class="map-tactic-list" id="map-tactic-list">
|
||
<?php foreach ($tactics as $tactic): ?>
|
||
<div class="map-tactic" data-tactic-id="<?= (int) $tactic['id'] ?>">
|
||
<label class="map-tactic-label">
|
||
<input type="checkbox" class="map-tactic-checkbox" value="<?= (int) $tactic['id'] ?>">
|
||
<span class="map-tactic-name"><?= e($tactic['name']) ?></span>
|
||
</label>
|
||
<span class="map-count"><?= count($tactic['shapes']) ?></span>
|
||
<?php if ($canEditTactics): ?>
|
||
<button type="button" class="icon-button map-tactic-edit" title="Taktik bearbeiten"><?= icon('edit') ?></button>
|
||
<?php endif; ?>
|
||
</div>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
<?php if ($canEditTactics): ?>
|
||
<button type="button" class="button-secondary map-add-tactic" id="map-add-tactic">+ Neue Taktik</button>
|
||
<?php endif; ?>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="map-stage">
|
||
<div class="map-toolbar">
|
||
<?php if ($canManageMap): ?>
|
||
<button type="button" class="map-tool" id="map-tool-marker" title="Marker setzen: Werkzeug aktivieren und auf die Karte klicken">
|
||
<?= icon('map-pin') ?><span>Marker setzen</span>
|
||
</button>
|
||
<?php endif; ?>
|
||
<?php if ($canEditTactics): ?>
|
||
<div class="map-tool-group" id="map-tactic-tools" hidden>
|
||
<span class="map-tool-group-label" id="map-tactic-active-name"></span>
|
||
<button type="button" class="map-tool" data-shape="point" title="Punkt/Sammelpunkt setzen"><?= icon('map-pin') ?><span>Punkt</span></button>
|
||
<button type="button" class="map-tool" data-shape="route" title="Route zeichnen: klicken für Punkte, Doppelklick beendet"><?= icon('route') ?><span>Route</span></button>
|
||
<button type="button" class="map-tool" data-shape="area" title="Fläche zeichnen: klicken für Eckpunkte, Doppelklick beendet"><?= icon('area') ?><span>Fläche</span></button>
|
||
<button type="button" class="map-tool" data-shape="text" title="Textnotiz setzen"><?= icon('edit') ?><span>Notiz</span></button>
|
||
<input type="color" id="map-shape-color" value="#c9a227" title="Farbe für neue Objekte">
|
||
<button type="button" class="map-tool map-tool-finish" id="map-shape-finish" hidden
|
||
title="Route/Fläche abschließen (geht auch per Doppelklick oder Enter)">
|
||
<?= icon('check') ?><span>Abschließen</span>
|
||
</button>
|
||
<button type="button" class="map-tool map-tool-done" id="map-tactic-close" title="Taktik-Bearbeitung beenden"><?= icon('x') ?><span>Fertig</span></button>
|
||
</div>
|
||
<?php endif; ?>
|
||
<div class="map-toolbar-spacer"></div>
|
||
<span class="map-coords" id="map-coords" title="Position des Mauszeigers"></span>
|
||
<button type="button" class="map-tool" id="map-reset-view" title="Ansicht zurücksetzen"><?= icon('restore') ?><span>Ansicht</span></button>
|
||
</div>
|
||
<div id="map-canvas" class="map-canvas"></div>
|
||
<p class="map-status text-muted" id="map-status"></p>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Marker anlegen/bearbeiten -->
|
||
<div class="modal-overlay" id="map-marker-modal" hidden>
|
||
<div class="modal">
|
||
<button type="button" class="modal-close icon-button" title="Schließen"><?= icon('x') ?></button>
|
||
<h2 id="map-marker-modal-title">Marker anlegen</h2>
|
||
<form id="map-marker-form">
|
||
<input type="hidden" name="marker_id" value="">
|
||
<input type="hidden" name="x" value="">
|
||
<input type="hidden" name="y" value="">
|
||
<div>
|
||
<label>Name</label>
|
||
<input type="text" name="name" maxlength="120" placeholder="z. B. Orihalum-Ader">
|
||
</div>
|
||
<div>
|
||
<label>Kategorie</label>
|
||
<select name="category_id">
|
||
<?php
|
||
$lastGroup = null;
|
||
foreach ($flatCategories as $category):
|
||
if ($category['group'] !== $lastGroup):
|
||
if ($lastGroup !== null): ?></optgroup><?php endif; ?>
|
||
<optgroup label="<?= e($category['group']) ?>">
|
||
<?php $lastGroup = $category['group'];
|
||
endif; ?>
|
||
<option value="<?= (int) $category['id'] ?>"><?= e($category['icon'] . ' ' . $category['name']) ?></option>
|
||
<?php endforeach;
|
||
if ($lastGroup !== null): ?></optgroup><?php endif; ?>
|
||
</select>
|
||
</div>
|
||
<div>
|
||
<label>Beschreibung <span class="text-muted">(optional)</span></label>
|
||
<textarea name="description" rows="3" placeholder="z. B. Respawn ca. 5 Min., 3er-Gruppe empfohlen"></textarea>
|
||
</div>
|
||
<div class="actions">
|
||
<button type="submit">Speichern</button>
|
||
<button type="button" class="button-secondary" id="map-marker-cancel">Abbrechen</button>
|
||
<button type="button" class="icon-button icon-button-danger" id="map-marker-delete" title="Marker löschen" hidden><?= icon('trash') ?></button>
|
||
<span class="map-feedback text-muted"></span>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Kategorie anlegen/bearbeiten -->
|
||
<div class="modal-overlay" id="map-category-modal" hidden>
|
||
<div class="modal">
|
||
<button type="button" class="modal-close icon-button" title="Schließen"><?= icon('x') ?></button>
|
||
<h2 id="map-category-modal-title">Kategorie anlegen</h2>
|
||
<form id="map-category-form">
|
||
<input type="hidden" name="category_id" value="">
|
||
<div>
|
||
<label>Gruppe</label>
|
||
<select name="parent_id">
|
||
<option value="0">– Eigene Gruppe (Überschrift) –</option>
|
||
<?php foreach ($categoryTree as $group): ?>
|
||
<?php if ((int) $group['id'] > 0): ?>
|
||
<option value="<?= (int) $group['id'] ?>"><?= e((string) $group['name']) ?></option>
|
||
<?php endif; ?>
|
||
<?php endforeach; ?>
|
||
</select>
|
||
</div>
|
||
<div>
|
||
<label>Name</label>
|
||
<input type="text" name="name" maxlength="80" placeholder="z. B. Orihalum-Erz">
|
||
</div>
|
||
<div class="map-category-form-row">
|
||
<div>
|
||
<label>Symbol</label>
|
||
<input type="text" name="icon" maxlength="4" placeholder="⛏">
|
||
</div>
|
||
<div>
|
||
<label>Farbe</label>
|
||
<input type="color" name="color" value="#c9a227">
|
||
</div>
|
||
</div>
|
||
<div class="actions">
|
||
<button type="submit">Speichern</button>
|
||
<button type="button" class="button-secondary" id="map-category-cancel">Abbrechen</button>
|
||
<button type="button" class="icon-button icon-button-danger" id="map-category-delete" title="Kategorie mitsamt ihren Markern löschen" hidden><?= icon('trash') ?></button>
|
||
<span class="map-feedback text-muted"></span>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Beschriftung fuer ein neu gezeichnetes Taktik-Objekt -->
|
||
<div class="modal-overlay" id="map-shape-modal" hidden>
|
||
<div class="modal">
|
||
<button type="button" class="modal-close icon-button" title="Schließen"><?= icon('x') ?></button>
|
||
<h2 id="map-shape-modal-title">Objekt beschriften</h2>
|
||
<form id="map-shape-form">
|
||
<div>
|
||
<label>Beschriftung <span class="text-muted" id="map-shape-label-hint">(optional)</span></label>
|
||
<input type="text" name="label" maxlength="120" placeholder="z. B. Sammelpunkt">
|
||
</div>
|
||
<div>
|
||
<label>Farbe</label>
|
||
<input type="color" name="color" value="#c9a227">
|
||
</div>
|
||
<div class="actions">
|
||
<button type="submit">Übernehmen</button>
|
||
<button type="button" class="button-secondary" id="map-shape-cancel">Abbrechen</button>
|
||
<span class="map-feedback text-muted"></span>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Taktik anlegen/bearbeiten -->
|
||
<div class="modal-overlay" id="map-tactic-modal" hidden>
|
||
<div class="modal">
|
||
<button type="button" class="modal-close icon-button" title="Schließen"><?= icon('x') ?></button>
|
||
<h2 id="map-tactic-modal-title">Taktik anlegen</h2>
|
||
<form id="map-tactic-form">
|
||
<input type="hidden" name="tactic_id" value="">
|
||
<div>
|
||
<label>Name</label>
|
||
<input type="text" name="name" maxlength="120" placeholder="z. B. Festung Verteron - Angriff Süd">
|
||
</div>
|
||
<div>
|
||
<label>Beschreibung <span class="text-muted">(optional)</span></label>
|
||
<textarea name="description" rows="3" placeholder="Ablauf, Rollenverteilung, Timings …"></textarea>
|
||
</div>
|
||
<div class="actions">
|
||
<button type="submit">Speichern & bearbeiten</button>
|
||
<button type="button" class="button-secondary" id="map-tactic-cancel">Abbrechen</button>
|
||
<button type="button" class="icon-button icon-button-danger" id="map-tactic-delete" title="Taktik löschen" hidden><?= icon('trash') ?></button>
|
||
<span class="map-feedback text-muted"></span>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
|
||
<script id="map-data" type="application/json"><?= json_encode([
|
||
'manifest' => [
|
||
'width' => (int) $manifest['width'],
|
||
'height' => (int) $manifest['height'],
|
||
'tile_size' => (int) ($manifest['tile_size'] ?? 256),
|
||
'min_zoom' => (int) ($manifest['min_zoom'] ?? 0),
|
||
'max_zoom' => (int) ($manifest['max_zoom'] ?? 0),
|
||
'url_template' => (string) $manifest['url_template'],
|
||
'name' => (string) $manifest['name'],
|
||
],
|
||
'categories' => $flatCategories,
|
||
'markers' => $markers,
|
||
'tactics' => $tactics,
|
||
], JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT) ?></script>
|
||
<script src="/assets/vendor/leaflet/leaflet.js"></script>
|
||
<script src="/assets/js/map.js"></script>
|
||
<?php endif; ?>
|
||
<?php include __DIR__ . '/includes/footer.php'; ?>
|