Exemplo n.º 1
0
    def set_entity(self, event):
        entity = event.entity
        entity_components = self.context['entities'][entity]['components']
        # clear views
        for i in range(self.component_tree_view.topLevelItemCount()-1,-1,-1):
            item = self.component_tree_view.takeTopLevelItem(i)
        for i in range(self.vector_list_view.count()-1,-1,-1):
            item = self.vector_list_view.takeItem(i)
        for i in range(self.debug_list_view.count()-1,-1,-1):
            item = self.debug_list_view.takeItem(i)

        # populate the component tree view
        self._find_components()

        # populate the vector list view
        vectors = entity_components['body']
        for vector in vectors:
            widget_item = WidgetItemComponent(vector.text, vector)
            self.vector_list_view.addItem(widget_item)

        # populate debug list view
        debugs = entity_components['debug']
        for deb in debugs:
            widget_item = WidgetItemComponent(deb.text, deb)
            self.debug_list_view.addItem(widget_item)
Exemplo n.º 2
0
    def set_entity(self, event):
        entity = event.entity
        bindings = self.context['entities'][entity]['components']['binding']
        # do a "soft" clear of the list
        # if we actually call self.graphic_list_view.clear(),
        # the C++ Qt objects will be deleted
        for i in range(self.binding_list_view.count() - 1, -1, -1):
            self.binding_list_view.takeItem(i)

        for binding in bindings:
            widget_component = WidgetItemComponent(binding.text, binding)
            self.binding_list_view.addItem(widget_component)

        # now do it for execution components
        execs = self.context['entities'][entity]['components']['execution']
        for i in range(self.exec_list_view.count() - 1, -1, -1):
            self.exec_list_view.takeItem(i)

        for exec_comp in execs:
            widget_component = WidgetItemComponent(exec_comp.text, exec_comp)
            self.exec_list_view.addItem(widget_component)

        # finally do it for moves
        moves = self.context['entities'][entity]['components']['move']
        for i in range(self.move_list_view.count() - 1, -1, -1):
            self.move_list_view.takeItem(i)

        for move in moves:
            widget_component = WidgetItemComponent(move.text, move)
            self.move_list_view.addItem(widget_component)
Exemplo n.º 3
0
 def new_input(self, event):
     widget_component = WidgetItemComponent(event.input_component.text,
                                            event.input_component)
     self.inp_list_view.addItem(widget_component)
     mirror_component = WidgetItemComponent(event.input_component.text,
                                            event.input_component)
     self.mirror_list_view.addItem(mirror_component)
Exemplo n.º 4
0
 def update(self):
     entity = self.context['selected_entity']
     self.graphic_list_view.clear()
     self.asset_list_view.clear()
     for asset in self.context['assets']:
         widget_component = WidgetItemComponent(asset.text, asset)
         self.asset_list_view.addItem(widget_component)
     if entity and entity != '':
         for graphic in self.context['entities'][entity]['components']['graphic']:
             widget_component = WidgetItemComponent(graphic.text, graphic)
             self.graphic_list_view.addItem(widget_component)
Exemplo n.º 5
0
    def update(self):
        entity = self.context['selected_entity']
        # first update state list
        self.state_list_view.clear()
        if entity and entity != '':
            for state in self.context['entities'][entity]['components']['state']:
                widget_component = WidgetItemComponent(state.text, state)
                self.state_list_view.addItem(widget_component)

        # then update rules
        for rule in self.context['rules']:
            widget_component = WidgetItemComponent(rule.text, rule)
            self.rule_list_view.addItem(widget_component)
Exemplo n.º 6
0
    def add_frame(self):
        frame_name = str(self.frame_name_field.text())
        entity = self.context['selected_entity']
        ani = self.selected_animation
        crop = Rect(int(self.frame_x_field.text()),
                    int(self.frame_y_field.text()),
                    int(self.frame_width_field.text()),
                    int(self.frame_height_field.text()))
        repeat = int(self.frame_repeat_field.text())
        frame_component = FrameComponent(entity_id=entity,
                                         crop=crop,
                                         repeat=repeat)
        frame_component_wrapper = Component(frame_component, frame_name)
        widget_component = WidgetItemComponent(frame_name,
                                               frame_component_wrapper)
        self.frame_list_view.addItem(widget_component)

        # add new frame component to the selected animation's frame list
        ani.component.frames.append(frame_component_wrapper)

        # fire event
        new_event = Event('added_component',
                          entity=entity,
                          component_type='frame',
                          component=frame_component_wrapper)
        EVENT_MANAGER.fire_event(new_event)
