311 lines
11 KiB
Plaintext
311 lines
11 KiB
Plaintext
#load "../ui/widgets.jai";
|
|
|
|
pick_scene_view_at :: (coordinates: Vector2) {
|
|
ray := normalized_screen_to_ray_v2(*editor.camera, coordinates);
|
|
|
|
if editor.should_check_entities {
|
|
hit_entity : *Entity;
|
|
closest : float = 100000000;
|
|
|
|
for game_state.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 cast(*Entity)hit_entity != editor.selected_entity {
|
|
editor.selected_entity = hit_entity;
|
|
}
|
|
} else if editor.selected_entity != null {
|
|
editor.selected_entity = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
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 mode == {
|
|
// case .PLAYING; {
|
|
// ui_set_next_background_color(.{0,0.6,0,1});
|
|
// if ui_button_with_texture(editor.icons.stop) {
|
|
// edit_current_scene();
|
|
// }
|
|
// ui_label(tprint("Playing '%'", 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(editor.icons.play) {
|
|
// play_current_editor_scene();
|
|
//}
|
|
ui_label(tprint("Editing '%'", game_state.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 game_state.current_scene.entities {
|
|
ui_set_next_padding(20);
|
|
clicked := false;
|
|
if it.name.count == 0 {
|
|
clicked = ui_clickable_label(tprint("%", it.type), it == editor.selected_entity, it_index);
|
|
} else {
|
|
clicked = ui_clickable_label(it.name, it == editor.selected_entity, it_index);
|
|
}
|
|
|
|
if clicked {
|
|
editor.selected_entity = 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.9);
|
|
|
|
state := ui_interactable_texture(get_texture_from_pass("FXAA"));
|
|
if state.left_mouse_down {
|
|
//pick_scene_view_at(.{state.normalized_local_mouse_coordinates.x, 1.0 - state.normalized_local_mouse_coordinates.y});
|
|
|
|
}
|
|
|
|
editor.mouse_viewport_state = state;
|
|
|
|
ui_set_next_size_x(.PCT, 1.0);
|
|
ui_set_next_size_y(.PCT, 0.1);
|
|
ui_tab_title_bar("SCENES");
|
|
}
|
|
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 editor.selected_entity != null {
|
|
ui_slider(*slider_value, 0.0, 1.0);
|
|
ui_label(tprint("Name: %", editor.selected_entity.name));
|
|
ui_label(tprint("Id: %", editor.selected_entity.id));
|
|
ui_label(tprint("Position: % % %", editor.selected_entity.transform.position.x, editor.selected_entity.transform.position.y, editor.selected_entity.transform.position.z));
|
|
ui_label(tprint("Rotation: % % % %", editor.selected_entity.transform.orientation.x, editor.selected_entity.transform.orientation.y, editor.selected_entity.transform.orientation.z, editor.selected_entity.transform.orientation.w));
|
|
ui_label(tprint("Scale: % % %", editor.selected_entity.transform.scale.x, editor.selected_entity.transform.scale.y, editor.selected_entity.transform.scale.z));
|
|
}
|
|
|
|
}
|
|
ui_pop_parent();
|
|
}
|
|
ui_pop_parent();
|
|
}
|
|
ui_pop_parent();
|
|
}
|
|
|
|
slider_value : float = 0.0;
|
|
|
|
base_editor_update :: () {
|
|
if editor.show_menu && (key_down(.MOUSE_LEFT) || key_down(.ESCAPE)) {
|
|
editor.show_menu = false;
|
|
eat_key(.MOUSE_LEFT);
|
|
}
|
|
|
|
// Check if we hit the gizmo
|
|
// @Incomplete: MOVE THIS
|
|
editor.should_check_entities = true;
|
|
|
|
if editor.selected_entity != null {
|
|
gizmo_scale := distance(editor.selected_entity.transform.position, editor.camera.position) * 0.1 * 0.5;
|
|
editor.transform_gizmo.uniform_gizmo_scale = gizmo_scale;
|
|
set_scale(*editor.transform_gizmo.transform, .{gizmo_scale, gizmo_scale, gizmo_scale});
|
|
|
|
coordinates := Vector2.{editor.mouse_viewport_state.normalized_local_mouse_coordinates.x, 1.0 - editor.mouse_viewport_state.normalized_local_mouse_coordinates.y};
|
|
ray := normalized_screen_to_ray_v2(*editor.camera, coordinates);
|
|
|
|
if update_transform_gizmo(ray, coordinates) {
|
|
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;
|
|
// editor.selected_entity = placed_entity;
|
|
// }
|
|
//}
|
|
|
|
camera := *editor.camera;
|
|
|
|
if key_pressed(.CTRL) && key_down(.S) {
|
|
save_scene(game_state.current_scene, "../assets/scenes/");
|
|
//show_message("Saved scene");
|
|
}
|
|
|
|
if editor.selected_entity != null {
|
|
// @Incomplete:@Incomplete: Duplicate
|
|
//if key_pressed(.CTRL) && key_down(.D) {
|
|
// make_directory_if_it_does_not_exist("../temp");
|
|
// save_entity(editor.selected_entity, "../temp/", "temp");
|
|
// duplicated := load_entity(editor_scene, "../temp/temp.ent");
|
|
// editor.selected_entity = duplicated;
|
|
//}
|
|
|
|
// DELETE
|
|
// DELETE
|
|
//if key_down(.DELETE) || key_down(.BACKSPACE) {
|
|
// delete_entity(editor.selected_entity);
|
|
// editor.selected_entity = null;
|
|
// editor.transform_gizmo.selected_axis = .NONE;
|
|
//}
|
|
}
|
|
|
|
//if key_pressed(.CTRL) && key_down(.Z) {
|
|
// editor_undo();
|
|
//}
|
|
|
|
if game_state.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 -= input.mouse.delta_x * MOUSE_SENSITIVITY;
|
|
camera.rotation.pitch += -input.mouse.delta_y * MOUSE_SENSITIVITY;
|
|
|
|
if key_down(.MOUSE_RIGHT) {
|
|
editor.last_right_mouse_click_time = time;
|
|
}
|
|
} else {
|
|
set_show_cursor(true);
|
|
|
|
if time - editor.last_right_mouse_click_time < 0.2 {
|
|
mouse_position : Vector2;
|
|
mouse_position.x = xx input.mouse.x;
|
|
mouse_position.y = xx input.mouse.y;
|
|
editor.show_menu = true;
|
|
editor.menu_position.x = mouse_position.x;
|
|
editor.menu_position.y = cast(float)renderer.render_target_height - mouse_position.y;
|
|
}
|
|
|
|
if key_down(.W) {
|
|
editor.transform_gizmo.transform_type = .TRANSLATION;
|
|
}
|
|
|
|
if key_down(.E) {
|
|
editor.transform_gizmo.transform_type = .ROTATION;
|
|
}
|
|
|
|
if key_down(.R) {
|
|
editor.transform_gizmo.transform_type = .SCALE;
|
|
}
|
|
}
|
|
|
|
update_view_matrix(camera);
|
|
}
|
|
|
|
if editor.selected_entity != null {
|
|
e := editor.selected_entity;
|
|
set_position(*editor.transform_gizmo.transform, e.transform.position);
|
|
update_gizmo_buffers();
|
|
}
|
|
|
|
//edit_scene_settings(*game_state.current_scene.settings);
|
|
}
|