Jump to content

DialogGUIImage help


Recommended Posts

Howdy All,

I'm working on extending an old project of mine right now, and the lack of documentation for DialogGUI classes is really messing me up, so I wanted to see if anybody can point me in the right direction.

As it stands, I have an image of the sun that I want to show in a Popup window, with a button to close the window. Simple enough. This is the function I currently call when I want it to come up, which mostly works:

internal void DrawPopupStuff()
        {
            if (imageLoaded == false)
            {
                LoadNewImage_KMI();
                imageLoaded = true;
            }

            if (isShowingWindow == true)
            {
                if (myPopupDialog == null && imageOfSun != null)
                {
                    myPopupDialog = PopupDialog.SpawnPopupDialog(new Vector2(0.3f, 0.3f),
                        new Vector2(0.3f, 0.3f),
                        new MultiOptionDialog(
                            "Solar Image Window",
                            "Global Message",
                            "Solar Image Window Title",
                            HighLogic.UISkin,
                            new Rect(0.25f, 0.25f, 800, 800),
                            new DialogGUIBase[]
                            {
                                new DialogGUIFlexibleSpace(),
                                new DialogGUIButton("close",
                                    delegate
                                    {
                                        isShowingWindow = false;
                                    },
                                    true),
                                new DialogGUIImage( new Vector2(0.0f, 0.0f),
                                    new Vector2(0.0f, 0.0f),Color.red,imageOfSun)
                            }
                        ),
                        false,
                        HighLogic.UISkin);
                }
                myPopupDialog.SetDraggable(true);
            }
            else
            {
                myPopupDialog.Dismiss();
            }
        }

Now, most of this seems to work as intended, but unfortunately the DialogGUIImage part escapes me. No image appears. I don't know exactly what it wants from me with the Vectors, nor why it needs a Color.
Screenshot:

Spoiler

 

LbqlAqI.png

 

If anybody could also point me to any examples of PopupDialog in action besides those already visible in DMagic's OG thread, that would be very helpful.

Edited by Snoopy20111
Link to comment
Share on other sites

The two vectors are for scale (first one) and position (second one) of the image. I haven't experimented with the position value, you can simply leave that as (0,0). However, by setting the scale of the image to (0,0) you are shrinking it to a size of 0x0 pixels. Setting the scale to (-1, -1) would stretch the image to fill out all available space, setting positive values sets a fixed amount of pixels in width / height.

The color parameter can be used to display the same texture in different shades. It is essentially a mask that is applied to every pixel of the texture, by multiplying the channels with each other. So, if a pixel has the color (1, 0.5, 1, 1) and you pass (0.25, 2, 0, 1) as the color parameter, the final color that is rendered would be (1 * 0.25, 0.5 * 2, 1 * 0, 1 * 1) = (0.25, 1, 0, 1).

Link to comment
Share on other sites

3 hours ago, Thomas P. said:

The two vectors are for scale (first one) and position (second one) of the image. I haven't experimented with the position value, you can simply leave that as (0,0). However, by setting the scale of the image to (0,0) you are shrinking it to a size of 0x0 pixels. Setting the scale to (-1, -1) would stretch the image to fill out all available space, setting positive values sets a fixed amount of pixels in width / height.

The color parameter can be used to display the same texture in different shades. It is essentially a mask that is applied to every pixel of the texture, by multiplying the channels with each other. So, if a pixel has the color (1, 0.5, 1, 1) and you pass (0.25, 2, 0, 1) as the color parameter, the final color that is rendered would be (1 * 0.25, 0.5 * 2, 1 * 0, 1 * 1) = (0.25, 1, 0, 1).

This is exactly the kind of information I was looking for, thank you! Unfortunately, I still can't get anything to come up. Not sure if the problem is DialogGUI, my image, or something else. At any rate, this will be helpful in the future.

5 hours ago, HebaruSan said:

Excellent lot of examples, thank you! I'm going to try your method of converting to a Sprite, hopefully it works.

Link to comment
Share on other sites

How are you generating the texture? And do you know if it is working correctly.

If you want to quickly verify that the texture works you can draw it with OnGUI. 