Exemplo n.º 7
0
    def add_binding(self):
        entity = self.context['selected_entity']
        binding_name = str(self.binding_name_field.text())

        # begin by building the bindings dictionary
        bindings = dict()
        mirrors = dict()
        for i in range(self.selected_inp_list_view.count()):
            input_comp = self.selected_inp_list_view.item(i).component
            key = input_comp.component.name.text
            bindings[key] = input_comp
            mirrors[key] = input_comp.component.mirror
        binding_comp = InputComponent(entity_id=entity,
                                      bindings=bindings,
                                      mirror_bindings=mirrors)

        binding_comp_wrapper = Component(binding_comp, binding_name)
        widget_component = WidgetItemComponent(binding_name,
                                               binding_comp_wrapper)
        self.binding_list_view.addItem(widget_component)

        # add the component to the application context
        self.context['entities'][entity]['components']['binding'].append(
            binding_comp_wrapper)

        # fire event for adding new binding
        new_event = Event('added_binding',
                          binding_component=binding_comp_wrapper)
        EVENT_MANAGER.fire_event(new_event)
        new_event = Event('added_component',
                          entity=entity,
                          component_type='binding',
                          component=binding_comp_wrapper)
        EVENT_MANAGER.fire_event(new_event)
Exemplo n.º 8
0
    def add_graphic(self):
        # add the new graphic to the UI
        selected_asset = self.asset_list_view.currentItem()
        selected_component = selected_asset.component
        file_name = selected_component.component.file_name
        graphic_name = str(self.graphic_name_field.text())
        selected_anchor = self.anchor_list_view.currentItem().component
        graphic_component = GraphicsComponent(entity_id=self.context.get('selected_entity'),
                                              surface=selected_component.component.surface,
                                              file_name=file_name,
                                              dest=selected_anchor)
        graphic_component_wrapper = Component(graphic_component, graphic_name)
        widget_component = WidgetItemComponent(graphic_name, graphic_component_wrapper)
        self.graphic_list_view.addItem(widget_component)

        # render it to the label image holder
        self.show_graphic(file_name)

        # then add it to the application context
        entity_name = self.context.get('selected_entity')
        if entity_name:
            self.context['entities'][entity_name]['components']['graphic'].append(graphic_component_wrapper)

        # fire off an event
        new_event = Event('graphic_added',
                          graphic_component=graphic_component_wrapper)
        EVENT_MANAGER.fire_event(new_event)
        new_event = Event('added_component',
                          entity=entity_name,
                          component_type='graphic',
                          component=graphic_component_wrapper)
        EVENT_MANAGER.fire_event(new_event)
Exemplo n.º 9
0
    def add_animation(self):
        animation_name = str(self.animation_name_field.text())
        entity = self.context['selected_entity']
        animation_component = AnimationComponent(entity_id=entity,
                                                 graphic=self.selected_graphic)
        animation_component_wrapper = Component(animation_component,
                                                animation_name)
        widget_component = WidgetItemComponent(animation_name,
                                               animation_component_wrapper)
        self.animation_list_view.addItem(widget_component)

        # add new component to the application context
        context_animations = self.context['entities'][entity]['components'][
            'animation']
        context_animations.append(animation_component_wrapper)

        # fire event for adding an animation
        new_event = Event(
            'added_animation',
            animation_component=animation_component_wrapper,
            entity=animation_component_wrapper.component.entity_id)
        EVENT_MANAGER.fire_event(new_event)
        new_event = Event('added_component',
                          entity=entity,
                          component_type='animation',
                          component=animation_component_wrapper)
        EVENT_MANAGER.fire_event(new_event)
