Jump to content

Does clicking in the Difficulty settings send some GameEvents ?


Recommended Posts

  • Does checkboxes' clicking in the Difficulty settings send some GameEvents ?

I move some code (which doesn't need to be updated every tick) from LateUpdate() to the functions, called by events, and it almost works with OnGameSettingsApplied() and some flight-scene-events. 

But I noticed, what if you open difficulty settings while in the flight-scene, and then click some checkboxes, LateUpdate() on-the-fly take this new values, so I need GameEvents for this (something like OnGameSettingsChanges(), but it isn't there) or

  • how to limit flight-scene to take only saved settings, after OnGameSettingsApplied event (I am using HighLogic.CurrentGame.Parameters.CustomParams<modSettings>().setting_name, and they are taken on-the-fly)
Edited by flart
Link to comment
Share on other sites

I had have:

Spoiler

public void LateUpdate()
{
	//....
	switch (mode) {
		case FlightGlobals.SpeedDisplayModes.Surface:
			//....
			display.textTitle.fontSize = line1_fontsize;
			display.textSpeed.fontSize = line2_fontsize;
			display.textSpeed.alignment = TMPro.TextAlignmentOptions.Midline;
			display.textSpeed.color = new Color(0.0f, 1.0f, 0.0f, 1f);
			display.textTitle.color = new Color(0.0f, 1.0f, 0.0f, 1f);
		case FlightGlobals.SpeedDisplayModes.Orbit:
			//....
			if (HighLogic.CurrentGame.Parameters.CustomParams<SpeedUnitAnnexSettings>().setting_orbit_time){
				//...
				display.textTitle.fontSize = lines_fontsize;
				display.textSpeed.fontSize = lines_fontsize;
				display.textSpeed.alignment = TMPro.TextAlignmentOptions.MidlineLeft;
			}
			else {
				//....
				display.textTitle.fontSize = line1_fontsize;
				display.textSpeed.fontSize = line2_fontsize;
				display.textSpeed.alignment = TMPro.TextAlignmentOptions.Midline;
				display.textSpeed.color = new Color(0.0f, 1.0f, 0.0f, 1f);
				display.textTitle.color = new Color(0.0f, 1.0f, 0.0f, 1f);
			}
	}

 

 

I moved this code (which doesn't need to be updated every tick) from LateUpdate() to the functions, called by events:

Spoiler

public void Start()
{
	GameEvents.OnGameSettingsApplied.Add(OnGameSettingsApplied);
	GameEvents.onSetSpeedMode.Add(onSetSpeedMode);
}

public void OnGameSettingsApplied() 
{
	SetDisplayToDefault();
}


public void onSetSpeedMode(FlightGlobals.SpeedDisplayModes mode)
{
	switch (mode)
	{
		case FlightGlobals.SpeedDisplayModes.Surface:
		case FlightGlobals.SpeedDisplayModes.Target:
		{
			SetDisplayToDefault();
			break;
		}
		case FlightGlobals.SpeedDisplayModes.Orbit:
		{
			if (HighLogic.CurrentGame.Parameters.CustomParams<SpeedUnitAnnexSettings>().setting_orbit_time)
				SetDisplayToOrbitTime();
			else
				SetDisplayToDefault(); 
			break;
		}
	}
}



private void SetDisplayToOrbitTime() 
{
	display.textTitle.fontSize = lines_fontsize;
	display.textSpeed.fontSize = lines_fontsize;
	display.textSpeed.alignment = TMPro.TextAlignmentOptions.MidlineLeft;
}

private void SetDisplayToDefault() 
{
	display.textTitle.fontSize = line1_fontsize;
	display.textSpeed.fontSize = line2_fontsize;
	display.textSpeed.alignment = TMPro.TextAlignmentOptions.Midline;
	display.textSpeed.color = new Color(0.0f, 1.0f, 0.0f, 1f);
	display.textTitle.color = new Color(0.0f, 1.0f, 0.0f, 1f);
}


public void LateUpdate()
{
	//....
	switch (mode) {
		case FlightGlobals.SpeedDisplayModes.Surface:
			//every tick calculation
		case FlightGlobals.SpeedDisplayModes.Orbit:
			//every tick calculation
			if (HighLogic.CurrentGame.Parameters.CustomParams<SpeedUnitAnnexSettings>().setting_orbit_time){
				//every tick calculation
			}
			else {
				//every tick calculation
			}
	}

 

But I noticed, what if you open difficulty settings while in the flight-scene, and then click setting_orbit_time checkbox (without saving, setting dialog are opened), then LateUpdate() in the background take this new values, but moved code isn't run so I need 

  • GameEvents for this (something like OnGameSettingsChanges instead of OnGameSettingsApplied

or

  • new setting-value should not be used in the LateUpdate() until user click save in the setting menu. 
Edited by flart
Link to comment
Share on other sites

Ok, I can make 

SpeedUnitAnnexSettings local_settings;

public void Start()
{
	local_settings = HighLogic.CurrentGame.Parameters.CustomParams<SpeedUnitAnnexSettings>();
}

public void OnGameSettingsWritten()
{
     local_settings = HighLogic.CurrentGame.Parameters.CustomParams<SpeedUnitAnnexSettings>();
}

and then use local_settings field.
Should works.

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