Ejemplo n.º 1
0
 protected override void UICommChannel_OnPanelMessage(
     string panelName,
     string msgType,
     string[] msgParams)
 {
     if (this._numPlayersSpinner.TryPanelMessage(panelName, msgType, msgParams, PanelBinding.PanelMessageTargetFlags.Self | PanelBinding.PanelMessageTargetFlags.Recursive))
     {
         this._numPlayersSpinner.SetValue(Math.Max(0.0, Math.Min((double)this._maxPlayers, this._numPlayersSpinner.Value)));
     }
     else
     {
         if (this._strategicTurnLengthSlider.TryPanelMessage(panelName, msgType, msgParams, PanelBinding.PanelMessageTargetFlags.Self) || this._combatTurnLengthSlider.TryPanelMessage(panelName, msgType, msgParams, PanelBinding.PanelMessageTargetFlags.Self) || (this._economicEfficiencySlider.TryPanelMessage(panelName, msgType, msgParams, PanelBinding.PanelMessageTargetFlags.Self) || this._researchEfficiencySlider.TryPanelMessage(panelName, msgType, msgParams, PanelBinding.PanelMessageTargetFlags.Self)) || (this._planetResourcesSlider.TryPanelMessage(panelName, msgType, msgParams, PanelBinding.PanelMessageTargetFlags.Self) || this._planetSizeSlider.TryPanelMessage(panelName, msgType, msgParams, PanelBinding.PanelMessageTargetFlags.Self) || (this._initialTreasurySlider.TryPanelMessage(panelName, msgType, msgParams, PanelBinding.PanelMessageTargetFlags.Self) || this._initialSystemsSpinner.TryPanelMessage(panelName, msgType, msgParams, PanelBinding.PanelMessageTargetFlags.Self | PanelBinding.PanelMessageTargetFlags.Recursive))) || (this._initialTechnologiesSpinner.TryPanelMessage(panelName, msgType, msgParams, PanelBinding.PanelMessageTargetFlags.Self | PanelBinding.PanelMessageTargetFlags.Recursive) || this._randomEncounterFrequencySlider.TryPanelMessage(panelName, msgType, msgParams, PanelBinding.PanelMessageTargetFlags.Self) || this._grandMenaceSlider.TryPanelMessage(panelName, msgType, msgParams, PanelBinding.PanelMessageTargetFlags.Self)))
         {
             return;
         }
         if (msgType == "slider_value")
         {
             if (!(panelName == "gameModeSlider"))
             {
                 return;
             }
             this._modeSliderVal = int.Parse(msgParams[0]);
             this.SetGameMode(this._gameMode);
         }
         else if (msgType == "button_clicked")
         {
             if (panelName == "gameBackButton")
             {
                 this.GoBack();
             }
             else if (panelName == "gamePlayerSetupButton")
             {
                 this.App.GameSetup._mode        = this._tempGameSetup._mode;
                 this.App.GameSetup._modeValue   = this._tempGameSetup._modeValue;
                 this.App.GameSetup.StarMapFile  = this._tempGameSetup.StarMapFile;
                 this.App.GameSetup.ScenarioFile = this._tempGameSetup.ScenarioFile;
                 if (this.App.GameSetup.HasScenarioFile())
                 {
                     Scenario s = new Scenario();
                     ScenarioXmlUtility.LoadScenarioFromXml(this.App.GameSetup.ScenarioFile, ref s);
                     int index = 0;
                     foreach (Kerberos.Sots.Data.ScenarioFramework.Player playerStartCondition in s.PlayerStartConditions)
                     {
                         PlayerSetup player = this.App.GameSetup.Players[index];
                         player.EmpireName      = playerStartCondition.Name;
                         player.Avatar          = playerStartCondition.Avatar;
                         player.Badge           = playerStartCondition.Badge;
                         player.ShipColor       = playerStartCondition.ShipColor;
                         player.Faction         = playerStartCondition.Faction;
                         player.AI              = playerStartCondition.isAI;
                         player.Fixed           = true;
                         player.InitialColonies = playerStartCondition.Colonies.Count;
                         player.InitialTechs    = playerStartCondition.StartingTechs.Count;
                         player.InitialTreasury = (int)playerStartCondition.Treasury;
                         ++index;
                     }
                 }
                 this.UpdateData();
                 if (this.App.GameSetup.IsMultiplayer)
                 {
                     this.App.SwitchGameState(this.App.PreviousState, (object)LobbyEntranceState.Multiplayer);
                 }
                 else
                 {
                     this.App.SwitchGameState <StarMapLobbyState>((object)LobbyEntranceState.SinglePlayer);
                 }
             }
             else if (panelName == "victoryToggle")
             {
                 this._victoryConditionDialog = this.App.UI.CreateDialog((Dialog) new VictoryConditionDialog(this.App, "dialogVictoryCondition"), null);
             }
             else if (panelName == "gameMapsCheckbox")
             {
                 this.App.UI.SetChecked("gameMapsCheckbox", true);
                 this.App.UI.SetChecked("gameScenariosCheckbox", false);
                 this.App.UI.SetVisible("gameScenarioList", false);
                 this.App.UI.SetVisible("gameStarMapList", true);
                 this._tempGameSetup.ScenarioFile = string.Empty;
                 this._tempGameSetup.StarMapFile  = string.Empty;
                 if (this._starmapIdMap.Count > 0)
                 {
                     if (ScriptHost.AllowConsole && this._starmapIdMap.Any <KeyValuePair <int, Starmap.StarmapInfo> >((Func <KeyValuePair <int, Starmap.StarmapInfo>, bool>)(x => x.Value.FileName == "FIGHT.starmap")))
                     {
                         this.App.UI.SetSelection("gameStarMapList", this._starmapIdMap.FirstOrDefault <KeyValuePair <int, Starmap.StarmapInfo> >((Func <KeyValuePair <int, Starmap.StarmapInfo>, bool>)(x => x.Value.FileName == "FIGHT.starmap")).Key);
                     }
                     else
                     {
                         this.App.UI.SetSelection("gameStarMapList", this._starmapIdMap.Keys.First <int>());
                     }
                 }
                 else
                 {
                     this.App.UI.ClearSelection("gameStarMapList");
                 }
             }
             else if (!(panelName == "gameScenariosCheckbox"))
             {
                 ;
             }
         }
         else if (msgType == "checkbox_clicked")
         {
             foreach (Faction faction in this.App.AssetDatabase.Factions)
             {
                 if (panelName == GameSetupState.UIAvailableFactionCheckBox(faction))
                 {
                     if (int.Parse(msgParams[0]) != 0)
                     {
                         this.App.GameSetup.AvailablePlayerFeatures.TryAddFaction(faction);
                     }
                     else if (this.App.GameSetup.AvailablePlayerFeatures.Factions.Keys.Count <Faction>() >= 2)
                     {
                         this.App.GameSetup.AvailablePlayerFeatures.TryRemoveFaction(faction);
                     }
                     else
                     {
                         this.App.UI.SetChecked(GameSetupState.UIAvailableFactionCheckBox(faction), true);
                     }
                 }
             }
         }
         else if (msgType == "list_sel_changed")
         {
             if (!(panelName == "gameStarMapList") && !(panelName == "gameScenarioList"))
             {
                 return;
             }
             bool isMapFile = panelName == "gameStarMapList";
             if (msgParams.Length == 1)
             {
                 this.SelectStarMapOrScenario(new int?(int.Parse(msgParams[0])), isMapFile);
             }
             else
             {
                 this.SelectStarMapOrScenario(new int?(), false);
             }
             this.App.UI.SetEnabled("gamePlayerSetupButton", this._tempGameSetup.HasStarMapFile() || this._tempGameSetup.HasScenarioFile());
         }
         else
         {
             if (!(msgType == "dialog_closed") || !(panelName == this._victoryConditionDialog))
             {
                 return;
             }
             GameMode mode = (GameMode)int.Parse(msgParams[0]);
             if (mode == GameMode.LandGrab)
             {
                 this.App.UI.SetPropertyInt("gameModeSlider", "value", 67);
                 this._modeSliderVal = 67;
             }
             else
             {
                 this.App.UI.SetPropertyInt("gameModeSlider", "value", 100);
                 this._modeSliderVal = 100;
             }
             this.SetGameMode(mode);
         }
     }
 }
