LumixEngine/src/editor/asset_browser.h

118 lines
3.2 KiB
C
Raw Normal View History

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"
2019-06-21 17:14:06 +02:00
#include "engine/associative_array.h"
2018-01-24 17:33:39 +01:00
#include "engine/hash_map.h"
2016-05-10 08:24:31 +02:00
#include "engine/delegate_list.h"
#include "engine/path.h"
2018-01-24 17:33:39 +01:00
#include "engine/resource.h"
2016-05-10 08:24:31 +02:00
#include "engine/mt/sync.h"
2015-09-14 18:03:45 +02:00
namespace Lumix
{
2016-06-16 22:32:30 +02:00
struct Action;
2019-06-21 18:49:30 +02:00
class Material;
class OutputMemoryStream;
2016-06-08 15:35:35 +02:00
class StudioApp;
2019-06-21 18:49:30 +02:00
class WorldEditor;
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
{
virtual ~IPlugin() {}
2018-01-23 23:56:29 +01:00
virtual bool canCreateResource() const { return false; }
virtual bool createResource(const char* path) { return false; }
virtual const char* getFileDialogFilter() const { return ""; }
virtual const char* getFileDialogExtensions() const { return ""; }
virtual const char* getDefaultExtension() const { return ""; }
2018-01-24 17:33:39 +01:00
virtual void onGUI(Resource* resource) = 0;
2017-05-23 19:57:11 +02:00
virtual void onResourceUnloaded(Resource* resource) = 0;
virtual const char* getName() const = 0;
2018-01-24 17:33:39 +01:00
virtual ResourceType getResourceType() 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() {}
};
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:
2017-11-28 19:37:15 +01:00
explicit AssetBrowser(StudioApp& app);
2015-09-20 17:30:37 +02:00
~AssetBrowser();
2015-10-03 01:14:38 +02:00
void onGUI();
void update();
2017-05-23 19:57:11 +02:00
int getTypeIndex(ResourceType type) const;
void selectResource(const Path& resource, bool record_history);
2019-07-25 18:50:31 +02:00
bool resourceInput(const char* label, const char* str_id, Span<char> buf, ResourceType type);
void addPlugin(IPlugin& plugin);
2018-03-27 01:15:29 +02:00
void removePlugin(IPlugin& plugin);
2017-11-28 19:37:15 +01:00
void openInExternalEditor(Resource* resource) const;
void openInExternalEditor(const char* path) const;
2019-07-25 18:50:31 +02:00
bool resourceList(Span<char> buf, Ref<u32> selected_idx, ResourceType type, float height, bool can_create_new) const;
2019-06-21 18:49:30 +02:00
OutputMemoryStream* beginSaveResource(Resource& resource);
void endSaveResource(Resource& resource, OutputMemoryStream& file, bool success);
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;
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-09-22 15:53:24 +02:00
void dirColumn();
void fileColumn();
void detailsGUI();
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 changeDir(const char* path);
void unloadResource();
2017-05-23 19:57:11 +02:00
void selectResource(Resource* resource, bool record_history);
2016-06-16 22:32:30 +02:00
void goBack();
void goForward();
2019-07-22 18:10:11 +02:00
void deleteTile(u32 idx);
2015-09-14 18:03:45 +02:00
private:
2016-06-08 15:35:35 +02:00
StudioApp& m_app;
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;
2017-05-23 19:57:11 +02:00
Array<Path> m_history;
2016-06-16 22:32:30 +02:00
int m_history_index;
2019-06-23 20:16:01 +02:00
HashMap<ResourceType, IPlugin*> m_plugins;
2017-05-23 19:57:11 +02:00
Resource* m_selected_resource;
2019-07-22 18:10:11 +02:00
int m_context_resource;
char m_new_name[MAX_PATH_LENGTH];
2017-05-23 19:57:11 +02:00
WorldEditor& m_editor;
2015-09-21 22:35:36 +02:00
int m_current_type;
char m_filter[128];
2017-05-23 19:57:11 +02:00
Path m_wanted_resource;
bool m_is_focus_requested;
2017-08-20 00:52:03 +02:00
bool m_show_thumbnails;
2016-06-16 22:32:30 +02:00
Action* m_back_action;
Action* m_forward_action;
2017-05-23 19:57:11 +02:00
};
} // namespace Lumix