def __init__(self, character, config, screen, action_factory, parent): """ Default constructor """ super(InventoryScreen, self).__init__() self.character = character self.config = config self.screen = screen.subwin(20, 75, 2, 2) self.inventory_controller = InventoryController( character, action_factory) self.parent = parent self.keys = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D' ]
def __init__(self, surface_manager, character, action_factory, config, parent): """ Default constructor """ super(InventoryWidget, self).__init__(parent) self.surface_manager = surface_manager self.character = character self.action_factory = action_factory self.config = config self.items_carried = None self.items_in_ground = None self.item_description = None self.character_inventory = None self.inventory_controller = InventoryController( character, action_factory) self.__set_layout(surface_manager, character, config)
def __init__(self, character, config, screen, action_factory, parent): """ Default constructor """ super(InventoryScreen, self).__init__() self.character = character self.config = config self.screen = screen.subwin(20, 75, 2, 2) self.inventory_controller = InventoryController(character, action_factory) self.parent = parent self.keys = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D']
def __init__(self, surface_manager, character, action_factory, config, parent): """ Default constructor """ super(InventoryWidget, self).__init__(parent) self.surface_manager = surface_manager self.character = character self.action_factory = action_factory self.config = config self.items_carried = None self.items_in_ground = None self.item_description = None self.character_inventory = None self.inventory_controller = InventoryController(character, action_factory) self.__set_layout(surface_manager, character, config)
class InventoryScreen(): """ Class for displaying inventero screen .. versionadded:: 0.9 """ @log_debug def __init__(self, character, config, screen, action_factory, parent): """ Default constructor """ super(InventoryScreen, self).__init__() self.character = character self.config = config self.screen = screen.subwin(20, 75, 2, 2) self.inventory_controller = InventoryController(character, action_factory) self.parent = parent self.keys = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D'] @log_debug def _draw_screen(self): """ Update the screen """ self.screen.clear() self.screen.border() for index, item in enumerate(self.character.inventory): if index < 15: column = 1 row = 1 + index else: column = 37 row = 1 + index - 15 self.screen.addstr(row, column, '{0} {1}'.format(self.keys[index], item.get_name(self.character, True))) self.screen.refresh() @log_info def show(self): """ Show inventory screen """ running = 1 self._draw_screen() while running == 1: item = None key = chr(self.screen.getch()) if key in ['u', 'r', 'd', 'i']: self.screen.addstr(0, 2, 'select item') item_key = chr(self.screen.getch()) if item_key in self.keys: index = self.keys.index(item_key) if index < len(self.character.inventory): item = self.character.inventory[index] if item is not None: if key == 'u': self.inventory_controller.use_item(item) elif key == 'r': self.inventory_controller.unequip_item(item) elif key == 'd': self.inventory_controller.drop_item(item) elif key == 'i': self.screen.border() self.screen.addstr(0, 2, 'press key to continue') self.screen.refresh() self._show_detailed_info(item, self.character) elif key == ' ': running = 0 self._draw_screen() self.parent.refresh() @log_debug def _show_detailed_info(self, item, character): """ Show detailed information screen for item :param item: item to show :type item: Item """ new_screen = self.screen.derwin(18, 73, 1, 1) new_screen.clear() new_screen.addstr(0, 0, self.inventory_controller.item_description(item)) new_screen.refresh() chr(new_screen.getch())
class InventoryWidget(QWidget): """ Widget for showing inventory .. versionadded:: 0.5 """ def __init__(self, surface_manager, character, action_factory, config, parent): """ Default constructor """ super(InventoryWidget, self).__init__(parent) self.surface_manager = surface_manager self.character = character self.action_factory = action_factory self.config = config self.items_carried = None self.items_in_ground = None self.item_description = None self.character_inventory = None self.inventory_controller = InventoryController( character, action_factory) self.__set_layout(surface_manager, character, config) ItemPickedUp = pyqtSignal(Item, name='ItemPickedUp') ItemDropped = pyqtSignal(Item, name='ItemDropped') def __set_layout(self, surface_manager, character, config): """ Set layout of this widget """ main_layout = QHBoxLayout() left_side = QVBoxLayout() self.character_inventory = CharacterInventoryWidget( surface_manager, character, config, self) self.character_inventory.ItemActionA.connect(self.unwield_weapon) self.character_inventory.ItemActionB.connect(self.unwield_weapon) self.item_description = ItemDescriptionWidget(self) left_side.addWidget(self.character_inventory) left_side.addWidget(self.item_description) right_side = QVBoxLayout() self.items_carried = ItemBox(surface_manager=surface_manager, config=config, parent=self, width=6, height=6) self.items_carried.ItemFocused.connect(self.on_item_focused) self.items_carried.ItemActionA.connect(self.use_item) self.items_carried.ItemActionB.connect(self.drop_item) self.items_in_ground = ItemBox(surface_manager=surface_manager, config=config, parent=self, width=6, height=2) self.items_in_ground.ItemFocused.connect(self.on_item_focused) self.items_in_ground.ItemActionA.connect(self.pick_up_item) right_side.addWidget(self.items_carried) right_side.addWidget(self.items_in_ground) main_layout.addLayout(left_side) main_layout.addLayout(right_side) self.setLayout(main_layout) self.update_inventory() self.items_carried.items[0].setFocus(Qt.OtherFocusReason) def update_inventory(self): """ Update items being displayed .. versionadded:: 0.6 """ self.items_carried.show_items(self.character.inventory) items = list(get_items(self.character.level, self.character.location)) self.items_in_ground.show_items(items) self.character_inventory.show_character() def on_item_focused(self, item): """ Handle item focused .. versionadded:: 0.6 """ description = self.inventory_controller.item_description(item) self.item_description.set_text(description) def focusNextPrevChild(self, next): #pylint: disable-msg=C0103 """ Handle moving focus around the widget .. versionadded:: 0.7 """ if len([ x for x in self.items_carried.items if x.display.objectName() == 'active_inventorybox' ]) > 0: focused = self.items_carried elif len([ x for x in self.items_in_ground.items if x.display.objectName() == 'active_inventorybox' ]) > 0: focused = self.items_in_ground.items else: focused = self.character_inventory if focused == self.character_inventory: if next == True: self.items_carried.focus_on_first_row(0) else: self.items_in_ground.focus_on_bottom_row(0) elif focused == self.items_carried: if next == True: index = self.items_carried.get_current_column() self.items_in_ground.focus_on_first_row(index) else: self.character_inventory.focus_on_last_item() else: if next == True: self.character_inventory.focus_on_first_item() else: index = self.items_in_ground.get_current_column() self.items_carried.focus_on_bottom_row(index) return True def pick_up_item(self, item): """ Pick up item .. versionadded:: 0.6 """ self.inventory_controller.pick_up_item(item) self.update_inventory() self.ItemPickedUp.emit(item) def drop_item(self, item): """ Drop item .. versionadded:: 0.6 """ self.inventory_controller.drop_item(item) self.update_inventory() self.ItemDropped.emit(item) def use_item(self, item): """ Use item in different ways, depending on the item .. versionadded:: 0.6 """ self.inventory_controller.use_item(item) self.update_inventory() def unwield_weapon(self, item): """ Unwield current weapon .. versionadded:: 0.6 """ self.inventory_controller.unequip_item(item) self.update_inventory()
class InventoryScreen(): """ Class for displaying inventero screen .. versionadded:: 0.9 """ @log_debug def __init__(self, character, config, screen, action_factory, parent): """ Default constructor """ super(InventoryScreen, self).__init__() self.character = character self.config = config self.screen = screen.subwin(20, 75, 2, 2) self.inventory_controller = InventoryController( character, action_factory) self.parent = parent self.keys = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D' ] @log_debug def _draw_screen(self): """ Update the screen """ self.screen.clear() self.screen.border() for index, item in enumerate(self.character.inventory): if index < 15: column = 1 row = 1 + index else: column = 37 row = 1 + index - 15 self.screen.addstr( row, column, '{0} {1}'.format(self.keys[index], item.get_name(self.character, True))) self.screen.refresh() @log_info def show(self): """ Show inventory screen """ running = 1 self._draw_screen() while running == 1: item = None key = chr(self.screen.getch()) if key in ['u', 'r', 'd', 'i']: self.screen.addstr(0, 2, 'select item') item_key = chr(self.screen.getch()) if item_key in self.keys: index = self.keys.index(item_key) if index < len(self.character.inventory): item = self.character.inventory[index] if item is not None: if key == 'u': self.inventory_controller.use_item(item) elif key == 'r': self.inventory_controller.unequip_item(item) elif key == 'd': self.inventory_controller.drop_item(item) elif key == 'i': self.screen.border() self.screen.addstr(0, 2, 'press key to continue') self.screen.refresh() self._show_detailed_info(item, self.character) elif key == ' ': running = 0 self._draw_screen() self.parent.refresh() @log_debug def _show_detailed_info(self, item, character): """ Show detailed information screen for item :param item: item to show :type item: Item """ new_screen = self.screen.derwin(18, 73, 1, 1) new_screen.clear() new_screen.addstr(0, 0, self.inventory_controller.item_description(item)) new_screen.refresh() chr(new_screen.getch())
class InventoryWidget(QWidget): """ Widget for showing inventory .. versionadded:: 0.5 """ def __init__(self, surface_manager, character, action_factory, config, parent): """ Default constructor """ super(InventoryWidget, self).__init__(parent) self.surface_manager = surface_manager self.character = character self.action_factory = action_factory self.config = config self.items_carried = None self.items_in_ground = None self.item_description = None self.character_inventory = None self.inventory_controller = InventoryController(character, action_factory) self.__set_layout(surface_manager, character, config) ItemPickedUp = pyqtSignal(Item, name='ItemPickedUp') ItemDropped = pyqtSignal(Item, name='ItemDropped') def __set_layout(self, surface_manager, character, config): """ Set layout of this widget """ main_layout = QHBoxLayout() left_side = QVBoxLayout() self.character_inventory = CharacterInventoryWidget(surface_manager, character, config, self) self.character_inventory.ItemActionA.connect(self.unwield_weapon) self.character_inventory.ItemActionB.connect(self.unwield_weapon) self.item_description = ItemDescriptionWidget(self) left_side.addWidget(self.character_inventory) left_side.addWidget(self.item_description) right_side = QVBoxLayout() self.items_carried = ItemBox(surface_manager = surface_manager, config = config, parent = self, width = 6, height = 6) self.items_carried.ItemFocused.connect(self.on_item_focused) self.items_carried.ItemActionA.connect(self.use_item) self.items_carried.ItemActionB.connect(self.drop_item) self.items_in_ground = ItemBox(surface_manager = surface_manager, config = config, parent = self, width = 6, height = 2) self.items_in_ground.ItemFocused.connect(self.on_item_focused) self.items_in_ground.ItemActionA.connect(self.pick_up_item) right_side.addWidget(self.items_carried) right_side.addWidget(self.items_in_ground) main_layout.addLayout(left_side) main_layout.addLayout(right_side) self.setLayout(main_layout) self.update_inventory() self.items_carried.items[0].setFocus(Qt.OtherFocusReason) def update_inventory(self): """ Update items being displayed .. versionadded:: 0.6 """ self.items_carried.show_items(self.character.inventory) items = list(get_items(self.character.level, self.character.location)) self.items_in_ground.show_items(items) self.character_inventory.show_character() def on_item_focused(self, item): """ Handle item focused .. versionadded:: 0.6 """ description = self.inventory_controller.item_description(item) self.item_description.set_text(description) def focusNextPrevChild(self, next): #pylint: disable-msg=C0103 """ Handle moving focus around the widget .. versionadded:: 0.7 """ if len([x for x in self.items_carried.items if x.display.objectName() == 'active_inventorybox']) > 0: focused = self.items_carried elif len([x for x in self.items_in_ground.items if x.display.objectName() == 'active_inventorybox']) > 0: focused = self.items_in_ground.items else: focused = self.character_inventory if focused == self.character_inventory: if next == True: self.items_carried.focus_on_first_row(0) else: self.items_in_ground.focus_on_bottom_row(0) elif focused == self.items_carried: if next == True: index = self.items_carried.get_current_column() self.items_in_ground.focus_on_first_row(index) else: self.character_inventory.focus_on_last_item() else: if next == True: self.character_inventory.focus_on_first_item() else: index = self.items_in_ground.get_current_column() self.items_carried.focus_on_bottom_row(index) return True def pick_up_item(self, item): """ Pick up item .. versionadded:: 0.6 """ self.inventory_controller.pick_up_item(item) self.update_inventory() self.ItemPickedUp.emit(item) def drop_item(self, item): """ Drop item .. versionadded:: 0.6 """ self.inventory_controller.drop_item(item) self.update_inventory() self.ItemDropped.emit(item) def use_item(self, item): """ Use item in different ways, depending on the item .. versionadded:: 0.6 """ self.inventory_controller.use_item(item) self.update_inventory() def unwield_weapon(self, item): """ Unwield current weapon .. versionadded:: 0.6 """ self.inventory_controller.unequip_item(item) self.update_inventory()