From cd41c4522d7d31cab73c426a78681c9fd4f7ae28 Mon Sep 17 00:00:00 2001 From: Joachim Meyer Date: Sat, 13 Sep 2014 22:47:50 +0200 Subject: [PATCH 01/19] Fixes #563, adds the ability to open a file directly in the IDE (with the right editor), without adding it to the project (Windows). --- Core/Contents/Source/PolyWinCore.cpp | 20 ++++++++++++++++-- IDE/Build/Windows2013/Polycode.rc | Bin 9330 -> 12372 bytes IDE/Build/Windows2013/Polycode.sln | 8 +++---- IDE/Build/Windows2013/resource.h | Bin 3298 -> 4328 bytes .../WindowsShared/PolycodeWinIDEView.cpp | 3 +++ IDE/Contents/Include/PolycodeEditor.h | 4 +++- IDE/Contents/Include/PolycodeEditorManager.h | 2 ++ IDE/Contents/Include/PolycodeIDEApp.h | 1 + IDE/Contents/Source/PolycodeEditor.cpp | 4 ++++ IDE/Contents/Source/PolycodeEditorManager.cpp | 11 ++++++++++ IDE/Contents/Source/PolycodeEntityEditor.cpp | 1 - IDE/Contents/Source/PolycodeIDEApp.cpp | 9 ++++++++ 12 files changed, 55 insertions(+), 8 deletions(-) diff --git a/Core/Contents/Source/PolyWinCore.cpp b/Core/Contents/Source/PolyWinCore.cpp index 4f06a0a35..a52c3eac5 100644 --- a/Core/Contents/Source/PolyWinCore.cpp +++ b/Core/Contents/Source/PolyWinCore.cpp @@ -1137,7 +1137,7 @@ std::vector Win32Core::openFilePicker(std::vector ext ofn.nMaxFileTitle = 0; ofn.lpstrInitialDir=NULL; - if(allowMultiple) { + if(!allowMultiple) { ofn.Flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_EXPLORER; } else { ofn.Flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_ALLOWMULTISELECT|OFN_EXPLORER; @@ -1147,7 +1147,23 @@ std::vector Win32Core::openFilePicker(std::vector ext if(GetOpenFileName(&ofn)) { if(allowMultiple) { - + String dir = fBuffer; + size_t pos = dir.length(), last = 0; + while (true){ + if (fBuffer[pos + 1] == NULL){ + if (retVec.size() == 0){ + retVec.push_back(dir); + } + break; + } else { + String fileName; + for (last = pos + 1; fBuffer[pos + 1] != NULL; pos++){ + fileName.append(fBuffer[pos + 1]); + } + retVec.push_back(dir + "/" + fileName); + pos++; + } + } } else { retVec.push_back(String(fBuffer)); } diff --git a/IDE/Build/Windows2013/Polycode.rc b/IDE/Build/Windows2013/Polycode.rc index d73e4349ed9eb7946a7d6c4553a62dbeeeda39dd..8f4b134a13c79fbd72ebd3d693dc9115234130d4 100644 GIT binary patch literal 12372 zcmds7Yj4{&6y@gu`wyB53@fsv-PS+gxK8RVi48kR+aZ9FB~6>nb&S|)T429@+c~_x z6-iOD9&OE>^l<-Y{6dMWm%+W|?VsyvsL5swO#;}(YSW_4COrT8%IQZVbaU_K!kMWKXbasMKM;QOm&U%2m zN4R@}cHioy-jRO$cy}MjpP3)=?lJo9;*N|7dra_DtXSktT8iaOdpHFpzhTy=U!Cp8 zty(pJEq_0OXYrnieZC9Y_pN7O?__nvJ?)u!yz;h`pKy$$=tr8&5%cgVR*Nh1e&v_M zyQJm}*JsdZ@%0(XB1FG5L{xX42iE^y!pi7T(1$*ZVA(^vlD>pz7~oD1{l(TfQqDLcu5}zcgar@5ztnsWf76Gh_X4TM$13-A zmcG@0 z!w|FHm_LEy0tkF0WB6%m(lS6*gkcDd56rJX)CIM5k?aA-)OttSmdgXi4WB91Zo4()o-0ro-VaVh%FtqvB+bKoKNWfS73zELYP30LJ}hN7xOGhD?enn<)c zC%ce8<9No1aoc!a$jguh#+3uCy^IIcZmaUr#Zi@;imVJr6KcwNbw(Nsz9b}psXJ#5BXZcmDInQ?O3d7utczcMY&Y{n9 z&_I1C<`e!jA6W|1A}^U$u!5@&x-N{Ib>wMuq?e`&ViTb`_;K@f$M5Ifgn z*C%CBtWpt1Ae0wJ`Eh6c2;>CX!;IP2-rs9bqDYwGF!mmJlqmkZ9*I8-=iY`cmTQ8` z#cXc+f$DQN*WoTA%rH87Q3m)_aB~owt!G`o^9)AS>qAP6w3sZ zkRs*@j4oM4+O4b=zIGDHd#k50EOIZ?mk@`qoy-JTRc(hzG~gX{msRlvsE;A@xkN4s z%5sFF5vR2gy773(6V<+=Hbms+1$89X+@_Af$=9~_$@quM#8BJ5Pd^zE|SSIkqtp=lz#{payGDd)!rAjHL7bx*Z~2@* zxB9nP=Za2S^5?>?n6zy9%1FJ_=WO{4E0UB=7l%X|%*&+yGzO=Op71^KsGr$kC=JyK zwj!As;*Msz(dpH;I=vcNCvsU~x+_pK#`71hH-9W6q`Z@X>r zlt*A8e>CzcLew5lc{Cm3$>QiZqV{;oGqDg4Et?rw9L=YYS8=o+(`P>>l8D{K)}BA* zS#ro9&5m6RuAQ~Vqm@VZt=YNY(F!OdhJ0Pr#nu+jDLe%$u1^XyBE+M05Eny+KBhmE zsd$KTztiqJN{FW|U(z+1U&xp2yAHjqe93Sz4A(uS#c9B}I93bv3Oh3lM$@w|vfMF5n}P z{_XLwni_kvi-)twch*?$?~cynX=9h-O(jotXAx`~&1LBP)i10F@C|u<_2kzM5#`zg z2CY%V5w+o1wfHyVSXn;(InXur6>6cr7BrRS*PUneZ5BMsWme1&X%ozmS&QJ#K<+tA zP;24tK-MyuOVh_B_>RZ@p?9`gz^_rPAIPpy?%2Ft^<83Qg8Qu5aF?jm7UuT*6?dMp zrpQ_u=i@ccG~<)qjBnA0m0;G=EQdgf@JTjVSrs%UkwO^jTMJxLsiMS7|=_7t) z#fQ77$`0*U*2jI8VxApTLeFw-2N?L}Zi#`_Af2Y9AqP?#wDXz7%d& zgr?xLR#PUBr@IfPoC@ydDm%Uu73V-bhgMKuS#v0oLh-J!Cc82>s|w?y(F%*U+|PFf w%lp6XxNNuEnp#YM=I(zNZ$q9c57n2seBPXMqAS+!8LV8s0fzhT<9i?f1E9OO!2kdN delta 1762 zcmb7FT}V@582(HhXWQ94o}HbYoin$y<2JXNBK;vHk*lVX=$bk-247t8> z2uj{Ay6VC!kqW~uLc9oyAnKwbyv;yDqPz%-ATN5q@9Ye%P3>ar``+`s&-1)LXZvvG zd)M4zb?7|NNt_Il0=YmY$T>2G_kKK$vfC9HY1Zafs@JOOUBp3BHwBk$r!`7@fG%rv8nU;n3q<&_y8mw8frjER8q~AROdVn+S3Yr9VMKiv*}jArAxRqiGxeQnhF(L-5G#SiVr4b ziE1}*KYw!y1Nd8)f+=4kzF};Ox0slP-A5Igwo@qjf{)699XYb<$g;X$`9n0zwQ0ie TPJ2GTp2%(cuQfl?{A1T2V(@BP diff --git a/IDE/Build/Windows2013/Polycode.sln b/IDE/Build/Windows2013/Polycode.sln index 02b3dad1f..67ae375fa 100644 --- a/IDE/Build/Windows2013/Polycode.sln +++ b/IDE/Build/Windows2013/Polycode.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Express 2013 for Windows Desktop -VisualStudioVersion = 12.0.21005.1 +# Visual Studio 2013 +VisualStudioVersion = 12.0.30723.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Polycode", "Polycode.vcxproj", "{D6C2171B-9167-4FB6-851A-DC1CEDCFC43D}" EndProject @@ -18,8 +18,8 @@ Global Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {D6C2171B-9167-4FB6-851A-DC1CEDCFC43D}.Debug|Win32.ActiveCfg = Debug|x64 - {D6C2171B-9167-4FB6-851A-DC1CEDCFC43D}.Debug|Win32.Build.0 = Debug|x64 + {D6C2171B-9167-4FB6-851A-DC1CEDCFC43D}.Debug|Win32.ActiveCfg = Debug|Win32 + {D6C2171B-9167-4FB6-851A-DC1CEDCFC43D}.Debug|Win32.Build.0 = Debug|Win32 {D6C2171B-9167-4FB6-851A-DC1CEDCFC43D}.Debug|x64.ActiveCfg = Debug|x64 {D6C2171B-9167-4FB6-851A-DC1CEDCFC43D}.Debug|x64.Build.0 = Debug|x64 {D6C2171B-9167-4FB6-851A-DC1CEDCFC43D}.Release|Win32.ActiveCfg = Release|Win32 diff --git a/IDE/Build/Windows2013/resource.h b/IDE/Build/Windows2013/resource.h index de8ce96948a0217bac086562161c9359c81e324c..e1e0b7a7f1f58e627118b36c7b78069335cc413d 100644 GIT binary patch delta 616 zcmY*W&ubGw6n>N4?2pO1L=8*Ylr&pZs`#U(X_7tJA5j#dEuj|dK`BPCAQ3`EkDfi0 zOh56c9_ponpn?Yv(!ZrAj~3?Sq4;*T3i6m4=DqKI^S*Bm#(u`5W`2#H(m>6&Zg0{f z8qyZ;HM&IudPq;`8TI+zrwxndHu{p{HDQlMzzofG4wClUG8jL~*mG{Z56*s7rBNcS$?p$;vp z!}FpI5md0^6mh|kN}of+X<%1ObD?6z2E9bfv_kh7jkiuasd z-1_HMVg#r4&<^r9_|Ll81OX1Lo2kzUPP#Ehc8GPml(9<;Y-8Sc`!5lG+bJ50c~jWV zo3RsCd6oF5tZPa~cyCQjF3=K3CbmZlw95AMsA24wp}IP(;HcnzeId66cAW@63S~5c GPk#XB1*nn$ delta 479 zcmXYt%}X0m6vgkG$;>$KO>~q&6g4J7=)%?}(M*gM3C0hE5T&#WODWXWf*`tRUAPhK zAJA%#`%)Kf1g#%SLGUlojY|brZWY(jJI`=8@80vfhjZU;>ZW}o+#DGg{!Bk;p1x9& z7HEmS&?2pHH_!byo-FdKkK!chHCK|})Au?(N2>>?{Q}!Y8*C$iQDef*QHF96jSKgc znxHAF&^T`uv2UiZ;kKaW`l5(#E9wG#lpcP{60YP+>`94-xNjBNBa2PZftu`L_R&fG zQLT~WL{f%AHc#VBwc%b>Q1wa-ExWzA^g1<>rHm$W@g(Nrq0)x+Sa)_BpKOU=b|?mQ zjQ_S&Wj^a2#~kF%-=Yh9w&#>-nr3Jgf1P2}oFRN@7rt+se^HE diff --git a/IDE/Build/WindowsShared/PolycodeWinIDEView.cpp b/IDE/Build/WindowsShared/PolycodeWinIDEView.cpp index c6f06ab8e..3504734a8 100644 --- a/IDE/Build/WindowsShared/PolycodeWinIDEView.cpp +++ b/IDE/Build/WindowsShared/PolycodeWinIDEView.cpp @@ -70,6 +70,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case ID_FILE_OPEN_PROJECT: globalApp->openProject(); break; + case ID_FILE_OPEN_FILE: + globalApp->openFilePicker(); + break; case ID_FILE_CLOSE_FILE: globalApp->closeFile(); break; diff --git a/IDE/Contents/Include/PolycodeEditor.h b/IDE/Contents/Include/PolycodeEditor.h index c02b6fac8..8261c03a5 100644 --- a/IDE/Contents/Include/PolycodeEditor.h +++ b/IDE/Contents/Include/PolycodeEditor.h @@ -127,7 +127,9 @@ class PolycodeEditorFactory { bool canHandleExtension(String extension); + std::vector getExtensions(); + protected: - std::vector extensions; + std::vector extensions; }; diff --git a/IDE/Contents/Include/PolycodeEditorManager.h b/IDE/Contents/Include/PolycodeEditorManager.h index 5854b1d52..f93ec3794 100644 --- a/IDE/Contents/Include/PolycodeEditorManager.h +++ b/IDE/Contents/Include/PolycodeEditorManager.h @@ -38,6 +38,8 @@ class PolycodeEditorManager : public EventDispatcher { void registerEditorFactory(PolycodeEditorFactory *editorFactory); PolycodeEditorFactory *getEditorFactoryForExtension(String extension); + + std::vector getExtensionsWithEditor(); void handleEvent(Event *event); diff --git a/IDE/Contents/Include/PolycodeIDEApp.h b/IDE/Contents/Include/PolycodeIDEApp.h index e90347d44..5c64cb8ef 100644 --- a/IDE/Contents/Include/PolycodeIDEApp.h +++ b/IDE/Contents/Include/PolycodeIDEApp.h @@ -68,6 +68,7 @@ class PolycodeIDEApp : public EventDispatcher { void openFileInProject(PolycodeProject *project, String filePath); void openFile(OSFileEntry file); + void openFilePicker(); void stopProject(); diff --git a/IDE/Contents/Source/PolycodeEditor.cpp b/IDE/Contents/Source/PolycodeEditor.cpp index 37e33b679..4afe3f086 100644 --- a/IDE/Contents/Source/PolycodeEditor.cpp +++ b/IDE/Contents/Source/PolycodeEditor.cpp @@ -42,6 +42,10 @@ bool PolycodeEditorFactory::canHandleExtension(String extension) { return false; } +std::vector PolycodeEditorFactory::getExtensions(){ + return extensions; +} + void PolycodeEditor::setFilePath(String newPath) { filePath = newPath; } diff --git a/IDE/Contents/Source/PolycodeEditorManager.cpp b/IDE/Contents/Source/PolycodeEditorManager.cpp index bddfc7241..066f9d197 100644 --- a/IDE/Contents/Source/PolycodeEditorManager.cpp +++ b/IDE/Contents/Source/PolycodeEditorManager.cpp @@ -45,6 +45,17 @@ PolycodeEditorFactory *PolycodeEditorManager::getEditorFactoryForExtension(Strin return NULL; } +std::vector PolycodeEditorManager::getExtensionsWithEditor(){ + std::vector extensions; + for (int i = 0; i < editorFactories.size(); i++) { + PolycodeEditorFactory *factory = editorFactories[i]; + for (int e = 0; e < factory->getExtensions().size(); e++){ + extensions.push_back(CoreFileExtension(factory->getExtensions()[e], factory->getExtensions()[e])); + } + } + return extensions; +} + PolycodeEditor *PolycodeEditorManager::createEditorForExtension(String extension) { for(int i=0;i < editorFactories.size(); i++) { PolycodeEditorFactory *factory = editorFactories[i]; diff --git a/IDE/Contents/Source/PolycodeEntityEditor.cpp b/IDE/Contents/Source/PolycodeEntityEditor.cpp index 4a2795cfa..e7aea4580 100644 --- a/IDE/Contents/Source/PolycodeEntityEditor.cpp +++ b/IDE/Contents/Source/PolycodeEntityEditor.cpp @@ -2517,4 +2517,3 @@ void PolycodeEntityEditor::Resize(int x, int y) { mainSizer->Resize(x, y); PolycodeEditor::Resize(x,y); } - diff --git a/IDE/Contents/Source/PolycodeIDEApp.cpp b/IDE/Contents/Source/PolycodeIDEApp.cpp index c57cff82f..c2e6b9404 100644 --- a/IDE/Contents/Source/PolycodeIDEApp.cpp +++ b/IDE/Contents/Source/PolycodeIDEApp.cpp @@ -703,6 +703,15 @@ void PolycodeIDEApp::openFile(OSFileEntry file) { } } +void PolycodeIDEApp::openFilePicker() { + std::vector extensions = editorManager->getExtensionsWithEditor(); + extensions.insert(extensions.begin(), CoreFileExtension("All Types", "*")); + std::vector filePaths = core->openFilePicker(extensions, true); + for (int f = 0; f < filePaths.size(); f++){ + openFile(OSFileEntry(filePaths[f], OSFileEntry::TYPE_FILE)); + } +} + void PolycodeIDEApp::handleEvent(Event *event) { if(event->getDispatcher() == frame->assetImporterWindow) { From eda3589e1f6214f947e809b80af57ff9bdb97980 Mon Sep 17 00:00:00 2001 From: Joachim Meyer Date: Sat, 16 Aug 2014 14:28:35 +0200 Subject: [PATCH 02/19] First steps to implement a plugin system: *New Plugin Resource, *Plugin Manager, *Props, *load plugins by the ResourceManager --- Core/Contents/Include/PolyCoreServices.h | 11 +- Core/Contents/Include/PolyPlugin.h | 82 ++++++++++++ Core/Contents/Include/PolyPluginManager.h | 43 +++++++ Core/Contents/Include/PolyResource.h | 7 +- Core/Contents/Include/PolyResourceManager.h | 1 + Core/Contents/Source/PolyCoreServices.cpp | 4 + Core/Contents/Source/PolyPlugin.cpp | 129 +++++++++++++++++++ Core/Contents/Source/PolyPluginManager.cpp | 56 ++++++++ Core/Contents/Source/PolyResourceManager.cpp | 27 ++++ 9 files changed, 354 insertions(+), 6 deletions(-) create mode 100644 Core/Contents/Include/PolyPlugin.h create mode 100644 Core/Contents/Include/PolyPluginManager.h create mode 100644 Core/Contents/Source/PolyPlugin.cpp create mode 100644 Core/Contents/Source/PolyPluginManager.cpp diff --git a/Core/Contents/Include/PolyCoreServices.h b/Core/Contents/Include/PolyCoreServices.h index b79f0f8f4..b21a6585e 100755 --- a/Core/Contents/Include/PolyCoreServices.h +++ b/Core/Contents/Include/PolyCoreServices.h @@ -38,10 +38,11 @@ namespace Polycode { class TweenManager; class ResourceManager; class SoundManager; + class PluginManager; class Core; class CoreMutex; class Logger; - + /** * Global services singleton. CoreServices instantiates and provides global Singleton access to all of the main manager classes in Polycode as well as the Renderer and Config classes. */ @@ -141,6 +142,13 @@ namespace Polycode { */ FontManager *getFontManager(); + /** + * Returns the plugin manager. The plugin manager is responsible for loading and managing plugins. + * @return Plugin Manager + * @see PluginManager + */ + PluginManager *getPluginManager(); + /** * Returns the logger. It can log messages and broadcast them to listeners. */ @@ -181,6 +189,7 @@ namespace Polycode { ResourceManager *resourceManager; SoundManager *soundManager; FontManager *fontManager; + PluginManager *pluginManager; Renderer *renderer; }; diff --git a/Core/Contents/Include/PolyPlugin.h b/Core/Contents/Include/PolyPlugin.h new file mode 100644 index 000000000..f4cf98ab6 --- /dev/null +++ b/Core/Contents/Include/PolyPlugin.h @@ -0,0 +1,82 @@ +/* +Copyright (C) 2014 by Joachim Meyer + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#pragma once +#include "PolyGlobals.h" +#include "PolyString.h" +#include "PolyResource.h" + +namespace Polycode { + + class _PolyExport Prop : public PolyBase { + public: + //Prop(int val); + //Prop(Number val); + //Prop(bool val); + //Prop(PolyBase *val); + + Prop(int type, String name); + ~Prop(); + + Prop *loadPropFromEntry(ObjectEntry* entry); + + //Number numberVal; + //int intVal; + //bool boolVal; + //PolyBase *classVal; + + int type; + String name; + + int length; + + std::vector children; + + static const unsigned int PROP_NUMBER = 0; + static const unsigned int PROP_INT = 1; + static const unsigned int PROP_BOOL = 2; + static const unsigned int PROP_STRING = 3; + static const unsigned int PROP_ARRAY = 4; + }; + + class _PolyExport Plugin : public Resource { + public: + Plugin(const String& name); + ~Plugin(); + + //void loadPluginFromFile(const String& fileName); + + Plugin* loadPluginFromEntry(ObjectEntry *entry); + + void addProp(Prop* prop); + + void removeProp(Prop* prop); + + std::vector getProps() const; + unsigned int getNumProps() const; + + protected: + String ext; + + std::vector props; + }; +} \ No newline at end of file diff --git a/Core/Contents/Include/PolyPluginManager.h b/Core/Contents/Include/PolyPluginManager.h new file mode 100644 index 000000000..c46197ea1 --- /dev/null +++ b/Core/Contents/Include/PolyPluginManager.h @@ -0,0 +1,43 @@ +/* +Copyright (C) 2014 by Joachim Meyer + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#pragma once +#include "PolyGlobals.h" +#include "PolyPlugin.h" + +namespace Polycode { + + class String; + + class PluginManager : public PolyBase { + public: + PluginManager(); + ~PluginManager(); + + std::vector loadPluginsFromFile(const String &fileName); + + private: + Number version; + std::vector plugins; + }; + +} \ No newline at end of file diff --git a/Core/Contents/Include/PolyResource.h b/Core/Contents/Include/PolyResource.h index 69596fa59..08f4d2782 100755 --- a/Core/Contents/Include/PolyResource.h +++ b/Core/Contents/Include/PolyResource.h @@ -59,7 +59,8 @@ namespace Polycode { static const int RESOURCE_CUBEMAP = 6; static const int RESOURCE_SPRITE = 7; static const int RESOURCE_ENTITY_INSTANCE = 8; - + static const int RESOURCE_PLUGIN = 9; + bool reloadOnFileModify; static bool defaultReloadOnFileModify; @@ -69,12 +70,8 @@ namespace Polycode { //@} protected: - - int type; String resourcePath; String name; - - }; } diff --git a/Core/Contents/Include/PolyResourceManager.h b/Core/Contents/Include/PolyResourceManager.h index 0fb5b6e4c..509658444 100755 --- a/Core/Contents/Include/PolyResourceManager.h +++ b/Core/Contents/Include/PolyResourceManager.h @@ -106,6 +106,7 @@ namespace Polycode { void parseShadersIntoPool(ResourcePool *pool, const String& dirPath, bool recursive); void parseProgramsIntoPool(ResourcePool *pool, const String& dirPath, bool recursive); void parseCubemapsIntoPool(ResourcePool *pool, const String& dirPath, bool recursive); + void parsePluginsIntoPool(ResourcePool *pool, const String& dirPath, bool recursive); void parseOtherIntoPool(ResourcePool *pool, const String& dirPath, bool recursive); ResourcePool *getGlobalPool(); diff --git a/Core/Contents/Source/PolyCoreServices.cpp b/Core/Contents/Source/PolyCoreServices.cpp index 42620f145..4d6e33f17 100755 --- a/Core/Contents/Source/PolyCoreServices.cpp +++ b/Core/Contents/Source/PolyCoreServices.cpp @@ -95,6 +95,10 @@ FontManager *CoreServices::getFontManager() { return fontManager; } +PluginManager *CoreServices::getPluginManager(){ + return pluginManager; +} + Config *CoreServices::getConfig() { return config; } diff --git a/Core/Contents/Source/PolyPlugin.cpp b/Core/Contents/Source/PolyPlugin.cpp new file mode 100644 index 000000000..cd2c67a06 --- /dev/null +++ b/Core/Contents/Source/PolyPlugin.cpp @@ -0,0 +1,129 @@ +/* +Copyright (C) 2014 by Joachim Meyer + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#include "PolyPlugin.h" +#include "PolyObject.h" + +using namespace Polycode; + +Plugin::Plugin(const String& name) : Resource(Resource::RESOURCE_PLUGIN) { + this->name = name; + +} + +Plugin::~Plugin() {} + +//void Plugin::loadPluginFromFile(const String& fileName) { +// Object loadFile; +// if (!loadFile.loadFromBinary(fileName)) +// if (!loadFile.loadFromXML(fileName)) +// return; +// +// ObjectEntry plugin = loadFile.root; +// +//} + + +Plugin* Plugin::loadPluginFromEntry(ObjectEntry* entry){ + + this->setResourceName((*entry)["name"]->stringVal); + ObjectEntry* props = (*entry)["props"]; + if (!props) + return NULL; + + for (int k = 0; k < props->length; k++){ + ObjectEntry* propEntry = props->children[k]; + if (!propEntry) + continue; + + Prop *prop; + prop->loadPropFromEntry(propEntry); + + this->addProp(prop); + } +} + +//Prop::Prop(int val){ +// this->intVal = val; +// this->type = PROP_INT; +//} +// +//Prop::Prop(Number val) { +// this->numberVal = val; +// this->type = PROP_NUMBER; +//} +// +//Prop::Prop(bool val) { +// this->boolVal = val; +// this->type = PROP_BOOL; +//} +// +//Prop::Prop(PolyBase *val) { +// this->classVal = val; +// this->type = PROP_CLASS; +//} + +Prop::Prop(int type, String name){ + this->type = type; + this->name = name; +} + +Prop::~Prop(){} + +Prop* Prop::loadPropFromEntry(ObjectEntry* entry){ + int type = (*entry)["type"]->intVal; + if (!type) + return NULL; + + if (!(*entry)["name"]) + return NULL; + String name = (*entry)["name"]->stringVal; + + Prop(type, name); + + /*switch (type){ + case Prop::PROP_NUMBER: + prop = new Prop(propEntry->NumberVal); + break; + case Prop::PROP_INT: + prop = new Prop(propEntry->intVal); + break; + case Prop::PROP_BOOL: + prop = new Prop(propEntry->NumberVal); + break; + case Prop::PROP_CLASS: + prop = new Prop(&propEntry->stringVal); + break; + default: + continue; + }*/ + + if (type == 4){ + int i = 0; + while (i < entry->length){ + children.push_back(loadPropFromEntry((*entry->children[i])["prop"])); + i++; + } + this->length = i; + } + return this; +} \ No newline at end of file diff --git a/Core/Contents/Source/PolyPluginManager.cpp b/Core/Contents/Source/PolyPluginManager.cpp new file mode 100644 index 000000000..7a7c4a408 --- /dev/null +++ b/Core/Contents/Source/PolyPluginManager.cpp @@ -0,0 +1,56 @@ +/* +Copyright (C) 2014 by Joachim Meyer + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#include "PolyPluginManager.h" +#include "PolyPlugin.h" +#include "PolyObject.h" + +using namespace Polycode; + +PluginManager::PluginManager() { + version = 1.0; +} + +PluginManager::~PluginManager(){} + +std::vector PluginManager::loadPluginsFromFile(const String &fileName){ + std::vector retPlugins; + Object pluginFile; + if (!pluginFile.loadFromBinary(fileName)) + if (!pluginFile.loadFromXML(fileName)) + return; + + ObjectEntry* versionEntry = pluginFile.root["version"]; + if (!versionEntry->NumberVal <= version) + return; + + for (int i = 0; i < pluginFile.root.length; i++){ + ObjectEntry* pluginEntry = pluginFile.root.children[i]; + if (!pluginEntry) + continue; + + Plugin *plugin; + plugin->loadPluginFromEntry(pluginEntry); + if (plugin) + retPlugins.push_back(plugin); + } +} \ No newline at end of file diff --git a/Core/Contents/Source/PolyResourceManager.cpp b/Core/Contents/Source/PolyResourceManager.cpp index 813254819..48c81fd52 100755 --- a/Core/Contents/Source/PolyResourceManager.cpp +++ b/Core/Contents/Source/PolyResourceManager.cpp @@ -30,6 +30,8 @@ #include "PolyMaterial.h" #include "PolyShader.h" #include "PolyTexture.h" +#include "PolyPluginManager.h" +#include "PolyPlugin.h" #include "OSBasics.h" #include "physfs.h" @@ -121,6 +123,7 @@ void ResourceManager::addDirResource(const String& dirPath, bool recursive) { parseShadersIntoPool(globalPool, dirPath, recursive); parseCubemapsIntoPool(globalPool, dirPath, recursive); parseMaterialsIntoPool(globalPool, dirPath, recursive); + parsePluginsIntoPool(globalPool, dirPath, recursive); parseOtherIntoPool(globalPool, dirPath, recursive); } @@ -312,6 +315,30 @@ void ResourceManager::parseCubemapsIntoPool(ResourcePool *pool, const String& di } } + +void ResourceManager::parsePluginsIntoPool(ResourcePool *pool, const String& dirPath, bool recursive) { + vector resourceDir; + resourceDir = OSBasics::parseFolder(dirPath, false); + + for (int i = 0; i < resourceDir.size(); i++) { + if (resourceDir[i].type == OSFileEntry::TYPE_FILE) { + if (resourceDir[i].extension == "plugin") { + + PluginManager *pluginManager = CoreServices::getInstance()->getPluginManager(); + std::vector plugins = pluginManager->loadPluginsFromFile(resourceDir[i].fullPath); + for (int p = 0; p < plugins.size(); p++) { + pool->addResource(plugins[p]); + } + } + } + else { + if (recursive) + parsePluginsIntoPool(pool, dirPath + "/" + resourceDir[i].name, true); + } + } +} + + void ResourceManager::handleEvent(Event *event) { if(event->getEventCode() == Event::RESOURCE_CHANGE_EVENT) { dispatchEvent(new Event(), Event::CHANGE_EVENT); From 4497246d7e5569923b36bb75ca9cd578909e46c3 Mon Sep 17 00:00:00 2001 From: Joachim Meyer Date: Tue, 19 Aug 2014 18:21:40 +0200 Subject: [PATCH 03/19] Further steps to implement plugin system: *Loading and saving of the Entities' props, *edited EntityProp to suit latest changes, *Entity file version now 3 Conflicts: IDE/Contents/Source/PolycodeEntityEditor.cpp Conflicts: IDE/Contents/Source/PolycodeEntityEditor.cpp --- Core/Contents/CMakeLists.txt | 12 +- Core/Contents/Include/PolyEntity.h | 29 +++- Core/Contents/Include/PolyPlugin.h | 17 +-- .../Include/PolySceneEntityInstance.h | 6 +- Core/Contents/Source/PolyEntity.cpp | 144 ++++++++++++++++-- Core/Contents/Source/PolyPlugin.cpp | 31 +++- Core/Contents/Source/PolyPluginManager.cpp | 4 +- .../Source/PolySceneEntityInstance.cpp | 64 +++++++- IDE/Contents/Include/PolycodeEntityEditor.h | 3 +- IDE/Contents/Include/PolycodeProps.h | 44 +++++- IDE/Contents/Source/PolycodeEntityEditor.cpp | 46 +++++- IDE/Contents/Source/PolycodeProps.cpp | 132 +++++++++++++++- 12 files changed, 460 insertions(+), 72 deletions(-) diff --git a/Core/Contents/CMakeLists.txt b/Core/Contents/CMakeLists.txt index 1b13a78c9..caa69b82c 100644 --- a/Core/Contents/CMakeLists.txt +++ b/Core/Contents/CMakeLists.txt @@ -19,7 +19,7 @@ SET(polycore_SRCS Source/PolyEventHandler.cpp Source/PolyFixedShader.cpp Source/PolyFont.cpp - Source/PolyFontGlyphSheet.cpp + Source/PolyFontGlyphSheet.cpp Source/PolyFontManager.cpp Source/PolyGLCubemap.cpp Source/PolyGLRenderer.cpp @@ -40,6 +40,8 @@ SET(polycore_SRCS Source/PolyObject.cpp Source/PolyParticleEmitter.cpp Source/PolyPerlin.cpp + Source/PolyPlugin.cpp + Source/PolyPluginManager.cpp Source/PolyQuaternion.cpp Source/PolyQuaternionCurve.cpp Source/PolyRectangle.cpp @@ -62,8 +64,8 @@ SET(polycore_SRCS Source/PolySound.cpp Source/PolySoundManager.cpp Source/PolyString.cpp - Source/PolyTextMesh.cpp - Source/PolyTexture.cpp + Source/PolyTextMesh.cpp + Source/PolyTexture.cpp Source/PolyThreaded.cpp Source/PolyTimer.cpp Source/PolyTimerManager.cpp @@ -105,7 +107,7 @@ SET(polycore_HDRS Include/PolyEventHandler.h Include/PolyFixedShader.h Include/PolyFont.h - Include/PolyFontGlyphSheet.h + Include/PolyFontGlyphSheet.h Include/PolyFontManager.h Include/PolyGLCubemap.h Include/PolyGLHeaders.h @@ -129,6 +131,8 @@ SET(polycore_HDRS Include/PolyObject.h Include/PolyParticleEmitter.h Include/PolyPerlin.h + Include/PolyPlugin.h + Include/PolyPluginManager.h Include/PolyQuaternionCurve.h Include/PolyQuaternion.h Include/PolyRectangle.h diff --git a/Core/Contents/Include/PolyEntity.h b/Core/Contents/Include/PolyEntity.h index 28e1fe2a2..1e742285f 100755 --- a/Core/Contents/Include/PolyEntity.h +++ b/Core/Contents/Include/PolyEntity.h @@ -30,6 +30,7 @@ #include "PolyRectangle.h" #include "PolyRay.h" #include "PolyEventDispatcher.h" +#include "PolyPlugin.h" #include namespace Polycode { @@ -42,10 +43,15 @@ namespace Polycode { bool blocked; }; - class _PolyExport EntityProp { + class _PolyExport EntityProp : public Prop { public: - String propName; - String propValue; + EntityProp(const String& name, const unsigned int& type = Prop::PROP_STRING); + + String stringVal; + Number numberVal; + int intVal; + bool boolVal; + std::vector arrayVal; }; class _PolyExport AABB { @@ -722,14 +728,23 @@ namespace Polycode { * @param Property name to look up. * @return String property for specified property name or "null" if this property doesn't exist. */ - String getEntityProp(const String& propName); - + bool readEntityProp(const String& propName, String& propVal); + bool readEntityProp(const String& propName, int& propVal); + bool readEntityProp(const String& propName, Number& propVal); + bool readEntityProp(const String& propName, bool& propVal); + bool readEntityProp(const String& propName, std::vector& propVal); + + std::vector getEntityPropArrayByName(const String& propName) const; /** * Sets the entity property for a specified property name in the entity's custom property dictionary. * @param propName Property name to set. * @param propValue Value to set for the specified property name. */ - void setEntityProp(const String& propName, const String& propValue); + void setEntityProp(const String& propName, const String& propVal); + void setEntityProp(const String& propName, const int& propVal); + void setEntityProp(const String& propName, const Number& propVal); + void setEntityProp(const String& propName, const bool& propVal); + void setEntityProp(const String& propName, const std::vector& propVal); /** * If set to true, the y position of the entity matrix will be multiplied by -1.0, inverting its Y-axis coordinate system. @@ -895,7 +910,7 @@ namespace Polycode { */ unsigned char layerID; - std::vector entityProps; + std::vector entityProps; protected: diff --git a/Core/Contents/Include/PolyPlugin.h b/Core/Contents/Include/PolyPlugin.h index f4cf98ab6..3e494a988 100644 --- a/Core/Contents/Include/PolyPlugin.h +++ b/Core/Contents/Include/PolyPlugin.h @@ -26,24 +26,15 @@ THE SOFTWARE. #include "PolyResource.h" namespace Polycode { - + class ObjectEntry; + class _PolyExport Prop : public PolyBase { public: - //Prop(int val); - //Prop(Number val); - //Prop(bool val); - //Prop(PolyBase *val); - - Prop(int type, String name); + Prop(const String& name, const int type = Prop::PROP_STRING); ~Prop(); Prop *loadPropFromEntry(ObjectEntry* entry); - //Number numberVal; - //int intVal; - //bool boolVal; - //PolyBase *classVal; - int type; String name; @@ -63,8 +54,6 @@ namespace Polycode { Plugin(const String& name); ~Plugin(); - //void loadPluginFromFile(const String& fileName); - Plugin* loadPluginFromEntry(ObjectEntry *entry); void addProp(Prop* prop); diff --git a/Core/Contents/Include/PolySceneEntityInstance.h b/Core/Contents/Include/PolySceneEntityInstance.h index bb4873a0c..75d275a30 100644 --- a/Core/Contents/Include/PolySceneEntityInstance.h +++ b/Core/Contents/Include/PolySceneEntityInstance.h @@ -78,7 +78,9 @@ class SceneEntityInstance : public Entity { SceneEntityInstanceLayer *createNewLayer(String name); - + + void addPluginByName(const String& name, ResourcePool *resourcePool = NULL); + String getFileName() const; bool cloneUsingReload; @@ -94,6 +96,8 @@ class SceneEntityInstance : public Entity { std::vector resourcePools; Scene *parentScene; SceneEntityInstanceResourceEntry *resourceEntry; + + std::vector requiredPlugins; }; diff --git a/Core/Contents/Source/PolyEntity.cpp b/Core/Contents/Source/PolyEntity.cpp index b88f6ad3e..3eb1b9698 100755 --- a/Core/Contents/Source/PolyEntity.cpp +++ b/Core/Contents/Source/PolyEntity.cpp @@ -804,28 +804,150 @@ void Entity::rebuildRotation() { rotationQuat.fromAxes(rotation.x, rotation.y, rotation.z); } -void Entity::setEntityProp(const String& propName, const String& propValue) { +void Entity::setEntityProp(const String& propName, const String& propVal) { for(int i=0; i < entityProps.size(); i++) { - if(entityProps[i].propName == propName) { - entityProps[i].propValue = propValue; + if(entityProps[i]->name == propName) { + entityProps[i]->stringVal = propVal; + entityProps[i]->type = Prop::PROP_STRING; return; } } - EntityProp entityProp; - entityProp.propName = propName; - entityProp.propValue = propValue; + EntityProp* entityProp = new EntityProp(propName, Prop::PROP_STRING); + entityProp->stringVal = propVal; entityProps.push_back(entityProp); } -String Entity::getEntityProp(const String& propName) { +void Entity::setEntityProp(const String& propName, const int& propVal) { + + for (int i = 0; i < entityProps.size(); i++) { + if (entityProps[i]->name == propName) { + entityProps[i]->intVal = propVal; + entityProps[i]->type = Prop::PROP_INT; + return; + } + } + + EntityProp* entityProp = new EntityProp(propName, Prop::PROP_INT); + entityProp->intVal = propVal; + entityProps.push_back(entityProp); +} + +void Entity::setEntityProp(const String& propName, const Number& propVal) { + + for (int i = 0; i < entityProps.size(); i++) { + if (entityProps[i]->name == propName) { + entityProps[i]->numberVal = propVal; + entityProps[i]->type = Prop::PROP_NUMBER; + return; + } + } + + EntityProp* entityProp = new EntityProp(propName, Prop::PROP_NUMBER); + entityProp->numberVal = propVal; + entityProps.push_back(entityProp); +} + +void Entity::setEntityProp(const String& propName, const bool& propVal) { + + for (int i = 0; i < entityProps.size(); i++) { + if (entityProps[i]->name == propName) { + entityProps[i]->boolVal = propVal; + entityProps[i]->type = Prop::PROP_BOOL; + return; + } + } + + EntityProp* entityProp = new EntityProp(propName, Prop::PROP_BOOL); + entityProp->boolVal = propVal; + entityProps.push_back(entityProp); +} + +void Entity::setEntityProp(const String& propName, const std::vector& propVal) { + + for (int i = 0; i < entityProps.size(); i++) { + if (entityProps[i]->name == propName) { + entityProps[i]->arrayVal = propVal; + entityProps[i]->type = Prop::PROP_ARRAY; + return; + } + } + + EntityProp* entityProp = new EntityProp(propName, Prop::PROP_ARRAY); + entityProp->arrayVal = propVal; + entityProps.push_back(entityProp); +} + +bool Entity::readEntityProp(const String& propName, String& propVal) { for(int i=0; i < entityProps.size(); i++) { - if(entityProps[i].propName == propName) { - return entityProps[i].propValue; + if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_STRING) { + propVal = entityProps[i]->stringVal; + return true; + } else if (entityProps[i]->name == propName && entityProps[i]->type != Prop::PROP_STRING) { + return false; + } + } + return false; +} + +bool Entity::readEntityProp(const String& propName, Number& propVal) { + for (int i = 0; i < entityProps.size(); i++) { + if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_NUMBER) { + propVal = entityProps[i]->numberVal; + return true; + } else if (entityProps[i]->name == propName && entityProps[i]->type != Prop::PROP_NUMBER) { + return false; + } + } + return false; +} + +bool Entity::readEntityProp(const String& propName, int& propVal) { + for (int i = 0; i < entityProps.size(); i++) { + if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_INT) { + propVal = entityProps[i]->intVal; + return true; + } else if (entityProps[i]->name == propName && entityProps[i]->type != Prop::PROP_INT) { + return false; + } + } + return false; +} + +bool Entity::readEntityProp(const String& propName, bool& propVal) { + for (int i = 0; i < entityProps.size(); i++) { + if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_BOOL) { + propVal = entityProps[i]->boolVal; + return true; + } else if (entityProps[i]->name == propName && entityProps[i]->type != Prop::PROP_BOOL) { + return false; + } + } + return false; +} + +bool Entity::readEntityProp(const String& propName, std::vector& propVal) { + for (int i = 0; i < entityProps.size(); i++) { + if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_ARRAY) { + propVal = entityProps[i]->arrayVal; + return true; + } else if (entityProps[i]->name == propName && entityProps[i]->type != Prop::PROP_ARRAY) { + return false; + } + } + return false; +} + +std::vector Entity::getEntityPropArrayByName(const String& propName) const { + for (int i = 0; i < entityProps.size(); i++) { + if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_ARRAY) { + return entityProps[i]->arrayVal; + } else if (entityProps[i]->name == propName && entityProps[i]->type != Prop::PROP_ARRAY) { + std::vector retVector; + return retVector; } } - return "null"; } Vector3 Entity::getCombinedPosition() const { @@ -1250,3 +1372,5 @@ MouseEventResult Entity::onMouseWheelDown(const Ray &ray, int timestamp) { } return ret; } + +EntityProp::EntityProp(const String& name, const unsigned int& type) : Prop(name, type) {} diff --git a/Core/Contents/Source/PolyPlugin.cpp b/Core/Contents/Source/PolyPlugin.cpp index cd2c67a06..c011bb051 100644 --- a/Core/Contents/Source/PolyPlugin.cpp +++ b/Core/Contents/Source/PolyPlugin.cpp @@ -22,12 +22,14 @@ THE SOFTWARE. #include "PolyPlugin.h" #include "PolyObject.h" +#include "PolyCoreServices.h" +#include "PolyPluginManager.h" +#include "PolyResourceManager.h" using namespace Polycode; Plugin::Plugin(const String& name) : Resource(Resource::RESOURCE_PLUGIN) { - this->name = name; - + Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_PLUGIN, name); } Plugin::~Plugin() {} @@ -62,6 +64,27 @@ Plugin* Plugin::loadPluginFromEntry(ObjectEntry* entry){ } } +unsigned int Plugin::getNumProps() const { + return props.size(); +} + +void Plugin::addProp(Prop *prop) { + props.push_back(prop); +} + +void Plugin::removeProp(Prop *propToRemove) { + for (int i = 0; i Plugin::getProps() const { + return props; +} + //Prop::Prop(int val){ // this->intVal = val; // this->type = PROP_INT; @@ -82,7 +105,7 @@ Plugin* Plugin::loadPluginFromEntry(ObjectEntry* entry){ // this->type = PROP_CLASS; //} -Prop::Prop(int type, String name){ +Prop::Prop(const String& name, const int type){ this->type = type; this->name = name; } @@ -98,7 +121,7 @@ Prop* Prop::loadPropFromEntry(ObjectEntry* entry){ return NULL; String name = (*entry)["name"]->stringVal; - Prop(type, name); + Prop(name, type); /*switch (type){ case Prop::PROP_NUMBER: diff --git a/Core/Contents/Source/PolyPluginManager.cpp b/Core/Contents/Source/PolyPluginManager.cpp index 7a7c4a408..67553d1bd 100644 --- a/Core/Contents/Source/PolyPluginManager.cpp +++ b/Core/Contents/Source/PolyPluginManager.cpp @@ -37,11 +37,11 @@ std::vector PluginManager::loadPluginsFromFile(const String &fileName){ Object pluginFile; if (!pluginFile.loadFromBinary(fileName)) if (!pluginFile.loadFromXML(fileName)) - return; + return retPlugins; ObjectEntry* versionEntry = pluginFile.root["version"]; if (!versionEntry->NumberVal <= version) - return; + return retPlugins; for (int i = 0; i < pluginFile.root.length; i++){ ObjectEntry* pluginEntry = pluginFile.root.children[i]; diff --git a/Core/Contents/Source/PolySceneEntityInstance.cpp b/Core/Contents/Source/PolySceneEntityInstance.cpp index f17048921..c9dde5945 100644 --- a/Core/Contents/Source/PolySceneEntityInstance.cpp +++ b/Core/Contents/Source/PolySceneEntityInstance.cpp @@ -498,7 +498,6 @@ Entity *SceneEntityInstance::loadObjectEntryIntoEntity(ObjectEntry *entry, Entit entity->color.b = (*entry)["cB"]->NumberVal; entity->color.a = (*entry)["cA"]->NumberVal; - if(!targetEntity) { entity->blendingMode = (*entry)["blendMode"]->intVal; @@ -529,16 +528,47 @@ Entity *SceneEntityInstance::loadObjectEntryIntoEntity(ObjectEntry *entry, Entit } } - ObjectEntry *props = (*entry)["props"]; - if(props) { - for(int i=0; i < props->length; i++) { - ObjectEntry *prop = ((*props))[i]; - if(prop) { - entity->setEntityProp((*prop)["name"]->stringVal, (*prop)["value"]->stringVal); + if (entityFileVersion <= 2){ + ObjectEntry *props = (*entry)["props"]; + if (props) { + for (int i = 0; i < props->length; i++) { + ObjectEntry *prop = ((*props))[i]; + if (prop) { + entity->setEntityProp((*prop)["name"]->stringVal, (*prop)["value"]->stringVal); + } + } + } + } else { + ObjectEntry *props = (*entry)["props"]; + if (props) { + for (int i = 0; i < props->length; i++) { + ObjectEntry *prop = ((*props))[i]; + if (prop) { + switch ((*prop)["type"]->intVal) { + case Prop::PROP_STRING: + entity->setEntityProp((*prop)["name"]->stringVal, (*prop)["value"]->stringVal); + break; + case Prop::PROP_ARRAY: + entity->setEntityProp((*prop)["name"]->stringVal, (*prop)["value"]); + break; + case Prop::PROP_BOOL: + entity->setEntityProp((*prop)["name"]->stringVal, (*prop)["value"]->boolVal); + break; + case Prop::PROP_INT: + entity->setEntityProp((*prop)["name"]->stringVal, (*prop)["value"]->intVal); + break; + case Prop::PROP_NUMBER: + entity->setEntityProp((*prop)["name"]->stringVal, (*prop)["value"]->NumberVal); + break; + default: + entity->setEntityProp((*prop)["name"]->stringVal, (*prop)["value"]->stringVal); + break; + } + } } } } - + ObjectEntry *children = (*entry)["children"]; if(children) { @@ -704,6 +734,14 @@ bool SceneEntityInstance::loadFromFile(const String& fileName) { } } } + + ObjectEntry *plugins = (*settings)["requiredPlugins"]; + if (plugins) { + for (int p = 0; p < plugins->length; p++) { + String requiredPlugin = (*plugins->children[p])["requiredPlugin"]->stringVal; + addPluginByName(requiredPlugin); + } + } } ObjectEntry *root = loadObject.root["root"]; @@ -725,3 +763,13 @@ bool SceneEntityInstance::loadFromFile(const String& fileName) { return true; } + +void SceneEntityInstance::addPluginByName(const String& name, ResourcePool *resourcePool) { + Plugin *plugin; + if (resourcePool) { + plugin = (Plugin*) resourcePool->getResource(Resource::RESOURCE_PLUGIN, name); + } else { + plugin = (Plugin*)Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_PLUGIN, name); + } + requiredPlugins.push_back(plugin); +} diff --git a/IDE/Contents/Include/PolycodeEntityEditor.h b/IDE/Contents/Include/PolycodeEntityEditor.h index de212bcae..ef0e5d5af 100644 --- a/IDE/Contents/Include/PolycodeEntityEditor.h +++ b/IDE/Contents/Include/PolycodeEntityEditor.h @@ -383,7 +383,8 @@ class PolycodeEntityEditor : public PolycodeEditor { void saveFile(); void saveCurveToObject(ObjectEntry *entry, BezierCurve *curve); void saveShaderOptionsToEntry(ObjectEntry *entry, Material *material, ShaderBinding *binding); - + void savePropsToEntry(ObjectEntry *entry, std::vector props); + void saveEntityToObjectEntry(Entity *entity, ObjectEntry *entry); void doAction(String actionName, PolycodeEditorActionData *data); diff --git a/IDE/Contents/Include/PolycodeProps.h b/IDE/Contents/Include/PolycodeProps.h index f75a538ec..5422c82fc 100644 --- a/IDE/Contents/Include/PolycodeProps.h +++ b/IDE/Contents/Include/PolycodeProps.h @@ -77,7 +77,6 @@ class Vector3Prop : public PropProp { }; - class Vector2Prop : public PropProp { public: Vector2Prop(String caption); @@ -130,7 +129,6 @@ class ButtonProp : public PropProp { UIButton *button; }; - class NumberProp : public PropProp { public: NumberProp(String caption); @@ -220,7 +218,6 @@ class RemovableStringProp : public PropProp { UIImageButton *removeButton; }; - class LayerProp : public PropProp { public: LayerProp(SceneEntityInstance *instance, SceneEntityInstanceLayer *layer); @@ -837,7 +834,7 @@ class SceneSpriteSheet : public PropSheet { void setSprite(SceneSprite *sprite); void setEntityInstance(SceneEntityInstance *instance); - + SceneSprite *sprite; SceneSpriteProp *spriteProp; @@ -845,7 +842,6 @@ class SceneSpriteSheet : public PropSheet { ComboProp *defaultStateProp; }; - class CameraSheet : public PropSheet { public: CameraSheet(); @@ -870,7 +866,6 @@ class CameraSheet : public PropSheet { Camera *camera; }; - class SceneEntityInstanceSheet : public PropSheet { public: SceneEntityInstanceSheet(); @@ -939,6 +934,43 @@ class LinkedMaterialsSheet : public PropSheet { }; +class CustomSheet : public PropSheet { +public: + CustomSheet(ObjectEntry *sheetEntry); + ~CustomSheet(); + + void handleEvent(Event *event); + void reloadSheetFromFile(ObjectEntry *sheetEntry); + void refreshProps(ObjectEntry *propsEntry); + void Update(); + + static const int PROP_VECTOR3 = 0; + static const int PROP_VECTOR2 = 1; + static const int PROP_SLIDER = 2; + static const int PROP_BUTTON = 3; + static const int PROP_NUMBER = 4; + static const int PROP_TARGET_BINDING = 5; + static const int PROP_RENDER_TARGET = 6; + static const int PROP_SHADER_PASS = 7; + static const int PROP_REMOVABLE_STRING = 8; + static const int PROP_LAYER = 9; + static const int PROP_CUSTOM = 10; + static const int PROP_STRING = 11; + static const int PROP_COLOR = 12; + static const int PROP_COMBO = 13; + static const int PROP_BOOL = 14; + static const int PROP_SOUND = 15; + static const int PROP_BEZIER_RGBA_CURVE = 16; + static const int PROP_BEZIER_CURVE = 17; + static const int PROP_MATERIAL = 18; + static const int PROP_TEXTURE = 19; + static const int PROP_SCENE_SPRITE = 20; + static const int PROP_SCENE_ENTITY_INSTANCE = 21; + +//private: +// std::vector props; +}; + class PropList : public UIElement { public: PropList(String caption="PROPERTIES"); diff --git a/IDE/Contents/Source/PolycodeEntityEditor.cpp b/IDE/Contents/Source/PolycodeEntityEditor.cpp index e7aea4580..eef0b0b1e 100644 --- a/IDE/Contents/Source/PolycodeEntityEditor.cpp +++ b/IDE/Contents/Source/PolycodeEntityEditor.cpp @@ -2142,11 +2142,7 @@ void PolycodeEntityEditor::saveEntityToObjectEntry(Entity *entity, ObjectEntry * if(entity->entityProps.size() > 0) { ObjectEntry *props = entry->addChild("props"); - for(int i=0; i < entity->entityProps.size(); i++) { - ObjectEntry *prop = props->addChild("prop"); - prop->addChild("name", entity->entityProps[i].propName); - prop->addChild("value", entity->entityProps[i].propValue); - } + savePropsToEntry(props, entity->entityProps); } if(dynamic_cast(entity) && entity != mainView->getObjectRoot()) { @@ -2502,12 +2498,11 @@ void PolycodeEntityEditor::saveFile() { } saveObject.root.name = "entity"; - saveObject.root.addChild("version", 2); + saveObject.root.addChild("version", 3); ObjectEntry *children = saveObject.root.addChild("root"); saveEntityToObjectEntry(mainView->getObjectRoot(), children); - - + saveObject.saveToXML(filePath); setHasChanges(false); } @@ -2517,3 +2512,38 @@ void PolycodeEntityEditor::Resize(int x, int y) { mainSizer->Resize(x, y); PolycodeEditor::Resize(x,y); } + +void PolycodeEntityEditor::savePropsToEntry(ObjectEntry *entry, std::vector props) { + for (int i = 0; i < props.size(); i++) { + ObjectEntry *prop = entry->addChild("prop"); + prop->addChild("name", props[i]->name); + //prop->addChild("value", entity->entityProps[i].propValue); + switch (props[i]->type) { + case Prop::PROP_STRING: + prop->addChild("value", props[i]->stringVal); + break; + case Prop::PROP_ARRAY: + ObjectEntry *childrenProps; + for (int a = 0; a < props[i]->arrayVal.size(); a++) { + ObjectEntry* childProp; + savePropsToEntry(childProp, props[i]->arrayVal); + childrenProps->addChild(childProp); + } + prop->addChild(childrenProps); + break; + case Prop::PROP_BOOL: + prop->addChild("value", props[i]->boolVal); + break; + case Prop::PROP_INT: + prop->addChild("value", props[i]->intVal); + break; + case Prop::PROP_NUMBER: + prop->addChild("value", props[i]->numberVal); + break; + default: + prop->addChild("value", props[i]->stringVal); + break; + } + prop->addChild("type", props[i]->type); + } +} \ No newline at end of file diff --git a/IDE/Contents/Source/PolycodeProps.cpp b/IDE/Contents/Source/PolycodeProps.cpp index 097df0a6f..29bc1baaa 100644 --- a/IDE/Contents/Source/PolycodeProps.cpp +++ b/IDE/Contents/Source/PolycodeProps.cpp @@ -2164,7 +2164,7 @@ void EntityPropSheet::handleEvent(Event *event) { if(event->getDispatcher() == addButtonProp->getButton() && event->getEventType() == "UIEvent") { PolycodeEditorPropActionData *beforeData = PropDataEntity(entity); - entity->entityProps.push_back(EntityProp()); + entity->entityProps.push_back(new EntityProp("")); refreshProps(); PolycodeEditorPropActionData *afterData = PropDataEntity(entity); PropEvent *propEvent = new PropEvent(NULL, this, beforeData, afterData); @@ -2181,12 +2181,12 @@ void EntityPropSheet::handleEvent(Event *event) { case Event::CHANGE_EVENT: PolycodeEditorPropActionData *beforeData = PropDataEntity(entity); if(i-1 < entity->entityProps.size()) { - entity->entityProps[i-1].propName = ((CustomProp*)props[i])->getKey(); - entity->entityProps[i-1].propValue = ((CustomProp*)props[i])->getValue(); + entity->entityProps[i-1]->name = ((CustomProp*)props[i])->getKey(); + entity->entityProps[i-1]->stringVal= ((CustomProp*)props[i])->getValue(); } - PolycodeEditorPropActionData *afterData = PropDataEntity(entity); + PolycodeEditorPropActionData *afterData = PropDataEntity(entity); PropEvent *propEvent = new PropEvent(NULL, this, beforeData, afterData); - dispatchEvent(propEvent, PropEvent::EVENT_PROP_CHANGE); + dispatchEvent(propEvent, PropEvent::EVENT_PROP_CHANGE); break; } } @@ -2208,8 +2208,8 @@ void EntityPropSheet::refreshProps() { for(int i=0; i < entity->entityProps.size(); i++) { - EntityProp prop = entity->entityProps[i]; - CustomProp *newProp = new CustomProp(prop.propName, prop.propValue); + EntityProp* prop = entity->entityProps[i]; + CustomProp *newProp = new CustomProp(prop->name, prop->stringVal); newProp->addEventListener(this, Event::CANCEL_EVENT); newProp->addEventListener(this, Event::CHANGE_EVENT); addProp(newProp); @@ -4011,3 +4011,121 @@ void SoundSheet::setSound(SceneSound *sound) { enabled = false; } } + +CustomSheet::CustomSheet(ObjectEntry *sheetEntry) : PropSheet((*sheetEntry)["name"]->stringVal.toUpperCase(), (*sheetEntry)["fileext"]->stringVal) { + //ObjectEntry *propsEntry = (*sheetEntry)["props"]; + reloadSheetFromFile(sheetEntry); +} + +CustomSheet::~CustomSheet(){} + +void CustomSheet::reloadSheetFromFile(ObjectEntry *sheetEntry){ + if (!(*sheetEntry)["props"]) + return; + + ObjectEntry *propsEntry = (*sheetEntry)["props"]; + refreshProps(propsEntry); + PropProp *prop; + if (propsEntry->children.size() == 0) + return; + + for (int i = 0; i < propsEntry->children.size(); i++) { + String caption = (*propsEntry->children[i])["name"]->stringVal; + switch ((*propsEntry->children[i])["type"]->intVal){ + case PROP_VECTOR3: + prop = new Vector3Prop(caption); + prop->setPropData(PropDataVector3(Vector3((*propsEntry->children[i])["v1"]->NumberVal, (*propsEntry->children[i])["v2"]->NumberVal, (*propsEntry->children[i])["v3"]->NumberVal))); + break; + case PROP_VECTOR2: + prop = new Vector2Prop(caption); + prop->setPropData(PropDataVector2(Vector2((*propsEntry->children[i])["v1"]->NumberVal, (*propsEntry->children[i])["v2"]->NumberVal))); + break; + case PROP_SLIDER: + prop = new SliderProp(caption, (*propsEntry->children[i])["min"]->NumberVal, (*propsEntry->children[i])["max"]->NumberVal); + dynamic_cast(prop)->set((*propsEntry->children[i])["current"]->NumberVal); + break; + case PROP_BUTTON: + prop = new ButtonProp(caption); + break; + case PROP_NUMBER: + prop = new NumberProp(caption); + break; + //case PROP_TARGET_BINDING: + // Shader *shader; + // Material *material; + // ShaderBinding *shaderBin; + // RenderTargetBinding *targetBin; + + // prop = new TargetBindingProp(shader, material, shaderBin, targetBin); + + // break; + //case PROP_RENDER_TARGET: + // ShaderRenderTarget *renderTarget; + // Material *material; + // prop = new RenderTargetProp(renderTarget, material); + // break; + //case PROP_SHADER_PASS: + // prop = new ShaderPassProp(); + // break; + //case PROP_REMOVABLE_STRING: + // prop = new RemovableStringProp(caption); + // break; + //case PROP_LAYER: + // SceneEntityInstance *instance = new SceneEntityInstance(); + // prop = new LayerProp(); + // break; + case PROP_STRING: + prop = new StringProp(caption); + dynamic_cast(prop)->set((*propsEntry->children[i])["current"]->stringVal); + break; + case PROP_COLOR: + prop = new ColorProp(caption); + break; + case PROP_COMBO: + prop = new ComboProp(caption); + break; + case PROP_BOOL: + prop = new BoolProp(caption); + break; + case PROP_SOUND: + prop = new SoundProp(caption); + break; + case PROP_BEZIER_RGBA_CURVE: + prop = new BezierRGBACurveProp(caption); + break; + case PROP_BEZIER_CURVE: + prop = new BezierCurveProp(caption, (*propsEntry->children[i])["curvename"]->stringVal); + break; + case PROP_MATERIAL: + prop = new MaterialProp(caption); + break; + case PROP_TEXTURE: + prop = new TextureProp(caption); + break; + case PROP_SCENE_SPRITE: + prop = new SceneSpriteProp(caption); + break; + case PROP_SCENE_ENTITY_INSTANCE: + prop = new SceneEntityInstanceProp(caption); + break; + case PROP_CUSTOM: + default: + prop = new CustomProp(caption, caption); + break; + } + addProp(prop); + props[i] = prop; + } +} + +void CustomSheet::refreshProps(ObjectEntry *propsEntry){ + +} + +void CustomSheet::Update(){ + +} + +void CustomSheet::handleEvent(Event *e){ + +} From 8c32c3e9b0946d0173050f350aae5e9fc5be878b Mon Sep 17 00:00:00 2001 From: Joachim Meyer Date: Thu, 28 Aug 2014 23:03:15 +0200 Subject: [PATCH 04/19] Rather final changes for loading plugins, props and sheets. Conflicts: Core/Contents/Source/PolyEntity.cpp Conflicts: Core/Contents/Source/PolySceneEntityInstance.cpp IDE/Contents/Include/EntityEditorPropertyView.h IDE/Contents/Source/PolycodeProps.cpp --- Core/Contents/Include/PolyEntity.h | 24 +- Core/Contents/Include/PolyPlugin.h | 9 +- Core/Contents/Include/PolyPluginManager.h | 2 +- .../Include/PolySceneEntityInstance.h | 5 +- Core/Contents/Source/PolyCoreServices.cpp | 2 + Core/Contents/Source/PolyEntity.cpp | 184 ++++-- Core/Contents/Source/PolyPlugin.cpp | 107 ++-- Core/Contents/Source/PolyPluginManager.cpp | 24 +- Core/Contents/Source/PolyResourceManager.cpp | 3 +- .../Source/PolySceneEntityInstance.cpp | 89 +-- .../Include/EntityEditorPropertyView.h | 2 +- IDE/Contents/Include/PolycodeProps.h | 76 +-- .../Source/EntityEditorPropertyView.cpp | 17 +- IDE/Contents/Source/PolycodeEntityEditor.cpp | 22 +- IDE/Contents/Source/PolycodeIDEApp.cpp | 2 +- .../Source/PolycodeMaterialEditor.cpp | 2 +- IDE/Contents/Source/PolycodeProps.cpp | 535 ++++++++++++------ 17 files changed, 692 insertions(+), 413 deletions(-) diff --git a/Core/Contents/Include/PolyEntity.h b/Core/Contents/Include/PolyEntity.h index 1e742285f..b6763a35c 100755 --- a/Core/Contents/Include/PolyEntity.h +++ b/Core/Contents/Include/PolyEntity.h @@ -36,6 +36,7 @@ namespace Polycode { class Renderer; + class ResourcePool; class _PolyExport MouseEventResult { public: @@ -728,12 +729,16 @@ namespace Polycode { * @param Property name to look up. * @return String property for specified property name or "null" if this property doesn't exist. */ - bool readEntityProp(const String& propName, String& propVal); - bool readEntityProp(const String& propName, int& propVal); - bool readEntityProp(const String& propName, Number& propVal); - bool readEntityProp(const String& propName, bool& propVal); - bool readEntityProp(const String& propName, std::vector& propVal); + //bool readEntityProp(const String& propName, String& propVal); + //bool readEntityProp(const String& propName, int& propVal); + //bool readEntityProp(const String& propName, Number& propVal); + //bool readEntityProp(const String& propName, bool& propVal); + //bool readEntityProp(const String& propName, std::vector& propVal); + int getEntityPropIntByName (const String& propName) const; + Number getEntityPropNumberByName (const String& propName) const; + bool getEntityPropBoolByName (const String& propName) const; + String getEntityPropStringByName (const String& propName) const; std::vector getEntityPropArrayByName(const String& propName) const; /** * Sets the entity property for a specified property name in the entity's custom property dictionary. @@ -744,8 +749,11 @@ namespace Polycode { void setEntityProp(const String& propName, const int& propVal); void setEntityProp(const String& propName, const Number& propVal); void setEntityProp(const String& propName, const bool& propVal); - void setEntityProp(const String& propName, const std::vector& propVal); - + void setEntityProp(const String& propName, std::vector propVal); + + bool isRequiredPlugin(const String& pluginName) const; + void addPluginByName(const String& name, ResourcePool *resourcePool = NULL); + /** * If set to true, the y position of the entity matrix will be multiplied by -1.0, inverting its Y-axis coordinate system. */ @@ -911,7 +919,7 @@ namespace Polycode { unsigned char layerID; std::vector entityProps; - + std::vector requiredPlugins; protected: diff --git a/Core/Contents/Include/PolyPlugin.h b/Core/Contents/Include/PolyPlugin.h index 3e494a988..ab6d2d2eb 100644 --- a/Core/Contents/Include/PolyPlugin.h +++ b/Core/Contents/Include/PolyPlugin.h @@ -31,6 +31,7 @@ namespace Polycode { class _PolyExport Prop : public PolyBase { public: Prop(const String& name, const int type = Prop::PROP_STRING); + Prop(ObjectEntry *entry); ~Prop(); Prop *loadPropFromEntry(ObjectEntry* entry); @@ -52,6 +53,7 @@ namespace Polycode { class _PolyExport Plugin : public Resource { public: Plugin(const String& name); + Plugin(ObjectEntry *entry); ~Plugin(); Plugin* loadPluginFromEntry(ObjectEntry *entry); @@ -63,9 +65,14 @@ namespace Polycode { std::vector getProps() const; unsigned int getNumProps() const; - protected: + unsigned int pluginType; + + static const unsigned int PLUGIN_ENTITY = 0; + String ext; + ObjectEntry *sheetEntry; + protected: std::vector props; }; } \ No newline at end of file diff --git a/Core/Contents/Include/PolyPluginManager.h b/Core/Contents/Include/PolyPluginManager.h index c46197ea1..29e187901 100644 --- a/Core/Contents/Include/PolyPluginManager.h +++ b/Core/Contents/Include/PolyPluginManager.h @@ -35,7 +35,7 @@ namespace Polycode { std::vector loadPluginsFromFile(const String &fileName); - private: + protected: Number version; std::vector plugins; }; diff --git a/Core/Contents/Include/PolySceneEntityInstance.h b/Core/Contents/Include/PolySceneEntityInstance.h index 75d275a30..48e56ab4a 100644 --- a/Core/Contents/Include/PolySceneEntityInstance.h +++ b/Core/Contents/Include/PolySceneEntityInstance.h @@ -57,6 +57,7 @@ class SceneEntityInstance : public Entity { void clearInstance(); void parseObjectIntoCurve(ObjectEntry *entry, BezierCurve *curve); + std::vector parseObjectEntryIntoProps(ObjectEntry *propsEntry); Entity *loadObjectEntryIntoEntity(ObjectEntry *entry, Entity *targetEntity = NULL, int entityFileVersion = 1); bool loadFromFile(const String& fileName); void applySceneMesh(ObjectEntry *entry, SceneMesh *sceneMesh); @@ -79,8 +80,6 @@ class SceneEntityInstance : public Entity { SceneEntityInstanceLayer *createNewLayer(String name); - void addPluginByName(const String& name, ResourcePool *resourcePool = NULL); - String getFileName() const; bool cloneUsingReload; @@ -96,8 +95,6 @@ class SceneEntityInstance : public Entity { std::vector resourcePools; Scene *parentScene; SceneEntityInstanceResourceEntry *resourceEntry; - - std::vector requiredPlugins; }; diff --git a/Core/Contents/Source/PolyCoreServices.cpp b/Core/Contents/Source/PolyCoreServices.cpp index 4d6e33f17..7bec527d2 100755 --- a/Core/Contents/Source/PolyCoreServices.cpp +++ b/Core/Contents/Source/PolyCoreServices.cpp @@ -35,6 +35,7 @@ #include "PolyTimerManager.h" #include "PolyTweenManager.h" #include "PolySoundManager.h" +#include "PolyPluginManager.h" using namespace Polycode; @@ -135,6 +136,7 @@ CoreServices::CoreServices() : EventDispatcher() { tweenManager = new TweenManager(); soundManager = new SoundManager(); fontManager = new FontManager(); + pluginManager = new PluginManager(); } CoreServices::~CoreServices() { diff --git a/Core/Contents/Source/PolyEntity.cpp b/Core/Contents/Source/PolyEntity.cpp index 3eb1b9698..6d49c9d72 100755 --- a/Core/Contents/Source/PolyEntity.cpp +++ b/Core/Contents/Source/PolyEntity.cpp @@ -23,6 +23,7 @@ #include "PolyRenderer.h" #include "PolyCoreServices.h" #include "PolyInputEvent.h" +#include "PolyResourceManager.h" using namespace Polycode; @@ -806,13 +807,14 @@ void Entity::rebuildRotation() { void Entity::setEntityProp(const String& propName, const String& propVal) { - for(int i=0; i < entityProps.size(); i++) { - if(entityProps[i]->name == propName) { + for (int i = 0; i < entityProps.size(); i++) { + if (entityProps[i]->name == propName) { entityProps[i]->stringVal = propVal; entityProps[i]->type = Prop::PROP_STRING; return; } - } + } + EntityProp* entityProp = new EntityProp(propName, Prop::PROP_STRING); entityProp->stringVal = propVal; @@ -864,7 +866,7 @@ void Entity::setEntityProp(const String& propName, const bool& propVal) { entityProps.push_back(entityProp); } -void Entity::setEntityProp(const String& propName, const std::vector& propVal) { +void Entity::setEntityProp(const String& propName, std::vector propVal) { for (int i = 0; i < entityProps.size(); i++) { if (entityProps[i]->name == propName) { @@ -879,75 +881,159 @@ void Entity::setEntityProp(const String& propName, const std::vectorname == propName && entityProps[i]->type == Prop::PROP_STRING) { - propVal = entityProps[i]->stringVal; - return true; - } else if (entityProps[i]->name == propName && entityProps[i]->type != Prop::PROP_STRING) { - return false; +//bool Entity::readEntityProp(const String& propName, String& propVal) { +// for(int i=0; i < entityProps.size(); i++) { +// if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_STRING) { +// propVal = entityProps[i]->stringVal; +// return true; +// } else if (entityProps[i]->name == propName && entityProps[i]->type != Prop::PROP_STRING) { +// return false; +// } +// } +// return false; +//} +// +//bool Entity::readEntityProp(const String& propName, Number& propVal) { +// for (int i = 0; i < entityProps.size(); i++) { +// if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_NUMBER) { +// propVal = entityProps[i]->numberVal; +// return true; +// } else if (entityProps[i]->name == propName && entityProps[i]->type != Prop::PROP_NUMBER) { +// return false; +// } +// } +// return false; +//} +// +//bool Entity::readEntityProp(const String& propName, int& propVal) { +// for (int i = 0; i < entityProps.size(); i++) { +// if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_INT) { +// propVal = entityProps[i]->intVal; +// return true; +// } else if (entityProps[i]->name == propName && entityProps[i]->type != Prop::PROP_INT) { +// return false; +// } +// } +// return false; +//} +// +//bool Entity::readEntityProp(const String& propName, bool& propVal) { +// for (int i = 0; i < entityProps.size(); i++) { +// if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_BOOL) { +// propVal = entityProps[i]->boolVal; +// return true; +// } else if (entityProps[i]->name == propName && entityProps[i]->type != Prop::PROP_BOOL) { +// return false; +// } +// } +// return false; +//} +// +//bool Entity::readEntityProp(const String& propName, std::vector& propVal) { +// for (int i = 0; i < entityProps.size(); i++) { +// if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_ARRAY) { +// propVal = entityProps[i]->arrayVal; +// return true; +// } else if (entityProps[i]->name == propName && entityProps[i]->type != Prop::PROP_ARRAY) { +// return false; +// } +// } +// return false; +//} + +int Entity::getEntityPropIntByName(const String& propName) const { + for (int i = 0; i < entityProps.size(); i++) { + if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_INT) { + return entityProps[i]->intVal; + } + if (entityProps[i]->type == Prop::PROP_ARRAY) { + for (int j = 0; j < entityProps[i]->arrayVal.size(); j++) { + if (entityProps[i]->arrayVal[j]->name == propName && entityProps[i]->arrayVal[j]->type == Prop::PROP_INT) { + EntityProp* retVal = (EntityProp*)entityProps[i]->arrayVal[j]; + return retVal->intVal; + } + } } } return false; } -bool Entity::readEntityProp(const String& propName, Number& propVal) { +Number Entity::getEntityPropNumberByName(const String& propName) const { for (int i = 0; i < entityProps.size(); i++) { if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_NUMBER) { - propVal = entityProps[i]->numberVal; - return true; - } else if (entityProps[i]->name == propName && entityProps[i]->type != Prop::PROP_NUMBER) { - return false; + return entityProps[i]->numberVal; } - } - return false; -} - -bool Entity::readEntityProp(const String& propName, int& propVal) { - for (int i = 0; i < entityProps.size(); i++) { - if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_INT) { - propVal = entityProps[i]->intVal; - return true; - } else if (entityProps[i]->name == propName && entityProps[i]->type != Prop::PROP_INT) { - return false; + if (entityProps[i]->type == Prop::PROP_ARRAY) { + for (int j = 0; j < entityProps[i]->arrayVal.size(); j++) { + if (entityProps[i]->arrayVal[j]->name == propName && entityProps[i]->arrayVal[j]->type == Prop::PROP_NUMBER) { + EntityProp* retVal = (EntityProp*)entityProps[i]->arrayVal[j]; + return retVal->numberVal; + } + } } } - return false; + return Number(NULL); } -bool Entity::readEntityProp(const String& propName, bool& propVal) { +bool Entity::getEntityPropBoolByName(const String& propName) const { for (int i = 0; i < entityProps.size(); i++) { if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_BOOL) { - propVal = entityProps[i]->boolVal; - return true; - } else if (entityProps[i]->name == propName && entityProps[i]->type != Prop::PROP_BOOL) { - return false; + return entityProps[i]->boolVal; + } + if (entityProps[i]->type == Prop::PROP_ARRAY) { + for (int j = 0; j < entityProps[i]->arrayVal.size(); j++) { + if (entityProps[i]->arrayVal[j]->name == propName && entityProps[i]->arrayVal[j]->type == Prop::PROP_BOOL) { + EntityProp* retVal = (EntityProp*)entityProps[i]->arrayVal[j]; + return retVal->boolVal; + } + } } } - return false; + return -1; } -bool Entity::readEntityProp(const String& propName, std::vector& propVal) { +String Entity::getEntityPropStringByName(const String& propName) const { for (int i = 0; i < entityProps.size(); i++) { - if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_ARRAY) { - propVal = entityProps[i]->arrayVal; - return true; - } else if (entityProps[i]->name == propName && entityProps[i]->type != Prop::PROP_ARRAY) { - return false; + if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_STRING) { + return entityProps[i]->stringVal; + } + if (entityProps[i]->type == Prop::PROP_ARRAY) { + for (int j = 0; j < entityProps[i]->arrayVal.size(); j++) { + if (entityProps[i]->arrayVal[j]->name == propName && entityProps[i]->arrayVal[j]->type == Prop::PROP_STRING) { + EntityProp* retVal = (EntityProp*)entityProps[i]->arrayVal[j]; + return retVal->stringVal; + } + } } } - return false; + return String("null"); } std::vector Entity::getEntityPropArrayByName(const String& propName) const { for (int i = 0; i < entityProps.size(); i++) { if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_ARRAY) { return entityProps[i]->arrayVal; - } else if (entityProps[i]->name == propName && entityProps[i]->type != Prop::PROP_ARRAY) { - std::vector retVector; - return retVector; + } + if (entityProps[i]->type == Prop::PROP_ARRAY) { + for (int j = 0; j < entityProps[i]->arrayVal.size(); j++) { + if (entityProps[i]->arrayVal[j]->name == propName && entityProps[i]->arrayVal[j]->type == Prop::PROP_ARRAY) { + EntityProp* retVal = (EntityProp*)entityProps[i]->arrayVal[j]; + return retVal->arrayVal; + } + } } } + std::vector retVector; + return retVector; +} + +bool Entity::isRequiredPlugin(const String& pluginName) const { + for (int i = 0; i < requiredPlugins.size(); i++) { + if (requiredPlugins[i]->getResourceName() == pluginName){ + return true; + } + } + return false; } Vector3 Entity::getCombinedPosition() const { @@ -1374,3 +1460,13 @@ MouseEventResult Entity::onMouseWheelDown(const Ray &ray, int timestamp) { } EntityProp::EntityProp(const String& name, const unsigned int& type) : Prop(name, type) {} + +void Entity::addPluginByName(const String& pluginName, ResourcePool *resourcePool) { + Plugin *plugin; + if (resourcePool) { + plugin = (Plugin*)resourcePool->getResource(Resource::RESOURCE_PLUGIN, pluginName); + } else { + plugin = (Plugin*)Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_PLUGIN, pluginName); + } + requiredPlugins.push_back(plugin); +} \ No newline at end of file diff --git a/Core/Contents/Source/PolyPlugin.cpp b/Core/Contents/Source/PolyPlugin.cpp index c011bb051..b3defd9fe 100644 --- a/Core/Contents/Source/PolyPlugin.cpp +++ b/Core/Contents/Source/PolyPlugin.cpp @@ -25,6 +25,7 @@ THE SOFTWARE. #include "PolyCoreServices.h" #include "PolyPluginManager.h" #include "PolyResourceManager.h" +#include "PolyLogger.h" using namespace Polycode; @@ -32,36 +33,38 @@ Plugin::Plugin(const String& name) : Resource(Resource::RESOURCE_PLUGIN) { Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_PLUGIN, name); } -Plugin::~Plugin() {} +Plugin::Plugin(ObjectEntry *entry) : Resource(Resource::RESOURCE_PLUGIN) { + loadPluginFromEntry(entry); +} -//void Plugin::loadPluginFromFile(const String& fileName) { -// Object loadFile; -// if (!loadFile.loadFromBinary(fileName)) -// if (!loadFile.loadFromXML(fileName)) -// return; -// -// ObjectEntry plugin = loadFile.root; -// -//} +Plugin::~Plugin() {} +Plugin* Plugin::loadPluginFromEntry(ObjectEntry* entry){ + if ((*entry)["name"]) + this->setResourceName((*entry)["name"]->stringVal); + + if ((*entry)["fileext"]) + this->ext = (*entry)["fileext"]->stringVal; + + if ((*entry)["sheet"] && (*(*entry)["sheet"])["props"]) + this->sheetEntry = (*entry)["sheet"]; -Plugin* Plugin::loadPluginFromEntry(ObjectEntry* entry){ + if ((*entry)["type"]) + this->pluginType = (*entry)["type"]->intVal; - this->setResourceName((*entry)["name"]->stringVal); ObjectEntry* props = (*entry)["props"]; - if (!props) - return NULL; - - for (int k = 0; k < props->length; k++){ - ObjectEntry* propEntry = props->children[k]; - if (!propEntry) - continue; - - Prop *prop; - prop->loadPropFromEntry(propEntry); - - this->addProp(prop); + if (props) { + for (int k = 0; k < props->length; k++) { + ObjectEntry* propEntry = props->children[k]; + if (!propEntry) + continue; + + Prop *prop = new Prop(propEntry); + this->addProp(prop); + } } + Logger::log("Adding plugin: [%s]\n", this->getResourceName().c_str()); + return this; } unsigned int Plugin::getNumProps() const { @@ -85,31 +88,15 @@ std::vector Plugin::getProps() const { return props; } -//Prop::Prop(int val){ -// this->intVal = val; -// this->type = PROP_INT; -//} -// -//Prop::Prop(Number val) { -// this->numberVal = val; -// this->type = PROP_NUMBER; -//} -// -//Prop::Prop(bool val) { -// this->boolVal = val; -// this->type = PROP_BOOL; -//} -// -//Prop::Prop(PolyBase *val) { -// this->classVal = val; -// this->type = PROP_CLASS; -//} - Prop::Prop(const String& name, const int type){ this->type = type; this->name = name; } +Prop::Prop(ObjectEntry *entry) { + loadPropFromEntry(entry); +} + Prop::~Prop(){} Prop* Prop::loadPropFromEntry(ObjectEntry* entry){ @@ -121,32 +108,18 @@ Prop* Prop::loadPropFromEntry(ObjectEntry* entry){ return NULL; String name = (*entry)["name"]->stringVal; - Prop(name, type); - - /*switch (type){ - case Prop::PROP_NUMBER: - prop = new Prop(propEntry->NumberVal); - break; - case Prop::PROP_INT: - prop = new Prop(propEntry->intVal); - break; - case Prop::PROP_BOOL: - prop = new Prop(propEntry->NumberVal); - break; - case Prop::PROP_CLASS: - prop = new Prop(&propEntry->stringVal); - break; - default: - continue; - }*/ + this->type = type; + this->name = name; if (type == 4){ - int i = 0; - while (i < entry->length){ - children.push_back(loadPropFromEntry((*entry->children[i])["prop"])); - i++; + int l = 0; + for (int i = 0; i < entry->children.size(); i++) { + if (entry->children[i]->name == "prop") { + children.push_back(new Prop(entry->children[i])); + l++; + } } - this->length = i; + this->length = l; } return this; } \ No newline at end of file diff --git a/Core/Contents/Source/PolyPluginManager.cpp b/Core/Contents/Source/PolyPluginManager.cpp index 67553d1bd..75fcee18a 100644 --- a/Core/Contents/Source/PolyPluginManager.cpp +++ b/Core/Contents/Source/PolyPluginManager.cpp @@ -23,6 +23,7 @@ THE SOFTWARE. #include "PolyPluginManager.h" #include "PolyPlugin.h" #include "PolyObject.h" +#include "PolyLogger.h" using namespace Polycode; @@ -38,19 +39,28 @@ std::vector PluginManager::loadPluginsFromFile(const String &fileName){ if (!pluginFile.loadFromBinary(fileName)) if (!pluginFile.loadFromXML(fileName)) return retPlugins; + + //Logger::log("Loading plugins from %s", fileName.c_str()); - ObjectEntry* versionEntry = pluginFile.root["version"]; - if (!versionEntry->NumberVal <= version) - return retPlugins; + version = 1.0; - for (int i = 0; i < pluginFile.root.length; i++){ + //ObjectEntry* versionEntry = pluginFile.root["version"]; + //if (versionEntry->NumberVal > version) + // return retPlugins; + + //if (!pluginsEntry) { + // Logger::log("No plugins in %s\n", fileName.c_str()); + // return retPlugins; + //} + + for (int i = 0; i < pluginFile.root.children.size(); i++){ ObjectEntry* pluginEntry = pluginFile.root.children[i]; - if (!pluginEntry) + if (!pluginEntry || pluginEntry->name != "plugin") continue; - Plugin *plugin; - plugin->loadPluginFromEntry(pluginEntry); + Plugin *plugin = new Plugin(pluginEntry); if (plugin) retPlugins.push_back(plugin); } + return retPlugins; } \ No newline at end of file diff --git a/Core/Contents/Source/PolyResourceManager.cpp b/Core/Contents/Source/PolyResourceManager.cpp index 48c81fd52..e38b04eb9 100755 --- a/Core/Contents/Source/PolyResourceManager.cpp +++ b/Core/Contents/Source/PolyResourceManager.cpp @@ -330,8 +330,7 @@ void ResourceManager::parsePluginsIntoPool(ResourcePool *pool, const String& dir pool->addResource(plugins[p]); } } - } - else { + } else { if (recursive) parsePluginsIntoPool(pool, dirPath + "/" + resourceDir[i].name, true); } diff --git a/Core/Contents/Source/PolySceneEntityInstance.cpp b/Core/Contents/Source/PolySceneEntityInstance.cpp index c9dde5945..10ed104a9 100644 --- a/Core/Contents/Source/PolySceneEntityInstance.cpp +++ b/Core/Contents/Source/PolySceneEntityInstance.cpp @@ -273,6 +273,36 @@ void SceneEntityInstance::parseObjectIntoCurve(ObjectEntry *entry, BezierCurve * } +std::vector SceneEntityInstance::parseObjectEntryIntoProps(ObjectEntry *propsEntry) { + Entity *retEntity = new Entity(); + for (int i = 0; i < propsEntry->children.size(); i++) { + ObjectEntry *prop = ((*propsEntry))[i]; + if (prop->name=="prop") { + switch ((*prop)["type"]->intVal) { + case Prop::PROP_STRING: + retEntity->setEntityProp((*prop)["name"]->stringVal, (*prop)["value"]->stringVal); + break; + case Prop::PROP_ARRAY: + retEntity->setEntityProp((*prop)["name"]->stringVal, parseObjectEntryIntoProps(prop)); + break; + case Prop::PROP_BOOL: + retEntity->setEntityProp((*prop)["name"]->stringVal, (*prop)["value"]->boolVal); + break; + case Prop::PROP_INT: + retEntity->setEntityProp((*prop)["name"]->stringVal, (*prop)["value"]->intVal); + break; + case Prop::PROP_NUMBER: + retEntity->setEntityProp((*prop)["name"]->stringVal, (*prop)["value"]->NumberVal); + break; + default: + retEntity->setEntityProp((*prop)["name"]->stringVal, (*prop)["value"]->stringVal); + break; + } + } + } + return retEntity->entityProps; +} + Entity *SceneEntityInstance::loadObjectEntryIntoEntity(ObjectEntry *entry, Entity *targetEntity, int entityFileVersion) { Entity *entity = NULL; @@ -539,34 +569,19 @@ Entity *SceneEntityInstance::loadObjectEntryIntoEntity(ObjectEntry *entry, Entit } } } else { - ObjectEntry *props = (*entry)["props"]; - if (props) { - for (int i = 0; i < props->length; i++) { - ObjectEntry *prop = ((*props))[i]; - if (prop) { - switch ((*prop)["type"]->intVal) { - case Prop::PROP_STRING: - entity->setEntityProp((*prop)["name"]->stringVal, (*prop)["value"]->stringVal); - break; - case Prop::PROP_ARRAY: - entity->setEntityProp((*prop)["name"]->stringVal, (*prop)["value"]); - break; - case Prop::PROP_BOOL: - entity->setEntityProp((*prop)["name"]->stringVal, (*prop)["value"]->boolVal); - break; - case Prop::PROP_INT: - entity->setEntityProp((*prop)["name"]->stringVal, (*prop)["value"]->intVal); - break; - case Prop::PROP_NUMBER: - entity->setEntityProp((*prop)["name"]->stringVal, (*prop)["value"]->NumberVal); - break; - default: - entity->setEntityProp((*prop)["name"]->stringVal, (*prop)["value"]->stringVal); - break; - } + ObjectEntry *plugins = (*entry)["requiredPlugins"]; + if (plugins) { + for (int p = 0; p < plugins->children.size(); p++) { + if (plugins->children[p]->name == "requiredPlugin") { + String requiredPlugin = (*plugins->children[p])["name"]->stringVal; + entity->addPluginByName(requiredPlugin); } } } + ObjectEntry *props = (*entry)["props"]; + if (props) { + entity->entityProps = parseObjectEntryIntoProps(props); + } } ObjectEntry *children = (*entry)["children"]; @@ -735,13 +750,6 @@ bool SceneEntityInstance::loadFromFile(const String& fileName) { } } - ObjectEntry *plugins = (*settings)["requiredPlugins"]; - if (plugins) { - for (int p = 0; p < plugins->length; p++) { - String requiredPlugin = (*plugins->children[p])["requiredPlugin"]->stringVal; - addPluginByName(requiredPlugin); - } - } } ObjectEntry *root = loadObject.root["root"]; @@ -764,12 +772,11 @@ bool SceneEntityInstance::loadFromFile(const String& fileName) { return true; } -void SceneEntityInstance::addPluginByName(const String& name, ResourcePool *resourcePool) { - Plugin *plugin; - if (resourcePool) { - plugin = (Plugin*) resourcePool->getResource(Resource::RESOURCE_PLUGIN, name); - } else { - plugin = (Plugin*)Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_PLUGIN, name); - } - requiredPlugins.push_back(plugin); -} + + + + + + + + diff --git a/IDE/Contents/Include/EntityEditorPropertyView.h b/IDE/Contents/Include/EntityEditorPropertyView.h index 8d969a953..a27bba8bb 100644 --- a/IDE/Contents/Include/EntityEditorPropertyView.h +++ b/IDE/Contents/Include/EntityEditorPropertyView.h @@ -60,7 +60,7 @@ class EntityEditorPropertyView : public UIElement { SoundSheet *soundSheet; SceneCurveSheet *curveSheet; CameraSheet *cameraSheet; - EntityPropSheet *propSheet; + std::vector propSheets; SceneMeshSheet *sceneMeshSheet; ShaderTexturesSheet *shaderTexturesSheet; diff --git a/IDE/Contents/Include/PolycodeProps.h b/IDE/Contents/Include/PolycodeProps.h index 5422c82fc..c1ec3dacc 100644 --- a/IDE/Contents/Include/PolycodeProps.h +++ b/IDE/Contents/Include/PolycodeProps.h @@ -36,20 +36,45 @@ class PolycodeEditorPropActionData; class PropProp : public UIElement { public: - PropProp(String caption, String type); + PropProp(String caption, int type); ~PropProp(); virtual void setPropData(PolycodeEditorPropActionData* data) {} virtual void setPropWidth(Number width) {} void setPropName(String newName); - - String propType; + String getPropName(); + + int propType; UILabel *label; Entity *propContents; bool suppressChangeEvent; bool settingFromData; + + static const int PROP_VECTOR3 = 0; + static const int PROP_VECTOR2 = 1; + static const int PROP_SLIDER = 2; + static const int PROP_BUTTON = 3; + static const int PROP_NUMBER = 4; + static const int PROP_TARGET_BINDING = 5; + static const int PROP_RENDER_TARGET = 6; + static const int PROP_SHADER_PASS = 7; + static const int PROP_REMOVABLE_STRING = 8; + static const int PROP_LAYER = 9; + static const int PROP_CUSTOM = 10; + static const int PROP_STRING = 11; + static const int PROP_COLOR = 12; + static const int PROP_COMBO = 13; + static const int PROP_BOOL = 14; + static const int PROP_SOUND = 15; + static const int PROP_BEZIER_RGBA_CURVE = 16; + static const int PROP_BEZIER_CURVE = 17; + static const int PROP_MATERIAL = 18; + static const int PROP_MATERIAL_PREVIEW = 19; + static const int PROP_TEXTURE = 20; + static const int PROP_SCENE_SPRITE = 21; + static const int PROP_SCENE_ENTITY_INSTANCE = 22; }; class Vector3Prop : public PropProp { @@ -774,19 +799,26 @@ class MaterialPropSheet : public PropSheet { class EntityPropSheet : public PropSheet { public: - EntityPropSheet(); - void handleEvent(Event *event); + EntityPropSheet(Plugin* plugin); + void Update(); void refreshProps(); + void reloadSheetFromEntry(ObjectEntry *sheetEntry); void applyPropActionData(PolycodeEditorPropActionData *data); void setEntity(Entity *entity); + void handleEvent(Event *event); + + //void refreshProps(ObjectEntry *propsEntry); - ButtonProp *addButtonProp; + //ButtonProp *addButtonProp; Entity *entity; + String plugin; + int lastNumProps; int removeIndex; + }; class SceneLabelSheet : public PropSheet { @@ -936,37 +968,7 @@ class LinkedMaterialsSheet : public PropSheet { class CustomSheet : public PropSheet { public: - CustomSheet(ObjectEntry *sheetEntry); - ~CustomSheet(); - - void handleEvent(Event *event); - void reloadSheetFromFile(ObjectEntry *sheetEntry); - void refreshProps(ObjectEntry *propsEntry); - void Update(); - - static const int PROP_VECTOR3 = 0; - static const int PROP_VECTOR2 = 1; - static const int PROP_SLIDER = 2; - static const int PROP_BUTTON = 3; - static const int PROP_NUMBER = 4; - static const int PROP_TARGET_BINDING = 5; - static const int PROP_RENDER_TARGET = 6; - static const int PROP_SHADER_PASS = 7; - static const int PROP_REMOVABLE_STRING = 8; - static const int PROP_LAYER = 9; - static const int PROP_CUSTOM = 10; - static const int PROP_STRING = 11; - static const int PROP_COLOR = 12; - static const int PROP_COMBO = 13; - static const int PROP_BOOL = 14; - static const int PROP_SOUND = 15; - static const int PROP_BEZIER_RGBA_CURVE = 16; - static const int PROP_BEZIER_CURVE = 17; - static const int PROP_MATERIAL = 18; - static const int PROP_TEXTURE = 19; - static const int PROP_SCENE_SPRITE = 20; - static const int PROP_SCENE_ENTITY_INSTANCE = 21; - + //private: // std::vector props; }; diff --git a/IDE/Contents/Source/EntityEditorPropertyView.cpp b/IDE/Contents/Source/EntityEditorPropertyView.cpp index 817ac2170..1da065281 100644 --- a/IDE/Contents/Source/EntityEditorPropertyView.cpp +++ b/IDE/Contents/Source/EntityEditorPropertyView.cpp @@ -86,11 +86,14 @@ EntityEditorPropertyView::EntityEditorPropertyView() : UIElement() { entitySheet = new EntitySheet(); entityProps->addPropSheet(entitySheet); entitySheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE); - - propSheet = new EntityPropSheet(); - entityProps->addPropSheet(propSheet); - propSheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE); - + + std::vector plugins = Services()->getResourceManager()->getGlobalPool()->getResources(Resource::RESOURCE_PLUGIN); + for (int p = 0; p < plugins.size(); p++) { + EntityPropSheet *propSheet = new EntityPropSheet(dynamic_cast(plugins[p])); + entityProps->addPropSheet(propSheet); + propSheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE); + propSheets.push_back(propSheet); + } } void EntityEditorPropertyView::setEntityInstance(SceneEntityInstance *instance) { @@ -182,7 +185,9 @@ void EntityEditorPropertyView::setEntity(Entity *entity) { particleSheet->setParticleEmitter(emitter); entitySheet->setEntity(entity); - propSheet->setEntity(entity); + for (int p = 0; p < propSheets.size(); p++) { + propSheets[p]->setEntity(entity); + } transformSheet->setEntity(entity); Resize(getWidth(), getHeight()); diff --git a/IDE/Contents/Source/PolycodeEntityEditor.cpp b/IDE/Contents/Source/PolycodeEntityEditor.cpp index eef0b0b1e..76a980c49 100644 --- a/IDE/Contents/Source/PolycodeEntityEditor.cpp +++ b/IDE/Contents/Source/PolycodeEntityEditor.cpp @@ -2139,6 +2139,13 @@ void PolycodeEntityEditor::saveEntityToObjectEntry(Entity *entity, ObjectEntry * } entry->addChild("tags", tagString); + if (entity->requiredPlugins.size() > 0) { + ObjectEntry *reqPluginsEntry = entry->addChild("requiredPlugins"); + for (int p = 0; p < entity->requiredPlugins.size(); p++) { + ObjectEntry* requiredPlugin = reqPluginsEntry->addChild("requiredPlugin"); + requiredPlugin->addChild("name", entity->requiredPlugins[p]->getResourceName()); + } + } if(entity->entityProps.size() > 0) { ObjectEntry *props = entry->addChild("props"); @@ -2502,7 +2509,7 @@ void PolycodeEntityEditor::saveFile() { ObjectEntry *children = saveObject.root.addChild("root"); saveEntityToObjectEntry(mainView->getObjectRoot(), children); - + saveObject.saveToXML(filePath); setHasChanges(false); } @@ -2517,19 +2524,13 @@ void PolycodeEntityEditor::savePropsToEntry(ObjectEntry *entry, std::vectoraddChild("prop"); prop->addChild("name", props[i]->name); - //prop->addChild("value", entity->entityProps[i].propValue); + prop->addChild("type", props[i]->type); switch (props[i]->type) { case Prop::PROP_STRING: prop->addChild("value", props[i]->stringVal); break; case Prop::PROP_ARRAY: - ObjectEntry *childrenProps; - for (int a = 0; a < props[i]->arrayVal.size(); a++) { - ObjectEntry* childProp; - savePropsToEntry(childProp, props[i]->arrayVal); - childrenProps->addChild(childProp); - } - prop->addChild(childrenProps); + savePropsToEntry(prop, props[i]->arrayVal); break; case Prop::PROP_BOOL: prop->addChild("value", props[i]->boolVal); @@ -2544,6 +2545,5 @@ void PolycodeEntityEditor::savePropsToEntry(ObjectEntry *entry, std::vectoraddChild("value", props[i]->stringVal); break; } - prop->addChild("type", props[i]->type); } -} \ No newline at end of file +} diff --git a/IDE/Contents/Source/PolycodeIDEApp.cpp b/IDE/Contents/Source/PolycodeIDEApp.cpp index c2e6b9404..dbb74f4bf 100644 --- a/IDE/Contents/Source/PolycodeIDEApp.cpp +++ b/IDE/Contents/Source/PolycodeIDEApp.cpp @@ -72,7 +72,7 @@ PolycodeIDEApp::PolycodeIDEApp(PolycodeView *view) : EventDispatcher() { CoreServices::getInstance()->getResourceManager()->addArchive("Physics3D.pak"); CoreServices::getInstance()->getResourceManager()->addArchive("UI.pak"); - CoreServices::getInstance()->getResourceManager()->addDirResource("Materials"); + CoreServices::getInstance()->getResourceManager()->addDirResource("Materials"); CoreServices::getInstance()->getFontManager()->registerFont("section", "Fonts/RobotoCondensed-Bold.ttf"); diff --git a/IDE/Contents/Source/PolycodeMaterialEditor.cpp b/IDE/Contents/Source/PolycodeMaterialEditor.cpp index 107a9c96b..ff1dbbcba 100644 --- a/IDE/Contents/Source/PolycodeMaterialEditor.cpp +++ b/IDE/Contents/Source/PolycodeMaterialEditor.cpp @@ -826,7 +826,7 @@ void MaterialPreviewBox::handleEvent(Event *event) { } } -MaterialPreviewProp::MaterialPreviewProp() : PropProp("", "") { +MaterialPreviewProp::MaterialPreviewProp() : PropProp("", PropProp::PROP_MATERIAL_PREVIEW) { previewBox = new MaterialPreviewBox(); propContents->addChild(previewBox); setHeight(300); diff --git a/IDE/Contents/Source/PolycodeProps.cpp b/IDE/Contents/Source/PolycodeProps.cpp index 29bc1baaa..6849887dc 100644 --- a/IDE/Contents/Source/PolycodeProps.cpp +++ b/IDE/Contents/Source/PolycodeProps.cpp @@ -333,7 +333,11 @@ void PropProp::setPropName(String newName) { label->setText(newName); } -PropProp::PropProp(String caption, String type) : UIElement() { +String PropProp::getPropName() { + return label->getText(); +} + +PropProp::PropProp(String caption, int type) : UIElement() { suppressChangeEvent = false; propType = type; @@ -353,7 +357,7 @@ PropProp::~PropProp() { } -ButtonProp::ButtonProp(const String &caption) : PropProp("", "ButtonProp") { +ButtonProp::ButtonProp(const String &caption) : PropProp("", PropProp::PROP_BUTTON) { button = new UIButton(caption, 100); addChild(button); setHeight(25); @@ -372,7 +376,7 @@ void ButtonProp::setPropWidth(Number width) { } -Vector3Prop::Vector3Prop(String caption) : PropProp(caption, "Vector3") { +Vector3Prop::Vector3Prop(String caption) : PropProp(caption, PropProp::PROP_VECTOR3) { xInput = NULL; yInput = NULL; @@ -463,7 +467,7 @@ Vector3Prop::~Vector3Prop() { } -Vector2Prop::Vector2Prop(String caption) : PropProp(caption, "Vector2") { +Vector2Prop::Vector2Prop(String caption) : PropProp(caption, PropProp::PROP_VECTOR2) { labelX = new UILabel("X:", 11); labelX->color.a = 1.0; @@ -545,7 +549,7 @@ Vector2Prop::~Vector2Prop() { } -RemovableStringProp::RemovableStringProp(const String &caption) : PropProp("", "RemovableStringProp") { +RemovableStringProp::RemovableStringProp(const String &caption) : PropProp("", PropProp::PROP_REMOVABLE_STRING){ label = new UILabel(caption, 12); addChild(label); @@ -573,7 +577,7 @@ void RemovableStringProp::handleEvent(Event *event) { } } -LayerProp::LayerProp(SceneEntityInstance *instance, SceneEntityInstanceLayer *layer) : PropProp("", "Layer") { +LayerProp::LayerProp(SceneEntityInstance *instance, SceneEntityInstanceLayer *layer) : PropProp("", PropProp::PROP_LAYER) { layerID = 0; bgRect = new UIRect(1.0, 1.0); @@ -697,7 +701,7 @@ void LayerProp::setPropWidth(Number width) { removeLayerButton->setPosition(width-PROP_PADDING-propContents->getPosition().x-20, 5.0); } -CustomProp::CustomProp(String key, String value) : PropProp("", "Custom") { +CustomProp::CustomProp(String key, String value) : PropProp("", PropProp::PROP_CUSTOM) { keyEntry = new UITextInput(false, 120, 12); keyEntry->setText(key); keyEntry->addEventListener(this, UIEvent::CHANGE_EVENT); @@ -758,7 +762,7 @@ String CustomProp::getKey() { } -StringProp::StringProp(String caption) : PropProp(caption, "String") { +StringProp::StringProp(String caption) : PropProp(caption, PropProp::PROP_STRING) { stringEntry = new UITextInput(false, 150, 12); stringEntry->addEventListener(this, UIEvent::CHANGE_EVENT); @@ -807,7 +811,7 @@ StringProp::~StringProp() { } -SliderProp::SliderProp(String caption, Number min, Number max) : PropProp(caption, "Slider") { +SliderProp::SliderProp(String caption, Number min, Number max) : PropProp(caption, PropProp::PROP_SLIDER) { slider = new UIHSlider(min, max, 100); slider->addEventListener(this, UIEvent::CHANGE_EVENT); @@ -866,7 +870,7 @@ SliderProp::~SliderProp() { } -NumberProp::NumberProp(String caption) : PropProp(caption, "Number") { +NumberProp::NumberProp(String caption) : PropProp(caption, PropProp::PROP_NUMBER) { numberEntry = new UITextInput(false, 50, 20); numberEntry->addEventListener(this, UIEvent::CHANGE_EVENT); @@ -918,7 +922,7 @@ NumberProp::~NumberProp() { } -ColorProp::ColorProp(String caption) : PropProp(caption, "Color") { +ColorProp::ColorProp(String caption) : PropProp(caption, PropProp::PROP_COLOR) { colorEntry = new UIColorBox(globalColorPicker, Color(), 45, 25); colorEntry->addEventListener(this, UIEvent::CHANGE_EVENT); @@ -965,7 +969,7 @@ ColorProp::~ColorProp() { } -ComboProp::ComboProp(String caption) : PropProp(caption, "Combo") { +ComboProp::ComboProp(String caption) : PropProp(caption, PropProp::PROP_COMBO) { comboEntry = new UIComboBox(globalMenu, 150); comboEntry->addEventListener(this, UIEvent::CHANGE_EVENT); propContents->addChild(comboEntry); @@ -1010,7 +1014,7 @@ ComboProp::~ComboProp() { } -BoolProp::BoolProp(String caption) : PropProp(caption, "Bool") { +BoolProp::BoolProp(String caption) : PropProp(caption, PropProp::PROP_BOOL) { checkEntry = new UICheckBox("", false); checkEntry->addEventListener(this, UIEvent::CHANGE_EVENT); @@ -1052,7 +1056,7 @@ BoolProp::~BoolProp() { } -SoundProp::SoundProp(String caption) : PropProp(caption, "Sound"){ +SoundProp::SoundProp(String caption) : PropProp(caption, PropProp::PROP_SOUND) { soundFile = new UILabel("", 11); soundFile->setPosition(0, 5); @@ -1135,7 +1139,7 @@ String SoundProp::get() { return ""; } -BezierRGBACurveProp::BezierRGBACurveProp(String caption) : PropProp(caption, "BezierRGBA") { +BezierRGBACurveProp::BezierRGBACurveProp(String caption) : PropProp(caption, PropProp::PROP_BEZIER_RGBA_CURVE) { changeButton = new UIButton("Edit", 120); @@ -1162,13 +1166,13 @@ void BezierRGBACurveProp::handleEvent(Event *event) { globalFrame->curveEditor->addCurve("Red", curveR, Color(1.0, 0.0, 0.0, 1.0)); globalFrame->curveEditor->addCurve("Green", curveG, Color(0.0, 1.0, 0.0, 1.0)); globalFrame->curveEditor->addCurve("Blue", curveB, Color(0.0, 0.0, 1.0, 1.0)); - globalFrame->curveEditor->addCurve("Alpha", curveA, Color(1.0, 1.0, 1.0, 1.0)); + globalFrame->curveEditor->addCurve("Alpha", curveA, Color(1.0, 1.0, 1.0, 1.0)); globalFrame->showCurveEditor(); } } } -BezierCurveProp::BezierCurveProp(String caption, String curveName) : PropProp(caption, "BezierCurve") { +BezierCurveProp::BezierCurveProp(String caption, String curveName) : PropProp(caption, PropProp::PROP_BEZIER_CURVE) { this->curveName = curveName; @@ -1196,7 +1200,7 @@ void BezierCurveProp::handleEvent(Event *event) { } } -MaterialProp::MaterialProp(const String &caption) : PropProp(caption, "Material"){ +MaterialProp::MaterialProp(const String &caption) : PropProp(caption, PropProp::PROP_MATERIAL) { currentMaterial = NULL; previewShape = new UIRect(48, 48); @@ -1314,7 +1318,7 @@ void MaterialProp::setPropWidth(Number width) { } -TextureProp::TextureProp(String caption) : PropProp(caption, "Texture"){ +TextureProp::TextureProp(String caption) : PropProp(caption, PropProp::PROP_TEXTURE) { previewShape = new UIRect(48, 48); previewShape->setAnchorPoint(-1.0, -1.0, 0.0); previewShape->setPosition(2, 1); @@ -1389,7 +1393,7 @@ Texture* TextureProp::get() { return previewShape->getTexture(); } -SceneSpriteProp::SceneSpriteProp(String caption) : PropProp(caption, "SceneSprite"){ +SceneSpriteProp::SceneSpriteProp(String caption) : PropProp(caption, PropProp::PROP_SCENE_SPRITE) { previewSprite = NULL; @@ -1500,7 +1504,7 @@ Sprite *SceneSpriteProp::get() { return sprite; } -SceneEntityInstanceProp::SceneEntityInstanceProp(String caption) : PropProp(caption, "SceneEntityInstance"){ +SceneEntityInstanceProp::SceneEntityInstanceProp(String caption) : PropProp(caption, PropProp::PROP_SCENE_ENTITY_INSTANCE){ // previewInstance = new SceneEntityInstance("default/default.entity"); previewInstance->setAnchorPoint(-1.0, -1.0, 0.0); previewInstance->setPosition(2, 1); @@ -1565,7 +1569,7 @@ String SceneEntityInstanceProp::get() { return previewInstance->getFileName(); } -ShaderPassProp::ShaderPassProp(Material *material, int shaderIndex) : PropProp("", "ShaderPassProp") { +ShaderPassProp::ShaderPassProp(Material *material, int shaderIndex) : PropProp("", PropProp::PROP_SHADER_PASS) { this->material = material; this->shader = material->getShader(shaderIndex); this->shaderIndex = shaderIndex; @@ -1629,7 +1633,7 @@ void ShaderPassProp::setPropWidth(Number width) { editButton->Resize(floor(adjustedWidth * 0.25), editButton->getHeight()); } -TargetBindingProp::TargetBindingProp(Shader *shader, Material *material, ShaderBinding *binding, RenderTargetBinding *targetBinding) : PropProp("", "TargetBindingProp") { +TargetBindingProp::TargetBindingProp(Shader *shader, Material *material, ShaderBinding *binding, RenderTargetBinding *targetBinding) : PropProp("", PropProp::PROP_TARGET_BINDING) { this->targetBinding = targetBinding; this->material = material; this->shader = shader; @@ -1763,7 +1767,7 @@ void TargetBindingProp::setPropWidth(Number width) { } -RenderTargetProp::RenderTargetProp(ShaderRenderTarget *renderTarget, Material *material) : PropProp("", "RenderTargetProp") { +RenderTargetProp::RenderTargetProp(ShaderRenderTarget *renderTarget, Material *material) : PropProp("", PropProp::PROP_RENDER_TARGET) { this->material = material; this->renderTarget = renderTarget; @@ -2129,20 +2133,19 @@ void RenderTargetsSheet::handleEvent(Event *event) { PropSheet::handleEvent(event); } - -EntityPropSheet::EntityPropSheet() : PropSheet("CUSTOM PROPERTIES", "entityProps"){ - - addButtonProp = new ButtonProp("Add Property"); - addProp(addButtonProp); - addButtonProp->getButton()->addEventListener(this, UIEvent::CLICK_EVENT); +EntityPropSheet::EntityPropSheet(Plugin* plugin) : PropSheet(plugin->getResourceName().toUpperCase(), plugin->ext){ + this->plugin = plugin->getResourceName(); customUndoHandler = true; - + entity = NULL; - + lastNumProps = 0; removeIndex = -1; - enabled = false; + enabled = false; + + if (plugin->sheetEntry) + refreshProps(); } void EntityPropSheet::applyPropActionData(PolycodeEditorPropActionData *data) { @@ -2161,16 +2164,6 @@ void EntityPropSheet::applyPropActionData(PolycodeEditorPropActionData *data) { void EntityPropSheet::handleEvent(Event *event) { if(!entity) return; - - if(event->getDispatcher() == addButtonProp->getButton() && event->getEventType() == "UIEvent") { - PolycodeEditorPropActionData *beforeData = PropDataEntity(entity); - entity->entityProps.push_back(new EntityProp("")); - refreshProps(); - PolycodeEditorPropActionData *afterData = PropDataEntity(entity); - PropEvent *propEvent = new PropEvent(NULL, this, beforeData, afterData); - dispatchEvent(propEvent, PropEvent::EVENT_PROP_CHANGE); - - } for(int i=0; i < props.size(); i++) { if(event->getDispatcher() == props[i] && event->getEventType() == "") { @@ -2180,9 +2173,103 @@ void EntityPropSheet::handleEvent(Event *event) { break; case Event::CHANGE_EVENT: PolycodeEditorPropActionData *beforeData = PropDataEntity(entity); - if(i-1 < entity->entityProps.size()) { - entity->entityProps[i-1]->name = ((CustomProp*)props[i])->getKey(); - entity->entityProps[i-1]->stringVal= ((CustomProp*)props[i])->getValue(); + if(i < entity->entityProps.size()) { + + std::vector propsVector; + EntityProp* prop; + + switch (props[i]->propType) { + case PropProp::PROP_VECTOR3: + prop = new EntityProp(props[i]->getPropName() + "x", Prop::PROP_NUMBER); + prop->numberVal = ((Vector3Prop*)props[i])->get().x; + propsVector.push_back(prop); + prop = new EntityProp(props[i]->getPropName() + "y", Prop::PROP_NUMBER); + prop->numberVal = ((Vector3Prop*)props[i])->get().y; + propsVector.push_back(prop); + prop = new EntityProp(props[i]->getPropName() + "z", Prop::PROP_NUMBER); + prop->numberVal = ((Vector3Prop*)props[i])->get().z; + propsVector.push_back(prop); + entity->setEntityProp(props[i]->getPropName(), propsVector); + break; + case PropProp::PROP_VECTOR2: + prop = new EntityProp(props[i]->getPropName() + "x", Prop::PROP_NUMBER); + propsVector.push_back(prop); + prop = new EntityProp(props[i]->getPropName() + "y", Prop::PROP_NUMBER); + propsVector.push_back(prop); + entity->setEntityProp(props[i]->getPropName(), propsVector); + break; + case PropProp::PROP_SLIDER: + entity->setEntityProp(props[i]->getPropName(), ((SliderProp*)props[i])->get()); + break; + //case PropProp::PROP_BUTTON: + // prop = new ButtonProp(caption); + // break; + case PropProp::PROP_NUMBER: + entity->setEntityProp(props[i]->getPropName(), ((NumberProp*)props[i])->get()); + break; + //case PropProp::PROP_TARGET_BINDING: + // + // break; + //case PropProp::PROP_RENDER_TARGET: + // break; + //case PropProp::PROP_SHADER_PASS: + // break; + case PropProp::PROP_REMOVABLE_STRING: + entity->setEntityProp(props[i]->getPropName(), ((RemovableStringProp*)props[i])->getCaption()); + break; + //case PropProp::PROP_LAYER: + // break; + case PropProp::PROP_STRING: + entity->setEntityProp(((StringProp*)props[i])->getPropName(), ((StringProp*)props[i])->get()); + break; + case PropProp::PROP_COLOR: + entity->setEntityProp(props[i]->getPropName() + "R", ((ColorProp*)props[i])->get().r); + entity->setEntityProp(props[i]->getPropName() + "G", ((ColorProp*)props[i])->get().g); + entity->setEntityProp(props[i]->getPropName() + "B", ((ColorProp*)props[i])->get().b); + entity->setEntityProp(props[i]->getPropName() + "A", ((ColorProp*)props[i])->get().a); + break; + //case PropProp::PROP_COMBO: + // //entity->setEntityProp(props[i]->getPropName() + String::NumberToString(c, 0), ((ComboProp*)props[i])->comboEntry->getItemAtIndex(c)->label); + // switch (((ComboProp*)props[i])->comboEntry->getSelectedItem()->data[0]) { + // case Prop::PROP_ARRAY: + // entity->setEntityProp(caption, entity->getEntityPropArrayByName(((ComboProp*)props[i])->comboEntry->getSelectedItem()->label)); + // case Prop::PROP_BOOL: + // entity->setEntityProp(caption, entity->getEntityPropBoolByName(((ComboProp*)props[i])->comboEntry->getSelectedItem()->label)); + // case Prop::PROP_INT: + // entity->setEntityProp(caption, entity->getEntityPropIntByName(((ComboProp*)props[i])->comboEntry->getSelectedItem()->label)); + // case Prop::PROP_NUMBER: + // entity->setEntityProp(caption, entity->getEntityPropNumberByName(((ComboProp*)props[i])->comboEntry->getSelectedItem()->label)); + // case Prop::PROP_STRING: + // entity->setEntityProp(caption, entity->getEntityPropStringByName(((ComboProp*)props[i])->comboEntry->getSelectedItem()->label)); + // } + // break; + case PropProp::PROP_BOOL: + entity->setEntityProp(props[i]->getPropName(), ((BoolProp*)props[i])->get()); + break; + case PropProp::PROP_SOUND: + entity->setEntityProp(props[i]->getPropName(), ((SoundProp*)props[i])->get()); + break; + //case PropProp::PROP_BEZIER_RGBA_CURVE: + // break; + //case PropProp::PROP_BEZIER_CURVE: + // break; + case PropProp::PROP_MATERIAL: + entity->setEntityProp(props[i]->getPropName(), ((MaterialProp*)props[i])->get()->getName()); + break; + case PropProp::PROP_TEXTURE: + entity->setEntityProp(props[i]->getPropName(), ((TextureProp*)props[i])->get()->getResourceName()); + break; + case PropProp::PROP_SCENE_SPRITE: + entity->setEntityProp(props[i]->getPropName(), ((SceneSpriteProp*)props[i])->get()->getResourceName()); + break; + case PropProp::PROP_SCENE_ENTITY_INSTANCE: + entity->setEntityProp(props[i]->getPropName(), ((SceneEntityInstanceProp*)props[i])->get()); + break; + case PropProp::PROP_CUSTOM: + default: + entity->setEntityProp(((CustomProp*)props[i])->getKey(), ((CustomProp*)props[i])->getValue()); + break; + } } PolycodeEditorPropActionData *afterData = PropDataEntity(entity); PropEvent *propEvent = new PropEvent(NULL, this, beforeData, afterData); @@ -2194,28 +2281,227 @@ void EntityPropSheet::handleEvent(Event *event) { PropSheet::handleEvent(event); } -void EntityPropSheet::refreshProps() { +void EntityPropSheet::reloadSheetFromEntry(ObjectEntry *sheetEntry) { + ObjectEntry *propsEntry = (*sheetEntry)["props"]; + if (propsEntry) { + refreshProps(); + //PropProp *prop; + //if (propsEntry) { + // for (int i = 0; i < propsEntry->children.size(); i++) { + // ObjectEntry* propEntry = propsEntry->children[i]; + // String caption = (*propEntry)["name"]->stringVal; + // switch ((*propEntry)["type"]->intVal) { + // case PropProp::PROP_VECTOR3: + // prop = new Vector3Prop(caption); + // break; + // case PropProp::PROP_VECTOR2: + // prop = new Vector2Prop(caption); + // break; + // case PropProp::PROP_SLIDER: + // prop = new SliderProp(caption, (*propEntry)["min"]->NumberVal, (*propEntry)["max"]->NumberVal); + // break; + // //case PropProp::PROP_BUTTON: + // // prop = new ButtonProp(caption); + // // break; + // case PropProp::PROP_NUMBER: + // prop = new NumberProp(caption); + // break; + // //case PropProp::PROP_TARGET_BINDING: + // // Shader *shader; + // // Material *material; + // // ShaderBinding *shaderBin; + // // RenderTargetBinding *targetBin; + // // + // // prop = new TargetBindingProp(shader, material, shaderBin, targetBin); + // // + // // break; + // //case PropProp::PROP_RENDER_TARGET: + // // ShaderRenderTarget *renderTarget; + // // Material *material; + // // prop = new RenderTargetProp(renderTarget, material); + // // break; + // //case PropProp::PROP_SHADER_PASS: + // // prop = new ShaderPassProp(); + // // break; + // //case PropProp::PROP_REMOVABLE_STRING: + // // prop = new RemovableStringProp(caption); + // // break; + // //case PropProp::PROP_LAYER: + // // SceneEntityInstance *instance = new SceneEntityInstance(); + // // prop = new LayerProp(); + // // break; + // case PropProp::PROP_STRING: + // prop = new StringProp(caption); + // break; + // case PropProp::PROP_COLOR: + // prop = new ColorProp(caption); + // break; + // case PropProp::PROP_COMBO: + // prop = new ComboProp(caption); + // break; + // case PropProp::PROP_BOOL: + // prop = new BoolProp(caption); + // break; + // case PropProp::PROP_SOUND: + // prop = new SoundProp(caption); + // break; + // case PropProp::PROP_BEZIER_RGBA_CURVE: + // prop = new BezierRGBACurveProp(caption); + // break; + // case PropProp::PROP_BEZIER_CURVE: + // prop = new BezierCurveProp(caption, (*propEntry)["curveName"]->stringVal); + // break; + // case PropProp::PROP_MATERIAL: + // prop = new MaterialProp(caption); + // break; + // case PropProp::PROP_TEXTURE: + // prop = new TextureProp(caption); + // break; + // case PropProp::PROP_SCENE_SPRITE: + // prop = new SceneSpriteProp(caption); + // break; + // case PropProp::PROP_SCENE_ENTITY_INSTANCE: + // prop = new SceneEntityInstanceProp(caption); + // break; + // case PropProp::PROP_CUSTOM: + // default: + // prop = new CustomProp(caption, ""); + // break; + // } + // addProp(prop); + // } + //} + } +} +void EntityPropSheet::refreshProps() { for(int i=0; i < props.size(); i++) { - if(props[i] != addButtonProp) { - contents->removeChild(props[i]); - props[i]->removeAllHandlersForListener(this); - delete props[i]; - } + contents->removeChild(props[i]); + props[i]->removeAllHandlersForListener(this); + delete props[i]; } props.clear(); - props.push_back(addButtonProp); - - - for(int i=0; i < entity->entityProps.size(); i++) { - EntityProp* prop = entity->entityProps[i]; - CustomProp *newProp = new CustomProp(prop->name, prop->stringVal); - newProp->addEventListener(this, Event::CANCEL_EVENT); - newProp->addEventListener(this, Event::CHANGE_EVENT); - addProp(newProp); + + if (!entity) + entity = new Entity(); + + if (!entity->isRequiredPlugin(plugin)) { + this->enabled = false; + this->visible = false; + return; + } else { + this->enabled = true; + this->visible = true; } - - + + ObjectEntry* propsEntry = (*dynamic_cast(Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_PLUGIN, plugin))->sheetEntry)["props"]; + if (propsEntry) { + PropProp* prop; + for (int i = 0; i < propsEntry->children.size(); i++) { + ObjectEntry* propEntry = propsEntry->children[i]; + String caption = (*propEntry)["name"]->stringVal; + switch ((*propEntry)["type"]->intVal) { + case PropProp::PROP_VECTOR3: + prop = new Vector3Prop(caption); + dynamic_cast(prop)->set(Vector3(entity->getEntityPropNumberByName(caption + "x"), entity->getEntityPropNumberByName(caption + "y"), entity->getEntityPropNumberByName(caption + "z"))); + break; + case PropProp::PROP_VECTOR2: + prop = new Vector2Prop(caption); + dynamic_cast(prop)->set(Vector2(entity->getEntityPropNumberByName(caption + "x"), entity->getEntityPropNumberByName(caption + "y"))); + break; + case PropProp::PROP_SLIDER: + prop = new SliderProp(caption, (*propEntry)["min"]->NumberVal, (*propEntry)["max"]->NumberVal); + dynamic_cast(prop)->set(entity->getEntityPropNumberByName(caption)); + break; + //case PropProp::PROP_BUTTON: + // prop = new ButtonProp(caption); + // break; + case PropProp::PROP_NUMBER: + prop = new NumberProp(caption); + prop->setPropData(PropDataNumber(entity->getEntityPropNumberByName(caption))); + break; + //case PropProp::PROP_TARGET_BINDING: + // Shader *shader = ((Shader*)Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_SHADER, entity->getEntityPropStringByName(caption))); + // Material *material = ((Material*)Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_MATERIAL, entity->getEntityPropStringByName(caption))); + // ShaderBinding *shaderBin = new ShaderBinding(shader); + // RenderTargetBinding *targetBin = new RenderTargetBinding(); + // + // prop = new TargetBindingProp(shader, material, shaderBin, targetBin); + // + // break; + //case PropProp::PROP_RENDER_TARGET: + // ShaderRenderTarget *renderTarget; + // Material *material; + // prop = new RenderTargetProp(renderTarget, material); + // break; + //case PropProp::PROP_SHADER_PASS: + // prop = new ShaderPassProp(); + // break; + case PropProp::PROP_REMOVABLE_STRING: + prop = new RemovableStringProp(caption); + prop->setPropData(PropDataString(entity->getEntityPropStringByName(caption))); + break; + //case PropProp::PROP_LAYER: + // SceneEntityInstance *instance = new SceneEntityInstance(); + // prop = new LayerProp(); + // break; + case PropProp::PROP_STRING: + prop = new StringProp(caption); + ((StringProp*)prop)->set(entity->getEntityPropStringByName(caption)); + break; + case PropProp::PROP_COLOR: + prop = new ColorProp(caption); + ((ColorProp*)prop)->set(new Color(entity->getEntityPropNumberByName(caption + "r"), entity->getEntityPropNumberByName(caption + "g"), entity->getEntityPropNumberByName(caption + "b"), entity->getEntityPropNumberByName(caption + "a"))); + break; + case PropProp::PROP_COMBO: + prop = new ComboProp(caption); + for (int c = 0; c < (*propsEntry)[caption]->children.size(); c++) { + ((ComboProp*)prop)->comboEntry->addComboItem(caption + String::NumberToString(c, 0), &(*propsEntry)[caption][c]["type"]->intVal); + } + break; + case PropProp::PROP_BOOL: + prop = new BoolProp(caption); + ((BoolProp*)prop)->set(entity->getEntityPropBoolByName(caption)); + break; + case PropProp::PROP_SOUND: + prop = new SoundProp(caption); + ((SoundProp*)prop)->set(entity->getEntityPropStringByName(caption)); + break; + //case PropProp::PROP_BEZIER_RGBA_CURVE: + // prop = new BezierRGBACurveProp(caption); + // for (int c = 0; c < entity->getEntityPropArrayByName(caption + "r").size(); c++) { + // ((BezierRGBACurveProp*)prop)->curveR->addControlPoint2d(entity->getEntityPropArrayByName(caption + "r")[c]); + // } + // break; + //case PropProp::PROP_BEZIER_CURVE: + //prop = new BezierCurveProp(caption, (*propEntry)["curveName"]->stringVal); + //break; + case PropProp::PROP_MATERIAL: + prop = new MaterialProp(caption); + ((MaterialProp*)prop)->set(new Material(entity->getEntityPropStringByName(caption))); + break; + case PropProp::PROP_TEXTURE: + prop = new TextureProp(caption); + ((TextureProp*)prop)->set(((Texture*)Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_TEXTURE, entity->getEntityPropStringByName(caption)))); + break; + case PropProp::PROP_SCENE_SPRITE: + prop = new SceneSpriteProp(caption); + ((SceneSpriteProp*)prop)->set(((Sprite*)Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_SPRITE, entity->getEntityPropStringByName(caption)))); + break; + case PropProp::PROP_SCENE_ENTITY_INSTANCE: + prop = new SceneEntityInstanceProp(caption); + ((SceneEntityInstanceProp*)prop)->set(entity->getEntityPropStringByName(caption)); + break; + case PropProp::PROP_CUSTOM: + default: + prop = new CustomProp(caption, ""); + break; + } + prop->addEventListener(this, Event::CHANGE_EVENT); + addProp(prop); + } + } + if(lastNumProps != entity->entityProps.size()) { dispatchEvent(new Event(), Event::COMPLETE_EVENT); } @@ -2271,12 +2557,12 @@ void ShaderOptionsSheet::handleEvent(Event *event) { LocalShaderParam *param = binding->getLocalParamByName(props[i]->label->getText()); - if(props[i]->propType == "Number") { + if(props[i]->propType == PropProp::PROP_NUMBER) { if(!param){ param = binding->addParam(ProgramParam::PARAM_NUMBER, props[i]->label->getText()); } (*(Number*)param->data) = ((NumberProp*)props[i])->get(); - } else if(props[i]->propType == "Color") { + } else if(props[i]->propType == PropProp::PROP_COLOR) { if(!param){ param = binding->addParam(ProgramParam::PARAM_COLOR, props[i]->label->getText()); @@ -4012,120 +4298,7 @@ void SoundSheet::setSound(SceneSound *sound) { } } -CustomSheet::CustomSheet(ObjectEntry *sheetEntry) : PropSheet((*sheetEntry)["name"]->stringVal.toUpperCase(), (*sheetEntry)["fileext"]->stringVal) { - //ObjectEntry *propsEntry = (*sheetEntry)["props"]; - reloadSheetFromFile(sheetEntry); -} - -CustomSheet::~CustomSheet(){} +//CustomSheet::CustomSheet(ObjectEntry *sheetEntry) : PropSheet((*sheetEntry)["name"]->stringVal.toUpperCase(), (*sheetEntry)["fileext"]->stringVal) { +// reloadSheetFromFile(sheetEntry); +//} -void CustomSheet::reloadSheetFromFile(ObjectEntry *sheetEntry){ - if (!(*sheetEntry)["props"]) - return; - - ObjectEntry *propsEntry = (*sheetEntry)["props"]; - refreshProps(propsEntry); - PropProp *prop; - if (propsEntry->children.size() == 0) - return; - - for (int i = 0; i < propsEntry->children.size(); i++) { - String caption = (*propsEntry->children[i])["name"]->stringVal; - switch ((*propsEntry->children[i])["type"]->intVal){ - case PROP_VECTOR3: - prop = new Vector3Prop(caption); - prop->setPropData(PropDataVector3(Vector3((*propsEntry->children[i])["v1"]->NumberVal, (*propsEntry->children[i])["v2"]->NumberVal, (*propsEntry->children[i])["v3"]->NumberVal))); - break; - case PROP_VECTOR2: - prop = new Vector2Prop(caption); - prop->setPropData(PropDataVector2(Vector2((*propsEntry->children[i])["v1"]->NumberVal, (*propsEntry->children[i])["v2"]->NumberVal))); - break; - case PROP_SLIDER: - prop = new SliderProp(caption, (*propsEntry->children[i])["min"]->NumberVal, (*propsEntry->children[i])["max"]->NumberVal); - dynamic_cast(prop)->set((*propsEntry->children[i])["current"]->NumberVal); - break; - case PROP_BUTTON: - prop = new ButtonProp(caption); - break; - case PROP_NUMBER: - prop = new NumberProp(caption); - break; - //case PROP_TARGET_BINDING: - // Shader *shader; - // Material *material; - // ShaderBinding *shaderBin; - // RenderTargetBinding *targetBin; - - // prop = new TargetBindingProp(shader, material, shaderBin, targetBin); - - // break; - //case PROP_RENDER_TARGET: - // ShaderRenderTarget *renderTarget; - // Material *material; - // prop = new RenderTargetProp(renderTarget, material); - // break; - //case PROP_SHADER_PASS: - // prop = new ShaderPassProp(); - // break; - //case PROP_REMOVABLE_STRING: - // prop = new RemovableStringProp(caption); - // break; - //case PROP_LAYER: - // SceneEntityInstance *instance = new SceneEntityInstance(); - // prop = new LayerProp(); - // break; - case PROP_STRING: - prop = new StringProp(caption); - dynamic_cast(prop)->set((*propsEntry->children[i])["current"]->stringVal); - break; - case PROP_COLOR: - prop = new ColorProp(caption); - break; - case PROP_COMBO: - prop = new ComboProp(caption); - break; - case PROP_BOOL: - prop = new BoolProp(caption); - break; - case PROP_SOUND: - prop = new SoundProp(caption); - break; - case PROP_BEZIER_RGBA_CURVE: - prop = new BezierRGBACurveProp(caption); - break; - case PROP_BEZIER_CURVE: - prop = new BezierCurveProp(caption, (*propsEntry->children[i])["curvename"]->stringVal); - break; - case PROP_MATERIAL: - prop = new MaterialProp(caption); - break; - case PROP_TEXTURE: - prop = new TextureProp(caption); - break; - case PROP_SCENE_SPRITE: - prop = new SceneSpriteProp(caption); - break; - case PROP_SCENE_ENTITY_INSTANCE: - prop = new SceneEntityInstanceProp(caption); - break; - case PROP_CUSTOM: - default: - prop = new CustomProp(caption, caption); - break; - } - addProp(prop); - props[i] = prop; - } -} - -void CustomSheet::refreshProps(ObjectEntry *propsEntry){ - -} - -void CustomSheet::Update(){ - -} - -void CustomSheet::handleEvent(Event *e){ - -} From e840e758dce9afab11c052abc49b87e369d3e2bf Mon Sep 17 00:00:00 2001 From: Joachim Meyer Date: Mon, 1 Sep 2014 15:16:57 +0200 Subject: [PATCH 05/19] Final changes for Sheets, added a Editor to create plugins (for now Plugin files have to be added to a project and after creating, added to a dir added to ResourceManager, requires restart..) Conflicts: IDE/Build/Windows2013/Polycode.sln Conflicts: IDE/Contents/Source/PolycodeProps.cpp --- Core/Contents/Include/PolyEntity.h | 68 +++- Core/Contents/Include/PolyPlugin.h | 1 + Core/Contents/Include/PolyPluginManager.h | 6 +- Core/Contents/Source/PolyEntity.cpp | 92 ++--- Core/Contents/Source/PolyPlugin.cpp | 20 +- Core/Contents/Source/PolyPluginManager.cpp | 28 +- Core/Contents/Source/PolyResourceManager.cpp | 6 +- IDE/Build/Windows2013/Polycode.sln | 3 +- IDE/Build/Windows2013/Polycode.vcxproj | 2 + .../Windows2013/Polycode.vcxproj.filters | 6 + .../Include/EntityEditorPropertyView.h | 1 + IDE/Contents/Include/PolycodeIDEApp.h | 1 + IDE/Contents/Include/PolycodePluginEditor.h | 144 +++++++ IDE/Contents/Include/PolycodeProps.h | 43 +++ .../FileTemplates/General/Plugin.plugin | 4 + .../Images/materialEditor/new_plugin.png | Bin 0 -> 469 bytes .../Images/materialEditor/plugin_icon.png | Bin 0 -> 474 bytes .../Source/EntityEditorPropertyView.cpp | 14 + IDE/Contents/Source/PolycodeIDEApp.cpp | 3 +- IDE/Contents/Source/PolycodePluginEditor.cpp | 353 ++++++++++++++++++ IDE/Contents/Source/PolycodeProps.cpp | 241 +++++++----- Modules/Contents/UI/Include/PolyUIComboBox.h | 2 +- 22 files changed, 846 insertions(+), 192 deletions(-) create mode 100644 IDE/Contents/Include/PolycodePluginEditor.h create mode 100644 IDE/Contents/Resources/FileTemplates/General/Plugin.plugin create mode 100644 IDE/Contents/Resources/Images/materialEditor/new_plugin.png create mode 100644 IDE/Contents/Resources/Images/materialEditor/plugin_icon.png create mode 100644 IDE/Contents/Source/PolycodePluginEditor.cpp diff --git a/Core/Contents/Include/PolyEntity.h b/Core/Contents/Include/PolyEntity.h index b6763a35c..7124e8bff 100755 --- a/Core/Contents/Include/PolyEntity.h +++ b/Core/Contents/Include/PolyEntity.h @@ -725,34 +725,80 @@ namespace Polycode { std::vector getEntitiesByLayerID(unsigned char layerID, bool recursive) const; /** - * Returns custom string dictionary property of the entity based on the property name. + * Returns int property of the entity based on the property name. * @param Property name to look up. - * @return String property for specified property name or "null" if this property doesn't exist. + * @return int property for specified property name or false if this property doesn't exist. */ - //bool readEntityProp(const String& propName, String& propVal); - //bool readEntityProp(const String& propName, int& propVal); - //bool readEntityProp(const String& propName, Number& propVal); - //bool readEntityProp(const String& propName, bool& propVal); - //bool readEntityProp(const String& propName, std::vector& propVal); - int getEntityPropIntByName (const String& propName) const; + + /** + * Returns Number property of the entity based on the property name. + * @param Property name to look up. + * @return Number property for specified property name or 0 if this property doesn't exist. + */ Number getEntityPropNumberByName (const String& propName) const; + + /** + * Returns Bool property of the entity based on the property name. + * @param Property name to look up. + * @return Bool property for specified property name or -1 if this property doesn't exist. + */ bool getEntityPropBoolByName (const String& propName) const; + + /** + * Returns String property of the entity based on the property name. + * @param Property name to look up. + * @return String property for specified property name or "null" if this property doesn't exist. + */ String getEntityPropStringByName (const String& propName) const; + + /** + * Returns vector of EntityProp property of the entity based on the property name. + * @param Property name to look up. + * @return vector of EntityProp property for specified property name - is empty if this property doesn't exist. + */ std::vector getEntityPropArrayByName(const String& propName) const; - /** - * Sets the entity property for a specified property name in the entity's custom property dictionary. + + /** + * Sets the entity property for a specified property name. * @param propName Property name to set. - * @param propValue Value to set for the specified property name. + * @param propVal String to set for the specified property name. */ void setEntityProp(const String& propName, const String& propVal); + + /** + * Sets the entity property for a specified property name. + * @param propName Property name to set. + * @param propVal int to set for the specified property name. + */ void setEntityProp(const String& propName, const int& propVal); + + /** + * Sets the entity property for a specified property name. + * @param propName Property name to set. + * @param propVal Number to set for the specified property name. + */ void setEntityProp(const String& propName, const Number& propVal); + + /** + * Sets the entity property for a specified property name. + * @param propName Property name to set. + * @param propVal bool to set for the specified property name. + */ void setEntityProp(const String& propName, const bool& propVal); + + /** + * Sets the entity property for a specified property name. + * @param propName Property name to set. + * @param propVal vector of EntityProp* to set for the specified property name. + */ void setEntityProp(const String& propName, std::vector propVal); + void setEntityProp(EntityProp* prop); + bool isRequiredPlugin(const String& pluginName) const; void addPluginByName(const String& name, ResourcePool *resourcePool = NULL); + void removePluginByName(const String& name); /** * If set to true, the y position of the entity matrix will be multiplied by -1.0, inverting its Y-axis coordinate system. diff --git a/Core/Contents/Include/PolyPlugin.h b/Core/Contents/Include/PolyPlugin.h index ab6d2d2eb..ba1394b16 100644 --- a/Core/Contents/Include/PolyPlugin.h +++ b/Core/Contents/Include/PolyPlugin.h @@ -59,6 +59,7 @@ namespace Polycode { Plugin* loadPluginFromEntry(ObjectEntry *entry); void addProp(Prop* prop); + void setProp(Prop* prop); void removeProp(Prop* prop); diff --git a/Core/Contents/Include/PolyPluginManager.h b/Core/Contents/Include/PolyPluginManager.h index 29e187901..a7463d803 100644 --- a/Core/Contents/Include/PolyPluginManager.h +++ b/Core/Contents/Include/PolyPluginManager.h @@ -26,6 +26,7 @@ THE SOFTWARE. namespace Polycode { + class ResourcePool; class String; class PluginManager : public PolyBase { @@ -33,7 +34,10 @@ namespace Polycode { PluginManager(); ~PluginManager(); - std::vector loadPluginsFromFile(const String &fileName); + std::vector loadPluginsFromFile(ResourcePool* pool, const String &fileName); + void loadPluginLibraryIntoPool(ResourcePool *pool, const String &pluginFile); + + void addPlugin(Plugin* plugin); protected: Number version; diff --git a/Core/Contents/Source/PolyEntity.cpp b/Core/Contents/Source/PolyEntity.cpp index 6d49c9d72..eb30a6b95 100755 --- a/Core/Contents/Source/PolyEntity.cpp +++ b/Core/Contents/Source/PolyEntity.cpp @@ -881,65 +881,16 @@ void Entity::setEntityProp(const String& propName, std::vector prop entityProps.push_back(entityProp); } -//bool Entity::readEntityProp(const String& propName, String& propVal) { -// for(int i=0; i < entityProps.size(); i++) { -// if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_STRING) { -// propVal = entityProps[i]->stringVal; -// return true; -// } else if (entityProps[i]->name == propName && entityProps[i]->type != Prop::PROP_STRING) { -// return false; -// } -// } -// return false; -//} -// -//bool Entity::readEntityProp(const String& propName, Number& propVal) { -// for (int i = 0; i < entityProps.size(); i++) { -// if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_NUMBER) { -// propVal = entityProps[i]->numberVal; -// return true; -// } else if (entityProps[i]->name == propName && entityProps[i]->type != Prop::PROP_NUMBER) { -// return false; -// } -// } -// return false; -//} -// -//bool Entity::readEntityProp(const String& propName, int& propVal) { -// for (int i = 0; i < entityProps.size(); i++) { -// if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_INT) { -// propVal = entityProps[i]->intVal; -// return true; -// } else if (entityProps[i]->name == propName && entityProps[i]->type != Prop::PROP_INT) { -// return false; -// } -// } -// return false; -//} -// -//bool Entity::readEntityProp(const String& propName, bool& propVal) { -// for (int i = 0; i < entityProps.size(); i++) { -// if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_BOOL) { -// propVal = entityProps[i]->boolVal; -// return true; -// } else if (entityProps[i]->name == propName && entityProps[i]->type != Prop::PROP_BOOL) { -// return false; -// } -// } -// return false; -//} -// -//bool Entity::readEntityProp(const String& propName, std::vector& propVal) { -// for (int i = 0; i < entityProps.size(); i++) { -// if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_ARRAY) { -// propVal = entityProps[i]->arrayVal; -// return true; -// } else if (entityProps[i]->name == propName && entityProps[i]->type != Prop::PROP_ARRAY) { -// return false; -// } -// } -// return false; -//} +void Entity::setEntityProp(EntityProp* prop){ + for (int i = 0; i < entityProps.size(); i++) { + if (entityProps[i] == prop) { + entityProps[i] = prop; + return; + } + } + + entityProps.push_back(prop); +} int Entity::getEntityPropIntByName(const String& propName) const { for (int i = 0; i < entityProps.size(); i++) { @@ -1463,10 +1414,31 @@ EntityProp::EntityProp(const String& name, const unsigned int& type) : Prop(name void Entity::addPluginByName(const String& pluginName, ResourcePool *resourcePool) { Plugin *plugin; + if (resourcePool) { plugin = (Plugin*)resourcePool->getResource(Resource::RESOURCE_PLUGIN, pluginName); } else { plugin = (Plugin*)Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_PLUGIN, pluginName); } - requiredPlugins.push_back(plugin); + + if (plugin){ + + for (int i = 0; i < requiredPlugins.size(); i++) { + if (requiredPlugins[i] == plugin) { + requiredPlugins[i] = plugin; + return; + } + } + + requiredPlugins.push_back(plugin); + } +} + +void Entity::removePluginByName(const String& pluginName) { + for (int i = 0; i < requiredPlugins.size(); i++) { + if (requiredPlugins[i]->getResourceName() == pluginName) { + requiredPlugins.erase(requiredPlugins.begin() + i); + return; + } + } } \ No newline at end of file diff --git a/Core/Contents/Source/PolyPlugin.cpp b/Core/Contents/Source/PolyPlugin.cpp index b3defd9fe..ae3a5150a 100644 --- a/Core/Contents/Source/PolyPlugin.cpp +++ b/Core/Contents/Source/PolyPlugin.cpp @@ -30,7 +30,13 @@ THE SOFTWARE. using namespace Polycode; Plugin::Plugin(const String& name) : Resource(Resource::RESOURCE_PLUGIN) { - Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_PLUGIN, name); + if (!Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_PLUGIN, name)) { + setResourceName(""); + ext = ""; + pluginType = 0; + type = Resource::RESOURCE_PLUGIN; + sheetEntry = NULL; + } } Plugin::Plugin(ObjectEntry *entry) : Resource(Resource::RESOURCE_PLUGIN) { @@ -75,9 +81,21 @@ void Plugin::addProp(Prop *prop) { props.push_back(prop); } +void Plugin::setProp(Prop *prop) { + for (int i = 0; i < props.size(); i++) { + if (props[i]->name == prop->name) { + props[i] = prop; + return; + } + } + + props.push_back(prop); +} + void Plugin::removeProp(Prop *propToRemove) { for (int i = 0; i PluginManager::loadPluginsFromFile(const String &fileName){ +std::vector PluginManager::loadPluginsFromFile(ResourcePool *pool, const String &fileName){ std::vector retPlugins; Object pluginFile; if (!pluginFile.loadFromBinary(fileName)) if (!pluginFile.loadFromXML(fileName)) return retPlugins; - //Logger::log("Loading plugins from %s", fileName.c_str()); - version = 1.0; - - //ObjectEntry* versionEntry = pluginFile.root["version"]; - //if (versionEntry->NumberVal > version) - // return retPlugins; - - //if (!pluginsEntry) { - // Logger::log("No plugins in %s\n", fileName.c_str()); - // return retPlugins; - //} for (int i = 0; i < pluginFile.root.children.size(); i++){ ObjectEntry* pluginEntry = pluginFile.root.children[i]; @@ -59,8 +49,20 @@ std::vector PluginManager::loadPluginsFromFile(const String &fileName){ continue; Plugin *plugin = new Plugin(pluginEntry); - if (plugin) + if (plugin){ + pool->addResource(plugin); retPlugins.push_back(plugin); + } } return retPlugins; +} + +void PluginManager::loadPluginLibraryIntoPool(ResourcePool *pool, const String &pluginFile) { + Logger::log("LOADING [%s] into pool [%s]\n", pluginFile.c_str(), pool->getName().c_str()); + + loadPluginsFromFile(pool, pluginFile); +} + +void PluginManager::addPlugin(Plugin* plugin) { + plugins.push_back(plugin); } \ No newline at end of file diff --git a/Core/Contents/Source/PolyResourceManager.cpp b/Core/Contents/Source/PolyResourceManager.cpp index e38b04eb9..0ce67ce7f 100755 --- a/Core/Contents/Source/PolyResourceManager.cpp +++ b/Core/Contents/Source/PolyResourceManager.cpp @@ -323,12 +323,8 @@ void ResourceManager::parsePluginsIntoPool(ResourcePool *pool, const String& dir for (int i = 0; i < resourceDir.size(); i++) { if (resourceDir[i].type == OSFileEntry::TYPE_FILE) { if (resourceDir[i].extension == "plugin") { - PluginManager *pluginManager = CoreServices::getInstance()->getPluginManager(); - std::vector plugins = pluginManager->loadPluginsFromFile(resourceDir[i].fullPath); - for (int p = 0; p < plugins.size(); p++) { - pool->addResource(plugins[p]); - } + std::vector plugins = pluginManager->loadPluginsFromFile(Services()->getResourceManager()->getGlobalPool(), resourceDir[i].fullPath); } } else { if (recursive) diff --git a/IDE/Build/Windows2013/Polycode.sln b/IDE/Build/Windows2013/Polycode.sln index 67ae375fa..a07f85ac4 100644 --- a/IDE/Build/Windows2013/Polycode.sln +++ b/IDE/Build/Windows2013/Polycode.sln @@ -1,8 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.30723.0 -MinimumVisualStudioVersion = 10.0.40219.1 +VisualStudioVersion = 12.0.30501.0MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Polycode", "Polycode.vcxproj", "{D6C2171B-9167-4FB6-851A-DC1CEDCFC43D}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0D5CDD59-CFF6-4143-8D1D-A92BBAB86060}" diff --git a/IDE/Build/Windows2013/Polycode.vcxproj b/IDE/Build/Windows2013/Polycode.vcxproj index 503c67b32..1dc8017ee 100644 --- a/IDE/Build/Windows2013/Polycode.vcxproj +++ b/IDE/Build/Windows2013/Polycode.vcxproj @@ -38,6 +38,7 @@ + @@ -76,6 +77,7 @@ + diff --git a/IDE/Build/Windows2013/Polycode.vcxproj.filters b/IDE/Build/Windows2013/Polycode.vcxproj.filters index dde3779ad..a77e0ee3e 100644 --- a/IDE/Build/Windows2013/Polycode.vcxproj.filters +++ b/IDE/Build/Windows2013/Polycode.vcxproj.filters @@ -114,6 +114,9 @@ Source + + Source + @@ -222,6 +225,9 @@ Include + + Include + diff --git a/IDE/Contents/Include/EntityEditorPropertyView.h b/IDE/Contents/Include/EntityEditorPropertyView.h index a27bba8bb..c8104edcc 100644 --- a/IDE/Contents/Include/EntityEditorPropertyView.h +++ b/IDE/Contents/Include/EntityEditorPropertyView.h @@ -60,6 +60,7 @@ class EntityEditorPropertyView : public UIElement { SoundSheet *soundSheet; SceneCurveSheet *curveSheet; CameraSheet *cameraSheet; + PluginsSheet *pluginsSheet; std::vector propSheets; SceneMeshSheet *sceneMeshSheet; diff --git a/IDE/Contents/Include/PolycodeIDEApp.h b/IDE/Contents/Include/PolycodeIDEApp.h index 5c64cb8ef..6dae452e9 100644 --- a/IDE/Contents/Include/PolycodeIDEApp.h +++ b/IDE/Contents/Include/PolycodeIDEApp.h @@ -42,6 +42,7 @@ #include "PolycodeSpriteEditor.h" #include "PolycodeMeshEditor.h" #include "PolycodeEntityEditor.h" +#include "PolycodePluginEditor.h" #include "PolycodeToolLauncher.h" diff --git a/IDE/Contents/Include/PolycodePluginEditor.h b/IDE/Contents/Include/PolycodePluginEditor.h new file mode 100644 index 000000000..18a5a11e8 --- /dev/null +++ b/IDE/Contents/Include/PolycodePluginEditor.h @@ -0,0 +1,144 @@ +/* +Copyright (C) 2014 by Joachim Meyer + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#pragma once +#include "PolycodeEditor.h" +#include +#include "PolycodeUI.h" +#include "PolycodeProps.h" +#include "PolyPlugin.h" + +namespace Polycode { + + class PluginBrowserData { + public: + PluginBrowserData() { + plugin = NULL; + } + Plugin *plugin; + }; + + class PluginBrowser : public UIElement { + public: + PluginBrowser(); + ~PluginBrowser(); + + void Resize(Number width, Number height); + + UITree *addPlugin(Plugin* plugin); + + void removeSelected(); + + void handleEvent(Event *event); + + PluginBrowserData *selectedData; + + UIImageButton *newPluginButton; + + UIImageButton *removeButton; + + UITree *selectedNode; + + protected: + + UIRect *headerBg; + UITree *pluginNode; + + UITreeContainer *treeContainer; + }; + + class PluginEditorPane : public UIElement { + public: + PluginEditorPane(ResourcePool* resourcePool); + ~PluginEditorPane(); + + void setPlugin(Plugin *plugin); + void handleEvent(Event *event); + + PropProp* getPropByName(); + void setProp(const String& name, PropProp* prop); + std::vector getProps(); + int getNumProps(); + + void Resize(Number width, Number height); + + Plugin *currentPlugin; + protected: + ResourcePool *resourcePool; + bool changingPlugin; + UIRect *headerBg; + PropList *propList; + PropSheet *propsSheet; + + StringProp* nameProp; + + StringProp* newPropName; + ButtonProp* addPropButton; + + //std::vector editProps; + //std::vector props; + }; + + class PluginMainWindow : public UIElement { + public: + PluginMainWindow(ResourcePool *resourcePool); + ~PluginMainWindow(); + + void Resize(Number width, Number height); + + PluginEditorPane *pluginPane; + + UIColorPicker *colorPicker; + }; + + class PolycodePluginEditor : public PolycodeEditor { + public: + PolycodePluginEditor(); + ~PolycodePluginEditor(); + + bool openFile(OSFileEntry filePath); + void Resize(int x, int y); + + void saveFile(); + void savePluginToObjectEntry(Plugin *plugin, ObjectEntry *entry); + + void handleEvent(Event *event); + + protected: + ResourcePool *resourcePool; + OSFileEntry filePath; + + PluginBrowser *pluginBrowser; + UIHSizer *mainSizer; + + PluginMainWindow *mainWindow; + std::vector plugins; + + UITree *selectedPluginNode; + }; + + class PolycodePluginEditorFactory : public PolycodeEditorFactory { + public: + PolycodePluginEditorFactory() : PolycodeEditorFactory() { extensions.push_back("plugin"); } + PolycodeEditor *createEditor() { return new PolycodePluginEditor(); } + }; +} \ No newline at end of file diff --git a/IDE/Contents/Include/PolycodeProps.h b/IDE/Contents/Include/PolycodeProps.h index c1ec3dacc..9c5ffe251 100644 --- a/IDE/Contents/Include/PolycodeProps.h +++ b/IDE/Contents/Include/PolycodeProps.h @@ -75,6 +75,7 @@ class PropProp : public UIElement { static const int PROP_TEXTURE = 20; static const int PROP_SCENE_SPRITE = 21; static const int PROP_SCENE_ENTITY_INSTANCE = 22; + static const int PROP_EDIT = 23; }; class Vector3Prop : public PropProp { @@ -493,6 +494,32 @@ class SceneEntityInstanceProp : public PropProp { }; +class PropEditProp : public PropProp { +public: + PropEditProp(PropProp* newProp); + ~PropEditProp(); + void handleEvent(Event *event); + + void set(PropProp *newProp); + PropProp *get(); + + int getPropType(); + + PropProp *currentProp; + + UITextInput *nameInput; + UIComboBox *typeChooser; + + UILabel *nameLabel; + UIMultilineLabel *typeLabel; + + int lastValue; + int currentValue; + + String lastName; + String currentName; +}; + class PropSheet : public UIElement { public: PropSheet(String caption, String type); @@ -579,6 +606,8 @@ class EntitySheet : public PropSheet { void setEntityInstance(SceneEntityInstance *instance); + std::vector pluginsProp; + protected: Entity *entity; @@ -589,6 +618,20 @@ class EntitySheet : public PropSheet { ColorProp *colorProp; ComboProp *blendingProp; Vector3Prop *bBoxProp; + +}; + +class PluginsSheet : public PropSheet { +public: + PluginsSheet(); + ~PluginsSheet(); + + void handleEvent(Event *event); + void setEntity(Entity *entity); + + std::vector pluginsProp; + + Entity *entity; }; class ShaderPassesSheet : public PropSheet { diff --git a/IDE/Contents/Resources/FileTemplates/General/Plugin.plugin b/IDE/Contents/Resources/FileTemplates/General/Plugin.plugin new file mode 100644 index 000000000..8b27dc254 --- /dev/null +++ b/IDE/Contents/Resources/FileTemplates/General/Plugin.plugin @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/IDE/Contents/Resources/Images/materialEditor/new_plugin.png b/IDE/Contents/Resources/Images/materialEditor/new_plugin.png new file mode 100644 index 0000000000000000000000000000000000000000..8b2677211e6ce9e7d2c5ad664cbf2baa412c5b72 GIT binary patch literal 469 zcmV;`0V@89P)h-z?6o9QMK~$8l)@sr) zjK2~oC3VZvfOBA*`RoFPYPBl0SnO9~+jc0}WHEMtvqrNi0Ynf4ao`fzU^yi42HcAv z2#$ah5WT+aoW)O(I0g(frPRxDCc{;+$bypRFlbnoaN6ykp7i^DR$(w0;QKzpG)+>; zBzL6}>2x}rznQV-dR}vIU6;pBhgFdPpW`vTUXO0KyOKl;gOAaOO1X^Zx}0RQ8Ze&9 zy`4UmQcC>$JMY6Gl}ZI*ZBjriwUZFn^8nU?5#Rw|lQ$GZt4H|;U{`66`ytdk00000 LNkvXXu0mjf24}k5 literal 0 HcmV?d00001 diff --git a/IDE/Contents/Resources/Images/materialEditor/plugin_icon.png b/IDE/Contents/Resources/Images/materialEditor/plugin_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..f2c270fe1c7a529588f84509d8534863357efc7c GIT binary patch literal 474 zcmV<00VV#4P) zK~y-)os+>zLO~dXzk72`-=ZgIYr7ULa@&Y6(t`w&FHqOGf)2GPYEcVQL9AT_;ihsC zl1fC%HA?>$H>GZRNe|3o&K$lu^TSwLYo^H<69LYFb>ITnOr=u8X<0jHSeAt`Mgf&? z0Kf)NF~%s{w!Jx z_-}}9+qn7sxWO#ISP7t<%jHyLX~}oA)`&<eq`0MYyyuRW%PH2m4Hp^41g@{bNNHF9L2BDB%zyHVk0x;Gk=$hor Q(EtDd07*qoM6N<$f<8pW?*IS* literal 0 HcmV?d00001 diff --git a/IDE/Contents/Source/EntityEditorPropertyView.cpp b/IDE/Contents/Source/EntityEditorPropertyView.cpp index 1da065281..67fa5891d 100644 --- a/IDE/Contents/Source/EntityEditorPropertyView.cpp +++ b/IDE/Contents/Source/EntityEditorPropertyView.cpp @@ -87,6 +87,10 @@ EntityEditorPropertyView::EntityEditorPropertyView() : UIElement() { entityProps->addPropSheet(entitySheet); entitySheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE); + pluginsSheet = new PluginsSheet(); + entityProps->addPropSheet(pluginsSheet); + pluginsSheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE); + std::vector plugins = Services()->getResourceManager()->getGlobalPool()->getResources(Resource::RESOURCE_PLUGIN); for (int p = 0; p < plugins.size(); p++) { EntityPropSheet *propSheet = new EntityPropSheet(dynamic_cast(plugins[p])); @@ -112,6 +116,13 @@ void EntityEditorPropertyView::handleEvent(Event *event) { PropEvent *propEvent = (PropEvent*) event; + if (event->getDispatcher() == pluginsSheet){ + for (int p = 0; p < propSheets.size(); p++){ + propSheets[p]->setEntity(this->targetEntity); + } + + } + PropEvent *newPropEvent = new PropEvent(propEvent->prop, propEvent->sheet, propEvent->beforeData, propEvent->afterData); dispatchEvent(newPropEvent, PropEvent::EVENT_PROP_CHANGE); } else { @@ -185,6 +196,9 @@ void EntityEditorPropertyView::setEntity(Entity *entity) { particleSheet->setParticleEmitter(emitter); entitySheet->setEntity(entity); + + pluginsSheet->setEntity(entity); + for (int p = 0; p < propSheets.size(); p++) { propSheets[p]->setEntity(entity); } diff --git a/IDE/Contents/Source/PolycodeIDEApp.cpp b/IDE/Contents/Source/PolycodeIDEApp.cpp index dbb74f4bf..32a8d062c 100644 --- a/IDE/Contents/Source/PolycodeIDEApp.cpp +++ b/IDE/Contents/Source/PolycodeIDEApp.cpp @@ -175,7 +175,8 @@ PolycodeIDEApp::PolycodeIDEApp(PolycodeView *view) : EventDispatcher() { editorManager->registerEditorFactory(new PolycodeSpriteEditorFactory()); editorManager->registerEditorFactory(new PolycodeMeshEditorFactory()); editorManager->registerEditorFactory(new PolycodeEntityEditorFactory()); - + editorManager->registerEditorFactory(new PolycodePluginEditorFactory()); + screen->addChild(globalMenu); frame->console->applyTheme(); diff --git a/IDE/Contents/Source/PolycodePluginEditor.cpp b/IDE/Contents/Source/PolycodePluginEditor.cpp new file mode 100644 index 000000000..343e16025 --- /dev/null +++ b/IDE/Contents/Source/PolycodePluginEditor.cpp @@ -0,0 +1,353 @@ +/* +Copyright (C) 2014 by Joachim Meyer + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#include "PolycodePluginEditor.h" +#include "PolyPluginManager.h" + +using namespace Polycode; + +PluginBrowser::PluginBrowser() : UIElement() { + treeContainer = new UITreeContainer("boxIcon.png", L"Polycode Plugins", 200, 555); + treeContainer->getRootNode()->toggleCollapsed(); + treeContainer->getRootNode()->addEventListener(this, UITreeEvent::SELECTED_EVENT); + treeContainer->addEventListener(this, InputEvent::EVENT_MOUSEDOWN); + + pluginNode = treeContainer->getRootNode()->addTreeChild("materialEditor/plugin_icon.png", "Plugins", NULL); + + addChild(treeContainer); + selectedData = NULL; + + headerBg = new UIRect(10, 10); + addChild(headerBg); + headerBg->setAnchorPoint(-1.0, -1.0, 0.0); + headerBg->color.setColorHexFromString(CoreServices::getInstance()->getConfig()->getStringValue("Polycode", "uiHeaderBgColor")); + + newPluginButton = new UIImageButton("materialEditor/new_plugin.png", 1.0, 22, 22); + addChild(newPluginButton); + newPluginButton->setPosition(5, 4); + + removeButton = new UIImageButton("main/remove_icon.png", 1.0, 12, 12); + addChild(removeButton); + removeButton->setPosition(0, 4); + + selectedNode = NULL; +} + +PluginBrowser::~PluginBrowser() {} + +void PluginBrowser::removeSelected() { + selectedNode->getParent()->removeTreeChild(selectedNode); +} + +void PluginBrowser::handleEvent(Event *event) { + + if (event->getDispatcher() == treeContainer->getRootNode()) { + if (event->getEventCode() == UITreeEvent::SELECTED_EVENT) { + selectedNode = treeContainer->getRootNode()->getSelectedNode(); + PluginBrowserData *data = (PluginBrowserData *)selectedNode->getUserData(); + selectedData = data; + dispatchEvent(new Event(), Event::CHANGE_EVENT); + } + } + Entity::handleEvent(event); +} + + +UITree *PluginBrowser::addPlugin(Plugin *plugin) { + PluginBrowserData *data = new PluginBrowserData(); + data->plugin = plugin; + return pluginNode->addTreeChild("materialEditor/material_icon.png", plugin->getResourceName(), (void*)data); +} + +void PluginBrowser::Resize(Number width, Number height) { + treeContainer->Resize(width, height - 30); + treeContainer->setPosition(0, 30); + headerBg->Resize(width, 30); + removeButton->setPosition(width - 24, 8); +} + + +PluginEditorPane::PluginEditorPane(ResourcePool *resourcePool) : UIElement() { + + this->resourcePool = resourcePool; + changingPlugin = false; + currentPlugin = NULL; + + headerBg = new UIRect(10, 10); + addChild(headerBg); + headerBg->setAnchorPoint(-1.0, -1.0, 0.0); + headerBg->color.setColorHexFromString(CoreServices::getInstance()->getConfig()->getStringValue("Polycode", "uiHeaderBgColor")); + + propList = new PropList("PLUGIN EDITOR"); + addChild(propList); + propList->setPosition(0, 0); + + PropSheet *baseProps = new PropSheet("PLUGIN SETTINGS", ""); + propList->addPropSheet(baseProps); + + nameProp = new StringProp("Name"); + baseProps->addProp(nameProp); + nameProp->addEventListener(this, Event::CHANGE_EVENT); + + addPropButton = new ButtonProp("New Prop"); + baseProps->addProp(addPropButton); + addPropButton->getButton()->addEventListener(this, UIEvent::CLICK_EVENT); + + baseProps->propHeight = 220; + + propsSheet = new PropSheet("PROPS", ""); + propList->addPropSheet(propsSheet); + + propList->updateProps(); + + enabled = false; +} + +PluginEditorPane::~PluginEditorPane() { + +} + +void PluginEditorPane::handleEvent(Event *event) { + if (!changingPlugin) { + + if (event->getDispatcher() == nameProp) { + currentPlugin->setResourceName(nameProp->get()); + dispatchEvent(new Event(), Event::CHANGE_EVENT); + } + + for (int p = 0; p < propsSheet->props.size(); p++){ + if (event->getDispatcher() == propsSheet->props[p]) { + dispatchEvent(new Event(), Event::CHANGE_EVENT); + } + } + + if (event->getDispatcher() == addPropButton->getButton()) { + PropEditProp *newProp = new PropEditProp(new PropProp("", 0)); + propsSheet->addProp(newProp); + dispatchEvent(new Event(), Event::CHANGE_EVENT); + } + + + } +} + +void PluginEditorPane::setPlugin(Plugin *plugin) { + changingPlugin = true; + + currentPlugin = plugin; + + nameProp->set(plugin->getResourceName()); + + ObjectEntry *propsEntry = (*plugin->sheetEntry)["props"]; + if (propsEntry) { + for (int p = 0; p < propsEntry->children.size(); p++) { + ObjectEntry* propEntry = (*propsEntry)[p]; + if (propEntry && propEntry->name == "prop") { + setProp((*propEntry)["name"]->stringVal, new PropProp((*propEntry)["name"]->stringVal, (*propEntry)["type"]->intVal)); + } + } + } + + enabled = true; + + changingPlugin = false; +} + +void PluginEditorPane::Resize(Number width, Number height) { + headerBg->Resize(width, 30); + propList->Resize(width, height); + propList->updateProps(); +} + +std::vector PluginEditorPane::getProps() { + return propsSheet->props; +} + +void PluginEditorPane::setProp(const String& name, PropProp* prop){ + for (int i = 0; i < propsSheet->props.size(); i++) { + if (propsSheet->props[i]->getPropName() == name) { + PropEditProp *newProp = new PropEditProp(prop); + propsSheet->props[i] = newProp; + newProp->addEventListener(this, Event::CHANGE_EVENT); + return; + } + } + + PropEditProp *newProp = new PropEditProp(prop); + propsSheet->addProp(newProp); + newProp->addEventListener(this, Event::CHANGE_EVENT); +} + +PluginMainWindow::PluginMainWindow(ResourcePool *resourcePool) : UIElement() { + + pluginPane = new PluginEditorPane(resourcePool); + + ownsChildren = true; + + addChild(pluginPane); +} + +PluginMainWindow::~PluginMainWindow() {} + +void PluginMainWindow::Resize(Number width, Number height) { + Vector2 pos = getScreenPositionForMainCamera(); + scissorBox.setRect(pos.x, pos.y, width, height); + pluginPane->Resize(width, height); +} + +PolycodePluginEditor::PolycodePluginEditor() : PolycodeEditor(true) { + selectedPluginNode = NULL; +} + +PolycodePluginEditor::~PolycodePluginEditor() { + delete resourcePool; + + mainWindow->setOwnsChildrenRecursive(true); + delete mainWindow; + delete mainSizer; + delete pluginBrowser; +} + +bool PolycodePluginEditor::openFile(OSFileEntry filePath) { + this->filePath = filePath; + + mainSizer = new UIHSizer(100, 100, 200, false); + addChild(mainSizer); + + pluginBrowser = new PluginBrowser(); + mainSizer->addRightChild(pluginBrowser); + + pluginBrowser->addEventListener(this, Event::CHANGE_EVENT); + + String resourceName = filePath.fullPath.replace(parentProject->getRootFolder() + "/", ""); + + resourcePool = CoreServices::getInstance()->getResourceManager()->getResourcePoolByName(resourceName); + + if (!resourcePool) { + resourcePool = new ResourcePool(resourceName, CoreServices::getInstance()->getResourceManager()->getGlobalPool()); + resourcePool->reloadResourcesOnModify = true; + resourcePool->deleteOnUnsubscribe = true; + CoreServices::getInstance()->getPluginManager()->loadPluginLibraryIntoPool(resourcePool, filePath.fullPath); + CoreServices::getInstance()->getResourceManager()->addResourcePool(resourcePool); + } + + CoreServices::getInstance()->getResourceManager()->subscribeToResourcePool(resourcePool); + + mainWindow = new PluginMainWindow(resourcePool); + mainSizer->addLeftChild(mainWindow); + + for (int i = 0; i < resourcePool->getResources(Resource::RESOURCE_PLUGIN).size(); i++) { + Plugin *plugin = (Plugin*)resourcePool->getResources(Resource::RESOURCE_PLUGIN)[i]; + pluginBrowser->addPlugin(plugin); + } + + mainWindow->pluginPane->addEventListener(this, Event::CHANGE_EVENT); + + pluginBrowser->newPluginButton->addEventListener(this, UIEvent::CLICK_EVENT); + pluginBrowser->removeButton->addEventListener(this, UIEvent::CLICK_EVENT); + + mainWindow->pluginPane->addEventListener(this, Event::CHANGE_EVENT); + + PolycodeEditor::openFile(filePath); + return true; +} + +void PolycodePluginEditor::saveFile() { + Object saveFile; + saveFile.root.name = "plugins"; + saveFile.root.addChild("version", 1); + for (int p = 0; p < resourcePool->getResources(Resource::RESOURCE_PLUGIN).size(); p++) { + ObjectEntry* pluginEntry = saveFile.root.addChild("plugin"); + if (pluginEntry) { + savePluginToObjectEntry(pluginBrowser->selectedData->plugin, pluginEntry); + } + } + saveFile.saveToXML(filePath.fullPath); + setHasChanges(false); +} + +void PolycodePluginEditor::savePluginToObjectEntry(Plugin* plugin, ObjectEntry* entry) { + entry->addChild("name", plugin->getResourceName()); + entry->addChild("fileext", plugin->ext); + entry->addChild("type", (int)plugin->pluginType); + + ObjectEntry* sheetEntry = entry->addChild("sheet"); + //sheetEntry->addChild("name", plugin->getSheetName()); + ObjectEntry* propsEntry = sheetEntry->addChild("props"); + std::vector props = mainWindow->pluginPane->getProps(); + for (int i = 0; i < props.size(); i++) { + ObjectEntry* propEntry = propsEntry->addChild("prop"); + propEntry->addChild("type", ((PropEditProp*)props[i])->getPropType()); + propEntry->addChild("name", props[i]->getPropName()); + } +} + +void PolycodePluginEditor::handleEvent(Event *event) { + + if (event->getDispatcher() == mainWindow->pluginPane && event->getEventType() == "" && event->getEventCode() == Event::CHANGE_EVENT) { + if (selectedPluginNode && mainWindow->pluginPane->currentPlugin) { + selectedPluginNode->setLabelText(mainWindow->pluginPane->currentPlugin->getResourceName()); + } + setHasChanges(true); + } + + if (event->getDispatcher() == pluginBrowser->newPluginButton && event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CLICK_EVENT) { + Plugin *newPlugin = new Plugin("New Plugin"); + pluginBrowser->addPlugin(newPlugin)->setSelected(); + resourcePool->addResource(newPlugin); + setHasChanges(true); + } + + if (event->getDispatcher() == pluginBrowser->removeButton && event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CLICK_EVENT) { + + mainWindow->pluginPane->enabled = false; + + if (pluginBrowser->selectedData->plugin) { + for (int i = 0; i < resourcePool->getResources(Resource::RESOURCE_PLUGIN).size(); i++) { + if ((Plugin*)resourcePool->getResources(Resource::RESOURCE_PLUGIN)[i] == pluginBrowser->selectedData->plugin) { + resourcePool->removeResource(resourcePool->getResource(Resource::RESOURCE_PLUGIN, pluginBrowser->selectedData->plugin->getResourceName())); + pluginBrowser->removeSelected(); + break; + } + } + } + } + + if (event->getDispatcher() == pluginBrowser) { + if (event->getEventType() == "" && event->getEventCode() == Event::CHANGE_EVENT) { + if (pluginBrowser->selectedData) { + mainWindow->pluginPane->enabled = false; + + if (pluginBrowser->selectedData->plugin) { + selectedPluginNode = pluginBrowser->selectedNode; + mainWindow->pluginPane->setPlugin(pluginBrowser->selectedData->plugin); + } + + } + } + } +} + +void PolycodePluginEditor::Resize(int x, int y) { + mainSizer->Resize(((Number)x), ((Number)y)); + PolycodeEditor::Resize(((Number)x), ((Number)y)); +} diff --git a/IDE/Contents/Source/PolycodeProps.cpp b/IDE/Contents/Source/PolycodeProps.cpp index 6849887dc..2454acb6f 100644 --- a/IDE/Contents/Source/PolycodeProps.cpp +++ b/IDE/Contents/Source/PolycodeProps.cpp @@ -1866,6 +1866,98 @@ void RenderTargetProp::handleEvent(Event *event) { PropProp::handleEvent(event); } +PropEditProp::PropEditProp(PropProp *newProp) : PropProp(newProp->getPropName(), PropProp::PROP_EDIT) { + nameInput = NULL; + typeChooser = NULL; + + nameLabel = new UILabel("Name:", 11); + nameLabel->color.a = 1.0; + propContents->addChild(nameLabel); + nameLabel->setPosition(-20, 5); + + typeLabel = new UIMultilineLabel("Type:\n(ni) = not implemented", 11, 7); + typeLabel->color.a = 1.0; + propContents->addChild(typeLabel); + typeLabel->setPosition(-20, 27); + + nameInput = new UITextInput(false, 50, 12); + nameInput->addEventListener(this, UIEvent::CHANGE_EVENT); + nameInput->setText(newProp->getPropName()); + propContents->addChild(nameInput); + nameInput->setPosition(50, 0); + + typeChooser = new UIComboBox(globalMenu, 200); + typeChooser->addComboItem("Vector3", (void*)0); + typeChooser->addComboItem("Vector2", (void*)1); + typeChooser->addComboItem("Slider", (void*)2); + typeChooser->addComboItem("Button (ni)", (void*)3); + typeChooser->addComboItem("Number", (void*)4); + typeChooser->addComboItem("Target Binding (ni)",(void*)5); + typeChooser->addComboItem("Render Target (ni)",(void*)6); + typeChooser->addComboItem("Shader Pass (ni)", (void*)7); + typeChooser->addComboItem("Removable String", (void*)8); + typeChooser->addComboItem("Layer (ni)", (void*)9); + typeChooser->addComboItem("Custom", (void*)10); + typeChooser->addComboItem("String", (void*)11); + typeChooser->addComboItem("Color", (void*)12); + typeChooser->addComboItem("Combo (ni)", (void*)13); + typeChooser->addComboItem("Bool", (void*)14); + typeChooser->addComboItem("Sound", (void*)15); + typeChooser->addComboItem("Bezier RGBA Curve (ni)", (void*)16); + typeChooser->addComboItem("Bezier Curve (ni)", (void*)17); + typeChooser->addComboItem("Material", (void*)18); + typeChooser->addComboItem("Material Preview", (void*)19); + typeChooser->addComboItem("Texture", (void*)20); + typeChooser->addComboItem("Scene Sprite", (void*)21); + typeChooser->addComboItem("Scene Entity Instance", (void*)22); + typeChooser->setSelectedIndex(newProp->propType); + typeChooser->addEventListener(this, UIEvent::CHANGE_EVENT); + propContents->addChild(typeChooser); + typeChooser->setPosition(50, 25); + + currentValue = newProp->propType; + + setHeight(65); +} + +PropEditProp::~PropEditProp(){} + +void PropEditProp::handleEvent(Event *event){ + if (event->getDispatcher() == typeChooser) { + if (event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CHANGE_EVENT) { + lastValue = currentValue; + currentValue = typeChooser->getSelectedIndex(); + if (!suppressChangeEvent) { + dispatchEvent(new Event(), Event::CHANGE_EVENT); + dispatchEvent(new PropEvent(this, NULL, PropDataInt(lastValue), PropDataInt(currentValue)), PropEvent::EVENT_PROP_CHANGE); + } + } + } + if (event->getDispatcher() == nameInput) { + if (event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CHANGE_EVENT) { + lastName = currentName; + currentName = nameInput->getText(); + setPropName(nameInput->getText()); + if (!suppressChangeEvent) { + dispatchEvent(new Event(), Event::CHANGE_EVENT); + dispatchEvent(new PropEvent(this, NULL, PropDataString(lastName), PropDataString(currentName)), PropEvent::EVENT_PROP_CHANGE); + } + } + } +} + +void PropEditProp::set(PropProp *newProp){ + currentProp = newProp; +} + +PropProp *PropEditProp::get(){ + return currentProp; +} + +int PropEditProp::getPropType(){ + return currentValue; +} + ShaderPassesSheet::ShaderPassesSheet(ResourcePool *resourcePool) : PropSheet("SHADER PASSES", "shaderPasses") { this->resourcePool = resourcePool; propHeight = 70; @@ -2133,7 +2225,7 @@ void RenderTargetsSheet::handleEvent(Event *event) { PropSheet::handleEvent(event); } -EntityPropSheet::EntityPropSheet(Plugin* plugin) : PropSheet(plugin->getResourceName().toUpperCase(), plugin->ext){ +EntityPropSheet::EntityPropSheet(Plugin* plugin) : PropSheet(plugin->getResourceName().toUpperCase(), plugin->getResourceName().toLowerCase()){ this->plugin = plugin->getResourceName(); customUndoHandler = true; @@ -2144,6 +2236,8 @@ EntityPropSheet::EntityPropSheet(Plugin* plugin) : PropSheet(plugin->getResource removeIndex = -1; enabled = false; + + if (plugin->sheetEntry) refreshProps(); } @@ -2154,7 +2248,7 @@ void EntityPropSheet::applyPropActionData(PolycodeEditorPropActionData *data) { entity->entityProps.clear(); for(int i=0; i < data->entity->entityProps.size(); i++) { - entity->entityProps.push_back(data->entity->entityProps[i]); + entity->setEntityProp(data->entity->entityProps[i]); } refreshProps(); @@ -2173,7 +2267,7 @@ void EntityPropSheet::handleEvent(Event *event) { break; case Event::CHANGE_EVENT: PolycodeEditorPropActionData *beforeData = PropDataEntity(entity); - if(i < entity->entityProps.size()) { + if(i <= entity->entityProps.size()) { std::vector propsVector; EntityProp* prop; @@ -2285,92 +2379,6 @@ void EntityPropSheet::reloadSheetFromEntry(ObjectEntry *sheetEntry) { ObjectEntry *propsEntry = (*sheetEntry)["props"]; if (propsEntry) { refreshProps(); - //PropProp *prop; - //if (propsEntry) { - // for (int i = 0; i < propsEntry->children.size(); i++) { - // ObjectEntry* propEntry = propsEntry->children[i]; - // String caption = (*propEntry)["name"]->stringVal; - // switch ((*propEntry)["type"]->intVal) { - // case PropProp::PROP_VECTOR3: - // prop = new Vector3Prop(caption); - // break; - // case PropProp::PROP_VECTOR2: - // prop = new Vector2Prop(caption); - // break; - // case PropProp::PROP_SLIDER: - // prop = new SliderProp(caption, (*propEntry)["min"]->NumberVal, (*propEntry)["max"]->NumberVal); - // break; - // //case PropProp::PROP_BUTTON: - // // prop = new ButtonProp(caption); - // // break; - // case PropProp::PROP_NUMBER: - // prop = new NumberProp(caption); - // break; - // //case PropProp::PROP_TARGET_BINDING: - // // Shader *shader; - // // Material *material; - // // ShaderBinding *shaderBin; - // // RenderTargetBinding *targetBin; - // // - // // prop = new TargetBindingProp(shader, material, shaderBin, targetBin); - // // - // // break; - // //case PropProp::PROP_RENDER_TARGET: - // // ShaderRenderTarget *renderTarget; - // // Material *material; - // // prop = new RenderTargetProp(renderTarget, material); - // // break; - // //case PropProp::PROP_SHADER_PASS: - // // prop = new ShaderPassProp(); - // // break; - // //case PropProp::PROP_REMOVABLE_STRING: - // // prop = new RemovableStringProp(caption); - // // break; - // //case PropProp::PROP_LAYER: - // // SceneEntityInstance *instance = new SceneEntityInstance(); - // // prop = new LayerProp(); - // // break; - // case PropProp::PROP_STRING: - // prop = new StringProp(caption); - // break; - // case PropProp::PROP_COLOR: - // prop = new ColorProp(caption); - // break; - // case PropProp::PROP_COMBO: - // prop = new ComboProp(caption); - // break; - // case PropProp::PROP_BOOL: - // prop = new BoolProp(caption); - // break; - // case PropProp::PROP_SOUND: - // prop = new SoundProp(caption); - // break; - // case PropProp::PROP_BEZIER_RGBA_CURVE: - // prop = new BezierRGBACurveProp(caption); - // break; - // case PropProp::PROP_BEZIER_CURVE: - // prop = new BezierCurveProp(caption, (*propEntry)["curveName"]->stringVal); - // break; - // case PropProp::PROP_MATERIAL: - // prop = new MaterialProp(caption); - // break; - // case PropProp::PROP_TEXTURE: - // prop = new TextureProp(caption); - // break; - // case PropProp::PROP_SCENE_SPRITE: - // prop = new SceneSpriteProp(caption); - // break; - // case PropProp::PROP_SCENE_ENTITY_INSTANCE: - // prop = new SceneEntityInstanceProp(caption); - // break; - // case PropProp::PROP_CUSTOM: - // default: - // prop = new CustomProp(caption, ""); - // break; - // } - // addProp(prop); - // } - //} } } @@ -3489,7 +3497,7 @@ EntitySheet::EntitySheet() : PropSheet("ENTITY", "entity"){ blendingProp->comboEntry->addComboItem("Color"); blendingProp->comboEntry->addComboItem("Premultiplied"); blendingProp->comboEntry->addComboItem("Multiply"); - + propHeight = 160; entity = NULL; @@ -3532,7 +3540,8 @@ void EntitySheet::handleEvent(Event *event) { } else if(event->getDispatcher() == layersProp && event->getEventCode() == Event::CHANGE_EVENT) { SceneEntityInstanceLayer *layer = (SceneEntityInstanceLayer*)layersProp->comboEntry->getSelectedItem()->data; entity->layerID = layer->layerID; - } + } + PropSheet::handleEvent(event); } @@ -3567,12 +3576,56 @@ void EntitySheet::setEntity(Entity *entity) { bBoxProp->set(entity->getLocalBoundingBox()); refreshLayers(); + enabled = true; } else { enabled = false; } } +PluginsSheet::PluginsSheet() : PropSheet("PLUGINS SHEETS", "plugins"){ + for (int p = 0; p < Services()->getResourceManager()->getGlobalPool()->getResources(Resource::RESOURCE_PLUGIN).size(); p++){ + BoolProp *pluginProp = new BoolProp(Services()->getResourceManager()->getGlobalPool()->getResources(Resource::RESOURCE_PLUGIN)[p]->getResourceName()); + pluginsProp.push_back(pluginProp); + addProp(pluginProp); + } + + entity = NULL; + + propHeight = 160; + enabled = false; +} + +PluginsSheet::~PluginsSheet() {} + +void PluginsSheet::handleEvent(Event *event) { + for (int p = 0; p < pluginsProp.size(); p++){ + if (event->getDispatcher() == pluginsProp[p]) { + if (pluginsProp[p]->get()){ + entity->addPluginByName(pluginsProp[p]->getPropName()); + } else { + entity->removePluginByName(pluginsProp[p]->getPropName()); + } + dispatchEvent(new Event(), Event::CHANGE_EVENT); + } + } + + PropSheet::handleEvent(event); +} + +void PluginsSheet::setEntity(Entity *entity) { + this->entity = entity; + if (entity) { + for (int p = 0; p < pluginsProp.size(); p++){ + pluginsProp[p]->set(entity->isRequiredPlugin(pluginsProp[p]->getPropName())); + } + + enabled = true; + } else { + enabled = false; + } +} + CameraSheet::CameraSheet() : PropSheet("CAMERA", "camera") { enabled = false; camera = NULL; @@ -4296,9 +4349,3 @@ void SoundSheet::setSound(SceneSound *sound) { } else { enabled = false; } -} - -//CustomSheet::CustomSheet(ObjectEntry *sheetEntry) : PropSheet((*sheetEntry)["name"]->stringVal.toUpperCase(), (*sheetEntry)["fileext"]->stringVal) { -// reloadSheetFromFile(sheetEntry); -//} - diff --git a/Modules/Contents/UI/Include/PolyUIComboBox.h b/Modules/Contents/UI/Include/PolyUIComboBox.h index 3d6f017f5..35d769f35 100755 --- a/Modules/Contents/UI/Include/PolyUIComboBox.h +++ b/Modules/Contents/UI/Include/PolyUIComboBox.h @@ -54,7 +54,7 @@ namespace Polycode { int addComboItem(String itemName); int addComboItem(String itemName, void *data); - + int getSelectedIndex(); UIComboBoxItem *getSelectedItem(); void setSelectedIndex(unsigned int newIndex, bool suppressChangeEvent = false); From deb676494d17496972bb633fa152bb12bf32add3 Mon Sep 17 00:00:00 2001 From: Joachim Meyer Date: Wed, 3 Sep 2014 22:37:18 +0200 Subject: [PATCH 06/19] Some improvements with the PluginEdior for long prop names. --- IDE/Contents/Include/PolycodePluginEditor.h | 2 ++ IDE/Contents/Include/PolycodeProps.h | 6 ++--- IDE/Contents/Source/PolycodePluginEditor.cpp | 26 +++++++++++++++++--- IDE/Contents/Source/PolycodeProps.cpp | 19 ++++++++------ 4 files changed, 39 insertions(+), 14 deletions(-) diff --git a/IDE/Contents/Include/PolycodePluginEditor.h b/IDE/Contents/Include/PolycodePluginEditor.h index 18a5a11e8..75a561c7e 100644 --- a/IDE/Contents/Include/PolycodePluginEditor.h +++ b/IDE/Contents/Include/PolycodePluginEditor.h @@ -94,6 +94,8 @@ namespace Polycode { StringProp* newPropName; ButtonProp* addPropButton; + int padding; + //std::vector editProps; //std::vector props; }; diff --git a/IDE/Contents/Include/PolycodeProps.h b/IDE/Contents/Include/PolycodeProps.h index 9c5ffe251..25a15289e 100644 --- a/IDE/Contents/Include/PolycodeProps.h +++ b/IDE/Contents/Include/PolycodeProps.h @@ -503,6 +503,8 @@ class PropEditProp : public PropProp { void set(PropProp *newProp); PropProp *get(); + int updatePadding(); + int getPropType(); PropProp *currentProp; @@ -851,10 +853,6 @@ class EntityPropSheet : public PropSheet { void setEntity(Entity *entity); void handleEvent(Event *event); - //void refreshProps(ObjectEntry *propsEntry); - - //ButtonProp *addButtonProp; - Entity *entity; String plugin; diff --git a/IDE/Contents/Source/PolycodePluginEditor.cpp b/IDE/Contents/Source/PolycodePluginEditor.cpp index 343e16025..dbff6d659 100644 --- a/IDE/Contents/Source/PolycodePluginEditor.cpp +++ b/IDE/Contents/Source/PolycodePluginEditor.cpp @@ -134,19 +134,31 @@ void PluginEditorPane::handleEvent(Event *event) { dispatchEvent(new Event(), Event::CHANGE_EVENT); } + int maxPadding = 0; for (int p = 0; p < propsSheet->props.size(); p++){ if (event->getDispatcher() == propsSheet->props[p]) { dispatchEvent(new Event(), Event::CHANGE_EVENT); } + if (((PropEditProp*)propsSheet->props[p])->updatePadding() > maxPadding){ + maxPadding = ((PropEditProp*)propsSheet->props[p])->updatePadding(); + } + } + + padding = maxPadding; + + if (padding < (propList->getWidth() - 320)){ + for (int p = 0; p < propsSheet->props.size(); p++){ + propsSheet->props[p]->propContents->setPositionX(padding + 20); + } } if (event->getDispatcher() == addPropButton->getButton()) { PropEditProp *newProp = new PropEditProp(new PropProp("", 0)); propsSheet->addProp(newProp); + newProp->addEventListener(this, Event::CHANGE_EVENT); + newProp->propContents->setPositionX(padding + 20); dispatchEvent(new Event(), Event::CHANGE_EVENT); } - - } } @@ -167,6 +179,10 @@ void PluginEditorPane::setPlugin(Plugin *plugin) { } } + for (int p = 0; p < propsSheet->props.size(); p++){ + propsSheet->props[p]->propContents->setPositionX(padding + 20); + } + enabled = true; changingPlugin = false; @@ -176,6 +192,7 @@ void PluginEditorPane::Resize(Number width, Number height) { headerBg->Resize(width, 30); propList->Resize(width, height); propList->updateProps(); + } std::vector PluginEditorPane::getProps() { @@ -186,13 +203,16 @@ void PluginEditorPane::setProp(const String& name, PropProp* prop){ for (int i = 0; i < propsSheet->props.size(); i++) { if (propsSheet->props[i]->getPropName() == name) { PropEditProp *newProp = new PropEditProp(prop); - propsSheet->props[i] = newProp; + if (((PropEditProp*)newProp)->updatePadding() > padding) + padding = ((PropEditProp*)newProp)->updatePadding(); newProp->addEventListener(this, Event::CHANGE_EVENT); return; } } PropEditProp *newProp = new PropEditProp(prop); + if (((PropEditProp*)newProp)->updatePadding() > padding) + padding = ((PropEditProp*)newProp)->updatePadding(); propsSheet->addProp(newProp); newProp->addEventListener(this, Event::CHANGE_EVENT); } diff --git a/IDE/Contents/Source/PolycodeProps.cpp b/IDE/Contents/Source/PolycodeProps.cpp index 2454acb6f..85b199f6c 100644 --- a/IDE/Contents/Source/PolycodeProps.cpp +++ b/IDE/Contents/Source/PolycodeProps.cpp @@ -1873,19 +1873,19 @@ PropEditProp::PropEditProp(PropProp *newProp) : PropProp(newProp->getPropName(), nameLabel = new UILabel("Name:", 11); nameLabel->color.a = 1.0; propContents->addChild(nameLabel); - nameLabel->setPosition(-20, 5); + nameLabel->setPosition(0, 5); typeLabel = new UIMultilineLabel("Type:\n(ni) = not implemented", 11, 7); typeLabel->color.a = 1.0; propContents->addChild(typeLabel); - typeLabel->setPosition(-20, 27); + typeLabel->setPosition(0, 27); - nameInput = new UITextInput(false, 50, 12); + nameInput = new UITextInput(false, 200, 12); nameInput->addEventListener(this, UIEvent::CHANGE_EVENT); nameInput->setText(newProp->getPropName()); propContents->addChild(nameInput); - nameInput->setPosition(50, 0); - + nameInput->setPosition(70, 0); + typeChooser = new UIComboBox(globalMenu, 200); typeChooser->addComboItem("Vector3", (void*)0); typeChooser->addComboItem("Vector2", (void*)1); @@ -1913,7 +1913,7 @@ PropEditProp::PropEditProp(PropProp *newProp) : PropProp(newProp->getPropName(), typeChooser->setSelectedIndex(newProp->propType); typeChooser->addEventListener(this, UIEvent::CHANGE_EVENT); propContents->addChild(typeChooser); - typeChooser->setPosition(50, 25); + typeChooser->setPosition(70, 25); currentValue = newProp->propType; @@ -1954,6 +1954,10 @@ PropProp *PropEditProp::get(){ return currentProp; } +int PropEditProp::updatePadding(){ + return label->getWidth(); +} + int PropEditProp::getPropType(){ return currentValue; } @@ -2418,7 +2422,7 @@ void EntityPropSheet::refreshProps() { dynamic_cast(prop)->set(Vector2(entity->getEntityPropNumberByName(caption + "x"), entity->getEntityPropNumberByName(caption + "y"))); break; case PropProp::PROP_SLIDER: - prop = new SliderProp(caption, (*propEntry)["min"]->NumberVal, (*propEntry)["max"]->NumberVal); + prop = new SliderProp(caption, entity->getEntityPropNumberByName(caption + "min"), entity->getEntityPropNumberByName(caption + "max")); dynamic_cast(prop)->set(entity->getEntityPropNumberByName(caption)); break; //case PropProp::PROP_BUTTON: @@ -2507,6 +2511,7 @@ void EntityPropSheet::refreshProps() { } prop->addEventListener(this, Event::CHANGE_EVENT); addProp(prop); + prop->Resize(getWidth(), prop->getHeight()); } } From 6e6f3105a252c1e4b13c298008b2723b4e63acc7 Mon Sep 17 00:00:00 2001 From: Joachim Meyer Date: Wed, 3 Sep 2014 23:35:05 +0200 Subject: [PATCH 07/19] Made prop names clearer, little rewrite of the plugin information saved in entity files. --- .../Include/PolySceneEntityInstance.h | 2 +- Core/Contents/Source/PolyEntity.cpp | 35 +++------------ .../Source/PolySceneEntityInstance.cpp | 45 ++++++++++++------- IDE/Contents/Include/PolycodeEntityEditor.h | 2 +- IDE/Contents/Source/PolycodeEntityEditor.cpp | 23 +++++----- IDE/Contents/Source/PolycodePluginEditor.cpp | 4 +- IDE/Contents/Source/PolycodeProps.cpp | 41 +++++++++-------- 7 files changed, 70 insertions(+), 82 deletions(-) diff --git a/Core/Contents/Include/PolySceneEntityInstance.h b/Core/Contents/Include/PolySceneEntityInstance.h index 48e56ab4a..b2ba26673 100644 --- a/Core/Contents/Include/PolySceneEntityInstance.h +++ b/Core/Contents/Include/PolySceneEntityInstance.h @@ -57,7 +57,7 @@ class SceneEntityInstance : public Entity { void clearInstance(); void parseObjectIntoCurve(ObjectEntry *entry, BezierCurve *curve); - std::vector parseObjectEntryIntoProps(ObjectEntry *propsEntry); + std::vector parseObjectEntryIntoProps(ObjectEntry *propsEntry, const String& pluginName); Entity *loadObjectEntryIntoEntity(ObjectEntry *entry, Entity *targetEntity = NULL, int entityFileVersion = 1); bool loadFromFile(const String& fileName); void applySceneMesh(ObjectEntry *entry, SceneMesh *sceneMesh); diff --git a/Core/Contents/Source/PolyEntity.cpp b/Core/Contents/Source/PolyEntity.cpp index eb30a6b95..c654b36a0 100755 --- a/Core/Contents/Source/PolyEntity.cpp +++ b/Core/Contents/Source/PolyEntity.cpp @@ -898,12 +898,7 @@ int Entity::getEntityPropIntByName(const String& propName) const { return entityProps[i]->intVal; } if (entityProps[i]->type == Prop::PROP_ARRAY) { - for (int j = 0; j < entityProps[i]->arrayVal.size(); j++) { - if (entityProps[i]->arrayVal[j]->name == propName && entityProps[i]->arrayVal[j]->type == Prop::PROP_INT) { - EntityProp* retVal = (EntityProp*)entityProps[i]->arrayVal[j]; - return retVal->intVal; - } - } + getEntityPropIntByName(propName); } } return false; @@ -915,12 +910,7 @@ Number Entity::getEntityPropNumberByName(const String& propName) const { return entityProps[i]->numberVal; } if (entityProps[i]->type == Prop::PROP_ARRAY) { - for (int j = 0; j < entityProps[i]->arrayVal.size(); j++) { - if (entityProps[i]->arrayVal[j]->name == propName && entityProps[i]->arrayVal[j]->type == Prop::PROP_NUMBER) { - EntityProp* retVal = (EntityProp*)entityProps[i]->arrayVal[j]; - return retVal->numberVal; - } - } + getEntityPropIntByName(propName); } } return Number(NULL); @@ -932,12 +922,7 @@ bool Entity::getEntityPropBoolByName(const String& propName) const { return entityProps[i]->boolVal; } if (entityProps[i]->type == Prop::PROP_ARRAY) { - for (int j = 0; j < entityProps[i]->arrayVal.size(); j++) { - if (entityProps[i]->arrayVal[j]->name == propName && entityProps[i]->arrayVal[j]->type == Prop::PROP_BOOL) { - EntityProp* retVal = (EntityProp*)entityProps[i]->arrayVal[j]; - return retVal->boolVal; - } - } + getEntityPropIntByName(propName); } } return -1; @@ -949,12 +934,7 @@ String Entity::getEntityPropStringByName(const String& propName) const { return entityProps[i]->stringVal; } if (entityProps[i]->type == Prop::PROP_ARRAY) { - for (int j = 0; j < entityProps[i]->arrayVal.size(); j++) { - if (entityProps[i]->arrayVal[j]->name == propName && entityProps[i]->arrayVal[j]->type == Prop::PROP_STRING) { - EntityProp* retVal = (EntityProp*)entityProps[i]->arrayVal[j]; - return retVal->stringVal; - } - } + getEntityPropIntByName(propName); } } return String("null"); @@ -966,12 +946,7 @@ std::vector Entity::getEntityPropArrayByName(const String& propName return entityProps[i]->arrayVal; } if (entityProps[i]->type == Prop::PROP_ARRAY) { - for (int j = 0; j < entityProps[i]->arrayVal.size(); j++) { - if (entityProps[i]->arrayVal[j]->name == propName && entityProps[i]->arrayVal[j]->type == Prop::PROP_ARRAY) { - EntityProp* retVal = (EntityProp*)entityProps[i]->arrayVal[j]; - return retVal->arrayVal; - } - } + getEntityPropIntByName(propName); } } std::vector retVector; diff --git a/Core/Contents/Source/PolySceneEntityInstance.cpp b/Core/Contents/Source/PolySceneEntityInstance.cpp index 10ed104a9..7239ab995 100644 --- a/Core/Contents/Source/PolySceneEntityInstance.cpp +++ b/Core/Contents/Source/PolySceneEntityInstance.cpp @@ -273,29 +273,29 @@ void SceneEntityInstance::parseObjectIntoCurve(ObjectEntry *entry, BezierCurve * } -std::vector SceneEntityInstance::parseObjectEntryIntoProps(ObjectEntry *propsEntry) { +std::vector SceneEntityInstance::parseObjectEntryIntoProps(ObjectEntry *propsEntry, const String& pluginName) { Entity *retEntity = new Entity(); for (int i = 0; i < propsEntry->children.size(); i++) { ObjectEntry *prop = ((*propsEntry))[i]; if (prop->name=="prop") { switch ((*prop)["type"]->intVal) { case Prop::PROP_STRING: - retEntity->setEntityProp((*prop)["name"]->stringVal, (*prop)["value"]->stringVal); + retEntity->setEntityProp(pluginName + (*prop)["name"]->stringVal, (*prop)["value"]->stringVal); break; case Prop::PROP_ARRAY: - retEntity->setEntityProp((*prop)["name"]->stringVal, parseObjectEntryIntoProps(prop)); + retEntity->setEntityProp(pluginName + (*prop)["name"]->stringVal, parseObjectEntryIntoProps(prop, pluginName)); break; case Prop::PROP_BOOL: - retEntity->setEntityProp((*prop)["name"]->stringVal, (*prop)["value"]->boolVal); + retEntity->setEntityProp(pluginName + (*prop)["name"]->stringVal, (*prop)["value"]->boolVal); break; case Prop::PROP_INT: - retEntity->setEntityProp((*prop)["name"]->stringVal, (*prop)["value"]->intVal); + retEntity->setEntityProp(pluginName + (*prop)["name"]->stringVal, (*prop)["value"]->intVal); break; case Prop::PROP_NUMBER: - retEntity->setEntityProp((*prop)["name"]->stringVal, (*prop)["value"]->NumberVal); + retEntity->setEntityProp(pluginName + (*prop)["name"]->stringVal, (*prop)["value"]->NumberVal); break; default: - retEntity->setEntityProp((*prop)["name"]->stringVal, (*prop)["value"]->stringVal); + retEntity->setEntityProp(pluginName + (*prop)["name"]->stringVal, (*prop)["value"]->stringVal); break; } } @@ -569,19 +569,32 @@ Entity *SceneEntityInstance::loadObjectEntryIntoEntity(ObjectEntry *entry, Entit } } } else { - ObjectEntry *plugins = (*entry)["requiredPlugins"]; - if (plugins) { + //ObjectEntry *plugins = (*entry)["requiredPlugins"]; + //if (plugins) { + // for (int p = 0; p < plugins->children.size(); p++) { + // if (plugins->children[p]->name == "requiredPlugin") { + // String requiredPlugin = (*plugins->children[p])["name"]->stringVal; + // entity->addPluginByName(requiredPlugin); + // } + // } + //} + ObjectEntry *plugins = (*entry)["plugins"]; + if (plugins){ for (int p = 0; p < plugins->children.size(); p++) { - if (plugins->children[p]->name == "requiredPlugin") { - String requiredPlugin = (*plugins->children[p])["name"]->stringVal; - entity->addPluginByName(requiredPlugin); + ObjectEntry *plugin = plugins->children[p]; + if (plugin){ + if (plugin->name == "plugin") { + String pluginName = (*plugin)["name"]->stringVal; + entity->addPluginByName(pluginName); + + ObjectEntry *props = (*plugin)["props"]; + if (props) { + entity->entityProps = parseObjectEntryIntoProps(props, pluginName); + } + } } } } - ObjectEntry *props = (*entry)["props"]; - if (props) { - entity->entityProps = parseObjectEntryIntoProps(props); - } } ObjectEntry *children = (*entry)["children"]; diff --git a/IDE/Contents/Include/PolycodeEntityEditor.h b/IDE/Contents/Include/PolycodeEntityEditor.h index ef0e5d5af..2bccc88e8 100644 --- a/IDE/Contents/Include/PolycodeEntityEditor.h +++ b/IDE/Contents/Include/PolycodeEntityEditor.h @@ -383,7 +383,7 @@ class PolycodeEntityEditor : public PolycodeEditor { void saveFile(); void saveCurveToObject(ObjectEntry *entry, BezierCurve *curve); void saveShaderOptionsToEntry(ObjectEntry *entry, Material *material, ShaderBinding *binding); - void savePropsToEntry(ObjectEntry *entry, std::vector props); + void savePropsToEntry(ObjectEntry *entry, std::vector props, const String& pluginName); void saveEntityToObjectEntry(Entity *entity, ObjectEntry *entry); void doAction(String actionName, PolycodeEditorActionData *data); diff --git a/IDE/Contents/Source/PolycodeEntityEditor.cpp b/IDE/Contents/Source/PolycodeEntityEditor.cpp index 76a980c49..f25238c89 100644 --- a/IDE/Contents/Source/PolycodeEntityEditor.cpp +++ b/IDE/Contents/Source/PolycodeEntityEditor.cpp @@ -2140,18 +2140,17 @@ void PolycodeEntityEditor::saveEntityToObjectEntry(Entity *entity, ObjectEntry * entry->addChild("tags", tagString); if (entity->requiredPlugins.size() > 0) { - ObjectEntry *reqPluginsEntry = entry->addChild("requiredPlugins"); + ObjectEntry *pluginsEntry = entry->addChild("plugins"); for (int p = 0; p < entity->requiredPlugins.size(); p++) { - ObjectEntry* requiredPlugin = reqPluginsEntry->addChild("requiredPlugin"); - requiredPlugin->addChild("name", entity->requiredPlugins[p]->getResourceName()); + ObjectEntry* plugin = pluginsEntry->addChild("plugin"); + plugin->addChild("name", entity->requiredPlugins[p]->getResourceName()); + if (entity->entityProps.size() > 0) { + ObjectEntry *props = plugin->addChild("props"); + savePropsToEntry(props, entity->entityProps, entity->requiredPlugins[p]->getResourceName()); + } } } - - if(entity->entityProps.size() > 0) { - ObjectEntry *props = entry->addChild("props"); - savePropsToEntry(props, entity->entityProps); - } - + if(dynamic_cast(entity) && entity != mainView->getObjectRoot()) { if(!(*(entry))["type"]) { entry->addChild("type", "SceneEntityInstance"); @@ -2520,17 +2519,17 @@ void PolycodeEntityEditor::Resize(int x, int y) { PolycodeEditor::Resize(x,y); } -void PolycodeEntityEditor::savePropsToEntry(ObjectEntry *entry, std::vector props) { +void PolycodeEntityEditor::savePropsToEntry(ObjectEntry *entry, std::vector props, const String& pluginName) { for (int i = 0; i < props.size(); i++) { ObjectEntry *prop = entry->addChild("prop"); - prop->addChild("name", props[i]->name); + prop->addChild("name", props[i]->name.replace(pluginName, "")); prop->addChild("type", props[i]->type); switch (props[i]->type) { case Prop::PROP_STRING: prop->addChild("value", props[i]->stringVal); break; case Prop::PROP_ARRAY: - savePropsToEntry(prop, props[i]->arrayVal); + savePropsToEntry(prop, props[i]->arrayVal, pluginName); break; case Prop::PROP_BOOL: prop->addChild("value", props[i]->boolVal); diff --git a/IDE/Contents/Source/PolycodePluginEditor.cpp b/IDE/Contents/Source/PolycodePluginEditor.cpp index dbff6d659..fc0f68fea 100644 --- a/IDE/Contents/Source/PolycodePluginEditor.cpp +++ b/IDE/Contents/Source/PolycodePluginEditor.cpp @@ -122,9 +122,7 @@ PluginEditorPane::PluginEditorPane(ResourcePool *resourcePool) : UIElement() { enabled = false; } -PluginEditorPane::~PluginEditorPane() { - -} +PluginEditorPane::~PluginEditorPane() {} void PluginEditorPane::handleEvent(Event *event) { if (!changingPlugin) { diff --git a/IDE/Contents/Source/PolycodeProps.cpp b/IDE/Contents/Source/PolycodeProps.cpp index 85b199f6c..ece251e42 100644 --- a/IDE/Contents/Source/PolycodeProps.cpp +++ b/IDE/Contents/Source/PolycodeProps.cpp @@ -2409,32 +2409,35 @@ void EntityPropSheet::refreshProps() { ObjectEntry* propsEntry = (*dynamic_cast(Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_PLUGIN, plugin))->sheetEntry)["props"]; if (propsEntry) { PropProp* prop; + for (int i = 0; i < propsEntry->children.size(); i++) { ObjectEntry* propEntry = propsEntry->children[i]; + String caption = (*propEntry)["name"]->stringVal; + switch ((*propEntry)["type"]->intVal) { case PropProp::PROP_VECTOR3: prop = new Vector3Prop(caption); - dynamic_cast(prop)->set(Vector3(entity->getEntityPropNumberByName(caption + "x"), entity->getEntityPropNumberByName(caption + "y"), entity->getEntityPropNumberByName(caption + "z"))); + dynamic_cast(prop)->set(Vector3(entity->getEntityPropNumberByName(plugin + caption + "x"), entity->getEntityPropNumberByName(plugin + caption + "y"), entity->getEntityPropNumberByName(plugin + caption + "z"))); break; case PropProp::PROP_VECTOR2: prop = new Vector2Prop(caption); - dynamic_cast(prop)->set(Vector2(entity->getEntityPropNumberByName(caption + "x"), entity->getEntityPropNumberByName(caption + "y"))); + dynamic_cast(prop)->set(Vector2(entity->getEntityPropNumberByName(plugin + caption + "x"), entity->getEntityPropNumberByName(plugin + caption + "y"))); break; case PropProp::PROP_SLIDER: - prop = new SliderProp(caption, entity->getEntityPropNumberByName(caption + "min"), entity->getEntityPropNumberByName(caption + "max")); - dynamic_cast(prop)->set(entity->getEntityPropNumberByName(caption)); + prop = new SliderProp(caption, entity->getEntityPropNumberByName(plugin + caption + "min"), entity->getEntityPropNumberByName(plugin + caption + "max")); + dynamic_cast(prop)->set(entity->getEntityPropNumberByName(plugin + caption)); break; //case PropProp::PROP_BUTTON: // prop = new ButtonProp(caption); // break; case PropProp::PROP_NUMBER: prop = new NumberProp(caption); - prop->setPropData(PropDataNumber(entity->getEntityPropNumberByName(caption))); + prop->setPropData(PropDataNumber(entity->getEntityPropNumberByName(plugin + caption))); break; //case PropProp::PROP_TARGET_BINDING: - // Shader *shader = ((Shader*)Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_SHADER, entity->getEntityPropStringByName(caption))); - // Material *material = ((Material*)Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_MATERIAL, entity->getEntityPropStringByName(caption))); + // Shader *shader = ((Shader*)Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_SHADER, entity->getEntityPropStringByName(plugin + caption))); + // Material *material = ((Material*)Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_MATERIAL, entity->getEntityPropStringByName(plugin + caption))); // ShaderBinding *shaderBin = new ShaderBinding(shader); // RenderTargetBinding *targetBin = new RenderTargetBinding(); // @@ -2451,7 +2454,7 @@ void EntityPropSheet::refreshProps() { // break; case PropProp::PROP_REMOVABLE_STRING: prop = new RemovableStringProp(caption); - prop->setPropData(PropDataString(entity->getEntityPropStringByName(caption))); + prop->setPropData(PropDataString(entity->getEntityPropStringByName(plugin + caption))); break; //case PropProp::PROP_LAYER: // SceneEntityInstance *instance = new SceneEntityInstance(); @@ -2459,30 +2462,30 @@ void EntityPropSheet::refreshProps() { // break; case PropProp::PROP_STRING: prop = new StringProp(caption); - ((StringProp*)prop)->set(entity->getEntityPropStringByName(caption)); + ((StringProp*)prop)->set(entity->getEntityPropStringByName(plugin + caption)); break; case PropProp::PROP_COLOR: prop = new ColorProp(caption); - ((ColorProp*)prop)->set(new Color(entity->getEntityPropNumberByName(caption + "r"), entity->getEntityPropNumberByName(caption + "g"), entity->getEntityPropNumberByName(caption + "b"), entity->getEntityPropNumberByName(caption + "a"))); + ((ColorProp*)prop)->set(new Color(entity->getEntityPropNumberByName(plugin + caption + "r"), entity->getEntityPropNumberByName(plugin + caption + "g"), entity->getEntityPropNumberByName(plugin + caption + "b"), entity->getEntityPropNumberByName(plugin + caption + "a"))); break; case PropProp::PROP_COMBO: prop = new ComboProp(caption); for (int c = 0; c < (*propsEntry)[caption]->children.size(); c++) { - ((ComboProp*)prop)->comboEntry->addComboItem(caption + String::NumberToString(c, 0), &(*propsEntry)[caption][c]["type"]->intVal); + ((ComboProp*)prop)->comboEntry->addComboItem(plugin + caption + String::NumberToString(c, 0), &(*propsEntry)[plugin + caption][c]["type"]->intVal); } break; case PropProp::PROP_BOOL: prop = new BoolProp(caption); - ((BoolProp*)prop)->set(entity->getEntityPropBoolByName(caption)); + ((BoolProp*)prop)->set(entity->getEntityPropBoolByName(plugin + caption)); break; case PropProp::PROP_SOUND: prop = new SoundProp(caption); - ((SoundProp*)prop)->set(entity->getEntityPropStringByName(caption)); + ((SoundProp*)prop)->set(entity->getEntityPropStringByName(plugin + caption)); break; //case PropProp::PROP_BEZIER_RGBA_CURVE: // prop = new BezierRGBACurveProp(caption); - // for (int c = 0; c < entity->getEntityPropArrayByName(caption + "r").size(); c++) { - // ((BezierRGBACurveProp*)prop)->curveR->addControlPoint2d(entity->getEntityPropArrayByName(caption + "r")[c]); + // for (int c = 0; c < entity->getEntityPropArrayByName(plugin + caption + "r").size(); c++) { + // ((BezierRGBACurveProp*)prop)->curveR->addControlPoint2d(entity->getEntityPropArrayByName(plugin + caption + "r")[c]); // } // break; //case PropProp::PROP_BEZIER_CURVE: @@ -2490,19 +2493,19 @@ void EntityPropSheet::refreshProps() { //break; case PropProp::PROP_MATERIAL: prop = new MaterialProp(caption); - ((MaterialProp*)prop)->set(new Material(entity->getEntityPropStringByName(caption))); + ((MaterialProp*)prop)->set(new Material(entity->getEntityPropStringByName(plugin + caption))); break; case PropProp::PROP_TEXTURE: prop = new TextureProp(caption); - ((TextureProp*)prop)->set(((Texture*)Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_TEXTURE, entity->getEntityPropStringByName(caption)))); + ((TextureProp*)prop)->set(((Texture*)Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_TEXTURE, entity->getEntityPropStringByName(plugin + caption)))); break; case PropProp::PROP_SCENE_SPRITE: prop = new SceneSpriteProp(caption); - ((SceneSpriteProp*)prop)->set(((Sprite*)Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_SPRITE, entity->getEntityPropStringByName(caption)))); + ((SceneSpriteProp*)prop)->set(((Sprite*)Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_SPRITE, entity->getEntityPropStringByName(plugin + caption)))); break; case PropProp::PROP_SCENE_ENTITY_INSTANCE: prop = new SceneEntityInstanceProp(caption); - ((SceneEntityInstanceProp*)prop)->set(entity->getEntityPropStringByName(caption)); + ((SceneEntityInstanceProp*)prop)->set(entity->getEntityPropStringByName(plugin + caption)); break; case PropProp::PROP_CUSTOM: default: From 9927988813e42f86135d919eb45c05139bdeae21 Mon Sep 17 00:00:00 2001 From: Joachim Meyer Date: Fri, 5 Sep 2014 23:53:58 +0200 Subject: [PATCH 08/19] Implemented ComboProps, added removeItem funtions to UIComboBox. EntityProp names are now as specific as possible. --- .../Include/PolySceneEntityInstance.h | 2 +- .../Source/PolySceneEntityInstance.cpp | 14 +- IDE/Contents/Include/PolycodeProps.h | 24 ++ IDE/Contents/Source/PolycodePluginEditor.cpp | 46 +++- IDE/Contents/Source/PolycodeProps.cpp | 240 ++++++++++++++---- Modules/Contents/UI/Include/PolyUIComboBox.h | 3 + Modules/Contents/UI/Source/PolyUIComboBox.cpp | 16 ++ 7 files changed, 284 insertions(+), 61 deletions(-) diff --git a/Core/Contents/Include/PolySceneEntityInstance.h b/Core/Contents/Include/PolySceneEntityInstance.h index b2ba26673..4e3423166 100644 --- a/Core/Contents/Include/PolySceneEntityInstance.h +++ b/Core/Contents/Include/PolySceneEntityInstance.h @@ -57,7 +57,7 @@ class SceneEntityInstance : public Entity { void clearInstance(); void parseObjectIntoCurve(ObjectEntry *entry, BezierCurve *curve); - std::vector parseObjectEntryIntoProps(ObjectEntry *propsEntry, const String& pluginName); + std::vector parseObjectEntryIntoProps(ObjectEntry *propsEntry, const String& baseName); Entity *loadObjectEntryIntoEntity(ObjectEntry *entry, Entity *targetEntity = NULL, int entityFileVersion = 1); bool loadFromFile(const String& fileName); void applySceneMesh(ObjectEntry *entry, SceneMesh *sceneMesh); diff --git a/Core/Contents/Source/PolySceneEntityInstance.cpp b/Core/Contents/Source/PolySceneEntityInstance.cpp index 7239ab995..facf4b995 100644 --- a/Core/Contents/Source/PolySceneEntityInstance.cpp +++ b/Core/Contents/Source/PolySceneEntityInstance.cpp @@ -273,29 +273,29 @@ void SceneEntityInstance::parseObjectIntoCurve(ObjectEntry *entry, BezierCurve * } -std::vector SceneEntityInstance::parseObjectEntryIntoProps(ObjectEntry *propsEntry, const String& pluginName) { +std::vector SceneEntityInstance::parseObjectEntryIntoProps(ObjectEntry *propsEntry, const String& baseName) { Entity *retEntity = new Entity(); for (int i = 0; i < propsEntry->children.size(); i++) { ObjectEntry *prop = ((*propsEntry))[i]; if (prop->name=="prop") { switch ((*prop)["type"]->intVal) { case Prop::PROP_STRING: - retEntity->setEntityProp(pluginName + (*prop)["name"]->stringVal, (*prop)["value"]->stringVal); + retEntity->setEntityProp(baseName + (*prop)["name"]->stringVal, (*prop)["value"]->stringVal); break; case Prop::PROP_ARRAY: - retEntity->setEntityProp(pluginName + (*prop)["name"]->stringVal, parseObjectEntryIntoProps(prop, pluginName)); + retEntity->setEntityProp(baseName + (*prop)["name"]->stringVal, parseObjectEntryIntoProps(prop, baseName + (*prop)["name"]->stringVal)); break; case Prop::PROP_BOOL: - retEntity->setEntityProp(pluginName + (*prop)["name"]->stringVal, (*prop)["value"]->boolVal); + retEntity->setEntityProp(baseName + (*prop)["name"]->stringVal, (*prop)["value"]->boolVal); break; case Prop::PROP_INT: - retEntity->setEntityProp(pluginName + (*prop)["name"]->stringVal, (*prop)["value"]->intVal); + retEntity->setEntityProp(baseName + (*prop)["name"]->stringVal, (*prop)["value"]->intVal); break; case Prop::PROP_NUMBER: - retEntity->setEntityProp(pluginName + (*prop)["name"]->stringVal, (*prop)["value"]->NumberVal); + retEntity->setEntityProp(baseName + (*prop)["name"]->stringVal, (*prop)["value"]->NumberVal); break; default: - retEntity->setEntityProp(pluginName + (*prop)["name"]->stringVal, (*prop)["value"]->stringVal); + retEntity->setEntityProp(baseName + (*prop)["name"]->stringVal, (*prop)["value"]->stringVal); break; } } diff --git a/IDE/Contents/Include/PolycodeProps.h b/IDE/Contents/Include/PolycodeProps.h index 25a15289e..ee00c9c1f 100644 --- a/IDE/Contents/Include/PolycodeProps.h +++ b/IDE/Contents/Include/PolycodeProps.h @@ -76,6 +76,7 @@ class PropProp : public UIElement { static const int PROP_SCENE_SPRITE = 21; static const int PROP_SCENE_ENTITY_INSTANCE = 22; static const int PROP_EDIT = 23; + static const int PROP_COMBO_EDIT = 24; }; class Vector3Prop : public PropProp { @@ -494,6 +495,28 @@ class SceneEntityInstanceProp : public PropProp { }; +class ComboPropEditProp : public PropProp { +public: + ComboPropEditProp(ComboProp* newCombo); + ~ComboPropEditProp(); + void handleEvent(Event *event); + + void set(ComboProp *newCombo); + ComboProp *get(); + + void layoutProps(); + + UILabel *nameLabel; + UIButton *addItemButton; + UITextInput *newItemName; + + std::vector items; + std::vector datas; + + ComboProp *lastCombo; + ComboProp *currentCombo; +}; + class PropEditProp : public PropProp { public: PropEditProp(PropProp* newProp); @@ -508,6 +531,7 @@ class PropEditProp : public PropProp { int getPropType(); PropProp *currentProp; + ComboPropEditProp *comboEditProp; UITextInput *nameInput; UIComboBox *typeChooser; diff --git a/IDE/Contents/Source/PolycodePluginEditor.cpp b/IDE/Contents/Source/PolycodePluginEditor.cpp index fc0f68fea..b4323881e 100644 --- a/IDE/Contents/Source/PolycodePluginEditor.cpp +++ b/IDE/Contents/Source/PolycodePluginEditor.cpp @@ -135,6 +135,10 @@ void PluginEditorPane::handleEvent(Event *event) { int maxPadding = 0; for (int p = 0; p < propsSheet->props.size(); p++){ if (event->getDispatcher() == propsSheet->props[p]) { + if (((int)((PropEditProp*)propsSheet->props[p])->typeChooser->getSelectedItem()->data) == PropProp::PROP_COMBO){ + + } + dispatchEvent(new Event(), Event::CHANGE_EVENT); } if (((PropEditProp*)propsSheet->props[p])->updatePadding() > maxPadding){ @@ -142,11 +146,11 @@ void PluginEditorPane::handleEvent(Event *event) { } } - padding = maxPadding; + padding = maxPadding + 20; - if (padding < (propList->getWidth() - 320)){ + if (padding < (propList->getWidth() - 370)){ for (int p = 0; p < propsSheet->props.size(); p++){ - propsSheet->props[p]->propContents->setPositionX(padding + 20); + propsSheet->props[p]->propContents->setPositionX(padding); } } @@ -154,9 +158,13 @@ void PluginEditorPane::handleEvent(Event *event) { PropEditProp *newProp = new PropEditProp(new PropProp("", 0)); propsSheet->addProp(newProp); newProp->addEventListener(this, Event::CHANGE_EVENT); - newProp->propContents->setPositionX(padding + 20); + newProp->propContents->setPositionX(padding); dispatchEvent(new Event(), Event::CHANGE_EVENT); } + + if (event->getEventCode() == Event::CHANGE_EVENT){ + propList->Resize(propList->getWidth(), propList->getHeight()); + } } } @@ -172,13 +180,24 @@ void PluginEditorPane::setPlugin(Plugin *plugin) { for (int p = 0; p < propsEntry->children.size(); p++) { ObjectEntry* propEntry = (*propsEntry)[p]; if (propEntry && propEntry->name == "prop") { - setProp((*propEntry)["name"]->stringVal, new PropProp((*propEntry)["name"]->stringVal, (*propEntry)["type"]->intVal)); + if ((*propEntry)["type"]->intVal != PropProp::PROP_COMBO){ + setProp((*propEntry)["name"]->stringVal, new PropProp((*propEntry)["name"]->stringVal, (*propEntry)["type"]->intVal)); + } else { + ComboProp *newComboProp = new ComboProp((*propEntry)["name"]->stringVal); + for (int c = 0; c < propEntry->children.size(); c++){ + ObjectEntry *comboEntry = propEntry->children[c]; + if (comboEntry && comboEntry->name == "prop"){ + newComboProp->comboEntry->addComboItem((*comboEntry)["name"]->stringVal, ((void*)(*comboEntry)["value"]->intVal)); + } + } + setProp(newComboProp->getPropName(), newComboProp); + } } } } for (int p = 0; p < propsSheet->props.size(); p++){ - propsSheet->props[p]->propContents->setPositionX(padding + 20); + propsSheet->props[p]->propContents->setPositionX(padding); } enabled = true; @@ -201,16 +220,16 @@ void PluginEditorPane::setProp(const String& name, PropProp* prop){ for (int i = 0; i < propsSheet->props.size(); i++) { if (propsSheet->props[i]->getPropName() == name) { PropEditProp *newProp = new PropEditProp(prop); - if (((PropEditProp*)newProp)->updatePadding() > padding) - padding = ((PropEditProp*)newProp)->updatePadding(); + if (((PropEditProp*)newProp)->updatePadding() > (padding - 20)) + padding = ((PropEditProp*)newProp)->updatePadding() + 20; newProp->addEventListener(this, Event::CHANGE_EVENT); return; } } PropEditProp *newProp = new PropEditProp(prop); - if (((PropEditProp*)newProp)->updatePadding() > padding) - padding = ((PropEditProp*)newProp)->updatePadding(); + if (((PropEditProp*)newProp)->updatePadding() > (padding - 20)) + padding = ((PropEditProp*)newProp)->updatePadding() + 20; propsSheet->addProp(newProp); newProp->addEventListener(this, Event::CHANGE_EVENT); } @@ -316,6 +335,13 @@ void PolycodePluginEditor::savePluginToObjectEntry(Plugin* plugin, ObjectEntry* ObjectEntry* propEntry = propsEntry->addChild("prop"); propEntry->addChild("type", ((PropEditProp*)props[i])->getPropType()); propEntry->addChild("name", props[i]->getPropName()); + if (((PropEditProp*)props[i])->getPropType() == PropProp::PROP_COMBO){ + for (int c = 0; c < ((PropEditProp*)props[i])->comboEditProp->items.size(); c++){ + ObjectEntry *comboEntry = propEntry->addChild("prop"); + comboEntry->addChild("name", ((PropEditProp*)props[i])->comboEditProp->get()->comboEntry->getItemAtIndex(c)->label); + comboEntry->addChild("value", ((int)((PropEditProp*)props[i])->comboEditProp->get()->comboEntry->getItemAtIndex(c)->data)); + } + } } } diff --git a/IDE/Contents/Source/PolycodeProps.cpp b/IDE/Contents/Source/PolycodeProps.cpp index ece251e42..bf2780b5b 100644 --- a/IDE/Contents/Source/PolycodeProps.cpp +++ b/IDE/Contents/Source/PolycodeProps.cpp @@ -23,6 +23,7 @@ #include "PolycodeProps.h" #include "PolycodeFrame.h" #include "PolyCubemap.h" +#include "PolyUIComboBox.h" extern UIColorPicker *globalColorPicker; extern PolycodeFrame *globalFrame; @@ -1900,7 +1901,7 @@ PropEditProp::PropEditProp(PropProp *newProp) : PropProp(newProp->getPropName(), typeChooser->addComboItem("Custom", (void*)10); typeChooser->addComboItem("String", (void*)11); typeChooser->addComboItem("Color", (void*)12); - typeChooser->addComboItem("Combo (ni)", (void*)13); + typeChooser->addComboItem("Combo", (void*)13); typeChooser->addComboItem("Bool", (void*)14); typeChooser->addComboItem("Sound", (void*)15); typeChooser->addComboItem("Bezier RGBA Curve (ni)", (void*)16); @@ -1917,7 +1918,18 @@ PropEditProp::PropEditProp(PropProp *newProp) : PropProp(newProp->getPropName(), currentValue = newProp->propType; - setHeight(65); + if (currentValue != PropProp::PROP_COMBO){ + comboEditProp = new ComboPropEditProp(new ComboProp(nameInput->getText())); + comboEditProp->enabled = false; + comboEditProp->visible = false; + setHeight(65); + } else { + comboEditProp = new ComboPropEditProp(((ComboProp*)newProp)); + setHeight(65 + comboEditProp->getHeight()); + } + comboEditProp->addEventListener(this, Event::CHANGE_EVENT); + propContents->addChild(comboEditProp); + comboEditProp->setPosition(-80, 60); } PropEditProp::~PropEditProp(){} @@ -1931,6 +1943,15 @@ void PropEditProp::handleEvent(Event *event){ dispatchEvent(new Event(), Event::CHANGE_EVENT); dispatchEvent(new PropEvent(this, NULL, PropDataInt(lastValue), PropDataInt(currentValue)), PropEvent::EVENT_PROP_CHANGE); } + if (currentValue == PropProp::PROP_COMBO){ + comboEditProp->setPropName(nameInput->getText()); + comboEditProp->set(comboEditProp->currentCombo); + comboEditProp->enabled = true; + comboEditProp->visible = true; + } else if (lastValue == PropProp::PROP_COMBO && currentValue != PropProp::PROP_COMBO){ + comboEditProp->enabled = false; + comboEditProp->visible = false; + } } } if (event->getDispatcher() == nameInput) { @@ -1944,10 +1965,25 @@ void PropEditProp::handleEvent(Event *event){ } } } + if (event->getDispatcher() == comboEditProp){ + if (event->getEventCode() == Event::CHANGE_EVENT) { + setHeight(80 + comboEditProp->getHeight()); + if (!suppressChangeEvent) { + dispatchEvent(new Event(), Event::CHANGE_EVENT); + } + } + } } void PropEditProp::set(PropProp *newProp){ currentProp = newProp; + nameInput->setText(newProp->getPropName()); + typeChooser->setSelectedIndex(newProp->propType); + if (newProp->propType != PropProp::PROP_COMBO){ + comboEditProp->set(new ComboProp(nameInput->getText())); + } else { + comboEditProp->set(((ComboProp*)newProp)); + } } PropProp *PropEditProp::get(){ @@ -1962,6 +1998,127 @@ int PropEditProp::getPropType(){ return currentValue; } +ComboPropEditProp::ComboPropEditProp(ComboProp* newCombo) : PropProp("", PropProp::PROP_COMBO_EDIT){ + nameLabel = new UILabel("New Item:", 11); + nameLabel->color.a = 1.0; + propContents->addChild(nameLabel); + nameLabel->setPosition(0, 5); + + newItemName = new UITextInput(false, 130, 12); + newItemName->addEventListener(this, UIEvent::CHANGE_EVENT); + newItemName->setText(newCombo->getPropName()); + propContents->addChild(newItemName); + newItemName->setPosition(70, 0); + + addItemButton = new UIButton("Add Item", 80); + addItemButton->addEventListener(this, UIEvent::CLICK_EVENT); + propContents->addChild(addItemButton); + addItemButton->setPosition(220, 0); + + currentCombo = newCombo; + + for (int c = 0; c < currentCombo->comboEntry->getNumItems(); c++){ + RemovableStringProp *newProp = new RemovableStringProp(currentCombo->comboEntry->getItemAtIndex(c)->label); + newProp->addEventListener(this, Event::REMOVE_EVENT); + propContents->addChild(newProp); + items.push_back(newProp); + + StringProp *newDataProp = new StringProp("Data:"); + newDataProp->set(((int)currentCombo->comboEntry->getItemAtIndex(c)->data)); + newDataProp->stringEntry->setPosition(-70, 0); + newDataProp->stringEntry->Resize(40, newDataProp->stringEntry->getHeight()); + newDataProp->stringEntry->setNumberOnly(true); + newDataProp->addEventListener(this, Event::CHANGE_EVENT); + propContents->addChild(newDataProp); + datas.push_back(newDataProp); + } + + layoutProps(); + setWidth(370); +} + +ComboPropEditProp::~ComboPropEditProp(){} + +void ComboPropEditProp::handleEvent(Event *event){ + if (event->getDispatcher() == addItemButton) { + RemovableStringProp *newProp = new RemovableStringProp(newItemName->getText()); + newProp->addEventListener(this, Event::REMOVE_EVENT); + propContents->addChild(newProp); + items.push_back(newProp); + currentCombo->comboEntry->addComboItem(newItemName->getText()); + + StringProp *newDataProp = new StringProp("Data:"); + newDataProp->stringEntry->setPosition(-70, 0); + newDataProp->stringEntry->Resize(40, newDataProp->stringEntry->getHeight()); + newDataProp->stringEntry->setNumberOnly(true); + newDataProp->addEventListener(this, Event::CHANGE_EVENT); + propContents->addChild(newDataProp); + datas.push_back(newDataProp); + + layoutProps(); + newItemName->setText(""); + dispatchEvent(new Event(), Event::CHANGE_EVENT); + } + for (int i = 0; i < items.size(); i++) { + if (items[i] == event->getDispatcher()) { + //items[i]->enabled = false; + //items[i]->visible = false; + propContents->removeChild(items[i]); + items[i]->removeAllHandlersForListener(this); + + propContents->removeChild(datas[i]); + datas[i]->removeAllHandlersForListener(this); + + currentCombo->comboEntry->removeComboItemAtIndex(i); + items.erase(items.begin() + i); + datas.erase(datas.begin() + i); + layoutProps(); + dispatchEvent(new Event(), Event::CHANGE_EVENT); + } + } +} + +void ComboPropEditProp::layoutProps(){ + for (int i = 0; i < items.size(); i++){ + items[i]->setPosition(75, 30 + i * 20); + datas[i]->setPosition(0, 30 + i * 20); + } + setHeight(30 + items.size() * 20); +} + +void ComboPropEditProp::set(ComboProp *newCombo){ + for (int c = 0; c < currentCombo->comboEntry->getNumItems(); c++){ + delete items[c]; + } + items.clear(); + + + lastCombo = currentCombo; + currentCombo = newCombo; + + for (int c = 0; c < newCombo->comboEntry->getNumItems(); c++){ + RemovableStringProp *newProp = new RemovableStringProp(newCombo->comboEntry->getItemAtIndex(c)->label); + newProp->addEventListener(this, Event::REMOVE_EVENT); + propContents->addChild(newProp); + items.push_back(newProp); + + StringProp *newDataProp = new StringProp("Data:"); + newDataProp->set(((int)currentCombo->comboEntry->getItemAtIndex(c)->data)); + newDataProp->stringEntry->setPosition(-70, 0); + newDataProp->stringEntry->Resize(40, newDataProp->stringEntry->getHeight()); + newDataProp->stringEntry->setNumberOnly(true); + newDataProp->addEventListener(this, Event::CHANGE_EVENT); + propContents->addChild(newDataProp); + datas.push_back(newDataProp); + } + + layoutProps(); +} + +ComboProp *ComboPropEditProp::get(){ + return currentCombo; +} + ShaderPassesSheet::ShaderPassesSheet(ResourcePool *resourcePool) : PropSheet("SHADER PASSES", "shaderPasses") { this->resourcePool = resourcePool; propHeight = 70; @@ -2278,32 +2435,32 @@ void EntityPropSheet::handleEvent(Event *event) { switch (props[i]->propType) { case PropProp::PROP_VECTOR3: - prop = new EntityProp(props[i]->getPropName() + "x", Prop::PROP_NUMBER); + prop = new EntityProp(plugin + props[i]->getPropName() + "x", Prop::PROP_NUMBER); prop->numberVal = ((Vector3Prop*)props[i])->get().x; propsVector.push_back(prop); - prop = new EntityProp(props[i]->getPropName() + "y", Prop::PROP_NUMBER); + prop = new EntityProp(plugin + props[i]->getPropName() + "y", Prop::PROP_NUMBER); prop->numberVal = ((Vector3Prop*)props[i])->get().y; propsVector.push_back(prop); - prop = new EntityProp(props[i]->getPropName() + "z", Prop::PROP_NUMBER); + prop = new EntityProp(plugin + props[i]->getPropName() + "z", Prop::PROP_NUMBER); prop->numberVal = ((Vector3Prop*)props[i])->get().z; propsVector.push_back(prop); - entity->setEntityProp(props[i]->getPropName(), propsVector); + entity->setEntityProp(plugin + props[i]->getPropName(), propsVector); break; case PropProp::PROP_VECTOR2: - prop = new EntityProp(props[i]->getPropName() + "x", Prop::PROP_NUMBER); + prop = new EntityProp(plugin + props[i]->getPropName() + "x", Prop::PROP_NUMBER); propsVector.push_back(prop); - prop = new EntityProp(props[i]->getPropName() + "y", Prop::PROP_NUMBER); + prop = new EntityProp(plugin + props[i]->getPropName() + "y", Prop::PROP_NUMBER); propsVector.push_back(prop); - entity->setEntityProp(props[i]->getPropName(), propsVector); + entity->setEntityProp(plugin + props[i]->getPropName(), propsVector); break; case PropProp::PROP_SLIDER: - entity->setEntityProp(props[i]->getPropName(), ((SliderProp*)props[i])->get()); + entity->setEntityProp(plugin + props[i]->getPropName(), ((SliderProp*)props[i])->get()); break; //case PropProp::PROP_BUTTON: // prop = new ButtonProp(caption); // break; case PropProp::PROP_NUMBER: - entity->setEntityProp(props[i]->getPropName(), ((NumberProp*)props[i])->get()); + entity->setEntityProp(plugin + props[i]->getPropName(), ((NumberProp*)props[i])->get()); break; //case PropProp::PROP_TARGET_BINDING: // @@ -2313,59 +2470,47 @@ void EntityPropSheet::handleEvent(Event *event) { //case PropProp::PROP_SHADER_PASS: // break; case PropProp::PROP_REMOVABLE_STRING: - entity->setEntityProp(props[i]->getPropName(), ((RemovableStringProp*)props[i])->getCaption()); + entity->setEntityProp(plugin + props[i]->getPropName(), ((RemovableStringProp*)props[i])->getCaption()); break; //case PropProp::PROP_LAYER: // break; case PropProp::PROP_STRING: - entity->setEntityProp(((StringProp*)props[i])->getPropName(), ((StringProp*)props[i])->get()); + entity->setEntityProp(plugin + props[i]->getPropName(), ((StringProp*)props[i])->get()); break; case PropProp::PROP_COLOR: - entity->setEntityProp(props[i]->getPropName() + "R", ((ColorProp*)props[i])->get().r); - entity->setEntityProp(props[i]->getPropName() + "G", ((ColorProp*)props[i])->get().g); - entity->setEntityProp(props[i]->getPropName() + "B", ((ColorProp*)props[i])->get().b); - entity->setEntityProp(props[i]->getPropName() + "A", ((ColorProp*)props[i])->get().a); + entity->setEntityProp(plugin + props[i]->getPropName() + "R", ((ColorProp*)props[i])->get().r); + entity->setEntityProp(plugin + props[i]->getPropName() + "G", ((ColorProp*)props[i])->get().g); + entity->setEntityProp(plugin + props[i]->getPropName() + "B", ((ColorProp*)props[i])->get().b); + entity->setEntityProp(plugin + props[i]->getPropName() + "A", ((ColorProp*)props[i])->get().a); + break; + case PropProp::PROP_COMBO: + entity->setEntityProp(plugin + props[i]->getPropName(), ((int)((ComboProp*)props[i])->comboEntry->getSelectedItem()->data)); break; - //case PropProp::PROP_COMBO: - // //entity->setEntityProp(props[i]->getPropName() + String::NumberToString(c, 0), ((ComboProp*)props[i])->comboEntry->getItemAtIndex(c)->label); - // switch (((ComboProp*)props[i])->comboEntry->getSelectedItem()->data[0]) { - // case Prop::PROP_ARRAY: - // entity->setEntityProp(caption, entity->getEntityPropArrayByName(((ComboProp*)props[i])->comboEntry->getSelectedItem()->label)); - // case Prop::PROP_BOOL: - // entity->setEntityProp(caption, entity->getEntityPropBoolByName(((ComboProp*)props[i])->comboEntry->getSelectedItem()->label)); - // case Prop::PROP_INT: - // entity->setEntityProp(caption, entity->getEntityPropIntByName(((ComboProp*)props[i])->comboEntry->getSelectedItem()->label)); - // case Prop::PROP_NUMBER: - // entity->setEntityProp(caption, entity->getEntityPropNumberByName(((ComboProp*)props[i])->comboEntry->getSelectedItem()->label)); - // case Prop::PROP_STRING: - // entity->setEntityProp(caption, entity->getEntityPropStringByName(((ComboProp*)props[i])->comboEntry->getSelectedItem()->label)); - // } - // break; case PropProp::PROP_BOOL: - entity->setEntityProp(props[i]->getPropName(), ((BoolProp*)props[i])->get()); + entity->setEntityProp(plugin + props[i]->getPropName(), ((BoolProp*)props[i])->get()); break; case PropProp::PROP_SOUND: - entity->setEntityProp(props[i]->getPropName(), ((SoundProp*)props[i])->get()); + entity->setEntityProp(plugin + props[i]->getPropName(), ((SoundProp*)props[i])->get()); break; //case PropProp::PROP_BEZIER_RGBA_CURVE: // break; //case PropProp::PROP_BEZIER_CURVE: // break; case PropProp::PROP_MATERIAL: - entity->setEntityProp(props[i]->getPropName(), ((MaterialProp*)props[i])->get()->getName()); + entity->setEntityProp(plugin + props[i]->getPropName(), ((MaterialProp*)props[i])->get()->getName()); break; case PropProp::PROP_TEXTURE: - entity->setEntityProp(props[i]->getPropName(), ((TextureProp*)props[i])->get()->getResourceName()); + entity->setEntityProp(plugin + props[i]->getPropName(), ((TextureProp*)props[i])->get()->getResourceName()); break; case PropProp::PROP_SCENE_SPRITE: - entity->setEntityProp(props[i]->getPropName(), ((SceneSpriteProp*)props[i])->get()->getResourceName()); + entity->setEntityProp(plugin + props[i]->getPropName(), ((SceneSpriteProp*)props[i])->get()->getResourceName()); break; case PropProp::PROP_SCENE_ENTITY_INSTANCE: - entity->setEntityProp(props[i]->getPropName(), ((SceneEntityInstanceProp*)props[i])->get()); + entity->setEntityProp(plugin + props[i]->getPropName(), ((SceneEntityInstanceProp*)props[i])->get()); break; case PropProp::PROP_CUSTOM: default: - entity->setEntityProp(((CustomProp*)props[i])->getKey(), ((CustomProp*)props[i])->getValue()); + entity->setEntityProp(plugin + ((CustomProp*)props[i])->getKey(), ((CustomProp*)props[i])->getValue()); break; } } @@ -2470,8 +2615,18 @@ void EntityPropSheet::refreshProps() { break; case PropProp::PROP_COMBO: prop = new ComboProp(caption); - for (int c = 0; c < (*propsEntry)[caption]->children.size(); c++) { - ((ComboProp*)prop)->comboEntry->addComboItem(plugin + caption + String::NumberToString(c, 0), &(*propsEntry)[plugin + caption][c]["type"]->intVal); + for (int c = 0; c < propEntry->children.size(); c++) { + ObjectEntry* comboEntry = propEntry->children[c]; + if (comboEntry){ + if (comboEntry->name == "prop" && (*comboEntry)["name"] && (*comboEntry)["value"]){ + ((ComboProp*)prop)->comboEntry->addComboItem((*comboEntry)["name"]->stringVal, ((void*)(*comboEntry)["value"]->intVal)); + } + } + } + for (int s = 0; s < ((ComboProp*)prop)->comboEntry->getNumItems(); s++){ + if (((int)((ComboProp*)prop)->comboEntry->getItemAtIndex(s)->data) == entity->getEntityPropIntByName(plugin + caption)){ + ((ComboProp*)prop)->comboEntry->setSelectedIndex(s); + } } break; case PropProp::PROP_BOOL: @@ -2509,7 +2664,7 @@ void EntityPropSheet::refreshProps() { break; case PropProp::PROP_CUSTOM: default: - prop = new CustomProp(caption, ""); + prop = new CustomProp(caption, entity->getEntityPropStringByName(plugin + caption)); break; } prop->addEventListener(this, Event::CHANGE_EVENT); @@ -4267,7 +4422,6 @@ void LinkedMaterialsSheet::updateMaterials() { addProp(addMaterialProp); } - void LinkedMaterialsSheet::setEntityInstance(SceneEntityInstance *instance) { this->instance = instance; if(instance) { diff --git a/Modules/Contents/UI/Include/PolyUIComboBox.h b/Modules/Contents/UI/Include/PolyUIComboBox.h index 35d769f35..4e10b7778 100755 --- a/Modules/Contents/UI/Include/PolyUIComboBox.h +++ b/Modules/Contents/UI/Include/PolyUIComboBox.h @@ -55,6 +55,9 @@ namespace Polycode { int addComboItem(String itemName); int addComboItem(String itemName, void *data); + void removeComboItem(const String& itemName); + void removeComboItemAtIndex(int index); + int getSelectedIndex(); UIComboBoxItem *getSelectedItem(); void setSelectedIndex(unsigned int newIndex, bool suppressChangeEvent = false); diff --git a/Modules/Contents/UI/Source/PolyUIComboBox.cpp b/Modules/Contents/UI/Source/PolyUIComboBox.cpp index ae4d397d7..582f865b1 100755 --- a/Modules/Contents/UI/Source/PolyUIComboBox.cpp +++ b/Modules/Contents/UI/Source/PolyUIComboBox.cpp @@ -140,6 +140,22 @@ int UIComboBox::addComboItem(String itemName) { return addComboItem(itemName, NULL); } +void UIComboBox::removeComboItem(const String& itemName){ + for (int i = 0; i < items.size(); i++){ + if (items[i]->label == itemName){ + items.erase(items.begin() + i); + if (i == selectedIndex){ + setSelectedIndex(0); + } + return; + } + } +} + +void UIComboBox::removeComboItemAtIndex(int index){ + items.erase(items.begin() + index); +} + UIComboBoxItem *UIComboBox::getSelectedItem() { if(selectedIndex < items.size()) { return items[selectedIndex]; From c0558d7cc306595dd12b1cc2a28e93fa532a0176 Mon Sep 17 00:00:00 2001 From: Joachim Meyer Date: Sat, 6 Sep 2014 18:12:07 +0200 Subject: [PATCH 09/19] Added ability to remove props from a plugin in the Plugin Editor --- IDE/Contents/Include/PolycodeProps.h | 4 ++++ IDE/Contents/Source/PolycodePluginEditor.cpp | 14 +++++++++++--- IDE/Contents/Source/PolycodeProps.cpp | 20 ++++++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/IDE/Contents/Include/PolycodeProps.h b/IDE/Contents/Include/PolycodeProps.h index ee00c9c1f..8df69f438 100644 --- a/IDE/Contents/Include/PolycodeProps.h +++ b/IDE/Contents/Include/PolycodeProps.h @@ -539,6 +539,8 @@ class PropEditProp : public PropProp { UILabel *nameLabel; UIMultilineLabel *typeLabel; + UIImageButton *delButton; + int lastValue; int currentValue; @@ -561,6 +563,8 @@ class PropSheet : public UIElement { void addProp(PropProp *prop); void setTopPadding(Number padding); + + void removeProp(PropProp *prop); String caption; String type; diff --git a/IDE/Contents/Source/PolycodePluginEditor.cpp b/IDE/Contents/Source/PolycodePluginEditor.cpp index b4323881e..c1afd1c6a 100644 --- a/IDE/Contents/Source/PolycodePluginEditor.cpp +++ b/IDE/Contents/Source/PolycodePluginEditor.cpp @@ -135,15 +135,20 @@ void PluginEditorPane::handleEvent(Event *event) { int maxPadding = 0; for (int p = 0; p < propsSheet->props.size(); p++){ if (event->getDispatcher() == propsSheet->props[p]) { - if (((int)((PropEditProp*)propsSheet->props[p])->typeChooser->getSelectedItem()->data) == PropProp::PROP_COMBO){ - - } + //if (((int)((PropEditProp*)propsSheet->props[p])->typeChooser->getSelectedItem()->data) == PropProp::PROP_COMBO){ + //} dispatchEvent(new Event(), Event::CHANGE_EVENT); } + if (((PropEditProp*)propsSheet->props[p])->updatePadding() > maxPadding){ maxPadding = ((PropEditProp*)propsSheet->props[p])->updatePadding(); } + + if (event->getEventCode() == Event::REMOVE_EVENT && event->getDispatcher() == propsSheet->props[p]){ + propsSheet->removeProp(propsSheet->props[p]); + dispatchEvent(new Event(), Event::REMOVE_EVENT); + } } padding = maxPadding + 20; @@ -220,9 +225,11 @@ void PluginEditorPane::setProp(const String& name, PropProp* prop){ for (int i = 0; i < propsSheet->props.size(); i++) { if (propsSheet->props[i]->getPropName() == name) { PropEditProp *newProp = new PropEditProp(prop); + propsSheet->props[i] = newProp; if (((PropEditProp*)newProp)->updatePadding() > (padding - 20)) padding = ((PropEditProp*)newProp)->updatePadding() + 20; newProp->addEventListener(this, Event::CHANGE_EVENT); + newProp->addEventListener(this, Event::REMOVE_EVENT); return; } } @@ -232,6 +239,7 @@ void PluginEditorPane::setProp(const String& name, PropProp* prop){ padding = ((PropEditProp*)newProp)->updatePadding() + 20; propsSheet->addProp(newProp); newProp->addEventListener(this, Event::CHANGE_EVENT); + newProp->addEventListener(this, Event::REMOVE_EVENT); } PluginMainWindow::PluginMainWindow(ResourcePool *resourcePool) : UIElement() { diff --git a/IDE/Contents/Source/PolycodeProps.cpp b/IDE/Contents/Source/PolycodeProps.cpp index bf2780b5b..5183019ff 100644 --- a/IDE/Contents/Source/PolycodeProps.cpp +++ b/IDE/Contents/Source/PolycodeProps.cpp @@ -325,6 +325,18 @@ void PropSheet::addProp(PropProp *prop) { Resize(getWidth(), getHeight()); } +void PropSheet::removeProp(PropProp *prop) { + contents->removeChild(prop); + prop->removeAllHandlers(); + + for (int p = 0; p < props.size(); p++){ + if (props[p] == prop){ + props.erase(props.begin() + p); + } + } + + Resize(getWidth(), getHeight()); +} void PropSheet::applyPropActionData(PolycodeEditorPropActionData *data) { data->prop->setPropData(data); @@ -1881,6 +1893,11 @@ PropEditProp::PropEditProp(PropProp *newProp) : PropProp(newProp->getPropName(), propContents->addChild(typeLabel); typeLabel->setPosition(0, 27); + delButton = new UIImageButton("main/remove_icon.png", 1.0, 12, 12); + delButton->addEventListener(this, UIEvent::CLICK_EVENT); + addChild(delButton); + delButton->setPosition(0, 25); + nameInput = new UITextInput(false, 200, 12); nameInput->addEventListener(this, UIEvent::CHANGE_EVENT); nameInput->setText(newProp->getPropName()); @@ -1973,6 +1990,9 @@ void PropEditProp::handleEvent(Event *event){ } } } + if (event->getDispatcher() == delButton) { + dispatchEvent(new Event(), Event::REMOVE_EVENT); + } } void PropEditProp::set(PropProp *newProp){ From efe3819a66171f2c419c4a172c84cc1f739ab928 Mon Sep 17 00:00:00 2001 From: Joachim Meyer Date: Thu, 11 Sep 2014 21:25:40 +0200 Subject: [PATCH 10/19] Got rid of the arrayVal in EntityProps. --- Core/Contents/Include/PolyEntity.h | 6 +- Core/Contents/Source/PolyEntity.cpp | 64 ++++++++----------- .../Source/PolySceneEntityInstance.cpp | 11 +++- IDE/Contents/Include/PolycodeEntityEditor.h | 2 +- IDE/Contents/Source/PolycodeEntityEditor.cpp | 48 +++++++------- IDE/Contents/Source/PolycodePluginEditor.cpp | 38 +++++------ IDE/Contents/Source/PolycodeProps.cpp | 53 ++++++++------- 7 files changed, 114 insertions(+), 108 deletions(-) diff --git a/Core/Contents/Include/PolyEntity.h b/Core/Contents/Include/PolyEntity.h index 7124e8bff..9db69c435 100755 --- a/Core/Contents/Include/PolyEntity.h +++ b/Core/Contents/Include/PolyEntity.h @@ -52,7 +52,7 @@ namespace Polycode { Number numberVal; int intVal; bool boolVal; - std::vector arrayVal; + //std::vector arrayVal; }; class _PolyExport AABB { @@ -757,7 +757,7 @@ namespace Polycode { * @param Property name to look up. * @return vector of EntityProp property for specified property name - is empty if this property doesn't exist. */ - std::vector getEntityPropArrayByName(const String& propName) const; + //std::vector getEntityPropArrayByName(const String& propName) const; /** * Sets the entity property for a specified property name. @@ -792,7 +792,7 @@ namespace Polycode { * @param propName Property name to set. * @param propVal vector of EntityProp* to set for the specified property name. */ - void setEntityProp(const String& propName, std::vector propVal); + //void setEntityProp(const String& propName, std::vector propVal); void setEntityProp(EntityProp* prop); diff --git a/Core/Contents/Source/PolyEntity.cpp b/Core/Contents/Source/PolyEntity.cpp index c654b36a0..22f5364df 100755 --- a/Core/Contents/Source/PolyEntity.cpp +++ b/Core/Contents/Source/PolyEntity.cpp @@ -866,20 +866,20 @@ void Entity::setEntityProp(const String& propName, const bool& propVal) { entityProps.push_back(entityProp); } -void Entity::setEntityProp(const String& propName, std::vector propVal) { - - for (int i = 0; i < entityProps.size(); i++) { - if (entityProps[i]->name == propName) { - entityProps[i]->arrayVal = propVal; - entityProps[i]->type = Prop::PROP_ARRAY; - return; - } - } - - EntityProp* entityProp = new EntityProp(propName, Prop::PROP_ARRAY); - entityProp->arrayVal = propVal; - entityProps.push_back(entityProp); -} +//void Entity::setEntityProp(const String& propName, std::vector propVal) { +// +// for (int i = 0; i < entityProps.size(); i++) { +// if (entityProps[i]->name == propName) { +// entityProps[i]->arrayVal = propVal; +// entityProps[i]->type = Prop::PROP_ARRAY; +// return; +// } +// } +// +// EntityProp* entityProp = new EntityProp(propName, Prop::PROP_ARRAY); +// entityProp->arrayVal = propVal; +// entityProps.push_back(entityProp); +//} void Entity::setEntityProp(EntityProp* prop){ for (int i = 0; i < entityProps.size(); i++) { @@ -897,9 +897,6 @@ int Entity::getEntityPropIntByName(const String& propName) const { if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_INT) { return entityProps[i]->intVal; } - if (entityProps[i]->type == Prop::PROP_ARRAY) { - getEntityPropIntByName(propName); - } } return false; } @@ -909,9 +906,6 @@ Number Entity::getEntityPropNumberByName(const String& propName) const { if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_NUMBER) { return entityProps[i]->numberVal; } - if (entityProps[i]->type == Prop::PROP_ARRAY) { - getEntityPropIntByName(propName); - } } return Number(NULL); } @@ -921,9 +915,6 @@ bool Entity::getEntityPropBoolByName(const String& propName) const { if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_BOOL) { return entityProps[i]->boolVal; } - if (entityProps[i]->type == Prop::PROP_ARRAY) { - getEntityPropIntByName(propName); - } } return -1; } @@ -933,25 +924,22 @@ String Entity::getEntityPropStringByName(const String& propName) const { if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_STRING) { return entityProps[i]->stringVal; } - if (entityProps[i]->type == Prop::PROP_ARRAY) { - getEntityPropIntByName(propName); - } } return String("null"); } -std::vector Entity::getEntityPropArrayByName(const String& propName) const { - for (int i = 0; i < entityProps.size(); i++) { - if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_ARRAY) { - return entityProps[i]->arrayVal; - } - if (entityProps[i]->type == Prop::PROP_ARRAY) { - getEntityPropIntByName(propName); - } - } - std::vector retVector; - return retVector; -} +//std::vector Entity::getEntityPropArrayByName(const String& propName) const { +// for (int i = 0; i < entityProps.size(); i++) { +// if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_ARRAY) { +// return entityProps[i]->arrayVal; +// } +// if (entityProps[i]->type == Prop::PROP_ARRAY) { +// getEntityPropIntByName(propName); +// } +// } +// std::vector retVector; +// return retVector; +//} bool Entity::isRequiredPlugin(const String& pluginName) const { for (int i = 0; i < requiredPlugins.size(); i++) { diff --git a/Core/Contents/Source/PolySceneEntityInstance.cpp b/Core/Contents/Source/PolySceneEntityInstance.cpp index facf4b995..ac7bae319 100644 --- a/Core/Contents/Source/PolySceneEntityInstance.cpp +++ b/Core/Contents/Source/PolySceneEntityInstance.cpp @@ -275,6 +275,7 @@ void SceneEntityInstance::parseObjectIntoCurve(ObjectEntry *entry, BezierCurve * std::vector SceneEntityInstance::parseObjectEntryIntoProps(ObjectEntry *propsEntry, const String& baseName) { Entity *retEntity = new Entity(); + std::vector entProps; for (int i = 0; i < propsEntry->children.size(); i++) { ObjectEntry *prop = ((*propsEntry))[i]; if (prop->name=="prop") { @@ -283,7 +284,10 @@ std::vector SceneEntityInstance::parseObjectEntryIntoProps(ObjectEn retEntity->setEntityProp(baseName + (*prop)["name"]->stringVal, (*prop)["value"]->stringVal); break; case Prop::PROP_ARRAY: - retEntity->setEntityProp(baseName + (*prop)["name"]->stringVal, parseObjectEntryIntoProps(prop, baseName + (*prop)["name"]->stringVal)); + entProps = parseObjectEntryIntoProps(prop, baseName + (*prop)["name"]->stringVal); + for (int i = 0; i < entProps.size(); i++){ + retEntity->setEntityProp(entProps[i]); + } break; case Prop::PROP_BOOL: retEntity->setEntityProp(baseName + (*prop)["name"]->stringVal, (*prop)["value"]->boolVal); @@ -588,8 +592,9 @@ Entity *SceneEntityInstance::loadObjectEntryIntoEntity(ObjectEntry *entry, Entit entity->addPluginByName(pluginName); ObjectEntry *props = (*plugin)["props"]; - if (props) { - entity->entityProps = parseObjectEntryIntoProps(props, pluginName); + std::vector entProps = parseObjectEntryIntoProps(props, pluginName); + for (int i = 0; i < entProps.size(); i++){ + entity->entityProps.push_back(entProps[i]); } } } diff --git a/IDE/Contents/Include/PolycodeEntityEditor.h b/IDE/Contents/Include/PolycodeEntityEditor.h index 2bccc88e8..8c5ca9a35 100644 --- a/IDE/Contents/Include/PolycodeEntityEditor.h +++ b/IDE/Contents/Include/PolycodeEntityEditor.h @@ -383,7 +383,7 @@ class PolycodeEntityEditor : public PolycodeEditor { void saveFile(); void saveCurveToObject(ObjectEntry *entry, BezierCurve *curve); void saveShaderOptionsToEntry(ObjectEntry *entry, Material *material, ShaderBinding *binding); - void savePropsToEntry(ObjectEntry *entry, std::vector props, const String& pluginName); + void savePropsToEntry(ObjectEntry *entry, std::vector props, const String& baseName); void saveEntityToObjectEntry(Entity *entity, ObjectEntry *entry); void doAction(String actionName, PolycodeEditorActionData *data); diff --git a/IDE/Contents/Source/PolycodeEntityEditor.cpp b/IDE/Contents/Source/PolycodeEntityEditor.cpp index f25238c89..02b12a092 100644 --- a/IDE/Contents/Source/PolycodeEntityEditor.cpp +++ b/IDE/Contents/Source/PolycodeEntityEditor.cpp @@ -2519,30 +2519,32 @@ void PolycodeEntityEditor::Resize(int x, int y) { PolycodeEditor::Resize(x,y); } -void PolycodeEntityEditor::savePropsToEntry(ObjectEntry *entry, std::vector props, const String& pluginName) { +void PolycodeEntityEditor::savePropsToEntry(ObjectEntry *entry, std::vector props, const String& baseName) { for (int i = 0; i < props.size(); i++) { - ObjectEntry *prop = entry->addChild("prop"); - prop->addChild("name", props[i]->name.replace(pluginName, "")); - prop->addChild("type", props[i]->type); - switch (props[i]->type) { - case Prop::PROP_STRING: - prop->addChild("value", props[i]->stringVal); - break; - case Prop::PROP_ARRAY: - savePropsToEntry(prop, props[i]->arrayVal, pluginName); - break; - case Prop::PROP_BOOL: - prop->addChild("value", props[i]->boolVal); - break; - case Prop::PROP_INT: - prop->addChild("value", props[i]->intVal); - break; - case Prop::PROP_NUMBER: - prop->addChild("value", props[i]->numberVal); - break; - default: - prop->addChild("value", props[i]->stringVal); - break; + if (props[i]->name.find(baseName) == 0){ + ObjectEntry *prop = entry->addChild("prop"); + prop->addChild("name", props[i]->name.replace(baseName, "")); + prop->addChild("type", props[i]->type); + switch (props[i]->type) { + case Prop::PROP_STRING: + prop->addChild("value", props[i]->stringVal); + break; + //case Prop::PROP_ARRAY: + // savePropsToEntry(prop, props[i]->arrayVal, props[i]->name); + // break; + case Prop::PROP_BOOL: + prop->addChild("value", props[i]->boolVal); + break; + case Prop::PROP_INT: + prop->addChild("value", props[i]->intVal); + break; + case Prop::PROP_NUMBER: + prop->addChild("value", props[i]->numberVal); + break; + default: + prop->addChild("value", props[i]->stringVal); + break; + } } } } diff --git a/IDE/Contents/Source/PolycodePluginEditor.cpp b/IDE/Contents/Source/PolycodePluginEditor.cpp index c1afd1c6a..84de9d0e0 100644 --- a/IDE/Contents/Source/PolycodePluginEditor.cpp +++ b/IDE/Contents/Source/PolycodePluginEditor.cpp @@ -31,7 +31,7 @@ PluginBrowser::PluginBrowser() : UIElement() { treeContainer->getRootNode()->addEventListener(this, UITreeEvent::SELECTED_EVENT); treeContainer->addEventListener(this, InputEvent::EVENT_MOUSEDOWN); - pluginNode = treeContainer->getRootNode()->addTreeChild("materialEditor/plugin_icon.png", "Plugins", NULL); + pluginNode = treeContainer->getRootNode()->addTreeChild("pluginEditor/plugin_icon.png", "Plugins", NULL); addChild(treeContainer); selectedData = NULL; @@ -41,7 +41,7 @@ PluginBrowser::PluginBrowser() : UIElement() { headerBg->setAnchorPoint(-1.0, -1.0, 0.0); headerBg->color.setColorHexFromString(CoreServices::getInstance()->getConfig()->getStringValue("Polycode", "uiHeaderBgColor")); - newPluginButton = new UIImageButton("materialEditor/new_plugin.png", 1.0, 22, 22); + newPluginButton = new UIImageButton("pluginEditor/new_plugin.png", 1.0, 22, 22); addChild(newPluginButton); newPluginButton->setPosition(5, 4); @@ -75,7 +75,7 @@ void PluginBrowser::handleEvent(Event *event) { UITree *PluginBrowser::addPlugin(Plugin *plugin) { PluginBrowserData *data = new PluginBrowserData(); data->plugin = plugin; - return pluginNode->addTreeChild("materialEditor/material_icon.png", plugin->getResourceName(), (void*)data); + return pluginNode->addTreeChild("pluginEditor/plugin_icon.png", plugin->getResourceName(), (void*)data); } void PluginBrowser::Resize(Number width, Number height) { @@ -179,23 +179,25 @@ void PluginEditorPane::setPlugin(Plugin *plugin) { currentPlugin = plugin; nameProp->set(plugin->getResourceName()); - - ObjectEntry *propsEntry = (*plugin->sheetEntry)["props"]; - if (propsEntry) { - for (int p = 0; p < propsEntry->children.size(); p++) { - ObjectEntry* propEntry = (*propsEntry)[p]; - if (propEntry && propEntry->name == "prop") { - if ((*propEntry)["type"]->intVal != PropProp::PROP_COMBO){ - setProp((*propEntry)["name"]->stringVal, new PropProp((*propEntry)["name"]->stringVal, (*propEntry)["type"]->intVal)); - } else { - ComboProp *newComboProp = new ComboProp((*propEntry)["name"]->stringVal); - for (int c = 0; c < propEntry->children.size(); c++){ - ObjectEntry *comboEntry = propEntry->children[c]; - if (comboEntry && comboEntry->name == "prop"){ - newComboProp->comboEntry->addComboItem((*comboEntry)["name"]->stringVal, ((void*)(*comboEntry)["value"]->intVal)); + + if (plugin->sheetEntry){ + ObjectEntry *propsEntry = (*plugin->sheetEntry)["props"]; + if (propsEntry) { + for (int p = 0; p < propsEntry->children.size(); p++) { + ObjectEntry* propEntry = (*propsEntry)[p]; + if (propEntry && propEntry->name == "prop") { + if ((*propEntry)["type"]->intVal != PropProp::PROP_COMBO){ + setProp((*propEntry)["name"]->stringVal, new PropProp((*propEntry)["name"]->stringVal, (*propEntry)["type"]->intVal)); + } else { + ComboProp *newComboProp = new ComboProp((*propEntry)["name"]->stringVal); + for (int c = 0; c < propEntry->children.size(); c++){ + ObjectEntry *comboEntry = propEntry->children[c]; + if (comboEntry && comboEntry->name == "prop"){ + newComboProp->comboEntry->addComboItem((*comboEntry)["name"]->stringVal, ((void*)(*comboEntry)["value"]->intVal)); + } } + setProp(newComboProp->getPropName(), newComboProp); } - setProp(newComboProp->getPropName(), newComboProp); } } } diff --git a/IDE/Contents/Source/PolycodeProps.cpp b/IDE/Contents/Source/PolycodeProps.cpp index 5183019ff..dde999ef0 100644 --- a/IDE/Contents/Source/PolycodeProps.cpp +++ b/IDE/Contents/Source/PolycodeProps.cpp @@ -2035,6 +2035,9 @@ ComboPropEditProp::ComboPropEditProp(ComboProp* newCombo) : PropProp("", PropPro propContents->addChild(addItemButton); addItemButton->setPosition(220, 0); + label->enabled = false; + label->visible = false; + currentCombo = newCombo; for (int c = 0; c < currentCombo->comboEntry->getNumItems(); c++){ @@ -2044,7 +2047,7 @@ ComboPropEditProp::ComboPropEditProp(ComboProp* newCombo) : PropProp("", PropPro items.push_back(newProp); StringProp *newDataProp = new StringProp("Data:"); - newDataProp->set(((int)currentCombo->comboEntry->getItemAtIndex(c)->data)); + newDataProp->set(String::NumberToString((int)currentCombo->comboEntry->getItemAtIndex(c)->data)); newDataProp->stringEntry->setPosition(-70, 0); newDataProp->stringEntry->Resize(40, newDataProp->stringEntry->getHeight()); newDataProp->stringEntry->setNumberOnly(true); @@ -2079,7 +2082,13 @@ void ComboPropEditProp::handleEvent(Event *event){ newItemName->setText(""); dispatchEvent(new Event(), Event::CHANGE_EVENT); } + for (int i = 0; i < items.size(); i++) { + if (event->getDispatcher() == datas[i]){ + currentCombo->comboEntry->getItemAtIndex(i)->data = (void*)datas[i]->get().toInteger(); + dispatchEvent(new Event(), Event::CHANGE_EVENT); + } + if (items[i] == event->getDispatcher()) { //items[i]->enabled = false; //items[i]->visible = false; @@ -2450,28 +2459,27 @@ void EntityPropSheet::handleEvent(Event *event) { PolycodeEditorPropActionData *beforeData = PropDataEntity(entity); if(i <= entity->entityProps.size()) { - std::vector propsVector; + //std::vector propsVector; EntityProp* prop; switch (props[i]->propType) { case PropProp::PROP_VECTOR3: - prop = new EntityProp(plugin + props[i]->getPropName() + "x", Prop::PROP_NUMBER); - prop->numberVal = ((Vector3Prop*)props[i])->get().x; - propsVector.push_back(prop); - prop = new EntityProp(plugin + props[i]->getPropName() + "y", Prop::PROP_NUMBER); - prop->numberVal = ((Vector3Prop*)props[i])->get().y; - propsVector.push_back(prop); - prop = new EntityProp(plugin + props[i]->getPropName() + "z", Prop::PROP_NUMBER); - prop->numberVal = ((Vector3Prop*)props[i])->get().z; - propsVector.push_back(prop); - entity->setEntityProp(plugin + props[i]->getPropName(), propsVector); + //prop = new EntityProp(plugin + props[i]->getPropName() + "x", Prop::PROP_NUMBER); + //prop->numberVal = ((Vector3Prop*)props[i])->get().x; + ////propsVector.push_back(prop); + //prop = new EntityProp(plugin + props[i]->getPropName() + "y", Prop::PROP_NUMBER); + //prop->numberVal = ((Vector3Prop*)props[i])->get().y; + ////propsVector.push_back(prop); + //prop = new EntityProp(plugin + props[i]->getPropName() + "z", Prop::PROP_NUMBER); + //prop->numberVal = ((Vector3Prop*)props[i])->get().z; + //propsVector.push_back(prop); + entity->setEntityProp(plugin + props[i]->getPropName() + "x", ((Vector3Prop*)props[i])->get().x); + entity->setEntityProp(plugin + props[i]->getPropName() + "y", ((Vector3Prop*)props[i])->get().y); + entity->setEntityProp(plugin + props[i]->getPropName() + "z", ((Vector3Prop*)props[i])->get().z); break; case PropProp::PROP_VECTOR2: - prop = new EntityProp(plugin + props[i]->getPropName() + "x", Prop::PROP_NUMBER); - propsVector.push_back(prop); - prop = new EntityProp(plugin + props[i]->getPropName() + "y", Prop::PROP_NUMBER); - propsVector.push_back(prop); - entity->setEntityProp(plugin + props[i]->getPropName(), propsVector); + entity->setEntityProp(plugin + props[i]->getPropName() + "x", ((Vector2Prop*)props[i])->get().x); + entity->setEntityProp(plugin + props[i]->getPropName() + "y", ((Vector2Prop*)props[i])->get().y); break; case PropProp::PROP_SLIDER: entity->setEntityProp(plugin + props[i]->getPropName(), ((SliderProp*)props[i])->get()); @@ -2643,11 +2651,12 @@ void EntityPropSheet::refreshProps() { } } } - for (int s = 0; s < ((ComboProp*)prop)->comboEntry->getNumItems(); s++){ - if (((int)((ComboProp*)prop)->comboEntry->getItemAtIndex(s)->data) == entity->getEntityPropIntByName(plugin + caption)){ - ((ComboProp*)prop)->comboEntry->setSelectedIndex(s); - } - } + //for (int s = 0; s < ((ComboProp*)prop)->comboEntry->getNumItems(); s++){ + // if (((int)((ComboProp*)prop)->comboEntry->getItemAtIndex(s)->data) == entity->getEntityPropIntByName(plugin + caption)){ + // ((ComboProp*)prop)->comboEntry->setSelectedIndex(s); + // } + //} + ((ComboProp*)prop)->comboEntry->setSelectedIndex(entity->getEntityPropIntByName(plugin + caption)); break; case PropProp::PROP_BOOL: prop = new BoolProp(caption); From e5396d8a30d5908d05c0fe09a91e047ae65597e0 Mon Sep 17 00:00:00 2001 From: Joachim Meyer Date: Sat, 13 Sep 2014 10:10:23 +0200 Subject: [PATCH 11/19] (Re-)adding pluginEditor icons, Fixing problems with more than one plugin in the editor, other bugfixes and (it at least seems like to) fix an issue with loading the plugins.. --- Core/Contents/Include/PolyEntity.h | 13 +- Core/Contents/Include/PolyPlugin.h | 36 ++- Core/Contents/Source/PolyEntity.cpp | 39 ++-- Core/Contents/Source/PolyPlugin.cpp | 56 +++-- .../Source/PolySceneEntityInstance.cpp | 10 +- .../Images/pluginEditor/new_plugin.png | Bin 0 -> 469 bytes .../Images/pluginEditor/plugin_icon.png | Bin 0 -> 474 bytes IDE/Contents/Source/PolycodeEntityEditor.cpp | 14 +- IDE/Contents/Source/PolycodePluginEditor.cpp | 89 ++++--- IDE/Contents/Source/PolycodeProps.cpp | 218 +++++++++--------- 10 files changed, 266 insertions(+), 209 deletions(-) create mode 100644 IDE/Contents/Resources/Images/pluginEditor/new_plugin.png create mode 100644 IDE/Contents/Resources/Images/pluginEditor/plugin_icon.png diff --git a/Core/Contents/Include/PolyEntity.h b/Core/Contents/Include/PolyEntity.h index 9db69c435..b9c141201 100755 --- a/Core/Contents/Include/PolyEntity.h +++ b/Core/Contents/Include/PolyEntity.h @@ -44,15 +44,24 @@ namespace Polycode { bool blocked; }; - class _PolyExport EntityProp : public Prop { + class _PolyExport EntityProp : public PolyBase { public: - EntityProp(const String& name, const unsigned int& type = Prop::PROP_STRING); + EntityProp(const String& name, const unsigned int& type = EntityProp::PROP_STRING); + + int type; + String name; String stringVal; Number numberVal; int intVal; bool boolVal; //std::vector arrayVal; + + static const unsigned int PROP_NUMBER = 0; + static const unsigned int PROP_INT = 1; + static const unsigned int PROP_BOOL = 2; + static const unsigned int PROP_STRING = 3; + static const unsigned int PROP_ARRAY = 4; }; class _PolyExport AABB { diff --git a/Core/Contents/Include/PolyPlugin.h b/Core/Contents/Include/PolyPlugin.h index ba1394b16..dc1c9b889 100644 --- a/Core/Contents/Include/PolyPlugin.h +++ b/Core/Contents/Include/PolyPlugin.h @@ -36,18 +36,37 @@ namespace Polycode { Prop *loadPropFromEntry(ObjectEntry* entry); + int type; - String name; - int length; + String name; + int value; std::vector children; - static const unsigned int PROP_NUMBER = 0; - static const unsigned int PROP_INT = 1; - static const unsigned int PROP_BOOL = 2; - static const unsigned int PROP_STRING = 3; - static const unsigned int PROP_ARRAY = 4; + static const int PROP_VECTOR3 = 0; + static const int PROP_VECTOR2 = 1; + static const int PROP_SLIDER = 2; + static const int PROP_BUTTON = 3; + static const int PROP_NUMBER = 4; + static const int PROP_TARGET_BINDING = 5; + static const int PROP_RENDER_TARGET = 6; + static const int PROP_SHADER_PASS = 7; + static const int PROP_REMOVABLE_STRING = 8; + static const int PROP_LAYER = 9; + static const int PROP_CUSTOM = 10; + static const int PROP_STRING = 11; + static const int PROP_COLOR = 12; + static const int PROP_COMBO = 13; + static const int PROP_BOOL = 14; + static const int PROP_SOUND = 15; + static const int PROP_BEZIER_RGBA_CURVE = 16; + static const int PROP_BEZIER_CURVE = 17; + static const int PROP_MATERIAL = 18; + static const int PROP_MATERIAL_PREVIEW = 19; + static const int PROP_TEXTURE = 20; + static const int PROP_SCENE_SPRITE = 21; + static const int PROP_SCENE_ENTITY_INSTANCE = 22; }; class _PolyExport Plugin : public Resource { @@ -62,6 +81,7 @@ namespace Polycode { void setProp(Prop* prop); void removeProp(Prop* prop); + void removeProp(const String& propName); std::vector getProps() const; unsigned int getNumProps() const; @@ -71,7 +91,7 @@ namespace Polycode { static const unsigned int PLUGIN_ENTITY = 0; String ext; - ObjectEntry *sheetEntry; + //ObjectEntry *sheetEntry; protected: std::vector props; diff --git a/Core/Contents/Source/PolyEntity.cpp b/Core/Contents/Source/PolyEntity.cpp index 22f5364df..1749c7396 100755 --- a/Core/Contents/Source/PolyEntity.cpp +++ b/Core/Contents/Source/PolyEntity.cpp @@ -810,13 +810,13 @@ void Entity::setEntityProp(const String& propName, const String& propVal) { for (int i = 0; i < entityProps.size(); i++) { if (entityProps[i]->name == propName) { entityProps[i]->stringVal = propVal; - entityProps[i]->type = Prop::PROP_STRING; + entityProps[i]->type = EntityProp::PROP_STRING; return; } } - EntityProp* entityProp = new EntityProp(propName, Prop::PROP_STRING); + EntityProp* entityProp = new EntityProp(propName, EntityProp::PROP_STRING); entityProp->stringVal = propVal; entityProps.push_back(entityProp); } @@ -826,12 +826,12 @@ void Entity::setEntityProp(const String& propName, const int& propVal) { for (int i = 0; i < entityProps.size(); i++) { if (entityProps[i]->name == propName) { entityProps[i]->intVal = propVal; - entityProps[i]->type = Prop::PROP_INT; + entityProps[i]->type = EntityProp::PROP_INT; return; } } - EntityProp* entityProp = new EntityProp(propName, Prop::PROP_INT); + EntityProp* entityProp = new EntityProp(propName, EntityProp::PROP_INT); entityProp->intVal = propVal; entityProps.push_back(entityProp); } @@ -841,12 +841,12 @@ void Entity::setEntityProp(const String& propName, const Number& propVal) { for (int i = 0; i < entityProps.size(); i++) { if (entityProps[i]->name == propName) { entityProps[i]->numberVal = propVal; - entityProps[i]->type = Prop::PROP_NUMBER; + entityProps[i]->type = EntityProp::PROP_NUMBER; return; } } - EntityProp* entityProp = new EntityProp(propName, Prop::PROP_NUMBER); + EntityProp* entityProp = new EntityProp(propName, EntityProp::PROP_NUMBER); entityProp->numberVal = propVal; entityProps.push_back(entityProp); } @@ -856,12 +856,12 @@ void Entity::setEntityProp(const String& propName, const bool& propVal) { for (int i = 0; i < entityProps.size(); i++) { if (entityProps[i]->name == propName) { entityProps[i]->boolVal = propVal; - entityProps[i]->type = Prop::PROP_BOOL; + entityProps[i]->type = EntityProp::PROP_BOOL; return; } } - EntityProp* entityProp = new EntityProp(propName, Prop::PROP_BOOL); + EntityProp* entityProp = new EntityProp(propName, EntityProp::PROP_BOOL); entityProp->boolVal = propVal; entityProps.push_back(entityProp); } @@ -871,12 +871,12 @@ void Entity::setEntityProp(const String& propName, const bool& propVal) { // for (int i = 0; i < entityProps.size(); i++) { // if (entityProps[i]->name == propName) { // entityProps[i]->arrayVal = propVal; -// entityProps[i]->type = Prop::PROP_ARRAY; +// entityProps[i]->type = EntityProp::PROP_ARRAY; // return; // } // } // -// EntityProp* entityProp = new EntityProp(propName, Prop::PROP_ARRAY); +// EntityProp* entityProp = new EntityProp(propName, EntityProp::PROP_ARRAY); // entityProp->arrayVal = propVal; // entityProps.push_back(entityProp); //} @@ -894,7 +894,7 @@ void Entity::setEntityProp(EntityProp* prop){ int Entity::getEntityPropIntByName(const String& propName) const { for (int i = 0; i < entityProps.size(); i++) { - if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_INT) { + if (entityProps[i]->name == propName && entityProps[i]->type == EntityProp::PROP_INT) { return entityProps[i]->intVal; } } @@ -903,7 +903,7 @@ int Entity::getEntityPropIntByName(const String& propName) const { Number Entity::getEntityPropNumberByName(const String& propName) const { for (int i = 0; i < entityProps.size(); i++) { - if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_NUMBER) { + if (entityProps[i]->name == propName && entityProps[i]->type == EntityProp::PROP_NUMBER) { return entityProps[i]->numberVal; } } @@ -912,7 +912,7 @@ Number Entity::getEntityPropNumberByName(const String& propName) const { bool Entity::getEntityPropBoolByName(const String& propName) const { for (int i = 0; i < entityProps.size(); i++) { - if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_BOOL) { + if (entityProps[i]->name == propName && entityProps[i]->type == EntityProp::PROP_BOOL) { return entityProps[i]->boolVal; } } @@ -921,7 +921,7 @@ bool Entity::getEntityPropBoolByName(const String& propName) const { String Entity::getEntityPropStringByName(const String& propName) const { for (int i = 0; i < entityProps.size(); i++) { - if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_STRING) { + if (entityProps[i]->name == propName && entityProps[i]->type == EntityProp::PROP_STRING) { return entityProps[i]->stringVal; } } @@ -930,10 +930,10 @@ String Entity::getEntityPropStringByName(const String& propName) const { //std::vector Entity::getEntityPropArrayByName(const String& propName) const { // for (int i = 0; i < entityProps.size(); i++) { -// if (entityProps[i]->name == propName && entityProps[i]->type == Prop::PROP_ARRAY) { +// if (entityProps[i]->name == propName && entityProps[i]->type == EntityProp::PROP_ARRAY) { // return entityProps[i]->arrayVal; // } -// if (entityProps[i]->type == Prop::PROP_ARRAY) { +// if (entityProps[i]->type == EntityProp::PROP_ARRAY) { // getEntityPropIntByName(propName); // } // } @@ -1373,7 +1373,10 @@ MouseEventResult Entity::onMouseWheelDown(const Ray &ray, int timestamp) { return ret; } -EntityProp::EntityProp(const String& name, const unsigned int& type) : Prop(name, type) {} +EntityProp::EntityProp(const String& name, const unsigned int& type) { + this->name = name; + this->type = type; +} void Entity::addPluginByName(const String& pluginName, ResourcePool *resourcePool) { Plugin *plugin; @@ -1387,7 +1390,7 @@ void Entity::addPluginByName(const String& pluginName, ResourcePool *resourcePoo if (plugin){ for (int i = 0; i < requiredPlugins.size(); i++) { - if (requiredPlugins[i] == plugin) { + if (requiredPlugins[i]->getResourceName() == plugin->getResourceName()) { requiredPlugins[i] = plugin; return; } diff --git a/Core/Contents/Source/PolyPlugin.cpp b/Core/Contents/Source/PolyPlugin.cpp index ae3a5150a..83109789c 100644 --- a/Core/Contents/Source/PolyPlugin.cpp +++ b/Core/Contents/Source/PolyPlugin.cpp @@ -35,7 +35,7 @@ Plugin::Plugin(const String& name) : Resource(Resource::RESOURCE_PLUGIN) { ext = ""; pluginType = 0; type = Resource::RESOURCE_PLUGIN; - sheetEntry = NULL; + //sheetEntry = NULL; } } @@ -52,21 +52,26 @@ Plugin* Plugin::loadPluginFromEntry(ObjectEntry* entry){ if ((*entry)["fileext"]) this->ext = (*entry)["fileext"]->stringVal; - if ((*entry)["sheet"] && (*(*entry)["sheet"])["props"]) - this->sheetEntry = (*entry)["sheet"]; + //if ((*entry)["sheet"] && (*(*entry)["sheet"])["props"]) + // this->sheetEntry = (*entry)["sheet"]; if ((*entry)["type"]) this->pluginType = (*entry)["type"]->intVal; - ObjectEntry* props = (*entry)["props"]; - if (props) { - for (int k = 0; k < props->length; k++) { - ObjectEntry* propEntry = props->children[k]; - if (!propEntry) - continue; - - Prop *prop = new Prop(propEntry); - this->addProp(prop); + if ((*entry)["sheet"]){ + ObjectEntry* sheetEntry = (*entry)["sheet"]; + if ((*sheetEntry)["props"]){ + ObjectEntry* propsEntry = (*sheetEntry)["props"]; + if (propsEntry) { + for (int k = 0; k < propsEntry->children.size(); k++) { + ObjectEntry* propEntry = propsEntry->children[k]; + if (!propEntry || propEntry->name != "prop") + continue; + + Prop *prop = new Prop(propEntry); + this->setProp(prop); + } + } } } Logger::log("Adding plugin: [%s]\n", this->getResourceName().c_str()); @@ -102,6 +107,16 @@ void Plugin::removeProp(Prop *propToRemove) { } } +void Plugin::removeProp(const String& propName) { + for (int i = 0; i < props.size(); i++) { + if (props[i]->name == propName) { + delete props[i]; + props.erase(props.begin() + i); + return; + } + } +} + std::vector Plugin::getProps() const { return props; } @@ -118,26 +133,21 @@ Prop::Prop(ObjectEntry *entry) { Prop::~Prop(){} Prop* Prop::loadPropFromEntry(ObjectEntry* entry){ - int type = (*entry)["type"]->intVal; - if (!type) + if (!entry->readInt("type", &this->type)) return NULL; if (!(*entry)["name"]) return NULL; - String name = (*entry)["name"]->stringVal; - - this->type = type; - this->name = name; + this->name = (*entry)["name"]->stringVal; - if (type == 4){ - int l = 0; + if (type == Prop::PROP_COMBO){ for (int i = 0; i < entry->children.size(); i++) { if (entry->children[i]->name == "prop") { - children.push_back(new Prop(entry->children[i])); - l++; + Prop* newProp = new Prop((*entry->children[i])["name"]->stringVal, Prop::PROP_COMBO); + newProp->value = (*entry->children[i])["value"]->intVal; + children.push_back(newProp); } } - this->length = l; } return this; } \ No newline at end of file diff --git a/Core/Contents/Source/PolySceneEntityInstance.cpp b/Core/Contents/Source/PolySceneEntityInstance.cpp index ac7bae319..73b3138bd 100644 --- a/Core/Contents/Source/PolySceneEntityInstance.cpp +++ b/Core/Contents/Source/PolySceneEntityInstance.cpp @@ -280,22 +280,22 @@ std::vector SceneEntityInstance::parseObjectEntryIntoProps(ObjectEn ObjectEntry *prop = ((*propsEntry))[i]; if (prop->name=="prop") { switch ((*prop)["type"]->intVal) { - case Prop::PROP_STRING: + case EntityProp::PROP_STRING: retEntity->setEntityProp(baseName + (*prop)["name"]->stringVal, (*prop)["value"]->stringVal); break; - case Prop::PROP_ARRAY: + case EntityProp::PROP_ARRAY: entProps = parseObjectEntryIntoProps(prop, baseName + (*prop)["name"]->stringVal); for (int i = 0; i < entProps.size(); i++){ retEntity->setEntityProp(entProps[i]); } break; - case Prop::PROP_BOOL: + case EntityProp::PROP_BOOL: retEntity->setEntityProp(baseName + (*prop)["name"]->stringVal, (*prop)["value"]->boolVal); break; - case Prop::PROP_INT: + case EntityProp::PROP_INT: retEntity->setEntityProp(baseName + (*prop)["name"]->stringVal, (*prop)["value"]->intVal); break; - case Prop::PROP_NUMBER: + case EntityProp::PROP_NUMBER: retEntity->setEntityProp(baseName + (*prop)["name"]->stringVal, (*prop)["value"]->NumberVal); break; default: diff --git a/IDE/Contents/Resources/Images/pluginEditor/new_plugin.png b/IDE/Contents/Resources/Images/pluginEditor/new_plugin.png new file mode 100644 index 0000000000000000000000000000000000000000..8b2677211e6ce9e7d2c5ad664cbf2baa412c5b72 GIT binary patch literal 469 zcmV;`0V@89P)h-z?6o9QMK~$8l)@sr) zjK2~oC3VZvfOBA*`RoFPYPBl0SnO9~+jc0}WHEMtvqrNi0Ynf4ao`fzU^yi42HcAv z2#$ah5WT+aoW)O(I0g(frPRxDCc{;+$bypRFlbnoaN6ykp7i^DR$(w0;QKzpG)+>; zBzL6}>2x}rznQV-dR}vIU6;pBhgFdPpW`vTUXO0KyOKl;gOAaOO1X^Zx}0RQ8Ze&9 zy`4UmQcC>$JMY6Gl}ZI*ZBjriwUZFn^8nU?5#Rw|lQ$GZt4H|;U{`66`ytdk00000 LNkvXXu0mjf24}k5 literal 0 HcmV?d00001 diff --git a/IDE/Contents/Resources/Images/pluginEditor/plugin_icon.png b/IDE/Contents/Resources/Images/pluginEditor/plugin_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..f2c270fe1c7a529588f84509d8534863357efc7c GIT binary patch literal 474 zcmV<00VV#4P) zK~y-)os+>zLO~dXzk72`-=ZgIYr7ULa@&Y6(t`w&FHqOGf)2GPYEcVQL9AT_;ihsC zl1fC%HA?>$H>GZRNe|3o&K$lu^TSwLYo^H<69LYFb>ITnOr=u8X<0jHSeAt`Mgf&? z0Kf)NF~%s{w!Jx z_-}}9+qn7sxWO#ISP7t<%jHyLX~}oA)`&<eq`0MYyyuRW%PH2m4Hp^41g@{bNNHF9L2BDB%zyHVk0x;Gk=$hor Q(EtDd07*qoM6N<$f<8pW?*IS* literal 0 HcmV?d00001 diff --git a/IDE/Contents/Source/PolycodeEntityEditor.cpp b/IDE/Contents/Source/PolycodeEntityEditor.cpp index 02b12a092..9f031fa2a 100644 --- a/IDE/Contents/Source/PolycodeEntityEditor.cpp +++ b/IDE/Contents/Source/PolycodeEntityEditor.cpp @@ -2526,19 +2526,19 @@ void PolycodeEntityEditor::savePropsToEntry(ObjectEntry *entry, std::vectoraddChild("name", props[i]->name.replace(baseName, "")); prop->addChild("type", props[i]->type); switch (props[i]->type) { - case Prop::PROP_STRING: + case EntityProp::PROP_STRING: prop->addChild("value", props[i]->stringVal); break; - //case Prop::PROP_ARRAY: - // savePropsToEntry(prop, props[i]->arrayVal, props[i]->name); - // break; - case Prop::PROP_BOOL: + //case Prop::PROP_ARRAY: + // savePropsToEntry(prop, props[i]->arrayVal, props[i]->name); + // break; + case EntityProp::PROP_BOOL: prop->addChild("value", props[i]->boolVal); break; - case Prop::PROP_INT: + case EntityProp::PROP_INT: prop->addChild("value", props[i]->intVal); break; - case Prop::PROP_NUMBER: + case EntityProp::PROP_NUMBER: prop->addChild("value", props[i]->numberVal); break; default: diff --git a/IDE/Contents/Source/PolycodePluginEditor.cpp b/IDE/Contents/Source/PolycodePluginEditor.cpp index 84de9d0e0..2c7c8cfd8 100644 --- a/IDE/Contents/Source/PolycodePluginEditor.cpp +++ b/IDE/Contents/Source/PolycodePluginEditor.cpp @@ -134,10 +134,17 @@ void PluginEditorPane::handleEvent(Event *event) { int maxPadding = 0; for (int p = 0; p < propsSheet->props.size(); p++){ - if (event->getDispatcher() == propsSheet->props[p]) { - //if (((int)((PropEditProp*)propsSheet->props[p])->typeChooser->getSelectedItem()->data) == PropProp::PROP_COMBO){ - //} - + if (event->getEventCode() == Event::CHANGE_EVENT && event->getDispatcher() == propsSheet->props[p]) { + currentPlugin->getProps()[p]->name = propsSheet->props[p]->getPropName(); + currentPlugin->getProps()[p]->type = ((PropEditProp*)propsSheet->props[p])->getPropType(); + if (currentPlugin->getProps()[p]->type == Prop::PROP_COMBO){ + currentPlugin->getProps()[p]->children.clear(); + for (int c = 0; c < ((PropEditProp*)propsSheet->props[p])->comboEditProp->currentCombo->comboEntry->getNumItems(); c++){ + Prop* newProp = new Prop(((PropEditProp*)propsSheet->props[p])->comboEditProp->currentCombo->comboEntry->getItemAtIndex(c)->label, Prop::PROP_COMBO); + newProp->value = (int)((PropEditProp*)propsSheet->props[p])->comboEditProp->currentCombo->comboEntry->getItemAtIndex(c)->data; + currentPlugin->getProps()[p]->children.push_back(newProp); + } + } dispatchEvent(new Event(), Event::CHANGE_EVENT); } @@ -146,6 +153,7 @@ void PluginEditorPane::handleEvent(Event *event) { } if (event->getEventCode() == Event::REMOVE_EVENT && event->getDispatcher() == propsSheet->props[p]){ + currentPlugin->removeProp(propsSheet->props[p]->getPropName()); propsSheet->removeProp(propsSheet->props[p]); dispatchEvent(new Event(), Event::REMOVE_EVENT); } @@ -162,7 +170,9 @@ void PluginEditorPane::handleEvent(Event *event) { if (event->getDispatcher() == addPropButton->getButton()) { PropEditProp *newProp = new PropEditProp(new PropProp("", 0)); propsSheet->addProp(newProp); + currentPlugin->setProp(new Prop("", 0)); newProp->addEventListener(this, Event::CHANGE_EVENT); + newProp->addEventListener(this, Event::REMOVE_EVENT); newProp->propContents->setPositionX(padding); dispatchEvent(new Event(), Event::CHANGE_EVENT); } @@ -174,32 +184,27 @@ void PluginEditorPane::handleEvent(Event *event) { } void PluginEditorPane::setPlugin(Plugin *plugin) { + for (int p = propsSheet->props.size(); p > 0; p--){ + propsSheet->removeProp(propsSheet->props[p - 1]); + } + changingPlugin = true; currentPlugin = plugin; nameProp->set(plugin->getResourceName()); - if (plugin->sheetEntry){ - ObjectEntry *propsEntry = (*plugin->sheetEntry)["props"]; - if (propsEntry) { - for (int p = 0; p < propsEntry->children.size(); p++) { - ObjectEntry* propEntry = (*propsEntry)[p]; - if (propEntry && propEntry->name == "prop") { - if ((*propEntry)["type"]->intVal != PropProp::PROP_COMBO){ - setProp((*propEntry)["name"]->stringVal, new PropProp((*propEntry)["name"]->stringVal, (*propEntry)["type"]->intVal)); - } else { - ComboProp *newComboProp = new ComboProp((*propEntry)["name"]->stringVal); - for (int c = 0; c < propEntry->children.size(); c++){ - ObjectEntry *comboEntry = propEntry->children[c]; - if (comboEntry && comboEntry->name == "prop"){ - newComboProp->comboEntry->addComboItem((*comboEntry)["name"]->stringVal, ((void*)(*comboEntry)["value"]->intVal)); - } - } - setProp(newComboProp->getPropName(), newComboProp); - } - } + for (int p = 0; p < plugin->getProps().size(); p++) { + Prop* propEntry = plugin->getProps()[p]; + if (propEntry->type != PropProp::PROP_COMBO){ + setProp(propEntry->name, new PropProp(propEntry->name, propEntry->type)); + } else { + ComboProp *newComboProp = new ComboProp(propEntry->name); + for (int c = 0; c < propEntry->children.size(); c++){ + Prop *comboEntry = propEntry->children[c]; + newComboProp->comboEntry->addComboItem(comboEntry->name, (void*)comboEntry->value); } + setProp(newComboProp->getPropName(), newComboProp); } } @@ -232,6 +237,16 @@ void PluginEditorPane::setProp(const String& name, PropProp* prop){ padding = ((PropEditProp*)newProp)->updatePadding() + 20; newProp->addEventListener(this, Event::CHANGE_EVENT); newProp->addEventListener(this, Event::REMOVE_EVENT); + currentPlugin->getProps()[i]->name = name; + currentPlugin->getProps()[i]->type = prop->propType; + if (currentPlugin->getProps()[i]->type == Prop::PROP_COMBO){ + currentPlugin->getProps()[i]->children.clear(); + for (int c = 0; c < ((ComboProp*)prop)->comboEntry->getNumItems(); c++){ + Prop* newProp = new Prop(((ComboProp*)prop)->comboEntry->getItemAtIndex(c)->label, Prop::PROP_COMBO); + newProp->value = (int)((ComboProp*)prop)->comboEntry->getItemAtIndex(c)->data; + currentPlugin->getProps()[i]->children.push_back(newProp); + } + } return; } } @@ -242,6 +257,15 @@ void PluginEditorPane::setProp(const String& name, PropProp* prop){ propsSheet->addProp(newProp); newProp->addEventListener(this, Event::CHANGE_EVENT); newProp->addEventListener(this, Event::REMOVE_EVENT); + Prop* pProp = new Prop(name, prop->propType); + if (prop->propType == Prop::PROP_COMBO){ + for (int c = 0; c < ((ComboProp*)prop)->comboEntry->getNumItems(); c++){ + Prop* comboProp = new Prop(((ComboProp*)prop)->comboEntry->getItemAtIndex(c)->label, Prop::PROP_COMBO); + comboProp->value = (int)((ComboProp*)prop)->comboEntry->getItemAtIndex(c)->data; + pProp->children.push_back(comboProp); + } + } + currentPlugin->setProp(pProp); } PluginMainWindow::PluginMainWindow(ResourcePool *resourcePool) : UIElement() { @@ -324,9 +348,7 @@ void PolycodePluginEditor::saveFile() { saveFile.root.addChild("version", 1); for (int p = 0; p < resourcePool->getResources(Resource::RESOURCE_PLUGIN).size(); p++) { ObjectEntry* pluginEntry = saveFile.root.addChild("plugin"); - if (pluginEntry) { - savePluginToObjectEntry(pluginBrowser->selectedData->plugin, pluginEntry); - } + savePluginToObjectEntry((Plugin*)resourcePool->getResources(Resource::RESOURCE_PLUGIN)[p], pluginEntry); } saveFile.saveToXML(filePath.fullPath); setHasChanges(false); @@ -340,16 +362,16 @@ void PolycodePluginEditor::savePluginToObjectEntry(Plugin* plugin, ObjectEntry* ObjectEntry* sheetEntry = entry->addChild("sheet"); //sheetEntry->addChild("name", plugin->getSheetName()); ObjectEntry* propsEntry = sheetEntry->addChild("props"); - std::vector props = mainWindow->pluginPane->getProps(); + std::vector props = plugin->getProps(); for (int i = 0; i < props.size(); i++) { ObjectEntry* propEntry = propsEntry->addChild("prop"); - propEntry->addChild("type", ((PropEditProp*)props[i])->getPropType()); - propEntry->addChild("name", props[i]->getPropName()); - if (((PropEditProp*)props[i])->getPropType() == PropProp::PROP_COMBO){ - for (int c = 0; c < ((PropEditProp*)props[i])->comboEditProp->items.size(); c++){ + propEntry->addChild("type", props[i]->type); + propEntry->addChild("name", props[i]->name); + if (props[i]->type == PropProp::PROP_COMBO){ + for (int c = 0; c < props[i]->children.size(); c++){ ObjectEntry *comboEntry = propEntry->addChild("prop"); - comboEntry->addChild("name", ((PropEditProp*)props[i])->comboEditProp->get()->comboEntry->getItemAtIndex(c)->label); - comboEntry->addChild("value", ((int)((PropEditProp*)props[i])->comboEditProp->get()->comboEntry->getItemAtIndex(c)->data)); + comboEntry->addChild("name", props[i]->children[c]->name); + comboEntry->addChild("value", props[i]->children[c]->value); } } } @@ -384,6 +406,7 @@ void PolycodePluginEditor::handleEvent(Event *event) { } } } + setHasChanges(true); } if (event->getDispatcher() == pluginBrowser) { diff --git a/IDE/Contents/Source/PolycodeProps.cpp b/IDE/Contents/Source/PolycodeProps.cpp index dde999ef0..abc4553fa 100644 --- a/IDE/Contents/Source/PolycodeProps.cpp +++ b/IDE/Contents/Source/PolycodeProps.cpp @@ -2428,7 +2428,7 @@ EntityPropSheet::EntityPropSheet(Plugin* plugin) : PropSheet(plugin->getResource - if (plugin->sheetEntry) + //if (plugin->sheetEntry) refreshProps(); } @@ -2579,93 +2579,86 @@ void EntityPropSheet::refreshProps() { this->visible = true; } - ObjectEntry* propsEntry = (*dynamic_cast(Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_PLUGIN, plugin))->sheetEntry)["props"]; - if (propsEntry) { - PropProp* prop; - - for (int i = 0; i < propsEntry->children.size(); i++) { - ObjectEntry* propEntry = propsEntry->children[i]; - - String caption = (*propEntry)["name"]->stringVal; - - switch ((*propEntry)["type"]->intVal) { - case PropProp::PROP_VECTOR3: - prop = new Vector3Prop(caption); - dynamic_cast(prop)->set(Vector3(entity->getEntityPropNumberByName(plugin + caption + "x"), entity->getEntityPropNumberByName(plugin + caption + "y"), entity->getEntityPropNumberByName(plugin + caption + "z"))); - break; - case PropProp::PROP_VECTOR2: - prop = new Vector2Prop(caption); - dynamic_cast(prop)->set(Vector2(entity->getEntityPropNumberByName(plugin + caption + "x"), entity->getEntityPropNumberByName(plugin + caption + "y"))); - break; - case PropProp::PROP_SLIDER: - prop = new SliderProp(caption, entity->getEntityPropNumberByName(plugin + caption + "min"), entity->getEntityPropNumberByName(plugin + caption + "max")); - dynamic_cast(prop)->set(entity->getEntityPropNumberByName(plugin + caption)); - break; - //case PropProp::PROP_BUTTON: - // prop = new ButtonProp(caption); - // break; - case PropProp::PROP_NUMBER: - prop = new NumberProp(caption); - prop->setPropData(PropDataNumber(entity->getEntityPropNumberByName(plugin + caption))); - break; - //case PropProp::PROP_TARGET_BINDING: - // Shader *shader = ((Shader*)Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_SHADER, entity->getEntityPropStringByName(plugin + caption))); - // Material *material = ((Material*)Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_MATERIAL, entity->getEntityPropStringByName(plugin + caption))); - // ShaderBinding *shaderBin = new ShaderBinding(shader); - // RenderTargetBinding *targetBin = new RenderTargetBinding(); - // - // prop = new TargetBindingProp(shader, material, shaderBin, targetBin); - // - // break; - //case PropProp::PROP_RENDER_TARGET: - // ShaderRenderTarget *renderTarget; - // Material *material; - // prop = new RenderTargetProp(renderTarget, material); - // break; - //case PropProp::PROP_SHADER_PASS: - // prop = new ShaderPassProp(); - // break; - case PropProp::PROP_REMOVABLE_STRING: - prop = new RemovableStringProp(caption); - prop->setPropData(PropDataString(entity->getEntityPropStringByName(plugin + caption))); - break; - //case PropProp::PROP_LAYER: - // SceneEntityInstance *instance = new SceneEntityInstance(); - // prop = new LayerProp(); - // break; - case PropProp::PROP_STRING: - prop = new StringProp(caption); - ((StringProp*)prop)->set(entity->getEntityPropStringByName(plugin + caption)); - break; - case PropProp::PROP_COLOR: - prop = new ColorProp(caption); - ((ColorProp*)prop)->set(new Color(entity->getEntityPropNumberByName(plugin + caption + "r"), entity->getEntityPropNumberByName(plugin + caption + "g"), entity->getEntityPropNumberByName(plugin + caption + "b"), entity->getEntityPropNumberByName(plugin + caption + "a"))); - break; - case PropProp::PROP_COMBO: - prop = new ComboProp(caption); - for (int c = 0; c < propEntry->children.size(); c++) { - ObjectEntry* comboEntry = propEntry->children[c]; - if (comboEntry){ - if (comboEntry->name == "prop" && (*comboEntry)["name"] && (*comboEntry)["value"]){ - ((ComboProp*)prop)->comboEntry->addComboItem((*comboEntry)["name"]->stringVal, ((void*)(*comboEntry)["value"]->intVal)); - } - } + std::vector props = dynamic_cast(Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_PLUGIN, plugin))->getProps(); + PropProp* prop; + + for (int i = 0; i < props.size(); i++) { + Prop* propEntry = props[i]; + String caption = propEntry->name; + + switch (propEntry->type) { + case PropProp::PROP_VECTOR3: + prop = new Vector3Prop(caption); + dynamic_cast(prop)->set(Vector3(entity->getEntityPropNumberByName(plugin + caption + "x"), entity->getEntityPropNumberByName(plugin + caption + "y"), entity->getEntityPropNumberByName(plugin + caption + "z"))); + break; + case PropProp::PROP_VECTOR2: + prop = new Vector2Prop(caption); + dynamic_cast(prop)->set(Vector2(entity->getEntityPropNumberByName(plugin + caption + "x"), entity->getEntityPropNumberByName(plugin + caption + "y"))); + break; + case PropProp::PROP_SLIDER: + prop = new SliderProp(caption, entity->getEntityPropNumberByName(plugin + caption + "min"), entity->getEntityPropNumberByName(plugin + caption + "max")); + dynamic_cast(prop)->set(entity->getEntityPropNumberByName(plugin + caption)); + break; + //case PropProp::PROP_BUTTON: + // prop = new ButtonProp(caption); + // break; + case PropProp::PROP_NUMBER: + prop = new NumberProp(caption); + prop->setPropData(PropDataNumber(entity->getEntityPropNumberByName(plugin + caption))); + break; + //case PropProp::PROP_TARGET_BINDING: + // Shader *shader = ((Shader*)Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_SHADER, entity->getEntityPropStringByName(plugin + caption))); + // Material *material = ((Material*)Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_MATERIAL, entity->getEntityPropStringByName(plugin + caption))); + // ShaderBinding *shaderBin = new ShaderBinding(shader); + // RenderTargetBinding *targetBin = new RenderTargetBinding(); + // + // prop = new TargetBindingProp(shader, material, shaderBin, targetBin); + // + // break; + //case PropProp::PROP_RENDER_TARGET: + // ShaderRenderTarget *renderTarget; + // Material *material; + // prop = new RenderTargetProp(renderTarget, material); + // break; + //case PropProp::PROP_SHADER_PASS: + // prop = new ShaderPassProp(); + // break; + case PropProp::PROP_REMOVABLE_STRING: + prop = new RemovableStringProp(caption); + prop->setPropData(PropDataString(entity->getEntityPropStringByName(plugin + caption))); + break; + //case PropProp::PROP_LAYER: + // SceneEntityInstance *instance = new SceneEntityInstance(); + // prop = new LayerProp(); + // break; + case PropProp::PROP_STRING: + prop = new StringProp(caption); + ((StringProp*)prop)->set(entity->getEntityPropStringByName(plugin + caption)); + break; + case PropProp::PROP_COLOR: + prop = new ColorProp(caption); + ((ColorProp*)prop)->set(new Color(entity->getEntityPropNumberByName(plugin + caption + "r"), entity->getEntityPropNumberByName(plugin + caption + "g"), entity->getEntityPropNumberByName(plugin + caption + "b"), entity->getEntityPropNumberByName(plugin + caption + "a"))); + break; + case PropProp::PROP_COMBO: + prop = new ComboProp(caption); + for (int c = 0; c < propEntry->children.size(); c++) { + Prop* comboEntry = propEntry->children[c]; + ((ComboProp*)prop)->comboEntry->addComboItem(comboEntry->name, ((void*)comboEntry->value)); + } + for (int s = 0; s < ((ComboProp*)prop)->comboEntry->getNumItems(); s++){ + if (((int)((ComboProp*)prop)->comboEntry->getItemAtIndex(s)->data) == entity->getEntityPropIntByName(plugin + caption)){ + ((ComboProp*)prop)->comboEntry->setSelectedIndex(s); } - //for (int s = 0; s < ((ComboProp*)prop)->comboEntry->getNumItems(); s++){ - // if (((int)((ComboProp*)prop)->comboEntry->getItemAtIndex(s)->data) == entity->getEntityPropIntByName(plugin + caption)){ - // ((ComboProp*)prop)->comboEntry->setSelectedIndex(s); - // } - //} - ((ComboProp*)prop)->comboEntry->setSelectedIndex(entity->getEntityPropIntByName(plugin + caption)); - break; - case PropProp::PROP_BOOL: - prop = new BoolProp(caption); - ((BoolProp*)prop)->set(entity->getEntityPropBoolByName(plugin + caption)); - break; - case PropProp::PROP_SOUND: - prop = new SoundProp(caption); - ((SoundProp*)prop)->set(entity->getEntityPropStringByName(plugin + caption)); - break; + } + break; + case PropProp::PROP_BOOL: + prop = new BoolProp(caption); + ((BoolProp*)prop)->set(entity->getEntityPropBoolByName(plugin + caption)); + break; + case PropProp::PROP_SOUND: + prop = new SoundProp(caption); + ((SoundProp*)prop)->set(entity->getEntityPropStringByName(plugin + caption)); + break; //case PropProp::PROP_BEZIER_RGBA_CURVE: // prop = new BezierRGBACurveProp(caption); // for (int c = 0; c < entity->getEntityPropArrayByName(plugin + caption + "r").size(); c++) { @@ -2673,33 +2666,32 @@ void EntityPropSheet::refreshProps() { // } // break; //case PropProp::PROP_BEZIER_CURVE: - //prop = new BezierCurveProp(caption, (*propEntry)["curveName"]->stringVal); - //break; - case PropProp::PROP_MATERIAL: - prop = new MaterialProp(caption); - ((MaterialProp*)prop)->set(new Material(entity->getEntityPropStringByName(plugin + caption))); - break; - case PropProp::PROP_TEXTURE: - prop = new TextureProp(caption); - ((TextureProp*)prop)->set(((Texture*)Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_TEXTURE, entity->getEntityPropStringByName(plugin + caption)))); - break; - case PropProp::PROP_SCENE_SPRITE: - prop = new SceneSpriteProp(caption); - ((SceneSpriteProp*)prop)->set(((Sprite*)Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_SPRITE, entity->getEntityPropStringByName(plugin + caption)))); - break; - case PropProp::PROP_SCENE_ENTITY_INSTANCE: - prop = new SceneEntityInstanceProp(caption); - ((SceneEntityInstanceProp*)prop)->set(entity->getEntityPropStringByName(plugin + caption)); - break; - case PropProp::PROP_CUSTOM: - default: - prop = new CustomProp(caption, entity->getEntityPropStringByName(plugin + caption)); - break; - } - prop->addEventListener(this, Event::CHANGE_EVENT); - addProp(prop); - prop->Resize(getWidth(), prop->getHeight()); + //prop = new BezierCurveProp(caption, (*propEntry)["curveName"]->stringVal); + //break; + case PropProp::PROP_MATERIAL: + prop = new MaterialProp(caption); + ((MaterialProp*)prop)->set(new Material(entity->getEntityPropStringByName(plugin + caption))); + break; + case PropProp::PROP_TEXTURE: + prop = new TextureProp(caption); + ((TextureProp*)prop)->set(((Texture*)Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_TEXTURE, entity->getEntityPropStringByName(plugin + caption)))); + break; + case PropProp::PROP_SCENE_SPRITE: + prop = new SceneSpriteProp(caption); + ((SceneSpriteProp*)prop)->set(((Sprite*)Services()->getResourceManager()->getGlobalPool()->getResource(Resource::RESOURCE_SPRITE, entity->getEntityPropStringByName(plugin + caption)))); + break; + case PropProp::PROP_SCENE_ENTITY_INSTANCE: + prop = new SceneEntityInstanceProp(caption); + ((SceneEntityInstanceProp*)prop)->set(entity->getEntityPropStringByName(plugin + caption)); + break; + case PropProp::PROP_CUSTOM: + default: + prop = new CustomProp(caption, entity->getEntityPropStringByName(plugin + caption)); + break; } + prop->addEventListener(this, Event::CHANGE_EVENT); + addProp(prop); + prop->Resize(getWidth(), prop->getHeight()); } if(lastNumProps != entity->entityProps.size()) { From ef6149e30de4b45f0b812bfaa90c8e84ecef6c04 Mon Sep 17 00:00:00 2001 From: Joachim Meyer Date: Fri, 12 Sep 2014 20:39:15 +0200 Subject: [PATCH 12/19] (Re-)adding pluginEditor icons, Fixing problems with more than one plugin in the editor - but warning: loading plugins seems broken! Conflicts: Core/Contents/Include/PolyEntity.h Core/Contents/Include/PolyPlugin.h Core/Contents/Source/PolyPlugin.cpp IDE/Contents/Source/PolycodeEntityEditor.cpp IDE/Contents/Source/PolycodePluginEditor.cpp IDE/Contents/Source/PolycodeProps.cpp --- Core/Contents/Include/PolyEntity.h | 3 +-- Core/Contents/Include/PolyPlugin.h | 7 ++----- Core/Contents/Source/PolyPlugin.cpp | 20 +++++--------------- IDE/Contents/Include/PolycodePluginEditor.h | 2 +- IDE/Contents/Source/PolycodeEntityEditor.cpp | 6 +----- IDE/Contents/Source/PolycodePluginEditor.cpp | 7 +++---- IDE/Contents/Source/PolycodeProps.cpp | 17 ++++++++++++----- 7 files changed, 25 insertions(+), 37 deletions(-) diff --git a/Core/Contents/Include/PolyEntity.h b/Core/Contents/Include/PolyEntity.h index b9c141201..5d13e0e44 100755 --- a/Core/Contents/Include/PolyEntity.h +++ b/Core/Contents/Include/PolyEntity.h @@ -44,8 +44,7 @@ namespace Polycode { bool blocked; }; - class _PolyExport EntityProp : public PolyBase { - public: + class _PolyExport EntityProp : public PolyBase { public: EntityProp(const String& name, const unsigned int& type = EntityProp::PROP_STRING); int type; diff --git a/Core/Contents/Include/PolyPlugin.h b/Core/Contents/Include/PolyPlugin.h index dc1c9b889..8b229547c 100644 --- a/Core/Contents/Include/PolyPlugin.h +++ b/Core/Contents/Include/PolyPlugin.h @@ -35,10 +35,9 @@ namespace Polycode { ~Prop(); Prop *loadPropFromEntry(ObjectEntry* entry); - + int type; - String name; int value; @@ -66,8 +65,7 @@ namespace Polycode { static const int PROP_MATERIAL_PREVIEW = 19; static const int PROP_TEXTURE = 20; static const int PROP_SCENE_SPRITE = 21; - static const int PROP_SCENE_ENTITY_INSTANCE = 22; - }; + static const int PROP_SCENE_ENTITY_INSTANCE = 22; }; class _PolyExport Plugin : public Resource { public: @@ -77,7 +75,6 @@ namespace Polycode { Plugin* loadPluginFromEntry(ObjectEntry *entry); - void addProp(Prop* prop); void setProp(Prop* prop); void removeProp(Prop* prop); diff --git a/Core/Contents/Source/PolyPlugin.cpp b/Core/Contents/Source/PolyPlugin.cpp index 83109789c..c90a28e18 100644 --- a/Core/Contents/Source/PolyPlugin.cpp +++ b/Core/Contents/Source/PolyPlugin.cpp @@ -52,22 +52,18 @@ Plugin* Plugin::loadPluginFromEntry(ObjectEntry* entry){ if ((*entry)["fileext"]) this->ext = (*entry)["fileext"]->stringVal; - //if ((*entry)["sheet"] && (*(*entry)["sheet"])["props"]) - // this->sheetEntry = (*entry)["sheet"]; - if ((*entry)["type"]) this->pluginType = (*entry)["type"]->intVal; if ((*entry)["sheet"]){ ObjectEntry* sheetEntry = (*entry)["sheet"]; if ((*sheetEntry)["props"]){ - ObjectEntry* propsEntry = (*sheetEntry)["props"]; - if (propsEntry) { - for (int k = 0; k < propsEntry->children.size(); k++) { - ObjectEntry* propEntry = propsEntry->children[k]; + ObjectEntry* props = (*sheetEntry)["props"]; + if (props) { + for (int k = 0; k < props->children.size(); k++) { + ObjectEntry* propEntry = props->children[k]; if (!propEntry || propEntry->name != "prop") continue; - Prop *prop = new Prop(propEntry); this->setProp(prop); } @@ -82,10 +78,6 @@ unsigned int Plugin::getNumProps() const { return props.size(); } -void Plugin::addProp(Prop *prop) { - props.push_back(prop); -} - void Plugin::setProp(Prop *prop) { for (int i = 0; i < props.size(); i++) { if (props[i]->name == prop->name) { @@ -135,13 +127,11 @@ Prop::~Prop(){} Prop* Prop::loadPropFromEntry(ObjectEntry* entry){ if (!entry->readInt("type", &this->type)) return NULL; - if (!(*entry)["name"]) return NULL; this->name = (*entry)["name"]->stringVal; - if (type == Prop::PROP_COMBO){ - for (int i = 0; i < entry->children.size(); i++) { + if (type == Prop::PROP_COMBO){ for (int i = 0; i < entry->children.size(); i++) { if (entry->children[i]->name == "prop") { Prop* newProp = new Prop((*entry->children[i])["name"]->stringVal, Prop::PROP_COMBO); newProp->value = (*entry->children[i])["value"]->intVal; diff --git a/IDE/Contents/Include/PolycodePluginEditor.h b/IDE/Contents/Include/PolycodePluginEditor.h index 75a561c7e..ca3d20147 100644 --- a/IDE/Contents/Include/PolycodePluginEditor.h +++ b/IDE/Contents/Include/PolycodePluginEditor.h @@ -133,7 +133,7 @@ namespace Polycode { UIHSizer *mainSizer; PluginMainWindow *mainWindow; - std::vector plugins; + //std::vector plugins; UITree *selectedPluginNode; }; diff --git a/IDE/Contents/Source/PolycodeEntityEditor.cpp b/IDE/Contents/Source/PolycodeEntityEditor.cpp index 9f031fa2a..1f7df48d2 100644 --- a/IDE/Contents/Source/PolycodeEntityEditor.cpp +++ b/IDE/Contents/Source/PolycodeEntityEditor.cpp @@ -2529,11 +2529,7 @@ void PolycodeEntityEditor::savePropsToEntry(ObjectEntry *entry, std::vectoraddChild("value", props[i]->stringVal); break; - //case Prop::PROP_ARRAY: - // savePropsToEntry(prop, props[i]->arrayVal, props[i]->name); - // break; - case EntityProp::PROP_BOOL: - prop->addChild("value", props[i]->boolVal); + case EntityProp::PROP_BOOL: prop->addChild("value", props[i]->boolVal); break; case EntityProp::PROP_INT: prop->addChild("value", props[i]->intVal); diff --git a/IDE/Contents/Source/PolycodePluginEditor.cpp b/IDE/Contents/Source/PolycodePluginEditor.cpp index 2c7c8cfd8..d62fc3466 100644 --- a/IDE/Contents/Source/PolycodePluginEditor.cpp +++ b/IDE/Contents/Source/PolycodePluginEditor.cpp @@ -170,8 +170,7 @@ void PluginEditorPane::handleEvent(Event *event) { if (event->getDispatcher() == addPropButton->getButton()) { PropEditProp *newProp = new PropEditProp(new PropProp("", 0)); propsSheet->addProp(newProp); - currentPlugin->setProp(new Prop("", 0)); - newProp->addEventListener(this, Event::CHANGE_EVENT); + currentPlugin->setProp(new Prop("", 0)); newProp->addEventListener(this, Event::CHANGE_EVENT); newProp->addEventListener(this, Event::REMOVE_EVENT); newProp->propContents->setPositionX(padding); dispatchEvent(new Event(), Event::CHANGE_EVENT); @@ -184,10 +183,9 @@ void PluginEditorPane::handleEvent(Event *event) { } void PluginEditorPane::setPlugin(Plugin *plugin) { - for (int p = propsSheet->props.size(); p > 0; p--){ +for (int p = propsSheet->props.size(); p > 0; p--){ propsSheet->removeProp(propsSheet->props[p - 1]); } - changingPlugin = true; currentPlugin = plugin; @@ -208,6 +206,7 @@ void PluginEditorPane::setPlugin(Plugin *plugin) { } } + for (int p = 0; p < propsSheet->props.size(); p++){ propsSheet->props[p]->propContents->setPositionX(padding); } diff --git a/IDE/Contents/Source/PolycodeProps.cpp b/IDE/Contents/Source/PolycodeProps.cpp index abc4553fa..ec8fdac63 100644 --- a/IDE/Contents/Source/PolycodeProps.cpp +++ b/IDE/Contents/Source/PolycodeProps.cpp @@ -2428,9 +2428,7 @@ EntityPropSheet::EntityPropSheet(Plugin* plugin) : PropSheet(plugin->getResource - //if (plugin->sheetEntry) - refreshProps(); -} + refreshProps();} void EntityPropSheet::applyPropActionData(PolycodeEditorPropActionData *data) { if(!entity) @@ -2586,7 +2584,7 @@ void EntityPropSheet::refreshProps() { Prop* propEntry = props[i]; String caption = propEntry->name; - switch (propEntry->type) { + switch (propEntry->type) { case PropProp::PROP_VECTOR3: prop = new Vector3Prop(caption); dynamic_cast(prop)->set(Vector3(entity->getEntityPropNumberByName(plugin + caption + "x"), entity->getEntityPropNumberByName(plugin + caption + "y"), entity->getEntityPropNumberByName(plugin + caption + "z"))); @@ -2596,7 +2594,15 @@ void EntityPropSheet::refreshProps() { dynamic_cast(prop)->set(Vector2(entity->getEntityPropNumberByName(plugin + caption + "x"), entity->getEntityPropNumberByName(plugin + caption + "y"))); break; case PropProp::PROP_SLIDER: - prop = new SliderProp(caption, entity->getEntityPropNumberByName(plugin + caption + "min"), entity->getEntityPropNumberByName(plugin + caption + "max")); + Number min, max; + for (int s = 0; s < propEntry->children.size(); s++){ + if (propEntry->children[s]->name == "min"){ + min = propEntry->children[s]->value; + } else if (propEntry->children[s]->name == "max"){ + max = propEntry->children[s]->value; + } + } + prop = new SliderProp(caption, min, max); dynamic_cast(prop)->set(entity->getEntityPropNumberByName(plugin + caption)); break; //case PropProp::PROP_BUTTON: @@ -2693,6 +2699,7 @@ void EntityPropSheet::refreshProps() { addProp(prop); prop->Resize(getWidth(), prop->getHeight()); } + if(lastNumProps != entity->entityProps.size()) { dispatchEvent(new Event(), Event::COMPLETE_EVENT); From 669183431bb3d2f80a9c4275328efb70aa0a7372 Mon Sep 17 00:00:00 2001 From: Joachim Meyer Date: Sat, 13 Sep 2014 14:50:38 +0200 Subject: [PATCH 13/19] Cleaned up a bit, added correct implementation of slider props (min and max values now editable in the PluginEditor), added setter and getter for start and end to UIHSlider. Conflicts: Core/Contents/Source/PolyPlugin.cpp --- Core/Contents/Include/PolyPlugin.h | 3 +- Core/Contents/Source/PolyEntity.cpp | 28 ---- Core/Contents/Source/PolyPlugin.cpp | 16 ++- IDE/Contents/Include/PolycodePluginEditor.h | 4 +- IDE/Contents/Include/PolycodeProps.h | 20 ++- IDE/Contents/Source/PolycodePluginEditor.cpp | 75 +++++++++-- IDE/Contents/Source/PolycodeProps.cpp | 130 ++++++++++++++----- Modules/Contents/UI/Include/PolyUIHSlider.h | 6 +- Modules/Contents/UI/Source/PolyUIHSlider.cpp | 13 ++ 9 files changed, 213 insertions(+), 82 deletions(-) diff --git a/Core/Contents/Include/PolyPlugin.h b/Core/Contents/Include/PolyPlugin.h index 8b229547c..640b53dbc 100644 --- a/Core/Contents/Include/PolyPlugin.h +++ b/Core/Contents/Include/PolyPlugin.h @@ -36,7 +36,6 @@ namespace Polycode { Prop *loadPropFromEntry(ObjectEntry* entry); - int type; String name; int value; @@ -88,7 +87,7 @@ namespace Polycode { static const unsigned int PLUGIN_ENTITY = 0; String ext; - //ObjectEntry *sheetEntry; + String author; protected: std::vector props; diff --git a/Core/Contents/Source/PolyEntity.cpp b/Core/Contents/Source/PolyEntity.cpp index 1749c7396..0a0601a9d 100755 --- a/Core/Contents/Source/PolyEntity.cpp +++ b/Core/Contents/Source/PolyEntity.cpp @@ -866,21 +866,6 @@ void Entity::setEntityProp(const String& propName, const bool& propVal) { entityProps.push_back(entityProp); } -//void Entity::setEntityProp(const String& propName, std::vector propVal) { -// -// for (int i = 0; i < entityProps.size(); i++) { -// if (entityProps[i]->name == propName) { -// entityProps[i]->arrayVal = propVal; -// entityProps[i]->type = EntityProp::PROP_ARRAY; -// return; -// } -// } -// -// EntityProp* entityProp = new EntityProp(propName, EntityProp::PROP_ARRAY); -// entityProp->arrayVal = propVal; -// entityProps.push_back(entityProp); -//} - void Entity::setEntityProp(EntityProp* prop){ for (int i = 0; i < entityProps.size(); i++) { if (entityProps[i] == prop) { @@ -928,19 +913,6 @@ String Entity::getEntityPropStringByName(const String& propName) const { return String("null"); } -//std::vector Entity::getEntityPropArrayByName(const String& propName) const { -// for (int i = 0; i < entityProps.size(); i++) { -// if (entityProps[i]->name == propName && entityProps[i]->type == EntityProp::PROP_ARRAY) { -// return entityProps[i]->arrayVal; -// } -// if (entityProps[i]->type == EntityProp::PROP_ARRAY) { -// getEntityPropIntByName(propName); -// } -// } -// std::vector retVector; -// return retVector; -//} - bool Entity::isRequiredPlugin(const String& pluginName) const { for (int i = 0; i < requiredPlugins.size(); i++) { if (requiredPlugins[i]->getResourceName() == pluginName){ diff --git a/Core/Contents/Source/PolyPlugin.cpp b/Core/Contents/Source/PolyPlugin.cpp index c90a28e18..8357a80f7 100644 --- a/Core/Contents/Source/PolyPlugin.cpp +++ b/Core/Contents/Source/PolyPlugin.cpp @@ -35,7 +35,6 @@ Plugin::Plugin(const String& name) : Resource(Resource::RESOURCE_PLUGIN) { ext = ""; pluginType = 0; type = Resource::RESOURCE_PLUGIN; - //sheetEntry = NULL; } } @@ -45,13 +44,16 @@ Plugin::Plugin(ObjectEntry *entry) : Resource(Resource::RESOURCE_PLUGIN) { Plugin::~Plugin() {} -Plugin* Plugin::loadPluginFromEntry(ObjectEntry* entry){ +Plugin* Plugin::loadPluginFromEntry(ObjectEntry* entry){ if ((*entry)["name"]) this->setResourceName((*entry)["name"]->stringVal); + + if ((*entry)["author"]) + this->author = (*entry)["author"]->stringVal; if ((*entry)["fileext"]) this->ext = (*entry)["fileext"]->stringVal; - + if ((*entry)["type"]) this->pluginType = (*entry)["type"]->intVal; @@ -127,17 +129,19 @@ Prop::~Prop(){} Prop* Prop::loadPropFromEntry(ObjectEntry* entry){ if (!entry->readInt("type", &this->type)) return NULL; + if (!(*entry)["name"]) return NULL; this->name = (*entry)["name"]->stringVal; - if (type == Prop::PROP_COMBO){ for (int i = 0; i < entry->children.size(); i++) { - if (entry->children[i]->name == "prop") { + if (type == Prop::PROP_COMBO || type == Prop::PROP_SLIDER){ + for (int i = 0; i < entry->children.size(); i++) { if (entry->children[i]->name == "prop") { Prop* newProp = new Prop((*entry->children[i])["name"]->stringVal, Prop::PROP_COMBO); newProp->value = (*entry->children[i])["value"]->intVal; children.push_back(newProp); } } + + return this; } - return this; } \ No newline at end of file diff --git a/IDE/Contents/Include/PolycodePluginEditor.h b/IDE/Contents/Include/PolycodePluginEditor.h index ca3d20147..cdfcfcdfd 100644 --- a/IDE/Contents/Include/PolycodePluginEditor.h +++ b/IDE/Contents/Include/PolycodePluginEditor.h @@ -90,14 +90,12 @@ namespace Polycode { PropSheet *propsSheet; StringProp* nameProp; + StringProp* author; StringProp* newPropName; ButtonProp* addPropButton; int padding; - - //std::vector editProps; - //std::vector props; }; class PluginMainWindow : public UIElement { diff --git a/IDE/Contents/Include/PolycodeProps.h b/IDE/Contents/Include/PolycodeProps.h index 8df69f438..a6d8c932a 100644 --- a/IDE/Contents/Include/PolycodeProps.h +++ b/IDE/Contents/Include/PolycodeProps.h @@ -77,6 +77,7 @@ class PropProp : public UIElement { static const int PROP_SCENE_ENTITY_INSTANCE = 22; static const int PROP_EDIT = 23; static const int PROP_COMBO_EDIT = 24; + static const int PROP_SLIDER_EDIT = 25; }; class Vector3Prop : public PropProp { @@ -284,7 +285,7 @@ class CustomProp : public PropProp { UITextInput *keyEntry; UITextInput *valueEntry; - UIImageButton *removeButton; + //UIImageButton *removeButton; }; class StringProp : public PropProp { @@ -495,6 +496,22 @@ class SceneEntityInstanceProp : public PropProp { }; +class SliderEditProp : public PropProp { +public: + SliderEditProp(SliderProp* newSlider); + ~SliderEditProp(); + void handleEvent(Event *event); + + void set(SliderProp *newCombo); + SliderProp *get(); + + StringProp *minProp; + StringProp *maxProp; + + SliderProp *lastSlider; + SliderProp *currentSlider; +}; + class ComboPropEditProp : public PropProp { public: ComboPropEditProp(ComboProp* newCombo); @@ -532,6 +549,7 @@ class PropEditProp : public PropProp { PropProp *currentProp; ComboPropEditProp *comboEditProp; + SliderEditProp *sliderEditProp; UITextInput *nameInput; UIComboBox *typeChooser; diff --git a/IDE/Contents/Source/PolycodePluginEditor.cpp b/IDE/Contents/Source/PolycodePluginEditor.cpp index d62fc3466..9762382e8 100644 --- a/IDE/Contents/Source/PolycodePluginEditor.cpp +++ b/IDE/Contents/Source/PolycodePluginEditor.cpp @@ -104,10 +104,14 @@ PluginEditorPane::PluginEditorPane(ResourcePool *resourcePool) : UIElement() { PropSheet *baseProps = new PropSheet("PLUGIN SETTINGS", ""); propList->addPropSheet(baseProps); - nameProp = new StringProp("Name"); + nameProp = new StringProp("Name:"); baseProps->addProp(nameProp); nameProp->addEventListener(this, Event::CHANGE_EVENT); + author = new StringProp("Author:"); + baseProps->addProp(author); + author->addEventListener(this, Event::CHANGE_EVENT); + addPropButton = new ButtonProp("New Prop"); baseProps->addProp(addPropButton); addPropButton->getButton()->addEventListener(this, UIEvent::CLICK_EVENT); @@ -132,6 +136,11 @@ void PluginEditorPane::handleEvent(Event *event) { dispatchEvent(new Event(), Event::CHANGE_EVENT); } + if (event->getDispatcher() == author) { + currentPlugin->author = author->get(); + dispatchEvent(new Event(), Event::CHANGE_EVENT); + } + int maxPadding = 0; for (int p = 0; p < propsSheet->props.size(); p++){ if (event->getEventCode() == Event::CHANGE_EVENT && event->getDispatcher() == propsSheet->props[p]) { @@ -144,6 +153,14 @@ void PluginEditorPane::handleEvent(Event *event) { newProp->value = (int)((PropEditProp*)propsSheet->props[p])->comboEditProp->currentCombo->comboEntry->getItemAtIndex(c)->data; currentPlugin->getProps()[p]->children.push_back(newProp); } + } else if (currentPlugin->getProps()[p]->type == Prop::PROP_SLIDER){ + currentPlugin->getProps()[p]->children.clear(); + Prop* newProp = new Prop("min", Prop::PROP_SLIDER); + newProp->value = ((PropEditProp*)propsSheet->props[p])->sliderEditProp->currentSlider->slider->getStart(); + currentPlugin->getProps()[p]->children.push_back(newProp); + newProp = new Prop("max", Prop::PROP_SLIDER); + newProp->value = ((PropEditProp*)propsSheet->props[p])->sliderEditProp->currentSlider->slider->getEnd(); + currentPlugin->getProps()[p]->children.push_back(newProp); } dispatchEvent(new Event(), Event::CHANGE_EVENT); } @@ -155,7 +172,7 @@ void PluginEditorPane::handleEvent(Event *event) { if (event->getEventCode() == Event::REMOVE_EVENT && event->getDispatcher() == propsSheet->props[p]){ currentPlugin->removeProp(propsSheet->props[p]->getPropName()); propsSheet->removeProp(propsSheet->props[p]); - dispatchEvent(new Event(), Event::REMOVE_EVENT); + dispatchEvent(new Event(), Event::CHANGE_EVENT); } } @@ -170,7 +187,8 @@ void PluginEditorPane::handleEvent(Event *event) { if (event->getDispatcher() == addPropButton->getButton()) { PropEditProp *newProp = new PropEditProp(new PropProp("", 0)); propsSheet->addProp(newProp); - currentPlugin->setProp(new Prop("", 0)); newProp->addEventListener(this, Event::CHANGE_EVENT); + currentPlugin->setProp(new Prop("", 0)); + newProp->addEventListener(this, Event::CHANGE_EVENT); newProp->addEventListener(this, Event::REMOVE_EVENT); newProp->propContents->setPositionX(padding); dispatchEvent(new Event(), Event::CHANGE_EVENT); @@ -191,18 +209,32 @@ for (int p = propsSheet->props.size(); p > 0; p--){ currentPlugin = plugin; nameProp->set(plugin->getResourceName()); - + author->set(plugin->author); + for (int p = 0; p < plugin->getProps().size(); p++) { Prop* propEntry = plugin->getProps()[p]; - if (propEntry->type != PropProp::PROP_COMBO){ - setProp(propEntry->name, new PropProp(propEntry->name, propEntry->type)); - } else { + if (propEntry->type == PropProp::PROP_COMBO){ ComboProp *newComboProp = new ComboProp(propEntry->name); for (int c = 0; c < propEntry->children.size(); c++){ Prop *comboEntry = propEntry->children[c]; newComboProp->comboEntry->addComboItem(comboEntry->name, (void*)comboEntry->value); } setProp(newComboProp->getPropName(), newComboProp); + } else if (propEntry->type == PropProp::PROP_SLIDER) { + SliderProp *newSliderProp = new SliderProp(propEntry->name, 0, 0); + Number min, max; + for (int s = 0; s < propEntry->children.size(); s++){ + Prop *sliderEntry = propEntry->children[s]; + if (sliderEntry->name == "min"){ + min = sliderEntry->value; + } else if (sliderEntry->name == "max"){ + max = sliderEntry->value; + } + } + newSliderProp->slider->setStartEnd(min, max); + setProp(newSliderProp->getPropName(), newSliderProp); + } else { + setProp(propEntry->name, new PropProp(propEntry->name, propEntry->type)); } } @@ -245,6 +277,14 @@ void PluginEditorPane::setProp(const String& name, PropProp* prop){ newProp->value = (int)((ComboProp*)prop)->comboEntry->getItemAtIndex(c)->data; currentPlugin->getProps()[i]->children.push_back(newProp); } + } else if (currentPlugin->getProps()[i]->type == Prop::PROP_SLIDER){ + currentPlugin->getProps()[i]->children.clear(); + Prop* newProp = new Prop("min", Prop::PROP_SLIDER); + newProp->value = ((SliderProp*)prop)->slider->getStart(); + currentPlugin->getProps()[i]->children.push_back(newProp); + newProp = new Prop("max", Prop::PROP_SLIDER); + newProp->value = ((SliderProp*)prop)->slider->getEnd(); + currentPlugin->getProps()[i]->children.push_back(newProp); } return; } @@ -263,6 +303,13 @@ void PluginEditorPane::setProp(const String& name, PropProp* prop){ comboProp->value = (int)((ComboProp*)prop)->comboEntry->getItemAtIndex(c)->data; pProp->children.push_back(comboProp); } + } else if (prop->propType == Prop::PROP_SLIDER){ + Prop* sliderProp = new Prop("min", Prop::PROP_SLIDER); + sliderProp->value = ((SliderProp*)prop)->slider->getStart(); + pProp->children.push_back(sliderProp); + sliderProp = new Prop("max", Prop::PROP_SLIDER); + sliderProp->value = ((SliderProp*)prop)->slider->getEnd(); + pProp->children.push_back(sliderProp); } currentPlugin->setProp(pProp); } @@ -355,11 +402,11 @@ void PolycodePluginEditor::saveFile() { void PolycodePluginEditor::savePluginToObjectEntry(Plugin* plugin, ObjectEntry* entry) { entry->addChild("name", plugin->getResourceName()); + entry->addChild("author", plugin->author); entry->addChild("fileext", plugin->ext); entry->addChild("type", (int)plugin->pluginType); ObjectEntry* sheetEntry = entry->addChild("sheet"); - //sheetEntry->addChild("name", plugin->getSheetName()); ObjectEntry* propsEntry = sheetEntry->addChild("props"); std::vector props = plugin->getProps(); for (int i = 0; i < props.size(); i++) { @@ -372,6 +419,18 @@ void PolycodePluginEditor::savePluginToObjectEntry(Plugin* plugin, ObjectEntry* comboEntry->addChild("name", props[i]->children[c]->name); comboEntry->addChild("value", props[i]->children[c]->value); } + } else if (props[i]->type == PropProp::PROP_SLIDER){ + for (int s = 0; s < props[i]->children.size(); s++){ + if (props[i]->children[s]->name == "min"){ + ObjectEntry* min = propEntry->addChild("prop"); + min->addChild("name", props[i]->children[s]->name); + min->addChild("value", props[i]->children[s]->value); + } else if (props[i]->children[s]->name == "max"){ + ObjectEntry* max = propEntry->addChild("prop"); + max->addChild("name", props[i]->children[s]->name); + max->addChild("value", props[i]->children[s]->value); + } + } } } } diff --git a/IDE/Contents/Source/PolycodeProps.cpp b/IDE/Contents/Source/PolycodeProps.cpp index ec8fdac63..2285e65a7 100644 --- a/IDE/Contents/Source/PolycodeProps.cpp +++ b/IDE/Contents/Source/PolycodeProps.cpp @@ -715,22 +715,17 @@ void LayerProp::setPropWidth(Number width) { } CustomProp::CustomProp(String key, String value) : PropProp("", PropProp::PROP_CUSTOM) { - keyEntry = new UITextInput(false, 120, 12); + keyEntry = new UITextInput(false, 130, 12); keyEntry->setText(key); keyEntry->addEventListener(this, UIEvent::CHANGE_EVENT); propContents->addChild(keyEntry); - keyEntry->setPosition(-90, 0); + keyEntry->setPosition(-110, 0); - valueEntry = new UITextInput(false, 120, 12); + valueEntry = new UITextInput(false, 140, 12); valueEntry->setText(value); valueEntry->addEventListener(this, UIEvent::CHANGE_EVENT); propContents->addChild(valueEntry); - valueEntry->setPosition(45, 0); - - removeButton = new UIImageButton("main/remove_icon.png", 1.0, 12, 12); - removeButton->addEventListener(this, UIEvent::CLICK_EVENT); - propContents->addChild(removeButton); - removeButton->setPosition(-110, 6); + valueEntry->setPosition(55, 0); setHeight(25); @@ -746,7 +741,6 @@ void CustomProp::setPropWidth(Number width) { CustomProp::~CustomProp() { keyEntry->removeAllHandlersForListener(this); valueEntry->removeAllHandlersForListener(this); - removeButton->removeAllHandlersForListener(this); } void CustomProp::handleEvent(Event *event) { @@ -757,9 +751,6 @@ void CustomProp::handleEvent(Event *event) { dispatchEvent(new Event(), Event::CHANGE_EVENT); } - if(event->getDispatcher() == removeButton) { - dispatchEvent(new Event(), Event::CANCEL_EVENT); - } } } @@ -1947,6 +1938,19 @@ PropEditProp::PropEditProp(PropProp *newProp) : PropProp(newProp->getPropName(), comboEditProp->addEventListener(this, Event::CHANGE_EVENT); propContents->addChild(comboEditProp); comboEditProp->setPosition(-80, 60); + + if (currentValue != PropProp::PROP_SLIDER){ + sliderEditProp = new SliderEditProp(new SliderProp(nameInput->getText(), 0, 0)); + sliderEditProp->enabled = false; + sliderEditProp->visible = false; + setHeight(65); + } else { + sliderEditProp = new SliderEditProp(((SliderProp*)newProp)); + setHeight(65 + sliderEditProp->getHeight()); + } + sliderEditProp->addEventListener(this, Event::CHANGE_EVENT); + propContents->addChild(sliderEditProp); + sliderEditProp->setPosition(-80, 60); } PropEditProp::~PropEditProp(){} @@ -1960,15 +1964,27 @@ void PropEditProp::handleEvent(Event *event){ dispatchEvent(new Event(), Event::CHANGE_EVENT); dispatchEvent(new PropEvent(this, NULL, PropDataInt(lastValue), PropDataInt(currentValue)), PropEvent::EVENT_PROP_CHANGE); } + setHeight(80); if (currentValue == PropProp::PROP_COMBO){ comboEditProp->setPropName(nameInput->getText()); comboEditProp->set(comboEditProp->currentCombo); comboEditProp->enabled = true; comboEditProp->visible = true; - } else if (lastValue == PropProp::PROP_COMBO && currentValue != PropProp::PROP_COMBO){ + setHeight(80 + comboEditProp->getHeight()); + } else if (lastValue == PropProp::PROP_COMBO){ comboEditProp->enabled = false; comboEditProp->visible = false; } + if (currentValue == PropProp::PROP_SLIDER){ + sliderEditProp->setPropName(nameInput->getText()); + sliderEditProp->set(sliderEditProp->currentSlider); + sliderEditProp->enabled = true; + sliderEditProp->visible = true; + setHeight(80 + sliderEditProp->getHeight()); + } else if (lastValue == PropProp::PROP_SLIDER){ + sliderEditProp->enabled = false; + sliderEditProp->visible = false; + } } } if (event->getDispatcher() == nameInput) { @@ -1990,6 +2006,16 @@ void PropEditProp::handleEvent(Event *event){ } } } + + if (event->getDispatcher() == sliderEditProp){ + if (event->getEventCode() == Event::CHANGE_EVENT) { + setHeight(80 + sliderEditProp->getHeight()); + if (!suppressChangeEvent) { + dispatchEvent(new Event(), Event::CHANGE_EVENT); + } + } + } + if (event->getDispatcher() == delButton) { dispatchEvent(new Event(), Event::REMOVE_EVENT); } @@ -1999,10 +2025,19 @@ void PropEditProp::set(PropProp *newProp){ currentProp = newProp; nameInput->setText(newProp->getPropName()); typeChooser->setSelectedIndex(newProp->propType); + setHeight(80); if (newProp->propType != PropProp::PROP_COMBO){ comboEditProp->set(new ComboProp(nameInput->getText())); } else { comboEditProp->set(((ComboProp*)newProp)); + setHeight(80 + comboEditProp->getHeight()); + } + + if (newProp->propType != PropProp::PROP_SLIDER){ + sliderEditProp->set(new SliderProp(nameInput->getText(), 0, 0)); + } else { + sliderEditProp->set((SliderProp*)newProp); + setHeight(80 + sliderEditProp->getHeight()); } } @@ -2090,8 +2125,6 @@ void ComboPropEditProp::handleEvent(Event *event){ } if (items[i] == event->getDispatcher()) { - //items[i]->enabled = false; - //items[i]->visible = false; propContents->removeChild(items[i]); items[i]->removeAllHandlersForListener(this); @@ -2132,7 +2165,7 @@ void ComboPropEditProp::set(ComboProp *newCombo){ items.push_back(newProp); StringProp *newDataProp = new StringProp("Data:"); - newDataProp->set(((int)currentCombo->comboEntry->getItemAtIndex(c)->data)); + newDataProp->set(String::IntToString((int)currentCombo->comboEntry->getItemAtIndex(c)->data)); newDataProp->stringEntry->setPosition(-70, 0); newDataProp->stringEntry->Resize(40, newDataProp->stringEntry->getHeight()); newDataProp->stringEntry->setNumberOnly(true); @@ -2148,6 +2181,52 @@ ComboProp *ComboPropEditProp::get(){ return currentCombo; } +SliderEditProp::SliderEditProp(SliderProp* newSlider) : PropProp("", PropProp::PROP_COMBO_EDIT){ + minProp = new StringProp("Min:"); + minProp->stringEntry->setNumberOnly(true); + minProp->set(String::NumberToString(newSlider->slider->getStart(), 1)); + minProp->addEventListener(this, Event::CHANGE_EVENT); + propContents->addChild(minProp); + minProp->setPosition(10, 0); + + maxProp = new StringProp("Max:"); + maxProp->stringEntry->setNumberOnly(true); + maxProp->set(String::NumberToString(newSlider->slider->getEnd(), 1)); + maxProp->addEventListener(this, Event::CHANGE_EVENT); + propContents->addChild(maxProp); + maxProp->setPosition(10, 30); + + label->enabled = false; + label->visible = false; + + currentSlider = newSlider; + + setWidth(100); + setHeight(60); +} + +SliderEditProp::~SliderEditProp(){} + +void SliderEditProp::handleEvent(Event *event){ + if (event->getDispatcher() == minProp || event->getDispatcher() == maxProp){ + lastSlider = currentSlider; + currentSlider->slider->setStartEnd(minProp->get().toNumber(), maxProp->get().toNumber()); + dispatchEvent(new Event, Event::CHANGE_EVENT); + } +} + +void SliderEditProp::set(SliderProp *newSlider){ + lastSlider = currentSlider; + currentSlider = newSlider; + + minProp->set(String::NumberToString(currentSlider->slider->getStart(), 1)); + maxProp->set(String::NumberToString(currentSlider->slider->getEnd(), 1)); +} + +SliderProp *SliderEditProp::get(){ + return currentSlider; +} + ShaderPassesSheet::ShaderPassesSheet(ResourcePool *resourcePool) : PropSheet("SHADER PASSES", "shaderPasses") { this->resourcePool = resourcePool; propHeight = 70; @@ -2425,9 +2504,7 @@ EntityPropSheet::EntityPropSheet(Plugin* plugin) : PropSheet(plugin->getResource lastNumProps = 0; removeIndex = -1; enabled = false; - - - + refreshProps();} void EntityPropSheet::applyPropActionData(PolycodeEditorPropActionData *data) { @@ -2456,21 +2533,8 @@ void EntityPropSheet::handleEvent(Event *event) { case Event::CHANGE_EVENT: PolycodeEditorPropActionData *beforeData = PropDataEntity(entity); if(i <= entity->entityProps.size()) { - - //std::vector propsVector; - EntityProp* prop; - switch (props[i]->propType) { case PropProp::PROP_VECTOR3: - //prop = new EntityProp(plugin + props[i]->getPropName() + "x", Prop::PROP_NUMBER); - //prop->numberVal = ((Vector3Prop*)props[i])->get().x; - ////propsVector.push_back(prop); - //prop = new EntityProp(plugin + props[i]->getPropName() + "y", Prop::PROP_NUMBER); - //prop->numberVal = ((Vector3Prop*)props[i])->get().y; - ////propsVector.push_back(prop); - //prop = new EntityProp(plugin + props[i]->getPropName() + "z", Prop::PROP_NUMBER); - //prop->numberVal = ((Vector3Prop*)props[i])->get().z; - //propsVector.push_back(prop); entity->setEntityProp(plugin + props[i]->getPropName() + "x", ((Vector3Prop*)props[i])->get().x); entity->setEntityProp(plugin + props[i]->getPropName() + "y", ((Vector3Prop*)props[i])->get().y); entity->setEntityProp(plugin + props[i]->getPropName() + "z", ((Vector3Prop*)props[i])->get().z); diff --git a/Modules/Contents/UI/Include/PolyUIHSlider.h b/Modules/Contents/UI/Include/PolyUIHSlider.h index 500e04c37..80c74a9d2 100755 --- a/Modules/Contents/UI/Include/PolyUIHSlider.h +++ b/Modules/Contents/UI/Include/PolyUIHSlider.h @@ -46,7 +46,11 @@ namespace Polycode { void setContinuous(bool _continuous); void setSliderValue(Number val); - Number getSliderValue(); + Number getSliderValue(); + + void setStartEnd(Number start, Number end); + Number getStart(); + Number getEnd(); private: diff --git a/Modules/Contents/UI/Source/PolyUIHSlider.cpp b/Modules/Contents/UI/Source/PolyUIHSlider.cpp index 9dc3be2db..7e1df4018 100755 --- a/Modules/Contents/UI/Source/PolyUIHSlider.cpp +++ b/Modules/Contents/UI/Source/PolyUIHSlider.cpp @@ -102,6 +102,19 @@ void UIHSlider::setSliderValue(Number val) { } } +void UIHSlider::setStartEnd(Number start, Number end){ + startValue = start; + endValue = end; +} + +Number UIHSlider::getStart(){ + return startValue; +} + +Number UIHSlider::getEnd(){ + return endValue; +} + bool UIHSlider::isContinuous() { return continuous; } From 58450818953a37c74098f6453dcf7e05545dc4d0 Mon Sep 17 00:00:00 2001 From: Joachim Meyer Date: Mon, 15 Sep 2014 16:58:03 +0200 Subject: [PATCH 14/19] Added Plugin folder to IDE Resources, including PhysicsModul.plugin, IDE includes this as a resource. Added Constructor to CollisionEntity, that only needs an entity with entity props, according to the PhysicsModul.plugin. --- IDE/Contents/Source/PolycodeIDEApp.cpp | 1 + .../Include/PolyCollisionSceneEntity.h | 1 + .../Source/PolyCollisionSceneEntity.cpp | 50 +++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/IDE/Contents/Source/PolycodeIDEApp.cpp b/IDE/Contents/Source/PolycodeIDEApp.cpp index 32a8d062c..92e05d86f 100644 --- a/IDE/Contents/Source/PolycodeIDEApp.cpp +++ b/IDE/Contents/Source/PolycodeIDEApp.cpp @@ -73,6 +73,7 @@ PolycodeIDEApp::PolycodeIDEApp(PolycodeView *view) : EventDispatcher() { CoreServices::getInstance()->getResourceManager()->addArchive("UI.pak"); CoreServices::getInstance()->getResourceManager()->addDirResource("Materials"); + CoreServices::getInstance()->getResourceManager()->addDirResource("Plugins"); CoreServices::getInstance()->getFontManager()->registerFont("section", "Fonts/RobotoCondensed-Bold.ttf"); diff --git a/Modules/Contents/3DPhysics/Include/PolyCollisionSceneEntity.h b/Modules/Contents/3DPhysics/Include/PolyCollisionSceneEntity.h index c97ae679c..975d40cff 100755 --- a/Modules/Contents/3DPhysics/Include/PolyCollisionSceneEntity.h +++ b/Modules/Contents/3DPhysics/Include/PolyCollisionSceneEntity.h @@ -42,6 +42,7 @@ namespace Polycode { * Main constructor. */ CollisionEntity(Entity *entity, int type, bool compoundChildren = false); + CollisionEntity(Entity *entity); virtual ~CollisionEntity(); /** @name Collision scene entity diff --git a/Modules/Contents/3DPhysics/Source/PolyCollisionSceneEntity.cpp b/Modules/Contents/3DPhysics/Source/PolyCollisionSceneEntity.cpp index e60630b5f..cae660ec3 100755 --- a/Modules/Contents/3DPhysics/Source/PolyCollisionSceneEntity.cpp +++ b/Modules/Contents/3DPhysics/Source/PolyCollisionSceneEntity.cpp @@ -83,6 +83,56 @@ CollisionEntity::CollisionEntity(Entity *entity, int type, bool compoundChildren // } } +CollisionEntity::CollisionEntity(Entity *entity){ + this->entity = entity; + shape = NULL; + + this->type = entity->getEntityPropIntByName("Physics3DShape"); + enabled = true; + lastPosition = entity->getPosition(); + + + btMatrix3x3 basisA; + basisA.setIdentity(); + + collisionObject = new btCollisionObject(); + collisionObject->getWorldTransform().setBasis(basisA); + + if (entity->getEntityPropBoolByName("Physics3DComp Children?")) { + btCompoundShape* compoundShape = new btCompoundShape(); + + for (int i = 0; i < entity->getNumChildren(); i++) { + Entity *child = (Entity*)entity->getChildAtIndex(i); + btCollisionShape *childShape = createCollisionShape(child, child->collisionShapeType); + btTransform transform; + + child->rebuildTransformMatrix(); + + btScalar mat[16]; + Matrix4 ent_mat = child->getTransformMatrix(); + + for (int i = 0; i < 16; i++) { + mat[i] = ent_mat.ml[i]; + } + + transform.setFromOpenGLMatrix(mat); + compoundShape->addChildShape(transform, childShape); + } + + shape = compoundShape; + } else { + shape = createCollisionShape(entity, type); + } + + if (shape) { + collisionObject->setCollisionShape(shape); + } + + collisionObject->setUserPointer((void*)this); + + convexShape = dynamic_cast(shape); +} + btCollisionShape *CollisionEntity::createCollisionShape(Entity *entity, int type) { btCollisionShape *collisionShape = NULL; From ac31c126feab28c219a9ee1f434e681f7421bbba Mon Sep 17 00:00:00 2001 From: Joachim Meyer Date: Mon, 15 Sep 2014 16:59:06 +0200 Subject: [PATCH 15/19] Fix last commit: forgot to add PhysicsModul.plugin. --- .../Resources/Plugins/PhysicsModul.plugin | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 IDE/Contents/Resources/Plugins/PhysicsModul.plugin diff --git a/IDE/Contents/Resources/Plugins/PhysicsModul.plugin b/IDE/Contents/Resources/Plugins/PhysicsModul.plugin new file mode 100644 index 000000000..a16c0b733 --- /dev/null +++ b/IDE/Contents/Resources/Plugins/PhysicsModul.plugin @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 0c011aeafa6e0ca829265b1b10e671b2cc1f4e79 Mon Sep 17 00:00:00 2001 From: Joachim Meyer Date: Tue, 23 Sep 2014 22:12:35 +0200 Subject: [PATCH 16/19] Fixed some issues, added addPhysicsChildEntity and addCollisionChildEntity, both take just an Entity loaded from a SceneEntityInstance, according to PhysicsModule.plugin --- Core/Contents/Source/PolyEntity.cpp | 13 +++++-- .../Source/PolySceneEntityInstance.cpp | 17 +++------- IDE/Build/Windows2013/Polycode.rc | Bin 12372 -> 12374 bytes .../Resources/Plugins/PhysicsModul.plugin | 22 +++++++++++- IDE/Contents/Source/PolycodeEntityEditor.cpp | 6 ++-- IDE/Contents/Source/PolycodePluginEditor.cpp | 4 ++- IDE/Contents/Source/PolycodeProps.cpp | 9 +++-- .../2DPhysics/Include/PolyPhysicsScreen.h | 15 +++++++- .../2DPhysics/Source/PolyPhysicsScreen.cpp | 14 ++++++++ .../3DPhysics/Include/PolyCollisionScene.h | 3 +- .../3DPhysics/Include/PolyPhysicsScene.h | 3 +- .../Include/PolyPhysicsSceneEntity.h | 1 + .../3DPhysics/Source/PolyCollisionScene.cpp | 9 +++++ .../Source/PolyCollisionSceneEntity.cpp | 4 +-- .../3DPhysics/Source/PolyPhysicsScene.cpp | 9 +++++ .../Source/PolyPhysicsSceneEntity.cpp | 32 ++++++++++++++++++ 16 files changed, 131 insertions(+), 30 deletions(-) diff --git a/Core/Contents/Source/PolyEntity.cpp b/Core/Contents/Source/PolyEntity.cpp index 0a0601a9d..a7c302248 100755 --- a/Core/Contents/Source/PolyEntity.cpp +++ b/Core/Contents/Source/PolyEntity.cpp @@ -868,7 +868,7 @@ void Entity::setEntityProp(const String& propName, const bool& propVal) { void Entity::setEntityProp(EntityProp* prop){ for (int i = 0; i < entityProps.size(); i++) { - if (entityProps[i] == prop) { + if (entityProps[i]->name == prop->name) { entityProps[i] = prop; return; } @@ -881,14 +881,18 @@ int Entity::getEntityPropIntByName(const String& propName) const { for (int i = 0; i < entityProps.size(); i++) { if (entityProps[i]->name == propName && entityProps[i]->type == EntityProp::PROP_INT) { return entityProps[i]->intVal; + } else if (entityProps[i]->name == propName && entityProps[i]->type == EntityProp::PROP_NUMBER){ + return entityProps[i]->numberVal; } } - return false; + return 0; } Number Entity::getEntityPropNumberByName(const String& propName) const { for (int i = 0; i < entityProps.size(); i++) { - if (entityProps[i]->name == propName && entityProps[i]->type == EntityProp::PROP_NUMBER) { + if (entityProps[i]->name == propName && entityProps[i]->type == EntityProp::PROP_INT) { + return entityProps[i]->intVal; + } else if (entityProps[i]->name == propName && entityProps[i]->type == EntityProp::PROP_NUMBER){ return entityProps[i]->numberVal; } } @@ -1369,6 +1373,9 @@ void Entity::addPluginByName(const String& pluginName, ResourcePool *resourcePoo } requiredPlugins.push_back(plugin); + for (int p = 0; p < plugin->getNumProps(); p++){ + setEntityProp(plugin->getResourceName() + plugin->getProps()[p]->name, 0); + } } } diff --git a/Core/Contents/Source/PolySceneEntityInstance.cpp b/Core/Contents/Source/PolySceneEntityInstance.cpp index 73b3138bd..be02dc9c6 100644 --- a/Core/Contents/Source/PolySceneEntityInstance.cpp +++ b/Core/Contents/Source/PolySceneEntityInstance.cpp @@ -573,15 +573,6 @@ Entity *SceneEntityInstance::loadObjectEntryIntoEntity(ObjectEntry *entry, Entit } } } else { - //ObjectEntry *plugins = (*entry)["requiredPlugins"]; - //if (plugins) { - // for (int p = 0; p < plugins->children.size(); p++) { - // if (plugins->children[p]->name == "requiredPlugin") { - // String requiredPlugin = (*plugins->children[p])["name"]->stringVal; - // entity->addPluginByName(requiredPlugin); - // } - // } - //} ObjectEntry *plugins = (*entry)["plugins"]; if (plugins){ for (int p = 0; p < plugins->children.size(); p++) { @@ -592,9 +583,11 @@ Entity *SceneEntityInstance::loadObjectEntryIntoEntity(ObjectEntry *entry, Entit entity->addPluginByName(pluginName); ObjectEntry *props = (*plugin)["props"]; - std::vector entProps = parseObjectEntryIntoProps(props, pluginName); - for (int i = 0; i < entProps.size(); i++){ - entity->entityProps.push_back(entProps[i]); + if (props){ + std::vector entProps = parseObjectEntryIntoProps(props, pluginName); + for (int i = 0; i < entProps.size(); i++){ + entity->setEntityProp(entProps[i]); + } } } } diff --git a/IDE/Build/Windows2013/Polycode.rc b/IDE/Build/Windows2013/Polycode.rc index 8f4b134a13c79fbd72ebd3d693dc9115234130d4..a629c414f3c1e64b277b082ec0f74af0672f968c 100644 GIT binary patch delta 62 zcmV-E0Kxy%VAf!;Y6c5;0BHbj0Av7f0C%%<2B{sBAPfwXBqS7*1}PGgup>T`j3hXd U@F-4`pdAXcj3goivpy*n2Z?|a-~a#s delta 44 zcmcbXa3x_w78_?GLmEQ`LlHyj=2EtmvXdK>3pUHCDzQv1Q0JK3qtdb2K~sz!0AOYg AmH+?% diff --git a/IDE/Contents/Resources/Plugins/PhysicsModul.plugin b/IDE/Contents/Resources/Plugins/PhysicsModul.plugin index a16c0b733..f0c2232d0 100644 --- a/IDE/Contents/Resources/Plugins/PhysicsModul.plugin +++ b/IDE/Contents/Resources/Plugins/PhysicsModul.plugin @@ -18,6 +18,26 @@ + + + + + + + + + + + + + + + + + + + + @@ -38,7 +58,7 @@ - + diff --git a/IDE/Contents/Source/PolycodeEntityEditor.cpp b/IDE/Contents/Source/PolycodeEntityEditor.cpp index 1f7df48d2..14f49d19a 100644 --- a/IDE/Contents/Source/PolycodeEntityEditor.cpp +++ b/IDE/Contents/Source/PolycodeEntityEditor.cpp @@ -1329,9 +1329,9 @@ void EntityEditorMainView::deleteSelected(bool doAction) { selectedEntities[i]->setOwnsChildrenRecursive(true); for(int j=0; j < icons.size(); j++) { if(icons[j]->getUserData() == selectedEntities[i]) { - delete icons[j]; - icons[j]->getParentEntity()->removeChild(icons[j]); - icons.erase(icons.begin()+j); + icons[j]->getParentEntity()->removeChild(icons[j]); + delete icons[j]; + icons.erase(icons.begin()+j); break; } } diff --git a/IDE/Contents/Source/PolycodePluginEditor.cpp b/IDE/Contents/Source/PolycodePluginEditor.cpp index 9762382e8..0b542a0ef 100644 --- a/IDE/Contents/Source/PolycodePluginEditor.cpp +++ b/IDE/Contents/Source/PolycodePluginEditor.cpp @@ -122,6 +122,7 @@ PluginEditorPane::PluginEditorPane(ResourcePool *resourcePool) : UIElement() { propList->addPropSheet(propsSheet); propList->updateProps(); + propList->Resize(propList->getWidth(), propList->getHeight()); enabled = false; } @@ -201,7 +202,7 @@ void PluginEditorPane::handleEvent(Event *event) { } void PluginEditorPane::setPlugin(Plugin *plugin) { -for (int p = propsSheet->props.size(); p > 0; p--){ + for (int p = propsSheet->props.size(); p > 0; p--){ propsSheet->removeProp(propsSheet->props[p - 1]); } changingPlugin = true; @@ -242,6 +243,7 @@ for (int p = propsSheet->props.size(); p > 0; p--){ for (int p = 0; p < propsSheet->props.size(); p++){ propsSheet->props[p]->propContents->setPositionX(padding); } + propList->Resize(propList->getWidth(), propList->getHeight()); enabled = true; diff --git a/IDE/Contents/Source/PolycodeProps.cpp b/IDE/Contents/Source/PolycodeProps.cpp index 2285e65a7..185f9b136 100644 --- a/IDE/Contents/Source/PolycodeProps.cpp +++ b/IDE/Contents/Source/PolycodeProps.cpp @@ -1925,15 +1925,15 @@ PropEditProp::PropEditProp(PropProp *newProp) : PropProp(newProp->getPropName(), typeChooser->setPosition(70, 25); currentValue = newProp->propType; + setHeight(65); if (currentValue != PropProp::PROP_COMBO){ comboEditProp = new ComboPropEditProp(new ComboProp(nameInput->getText())); comboEditProp->enabled = false; comboEditProp->visible = false; - setHeight(65); } else { comboEditProp = new ComboPropEditProp(((ComboProp*)newProp)); - setHeight(65 + comboEditProp->getHeight()); + setHeight(80 + comboEditProp->getHeight()); } comboEditProp->addEventListener(this, Event::CHANGE_EVENT); propContents->addChild(comboEditProp); @@ -1943,10 +1943,9 @@ PropEditProp::PropEditProp(PropProp *newProp) : PropProp(newProp->getPropName(), sliderEditProp = new SliderEditProp(new SliderProp(nameInput->getText(), 0, 0)); sliderEditProp->enabled = false; sliderEditProp->visible = false; - setHeight(65); } else { sliderEditProp = new SliderEditProp(((SliderProp*)newProp)); - setHeight(65 + sliderEditProp->getHeight()); + setHeight(80 + sliderEditProp->getHeight()); } sliderEditProp->addEventListener(this, Event::CHANGE_EVENT); propContents->addChild(sliderEditProp); @@ -2025,7 +2024,7 @@ void PropEditProp::set(PropProp *newProp){ currentProp = newProp; nameInput->setText(newProp->getPropName()); typeChooser->setSelectedIndex(newProp->propType); - setHeight(80); + setHeight(65); if (newProp->propType != PropProp::PROP_COMBO){ comboEditProp->set(new ComboProp(nameInput->getText())); } else { diff --git a/Modules/Contents/2DPhysics/Include/PolyPhysicsScreen.h b/Modules/Contents/2DPhysics/Include/PolyPhysicsScreen.h index adf4dedd7..02619dca6 100755 --- a/Modules/Contents/2DPhysics/Include/PolyPhysicsScreen.h +++ b/Modules/Contents/2DPhysics/Include/PolyPhysicsScreen.h @@ -185,6 +185,13 @@ class _PolyExport PhysicsScene2D : public Scene, b2ContactListener { */ PhysicsScene2DEntity *addPhysicsChild(Entity *newEntity, int entType, bool isStatic, Number friction=0.1, Number density=1, Number restitution = 0, bool isSensor = false, bool fixedRotation = false, int groupIndex = 0); + /** + * Adds a Entity as a physics enabled child. Once an entity is added as a physics child, its transforms are set by the physics engine and you are not able to position it manually. Use addCollisionChild/trackCollisionChild to track collisions of entities that you can position manually. + * @param newEntity Screen entity to add, with the Physics2D plugin EntityProps loaded. + * @return The physics entity wrapper. + */ + PhysicsScene2DEntity *addPhysicsChildEntity(Entity *newEntity); + /** * Tracks a Entity as a physics enabled child. Once an entity is added as a physics child, its transforms are set by the physics engine and you are not able to position it manually. Use addCollisionChild/trackCollisionChild to track collisions of entities that you can position manually. * @param newEntity Screen entity to add. @@ -223,7 +230,13 @@ class _PolyExport PhysicsScene2D : public Scene, b2ContactListener { * @param entityToRemove Entity to remove from the screen. */ PhysicsScene2DEntity *addCollisionChild(Entity *newEntity, int entType, int groupIndex = 0, bool sensorOnly = true); - + + /** + * Begins tracking collisions for a Entity and adds it to the scene. + * @param newEntity Entity to track collisions for, with the Physics2D plugin EntityProps loaded. + */ + PhysicsScene2DEntity *addCollisionChildEntity(Entity *newEntity); + /** * Begins tracking collisions for a Entity. * @param newEntity Entity to track collisions for. diff --git a/Modules/Contents/2DPhysics/Source/PolyPhysicsScreen.cpp b/Modules/Contents/2DPhysics/Source/PolyPhysicsScreen.cpp index 12fa83c7d..c852e42f1 100755 --- a/Modules/Contents/2DPhysics/Source/PolyPhysicsScreen.cpp +++ b/Modules/Contents/2DPhysics/Source/PolyPhysicsScreen.cpp @@ -343,6 +343,14 @@ PhysicsScene2DEntity *PhysicsScene2D::addCollisionChild(Entity *newEntity, int e return ret; } +PhysicsScene2DEntity *PhysicsScene2D::addCollisionChildEntity(Entity *newEntity) { + PhysicsScene2DEntity *ret; + ret = addPhysicsChild(newEntity, newEntity->getEntityPropIntByName("Physics2DShape"), false, 0, 0, 0, newEntity->getEntityPropBoolByName("Physics2DSensor?"), false, newEntity->getEntityPropIntByName("Physics2DGroup")); + newEntity->ignoreParentMatrix = false; + ret->collisionOnly = true; + return ret; +} + PhysicsScene2DEntity *PhysicsScene2D::trackCollisionChild(Entity *newEntity, int entType, int groupIndex) { PhysicsScene2DEntity *ret; ret = trackPhysicsChild(newEntity, entType, false, 0,0.0,0, true, false, groupIndex); @@ -471,6 +479,12 @@ PhysicsScene2DEntity *PhysicsScene2D::addPhysicsChild(Entity *newEntity, int ent } +PhysicsScene2DEntity *PhysicsScene2D::addPhysicsChildEntity(Entity *newEntity) { + addChild(newEntity); + return trackPhysicsChild(newEntity, newEntity->getEntityPropIntByName("Physics2DShape"), newEntity->getEntityPropBoolByName("Physics2DStatic?"), newEntity->getEntityPropNumberByName("Physics2DFriction"), newEntity->getEntityPropNumberByName("Physics2DDensity"), newEntity->getEntityPropNumberByName("Physics2DRestitution"), newEntity->getEntityPropBoolByName("Physics2DSensor?"), newEntity->getEntityPropBoolByName("Physics2DFixed Rot?"), newEntity->getEntityPropIntByName("Physics2DGroup")); + +} + PhysicsScene2DEntity *PhysicsScene2D::trackPhysicsChild(Entity *newEntity, int entType, bool isStatic, Number friction, Number density, Number restitution, bool isSensor, bool fixedRotation, int groupIndex) { PhysicsScene2DEntity *newPhysicsEntity = new PhysicsScene2DEntity(newEntity, world, worldScale, entType, isStatic, friction, density, restitution, isSensor,fixedRotation, groupIndex); diff --git a/Modules/Contents/3DPhysics/Include/PolyCollisionScene.h b/Modules/Contents/3DPhysics/Include/PolyCollisionScene.h index 1d54de811..db5f300d9 100755 --- a/Modules/Contents/3DPhysics/Include/PolyCollisionScene.h +++ b/Modules/Contents/3DPhysics/Include/PolyCollisionScene.h @@ -114,7 +114,8 @@ struct CollisionResult { bool isColliding(Entity *ent1); virtual CollisionEntity *addCollisionChild(Entity *newEntity, int type=0, int group=1); - CollisionEntity *trackCollision(Entity *newEntity, int type=0, int group=1); + virtual CollisionEntity *addCollisionChildEntity(Entity *newEntity); + CollisionEntity *trackCollision(Entity *newEntity, int type = 0, int group = 1); void removeCollision(Entity *entity); void adjustForCollision(CollisionEntity *collisionEntity); diff --git a/Modules/Contents/3DPhysics/Include/PolyPhysicsScene.h b/Modules/Contents/3DPhysics/Include/PolyPhysicsScene.h index d723917b8..72e79f302 100644 --- a/Modules/Contents/3DPhysics/Include/PolyPhysicsScene.h +++ b/Modules/Contents/3DPhysics/Include/PolyPhysicsScene.h @@ -109,7 +109,8 @@ namespace Polycode { void removePhysicsChild(Entity *entity); PhysicsEntity *getPhysicsEntityByEntity(Entity *entity); - PhysicsEntity *addPhysicsChild(Entity *newEntity, int type=0, Number mass = 0.0f, Number friction=1, Number restitution=0, int group=1, bool compoundChildren = false); + PhysicsEntity *addPhysicsChild(Entity *newEntity, int type=0, Number mass = 0.0f, Number friction=1, Number restitution=0, int group=1, bool compoundChildren = false); + PhysicsEntity *addPhysicsChildEntity(Entity *newEntity); PhysicsEntity *trackPhysicsChild(Entity *newEntity, int type=0, Number mass = 0.0f, Number friction=1, Number restitution=0, int group=1, bool compoundChildren = false); PhysicsCharacter *addCharacterChild(Entity *newEntity, Number mass, Number friction, Number stepSize, int group = 1); diff --git a/Modules/Contents/3DPhysics/Include/PolyPhysicsSceneEntity.h b/Modules/Contents/3DPhysics/Include/PolyPhysicsSceneEntity.h index 2621d17b4..c421ff13d 100644 --- a/Modules/Contents/3DPhysics/Include/PolyPhysicsSceneEntity.h +++ b/Modules/Contents/3DPhysics/Include/PolyPhysicsSceneEntity.h @@ -41,6 +41,7 @@ namespace Polycode { class _PolyExport PhysicsEntity : public CollisionEntity { public: PhysicsEntity(Entity *entity, int type, Number mass, Number friction, Number restitution, bool compoundChildren = false); + PhysicsEntity(Entity *entity); virtual ~PhysicsEntity(); virtual void Update(); diff --git a/Modules/Contents/3DPhysics/Source/PolyCollisionScene.cpp b/Modules/Contents/3DPhysics/Source/PolyCollisionScene.cpp index abace7559..8dd0e1b0a 100755 --- a/Modules/Contents/3DPhysics/Source/PolyCollisionScene.cpp +++ b/Modules/Contents/3DPhysics/Source/PolyCollisionScene.cpp @@ -259,3 +259,12 @@ CollisionEntity *CollisionScene::addCollisionChild(Entity *newEntity, int type, return trackCollision(newEntity, type, group); } + +CollisionEntity *CollisionScene::addCollisionChildEntity(Entity *newEntity) { + addEntity(newEntity); + int group = newEntity->getEntityPropIntByName("Collision3DGroup"); + if (group == 0){ + group = 1; + } + return trackCollision(newEntity, newEntity->getEntityPropIntByName("Collision3DShape"), group); +} \ No newline at end of file diff --git a/Modules/Contents/3DPhysics/Source/PolyCollisionSceneEntity.cpp b/Modules/Contents/3DPhysics/Source/PolyCollisionSceneEntity.cpp index cae660ec3..627e95337 100755 --- a/Modules/Contents/3DPhysics/Source/PolyCollisionSceneEntity.cpp +++ b/Modules/Contents/3DPhysics/Source/PolyCollisionSceneEntity.cpp @@ -87,7 +87,7 @@ CollisionEntity::CollisionEntity(Entity *entity){ this->entity = entity; shape = NULL; - this->type = entity->getEntityPropIntByName("Physics3DShape"); + this->type = entity->getEntityPropIntByName("Collision3DShape"); enabled = true; lastPosition = entity->getPosition(); @@ -98,7 +98,7 @@ CollisionEntity::CollisionEntity(Entity *entity){ collisionObject = new btCollisionObject(); collisionObject->getWorldTransform().setBasis(basisA); - if (entity->getEntityPropBoolByName("Physics3DComp Children?")) { + if (entity->getEntityPropBoolByName("Collision3DComp Children?")) { btCompoundShape* compoundShape = new btCompoundShape(); for (int i = 0; i < entity->getNumChildren(); i++) { diff --git a/Modules/Contents/3DPhysics/Source/PolyPhysicsScene.cpp b/Modules/Contents/3DPhysics/Source/PolyPhysicsScene.cpp index 8dfe0935b..30e55a8e5 100644 --- a/Modules/Contents/3DPhysics/Source/PolyPhysicsScene.cpp +++ b/Modules/Contents/3DPhysics/Source/PolyPhysicsScene.cpp @@ -451,3 +451,12 @@ PhysicsEntity *PhysicsScene::addPhysicsChild(Entity *newEntity, int type, Number addEntity(newEntity); return trackPhysicsChild(newEntity, type, mass, friction, restitution, group, compoundChildren); } + +PhysicsEntity *PhysicsScene::addPhysicsChildEntity(Entity *newEntity) { + addEntity(newEntity); + int group = newEntity->getEntityPropIntByName("Physics3DGroup"); + if (group == 0){ + group = 1; + } + return trackPhysicsChild(newEntity, newEntity->getEntityPropIntByName("Physics3DShape"), newEntity->getEntityPropNumberByName("Physics3DMass"), newEntity->getEntityPropNumberByName("Physics3DFriction"), newEntity->getEntityPropNumberByName("Physics3DRestitution"), group, newEntity->getEntityPropBoolByName("Physics3DComp Children?")); +} \ No newline at end of file diff --git a/Modules/Contents/3DPhysics/Source/PolyPhysicsSceneEntity.cpp b/Modules/Contents/3DPhysics/Source/PolyPhysicsSceneEntity.cpp index 0bc5cc99d..2b1b58034 100644 --- a/Modules/Contents/3DPhysics/Source/PolyPhysicsSceneEntity.cpp +++ b/Modules/Contents/3DPhysics/Source/PolyPhysicsSceneEntity.cpp @@ -213,6 +213,38 @@ PhysicsEntity::PhysicsEntity(Entity *entity, int type, Number mass, Number frict } } +PhysicsEntity::PhysicsEntity(Entity *entity) : CollisionEntity(entity) { + enabled = true; + this->mass = entity->getEntityPropNumberByName("Physics3DMass"); + btVector3 localInertia(0, 0, 0); + btTransform transform; + transform.setIdentity(); + + Matrix4 ent_mat = entity->getConcatenatedMatrix(); + Vector3 pos = ent_mat * Vector3(0.0, 0.0, 0.0); + transform.setOrigin(btVector3(pos.x, pos.y, pos.z)); + + Quaternion q = entity->getConcatenatedQuat(); + transform.setRotation(btQuaternion(q.x, q.y, q.z, q.w)); + + if (mass != 0.0f) { + shape->calculateLocalInertia(mass, localInertia); + } + + if (entity->getEntityPropIntByName("Physics3DShape") == CHARACTER_CONTROLLER) { + rigidBody = NULL; + myMotionState = NULL; + } else { + myMotionState = new btDefaultMotionState(transform); + btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, myMotionState, shape, localInertia); + rigidBody = new btRigidBody(rbInfo); + // rigidBody->setActivationState(ISLAND_SLEEPING); + rigidBody->setFriction(entity->getEntityPropNumberByName("Physics3DFriction")); + rigidBody->setRestitution(entity->getEntityPropNumberByName("Physics3DRestitution")); + rigidBody->setUserPointer((void*)this); + } +} + void PhysicsEntity::setFriction(Number friction) { rigidBody->setFriction(friction); } From 39d0ad11a379b374f44f38280af15e97d5ca6805 Mon Sep 17 00:00:00 2001 From: Joachim Meyer Date: Sat, 13 Sep 2014 23:13:00 +0200 Subject: [PATCH 17/19] Hopefully (not tested) add the function to Linux IDE to open files directly. --- IDE/Contents/Source/PolycodeIDEApp.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/IDE/Contents/Source/PolycodeIDEApp.cpp b/IDE/Contents/Source/PolycodeIDEApp.cpp index 92e05d86f..067990f38 100644 --- a/IDE/Contents/Source/PolycodeIDEApp.cpp +++ b/IDE/Contents/Source/PolycodeIDEApp.cpp @@ -189,6 +189,7 @@ PolycodeIDEApp::PolycodeIDEApp(PolycodeView *view) : EventDispatcher() { fileEntry->addItem("New File", "new_file", KEY_n); fileEntry->addItem("New Project", "new_project", KEY_LSHIFT, KEY_n); fileEntry->addItem("New Folder", "new_folder", KEY_LSHIFT, KEY_f); + fileEntry->addItem("Open File", "open_file", KEY_o); fileEntry->addItem("Open Project", "open_project", KEY_LSHIFT, KEY_o); fileEntry->addItem("Close Project", "close_project", KEY_LSHIFT, KEY_w); fileEntry->addItem("Close File", "close_file", KEY_w); @@ -783,7 +784,9 @@ void PolycodeIDEApp::handleEvent(Event *event) { newProject(); } else if(action == "new_folder") { newGroup(); - } else if(action == "open_project") { + } else if (action == "open_file") { + openFilePicker(); + } else if (action == "open_project") { openProject(); } else if(action == "close_project") { closeProject(); From f6fad7e96f623199c713be9b9c508f3fe108517f Mon Sep 17 00:00:00 2001 From: Joachim Meyer Date: Mon, 15 Sep 2014 14:34:51 +0200 Subject: [PATCH 18/19] Fix PolycodeIDEApp::openFilePicker() to be able to use PolycodeUI file dialogs. --- IDE/Contents/Source/PolycodeIDEApp.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/IDE/Contents/Source/PolycodeIDEApp.cpp b/IDE/Contents/Source/PolycodeIDEApp.cpp index 067990f38..bb71f6ec8 100644 --- a/IDE/Contents/Source/PolycodeIDEApp.cpp +++ b/IDE/Contents/Source/PolycodeIDEApp.cpp @@ -708,11 +708,21 @@ void PolycodeIDEApp::openFile(OSFileEntry file) { void PolycodeIDEApp::openFilePicker() { std::vector extensions = editorManager->getExtensionsWithEditor(); + #ifdef USE_POLYCODEUI_FILE_DIALOGS + std::vector exts; + for(int e = 0; e < extensions.size(); e++){ + exts.push_back((extensions[e].extension)); + } + frame->showFileBrowser(CoreServices::getInstance()->getCore()->getUserHomeDirectory(), false, exts, false); + frame->fileDialog->addEventListener(this, UIEvent::OK_EVENT); + frame->fileDialog->action = "openFile"; +#else extensions.insert(extensions.begin(), CoreFileExtension("All Types", "*")); std::vector filePaths = core->openFilePicker(extensions, true); for (int f = 0; f < filePaths.size(); f++){ openFile(OSFileEntry(filePaths[f], OSFileEntry::TYPE_FILE)); } +#endif } void PolycodeIDEApp::handleEvent(Event *event) { @@ -770,6 +780,8 @@ void PolycodeIDEApp::handleEvent(Event *event) { frame->assetImporterWindow->setSourceFileAndTargetFolder(path, projectManager->activeFolder, projectManager->activeFolder.replace(projectManager->getActiveProject()->getRootFolder(), "")); frame->showModal(frame->assetImporterWindow); frame->assetImporterWindow->addEventListener(this, UIEvent::OK_EVENT); + } else if(frame->fileDialog->action == "openFile") { + openFile(OSFileEntry(path, OSFileEntry::TYPE_FILE)); } } } From 6da87cd4ee971c07b6580ba911bb784be5c3cdaa Mon Sep 17 00:00:00 2001 From: Joachim Meyer Date: Tue, 23 Sep 2014 22:43:06 +0200 Subject: [PATCH 19/19] Fix rebase issue. --- IDE/Contents/Source/PolycodeProps.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/IDE/Contents/Source/PolycodeProps.cpp b/IDE/Contents/Source/PolycodeProps.cpp index 185f9b136..3b1b519cd 100644 --- a/IDE/Contents/Source/PolycodeProps.cpp +++ b/IDE/Contents/Source/PolycodeProps.cpp @@ -4587,18 +4587,20 @@ void SoundSheet::handleEvent(Event *event) { } void SoundSheet::setSound(SceneSound *sound) { - this->sound = sound; + this->sound = sound; - if(sound) { - enabled = true; + if (sound) { + enabled = true; - soundProp->set(sound->getSound()->getFileName()); - referenceDistance->set(sound->getSound()->getReferenceDistance()); - maxDistance->set(sound->getSound()->getMaxDistance()); - volume->set(sound->getSound()->getVolume()); - pitch->set(sound->getSound()->getPitch()); - soundProp->previewSound->setPitch(sound->getSound()->getPitch()); + soundProp->set(sound->getSound()->getFileName()); + referenceDistance->set(sound->getSound()->getReferenceDistance()); + maxDistance->set(sound->getSound()->getMaxDistance()); + volume->set(sound->getSound()->getVolume()); + pitch->set(sound->getSound()->getPitch()); + soundProp->previewSound->setPitch(sound->getSound()->getPitch()); } else { enabled = false; } + +} \ No newline at end of file