Ejemplo n.º 2
0
 private void SelectStarMapOrScenario(int?nullableId, bool isMapFile)
 {
     if (!nullableId.HasValue)
     {
         this._tempGameSetup.StarMapFile  = string.Empty;
         this._tempGameSetup.ScenarioFile = string.Empty;
         if (this._starmapPreview == null)
         {
             return;
         }
         this._starmapPreview.Dispose();
         this._starmapPreview = (StarMapPreview)null;
     }
     else
     {
         int    index = nullableId.Value;
         string fallbackTitle;
         string strId;
         if (isMapFile)
         {
             fallbackTitle = this._starmapIdMap[index].GetFallbackTitle();
             strId         = this._starmapIdMap[index].Description;
         }
         else
         {
             fallbackTitle = this._scenarioIdMap[index].GetFallbackTitle();
             strId         = string.Empty;
         }
         this.App.UI.SetPropertyString("mapLabel", "text", App.Localize(fallbackTitle));
         this.App.UI.SetText("mapsummary_Content", App.Localize(strId));
         if (isMapFile)
         {
             foreach (Faction faction in this.App.AssetDatabase.Factions)
             {
                 this.App.GameSetup.AvailablePlayerFeatures.TryAddFaction(faction);
                 if (faction.IsPlayable)
                 {
                     this.App.UI.SetChecked(GameSetupState.UIAvailableFactionCheckBox(faction), true);
                     this.App.UI.SetEnabled(GameSetupState.UIAvailableFactionCheckBox(faction), true);
                 }
             }
             this._numPlayersSpinner.SetEnabled(true);
             this._initialSystemsSpinner.SetEnabled(true);
             this._initialTechnologiesSpinner.SetEnabled(true);
             this._initialTreasurySlider.SetEnabled(true);
             this.App.UI.SetEnabled("victoryToggle", true);
             Starmap.StarmapInfo starmapId = this._starmapIdMap[index];
             this._tempGameSetup.StarMapFile  = starmapId.FileName;
             this._tempGameSetup.ScenarioFile = string.Empty;
             this._numPlayersSpinner.SetValue((double)starmapId.NumPlayers);
             this._maxPlayers = starmapId.NumPlayers;
         }
         else
         {
             Scenario.ScenarioInfo scenarioId = this._scenarioIdMap[index];
             this._tempGameSetup.ScenarioFile = scenarioId.FileName;
             this._tempGameSetup.StarMapFile  = scenarioId.StarmapInfo.FileName;
             this._numPlayersSpinner.SetValue((double)scenarioId.StarmapInfo.NumPlayers);
             Scenario s = new Scenario();
             ScenarioXmlUtility.LoadScenarioFromXml(scenarioId.FileName, ref s);
             foreach (Faction faction in this.App.AssetDatabase.Factions)
             {
                 this.App.GameSetup.AvailablePlayerFeatures.TryRemoveFaction(faction);
                 if (faction.IsPlayable)
                 {
                     this.App.UI.SetChecked(GameSetupState.UIAvailableFactionCheckBox(faction), false);
                     this.App.UI.SetEnabled(GameSetupState.UIAvailableFactionCheckBox(faction), false);
                 }
             }
             foreach (Kerberos.Sots.Data.ScenarioFramework.Player playerStartCondition in s.PlayerStartConditions)
             {
                 Faction faction = this.App.AssetDatabase.GetFaction(playerStartCondition.Faction);
                 this.App.GameSetup.AvailablePlayerFeatures.TryAddFaction(faction);
                 if (faction.IsPlayable)
                 {
                     this.App.UI.SetChecked(GameSetupState.UIAvailableFactionCheckBox(faction), true);
                 }
             }
             this._numPlayersSpinner.SetEnabled(false);
             this._initialSystemsSpinner.SetEnabled(false);
             this._initialTechnologiesSpinner.SetEnabled(false);
             this._initialTreasurySlider.SetEnabled(false);
             this.App.UI.SetEnabled("victoryToggle", false);
         }
         this.RecreateStarmapPreview();
     }
 }