Jump to content

The official unoffical "help a fellow plugin developer" thread


Recommended Posts

1 hour ago, hab136 said:

KSP 1.4.1 doesn't like my PNG textures.  Why?  The exact same textures worked fine in KSP 1.3, 1.2, 1.1, 1.0.  I've tried re-saving them several times with different editors, no go.

ixQu96I.jpg

Do you know whether you're using OpenGL or one of the Direct-things? I think I saw this on one of them but not the others.

Link to comment
Share on other sites

1 hour ago, hab136 said:

KSP 1.4.1 doesn't like my PNG textures.  Why?  The exact same textures worked fine in KSP 1.3, 1.2, 1.1, 1.0.  I've tried re-saving them several times with different editors, no go.

ixQu96I.jpg

Are they sized to a power of two ? 

Link to comment
Share on other sites

6 minutes ago, hab136 said:

They are not!  I was unaware of this (new?) requirement.  Thanks, I'll try with 32x32.

 You could also load the images manually rather then using the game database. 

I had this exact same problem with part commander, and solved it with manual loading.

@hab136, here is the code I'm using, it works nicely

 Log.Info("Loading image manually");

_imagetex = new WWW(KSPUtil.ApplicationRootPath.Replace("\\", "/") +  "/GameData/" + path + ".png");
Texture2D img = _imagetex.texture;
_imagetex.Dispose();

 

Edited by linuxgurugamer
Link to comment
Share on other sites

Hello.

Does anyone know how to differentiate the overview of the KSC from, say, the management building scene?

I'm trying to make my plugin appear only in the KSC overview, the trackstation and in flight...

I tried with 

[KSPAddon (KSPAddon.Startup.FlightAndKSC, true)]
coupled with a little
UnityEngine.Object.DontDestroyOnLoad (this);
and some
if (HighLogic.LoadedScene.Equals (GameScenes.SPACECENTER) || HighLogic.LoadedScene.Equals (GameScenes.TRACKSTATION) || HighLogic.LoadedSceneIsFlight)

But it keeps showing up in KSC's building other than editors.

I tried to remove the DontDestroyOnLoad(), but once it's gone, it's gone for good...

 

I'm out of ideas, please send help :P

Link to comment
Share on other sites

@Askirkela My guess is that building others than editors and the tracking station are not scene, just screen on top of the current scene (ie the KSC). You can try to listen for event fired when those screen shows/hide : "GameEvents.onGUIAdministrationFacilitySpawn" for example. And hide/show your app accordingly.

Link to comment
Share on other sites

1 hour ago, Askirkela said:

Hello.

Does anyone know how to differentiate the overview of the KSC from, say, the management building scene?

I'm trying to make my plugin appear only in the KSC overview, the trackstation and in flight...

The second param of KSPAddon is true if you want a plugin to start only once. So set it to false and remove the dontdestroyonload

Link to comment
Share on other sites

does anyone know how to chance the cost typ in the tech tree from 'science' to funds or specific science experiments?

like: crew report from launchpad will unlock basic rocketry node

or: 1k funds instead of 5 science will unlock the node

thank you!

Link to comment
Share on other sites

  • 4 weeks later...

Hey all! Got a mod engine I made using NFE uranium as fuel but I cannot get an alternator to output depleted fuel for some reason. I've got the code for the alternator pulled off another liquid engine and just replaced electric charge with depleted. (With the proper names) what have I done wrong?

It's also a fuel tank with the rules for needing an engineer to transfer fuels if that matters?

Edited by Maxx
Link to comment
Share on other sites

I have just started dipping my toes into modding, trying to make some parts. For some reason this cockpit insist on coming being upside down and backwards, or if you will rotated 180 degrees about the x axis. I have tried rotating the part in unity, but that seems to do exactly nothing, and googling the issue only turns up results for how to rotate stuff in the SPH, which is not at all useful. Any Ideas of what I am doing wrong? There are some more images in the imgur album.

https://imgur.com/a/jyHzhP9

Figured it out on my own. Apparently it does not work to have the part tools in the mesh, needs to be in the "root" empty.

Edited by neistridlar
figured it out
Link to comment
Share on other sites

Hello there! I am new to creating mods, but I have already learned the basics of changing and adding functionality to parts. My question is How do you change the name of a module without changing the functionality of the module? Should I just create a new module, and if so, how? Also, is there a way to bundle multiple modules together so that they all fire with one action? And lastly, How do I make a module that generates a specific amount of a resources relative to another resource without actually using that second resource? Thanks a lot!

Link to comment
Share on other sites

  • 2 weeks later...

In moving from 1.3.1 to 1.4.0 I've run into a problem with scrollable sections. 
I've got a simple GUILayout window with a GUILayout.BeginScrollView....GUILayout.EndScrollView section. In 1.3.x this worked as expected, but in 1.4.0 (also tried in 1.4.3) there are several issues;
1) the mouse wheel scroll is inverted, mouse wheel down results in scrolling up
2) mouse wheel scroll is very slow compared to how it was in 1.3.x
3) Main issue: there is an offset in where mousewheel scroll is detected. with the mouse over the top of the scrollable section it doesn't respond to the mouse wheel, but by moving the mouse down to about halfway down the scrollable section it then detects and responds to the mousewheel (and continues to detect and respond after the mouse has gone off the bottom of the scrollable area (by about the same offset as was needed to start detection at the top).  I'm also noticing that buttons (or things with on hover style changes) are behaving like the mouse is over them, when in fact the mouse is much lower down, but only while using the scroll wheel.  It's like using the scrollwheel results in the position of the mouse being interpreted incorrectly.

Has anyone else run into mouse wheel scroll related issues in 1.4.x and are there any know workarounds?

Link to comment
Share on other sites

