Fractal Softworks Forum

Please login or register.

Login with username, password and session length

Author Topic: Removing selected intel still leaves a reference to it in the save file  (Read 384 times)

Jaghaimo

  • Admiral
  • *****
  • Posts: 661
    • View Profile

Affects: save compatibility, mod uninstallation
Non-critical: has workaround

IntelUI keeps track of currently opened intel, e.g.:

<selectedIntel cl="stelnet.board.contact.SebestyenContactIntel" z="173229" ii="true" tt="-55465585688000">

When I remove all intel of given class (here, SebestyenContactIntel) during beforeGameSave() hook, the save file still has the reference to it (the above) if it was the currently selected intel.

To fix it in the save, I have to open intel UI after the first save, and (even without clicking) close and save again. Alternatively, select a different (not one that will be deleted during save) intel in the UI prior to saving.

Is there a call I can make to force-flush selected intel?
« Last Edit: June 02, 2022, 07:31:09 AM by Jaghaimo »
Logged

Jaghaimo

  • Admiral
  • *****
  • Posts: 661
    • View Profile

Ugh, did the dirty workaround since Alex confirmed there's no way to set it right now in https://fractalsoftworks.com/forum/index.php?topic=5061.msg366694#msg366694. For those interested, call `resetIntelUi` twice (once before removing your potentially selected intel, and once after).

Code
    /*
     * WARNING! Do not call this from `onNewGame()` or `onLoadGame(bool isNewGame)` when `isNewGame` is `true`.
     * while campaign UI is not null it is not fully initialized and `showCoreUITab()` will crash. Still, no point in resetting
     * UI on NEW GAME, right? Riiight...
     */
    public void resetIntelUi() {
        CampaignUIAPI campaignUi = Global.getSector().getCampaignUI();
        if (campaignUi == null) {/* can be null if it's an auto-save after new game has started */
            return;
        }
        campaignUi.showCoreUITab(CoreUITabId.INTEL, null);/* show intel ui, select nothing on it */
        sendKey(KeyEvent.VK_ESCAPE);/* close intel ui by faking esc key, intel ui will still flicker momentarily */
    }

    private void sendKey(int key) {
        try {
            Robot robot = new Robot();
            robot.keyPress(key);
            robot.keyRelease(key);
        } catch (AWTException exception) {
            log.warn("Something went wrong sending a key!", exception);
        }
    }
« Last Edit: June 21, 2022, 02:24:03 AM by Jaghaimo »
Logged