Jump to content

[WIP] [1.12.x] HUDReplacer - (v1.2.11-beta)


UltraJohn

Recommended Posts

25 minutes ago, UltraJohn said:

I don't think this will make the cursor load. If it doesn't exist as a Texture2D, then none of the scene types will have an effect.

I proposed this one just to be sure HUDReplacer works in all scenes. The one before ( [KSPAddon(KSPAddon.Startup.Instantly, true)] ) would maybe have an effect on the cursor?

That said, looking at cursordeleter's source

Spoiler
namespace CursorDeleter
{
	[KSPAddon(KSPAddon.Startup.EveryScene, false)]
	public class CursorDeleter : MonoBehaviour
	{
		private Timer checkTimer;
		public void Awake()
		{
			/*
			 * Because this script might run before or after the cursor controller
			 * becomes available, this timer will repeatedly check for a
			 * controller instance.
			 */
			checkTimer = new System.Timers.Timer(20);
			checkTimer.Elapsed += _removeCursor;
			checkTimer.Enabled = true;
		}
		private void _removeCursor(object source, ElapsedEventArgs e)
		{
			if (Cursors.CursorController.Instance) //Only bother if there's a cursor controller to kill.
			{
				/*
				 * Kill the cursor controller WITH FIRE.
				 */
				Cursors.CursorController.Destroy(Cursors.CursorController.Instance);
				/*
				 * Set the cursor back to default.
				 */
				UnityEngine.Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
				/*
				 * Done checking. Turn the timer off!
				 */
				checkTimer.Enabled = false;
			}
		}
	}
}

yields that it uses  KSPAddon.Startup.EveryScene  , and it gets active right after game startup. So using it may make the mod do its stuff right on startup? IDK for I haven't tested it.

Hold on, I'm looking at the KSP API for  Cursors.CursorController ...

