core: Implement forced button mode flag for AVM2.

This commit is contained in:
David Wendt 2021-12-04 19:08:50 -05:00 committed by Mike Welsh
parent 7b6f8aef06
commit cbeb24f3f8
2 changed files with 67 additions and 5 deletions

View File

@ -113,6 +113,44 @@ pub fn set_sound_transform<'gc>(
Ok(Value::Undefined) Ok(Value::Undefined)
} }
/// Implements `buttonMode`'s getter
pub fn button_mode<'gc>(
_activation: &mut Activation<'_, 'gc, '_>,
this: Option<Object<'gc>>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error> {
if let Some(mc) = this
.and_then(|o| o.as_display_object())
.and_then(|o| o.as_movie_clip())
{
return Ok(mc.forced_button_mode().into());
}
Ok(Value::Undefined)
}
/// Implements `buttonMode`'s setter
pub fn set_button_mode<'gc>(
activation: &mut Activation<'_, 'gc, '_>,
this: Option<Object<'gc>>,
args: &[Value<'gc>],
) -> Result<Value<'gc>, Error> {
if let Some(mc) = this
.and_then(|o| o.as_display_object())
.and_then(|o| o.as_movie_clip())
{
let forced_button_mode = args
.get(0)
.cloned()
.unwrap_or(Value::Undefined)
.coerce_to_boolean();
mc.set_forced_button_mode(&mut activation.context, forced_button_mode);
}
Ok(Value::Undefined)
}
/// Construct `Sprite`'s class. /// Construct `Sprite`'s class.
pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>> { pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>> {
let class = Class::new( let class = Class::new(
@ -144,6 +182,7 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>
Some(sound_transform), Some(sound_transform),
Some(set_sound_transform), Some(set_sound_transform),
), ),
("buttonMode", Some(button_mode), Some(set_button_mode)),
]; ];
write.define_public_builtin_instance_properties(mc, PUBLIC_INSTANCE_PROPERTIES); write.define_public_builtin_instance_properties(mc, PUBLIC_INSTANCE_PROPERTIES);

View File

@ -87,7 +87,13 @@ pub struct MovieClipData<'gc> {
is_focusable: bool, is_focusable: bool,
has_focus: bool, has_focus: bool,
enabled: bool, enabled: bool,
/// Show a hand cursor when the clip is in button mode.
use_hand_cursor: bool, use_hand_cursor: bool,
/// Force enable button mode, which causes all mouse-related events to
/// trigger on this clip rather than any input-eligible children.
button_mode: bool,
last_queued_script_frame: Option<FrameNumber>, last_queued_script_frame: Option<FrameNumber>,
queued_script_frame: Option<FrameNumber>, queued_script_frame: Option<FrameNumber>,
queued_goto_frame: Option<FrameNumber>, queued_goto_frame: Option<FrameNumber>,
@ -116,6 +122,7 @@ impl<'gc> MovieClip<'gc> {
has_focus: false, has_focus: false,
enabled: true, enabled: true,
use_hand_cursor: true, use_hand_cursor: true,
button_mode: false,
last_queued_script_frame: None, last_queued_script_frame: None,
queued_script_frame: None, queued_script_frame: None,
queued_goto_frame: None, queued_goto_frame: None,
@ -150,6 +157,7 @@ impl<'gc> MovieClip<'gc> {
has_focus: false, has_focus: false,
enabled: true, enabled: true,
use_hand_cursor: true, use_hand_cursor: true,
button_mode: false,
last_queued_script_frame: None, last_queued_script_frame: None,
queued_script_frame: None, queued_script_frame: None,
queued_goto_frame: None, queued_goto_frame: None,
@ -187,6 +195,7 @@ impl<'gc> MovieClip<'gc> {
has_focus: false, has_focus: false,
enabled: true, enabled: true,
use_hand_cursor: true, use_hand_cursor: true,
button_mode: false,
last_queued_script_frame: None, last_queued_script_frame: None,
queued_script_frame: None, queued_script_frame: None,
queued_goto_frame: None, queued_goto_frame: None,
@ -221,6 +230,7 @@ impl<'gc> MovieClip<'gc> {
has_focus: false, has_focus: false,
enabled: true, enabled: true,
use_hand_cursor: true, use_hand_cursor: true,
button_mode: false,
last_queued_script_frame: None, last_queued_script_frame: None,
queued_script_frame: None, queued_script_frame: None,
queued_goto_frame: None, queued_goto_frame: None,
@ -1675,8 +1685,21 @@ impl<'gc> MovieClip<'gc> {
self.0.read().tag_stream_len() self.0.read().tag_stream_len()
} }
pub fn forced_button_mode(self) -> bool {
self.0.read().button_mode
}
pub fn set_forced_button_mode(
self,
context: &mut UpdateContext<'_, 'gc, '_>,
button_mode: bool,
) {
self.0.write(context.gc_context).button_mode = button_mode;
}
pub fn is_button_mode(&self, context: &mut UpdateContext<'_, 'gc, '_>) -> bool { pub fn is_button_mode(&self, context: &mut UpdateContext<'_, 'gc, '_>) -> bool {
if self if self.forced_button_mode()
|| self
.0 .0
.read() .read()
.clip_event_flags .clip_event_flags