diff --git a/core/scene.jai b/core/scene.jai index 9036e62..b0124c3 100644 --- a/core/scene.jai +++ b/core/scene.jai @@ -7,6 +7,7 @@ #placeholder serialize_entity; #placeholder deserialize_entity; #placeholder duplicate_entity; +#placeholder entity_ui; MAX_CACHED_PILES :: 8; last_unnamed_scene_id := 0; @@ -262,6 +263,14 @@ update_entity_transform :: (e: *Entity, parent_matrix: Matrix4 = Matrix4_Identit } } +get_entity_with_id :: (scene: *Scene, id: s64) -> *Entity { + for scene.entities { + if it.id == id return it; + } + + return null; +} + #scope_file next_entity_id: Entity_Id; \ No newline at end of file diff --git a/editor/editor_ui.jai b/editor/editor_ui.jai index 5a9e517..1de7438 100644 --- a/editor/editor_ui.jai +++ b/editor/editor_ui.jai @@ -229,6 +229,8 @@ editor_ui :: () { ui_vector_field("Scale", *entity.transform.scale); update_matrix(*entity.transform); + + entity_ui(entity); } } diff --git a/metaprogram.jai b/metaprogram.jai index 2097062..3033283 100644 --- a/metaprogram.jai +++ b/metaprogram.jai @@ -81,6 +81,32 @@ should_serialize :: (type: *Type_Info_Struct, member: Type_Info_Struct_Member) - return true; } +generate_member_ui :: (type: *Type_Info_Struct, builder: *String_Builder, path: string = "") { + for type.members { + if should_serialize(type, it) { + new_path : string; + if path.count == 0 { + new_path = it.name; + } else { + new_path = tprint("%1.%2", path, it.name); + } + + if it.type.type == { + //case .STRUCT; { + // info_struct := cast(*Type_Info_Struct) it.type; + // generate_member_serialization(info_struct, builder, new_path); + //} + //case .BOOL; #through; + //case .FLOAT; #through; + //case .ENUM; #through; + case .INTEGER; { + print_to_builder(builder, "\tui_int_field(tprint(\"%\"), *e.%);\n", new_path, new_path); + } + } + } + } +} + generate_member_serialization :: (type: *Type_Info_Struct, builder: *String_Builder, path: string = "") { for type.members { if should_serialize(type, it) { @@ -159,6 +185,18 @@ generate_member_copy :: (type: *Type_Info_Struct, builder: *String_Builder, path } } +generate_ui_procedure_for_entity :: (code_struct: *Code_Struct) { + name := code_struct.defined_type.name; + + // Serialize + ui : String_Builder; + print_to_builder(*ui, "entity_ui_proc :: (e: *%) {\n", name); + generate_member_ui(code_struct.defined_type, *ui); + print_to_builder(*ui, "}\n"); + + array_add(*entity_serialize_proc_string, builder_to_string(*ui)); +} + generate_serialize_procedure_for_entity :: (code_struct: *Code_Struct) { name := code_struct.defined_type.name; @@ -213,6 +251,7 @@ note_struct :: (code_struct: *Code_Struct) { print("Detected entity '%'.\n", name); generate_serialize_procedure_for_entity(code_struct); + generate_ui_procedure_for_entity(code_struct); } } } @@ -356,6 +395,17 @@ generate_code :: (w: Workspace) { add_build_string(build_string, w); } + { + builder: String_Builder; + + for entity_type_names { + print_to_builder(*builder, "\tcase %1; entity_ui_proc(cast(*%1)e);\n", it); + } + + build_string := sprint(ENTITY_UI, builder_to_string(*builder)); + add_build_string(build_string, w); + } + { builder: String_Builder; @@ -462,6 +512,14 @@ duplicate_entity :: (e: *Entity) -> *Entity { } DONE +ENTITY_UI :: #string DONE +entity_ui :: (e: *Entity) { + if e.type == { + %1 + } +} +DONE + INIT_SCENE :: #string DONE init_scene :: (scene: *Scene) { %1 diff --git a/ui/widgets.jai b/ui/widgets.jai index c606b07..e9fc8aa 100644 --- a/ui/widgets.jai +++ b/ui/widgets.jai @@ -184,6 +184,107 @@ ui_textfield :: (label: string, text: *string, identifier: s64 = 0, loc := #call ui_pop_parent(); } +ui_int_field :: (label: string, value: *int, identifier: s64 = 0, loc := #caller_location) { + ui_container_layout(identifier=identifier, loc=loc); + ui_set_next_size_x(.CHILDREN_SUM); + ui_push_parent(ui_state.last_box, .LEFT, .HORIZONTAL); + { + ui_label(label); + + text_size := get_text_size(engine.renderer, tprint("%", < 0 { + text_widget._number_text.count -= 1; + } + + if key_down(.RETURN) { + // FORMAT IT BACK! + temp_str : string; + temp_str.data = text_widget._number_text.data.data; + temp_str.count = text_widget._number_text.count; + <