Skip to content

Commit b20e0a2

Browse files
authored
Merge pull request #236 from mdziekon/gh-230-res-transport-component
GH-230 | Overview - Quick Transport & Stats list refactor
2 parents 4687ac7 + 6b5e663 commit b20e0a2

File tree

11 files changed

+269
-208
lines changed

11 files changed

+269
-208
lines changed

modules/overview/_includes.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
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');
29+
include($includePath . './screens/Overview/components/StatsList/StatsList.component.php');
2830

2931
include($includePath . './screens/PlanetNameChange/PlanetNameChange.screen.php');
3032
include($includePath . './screens/PlanetNameChange/PlanetNameChange.utils.php');
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
3+
namespace UniEngine\Engine\Modules\Overview\Screens\Overview\Components\ResourcesTransport;
4+
5+
use UniEngine\Engine\Includes\Helpers\World\Elements;
6+
use UniEngine\Engine\Includes\Helpers\World\Resources;
7+
8+
/**
9+
* @param array $props
10+
* @param arrayRef $props['user']
11+
* @param arrayRef $props['planet']
12+
*/
13+
function render($props) {
14+
global $_Lang, $_Vars_ElementCategories;
15+
16+
$user = &$props['user'];
17+
$planet = &$props['planet'];
18+
19+
$localTemplateLoader = createLocalTemplateLoader(__DIR__);
20+
$tplBodyCache = [
21+
'body' => $localTemplateLoader('body'),
22+
'shipRow' => $localTemplateLoader('shipRow'),
23+
];
24+
25+
$resourcesTotalSum = array_sum(
26+
array_map_withkeys(
27+
Resources\getKnownPillagableResourceKeys(),
28+
function ($resourceKey) use (&$user, &$planet) {
29+
return Resources\getResourceState($resourceKey, $user, $planet);
30+
}
31+
)
32+
);
33+
34+
$shipRows = [];
35+
36+
foreach ($_Vars_ElementCategories['units']['transport'] as $shipId) {
37+
$requiredShipsCount = ceil($resourcesTotalSum / getShipsStorageCapacity($shipId));
38+
$currentShipsCount = Elements\getElementCurrentCount($shipId, $planet, $user);
39+
$remainingShipsCount = $currentShipsCount - $requiredShipsCount;
40+
41+
$shipRows[] = parsetemplate($tplBodyCache['shipRow'], [
42+
'shipName' => $_Lang['tech'][$shipId],
43+
'requiredCount' => prettyNumber($requiredShipsCount),
44+
'remainingCount' => str_replace('-', '', prettyColorNumber($remainingShipsCount, true)),
45+
]);
46+
}
47+
48+
$shouldDisplayQuickTransportBtn = (
49+
isPro($user) &&
50+
$user['current_planet'] != $user['settings_mainPlanetID']
51+
);
52+
$quickTransportBtnText = '';
53+
54+
if ($shouldDisplayQuickTransportBtn) {
55+
$getQuickTransportTargetPlanetQuery = (
56+
"SELECT " .
57+
"`name`, `galaxy`, `system`, `planet` " .
58+
"FROM {{table}} " .
59+
"WHERE " .
60+
"`id` = {$user['settings_mainPlanetID']} " .
61+
";"
62+
);
63+
$quickTransportTargetPlanet = doquery($getQuickTransportTargetPlanetQuery, 'planets', true);
64+
65+
$quickTransportBtnText = sprintf(
66+
$_Lang['QuickResSend_Button'],
67+
$quickTransportTargetPlanet['name'],
68+
$quickTransportTargetPlanet['galaxy'],
69+
$quickTransportTargetPlanet['system'],
70+
$quickTransportTargetPlanet['planet']
71+
);
72+
}
73+
74+
$tplBodyParams = [
75+
'shipRowsHTML' => implode('', $shipRows),
76+
'Hide_QuickResButton' => (
77+
$shouldDisplayQuickTransportBtn ?
78+
'' :
79+
'style="display: none;"'
80+
),
81+
'QuickResSend_Button' => $quickTransportBtnText,
82+
];
83+
$tplBodyParams = array_merge($_Lang, $tplBodyParams);
84+
85+
$componentHTML = parsetemplate(
86+
$tplBodyCache['body'],
87+
$tplBodyParams
88+
);
89+
90+
return [
91+
'componentHTML' => $componentHTML,
92+
];
93+
}
94+
95+
?>
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>
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?php
2+
3+
namespace UniEngine\Engine\Modules\Overview\Screens\Overview\Components\StatsList;
4+
5+
/**
6+
* @param array $props
7+
* @param array $props['stats']
8+
*/
9+
function render($props) {
10+
global $_Lang;
11+
12+
$stats = $props['stats'];
13+
14+
$localTemplateLoader = createLocalTemplateLoader(__DIR__);
15+
$tplBodyCache = [
16+
'body' => $localTemplateLoader('body'),
17+
'statCategoryRow' => $localTemplateLoader('statCategoryRow'),
18+
];
19+
20+
$categories = [
21+
'general' => [
22+
'categoryName' => $_Lang['Box_statGeneral'],
23+
'categoryType' => '',
24+
'pointsKey' => 'total_points',
25+
'recordsCurrentKey' => 'total_old_rank',
26+
'recordsOldKey' => 'total_rank',
27+
],
28+
'buildings' => [
29+
'categoryName' => $_Lang['Box_statBuildings'],
30+
'categoryType' => '4',
31+
'pointsKey' => 'build_points',
32+
'recordsCurrentKey' => 'build_rank',
33+
'recordsOldKey' => 'build_old_rank',
34+
],
35+
'fleet' => [
36+
'categoryName' => $_Lang['Box_statFleet'],
37+
'categoryType' => '2',
38+
'pointsKey' => 'fleet_points',
39+
'recordsCurrentKey' => 'fleet_rank',
40+
'recordsOldKey' => 'fleet_old_rank',
41+
],
42+
'defenses' => [
43+
'categoryName' => $_Lang['Box_statDefense'],
44+
'categoryType' => '5',
45+
'pointsKey' => 'defs_points',
46+
'recordsCurrentKey' => 'defs_rank',
47+
'recordsOldKey' => 'defs_old_rank',
48+
],
49+
'research' => [
50+
'categoryName' => $_Lang['Box_statResearch'],
51+
'categoryType' => '3',
52+
'pointsKey' => 'tech_points',
53+
'recordsCurrentKey' => 'tech_rank',
54+
'recordsOldKey' => 'tech_old_rank',
55+
],
56+
];
57+
58+
$categoriesHTML = [];
59+
60+
foreach ($categories as $category) {
61+
$categoryTplBodyParams = [
62+
'categoryName' => $category['categoryName'],
63+
'statCategoryType' => $category['categoryType'],
64+
'userCategoryRankLabel' => '0',
65+
'userCategoryRankPosition' => '0',
66+
'userCategoryPoints' => prettyNumber($stats[$category['pointsKey']]),
67+
'statsUnit' => $_Lang['_statUnit'],
68+
];
69+
70+
$recordsCurrentKey = $category['recordsCurrentKey'];
71+
$recordsOldKey = $category['recordsOldKey'];
72+
73+
if (
74+
!isset($stats[$recordsCurrentKey]) ||
75+
$stats[$recordsCurrentKey] <= 0
76+
) {
77+
$categoriesHTML[] = parsetemplate($tplBodyCache['statCategoryRow'], $categoryTplBodyParams);
78+
79+
continue;
80+
}
81+
82+
$oldPosition = $stats[$recordsOldKey];
83+
$currentPosition = $stats[$recordsCurrentKey];
84+
85+
$positionDifference = $oldPosition - $currentPosition;
86+
$positionDifferenceLabel = null;
87+
88+
if ($positionDifference > 0) {
89+
$positionDifferenceLabel = "<span class=\"lime\">(+{$positionDifference})</span>";
90+
} elseif ($positionDifference == 0) {
91+
$positionDifferenceLabel = "<span class=\"lightblue\">(*)</span>";
92+
} else {
93+
$positionDifferenceLabel = "<span class=\"red\">({$positionDifference})</span>";
94+
}
95+
96+
$categoryTplBodyParams['userCategoryRankPosition'] = $currentPosition;
97+
$categoryTplBodyParams['userCategoryRankLabel'] = implode(
98+
' ',
99+
[
100+
$currentPosition,
101+
$positionDifferenceLabel,
102+
]
103+
);
104+
105+
$categoriesHTML[] = parsetemplate($tplBodyCache['statCategoryRow'], $categoryTplBodyParams);
106+
}
107+
108+
$tplBodyParams = [
109+
'statsCategories' => implode('', $categoriesHTML),
110+
];
111+
$tplBodyParams = array_merge($_Lang, $tplBodyParams);
112+
113+
$componentHTML = parsetemplate(
114+
$tplBodyCache['body'],
115+
$tplBodyParams
116+
);
117+
118+
return [
119+
'componentHTML' => $componentHTML,
120+
];
121+
}
122+
123+
?>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<table width="100%" align="center">
2+
<tr>
3+
<td colspan="2" class="c pad3">{Statistics}</td>
4+
</tr>
5+
{statsCategories}
6+
</table>
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<tr>
2+
<th><a href="stats.php?range={userCategoryRankPosition}&amp;type={statCategoryType}">{categoryName}</a></th>
3+
<th>{userCategoryRankLabel}<br/><span class="grey">{userCategoryPoints} {statsUnit}</span></th>
4+
</tr>

0 commit comments

Comments
 (0)