1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use amethyst_audio::SourceHandle;
use amethyst_core::specs::prelude::{Component, DenseVecStorage};
use amethyst_renderer::TextureHandle;

/// When this component is added to a UI element with a `UiImage`
/// it will change that image based on mouse interaction.
/// Requires `MouseReactive`.
pub struct OnUiActionImage {
    /// Default image
    pub(crate) normal_image: Option<TextureHandle>,
    /// Image used when the mouse hovers over this element
    pub(crate) hover_image: Option<TextureHandle>,
    /// Image used when element is pressed
    pub(crate) press_image: Option<TextureHandle>,
}

impl OnUiActionImage {
    /// A constructor for this component
    pub fn new(
        normal_image: Option<TextureHandle>,
        hover_image: Option<TextureHandle>,
        press_image: Option<TextureHandle>,
    ) -> Self {
        Self {
            normal_image,
            hover_image,
            press_image,
        }
    }
}

impl Component for OnUiActionImage {
    type Storage = DenseVecStorage<Self>;
}

/// When this component is added to a UI element
/// it will play sounds based on mouse interaction.
/// Requires `MouseReactive`.
pub struct OnUiActionSound {
    /// Sound made when this button is hovered over
    pub(crate) hover_sound: Option<SourceHandle>,
    /// Sound made when this button is pressed.
    pub(crate) press_sound: Option<SourceHandle>,
    /// Sound made when this button is released.
    pub(crate) release_sound: Option<SourceHandle>,
}

impl OnUiActionSound {
    /// A constructor for this component
    pub fn new(
        hover_sound: Option<SourceHandle>,
        press_sound: Option<SourceHandle>,
        release_sound: Option<SourceHandle>,
    ) -> Self {
        Self {
            hover_sound,
            press_sound,
            release_sound,
        }
    }
}

impl Component for OnUiActionSound {
    type Storage = DenseVecStorage<Self>;
}