Skip to content

Commit ae9d4c1

Browse files
committed
Implement filesystem view.
1 parent 6928cbf commit ae9d4c1

23 files changed

Lines changed: 2144 additions & 1423 deletions

src/editor/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ set(PROJECT_SOURCES
1717
src/ui/world_inspector.h
1818
src/ui/property_inspector.c
1919
src/ui/property_inspector.h
20+
src/ui/filesystem_view.c
21+
src/ui/filesystem_view.h
2022
)
2123

2224
add_executable(${PROJECT_NAME} ${PROJECT_SOURCES})

src/editor/src/editor.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#include <ui/world_inspector.h>
1919

2020
struct te_editor {
21+
// NULL if the game is not started yet.
22+
te_game_manager* game_manager;
23+
2124
// Always valid pointer. Must be destroyed during the editor's destruction.
2225
te_editor_camera* editor_camera;
2326

@@ -41,7 +44,8 @@ te_editor*
4144
editor_create() {
4245
te_editor* editor = malloc(sizeof(te_editor));
4346
editor->editor_camera = editor_camera_create();
44-
editor->ui = editor_ui_create();
47+
editor->game_manager = NULL;
48+
editor->ui = editor_ui_create(editor);
4549
editor->game_world_stats_widget = NULL;
4650
editor->game_world = NULL;
4751
editor->editor_world = NULL;
@@ -77,10 +81,12 @@ editor_on_game_started(void* game_instance, te_game_manager* game_manager) {
7781
te_font_manager* font_manager = renderer_get_font_manager(renderer);
7882
font_manager_load_font(font_manager, "engine/font/font.ttf");
7983

80-
// Create worlds.
8184
te_editor* editor = game_instance;
85+
editor->game_manager = game_manager;
86+
87+
// Create worlds.
8288
editor_create_editor_world(editor, game_manager);
83-
editor_create_game_world(editor, game_manager);
89+
editor_create_game_world(editor, NULL);
8490
}
8591

8692
static void
@@ -95,16 +101,18 @@ prv_editor_destroy_game_world(te_editor* editor, te_game_manager* game_manager)
95101
}
96102

97103
void
98-
editor_create_game_world(te_editor* editor, te_game_manager* game_manager) {
104+
editor_create_game_world(te_editor* editor, const char* relative_path_to_world) {
105+
// Cleanup.
106+
editor_ui_reset(editor->ui);
99107
if (editor->game_world != NULL) {
100-
prv_editor_destroy_game_world(editor, game_manager);
108+
prv_editor_destroy_game_world(editor, editor->game_manager);
101109
}
102110

103-
editor->game_world = game_manager_create_world(game_manager, "game");
111+
editor->game_world = game_manager_create_world(editor->game_manager, "game");
104112
editor_camera_spawn(editor->editor_camera, editor->game_world);
105113

106-
// Prepare a sample scene.
107-
{
114+
if (relative_path_to_world == NULL) {
115+
// Prepare a sample scene.
108116
te_model* floor = model_create();
109117
model_set_name(floor, "floor");
110118
model_set_scale(floor, (vec3){5.0f, 1.0f, 5.0f});
@@ -115,6 +123,8 @@ editor_create_game_world(te_editor* editor, te_game_manager* game_manager) {
115123
model_set_name(box, "box");
116124
model_set_position(box, (vec3){0.0f, 1.0f, -1.0f});
117125
world_spawn_model(editor->game_world, box);
126+
} else {
127+
world_add_from_file(editor->game_world, relative_path_to_world);
118128
}
119129

120130
// Prepare stats widget.
@@ -358,8 +368,10 @@ editor_on_input_source_changed(
358368

359369
void
360370
editor_on_window_received_focus(void* game_instance, struct te_game_manager* game_manager) {
361-
(void)game_instance;
362371
(void)game_manager;
372+
373+
te_editor* editor = game_instance;
374+
editor_ui_refresh_filesystem_view(editor->ui);
363375
}
364376

365377
void

src/editor/src/editor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ te_editor* editor_create();
1212
void editor_destroy(te_editor* editor);
1313

1414
// Destroys previous game world (if existed).
15-
void editor_create_game_world(te_editor* editor, struct te_game_manager* game_manager);
15+
// Optionally specify a non-NULL path to file to load as the new world.
16+
void editor_create_game_world(te_editor* editor, const char* relative_path_to_world);
1617

1718
// window callbacks -------------------------------------------------------------------------------
1819
void editor_on_game_started(void* game_instance, struct te_game_manager* game_manager);

src/editor/src/ui/editor_ui.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,24 @@
44
#include <ui/theme.h>
55
#include <ui/property_inspector.h>
66
#include <ui/world_inspector.h>
7+
#include <ui/filesystem_view.h>
78
#include <widget/rect_widget.h>
89
#include <widget/widget.h>
910

1011
struct te_editor_ui {
1112
te_world_inspector* world_inspector;
1213
te_property_inspector* property_inspector;
14+
te_filesystem_view* filesystem_view;
1315
te_world* game_world;
1416
};
1517

1618
te_editor_ui*
17-
editor_ui_create(void) {
19+
editor_ui_create(struct te_editor* editor) {
1820
te_editor_ui* ui = malloc(sizeof(te_editor_ui));
1921

2022
ui->property_inspector = property_inspector_create(ui);
2123
ui->world_inspector = world_inspector_create(ui->property_inspector);
24+
ui->filesystem_view = filesystem_view_create(editor);
2225

2326
return ui;
2427
}
@@ -27,6 +30,8 @@ void
2730
editor_ui_destroy(te_editor_ui* ui) {
2831
world_inspector_destroy(ui->world_inspector);
2932
property_inspector_destroy(ui->property_inspector);
33+
filesystem_view_destroy(ui->filesystem_view);
34+
3035
free(ui);
3136
}
3237

@@ -57,6 +62,7 @@ editor_ui_spawn(te_editor_ui* ui, te_world* editor_world) {
5762
// Add editor widgets.
5863
world_inspector_add(ui->world_inspector, rect_widget_get_widget(left_rect));
5964
property_inspector_set_parent(ui->property_inspector, rect_widget_get_widget(right_rect));
65+
filesystem_view_add(ui->filesystem_view, rect_widget_get_widget(left_rect));
6066

6167
// Spawn.
6268
world_spawn_widget(editor_world, rect_widget_get_widget(left_rect));
@@ -67,3 +73,12 @@ te_world_inspector*
6773
editor_ui_get_world_inspector(te_editor_ui* ui) {
6874
return ui->world_inspector;
6975
}
76+
77+
void
78+
editor_ui_refresh_filesystem_view(te_editor_ui* ui) {
79+
filesystem_view_refresh(ui->filesystem_view);
80+
}
81+
82+
void editor_ui_reset(te_editor_ui* ui) {
83+
property_inspector_hide(ui->property_inspector);
84+
}

src/editor/src/ui/editor_ui.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#pragma once
22

33
typedef struct te_editor_ui te_editor_ui;
4+
struct te_editor;
45
struct te_world;
56
struct te_world_inspector;
67

7-
te_editor_ui* editor_ui_create(void);
8+
te_editor_ui* editor_ui_create(struct te_editor* editor);
89
void editor_ui_destroy(te_editor_ui* ui);
910

1011
// Creates and spawns editor's UI widgets.
@@ -13,3 +14,9 @@ void editor_ui_spawn(te_editor_ui* ui, struct te_world* editor_world);
1314
// Returns always valid pointer to world inspector.
1415
// Do not delete/free returned pointer.
1516
struct te_world_inspector* editor_ui_get_world_inspector(te_editor_ui* ui);
17+
18+
// Refreshes displayed directory entries in file explorer.
19+
void editor_ui_refresh_filesystem_view(te_editor_ui* ui);
20+
21+
// Clears all information in UI widgets (resets to their initial state).
22+
void editor_ui_reset(te_editor_ui* ui);

0 commit comments

Comments
 (0)