Editor UI
This commit is contained in:
@@ -69,6 +69,69 @@ if _scene == null {
|
||||
_scene = engine.current_scene; }
|
||||
p, locator := find_and_occupy_empty_slot(*_scene.by_type._Item); p._locator = locator; register_entity(_scene, p); p.transform = create_identity_transform(); init_entity(p); return p; }
|
||||
|
||||
//
|
||||
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:272.
|
||||
//
|
||||
serialize_entity :: (e: *Item, builder: *String_Builder) {
|
||||
print_to_builder(builder, "type: Item\n");
|
||||
print_to_builder(builder, "entity.enabled: %\n", e.entity.enabled);
|
||||
print_to_builder(builder, "entity.flags: %\n", e.entity.flags);
|
||||
print_to_builder(builder, "entity.transform.position.x: %\n", e.entity.transform.position.x);
|
||||
print_to_builder(builder, "entity.transform.position.y: %\n", e.entity.transform.position.y);
|
||||
print_to_builder(builder, "entity.transform.position.z: %\n", e.entity.transform.position.z);
|
||||
print_to_builder(builder, "entity.transform.orientation.x: %\n", e.entity.transform.orientation.x);
|
||||
print_to_builder(builder, "entity.transform.orientation.y: %\n", e.entity.transform.orientation.y);
|
||||
print_to_builder(builder, "entity.transform.orientation.z: %\n", e.entity.transform.orientation.z);
|
||||
print_to_builder(builder, "entity.transform.orientation.w: %\n", e.entity.transform.orientation.w);
|
||||
print_to_builder(builder, "entity.transform.scale.x: %\n", e.entity.transform.scale.x);
|
||||
print_to_builder(builder, "entity.transform.scale.y: %\n", e.entity.transform.scale.y);
|
||||
print_to_builder(builder, "entity.transform.scale.z: %\n", e.entity.transform.scale.z);
|
||||
print_to_builder(builder, "entity.snap_offset.x: %\n", e.entity.snap_offset.x);
|
||||
print_to_builder(builder, "entity.snap_offset.y: %\n", e.entity.snap_offset.y);
|
||||
print_to_builder(builder, "entity.snap_offset.z: %\n", e.entity.snap_offset.z);
|
||||
}
|
||||
|
||||
//
|
||||
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:272.
|
||||
//
|
||||
deserialize_entity :: (scene: *Scene, lines: [] string, e: *Item) {
|
||||
for line: lines {
|
||||
values := split(line, ":");
|
||||
if values.count == 2 {
|
||||
if trim(values[0], " ") == {
|
||||
case "entity.enabled";
|
||||
scan2(values[1], "%", *e.entity.enabled);
|
||||
case "entity.transform.position.x";
|
||||
scan2(values[1], "%", *e.entity.transform.position.x);
|
||||
case "entity.transform.position.y";
|
||||
scan2(values[1], "%", *e.entity.transform.position.y);
|
||||
case "entity.transform.position.z";
|
||||
scan2(values[1], "%", *e.entity.transform.position.z);
|
||||
case "entity.transform.orientation.x";
|
||||
scan2(values[1], "%", *e.entity.transform.orientation.x);
|
||||
case "entity.transform.orientation.y";
|
||||
scan2(values[1], "%", *e.entity.transform.orientation.y);
|
||||
case "entity.transform.orientation.z";
|
||||
scan2(values[1], "%", *e.entity.transform.orientation.z);
|
||||
case "entity.transform.orientation.w";
|
||||
scan2(values[1], "%", *e.entity.transform.orientation.w);
|
||||
case "entity.transform.scale.x";
|
||||
scan2(values[1], "%", *e.entity.transform.scale.x);
|
||||
case "entity.transform.scale.y";
|
||||
scan2(values[1], "%", *e.entity.transform.scale.y);
|
||||
case "entity.transform.scale.z";
|
||||
scan2(values[1], "%", *e.entity.transform.scale.z);
|
||||
case "entity.snap_offset.x";
|
||||
scan2(values[1], "%", *e.entity.snap_offset.x);
|
||||
case "entity.snap_offset.y";
|
||||
scan2(values[1], "%", *e.entity.snap_offset.y);
|
||||
case "entity.snap_offset.z";
|
||||
scan2(values[1], "%", *e.entity.snap_offset.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:272.
|
||||
//
|
||||
@@ -136,69 +199,6 @@ deserialize_entity :: (scene: *Scene, lines: [] string, e: *Block) {
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:272.
|
||||
//
|
||||
serialize_entity :: (e: *Item, builder: *String_Builder) {
|
||||
print_to_builder(builder, "type: Item\n");
|
||||
print_to_builder(builder, "entity.enabled: %\n", e.entity.enabled);
|
||||
print_to_builder(builder, "entity.flags: %\n", e.entity.flags);
|
||||
print_to_builder(builder, "entity.transform.position.x: %\n", e.entity.transform.position.x);
|
||||
print_to_builder(builder, "entity.transform.position.y: %\n", e.entity.transform.position.y);
|
||||
print_to_builder(builder, "entity.transform.position.z: %\n", e.entity.transform.position.z);
|
||||
print_to_builder(builder, "entity.transform.orientation.x: %\n", e.entity.transform.orientation.x);
|
||||
print_to_builder(builder, "entity.transform.orientation.y: %\n", e.entity.transform.orientation.y);
|
||||
print_to_builder(builder, "entity.transform.orientation.z: %\n", e.entity.transform.orientation.z);
|
||||
print_to_builder(builder, "entity.transform.orientation.w: %\n", e.entity.transform.orientation.w);
|
||||
print_to_builder(builder, "entity.transform.scale.x: %\n", e.entity.transform.scale.x);
|
||||
print_to_builder(builder, "entity.transform.scale.y: %\n", e.entity.transform.scale.y);
|
||||
print_to_builder(builder, "entity.transform.scale.z: %\n", e.entity.transform.scale.z);
|
||||
print_to_builder(builder, "entity.snap_offset.x: %\n", e.entity.snap_offset.x);
|
||||
print_to_builder(builder, "entity.snap_offset.y: %\n", e.entity.snap_offset.y);
|
||||
print_to_builder(builder, "entity.snap_offset.z: %\n", e.entity.snap_offset.z);
|
||||
}
|
||||
|
||||
//
|
||||
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:272.
|
||||
//
|
||||
deserialize_entity :: (scene: *Scene, lines: [] string, e: *Item) {
|
||||
for line: lines {
|
||||
values := split(line, ":");
|
||||
if values.count == 2 {
|
||||
if trim(values[0], " ") == {
|
||||
case "entity.enabled";
|
||||
scan2(values[1], "%", *e.entity.enabled);
|
||||
case "entity.transform.position.x";
|
||||
scan2(values[1], "%", *e.entity.transform.position.x);
|
||||
case "entity.transform.position.y";
|
||||
scan2(values[1], "%", *e.entity.transform.position.y);
|
||||
case "entity.transform.position.z";
|
||||
scan2(values[1], "%", *e.entity.transform.position.z);
|
||||
case "entity.transform.orientation.x";
|
||||
scan2(values[1], "%", *e.entity.transform.orientation.x);
|
||||
case "entity.transform.orientation.y";
|
||||
scan2(values[1], "%", *e.entity.transform.orientation.y);
|
||||
case "entity.transform.orientation.z";
|
||||
scan2(values[1], "%", *e.entity.transform.orientation.z);
|
||||
case "entity.transform.orientation.w";
|
||||
scan2(values[1], "%", *e.entity.transform.orientation.w);
|
||||
case "entity.transform.scale.x";
|
||||
scan2(values[1], "%", *e.entity.transform.scale.x);
|
||||
case "entity.transform.scale.y";
|
||||
scan2(values[1], "%", *e.entity.transform.scale.y);
|
||||
case "entity.transform.scale.z";
|
||||
scan2(values[1], "%", *e.entity.transform.scale.z);
|
||||
case "entity.snap_offset.x";
|
||||
scan2(values[1], "%", *e.entity.snap_offset.x);
|
||||
case "entity.snap_offset.y";
|
||||
scan2(values[1], "%", *e.entity.snap_offset.y);
|
||||
case "entity.snap_offset.z";
|
||||
scan2(values[1], "%", *e.entity.snap_offset.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:272.
|
||||
//
|
||||
|
||||
@@ -153,7 +153,7 @@ screen_to_world :: (camera: Camera, screen_position: Vector2) -> Vector3 {
|
||||
return world_position;
|
||||
}
|
||||
|
||||
normalized_screen_to_ray_v2 :: (camera: *Camera, screen_position: Vector2) -> Ray {
|
||||
normalized_screen_to_ray_v2 :: (camera: Camera, screen_position: Vector2) -> Ray {
|
||||
nds : Vector2;
|
||||
nds.x = (2.0 * screen_position.x) - 1.0;
|
||||
nds.y = (2.0 * screen_position.y) - 1.0;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#placeholder deserialize_entity;
|
||||
|
||||
MAX_CACHED_PILES :: 8;
|
||||
last_unnamed_scene_id := 0;
|
||||
|
||||
Scene :: struct {
|
||||
name: string;
|
||||
@@ -44,7 +45,9 @@ visitor :: (info : *File_Visit_Info, files: *[..] Entity_File_Info) {
|
||||
}
|
||||
|
||||
load_scene :: (path: string) -> *Scene {
|
||||
scene := create_scene("", 1024);
|
||||
split_path := split(path, "/");
|
||||
name := split_path[split_path.count-1];
|
||||
scene := create_scene(name, 1024);
|
||||
|
||||
files : [..] Entity_File_Info;
|
||||
files.allocator = temp;
|
||||
@@ -86,9 +89,23 @@ unload_scene :: (scene: *Scene) {
|
||||
free(scene);
|
||||
}
|
||||
|
||||
create_scene :: (name: string, max_entities: s64 = 256) -> *Scene {
|
||||
create_scene :: (name: string = "", max_entities: s64 = 256) -> *Scene {
|
||||
scene := New(Scene);
|
||||
scene.name = copy_string(name);
|
||||
new_name := name;
|
||||
|
||||
// If no name was specified, we're going to pick an unused "unnamed_scene"-variant
|
||||
if new_name.count == 0 {
|
||||
while true {
|
||||
defer last_unnamed_scene_id += 1;
|
||||
temp_name := tprint("unnamed_scene_%", last_unnamed_scene_id);
|
||||
if !file_exists(tprint("../assets/scenes/%", temp_name)) {
|
||||
new_name = temp_name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
scene.name = copy_string(new_name);
|
||||
|
||||
// Setup allocator
|
||||
scene.pool = .{};
|
||||
|
||||
@@ -58,7 +58,6 @@ Transform_Gizmo :: struct {
|
||||
uniform_gizmo_scale: float;
|
||||
}
|
||||
|
||||
|
||||
Editor :: struct {
|
||||
show_menu: bool;
|
||||
should_check_entities: bool;
|
||||
@@ -72,6 +71,11 @@ Editor :: struct {
|
||||
menu_position: Vector2;
|
||||
}
|
||||
|
||||
init_editor :: () {
|
||||
aspect_ratio := cast(float)engine.renderer.render_target_width / cast(float)engine.renderer.render_target_height;
|
||||
engine.editor.camera = create_perspective_camera(.{0, 10, -10}, yaw=0, pitch=-40, roll=0.0, fov=40, aspect=aspect_ratio);
|
||||
}
|
||||
|
||||
update_transform_gizmo :: (ray: Ray, mouse_position: Vector2) -> bool {
|
||||
return false;
|
||||
// selected_entity := engine.editor.selected_entity;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#load "../ui/widgets.jai";
|
||||
|
||||
pick_scene_view_at :: (coordinates: Vector2) {
|
||||
ray := normalized_screen_to_ray_v2(*engine.current_scene.camera, coordinates);
|
||||
pick_scene_view_at :: (camera: Camera, coordinates: Vector2) {
|
||||
ray := normalized_screen_to_ray_v2(camera, coordinates);
|
||||
|
||||
if editor.should_check_entities {
|
||||
if engine.editor.should_check_entities {
|
||||
hit_entity : *Entity;
|
||||
closest : float = 100000000;
|
||||
|
||||
@@ -19,14 +19,14 @@ pick_scene_view_at :: (coordinates: Vector2) {
|
||||
}
|
||||
|
||||
if hit_entity != null {
|
||||
if !array_find(editor.selected_entities, hit_entity) {
|
||||
if !array_find(engine.editor.selected_entities, hit_entity) {
|
||||
if !key_pressed(.CTRL) {
|
||||
editor.selected_entities.count = 0;
|
||||
engine.editor.selected_entities.count = 0;
|
||||
}
|
||||
array_add(*editor.selected_entities, hit_entity);
|
||||
array_add(*engine.editor.selected_entities, hit_entity);
|
||||
}
|
||||
} else {
|
||||
editor.selected_entities.count = 0;
|
||||
engine.editor.selected_entities.count = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -99,15 +99,24 @@ editor_ui :: () {
|
||||
for engine.current_scene.entities {
|
||||
ui_set_next_padding(20);
|
||||
clicked := false;
|
||||
selected := array_find(editor.selected_entities, it);
|
||||
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 && !selected {
|
||||
array_add(*editor.selected_entities, it);
|
||||
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);
|
||||
}
|
||||
@@ -130,11 +139,11 @@ editor_ui :: () {
|
||||
|
||||
state := ui_interactable_texture(get_texture_from_pass("UI Blend Pass"));
|
||||
if state.left_mouse_down {
|
||||
pick_scene_view_at(.{state.normalized_local_mouse_coordinates.x, 1.0-state.normalized_local_mouse_coordinates.y});
|
||||
pick_scene_view_at(engine.editor.camera, .{state.normalized_local_mouse_coordinates.x, 1.0-state.normalized_local_mouse_coordinates.y});
|
||||
|
||||
}
|
||||
|
||||
editor.mouse_viewport_state = state;
|
||||
engine.editor.mouse_viewport_state = state;
|
||||
|
||||
ui_set_next_size_x(.PCT, 1.0);
|
||||
ui_set_next_size_y(.PCT, 0.1);
|
||||
@@ -173,14 +182,14 @@ editor_ui :: () {
|
||||
slider_value : float = 0.0;
|
||||
|
||||
base_editor_update :: () {
|
||||
if editor.show_menu && (key_down(.MOUSE_LEFT) || key_down(.ESCAPE)) {
|
||||
editor.show_menu = false;
|
||||
if engine.editor.show_menu && (key_down(.MOUSE_LEFT) || key_down(.ESCAPE)) {
|
||||
engine.editor.show_menu = false;
|
||||
eat_key(.MOUSE_LEFT);
|
||||
}
|
||||
|
||||
// Check if we hit the gizmo
|
||||
// @Incomplete: MOVE THIS
|
||||
editor.should_check_entities = true;
|
||||
engine.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;
|
||||
@@ -207,7 +216,7 @@ base_editor_update :: () {
|
||||
// }
|
||||
//}
|
||||
|
||||
camera := *editor.camera;
|
||||
camera := *engine.editor.camera;
|
||||
|
||||
if key_pressed(.CTRL) && key_down(.S) {
|
||||
save_scene(engine.current_scene, "../assets/scenes/");
|
||||
@@ -236,7 +245,7 @@ base_editor_update :: () {
|
||||
// editor_undo();
|
||||
//}
|
||||
|
||||
if mode == .EDITING {
|
||||
if engine.mode == .EDITING {
|
||||
if key_pressed(.MOUSE_RIGHT) {
|
||||
set_show_cursor(false);
|
||||
// Update camera
|
||||
@@ -274,30 +283,30 @@ base_editor_update :: () {
|
||||
camera.rotation.pitch += -engine.input.mouse.delta_y * MOUSE_SENSITIVITY;
|
||||
|
||||
if key_down(.MOUSE_RIGHT) {
|
||||
editor.last_right_mouse_click_time = time;
|
||||
engine.editor.last_right_mouse_click_time = time;
|
||||
}
|
||||
} else {
|
||||
set_show_cursor(true);
|
||||
|
||||
if time - editor.last_right_mouse_click_time < 0.2 {
|
||||
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;
|
||||
editor.show_menu = true;
|
||||
editor.menu_position.x = mouse_position.x;
|
||||
editor.menu_position.y = cast(float)engine.renderer.render_target_height - mouse_position.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_down(.W) {
|
||||
editor.transform_gizmo.transform_type = .TRANSLATION;
|
||||
engine.editor.transform_gizmo.transform_type = .TRANSLATION;
|
||||
}
|
||||
|
||||
if key_down(.E) {
|
||||
editor.transform_gizmo.transform_type = .ROTATION;
|
||||
engine.editor.transform_gizmo.transform_type = .ROTATION;
|
||||
}
|
||||
|
||||
if key_down(.R) {
|
||||
editor.transform_gizmo.transform_type = .SCALE;
|
||||
engine.editor.transform_gizmo.transform_type = .SCALE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
13
module.jai
13
module.jai
@@ -8,17 +8,20 @@ NETWORKING :: WITH_NETWORKING;
|
||||
//#load "../editor/scene_editor.jai";
|
||||
//#load "../ui/new_ui/new_ui.jai";
|
||||
#load "editor/editor.jai";
|
||||
|
||||
editor: Editor;
|
||||
}
|
||||
|
||||
Engine_Mode :: enum {
|
||||
PLAYING;
|
||||
EDITING;
|
||||
}
|
||||
mode: Engine_Mode;
|
||||
|
||||
Engine_Core :: struct {
|
||||
mode: Engine_Mode;
|
||||
|
||||
#if EDITOR {
|
||||
editor: Editor;
|
||||
}
|
||||
|
||||
window: *Window;
|
||||
renderer: *Renderer;
|
||||
input : Input_State;
|
||||
@@ -57,6 +60,10 @@ coven_init :: (window_title: string, window_width: u32, window_height: u32, full
|
||||
init_audio_system();
|
||||
init_console();
|
||||
|
||||
#if EDITOR {
|
||||
init_editor();
|
||||
}
|
||||
|
||||
ui_init();
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ sync_engine_buffers :: () {
|
||||
update_light_buffer();
|
||||
|
||||
// Camera buffer
|
||||
camera := *engine.current_scene.camera;
|
||||
camera := ifx engine.mode == .EDITING then *engine.editor.camera else *engine.current_scene.camera;
|
||||
|
||||
camera_data : Camera_Data;
|
||||
camera_data.projection_matrix = camera.projection_matrix;
|
||||
|
||||
Reference in New Issue
Block a user