Ejemplo n.º 1
0
        private void _limitationValueSpinner_ValueChanged(object sender, ValueChangedEventArgs e)
        {
            LimitationTreatyInfo editedTreaty = (LimitationTreatyInfo)this._editedTreaty;

            editedTreaty.LimitationAmount = (float)e.NewValue;
            this._app.UI.SetText("txtLimitationValue", editedTreaty.LimitationAmount.ToString());
        }
Ejemplo n.º 2
0
 private void SyncTreaties()
 {
     this._app.UI.ClearItems(TreatiesPopup.TreatyList);
     this._treaties = this._app.GameDatabase.GetTreatyInfos().Where <TreatyInfo>((Func <TreatyInfo, bool>)(x =>
     {
         if (x.ReceivingPlayerId == this._otherPlayer && x.InitiatingPlayerId == this._app.LocalPlayer.ID)
         {
             return(true);
         }
         if (x.ReceivingPlayerId == this._app.LocalPlayer.ID)
         {
             return(x.InitiatingPlayerId == this._otherPlayer);
         }
         return(false);
     })).ToList <TreatyInfo>();
     foreach (TreatyInfo treaty in this._treaties)
     {
         if (treaty.Type == TreatyType.Limitation)
         {
             LimitationTreatyInfo limitationTreatyInfo = (LimitationTreatyInfo)treaty;
             this._app.UI.AddItem(TreatiesPopup.TreatyList, string.Empty, treaty.ID, string.Empty);
             this._app.UI.SetText(this._app.UI.Path(this._app.UI.GetItemGlobalID(TreatiesPopup.TreatyList, string.Empty, treaty.ID, string.Empty), "lblHeader"), string.Format("{0}", (object)App.Localize(TreatyEditDialog.LimitationTreatyTypeLocMap[limitationTreatyInfo.LimitationType])));
         }
         else
         {
             this._app.UI.AddItem(TreatiesPopup.TreatyList, string.Empty, treaty.ID, string.Empty);
             this._app.UI.SetText(this._app.UI.Path(this._app.UI.GetItemGlobalID(TreatiesPopup.TreatyList, string.Empty, treaty.ID, string.Empty), "lblHeader"), App.Localize(TreatyEditDialog.TreatyTypeLocMap[treaty.Type]));
         }
     }
 }
