entity_ui_proc generation
This commit is contained in:
@@ -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;
|
||||
@@ -229,6 +229,8 @@ editor_ui :: () {
|
||||
ui_vector_field("Scale", *entity.transform.scale);
|
||||
|
||||
update_matrix(*entity.transform);
|
||||
|
||||
entity_ui(entity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
101
ui/widgets.jai
101
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("%", <<value), ui_state.fonts.button);
|
||||
|
||||
ui_set_next_size_y(.PIXELS, text_size.y); // TODO
|
||||
ui_set_next_size_x(.CHILDREN_SUM);
|
||||
ui_set_next_padding(5);
|
||||
|
||||
//ui_set_next_text_alignment(.CENTER_VERTICALLY);
|
||||
outer := ui_box_make(.ANIMATE_ON_HOVER | .CLICKABLE | .DRAW_BORDER, get_hash(loc, identifier));
|
||||
|
||||
if outer.interaction.editing {
|
||||
outer.style.border_color = .{0.3,0.3,1.0,1.0};
|
||||
}
|
||||
|
||||
ui_push_parent(outer, alignment=.LEFT, axis=.HORIZONTAL);
|
||||
{
|
||||
ui_set_next_text_color(.{1,1,1,1});
|
||||
ui_set_next_text_alignment(.CENTER_VERTICALLY);
|
||||
ui_set_next_text_color(.{1,1,1,1});
|
||||
ui_set_next_size_x(.TEXT_DIM);
|
||||
ui_set_next_size_y(.TEXT_DIM);
|
||||
text_widget := ui_box_make(.DRAW_TEXT, get_hash(loc, identifier));
|
||||
|
||||
if outer.interaction.editing {
|
||||
text_widget.text = alloc_string(text_widget._number_text.count,, allocator=temp);
|
||||
memcpy(text_widget.text.data, text_widget._number_text.data.data, text_widget._number_text.count);
|
||||
|
||||
// Cursor
|
||||
ui_set_next_background_color(.{1.0,1.0,1.0,1.0});
|
||||
ui_set_next_size_x(.PIXELS, 2);
|
||||
ui_set_next_size_y(.PCT, 1);
|
||||
cursor := ui_box_make(.DRAW_BACKGROUND, get_hash(loc, identifier));
|
||||
|
||||
if key_down(.BACKSPACE) && text_widget._number_text.count > 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;
|
||||
<<value = parse_int(*temp_str);
|
||||
outer.interaction.editing = false;
|
||||
engine.editor.focused_widget = null;
|
||||
}
|
||||
|
||||
if engine.input.has_char {
|
||||
text_str := alloc_string(1,, allocator=temp);
|
||||
text_str[0] = xx engine.input.current_char;
|
||||
|
||||
if text_str == {
|
||||
case "0";#through;
|
||||
case "1";#through;
|
||||
case "2";#through;
|
||||
case "3";#through;
|
||||
case "4";#through;
|
||||
case "5";#through;
|
||||
case "6";#through;
|
||||
case "7";#through;
|
||||
case "8";#through;
|
||||
case "9";
|
||||
{
|
||||
if !(text_str == "." && (array_contains(text_widget._number_text, #char ".") || text_widget._number_text.count == 0)) {
|
||||
text_widget._number_text.data[text_widget._number_text.count] = text_str[0];
|
||||
text_widget._number_text.count += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Ignore non-numeric characters
|
||||
} else {
|
||||
text_widget.text = copy_temporary_string(tprint("%", <<value));
|
||||
}
|
||||
|
||||
if outer.interaction.clicked {
|
||||
if engine.editor.focused_widget != null {
|
||||
engine.editor.focused_widget.interaction.editing = false;
|
||||
}
|
||||
|
||||
outer.interaction.editing = true;
|
||||
engine.editor.focused_widget = outer;
|
||||
formatted_text := copy_temporary_string(tprint("%", <<value));
|
||||
memcpy(text_widget._number_text.data.data, formatted_text.data, formatted_text.count);
|
||||
text_widget._number_text.count = formatted_text.count;
|
||||
}
|
||||
}
|
||||
ui_pop_parent();
|
||||
}
|
||||
ui_pop_parent();
|
||||
ui_set_next_background_color(.{0.0,1.0,1.0,0.0});
|
||||
ui_set_next_border_color(.{0.3,0.3,0.3,1.0});
|
||||
ui_set_next_size_x(.CHILDREN_SUM, 1);
|
||||
}
|
||||
|
||||
ui_float_field :: (value: *float, identifier: s64 = 0, loc := #caller_location) {
|
||||
ui_set_next_background_color(.{0.0,1.0,1.0,0.0});
|
||||
ui_set_next_border_color(.{0.3,0.3,0.3,1.0});
|
||||
|
||||
Reference in New Issue
Block a user