GUI.DrawTexture, or something like that on the OnGUI method. (On phone, so I can't give a real example).

Link to comment
Share on other sites

3 hours ago, DMagic said:

How are you generating the texture? And do you know if it is working correctly.

If you want to quickly verify that the texture works you can draw it with OnGUI. 

GUI.DrawTexture, or something like that on the OnGUI method. (On phone, so I can't give a real example).

 

After using the mentioned methods to check my texture works, I can confirm it is loading into the game, being assigned properly to a Texture2D variable, and displayed with OnGUI. Image is in the upper left:

OK0CqINg.png

So I think this means there's something up with the DialogGUIImage methods (or at least I'm not using them right) but I don't know what.

Link to comment
Share on other sites

So, I've been working with this, and I haven't found a great solution. Basically, the only thing I've gotten to properly work is to make it show up as the UIStyle for a Button (thank you HebaruSan!!).

9Wc5VjP.png

This displays mostly as I would like it to, but it's pretty weird behind the scenes, and I would still like to just use the DialogGUIImage stuff instead. The main issue is when I mouse over the button, it does this:

FOFr5w8.png

The draw function for making this happen is as follows. If anybody has any ideas or any further information on where to go from here, I would really appreciate it.

internal void DrawPopupStuff()
        {
            if (imageLoaded == false)
            {
                LoadNewImage_KMI();
                imageLoaded = true;
            }

            UIStyleState currentImageOfSun = new UIStyleState()
            {
                background = spriteOfSun,
                textColor = Color.black
            };

            UIStyle sunDisplayStyle = new UIStyle()
            {
                normal = currentImageOfSun,
                highlight = currentImageOfSun,
                active = currentImageOfSun,
                disabled = currentImageOfSun,
            };

            if (isShowingWindow == true)
            {
                if (myPopupDialog == null && imageOfSun != null)
                {
                    myPopupDialog = PopupDialog.SpawnPopupDialog(new Vector2(0.3f, 0.3f),
                        new Vector2(0.3f, 0.3f),
                        new MultiOptionDialog(
                            "Solar Image Window",
                            "Global Message",
                            "Solar Image Window Title",
                            HighLogic.UISkin,
                            new Rect(0.25f, 0.25f, imageOfSun.width/2, imageOfSun.height/2),
                            new DialogGUIBase[]
                            {
                                //new DialogGUIImage( new Vector2(0, 0),
                                    //new Vector2(560, 512),new Color(1, 1, 1, 1),imageOfSun),

                                new DialogGUIButton(spriteOfSun, delegate{ isShowingWindow = false; },
                                    imageOfSun.width/2, imageOfSun.height/2, true),

                                /*new DialogGUIBox("message", sunDisplayStyle, imageOfSun.width, imageOfSun.height,
                                delegate{return false;},
                                new DialogGUIBase[]
                                {
                                    new DialogGUIButton("test",
                                    delegate {},
                                    true)
                                }),*/

                                //new DialogGUIFlexibleSpace(),

                                /*new DialogGUIButton("close",
                                    delegate
                                    {
                                        isShowingWindow = false;
                                    },
                                    true)*/
                            }
                        ),
                        false,
                        HighLogic.UISkin);
                }
                myPopupDialog.SetDraggable(true);
            }
            else
            {
                myPopupDialog.Dismiss();
            }
        }

 

Link to comment
Share on other sites

Oh! I misunderstood what the goal was; I conflated your close button with the image you wanted to display (probably because my own close button was image-based). Try putting that UIStyle on some more neutral component, like a DialogGUIBox or DialogGUISpace, or possibly DialogGUISprite.

https://kerbalspaceprogram.com/api/class_dialog_g_u_i_base.html

Link to comment
Share on other sites

12 minutes ago, HebaruSan said:

Oh! I misunderstood what the goal was; I conflated your close button with the image you wanted to display (probably because my own close button was image-based). Try putting that UIStyle on some more neutral component, like a DialogGUIBox or DialogGUISpace, or possibly DialogGUISprite.

https://kerbalspaceprogram.com/api/class_dialog_g_u_i_base.html

Truth be told, I was also looking for a better solution for the button, but the main issue was indeed the image display. I already tried DialogGUIBox and DialogGUISpace, but neither of those displayed anything. DialogGUISprite though, I completely overlooked in the first place. Without UI Styles, it displays my image! Working with the scaling to make it display with the same dimensions and all, but this is a great step forward. Thank you! I'll post again once I get it properly together or if there are any further problems.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...