Skip to content

Commit

Permalink
GH-230 Move quick transport rendering to a separate component
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Jul 7, 2022
1 parent 4687ac7 commit f05f60f
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 53 deletions.
1 change: 1 addition & 0 deletions modules/overview/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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/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,91 @@
<?php

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

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

/**
* @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 = (
$planet['metal'] +
$planet['crystal'] +
$planet['deuterium']
);

$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>
29 changes: 4 additions & 25 deletions overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,31 +535,10 @@
}

// --- Transporters ----------------------------
$resourcesTransportNeededStorage = (
$_Planet['metal'] +
$_Planet['crystal'] +
$_Planet['deuterium']
);

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

$parse["transportShips__{$shipId}__name"] = $_Lang['tech'][$shipId];
$parse["transportShips__{$shipId}__requiredCount"] = prettyNumber($requiredShipsCount);
$parse["transportShips__{$shipId}__remainingCount"] = str_replace('-', '', prettyColorNumber($remainingShipsCount, true));
}

if(isPro() AND $_User['current_planet'] != $_User['settings_mainPlanetID'])
{
$GetQuickResPlanet = doquery("SELECT `name`, `galaxy`, `system`, `planet` FROM {{table}} WHERE `id` = {$_User['settings_mainPlanetID']};", 'planets', true);
$parse['QuickResSend_Button'] = sprintf($_Lang['QuickResSend_Button'], $GetQuickResPlanet['name'], $GetQuickResPlanet['galaxy'], $GetQuickResPlanet['system'], $GetQuickResPlanet['planet']);
}
else
{
$parse['Hide_QuickResButton'] = ' style="display: none;"';
}
$parse['Component_QuickTransport'] = Overview\Screens\Overview\Components\ResourcesTransport\render([
'user' => &$_User,
'planet' => &$_Planet,
])['componentHTML'];

// --- Flying Fleets Table ---
$Result_GetFleets = Flights\Fetchers\fetchCurrentFlights([ 'userId' => $_User['id'] ]);
Expand Down
29 changes: 1 addition & 28 deletions templates/default_template/overview_body.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -256,34 +256,7 @@ $(document).ready(function()
</th>
</tr>
<tr class="inv"><td></td></tr>
<tr>
<td colspan="3" class="c pad3">{ResourcesTransport}</td>
</tr>
<tr>
<th>&nbsp;</th>
<th>{Box_transRequired}</th>
<th>{Box_transMissing_Stay}</th>
</tr>
<tr>
<th>{transportShips__202__name}</th>
<th>{transportShips__202__requiredCount}</th>
<th>{transportShips__202__remainingCount}</th>
</tr>
<tr>
<th>{transportShips__203__name}</th>
<th>{transportShips__203__requiredCount}</th>
<th>{transportShips__203__remainingCount}</th>
</tr>
<tr>
<th>{transportShips__217__name}</th>
<th>{transportShips__217__requiredCount}</th>
<th>{transportShips__217__remainingCount}</th>
</tr>
<tr{Hide_QuickResButton}>
<th class="pad5" colspan="3">
<input type="button" value="{QuickResSend_Button}" id="quickres"/>
</th>
</tr>
{Component_QuickTransport}
<tr class="inv" {hide_other_planets}><td></td></tr>
<tr {hide_other_planets}>
<td colspan="3" class="c">{OtherPlanets_header}</td>
Expand Down

0 comments on commit f05f60f

Please sign in to comment.