Completed
Push — master ( e7ee3b...814f23 )
by De Cramer
17s
created

WindowHelpDetailsFactory::setLineFactory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
4
namespace eXpansion\Framework\Core\Plugins\Gui;
5
use eXpansion\Framework\Core\Helpers\Translations;
6
use eXpansion\Framework\Core\Model\ChatCommand\AbstractChatCommand;
7
use eXpansion\Framework\Core\Model\Gui\Factory\LineFactory;
8
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface;
9
10
/**
11
 * Class WindowHelpDetailsFactory
12
 *
13
 * @package eXpansion\Framework\Core\Plugins\Gui;
14
 * @author  oliver de Cramer <[email protected]>
15
 */
16
class WindowHelpDetailsFactory extends WindowFactory
17
{
18
    /** @var AbstractChatCommand */
19
    protected $currentCommand = null;
20
21
    /** @var  Translations */
22
    protected $translationsHelper;
23
24
    /** @var LineFactory */
25
    protected $lineFactory;
26
27
    /** @var LineFactory */
28
    protected $titleLineFactory;
29
30
    /**
31
     * @param LineFactory $lineFactory
32
     */
33
    public function setLineFactory($lineFactory)
34
    {
35
        $this->lineFactory = $lineFactory;
36
    }
37
38
    /**
39
     * @param LineFactory $titleLineFactory
40
     */
41
    public function setTitleLineFactory($titleLineFactory)
42
    {
43
        $this->titleLineFactory = $titleLineFactory;
44
    }
45
46
    /**
47
     * @param Translations $translationsHelper
48
     */
49
    public function setTranslationsHelper($translationsHelper)
50
    {
51
        $this->translationsHelper = $translationsHelper;
52
    }
53
54
    /**
55
     * @inheritdoc
56
     */
57
    protected function createContent(ManialinkInterface $manialink)
58
    {
59
        $manialink->setData('command', $this->currentCommand);
60
    }
61
62
    /**
63
     * @inheritdoc
64
     */
65
    protected function updateContent(ManialinkInterface $manialink)
66
    {
67
        $manialink->getContentFrame()->removeAllChildren();
68
69
        /** @var AbstractChatCommand $command */
70
        $command = $manialink->getData('command');
71
72
        $column1Width = $manialink->getContentFrame()->getWidth() * (2/3);
73
        $column2Width = $manialink->getContentFrame()->getWidth() * (1/3) - 1;
74
75
        /*
76
         * COLUMN 1 Description of the chat command
77
         */
78
        $descriptionTitle = $this->titleLineFactory->create(
79
            20,
80
            [
81
                [
82
                    'text' => 'expansion_core.windows.chat_commands_description.description',
83
                    'width' => 1,
84
                    'translatable' => true
85
                ]
86
            ],
87
            0
88
        );
89
        $manialink->addChild($descriptionTitle);
90
91
        $descriptionLabel = $this->lineFactory->create(
92
            $column1Width - 21,
93
            [
94
                [
95
                    'text' => $command->getDescription(),
96
                    'width' => 1,
97
                    'translatable' => true
98
99
                ]
100
            ],
101
            0,
102
            16,
103
            true,
104
            4
105
        );
106
        $descriptionLabel->setPosition(21, 0);
107
        $manialink->addChild($descriptionLabel);
108
109
        $helpTitle = $this->titleLineFactory->create(
110
            20,
111
            [
112
                [
113
                    'text' => 'expansion_core.windows.chat_commands_description.help',
114
                    'width' => 1,
115
                    'translatable' => true
116
                ]
117
            ],
118
            0
119
        );
120
        $helpTitle->setPosition(0, -1 * ($descriptionLabel->getHeight() + 1));
121
        $manialink->addChild($helpTitle);
122
123
        $helpLabel = $this->lineFactory->create(
124
            $column1Width - 21,
125
            [
126
                [
127
                    'text' => "Use '/" . $this->currentCommand->getCommand() . " -h' to get help on the usage of the command.",
128
                    'width' => 1,
129
                    'translatable' => false
130
131
                ]
132
            ],
133
            0,
134
            8,
135
            true,
136
            2
137
        );
138
        $helpLabel->setPosition(21, $helpTitle->getY());
139
        $manialink->addChild($helpLabel);
140
141
        /**
142
         * COLUMN2 Aliases of the chat command.
143
         */
144
        $aliasesTitle = $this->titleLineFactory->create(
145
            20,
146
            [
147
                [
148
                    'text' => 'expansion_core.windows.chat_commands_description.aliases',
149
                    'width' => 1,
150
                    'translatable' => true
151
                ]
152
            ],
153
            0
154
        );
155
        $aliasesTitle->setPosition($column1Width + 1, 0);
156
        $manialink->addChild($aliasesTitle);
157
158
        $posY = 0;
159
        foreach ($command->getAliases() as $i => $alias) {
160
            $aliasesLabel = $this->lineFactory->create(
161
                $column2Width - 21,
162
                [
163
                    [
164
                        'text' => "/$alias",
165
                        'width' => 1,
166
                        'translatable' => false
167
168
                    ]
169
                ],
170
                $i
171
            );
172
            $aliasesLabel->setPosition($column1Width + 22, $posY);
173
            $manialink->addChild($aliasesLabel);
174
175
            $posY -= ($aliasesLabel->getHeight() + 1);
176
        }
177
    }
178
179
    /**
180
     * @param null $currentCommand
181
     */
182
    public function setCurrentCommand($currentCommand)
183
    {
184
        $this->currentCommand = $currentCommand;
185
    }
186
}
187