SpiderPig Posted February 3 Share Posted February 3 Is it possible to get the filename of the currently open material in the material editor in lua extension? Quote Link to comment Share on other sites More sharing options...
Josh Posted February 3 Share Posted February 3 I think program.asseteditors is a table you can iterate through, and get the asset for each one. Keep in mind some might be hidden and not have an asset. void InitEditorLuaBindings(sol::state* L) { //L->set_function("WriteFile", &lua_WriteFile); //L->set_function("OpenFile", &lua_OpenFile); //L->set_function("RequestFile", &lua_RequestFile); #ifdef _WIN32 L->set_function("CreateWindow", sol::overload( //sol::resolve<shared_ptr<Window>(shared_ptr<Display>, const WString&, const int, const int, const int, const int, const WindowStyles, shared_ptr<Window>)>(&CreateWindow), [](std::string title, const int x, const int y, const int width, const int height, shared_ptr<Window> parent, const WindowStyles style) { auto w = CreateWindow(title, x, y, width, height, parent, style); SetDarkMode(w); return w; }, [](std::string title, const int x, const int y, const int width, const int height, shared_ptr<Display> display, const WindowStyles style) { auto w = CreateWindow(title, x, y, width, height, display, style); SetDarkMode(w); return w; }, [](std::string title, const int x, const int y, const int width, const int height, shared_ptr<Window> parent) { auto w = CreateWindow(title, x, y, width, height, parent); SetDarkMode(w); return w; }, [](std::string title, const int x, const int y, const int width, const int height, shared_ptr<Display> display) { auto w = CreateWindow(title, x, y, width, height, display); SetDarkMode(w); return w; } //[](string& title, const int x, const int y, const int width, const int height) { return CreateWindow(title, x, y, width, height); } )); #endif L->new_usertype<UltraEngine::Editor::Console> ( "Console", sol::base_classes, sol::bases<Widget>(), "log", &UltraEngine::Editor::Console::log, "errorlog", &UltraEngine::Editor::Console::errorlog, "warninglog", &UltraEngine::Editor::Console::warninglog, "inputfield", &UltraEngine::Editor::Console::entry ); L->new_usertype<UltraEngine::Editor::TextureInfo> ( "TextureInfoClass", sol::base_classes, sol::bases<UltraEngine::Object>(), "mipchain", &TextureInfo::mipchain ); L->set_function("TextureInfo", [](Object* o) { std::shared_ptr<TextureInfo> i; if (o) i = o->As<TextureInfo>(); return i; }); L->new_usertype<UltraEngine::Editor::TerrainEditor> ( "TerrainEditorClass", sol::base_classes, sol::bases<UltraEngine::Object>(), "panel", &TerrainEditor::panel, "materiallist", &TerrainEditor::materiallist ); L->set_function("TerrainEditor", [](shared_ptr<UltraEngine::Object> o) { return o->As<UltraEngine::Editor::TerrainEditor>(); }); L->new_usertype<UltraEngine::Editor::AssetEditor> ( "AssetEditorClass", sol::base_classes, sol::bases<UltraEngine::Object>(), "texturemenu", &AssetEditor::texturemenu, "materialmenu", &AssetEditor::materialmenu, "modelmenu", &AssetEditor::modelmenu, "asset", &AssetEditor::asset, "window", &AssetEditor::window, "Modify", &AssetEditor::Modify, "texturepanel", &AssetEditor::texturepanel, "UpdateTexturePanel", &AssetEditor::UpdateTexturePanel ); L->set_function("AssetEditor", [](shared_ptr<UltraEngine::Object> o) { return o->As<UltraEngine::Editor::AssetEditor>(); }); L->new_usertype<UltraEngine::Editor::FilePath> ( "FilePathClass", sol::base_classes, sol::bases<UltraEngine::Object>(), "path", sol::property([](UltraEngine::Editor::FilePath& p) { return std::string(p.path.ToUtf8String()); }), "package", sol::property([](UltraEngine::Editor::FilePath& p) { return p.package; }) ); L->new_usertype<UltraEngine::Editor::AssetBrowser> ( "AssetBrowserClass", sol::base_classes, sol::bases<UltraEngine::Object>(), "SelectFile", sol::overload( [](AssetBrowser& a, std::string f) { return a.SelectFile(f); } ), "addpopupmenu", &AssetBrowser::addpopupmenu, "selectedfile", &AssetBrowser::selectedasset, "filepopupmenu", &AssetBrowser::filepopupmenu, "folderpopupmenu", &AssetBrowser::folderpopupmenu, "SelectFolder", sol::overload( [](AssetBrowser& a, std::string f) { return a.SelectFolder(f, nullptr); }, [](AssetBrowser& a, std::string f, shared_ptr<Package> p) { return a.SelectFolder(f, p); } ), "treeview", &AssetBrowser::treeview ); L->new_usertype<UltraEngine::Editor::SceneBrowser> ( "SceneBrowserClass", sol::base_classes, sol::bases<UltraEngine::Object>(), "treeview", &SceneBrowser::treeview, "addpopupmenu", &SceneBrowser::addpopupmenu ); //L->set("GetAuthToken", []() { if (not UserData["authenticationToken"].is_string()) return ""; return std::string(UserData["authenticationToken"]; } ); /*L->new_usertype<UltraEngine::PropertyGroup> ( "PropertyGroupClass", sol::base_classes, sol::bases<Widget>(), "AddProperty", sol::overload( [](PropertyGroup& p, std::string s, PropertyType t) { return p.AddProperty(s, t); } ) );*/ L->new_usertype<UltraEngine::Editor::PropertyGrid> ( "PropertyGridClass", sol::base_classes, sol::bases<Widget>(), "AddGroup", sol::overload( [](PropertyGrid& p, std::string s) { return p.AddGroup(s); }, [](PropertyGrid& p, std::string s, shared_ptr<Icon> i) { return p.AddGroup(s, i); } ) ); /*L->new_usertype<UltraEngine::Editor::AssetFile> ( "AssetFileClass", sol::base_classes, sol::bases<Object>(), "tabber", &UltraEngine::Editor::AssetFile::tabber, "asset", &UltraEngine::Editor::AssetFile::asset, "model", &UltraEngine::Editor::AssetFile::model, "propertygrid", &UltraEngine::Editor::AssetFile::propertygrid ); L->new_usertype<UltraEngine::Editor::AssetEditor> ( "AssetEditorClass", sol::base_classes, sol::bases<Object>(), "window", &UltraEngine::Editor::AssetEditor::window, "closebutton", &UltraEngine::Editor::AssetEditor::closebutton, "files", &UltraEngine::Editor::AssetEditor::files, "Close", &UltraEngine::Editor::AssetEditor::Close );*/ L->new_usertype<SceneObject> ( "GameObjectClass", sol::base_classes, sol::bases<Object>(), "GetParent", &SceneObject::GetParent, "SetName", [](SceneObject& o, std::string n) { o.SetName(n); }, "SetSelected", sol::overload( [](SceneObject& o, bool s) { o.SetSelected(s); }, [](SceneObject& o, bool s, bool r) { o.SetSelected(s, r); } ), "entity", &SceneObject::entity ); L->set("CreateGameObject", sol::overload( &CreateSceneObject, [](shared_ptr<UltraEngine::Entity> e) {return CreateSceneObject(e); }, [](shared_ptr<UltraEngine::Model> e, bool r) {return CreateSceneObject(e, r); }, [](shared_ptr<UltraEngine::Model> e) {return CreateSceneObject(e); }, [](shared_ptr<UltraEngine::Brush> e, bool r) {return CreateSceneObject(e, r); }, [](shared_ptr<UltraEngine::Brush> e) {return CreateSceneObject(e); } )); L->new_usertype<UltraEngine::Editor::OptionsWindow> ( "OptionsWindowClass", sol::base_classes, sol::bases<Object>(), "window", &UltraEngine::Editor::OptionsWindow::window, "AddSetting", [](OptionsWindow& w, std::string g, std::string n, PropertyType p) { return w.AddSetting(g, n, p); } ); L->new_usertype<UltraEngine::Editor::Project> ( "ProjectClass", sol::base_classes, sol::bases<Object>(), "name", sol::property([](UltraEngine::Editor::Project& p) { return std::string(p.name.ToUtf8String()); }), "path", sol::property([](UltraEngine::Editor::Project& p) { return std::string(p.path.ToUtf8String()); }), "properties", sol::property( [](const Project& e) { return tableplusplus::tablewrapper(e.properties); }, [](Project& e, const sol::table& t) { e.properties = t; } ), "Save", &Editor::Project::Save ); L->set("PROPERTY_BOOLEAN", PROPERTY_BOOLEAN); L->set("PROPERTY_OPTION", PROPERTY_OPTION); L->set("PROPERTY_STRING", PROPERTY_STRING); L->new_usertype<UltraEngine::Editor::Program>( "ProgramClass", "GetSelection", &UltraEngine::Editor::Program::GetSelection, "BuildGI", [](UltraEngine::Editor::Program& p) { BuildGI(); }, "AddConverter", & UltraEngine::Editor::Program::AddConverter, "title", sol::property([](UltraEngine::Editor::Program& p) { return std::string(p.apptitle.ToUtf8String()); }), //"commandline", &Editor::Program::commandline, "mainsplitter", & UltraEngine::Editor::Program::mainsplitter, "SelectNone", &UltraEngine::Editor::Program::SelectNone, "subsplitter", & UltraEngine::Editor::Program::secondsplitter, "sidepanel", sol::property([](UltraEngine::Editor::Program& p) { return p.sidepanel; }), "console", & UltraEngine::Editor::Program::console, "asseteditors", &UltraEngine::Editor::Program::asseteditors, "assetbrowser", &UltraEngine::Editor::Program::assetbrowser, "scenebrowser", &UltraEngine::Editor::Program::scenebrowser, "terraineditor", & UltraEngine::Editor::Program::terrainpanel, //"asseteditor", sol::property([](UltraEngine::Editor::Program& p) { return p.GetAssetEditor(); }), "optionsdialog", sol::property([](UltraEngine::Editor::Program& p) { return p.GetOptionsDialog(); }), "path", sol::property([](UltraEngine::Editor::Program& p) { return std::string(AppDir().ToUtf8String()); }), "window", &UltraEngine::Editor::Program::mainwindow, "ui", &UltraEngine::Editor::Program::mainui, "menu", &UltraEngine::Editor::Program::mainmenu, "world", &UltraEngine::Editor::Program::mainworld, "Quit", &UltraEngine::Editor::Program::Shutdown, "OpenAsset", sol::overload( &UltraEngine::Editor::Program::OpenAsset, [](UltraEngine::Editor::Program& p, std::string s) { return p.assetbrowser->OpenAsset(s, nullptr); }, [](UltraEngine::Editor::Program& p, std::string s, Package* ppak) { shared_ptr<Package> pak; if (ppak) pak = ppak->As<Package>(); return p.assetbrowser->OpenAsset(s, pak); } ), "ResetLayout", &UltraEngine::Editor::Program::ResetLayout, //"SetThumbnail", sol::overload( // [](shared_ptr<Widget> w, int item, std::string path) { editor->thumbmanager->SetThumbnail(w, -1, path); }, // [](shared_ptr<Widget> w, int item, std::string path, shared_ptr<Package> package) { editor->thumbmanager->SetThumbnail(w, -1, path, package); }, // [](shared_ptr<Widget> w, int item, std::string path, shared_ptr<Package> package, bool priority) { editor->thumbmanager->SetThumbnail(w, -1, path, package, priority); } //), //"settings", sol::property([](Program& p) {return tablewrapper(&p.settings); }), "settings", sol::property( [](const Program& e) { return tableplusplus::tablewrapper(e.settings); }, [](Program& e, const sol::table& t) { e.settings = t; } ), "project", &Editor::Program::project, "UpdateLayout", & UltraEngine::Editor::Program::UpdateLayout, "ClearThumbnailCache", &UltraEngine::Editor::Program::ClearThumbnailCache ); L->set("program", editor); // Custom event IDs L->set("EVENT_PROGRAMSTART", EVENT_PROGRAMSTART); L->set("EVENT_OPENASSETPREVIEW", EVENT_OPENASSETPREVIEW); L->set("EVENT_CLOSEASSETPREVIEW", EVENT_CLOSEASSETPREVIEW); L->set("EVENT_OPENASSETEDITOR", EVENT_OPENASSETEDITOR); L->set("EVENT_INITASSETEDITOR", EVENT_INITASSETEDITOR); L->set("EVENT_OPENASSET", EVENT_OPENASSET); L->set("EVENT_OPENPROJECT", EVENT_OPENPROJECT); //String formatting functions L->set_function("FormatTime", [](double s) { return std::string(FormatTime(Round(s))); }); L->set_function("FormatDate", [](double s) { return std::string(FormatDate(Round(s))); }); L->set_function("FormatBytes", [](double s) { return std::string(FormatBytes(Round(s))); }); 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.