-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialog_ui.rs
106 lines (94 loc) · 3.28 KB
/
dialog_ui.rs
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
use bevy::prelude::*;
use bevy::render::view::visibility::RenderLayers;
use bevy::text::Text2dBounds;
use crate::definitions::*;
use crate::f117_ai::*;
#[derive(Component)]
pub struct LabelAIDialogAvatar;
#[derive(Component)]
pub struct LabelAIDialogBox;
#[derive(Component)]
pub struct LabelAIDialogText;
#[allow(dead_code)]
#[derive(Resource)]
pub struct AIDialogUIState {
pub is_visible: bool,
}
pub fn setup_dialog_ui(
mut commands: Commands,
asset_server: Res<AssetServer>,
) {
let ui_state = AIDialogUIState{
is_visible: false,
};
commands.insert_resource(ui_state);
let font = asset_server.load("fonts/BigBlueTerm437NerdFontMono-Regular.ttf");
let text_style = TextStyle {
font: font.clone(),
font_size: 25.0,
color: Color::WHITE,
};
/*/
commands.spawn(
ImageBundle {
image: UiImage::new(asset_server.load("avatars/f117a.png")),
transform: Transform::from_translation(Vec3::new(300.0, 300.0, 0.0)),
..default()
}
)
.insert(RenderLayers::layer(RENDERLAYER_COCKPIT))
.insert(LabelAIDialogAvatar);
*/
commands.spawn(
SpriteBundle {
texture: asset_server.load("avatars/f117a.png"),
transform: Transform::from_translation(Vec3::new(-680.0, 450.0, 0.0)),
..default()
}
)
.insert(RenderLayers::layer(RENDERLAYER_COCKPIT))
.insert(Visibility::Hidden)
.insert(LabelAIDialogAvatar);
commands.spawn(
Text2dBundle {
text: Text::from_section("".to_string(), text_style.clone()).with_justify(JustifyText::Left),
transform: Transform::from_translation(Vec3::new(-610.0, 450.0, 1.0)),
text_2d_bounds: Text2dBounds {
size: Vec2::new(380.0, 100.0),
..default()
},
..default()
},
)
.insert(RenderLayers::layer(RENDERLAYER_COCKPIT))
.insert(Visibility::Hidden)
.insert(LabelAIDialogText);
}
pub fn update_dialog_ui(
mut text_query: Query<(&mut Text, &mut Visibility), (With<LabelAIDialogText>, Without<LabelAIDialogAvatar>)>,
mut avatar_query: Query<&mut Visibility, (With<LabelAIDialogAvatar>, Without<LabelAIDialogText>)>,
f117_ai_state: Res<F117AIState>,
mut ui_state: ResMut<AIDialogUIState>,
) {
// Hide dialog if there is no text to display
if ui_state.is_visible == true && f117_ai_state.display_line.len() == 0 {
ui_state.is_visible = false;
for (mut text, mut visibility) in text_query.iter_mut() {
text.sections[0].value = "".to_string();
*visibility = Visibility::Hidden;
}
for mut visibility in avatar_query.iter_mut() {
*visibility = Visibility::Hidden;
}
} else // Show dialog if there's text, but only after a delay of 1 second.
if ui_state.is_visible == false && f117_ai_state.display_line.len() > 0 && f117_ai_state.active_time > 1.0 {
ui_state.is_visible = true;
for (mut text, mut visibility) in text_query.iter_mut() {
text.sections[0].value = f117_ai_state.display_line.clone();
*visibility = Visibility::Visible;
}
for mut visibility in avatar_query.iter_mut() {
*visibility = Visibility::Visible;
}
}
}