7 minutes ago, katateochi said:

Has anyone else run into mouse wheel scroll related issues in 1.4.x and are there any know workarounds?

I don't have those issue in Antenna Helper (tested on last version recompiled against KSP 1.4.3 dll). The scroll view code start here if you want to have a look.

Link to comment
Share on other sites

I've made a little test mod that is just a window with a scroll view to check that it's not dependent on something else I'm doing, so this is my test code;
This is in 1.4.3 on Linux, and aside from this bit of code, nothing else non-stock is present.
 

using System;
using UnityEngine;

namespace ScrollTest
{
    [KSPAddon(KSPAddon.Startup.AllGameScenes, false)]
    public class ScrollTest : MonoBehaviour
    {
        public Rect window_pos = new Rect(100, 100, 310, 5);
        public Vector2 scroll_pos = new Vector2();
        public int window_id = 42;

        protected void OnGUI(){
            window_pos = GUILayout.Window(
                window_id, window_pos, WindowContent, "test", GUI.skin.window               
            );
        }

        protected void WindowContent(int win_id){
            if(GUILayout.Button("test")){
                Debug.Log("test clicked");
            }
            GUILayout.Label(scroll_pos.y.ToString());

            float scroll_width = 200f;
            float scroll_height = 200f;

            scroll_pos = GUILayout.BeginScrollView(scroll_pos, GUI.skin.scrollView, GUILayout.Width(scroll_width), GUILayout.MaxWidth(scroll_width), GUILayout.Height(scroll_height));
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.EndScrollView();
        }
    }
}

And this is the result: 
mousewheel scroll is not detected where you'd expect, but is detected (roughly) in the large red shaded box. and for added oddness, if you keep rolling the mousewheel while moving the mouse further down to the small red box the on hover effect for the 'test' button is shown.  So....it's like the mouse detection is inverted and transposed 
vepP6SR.png

Edit: removing the extra arguments to BeginScrollView doesn't change anything. with `scroll_pos = GUILayout.BeginScrollView(scroll_pos);` the same issue happens. 

Edited by katateochi
Link to comment
Share on other sites

Surround each one with a GUILayout.BeginHorizontal()/GUILayout.EndHorizontal().  Works for me.

Here is a link to some working code:  

https://github.com/linuxgurugamer/ToolbarControl/blob/b23b0106570b219b84e00b002d3623585fdcd160/ToolbarControl/BlizzyOptions.cs#L121-L198
Link to comment
Share on other sites

8 minutes ago, linuxgurugamer said:

Surround each one with a GUILayout.BeginHorizontal()/GUILayout.EndHorizontal().  Works for me.

Thanks for the tip.....but I still get the same issue.
This is the code now:

using System;
using UnityEngine;

namespace ScrollTest
{
    [KSPAddon(KSPAddon.Startup.AllGameScenes, false)]
    public class ScrollTest : MonoBehaviour
    {
        public Rect window_pos = new Rect(100, 100, 310, 5);
        public Vector2 scroll_pos = new Vector2();
        public int window_id = 42;

        protected void OnGUI(){
            window_pos = GUILayout.Window(
                window_id, window_pos, WindowContent, "test", GUI.skin.window               
            );
        }

        protected void WindowContent(int win_id){
            if(GUILayout.Button("test")){
                Debug.Log("test clicked");
            }
            GUILayout.Label(scroll_pos.y.ToString());

            GUILayout.BeginHorizontal();

            scroll_pos = GUILayout.BeginScrollView(scroll_pos);
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.Label("foo");
            GUILayout.EndScrollView();

            GUILayout.EndHorizontal();
        }
    }
}

and it has the same problem of mousewheel scroll being detected some way below the scrollable area (and inverted).

BUT, I just tried this same bit out in windows and it works fine, the scroll behaves exactly as expected.

Link to comment
Share on other sites

17 minutes ago, linuxgurugamer said:

Oh,  I missed the Linux part, sorry.

Sounds like a Unity issue, maybe?

You off all people to miss the Linux part! :P
I guess it could be a unity issue, I always assume that it's something that I've done wrong!
If you have a moment, could you throw that bit of code into a test mod and see if you get the same issue in Linux?

Link to comment
Share on other sites

3 minutes ago, katateochi said:

You off all people to miss the Linux part! :P
I guess it could be a unity issue, I always assume that it's something that I've done wrong!
If you have a moment, could you throw that bit of code into a test mod and see if you get the same issue in Linux?

Believe it or not, I don't run KSP on Linux :D

Link to comment
Share on other sites

In 1.3.x I had a little helper that I used to speed up development testing by jumping me from the main menu to the scene I needed to be at, but in 1.4.x it doesn't work, or rather it jumps to the right scene, but (ie in an editor) none of the assets are present and most buttons don't function.
This was the helper I used before

[KSPAddon(KSPAddon.Startup.MainMenu, true)]
public class DevTools : MonoBehaviour
{
    public void Start(){
        HighLogic.SaveFolder = "test_save";            
        GamePersistence.LoadGame("persistent", HighLogic.SaveFolder, true, false);
        EditorDriver.StartEditor(EditorFacility.SPH);            
    }
}

Any ideas how to load a specific scene in 1.4.x?

Link to comment
Share on other sites

@katateochi I wouldn't jump to any scene other than the Space Center scene, and I would also make sure that you delay loading from the main menu for a second or so (start a coroutine from the Start method with a yield for WaitForSeconds(1) before loading). Some things in KSP could be depending on a specific load order to work right.

I guess you could make a script that starts in the Main Menu, waits a second or so, then loads a save file to the Space Center scene, then load another script that waits another second, then go to the scene you want, it would only add a few seconds to the load time, but it would ensure that everything is loaded in the standard order.

Link to comment
Share on other sites

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...