Please help me.Is this a bug or am I doing something wrong? #637
Unanswered
Matteo-Barberis
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Here is a minimal reproducible example:
The code simply opens and closes an inventory.
PROBLEM 1:
If the inventory_panel is set to visible = 0, like in the example, when the inventory is then visible (as a result of pressing the inventory button), it's not scrollable. The scrollbar doesn't appear (however it should).
PROBLEM 2:
If the inventory_panel is NOT set to visible = 0, but we are simply not defining the visible property, then the inventory will have the scrollbar, but when the panel is set to invisible again, the scrollbar will still be visible.
Is this a bug? Am i doing something wrong? Could anyone help?
`
import pygame
import pygame_gui
import json
pygame.init()
window_size = (1200, 800)
window_width, window_height = window_size
screen = pygame.display.set_mode(window_size)
pygame.display.set_caption("Minimal Inventory Example")
ui_manager = pygame_gui.UIManager(window_size)
inventory_button = pygame_gui.elements.UIButton(
relative_rect=pygame.Rect((650, 10), (140, 40)),
text="Inventory",
manager=ui_manager
)
inventory_panel = pygame_gui.elements.UITextBox(
relative_rect=pygame.Rect((50, window_height - 500), (window_width - 100, 360)),
html_text="",
manager=ui_manager,
visible = 0
)
clock = pygame.time.Clock()
inventory_visible = False
inventory_data = json.loads("""{
"inventory": [
{
"name": "Small Potion",
"description": "A small potion that restores a small amount of health.",
"quantity": 3,
"type": "consumable",
"effect": "Restores 20 HP",
"usable": true,
"rarity": "common",
"durability": null,
"value": 10
},
{
"name": "Small Bomb",
"description": "A small bomb that when used inflicts damage to entities that are hit by it.",
"quantity": 2,
"type": "consumable",
"effect": "Inflicts 30 damage to HP",
"usable": true,
"rarity": "common",
"durability": null,
"value": 10
},
{
"name": "Poison Bomb",
"description": "A small bomb that when used poisons entities hit by it",
"quantity": 1,
"type": "consumable",
"effect": "Inflicts poison damage over time",
"usable": true,
"rarity": "common",
"durability": null,
"value": 10
},
{
"name": "Whispering Shard",
"description": "A translucent crystal that flickers with an inner light, said to contain echoes of lost souls.",
"quantity": 1,
"type": "Artifact",
"effect": "Contains whispers of lost souls, can be used for divination.",
"usable": true,
"rarity": "Rare",
"durability": null,
"value": 250
},
{
"name": "Pair of Ethereal Gloves",
"description": "Gloves that grant the wearer a fleeting ability to phase through the mist.",
"quantity": 1,
"type": "Accessory",
"effect": "Allows the wearer to phase through misty areas temporarily.",
"usable": true,
"rarity": "Uncommon",
"durability": null,
"value": 150
},
{
"name": "Misty Essence",
"description": "A swirling, smoky substance known for its use in enchantments and potions that enhance stealth.",
"quantity": 5,
"type": "Component",
"effect": "Enhances potions and enchantments related to stealth.",
"usable": false,
"rarity": "Common",
"durability": null,
"value": 30
}
]
}"""
)
def format_inventory(inventory):
formatted = "Inventory:
"
for item in inventory['inventory']:
formatted += f"{item['name']} (x{item['quantity']})
"
formatted += f"Effects: {item['effect']}
"
formatted += f"Type: {item['type']}, Rarity: {item['rarity']}, Value: {item['value']}
"
return formatted
inventory_panel.set_text(format_inventory(inventory_data))
running = True
while running:
time_delta = clock.tick(60)/1000.0
pygame.quit()
`
Beta Was this translation helpful? Give feedback.
All reactions