1 from logging
import info
, debug
2 from sys
import platform
, exit
3 from os
import environ
, system
4 from webbrowser
import open_new_tab
5 from panda3d
.core
import Texture
, TextNode
, WindowProperties
, LVector2i
, \
6 TextProperties
, TextPropertiesManager
7 from direct
.gui
.DirectGui
import DirectButton
, DirectCheckButton
, \
8 DirectOptionMenu
, DirectSlider
, DirectCheckButton
9 from direct
.gui
.DirectGuiGlobals
import FLAT
10 from direct
.gui
.OnscreenText
import OnscreenText
11 from lib
.engine
.gui
.cursor
import MouseCursor
16 def __init__(self
, fsm
, lang_mgr
, opt_file
, music
, pipeline
):
18 self
._lang
_mgr
= lang_mgr
19 self
._opt
_file
= opt_file
21 self
._pipeline
= pipeline
22 self
._cursor
= MouseCursor(
23 'assets/buttons/arrowUpLeft.png', (.04, 1, .04), (.5, .5, .5, 1),
25 self
._font
= base
.loader
.load_font('assets/fonts/Hanken-Book.ttf')
27 self
._font
.set_pixels_per_unit(60)
28 self
._font
.set_minfilter(Texture
.FTLinearMipmapLinear
)
29 self
._font
.set_outline((0, 0, 0, 1), .8, .2)
33 'text_font': self
._font
,
34 'text_fg': (.9, .9, .9, 1),
36 'frameColor': (.4, .4, .4, .14),
37 'rolloverSound': loader
.load_sfx('assets/audio/sfx/rollover.ogg'),
38 'clickSound': loader
.load_sfx('assets/audio/sfx/click.ogg')}
39 self
._common
_btn
= {'frameSize': (-3.8, 3.8, -.6, 1.2)} | self
._common
40 hlc
= self
._common
_btn
['frameColor']
41 hlc
= (hlc
[0] + .2, hlc
[1] + .2, hlc
[2] + .2, hlc
[3] + .2)
43 'item_frameColor': self
._common
_btn
['frameColor'],
44 'popupMarker_frameColor': self
._common
_btn
['frameColor'],
45 'item_relief': self
._common
_btn
['relief'],
46 'item_text_font': self
._common
_btn
['text_font'],
47 'item_text_fg': self
._common
_btn
['text_fg'],
49 'highlightColor': hlc
,
50 'text_align': TextNode
.A_center
,
52 f_s
= self
._common
_opt
['frameSize']
53 self
._common
_opt
['frameSize'] = f_s
[0], f_s
[1] - .56, f_s
[2], f_s
[3]
54 self
._common
_slider
= self
._common |
{
56 'thumb_frameColor': (.4, .4, .4, .4),
59 del self
._common
_slider
['rolloverSound']
60 del self
._common
_slider
['clickSound']
65 self
._widgets
+= [DirectButton(
66 text
=_('Play'), pos
=(0, 1, .6), command
=self
.on_play
,
68 self
._widgets
+= [DirectButton(
69 text
=_('Options'), pos
=(0, 1, .2), command
=self
.on_options
,
71 self
._widgets
+= [DirectButton(
72 text
=_('Credits'), pos
=(0, 1, -.2), command
=self
.on_credits
,
74 self
._widgets
+= [DirectButton(
75 text
=_('Exit'), pos
=(0, 1, -.6), command
=lambda: exit(),
78 def _set_options(self
):
80 self
._lang
_funcs
= [lambda: _('English'), lambda: _('Italian')]
81 items
= [fnc() for fnc
in self
._lang
_funcs
]
85 }[self
._opt
_file
['settings']['language']]
86 btn
= DirectOptionMenu(
87 text
=_('Language'), items
=items
, initialitem
=inititem
,
88 pos
=(0, 1, .8), command
=self
.on_language
, **self
._common
_opt
)
89 btn
.popupMenu
['frameColor'] = self
._common
_btn
['frameColor']
90 btn
.popupMenu
['relief'] = self
._common
_btn
['relief']
91 self
._widgets
+= [btn
]
92 self
._widgets
+= [OnscreenText(
93 _('Volume'), pos
=(-.1, .55), font
=self
._common
['text_font'],
94 scale
=self
._common
['scale'], fg
=self
._common
['text_fg'],
95 align
=TextNode
.A_right
)]
96 self
._widgets
+= [DirectSlider(
98 value
=self
._opt
_file
['settings']['volume'],
99 command
=self
.on_volume
,
100 **self
._common
_slider
)]
101 self
._slider
= self
._widgets
[-1]
102 self
._widgets
+= [DirectCheckButton(
103 text
=_('Fullscreen'), pos
=(0, 1, .3), command
=self
.on_fullscreen
,
104 indicator_frameColor
=self
._common
_opt
['highlightColor'],
105 indicator_relief
=self
._common
_btn
['relief'],
106 indicatorValue
=self
._opt
_file
['settings']['fullscreen'],
108 res
= self
._opt
_file
['settings']['resolution']
109 d_i
= base
.pipe
.get_display_information()
111 return d_i
.get_display_mode_width(idx
), \
112 d_i
.get_display_mode_height(idx
)
114 _res(idx
) for idx
in range(d_i
.get_total_display_modes())]
115 resolutions
= list(set(resolutions
))
116 resolutions
= sorted(resolutions
)
117 resolutions
= [(str(_res
[0]), str(_res
[1])) for _res
in resolutions
]
118 resolutions
= ['x'.join(_res
) for _res
in resolutions
]
120 res
= resolutions
[-1]
121 btn
= DirectOptionMenu(
122 text
=_('Resolution'), items
=resolutions
, initialitem
=res
,
123 pos
=(0, 1, .05), command
=self
.on_resolution
, **self
._common
_opt
)
124 btn
.popupMenu
['frameColor'] = self
._common
_btn
['frameColor']
125 btn
.popupMenu
['relief'] = self
._common
_btn
['relief']
126 self
._widgets
+= [btn
]
127 self
._widgets
+= [DirectCheckButton(
128 text
=_('Antialiasing'), pos
=(0, 1, -.2), command
=self
.on_aa
,
129 indicator_frameColor
=self
._common
_opt
['highlightColor'],
130 indicator_relief
=self
._common
_btn
['relief'],
131 indicatorValue
=self
._opt
_file
['settings']['antialiasing'],
133 self
._widgets
+= [DirectCheckButton(
134 text
=_('Shadows'), pos
=(0, 1, -.45), command
=self
.on_shadows
,
135 indicator_frameColor
=self
._common
_opt
['highlightColor'],
136 indicator_relief
=self
._common
_btn
['relief'],
137 indicatorValue
=self
._opt
_file
['settings']['shadows'],
139 self
._widgets
+= [DirectButton(
140 text
=_('Back'), pos
=(0, 1, -.8), command
=self
.on_back
,
143 def _set_credits(self
):
145 tp_scale
= TextProperties()
146 tp_scale
.set_text_scale(.64)
147 TextPropertiesManager
.getGlobalPtr().setProperties('scale', tp_scale
)
148 self
._widgets
+= [OnscreenText(
149 _('Code and gfx\n \1scale\1Flavio Calva\2\n\n\nMusic\n \1scale\1Stefan Grossmann\2'),
150 pos
=(-.9, .55), font
=self
._common
['text_font'],
151 scale
=self
._common
['scale'], fg
=self
._common
['text_fg'],
152 align
=TextNode
.A_left
)]
153 self
._widgets
+= [DirectButton(
154 text
=_('Website'), pos
=(-.6, 1, .29), command
=self
.on_website
,
155 **self
._common
_btn |
{'scale': .08})]
156 self
._widgets
+= [OnscreenText(
157 _('Supporters\n \1scale\1rdb\2\n \1scale\1Luisa Tenuta\2\n \1scale\1Damiana Ercolani\2'),
158 pos
=(.1, .55), font
=self
._common
['text_font'],
159 scale
=self
._common
['scale'], fg
=self
._common
['text_fg'],
160 align
=TextNode
.A_left
)]
161 self
._widgets
+= [DirectButton(
162 text
=_('Back'), pos
=(0, 1, -.8), command
=self
.on_back
,
166 self
._fsm
.demand('Scene')
168 def on_options(self
):
172 def on_credits(self
):
176 def on_language(self
, arg
):
178 _('English'): 'en_EN',
179 _('Italian'): 'it_IT'}[arg
]
180 self
._lang
_mgr
.set_lang(lang_code
)
181 self
._opt
_file
['settings']['language'] = lang_code
[:2]
182 self
._opt
_file
.store()
186 self
._opt
_file
['settings']['volume'] = self
._slider
['value']
187 self
._music
.set_volume(self
._slider
['value'])
189 def on_fullscreen(self
, arg
):
190 props
= WindowProperties()
191 props
.set_fullscreen(arg
)
192 base
.win
.request_properties(props
)
193 self
._opt
_file
['settings']['fullscreen'] = int(arg
)
194 self
._opt
_file
.store()
196 def on_resolution(self
, arg
):
197 props
= WindowProperties()
198 props
.set_size(LVector2i(*[int(_res
) for _res
in arg
.split('x')]))
199 base
.win
.request_properties(props
)
200 self
._opt
_file
['settings']['resolution'] = arg
201 self
._opt
_file
.store()
203 def on_aa(self
, arg
):
204 self
._pipeline
.msaa_samples
= 4 if arg
else 1
205 debug(f
'msaa: {self._pipeline.msaa_samples}')
206 self
._opt
_file
['settings']['antialiasing'] = int(arg
)
207 self
._opt
_file
.store()
209 def on_shadows(self
, arg
):
210 self
._pipeline
.enable_shadows
= int(arg
)
211 debug(f
'shadows: {self._pipeline.enable_shadows}')
212 self
._opt
_file
['settings']['shadows'] = int(arg
)
213 self
._opt
_file
.store()
215 def on_website(self
):
216 if platform
.startswith('linux'):
217 environ
['LD_LIBRARY_PATH'] = ''
218 system('xdg-open https://www.ya2.it')
220 open_new_tab('https://www.ya2.it')
223 self
._opt
_file
.store()
228 [wdg
.destroy() for wdg
in self
._widgets
]
229 self
._cursor
.destroy()