1 from logging
import info
2 from panda3d
.core
import Texture
, TextNode
, WindowProperties
, LVector2i
3 from direct
.gui
.DirectGui
import DirectButton
, DirectCheckButton
, \
4 DirectOptionMenu
, DirectSlider
, DirectCheckButton
5 from direct
.gui
.DirectGuiGlobals
import FLAT
6 from direct
.gui
.OnscreenText
import OnscreenText
11 def __init__(self
, fsm
, lang_mgr
, opt_file
, music
, pipeline
):
13 self
._lang
_mgr
= lang_mgr
14 self
._opt
_file
= opt_file
16 self
._pipeline
= pipeline
17 self
._font
= base
.loader
.load_font('assets/fonts/Hanken-Book.ttf')
19 self
._font
.set_pixels_per_unit(60)
20 self
._font
.set_minfilter(Texture
.FTLinearMipmapLinear
)
21 self
._font
.set_outline((0, 0, 0, 1), .8, .2)
25 'text_font': self
._font
,
26 'text_fg': (.9, .9, .9, 1),
28 'frameColor': (.4, .4, .4, .14),
29 'rolloverSound': loader
.load_sfx('assets/audio/sfx/rollover.ogg'),
30 'clickSound': loader
.load_sfx('assets/audio/sfx/click.ogg')}
31 self
._common
_btn
= {'frameSize': (-3.8, 3.8, -.6, 1.2)} | self
._common
32 hlc
= self
._common
_btn
['frameColor']
33 hlc
= (hlc
[0] + .2, hlc
[1] + .2, hlc
[2] + .2, hlc
[3] + .2)
35 'item_frameColor': self
._common
_btn
['frameColor'],
36 'popupMarker_frameColor': self
._common
_btn
['frameColor'],
37 'item_relief': self
._common
_btn
['relief'],
38 'item_text_font': self
._common
_btn
['text_font'],
39 'item_text_fg': self
._common
_btn
['text_fg'],
41 'highlightColor': hlc
,
42 'text_align': TextNode
.A_center
,
44 f_s
= self
._common
_opt
['frameSize']
45 self
._common
_opt
['frameSize'] = f_s
[0], f_s
[1] - .56, f_s
[2], f_s
[3]
46 self
._common
_slider
= self
._common |
{
48 'thumb_frameColor': (.4, .4, .4, .4),
51 del self
._common
_slider
['rolloverSound']
52 del self
._common
_slider
['clickSound']
57 self
._widgets
+= [DirectButton(
58 text
=_('Play'), pos
=(0, 1, .6), command
=self
.on_play
,
60 self
._widgets
+= [DirectButton(
61 text
=_('Options'), pos
=(0, 1, .3), command
=self
.on_options
,
63 self
._widgets
+= [DirectButton(
64 text
=_('Support us'), pos
=(0, 1, 0), command
=self
.on_play
,
66 self
._widgets
+= [DirectButton(
67 text
=_('Credits'), pos
=(0, 1, -.3), command
=self
.on_play
,
69 self
._widgets
+= [DirectButton(
70 text
=_('Exit'), pos
=(0, 1, -.6), command
=self
.on_play
,
73 def _set_options(self
):
75 self
._lang
_funcs
= [lambda: _('English'), lambda: _('Italian')]
76 items
= [fnc() for fnc
in self
._lang
_funcs
]
80 }[self
._opt
_file
['settings']['language']]
81 btn
= DirectOptionMenu(
82 text
=_('Language'), items
=items
, initialitem
=inititem
,
83 pos
=(0, 1, .8), command
=self
.on_language
, **self
._common
_opt
)
84 btn
.popupMenu
['frameColor'] = self
._common
_btn
['frameColor']
85 btn
.popupMenu
['relief'] = self
._common
_btn
['relief']
86 self
._widgets
+= [btn
]
87 self
._widgets
+= [OnscreenText(
88 _('Volume'), pos
=(-.1, .55), font
=self
._common
['text_font'],
89 scale
=self
._common
['scale'], fg
=self
._common
['text_fg'],
90 align
=TextNode
.A_right
)]
91 self
._widgets
+= [DirectSlider(
93 value
=self
._opt
_file
['settings']['volume'],
94 command
=self
.on_volume
,
95 **self
._common
_slider
)]
96 self
._slider
= self
._widgets
[-1]
97 self
._widgets
+= [DirectCheckButton(
98 text
=_('Fullscreen'), pos
=(0, 1, .3), command
=self
.on_fullscreen
,
99 indicator_frameColor
=self
._common
_opt
['highlightColor'],
100 indicator_relief
=self
._common
_btn
['relief'],
101 indicatorValue
=self
._opt
_file
['settings']['fullscreen'],
103 res
= self
._opt
_file
['settings']['resolution']
104 d_i
= base
.pipe
.get_display_information()
106 return d_i
.get_display_mode_width(idx
), \
107 d_i
.get_display_mode_height(idx
)
109 _res(idx
) for idx
in range(d_i
.get_total_display_modes())]
110 resolutions
= list(set(resolutions
))
111 resolutions
= sorted(resolutions
)
112 resolutions
= [(str(_res
[0]), str(_res
[1])) for _res
in resolutions
]
113 resolutions
= ['x'.join(_res
) for _res
in resolutions
]
115 res
= resolutions
[-1]
116 btn
= DirectOptionMenu(
117 text
=_('Resolution'), items
=resolutions
, initialitem
=res
,
118 pos
=(0, 1, .05), command
=self
.on_resolution
, **self
._common
_opt
)
119 btn
.popupMenu
['frameColor'] = self
._common
_btn
['frameColor']
120 btn
.popupMenu
['relief'] = self
._common
_btn
['relief']
121 self
._widgets
+= [btn
]
122 self
._widgets
+= [DirectCheckButton(
123 text
=_('Antialiasing'), pos
=(0, 1, -.2), command
=self
.on_aa
,
124 indicator_frameColor
=self
._common
_opt
['highlightColor'],
125 indicator_relief
=self
._common
_btn
['relief'],
126 indicatorValue
=self
._opt
_file
['settings']['antialiasing'],
128 self
._widgets
+= [DirectButton(
129 text
=_('Back'), pos
=(0, 1, -.8), command
=self
.on_back
,
133 self
._fsm
.demand('Scene')
135 def on_options(self
):
139 def on_language(self
, arg
):
141 _('English'): 'en_EN',
142 _('Italian'): 'it_IT'}[arg
]
143 self
._lang
_mgr
.set_lang(lang_code
)
144 self
._opt
_file
['settings']['language'] = lang_code
[:2]
145 self
._opt
_file
.store()
149 self
._opt
_file
['settings']['volume'] = self
._slider
['value']
150 self
._music
.set_volume(self
._slider
['value'])
152 def on_fullscreen(self
, arg
):
153 props
= WindowProperties()
154 props
.set_fullscreen(arg
)
155 base
.win
.request_properties(props
)
156 self
._opt
_file
['settings']['fullscreen'] = int(arg
)
157 self
._opt
_file
.store()
159 def on_resolution(self
, arg
):
160 props
= WindowProperties()
161 props
.set_size(LVector2i(*[int(_res
) for _res
in arg
.split('x')]))
162 base
.win
.request_properties(props
)
163 self
._opt
_file
['settings']['resolution'] = arg
164 self
._opt
_file
.store()
166 def on_aa(self
, arg
):
167 self
._pipeline
.msaa_samples
= 4 if arg
else 1
168 info(f
'msaa: {self._pipeline.msaa_samples}')
169 self
._pipeline
._setup
_tonemapping
()
170 self
._opt
_file
['settings']['antialiasing'] = int(arg
)
171 self
._opt
_file
.store()
174 self
._opt
_file
.store()
179 [wdg
.destroy() for wdg
in self
._widgets
]