MyreMylar / pygame_gui

A GUI system for pygame.
MIT License
696 stars 81 forks source link

Images in theme not loading #51

Closed Snayff closed 4 years ago

Snayff commented 4 years ago

Describe the bug I can't seem to get my theme to load into the UIManager, let alone be applied. I've been comparing the code to the tower defence game you linked and using the same approaches.

To Reproduce Load the theme: gui = pygame_gui.UIManager((VisualInfo.BASE_WINDOW_WIDTH, VisualInfo.BASE_WINDOW_HEIGHT), "data/ui/themes.json")

Configure the theme (themes.json):

{
     "#skill_button":
     {
         "normal_image":
         {
             "path": "assets/skills/placeholder/icon_00.png"
         },
         "hovered_image":
         {
             "path": "assets/skills/placeholder/icon_00.png"
         }
     }
 }

Create the button:

skill = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((x, y), (width, height)), text=f"{skill_slot}",  manager=manager,
                                                 container=self.get_container(), object_id=f"#skill_button")

Expected behaviour Expected button to be shown with an image.

Platform and software (please complete the following information):

Additional context Nothing is applied on screen to the buttons, and when I inspect the gui (UIManager) the theme attirbutes show a lot of data I haven't set, like "#message_window", which I assume is somewhere in the defaults. Although, I didn't even see that when I was looking into the UIAppearanceTheme.

Am I missing something obvious? I tried using an os.abs path, and setting a colour in the json. Setting a colour in a "button" block applied to all buttons, and in the "#skill_button" block also applied, but the images didnt show either way.

P.S. I debated adding this to the thread on reddit, but assumed it would be better suited here. Let me know if you'd rather I raise it somewhere else!

MyreMylar commented 4 years ago

You need an 'images' sub block like this:


{
     "#skill_button":
     {
         "images":
         {
              "normal_image":
              {
                 "path": "assets/skills/placeholder/icon_00.png"
              },
             "hovered_image":
             {
                 "path": "assets/skills/placeholder/icon_00.png"
             }
        }
     }
 }

see the example at the bottom of this page in the docs:
https://pygame-gui.readthedocs.io/en/latest/theme_reference/theme_button.html
Snayff commented 4 years ago

Ah, sorry buddy. That's such a rookie error. :(

MyreMylar commented 4 years ago

No worries. I'm sure there are lots of bugs hidden in my code somewhere and the only way to find them is from people finding them and reporting back. I'd much rather a ton of easily solved bug reports like this than none at all :)

On Tue, 3 Dec 2019, 08:44 Snayff, notifications@github.com wrote:

Ah, sorry buddy. That's such a rookie error. :(

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/MyreMylar/pygame_gui/issues/51?email_source=notifications&email_token=ADGDGGUIFH2A7E4E3NNY5ITQWYL5ZA5CNFSM4JUCWPE2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFYR2EQ#issuecomment-561061138, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADGDGGQ6YOOS2GEM45XJOM3QWYL5ZANCNFSM4JUCWPEQ .

zhuoyizhang commented 4 years ago

How to load an image from the theme and still do convert_alpha()? My goal is to attach an image with transparent center. I only find the way to attach an image from theme as the way you described in this thread. If there is a way for me to attach an image to a button without using theme, that could be a workaround for me, but I couldn't find it.

Thanks!

MyreMylar commented 4 years ago

At the minute all images are loaded by calling convert alpha anyway so you should be OK.

On Wed, 25 Dec 2019, 21:28 zhuoyizhang, notifications@github.com wrote:

How to load an image from the theme and still do convert_alpha()? My goal is to attach an image with transparent center. I only find the way to attack image from theme. If there is a way for me to attach image to a button without theme that could be a workaround for me, but I couldn't find it.

Thanks!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/MyreMylar/pygame_gui/issues/51?email_source=notifications&email_token=ADGDGGUBCI6EYQDMGITCYD3Q2PF7FA5CNFSM4JUCWPE2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHUTTTA#issuecomment-568932812, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADGDGGXMOKZV5CCTCJNUZJ3Q2PF7FANCNFSM4JUCWPEQ .