1 from panda3d
.core
import LPoint3f
, Texture
2 from direct
.gui
.OnscreenImage
import OnscreenImage
3 from direct
.gui
.DirectGui
import DirectFrame
, DirectButton
4 from direct
.gui
.DirectGuiGlobals
import NORMAL
, B1PRESS
, B1RELEASE
, FLAT
5 from ya2
.utils
.gfx
import DirectGuiMixin
8 class AugmentedDirectFrame(DirectFrame
):
10 def __init__(self
, *args
, **kwargs
):
11 self
.__delta
_drag
= kwargs
['delta_drag']
12 del kwargs
['delta_drag']
13 collapse_pos
= kwargs
['collapse_pos']
14 del kwargs
['collapse_pos']
15 pos_mgr
= kwargs
['pos_mgr']
17 frame_name
= kwargs
['frame_name']
18 del kwargs
['frame_name']
19 super().__init
__(*args
, **kwargs
)
20 self
.initialiseoptions(AugmentedDirectFrame
)
21 self
['state'] = NORMAL
22 self
.bind(B1PRESS
, self
.__drag
)
23 self
.bind(B1RELEASE
, self
.__drop
)
24 self
.__start
_drag
_pos
= None
25 self
.__update
_dd
_task
= taskMgr
.add(self
.__update
_dd
, 'update_dd', sort
=-50)
26 fcols
= (.4, .4, .4, .14), (.3, .3, .3, .05)
27 self
.__collapse
_btn
= DirectButton(
28 image
=self
.__load
_images
_btn
('up', 'gray'), scale
=.05,
30 parent
=self
, command
=self
.__on
_collapse
, state
=NORMAL
, relief
=FLAT
,
32 rolloverSound
=loader
.load_sfx('assets/audio/sfx/rollover.ogg'),
33 clickSound
=loader
.load_sfx('assets/audio/sfx/click.ogg'))
34 self
.__collapse
_btn
.__class
__ = type('DirectButtonMixed', (DirectButton
, DirectGuiMixin
), {})
35 pos_mgr
[f
'collapse_button_{frame_name}'] = self
.__collapse
_btn
.pos_pixel()
36 _font
= base
.loader
.load_font(
37 'assets/fonts/Hanken-Book.ttf')
39 _font
.set_pixels_per_unit(60)
40 _font
.set_minfilter(Texture
.FTLinearMipmapLinear
)
41 _font
.set_outline((0, 0, 0, 1), .8, .2)
45 'text_fg': (.9, .9, .9, 1),
47 'frameColor': (.4, .4, .4, .14),
48 'rolloverSound': loader
.load_sfx(
49 'assets/audio/sfx/rollover.ogg'),
50 'clickSound': loader
.load_sfx(
51 'assets/audio/sfx/click.ogg')}
52 tooltip_args
= _common
['text_font'], _common
['scale'], _common
['text_fg']
53 self
.__collapse
_btn
.set_tooltip(_('Collapse/Expand'), *tooltip_args
)
54 self
.__collapsed
= False
56 def __drag(self
, mouse_pos
=None):
57 m
= mouse_pos
.get_mouse()
58 m
= LPoint3f(m
[0], 0, m
[1])
59 from_origin
= m
- self
.parent
.get_pos()
60 self
.__start
_drag
_pos
= self
.get_pos(), from_origin
62 def __drop(self
, mouse_pos
=None):
63 self
.__start
_drag
_pos
= None
65 def __update_dd(self
, task
):
66 if base
.mouseWatcherNode
.has_mouse() and self
.__start
_drag
_pos
:
67 m
= base
.mouseWatcherNode
.get_mouse()
68 m
= LPoint3f(m
[0], 0, m
[1])
69 delta
= m
- self
.__start
_drag
_pos
[1]
70 new_pos
= self
.__start
_drag
_pos
[0] + delta
+ self
.__delta
_drag
74 def __load_img_btn(self
, path
, col
):
75 img
= OnscreenImage('assets/images/buttons/%s.dds' % path
)
76 img
.set_transparency(True)
81 def __load_images_btn(self
, path
, col
):
84 (.6, .6, .6, 1), # ready
86 (.8, .8, .8, 1), # rollover
92 (.4, .1, .1, .4)]}[col
]
93 return [self
.__load
_img
_btn
(path
, col
) for col
in colors
]
95 def __on_collapse(self
):
96 self
.__expand
() if self
.__collapsed
else self
.__collapse
()
99 self
.__collapsed
= True
100 for c
in self
.children
:
102 self
.__collapse
_btn
.show()
103 self
.__collapse
_btn
['image'] = self
.__load
_images
_btn
('down', 'gray')
104 self
.__prev
_fs
= self
['frameSize']
105 self
['frameSize'] = (0, 0, 0, 0)
108 self
.__collapsed
= False
109 for c
in self
.children
:
111 self
.__collapse
_btn
['image'] = self
.__load
_images
_btn
('up', 'gray')
112 self
['frameSize'] = self
.__prev
_fs
116 taskMgr
.remove(self
.__update
_dd
_task
)