private void RefreshProjects() { this._app.UI.ClearItems(this._app.UI.Path(this.ID, "specialList")); this.SyncRates(); this._rates.Clear(); List <SpecialProjectInfo> list = this._app.GameDatabase.GetSpecialProjectInfosByPlayerID(this._app.LocalPlayer.ID, true).Where <SpecialProjectInfo>((Func <SpecialProjectInfo, bool>)(x => x.Type == SpecialProjectType.Salvage)).ToList <SpecialProjectInfo>().OrderBy <SpecialProjectInfo, bool>((Func <SpecialProjectInfo, bool>)(x => x.Progress < 0)).ToList <SpecialProjectInfo>(); if ((double)list.Sum <SpecialProjectInfo>((Func <SpecialProjectInfo, float>)(x => x.Rate)) < 0.99) { SpecialProjectInfo specialProjectInfo = list.FirstOrDefault <SpecialProjectInfo>((Func <SpecialProjectInfo, bool>)(x => x.Progress >= 0)); if (specialProjectInfo != null) { specialProjectInfo.Rate = 1f; } } PlayerInfo playerInfo = this._app.GameDatabase.GetPlayerInfo(this._app.LocalPlayer.ID); this._researchPoints = this._app.Game.ConvertToResearchPoints(this._app.LocalPlayer.ID, Budget.GenerateBudget(this._app.Game, playerInfo, (IEnumerable <DesignInfo>)null, BudgetProjection.Actual).ResearchSpending.RequestedTotal); this._salvagePoints = (int)((double)this._researchPoints * (double)playerInfo.RateResearchSalvageResearch); foreach (SpecialProjectInfo specialProjectInfo in list) { this._app.UI.AddItem(this._app.UI.Path(this.ID, "specialList"), "", specialProjectInfo.ID, ""); string itemGlobalId = this._app.UI.GetItemGlobalID(this._app.UI.Path(this.ID, "specialList"), "", specialProjectInfo.ID, ""); this._app.UI.SetPropertyString(this._app.UI.Path(itemGlobalId, "projectName"), "text", specialProjectInfo.Name); this._app.UI.SetPropertyString(this._app.UI.Path(itemGlobalId, "description"), "text", GameSession.GetSpecialProjectDescription(specialProjectInfo.Type)); if (specialProjectInfo.Progress >= 0) { this._app.UI.SetVisible(this._app.UI.Path(itemGlobalId, "startButton"), false); this._app.UI.SetVisible(this._app.UI.Path(itemGlobalId, "cancelButton"), true); this._app.UI.SetVisible(this._app.UI.Path(itemGlobalId, "activeIndicator"), true); this._app.UI.SetVisible(this._app.UI.Path(itemGlobalId, "projectRate"), true); } else { this._app.UI.SetVisible(this._app.UI.Path(itemGlobalId, "startButton"), true); this._app.UI.SetVisible(this._app.UI.Path(itemGlobalId, "cancelButton"), false); this._app.UI.SetVisible(this._app.UI.Path(itemGlobalId, "activeIndicator"), false); this._app.UI.SetVisible(this._app.UI.Path(itemGlobalId, "projectRate"), false); } this._app.UI.SetPropertyString(this._app.UI.Path(itemGlobalId, "startButton"), "id", "startButton|" + specialProjectInfo.ID.ToString()); this._app.UI.SetPropertyString(this._app.UI.Path(itemGlobalId, "cancelButton"), "id", "cancelButton|" + specialProjectInfo.ID.ToString()); this._app.UI.SetSliderValue(this._app.UI.Path(itemGlobalId, "projectProgress"), (int)((double)specialProjectInfo.Progress / (double)specialProjectInfo.Cost * 100.0)); this._app.UI.SetPropertyString(this._app.UI.Path(itemGlobalId, "projectRate"), "id", "projectRate|" + specialProjectInfo.ID.ToString()); this._app.UI.SetPropertyString(this._app.UI.Path(itemGlobalId, "projectTurnCount"), "id", "projectTurnCount|" + specialProjectInfo.ID.ToString()); this._rates.Add(specialProjectInfo); } this.RefreshSliders(); this.UpdateResearchSliders(playerInfo, ""); }
protected override void OnPanelMessage(string panelName, string msgType, string[] msgParams) { if (msgType == "button_clicked") { if (panelName == "okButton") { this._app.UI.CloseDialog((Dialog)this, true); } else if (panelName.Contains("startButton")) { SpecialProjectInfo specialProjectInfo = this._app.GameDatabase.GetSpecialProjectInfo(int.Parse(panelName.Split('|')[1])); if (specialProjectInfo == null || specialProjectInfo.Progress != -1) { return; } this._contextProject = specialProjectInfo; this._confirmProjectChangeDialog = this._app.UI.CreateDialog((Dialog) new GenericQuestionDialog(this._app, App.Localize("@UI_SALVAGE_RESEARCH_START_TITLE"), App.Localize("@UI_SALVAGE_RESEARCH_START_DESC"), "dialogGenericQuestion"), null); } else { if (!panelName.Contains("cancelButton")) { return; } SpecialProjectInfo specialProjectInfo = this._app.GameDatabase.GetSpecialProjectInfo(int.Parse(panelName.Split('|')[1])); if (specialProjectInfo == null || specialProjectInfo.Progress <= -1) { return; } this._contextProject = specialProjectInfo; this._confirmProjectChangeDialog = this._app.UI.CreateDialog((Dialog) new GenericQuestionDialog(this._app, App.Localize("@UI_SALVAGE_RESEARCH_CANCEL_TITLE"), App.Localize("@UI_SALVAGE_RESEARCH_CANCEL_DESC"), "dialogGenericQuestion"), null); } } else if (msgType == "slider_value") { if (panelName.Contains("projectRate")) { this.SetRate(int.Parse(panelName.Split('|')[1]), (float)int.Parse(msgParams[0]) / 100f); } else { PlayerInfo playerInfo = this._app.GameDatabase.GetPlayerInfo(this._app.LocalPlayer.ID); if (panelName == SalvageProjectDialog.UIGovernmentResearchSlider) { float num = ((float)int.Parse(msgParams[0]) / 100f).Clamp(0.0f, 1f); playerInfo.RateGovernmentResearch = 1f - num; if (this._app.GameDatabase.GetSliderNotchSettingInfo(playerInfo.ID, UISlidertype.SecuritySlider) != null) { EmpireSummaryState.DistributeGovernmentSpending(this._app.Game, EmpireSummaryState.GovernmentSpendings.Security, (float)Math.Min((double)Budget.GenerateBudget(this._app.Game, playerInfo, (IEnumerable <DesignInfo>)null, BudgetProjection.Pessimistic).RequiredSecurity / 100.0, 1.0), playerInfo); } else { this._app.GameDatabase.UpdatePlayerSliders(this._app.Game, playerInfo); } this._researchPoints = this._app.Game.ConvertToResearchPoints(this._app.LocalPlayer.ID, Budget.GenerateBudget(this._app.Game, playerInfo, (IEnumerable <DesignInfo>)null, BudgetProjection.Actual).ResearchSpending.RequestedTotal); this._salvagePoints = (int)((double)this._researchPoints * (double)playerInfo.RateResearchSalvageResearch); Budget budget = Budget.GenerateBudget(this._app.Game, playerInfo, (IEnumerable <DesignInfo>)null, BudgetProjection.Pessimistic); this._piechart.SetSlices(budget); this._behindPiechart.SetSlices(budget); this._app.UI.ShakeViolently("piechartD"); } else if (panelName == SalvageProjectDialog.UICurrentProjectSlider) { EmpireSummaryState.DistibuteResearchSpending(this._app.Game, this._app.GameDatabase, EmpireSummaryState.ResearchSpendings.CurrentProject, (float)int.Parse(msgParams[0]) / 100f, playerInfo); this._salvagePoints = (int)((double)this._researchPoints * (double)playerInfo.RateResearchSalvageResearch); } else if (panelName == SalvageProjectDialog.UISpecialProjectSlider) { EmpireSummaryState.DistibuteResearchSpending(this._app.Game, this._app.GameDatabase, EmpireSummaryState.ResearchSpendings.SpecialProject, (float)int.Parse(msgParams[0]) / 100f, playerInfo); this._salvagePoints = (int)((double)this._researchPoints * (double)playerInfo.RateResearchSalvageResearch); } else if (panelName == SalvageProjectDialog.UISalvageResearchSlider) { EmpireSummaryState.DistibuteResearchSpending(this._app.Game, this._app.GameDatabase, EmpireSummaryState.ResearchSpendings.SalvageResearch, (float)int.Parse(msgParams[0]) / 100f, playerInfo); this._salvagePoints = (int)((double)this._researchPoints * (double)playerInfo.RateResearchSalvageResearch); } this.UpdateResearchSliders(playerInfo, panelName); this.RefreshSliders(); } } else { if (!(msgType == "dialog_closed") || !(panelName == this._confirmProjectChangeDialog)) { return; } if (bool.Parse(msgParams[0]) && this._contextProject != null) { if (this._contextProject.Progress == -1) { this._app.GameDatabase.UpdateSpecialProjectProgress(this._contextProject.ID, 0); this.RefreshProjects(); } else { this._app.GameDatabase.RemoveSpecialProject(this._contextProject.ID); this.RefreshProjects(); } } this._contextProject = (SpecialProjectInfo)null; this._confirmProjectChangeDialog = ""; } }
private void SetRate(int id, float value) { SpecialProjectInfo specialProjectInfo1 = this._rates.FirstOrDefault <SpecialProjectInfo>((Func <SpecialProjectInfo, bool>)(x => x.ID == id)); List <SpecialProjectInfo> list = this._rates.Where <SpecialProjectInfo>((Func <SpecialProjectInfo, bool>)(x => x.Progress >= 0)).ToList <SpecialProjectInfo>(); if (specialProjectInfo1 != null) { float num1 = specialProjectInfo1.Rate - value; float num2 = 0.0f; float num3 = this._rates.Sum <SpecialProjectInfo>((Func <SpecialProjectInfo, float>)(x => x.Rate)); if (this._rates.Count > 1 && (double)num3 >= 0.999) { int num4 = 100; do { --num4; foreach (SpecialProjectInfo specialProjectInfo2 in list) { if (specialProjectInfo2.ID != id) { float num5 = Math.Abs(num1 / (float)(this._rates.Count - 1)); if ((double)num1 < 0.0) { if ((double)specialProjectInfo2.Rate - (double)num5 > 0.0) { specialProjectInfo2.Rate -= num5; } else { num5 = specialProjectInfo2.Rate; specialProjectInfo2.Rate = 0.0f; } num2 += num5; if ((double)num2 >= (double)Math.Abs(num1)) { specialProjectInfo2.Rate += num2 - Math.Abs(num1); num2 = Math.Abs(num1); break; } } else { if ((double)specialProjectInfo2.Rate + (double)num5 < 1.0) { specialProjectInfo2.Rate += num5; } else { num5 = 1f - specialProjectInfo2.Rate; specialProjectInfo2.Rate = 1f; } num2 += num5; if ((double)num2 >= (double)num1) { specialProjectInfo2.Rate -= num2 - num1; num2 = num1; break; } } } } }while ((double)num2 < (double)Math.Abs(num1) - 9.99999974737875E-05 && num4 > 0); specialProjectInfo1.Rate -= num1; } else { specialProjectInfo1.Rate = 1f; } } this.RefreshSliders(); }