forked from bartvdbraak/blender
- Add remove game properties now possible from the logic space properties panel.
- PyDebugLine, utility function to run if the BGE crashes, you can see which python file and line called the C/C++ code.
This commit is contained in:
parent
043ad7bc8e
commit
c97d964064
@ -14,12 +14,17 @@ class LOGIC_PT_properties(bpy.types.Panel):
|
||||
ob = context.active_object
|
||||
game = ob.game
|
||||
|
||||
for prop in game.properties:
|
||||
flow = layout.row()
|
||||
for i, prop in enumerate(game.properties):
|
||||
flow = layout.row(align=True)
|
||||
flow.itemR(prop, "name", text="")
|
||||
flow.itemR(prop, "type", text="")
|
||||
flow.itemR(prop, "value", text="") # we dont care about the type. rna will display correctly
|
||||
flow.itemR(prop, "debug")
|
||||
flow.itemR(prop, "debug", text="", toggle=True, icon='ICON_INFO')
|
||||
flow.item_intO("object.game_property_remove", "index", i, text="", icon='ICON_X')
|
||||
|
||||
flow = layout.row()
|
||||
flow.itemO("object.game_property_new")
|
||||
|
||||
|
||||
|
||||
bpy.types.register(LOGIC_PT_properties)
|
||||
|
||||
|
@ -7161,3 +7161,72 @@ void ED_object_toggle_modes(bContext *C, int mode)
|
||||
if(mode & OB_MODE_PARTICLE_EDIT)
|
||||
WM_operator_name_call(C, "PARTICLE_OT_particle_edit_toggle", WM_OP_EXEC_REGION_WIN, NULL);
|
||||
}
|
||||
|
||||
/* game property ops */
|
||||
|
||||
static int game_property_new(bContext *C, wmOperator *op)
|
||||
{
|
||||
Object *ob= CTX_data_active_object(C);
|
||||
bProperty *prop;
|
||||
|
||||
if(!ob)
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
prop= new_property(PROP_FLOAT);
|
||||
BLI_addtail(&ob->prop, prop);
|
||||
unique_property(NULL, prop, 0); // make_unique_prop_names(prop->name);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
|
||||
void OBJECT_OT_game_property_new(wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
ot->name= "New Game Property";
|
||||
ot->idname= "OBJECT_OT_game_property_new";
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec= game_property_new;
|
||||
|
||||
/* flags */
|
||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||
}
|
||||
|
||||
static int game_property_remove(bContext *C, wmOperator *op)
|
||||
{
|
||||
Object *ob= CTX_data_active_object(C);
|
||||
bProperty *prop;
|
||||
int index;
|
||||
|
||||
if(!ob)
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
index = RNA_int_get(op->ptr, "index");
|
||||
|
||||
prop= BLI_findlink(&ob->prop, index);
|
||||
|
||||
if(prop) {
|
||||
BLI_remlink(&ob->prop, prop);
|
||||
free_property(prop);
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
else {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
}
|
||||
|
||||
void OBJECT_OT_game_property_remove(wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
ot->name= "Remove Game Property";
|
||||
ot->idname= "OBJECT_OT_game_property_remove";
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec= game_property_remove;
|
||||
|
||||
/* flags */
|
||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||
|
||||
RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "Property index to remove ", 0, INT_MAX);
|
||||
}
|
||||
|
@ -147,6 +147,9 @@ void OBJECT_OT_vertex_group_deselect(struct wmOperatorType *ot);
|
||||
void OBJECT_OT_vertex_group_copy_to_linked(struct wmOperatorType *ot);
|
||||
void OBJECT_OT_vertex_group_copy(struct wmOperatorType *ot);
|
||||
|
||||
void OBJECT_OT_game_property_new(struct wmOperatorType *ot);
|
||||
void OBJECT_OT_game_property_remove(struct wmOperatorType *ot);
|
||||
|
||||
/* editkey.c */
|
||||
void OBJECT_OT_shape_key_add(struct wmOperatorType *ot);
|
||||
void OBJECT_OT_shape_key_remove(struct wmOperatorType *ot);
|
||||
|
@ -150,6 +150,9 @@ void ED_operatortypes_object(void)
|
||||
WM_operatortype_append(OBJECT_OT_vertex_group_copy_to_linked);
|
||||
WM_operatortype_append(OBJECT_OT_vertex_group_copy);
|
||||
|
||||
WM_operatortype_append(OBJECT_OT_game_property_new);
|
||||
WM_operatortype_append(OBJECT_OT_game_property_remove);
|
||||
|
||||
WM_operatortype_append(OBJECT_OT_shape_key_add);
|
||||
WM_operatortype_append(OBJECT_OT_shape_key_remove);
|
||||
|
||||
|
@ -906,45 +906,47 @@ void PyObjectPlus::SetDeprecationWarnings(bool ignoreDeprecationWarnings)
|
||||
m_ignore_deprecation_warnings = ignoreDeprecationWarnings;
|
||||
}
|
||||
|
||||
void PyObjectPlus::ShowDeprecationWarning_func(const char* old_way,const char* new_way)
|
||||
void PyDebugLine()
|
||||
{
|
||||
{
|
||||
printf("Method %s is deprecated, please use %s instead.\n", old_way, new_way);
|
||||
|
||||
// import sys; print '\t%s:%d' % (sys._getframe(0).f_code.co_filename, sys._getframe(0).f_lineno)
|
||||
|
||||
PyObject *getframe, *frame;
|
||||
PyObject *f_lineno, *f_code, *co_filename;
|
||||
|
||||
getframe = PySys_GetObject((char *)"_getframe"); // borrowed
|
||||
if (getframe) {
|
||||
frame = PyObject_CallObject(getframe, NULL);
|
||||
if (frame) {
|
||||
f_lineno= PyObject_GetAttrString(frame, "f_lineno");
|
||||
f_code= PyObject_GetAttrString(frame, "f_code");
|
||||
if (f_lineno && f_code) {
|
||||
co_filename= PyObject_GetAttrString(f_code, "co_filename");
|
||||
if (co_filename) {
|
||||
|
||||
printf("\t%s:%d\n", _PyUnicode_AsString(co_filename), (int)PyLong_AsSsize_t(f_lineno));
|
||||
|
||||
Py_DECREF(f_lineno);
|
||||
Py_DECREF(f_code);
|
||||
Py_DECREF(co_filename);
|
||||
Py_DECREF(frame);
|
||||
return;
|
||||
}
|
||||
// import sys; print '\t%s:%d' % (sys._getframe(0).f_code.co_filename, sys._getframe(0).f_lineno)
|
||||
|
||||
PyObject *getframe, *frame;
|
||||
PyObject *f_lineno, *f_code, *co_filename;
|
||||
|
||||
getframe = PySys_GetObject((char *)"_getframe"); // borrowed
|
||||
if (getframe) {
|
||||
frame = PyObject_CallObject(getframe, NULL);
|
||||
if (frame) {
|
||||
f_lineno= PyObject_GetAttrString(frame, "f_lineno");
|
||||
f_code= PyObject_GetAttrString(frame, "f_code");
|
||||
if (f_lineno && f_code) {
|
||||
co_filename= PyObject_GetAttrString(f_code, "co_filename");
|
||||
if (co_filename) {
|
||||
|
||||
printf("\t%s:%d\n", _PyUnicode_AsString(co_filename), (int)PyLong_AsSsize_t(f_lineno));
|
||||
|
||||
Py_DECREF(f_lineno);
|
||||
Py_DECREF(f_code);
|
||||
Py_DECREF(co_filename);
|
||||
Py_DECREF(frame);
|
||||
return;
|
||||
}
|
||||
|
||||
Py_XDECREF(f_lineno);
|
||||
Py_XDECREF(f_code);
|
||||
Py_DECREF(frame);
|
||||
}
|
||||
|
||||
Py_XDECREF(f_lineno);
|
||||
Py_XDECREF(f_code);
|
||||
Py_DECREF(frame);
|
||||
}
|
||||
PyErr_Clear();
|
||||
printf("\tERROR - Could not access sys._getframe(0).f_lineno or sys._getframe().f_code.co_filename\n");
|
||||
|
||||
}
|
||||
PyErr_Clear();
|
||||
printf("\tERROR - Could not access sys._getframe(0).f_lineno or sys._getframe().f_code.co_filename\n");
|
||||
}
|
||||
|
||||
void PyObjectPlus::ShowDeprecationWarning_func(const char* old_way,const char* new_way)
|
||||
{
|
||||
printf("Method %s is deprecated, please use %s instead.\n", old_way, new_way);
|
||||
PyDebugLine();
|
||||
}
|
||||
|
||||
void PyObjectPlus::ClearDeprecationWarning()
|
||||
|
Loading…
Reference in New Issue
Block a user