This commit is contained in:
John Alanbrook 2022-08-18 13:50:03 +00:00
parent 5823947fb4
commit 37ef9affb2
3 changed files with 46 additions and 39 deletions

View file

@ -27,7 +27,6 @@
#include <stdio.h>
#include <stdlib.h>
#define __USE_XOPEN_EXTENDED 1
#include "ftw.h"
#include <stb_ds.h>
@ -67,6 +66,8 @@ struct fileasset *selected_asset;
static int selected_index = -1;
int show_desktop = 0;
static int grid1_width = 1;
static int grid1_span = 100;
static int grid2_width = 3;
@ -88,31 +89,30 @@ static const char *get_extension(const char *filepath) {
return strrchr(filepath, '.');
}
static int check_if_resource(const char *fpath, const struct stat *sb,
int typeflag, struct FTW *ftwbuf) {
if (typeflag == FTW_F) {
static int check_if_resource(const char *fpath, const struct stat *sb, int typeflag) {
if (typeflag != FTW_F)
return 0;
const char *ext = get_extension(fpath);
if (ext && is_allowed_extension(ext)) {
struct fileasset *newasset =
(struct fileasset *)calloc(1, sizeof(struct fileasset));
newasset->filename = (char *)malloc(sizeof(char) * strlen(fpath) + 1);
struct fileasset *newasset = calloc(1, sizeof(struct fileasset));
newasset->filename = malloc(sizeof(char) * strlen(fpath) + 1);
strcpy(newasset->filename, fpath);
newasset->extension_len = strlen(ext);
newasset->searched = true;
shput(assets, newasset->filename, newasset);
}
}
return 0;
}
static void print_files_in_directory(const char *dirpath) {
int nflags = 0;
shfree(assets);
nftw(dirpath, &check_if_resource, 10, nflags);
ftw(dirpath, check_if_resource, 10);
}
static void get_all_files() { print_files_in_directory(DATA_PATH); }
static void get_all_files() { print_files_in_directory("."); }
static int *compute_prefix_function(const char *str) {
int str_len = strlen(str);
@ -239,8 +239,14 @@ static void edit_input_cb(GLFWwindow *w, int key, int scancode, int action, int
if (editor_wantkeyboard())
return;
if (action != GLFW_PRESS)
if (action == GLFW_RELEASE) {
switch(key) {
case GLFW_KEY_TAB:
show_desktop = 0;
break;
}
return;
}
switch (key) {
case GLFW_KEY_ESCAPE:
@ -346,6 +352,10 @@ static void edit_input_cb(GLFWwindow *w, int key, int scancode, int action, int
}
*/
break;
case GLFW_KEY_TAB:
show_desktop = 1;
break;
}
}
@ -387,7 +397,7 @@ static void edit_mouse_cb(GLFWwindow *w, int button, int action, int mods) {
}
void editor_init(struct mSDLWindow *window) {
levels = vec_make(MAXNAME, 10);
levels = vec_make(MAXPATH, 10);
get_levels();
editor_load_projects();
findPrefabs();
@ -595,8 +605,7 @@ void editor_project_gui() {
NK_MENU_END()
if (nk_begin(ctx, "Simulate", nk_rect_std, nuk_std)) {
NK_FORCE(simulate)
nk_layout_row_dynamic(ctx, 25, 2);
if (physOn) {
if (nk_button_label(ctx, "Pause"))
@ -609,15 +618,13 @@ void editor_project_gui() {
game_start();
}
nk_end(ctx);
}
NK_FORCE_END()
if (nk_begin(ctx, "Prefab Creator", nk_rect_std, nuk_std)) {
NK_FORCE(prefab)
nk_layout_row_dynamic(ctx, 25, 1);
vec_walk(prefabs, editor_prefab_btn);
nk_end(ctx);
}
NK_FORCE_END()
NK_MENU_START(assets)
nk_layout_row_dynamic(ctx,25,1);
@ -653,7 +660,6 @@ NULL) ? false : true;
if (nk_button_label(ctx, "Reload all files"))
get_all_files();
nk_group_begin(ctx, "##scrolling", NK_WINDOW_NO_SCROLLBAR);
for (int i = 0; i < shlen(assets); i++) {
if (!assets[i].value->searched)
continue;
@ -662,7 +668,6 @@ NULL) ? false : true;
editor_selectasset(assets[i].value);
}
}
nk_group_end(ctx);
NK_MENU_END()
@ -753,8 +758,7 @@ void pickGameObject(int pickID) {
}
int is_allowed_extension(const char *ext) {
for (size_t i = 0;
i < sizeof(allowed_extensions) / sizeof(allowed_extensions[0]); i++) {
for (size_t i = 0; i < sizeof(allowed_extensions) / sizeof(allowed_extensions[0]); i++) {
if (!strcmp(ext + 1, allowed_extensions[i]))
return true;
}
@ -775,11 +779,10 @@ void editor_selectasset(struct fileasset *asset) {
if (!strcmp(ext + 1, "png") || !strcmp(ext + 1, "jpg")) {
asset->data = texture_loadfromfile(asset->filename);
tex_gui_anim.tex = (struct Texture *)asset->data;
tex_gui_anim.tex = asset->data;
asset->type = ASSET_TYPE_IMAGE;
tex_anim_set(&tex_gui_anim);
// float tex_scale = float((float) ASSET_WIN_SIZE /
// tex_gui_anim.tex->width);
float tex_scale = (float) ASSET_WIN_SIZE / (float)tex_gui_anim.tex->width;
if (tex_scale >= 10.f)
tex_scale = 10.f;
} else if (!strcmp(ext + 1, "glsl")) {
@ -906,22 +909,23 @@ void editor_asset_gui(struct fileasset *asset) {
nk_begin(ctx, "Asset Viewer", nk_rect_std, nuk_std);
nuke_nel(2);
nk_labelf(ctx, NK_TEXT_LEFT, "%s", selected_asset->filename);
// ImGui::SameLine();
if (nk_button_label(ctx, "Close"))
selected_asset = NULL;
nuke_nel(1);
switch (asset->type) {
case ASSET_TYPE_NULL:
break;
case ASSET_TYPE_IMAGE:
editor_asset_tex_gui((struct Texture *)asset->data);
editor_asset_tex_gui(asset->data);
break;
case ASSET_TYPE_TEXT:
editor_asset_text_gui((char *)asset->data);
editor_asset_text_gui(asset->data);
break;
}

View file

@ -38,11 +38,15 @@ struct editorVars {
editor_win level;
editor_win gameobject;
editor_win components;
editor_win simulate;
editor_win prefab;
};
struct mGameObject;
#define NK_MENU_START(VAR) if (editor.VAR.show) { \
extern int show_desktop;
#define NK_MENU_START(VAR) if (editor.VAR.show && !show_desktop) { \
if (editor.VAR.rect.w == 0) editor.VAR.rect = nk_rect_std; \
if (nk_begin(ctx, #VAR, editor.VAR.rect, nuk_std)) { \
editor.VAR.rect = nk_window_get_bounds(ctx);
@ -50,10 +54,10 @@ struct mGameObject;
#define NK_MENU_END() } nk_end(ctx); }
#define NK_FORCE(VAR) if (editor.VAR.rect.w == 0) editor.VAR.rect = nk_rect_std; \
if (nk_begin(ctx, #VAR, editor.VAR.rect, nuk_std)) { \
if (!show_desktop && nk_begin(ctx, #VAR, editor.VAR.rect, nuk_std)) { \
editor.VAR.rect = nk_window_get_bounds(ctx);
#define NK_FORCE_END() } nk_end(ctx);
#define NK_FORCE_END() nk_end(ctx); }
#define NEGATE(VAR) VAR = ! VAR

View file

@ -12,7 +12,6 @@
#include <unistd.h>
#include <stdlib.h>
#define __USE_XOPEN_EXTENDED 1
#include <ftw.h>
char *DATA_PATH = NULL;
@ -33,9 +32,9 @@ char pathbuf[MAXPATH];
void resources_init()
{
DATA_PATH = malloc(256);
getcwd(DATA_PATH, 256);
strncat(DATA_PATH, "/", 256);
DATA_PATH = malloc(MAXPATH);
getcwd(DATA_PATH, MAXPATH);
strncat(DATA_PATH, "/", MAXPATH);
if (!PREF_PATH)
PREF_PATH = strdup("./tmp/");
@ -77,7 +76,7 @@ FILE *res_open(char *path, const char *tag)
return f;
}
static int ext_check(const char *path, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
static int ext_check(const char *path, const struct stat *sb, int typeflag)
{
if (typeflag == FTW_F) {
const char *ext = strrchr(path, '.');
@ -93,7 +92,7 @@ void fill_extensions(struct vec *vec, const char *path, const char *ext)
c_vec = vec;
cur_ext = ext;
vec_clear(c_vec);
nftw(path, &ext_check, 10, 0);
ftw(".", ext_check, 10);
}
void findPrefabs()