def __on_mousemove(self, event): if self.current_object and pf.map_pos_under_cursor(): self.current_object.pos = pf.map_pos_under_cursor() if self.right_mousebutton_state == pf.SDL_PRESSED: sel = pf.get_unit_selection() if len(sel) == 1: sel[0].pos = pf.map_pos_under_cursor()
def __on_mousewheel(self, event): CCW_ROT_5DEG = [0.0, 0.0436194, 0.0, 0.9990482] CW_ROT_5DEG = [0.0, -0.0436194, 0.0, 0.9990482] if self.view.mode == self.view.OBJECTS_MODE_SELECT: sel_obj_list = pf.get_unit_selection() if len(sel_obj_list) != 1: return obj = sel_obj_list[0] else: obj = self.current_object if event[1] > 0: obj.rotation = pf.multiply_quaternions(obj.rotation, CCW_ROT_5DEG) else: obj.rotation = pf.multiply_quaternions(obj.rotation, CW_ROT_5DEG)
def __on_click(self, event): if not mouse_events.mouse_over_map: return if pf.map_pos_under_cursor() is None: return if event[0] == pf.SDL_BUTTON_LEFT: if self.current_object: self.current_object.faction_id = pf.get_factions_list()[self.view.selected_faction_idx]["id"] globals.active_objects_list.append(self.current_object) self.current_object = self.__object_at_index(self.view.selected_object_idx) self.current_object.pos = pf.map_pos_under_cursor() elif event[0] == pf.SDL_BUTTON_RIGHT: self.right_mousebutton_state = event[1] sel = pf.get_unit_selection() if len(sel) == 1: sel[0].pos = pf.map_pos_under_cursor()
def __on_selection_changed(self, event): self.__view.clear_actions() if self.__active_controllable and self.__active_controllable(): self.__uninstall_hotkeys(self.__active_controllable()) self.__active_controllable = None sel = pf.get_unit_selection() controllable_sel = [ent for ent in sel if isinstance(ent, cont.Controllable)] if len(controllable_sel) > 0: first = controllable_sel[0] fac_list = pf.get_factions_list() if fac_list[first.faction_id]["controllable"]: self.__active_controllable = weakref.ref(first) self.__install_hotkeys(first) self.__view.actions = [first.action(i) for i in range(0, ACTION_NUM_ROWS * ACTION_NUM_COLS)]
def __stop_action(cls): for ent in pf.get_unit_selection(): ent.stop()
def update(self): # Mode self.layout_row_dynamic(20, 1) self.label_colored_wrap("Mode:", (255, 255, 255)) old_mode = self.mode self.layout_row_dynamic(20, 2) if self.option_label("Place", self.mode == self.OBJECTS_MODE_PLACE): self.mode = self.OBJECTS_MODE_PLACE if self.option_label("Select", self.mode == self.OBJECTS_MODE_SELECT): self.mode = self.OBJECTS_MODE_SELECT self.layout_row_dynamic(10, 1) if self.mode != old_mode: pf.global_event(EVENT_OBJECTS_TAB_MODE_CHANGED, self.mode) if self.mode == self.OBJECTS_MODE_PLACE: # Faction self.layout_row_dynamic(20, 1) self.label_colored_wrap("Faction:", (255, 255, 255)) self.layout_row_dynamic(25, 1) fac_names = [fac["name"] for fac in pf.get_factions_list()] self.selected_faction_idx = self.combo_box( fac_names, self.selected_faction_idx, 25, (UI_LEFT_PANE_WIDTH - 30, 200)) self.layout_row_dynamic(10, 1) # Objects self.layout_row_dynamic(20, 1) self.label_colored_wrap("Objects:", (255, 255, 255)) def objects_group(): self.layout_row_static(25, UI_LEFT_PANE_WIDTH - 60, 1) for i in range(0, len(self.objects_list)): old = self.selected_object_idx on = self.selectable_label(self.objects_list[i], pf.NK_TEXT_ALIGN_LEFT, i == self.selected_object_idx) if on: self.selected_object_idx = i if self.selected_object_idx != old: pf.global_event(EVENT_OBJECT_SELECTION_CHANGED, i) self.layout_row_static(400, UI_LEFT_PANE_WIDTH - 30, 1) self.group("Objects", pf.NK_WINDOW_BORDER, objects_group) elif self.mode == self.OBJECTS_MODE_SELECT: # Selection sel_obj_list = pf.get_unit_selection() if len(sel_obj_list) == 0: return self.layout_row_dynamic(20, 1) self.label_colored_wrap("Selection:", (255, 255, 255)) if len(sel_obj_list) > 1: def selection_group(): self.layout_row_static(25, UI_LEFT_PANE_WIDTH - 60, 1) for i in range(0, len(sel_obj_list)): name = "{0} {1}".format( sel_obj_list[i].name, format_str_for_numlist(sel_obj_list[i].pos)) on = self.selectable_label(name, pf.NK_TEXT_ALIGN_LEFT, False) if on: pf.global_event(EVENT_OBJECT_SELECTED_UNIT_PICKED, sel_obj_list[i]) self.layout_row_static(400, UI_LEFT_PANE_WIDTH - 30, 1) self.group("Selection", pf.NK_WINDOW_BORDER, selection_group) else: assert (len(sel_obj_list) == 1) self.layout_row_dynamic(10, 1) self.layout_row_dynamic(20, 1) self.label_colored_wrap(sel_obj_list[0].name, (200, 200, 0)) pos_str = "Position: {0}".format( format_str_for_numlist(sel_obj_list[0].pos)) self.layout_row_dynamic(20, 1) self.label_colored_wrap(pos_str, (255, 255, 255)) rot_str = "Rotation: {0}".format( format_str_for_numlist(sel_obj_list[0].rotation)) self.layout_row_dynamic(20, 1) self.label_colored_wrap(rot_str, (255, 255, 255)) scale_str = "Scale: {0}".format( format_str_for_numlist(sel_obj_list[0].scale)) self.layout_row_dynamic(20, 1) self.label_colored_wrap(scale_str, (255, 255, 255)) select_str = "Selectable: {0}".format( "True" if sel_obj_list[0].selectable else "False") self.layout_row_dynamic(20, 1) self.label_colored_wrap(select_str, (255, 255, 255)) fac = next(f for f in pf.get_factions_list() if f["id"] == sel_obj_list[0].faction_id) select_str = "Faction: {0}".format(fac["name"]) self.layout_row_dynamic(20, 1) self.label_colored_wrap(select_str, (255, 255, 255)) def on_delete(): pf.global_event(EVENT_OBJECT_DELETE_SELECTION, None) self.layout_row_dynamic(30, 1) self.button_label("Delete", on_delete)
def __on_delete_selection(self, event): sel_obj_list = pf.get_unit_selection() for obj in sel_obj_list: globals.active_objects_list.remove(obj)
def __hold_position_action(cls): for ent in pf.get_unit_selection(): if isinstance(ent, pf.CombatableEntity): ent.hold_position()
def __toggle_idle_action(cls): for ent in pf.get_unit_selection(): if isinstance(ent, Sinbad): ent.anim_toggle()
def __hold_position_action(cls): for ent in pf.get_unit_selection(): ent.hold_position()