def item(self, value): self._item = value if self.amount_label: self.amount_label.delete() self.amount_label = None if not value: self.icon = None return img = get_block_icon(self._item.get_object(), self.width, self.world) self.icon = image_sprite(img, self.batch, self.group) image_scale = 1.0 / (img.width / self.width) self.icon.scale = image_scale self.icon.x = self.x self.icon.y = self.y if self.is_quickslot: self._item.quickslots_x = self.icon.x self._item.quickslots_y = self.icon.y if self._item.max_durability != -1 and self._item.durability != -1: self.icon.opacity = min(self._item.max_durability, self._item.durability + 1) * 255 // self._item.max_durability if self._item.amount > 1: self.amount_label = pyglet.text.Label( str(self._item.amount), font_name=G.DEFAULT_FONT, font_size=9, x=self.icon.x + 8, y=self.icon.y, anchor_x='left', anchor_y='bottom', color=self._item.get_object().amount_label_color, batch=self.batch, group=self.label_group)
def set_crafting_outcome(self, item): if not item: self.remove_crafting_outcome() return self.crafting_outcome = item self.crafting_outcome_icon = image_sprite(get_block_icon(item.get_object(), self.icon_size, self.world), self.batch, self.group) inventory_rows = floor(self.max_items / 9) inventory_height = (inventory_rows * (self.icon_size * 0.5)) + (inventory_rows * 3) quick_slots_y = self.frame.y + 4 inventory_y = quick_slots_y + (42 if self.mode == 0 else 14 if self.mode == 1 else 32) x, y = 0, 0 if self.mode == 0: x, y = 270, 62 elif self.mode == 1: x, y = 225, 80 elif self.mode == 2: x, y = 222, 67 self.crafting_outcome_icon.scale = 0.5 self.crafting_outcome_icon.x = self.frame.x + x self.crafting_outcome_icon.y = inventory_y + inventory_height + y self.crafting_outcome_label = pyglet.text.Label( str(item.amount), font_name=G.DEFAULT_FONT, font_size=9, x= self.crafting_outcome_icon.x + 3, y= self.crafting_outcome_icon.y, anchor_x='left', anchor_y='bottom', color=item.get_object().amount_label_color, group=self.group)
def update_items(self): self.player.quick_slots.remove_unnecessary_stacks() self.icons = [] for amount_label in self.amount_labels: amount_label.delete() self.amount_labels = [] x = self.frame.x + 3 items = self.player.quick_slots.get_items() items = items[:self.max_items] for item in items: if not item: x += (self.icon_size * 0.5) + 3 continue icon = image_sprite(get_block_icon(item.get_object(), self.icon_size, self.world), self.batch, self.group) icon.scale = 0.5 icon.x = x icon.y = self.frame.y + 3 item.quickslots_x = icon.x item.quickslots_y = icon.y x += (self.icon_size * 0.5) + 3 if item.max_durability != -1 and item.durability != -1: icon.opacity = min(item.max_durability, item.durability + 1) * 255 / item.max_durability amount_label = pyglet.text.Label( str(item.amount), font_name=G.DEFAULT_FONT, font_size=9, x=icon.x + 3, y=icon.y, anchor_x='left', anchor_y='bottom', color=item.get_object().amount_label_color, batch=self.batch, group=self.labels_group) self.amount_labels.append(amount_label) self.icons.append(icon) self.update_current()
def set_selected_item(self, item): if not item: self.remove_selected_item() return self.selected_item = item self.selected_item_icon = image_sprite(get_block_icon(item.get_object(), self.icon_size, self.world), self.batch, self.group) self.selected_item_icon.scale = 0.4
def set_selected_item(self, item, x=0, y=0): if not item: self.remove_selected_item() return self.selected_item = item img = get_block_icon(item.get_object(), self.icon_size, self.world) self.selected_item_icon = image_sprite(img, self.batch[self.mode], self.group[self.mode]) image_scale = 0.8 / (img.width / self.icon_size) self.selected_item_icon.scale = image_scale self.selected_item_icon.x = x - (self.selected_item_icon.width // 2) self.selected_item_icon.y = y - (self.selected_item_icon.height // 2)
def update_items(self): rows = floor(self.max_items / 9) inventory_y = 43 inventory_height = (rows * (self.icon_size * 0.5)) + ((rows+1) * 3) self.icons = [] for amount_label in self.amount_labels: amount_label.delete() self.amount_labels = [] x = self.frame.x + 7 y = self.frame.y + inventory_y + inventory_height items = self.player.inventory.get_items() items = items[:self.max_items] for i, item in enumerate(items): if not item: x += (self.icon_size * 0.5) + 3 if x >= (self.frame.x + self.frame.width) - 7: x = self.frame.x + 7 y -= (self.icon_size * 0.5) + 3 continue icon = image_sprite(get_block_icon(item.get_object(), self.icon_size, self.world), self.batch, self.group) icon.scale = 0.5 icon.x = x icon.y = y - icon.height x += (self.icon_size * 0.5) + 3 if x >= (self.frame.x + self.frame.width) - 7: x = self.frame.x + 7 y -= (self.icon_size * 0.5) + 3 if item.max_durability != -1 and item.durability != -1: icon.opacity = min(item.max_durability, item.durability + 1) * 255 / item.max_durability amount_label = pyglet.text.Label( str(item.amount), font_name=G.DEFAULT_FONT, font_size=9, x=icon.x + 3, y=icon.y, anchor_x='left', anchor_y='bottom', color=item.get_object().amount_label_color, batch=self.batch, group=self.labels_group) self.amount_labels.append(amount_label) self.icons.append(icon) items = self.player.quick_slots.get_items() items = items[:self.player.quick_slots.slot_count] for i, item in enumerate(items): if not item: x += (self.icon_size * 0.5) + 3 continue icon = image_sprite(get_block_icon(item.get_object(), self.icon_size, self.world), self.batch, self.group) icon.scale = 0.5 icon.x = x icon.y = self.frame.y + 7 item.quickslots_x = icon.x item.quickslots_y = icon.y x += (self.icon_size * 0.5) + 3 if item.max_durability != -1 and item.durability != -1: icon.opacity = min(item.max_durability, item.durability + 1) * 255 / item.max_durability amount_label = pyglet.text.Label( str(item.amount), font_name=G.DEFAULT_FONT, font_size=9, x=icon.x + 3, y=icon.y, anchor_x='left', anchor_y='bottom', color=item.get_object().amount_label_color, batch=self.batch, group=self.labels_group) self.amount_labels.append(amount_label) self.icons.append(icon) items = self.player.armor.get_items() items = items[:4] x = self.frame.x + 7 y = inventory_y + inventory_height + 10 + 4 * self.icon_size * 0.5 + 9 for i, item in enumerate(items): if not item: y -= (self.icon_size * 0.5) + 3 continue icon = image_sprite(get_block_icon(item.get_object(), self.icon_size, self.world), self.batch, self.group) icon.scale = 0.5 icon.x = x icon.y = y if item.max_durability != -1 and item.durability != -1: icon.opacity = min(item.max_durability, item.durability + 1) * 255 / item.max_durability amount_label = pyglet.text.Label( str(item.amount), font_name=G.DEFAULT_FONT, font_size=9, x=icon.x + 3, y=icon.y, anchor_x='left', anchor_y='bottom', color=item.get_object().amount_label_color, batch=self.batch, group=self.labels_group) self.amount_labels.append(amount_label) self.icons.append(icon) crafting_y = inventory_y + inventory_height + (42 if self.mode == 0 else 14 if self.mode == 1 else 32) crafting_rows = (2 if self.mode == 0 else 3 if self.mode == 1 else 2) crafting_height = (crafting_rows * (self.icon_size * 0.5)) + (crafting_rows * 3) x = self.frame.x + (165 if self.mode == 0 else 72 if self.mode == 1 else 63) y = self.frame.y + crafting_y + crafting_height items = self.crafting_panel.get_items() if self.mode == 0 else self.crafting_table_panel.get_items() if self.mode == 1 else self.furnace_panel.get_items() items = items[:self.crafting_panel.slot_count] if self.mode == 0 else items[:self.crafting_table_panel.slot_count] if self.mode == 1 else items[:self.furnace_panel.slot_count] # NOTE: each line in the crafting panel should be a sub-list in the crafting ingredient list crafting_ingredients = [[], []] if self.mode == 0 else [[], [], []] if self.mode == 1 else [[], []] for i, item in enumerate(items): if not item: # placeholder crafting_ingredients[int(floor(i / (2 if self.mode == 0 else 3 if self.mode == 1 else 1)))].append(air_block) x += (self.icon_size * 0.5) + 3 if x >= (self.frame.x + (165 if self.mode == 0 else 72 if self.mode == 1 else 63)) + 35 * ((2 if self.mode == 0 else 3 if self.mode == 1 else 1)): x = self.frame.x + (165 if self.mode == 0 else 72 if self.mode == 1 else 63) y -= (self.icon_size * 0.5) + 3 continue icon = image_sprite(get_block_icon(item.get_object(), self.icon_size, self.world), self.batch, self.group) icon.scale = 0.5 icon.x = x icon.y = y - icon.height item.quickslots_x = icon.x item.quickslots_y = icon.y x += (self.icon_size * 0.5) + 3 if x >= (self.frame.x + (165 if self.mode == 0 else 72 if self.mode == 1 else 63)) + 35 * ((2 if self.mode == 0 else 3 if self.mode == 1 else 1)): x = self.frame.x + (165 if self.mode == 0 else 72 if self.mode == 1 else 63) y -= (self.icon_size * 0.5) + 3 if item.max_durability != -1 and item.durability != -1: icon.opacity = min(item.max_durability, item.durability + 1) * 255 / item.max_durability amount_label = pyglet.text.Label( str(item.amount), font_name=G.DEFAULT_FONT, font_size=9, x=icon.x + 3, y=icon.y, anchor_x='left', anchor_y='bottom', color=item.get_object().amount_label_color, batch=self.batch, group=self.labels_group) self.amount_labels.append(amount_label) self.icons.append(icon) if item.get_object().id > 0: crafting_ingredients[int(floor(i / (2 if self.mode == 0 else 3 if self.mode == 1 else 1)))].append(item.get_object()) if len(crafting_ingredients) > 0 and self.mode < 2: outcome = G.recipes.craft(crafting_ingredients) if outcome: self.set_crafting_outcome(outcome) elif self.crafting_outcome: self.remove_crafting_outcome() elif len(crafting_ingredients) > 0 and self.mode == 2: outcome = self.furnace_panel.get_smelt_outcome() if outcome: self.set_crafting_outcome(outcome) elif self.crafting_outcome: self.remove_crafting_outcome()