001package com.fs.starfarer.api.impl.campaign.eventide;
002
003import java.util.Map;
004
005import com.fs.starfarer.api.campaign.CustomUIPanelPlugin;
006import com.fs.starfarer.api.campaign.CustomVisualDialogDelegate;
007import com.fs.starfarer.api.campaign.InteractionDialogAPI;
008import com.fs.starfarer.api.campaign.rules.MemKeys;
009import com.fs.starfarer.api.campaign.rules.MemoryAPI;
010import com.fs.starfarer.api.impl.campaign.rulecmd.FireBest;
011import com.fs.starfarer.api.ui.CustomPanelAPI;
012
013public class DuelDialogDelegate implements CustomVisualDialogDelegate {
014        protected DialogCallbacks callbacks;
015        protected float endDelay = 2f;
016        protected boolean finished = false;
017        
018        protected String musicId;
019        protected DuelPanel duelPanel;
020        protected InteractionDialogAPI dialog;
021        protected Map<String, MemoryAPI> memoryMap;
022        protected boolean tutorialMode;
023        
024        
025        public DuelDialogDelegate(@Deprecated String musicId, DuelPanel duelPanel, InteractionDialogAPI dialog,
026                                                          Map<String, MemoryAPI> memoryMap, boolean tutorialMode) {
027                this.musicId = musicId;
028                this.duelPanel = duelPanel;
029                this.dialog = dialog;
030                this.memoryMap = memoryMap;
031                this.tutorialMode = tutorialMode;
032        }
033        public CustomUIPanelPlugin getCustomPanelPlugin() {
034                return duelPanel;
035        }
036        public void init(CustomPanelAPI panel, DialogCallbacks callbacks) {
037                this.callbacks = callbacks;
038                callbacks.getPanelFader().setDurationOut(2f);
039                duelPanel.init(panel, callbacks, dialog);
040//              if (musicId != null && !musicId.isEmpty()) {
041//                      Global.getSoundPlayer().setSuspendDefaultMusicPlayback(true);
042//                      Global.getSoundPlayer().playCustomMusic(1, 1, musicId);
043//              } else {
044//                      Global.getSoundPlayer().pauseMusic();
045//                      Global.getSoundPlayer().setSuspendDefaultMusicPlayback(true);
046//              }
047        }
048        public float getNoiseAlpha() {
049                return 0;
050        }
051        public void advance(float amount) {
052                if (!finished && 
053                                (duelPanel.getPlayer().health <= 0 || duelPanel.getEnemy().health <= 0)) {
054                        endDelay -= amount;
055                        if (endDelay <= 0f) {
056                                callbacks.getPanelFader().fadeOut();
057                                if (callbacks.getPanelFader().isFadedOut()) {
058                                        callbacks.dismissDialog();
059                                        finished = true;
060                                }
061                        }
062                }
063        }
064        public void reportDismissed(int option) {
065//              Global.getSoundPlayer().setSuspendDefaultMusicPlayback(false);
066//              Global.getSoundPlayer().restartCurrentMusic();
067                
068                if (memoryMap != null) { // null when called from the test dialog
069                        if (!tutorialMode) {
070                                if (duelPanel.getPlayer().health > 0) {
071                                        memoryMap.get(MemKeys.LOCAL).set("$soe_playerWonDuel", true, 0);
072                                } else {
073                                        memoryMap.get(MemKeys.LOCAL).set("$soe_playerLostDuel", true, 0);
074                                }
075                                FireBest.fire(null, dialog, memoryMap, "SOEDuelFinished");
076                        } else {
077                                FireBest.fire(null, dialog, memoryMap, "SOETutorialFinished");
078                        }
079                }
080        }
081}
082