Exemplo n.º 10
0
    def add_move(self):
        move_name = str(self.move_name_field.text())
        entity = self.context['selected_entity']
        selected_animation = self.ani_list_view.currentItem().component
        # build a list of the chosen inputs
        inputs = list()
        for i in range(self.selected_inp_list_view.count()):
            item = self.selected_inp_list_view.item(i)
            inp_component = item.component
            inputs.append(inp_component)

        # construct the move component
        move = MoveComponent(entity_id=entity,
                             name=move_name,
                             animation=selected_animation,
                             inputs=inputs)
        move_component_wrapper = Component(move, move_name)
        widget_component = WidgetItemComponent(move_name, move_component_wrapper)
        self.move_list_view.addItem(widget_component)

        # add the move component to the application context
        self.context['entities'][entity]['components']['move'].append(move_component_wrapper)

        # fire event for adding new move
        new_event = Event('added_move',
                          move_component=move_component_wrapper)
        EVENT_MANAGER.fire_event(new_event)
        new_event = Event('added_component',
                          entity=entity,
                          component_type='move',
                          component=move_component_wrapper)
        EVENT_MANAGER.fire_event(new_event)
Exemplo n.º 11
0
 def add_component(self, event):
     entity = event.entity
     component_type = event.component_type
     component = event.component
     if component_type == 'body':
         widget_item = WidgetItemComponent(component.text, component)
         self.vector_list_view.addItem(widget_item)
Exemplo n.º 12
0
 def add_state(self):
     entity = self.context['selected_entity']
     state_name = str(self.state_name_field.text())
     # get activation event
     act_event_name = str(self.activation_list_view.currentItem().text())
     # get deactivation event
     deact_event_name = str(self.deactivation_list_view.currentItem().text())
     # get activation component
     act_component = self.activation_component_tree_view.currentItem().component
     # build list of rules added to this state
     rules = list()
     rule_values = dict()
     for i in range(self.selected_rule_list_view.count()):
         item = self.selected_rule_list_view.item(i)
         rule_component = item.component
         rules.append(rule_component.rule)
         rule_values[str(rule_component.rule.text)] = rule_component.rule_value
     # create state component
     state_component = StateComponent(entity_id=entity,
                                      rules=rules,
                                      activation_event_type=act_event_name,
                                      deactivation_event_type=deact_event_name,
                                      activation_component=act_component,
                                      rule_values=rule_values)
     state_component_wrapper = Component(state_component, state_name)
     widget_component = WidgetItemComponent(state_name, state_component_wrapper)
     self.state_list_view.addItem(widget_component)
     # add state component to application context
     self.context['entities'][entity]['components']['state'].append(state_component_wrapper)
     # fire event for adding component
     new_event = Event('added_component',
                       entity=entity,
                       component_type='state',
                       component=state_component_wrapper)
     EVENT_MANAGER.fire_event(new_event)
Exemplo n.º 13
0
    def add_rule(self):
        selected_item = self.rule_list_view.currentItem()
        selected_component = selected_item.component
        rule_name = selected_component.text

        # determine the rule value for this rule
        rule_value = str(self.rule_value_field.text())
        rule_text = '{name} - {value}'.format(name=rule_name, value=rule_value)
        # if no value is entered in the rule value field,
        # we then look for a chosen component property
        if rule_value is None or rule_value == '':
            component_item = self.rule_value_component_tree_view.currentItem()
            component_text = str(component_item.text(0))
            component = component_item.component
            rule_value = component
            if component_item.parent() != None:
                component_text = '{a}.{b}'.format(a=str(component_item.parent().text(0)),
                                                  b=component_text)
            rule_text = '{name} - {value}'.format(name=rule_name,
                                                  value=component_text)

        rule_wrapper = RuleRuleValueWrapper(selected_component, rule_value)
        #widget_component = WidgetItemComponent(rule_text, rule_value)
        widget_component = WidgetItemComponent(rule_text, rule_wrapper)
        self.selected_rule_list_view.addItem(widget_component)
