Skip to content

Commit

Permalink
GH-208 Simplify planet's menu links rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed May 5, 2022
1 parent 1bf4794 commit b18a845
Showing 1 changed file with 54 additions and 40 deletions.
94 changes: 54 additions & 40 deletions includes/functions/GalaxyRowPlanet.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ function GalaxyRowPlanet($GalaxyRow, $GalaxyRowPlanet, $GalaxyRowUser, $Galaxy,
$PlanetType = 1;
$Links = [];

$isCurrentUser = $GalaxyRowUser['id'] == $_User['id'];
$isCurrentGalaxy = $GalaxyRowPlanet['galaxy'] == $CurrentGalaxy;

if (
$SensonPhalanxLevel > 0 &&
$GalaxyRowUser['id'] != $_User['id'] &&
$GalaxyRowPlanet['galaxy'] == $CurrentGalaxy
!$isCurrentUser &&
$isCurrentGalaxy
) {
$isInRange = Checks\isTargetInRange([
'originPosition' => $CurrentSystem,
Expand All @@ -29,14 +32,16 @@ function GalaxyRowPlanet($GalaxyRow, $GalaxyRowPlanet, $GalaxyRowUser, $Galaxy,
]);

if ($isInRange) {
$Links[] = array('prio' => 3, 'txt' => "<a href=# onclick=&#039return Phalanx({$Galaxy},{$System},{$Planet},{$PlanetType});&#039 >{$_Lang['gl_phalanx']}</a>");
$Links[3] = [
'txt' => "<a href=# onclick=&#039return Phalanx({$Galaxy},{$System},{$Planet},{$PlanetType});&#039 >{$_Lang['gl_phalanx']}</a>",
];
}
}

if (
$CurrentMIP > 0 &&
$GalaxyRowUser['id'] != $_User['id'] &&
$GalaxyRowPlanet['galaxy'] == $CurrentGalaxy
!$isCurrentUser &&
$isCurrentGalaxy
) {
$isInRange = Checks\isTargetInRange([
'originPosition' => $CurrentSystem,
Expand All @@ -45,68 +50,77 @@ function GalaxyRowPlanet($GalaxyRow, $GalaxyRowPlanet, $GalaxyRowUser, $Galaxy,
]);

if ($isInRange) {
$Links[] = array('prio' => 9, 'txt' => "<a class=missileAttack href=galaxy.php?mode=2&galaxy={$Galaxy}&system={$System}&planet={$Planet} >{$_Lang['type_mission'][10]}</a>");
$Links[9] = [
'txt' => "<a class=missileAttack href=galaxy.php?mode=2&galaxy={$Galaxy}&system={$System}&planet={$Planet} >{$_Lang['type_mission'][10]}</a>",
];
}
}

if($GalaxyRowUser['id'] != $_User['id'])
{
$Links[] = array('prio' => 1, 'txt' => "<a href=# onclick=&#039return sendShips(1, {$Galaxy}, {$System}, {$Planet}, {$PlanetType});&#039 >{$_Lang['type_mission'][6]}</a>");
$Links[] = array('prio' => 2, 'txt' => '', 'html' => '<td class=\"c hiFnt\">&nbsp;</td>');
$Links[] = array('prio' => 4, 'txt' => "<a href=fleet.php?galaxy={$Galaxy}&amp;system={$System}&amp;planet={$Planet}&amp;planettype={$PlanetType}&amp;target_mission=1>{$_Lang['type_mission'][1]}</a>");
if (!$isCurrentUser) {
$Links[1] = [
'txt' => "<a href=# onclick=&#039return sendShips(1, {$Galaxy}, {$System}, {$Planet}, {$PlanetType});&#039 >{$_Lang['type_mission'][6]}</a>",
];
$Links[2] = [
'txt' => '',
'html' => '<td class=\"c hiFnt\">&nbsp;</td>',
];
$Links[4] = [
'txt' => "<a href=fleet.php?galaxy={$Galaxy}&amp;system={$System}&amp;planet={$Planet}&amp;planettype={$PlanetType}&amp;target_mission=1>{$_Lang['type_mission'][1]}</a>",
];

if($GalaxyRowPlanet['id_owner'] > 0)
{
if(($GalaxyRowUser['ally_id'] == $_User['ally_id'] AND $_User['ally_id'] > 0) OR in_array($GalaxyRowUser['id'], $MyBuddies) OR (isset($MyAllyPacts[$GalaxyRowUser['ally_id']]) && $MyAllyPacts[$GalaxyRowUser['ally_id']] >= 3))
{
$Links[] = array('prio' => 5, 'txt' => "<a href=fleet.php?galaxy={$Galaxy}&system={$System}&planet={$Planet}&planettype={$PlanetType}&target_mission=5>{$_Lang['type_mission'][5]}</a>");
$Links[5] = [
'txt' => "<a href=fleet.php?galaxy={$Galaxy}&system={$System}&planet={$Planet}&planettype={$PlanetType}&target_mission=5>{$_Lang['type_mission'][5]}</a>",
];
}
}
}
else
{
$Links[] = array('prio' => 6, 'txt' => "<a href=fleet.php?galaxy={$Galaxy}&system={$System}&planet={$Planet}&planettype={$PlanetType}&target_mission=4>{$_Lang['type_mission'][4]}</a>");
$Links[6] = [
'txt' => "<a href=fleet.php?galaxy={$Galaxy}&system={$System}&planet={$Planet}&planettype={$PlanetType}&target_mission=4>{$_Lang['type_mission'][4]}</a>",
];

if(isPro() AND $_User['current_planet'] != $GalaxyRowPlanet['id'])
{
$Links[] = array('prio' => 8, 'txt' => "<a href=fleet.php?quickres=1&galaxy={$Galaxy}&system={$System}&planet={$Planet}&planettype={$PlanetType}&target_mission=3>{$_Lang['type_mission_quickres']}</a>");
$Links[8] = [
'txt' => "<a href=fleet.php?quickres=1&galaxy={$Galaxy}&system={$System}&planet={$Planet}&planettype={$PlanetType}&target_mission=3>{$_Lang['type_mission_quickres']}</a>",
];
}
}

$Links[] = array('prio' => 7, 'txt' => "<a href=fleet.php?galaxy={$Galaxy}&system={$System}&planet={$Planet}&planettype={$PlanetType}&target_mission=3>{$_Lang['type_mission'][3]}</a>");
$Links[7] = [
'txt' => "<a href=fleet.php?galaxy={$Galaxy}&system={$System}&planet={$Planet}&planettype={$PlanetType}&target_mission=3>{$_Lang['type_mission'][3]}</a>",
];

foreach($Links as $Index => $Data)
{
$PriorityArray[$Index] = $Data['prio'];
}
array_multisort($PriorityArray, SORT_ASC, $Links);
ksort($Links);

$Parse = array
(
'Lang_Planet' => $_Lang['gl_planet'],
$firstLink = array_shift($Links);

$Parse = [
'Lang_Planet' => $_Lang['gl_planet'],
'PlanetName' => $GalaxyRowPlanet['name'],
'Galaxy' => $Galaxy,
'System' => $System,
'Planet' => $Planet,
'SkinPath' => $_SkinPath,
'PlanetImg' => $GalaxyRowPlanet['image'],
'RowCount' => count($Links),
'FirstLink' => $Links[0]['txt'],
'SkinPath' => $_SkinPath,
'PlanetImg' => $GalaxyRowPlanet['image'],
'RowCount' => count($Links) + 1,
'FirstLink' => $firstLink['txt'],
'OtherLinks' => ''
);
];

foreach ($Links as $linkEntry) {
if (!empty($linkEntry['html'])) {
$Parse['OtherLinks'] .= "<tr>{$linkEntry['html']}</tr>";

foreach($Links as $Index => $Data)
{
if($Index == 0)
{
continue;
}
if(!empty($Data['html']))
{
$Parse['OtherLinks'] .= "<tr>{$Data['html']}</tr>";
}
else
{
$Parse['OtherLinks'] .= "<tr><th".($Data['txt'] == '&nbsp;' ? ' class=tipS' : '').">{$Data['txt']}</th></tr>";
}

$Parse['OtherLinks'] .= "<tr><th".($linkEntry['txt'] == '&nbsp;' ? ' class=tipS' : '').">{$linkEntry['txt']}</th></tr>";
}

return parsetemplate($TPL, $Parse);
Expand Down

0 comments on commit b18a845

Please sign in to comment.