Skip to content

Commit

Permalink
GH-224 Move fleet mission colors form to a component
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Jun 30, 2022
1 parent 884a611 commit b5ceeeb
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 20 deletions.
1 change: 1 addition & 0 deletions modules/settings/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

$includePath = $_EnginePath . 'modules/settings/';

include($includePath . './components/FleetMissionColorsForm/FleetMissionColorsForm.component.php');
include($includePath . './components/IgnoredUsersList/IgnoredUsersList.component.php');
include($includePath . './components/LanguageSelectorList/LanguageSelectorList.component.php');
include($includePath . './components/LoginHistory/LoginHistory.component.php');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace UniEngine\Engine\Modules\Settings\Components\FleetMissionColorsForm;

/**
* @param object $props
* @param number $props['missionsColorSettings']
*
* @return object $result
* @return string $result['componentHTML']
*/
function render($props) {
global $_Lang, $_Vars_FleetMissions;

$missionsColorSettings = (
!empty($props['missionsColorSettings']) ?
json_decode($props['missionsColorSettings'], true) :
[]
);

$localTemplateLoader = createLocalTemplateLoader(__DIR__);

$tplBodyCache = [
'missionRow' => $localTemplateLoader('missionRow'),
];

$getMissionColor = function ($missionId, $flightType) use ($missionsColorSettings) {
return (
isset($missionsColorSettings[$flightType][$missionId]) ?
$missionsColorSettings[$flightType][$missionId] :
null
);
};

$missionRows = array_map_withkeys(
$_Vars_FleetMissions['all'],
function ($missionId) use (&$tplBodyCache, &$_Lang, $getMissionColor) {
$tplParams = [
'MissionName' => $_Lang['type_mission'][$missionId],
'MissionID' => $missionId,
'Value_OwnFly' => $getMissionColor($missionId, 'ownfly'),
'Value_OwnComeback' => $getMissionColor($missionId, 'owncb'),
'Value_NonOwn' => $getMissionColor($missionId, 'nonown'),
];

return parsetemplate($tplBodyCache['missionRow'], $tplParams);
}
);

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

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

?>
5 changes: 5 additions & 0 deletions modules/settings/components/FleetMissionColorsForm/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

header("Location: ../index.php");

?>
27 changes: 7 additions & 20 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -1065,26 +1065,13 @@ function isInputKeyChecked($input, $key) {
])['componentHTML'];

// FleetColors - Pickers
$TPL_FleetColors_Row = gettemplate('settings_fleetcolors_row');
if(!empty($_User['settings_FleetColors']))
{
if(isset($FleetColors_NeedChange) && $FleetColors_NeedChange === true)
{
$_User['settings_FleetColors'] = stripslashes($_User['settings_FleetColors']);
}
$FleetColors = json_decode($_User['settings_FleetColors'], true);
}
foreach($_Vars_FleetMissions['all'] as $MissionID)
{
$_Lang['Insert_FleetColors_Pickers'][] = parsetemplate($TPL_FleetColors_Row, [
'MissionName' => $_Lang['type_mission'][$MissionID],
'MissionID' => $MissionID,
'Value_OwnFly' => (isset($FleetColors['ownfly'][$MissionID]) ? $FleetColors['ownfly'][$MissionID] : null),
'Value_OwnComeback' => (isset($FleetColors['owncb'][$MissionID]) ? $FleetColors['owncb'][$MissionID] : null),
'Value_NonOwn' => (isset($FleetColors['nonown'][$MissionID]) ? $FleetColors['nonown'][$MissionID] : null),
]);
}
$_Lang['Insert_FleetColors_Pickers'] = implode('', $_Lang['Insert_FleetColors_Pickers']);
$_Lang['Insert_FleetColors_Pickers'] = Settings\Components\FleetMissionColorsForm\render([
'missionsColorSettings' => (
(isset($FleetColors_NeedChange) && $FleetColors_NeedChange) ?
stripslashes($_User['settings_FleetColors']) :
$_User['settings_FleetColors']
),
])['componentHTML'];

$BodyTPL = gettemplate('settings_body');
$Page = parsetemplate($BodyTPL, $_Lang);
Expand Down

0 comments on commit b5ceeeb

Please sign in to comment.