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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
use crate::app_context::AssetKey;
use crate::project_io::EditorProjectFile;
use nightshade::prelude::*;
pub struct AssetsWindowResult {
#[cfg(not(target_arch = "wasm32"))]
pub scan_requested: bool,
}
pub fn assets_panel_ui(
ui_context: &egui::Context,
project: Option<&EditorProjectFile>,
show_window: &mut bool,
pending_asset_update: &mut Option<(AssetKey, String)>,
) -> AssetsWindowResult {
#[cfg_attr(target_arch = "wasm32", allow(unused_mut))]
let mut result = AssetsWindowResult {
#[cfg(not(target_arch = "wasm32"))]
scan_requested: false,
};
if !*show_window {
return result;
}
let mut window_open = *show_window;
egui::Window::new("Assets")
.open(&mut window_open)
.default_width(600.0)
.default_height(400.0)
.resizable(true)
.show(ui_context, |ui| {
#[cfg(not(target_arch = "wasm32"))]
{
if ui.button("Scan Assets Directory").clicked() {
result.scan_requested = true;
}
ui.separator();
egui::ScrollArea::vertical()
.id_salt("assets_scroll")
.show(ui, |ui| {
if let Some(project) = project {
let mut all_prefabs: Vec<(String, String, String, bool)> = Vec::new();
let empty = std::collections::HashMap::new();
let scenes = project.data.as_ref().map(|d| &d.scenes).unwrap_or(&empty);
for (map_name, map) in scenes {
if let Some(nightshade::ecs::scene::SceneHdrSkybox::Reference {
path,
}) = &map.hdr_skybox
{
let exists = std::path::Path::new(path).exists();
all_prefabs.push((
map_name.clone(),
"HDR Skybox".to_string(),
path.clone(),
exists,
));
}
}
if all_prefabs.is_empty() {
ui.label("No referenced assets in project");
} else {
egui::Grid::new("assets_grid")
.num_columns(5)
.striped(true)
.min_col_width(100.0)
.show(ui, |ui| {
ui.strong("Map");
ui.strong("Asset");
ui.strong("Path");
ui.strong("Status");
ui.strong("Actions");
ui.end_row();
for (map_name, prefab_name, path, exists) in &all_prefabs {
ui.label(map_name);
ui.label(prefab_name);
let path_color = if *exists {
egui::Color32::from_rgb(100, 200, 100)
} else {
egui::Color32::from_rgb(200, 100, 100)
};
ui.label(
egui::RichText::new(path).color(path_color).small(),
);
if *exists {
ui.label(
egui::RichText::new("Found").color(
egui::Color32::from_rgb(100, 200, 100),
),
);
} else {
ui.label(
egui::RichText::new("Missing").color(
egui::Color32::from_rgb(200, 100, 100),
),
);
}
ui.horizontal(|ui| {
let asset_filters = [
nightshade::filesystem::FileFilter {
name: "GLTF/GLB".to_string(),
extensions: vec![
"gltf".to_string(),
"glb".to_string(),
],
},
nightshade::filesystem::FileFilter {
name: "HDR".to_string(),
extensions: vec!["hdr".to_string()],
},
];
if ui.small_button("...").clicked()
&& let Some(new_path) =
nightshade::filesystem::pick_file(
&asset_filters,
)
{
let new_path_str = new_path
.canonicalize()
.ok()
.and_then(|p| {
p.to_str().map(|s| s.to_string())
})
.unwrap_or_else(|| {
new_path.display().to_string()
});
*pending_asset_update = Some((
AssetKey::new(
map_name.clone(),
prefab_name.clone(),
),
new_path_str,
));
}
});
ui.end_row();
}
});
}
} else {
ui.label("No project loaded");
}
});
}
#[cfg(target_arch = "wasm32")]
{
let _ = (project, pending_asset_update);
ui.label("Asset management is not available on web");
}
});
*show_window = window_open;
result
}