Skip to content

Commit

Permalink
Merge pull request #240 from mdziekon/gh-230-more-overview-components
Browse files Browse the repository at this point in the history
GH-230 | Overview - Various components refactor (part 1)
  • Loading branch information
mdziekon authored Jul 17, 2022
2 parents 59bf5a7 + 8bd6ce3 commit d995eac
Show file tree
Hide file tree
Showing 39 changed files with 854 additions and 186 deletions.
2 changes: 1 addition & 1 deletion language/en/overview.lang
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ $_Lang['BuildJS_Complete'] = 'Completed';
$_Lang['BuildJS_Continue'] = 'Continue';

// Free PremiumItems Box
$_Lang['FreePremItem_Text'] = 'You\'ve received free Premium Items [%s] as a reward from the Game or Administration!<br/>Go to the Ship to check your items list!';
$_Lang['FreePremItem_Text'] = 'You\'ve received free Premium Items (%s) as a reward from the Game or Administration!<br/>Go to the Ship to check your items list!';

// Vacation Mode Box
$_Lang['VacationModeBox_Text'] = 'Your account is currently in <a class="orange" href="settings.php"><u>Vacation Mode</u></a>';
Expand Down
2 changes: 1 addition & 1 deletion language/fr/overview.lang
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ $_Lang['BuildJS_Complete'] = 'Terminé';
$_Lang['BuildJS_Continue'] = 'Continuer';

// Free PremiumItems Box
$_Lang['FreePremItem_Text'] = 'Tu as reçu un cadeau Premium [%s] de la part du jeu ou des administrateurs !<br/>Regarde dans la Boutique ce que tu as reçu !';
$_Lang['FreePremItem_Text'] = 'Tu as reçu un cadeau Premium (%s) de la part du jeu ou des administrateurs !<br/>Regarde dans la Boutique ce que tu as reçu !';

// Vacation Mode Box
$_Lang['VacationModeBox_Text'] = 'Ton compte est actuellement en <a class="orange" href="settings.php"><u>mode vacances</u></a>.';
Expand Down
2 changes: 1 addition & 1 deletion language/pl/overview.lang
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ $_Lang['BuildJS_Complete'] = 'Zakończono';
$_Lang['BuildJS_Continue'] = 'Kontynuuj';

// Free PremiumItems Box
$_Lang['FreePremItem_Text'] = 'Otrzymałeś Darmowe Towary Premium [%s] (Konto Pro, Oficerowie itp.) od Systemu lub Administracji!<br/>Przejdź do Sklepu aby przejrzeć listę!';
$_Lang['FreePremItem_Text'] = 'Otrzymałeś Darmowe przedmioty Premium (%s) od Systemu lub Administracji!<br/>Przejdź do Sklepu aby przejrzeć listę!';

// Vacation Mode Box
$_Lang['VacationModeBox_Text'] = 'Twoje konto jest obecnie w <a class="orange" href="settings.php"><u>Trybie Urlopu</u></a>';
Expand Down
14 changes: 14 additions & 0 deletions modules/overview/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,27 @@
include($includePath . './screens/FirstLogin/utils/effects/updateUserOnFirstLogin.effect.php');
include($includePath . './screens/FirstLogin/utils/helpers/getReferrerTasksData.helper.php');

