2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-11-30 19:52:21 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU 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 General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-11-30 19:52:21 +00:00
|
|
|
*
|
|
|
|
|
* Contributor(s): Blender Foundation (2008).
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
2011-02-27 20:20:01 +00:00
|
|
|
/** \file blender/makesrna/intern/rna_property.c
|
|
|
|
|
* \ingroup RNA
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2008-11-30 19:52:21 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
#include "RNA_define.h"
|
|
|
|
|
|
|
|
|
|
#include "rna_internal.h"
|
|
|
|
|
|
|
|
|
|
#include "DNA_property_types.h"
|
|
|
|
|
|
2010-05-08 22:11:00 +00:00
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
2012-01-04 21:40:00 +00:00
|
|
|
EnumPropertyItem gameproperty_type_items[] ={
|
|
|
|
|
{GPROP_BOOL, "BOOL", 0, "Boolean", "Boolean Property"},
|
|
|
|
|
{GPROP_INT, "INT", 0, "Integer", "Integer Property"},
|
|
|
|
|
{GPROP_FLOAT, "FLOAT", 0, "Float", "Floating-Point Property"},
|
|
|
|
|
{GPROP_STRING, "STRING", 0, "String", "String Property"},
|
|
|
|
|
{GPROP_TIME, "TIMER", 0, "Timer", "Timer Property"},
|
|
|
|
|
{0, NULL, 0, NULL, NULL}};
|
|
|
|
|
|
|
|
|
|
|
2008-11-30 19:52:21 +00:00
|
|
|
#ifdef RNA_RUNTIME
|
|
|
|
|
|
2009-07-20 16:21:55 +00:00
|
|
|
#include "BKE_property.h"
|
|
|
|
|
|
2008-12-02 23:45:11 +00:00
|
|
|
static StructRNA* rna_GameProperty_refine(struct PointerRNA *ptr)
|
|
|
|
|
{
|
|
|
|
|
bProperty *property= (bProperty*)ptr->data;
|
|
|
|
|
|
|
|
|
|
switch(property->type){
|
2008-12-23 19:47:33 +00:00
|
|
|
case GPROP_BOOL:
|
2008-12-02 23:45:11 +00:00
|
|
|
return &RNA_GameBooleanProperty;
|
2008-12-23 19:47:33 +00:00
|
|
|
case GPROP_INT:
|
2008-12-02 23:45:11 +00:00
|
|
|
return &RNA_GameIntProperty;
|
2008-12-23 19:47:33 +00:00
|
|
|
case GPROP_FLOAT:
|
2008-12-02 23:45:11 +00:00
|
|
|
return &RNA_GameFloatProperty;
|
2008-12-23 19:47:33 +00:00
|
|
|
case GPROP_STRING:
|
2008-12-02 23:45:11 +00:00
|
|
|
return &RNA_GameStringProperty;
|
2008-12-23 19:47:33 +00:00
|
|
|
case GPROP_TIME:
|
2009-01-10 22:57:33 +00:00
|
|
|
return &RNA_GameTimerProperty;
|
2008-12-02 23:45:11 +00:00
|
|
|
default:
|
|
|
|
|
return &RNA_GameProperty;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* for both float and timer */
|
|
|
|
|
static float rna_GameFloatProperty_value_get(PointerRNA *ptr)
|
|
|
|
|
{
|
|
|
|
|
bProperty *prop= (bProperty*)(ptr->data);
|
|
|
|
|
return *(float*)(&prop->data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void rna_GameFloatProperty_value_set(PointerRNA *ptr, float value)
|
|
|
|
|
{
|
|
|
|
|
bProperty *prop= (bProperty*)(ptr->data);
|
|
|
|
|
CLAMP(value, -10000.0f, 10000.0f);
|
|
|
|
|
*(float*)(&prop->data)= value;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-20 16:21:55 +00:00
|
|
|
static void rna_GameProperty_type_set(PointerRNA *ptr, int value)
|
|
|
|
|
{
|
|
|
|
|
bProperty *prop= (bProperty*)(ptr->data);
|
|
|
|
|
|
|
|
|
|
if(prop->type != value) {
|
|
|
|
|
prop->type= value;
|
|
|
|
|
init_property(prop);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void rna_GameProperty_name_set(PointerRNA *ptr, const char *value)
|
|
|
|
|
{
|
|
|
|
|
bProperty *prop= (bProperty*)(ptr->data);
|
2011-09-15 12:26:48 +00:00
|
|
|
BLI_strncpy_utf8(prop->name, value, sizeof(prop->name));
|
2009-07-20 16:21:55 +00:00
|
|
|
unique_property(NULL, prop, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-11-30 19:52:21 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
void RNA_def_gameproperty(BlenderRNA *brna)
|
|
|
|
|
{
|
|
|
|
|
StructRNA *srna;
|
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
2008-12-02 01:05:23 +00:00
|
|
|
/* Base Struct for GameProperty */
|
2008-12-19 04:06:24 +00:00
|
|
|
srna= RNA_def_struct(brna, "GameProperty", NULL);
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_struct_ui_text(srna , "Game Property", "Game engine user defined object property");
|
2008-11-30 19:52:21 +00:00
|
|
|
RNA_def_struct_sdna(srna, "bProperty");
|
2009-01-01 15:52:51 +00:00
|
|
|
RNA_def_struct_refine_func(srna, "rna_GameProperty_refine");
|
2008-11-30 19:52:21 +00:00
|
|
|
|
2008-12-02 23:45:11 +00:00
|
|
|
prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
|
2010-05-04 05:15:53 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Name", "Available as GameObject attributes in the game engine's python API");
|
2008-12-02 23:45:11 +00:00
|
|
|
RNA_def_struct_name_property(srna, prop);
|
2009-07-20 16:21:55 +00:00
|
|
|
RNA_def_property_string_funcs(prop, NULL, NULL, "rna_GameProperty_name_set");
|
2010-05-08 22:11:00 +00:00
|
|
|
RNA_def_property_update(prop, NC_LOGIC, NULL);
|
2008-11-30 19:52:21 +00:00
|
|
|
|
|
|
|
|
prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
|
2008-12-02 23:45:11 +00:00
|
|
|
RNA_def_property_enum_items(prop, gameproperty_type_items);
|
|
|
|
|
RNA_def_property_ui_text(prop, "Type", "");
|
2009-07-20 16:21:55 +00:00
|
|
|
RNA_def_property_enum_funcs(prop, NULL, "rna_GameProperty_type_set", NULL);
|
2010-05-08 22:11:00 +00:00
|
|
|
RNA_def_property_update(prop, NC_LOGIC, NULL);
|
2008-11-30 19:52:21 +00:00
|
|
|
|
2010-08-21 04:51:00 +00:00
|
|
|
prop= RNA_def_property(srna, "show_debug", PROP_BOOLEAN, PROP_NONE);
|
2008-12-02 01:05:23 +00:00
|
|
|
RNA_def_property_boolean_sdna(prop, NULL, "flag", PROP_DEBUG);
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Debug", "Print debug information for this property");
|
2010-05-08 22:11:00 +00:00
|
|
|
RNA_def_property_update(prop, NC_LOGIC, NULL);
|
2008-12-02 01:05:23 +00:00
|
|
|
|
|
|
|
|
/* GameBooleanProperty */
|
2008-12-19 04:06:24 +00:00
|
|
|
srna= RNA_def_struct(brna, "GameBooleanProperty", "GameProperty");
|
2010-05-04 05:15:53 +00:00
|
|
|
RNA_def_struct_ui_text(srna , "Game Boolean Property", "Game engine user defined Boolean property");
|
2008-12-02 01:05:23 +00:00
|
|
|
RNA_def_struct_sdna(srna, "bProperty");
|
2010-05-08 22:11:00 +00:00
|
|
|
RNA_def_property_update(prop, NC_LOGIC, NULL);
|
2008-12-02 01:05:23 +00:00
|
|
|
|
2009-01-10 22:57:33 +00:00
|
|
|
prop= RNA_def_property(srna, "value", PROP_BOOLEAN, PROP_NONE);
|
2008-12-02 01:05:23 +00:00
|
|
|
RNA_def_property_boolean_sdna(prop, NULL, "data", 1);
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Value", "Property value");
|
2010-05-08 22:11:00 +00:00
|
|
|
RNA_def_property_update(prop, NC_LOGIC, NULL);
|
2008-12-02 01:05:23 +00:00
|
|
|
|
|
|
|
|
/* GameIntProperty */
|
2008-12-19 04:06:24 +00:00
|
|
|
srna= RNA_def_struct(brna, "GameIntProperty", "GameProperty");
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_struct_ui_text(srna , "Game Integer Property", "Game engine user defined integer number property");
|
2008-12-02 01:05:23 +00:00
|
|
|
RNA_def_struct_sdna(srna, "bProperty");
|
|
|
|
|
|
2008-12-02 23:45:11 +00:00
|
|
|
prop= RNA_def_property(srna, "value", PROP_INT, PROP_NONE);
|
2008-12-02 01:05:23 +00:00
|
|
|
RNA_def_property_int_sdna(prop, NULL, "data");
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Value", "Property value");
|
2008-12-02 01:05:23 +00:00
|
|
|
RNA_def_property_range(prop, -10000, 10000);
|
2010-05-08 22:11:00 +00:00
|
|
|
RNA_def_property_update(prop, NC_LOGIC, NULL);
|
2008-12-02 01:05:23 +00:00
|
|
|
|
|
|
|
|
/* GameFloatProperty */
|
2008-12-19 04:06:24 +00:00
|
|
|
srna= RNA_def_struct(brna, "GameFloatProperty", "GameProperty");
|
2011-11-22 00:14:59 +00:00
|
|
|
RNA_def_struct_ui_text(srna, "Game Float Property", "Game engine user defined floating point number property");
|
2008-12-02 01:05:23 +00:00
|
|
|
RNA_def_struct_sdna(srna, "bProperty");
|
|
|
|
|
|
2008-12-02 23:45:11 +00:00
|
|
|
prop= RNA_def_property(srna, "value", PROP_FLOAT, PROP_NONE);
|
2010-12-31 04:12:20 +00:00
|
|
|
// RNA_def_property_float_sdna(prop, NULL, "data");
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Value", "Property value");
|
2008-12-02 01:05:23 +00:00
|
|
|
RNA_def_property_range(prop, -10000, 10000);
|
2008-12-02 23:45:11 +00:00
|
|
|
RNA_def_property_float_funcs(prop, "rna_GameFloatProperty_value_get", "rna_GameFloatProperty_value_set", NULL);
|
2010-05-08 22:11:00 +00:00
|
|
|
RNA_def_property_update(prop, NC_LOGIC, NULL);
|
2008-12-02 01:05:23 +00:00
|
|
|
|
|
|
|
|
/* GameTimerProperty */
|
2009-01-10 22:57:33 +00:00
|
|
|
srna= RNA_def_struct(brna, "GameTimerProperty", "GameProperty");
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_struct_ui_text(srna, "Game Timer Property", "Game engine user defined timer property");
|
2008-12-02 01:05:23 +00:00
|
|
|
RNA_def_struct_sdna(srna, "bProperty");
|
|
|
|
|
|
2008-12-02 23:45:11 +00:00
|
|
|
prop= RNA_def_property(srna, "value", PROP_FLOAT, PROP_NONE);
|
2010-12-31 04:12:20 +00:00
|
|
|
// RNA_def_property_float_sdna(prop, NULL, "data");
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Value", "Property value");
|
2008-12-02 01:05:23 +00:00
|
|
|
RNA_def_property_range(prop, -10000, 10000);
|
2008-12-02 23:45:11 +00:00
|
|
|
RNA_def_property_float_funcs(prop, "rna_GameFloatProperty_value_get", "rna_GameFloatProperty_value_set", NULL);
|
2010-05-08 22:11:00 +00:00
|
|
|
RNA_def_property_update(prop, NC_LOGIC, NULL);
|
2008-12-02 01:05:23 +00:00
|
|
|
|
|
|
|
|
/* GameStringProperty */
|
2008-12-19 04:06:24 +00:00
|
|
|
srna= RNA_def_struct(brna, "GameStringProperty", "GameProperty");
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_struct_ui_text(srna, "Game String Property", "Game engine user defined text string property");
|
2008-12-02 01:05:23 +00:00
|
|
|
RNA_def_struct_sdna(srna, "bProperty");
|
|
|
|
|
|
2008-12-02 23:45:11 +00:00
|
|
|
prop= RNA_def_property(srna, "value", PROP_STRING, PROP_NONE);
|
2008-12-02 01:05:23 +00:00
|
|
|
RNA_def_property_string_sdna(prop, NULL, "poin");
|
2008-12-02 23:45:11 +00:00
|
|
|
RNA_def_property_string_maxlength(prop, MAX_PROPSTRING);
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Value", "Property value");
|
2010-05-08 22:11:00 +00:00
|
|
|
RNA_def_property_update(prop, NC_LOGIC, NULL);
|
2008-11-30 19:52:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|