home.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. <?php
  2. /**
  3. * Vue de la page d'accueil
  4. */
  5. include __DIR__ . '/partials/header.php';
  6. ?>
  7. <main class="main-content">
  8. <div class="container-fluid">
  9. <div class="row">
  10. <div class="col-12">
  11. <!-- Zone de travail principale -->
  12. <div class="card">
  13. <div class="card-header">
  14. <h5 class="card-title mb-0">
  15. <i class="bi bi-pencil-square me-2"></i>
  16. Éditeur de carte
  17. </h5>
  18. </div>
  19. <div class="card-body">
  20. <?php
  21. $loaded_map = $loaded_map ?? ($GLOBALS['view_data']['loaded_map'] ?? null);
  22. $map_data = $map_data ?? ($GLOBALS['view_data']['map_data'] ?? null);
  23. ?>
  24. <?php if (isset($loaded_map) && $loaded_map): ?>
  25. <!-- Interface de la carte chargée -->
  26. <div class="alert alert-success">Carte chargée avec succès !</div>
  27. <!-- Interface de la carte chargée -->
  28. <div class="map-editor-container">
  29. <!-- Barre d'outils de la carte -->
  30. <div class="map-toolbar d-flex justify-content-between align-items-center mb-3">
  31. <div class="d-flex align-items-center gap-2">
  32. <h6 class="mb-0">
  33. <i class="bi bi-map me-2"></i><?php echo htmlspecialchars($map_data['name']); ?>
  34. </h6>
  35. <span class="badge bg-info">
  36. <?php echo $map_data['width']; ?> × <?php echo $map_data['height']; ?>
  37. </span>
  38. </div>
  39. <div class="d-flex align-items-center gap-2">
  40. <small class="text-muted">
  41. Zoom: <span id="zoomLevel">100</span>%
  42. </small>
  43. <div class="btn-group btn-group-sm">
  44. <button class="btn btn-outline-secondary" id="zoomOut" title="Zoom arrière">
  45. <i class="bi bi-zoom-out"></i>
  46. </button>
  47. <button class="btn btn-outline-secondary" id="zoomIn" title="Zoom avant">
  48. <i class="bi bi-zoom-in"></i>
  49. </button>
  50. <button class="btn btn-outline-secondary" id="fitToScreen" title="Adapter à l'écran">
  51. <i class="bi bi-arrows-fullscreen"></i>
  52. </button>
  53. </div>
  54. </div>
  55. </div>
  56. <!-- Zone de la carte interactive -->
  57. <div class="map-canvas-container border" style="position: relative; overflow: hidden; height: 600px; background-color: #f8f9fa;">
  58. <div id="mapCanvas" style="position: absolute; top: 0; left: 0; cursor: grab;">
  59. <!-- La carte sera rendue ici via JavaScript -->
  60. </div>
  61. <!-- Indicateur de chargement -->
  62. <div id="mapLoading" class="d-flex align-items-center justify-content-center" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(255,255,255,0.8);">
  63. <div class="text-center">
  64. <div class="spinner-border text-primary mb-2" role="status">
  65. <span class="visually-hidden">Chargement...</span>
  66. </div>
  67. <p class="mb-0">Chargement de la carte...</p>
  68. </div>
  69. </div>
  70. </div>
  71. <!-- Informations de la tuile sélectionnée -->
  72. <div id="tileInfo" class="mt-3 p-3 bg-light rounded" style="display: none;">
  73. <h6 class="mb-2">
  74. <i class="bi bi-info-circle me-1"></i>Propriétés de la parcelle
  75. </h6>
  76. <div class="row">
  77. <div class="col-md-6">
  78. <small class="text-muted">Position</small>
  79. <p class="mb-1" id="tilePosition">Q: 0, R: 0</p>
  80. </div>
  81. <div class="col-md-6">
  82. <small class="text-muted">Type</small>
  83. <p class="mb-1" id="tileType">Vide</p>
  84. </div>
  85. </div>
  86. <div id="tileProperties" class="mt-2">
  87. <!-- Les propriétés de la tuile seront affichées ici -->
  88. </div>
  89. </div>
  90. </div>
  91. <?php else: ?>
  92. <!-- Zone indiquant qu'aucun projet n'est chargé -->
  93. <div class="alert alert-info">Aucune carte chargée</div>
  94. <div class="editor-empty border d-flex align-items-center justify-content-center" style="width:100%; height:600px; background-color:#e9ecef;">
  95. <div class="text-center">
  96. <!-- Illustration SVG représentant une carte vide -->
  97. <svg role="img" aria-label="Illustration : cadriage avec point d'attention" width="200" height="140" viewBox="0 0 200 140" xmlns="http://www.w3.org/2000/svg" class="mx-auto d-block">
  98. <defs>
  99. <linearGradient id="g" x1="0" x2="1">
  100. <stop offset="0" stop-color="#f8f9fa"/>
  101. <stop offset="1" stop-color="#e9ecef"/>
  102. </linearGradient>
  103. </defs>
  104. <rect x="8" y="12" width="184" height="116" rx="8" fill="url(#g)" stroke="#ced4da" />
  105. <!-- Grid lines -->
  106. <g stroke="#adb5bd" stroke-width="1">
  107. <line x1="20" y1="20" x2="180" y2="20"/>
  108. <line x1="20" y1="40" x2="180" y2="40"/>
  109. <line x1="20" y1="60" x2="180" y2="60"/>
  110. <line x1="20" y1="80" x2="180" y2="80"/>
  111. <line x1="20" y1="100" x2="180" y2="100"/>
  112. <line x1="20" y1="120" x2="180" y2="120"/>
  113. <line x1="20" y1="20" x2="20" y2="120"/>
  114. <line x1="60" y1="20" x2="60" y2="120"/>
  115. <line x1="100" y1="20" x2="100" y2="120"/>
  116. <line x1="140" y1="20" x2="140" y2="120"/>
  117. <line x1="180" y1="20" x2="180" y2="120"/>
  118. </g>
  119. <!-- Point d'attention -->
  120. <rect x="95" y="55" width="10" height="10" fill="#dc3545" stroke="#b02a37" rx="2"/>
  121. <text x="100" y="50" text-anchor="middle" font-size="8" fill="#dc3545" font-weight="bold">!</text>
  122. </svg>
  123. <!-- Texte principal -->
  124. <h5 class="mt-3 mb-1">Aucun projet chargé</h5>
  125. <!-- Explication -->
  126. <p class="text-muted small mb-3">Créez un nouveau projet ou chargez-en un existant pour commencer à éditer une carte.</p>
  127. <!-- Actions rapides -->
  128. <div class="d-flex justify-content-center gap-2">
  129. <a href="/projects/new" class="btn btn-primary btn-sm">Nouveau projet</a>
  130. <a href="/projects" class="btn btn-outline-secondary btn-sm">Charger un projet</a>
  131. </div>
  132. </div>
  133. </div>
  134. <?php endif; ?>
  135. </div>
  136. </div>
  137. <!-- Informations sur le projet -->
  138. <div class="row mt-4">
  139. <div class="col-md-4">
  140. <div class="card">
  141. <div class="card-body">
  142. <h6 class="card-title">
  143. <i class="bi bi-info-circle me-1"></i>
  144. Informations
  145. </h6>
  146. <p class="card-text small">
  147. <strong>Dimensions:</strong> 800x600 px<br>
  148. <strong>Calques:</strong> 1<br>
  149. <strong>Outil actif:</strong> Pinceau<br>
  150. <strong>Couleur:</strong> <span style="display: inline-block; width: 12px; height: 12px; background-color: #000000; border-radius: 2px;"></span> Noir
  151. </p>
  152. </div>
  153. </div>
  154. </div>
  155. <div class="col-md-4">
  156. <div class="card">
  157. <div class="card-body">
  158. <h6 class="card-title">
  159. <i class="bi bi-clock-history me-1"></i>
  160. Historique
  161. </h6>
  162. <ul class="list-unstyled small">
  163. <li><i class="bi bi-dot me-1"></i>Carte créée</li>
  164. <li><i class="bi bi-dot me-1"></i>Calque ajouté</li>
  165. <li><i class="bi bi-dot me-1"></i>Outil sélectionné</li>
  166. </ul>
  167. </div>
  168. </div>
  169. </div>
  170. <div class="col-md-4">
  171. <div class="card">
  172. <div class="card-body">
  173. <h6 class="card-title">
  174. <i class="bi bi-star me-1"></i>
  175. Astuces
  176. </h6>
  177. <p class="card-text small">
  178. Utilisez Ctrl+Z pour annuler.<br>
  179. Cliquez-droit pour le menu contextuel.<br>
  180. Glissez-déposez des images pour les importer.
  181. </p>
  182. </div>
  183. </div>
  184. </div>
  185. </div>
  186. </div>
  187. </div>
  188. </div>
  189. </main>
  190. <?php if ($loaded_map): ?>
  191. <script>
  192. // Données de la carte
  193. const mapData = <?php echo json_encode($map_data); ?>;
  194. const mapWidth = mapData.width;
  195. const mapHeight = mapData.height;
  196. // Configuration de l'éditeur de carte
  197. class MapEditor {
  198. constructor() {
  199. this.canvas = document.getElementById('mapCanvas');
  200. this.container = document.querySelector('.map-canvas-container');
  201. this.zoomLevel = 1;
  202. this.panOffset = { x: 0, y: 0 };
  203. this.isDragging = false;
  204. this.lastMousePos = { x: 0, y: 0 };
  205. this.selectedTile = null;
  206. this.tileSize = 30; // Taille de base d'une tuile hexagonale
  207. this.init();
  208. }
  209. init() {
  210. this.setupCanvas();
  211. this.renderMap();
  212. this.setupEventListeners();
  213. this.hideLoading();
  214. this.fitToScreen();
  215. }
  216. setupCanvas() {
  217. // Calculer la taille du canvas
  218. const hexWidth = this.tileSize * 1.5;
  219. const hexHeight = this.tileSize * Math.sqrt(3);
  220. const canvasWidth = (mapWidth + 0.5) * hexWidth;
  221. const canvasHeight = (mapHeight + 0.5) * hexHeight;
  222. this.canvas.style.width = canvasWidth + 'px';
  223. this.canvas.style.height = canvasHeight + 'px';
  224. this.canvas.style.transformOrigin = '0 0';
  225. }
  226. renderMap() {
  227. this.canvas.innerHTML = '';
  228. for (let q = 0; q < mapWidth; q++) {
  229. for (let r = 0; r < mapHeight; r++) {
  230. this.renderHexagon(q, r);
  231. }
  232. }
  233. }
  234. renderHexagon(q, r) {
  235. const hex = document.createElement('div');
  236. hex.className = 'hexagon';
  237. hex.dataset.q = q;
  238. hex.dataset.r = r;
  239. // Positionner l'hexagone
  240. const x = q * this.tileSize * 1.5;
  241. const y = r * this.tileSize * Math.sqrt(3) + (q % 2) * this.tileSize * Math.sqrt(3) / 2;
  242. hex.style.left = x + 'px';
  243. hex.style.top = y + 'px';
  244. hex.style.width = this.tileSize + 'px';
  245. hex.style.height = this.tileSize + 'px';
  246. // Style de base
  247. hex.style.position = 'absolute';
  248. hex.style.border = '1px solid #ddd';
  249. hex.style.backgroundColor = '#fff';
  250. hex.style.cursor = 'pointer';
  251. hex.style.transition = 'background-color 0.2s';
  252. // Créer la forme hexagonale avec CSS
  253. hex.style.clipPath = 'polygon(50% 0%, 93.3% 25%, 93.3% 75%, 50% 100%, 6.7% 75%, 6.7% 25%)';
  254. // Gestionnaire de clic
  255. hex.addEventListener('click', (e) => {
  256. e.stopPropagation();
  257. this.selectTile(q, r);
  258. });
  259. // Gestionnaire de survol
  260. hex.addEventListener('mouseenter', () => {
  261. if (!this.selectedTile || this.selectedTile.q !== q || this.selectedTile.r !== r) {
  262. hex.style.backgroundColor = '#e3f2fd';
  263. }
  264. });
  265. hex.addEventListener('mouseleave', () => {
  266. if (!this.selectedTile || this.selectedTile.q !== q || this.selectedTile.r !== r) {
  267. hex.style.backgroundColor = '#fff';
  268. }
  269. });
  270. this.canvas.appendChild(hex);
  271. }
  272. selectTile(q, r) {
  273. // Désélectionner la tuile précédente
  274. if (this.selectedTile) {
  275. const prevHex = this.canvas.querySelector(`[data-q="${this.selectedTile.q}"][data-r="${this.selectedTile.r}"]`);
  276. if (prevHex) {
  277. prevHex.style.backgroundColor = '#fff';
  278. prevHex.style.borderColor = '#ddd';
  279. }
  280. }
  281. // Sélectionner la nouvelle tuile
  282. this.selectedTile = { q, r };
  283. const hex = this.canvas.querySelector(`[data-q="${q}"][data-r="${r}"]`);
  284. if (hex) {
  285. hex.style.backgroundColor = '#2196f3';
  286. hex.style.borderColor = '#1976d2';
  287. }
  288. // Afficher les informations de la tuile
  289. this.showTileInfo(q, r);
  290. }
  291. showTileInfo(q, r) {
  292. const tileInfo = document.getElementById('tileInfo');
  293. const tilePosition = document.getElementById('tilePosition');
  294. const tileType = document.getElementById('tileType');
  295. const tileProperties = document.getElementById('tileProperties');
  296. tilePosition.textContent = `Q: ${q}, R: ${r}`;
  297. tileType.textContent = 'Vide'; // Par défaut
  298. // TODO: Récupérer les vraies propriétés de la tuile depuis les données
  299. tileProperties.innerHTML = `
  300. <div class="row">
  301. <div class="col-md-6">
  302. <label class="form-label small">Type de terrain</label>
  303. <select class="form-select form-select-sm">
  304. <option>Vide</option>
  305. <option>Forêt</option>
  306. <option>Montagne</option>
  307. <option>Eau</option>
  308. <option>Ville</option>
  309. <option>Route</option>
  310. </select>
  311. </div>
  312. <div class="col-md-6">
  313. <label class="form-label small">Élévation</label>
  314. <input type="number" class="form-control form-control-sm" placeholder="0">
  315. </div>
  316. </div>
  317. <div class="mt-2">
  318. <label class="form-label small">Ressources</label>
  319. <div class="input-group input-group-sm">
  320. <input type="text" class="form-control" placeholder="Ajouter une ressource...">
  321. <button class="btn btn-outline-secondary" type="button">+</button>
  322. </div>
  323. </div>
  324. `;
  325. tileInfo.style.display = 'block';
  326. }
  327. setupEventListeners() {
  328. // Zoom
  329. document.getElementById('zoomIn').addEventListener('click', () => this.zoom(1.2));
  330. document.getElementById('zoomOut').addEventListener('click', () => this.zoom(0.8));
  331. document.getElementById('fitToScreen').addEventListener('click', () => this.fitToScreen());
  332. // Déplacement (pan)
  333. this.container.addEventListener('mousedown', (e) => {
  334. if (e.target === this.container) {
  335. this.isDragging = true;
  336. this.lastMousePos = { x: e.clientX, y: e.clientY };
  337. this.canvas.style.cursor = 'grabbing';
  338. }
  339. });
  340. document.addEventListener('mousemove', (e) => {
  341. if (this.isDragging) {
  342. const deltaX = e.clientX - this.lastMousePos.x;
  343. const deltaY = e.clientY - this.lastMousePos.y;
  344. this.panOffset.x += deltaX;
  345. this.panOffset.y += deltaY;
  346. this.updateTransform();
  347. this.lastMousePos = { x: e.clientX, y: e.clientY };
  348. }
  349. });
  350. document.addEventListener('mouseup', () => {
  351. this.isDragging = false;
  352. this.canvas.style.cursor = 'grab';
  353. });
  354. // Zoom avec la molette
  355. this.container.addEventListener('wheel', (e) => {
  356. e.preventDefault();
  357. const zoomFactor = e.deltaY > 0 ? 0.9 : 1.1;
  358. this.zoom(zoomFactor);
  359. });
  360. // Désélectionner en cliquant sur le fond
  361. this.container.addEventListener('click', () => {
  362. if (this.selectedTile) {
  363. this.selectTile(null, null);
  364. document.getElementById('tileInfo').style.display = 'none';
  365. }
  366. });
  367. }
  368. zoom(factor) {
  369. this.zoomLevel *= factor;
  370. this.zoomLevel = Math.max(0.1, Math.min(5, this.zoomLevel)); // Limiter le zoom entre 0.1x et 5x
  371. this.updateTransform();
  372. document.getElementById('zoomLevel').textContent = Math.round(this.zoomLevel * 100);
  373. }
  374. fitToScreen() {
  375. const containerRect = this.container.getBoundingClientRect();
  376. const canvasRect = this.canvas.getBoundingClientRect();
  377. const scaleX = containerRect.width / canvasRect.width;
  378. const scaleY = containerRect.height / canvasRect.height;
  379. const scale = Math.min(scaleX, scaleY) * 0.9; // Laisser un peu de marge
  380. this.zoomLevel = scale;
  381. this.panOffset = { x: 0, y: 0 };
  382. this.updateTransform();
  383. document.getElementById('zoomLevel').textContent = Math.round(this.zoomLevel * 100);
  384. }
  385. updateTransform() {
  386. this.canvas.style.transform = `translate(${this.panOffset.x}px, ${this.panOffset.y}px) scale(${this.zoomLevel})`;
  387. }
  388. hideLoading() {
  389. document.getElementById('mapLoading').style.display = 'none';
  390. }
  391. }
  392. // Initialiser l'éditeur de carte quand le DOM est chargé
  393. document.addEventListener('DOMContentLoaded', function() {
  394. if (typeof mapData !== 'undefined') {
  395. new MapEditor();
  396. }
  397. });
  398. </script>
  399. <?php endif; ?>
  400. <?php
  401. include __DIR__ . '/partials/footer.php';
  402. ?>