THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 06/05/2012 at 16:03, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 13
Platform: Windows ;
Language(s) : C++ ;
---------
Hey guys,
I'm having some trouble with creating custom preferences.
I'm using the example code that's in the docs to learn from. But I don't see anywhere in that example where it actually does anything.
As a practice example. I tried to make the timeline's highlight option turn on/off with my custom entry. But it doesn't work.
No errors..It just simply doesn't do anything.
Here's the .cpp code:
#include "c4d.h"
#include "c4d_symbols.h"
#include "lib_prefs.h"
#include "prefsmyprefs.h"
#include "..\..\..\..\modules\newman\res\description\prefstimeline.h"
#define PLUGIN_ID 1025669 //A plugin id gotten from plugincafe.com
#define MY_PREFS_DIALOG_ID 1026251 //A custom user container id gotten from plugincafe.com
class MyPrefs : public PrefsDialogObject
{
INSTANCEOF(MyPrefs, PrefsDialogObject)
public:
virtual Bool InitValues(const DescID &id, Description* desc = NULL);
virtual Bool Init(GeListNode* node);
virtual Bool GetDParameter(GeListNode *node, const DescID &id, GeData &t_data, DESCFLAGS_GET &flags);
virtual Bool SetDParameter(GeListNode *node, const DescID &id, const GeData &t_data, DESCFLAGS_SET &flags);
virtual Bool GetDEnabling(GeListNode *node, const DescID &id, const GeData &t_data, DESCFLAGS_ENABLE flags, const BaseContainer *itemdesc);
virtual Bool GetDDescription(GeListNode *node, Description *description, DESCFLAGS_DESC &flags);
BaseContainer *GetMyPrefs();
static NodeData *Alloc() { return gNew MyPrefs; }
};
Bool MyPrefs::InitValues(const DescID &id, Description *desc)
{
BaseContainer* bc = GetMyPrefs();
if (!bc) return FALSE;
switch (id[0].id)
{
case PREF_MYPREFS_BOOL1: InitPrefsValue(PREF_MYPREFS_BOOL1,GeData(TRUE),desc,id,bc); return TRUE;
}
return TRUE;
}
Bool MyPrefs::Init(GeListNode* node)
{
InitValues(PREF_MYPREFS_BOOL1);
return TRUE;
}
Bool MyPrefs::GetDParameter(GeListNode *node, const DescID &id, GeData &t_data, DESCFLAGS_GET &flags)
{
BaseContainer* bc = GetMyPrefs();
if (!bc) SUPER::GetDParameter(node,id,t_data,flags);
switch (id[0].id)
{
case PREF_MYPREFS_BOOL1: t_data = bc->GetBool(PREF_TL_HIGHLIGHT,TRUE); flags |= DESCFLAGS_GET_PARAM_GET; return TRUE; //<----Is this Wrong???
}
return SUPER::GetDParameter(node,id,t_data,flags);
}
Bool MyPrefs::SetDParameter(GeListNode *node, const DescID &id, const GeData &t_data, DESCFLAGS_SET &flags)
{
BaseContainer* bc = GetMyPrefs();
if (!bc) SUPER::SetDParameter(node,id,t_data,flags);
switch (id[0].id)
{
case PREF_MYPREFS_BOOL1: bc->SetBool(PREF_TL_HIGHLIGHT,t_data.GetLong()); flags |= DESCFLAGS_SET_PARAM_SET; GeUpdateUI(); return TRUE; //<----Is this Wrong???
}
return SUPER::SetDParameter(node,id,t_data,flags);
}
Bool MyPrefs::GetDEnabling(GeListNode *node, const DescID &id, const GeData &t_data, DESCFLAGS_ENABLE flags, const BaseContainer *itemdesc)
{
BaseContainer* bc = GetMyPrefs();
if (!bc) SUPER::GetDEnabling(node,id,t_data,flags,itemdesc);
return SUPER::GetDEnabling(node,id,t_data,flags,itemdesc);
}
Bool MyPrefs::GetDDescription(GeListNode *node, Description *description, DESCFLAGS_DESC &flags)
{
if (!description->LoadDescription("Prefsmyprefs")) return FALSE;
if ( flags & DESCFLAGS_DESC_NEEDDEFAULTVALUE )
{
InitValues(PREF_MYPREFS_BOOL1,description);
}
flags |= DESCFLAGS_DESC_LOADED;
return SUPER::GetDDescription(node, description, flags);
}
BaseContainer* MyPrefs::GetMyPrefs()
{
BaseContainer* bc = GetWorldContainerInstance()->GetContainerInstance(MY_PREFS_DIALOG_ID);
if (!bc)
{
GetWorldContainerInstance()->SetContainer(MY_PREFS_DIALOG_ID, BaseContainer());
bc = GetWorldContainerInstance()->GetContainerInstance(MY_PREFS_DIALOG_ID);
if (!bc) return NULL;
}
return bc;
}
Bool RegisterMyPrefs()
{
PrefsDialogObject::Register(PLUGIN_ID, MyPrefs::Alloc, GeLoadString(IDS_MYPREFS), "Prefsmyprefs", 0, PREFS_PRI_MODULES);
return TRUE;
}
AFAICT. This type of plugin uses descriptions to do it's work. And I'm guessing that the methods GetDParameter() & SetDParameter() are the heavy lifters that actually do the work to execute things that are enabled in the preferences?
Can anyone tell me what I'm doing wrong?
-ScottA