1- use std:: sync:: Arc ;
1+ use std:: { cell :: RefCell , path :: PathBuf , sync:: Arc } ;
22
33use egui:: ScrollArea ;
44use 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 ( ) ) ;
0 commit comments