Skip to content

Commit

Permalink
map navigation improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
g5bot committed Dec 22, 2023
1 parent 3273763 commit 3ba1990
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 28 deletions.
25 changes: 13 additions & 12 deletions src/Module/Admin/View/Map/EditSection/EditSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,24 @@ public function handle(GameControllerInterface $game): void
$possibleBorder['row_' . ($key % 1)][] = $value;
}

$game->setViewTemplate('html/admin/mapeditor_section.twig');
$helper = $this->starmapUiFactory->createMapSectionHelper();
$newSectionId = $helper->setTemplateVars(
$game,
$layer,
$section_id,
true,
$this->request->getDirection()
);

$game->setTemplateFile('html/admin/mapeditor_section.twig');
$game->appendNavigationPart('/admin/?SHOW_MAP_EDITOR=1', _('Karteneditor'));
$game->appendNavigationPart(
sprintf(
'/admin/?SHOW_EDIT_MAP_SECTION=1&section=%d&layerid=%d',
$section_id,
$newSectionId,
$layerId
),
sprintf(_('Sektion %d anzeigen'), $section_id)
sprintf(_('Sektion %d anzeigen'), $newSectionId)
);
$game->setPageTitle(_('Sektion anzeigen'));
$game->setTemplateVar('POSSIBLE_FIELD_TYPES', $possibleFieldTypes);
Expand All @@ -118,17 +127,9 @@ public function handle(GameControllerInterface $game): void
$game->setTemplateVar('POSSIBLE_ADMIN_REGION', $possibleAdminRegion);
$game->setTemplateVar('FIELDS_PER_SECTION', MapEnum::FIELDS_PER_SECTION);

$helper = $this->starmapUiFactory->createMapSectionHelper();
$helper->setTemplateVars(
$game,
$layer,
$section_id,
true,
$this->request->getDirection()
);

$game->addExecuteJS(sprintf(
"registerNavKeys('admin/', '%s', '', true);",
"registerNavKeys('/admin/', '%s', '', true);",
self::VIEW_IDENTIFIER
), GameEnum::JS_EXECUTION_AJAX_UPDATE);
}
Expand Down
6 changes: 1 addition & 5 deletions src/Module/Admin/View/Map/ShowMapEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ public function handle(GameControllerInterface $game): void
$layers = $this->layerRepository->findAllIndexed();

$layerId = request::getInt('layerid');
$layer = $layerId === 0 ? current($layers) : $layers[$layerId];

if ($layer === false) {
return;
}
$layer = $layerId === 0 ? $layers[MapEnum::DEFAULT_LAYER] : $layers[$layerId];

//HEADROW
$xHeadRow = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Module/Starmap/View/ShowByPosition/ShowByPosition.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function handle(GameControllerInterface $game): void
);

$game->addExecuteJS(sprintf(
"registerNavKeys('%s.php', '%s', '%s', false);",
"registerNavKeys('%s.php', '%s', '%s', false, false);",
ModuleViewEnum::MAP->value,
RefreshSection::VIEW_IDENTIFIER,
'html/starmapSectionTable.twig'
Expand Down
2 changes: 1 addition & 1 deletion src/Module/Starmap/View/ShowSection/ShowSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function handle(GameControllerInterface $game): void
);

$game->addExecuteJS(sprintf(
"registerNavKeys('%s.php', '%s', '%s', false);",
"registerNavKeys('%s.php', '%s', '%s', false, true);",
ModuleViewEnum::MAP->value,
self::VIEW_IDENTIFIER,
'html/starmapSectionTable.twig'
Expand Down
24 changes: 18 additions & 6 deletions src/Public/static/js/starmap.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
var navKeysRegistered = false;
var currentModule = '';
var currentView = '';
var currentMacro = '';

function registerNavKeys(module, view, macro, isRedirect) {
function registerNavKeys(module, view, macro, isRedirect, isInnerContent) {

if (navKeysRegistered) {
return;
}

currentModule = module;
currentView = view;
Expand All @@ -11,18 +16,20 @@ function registerNavKeys(module, view, macro, isRedirect) {
document.addEventListener("keydown", (event) => {

if (event.key === "ArrowUp") {
refreshMapSection(4, isRedirect);
refreshMapSection(4, isRedirect, isInnerContent);
}
if (event.key === "ArrowDown") {
refreshMapSection(2, isRedirect);
refreshMapSection(2, isRedirect, isInnerContent);
}
if (event.key === "ArrowLeft") {
refreshMapSection(1, isRedirect);
refreshMapSection(1, isRedirect, isInnerContent);
}
if (event.key === "ArrowRight") {
refreshMapSection(3, isRedirect);
refreshMapSection(3, isRedirect, isInnerContent);
}
});

navKeysRegistered = true;
}

var currentSection = 0;
Expand Down Expand Up @@ -82,7 +89,12 @@ function refreshMapContent(direction) {
switchInnerContent(currentView, 'Sektion anzeigen', params, currentModule);
}

function refreshMapSection(direction, isRedirect) {
function refreshMapSection(direction, isRedirect, isInnerContent) {

if (isInnerContent) {
refreshMapContent(direction);
return;
}

if (!isDirectionAllowed(direction)) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/html/admin/scripts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<br />
<div>
<br />
<a href="/admin/?SHOW_MAP_EDITOR=1&layerid=1">Karteneditor</a>
<a href="/admin/?SHOW_MAP_EDITOR=1">Karteneditor</a>
<br />
<a href="/admin/?SHOW_MAP_OVERALL=1&layerid=1" target="_blank">Karten Gesamtansicht</a>
<br />
Expand Down
2 changes: 1 addition & 1 deletion src/html/macros.twig
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
{% macro adminnavigation() %}
{{ _self.admin_navigation_item('Spielerliste', '/admin/?SHOW_PLAYER_LIST=1', 'ally') }}
{{ _self.admin_navigation_item('Nachrichten', '/admin/?SHOW_MASS_MAIL=1', 'msg') }}
{{ _self.admin_navigation_item('Karteneditor', '/admin/?SHOW_MAP_EDITOR=1&layerid=1', 'map') }}
{{ _self.admin_navigation_item('Karteneditor', '/admin/?SHOW_MAP_EDITOR=1', 'map') }}
{{ _self.admin_navigation_item('Kolonie-Sandbox', '/admin/?SHOW_COLONY_SANDBOX=1', 'sandbox') }}
{{ _self.admin_navigation_item('Ticks', '/admin/?SHOW_TICKS=1', 'ticks') }}
{{ _self.admin_navigation_item('Skripte', '/admin/?SHOW_SCRIPTS=1', 'scripts') }}
Expand Down
2 changes: 1 addition & 1 deletion src/html/sitemacros.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@
<metal:macro metal:use-macro="navigation_item"
tal:define="title string:Nachrichten; url string:/admin/?SHOW_MASS_MAIL=1; icon_url string:msg" />
<metal:macro metal:use-macro="navigation_item"
tal:define="title string:Karteneditor; url string:/admin/?SHOW_MAP_EDITOR=1&layerid=1; icon_url string:map" />
tal:define="title string:Karteneditor; url string:/admin/?SHOW_MAP_EDITOR=1; icon_url string:map" />
<metal:macro metal:use-macro="navigation_item"
tal:define="title string:Kolonie-Sandbox; url string:/admin/?SHOW_COLONY_SANDBOX=1; icon_url string:sandbox" />
<metal:macro metal:use-macro="navigation_item"
Expand Down

0 comments on commit 3ba1990

Please sign in to comment.