Пример #1
0
    def on_inventory_updated(self, item_slots: List[ItemInventorySlot]):
        for i in range(len(item_slots)):
            icon = self.inventory_icons[i]
            slot = item_slots[i]
            item_type = slot.get_item_type() if not slot.is_empty() else None
            slot_equipment_category = slot.enforced_equipment_category
            image = None
            tooltip = None
            if item_type:
                data = ITEMS[item_type]
                image = self.images_by_ui_sprite[data.icon_sprite]
                category_name = None
                if data.item_equipment_category:
                    category_name = ITEM_EQUIPMENT_CATEGORY_NAMES[
                        data.item_equipment_category]
                tooltip = TooltipGraphics.create_for_item(
                    self.ui_render, data, category_name, icon.rect.topleft)
            elif slot_equipment_category:
                image = self.images_by_item_category[slot_equipment_category]
                category_name = ITEM_EQUIPMENT_CATEGORY_NAMES[
                    slot_equipment_category]
                tooltip_details = [
                    "[" + category_name + "]",
                    "You have nothing equipped. Drag an item here to equip it!"
                ]
                tooltip = TooltipGraphics(self.ui_render,
                                          COLOR_WHITE,
                                          "...",
                                          tooltip_details,
                                          bottom_left=icon.rect.topleft)

            icon.image = image
            icon.tooltip = tooltip
            icon.slot_equipment_category = slot_equipment_category
            icon.item_type = item_type
Пример #2
0
    def on_player_stats_updated(self, player_state: PlayerState):
        self.stats_window.player_state = player_state
        health_regen = player_state.health_resource.get_effective_regen()
        mana_regen = player_state.mana_resource.get_effective_regen()

        tooltip_details = [
            DetailLine("regeneration: " + "{:.1f}".format(health_regen) + "/s")
        ]
        health_tooltip = TooltipGraphics(
            self.ui_render,
            COLOR_WHITE,
            "Health",
            tooltip_details,
            bottom_left=(self.healthbar.rect.left - 2,
                         self.healthbar.rect.top - 1))
        self.healthbar.tooltip = health_tooltip
        tooltip_details = [
            DetailLine("regeneration: " + "{:.1f}".format(mana_regen) + "/s")
        ]
        mana_tooltip = TooltipGraphics(self.ui_render,
                                       COLOR_WHITE,
                                       "Mana",
                                       tooltip_details,
                                       bottom_left=(self.manabar.rect.left - 2,
                                                    self.manabar.rect.top - 1))
        self.manabar.tooltip = mana_tooltip
Пример #3
0
    def on_inventory_updated(self, item_slots: List[ItemInventorySlot]):
        for i in range(len(item_slots)):
            icon = self.inventory_icons[i]
            slot = item_slots[i]
            item_id = slot.get_item_id() if not slot.is_empty() else None
            slot_equipment_category = slot.enforced_equipment_category
            image = None
            tooltip = None
            if item_id:
                item_type = item_id.item_type
                data = get_item_data_by_type(item_type)
                image = self.images_by_ui_sprite[data.icon_sprite]
                category_name = None
                if data.item_equipment_category:
                    category_name = ITEM_EQUIPMENT_CATEGORY_NAMES[
                        data.item_equipment_category]
                description_lines = create_item_description(item_id)
                item_name = build_item_name(item_id)
                is_rare = item_id.suffix_id is not None
                is_unique = data.is_unique
                tooltip = TooltipGraphics.create_for_item(self.ui_render,
                                                          item_name,
                                                          category_name,
                                                          icon.rect.topleft,
                                                          description_lines,
                                                          is_rare=is_rare,
                                                          is_unique=is_unique)
            elif slot_equipment_category:
                image = self.images_by_item_category[slot_equipment_category]
                category_name = ITEM_EQUIPMENT_CATEGORY_NAMES[
                    slot_equipment_category]
                tooltip_details = [
                    DetailLine("[" + category_name + "]"),
                    DetailLine(
                        "You have nothing equipped. Drag an item here to equip it!"
                    )
                ]
                tooltip = TooltipGraphics(self.ui_render,
                                          COLOR_WHITE,
                                          "...",
                                          tooltip_details,
                                          bottom_left=icon.rect.topleft)

            icon.image = image
            icon.tooltip = tooltip
            icon.slot_equipment_category = slot_equipment_category
            icon.item_id = item_id
