Skip to content

Commit f05f60f

Browse files
committed
GH-230 Move quick transport rendering to a separate component
1 parent 4687ac7 commit f05f60f

File tree

7 files changed

+121
-53
lines changed

7 files changed

+121
-53
lines changed

modules/overview/_includes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
include($includePath . './screens/FirstLogin/utils/helpers/getReferrerTasksData.helper.php');
2626

2727
include($includePath . './screens/Overview/components/PlanetsListElement/PlanetsListElement.component.php');
28+
include($includePath . './screens/Overview/components/ResourcesTransport/ResourcesTransport.component.php');
2829

2930
include($includePath . './screens/PlanetNameChange/PlanetNameChange.screen.php');
3031
include($includePath . './screens/PlanetNameChange/PlanetNameChange.utils.php');
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
namespace UniEngine\Engine\Modules\Overview\Screens\Overview\Components\ResourcesTransport;
4+
5+
use UniEngine\Engine\Includes\Helpers\World\Elements;
6+
7+
/**
8+
* @param array $props
9+
* @param arrayRef $props['user']
10+
* @param arrayRef $props['planet']
11+
*/
12+
function render($props) {
13+
global $_Lang, $_Vars_ElementCategories;
14+
15+
$user = &$props['user'];
16+
$planet = &$props['planet'];
17+
18+
$localTemplateLoader = createLocalTemplateLoader(__DIR__);
19+
$tplBodyCache = [
20+
'body' => $localTemplateLoader('body'),
21+
'shipRow' => $localTemplateLoader('shipRow'),
22+
];
23+
24+
$resourcesTotalSum = (
25+
$planet['metal'] +
26+
$planet['crystal'] +
27+
$planet['deuterium']
28+
);
29+
30+
$shipRows = [];
31+
32+
foreach ($_Vars_ElementCategories['units']['transport'] as $shipId) {
33+
$requiredShipsCount = ceil($resourcesTotalSum / getShipsStorageCapacity($shipId));
34+
$currentShipsCount = Elements\getElementCurrentCount($shipId, $planet, $user);
35+
$remainingShipsCount = $currentShipsCount - $requiredShipsCount;
36+
37+
$shipRows[] = parsetemplate($tplBodyCache['shipRow'], [
38+
'shipName' => $_Lang['tech'][$shipId],
39+
'requiredCount' => prettyNumber($requiredShipsCount),
40+
'remainingCount' => str_replace('-', '', prettyColorNumber($remainingShipsCount, true)),
41+
]);
42+
}
43+
44+
$shouldDisplayQuickTransportBtn = (
45+
isPro($user) &&
46+
$user['current_planet'] != $user['settings_mainPlanetID']
47+
);
48+
$quickTransportBtnText = '';
49+
50+
if ($shouldDisplayQuickTransportBtn) {
51+
$getQuickTransportTargetPlanetQuery = (
52+
"SELECT " .
53+
"`name`, `galaxy`, `system`, `planet` " .
54+
"FROM {{table}} " .
55+
"WHERE " .
56+
"`id` = {$user['settings_mainPlanetID']} " .
57+
";"
58+
);
59+
$quickTransportTargetPlanet = doquery($getQuickTransportTargetPlanetQuery, 'planets', true);
60+
61+
$quickTransportBtnText = sprintf(
62+
$_Lang['QuickResSend_Button'],
63+
$quickTransportTargetPlanet['name'],
64+
$quickTransportTargetPlanet['galaxy'],
65+
$quickTransportTargetPlanet['system'],
66+
$quickTransportTargetPlanet['planet']
67+
);
68+
}
69+
70+
$tplBodyParams = [
71+
'shipRowsHTML' => implode('', $shipRows),
72+
'Hide_QuickResButton' => (
73+
$shouldDisplayQuickTransportBtn ?
74+
'' :
75+
'style="display: none;"'
76+
),
77+
'QuickResSend_Button' => $quickTransportBtnText,
78+
];
79+
$tplBodyParams = array_merge($_Lang, $tplBodyParams);
80+
81+
$componentHTML = parsetemplate(
82+
$tplBodyCache['body'],
83+
$tplBodyParams
84+
);
85+
86+
return [
87+
'componentHTML' => $componentHTML,
88+
];
89+
}
90+
91+
?>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<tr>
2+
<td colspan="3" class="c pad3">{ResourcesTransport}</td>
3+
</tr>
4+
<tr>
5+
<th>&nbsp;</th>
6+
<th>{Box_transRequired}</th>
7+
<th>{Box_transMissing_Stay}</th>
8+
</tr>
9+
{shipRowsHTML}
10+
<tr {Hide_QuickResButton}>
11+
<th class="pad5" colspan="3">
12+
<input type="button" value="{QuickResSend_Button}" id="quickres"/>
13+
</th>
14+
</tr>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
header("Location: ../index.php");
4+
5+
?>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<tr>
2+
<th>{shipName}</th>
3+
<th>{requiredCount}</th>
4+
<th>{remainingCount}</th>
5+
</tr>

