Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Author Topic: 0.8.1a-RC8: setPaused() is probably not working  (Read 2068 times)

Iridescens

  • Lieutenant
  • **
  • Posts: 56
    • View Profile
0.8.1a-RC8: setPaused() is probably not working
« on: October 18, 2017, 05:40:06 PM »

Using
Code
if (option == OptionId.LEAVE) {
Global.getSector().setPaused(true);
dialog.dismiss();
return;
}
does not yield a game being paused after a dialog closing.
This worked fine in a 0.7.2a. Perhaps changes were made which are not reflected in API?
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: 0.8.1a-RC8: setPaused() is probably not working
« Reply #1 on: October 18, 2017, 06:01:45 PM »

It's likely that the logic for unpausing the game after closing a dialog changed - so the method is working, but the game then unpauses anyway.

Hmm - to do what you're looking to do, I'd suggest maybe adding a script that pauses on the next unpaused frame and then removes itself.
Logged

Iridescens

  • Lieutenant
  • **
  • Posts: 56
    • View Profile
Re: 0.8.1a-RC8: setPaused() is probably not working
« Reply #2 on: October 20, 2017, 06:57:31 PM »

Ok, tried to add this after invokation of dialog:
Code
Global.getSector().getCampaignUI().showInteractionDialog(new SomeDialog(), Global.getSector().getPlayerFleet());
Global.getSector().addTransientScript(new Es_GameSetPausePlugin());
with Es_GameSetPausePlugin() being
Spoiler
Code
public class Es_GameSetPausePlugin implements EveryFrameScript{
private static final Logger Log = Global.getLogger(Es_GameSetPausePlugin.class);

@Override
public boolean isDone() {
if(Global.getSector().isPaused()) {
Log.log(Level.INFO,"Es_GameSetPausePlugin in -isDone-Paused- state");
return true;
}

return false;

}

@Override
public boolean runWhilePaused() {
return true;
}

@Override
public void advance(float amount) {
Log.log(Level.INFO,"Es_GameSetPausePlugin in -advance- state");
if(!Global.getSector().isPaused()) {
Global.getSector().setPaused(true);
}
}
}
[close]
First of all, it doesn't produce -advance- state in log.
Secondly, it still does not pause the game, but correctly logs -isDone-Paused- when I pause it manually.

Where am I being dumb?
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: 0.8.1a-RC8: setPaused() is probably not working
« Reply #3 on: October 21, 2017, 01:39:57 PM »

Unless I'm missing something, isDone() for the script is going to return true right away (since showing the dialog will pause the game) and so advance() will never get called.
Logged

Iridescens

  • Lieutenant
  • **
  • Posts: 56
    • View Profile
Re: 0.8.1a-RC8: setPaused() is probably not working
« Reply #4 on: October 21, 2017, 05:41:29 PM »

That's a good point! Many thanks, Alex!

For all curious modders, the recipy is:
Spoiler
Code: java
import com.fs.starfarer.api.EveryFrameScript;
import com.fs.starfarer.api.Global;

public class GameSetPausePlugin implements EveryFrameScript{

@Override
public boolean isDone() {
if(Global.getSector().isPaused()) {
return true;
}
return false;

}

@Override
public boolean runWhilePaused() {
return false;
}

@Override
public void advance(float amount) {
if(!Global.getSector().isPaused()) {
Global.getSector().setPaused(true);
}
}
}
[close]
Which should be run after closing dialog as follows:
Code: java
dialog.dismiss();
Global.getSector().addTransientScript(new GameSetPausePlugin());

P.s. I've just noticed that community Version Checker is unpausing after dismissing the dialog. This could be helpful.
« Last Edit: October 21, 2017, 05:44:07 PM by Alex »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: 0.8.1a-RC8: setPaused() is probably not working
« Reply #5 on: October 21, 2017, 05:44:43 PM »

(Glad you got it sorted out! I took the liberty of editing your post to display the code better - you can do (bracket)code=java(bracket) to get the nicer formatting.)
« Last Edit: October 21, 2017, 05:46:48 PM by Alex »
Logged