def __on_change_type(self, event): if self.transition_path != None and not self.skip_change_type_event: # Remove transition from state transition = self.__get_transition() state = self.__get_state() state.removetransition(transition) # Get free conditions for the selected transition type state_path = fsm.get_state_of_transition(self.transition_path) conds_paths = get_free_conditions(event.GetSelection(), state_path) # Delete condition if it's an event condition with filter cond_path = fsm.get_filteredcondition_of_transition( self.transition_path) try: pynebula.lookup(cond_path) pynebula.delete(cond_path) except: pass # Set first free condition for the selected transition type transition.setcondition(pynebula.lookup(conds_paths[0])) # Add transition to state state.addtransition(transition) # Refresh condition parameters panel if self.GetSelection() == 0: self.panel_event.set_transition(self.transition_path) else: self.panel_script.set_transition(self.transition_path) # Signal change fsmevents.signal_fsm_change(self, self.transition_path)
def __on_change_type(self, event): if self.transition_path != None and not self.skip_change_type_event: # Remove transition from state transition = self.__get_transition() state = self.__get_state() state.removetransition( transition ) # Get free conditions for the selected transition type state_path = fsm.get_state_of_transition( self.transition_path ) conds_paths = get_free_conditions( event.GetSelection(), state_path ) # Delete condition if it's an event condition with filter cond_path = fsm.get_filteredcondition_of_transition( self.transition_path ) try: pynebula.lookup( cond_path ) pynebula.delete( cond_path ) except: pass # Set first free condition for the selected transition type transition.setcondition( pynebula.lookup(conds_paths[0]) ) # Add transition to state state.addtransition( transition ) # Refresh condition parameters panel if self.GetSelection() == 0: self.panel_event.set_transition( self.transition_path ) else: self.panel_script.set_transition( self.transition_path ) # Signal change fsmevents.signal_fsm_change( self, self.transition_path )
def __on_delete_state(self, event): """Ask to confirm the state deletion and delete it if so""" state_name = self.list_states.GetStringSelection() if state_name != "": msg = "Deleting a state cannot be undone.\n" msg = msg + "Are you sure that you want to delete the " msg = msg + "'" + state_name + "' state?" result = cjr.warn_yes_no(self, msg) if result == wx.ID_YES: # Delete all transition targets pointing to the state to be deleted state = self.__get_current_state() fsm_ = fsm.get_fsm_of_state( state.getfullname() ) states = fsm.get_states( fsm_ ) for s in states: transitions = fsm.get_transitions(s) for t in transitions: t_obj = pynebula.lookup(t) t_obj.removetarget(state) # Delete the transition if it's emmpty after deleting the target if t_obj.gettargetsnumber() == 0: s_obj = pynebula.lookup(s) s_obj.deletetransition(t_obj) t_obj = None # Delete the state self.__get_fsm().deletestate( state ) state = None self.list_states.Delete( self.list_states.GetSelection() ) self.__on_select_state(None) fsmevents.signal_fsm_change(self)
def on_change_action(self, event): action = self.__get_action() i = 0 pid = self.pg.get_first_child_of_category(None) while pid is not None: type = self.pg.get_property_type(pid) if type == propgrid.Type_Bool: action.setboolarg( i, self.pg.get_property_value(pid) ) elif type == propgrid.Type_Float: action.setfloatarg( i, self.pg.get_property_value(pid) ) elif type == propgrid.Type_Int: action.setintarg( i, self.pg.get_property_value(pid) ) elif type == propgrid.Type_Object: action.setentityarg( i, self.pg.get_property_value(pid) ) elif type == propgrid.Type_String: action.setstringarg( i, str(self.pg.get_property_value(pid)) ) elif type == propgrid.Type_Vector3: v = self.pg.get_property_value(pid) action.setvector3arg( i, v[0], v[1], v[2] ) else: name = self.pg.get_property_name(pid) raise TypeError, "Unsupported type '" + type + "' for property '" + name + "'" i = i + len(type) pid = self.pg.get_next_sibling(pid) fsmevents.signal_fsm_change( self )
def __on_new_state(self, event): """Create a new state with default values""" state_path = fsm.get_free_name( self.fsm_path, 'state' ) state = fsmstatetype.create_default_state( state_path ) if state != None: self.__get_fsm().addstate( state ) self.list_states.Append( get_state_gui_name(state_path) ) fsmevents.signal_fsm_change(self, fsmevents.ID_NewState)
def __on_delete_target(self, event): """Delete the current selected target""" target_index = self.__get_current_target() self.__get_transition().removetargetbyindex( target_index ) self.list_targets.DeleteItem( target_index ) self.__on_select_target(None) self.__update_total_probability() self.__update_new_button() fsmevents.signal_fsm_change(self)
def __on_delete_target(self, event): """Delete the current selected target""" target_index = self.__get_current_target() self.__get_transition().removetargetbyindex(target_index) self.list_targets.DeleteItem(target_index) self.__on_select_target(None) self.__update_total_probability() self.__update_new_button() fsmevents.signal_fsm_change(self)
def __on_select_script(self, event): transition = pynebula.lookup( self.transition_path ) state_path = fsm.get_state_of_transition( self.transition_path ) state = pynebula.lookup( state_path ) state.removetransition( transition ) condition = servers.get_fsm_server().getscriptcondition( str(self.choice_script.GetStringSelection()) ) transition.setcondition( condition ) state.addtransition( transition ) fsmevents.signal_fsm_change( self, self.transition_path )
def __on_select_script(self, event): transition = pynebula.lookup(self.transition_path) state_path = fsm.get_state_of_transition(self.transition_path) state = pynebula.lookup(state_path) state.removetransition(transition) condition = servers.get_fsm_server().getscriptcondition( str(self.choice_script.GetStringSelection())) transition.setcondition(condition) state.addtransition(transition) fsmevents.signal_fsm_change(self, self.transition_path)
def __on_change_state(self, event): state_path = fsm.find_path( fsm.get_fsm_of_transition( self.transition_path ), self.choice_state.GetStringSelection(), fsmstates.get_state_gui_name ) if self.__get_transition().gettargetstatebyindex( self.target_index ).getfullname() != state_path: self.__get_transition().settargetstatebyindex( self.target_index, pynebula.lookup( state_path ) ) fsmevents.signal_fsm_change(self, self.target_index)
def __on_change_state(self, event): state_path = fsm.find_path( fsm.get_fsm_of_transition(self.transition_path), self.choice_state.GetStringSelection(), fsmstates.get_state_gui_name) if self.__get_transition().gettargetstatebyindex( self.target_index).getfullname() != state_path: self.__get_transition().settargetstatebyindex( self.target_index, pynebula.lookup(state_path)) fsmevents.signal_fsm_change(self, self.target_index)
def __on_change_type(self, event): if self.state_path != None and not self.skip_change_type_event: # Rename the old state to keep it while building the new one old_state = self.__get_state() old_state.setname('_tmp') # Create new state for the new state type if self.GetSelection() == self.ID_NodeStatePanel: new_state = create_default_state(self.state_path, 'nnodestate') elif self.GetSelection() == self.ID_LeafStatePanel: new_state = create_default_state(self.state_path, 'nleafstate') else: new_state = create_default_state(self.state_path, 'nendstate') if new_state == None: # If creating a default state fails abort and restore old state old_state.setname(str(format.get_name(self.state_path))) self.skip_change_type_event = True self.SetSelection(event.GetOldSelection()) self.skip_change_type_event = False return fsm_ = self.__get_fsm() fsm_.addstate(new_state) # Copy info that's independent of the state type old_trans_path = fsm.get_transitions_dir_of_state( old_state.getfullname()) new_trans_path = fsm.get_transitions_dir_of_state( new_state.getfullname(), False) pynebula.lookup(str(old_trans_path)).clone(str(new_trans_path)) transitions = fsm.get_transitions(new_state.getfullname()) for t in transitions: t_obj = pynebula.lookup(t) new_state.addtransition(t_obj) if fsm_.getinitialstate() == old_state: fsm_.setinitialstate(new_state) # Update all transitions to point to the new state if pointing the old one states = fsm.get_states(fsm_.getfullname()) for s in states: transitions = fsm.get_transitions(s) for t in transitions: t_obj = pynebula.lookup(t) for i in range(t_obj.gettargetsnumber()): if t_obj.gettargetstatebyindex(i) == old_state: t_obj.settargetstatebyindex(i, new_state) # Delete old state fsm_.deletestate(old_state) old_state = None # Python, release that #$%&/)?! reference NOW! # Update type specific controls self.__update_controls() # Signal change fsmevents.signal_fsm_change(self, self.state_path)
def __on_update_condition(self, event): # Remove transition from state transition = self.__get_transition() state_path = fsm.get_state_of_transition(self.transition_path) state = pynebula.lookup(state_path) state.removetransition(transition) # Get old event and filter old_cond_obj = transition.getcondition() old_event_id = old_cond_obj.getevent() old_filter_obj = old_cond_obj.getfiltercondition() # Get new event and filter # new_event_name = self.choice_event.GetStringSelection() # new_event_id = servers.get_fsm_server().geteventcondition( str(new_event_name) ).getevent() new_event_id = self.event_ids[self.choice_event.GetSelection()] new_filter_name = self.choice_filter.GetStringSelection() new_filter_obj = None if new_filter_name != "<none>": new_filter_obj = servers.get_fsm_server().getscriptcondition( str(new_filter_name)) # Act depending on filter condition existance and selection local_cond_path = fsm.get_filteredcondition_of_transition( self.transition_path) if old_filter_obj == None: if new_filter_obj == None: # Neither the old or the new conditions have a filter # Just select a shared condition new_cond_obj = get_event_condition( new_event_id ) #servers.get_fsm_server().geteventcondition( str(new_event_name) ) else: # The old condition doesn't have a filter, but the new one does # Create a local condition, with the same event and new filter new_cond_obj = pynebula.new('neventcondition', local_cond_path) new_cond_obj.setevent(new_event_id) new_cond_obj.setfiltercondition(new_filter_obj) else: if new_filter_obj == None: # The old condition has a filter, but the new one doesn't # Remove the local condition and select a shared condition old_cond_obj = None pynebula.delete(str(local_cond_path)) new_cond_obj = get_event_condition( new_event_id ) #servers.get_fsm_server().geteventcondition( str(new_event_name) ) else: # Both the old and the new conditions have a filter # Update the local condition with the new event new_cond_obj = old_cond_obj new_cond_obj.setevent(new_event_id) # Reinsert the transition into the state transition.setcondition(new_cond_obj) state.addtransition(transition) # Signal the change fsmevents.signal_fsm_change(self, self.transition_path)
def __on_change_type(self, event): if self.state_path != None and not self.skip_change_type_event: # Rename the old state to keep it while building the new one old_state = self.__get_state() old_state.setname("_tmp") # Create new state for the new state type if self.GetSelection() == self.ID_NodeStatePanel: new_state = create_default_state(self.state_path, "nnodestate") elif self.GetSelection() == self.ID_LeafStatePanel: new_state = create_default_state(self.state_path, "nleafstate") else: new_state = create_default_state(self.state_path, "nendstate") if new_state == None: # If creating a default state fails abort and restore old state old_state.setname(str(format.get_name(self.state_path))) self.skip_change_type_event = True self.SetSelection(event.GetOldSelection()) self.skip_change_type_event = False return fsm_ = self.__get_fsm() fsm_.addstate(new_state) # Copy info that's independent of the state type old_trans_path = fsm.get_transitions_dir_of_state(old_state.getfullname()) new_trans_path = fsm.get_transitions_dir_of_state(new_state.getfullname(), False) pynebula.lookup(str(old_trans_path)).clone(str(new_trans_path)) transitions = fsm.get_transitions(new_state.getfullname()) for t in transitions: t_obj = pynebula.lookup(t) new_state.addtransition(t_obj) if fsm_.getinitialstate() == old_state: fsm_.setinitialstate(new_state) # Update all transitions to point to the new state if pointing the old one states = fsm.get_states(fsm_.getfullname()) for s in states: transitions = fsm.get_transitions(s) for t in transitions: t_obj = pynebula.lookup(t) for i in range(t_obj.gettargetsnumber()): if t_obj.gettargetstatebyindex(i) == old_state: t_obj.settargetstatebyindex(i, new_state) # Delete old state fsm_.deletestate(old_state) old_state = None # Python, release that #$%&/)?! reference NOW! # Update type specific controls self.__update_controls() # Signal change fsmevents.signal_fsm_change(self, self.state_path)
def on_change_type(self, event): # replace old action with a new one for the new action type if self.action_path != None and not self.skip_change_type_event: state_path = fsm.get_state_of_behaction( self.action_path ) state = pynebula.lookup( state_path ) action = pynebula.lookup( str(self.action_path) ) ## action_panel = self.GetPage( event.GetSelection() ) ## action.setactiontype( action_panel.action_id ) ## action_panel.update_action( action ) action.setactionclass( str( self.choice.GetStringSelection() ) ) self.__update_propgrid() fsmevents.signal_fsm_change( self )
def __on_new_target(self, event): """Create a new target with default values""" # Create a transition to the first free target state by default state = pynebula.lookup(get_free_targets(self.transition_path)[0]) probability = 100 self.__get_transition().addtarget(state, probability) index = self.list_targets.GetItemCount() gui_name = fsmstates.get_state_gui_name(state.getfullname()) self.list_targets.InsertStringItem(index, gui_name) self.list_targets.SetStringItem(index, 1, str(probability) + "%") self.__update_total_probability() self.__update_new_button() fsmevents.signal_fsm_change(self, fsmevents.ID_NewTarget)
def __on_new_target(self, event): """Create a new target with default values""" # Create a transition to the first free target state by default state = pynebula.lookup( get_free_targets(self.transition_path)[0] ) probability = 100 self.__get_transition().addtarget( state, probability ) index = self.list_targets.GetItemCount() gui_name = fsmstates.get_state_gui_name( state.getfullname() ) self.list_targets.InsertStringItem( index, gui_name ) self.list_targets.SetStringItem( index, 1, str(probability) + "%" ) self.__update_total_probability() self.__update_new_button() fsmevents.signal_fsm_change(self, fsmevents.ID_NewTarget)
def __on_update_condition(self, event): # Remove transition from state transition = self.__get_transition() state_path = fsm.get_state_of_transition( self.transition_path ) state = pynebula.lookup( state_path ) state.removetransition( transition ) # Get old event and filter old_cond_obj = transition.getcondition() old_event_id = old_cond_obj.getevent() old_filter_obj = old_cond_obj.getfiltercondition() # Get new event and filter # new_event_name = self.choice_event.GetStringSelection() # new_event_id = servers.get_fsm_server().geteventcondition( str(new_event_name) ).getevent() new_event_id = self.event_ids[ self.choice_event.GetSelection() ] new_filter_name = self.choice_filter.GetStringSelection() new_filter_obj = None if new_filter_name != "<none>": new_filter_obj = servers.get_fsm_server().getscriptcondition( str(new_filter_name) ) # Act depending on filter condition existance and selection local_cond_path = fsm.get_filteredcondition_of_transition( self.transition_path ) if old_filter_obj == None: if new_filter_obj == None: # Neither the old or the new conditions have a filter # Just select a shared condition new_cond_obj = get_event_condition( new_event_id ) #servers.get_fsm_server().geteventcondition( str(new_event_name) ) else: # The old condition doesn't have a filter, but the new one does # Create a local condition, with the same event and new filter new_cond_obj = pynebula.new( 'neventcondition', local_cond_path ) new_cond_obj.setevent( new_event_id ) new_cond_obj.setfiltercondition( new_filter_obj ) else: if new_filter_obj == None: # The old condition has a filter, but the new one doesn't # Remove the local condition and select a shared condition old_cond_obj = None pynebula.delete( str(local_cond_path) ) new_cond_obj = get_event_condition( new_event_id ) #servers.get_fsm_server().geteventcondition( str(new_event_name) ) else: # Both the old and the new conditions have a filter # Update the local condition with the new event new_cond_obj = old_cond_obj new_cond_obj.setevent( new_event_id ) # Reinsert the transition into the state transition.setcondition( new_cond_obj ) state.addtransition( transition ) # Signal the change fsmevents.signal_fsm_change( self, self.transition_path )
def __on_delete_transition(self, event): """Ask to confirm the transition deletion and delete it if so""" transition_name = self.list_transitions.GetStringSelection() if transition_name != "": msg = "Deleting a transition cannot be undone.\n" msg = msg + "Are you sure that you want to delete the " msg = msg + "'" + transition_name + "' transition?" result = cjr.warn_yes_no(self, msg) if dlg.ShowModal() == wx.ID_YES: transition = self.__get_current_transition() self.__get_state().deletetransition( transition ) transition = None self.list_transitions.Delete( self.list_transitions.GetSelection() ) self.__on_select_transition(None) self.__update_new_button() fsmevents.signal_fsm_change(self)
def __on_change_name(self, event): # Change the FSM file and object names fsm = pynebula.lookup( self.fsm_path ) old_name = str( format.get_name( self.fsm_path ) ) new_name = str( self.text_name.get_value() ) fsm.setname( new_name ) servers.get_fsm_server().savefsm( fsm ) fsm.setname( old_name ) servers.get_fsm_server().erasefsm( fsm ) fsm.setname( new_name ) # Update the controls self.fsm_path = fsm.getfullname() self.ctrl_states.set_fsm( self.fsm_path ) self.ctrl_statetype.set_state(None) self.ctrl_transitions.set_state(None) # self.ctrl_emotactions.set_state(None) # Notify change to update the name in the FSM library app.get_top_window(self).emit_app_event( events.FSMNameChanged( new_name=new_name, old_name=old_name ) ) fsmevents.signal_fsm_change( self, fsmevents.ID_FSMNameChanged, self.fsm_path )
def __on_change_name(self, event): # Change the FSM file and object names fsm = pynebula.lookup(self.fsm_path) old_name = str(format.get_name(self.fsm_path)) new_name = str(self.text_name.get_value()) fsm.setname(new_name) servers.get_fsm_server().savefsm(fsm) fsm.setname(old_name) servers.get_fsm_server().erasefsm(fsm) fsm.setname(new_name) # Update the controls self.fsm_path = fsm.getfullname() self.ctrl_states.set_fsm(self.fsm_path) self.ctrl_statetype.set_state(None) self.ctrl_transitions.set_state(None) # self.ctrl_emotactions.set_state(None) # Notify change to update the name in the FSM library app.get_top_window(self).emit_app_event( events.FSMNameChanged(new_name=new_name, old_name=old_name)) fsmevents.signal_fsm_change(self, fsmevents.ID_FSMNameChanged, self.fsm_path)
def __on_new_transition(self, event): """Create a new transition with default values""" # Get the first free condition by default cond_paths = fsmtransitiontype.get_free_event_conditions( self.state_path ) if len(cond_paths) == 0: cond_paths = fsmtransitiontype.get_free_script_conditions( self.state_path ) if len(cond_paths) == 0: cjr.show_information_message( "This state already has transitions for all " \ "the available conditions." ) return condition = pynebula.lookup( cond_paths[0] ) # Create the transition with a free name transition_path = fsm.get_free_name( self.__get_transitions_path(), 'transition' ) transition = pynebula.new( "ntransition", transition_path ) transition.setcondition( condition ) self.__get_state().addtransition( transition ) self.list_transitions.Append( get_transition_gui_name( transition.getfullname() ) ) self.__update_new_button() fsmevents.signal_fsm_change(self, fsmevents.ID_NewTransition)
def __on_change_current_state_type(self, event): self.ctrl_states.refresh_current_state_name( event.get_value() ) fsmevents.signal_fsm_change( self )
def __on_change_current_transition_type(self, event): self.ctrl_list.refresh_current_transition_name( event.get_value() ) fsmevents.signal_fsm_change(self)
def __on_change_state(self, event): fsmevents.signal_fsm_change(self) if event.get_value() != None: if event.get_value() == fsmevents.ID_NewTransition: self.ctrl_type.on_new_transition()
def __on_choice_selector(self, event): selector_name = str(self.choice_selector.GetStringSelection()) self.__get_state().setfsmselectorbyname(str(selector_name)) fsmevents.signal_fsm_change(self, self.state_path)
def __on_change_current_target(self, event): self.list_ctrl.refresh_current_target(event.get_value()) fsmevents.signal_fsm_change(self)
def __on_change_condition(self, event): fsmevents.signal_fsm_change(self, event.get_value())
def __on_change_probability(self, event): self.__get_transition().settargetprobabilitybyindex( self.target_index, self.spin_probability.GetValue()) if not self.skip_fsm_change_event: fsmevents.signal_fsm_change(self, self.target_index)
def update_action(self, action): ActionPanel.update_action(self, action) action.clearargs() class_name = str( self.choice_script.GetStringSelection() ) action.appendstringarg( class_name ) fsmevents.signal_fsm_change( self )
def __on_change_current_state_type(self, event): self.ctrl_states.refresh_current_state_name(event.get_value()) fsmevents.signal_fsm_change(self)
def __on_change_action(self, event): fsmevents.signal_fsm_change( self )
def __on_change_action(self, event): fsmevents.signal_fsm_change(self, self.state_path)
def __on_change_state(self, event): fsmevents.signal_fsm_change(self, event.get_value())
def __on_set_initial_state(self, event): state = self.__get_current_state() self.__get_fsm().setinitialstate( state ) fsmevents.signal_fsm_change(self)
def __on_change_probability(self, event): self.__get_transition().settargetprobabilitybyindex( self.target_index, self.spin_probability.GetValue() ) if not self.skip_fsm_change_event: fsmevents.signal_fsm_change(self, self.target_index)
def __on_change_transition(self, event): fsmevents.signal_fsm_change(self) if event.get_value() != None: if event.get_value() == fsmevents.ID_NewTarget: self.edit_ctrl.on_new_target()
def __on_change_current_target(self, event): self.list_ctrl.refresh_current_target( event.get_value() ) fsmevents.signal_fsm_change(self)
def __on_change_condition(self, event): fsmevents.signal_fsm_change( self, event.get_value() )