core: Add click index to ClipEvent::Release

This commit is contained in:
Kamil Jarosz 2024-07-07 14:56:04 +02:00 committed by Nathan Adams
parent 6fa2f41eee
commit 0b64bc681a
6 changed files with 16 additions and 9 deletions

View File

@ -484,7 +484,7 @@ impl<'gc> TInteractiveObject<'gc> for Avm1Button<'gc> {
Some(ButtonActionCondition::OVER_UP_TO_OVER_DOWN),
static_data.over_to_down_sound.as_ref(),
),
ClipEvent::Release => (
ClipEvent::Release { .. } => (
ButtonState::Over,
Some(ButtonActionCondition::OVER_DOWN_TO_OVER_UP),
static_data.down_to_over_sound.as_ref(),

View File

@ -753,7 +753,9 @@ impl<'gc> TInteractiveObject<'gc> for Avm2Button<'gc> {
ClipEvent::DragOut { .. } => (ButtonState::Over, None),
ClipEvent::DragOver { .. } => (ButtonState::Down, None),
ClipEvent::Press { .. } => (ButtonState::Down, static_data.over_to_down_sound.as_ref()),
ClipEvent::Release => (ButtonState::Over, static_data.down_to_over_sound.as_ref()),
ClipEvent::Release { .. } => {
(ButtonState::Over, static_data.down_to_over_sound.as_ref())
}
ClipEvent::ReleaseOutside => (ButtonState::Up, static_data.over_to_up_sound.as_ref()),
ClipEvent::MouseUpInside => (ButtonState::Up, static_data.over_to_up_sound.as_ref()),
ClipEvent::RollOut { .. } => (ButtonState::Up, static_data.over_to_up_sound.as_ref()),

View File

@ -328,7 +328,7 @@ pub trait TInteractiveObject<'gc>:
Avm2::dispatch_event(&mut activation.context, avm2_event, target).into()
}
ClipEvent::Release => {
ClipEvent::Release { .. } => {
let read = self.raw_interactive();
let last_click = read.last_click;
let this_click = Instant::now();

View File

@ -3001,7 +3001,7 @@ impl<'gc> TInteractiveObject<'gc> for MovieClip<'gc> {
) -> ClipEventResult {
let frame_name = match event {
ClipEvent::RollOut { .. } | ClipEvent::ReleaseOutside => Some(WStr::from_units(b"_up")),
ClipEvent::RollOver { .. } | ClipEvent::Release | ClipEvent::DragOut { .. } => {
ClipEvent::RollOver { .. } | ClipEvent::Release { .. } | ClipEvent::DragOut { .. } => {
Some(WStr::from_units(b"_over"))
}
ClipEvent::Press { .. } | ClipEvent::DragOver { .. } => {

View File

@ -267,7 +267,10 @@ pub enum ClipEvent<'gc> {
/// This is a targeted equivalent to `MouseUp` and is available in both
/// AVM1 and AVM2. The target of this event is the last target of the
/// `Press` event.
Release,
Release {
/// The index of this click, same as the index of the last [`ClipEvent::Press`] event.
index: usize,
},
/// Right mouse button was released inside a previously-pressed display object.
///
@ -350,7 +353,7 @@ impl<'gc> ClipEvent<'gc> {
ClipEvent::Press { .. } => Some(ClipEventFlag::PRESS),
ClipEvent::RollOut { .. } => Some(ClipEventFlag::ROLL_OUT),
ClipEvent::RollOver { .. } => Some(ClipEventFlag::ROLL_OVER),
ClipEvent::Release => Some(ClipEventFlag::RELEASE),
ClipEvent::Release { .. } => Some(ClipEventFlag::RELEASE),
ClipEvent::ReleaseOutside => Some(ClipEventFlag::RELEASE_OUTSIDE),
ClipEvent::Unload => Some(ClipEventFlag::UNLOAD),
_ => None,
@ -407,7 +410,7 @@ impl<'gc> ClipEvent<'gc> {
ClipEvent::Press { .. } => Some("onPress"),
ClipEvent::RollOut { .. } => Some("onRollOut"),
ClipEvent::RollOver { .. } => Some("onRollOver"),
ClipEvent::Release => Some("onRelease"),
ClipEvent::Release { .. } => Some("onRelease"),
ClipEvent::ReleaseOutside => Some("onReleaseOutside"),
ClipEvent::Unload => Some("onUnload"),
_ => None,

View File

@ -1233,7 +1233,7 @@ impl Player {
// The button/clip is pressed and then immediately released.
// We do not have to wait for KeyUp.
focus.handle_clip_event(context, ClipEvent::Press { index: 0 });
focus.handle_clip_event(context, ClipEvent::Release);
focus.handle_clip_event(context, ClipEvent::Release { index: 0 });
}
if let PlayerEvent::KeyDown { key_code, .. } = event {
@ -1621,7 +1621,9 @@ impl Player {
}
if released_inside {
let event = match button {
MouseButton::Left => ClipEvent::Release,
MouseButton::Left => ClipEvent::Release {
index: context.input.last_click_index(),
},
MouseButton::Right => ClipEvent::RightRelease,
MouseButton::Middle => ClipEvent::MiddleRelease,
_ => unreachable!(),