Skip to content

Commit

Permalink
GH-224 Move skin selector rendering to a component
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Jun 27, 2022
1 parent 0f8fc8b commit 2ccc823
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 10 deletions.
1 change: 1 addition & 0 deletions modules/settings/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
include($includePath . './components/LanguageSelectorList/LanguageSelectorList.component.php');
include($includePath . './components/LoginHistoryEntry/LoginHistoryEntry.component.php');
include($includePath . './components/QuickTransportPlanetsList/QuickTransportPlanetsList.component.php');
include($includePath . './components/SkinSelectorList/SkinSelectorList.component.php');

include($includePath . './screens/InVacationMode/InVacationMode.screen.php');
include($includePath . './screens/InVacationMode/InVacationMode.utils.php');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

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

use UniEngine\Engine\Modules\Settings;

/**
* @param object $props
* @param number $props['currentUserSkinPath']
*
* @return object $result
* @return string $result['componentHTML']
*/
function render($props) {
$currentUserSkinPath = $props['currentUserSkinPath'];

$localTemplateLoader = createLocalTemplateLoader(__DIR__);

$tplBodyCache = [
'optionBody' => $localTemplateLoader('optionBody'),
];
$availableSkins = Settings\Utils\Helpers\getAvailableSkins();

$options = array_map_withkeys(
$availableSkins,
function ($skinDetails) use ($currentUserSkinPath, &$tplBodyCache) {
$isSelectedHTMLAttr = ($skinDetails['path'] == $currentUserSkinPath ? "selected" : "");

$tplParams = [
'skinPath' => $skinDetails['path'],
'isSelectedHTMLAttr' => $isSelectedHTMLAttr,
'skinName' => $skinDetails['name'],
];

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

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

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

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

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

?>
3 changes: 3 additions & 0 deletions modules/settings/components/SkinSelectorList/optionBody.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<option value="{skinPath}" {isSelectedHTMLAttr}>
{skinName}
</option>
13 changes: 3 additions & 10 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -1008,16 +1008,9 @@ function isInputKeyChecked($input, $key) {
$_Lang['DeleteMsg'] = '';
}

$availableSkins = Settings\Utils\Helpers\getAvailableSkins();

$_Lang['ServerSkins'] = array_map_withkeys($availableSkins, function ($skinDetails) use (&$_User) {
$isCurrentSkin = $skinDetails['path'] === $_User['skinpath'];
$isCurrentSkinAttr = $isCurrentSkin ? "selected=\"selected\"" : "";

return "<option value=\"{$skinDetails['path']}\" {$isCurrentSkinAttr}>{$skinDetails['name']}</option>";
});
$_Lang['ServerSkins'] = implode('', $_Lang['ServerSkins']);

$_Lang['ServerSkins'] = Settings\Components\SkinSelectorList\render([
'currentUserSkinPath' => $_User['skinpath'],
])['componentHTML'];
$_Lang['PHP_Insert_LanguageOptions'] = Settings\Components\LanguageSelectorList\render([
'currentUserLanguage' => getCurrentLang(),
])['componentHTML'];
Expand Down

0 comments on commit 2ccc823

Please sign in to comment.