Exemplo n.º 14
0
    def add_exec(self):
        entity = self.context['selected_entity']
        exec_name = str(self.exec_name_field.text())
        binding = self.binding_list_view.currentItem().component
        # build list of selected moves
        moves = list()
        for i in range(self.selected_move_list_view.count()):
            item = self.selected_move_list_view.item(i)
            move = item.component
            moves.append(move)
        exec_component = ExecutionComponent(entity_id=entity,
                                            executables=moves,
                                            inputs=binding)
        exec_component_wrapper = Component(exec_component, exec_name)
        widget_component = WidgetItemComponent(exec_name,
                                               exec_component_wrapper)
        self.exec_list_view.addItem(widget_component)

        # add execution component to the application context
        self.context['entities'][entity]['components']['execution'].append(
            exec_component_wrapper)

        # fire event for adding new execution
        new_event = Event('added_execution',
                          execution_component=exec_component_wrapper)
        EVENT_MANAGER.fire_event(new_event)
        new_event = Event('added_component',
                          entity=entity,
                          component_type='execution',
                          component=exec_component_wrapper)
        EVENT_MANAGER.fire_event(new_event)
Exemplo n.º 15
0
    def add_box(self):
        box_name = str(self.box_name_field.text())
        entity = self.context['selected_entity']
        frame = self.selected_frame.component
        rect = Rect(int(self.box_x_field.text()), int(self.box_y_field.text()),
                    int(self.box_width_field.text()),
                    int(self.box_height_field.text()))
        hitactive = self.check_context['hitactive'] > 0
        hurtactive = self.check_context['hurtactive'] > 0
        blockactive = self.check_context['blockactive'] > 0
        solid = self.check_context['solid'] > 0
        box_component = BoxComponent(entity_id=entity,
                                     rect=rect,
                                     anchor=self.anchor,
                                     hitactive=hitactive,
                                     hurtactive=hurtactive,
                                     blockactive=blockactive,
                                     solid=solid)
        box_component_wrapper = Component(box_component, box_name)
        widget_component = WidgetItemComponent(box_name, box_component_wrapper)
        self.box_list_view.addItem(widget_component)

        # add box to the selected frame's box list
        frame.hitboxes.append(box_component_wrapper)

        # add the box component to the application context
        self.context['entities'][entity]['components']['hitbox'].append(
            box_component_wrapper)

        # fire event
        new_event = Event('added_component',
                          entity=entity,
                          component_type='hitbox',
                          component=box_component_wrapper)
        EVENT_MANAGER.fire_event(new_event)
Exemplo n.º 16
0
    def update(self):
        # first update move list
        entity = self.context['selected_entity']
        self.move_list_view.clear()
        if entity and entity != '':
            for move in self.context['entities'][entity]['components']['move']:
                widget_component = WidgetItemComponent(move.text, move)
                self.move_list_view.addItem(widget_component)

        # then update input list
        self.inp_list_view.clear()
        for inp in self.context['inputs']:
            widget_component = WidgetItemComponent(inp.text, inp)
            self.inp_list_view.addItem(widget_component)

        # finally update animation list
        self.ani_list_view.clear()
Exemplo n.º 17
0
 def update(self):
     entity = self.context['selected_entity']
     self.exec_list_view.clear()
     if entity and entity != '':
         for execution in self.context[entity]['components']['execution']:
             widget_component = WidgetItemComponent(execution.text,
                                                    execution)
             self.exec_list_view.addItem(widget_component)
Exemplo n.º 18
0
 def update(self):
     entity = self.context['selected_entity']
     self.animation_list_view.clear()
     if entity and entity != '':
         for animation in self.context['entities'][entity]['components'][
                 'animation']:
             widget_component = WidgetItemComponent(animation.text,
                                                    animation)
             self.animation_list_view.addItem(widget_component)
Exemplo n.º 19
0
 def add_entity(self):
     entity_name = str(self.entity_name_field.text())
     new_entity = Entity(entity_name)
     new_entity_wrapper = Component(new_entity, entity_name)
     widget_component = WidgetItemComponent(entity_name, new_entity_wrapper)
     self.entity_list_view.addItem(widget_component)
     self.context['entities'][entity_name] = dict()
     self.context['entities'][entity_name]['entity'] = new_entity
     self.context['entities'][entity_name]['components'] = defaultdict(list)
