protected override void OnPanelMessage(string panelId, string msgType, string[] msgParams) { if (this._durationSpinner.TryPanelMessage(panelId, msgType, msgParams, PanelBinding.PanelMessageTargetFlags.Self | PanelBinding.PanelMessageTargetFlags.Recursive) || this._limitationValueSpinner.TryPanelMessage(panelId, msgType, msgParams, PanelBinding.PanelMessageTargetFlags.Self | PanelBinding.PanelMessageTargetFlags.Recursive)) { return; } if (msgType == "list_sel_changed") { if (panelId == "lstTreatyType") { this._editedTreaty.Type = (TreatyType)int.Parse(msgParams[0]); this.SyncTreatyTypePanels(); this.SyncRDPCost(this._editedTreaty); } else if (panelId == "lstLimitationType") { LimitationTreatyInfo editedTreaty = (LimitationTreatyInfo)this._editedTreaty; editedTreaty.LimitationType = (LimitationTreatyType)int.Parse(msgParams[0]); if (TreatyEditDialog.EnableValueList.Contains(editedTreaty.LimitationType)) { this._limitationValueSpinner.SetValueDescriptor(TreatyEditDialog.LimitationTypeSpinnerDescriptors[editedTreaty.LimitationType]); editedTreaty.LimitationAmount = (float)this._limitationValueSpinner.Value; this._app.UI.SetPropertyString("txtLimitationValue", "text", editedTreaty.LimitationAmount.ToString()); } this.SyncLimitationGroup(editedTreaty.LimitationType); this._app.UI.ClearSelection("lstLimitationGroup"); this.SyncRDPCost((TreatyInfo)editedTreaty); } else if (panelId == "lstArmisticeType") { ArmisticeTreatyInfo editedTreaty = (ArmisticeTreatyInfo)this._editedTreaty; editedTreaty.SuggestedDiplomacyState = (DiplomacyState)int.Parse(msgParams[0]); this.SyncRDPCost((TreatyInfo)editedTreaty); } else if (panelId == "lstLimitationGroup") { if (int.Parse(msgParams[0]) == -1) { return; } LimitationTreatyInfo editedTreaty = (LimitationTreatyInfo)this._editedTreaty; switch (editedTreaty.LimitationType) { case LimitationTreatyType.ShipClass: editedTreaty.LimitationGroup = msgParams[0]; break; case LimitationTreatyType.Weapon: editedTreaty.LimitationGroup = msgParams[0]; break; case LimitationTreatyType.ResearchTree: editedTreaty.LimitationGroup = this._app.AssetDatabase.MasterTechTree.TechFamilies[int.Parse(msgParams[0])].Id; break; case LimitationTreatyType.ResearchTech: editedTreaty.LimitationGroup = msgParams[0]; break; case LimitationTreatyType.StationType: editedTreaty.LimitationGroup = msgParams[0]; break; } } else if (panelId == "lstConsequences") { this._selectedConsequence = string.IsNullOrEmpty(msgParams[0]) ? new int?() : new int?(int.Parse(msgParams[0])); } else if (panelId == "lstIncentives") { this._selectedIncentive = string.IsNullOrEmpty(msgParams[0]) ? new int?() : new int?(int.Parse(msgParams[0])); } } else if (msgType == "button_clicked") { if (panelId == "btnCancel") { this._app.UI.CloseDialog((Dialog)this, true); } if (panelId == "btnDone") { this._app.GameDatabase.SpendDiplomacyPoints(this._app.GameDatabase.GetPlayerInfo(this._editedTreaty.InitiatingPlayerId), this._app.GameDatabase.GetPlayerFactionID(this._editedTreaty.ReceivingPlayerId), this._app.Game.GetTreatyRdpCost(this._editedTreaty)); this._app.GameDatabase.DeleteTreatyInfo(this._editedTreaty.ID); this._app.GameDatabase.InsertTreaty(this._editedTreaty); this._app.UI.CloseDialog((Dialog)this, true); } else if (panelId == "btnRemoveConsequence") { if (this._selectedConsequence.HasValue) { this._editedTreaty.Consequences.RemoveAt(this._selectedConsequence.Value); this.SyncConsequences(); } } else if (panelId == "btnEditConsequence") { if (this._selectedConsequence.HasValue) { TreatyConsequenceInfo consequence = this._editedTreaty.Consequences[this._selectedConsequence.Value]; this._consequenceDialogId = this._app.UI.CreateDialog((Dialog) new ConsequenceEditDialog(this._app, ref consequence, this._receivingPlayer.PrimaryColor, "TreatyConsequencePopup"), null); } } else if (panelId == "btnAddConsequence") { TreatyConsequenceInfo tci = new TreatyConsequenceInfo(); tci.TreatyId = this._editedTreaty.ID; this._editedTreaty.Consequences.Add(tci); this._consequenceDialogId = this._app.UI.CreateDialog((Dialog) new ConsequenceEditDialog(this._app, ref tci, this._receivingPlayer.PrimaryColor, "TreatyConsequencePopup"), null); } else if (panelId == "btnRemoveIncentive") { if (this._selectedIncentive.HasValue) { this._editedTreaty.Incentives.RemoveAt(this._selectedIncentive.Value); this.SyncIncentives(); } } else if (panelId == "btnEditIncentive") { if (this._selectedIncentive.HasValue) { TreatyIncentiveInfo incentive = this._editedTreaty.Incentives[this._selectedIncentive.Value]; this._incentiveDialogId = this._app.UI.CreateDialog((Dialog) new IncentiveEditDialog(this._app, ref incentive, this._receivingPlayer.PrimaryColor, "TreatyConsequencePopup"), null); } } else if (panelId == "btnAddIncentive") { TreatyIncentiveInfo tci = new TreatyIncentiveInfo(); tci.TreatyId = this._editedTreaty.ID; this._editedTreaty.Incentives.Add(tci); this._incentiveDialogId = this._app.UI.CreateDialog((Dialog) new IncentiveEditDialog(this._app, ref tci, this._receivingPlayer.PrimaryColor, "TreatyConsequencePopup"), null); } } else if (msgType == "dialog_closed") { if (panelId == this._incentiveDialogId) { this.SyncIncentives(); } else if (panelId == this._consequenceDialogId) { this.SyncConsequences(); } } else if (msgType == "text_changed") { if (panelId == "txtDuration") { int result = 0; if (int.TryParse(msgParams[0], out result)) { this._editedTreaty.Duration = result; } } else if (panelId == "txtLimitationValue") { float result = 0.0f; if (float.TryParse(msgParams[0], out result)) { ((LimitationTreatyInfo)this._editedTreaty).LimitationAmount = result; } } } base.OnPanelMessage(panelId, msgType, msgParams); }
public void SyncTreatyTypePanels() { if (this._editedTreaty.Type == TreatyType.Armistice) { this._app.UI.SetVisible("pnlArmisticePanel", true); this._app.UI.SetVisible("pnlDurationPanel", false); int receivingPlayerId = this._editedTreaty.ReceivingPlayerId; int id = this._editedTreaty.ID; if (!typeof(ArmisticeTreatyInfo).IsAssignableFrom(this._editedTreaty.GetType())) { this._editedTreaty = (TreatyInfo) new ArmisticeTreatyInfo(); this._editedTreaty.ID = id; this._editedTreaty.InitiatingPlayerId = this._app.Game.LocalPlayer.ID; this._editedTreaty.ReceivingPlayerId = receivingPlayerId; this._editedTreaty.Type = TreatyType.Armistice; this._editedTreaty.StartingTurn = this._app.GameDatabase.GetTurnCount() + 1; } ArmisticeTreatyInfo editedTreaty = (ArmisticeTreatyInfo)this._editedTreaty; this._app.UI.SetEnabled("btnDone", editedTreaty.SuggestedDiplomacyState >= DiplomacyState.CEASE_FIRE); this._app.UI.SetSelection("lstArmisticeType", (int)editedTreaty.SuggestedDiplomacyState); } else { this._app.UI.SetVisible("pnlArmisticePanel", false); this._app.UI.SetVisible("pnlDurationPanel", true); if (this._durationSpinner != null) { this._durationSpinner.SetValue((double)this._editedTreaty.Duration); } this._app.UI.SetPropertyString("txtDuration", "text", this._editedTreaty.Duration.ToString()); bool flag = this._editedTreaty.Type == TreatyType.Limitation; this._app.UI.SetVisible("pnlLimitationPanel", flag); if (!flag) { return; } int receivingPlayerId = this._editedTreaty.ReceivingPlayerId; int id = this._editedTreaty.ID; if (!typeof(LimitationTreatyInfo).IsAssignableFrom(this._editedTreaty.GetType())) { this._editedTreaty = (TreatyInfo) new LimitationTreatyInfo(); this._editedTreaty.ID = id; this._editedTreaty.InitiatingPlayerId = this._app.Game.LocalPlayer.ID; this._editedTreaty.ReceivingPlayerId = receivingPlayerId; this._editedTreaty.Type = TreatyType.Limitation; this._editedTreaty.StartingTurn = this._app.GameDatabase.GetTurnCount() + 1; } LimitationTreatyInfo editedTreaty = (LimitationTreatyInfo)this._editedTreaty; this._app.UI.SetSelection("lstLimitationType", (int)editedTreaty.LimitationType); this._app.UI.SetEnabled("txtLimitationValue", TreatyEditDialog.EnableValueList.Contains(editedTreaty.LimitationType)); this._app.UI.SetEnabled("lstLimitationGroup", TreatyEditDialog.EnableGroupList.Contains(editedTreaty.LimitationType)); if (TreatyEditDialog.LimitationTypeSpinnerDescriptors.ContainsKey(editedTreaty.LimitationType)) { this._limitationValueSpinner.SetValue((double)editedTreaty.LimitationAmount); this._limitationValueSpinner.SetValueDescriptor(TreatyEditDialog.LimitationTypeSpinnerDescriptors[editedTreaty.LimitationType]); editedTreaty.LimitationAmount = (float)this._limitationValueSpinner.Value; this._app.UI.SetPropertyString("txtLimitationValue", "text", editedTreaty.LimitationAmount.ToString()); } this.SyncConsequences(); this.SyncLimitationGroup(editedTreaty.LimitationType); } }