358 lines
13 KiB
Plaintext
358 lines
13 KiB
Plaintext
#load "../ui/widgets.jai";
|
|
|
|
#placeholder editor_ui_entity_creation;
|
|
|
|
pick_scene_view_at :: (camera: Camera, coordinates: Vector2) {
|
|
ray := normalized_screen_to_ray_v2(camera, coordinates);
|
|
|
|
if engine.editor.should_check_entities {
|
|
hit_entity : *Entity;
|
|
closest : float = 100000000;
|
|
|
|
for engine.current_scene.entities {
|
|
if !(it.flags & .RENDERABLE) continue;
|
|
//if it.flags & Entity_Flags.DELETED || !it.selectable || it.parent != null continue;
|
|
|
|
success, dist := ray_entity_intersect(ray, it);
|
|
if success && dist < closest {
|
|
closest = dist;
|
|
hit_entity = it;
|
|
}
|
|
}
|
|
|
|
if hit_entity != null {
|
|
if !array_find(engine.editor.selected_entities, hit_entity) {
|
|
if !key_pressed(.CTRL) {
|
|
engine.editor.selected_entities.count = 0;
|
|
}
|
|
array_add(*engine.editor.selected_entities, hit_entity);
|
|
}
|
|
} else {
|
|
engine.editor.selected_entities.count = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
editor_ui :: () {
|
|
ui_full_size_background();
|
|
ui_push_parent(ui_state.last_box, alignment=.LEFT, axis=.VERTICAL);
|
|
{
|
|
ui_set_next_padding(1);
|
|
ui_toolbar();
|
|
ui_push_parent(ui_state.last_box, alignment=.LEFT, axis=.HORIZONTAL);
|
|
{
|
|
if ui_toolbar_button("File") {
|
|
}
|
|
|
|
//ui_space(15, 10);
|
|
|
|
if ui_toolbar_button("Edit") {
|
|
}
|
|
|
|
//ui_space(15, 10);
|
|
|
|
if ui_toolbar_button("View") {
|
|
}
|
|
|
|
ui_space(20, 0);
|
|
|
|
if engine.mode == {
|
|
case .PLAYING; {
|
|
ui_set_next_background_color(.{0,0.6,0,1});
|
|
if ui_button_with_texture(engine.editor.icons.stop) {
|
|
switch_engine_mode(.EDITING);
|
|
}
|
|
ui_label(tprint("Playing '%'", engine.current_scene.name), .{0,0.7,0,1});
|
|
}
|
|
case .EDITING; {
|
|
ui_set_next_background_color(.{0.6,0,0,1});
|
|
if ui_button_with_texture(engine.editor.icons.play) {
|
|
switch_engine_mode(.PLAYING);
|
|
}
|
|
ui_label(tprint("Editing '%'", engine.current_scene.name), .{1,1,1,1});
|
|
}
|
|
}
|
|
}
|
|
ui_pop_parent();
|
|
|
|
ui_set_next_size_x(.PCT, 1.0);
|
|
ui_set_next_size_y(.PCT, 0.965);
|
|
ui_set_next_background_color(.{0,0,0,1});
|
|
background := ui_box(.NONE);
|
|
|
|
ui_push_parent(ui_state.last_box, alignment=.LEFT, axis=.HORIZONTAL);
|
|
{
|
|
ui_set_next_size_x(.PCT, 0.1);
|
|
ui_set_next_size_y(.PCT, 1.0);
|
|
ui_set_next_padding(1);
|
|
first_panel := ui_box(.NONE);
|
|
ui_push_parent(first_panel, alignment=.LEFT, axis=.VERTICAL);
|
|
{
|
|
ui_set_next_size_x(.PCT, 1.0);
|
|
ui_set_next_size_y(.PCT, 1.0);
|
|
ui_set_next_background_color(.{0.04, 0.04, 0.04, 1.0});
|
|
background := ui_box(.DRAW_BACKGROUND|.DRAW_BORDER);
|
|
|
|
ui_push_parent(background, alignment=.LEFT, axis=.VERTICAL);
|
|
{
|
|
ui_set_next_size_x(.PCT, 1.0);
|
|
ui_tab_title_bar("ENTITIES");
|
|
|
|
for engine.current_scene.entities {
|
|
ui_set_next_padding(20);
|
|
clicked := false;
|
|
selected := array_find(engine.editor.selected_entities, it);
|
|
if it.name.count == 0 {
|
|
clicked = ui_clickable_label(tprint("%", it.type), selected, it_index);
|
|
} else {
|
|
clicked = ui_clickable_label(it.name, selected, it_index);
|
|
}
|
|
|
|
if clicked {
|
|
if !key_pressed(.CTRL) {
|
|
engine.editor.selected_entities.count = 0;
|
|
array_add(*engine.editor.selected_entities, it);
|
|
} else {
|
|
if selected {
|
|
array_unordered_remove_by_value(*engine.editor.selected_entities, it);
|
|
} else {
|
|
array_add(*engine.editor.selected_entities, it);
|
|
}
|
|
}
|
|
}
|
|
//ui_space(0, 5);
|
|
}
|
|
}
|
|
ui_pop_parent();
|
|
}
|
|
ui_pop_parent();
|
|
|
|
// Scene
|
|
ui_set_next_size_x(.PCT, 0.7);
|
|
ui_set_next_size_y(.PCT, 1.0);
|
|
ui_set_next_padding(1);
|
|
viewport_layer := ui_box(.NONE);
|
|
ui_push_parent(viewport_layer, alignment=.LEFT, axis=.VERTICAL);
|
|
{
|
|
ui_set_next_size_x(.PCT, 1.0);
|
|
ui_tab_title_bar("SCENE");
|
|
ui_set_next_size_x(.PCT, 1.0);
|
|
ui_set_next_size_y(.PCT, 0.75);
|
|
|
|
state := ui_interactable_texture(get_texture_from_pass("UI Blend Pass"));
|
|
if state.left_mouse_down {
|
|
pick_scene_view_at(engine.editor.camera, .{state.normalized_local_mouse_coordinates.x, 1.0-state.normalized_local_mouse_coordinates.y});
|
|
|
|
}
|
|
|
|
engine.editor.mouse_viewport_state = state;
|
|
|
|
ui_set_next_size_x(.PCT, 1.0);
|
|
ui_set_next_size_y(.PCT, 0.25);
|
|
ui_tab_title_bar("Create entities");
|
|
{
|
|
new_entity := editor_ui_entity_creation();
|
|
if new_entity != null {
|
|
set_position(*new_entity.transform, engine.editor.camera.position + engine.editor.camera.forward * 20.0);
|
|
engine.editor.selected_entities.count = 0;
|
|
array_add(*engine.editor.selected_entities, new_entity);
|
|
}
|
|
}
|
|
}
|
|
ui_pop_parent();
|
|
|
|
// Properties
|
|
ui_set_next_size_x(.PCT, 0.2);
|
|
ui_set_next_size_y(.PCT, 1.0);
|
|
ui_set_next_background_color(.{0.04, 0.04, 0.04, 1.0});
|
|
ui_set_next_padding(1);
|
|
inspector := ui_box(.DRAW_BACKGROUND | .DRAW_BORDER);
|
|
ui_push_parent(inspector, alignment=.LEFT, axis=.VERTICAL);
|
|
{
|
|
ui_set_next_size_x(.PCT, 1.0);
|
|
ui_tab_title_bar("PROPERTIES");
|
|
|
|
if engine.editor.selected_entities.count == 1 {
|
|
entity := engine.editor.selected_entities[0];
|
|
//ui_slider(*slider_value, 0.0, 1.0);
|
|
|
|
ui_textfield("Name", *entity.name);
|
|
|
|
ui_label(tprint("Id: %", entity.id));
|
|
|
|
ui_vector_field("Position", *entity.transform.position);
|
|
euler_rotation := quaternion_to_euler_v3(entity.transform.orientation);
|
|
euler_rotation *= RADIANS_TO_DEGREES;
|
|
ui_vector_field("Rotation", *euler_rotation);
|
|
euler_rotation *= DEGREES_TO_RADIANS;
|
|
entity.transform.orientation = euler_to_quaternion(euler_rotation);
|
|
ui_vector_field("Scale", *entity.transform.scale);
|
|
|
|
update_matrix(*entity.transform);
|
|
}
|
|
|
|
}
|
|
ui_pop_parent();
|
|
}
|
|
ui_pop_parent();
|
|
}
|
|
ui_pop_parent();
|
|
}
|
|
|
|
text_fun : string;
|
|
slider_value : float = 0.0;
|
|
|
|
base_editor_update :: () {
|
|
if engine.editor.show_menu && (key_down(.MOUSE_LEFT) || key_down(.ESCAPE)) {
|
|
engine.editor.show_menu = false;
|
|
eat_key(.MOUSE_LEFT);
|
|
}
|
|
|
|
// @Incomplete: Show that we saved the scene in the editor. Maybe a quick text message or just inside one of the tab titles
|
|
if key_pressed(.CTRL) && key_down(.S) {
|
|
save_scene(engine.current_scene);
|
|
}
|
|
|
|
// Check if we hit the gizmo
|
|
// @Incomplete: MOVE THIS
|
|
engine.editor.should_check_entities = true;
|
|
|
|
if engine.editor.selected_entities.count == 1 {
|
|
entity := engine.editor.selected_entities[0];
|
|
gizmo_scale := distance(entity.transform.position, engine.editor.camera.position) * 0.1 * 0.5;
|
|
engine.editor.transform_gizmo.uniform_gizmo_scale = gizmo_scale;
|
|
set_scale(*engine.editor.transform_gizmo.transform, .{gizmo_scale, gizmo_scale, gizmo_scale});
|
|
|
|
coordinates := Vector2.{engine.editor.mouse_viewport_state.normalized_local_mouse_coordinates.x, 1.0 - engine.editor.mouse_viewport_state.normalized_local_mouse_coordinates.y};
|
|
ray := normalized_screen_to_ray_v2(engine.editor.camera, coordinates);
|
|
|
|
if update_transform_gizmo(ray, coordinates) {
|
|
engine.editor.should_check_entities = false;
|
|
}
|
|
}
|
|
|
|
editor_ui();
|
|
|
|
//if editor.show_menu {
|
|
// placed_entity := imgui_show_place_entity();
|
|
// if placed_entity != null {
|
|
// // @Incomplete: At some point we want this to place entities at either a set distance or a distance depending on a raycast in the camera's forward direction so that we don't place things behind other entities
|
|
// set_position(*placed_entity.transform, editor.camera.position + editor.camera.forward * 30);
|
|
// editor.show_menu = false;
|
|
// entity = placed_entity;
|
|
// }
|
|
//}
|
|
|
|
camera := *engine.editor.camera;
|
|
|
|
if key_pressed(.CTRL) && key_down(.S) {
|
|
save_scene(engine.current_scene, "../assets/scenes/");
|
|
//show_message("Saved scene");
|
|
}
|
|
|
|
if key_down(.DELETE) || key_down(.BACKSPACE) {
|
|
for engine.editor.selected_entities {
|
|
mark_entity_deleted(it);
|
|
}
|
|
|
|
engine.editor.selected_entities.count = 0;
|
|
}
|
|
|
|
//if entity != null {
|
|
// // @Incomplete:@Incomplete: Duplicate
|
|
// //if key_pressed(.CTRL) && key_down(.D) {
|
|
// // make_directory_if_it_does_not_exist("../temp");
|
|
// // save_entity(entity, "../temp/", "temp");
|
|
// // duplicated := load_entity(editor_scene, "../temp/temp.ent");
|
|
// // entity = duplicated;
|
|
// //}
|
|
|
|
// // DELETE
|
|
// // DELETE
|
|
// //if key_down(.DELETE) || key_down(.BACKSPACE) {
|
|
// // delete_entity(entity);
|
|
// // entity = null;
|
|
// // editor.transform_gizmo.selected_axis = .NONE;
|
|
// //}
|
|
//}
|
|
|
|
//if key_pressed(.CTRL) && key_down(.Z) {
|
|
// editor_undo();
|
|
//}
|
|
|
|
if engine.mode == .EDITING {
|
|
if key_pressed(.MOUSE_RIGHT) {
|
|
set_show_cursor(false);
|
|
// Update camera
|
|
mouse_speed :: 54.0;
|
|
dir : Vector3;
|
|
|
|
if key_pressed(.W) {
|
|
dir += camera.forward;
|
|
} else if key_pressed(.S) {
|
|
dir += -camera.forward;
|
|
}
|
|
|
|
if key_pressed(.A) {
|
|
dir += -camera.right;
|
|
} else if key_pressed(.D) {
|
|
dir += camera.right;
|
|
}
|
|
|
|
if key_pressed(.Q) {
|
|
dir += -camera.up;
|
|
} else if key_pressed(.E) {
|
|
dir += camera.up;
|
|
}
|
|
|
|
dir = normalize(dir);
|
|
|
|
if length(dir) > 0.05 {
|
|
multiplier := ifx key_pressed(.SHIFT) then 10.0 else 1.0;
|
|
camera.position += dir * 20.0 * multiplier * dt;
|
|
//print("Camera position %\n", camera.position);
|
|
}
|
|
|
|
MOUSE_SENSITIVITY :: 0.06;
|
|
camera.rotation.yaw -= engine.input.mouse.delta_x * MOUSE_SENSITIVITY;
|
|
camera.rotation.pitch += -engine.input.mouse.delta_y * MOUSE_SENSITIVITY;
|
|
|
|
if key_down(.MOUSE_RIGHT) {
|
|
engine.editor.last_right_mouse_click_time = time;
|
|
}
|
|
} else {
|
|
set_show_cursor(true);
|
|
|
|
if time - engine.editor.last_right_mouse_click_time < 0.2 {
|
|
mouse_position : Vector2;
|
|
mouse_position.x = xx engine.input.mouse.x;
|
|
mouse_position.y = xx engine.input.mouse.y;
|
|
engine.editor.show_menu = true;
|
|
engine.editor.menu_position.x = mouse_position.x;
|
|
engine.editor.menu_position.y = cast(float)engine.renderer.render_target_height - mouse_position.y;
|
|
}
|
|
|
|
if !key_pressed(.CTRL) {
|
|
if key_down(.W) {
|
|
engine.editor.transform_gizmo.transform_type = .TRANSLATION;
|
|
}
|
|
|
|
if key_down(.E) {
|
|
engine.editor.transform_gizmo.transform_type = .ROTATION;
|
|
}
|
|
|
|
if key_down(.R) {
|
|
engine.editor.transform_gizmo.transform_type = .SCALE;
|
|
}
|
|
}
|
|
}
|
|
|
|
update_view_matrix(camera);
|
|
}
|
|
|
|
if key_pressed(.CTRL) && key_down(.E) {
|
|
new_mode := ifx engine.mode == .EDITING then Engine_Mode.PLAYING else .EDITING;
|
|
switch_engine_mode(new_mode);
|
|
}
|
|
}
|