forked from bartvdbraak/blender
2.49 feature: Game Controller State name shows up when mouse over them (the name of a state is the name of the top controller of this state)
review and small tweaks by Campbell Barton
This commit is contained in:
parent
b889e9c573
commit
184a232ccc
@ -74,5 +74,7 @@ void sca_move_sensor(struct bSensor *sens_to_move, struct Object *ob, int move_u
|
||||
void sca_move_controller(struct bController *cont_to_move, struct Object *ob, int move_up);
|
||||
void sca_move_actuator(struct bActuator *act_to_move, struct Object *ob, int move_up);
|
||||
|
||||
const char *sca_state_name_get(Object *ob, short bit);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -875,3 +875,20 @@ void unlink_logicbricks(void **poin, void ***ppoin, short *tot)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const char *sca_state_name_get(Object *ob, short bit)
|
||||
{
|
||||
bController *cont;
|
||||
unsigned int mask;
|
||||
|
||||
mask = (1<<bit);
|
||||
cont = ob->controllers.first;
|
||||
while (cont) {
|
||||
if (cont->state_mask & mask) {
|
||||
return cont->name;
|
||||
}
|
||||
cont = cont->next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -810,6 +810,8 @@ void uiTemplateCurveMapping(uiLayout *layout, struct PointerRNA *ptr, const char
|
||||
void uiTemplateColorWheel(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int value_slider, int lock, int lock_luminosity, int cubic);
|
||||
void uiTemplateLayers(uiLayout *layout, struct PointerRNA *ptr, const char *propname,
|
||||
PointerRNA *used_ptr, const char *used_propname, int active_layer);
|
||||
void uiTemplateGameStates(uiLayout *layout, struct PointerRNA *ptr, const char *propname,
|
||||
PointerRNA *used_ptr, const char *used_propname, int active_state);
|
||||
void uiTemplateImage(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, const char *propname, struct PointerRNA *userptr, int compact);
|
||||
void uiTemplateImageSettings(uiLayout *layout, struct PointerRNA *imfptr, int color_management);
|
||||
void uiTemplateImageLayers(uiLayout *layout, struct bContext *C, struct Image *ima, struct ImageUser *iuser);
|
||||
|
@ -57,6 +57,7 @@
|
||||
#include "BKE_texture.h"
|
||||
#include "BKE_report.h"
|
||||
#include "BKE_displist.h"
|
||||
#include "BKE_sca.h"
|
||||
#include "BKE_scene.h"
|
||||
|
||||
#include "ED_screen.h"
|
||||
@ -2089,6 +2090,74 @@ void uiTemplateLayers(uiLayout *layout, PointerRNA *ptr, const char *propname,
|
||||
}
|
||||
}
|
||||
|
||||
void uiTemplateGameStates(uiLayout *layout, PointerRNA *ptr, const char *propname,
|
||||
PointerRNA *used_ptr, const char *used_propname, int active_state)
|
||||
{
|
||||
uiLayout *uRow, *uCol;
|
||||
PropertyRNA *prop, *used_prop = NULL;
|
||||
int groups, cols, states;
|
||||
int group, col, state, row;
|
||||
int cols_per_group = 5;
|
||||
Object *ob = (Object *)ptr->id.data;
|
||||
|
||||
prop = RNA_struct_find_property(ptr, propname);
|
||||
if (!prop) {
|
||||
RNA_warning("states property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
|
||||
return;
|
||||
}
|
||||
|
||||
/* the number of states determines the way we group them
|
||||
* - we want 2 rows only (for now)
|
||||
* - the number of columns (cols) is the total number of buttons per row
|
||||
* the 'remainder' is added to this, as it will be ok to have first row slightly wider if need be
|
||||
* - for now, only split into groups if group will have at least 5 items
|
||||
*/
|
||||
states = RNA_property_array_length(ptr, prop);
|
||||
cols = (states / 2) + (states % 2);
|
||||
groups = ((cols / 2) < cols_per_group) ? (1) : (cols / cols_per_group);
|
||||
|
||||
if (used_ptr && used_propname) {
|
||||
used_prop = RNA_struct_find_property(used_ptr, used_propname);
|
||||
if (!used_prop) {
|
||||
RNA_warning("used layers property not found: %s.%s", RNA_struct_identifier(ptr->type), used_propname);
|
||||
return;
|
||||
}
|
||||
|
||||
if (RNA_property_array_length(used_ptr, used_prop) < states)
|
||||
used_prop = NULL;
|
||||
}
|
||||
|
||||
/* layers are laid out going across rows, with the columns being divided into groups */
|
||||
|
||||
for (group = 0; group < groups; group++) {
|
||||
uCol = uiLayoutColumn(layout, TRUE);
|
||||
|
||||
for (row = 0; row < 2; row++) {
|
||||
uiBlock *block;
|
||||
uiBut *but;
|
||||
|
||||
uRow = uiLayoutRow(uCol, TRUE);
|
||||
block = uiLayoutGetBlock(uRow);
|
||||
state = groups * cols_per_group * row + cols_per_group * group;
|
||||
|
||||
/* add layers as toggle buts */
|
||||
for (col = 0; (col < cols_per_group) && (state < states); col++, state++) {
|
||||
int icon = 0;
|
||||
int butlay = 1 << state;
|
||||
|
||||
if (active_state & butlay)
|
||||
icon = ICON_LAYER_ACTIVE;
|
||||
else if (used_prop && RNA_property_boolean_get_index(used_ptr, used_prop, state))
|
||||
icon = ICON_LAYER_USED;
|
||||
|
||||
but = uiDefIconButR_prop(block, ICONTOG, 0, icon, 0, 0, UI_UNIT_X / 2, UI_UNIT_Y / 2, ptr, prop, state, 0, 0, -1, -1, sca_state_name_get(ob, state));
|
||||
uiButSetFunc(but, handle_layer_buttons, but, SET_INT_IN_POINTER(state));
|
||||
but->type = TOG;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/************************* List Template **************************/
|
||||
|
||||
|
@ -1786,22 +1786,6 @@ static void update_object_actuator_PID(bContext *UNUSED(C), void *act, void *UNU
|
||||
oa->forcerot[0] = 60.0f*oa->forcerot[1];
|
||||
}
|
||||
|
||||
static char *get_state_name(Object *ob, short bit)
|
||||
{
|
||||
bController *cont;
|
||||
unsigned int mask;
|
||||
|
||||
mask = (1<<bit);
|
||||
cont = ob->controllers.first;
|
||||
while (cont) {
|
||||
if (cont->state_mask & mask) {
|
||||
return cont->name;
|
||||
}
|
||||
cont = cont->next;
|
||||
}
|
||||
return (char*)"";
|
||||
}
|
||||
|
||||
static void check_state_mask(bContext *C, void *arg1_but, void *arg2_mask)
|
||||
{
|
||||
wmWindow *win= CTX_wm_window(C);
|
||||
@ -2632,11 +2616,11 @@ static short draw_actuatorbuttons(Main *bmain, Object *ob, bActuator *act, uiBlo
|
||||
for (wval=0; wval<15; wval+=5) {
|
||||
uiBlockBeginAlign(block);
|
||||
for (stbit=0; stbit<5; stbit++) {
|
||||
but = uiDefButBitI(block, TOG, 1<<(stbit+wval), stbit+wval, "", (short)(xco+85+12*stbit+13*wval), yco-17, 12, 12, (int *)&(staAct->mask), 0, 0, 0, 0, get_state_name(ob, (short)(stbit+wval)));
|
||||
but = uiDefButBitI(block, TOG, 1<<(stbit+wval), stbit+wval, "", (short)(xco+85+12*stbit+13*wval), yco-17, 12, 12, (int *)&(staAct->mask), 0, 0, 0, 0, sca_state_name_get(ob, (short)(stbit+wval)));
|
||||
uiButSetFunc(but, check_state_mask, but, &(staAct->mask));
|
||||
}
|
||||
for (stbit=0; stbit<5; stbit++) {
|
||||
but = uiDefButBitI(block, TOG, 1<<(stbit+wval+15), stbit+wval+15, "", (short)(xco+85+12*stbit+13*wval), yco-29, 12, 12, (int *)&(staAct->mask), 0, 0, 0, 0, get_state_name(ob, (short)(stbit+wval+15)));
|
||||
but = uiDefButBitI(block, TOG, 1<<(stbit+wval+15), stbit+wval+15, "", (short)(xco+85+12*stbit+13*wval), yco-29, 12, 12, (int *)&(staAct->mask), 0, 0, 0, 0, sca_state_name_get(ob, (short)(stbit+wval+15)));
|
||||
uiButSetFunc(but, check_state_mask, but, &(staAct->mask));
|
||||
}
|
||||
}
|
||||
@ -4573,9 +4557,9 @@ static void logic_buttons_new(bContext *C, ARegion *ar)
|
||||
col = uiLayoutColumn(subsplit, FALSE);
|
||||
row = uiLayoutRow(col, FALSE);
|
||||
uiLayoutSetActive(row, RNA_boolean_get(&settings_ptr, "use_all_states") == FALSE);
|
||||
uiTemplateLayers(row, &settings_ptr, "states_visible", &settings_ptr, "used_states", 0);
|
||||
uiTemplateGameStates(row, &settings_ptr, "states_visible", &settings_ptr, "used_states", 0);
|
||||
row = uiLayoutRow(col, FALSE);
|
||||
uiTemplateLayers(row, &settings_ptr, "states_initial", &settings_ptr, "used_states", 0);
|
||||
uiTemplateGameStates(row, &settings_ptr, "states_initial", &settings_ptr, "used_states", 0);
|
||||
|
||||
col = uiLayoutColumn(subsplit, FALSE);
|
||||
uiItemR(col, &settings_ptr, "use_all_states", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
|
||||
@ -4880,11 +4864,11 @@ void logic_buttons(bContext *C, ARegion *ar)
|
||||
for (offset=0; offset<15; offset+=5) {
|
||||
uiBlockBeginAlign(block);
|
||||
for (stbit=0; stbit<5; stbit++) {
|
||||
but = uiDefButBitI(block, controller_state_mask&(1<<(stbit+offset)) ? BUT_TOGDUAL:TOG, 1<<(stbit+offset), stbit+offset, "", (short)(xco+31+12*stbit+13*offset), yco, 12, 12, (int *)&(ob->state), 0, 0, 0, 0, get_state_name(ob, (short)(stbit+offset)));
|
||||
but = uiDefButBitI(block, controller_state_mask&(1<<(stbit+offset)) ? BUT_TOGDUAL:TOG, 1<<(stbit+offset), stbit+offset, "", (short)(xco+31+12*stbit+13*offset), yco, 12, 12, (int *)&(ob->state), 0, 0, 0, 0, sca_state_name_get(ob, (short)(stbit+offset)));
|
||||
uiButSetFunc(but, check_state_mask, but, &(ob->state));
|
||||
}
|
||||
for (stbit=0; stbit<5; stbit++) {
|
||||
but = uiDefButBitI(block, controller_state_mask&(1<<(stbit+offset+15)) ? BUT_TOGDUAL:TOG, 1<<(stbit+offset+15), stbit+offset+15, "", (short)(xco+31+12*stbit+13*offset), yco-12, 12, 12, (int *)&(ob->state), 0, 0, 0, 0, get_state_name(ob, (short)(stbit+offset+15)));
|
||||
but = uiDefButBitI(block, controller_state_mask&(1<<(stbit+offset+15)) ? BUT_TOGDUAL:TOG, 1<<(stbit+offset+15), stbit+offset+15, "", (short)(xco+31+12*stbit+13*offset), yco-12, 12, 12, (int *)&(ob->state), 0, 0, 0, 0, sca_state_name_get(ob, (short)(stbit+offset+15)));
|
||||
uiButSetFunc(but, check_state_mask, but, &(ob->state));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user