afde786acd74074649bae264ef7ce2230a79be1a
2 from xmlrpc
.client
import ServerProxy
3 from direct
.gui
.DirectGui
import DirectButton
4 from ya2
.utils
.gfx
import DirectGuiMixin
5 from pmachines
.gui
.base_page
import BasePage
8 class MainPage(BasePage
):
10 def __init__(self
, menu
, test_positions
, gui_args
, running_functional_tests
, scenes
, application_fsm
):
11 super().__init
__(menu
, running_functional_tests
)
12 self
._running
_functional
_tests
= running_functional_tests
13 self
._test
_positions
= test_positions
15 self
._application
_fsm
= application_fsm
16 for k
in list(self
._test
_positions
.keys()): del self
._test
_positions
[k
]
18 self
._widgets
+= [DirectButton(
19 text
=_('Play'), pos
=(0, 1, .6), command
=self
.on_play
,
21 self
._widgets
[-1].__class
__ = type('DirectButtonMixed', (DirectButton
, DirectGuiMixin
), {})
22 self
._test
_positions
['play'] = self
._widgets
[-1].pos_pixel()
23 self
._widgets
+= [DirectButton(
24 text
=_('Options'), pos
=(0, 1, .2), command
=self
.on_options
,
26 self
._widgets
[-1].__class
__ = type('DirectButtonMixed', (DirectButton
, DirectGuiMixin
), {})
27 self
._test
_positions
['options'] = self
._widgets
[-1].pos_pixel()
28 self
._widgets
+= [DirectButton(
29 text
=_('Credits'), pos
=(0, 1, -.2), command
=self
.on_credits
,
31 self
._widgets
[-1].__class
__ = type('DirectButtonMixed', (DirectButton
, DirectGuiMixin
), {})
32 self
._test
_positions
['credits'] = self
._widgets
[-1].pos_pixel()
35 if self
._running
_functional
_tests
:
36 ServerProxy('http://localhost:7000').destroy()
38 self
._widgets
+= [DirectButton(
39 text
=_('Exit'), pos
=(0, 1, -.6), command
=lambda: btn_exit(),
41 self
._widgets
[-1].__class
__ = type('DirectButtonMixed', (DirectButton
, DirectGuiMixin
), {})
42 self
._test
_positions
['exit'] = self
._widgets
[-1].pos_pixel()
43 self
._rearrange
_width
()
44 self
.accept('enforce_resolution', self
.enforce_resolution
)
47 self
._menu
.set_page('options')
51 self
._menu
.set_page('credits')
55 self
._menu
.set_page('play')
58 def _rearrange_width(self
):
60 for wdg
in self
._widgets
:
61 t_n
= wdg
.component('text0')
62 u_l
= t_n
.textNode
.get_upper_left_3d()
63 l_r
= t_n
.textNode
.get_lower_right_3d()
64 max_width
= max(l_r
[0] - u_l
[0], max_width
)
65 for wdg
in self
._widgets
:
66 m_w
= max_width
/ 2 + .8
67 wdg
['frameSize'] = -m_w
, m_w
, wdg
['frameSize'][2], wdg
['frameSize'][3]