2015-09-14 18:03:45 +02:00
|
|
|
#pragma once
|
2016-01-13 00:48:20 +01:00
|
|
|
|
|
|
|
|
2016-05-10 08:24:31 +02:00
|
|
|
#include "engine/array.h"
|
|
|
|
#include "engine/delegate_list.h"
|
|
|
|
#include "engine/path.h"
|
|
|
|
#include "engine/mt/sync.h"
|
2015-09-14 18:03:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
namespace Lumix
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2017-05-23 19:57:11 +02:00
|
|
|
class Material;
|
|
|
|
class Resource;
|
|
|
|
struct ResourceType;
|
|
|
|
class WorldEditor;
|
2016-06-16 22:32:30 +02:00
|
|
|
struct Action;
|
2015-09-20 17:30:37 +02:00
|
|
|
class FileSystemWatcher;
|
2015-09-29 22:21:43 +02:00
|
|
|
class Metadata;
|
2016-06-08 15:35:35 +02:00
|
|
|
class StudioApp;
|
2015-09-20 17:30:37 +02:00
|
|
|
|
|
|
|
|
2016-01-14 00:09:57 +01:00
|
|
|
class LUMIX_EDITOR_API AssetBrowser
|
2015-09-14 18:03:45 +02:00
|
|
|
{
|
|
|
|
public:
|
2017-08-11 18:26:00 +02:00
|
|
|
struct LUMIX_EDITOR_API IPlugin
|
2015-12-30 12:17:34 +01:00
|
|
|
{
|
|
|
|
virtual ~IPlugin() {}
|
|
|
|
|
2017-05-23 19:57:11 +02:00
|
|
|
virtual bool onGUI(Resource* resource, ResourceType type) = 0;
|
|
|
|
virtual ResourceType getResourceType(const char* ext) = 0;
|
|
|
|
virtual void onResourceUnloaded(Resource* resource) = 0;
|
2015-12-30 12:17:34 +01:00
|
|
|
virtual const char* getName() const = 0;
|
2017-05-23 19:57:11 +02:00
|
|
|
virtual bool hasResourceManager(ResourceType type) const = 0;
|
|
|
|
virtual bool acceptExtension(const char* ext, ResourceType type) const = 0;
|
2017-09-12 12:33:27 +02:00
|
|
|
virtual bool createTile(const char* in_path, const char* out_path, ResourceType type);
|
2017-08-11 17:57:04 +02:00
|
|
|
virtual void update() {}
|
2015-12-30 12:17:34 +01:00
|
|
|
};
|
|
|
|
|
2017-05-23 19:57:11 +02:00
|
|
|
typedef DelegateList<void(const Path&, const char*)> OnResourceChanged;
|
2016-02-22 22:56:46 +01:00
|
|
|
|
2015-09-14 18:03:45 +02:00
|
|
|
public:
|
2016-06-08 15:35:35 +02:00
|
|
|
AssetBrowser(StudioApp& app);
|
2015-09-20 17:30:37 +02:00
|
|
|
~AssetBrowser();
|
2015-10-03 01:14:38 +02:00
|
|
|
void onGUI();
|
2015-09-20 20:28:51 +02:00
|
|
|
void update();
|
2017-05-23 19:57:11 +02:00
|
|
|
const Array<Path>& getResources(int type) const;
|
|
|
|
int getTypeIndex(ResourceType type) const;
|
|
|
|
void selectResource(const Path& resource, bool record_history);
|
|
|
|
bool resourceInput(const char* label, const char* str_id, char* buf, int max_size, ResourceType type);
|
2017-07-04 10:12:48 +02:00
|
|
|
void onInitFinished();
|
2015-12-30 12:17:34 +01:00
|
|
|
void addPlugin(IPlugin& plugin);
|
2017-05-23 19:57:11 +02:00
|
|
|
void openInExternalEditor(Resource* resource);
|
2016-02-18 20:06:10 +01:00
|
|
|
void openInExternalEditor(const char* path);
|
2016-02-21 14:35:15 +01:00
|
|
|
void enableUpdate(bool enable) { m_is_update_enabled = enable; }
|
2016-02-22 22:56:46 +01:00
|
|
|
OnResourceChanged& resourceChanged() { return m_on_resource_changed; }
|
2017-05-23 19:57:11 +02:00
|
|
|
bool resourceList(char* buf, int max_size, ResourceType type, float height);
|
2015-09-14 18:03:45 +02:00
|
|
|
|
2015-09-19 01:18:52 +02:00
|
|
|
public:
|
2017-08-20 00:16:42 +02:00
|
|
|
bool m_is_open;
|
|
|
|
float m_left_column_width = 120;
|
|
|
|
float m_middle_column_width = 300;
|
2017-08-13 18:01:54 +02:00
|
|
|
static const int TILE_SIZE = 128;
|
2015-09-19 01:18:52 +02:00
|
|
|
|
2015-09-14 18:03:45 +02:00
|
|
|
private:
|
2017-08-13 18:01:54 +02:00
|
|
|
struct FileInfo
|
|
|
|
{
|
|
|
|
StaticString<MAX_PATH_LENGTH> clamped_filename;
|
|
|
|
StaticString<MAX_PATH_LENGTH> filepath;
|
|
|
|
u32 file_path_hash;
|
|
|
|
void* tex = nullptr;
|
2017-09-05 18:27:02 +02:00
|
|
|
bool create_called = false;
|
2017-08-13 18:01:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2017-08-20 00:16:42 +02:00
|
|
|
void leftColumn();
|
|
|
|
void middleColumn();
|
|
|
|
void rightColumn();
|
|
|
|
|
2017-09-12 12:33:27 +02:00
|
|
|
void createTile(FileInfo& tile, const char* out_path);
|
2017-09-05 18:27:02 +02:00
|
|
|
void thumbnail(FileInfo& tile);
|
|
|
|
int getThumbnailIndex(int i, int j, int columns) const;
|
|
|
|
void doFilter();
|
2017-08-19 19:29:31 +02:00
|
|
|
void breadcrumbs();
|
2017-08-13 18:01:54 +02:00
|
|
|
void onTilesGUI();
|
|
|
|
void changeDir(const char* path);
|
2015-09-20 17:30:37 +02:00
|
|
|
void onFileChanged(const char* path);
|
2015-09-14 18:03:45 +02:00
|
|
|
void findResources();
|
2016-02-18 20:06:10 +01:00
|
|
|
void processDir(const char* path, int base_length);
|
2015-09-14 18:03:45 +02:00
|
|
|
void addResource(const char* path, const char* filename);
|
2015-09-20 20:28:51 +02:00
|
|
|
void unloadResource();
|
2017-05-23 19:57:11 +02:00
|
|
|
void selectResource(Resource* resource, bool record_history);
|
2016-01-13 00:48:20 +01:00
|
|
|
int getResourceTypeIndex(const char* ext);
|
2017-05-23 19:57:11 +02:00
|
|
|
bool acceptExtension(const char* ext, ResourceType type);
|
2016-06-16 22:32:30 +02:00
|
|
|
void goBack();
|
|
|
|
void goForward();
|
|
|
|
void toggleAutoreload();
|
|
|
|
bool isAutoreload() const { return m_autoreload_changed_resource; }
|
2015-12-30 12:17:34 +01:00
|
|
|
|
2017-05-23 19:57:11 +02:00
|
|
|
ResourceType getResourceType(const char* path) const;
|
2015-09-14 18:03:45 +02:00
|
|
|
|
|
|
|
private:
|
2016-06-08 15:35:35 +02:00
|
|
|
StudioApp& m_app;
|
2015-09-29 22:21:43 +02:00
|
|
|
Metadata& m_metadata;
|
2017-05-23 19:57:11 +02:00
|
|
|
Array<Path> m_changed_files;
|
2017-08-13 18:01:54 +02:00
|
|
|
StaticString<MAX_PATH_LENGTH> m_dir;
|
|
|
|
Array<StaticString<MAX_PATH_LENGTH> > m_subdirs;
|
|
|
|
Array<FileInfo> m_file_infos;
|
2017-09-05 18:27:02 +02:00
|
|
|
Array<int> m_filtered_file_infos;
|
2016-02-22 22:56:46 +01:00
|
|
|
OnResourceChanged m_on_resource_changed;
|
2017-05-23 19:57:11 +02:00
|
|
|
Array<Path> m_history;
|
2016-06-16 22:32:30 +02:00
|
|
|
int m_history_index;
|
2017-05-23 19:57:11 +02:00
|
|
|
Array<IPlugin*> m_plugins;
|
|
|
|
MT::SpinMutex m_changed_files_mutex;
|
|
|
|
Array<Array<Path> > m_resources;
|
|
|
|
Resource* m_selected_resource;
|
|
|
|
WorldEditor& m_editor;
|
2016-02-18 20:06:10 +01:00
|
|
|
FileSystemWatcher* m_watchers[2];
|
2015-09-21 22:35:36 +02:00
|
|
|
int m_current_type;
|
|
|
|
char m_filter[128];
|
2017-05-23 19:57:11 +02:00
|
|
|
char m_patch_base_path[MAX_PATH_LENGTH];
|
|
|
|
Path m_wanted_resource;
|
2015-09-20 20:28:51 +02:00
|
|
|
bool m_autoreload_changed_resource;
|
2015-10-17 20:13:59 +02:00
|
|
|
bool m_is_focus_requested;
|
2016-02-12 21:55:02 +01:00
|
|
|
bool m_activate;
|
2016-02-21 14:35:15 +01:00
|
|
|
bool m_is_update_enabled;
|
2017-07-04 10:12:48 +02:00
|
|
|
bool m_is_init_finished;
|
2017-08-20 00:52:03 +02:00
|
|
|
bool m_show_thumbnails;
|
2016-06-16 22:32:30 +02:00
|
|
|
Action* m_auto_reload_action;
|
|
|
|
Action* m_back_action;
|
|
|
|
Action* m_forward_action;
|
|
|
|
Action* m_refresh_action;
|
2017-05-23 19:57:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace Lumix
|