Ejemplo n.º 3
0
        public override void Initialize()
        {
            foreach (KeyValuePair <TreatyType, string> treatyPanel in this._treatyPanelMap)
            {
                this._app.UI.SetVisible(treatyPanel.Value, false);
            }
            this._app.UI.SetVisible(this._treatyPanelMap[TreatyType.Limitation], true);
            PlayerInfo playerInfo = this._app.GameDatabase.GetPlayerInfo(this._treatyInfo.InitiatingPlayerId);

            this._app.UI.SetPropertyString(this.UI.Path(this.ID, "lblIncentives"), "text", App.Localize("@UI_TREATY_REQUEST_INCENTIVES"));
            new DiplomacyCard(this._app, playerInfo.ID, this.UI, "playerdiplocard1").Initialize();
            this._app.UI.ClearItems("lstIncentives");
            foreach (TreatyIncentiveInfo incentive in this._treatyInfo.Incentives)
            {
                this._app.UI.AddItem("lstIncentives", string.Empty, incentive.ID, string.Format("{0} {1}", (object)App.Localize(TreatyEditDialog.IncentiveTypeLocMap[incentive.Type]), (object)incentive.IncentiveValue));
            }
            switch (this._treatyInfo.Type)
            {
            case TreatyType.Armistice:
                this._app.UI.SetPropertyString(this.UI.Path(this.ID, "lblArmisticeTreatyDesc"), "text", string.Format(App.Localize("@UI_TREATY_REQUEST_ARMISTICE_DESC"), (object)App.Localize(this._diplomacyTypeLocMap[((ArmisticeTreatyInfo)this._treatyInfo).SuggestedDiplomacyState]), (object)playerInfo.Name));
                break;

            case TreatyType.Trade:
                this._app.UI.SetPropertyString(this.UI.Path(this.ID, "lblTradeTreatyDesc"), "text", string.Format(App.Localize("@UI_TREATY_REQUEST_TRADE_DESC"), (object)this._treatyInfo.Duration, (object)playerInfo.Name));
                break;

            case TreatyType.Limitation:
                LimitationTreatyInfo lti = (LimitationTreatyInfo)this._treatyInfo;
                this._app.UI.ClearItems("lstLimitationTreatyConsequences");
                foreach (TreatyConsequenceInfo consequence in lti.Consequences)
                {
                    this._app.UI.AddItem("lstLimitationTreatyConsequences", string.Empty, consequence.ID, string.Format("{0} {1}", (object)App.Localize(TreatyEditDialog.ConsequenceTypeLocMap[consequence.Type]), (object)consequence.ConsequenceValue));
                }
                string str;
                switch (lti.LimitationType)
                {
                case LimitationTreatyType.FleetSize:
                    this._app.UI.SetPropertyString(this.UI.Path(this.ID, "lblLimitationTreatyDesc"), "text", string.Format(App.Localize("@UI_TREATY_REQUEST_LIMITATION_FLEETSIZE"), (object)lti.Duration, (object)lti.LimitationAmount, (object)playerInfo.Name));
                    return;

                case LimitationTreatyType.ShipClass:
                    str = App.Localize(this._shipClassLocStringMap[(ShipClass)int.Parse(lti.LimitationGroup)]);
                    this._app.UI.SetPropertyString(this.UI.Path(this.ID, "lblLimitationTreatyDesc"), "text", string.Format(App.Localize("@UI_TREATY_REQUEST_LIMITATION_SHIPCLASS"), (object)lti.Duration, (object)lti.LimitationGroup, (object)lti.LimitationAmount, (object)playerInfo.Name));
                    return;

                case LimitationTreatyType.Weapon:
                    str = this._app.AssetDatabase.Weapons.First <LogicalWeapon>((Func <LogicalWeapon, bool>)(x => x.UniqueWeaponID == int.Parse(lti.LimitationGroup))).Name;
                    this._app.UI.SetPropertyString(this.UI.Path(this.ID, "lblLimitationTreatyDesc"), "text", string.Format(App.Localize("@UI_TREATY_REQUEST_LIMITATION_WEAPON"), (object)lti.Duration, (object)lti.LimitationGroup, (object)playerInfo.Name));
                    return;

                case LimitationTreatyType.ResearchTree:
                    string name1 = this._app.AssetDatabase.MasterTechTree.TechFamilies.First <TechFamily>((Func <TechFamily, bool>)(x => x.Id == lti.LimitationGroup)).Name;
                    this._app.UI.SetPropertyString(this.UI.Path(this.ID, "lblLimitationTreatyDesc"), "text", string.Format(App.Localize("@UI_TREATY_REQUEST_LIMITATION_RESEARCHTREE"), (object)lti.Duration, (object)name1, (object)playerInfo.Name));
                    return;

                case LimitationTreatyType.ResearchTech:
                    string name2 = this._app.AssetDatabase.MasterTechTree.Technologies.First <Tech>((Func <Tech, bool>)(x => x.Id == lti.LimitationGroup)).Name;
                    this._app.UI.SetPropertyString(this.UI.Path(this.ID, "lblLimitationTreatyDesc"), "text", string.Format(App.Localize("@UI_TREATY_REQUEST_LIMITATION_RESEARCHTECH"), (object)lti.Duration, (object)name2, (object)playerInfo.Name));
                    return;

                case LimitationTreatyType.EmpireSize:
                    this._app.UI.SetPropertyString(this.UI.Path(this.ID, "lblLimitationTreatyDesc"), "text", string.Format(App.Localize("@UI_TREATY_REQUEST_LIMITATION_EMPIRESIZE"), (object)lti.Duration, (object)lti.LimitationAmount, (object)playerInfo.Name));
                    return;

                case LimitationTreatyType.ForgeGemWorlds:
                    this._app.UI.SetPropertyString(this.UI.Path(this.ID, "lblLimitationTreatyDesc"), "text", string.Format(App.Localize("@UI_TREATY_REQUEST_LIMITATION_FORGEGEMWORLDS"), (object)lti.Duration, (object)lti.LimitationAmount, (object)playerInfo.Name));
                    return;

                case LimitationTreatyType.StationType:
                    str = App.Localize(this._stationTypeLocStringMap[(StationType)int.Parse(lti.LimitationGroup)]);
                    this._app.UI.SetPropertyString(this.UI.Path(this.ID, "lblLimitationTreatyDesc"), "text", string.Format(App.Localize("@UI_TREATY_REQUEST_LIMITATION_STATIONTYPE"), (object)lti.Duration, (object)lti.LimitationGroup, (object)lti.LimitationAmount, (object)playerInfo.Name));
                    return;

                default:
                    return;
                }
            }
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
 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);
     }
 }