(https://www.kerbalspaceprogram.com/ksp/api/namespace_cursors.html)

 

Found this: Cursors.CursorController.DefaultCursor = <texture2d>  changes the default cursor to whatever's in <texture2d>. Replace DefaultCursor with DefaultLeftClick and DefaultRightClick as needed. I still need to find a function to force cursor image updating, though.

Link to comment
Share on other sites

It looks like the cursor is not stored as a gameobject in the scene, so it doesn't matter which startup mode i set. I can add a special case in the code to check for a cursor texture and then manually apply it directly to the cursor. I will look into that as soon as I have the time.

Link to comment
Share on other sites

Maybe try to execute  Cursors.CursorController.Clear()  on keypress, just to see what it does? I can't test rn.

1 minute ago, UltraJohn said:

It looks like the cursor is not stored as a gameobject in the scene, so it doesn't matter which startup mode i set. I can add a special case in the code to check for a cursor texture and then manually apply it directly to the cursor. I will look into that as soon as I have the time.

or just call whatever function that forces the cursor to update its textures, if there is one, at the end of HR's  Update() .

Link to comment
Share on other sites

5 hours ago, Nazalassa said:

Maybe try to execute  Cursors.CursorController.Clear()  on keypress, just to see what it does? I can't test rn.

I've tried that and Cursor.SetCursor(), no luck with either. I gotta dig a bit deeper I suppose. I refuse to be defeated by one pointy boy!!

Link to comment
Share on other sites

8 hours ago, UltraJohn said:

I've tried that and Cursor.SetCursor(), no luck with either. I gotta dig a bit deeper I suppose. I refuse to be defeated by one pointy boy!!

Are you sure Cursor.SetCursor()doesn't work? I've been testing some things and

Spoiler
using System;
using UnityEngine;
using System.IO;

namespace cursorchang
{
    [KSPAddon(KSPAddon.Startup.EveryScene, false)]
    public class cursorchang : MonoBehaviour
    {
        //shiny texture
        private Texture2D customCursor = LoadPNG("GameData/CursorChanger/test.png");
        private Texture2D customLCursor = LoadPNG("GameData/CursorChanger/testL.png");
        private Texture2D customRCursor = LoadPNG("GameData/CursorChanger/testR.png");

        void Update()
        {
            //this is legacy????
            if (Input.GetMouseButton(0))
            {
                Cursor.SetCursor(customLCursor, new Vector2(6,0), CursorMode.Auto);
            }
            else if (Input.GetMouseButton(1))
            {
                Cursor.SetCursor(customRCursor, new Vector2(6, 0), CursorMode.Auto);
            }
            else
            {
                Cursor.SetCursor(customCursor, new Vector2(6, 0), CursorMode.Auto);
            }
        }

        //LoadPNG from mousecursorchanger
        //dunno if i can share it here but it's LoadPNG from MouseCursorChanger with tex.LoadImage(fileData) replaced with ImageConversion.LoadImage(tex, fileData)
    }
}

seems to work. (don't just copy the code and compile it though)

(reminder that I'm not a unity dev or a c# dev but I'm suprised that this worked)

Link to comment
Share on other sites

1 hour ago, zapsnh said:

Ok so it looks like the problem is that the cursor texture is being reverted back to default on click. What this guys source code does is that he is apparently updating the cursor texture every frame, so that it reapplies the new texture after clicking. Sounds quite unoptimal, so I have to look for a better solution.

 

The second problem is that trying to access CursorController's instance is not possible during scene load, since this controller is loaded slightly after the scene is. I've tried implementing the timer example shown in the previous post by @Nazalassa but it looks like this just straight up crashes the game. Once I figure this part out, I may have a working implementation ready for testing!

Link to comment
Share on other sites

9 minutes ago, UltraJohn said:

The second problem is that trying to access CursorController's instance is not possible during scene load, since this controller is loaded slightly after the scene is. I've tried implementing the timer example shown in the previous post by @Nazalassa but it looks like this just straight up crashes the game. Once I figure this part out, I may have a working implementation ready for testing!

It's just a copy-paste of the entire code of cursordeleter, minus three lines of "using xyz" at the top.

The complete code is the following:

using System;
using System.Timers;
using UnityEngine;

namespace CursorDeleter
{
	[KSPAddon(KSPAddon.Startup.EveryScene, false)]
	public class CursorDeleter : MonoBehaviour
	{
		private Timer checkTimer;
		public void Awake()
		{
			/*
			 * Because this script might run before or after the cursor controller
			 * becomes available, this timer will repeatedly check for a
			 * controller instance.
			 */
			checkTimer = new System.Timers.Timer(20);
			checkTimer.Elapsed += _removeCursor;
			checkTimer.Enabled = true;
		}
		private void _removeCursor(object source, ElapsedEventArgs e)
		{
			if (Cursors.CursorController.Instance) //Only bother if there's a cursor controller to kill.
			{
				/*
				 * Kill the cursor controller WITH FIRE.
				 */
				Cursors.CursorController.Destroy(Cursors.CursorController.Instance);
				/*
				 * Set the cursor back to default.
				 */
				UnityEngine.Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
				/*
				 * Done checking. Turn the timer off!
				 */
				checkTimer.Enabled = false;
			}
		}
	}
}

(it's under MIT iirc)

I think I can make something that kind of works - give me a bit of time.

Link to comment
Share on other sites

1.0.5-beta is released (pre-release testing)

https://github.com/UltraJohn/HUDReplacer/releases/tag/1.0.5-beta

Try this out and see if it works for you guys. There may be a few quirks with this so I've flagged it as pre-release until we know it works.

 

Known issues:

The cursor may not change immediately once loaded into the main menu, but clicking once should make it apply.

Link to comment
Share on other sites

10 minutes ago, UltraJohn said:

1.0.5-beta is released (pre-release testing)

https://github.com/UltraJohn/HUDReplacer/releases/tag/1.0.5-beta

Try this out and see if it works for you guys. There may be a few quirks with this so I've flagged it as pre-release until we know it works.

 

Known issues:

The cursor may not change immediately once loaded into the main menu, but clicking once should make it apply.

Small issue where the original cursor texture shows up for a bit when in a loading screen.

And also sometimes after scene change (KSC > VAB)? (clicking makes it apply though)

Edited by zapsnh
Link to comment
Share on other sites

Will try.

It would've be nice (from the devs? Or not, idk) if we could just look into the texture dictionnary for a certain name.

That way we could just look for cursor textures at the beginning and the amount of time we see KSP's cursor would be lower.

--

I can report the same issues as @zapsnh.

Also, maybe add in the README what pressing 'g' does in dev version? if I understood the source correctly, it says "that UI element has that and that images associated with it" or something like that.

Link to comment
Share on other sites

1 hour ago, Nazalassa said:

Also, maybe add in the README what pressing 'g' does in dev version? if I understood the source correctly, it says "that UI element has that and that images associated with it" or something like that.

It doesn't work, I just forgot to remove it before committing the build. You can ignore it.

Link to comment
Share on other sites

The maneuver delete button (near the navball) and the fire/remove kerbal buttons use the same texture (vsd_widget_crew_button_x), and the aspect ratios are not the same...  So:
theyrethesamepicture.png
one of them has to be distorted
Literally unplayable.

----

And since making this reply anyway I'm gonna give you an album of my theme since I can no longer share it.
https://ibb.co/album/jZQ67B

Edited by zapsnh
Link to comment
Share on other sites

1 hour ago, zapsnh said:

The maneuver delete button (near the navball) and the fire/remove kerbal buttons use the same texture (vsd_widget_crew_button_x), and the aspect ratios are not the same...  So:

have you tried adding the tag for texture size to the filename? This is explained in the readme on github:

In the case of a texture which has multiple versions that have the same name but different sizes (e.g. "rect_round_dark"), we must ensure that we append the dimensions of the texture to the filename, like this: rect_round_dark#64x64.png or rect_round_dark#69x69.png otherwise, we will be replacing the wrong size texture and that will scale incorrectly.

Link to comment
Share on other sites

    (how do I put a quote in a reply on mobile)  There is no other version of vsd crew widget x. If you boot up stock ksp and make a maneuver you would see that the x is kinda squished. 

Edited by zapsnh
power outage and also stupid mobile formatting issues
Link to comment
Share on other sites

53 minutes ago, zapsnh said:

There is no other version of vsd crew widget x. If you boot up stock ksp and make a maneuver you would see that the x is kinda squished.

Ah I see what's going on then. That's just how stock game renders the UI.

Some textures, like the vertical speed gauge at the top, have a larger texture size and the game scales it down to fit on screen. As long as the textures are scaled equally on both width and height to keep the aspect ratio, they will look fine mostly fine, but this specific button vsd_widget_crew_button_x is not the case and is scaled incorrectly, which you observed with the stock textures.

Link to comment
Share on other sites

6 minutes ago, Nazalassa said:

Wow! One question though: how did you change the planet colors in the loading screen? I can't find the texture's name (if any).

Fun fact: They are actually planets/bodies from GPP (Niven, Gael, Grannus):

Textures:

(all 128x128)
01_sun.png
02_eve.png
03_kerbin.png
04_jool.png

got ninja'd

Edited by zapsnh
Link to comment
Share on other sites

3 minutes ago, UltraJohn said:

Probably these:

01_sun, 02_eve, 03_kerbin, 04_jool

2 minutes ago, zapsnh said:

Fun fact: They are actually planets/bodies from GPP (Niven, Gael, Grannus):

Textures:

(all 128x128)
01_sun.png
02_eve.png
03_kerbin.png
04_jool.png

got ninja'd

Thanks!

Link to comment
Share on other sites

Idea:
There should be a toolbar (or any other) button that toggles HUDReplacer's keybinds. I either sometimes find some textures that need texturing during normal sessions (and forget about them) or just forget that I had the dev version installed and either have to suffer with no roll controls or suffer with the atrocious loading times again (mods + HDD).
hudbutton.png
no background - dev keybinds disabled (d, q, e disabled)
w/ background - dev keybinds enabled (d, q, e enabled)

Link to comment
Share on other sites

I second @zapsnh's idea and I propose another one:

I have a small idea of thing to add to HUDReplacer: when pressing a key (like 'a' or something) HUDReplacer goes through all loaded textures and dumps them to  GameData/HUDReplacer/PluginData/  or something. Or pressing that key pops out a dialog box where we can enter a texture's name, which HUDReplacer saves to  GameData/HUDReplacer/PluginData/ . Just an idea, but it may help quite a lot.

I'll search for "how to make UI for KSP mods" just in case :)

 

EDIT: Found this

https://forum.kerbalspaceprogram.com/index.php?/topic/149324-popupdialog-and-the-dialoggui-classes/

Edited by Nazalassa
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...