Logic UI: partial implementation of state per controller

Adding two rna properties: state and state_number

For scripting "state_number" (integer) makes more sense while "state" (boolean/array) may be needed for the UI.
So far the UI is only showing the state number (using Label). Still have to decide how is the better way to "change the state".

If we don't need "state" (as boolean) for the UI, we can have only the integer one and rename it to "state".

+ some cosmetic changes (renamed ob "states" to "visible states")

ps.: 2 goals == 2 commits... let's see if I can keep that ratio until the middle of July ...
This commit is contained in:
Dalai Felinto 2010-06-16 08:29:40 +00:00
parent bc8e0c0f93
commit 6a70a6bee2
4 changed files with 81 additions and 4 deletions

@ -484,7 +484,6 @@ static int actuator_add_exec(bContext *C, wmOperator *op)
PropertyRNA *prop;
const char *act_name;
char name[32];
//XXX RNA_string_get is not using maxlen, it's using UserPreferencesFilePaths_python_scripts_directory_get instead (what limits the string copy to 160 chars in this case and CRASHES Blender).
int type= RNA_enum_get(op->ptr, "type");
act= new_actuator(type);

@ -3507,6 +3507,7 @@ void draw_brick_sensor(uiLayout *layout, PointerRNA *ptr, bContext *C)
static void draw_controller_header(uiLayout *layout, PointerRNA *ptr)
{
uiLayout *box, *row;
char name[3]; //XXX provisorly for state number
box= uiLayoutBox(layout);
row= uiLayoutRow(box, 0);
@ -3514,6 +3515,11 @@ static void draw_controller_header(uiLayout *layout, PointerRNA *ptr)
uiItemR(row, ptr, "expanded", UI_ITEM_R_NO_BG, "", 0);
uiItemR(row, ptr, "type", 0, "", 0);
uiItemR(row, ptr, "name", 0, "", 0);
/* XXX provisory: state number */
sprintf(name, "%d", RNA_int_get(ptr, "state_number"));
uiItemL(row, name, 0);
uiItemR(row, ptr, "priority", 0, "", 0);
uiItemO(row, "", ICON_X, "LOGIC_OT_controller_remove");
}
@ -4425,7 +4431,7 @@ static void logic_buttons_new(bContext *C, ARegion *ar)
col= uiLayoutColumn(subsplit, 0);
row= uiLayoutRow(col, 0);
uiLayoutSetActive(row, RNA_boolean_get(&settings_ptr, "all_states")==0);
uiTemplateLayers(row, &settings_ptr, "state", &settings_ptr, "used_state", 0);
uiTemplateLayers(row, &settings_ptr, "visible_state", &settings_ptr, "used_state", 0);
row= uiLayoutRow(col, 0);
uiTemplateLayers(row, &settings_ptr, "initial_state", &settings_ptr, "used_state", 0);

@ -28,7 +28,7 @@
#include "RNA_define.h"
#include "rna_internal.h"
#include "DNA_object_types.h"
#include "DNA_controller_types.h"
EnumPropertyItem controller_type_items[] ={
@ -82,6 +82,60 @@ static void rna_Controller_type_set(struct PointerRNA *ptr, int value)
}
}
static int rna_Controller_state_number_get(struct PointerRNA *ptr)
{
bController *cont= (bController *)ptr->data;
int bit;
for (bit=0; bit<32; bit++) {
if (cont->state_mask & (1<<bit))
return bit+1;
}
return 0;
}
static int rna_Controller_state_number_set(struct PointerRNA *ptr, const int value)
{
bController *cont= (bController *)ptr->data;
if (value < 1 || value > OB_MAX_STATES)
return;
cont->state_mask = (1 << (value - 1));
}
static void rna_Controller_state_get(PointerRNA *ptr, int *values)
{
bController *cont= (bController *)ptr->data;
int i;
memset(values, 0, sizeof(int)*OB_MAX_STATES);
for(i=0; i<OB_MAX_STATES; i++)
values[i] = (cont->state_mask & (1<<i));
}
static void rna_Controller_state_set(PointerRNA *ptr, const int *values)
{
bController *cont= (bController *)ptr->data;
int i, tot= 0;
/* ensure we always have some state selected */
for(i=0; i<OB_MAX_STATES; i++)
if(values[i])
tot++;
if(tot==0)
return;
/* only works for one state at once */
if(tot>1)
return;
for(i=0; i<OB_MAX_STATES; i++) {
if(values[i]) cont->state_mask |= (1<<i);
else cont->state_mask &= ~(1<<i);
}
}
#else
void RNA_def_controller(BlenderRNA *brna)
@ -124,6 +178,24 @@ void RNA_def_controller(BlenderRNA *brna)
RNA_def_property_ui_icon(prop, ICON_BOOKMARKS, 1);
RNA_def_property_update(prop, NC_LOGIC, NULL);
/* State */
// array of OB_MAX_STATES
prop= RNA_def_property(srna, "state", PROP_BOOLEAN, PROP_LAYER_MEMBER);
RNA_def_property_array(prop, OB_MAX_STATES);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "", "Set Controller state index (1 to 30)");
RNA_def_property_boolean_funcs(prop, "rna_Controller_state_get", "rna_Controller_state_set");
RNA_def_property_update(prop, NC_LOGIC, NULL);
// number of the state
prop= RNA_def_property(srna, "state_number", PROP_INT, PROP_UNSIGNED);
RNA_def_property_int_sdna(prop, NULL, "state_mask");
RNA_def_property_range(prop, 1, OB_MAX_STATES);
RNA_def_property_ui_text(prop, "", "Set Controller state index (1 to 30)");
RNA_def_property_int_funcs(prop, "rna_Controller_state_number_get", "rna_Controller_state_number_set", NULL);
RNA_def_property_update(prop, NC_LOGIC, NULL);
/* Expression Controller */
srna= RNA_def_struct(brna, "ExpressionController", "Controller");
RNA_def_struct_sdna_from(srna, "bExpressionCont", "data");

@ -1264,7 +1264,7 @@ static void rna_def_object_game_settings(BlenderRNA *brna)
/* state */
prop= RNA_def_property(srna, "state", PROP_BOOLEAN, PROP_LAYER_MEMBER);
prop= RNA_def_property(srna, "visible_state", PROP_BOOLEAN, PROP_LAYER_MEMBER);
RNA_def_property_boolean_sdna(prop, NULL, "state", 1);
RNA_def_property_array(prop, OB_MAX_STATES);
RNA_def_property_ui_text(prop, "State", "State determining which controllers are displayed");