include($includePath . './screens/Overview/components/AccountActivationInfoBox/AccountActivationInfoBox.component.php');
include($includePath . './screens/Overview/components/AdminAlerts/AdminAlerts.component.php');
include($includePath . './screens/Overview/components/CombatStatsList/CombatStatsList.component.php');
include($includePath . './screens/Overview/components/CombatStatsList/CombatStatsList.utils.php');
include($includePath . './screens/Overview/components/EmailChangeInfo/EmailChangeInfo.component.php');
include($includePath . './screens/Overview/components/FeedbackMessagesDisplay/FeedbackMessagesDisplay.component.php');
include($includePath . './screens/Overview/components/FeedbackMessagesDisplay/FeedbackMessagesDisplay.utils.php');
include($includePath . './screens/Overview/components/GiftItemsInfoBox/GiftItemsInfoBox.component.php');
include($includePath . './screens/Overview/components/Morale/Morale.component.php');
include($includePath . './screens/Overview/components/Morale/Morale.utils.php');
include($includePath . './screens/Overview/components/NewMessagesInfo/NewMessagesInfo.component.php');
include($includePath . './screens/Overview/components/NewSurveysInfo/NewSurveysInfo.component.php');
include($includePath . './screens/Overview/components/NoobProtectionInfoBox/NoobProtectionInfoBox.component.php');
include($includePath . './screens/Overview/components/NoobProtectionInfoBox/NoobProtectionInfoBox.utils.php');
include($includePath . './screens/Overview/components/NoobProtectionInfoBox/utils/helpers.utils.php');
include($includePath . './screens/Overview/components/NoobProtectionInfoBox/utils/effects/turnOffProtection.effect.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/Overview/components/StatsList/StatsList.utils.php');
include($includePath . './screens/Overview/components/VacationInfoBox/VacationInfoBox.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,30 @@
<?php

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

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

if (isUserAccountActivated($props['user'])) {
return [
'componentHTML' => '',
];
}

$localTemplateLoader = createLocalTemplateLoader(__DIR__);

$componentHTML = parsetemplate(
$localTemplateLoader('body'),
$_Lang
);

return [
'componentHTML' => $componentHTML,
];
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<tr>
<th class="c pad5 orange" colspan="3">
{ActivationInfo_Text}
</th>
</tr>
<tr>
<th style="visibility: hidden;">&nbsp;</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,118 @@
<?php

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

use UniEngine\Engine\Modules\Overview\Screens\Overview\Components\CombatStatsList;

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

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

$statsData = CombatStatsList\Utils\getUserCombatStats([
'userId' => $props['userId'],
]);

$categories = [
'allBattles' => [
'label' => $_Lang['Box_battlesAll'],
'statsTableKeys' => [
'ustat_raids_won',
'ustat_raids_draw',
'ustat_raids_lost',
'ustat_raids_inAlly',
],
],
'battlesWon' => [
'label' => $_Lang['Box_battlesWon'],
'statsTableKeys' => [
'ustat_raids_won',
],
],
'battlesWonUnited' => [
'label' => $_Lang['Box_battlesACSWon'],
'statsTableKeys' => [
'ustat_raids_acs_won',
],
'colorClass' => 'orange',
],
'battlesDrawn' => [
'label' => $_Lang['Box_battlesDraw'],
'statsTableKeys' => [
'ustat_raids_draw',
],
],
'battlesLost' => [
'label' => $_Lang['Box_battlesLost'],
'statsTableKeys' => [
'ustat_raids_lost',
],
],
'battlesInAlly' => [
'label' => $_Lang['Box_battlesInAlly'],
'statsTableKeys' => [
'ustat_raids_inAlly',
],
],
'missileStrikes' => [
'label' => $_Lang['Box_missileAttacks'],
'statsTableKeys' => [
'ustat_raids_missileAttack',
],
],
];

$categoriesHTML = [];

foreach ($categories as $categoryKey => $category) {
$categorySubValues = array_map_withkeys($category['statsTableKeys'], function ($key) use ($statsData) {
return $statsData[$key];
});
$categoryTotalValue = array_sum($categorySubValues);

$categoryTplBodyParams = [
'statCategoryColorClass' => (
!empty($category['colorClass']) ?
$category['colorClass'] :
''
),
'statCategoryLabel' => $category['label'],
'statCategoryValue' => prettyNumber($categoryTotalValue),
];

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

$tplBodyParams = [
'categoryRow_allBattles' => $categoriesHTML['allBattles'],
'categoryRow_battlesWon' => $categoriesHTML['battlesWon'],
'categoryRow_battlesWonUnited' => $categoriesHTML['battlesWonUnited'],
'categoryRow_battlesDrawn' => $categoriesHTML['battlesDrawn'],
'categoryRow_battlesLost' => $categoriesHTML['battlesLost'],
'categoryRow_battlesInAlly' => $categoriesHTML['battlesInAlly'],
'categoryRow_missileStrikes' => $categoriesHTML['missileStrikes'],
];
$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,30 @@
<?php

namespace UniEngine\Engine\Modules\Overview\Screens\Overview\Components\CombatStatsList\Utils;

/**
* @param array $props
* @param array $props['userId']
*/
function getUserCombatStats($props) {
$userId = $props['userId'];

$query = (
"SELECT " .
"`ustat_raids_won`, " .
"`ustat_raids_draw`, " .
"`ustat_raids_lost`, " .
"`ustat_raids_acs_won`, " .
"`ustat_raids_inAlly`, " .
"`ustat_raids_missileAttack` " .
"FROM {{table}} " .
"WHERE " .
"`A_UserID` = {$userId} " .
"LIMIT 1 " .
";"
);

return doquery($query, 'achievements_stats', true);
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<table width="100%" align="center">
<tr>
<td colspan="2" class="c pad3">{YourBattles}</td>
</tr>
{categoryRow_allBattles}
<tr>
<th class="invNF">&nbsp;</th>
</tr>
{categoryRow_battlesWon}
{categoryRow_battlesWonUnited}
{categoryRow_battlesDrawn}
{categoryRow_battlesLost}
{categoryRow_battlesInAlly}
<tr>
<th class="invNF">&nbsp;</th>
</tr>
{categoryRow_missileStrikes}
</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 class="{statCategoryColorClass}">{statCategoryLabel}</th>
<th>{statCategoryValue}</th>
</tr>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

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

use UniEngine\Engine\Modules\Overview\Screens\Overview\Components\FeedbackMessagesDisplay;

/**
* @param array $props
* @param arrayRef $props['input']
*/
function render($props) {
$messages = FeedbackMessagesDisplay\Utils\getMessagesToDisplay($props);

if (empty($messages)) {
return [
'componentHTML' => '',
];
}

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

$parsedMessages = array_map_withkeys($messages, function ($message) use (&$tplBodyCache) {
return parsetemplate(
$tplBodyCache['messageRow'],
$message
);
});

$componentHTML = implode('', $parsedMessages);

return [
'componentHTML' => $componentHTML,
];
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace UniEngine\Engine\Modules\Overview\Screens\Overview\Components\FeedbackMessagesDisplay\Utils;

/**
* @param array $props
* @param arrayRef $props['input']
*/
function getMessagesToDisplay($props) {
global $_Lang;

$input = &$props['input'];

$messages = [];

if (
!empty($input['showmsg']) &&
$input['showmsg'] == 'abandon'
) {
$messages[] = [
'messageContent' => $_Lang['Abandon_ColonyAbandoned'],
'colorClass' => 'lime',
];
}

return $messages;
}

?>
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 colspan="3" class="pad5 {colorClass}">
{messageContent}
</th>
</tr>
Loading

0 comments on commit d995eac

Please sign in to comment.