mouse_pos := mouse_raw - scene_render_offset;
if is_button_just_up(GLFW_MOUSE_BUTTON_LEFT) && mouse_raw.x < ~~window_width - sidebar_width && mouse_raw.x >= 0 {
- schematic := scene.schematics.entries[active_index].value;
- entity := schematic.create(^scene);
- entity.schematic = schematic.type;
- scene->add(entity);
+ entity: ^Entity;
+ if active_index == 0 {
+ entity = scene->make();
+ } else {
+ schematic := scene.schematics.entries[active_index - 1].value;
+ entity = schematic.create(^scene);
+ entity.schematic = schematic.type;
+ }
+ scene->add(entity);
entity.pos = mouse_pos;
if entity.size.x == 0 do entity.size.x = editor_grid_size;
if entity.size.y == 0 do entity.size.y = editor_grid_size;
h -= 40;
y += 40;
+ theme := Button_Theme.{};
+
i := 0;
+ y += 40;
+ theme.active = active_index == i;
+ if draw_button(.{x, y - 18, w, 36}, "Custom", ^theme) do active_index = i;
+
for^ scene.schematics.entries {
- defer i += 1;
+ i += 1;
name := it.key;
- if search_value.count != 0 {
- if !string.contains(name, search_value) do continue;
- }
+ if !string.contains(name, search_value) do continue;
y += 40.0f;
- theme := Button_Theme.{active = active_index == i};
+ theme.active = active_index == i;
if draw_button(.{x, y - 18, w, 36.0f}, name, ^theme, increment=i) {
active_index = i;
}
font_print(editor_big_font, x + 2, y + 24, info.name);
}
- if draw_button(.{ x + w - 150, y, 150, 24 }, "Delete") {
- scene->delete(entity);
- selected_entity_id = Entity_Nothing;
- return;
- }
+ if active_index == Component_Selection_Active {
+ if draw_button(.{ x + w - 150, y, 150, 24 }, "Back") {
+ active_index = Nothing_Active;
+ return;
+ }
- if active_index >= 0 do sidebar_width += w;
+ #persist search_buffer: [..] u8;
+ y += 32;
+ draw_textbox(.{x, y, w, 32}, ^search_buffer, placeholder="Search...");
- y += 4;
- i := 0;
- y, i = render_struct_fields(ptr_to_any(entity), i, x, y, w, h);
+ y += 32;
+ for^ entry: scene.component_vtables.entries {
+ info = ~~ type_info.get_type_info(entry.key);
+ if !string.contains(info.name, search_buffer) do continue;
+
+ if draw_button(.{ x, y, w, 32 }, info.name, increment=~~y) {
+ new_comp := scene->create_component(entry.key);
+ entity->add(new_comp);
+ active_index = Nothing_Active;
+ }
+ y += 32;
+ }
- y += 32;
- for^ entry: entity.components.entries {
- immediate_set_color(.{0, 0, 0});
- immediate_rectangle(x, y, w, 4);
+ } else {
+ if draw_button(.{ x + w - 150, y, 150, 24 }, "Delete") {
+ scene->delete(entity);
+ selected_entity_id = Entity_Nothing;
+ return;
+ }
+
+ if active_index >= 0 do sidebar_width += w;
- y += 16;
- info = ~~ type_info.get_type_info(entry.key);
- font_print(editor_font, x + 2, y + 20, info.name);
+ y += 4;
+ i := 0;
+ y, i = render_struct_fields(ptr_to_any(entity), i, x, y, w, h);
- y, i = render_struct_fields(any.{~~entry.value, entry.key}, i, x, y, w, h);
y += 32;
+ for^ entry: entity.components.entries {
+ immediate_set_color(.{0, 0, 0});
+ immediate_rectangle(x, y, w, 4);
+
+ y += 16;
+ info = ~~ type_info.get_type_info(entry.key);
+ font_print(editor_font, x + 2, y + 20, info.name);
+
+ if draw_button(.{ x + w - 100, y, 100, 20 }, "Remove", increment=~~y) {
+ entity->remove(entry.value);
+
+ // This has to break, otherwise the loop could be very wrong.
+ break;
+ }
+
+ y, i = render_struct_fields(any.{~~entry.value, entry.key}, i, x, y, w, h);
+ y += 32;
+ }
+
+ if draw_button(.{x, y, w, 40}, "Add component") {
+ active_index = Component_Selection_Active;
+ }
}
}
active_tab := Tabs.Edit;
clicked_tab := Tabs.None;
- active_index := -1;
field_shown := -1;
field_buffer: [..] u8;
+ Nothing_Active :: -1;
+ Component_Selection_Active :: -2;
+ active_index := -1;
+
editor_grid_shown := false;
editor_grid_size := 16.0f; @TODO // This should be configurable
for entities {
info := cast(^Type_Info_Struct) get_type_info(it.schematic);
- io.write_format(writer, "[{}]\n", info.name);
+ name := info.name;
+ if name.count == 0 do name = "Custom";
+ io.write_format(writer, "[{}]\n", name);
emit_struct_fields(any.{~~ it, Entity}, writer, "");
for^ it.components.entries {
|> (x => str.{x.data, x.count - 1})(); // In the grossest way possible remove one character from the end.
debug_log(.Debug, "Creating entity from schematic: {}.", entity_kind);
- current_entity = this->create_from_schematic(entity_kind);
- if current_entity == null {
- debug_log(.Error, "Unknown entity kind '{}' on line {}.", entity_kind, line_number);
- current_entity = null;
- continue;
+ if entity_kind == "Custom" {
+ current_entity = this->make();
+ } else {
+ current_entity = this->create_from_schematic(entity_kind);
+ if current_entity == null {
+ debug_log(.Error, "Unknown entity kind '{}' on line {}.", entity_kind, line_number);
+ current_entity = null;
+ continue;
+ }
}
continue;