@@ -11,6 +11,8 @@ use crate::{
1111 util:: dds,
1212} ;
1313
14+ use super :: gui:: HiddenWindows ;
15+
1416pub struct TagDumper {
1517 package_id : String ,
1618 entry_index : String ,
@@ -61,55 +63,58 @@ impl Overlay for TagDumper {
6163 & mut self ,
6264 ctx : & egui:: Context ,
6365 _window : & Window ,
64- _resources : & mut Resources ,
66+ resources : & mut Resources ,
6567 _gui : & mut super :: gui:: GuiContext < ' _ > ,
6668 ) -> bool {
67- egui:: Window :: new ( "Tag Dumper" ) . show ( ctx, |ui| {
68- ui. horizontal ( |ui| {
69- ui. radio_value ( & mut self . use_full_hash , true , "Full hash" ) ;
70- ui. radio_value ( & mut self . use_full_hash , false , "Split hash" ) ;
71- } ) ;
72-
73- let pressed_enter = if self . use_full_hash {
74- ui. label ( "Tag" ) ;
75- ui. text_edit_singleline ( & mut self . tag_string ) . lost_focus ( )
76- && ui. input ( |i| i. key_pressed ( egui:: Key :: Enter ) )
77- } else {
78- ui. label ( "Package ID" ) ;
79- ui. text_edit_singleline ( & mut self . package_id ) ;
80-
81- ui. label ( "Entry Index" ) ;
82- ui. text_edit_singleline ( & mut self . entry_index ) . lost_focus ( )
83- && ui. input ( |i| i. key_pressed ( egui:: Key :: Enter ) )
84- } ;
69+ let mut windows = resources. get_mut :: < HiddenWindows > ( ) . unwrap ( ) ;
70+ egui:: Window :: new ( "Tag Dumper" )
71+ . open ( & mut windows. tag_dumper )
72+ . show ( ctx, |ui| {
73+ ui. horizontal ( |ui| {
74+ ui. radio_value ( & mut self . use_full_hash , true , "Full hash" ) ;
75+ ui. radio_value ( & mut self . use_full_hash , false , "Split hash" ) ;
76+ } ) ;
77+
78+ let pressed_enter = if self . use_full_hash {
79+ ui. label ( "Tag" ) ;
80+ ui. text_edit_singleline ( & mut self . tag_string ) . lost_focus ( )
81+ && ui. input ( |i| i. key_pressed ( egui:: Key :: Enter ) )
82+ } else {
83+ ui. label ( "Package ID" ) ;
84+ ui. text_edit_singleline ( & mut self . package_id ) ;
8585
86- if ui. button ( "Dump!" ) . clicked ( ) || pressed_enter {
87- if self . use_full_hash {
88- let tag = u32:: from_str_radix ( & self . tag_string , 16 ) ;
86+ ui. label ( "Entry Index" ) ;
87+ ui. text_edit_singleline ( & mut self . entry_index ) . lost_focus ( )
88+ && ui. input ( |i| i. key_pressed ( egui:: Key :: Enter ) )
89+ } ;
8990
90- if let Ok ( tag) = tag {
91- let tag = TagHash ( u32:: from_be ( tag) ) ;
92- self . message = Some ( self . dump_entry ( tag) . map ( |v| ( tag, v) ) ) ;
93- } else {
94- self . message = Some ( Err ( "Malformed input tag." . to_string ( ) ) ) ;
95- }
96- } else {
97- let pkg = u16:: from_str_radix ( & self . package_id , 16 ) ;
98- let entry = self . entry_index . parse ( ) ;
91+ if ui. button ( "Dump!" ) . clicked ( ) || pressed_enter {
92+ if self . use_full_hash {
93+ let tag = u32:: from_str_radix ( & self . tag_string , 16 ) ;
9994
100- if let ( Ok ( pkg) , Ok ( entry) ) = ( pkg, entry) {
101- let tag = TagHash :: new ( pkg, entry) ;
102- self . message = Some ( self . dump_entry ( tag) . map ( |v| ( tag, v) ) ) ;
95+ if let Ok ( tag) = tag {
96+ let tag = TagHash ( u32:: from_be ( tag) ) ;
97+ self . message = Some ( self . dump_entry ( tag) . map ( |v| ( tag, v) ) ) ;
98+ } else {
99+ self . message = Some ( Err ( "Malformed input tag." . to_string ( ) ) ) ;
100+ }
103101 } else {
104- self . message = Some ( Err ( "Malformed input tag." . to_string ( ) ) ) ;
102+ let pkg = u16:: from_str_radix ( & self . package_id , 16 ) ;
103+ let entry = self . entry_index . parse ( ) ;
104+
105+ if let ( Ok ( pkg) , Ok ( entry) ) = ( pkg, entry) {
106+ let tag = TagHash :: new ( pkg, entry) ;
107+ self . message = Some ( self . dump_entry ( tag) . map ( |v| ( tag, v) ) ) ;
108+ } else {
109+ self . message = Some ( Err ( "Malformed input tag." . to_string ( ) ) ) ;
110+ }
105111 }
106112 }
107- }
108113
109- if let Some ( result) = self . message . as_ref ( ) {
110- match result {
111- Ok ( ( tag, entry) ) => {
112- let msg = format ! (
114+ if let Some ( result) = self . message . as_ref ( ) {
115+ match result {
116+ Ok ( ( tag, entry) ) => {
117+ let msg = format ! (
113118 "Dumped {tag} / {:04X}_{:04X}\n Reference: {:08X}\n Type: {}, Subtype: \
114119 {}",
115120 tag. pkg_id( ) ,
@@ -118,12 +123,12 @@ impl Overlay for TagDumper {
118123 entry. file_type,
119124 entry. file_subtype
120125 ) ;
121- ui. label ( egui:: RichText :: new ( msg) . color ( egui:: Color32 :: GREEN ) )
122- }
123- Err ( msg) => ui. label ( egui:: RichText :: new ( msg) . color ( egui:: Color32 :: RED ) ) ,
124- } ;
125- }
126- } ) ;
126+ ui. label ( egui:: RichText :: new ( msg) . color ( egui:: Color32 :: GREEN ) )
127+ }
128+ Err ( msg) => ui. label ( egui:: RichText :: new ( msg) . color ( egui:: Color32 :: RED ) ) ,
129+ } ;
130+ }
131+ } ) ;
127132
128133 true
129134 }
@@ -140,35 +145,38 @@ impl Overlay for BulkTextureDumper {
140145 & mut self ,
141146 ctx : & egui:: Context ,
142147 _window : & Window ,
143- _resources : & mut Resources ,
148+ resources : & mut Resources ,
144149 _gui : & mut super :: gui:: GuiContext < ' _ > ,
145150 ) -> bool {
146- egui:: Window :: new ( "Bulk Texture Dumper" ) . show ( ctx, |ui| {
147- ui. horizontal ( |ui| {
148- ui. radio_value ( & mut self . bake_png , false , "DDS" ) ;
149- ui. set_enabled ( false ) ;
150- ui. radio_value ( & mut self . bake_png , true , "PNG" ) ;
151- } ) ;
152-
153- if ui. button ( "Dump!" ) . clicked ( ) {
154- for i in self . input . lines ( ) {
155- if let Ok ( itag) = u32:: from_str_radix ( i, 16 ) {
156- let tag = TagHash ( itag. to_be ( ) ) ;
157- let mut dds_data: Vec < u8 > = vec ! [ ] ;
158- let ( texture, texture_data) =
159- Texture :: load_data ( ExtendedHash :: Hash32 ( tag) , true ) . unwrap ( ) ;
160-
161- dds:: dump_to_dds ( & mut dds_data, & texture, & texture_data) ;
162- std:: fs:: create_dir ( "./textures/" ) . ok ( ) ;
163- if let Ok ( mut f) = File :: create ( format ! ( "./textures/{}.dds" , tag) ) {
164- f. write_all ( & dds_data) . ok ( ) ;
151+ let mut windows = resources. get_mut :: < HiddenWindows > ( ) . unwrap ( ) ;
152+ egui:: Window :: new ( "Bulk Texture Dumper" )
153+ . open ( & mut windows. texture_dumper )
154+ . show ( ctx, |ui| {
155+ ui. horizontal ( |ui| {
156+ ui. radio_value ( & mut self . bake_png , false , "DDS" ) ;
157+ ui. set_enabled ( false ) ;
158+ ui. radio_value ( & mut self . bake_png , true , "PNG" ) ;
159+ } ) ;
160+
161+ if ui. button ( "Dump!" ) . clicked ( ) {
162+ for i in self . input . lines ( ) {
163+ if let Ok ( itag) = u32:: from_str_radix ( i, 16 ) {
164+ let tag = TagHash ( itag. to_be ( ) ) ;
165+ let mut dds_data: Vec < u8 > = vec ! [ ] ;
166+ let ( texture, texture_data) =
167+ Texture :: load_data ( ExtendedHash :: Hash32 ( tag) , true ) . unwrap ( ) ;
168+
169+ dds:: dump_to_dds ( & mut dds_data, & texture, & texture_data) ;
170+ std:: fs:: create_dir ( "./textures/" ) . ok ( ) ;
171+ if let Ok ( mut f) = File :: create ( format ! ( "./textures/{}.dds" , tag) ) {
172+ f. write_all ( & dds_data) . ok ( ) ;
173+ }
165174 }
166175 }
167176 }
168- }
169177
170- ui. text_edit_multiline ( & mut self . input ) ;
171- } ) ;
178+ ui. text_edit_multiline ( & mut self . input ) ;
179+ } ) ;
172180
173181 true
174182 }
0 commit comments