Пример #4
0
 def _setup_ui_components(self):
     icon_space = 5
     x_1 = 165
     y_2 = 40
     self.button_delete_entities = self._create_map_editor_icon(
         Rect(20, y_2, MAP_EDITOR_UI_ICON_SIZE[0], MAP_EDITOR_UI_ICON_SIZE[1]),
         'Q', None, UiIconSprite.MAP_EDITOR_TRASHCAN, 0, None)
     self.button_delete_decorations = self._create_map_editor_icon(
         Rect(20 + MAP_EDITOR_UI_ICON_SIZE[0] + icon_space, y_2, MAP_EDITOR_UI_ICON_SIZE[0],
              MAP_EDITOR_UI_ICON_SIZE[1]), 'Z', None, UiIconSprite.MAP_EDITOR_RECYCLING, 0, None)
     self.entity_icons_by_type = {}
     num_icons_per_row = 23
     for entity_type in EntityTab:
         self.entity_icons_by_type[entity_type] = []
         for i, entity in enumerate(self._entities_by_type[entity_type]):
             x = x_1 + (i % num_icons_per_row) * (MAP_EDITOR_UI_ICON_SIZE[0] + icon_space)
             row_index = (i // num_icons_per_row)
             y = y_2 + row_index * (MAP_EDITOR_UI_ICON_SIZE[1] + icon_space)
             if entity.item_id is not None:
                 data = get_item_data(entity.item_id)
                 category_name = None
                 if data.item_equipment_category:
                     category_name = ITEM_EQUIPMENT_CATEGORY_NAMES[data.item_equipment_category]
                 description_lines = create_item_description(entity.item_id)
                 item_name = build_item_name(entity.item_id)
                 is_rare = entity.item_id.suffix_id is not None
                 is_unique = data.is_unique
                 tooltip = TooltipGraphics.create_for_item(self._ui_render, item_name, category_name, (x, y),
                                                           description_lines, is_rare=is_rare, is_unique=is_unique)
             elif entity.consumable_type is not None:
                 data = CONSUMABLES[entity.consumable_type]
                 tooltip = TooltipGraphics.create_for_consumable(self._ui_render, data, (x, y))
             elif entity.npc_type is not None:
                 data = NON_PLAYER_CHARACTERS[entity.npc_type]
                 tooltip = TooltipGraphics.create_for_npc(self._ui_render, entity.npc_type, data, (x, y))
             elif entity.portal_id is not None:
                 tooltip = TooltipGraphics.create_for_portal(self._ui_render, entity.portal_id, (x, y))
             elif entity.is_smart_floor_tile:
                 tooltip = TooltipGraphics.create_for_smart_floor_tile(self._ui_render, entity.entity_size, (x, y))
             else:
                 tooltip = None
             icon = self._create_map_editor_icon(
                 Rect(x, y, MAP_EDITOR_UI_ICON_SIZE[0], MAP_EDITOR_UI_ICON_SIZE[1]), '', entity.sprite, None,
                 entity.map_editor_entity_id, tooltip)
             self.entity_icons_by_type[entity_type].append(icon)
 def _setup_ui_components(self):
     icon_space = 5
     x_1 = 165
     y_2 = 40
     self.button_delete_entities = self._create_map_editor_icon(
         Rect(20, y_2, MAP_EDITOR_UI_ICON_SIZE[0],
              MAP_EDITOR_UI_ICON_SIZE[1]), 'Q', None,
         UiIconSprite.MAP_EDITOR_TRASHCAN, 0, None)
     self.button_delete_decorations = self._create_map_editor_icon(
         Rect(20 + MAP_EDITOR_UI_ICON_SIZE[0] + icon_space, y_2,
              MAP_EDITOR_UI_ICON_SIZE[0], MAP_EDITOR_UI_ICON_SIZE[1]), 'Z',
         None, UiIconSprite.MAP_EDITOR_RECYCLING, 0, None)
     self.entity_icons_by_type = {}
     num_icons_per_row = 23
     for entity_type in EntityTab:
         self.entity_icons_by_type[entity_type] = []
         for i, entity in enumerate(self._entities_by_type[entity_type]):
             x = x_1 + (i % num_icons_per_row) * (
                 MAP_EDITOR_UI_ICON_SIZE[0] + icon_space)
             row_index = (i // num_icons_per_row)
             y = y_2 + row_index * (MAP_EDITOR_UI_ICON_SIZE[1] + icon_space)
             if entity.item_type is not None:
                 data = ITEMS[entity.item_type]
                 category_name = None
                 if data.item_equipment_category:
                     category_name = ITEM_EQUIPMENT_CATEGORY_NAMES[
                         data.item_equipment_category]
                 tooltip = TooltipGraphics.create_for_item(
                     self._ui_render, data, category_name, (x, y))
             elif entity.consumable_type is not None:
                 data = CONSUMABLES[entity.consumable_type]
                 tooltip = TooltipGraphics.create_for_consumable(
                     self._ui_render, data, (x, y))
             else:
                 tooltip = None
             icon = self._create_map_editor_icon(
                 Rect(x, y, MAP_EDITOR_UI_ICON_SIZE[0],
                      MAP_EDITOR_UI_ICON_SIZE[1]), '', entity.sprite, None,
                 entity.map_editor_entity_id, tooltip)
             self.entity_icons_by_type[entity_type].append(icon)