Skip to content

Commit a75146d

Browse files
committed
🎉 improve the resources tool
1 parent 444c399 commit a75146d

File tree

5 files changed

+61
-20
lines changed

5 files changed

+61
-20
lines changed

TODO.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
- [ ] Make the examples better looking
44
- [ ] Open-source the project
55
- [ ] Animation system from multiple PNG files
6-
- [ ] Add search in the resource window
7-
- [ ] Allow opening the game folder in the resource window
86
- [ ] Rework the resource API to use futures to prevent use of unloaded resources
7+
- [ ] In loader add a way to load a text resource
98
- [ ] Add a help button to the editor menu with the options:
109
- [ ] Open Manual
1110
- [ ] Open Github
@@ -73,6 +72,8 @@
7372

7473
# Done
7574

75+
- [x] Add search in the resource window
76+
- [x] Allow opening the game folder in the resource window
7677
- [x] Lua performance helper:
7778
- [x] Add a lua function which computes AV + B for a list of V efficiently
7879
- [x] Add drawing functions that operate on lists of Lua objects and can perform common linear transformations before drawing

editor/src/editorinterface/editorconsole.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::editorinterface::EditorState;
1111

1212
pub fn draw_editor_console(editor: &mut EditorState, ctx: &egui::Context) {
1313
let mut project = editor.project.borrow_mut();
14+
let mut is_shown = editor.config.borrow_mut().is_console_shown;
1415

1516
let game = match project.as_mut() {
1617
Some(proj) => Some(&mut proj.game),
@@ -21,6 +22,8 @@ pub fn draw_editor_console(editor: &mut EditorState, ctx: &egui::Context) {
2122
let window = egui::Window::new("Console")
2223
.default_height(200.0)
2324
.default_width(300.0)
25+
.open(&mut is_shown)
26+
.collapsible(false)
2427
.vscroll(false);
2528
let response = window.show(ctx, |ui| {
2629
ui.horizontal(|ui| {
@@ -63,15 +66,15 @@ pub fn draw_editor_console(editor: &mut EditorState, ctx: &egui::Context) {
6366
egui::CentralPanel::default().show_inside(ui, |ui| {
6467
draw_console_content(ui);
6568
});
66-
6769
});
6870
if let Some(response) = response {
6971
let on_top = Some(response.response.layer_id) == ctx.top_layer_id();
70-
if on_top
71-
&& ctx.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Escape)) {
72-
editor.config.borrow_mut().is_console_shown = false;
73-
}
72+
if on_top && ctx.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Escape))
73+
{
74+
is_shown = false;
75+
}
7476
}
77+
editor.config.borrow_mut().is_console_shown = is_shown;
7578
}
7679
}
7780

