1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace ManiaLive\Gui\Windows;
13:
14: use ManiaLib\Gui\Elements\Bgs1;
15: use ManiaLib\Gui\Elements\Label;
16: use ManiaLib\Gui\Elements\Quad;
17: use ManiaLib\Gui\Layouts\Line;
18: use ManiaLive\Gui\Controls\ButtonResizable;
19: use ManiaLive\Gui\Controls\Frame;
20:
21: 22: 23:
24: final class Dialog extends \ManiaLive\Gui\Panel
25: {
26: const YES = 1;
27: const NO = 2;
28: const RETRY = 4;
29: const APPLY = 8;
30: const OK = 16;
31: const CANCEL = 32;
32:
33: static protected $labels = array(
34: self::YES => 'Yes',
35: self::NO => 'No',
36: self::RETRY => 'Retry',
37: self::APPLY => 'Apply',
38: self::OK => 'OK',
39: self::CANCEL => 'Cancel'
40: );
41:
42: protected $text;
43: protected $options;
44:
45: protected $answer;
46: protected $buttons;
47:
48: protected function onConstruct()
49: {
50: parent::onConstruct();
51: $this->setBackgroundStyle(Bgs1::BgWindow2);
52:
53: $this->text = new Label();
54: $this->text->setPosition(2, -17);
55: $this->text->enableAutonewline();
56: $this->addComponent($this->text);
57:
58: $this->options = new Frame(0, 0, new Line());
59: $this->options->setHalign('center');
60: $this->addComponent($this->options);
61: }
62:
63: protected function onResize($oldX, $oldY)
64: {
65: parent::onResize($oldX, $oldY);
66:
67: $this->text->setSize($this->sizeX - 4, $this->sizeY - 6);
68:
69: $this->options->setSizeX($this->sizeX);
70: $this->options->getLayout()->setSizeX($this->sizeX);
71: $this->options->setPosition($this->sizeX / 2, 8 - $this->sizeY);
72:
73: $options = $this->options->getComponents();
74: if(count($options))
75: {
76: $optionSizeX = ($this->sizeX - 2.5) / count($options);
77: foreach($options as $ui)
78: {
79: $ui->setSizeX($optionSizeX);
80: $ui->setPosX(1.25);
81: }
82: }
83: }
84:
85: function setText($text)
86: {
87: $this->text->setText($text);
88: }
89:
90: function onButton($login, $button)
91: {
92: $this->answer = $button;
93: $this->hide($login);
94: }
95:
96: function getAnswer()
97: {
98: return $this->answer;
99: }
100:
101: function setButtons($buttons)
102: {
103: $this->buttons = $buttons;
104: $this->options->clearComponents();
105:
106: $options = array();
107: for($i = 1; $i <= $this->buttons; $i <<= 1)
108: if($this->buttons & $i)
109: $options[] = $i;
110: $optionSizeX = ($this->sizeX - 2.5) / count($options);
111:
112: foreach($options as $option)
113: {
114: $ui = new ButtonResizable($optionSizeX, 7);
115: $ui->setPosX(1.25);
116: $ui->setText(self::$labels[$option]);
117: $ui->setAction($this->createAction(array($this, 'onButton'), $option));
118: $this->options->addComponent($ui);
119: }
120: }
121:
122: function destroy()
123: {
124: parent::destroy();
125: $this->options->destroy();
126: }
127: }
128:
129: ?>