Skip to content

Commit

Permalink
Merge pull request #235 from mdziekon/gh-230-overview-components-refa…
Browse files Browse the repository at this point in the history
…ctor

GH-230 | Overview - Planets list summary refactor
  • Loading branch information
mdziekon authored Jul 6, 2022
2 parents b99fb9b + 5976746 commit 4687ac7
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 85 deletions.
11 changes: 11 additions & 0 deletions css/overview.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,14 @@
padding: 3px 15px;
color: lime;
}

.otherPlanetsSection {
display: flex;
justify-content: flex-start;
flex-wrap: wrap;
}
.otherPlanetItem {
flex: 0 0 25%;
align-self: flex-start;
margin: 8px 0;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions modules/overview/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
include($includePath . './screens/FirstLogin/utils/effects/updateUserOnFirstLogin.effect.php');
include($includePath . './screens/FirstLogin/utils/helpers/getReferrerTasksData.helper.php');

include($includePath . './screens/Overview/components/PlanetsListElement/PlanetsListElement.component.php');

include($includePath . './screens/PlanetNameChange/PlanetNameChange.screen.php');
include($includePath . './screens/PlanetNameChange/PlanetNameChange.utils.php');
include($includePath . './screens/PlanetNameChange/utils/errorMappers/validateNewName.errorMapper.php');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace UniEngine\Engine\Modules\Overview\Screens\Overview\Components\PlanetsListElement;

use UniEngine\Engine\Includes\Helpers\Planets\Queues\Structures;

/**
* @param array $props
* @param arrayRef $props['planet']
* @param number $props['currentTimestamp']
*/
function render($props) {
global $_Lang, $_SkinPath;

$planet = &$props['planet'];
$currentTimestamp = $props['currentTimestamp'];

$localTemplateLoader = createLocalTemplateLoader(__DIR__);
$tplBodyCache = [
'body' => $localTemplateLoader('body'),
'queueStateBusy' => $localTemplateLoader('queueStateBusy'),
'queueStateEmpty' => $localTemplateLoader('queueStateEmpty'),
];

$queueStateHTML = null;

if ($planet['buildQueue_firstEndTime'] > 0) {
$buildingsQueue = Structures\parseQueueString(
Structures\getQueueString($planet)
);
$firstQueueElement = $buildingsQueue[0];
$elementId = $firstQueueElement['elementID'];
$elementLevel = $firstQueueElement['level'];

$queueStateHTML = parsetemplate(
$tplBodyCache['queueStateBusy'],
[
'elementName' => $_Lang['tech'][$elementId],
'elementLevel' => $elementLevel,
'elementConstructionRestTime' => pretty_time(
$firstQueueElement['endTimestamp'] - $currentTimestamp
),
]
);
} else {
$queueStateHTML = parsetemplate(
$tplBodyCache['queueStateEmpty'],
$_Lang
);
}

$tplBodyParams = [
'skinPath' => $_SkinPath,
'planetName' => $planet['name'],
'planetId' => $planet['id'],
'planetImg' => $planet['image'],
'queueStateHTML' => $queueStateHTML,
];
$tplBodyParams = array_merge($_Lang, $tplBodyParams);

$componentHTML = parsetemplate(
$tplBodyCache['body'],
$tplBodyParams
);

return [
'componentHTML' => $componentHTML,
];
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<div class="otherPlanetItem">
{planetName}
<br/>
<a
href="?cp={planetId}&re=0"
title="{planetName}"
>
<img
src="{skinPath}planeten/small/s_{planetImg}.jpg"
height="90"
width="90"
>
</a>
<br>
<center>
{queueStateHTML}
</center>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

header("Location: ../index.php");

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{elementName} ({elementLevel})
<br>
<span style="color: #7f7f7f;">
({elementConstructionRestTime})
</span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{Free}
<br/>
&nbsp;
5 changes: 5 additions & 0 deletions modules/overview/screens/Overview/components/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

header("Location: ../index.php");

?>
5 changes: 5 additions & 0 deletions modules/overview/screens/Overview/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

header("Location: ../index.php");

?>
98 changes: 16 additions & 82 deletions overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
include_once($_EnginePath . 'modules/overview/_includes.php');

use UniEngine\Engine\Includes\Helpers\World\Elements;
use UniEngine\Engine\Common;
use UniEngine\Engine\Modules\Session;
use UniEngine\Engine\Modules\Flights;
use UniEngine\Engine\Modules\FlightControl;
use UniEngine\Engine\Modules\Overview;
Expand Down Expand Up @@ -593,99 +591,35 @@
{
$QryPlanets .= "`name` {$Order}";
}
$parse['OtherPlanets'] = '';
$parse['OtherPlanets'] = [];

$SQLResult_GetAllOtherPlanets = doquery($QryPlanets, 'planets');

if($SQLResult_GetAllOtherPlanets->num_rows > 0)
{
$InCurrentRow = 0;
$InNextRow = false;

while($PlanetsData = $SQLResult_GetAllOtherPlanets->fetch_assoc())
{
// Show Planet on List
if(empty($DontShowPlanet) OR !in_array($PlanetsData['id'], $DontShowPlanet))
{
$DontShowThisPlanet = false;
}
else
{
$DontShowThisPlanet = true;
}
if($DontShowThisPlanet === false)
{
if($InCurrentRow == 0)
{
$parse['OtherPlanets'] .= '<tr>';
}
$parse['OtherPlanets'] .= '<th>'.$PlanetsData['name'].'<br/>';
$parse['OtherPlanets'] .= "<a href=\"?cp={$PlanetsData['id']}&re=0\" title=\"{$PlanetsData['name']}\"><img src=\"{$_SkinPath}planeten/small/s_{$PlanetsData['image']}.jpg\" height=\"50\" width=\"50\"></a><br>";
$parse['OtherPlanets'] .= '<center>';
}
if ($SQLResult_GetAllOtherPlanets->num_rows > 0) {
while ($PlanetsData = $SQLResult_GetAllOtherPlanets->fetch_assoc()) {
// Update Planet - Building Queue
if(HandlePlanetUpdate($PlanetsData, $_User, $Now, true) === true)
{
if (HandlePlanetUpdate($PlanetsData, $_User, $Now, true) === true) {
$Results['planets'][] = $PlanetsData;
}
if($PlanetsData['buildQueue_firstEndTime'] > 0)
{
if($DontShowThisPlanet === false)
{
$BuildQueue = $PlanetsData['buildQueue'];
$QueueArray = explode (';', $BuildQueue);
$CurrentBuild = explode (',', $QueueArray[0]);
$BuildElement = $CurrentBuild[0];
$BuildLevel = $CurrentBuild[1];
$BuildRestTime = pretty_time($CurrentBuild[3] - $Now);

$parse['OtherPlanets'] .= $_Lang['tech'][$BuildElement].' ('.$BuildLevel.')';
$parse['OtherPlanets'] .= '<br><span style="color: #7f7f7f;">('.$BuildRestTime.')</span>';
}
}
else
{
if($DontShowThisPlanet === false)
{
$parse['OtherPlanets'] .= $_Lang['Free'].'<br/>&nbsp;';
}
}

if($DontShowThisPlanet === false)
{
$parse['OtherPlanets'] .= '</center></th>';
}

if($DontShowThisPlanet === false)
{
$InCurrentRow += 1;
if($InCurrentRow >= 5)
{
$InCurrentRow = 0;
$InNextRow = true;
if($DontShowThisPlanet == false)
{
$parse['OtherPlanets'] .= '</tr>';
}
}
if (
!empty($DontShowPlanet) &&
in_array($PlanetsData['id'], $DontShowPlanet)
) {
continue;
}
}

if($InNextRow === true AND $InCurrentRow > 0)
{
$Difference = 5 - $InCurrentRow;
for($i = 0; $i < $Difference; $i += 1)
{
$parse['OtherPlanets'] .= '<th>&nbsp;</th>';
}
$parse['OtherPlanets'] .= '</tr>';
$parse['OtherPlanets'][] = Overview\Screens\Overview\Components\PlanetsListElement\render([
'planet' => &$PlanetsData,
'currentTimestamp' => $Now,
])['componentHTML'];
}
}
else
{
} else {
$parse['hide_other_planets'] = 'style="display: none;"';
}

$parse['OtherPlanets'] = implode('', $parse['OtherPlanets']);

// Update this planet (if necessary)
if(HandlePlanetUpdate($_Planet, $_User, $Now, true) === true)
{
Expand Down
6 changes: 4 additions & 2 deletions templates/default_template/overview_body.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $(document).ready(function()
});
});
</script>
<link rel="stylesheet" type="text/css" href="dist/css/overview.cachebuster-1546565145290.min.css" />
<link rel="stylesheet" type="text/css" href="dist/css/overview.cachebuster-1657148521824.min.css" />
<br />
{P_SFBInfobox}
<table width="750">
Expand Down Expand Up @@ -290,7 +290,9 @@ $(document).ready(function()
</tr>
<tr {hide_other_planets}>
<th colspan="3">
<table class="s" border="0" align="center">{OtherPlanets}</table>
<div class="otherPlanetsSection">
{OtherPlanets}
</div>
</th>
</tr>
<tr class="inv"><td></td></tr>
Expand Down

0 comments on commit 4687ac7

Please sign in to comment.