-
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 morale rendering code to own component
- Loading branch information
Showing
7 changed files
with
180 additions
and
74 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
66 changes: 66 additions & 0 deletions
66
modules/overview/screens/Overview/components/Morale/Morale.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,66 @@ | ||
<?php | ||
|
||
namespace UniEngine\Engine\Modules\Overview\Screens\Overview\Components\Morale; | ||
|
||
use UniEngine\Engine\Modules\Overview\Screens\Overview\Components\Morale; | ||
|
||
/** | ||
* @param array $props | ||
* @param arrayRef $props['user'] | ||
* @param number $props['currentTimestamp'] | ||
*/ | ||
function render($props) { | ||
global $_Lang; | ||
|
||
if (!MORALE_ENABLED) { | ||
return [ | ||
'componentHTML' => '', | ||
'globalJS' => '', | ||
]; | ||
} | ||
|
||
$user = &$props['user']; | ||
$currentTimestamp = $props['currentTimestamp']; | ||
|
||
$localTemplateLoader = createLocalTemplateLoader(__DIR__); | ||
|
||
$moraleLevelColor = null; | ||
|
||
if ($user['morale_level'] > 0) { | ||
$moraleLevelColor = 'lime'; | ||
} else if ($user['morale_level'] == 0) { | ||
$moraleLevelColor = ''; | ||
} else if ($user['morale_level'] > -50) { | ||
$moraleLevelColor = 'orange'; | ||
} else { | ||
$moraleLevelColor = 'red'; | ||
} | ||
|
||
$moraleStatusData = Morale\Utils\getMoraleStatusData([ | ||
'user' => &$user, | ||
'currentTimestamp' => $currentTimestamp, | ||
]); | ||
|
||
$tplBodyParams = [ | ||
'Insert_Morale_Level' => $user['morale_level'], | ||
'Insert_Morale_Color' => $moraleLevelColor, | ||
'Insert_Morale_Status' => $moraleStatusData['text'], | ||
'Insert_Morale_Points' => sprintf( | ||
$_Lang['Box_Morale_Points'], | ||
prettyNumber($user['morale_points']) | ||
), | ||
]; | ||
$tplBodyParams = array_merge($_Lang, $tplBodyParams); | ||
|
||
$componentHTML = parsetemplate( | ||
$localTemplateLoader('body'), | ||
$tplBodyParams | ||
); | ||
|
||
return [ | ||
'componentHTML' => $componentHTML, | ||
'globalJS' => $moraleStatusData['globalJS'], | ||
]; | ||
} | ||
|
||
?> |
80 changes: 80 additions & 0 deletions
80
modules/overview/screens/Overview/components/Morale/Morale.utils.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,80 @@ | ||
<?php | ||
|
||
namespace UniEngine\Engine\Modules\Overview\Screens\Overview\Components\Morale\Utils; | ||
|
||
/** | ||
* @param array $props | ||
* @param arrayRef $props['user'] | ||
* @param number $props['currentTimestamp'] | ||
*/ | ||
function getMoraleStatusData($props) { | ||
global $_Lang; | ||
|
||
$user = &$props['user']; | ||
$currentTimestamp = $props['currentTimestamp']; | ||
|
||
$userMoraleLevel = $user['morale_level']; | ||
|
||
if ($userMoraleLevel == 0) { | ||
return [ | ||
'text' => $_Lang['Box_Morale_NoChanges'], | ||
'globalJS' => null, | ||
]; | ||
} | ||
|
||
$moraleSentiment = ( | ||
$userMoraleLevel > 0 ? | ||
'Pos' : | ||
'Neg' | ||
); | ||
$moraleDroptimeRemaining = $user['morale_droptime'] - $currentTimestamp; | ||
|
||
if ($moraleDroptimeRemaining > 0) { | ||
return [ | ||
'text' => sprintf( | ||
$_Lang["Box_Morale_DropStartIn_{$moraleSentiment}"], | ||
pretty_time( | ||
$moraleDroptimeRemaining, | ||
true, | ||
'D' | ||
) | ||
), | ||
'globalJS' => InsertJavaScriptChronoApplet( | ||
'morale', | ||
'', | ||
$user['morale_droptime'], | ||
true | ||
), | ||
]; | ||
} | ||
|
||
$moraleDropInterval = ( | ||
$userMoraleLevel > 0 ? | ||
MORALE_DROPINTERVAL_POSITIVE : | ||
MORALE_DROPINTERVAL_NEGATIVE | ||
); | ||
$moraleDropNextTimepoint = ( | ||
($user['morale_lastupdate'] == 0) ? | ||
($user['morale_droptime'] + $moraleDropInterval) : | ||
($user['morale_lastupdate'] + $moraleDropInterval) | ||
); | ||
|
||
return [ | ||
'text' => sprintf( | ||
$_Lang["Box_Morale_Dropping_{$moraleSentiment}"], | ||
pretty_time( | ||
$moraleDropNextTimepoint - $currentTimestamp, | ||
true, | ||
'D' | ||
) | ||
), | ||
'globalJS' => InsertJavaScriptChronoApplet( | ||
'morale', | ||
'', | ||
$moraleDropNextTimepoint, | ||
true | ||
), | ||
]; | ||
} | ||
|
||
?> |
18 changes: 18 additions & 0 deletions
18
modules/overview/screens/Overview/components/Morale/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,18 @@ | ||
<table width="100%" align="center"> | ||
<tr> | ||
<td class="c pad3"> | ||
<b class="fl">{Box_Morale_Header}</b> | ||
<a class="fr" href="morale_info.php" title="{Box_Morale_InfoTitle}">(?)</a> | ||
</td> | ||
</tr> | ||
<tr> | ||
<th> | ||
<b class="{Insert_Morale_Color}">{Insert_Morale_Level}%</b><br/> | ||
{Insert_Morale_Status} | ||
</th> | ||
</tr> | ||
<tr> | ||
<th>{Insert_Morale_Points}</th> | ||
</tr> | ||
</table> | ||
<br/> |
5 changes: 5 additions & 0 deletions
5
modules/overview/screens/Overview/components/Morale/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"); | ||
|
||
?> |
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 was deleted.
Oops, something went wrong.