/* PNJ Editor - DMS - junary 2008 - by Bastien BOURINEAU */ /******************************************************************************* Variables *******************************************************************************/ /* Plugin basic variables */ typeof plugin = S;; /* '*.plug' file name */ typeof class = S;; /* plugin name */ var sPath = "/";; typeof ed = PluginEditor;; typeof winEdt = ObjWin;; /* Editor's window */ typeof txtM3D = ObjText;; /* Text and EditLine objects for the different */ typeof edtM3D = ObjText;; typeof btnBrowseM3d = ObjButton;; typeof txtAFR = ObjText;; /* Text and EditLine objects for the animations' */ typeof edtAFR = ObjText;; /* framerate */ typeof lAnimlist = [[S r1] r1];; typeof lSoundlist = [[S r1] r1];; typeof lTranslist = [[S r1] r1];; typeof lScriptlist = [[S r1] r1];; /******************************************************************************* Protos *******************************************************************************/ proto cbSave = fun [[Inst r1]] [[S r1] [S r1] [[S r1] r1] [[S r1] r1]];; /******************************************************************************* Functions *******************************************************************************/ fun InstParam(UI)=UI.paramInst;; fun InstName(UI)=UI.nameInst;; fun brwSearchLastpoint(s)= if s == nil then nil else let (strlen s) - 1 -> i in ( while (i >= 0) && ((nth_char s i) != '.) do ( set i = i - 1; ); i );; fun getFileWithoutExtension(file)= let brwSearchLastpoint file -> i in substr file 0 i;; fun getPathFile (longfile, file)= if (longfile==nil) || (strlen longfile)==0 || (nth_char longfile ((strlen longfile)-1)) == '/ then [longfile file] else getPathFile substr longfile 0 (strlen longfile)-1 strcat substr longfile ((strlen longfile)-1) 1 file;; fun getFileNameFromPath(path)= if path == nil then nil else let strlen path -> size in let 0 -> pos in let 0 -> prevpos in ( while pos != nil && pos < size do ( set prevpos = pos; let strfind "/" path pos -> npos in set pos = if npos != nil then npos + 1 else nil; ); substr path prevpos (size - prevpos); );; /******************************************************************************* Functions: Freeing Editor's resources *******************************************************************************/ /******************************************************************************* cbDestroyWin() win -> ObjWin : Plugin Editor window p -> u0 : Not used <- I : Not used Callback function activated when the plugin Editor window is destroyed. Resources allocated in cbOpenEdit should be freed here. Checking the real allocation prevents corruptions in Voyager's data structures. *******************************************************************************/ fun cbDestroyWin(win, p) = if (txtM3D != nil) then (_DStext txtM3D; set txtM3D = nil; 0;) else 0; if (edtM3D != nil) then (_DStext edtM3D; set edtM3D = nil; 0;) else 0; if (txtAFR != nil) then (_DStext txtAFR; set txtAFR = nil; 0;) else 0; if (edtAFR != nil) then (_DStext edtAFR; set edtAFR = nil; 0;) else 0; if (btnBrowseM3d != nil) then (_DSbutton btnBrowseM3d; set btnBrowseM3d = nil; 0;) else 0; 0;; /******************************************************************************* Functions: Saving plugin's DMI information *******************************************************************************/ /******************************************************************************* SaveBasicActionsAndEvents() name -> S : Instance name <- [[S r1] r1] : Basic actions and events of the plugin Saves basic actions and events of the plugin *******************************************************************************/ fun SaveActionsAndEvents(l) = if l == nil then nil else let nil -> extented in let l -> [a n] in let strextr (InstParam a) -> lparams in let ("eventC"::(strcat (InstName a) ".in")::nil):: ("eventC"::(strcat (InstName a) ".entering")::nil):: ("eventC"::(strcat (InstName a) ".leftClick")::nil):: ("eventC"::(strcat (InstName a) ".rightClick")::nil):: nil -> basics in ( let strextr getInfo lparams "anims" -> data in let sizelist data -> size in let 0 -> i in while i < size do ( let getFileWithoutExtension getFileNameFromPath hd (nth_list data i) -> elem in set extented = listcat extented ("actionC"::(strcatn (InstName a)::".anim_"::elem::".play"::nil)::nil)::("actionC"::(strcatn (InstName a)::".anim_"::elem::".stop"::nil)::nil)::nil; set i = i + 1; ); let strextr getInfo lparams "sounds" -> data in let sizelist data -> size in let 0 -> i in while i < size do ( let getFileWithoutExtension getFileNameFromPath hd (nth_list data i) -> elem in set extented = listcat extented ("actionC"::(strcatn (InstName a)::".sound_"::elem::".play"::nil)::nil)::("actionC"::(strcatn (InstName a)::".sound_"::elem::".stop"::nil)::nil)::nil; set i = i + 1; ); let strextr getInfo lparams "trans" -> data in let sizelist data -> size in let 0 -> i in while i < size do ( let hd (nth_list data i) -> elem in set extented = listcat extented ("actionC"::(strcatn (InstName a)::".trans_"::elem::".play"::nil)::nil)::("actionC"::(strcatn (InstName a)::".trans_"::elem::".stop"::nil)::nil)::nil; set i = i + 1; ); listcat basics listcat extented SaveActionsAndEvents n; );; /******************************************************************************* SaveDMI() l -> [Inst r1] : List of plugin's instances <- [[S r1] r1] : DMI informations Saves supplementary DMI information *******************************************************************************/ fun SaveDMI(l) = (SaveActionsAndEvents l);; /******************************************************************************* cbSave() l -> [Inst r1] : List of plugin's instances <- [[S r1] [S r1] [[S r1] r1] [[S r1] r1]] : cf comments in code Callback function called when you click on Apply in C3D3 Editor, or on OK in C3D3 Editor (in this case, cbClose is called just after). *******************************************************************************/ fun cbSave(l)= if (l == nil) then [nil nil nil nil] else [ nil /* registerF */ nil /* register */ ("plugin"::plugin::nil)::nil /* supplementary Dat */ SaveDMI l /* supplementary Dmi */ ];; /******************************************************************************* Functions: Quitting C3D3's Editor *******************************************************************************/ /******************************************************************************* cbClose() <- I : Not used Callback function which is called when you click on the Cancel button of the C3D3 or on the OK button of the C3D3 (in this case, the cbSave function is called just before). *******************************************************************************/ fun cbClose() = 0;; fun cbBrowseM3d(dlg, edttxt, file)= let _PtoScol file -> name in if name == nil then nil else ( let getPathFile name nil -> [path _] in set sPath = path; _SETtext edttxt name; ); 0;; fun cbBtnBrowseM3d(btn, edttxt)= _DLGrflopen _DLGOpenFile _channel winEdt sPath nil "M3D\0*.m3d\0\0" @cbBrowseM3d edttxt; 0;; /******************************************************************************* Functions: Opening Plugin's Editor *******************************************************************************/ /******************************************************************************* cbOpenEdit() win -> ObjWin : Plugin's Editor father window params -> S : "strbuilded" list of plugin's instance's parameters and params' values <- I : Not used Callback function called when the Editor of the plugin is opened. Caution! Resources allocated here will not be destroyed until the cbDestroyWin callback is triggered and if you destroy them in this function. Multiple openings of the plugin Editor should thus consume a lot of resources if resources are not properly handled. *******************************************************************************/ fun cbOpenEdit(win, params)= let strextr params -> l in let _GETwindowSizePosition win -> [w h x y] in ( set ed = startPluginEditor _channel win 0 0 w h WN_CHILDINSIDE|WN_NOBORDER class; set winEdt = ed.PluginEditorEditWin; set txtM3D = _CRtext _channel winEdt 5 5 150 20 ET_ALIGN_LEFT EasyLocEditor "KW_DIRM3D"; set edtM3D = _CReditLine _channel winEdt 170 5 300 20 ET_AHSCROLL|ET_BORDER ""; set btnBrowseM3d = _CBbutton _CRbutton _channel winEdt 475 5 20 20 PB_DEFAULT "..." @cbBtnBrowseM3d edtM3D; set txtAFR = _CRtext _channel winEdt 5 35 150 20 ET_ALIGN_LEFT EasyLocEditor "KW_FRAMERATE"; set edtAFR = _CReditLine _channel winEdt 170 35 30 20 ET_AHSCROLL|ET_BORDER|ET_NUMBER ""; _CRtext _channel winEdt 5 100 (w-10) 20 ET_ALIGN_LEFT "Full editor Online only !!"; _SETtext edtM3D getInfo l "m3dpath"; if (getInfo l "frameR") != nil then _SETtext edtAFR (getInfo l "frameR") else _SETtext edtAFR "30"; set lAnimlist = strextr (getInfo l "anims"); set lSoundlist = strextr (getInfo l "sounds"); set lTranslist = strextr (getInfo l "trans"); set lScriptlist = strextr (getInfo l "script"); _CBwinDestroy win @cbDestroyWin nil; ); 0;; /******************************************************************************* Functions: Quitting Plugin's Editor *******************************************************************************/ /******************************************************************************* SaveBasicParameters() <- [[S r1] r1] : Plugin basic parameters Saves the basic parameters of the plugin: files' pathes & framerate *******************************************************************************/ fun SaveBasicParameters() = ("m3dpath"::(_GETtext edtM3D)::nil):: ("frameR"::(_GETtext edtAFR)::nil):: ("anims"::(strbuild lAnimlist)::nil):: ("sounds"::(strbuild lSoundlist)::nil):: ("trans"::(strbuild lTranslist)::nil):: ("script"::(strbuild lScriptlist)::nil):: nil;; /******************************************************************************* cbCloseEdit() <- S : "strbuilded" list of plugin's instance's parameters and params' values Callback function called when you click on the OK button of the plugin Editor. The Cancel button doesn't call this callback, nor any other one. *******************************************************************************/ fun cbCloseEdit() = strbuild SaveBasicParameters;; /******************************************************************************* Functions: Plugin's Editor initialization *******************************************************************************/ /******************************************************************************* Init_2DAPI_Objects() <- I : Not used Initializes all 2D Objects to nil value *******************************************************************************/ fun Init_2DAPI_Objects() = set txtM3D = nil; set edtM3D = nil; set txtAFR = nil; set edtAFR = nil; set btnBrowseM3d = nil; set lAnimlist = nil; set lSoundlist = nil; set lTranslist = nil; set lScriptlist = nil; 0;; /******************************************************************************* IniPlug() file -> S : '*.plug' file name <- I : Not used Standard function. Plugin initialisation, the PlugRegister function has to be called at the end. This function is called when you open the C3D3 Editor. *******************************************************************************/ fun IniPlug(file)= set plugin = file; set class = getInfo strextr _getpack _checkpack file "name"; let _GetFileNameFromP _checkpack plugin -> fileName in let strfind fileName plugin 0 -> posFileName in let strcat (substr plugin 0 posFileName) "editorLang" -> filePath in Init_EasyLocEditor filePath class; Init_2DAPI_Objects; PlugRegister class @cbSave @cbClose @cbOpenEdit @cbCloseEdit; 0;;