Exemplo n.º 20
0
    def update(self):
        # first update input list and mirror input list
        self.inp_list_view.clear()
        self.mirror_list_view.clear()
        for inp in self.context['inputs']:
            widget_component = WidgetItemComponent(inp.text, inp)
            self.inp_list_view.addItem(widget_component)
            mirror_component = WidgetItemComponent(inp.text, inp)
            self.mirror_list_view.addItem(mirror_component)

        # then update binding list
        entity = self.context['selected_entity']
        self.binding_list_view.clear()
        if entity and entity != '':
            for bind in self.context['entities'][entity]['components'][
                    'binding']:
                widget_component = WidgetItemComponent(binding.text, binding)
                self.binding_list_view.addItem(widget_component)
Exemplo n.º 21
0
    def select_state(self):
        '''
            update the state editor GUI to show all properties
            of the selected state
        '''
        entity = self.context['selected_entity']
        selected_item = self.state_list_view.currentItem()
        selected_component = selected_item.component

        # start by setting the state name
        self.state_name_field.setText(selected_component.text)

        # then set the selected activation event
        for i in range(self.activation_list_view.count()):
            item = self.activation_list_view.item(i)
            if item.text() == selected_component.component.activation_event_type:
                self.activation_list_view.setCurrentRow(i)
                break

        # then set the selected deactivation event
        for i in range(self.deactivation_list_view.count()):
            item = self.deactivation_list_view.item(i)
            if item.text() == selected_component.component.deactivation_event_type:
                self.deactivation_list_view.setCurrentRow(i)
                break

        # then select activation component
        # begin by deselecting any selected node and collapsing all branches
        activation_component = selected_component.component.activation_component
        for i in range(self.activation_component_tree_view.topLevelItemCount()):
            tl_item = self.activation_component_tree_view.topLevelItem(i)
            for j in range(tl_item.childCount()):
                child_item = tl_item.child(j)
                child_item.setSelected(False)
            tl_item.setExpanded(False)
        # then find and select the proper node
        for i in range(self.activation_component_tree_view.topLevelItemCount()):
            tl_item = self.activation_component_tree_view.topLevelItem(i)
            for j in range(tl_item.childCount()):
                child_item = tl_item.child(j)
                if child_item.component == activation_component:
                    tl_item.setExpanded(True)
                    child_item.setSelected(True)
                    break

        # then show the proper rules in the selected rule box
        # also, deselect any selected rule or rule component values
        for i in range(self.selected_rule_list_view.count()-1,-1,-1):
            item = self.selected_rule_list_view.takeItem(i)
        context_rules = self.context['entities'][entity]['components']['rules']
        rules = [RuleRuleValueWrapper(x, y) for x in selected_component.component.rules for k,y in selected_component.component.rule_values.iteritems() if k == x.component.name]
        for rule in rules:
            comp = Component(rule, rule.rule.text)
            widget_item = WidgetItemComponent(comp.text, comp)
            self.selected_rule_list_view.addItem(widget_item)
        self.rule_list_view.setCurrentRow(-1)
Exemplo n.º 22
0
    def set_graphics(self, event):
        entity = event.entity
        available_graphics = self.context['entities'][entity]['components']['graphic']
        # do a "soft" clear of the list
        # if we actually call self.graphic_list_view.clear(),
        # the C++ Qt objects will be deleted
        for i in range(self.graphic_list_view.count()-1,-1,-1):
            self.graphic_list_view.takeItem(i)

        for graphic in available_graphics:
            widget_component = WidgetItemComponent(graphic.text, graphic)
            self.graphic_list_view.addItem(widget_component)

        # clear and populate anchor list
        self.anchor_list_view.clear()        
        available_anchors = self.context['entities'][entity]['components']['body']
        for anchor in available_anchors:
            widget_component = WidgetItemComponent(anchor.text, anchor)
            self.anchor_list_view.addItem(widget_component)
