-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-230 Move stats list to a component
- Loading branch information
Showing
7 changed files
with
144 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
modules/overview/screens/Overview/components/StatsList/StatsList.component.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
]; | ||
} | ||
|
||
?> |
6 changes: 6 additions & 0 deletions
6
modules/overview/screens/Overview/components/StatsList/body.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
5 changes: 5 additions & 0 deletions
5
modules/overview/screens/Overview/components/StatsList/index.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
header("Location: ../index.php"); | ||
|
||
?> |
4 changes: 4 additions & 0 deletions
4
modules/overview/screens/Overview/components/StatsList/statCategoryRow.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<tr> | ||
<th><a href="stats.php?range={userCategoryRankPosition}&type={statCategoryType}">{categoryName}</a></th> | ||
<th>{userCategoryRankLabel}<br/><span class="grey">{userCategoryPoints} {statsUnit}</span></th> | ||
</tr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters