1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Lib\Map\VisualPanel; |
6
|
|
|
|
7
|
|
|
use Stu\Component\Ship\ShipRumpEnum; |
8
|
|
|
use Stu\Lib\Map\VisualPanel\Layer\PanelLayers; |
9
|
|
|
use Stu\Orm\Entity\ShipInterface; |
10
|
|
|
|
11
|
|
|
class VisualNavPanelEntry extends SignaturePanelEntry |
12
|
|
|
{ |
13
|
|
|
private ShipInterface $currentShip; |
14
|
|
|
|
15
|
|
|
private bool $isOnShipLevel; |
16
|
|
|
|
17
|
|
|
public function __construct( |
18
|
|
|
int $x, |
19
|
|
|
int $y, |
20
|
|
|
bool $isOnShipLevel, |
21
|
|
|
PanelLayers $layers, |
22
|
|
|
ShipInterface $currentShip |
23
|
|
|
) { |
24
|
|
|
parent::__construct($x, $y, $layers); |
25
|
|
|
$this->currentShip = $currentShip; |
26
|
|
|
$this->isOnShipLevel = $isOnShipLevel; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
private function isCurrentShipPosition(): bool |
30
|
|
|
{ |
31
|
|
|
if (!$this->isOnShipLevel) { |
32
|
|
|
return false; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
if ($this->x !== $this->currentShip->getPosX()) { |
36
|
|
|
return false; |
37
|
|
|
} |
38
|
|
|
if ($this->y !== $this->currentShip->getPosY()) { |
39
|
|
|
return false; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
return true; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function getCssClass(): string |
46
|
|
|
{ |
47
|
|
|
if ($this->isCurrentShipPosition()) { |
48
|
|
|
return 'lss_current'; |
49
|
|
|
} |
50
|
|
|
return parent::getCssClass(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function isClickAble(): bool |
54
|
|
|
{ |
55
|
|
|
if ( |
56
|
|
|
$this->currentShip->getRump()->getRoleId() === ShipRumpEnum::SHIP_ROLE_SENSOR |
57
|
|
|
|| $this->currentShip->getRump()->getRoleId() === ShipRumpEnum::SHIP_ROLE_BASE |
58
|
|
|
) { |
59
|
|
|
return true; |
60
|
|
|
} |
61
|
|
|
if (!$this->currentShip->canMove()) { |
62
|
|
|
return false; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return !$this->isCurrentShipPosition() |
66
|
|
|
&& ($this->x === $this->currentShip->getPosX() || $this->y === $this->currentShip->getPosY()); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function getOnClick(): string |
70
|
|
|
{ |
71
|
|
|
if ( |
72
|
|
|
$this->currentShip->getRump()->getRoleId() === ShipRumpEnum::SHIP_ROLE_SENSOR |
73
|
|
|
|| $this->currentShip->getRump()->getRoleId() === ShipRumpEnum::SHIP_ROLE_BASE |
74
|
|
|
) { |
75
|
|
|
return sprintf( |
76
|
|
|
'showSectorScanWindow(this, %d, %d, %d, %s);', |
77
|
|
|
$this->x, |
78
|
|
|
$this->y, |
79
|
|
|
0, |
80
|
|
|
'true' |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
return sprintf('moveToPosition(%d,%d);', $this->x, $this->y); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|