editor/src/editorinterface/editorprofiler.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub fn draw_editor_profiler(editor: &mut EditorState, ctx: &egui::Context) {
1313
.default_width(400.0)
1414
.default_height(200.0)
1515
.open(&mut is_shown)
16+
.collapsible(false)
1617
.show(ctx, |ui| {
1718
let mut project = editor.project.borrow_mut();
1819
let project = project.as_mut();

editor/src/editorinterface/editorresources.rs

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::sync::Arc;
1+
use std::{cell::RefCell, path::PathBuf, sync::Arc};
22

33
use egui::ScrollArea;
44
use egui_extras::{Column, TableBuilder};
@@ -13,19 +13,20 @@ pub fn draw_editor_resources(editor: &EditorState, ctx: &egui::Context) {
1313
None => None,
1414
};
1515

16+
let Some(game) = game else {
17+
return;
18+
};
19+
1620
let mut is_shown = editor.config.borrow().is_resources_window_shown;
1721
let maybe_response = egui::Window::new("Resources")
1822
.default_width(400.0)
1923
.default_height(200.0)
2024
.open(&mut is_shown)
25+
.collapsible(false)
2126
.show(ctx, |ui| {
2227
ScrollArea::vertical()
2328
.auto_shrink([true, false])
24-
.show(ui, |ui| {
25-
// TODO: Add search
26-
27-
draw_resource_table(editor, ui, &game);
28-
});
29+
.show(ui, |ui| draw_scroll_area_content(editor, ui, game));
2930
});
3031
if let Some(response) = maybe_response {
3132
let on_top = Some(response.response.layer_id) == ctx.top_layer_id();
@@ -36,9 +37,7 @@ pub fn draw_editor_resources(editor: &EditorState, ctx: &egui::Context) {
3637

3738
editor.config.borrow_mut().is_resources_window_shown = is_shown;
3839

39-
if let Some(id) = editor.config.borrow().debug_resource_shown
40-
&& let Some(game) = game
41-
{
40+
if let Some(id) = editor.config.borrow().debug_resource_shown {
4241
let res = game.lua_env.resources.get_holder_by_id(id);
4342
egui::Window::new(format!(
4443
"Resource debug - {}",
@@ -51,7 +50,41 @@ pub fn draw_editor_resources(editor: &EditorState, ctx: &egui::Context) {
5150
};
5251
}
5352

54-
fn draw_resource_table(editor: &EditorState, ui: &mut egui::Ui, game: &Option<&mut Game>) {
53+
fn draw_scroll_area_content(editor: &EditorState, ui: &mut egui::Ui, game: &mut Game) {
54+
thread_local! {
55+
static RESOURCE_SEARCH: RefCell<String> = const { RefCell::new(String::new()) };
56+
}
57+
58+
ui.horizontal(|ui| {
59+
if ui.button("Open game folder").clicked() {
60+
let absolute_path = game.lua_env.resources.get_absolute_path(&PathBuf::new());
61+
editor.config.borrow_mut().is_always_on_top = false;
62+
editor.window.borrow_mut().set_always_on_top(false);
63+
open::that(absolute_path).ok();
64+
}
65+
66+
let resource_count = game.lua_env.resources.enumerate().count();
67+
// No need to display the search if there are few resources
68+
if resource_count > 3 {
69+
RESOURCE_SEARCH.with_borrow_mut(|s| {
70+
egui::TextEdit::singleline(s)
71+
.hint_text("Filter resources by path")
72+
.desired_width(200.0)
73+
.show(ui);
74+
});
75+
}
76+
});
77+
let search_query = RESOURCE_SEARCH.with_borrow(|s| s.clone());
78+
79+
draw_resource_table(editor, ui, game, &search_query);
80+
}
81+
82+
fn draw_resource_table(
83+
editor: &EditorState,
84+
ui: &mut egui::Ui,
85+
game: &mut Game,
86+
search_query: &str,
87+
) {
5588
let available_height = ui.available_height();
5689
let table = TableBuilder::new(ui)
5790
.striped(true)
@@ -88,15 +121,17 @@ fn draw_resource_table(editor: &EditorState, ui: &mut egui::Ui, game: &Option<&m
88121
});
89122
})
90123
.body(|mut body| {
91-
let Some(game) = game else {
92-
return;
93-
};
94124
for (id, res) in game.lua_env.resources.enumerate() {
95125
let resources = game.lua_env.resources.clone();
96126
let status_string = res.get_status().to_string();
97127
let status_length = status_string.len();
98128
let row_height = f32::max(20.0, status_length as f32 / 2.0);
99129

130+
let path = resources.get_absolute_path(res.get_path());
131+
if !path.contains(search_query) {
132+
continue;
133+
}
134+
100135
body.row(row_height, |mut row| {
101136
row.col(|ui| {
102137
ui.label(id.to_string());

editor/src/editorinterface/editorwatcher.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub fn draw_editor_watcher(editor: &mut EditorState, ctx: &egui::Context) {
1919
.default_width(400.0)
2020
.default_height(200.0)
2121
.open(&mut is_shown)
22+
.collapsible(false)
2223
.show(ctx, |ui| {
2324
draw_editor_watcher_window(ui, editor);
2425
});

0 commit comments

Comments
 (0)