overview.php

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -535,31 +535,10 @@
535535
}
536536

537537
// --- Transporters ----------------------------
538-
$resourcesTransportNeededStorage = (
539-
$_Planet['metal'] +
540-
$_Planet['crystal'] +
541-
$_Planet['deuterium']
542-
);
543-
544-
foreach ($_Vars_ElementCategories['units']['transport'] as $shipId) {
545-
$requiredShipsCount = ceil($resourcesTransportNeededStorage / getShipsStorageCapacity($shipId));
546-
$currentShipsCount = Elements\getElementCurrentCount($shipId, $_Planet, $_User);
547-
$remainingShipsCount = $currentShipsCount - $requiredShipsCount;
548-
549-
$parse["transportShips__{$shipId}__name"] = $_Lang['tech'][$shipId];
550-
$parse["transportShips__{$shipId}__requiredCount"] = prettyNumber($requiredShipsCount);
551-
$parse["transportShips__{$shipId}__remainingCount"] = str_replace('-', '', prettyColorNumber($remainingShipsCount, true));
552-
}
553-
554-
if(isPro() AND $_User['current_planet'] != $_User['settings_mainPlanetID'])
555-
{
556-
$GetQuickResPlanet = doquery("SELECT `name`, `galaxy`, `system`, `planet` FROM {{table}} WHERE `id` = {$_User['settings_mainPlanetID']};", 'planets', true);
557-
$parse['QuickResSend_Button'] = sprintf($_Lang['QuickResSend_Button'], $GetQuickResPlanet['name'], $GetQuickResPlanet['galaxy'], $GetQuickResPlanet['system'], $GetQuickResPlanet['planet']);
558-
}
559-
else
560-
{
561-
$parse['Hide_QuickResButton'] = ' style="display: none;"';
562-
}
538+
$parse['Component_QuickTransport'] = Overview\Screens\Overview\Components\ResourcesTransport\render([
539+
'user' => &$_User,
540+
'planet' => &$_Planet,
541+
])['componentHTML'];
563542

564543
// --- Flying Fleets Table ---
565544
$Result_GetFleets = Flights\Fetchers\fetchCurrentFlights([ 'userId' => $_User['id'] ]);

templates/default_template/overview_body.tpl

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -256,34 +256,7 @@ $(document).ready(function()
256256
</th>
257257
</tr>
258258
<tr class="inv"><td></td></tr>
259-
<tr>
260-
<td colspan="3" class="c pad3">{ResourcesTransport}</td>
261-
</tr>
262-
<tr>
263-
<th>&nbsp;</th>
264-
<th>{Box_transRequired}</th>
265-
<th>{Box_transMissing_Stay}</th>
266-
</tr>
267-
<tr>
268-
<th>{transportShips__202__name}</th>
269-
<th>{transportShips__202__requiredCount}</th>
270-
<th>{transportShips__202__remainingCount}</th>
271-
</tr>
272-
<tr>
273-
<th>{transportShips__203__name}</th>
274-
<th>{transportShips__203__requiredCount}</th>
275-
<th>{transportShips__203__remainingCount}</th>
276-
</tr>
277-
<tr>
278-
<th>{transportShips__217__name}</th>
279-
<th>{transportShips__217__requiredCount}</th>
280-
<th>{transportShips__217__remainingCount}</th>
281-
</tr>
282-
<tr{Hide_QuickResButton}>
283-
<th class="pad5" colspan="3">
284-
<input type="button" value="{QuickResSend_Button}" id="quickres"/>
285-
</th>
286-
</tr>
259+
{Component_QuickTransport}
287260
<tr class="inv" {hide_other_planets}><td></td></tr>
288261
<tr {hide_other_planets}>
289262
<td colspan="3" class="c">{OtherPlanets_header}</td>

0 commit comments

Comments
 (0)