Skip to content

Commit

Permalink
Merge pull request #236 from mdziekon/gh-230-res-transport-component
Browse files Browse the repository at this point in the history
GH-230 | Overview - Quick Transport & Stats list refactor
  • Loading branch information
mdziekon authored Jul 7, 2022
2 parents 4687ac7 + 6b5e663 commit b20e0a2
Show file tree
Hide file tree
Showing 11 changed files with 269 additions and 208 deletions.
2 changes: 2 additions & 0 deletions modules/overview/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
include($includePath . './screens/FirstLogin/utils/helpers/getReferrerTasksData.helper.php');

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

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

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

use UniEngine\Engine\Includes\Helpers\World\Elements;
use UniEngine\Engine\Includes\Helpers\World\Resources;

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

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

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

$resourcesTotalSum = array_sum(
array_map_withkeys(
Resources\getKnownPillagableResourceKeys(),
function ($resourceKey) use (&$user, &$planet) {
return Resources\getResourceState($resourceKey, $user, $planet);
}
)
);

$shipRows = [];

foreach ($_Vars_ElementCategories['units']['transport'] as $shipId) {
$requiredShipsCount = ceil($resourcesTotalSum / getShipsStorageCapacity($shipId));
$currentShipsCount = Elements\getElementCurrentCount($shipId, $planet, $user);
$remainingShipsCount = $currentShipsCount - $requiredShipsCount;

$shipRows[] = parsetemplate($tplBodyCache['shipRow'], [
'shipName' => $_Lang['tech'][$shipId],
'requiredCount' => prettyNumber($requiredShipsCount),
'remainingCount' => str_replace('-', '', prettyColorNumber($remainingShipsCount, true)),
]);
}

$shouldDisplayQuickTransportBtn = (
isPro($user) &&
$user['current_planet'] != $user['settings_mainPlanetID']
);
$quickTransportBtnText = '';

if ($shouldDisplayQuickTransportBtn) {
$getQuickTransportTargetPlanetQuery = (
"SELECT " .
"`name`, `galaxy`, `system`, `planet` " .
"FROM {{table}} " .
"WHERE " .
"`id` = {$user['settings_mainPlanetID']} " .
";"
);
$quickTransportTargetPlanet = doquery($getQuickTransportTargetPlanetQuery, 'planets', true);

$quickTransportBtnText = sprintf(
$_Lang['QuickResSend_Button'],
$quickTransportTargetPlanet['name'],
$quickTransportTargetPlanet['galaxy'],
$quickTransportTargetPlanet['system'],
$quickTransportTargetPlanet['planet']
);
}

$tplBodyParams = [
'shipRowsHTML' => implode('', $shipRows),
'Hide_QuickResButton' => (
$shouldDisplayQuickTransportBtn ?
'' :
'style="display: none;"'
),
'QuickResSend_Button' => $quickTransportBtnText,
];
$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,14 @@
<tr>
<td colspan="3" class="c pad3">{ResourcesTransport}</td>
</tr>
<tr>
<th>&nbsp;</th>
<th>{Box_transRequired}</th>
<th>{Box_transMissing_Stay}</th>
</tr>
{shipRowsHTML}
<tr {Hide_QuickResButton}>
<th class="pad5" colspan="3">
<input type="button" value="{QuickResSend_Button}" id="quickres"/>
</th>
</tr>
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 @@
<tr>
<th>{shipName}</th>
<th>{requiredCount}</th>
<th>{remainingCount}</th>
</tr>
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php

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

/**
* @param array $props
* @param array $props['stats']
*/
function render($props) {
global $_Lang;

$stats = $props['stats'];

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

$categories = [
'general' => [
'categoryName' => $_Lang['Box_statGeneral'],
'categoryType' => '',
'pointsKey' => 'total_points',
'recordsCurrentKey' => 'total_old_rank',
'recordsOldKey' => 'total_rank',
],
'buildings' => [
'categoryName' => $_Lang['Box_statBuildings'],
'categoryType' => '4',
'pointsKey' => 'build_points',
'recordsCurrentKey' => 'build_rank',
'recordsOldKey' => 'build_old_rank',
],
'fleet' => [
'categoryName' => $_Lang['Box_statFleet'],
'categoryType' => '2',
'pointsKey' => 'fleet_points',
'recordsCurrentKey' => 'fleet_rank',
'recordsOldKey' => 'fleet_old_rank',
],
'defenses' => [
'categoryName' => $_Lang['Box_statDefense'],
'categoryType' => '5',
'pointsKey' => 'defs_points',
'recordsCurrentKey' => 'defs_rank',
'recordsOldKey' => 'defs_old_rank',
],
'research' => [
'categoryName' => $_Lang['Box_statResearch'],
'categoryType' => '3',
'pointsKey' => 'tech_points',
'recordsCurrentKey' => 'tech_rank',
'recordsOldKey' => 'tech_old_rank',
],
];

$categoriesHTML = [];

foreach ($categories as $category) {
$categoryTplBodyParams = [
'categoryName' => $category['categoryName'],
'statCategoryType' => $category['categoryType'],
'userCategoryRankLabel' => '0',
'userCategoryRankPosition' => '0',
'userCategoryPoints' => prettyNumber($stats[$category['pointsKey']]),
'statsUnit' => $_Lang['_statUnit'],
];

$recordsCurrentKey = $category['recordsCurrentKey'];
$recordsOldKey = $category['recordsOldKey'];

if (
!isset($stats[$recordsCurrentKey]) ||
$stats[$recordsCurrentKey] <= 0
) {
$categoriesHTML[] = parsetemplate($tplBodyCache['statCategoryRow'], $categoryTplBodyParams);

continue;
}

$oldPosition = $stats[$recordsOldKey];
$currentPosition = $stats[$recordsCurrentKey];

$positionDifference = $oldPosition - $currentPosition;
$positionDifferenceLabel = null;

if ($positionDifference > 0) {
$positionDifferenceLabel = "<span class=\"lime\">(+{$positionDifference})</span>";
} elseif ($positionDifference == 0) {
$positionDifferenceLabel = "<span class=\"lightblue\">(*)</span>";
} else {
$positionDifferenceLabel = "<span class=\"red\">({$positionDifference})</span>";
}

$categoryTplBodyParams['userCategoryRankPosition'] = $currentPosition;
$categoryTplBodyParams['userCategoryRankLabel'] = implode(
' ',
[
$currentPosition,
$positionDifferenceLabel,
]
);

$categoriesHTML[] = parsetemplate($tplBodyCache['statCategoryRow'], $categoryTplBodyParams);
}

$tplBodyParams = [
'statsCategories' => implode('', $categoriesHTML),
];
$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,6 @@
<table width="100%" align="center">
<tr>
<td colspan="2" class="c pad3">{Statistics}</td>
</tr>
{statsCategories}
</table>
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,4 @@
<tr>
<th><a href="stats.php?range={userCategoryRankPosition}&amp;type={statCategoryType}">{categoryName}</a></th>
<th>{userCategoryRankLabel}<br/><span class="grey">{userCategoryPoints} {statsUnit}</span></th>
</tr>
Loading

0 comments on commit b20e0a2

Please sign in to comment.