Exemplo n.º 23
0
    def set_entity(self, event):
        entity = event.entity

        # first do a soft clear of the tree view
        for i in range(self.activation_component_tree_view.topLevelItemCount()-1,-1,-1):
            item = self.activation_component_tree_view.takeTopLevelItem(i)
            for j in range(item.childCount()-1,-1,-1):
                child_item = item.takeChild(j)

        # repopulate the tree with the current entity's components
        tl_items = self.context['entities'][entity]['components'].keys()
        # component types represent the top level tree items
        for item in tl_items:
            components = self.context['entities'][entity]['components'][item]
            tl_tree_item = TreeWidgetItemComponent(item, components)
            self.activation_component_tree_view.addTopLevelItem(tl_tree_item)
            # the components should all be listed under their respective 
            # component type
            for component in components:
                tree_item = TreeWidgetItemComponent(component.text, component)
                tl_tree_item.addChild(tree_item)

        # now do this same stuff for the rule value component tree
        rule_value_tree = self.rule_value_component_tree_view
        # clear it out first
        for i in range(rule_value_tree.topLevelItemCount()-1,-1,-1):
            item = rule_value_tree.takeTopLevelItem(i)
            for j in range(item.childCount()-1,-1,-1):
                child_item = item.takeChild(j)
                for k in range(child_item.childCount()-1,-1,-1):
                    grand_child_item = child_item.takeChild(k)

        # then repopulate the tree with components and component properties
        tl_items = self.context['entities'][entity]['components'].keys()
        for item in tl_items:
            components = self.context['entities'][entity]['components'][item]
            tl_tree_item = TreeWidgetItemComponent(item, components)
            rule_value_tree.addTopLevelItem(tl_tree_item)
            for component in components:
                component_item = TreeWidgetItemComponent(component.text, component)
                tl_tree_item.addChild(component_item)
                # then add a child item for each non-private attribute of 
                # this component
                for name in (x for x in dir(component.component) if not x.startswith('_')):
                    # still using outer component
                    val = LambdaDef(component, name)
                    component_attr_item = TreeWidgetItemComponent(name, val)
                    component_item.addChild(component_attr_item)

        # finally, repopulate the state component list
        self.state_list_view.clear()
        for state in self.context['entities'][entity]['components']['state']:
            widget_component = WidgetItemComponent(state.text, state)
            self.state_list_view.addItem(widget_component)
Exemplo n.º 24
0
    def add_debug(self):
        entity = self.context['selected_entity']
        name = self.debug_name_field.text()
        component_item = self.component_tree_view.currentItem()
        lambda_component = component_item.component
        color = self.color_list_view.currentItem().component
        location_vec = self.vector_list_view.currentItem().component

        inner_component = lambda_component.component.component
        #component_type = component_wrapper.__class__.__name__
        attr = getattr(inner_component, lambda_component.attr).component
        component_type = attr.__class__.__name__
        # create the debug component
        # extract the real component from a LambdaDef
        if component_type == 'BoxComponent':
            rect = getattr(inner_component, lambda_component.attr)
            debug_component = DebugComponent(entity_id=entity,
                                             rect=rect,
                                             style={'color': color})
        else:
            lambda_name = lambda_component.attr
            text_lambda = TextLambdaDef(lambda_component, lambda_name, '{a}')
            text = str(getattr(lambda_component.component.component, lambda_name).component)
            text_comp = TextComponent(entity_id=entity,
                                      text=text,
                                      loc=location_vec,
                                      style={'color':color})
            text_wrapper = Component(text_comp, text)
            # add this text component to the context
            self.context['entities'][entity]['components']['text'].append(text_wrapper)
            new_event = Event('added_component',
                              entity=entity,
                              component_type='text',
                              component=text_wrapper)
            EVENT_MANAGER.fire_event(new_event)
            # finally create debug component
            debug_component = DebugComponent(entity_id=entity,
                                             text=text_wrapper,
                                             get_value=text_lambda,
                                             style={'color': color})

        debug_wrapper = Component(debug_component, name)
        widget_item = WidgetItemComponent(name, debug_wrapper)
        self.debug_list_view.addItem(widget_item)

        # add to context
        self.context['entities'][entity]['components']['debug'].append(debug_wrapper)
        # fire event
        new_event = Event('added_component',
                          entity=entity,
                          component_type='debug',
                          component=debug_wrapper)
        EVENT_MANAGER.fire_event(new_event)
