Completed
Pull Request — master (#167)
by
unknown
03:03
created

CurrentMapWidgetFactory::createContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 62
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 62
c 0
b 0
f 0
ccs 0
cts 20
cp 0
rs 9.4743
cc 1
eloc 25
nc 1
nop 1
crap 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace eXpansion\Bundle\WidgetCurrentMap\Plugins\Gui;
4
5
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface;
6
use eXpansion\Framework\Core\Model\Gui\Widget;
7
use eXpansion\Framework\Core\Model\Gui\WidgetFactoryContext;
8
use eXpansion\Framework\Core\Plugins\Gui\WidgetFactory;
9
use eXpansion\Framework\Gui\Components\uiLabel;
10
use eXpansion\Framework\Gui\Ui\Factory;
11
use FML\Script\ScriptLabel;
12
13
class CurrentMapWidgetFactory extends WidgetFactory
14
{
15
16
    /***
17
     * MenuFactory constructor.
18
     *
19
     * @param                      $name
20
     * @param                      $sizeX
21
     * @param                      $sizeY
22
     * @param null                 $posX
23
     * @param null                 $posY
24
     * @param WidgetFactoryContext $context
25
     * @param Factory              $uiFactory
26
     */
27
    public function __construct(
28
        $name,
29
        $sizeX,
30
        $sizeY,
31
        $posX,
32
        $posY,
33
        WidgetFactoryContext $context,
34
        Factory $uiFactory
35
    ) {
36
        parent::__construct($name, $sizeX, $sizeY, $posX, $posY, $context);
37
38
        $this->uiFactory = $uiFactory;
39
    }
40
41
    /**
42
     * @param Widget|ManialinkInterface $manialink
43
     */
44
    protected function createContent(ManialinkInterface $manialink)
45
    {
46
        parent::createContent($manialink);
47
48
49
        $rows = $this->uiFactory->createLayoutRow(0, 0, [], -1);
50
        $manialink->addChild($rows);
51
52
53
        $lbl = $this->uiFactory->createLabel("empty value", uiLabel::TYPE_TITLE, "MapName");
54
        $lbl->setAlign("right", "center");
55
        $lbl->setTextSize(3)->setSize(40, 4);
56
        $rows->addChild($lbl);
57
58
        $lbl = $this->uiFactory->createLabel("empty value", uiLabel::TYPE_NORMAL, "AuthorName");
59
        $lbl->setAlign("right", "center");
60
        $lbl->setTextSize(2)->setSize(40, 4);
61
        $rows->addChild($lbl);
62
63
        $lbl = $this->uiFactory->createLabel("empty value", uiLabel::TYPE_TITLE, "AuthorTime");
64
        $lbl->setAlign("right", "center");
65
        $lbl->setTextSize(1)->setSize(20, 4);
66
        $rows->addChild($lbl);
67
68
69
        $manialink->getFmlManialink()->getScript()->addScriptFunction("",
70
            <<<EOL
71
            
72
            Text TimeToText(Integer intime) {
73
                declare time = MathLib::Abs(intime);
74
                declare Integer cent = time % 1000;	
75
                declare Integer sec = (time / 1000) % 60;
76
                declare Integer min = time / 60000;
77
                declare Integer hour = time / 3600000;
78
                declare Text sign = "";
79
                if (intime < 0)  {
80
                    sign = "-";
81
                }
82
                
83
                if (hour > 0) {
84
                    return sign ^ hour ^ ":" ^ TextLib::FormatInteger(min,2) ^ ":" ^ TextLib::FormatInteger(sec,2) ^ "." ^ TextLib::FormatInteger(cent,3);
85
                } 
86
                return sign ^ TextLib::FormatInteger(min,2) ^ ":" ^ TextLib::FormatInteger(sec,2) ^ "." ^ TextLib::FormatInteger(cent,3);                                
87
            }
88
            
89
EOL
90
        );
91
92
        $manialink->getFmlManialink()->getScript()->addCustomScriptLabel(ScriptLabel::OnInit,
93
            <<<EOL
94
            
95
            (Page.GetFirstChild("MapName") as CMlLabel).Value = Map.MapName;            
96
            (Page.GetFirstChild("AuthorName") as CMlLabel).Value = Map.AuthorNickName;
97
            (Page.GetFirstChild("AuthorTime") as CMlLabel).Value = TimeToText(Map.TMObjective_AuthorTime);
98
                                                                                          
99
EOL
100
        );
101
102
        $manialink->addChild($rows);
103
104
105
    }
106
107
108
    protected function updateContent(ManialinkInterface $manialink)
109
    {
110
        parent::updateContent($manialink);
111
    }
112
113
114
}
115