11package org.lazywizard.console.overlay.v2.panels
22
33import com.fs.graphics.util.Fader
4+ import com.fs.starfarer.api.EveryFrameScript
45import com.fs.starfarer.api.GameState
56import com.fs.starfarer.api.Global
67import com.fs.starfarer.api.campaign.BaseCustomUIPanelPlugin
78import com.fs.starfarer.api.campaign.InteractionDialogAPI
89import com.fs.starfarer.api.campaign.InteractionDialogPlugin
910import com.fs.starfarer.api.campaign.rules.MemoryAPI
1011import com.fs.starfarer.api.combat.EngagementResultAPI
12+ import com.fs.starfarer.api.impl.MusicPlayerPluginImpl
13+ import com.fs.starfarer.api.impl.campaign.ids.Factions
1114import com.fs.starfarer.api.input.InputEventAPI
1215import com.fs.starfarer.api.ui.CustomPanelAPI
1316import com.fs.starfarer.api.ui.TooltipMakerAPI
@@ -35,6 +38,7 @@ import org.lazywizard.console.overlay.v2.elements.ConsoleTextfield
3538import org.lazywizard.console.overlay.v2.font.ConsoleFont
3639import org.lazywizard.console.overlay.v2.misc.ReflectionUtils
3740import org.lazywizard.console.overlay.v2.misc.clearChildren
41+ import org.lazywizard.console.overlay.v2.misc.getChildrenCopy
3842import org.lazywizard.console.overlay.v2.misc.getParent
3943import org.lazywizard.console.overlay.v2.settings.ConsoleV2Settings
4044import org.lazywizard.lazylib.JSONUtils
@@ -141,7 +145,7 @@ class ConsoleOverlayPanel(private val context: CommandContext) : BaseCustomUIPan
141145
142146 var requiresRecreation = false
143147
144- var placeHolderDialog: InteractionDialogAPI ? = null
148+ var placeHolderDialog: UIPanelAPI ? = null
145149
146150 var compileScope = CoroutineScope (Dispatchers .Default )
147151 var compileJob: Job ? = null
@@ -165,11 +169,32 @@ class ConsoleOverlayPanel(private val context: CommandContext) : BaseCustomUIPan
165169
166170 instance = this
167171
172+ if (Global .getCurrentState() == GameState .COMBAT ) {
173+ wasPaused = Global .getCombatEngine().isPaused
174+ // Global.getCombatEngine().viewport.isExternalControl = true //Prevent moving screen with dragging
175+ Global .getCombatEngine().isPaused = true
176+ }
177+
178+ if (Global .getCurrentState() == GameState .CAMPAIGN ) {
179+ wasPaused = Global .getSector().isPaused
180+ Global .getSector().isPaused = true ;
181+ }
182+
168183 // Open a dialog to prevent input from most other mods
169184 if (context.isInCampaign) {
170185 if (! Global .getSector().campaignUI.isShowingDialog) {
171- Global .getSector().campaignUI.showInteractionDialog(PlaceholderDialog (), Global .getSector().playerFleet)
172- placeHolderDialog = Global .getSector().campaignUI.currentInteractionDialog
186+ var ui = Global .getSector().campaignUI
187+
188+ // Use message dialog instead of InteractionDialog, as it doesnt hide campaign UI and doesnt mess with pause behaviour
189+ ui.showMessageDialog(" " )
190+ val screenPanel = ReflectionUtils .get(" screenPanel" , ui) as UIPanelAPI
191+ placeHolderDialog = screenPanel.getChildrenCopy().find { ReflectionUtils .hasMethodOfName(" getOptionMap" , it) } as ? UIPanelAPI
192+ if (placeHolderDialog != null ) {
193+ ReflectionUtils .invoke(" setOpacity" , placeHolderDialog!! , 0f )
194+ ReflectionUtils .invoke(" setBackgroundDimAmount" , placeHolderDialog!! , 0f )
195+ ReflectionUtils .invoke(" setAbsorbOutsideEvents" , placeHolderDialog!! , false )
196+ ReflectionUtils .invoke(" makeOptionInstant" , placeHolderDialog!! , 0f )
197+ }
173198 }
174199 }
175200
@@ -186,18 +211,6 @@ class ConsoleOverlayPanel(private val context: CommandContext) : BaseCustomUIPan
186211 var state = AppDriver .getInstance().currentState
187212 var screenPanel = ReflectionUtils .invoke(" getScreenPanel" , state) as UIPanelAPI
188213
189- if (Global .getCurrentState() == GameState .COMBAT ) {
190- wasPaused = Global .getCombatEngine().isPaused
191- // Global.getCombatEngine().viewport.isExternalControl = true //Prevent moving screen with dragging
192- Global .getCombatEngine().isPaused = true
193- }
194-
195- if (Global .getCurrentState() == GameState .CAMPAIGN ) {
196- wasPaused = Global .getSector().isPaused
197- Global .getSector().isPaused = true ;
198- }
199-
200-
201214
202215 parent = Global .getSettings().createCustom(screenPanel.position.width, screenPanel.position.height, null )
203216 screenPanel.addComponent(parent)
@@ -1292,7 +1305,13 @@ class ConsoleOverlayPanel(private val context: CommandContext) : BaseCustomUIPan
12921305
12931306 compileScope.cancel()
12941307
1295- var state = AppDriver .getInstance().currentState
1308+ /* placeHolderDialog?.dismiss()
1309+ placeHolderDialog = null*/
1310+
1311+ if (placeHolderDialog != null ) {
1312+ ReflectionUtils .invoke(" dismiss" , placeHolderDialog!! , 0 )
1313+ placeHolderDialog = null
1314+ }
12961315
12971316 if (Global .getCurrentState() == GameState .COMBAT ) {
12981317 if (! wasPaused) Global .getCombatEngine().isPaused = false
@@ -1301,12 +1320,9 @@ class ConsoleOverlayPanel(private val context: CommandContext) : BaseCustomUIPan
13011320 }
13021321
13031322 if (Global .getCurrentState() == GameState .CAMPAIGN ) {
1304- if ( ! wasPaused) Global .getSector().isPaused = false ;
1323+ Global .getSector().isPaused = wasPaused ;
13051324 }
13061325
1307- placeHolderDialog?.dismiss()
1308- placeHolderDialog = null
1309-
13101326 instance = null
13111327 parent.getParent()?.removeComponent(parent)
13121328 }
@@ -1353,47 +1369,4 @@ class ConsoleOverlayPanel(private val context: CommandContext) : BaseCustomUIPan
13531369 val percent = DecimalFormat .getPercentInstance().format(used / Math .max(max, committed).toDouble())
13541370 " $percent (${asString(used)} /${asString(Math .max(max, committed))} )"
13551371 }
1356-
1357- class PlaceholderDialog () : InteractionDialogPlugin {
1358-
1359- var dialog: InteractionDialogAPI ? = null
1360-
1361- override fun init (dialog : InteractionDialogAPI ? ) {
1362- this .dialog = dialog
1363-
1364- dialog!! .promptText = " Test"
1365- /* if (dialog is UIPanelAPI) {
1366- dialog.opacity = 0f
1367- //var fader =ReflectionUtils.invoke("getFader", dialog) as Fader
1368- }*/
1369- }
1370-
1371- override fun optionSelected (optionText : String? , optionData : Any? ) {
1372-
1373- }
1374-
1375- override fun optionMousedOver (optionText : String? , optionData : Any? ) {
1376-
1377- }
1378-
1379- override fun advance (amount : Float ) {
1380- // ReflectionUtils.invoke("setOpacity", dialog!!, 0f)
1381- var fader = ReflectionUtils .invoke(" getFader" , dialog!! .visualPanel) as Fader
1382- fader.brightness = 0f
1383- }
1384-
1385- override fun backFromEngagement (battleResult : EngagementResultAPI ? ) {
1386-
1387- }
1388-
1389- override fun getContext (): Any? {
1390- return null
1391- }
1392-
1393- override fun getMemoryMap (): MutableMap <String , MemoryAPI > {
1394- return hashMapOf()
1395- }
1396-
1397- }
1398-
13991372}
0 commit comments