Exemplo n.º 25
0
    def set_animations(self, event):
        entity = event.entity
        available_animations = self.context['entities'][entity]['components']['animation']
        # do a "soft" clear of the list
        # if we actually call self.graphic_list_view.clear(),
        # the C++ Qt objects will be deleted
        for i in range(self.ani_list_view.count()-1,-1,-1):
            self.ani_list_view.takeItem(i)

        for animation in available_animations:
            widget_component = WidgetItemComponent(animation.text, animation)
            self.ani_list_view.addItem(widget_component)

        # now do the moves list
        available_moves = self.context['entities'][entity]['components']['move']
        for i in range(self.move_list_view.count()-1,-1,-1):
            self.move_list_view.takeItem(i)

        for move in available_moves:
            widget_component = WidgetItemComponent(move.text, move)
            self.move_list_view.addItem(widget_component)
Exemplo n.º 26
0
    def add_inputs(self):
        # possible multiple selection
        selected_items = self.inp_list_view.selectedItems()
        widget_component = None
        if len(selected_items) > 0:
            # if multiple items selected, join each component's
            # text together, and use the list of components as the
            # component
            text = ' + '.join([str(x.text()) for x in selected_items])
            agg_comp = Component([x.component for x in selected_items],
                                 text)
            widget_component = WidgetItemComponent(text, agg_comp)
        elif len(selected_items) == 1:
            # if just one item selected, follow the normal process
            comp = Component(selected_items[0].component,
                             selected_items[0].text)
            widget_component = WidgetItemComponent(comp.text, comp)
        else:
            return

        # then add the widget item to the selected inputs list
        self.selected_inp_list_view.addItem(widget_component)
Exemplo n.º 27
0
    def add_input(self):
        inp_name = str(self.input_name_field.text())
        inp = Input(name=inp_name)
        inp_wrapper = Component(inp, inp_name)
        widget_component = WidgetItemComponent(inp_name, inp_wrapper)
        self.input_list_view.addItem(widget_component)

        # add input to the application context
        self.context['inputs'].append(inp_wrapper)

        # fire event for adding new input
        new_event = Event('added_input', input_component=inp_wrapper)
        EVENT_MANAGER.fire_event(new_event)
Exemplo n.º 28
0
    def set_bindings(self, event):
        entity = event.entity
        available_bindings = self.context['entities'][entity]['components'][
            'binding']
        # do a "soft" clear of the list
        # if we actually call self.graphic_list_view.clear(),
        # the C++ Qt objects will be deleted
        for i in range(self.binding_list_view.count() - 1, -1, -1):
            self.binding_list_view.takeItem(i)

        for binding in available_bindings:
            widget_component = WidgetItemComponent(binding.text, binding)
            self.binding_list_view.addItem(widget_component)
Exemplo n.º 29
0
    def set_entity(self, event):
        entity = event.entity
        self.entity = entity

        # soft clear physics object list
        for i in range(self.physics_list_view.count() - 1, -1, -1):
            self.physics_list_view.takeItem(i)

        available_physics = self.context['entities'][entity]['components'][
            'physics']
        for phys in available_physics:
            widget_component = WidgetItemComponent(phys.text, phys)
            self.physics_list_view.addItem(widget_component)
Exemplo n.º 30
0
 def add_input(self):
     selected_item = self.inp_list_view.currentItem()
     selected_component = selected_item.component
     selected_key = self.key_list_view.currentItem().component
     selected_mirror = self.mirror_list_view.currentItem()
     selected_mirror = None if selected_mirror is None else selected_mirror.component
     bound_input = InputToKeyBinding(selected_component, selected_key,
                                     selected_mirror)
     bound_input_wrapper = Component(
         bound_input, '{a} - {b}'.format(a=selected_component.text,
                                         b=selected_key.text))
     widget_component = WidgetItemComponent(bound_input_wrapper.text,
                                            bound_input_wrapper)
     self.selected_inp_list_view.addItem(widget_component)