/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2012 I-maginer This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to http://www.gnu.org/copyleft/lesser.txt ----------------------------------------------------------------------------- */ struct CondListPlugin=[ CLP_inst : PInstance, CLP_lCond : [[S [S I]] r1], CLP_bAutoReset : I ] mkCondListPlugin;; fun deleteOb(inst, obstr)= 0;; fun cbReset(inst, from, action, param, rep, obstr)= let sizelist obstr.CLP_lCond -> size in let 0 -> i in while (i < size) do ( let nth_list obstr.CLP_lCond i -> [_ condition] in mutate condition <- [_ 0]; set i = i + 1; ); 0;; fun areConditionsActivated(obstr)= let sizelist obstr.CLP_lCond -> size in let 0 -> i in let 1 -> activated in ( while (i < size && activated) do ( let nth_list obstr.CLP_lCond i -> [_ [_ state]] in set activated = state; set i = i + 1; ); if (!activated) then nil else ( SendPluginEvent obstr.CLP_inst "Conditions activated" nil nil; if (!obstr.CLP_bAutoReset) then nil else cbReset obstr.CLP_inst nil nil nil nil obstr; ); ); 0;; fun cbSetState(inst, from, action, param, rep, p)= if (param == nil) || (strcmpi param "") == 0 then nil else let p -> [obstr condname] in let if (atoi param) <= 0 then 0 else 1 -> state in ( let switchstri obstr.CLP_lCond condname -> condition in mutate condition <- [_ state]; SendPluginEvent obstr.CLP_inst (strcat condname " state") (itoa state) nil; if state then SendPluginEvent obstr.CLP_inst (strcat condname " checked") nil nil else SendPluginEvent obstr.CLP_inst (strcat condname " unchecked") nil nil; areConditionsActivated obstr; ); 0;; fun cbCheck(inst, from, action, param, rep, p)= let p -> [obstr condname] in ( let switchstri obstr.CLP_lCond condname -> condition in mutate condition <- [_ 1]; SendPluginEvent obstr.CLP_inst (strcat condname " state") "1" nil; SendPluginEvent obstr.CLP_inst (strcat condname " checked") nil nil; areConditionsActivated obstr; ); 0;; fun cbUncheck(inst, from, action, param, rep, p)= let p -> [obstr condname] in ( let switchstri obstr.CLP_lCond condname -> condition in mutate condition <- [_ 0]; SendPluginEvent obstr.CLP_inst (strcat condname " state") "0" nil; SendPluginEvent obstr.CLP_inst (strcat condname " unchecked") nil nil; areConditionsActivated obstr; ); 0;; fun cbToggle(inst, from, action, param, rep, p)= let p -> [obstr condname] in let switchstri obstr.CLP_lCond condname -> condition in let condition -> [_ state] in ( mutate condition <- [_ !state]; SendPluginEvent obstr.CLP_inst (strcat condname " state") (itoa !state) nil; if !state then SendPluginEvent obstr.CLP_inst (strcat condname " checked") nil nil else SendPluginEvent obstr.CLP_inst (strcat condname " unchecked") nil nil; areConditionsActivated obstr; ); 0;; fun loadConditionsList(obstr)= let 0 -> i in let getPluginInstanceParam obstr.CLP_inst (strcat "condition_" (itoa i)) -> condname in while (condname != nil) do ( set obstr.CLP_lCond = if i == 0 then [condname [condname 0]]::nil else lcat obstr.CLP_lCond [condname [condname 0]]::nil; PluginRegisterAction obstr.CLP_inst (strcatn "Set "::condname::" state"::nil) mkfun6 @cbSetState [obstr condname]; PluginRegisterAction obstr.CLP_inst (strcat "Check " condname) mkfun6 @cbCheck [obstr condname]; PluginRegisterAction obstr.CLP_inst (strcat "Uncheck " condname) mkfun6 @cbUncheck [obstr condname]; PluginRegisterAction obstr.CLP_inst (strcat "Toggle " condname) mkfun6 @cbToggle [obstr condname]; set i = i + 1; set condname = getPluginInstanceParam obstr.CLP_inst (strcat "condition_" (itoa i)); ); 0;; fun newOb(inst)= let atoi (getPluginInstanceParam inst "autoreset") -> autoreset in let if autoreset == nil then 0 else autoreset -> autoreset in let mkCondListPlugin [inst nil autoreset] -> obstr in ( loadConditionsList obstr; PluginRegisterAction inst "Reset" mkfun6 @cbReset obstr; setPluginInstanceCbDel inst mkfun2 @deleteOb obstr; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;