private void CreateMessagePageMenuControls() { this.assignBuildingWorkersButton = this.CreateMenuButton("AssignBuildingWorkersButton", () => { HumanResource.AssignBuildingWorkersForTaiwuVillage(); this.ShowMessage(showLastPage: true); }, Path.Combine(Path.Combine(Main.resBasePath, "Texture"), $"ButtonIcon_Majordomo_AssignBuildingWorkers.png"), TaiwuCommon.SetColor(TaiwuCommon.COLOR_WHITE, "重新指派工作")); }
/// <summary> /// 指派工作人员 /// </summary> public void AssignBuildingWorkers() { float compositeWorkIndex = HumanResource.GetCompositeWorkIndex(this.partId, this.placeId); MajordomoWindow.instance.AppendMessage(this.currDate, Message.IMPORTANCE_NORMAL, TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_BLUE, "开始指派工作人员") + " - " + TaiwuCommon.SetColor(TaiwuCommon.COLOR_DARK_BROWN, "综合工作指数") + ": " + TaiwuCommon.SetColor(TaiwuCommon.COLOR_WHITE, compositeWorkIndex.ToString())); Original.RemoveWorkersFromBuildings(this.partId, this.placeId, this.excludedBuildings, this.excludedWorkers); MajordomoWindow.instance.AppendMessage(this.currDate, Message.IMPORTANCE_LOWEST, TaiwuCommon.SetColor(TaiwuCommon.COLOR_DARK_GRAY, "开始第一轮指派……")); this.AssignBuildingWorkers_PrepareData(); this.AssignBedroomWorkers(); MajordomoWindow.instance.AppendMessage(this.currDate, Message.IMPORTANCE_LOWEST, TaiwuCommon.SetColor(TaiwuCommon.COLOR_DARK_GRAY, "开始第二轮指派……")); // 指派完厢房后,重新计算 this.AssignBuildingWorkers_PrepareData(); this.AssignLeftBuildings(); Original.UpdateAllBuildings(this.partId, this.placeId); compositeWorkIndex = HumanResource.GetCompositeWorkIndex(this.partId, this.placeId); MajordomoWindow.instance.AppendMessage(this.currDate, Message.IMPORTANCE_NORMAL, TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_BLUE, "结束指派工作人员") + " - " + TaiwuCommon.SetColor(TaiwuCommon.COLOR_DARK_BROWN, "综合工作指数") + ": " + TaiwuCommon.SetColor(TaiwuCommon.COLOR_WHITE, compositeWorkIndex.ToString())); MajordomoWindow.instance.SetCompositeWorkIndex(this.currDate, compositeWorkIndex); }
private static string GetHarvestedItemsDetails() { string details = ""; if (AutoHarvest.harvestedItems.Count == 0) { return(details); } foreach (var items in AutoHarvest.harvestedItems.Reverse()) { int quality = items.Key; foreach (var item in items.Value) { int itemId = item.Key; int quantity = item.Value; string name = DateFile.instance.GetItemDate(itemId, 0, otherMassage: false); string coloredName = TaiwuCommon.SetColor(TaiwuCommon.COLOR_LOWEST_LEVEL + quality - 1, name); string coloredQuntity = TaiwuCommon.SetColor(TaiwuCommon.COLOR_WHITE, quantity.ToString()); details += $"{coloredName} × {coloredQuntity}、"; } } details = details.Substring(0, details.Length - 1) + "。"; return(details); }
private static string GetHarvestedResourcesDetails(ref int earnedMoney) { string details = ""; earnedMoney = 0; if (AutoHarvest.harvestedResources.Count == 0) { return(details); } foreach (var entry in AutoHarvest.harvestedResources) { int resourceIndex = entry.Key; int quantity = entry.Value; string name = DateFile.instance.resourceDate[resourceIndex][1]; details += TaiwuCommon.SetColor(TaiwuCommon.COLOR_YELLOW, name) + "\u00A0" + TaiwuCommon.SetColor(TaiwuCommon.COLOR_WHITE, quantity.ToString()) + "、"; if (resourceIndex == ResourceMaintainer.RES_ID_MONEY) { earnedMoney = quantity; } } details = details.Substring(0, details.Length - 1) + "。"; return(details); }
private static void UpdateShoppingRecord() { string text = ""; if (ResourceMaintainer.spentMoney > 0) { text += "花费" + TaiwuCommon.SetColor(TaiwuCommon.COLOR_YELLOW, "银钱") + "\u00A0" + TaiwuCommon.SetColor(TaiwuCommon.COLOR_WHITE, ResourceMaintainer.spentMoney.ToString()) + "\u00A0,购入了"; foreach (var entry in ResourceMaintainer.boughtResources) { int resourceId = entry.Key; int nResources = entry.Value; string name = DateFile.instance.resourceDate[resourceId][1]; text += TaiwuCommon.SetColor(TaiwuCommon.COLOR_YELLOW, name) + "\u00A0" + TaiwuCommon.SetColor(TaiwuCommon.COLOR_WHITE, nResources.ToString()) + "、"; } text = text.Substring(0, text.Length - 1) + "。\n"; } ResourceMaintainer.shoppingRecord = text; if (!string.IsNullOrEmpty(text)) { string recordingMessage = "管家" + text.Replace("\n", ""); MajordomoWindow.instance.AppendMessage(new TaiwuDate(), Message.IMPORTANCE_HIGH, recordingMessage); } }
// 因为每时每刻的资源数量都可能变化,因此要显示月初的资源警示,就必须缓存住 public static void UpdateResourceWarning() { string text = ""; foreach (var entry in ResourceMaintainer.GetResourcesInfo()) { var resourceId = entry.Key; var resourceInfo = entry.Value; if (resourceInfo.current < -resourceInfo.consumed * Main.settings.resMinHolding) { string name = DateFile.instance.resourceDate[(int)resourceId][1]; text += TaiwuCommon.SetColor(TaiwuCommon.COLOR_YELLOW, name) + "、"; } } if (text.Length > 0) { text = "以下资源库存不足:" + text.Substring(0, text.Length - 1) + "。\n需要尽快补充,否则将导致建筑损坏。\n"; text = TaiwuCommon.SetColor(TaiwuCommon.COLOR_RED, text); } ResourceMaintainer.resourceWarning = text; if (!string.IsNullOrEmpty(text)) { string recordingMessage = text.Replace("\n", ""); MajordomoWindow.instance.AppendMessage(new TaiwuDate(), Message.IMPORTANCE_HIGHEST, recordingMessage); } }
/// <summary> /// 记录收获详情文本(以及当月收获银钱) /// </summary> private static void RecordHarvestDetails() { var currDate = new TaiwuDate(); int earnedMoney = 0; string details = GetHarvestedResourcesDetails(ref earnedMoney); if (!string.IsNullOrEmpty(details)) { MajordomoWindow.instance.AppendMessage(currDate, Message.IMPORTANCE_HIGH, TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, "本月收获资源") + ":" + details); } MajordomoWindow.instance.SetEarnedMoney(currDate, earnedMoney); details = GetHarvestedItemsDetails(); if (!string.IsNullOrEmpty(details)) { MajordomoWindow.instance.AppendMessage(currDate, Message.IMPORTANCE_HIGH, TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, "本月收获物品") + ":" + details); } details = GetHarvestedActorsDetails(); if (!string.IsNullOrEmpty(details)) { MajordomoWindow.instance.AppendMessage(currDate, Message.IMPORTANCE_HIGH, TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, "本月接纳新村民") + ":" + details); } }
private static string GetHarvestedActorsSummary() { string summary = ""; if (AutoHarvest.harvestedActors.Count == 0) { return(summary); } int numDisplayedActors = 0; foreach (var actorId in AutoHarvest.harvestedActors) { string name = DateFile.instance.GetActorName(actorId); string coloredName = TaiwuCommon.SetColor(TaiwuCommon.COLOR_DARK_BROWN, name); summary += coloredName + "、"; ++numDisplayedActors; if (numDisplayedActors >= MAX_DISPLAYED_ACTORS) { break; } } summary = summary.Substring(0, summary.Length - 1) + "等\u00A0" + AutoHarvest.harvestedActors.Count + "\u00A0位村民。\n"; return(summary); }
/// <summary> /// 由于过早的月份的消息会被删除,故只显示最近的数个月的消息 /// </summary> private void UpdateMessage() { int baseDateIndex = Mathf.Max(this.history.Count - MajordomoWindow.MESSAGE_SHELF_LIFE, 0); var orderedDates = this.history.Keys.OrderByDescending(date => date) .Take(MajordomoWindow.MESSAGE_SHELF_LIFE).Reverse().ToList(); if (this.sortedDateIndex >= baseDateIndex && this.sortedDateIndex < this.history.Count) { var date = orderedDates[this.sortedDateIndex - baseDateIndex]; var record = this.history[date]; var messages = record.messages .Where(message => message.importance >= Main.settings.messageImportanceThreshold) .Select(message => { var content = message.content.Length > MESSAGE_MAX_LENGTH ? message.content.Substring(0, MESSAGE_MAX_LENGTH) + TaiwuCommon.SetColor(TaiwuCommon.COLOR_DARK_GRAY, "……") : message.content; return(TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, "·") + " " + content); }) .ToList(); this.CreateMessageContentItems(messages); } else { this.CreateMessageContentItems(new List <string>()); } this.textMessagePage.text = $"{this.sortedDateIndex - baseDateIndex + 1} / {orderedDates.Count}"; }
public string ToString() { return(TaiwuCommon.SetColor(TaiwuCommon.COLOR_DARK_BROWN, string.Format("第 {0} 年 {1} 月", TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_BROWN, this.year.ToString()), TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_BROWN, (this.GetMonthIndex() + 1).ToString())))); }
/// <summary> /// 由于过早的月份的消息会被删除,故只显示最近的数个月的消息 /// </summary> /// <param name="showLastPage"></param> private void ShowMessage(bool showLastPage = false) { if (showLastPage) { this.dateIndex = this.history.Count - 1; } int baseDateIndex = Mathf.Max(this.history.Count - MESSAGE_SHELF_LIFE, 0); var orderedDates = this.history.Keys.OrderByDescending(date => date).Take(MESSAGE_SHELF_LIFE).Reverse().ToList(); if (this.dateIndex >= baseDateIndex && this.dateIndex < this.history.Count) { var date = orderedDates[this.dateIndex - baseDateIndex]; var record = this.history[date]; var messages = record.messages .Where(message => message.importance >= Main.settings.messageImportanceThreshold) .Select(message => TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, "·") + " " + message.content) .ToList(); this.CreateMessageContentItems(messages); } else { this.CreateMessageContentItems(new List <string>()); } this.textMessagePage.text = $"{this.dateIndex - baseDateIndex + 1} / {orderedDates.Count}"; }
public static void LogBuildingAndWorker(BuildingWorkInfo info, int selectedWorkerId, int partId, int placeId, TaiwuDate currDate, Dictionary <int, Dictionary <int, int> > workerAttrs, bool suppressNoWorkerWarnning) { var building = DateFile.instance.homeBuildingsDate[partId][placeId][info.buildingIndex]; int baseBuildingId = building[0]; int buildingLevel = building[1]; var baseBuilding = DateFile.instance.basehomePlaceDate[baseBuildingId]; string buildingName = baseBuilding[0]; string attrName = Output.GetRequiredAttrName(info.requiredAttrId); string logText = string.Format("{0}:{1} ({2}) {3} [{4}, {5}] - ", TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, Common.ToFullWidth(info.priority.ToString("F0").PadLeft(4))), TaiwuCommon.SetColor(TaiwuCommon.COLOR_YELLOW, Common.ToFullWidth(buildingName.PadRight(5))), TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, Common.ToFullWidth(buildingLevel.ToString().PadLeft(2))), TaiwuCommon.SetColor(TaiwuCommon.COLOR_RICE_WHITE, Common.ToFullWidth(attrName.PadRight(2))), TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, Common.ToFullWidth(info.halfWorkingAttrValue.ToString().PadLeft(3))), TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, Common.ToFullWidth(info.fullWorkingAttrValue.ToString().PadLeft(3)))); if (selectedWorkerId >= 0) { string workerName = DateFile.instance.GetActorName(selectedWorkerId); int attrValue = info.requiredAttrId != 0 ? workerAttrs[selectedWorkerId][info.requiredAttrId] : -1; int mood = int.Parse(DateFile.instance.GetActorDate(selectedWorkerId, 4, false)); int favor = DateFile.instance.GetActorFavor(false, DateFile.instance.MianActorID(), selectedWorkerId, getLevel: true); // 这里的工作效率并不一定等于最终工作效率,因为可能还有厢房未分配 int workEffectiveness = info.requiredAttrId != 0 ? Original.GetWorkEffectiveness(partId, placeId, info.buildingIndex, selectedWorkerId) : -1; string workEffectivenessStr = workEffectiveness >= 0 ? workEffectiveness / 2 + "%" : "N/A"; MajordomoWindow.instance.AppendMessage(currDate, Message.IMPORTANCE_LOW, logText + string.Format( "{0} 资质: {1} 心情: {2} 好感: {3} 工作效率: {4}", TaiwuCommon.SetColor(TaiwuCommon.COLOR_YELLOW, Common.ToFullWidth(workerName.PadRight(5))), TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, Common.ToFullWidth(attrValue.ToString().PadLeft(3))), TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, Common.ToFullWidth(mood.ToString().PadLeft(4))), TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, Common.ToFullWidth(favor.ToString().PadLeft(2))), TaiwuCommon.SetColor(TaiwuCommon.COLOR_WHITE, Common.ToFullWidth(workEffectivenessStr.PadLeft(4))))); } else { if (suppressNoWorkerWarnning) { MajordomoWindow.instance.AppendMessage(currDate, Message.IMPORTANCE_LOW, logText + TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, "无合适人选")); } else { MajordomoWindow.instance.AppendMessage(currDate, Message.IMPORTANCE_HIGH, logText + TaiwuCommon.SetColor(TaiwuCommon.COLOR_RED, "无合适人选")); } } }
/// <summary> /// 指派完厢房之后,继续指派其他建筑 /// /// 其实本轮指派开始时仍有可能包含厢房,本轮临近结束时也仍有可能尚未指派厢房。 /// 本轮最后厢房指派,不考虑是否达到心情好感阈值,只要还有人就往里放。 /// 上次分配后还有厢房剩下的原因:人太少,辅助性厢房装不满;心情都挺好,一般厢房装不满。 /// 本次分配后还有厢房剩下的原因:人太少。 /// /// 建筑类型优先级因子中的厢房因子依然不能控制此处的厢房指派优先级,所有厢房在最后阶段指派。 /// </summary> private void AssignLeftBuildings() { MajordomoWindow.instance.AppendMessage(this.currDate, Message.IMPORTANCE_LOWEST, TaiwuCommon.SetColor(TaiwuCommon.COLOR_DARK_GRAY, "开始指派主要建筑……")); var sortedBuildings = this.buildings.OrderByDescending(entry => entry.Value.priority).Select(entry => entry.Value); foreach (var info in sortedBuildings) { if (this.excludedBuildings.Contains(info.buildingIndex)) { continue; } if (info.IsBedroom()) { continue; } int selectedWorkerId = this.SelectBuildingWorker(info.buildingIndex, info.requiredAttrId); if (selectedWorkerId >= 0) { Original.SetBuildingWorker(this.partId, this.placeId, info.buildingIndex, selectedWorkerId); } Output.LogBuildingAndWorker(info, selectedWorkerId, this.partId, this.placeId, this.currDate, this.workerAttrs, suppressNoWorkerWarnning: false); } // 最后指派尚未指派的厢房 MajordomoWindow.instance.AppendMessage(this.currDate, Message.IMPORTANCE_LOWEST, TaiwuCommon.SetColor(TaiwuCommon.COLOR_DARK_GRAY, "开始指派尚未指派的厢房……")); sortedBuildings = this.buildings.OrderByDescending(entry => entry.Value.priority).Select(entry => entry.Value); foreach (var info in sortedBuildings) { if (this.excludedBuildings.Contains(info.buildingIndex)) { continue; } if (!info.IsBedroom()) { continue; } int selectedWorkerId = this.SelectLeftBedroomWorker(info.buildingIndex); if (selectedWorkerId >= 0) { Original.SetBuildingWorker(this.partId, this.placeId, info.buildingIndex, selectedWorkerId); } Output.LogBuildingAndWorker(info, selectedWorkerId, this.partId, this.placeId, this.currDate, this.workerAttrs, suppressNoWorkerWarnning: false); } }
public static void LogAuxiliaryBedroomAndWorker(int bedroomIndex, List <BuildingWorkInfo> relatedBuildings, int priority, int selectedWorkerId, int partId, int placeId, TaiwuDate currDate, Dictionary <int, Dictionary <int, int> > workerAttrs) { var building = DateFile.instance.homeBuildingsDate[partId][placeId][bedroomIndex]; int baseBuildingId = building[0]; int buildingLevel = building[1]; var baseBuilding = DateFile.instance.basehomePlaceDate[baseBuildingId]; string buildingName = baseBuilding[0]; var attrNames = new List <string>(); foreach (var info in relatedBuildings) { string attrName = Common.ToFullWidth(Output.GetRequiredAttrName(info.requiredAttrId).PadRight(2)); attrNames.Add(TaiwuCommon.SetColor(TaiwuCommon.COLOR_RICE_WHITE, attrName)); } string logText = string.Format("{0}:{1} ({2}) [{3}] - ", TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, Common.ToFullWidth(priority.ToString().PadLeft(4))), TaiwuCommon.SetColor(TaiwuCommon.COLOR_YELLOW, Common.ToFullWidth(buildingName.PadRight(5))), TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, Common.ToFullWidth(buildingLevel.ToString().PadLeft(2))), string.Join(", ", attrNames.ToArray())); if (selectedWorkerId >= 0) { string workerName = DateFile.instance.GetActorName(selectedWorkerId); var attrValues = new List <string>(); foreach (var info in relatedBuildings) { string attrValue = Common.ToFullWidth(workerAttrs[selectedWorkerId][info.requiredAttrId].ToString().PadLeft(3)); attrValues.Add(TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, attrValue)); } int mood = int.Parse(DateFile.instance.GetActorDate(selectedWorkerId, 4, addValue: false)); int favor = DateFile.instance.GetActorFavor(false, DateFile.instance.MianActorID(), selectedWorkerId, getLevel: true); MajordomoWindow.instance.AppendMessage(currDate, Message.IMPORTANCE_LOW, logText + string.Format( "{0} 资质: [{1}] 心情: {2} 好感: {3}", TaiwuCommon.SetColor(TaiwuCommon.COLOR_YELLOW, Common.ToFullWidth(workerName.PadRight(5))), string.Join(", ", attrValues.ToArray()), TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, Common.ToFullWidth(mood.ToString().PadLeft(4))), TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, Common.ToFullWidth(favor.ToString().PadLeft(2))))); } else { MajordomoWindow.instance.AppendMessage(currDate, Message.IMPORTANCE_HIGH, logText + TaiwuCommon.SetColor(TaiwuCommon.COLOR_RED, "无合适人选")); } }
/// <summary> /// 获取当前综合工作指数 /// </summary> /// <returns></returns> private string GetCurrentCompositeWorkIndex() { string text; if (this.history.Count > 0) { var newestDate = this.history.Keys.Max(date => date); text = this.history[newestDate].compositeWorkIndex.ToString("F0"); } else { text = "???"; } return(TaiwuCommon.SetColor(TaiwuCommon.COLOR_DARK_BROWN, text)); }
/// <summary> /// 计算汇总统计信息 /// /// 计算过去一年内金钱收入等时,数据不足时会进行估算,至少有三个月数据才计算。 /// 如果数据中间有空缺月份,则计算跨度会大于一年。 /// </summary> private string[] GetSummaryStatsTexts() { const int MIN_CALCULATING_MONTHS = 3; const int N_EXPECTED_MONTHS = 12; string avgCompositeHealth, avgWorkMotivation, avgWorkEffectiveness, earnedMoneyOfLastYear, gdpOfLastYear; if (this.history.Count > 0) { var newestDate = this.history.Keys.Max(date => date); avgCompositeHealth = (this.history[newestDate].workerStats.avgCompositeHealth * 100).ToString("F2"); avgWorkMotivation = (this.history[newestDate].workerStats.avgWorkMotivation * 100).ToString("F2"); avgWorkEffectiveness = (this.history[newestDate].workingStats.avgWorkEffectiveness * 100).ToString("F2"); } else { avgCompositeHealth = "???"; avgWorkMotivation = "???"; avgWorkEffectiveness = "???"; } if (this.history.Count >= MIN_CALCULATING_MONTHS) { var datesWithin = this.history.OrderByDescending(entry => entry.Key).Take(N_EXPECTED_MONTHS); var earnedMoneyList = datesWithin.Select(entry => entry.Value.earningStats.earnedMoney); float earnedMoneyOfLastYear_ = (float)earnedMoneyList.Sum() / earnedMoneyList.Count() * N_EXPECTED_MONTHS; earnedMoneyOfLastYear = earnedMoneyOfLastYear_.ToString("F0"); var gdpList = datesWithin.Select(entry => entry.Value.earningStats.gdp); float gdpOfLastYear_ = (float)gdpList.Sum() / gdpList.Count() * N_EXPECTED_MONTHS; gdpOfLastYear = gdpOfLastYear_.ToString("F0"); } else { earnedMoneyOfLastYear = "???"; gdpOfLastYear = "???"; } return(new string[] { "平均综合健康: " + TaiwuCommon.SetColor(TaiwuCommon.COLOR_WHITE, avgCompositeHealth) + " %", "平均工作动力: " + TaiwuCommon.SetColor(TaiwuCommon.COLOR_WHITE, avgWorkMotivation) + " %", "平均工作效率: " + TaiwuCommon.SetColor(TaiwuCommon.COLOR_WHITE, avgWorkEffectiveness) + " %", "一年内银钱收入: " + TaiwuCommon.SetColor(TaiwuCommon.COLOR_YELLOW, earnedMoneyOfLastYear), "一年内生产总值: " + TaiwuCommon.SetColor(TaiwuCommon.COLOR_YELLOW, gdpOfLastYear), }); }
private static string GetHarvestedActorsDetails() { string details = ""; if (AutoHarvest.harvestedActors.Count == 0) { return(details); } foreach (var actorId in AutoHarvest.harvestedActors) { string name = DateFile.instance.GetActorName(actorId); string coloredName = TaiwuCommon.SetColor(TaiwuCommon.COLOR_DARK_BROWN, name); details += coloredName + "、"; } details = details.Substring(0, details.Length - 1) + "。"; return(details); }
/// <summary> /// 计算过去一年内金钱收入 /// 数据不足时会进行估算,至少有三个月数据才计算 /// 如果数据中间有空缺月份,则计算跨度会大于一年 /// </summary> /// <returns></returns> private string GetEarnedMoneyOfLastYear() { const int MIN_CALCULATING_MONTHS = 3; const int N_EXPECTED_MONTHS = 12; string text; if (this.history.Count >= MIN_CALCULATING_MONTHS) { var earnedMoneyList = this.history.OrderByDescending(entry => entry.Key).Take(N_EXPECTED_MONTHS) .Select(entry => entry.Value.earnedMoney); float earnedMoneyOfLastYear = earnedMoneyList.Sum() / earnedMoneyList.Count() * N_EXPECTED_MONTHS; text = earnedMoneyOfLastYear.ToString("F0"); } else { text = "???"; } return(TaiwuCommon.SetColor(TaiwuCommon.COLOR_YELLOW, text)); }
private static string GetHarvestedResourcesSummary() { string summary = ""; if (AutoHarvest.harvestedResources.Count == 0) { return(summary); } foreach (var entry in AutoHarvest.harvestedResources) { int resourceIndex = entry.Key; int quantity = entry.Value; string name = DateFile.instance.resourceDate[resourceIndex][1]; summary += TaiwuCommon.SetColor(TaiwuCommon.COLOR_YELLOW, name) + "\u00A0" + TaiwuCommon.SetColor(TaiwuCommon.COLOR_WHITE, quantity.ToString()) + "、"; } summary = summary.Substring(0, summary.Length - 1) + "。\n"; return(summary); }
private static string GetHarvestedItemsSummary() { string summary = ""; if (AutoHarvest.harvestedItems.Count == 0) { return(summary); } int numDisplayedItems = 0; foreach (var items in AutoHarvest.harvestedItems.Reverse()) { int quality = items.Key; foreach (var item in items.Value) { int itemId = item.Key; int quantity = item.Value; string name = DateFile.instance.GetItemDate(itemId, 0, otherMassage: false); string coloredName = TaiwuCommon.SetColor(TaiwuCommon.COLOR_LOWEST_LEVEL + quality - 1, name); summary += coloredName + "、"; ++numDisplayedItems; if (numDisplayedItems >= MAX_DISPLAYED_ITEMS) { break; } } if (numDisplayedItems >= MAX_DISPLAYED_ITEMS) { break; } } summary = summary.Substring(0, summary.Length - 1) + "等\u00A0" + AutoHarvest.numharvestedItems + "\u00A0件物品。\n"; return(summary); }
private static string GetHarvestedResourcesDetails(ref EarningStats stats) { string details = ""; if (AutoHarvest.harvestedResources.Count == 0) { return(details); } foreach (var entry in AutoHarvest.harvestedResources) { int resourceIndex = entry.Key; int quantity = entry.Value; string name = DateFile.instance.resourceDate[resourceIndex][1]; details += TaiwuCommon.SetColor(TaiwuCommon.COLOR_YELLOW, name) + "\u00A0" + TaiwuCommon.SetColor(TaiwuCommon.COLOR_WHITE, quantity.ToString()) + "、"; switch (resourceIndex) { case ResourceMaintainer.RES_ID_MONEY: stats.earnedMoney += quantity; stats.gdp += quantity; break; case ResourceMaintainer.RES_ID_FAME: stats.earnedFame += quantity; stats.gdp += Mathf.RoundToInt(quantity * ResourceMaintainer.EXCHANGE_RATE_FAME); break; default: stats.gdp += Mathf.RoundToInt(quantity * ResourceMaintainer.EXCHANGE_RATE_DEFAULT); break; } } details = details.Substring(0, details.Length - 1) + "。"; return(details); }
/// <summary> /// 计算指定地区的工作人员统计信息 /// </summary> /// <param name="partId"></param> /// <param name="placeId"></param> /// <returns></returns> public static WorkerStats GetWorkerStats(int partId, int placeId) { int mainActorId = DateFile.instance.MianActorID(); List <int> workerIds = Original.GetWorkerIds(partId, placeId); var stats = new WorkerStats(); foreach (int workerId in workerIds) { stats.avgHealthInjury += 1f - TaiwuCommon.GetInjuryRate(workerId); stats.avgHealthCirculating += 1f - TaiwuCommon.GetCirculatingBlockingRate(workerId); stats.avgHealthPoison += 1f - TaiwuCommon.GetPoisoningRate(workerId); stats.avgHealthLifespan += 1f - TaiwuCommon.GetLifespanDamageRate(workerId); int mood = int.Parse(DateFile.instance.GetActorDate(workerId, 4, false)); int favor = DateFile.instance.GetActorFavor(false, mainActorId, workerId); int favorLevel = DateFile.instance.GetActorFavor(false, mainActorId, workerId, getLevel: true); int scaledFavor = Original.GetScaledFavor(favorLevel); scaledFavor = Original.AdjustScaledFavorWithMood(scaledFavor, mood); stats.avgMood += mood; stats.avgFriendliness += favor; stats.avgWorkMotivation += Mathf.Max(scaledFavor, 0) / 100f; } if (workerIds.Count > 0) { stats.nWorkers = workerIds.Count; stats.avgHealthInjury /= workerIds.Count; stats.avgHealthCirculating /= workerIds.Count; stats.avgHealthPoison /= workerIds.Count; stats.avgHealthLifespan /= workerIds.Count; stats.avgCompositeHealth = (stats.avgHealthInjury + stats.avgHealthCirculating + stats.avgHealthPoison + stats.avgHealthLifespan) / 4; stats.avgMood /= workerIds.Count; stats.avgFriendliness /= workerIds.Count; stats.avgWorkMotivation /= workerIds.Count; } return(stats); }
private GameObject CreateMenuButton(string name, UnityEngine.Events.UnityAction callback, string iconPath, string label) { // clone & modify button if (!HomeSystem.instance.studyActor) { throw new Exception("HomeSystem.instance.studyActor is null"); } var studySkillButton = Common.GetChild(HomeSystem.instance.studyActor, "StudySkill,0"); if (!studySkillButton) { throw new Exception("Failed to get child 'StudySkill,0' from HomeSystem.instance.studyActor"); } var goMenuButton = UnityEngine.Object.Instantiate(studySkillButton, this.menu.transform); goMenuButton.SetActive(true); goMenuButton.name = name; goMenuButton.tag = "Untagged"; var button = goMenuButton.AddComponent <Button>(); button.onClick.AddListener(callback); goMenuButton.AddComponent <PointerClick>(); // modify button background var buttonBack = Common.GetChild(goMenuButton, "StudyEffectBack"); if (!buttonBack) { throw new Exception("Failed to get child 'StudyEffectBack' from 'StudySkill,0'"); } buttonBack.name = "MajordomoMenuButtonBack"; var image = buttonBack.GetComponent <Image>(); image.color = MajordomoWindow.MENU_BTN_BG_COLOR_UNSELECTED; var rectTransform = buttonBack.GetComponent <RectTransform>(); rectTransform.anchorMin = new Vector2(0, 0); rectTransform.anchorMax = new Vector2(1, 0); rectTransform.offsetMin = new Vector2(0, 0); rectTransform.offsetMax = new Vector2(0, 30); // modify button icon var buttonIcon = Common.GetChild(goMenuButton, "StudySkillIcon,0"); if (!buttonIcon) { throw new Exception("Failed to get child 'StudySkillIcon,0' from 'StudySkill,0'"); } buttonIcon.name = "MajordomoMenuButtonIcon"; rectTransform = buttonIcon.GetComponent <RectTransform>(); rectTransform.anchorMin = new Vector2(0, 1); rectTransform.anchorMax = new Vector2(1, 1); rectTransform.offsetMin = new Vector2(25, -80); rectTransform.offsetMax = new Vector2(-25, -20); var buttonIconImage = buttonIcon.GetComponent <Image>(); buttonIconImage.sprite = ResourceLoader.CreateSpriteFromImage(iconPath); if (!buttonIconImage.sprite) { throw new Exception($"Failed to create sprite: {iconPath}"); } // modify button text var buttonText = Common.GetChild(goMenuButton, "StudyEffectText"); if (!buttonText) { throw new Exception("Failed to get child 'StudyEffectText' from 'StudySkill,0'"); } buttonText.name = "MajordomoMenuButtonText"; rectTransform = buttonText.GetComponent <RectTransform>(); rectTransform.anchorMin = new Vector2(0, 0); rectTransform.anchorMax = new Vector2(1, 0); rectTransform.offsetMin = new Vector2(0, 0); rectTransform.offsetMax = new Vector2(0, 30); var text = buttonText.GetComponent <Text>(); if (!text) { throw new Exception("Failed to get Text component from 'StudyEffectText'"); } text.text = label; text.color = MajordomoWindow.MENU_BTN_COLOR_UNSELECTED; TaiwuCommon.SetFont(text); Common.RemoveComponent <SetFont>(buttonText); return(goMenuButton); }
private void CreateWindow() { // clone & modify main window if (!QuquBox.instance.ququBoxWindow) { throw new Exception("QuquBox.instance.ququBoxWindow is null"); } this.window = UnityEngine.Object.Instantiate( QuquBox.instance.ququBoxWindow, QuquBox.instance.ququBoxWindow.transform.parent); this.window.SetActive(true); this.window.name = "MajordomoWindow"; Common.RemoveComponent <QuquBox>(this.window); Common.RemoveChildren(this.window, new List <string> { "ChooseItemMask", "ItemsBack" }); // modify panel container this.panelContainer = Common.GetChild(this.window, "QuquBoxHolder"); if (!this.panelContainer) { throw new Exception("Failed to get child 'QuquBoxHolder' from QuquBox.instance.ququBoxWindow"); } this.panelContainer.name = "MajordomoPanelContainer"; // clone & modify menu this.menu = UnityEngine.Object.Instantiate(this.panelContainer, this.window.transform); this.menu.SetActive(true); this.menu.name = "MajordomoMenu"; Common.RemoveChildren(this.menu); // modify panel container Common.RemoveComponent <GridLayoutGroup>(this.panelContainer); Common.RemoveComponent <Image>(this.panelContainer); Common.RemoveComponent <CanvasRenderer>(this.panelContainer); Common.RemoveChildren(this.panelContainer); // resize panel container & menu var rectTransform = this.panelContainer.GetComponent <RectTransform>(); float width = rectTransform.offsetMax.x - rectTransform.offsetMin.x; float panelContainerWidth = width * 0.9f; float menuWidth = width - panelContainerWidth; rectTransform.offsetMin = new Vector2(rectTransform.offsetMin.x + menuWidth, rectTransform.offsetMin.y); rectTransform = this.menu.GetComponent <RectTransform>(); rectTransform.offsetMax = new Vector2(rectTransform.offsetMax.x - panelContainerWidth, rectTransform.offsetMax.y); // set menu layout var gridLayoutGroup = Common.RemoveComponent <GridLayoutGroup>(this.menu, recreate: true); gridLayoutGroup.padding = new RectOffset(20, 20, 20, 20); gridLayoutGroup.cellSize = new Vector2(110, 120); gridLayoutGroup.spacing = new Vector2(20, 20); gridLayoutGroup.startAxis = GridLayoutGroup.Axis.Vertical; gridLayoutGroup.childAlignment = TextAnchor.UpperCenter; // modify close button var goCloseButton = Common.GetChild(this.window, "CloseQuquBoxButton"); if (!goCloseButton) { throw new Exception("Failed to get child 'CloseQuquBoxButton' from QuquBox.instance.ququBoxWindow"); } goCloseButton.name = "MajordomoCloseButton"; var closeButton = Common.RemoveComponent <Button>(goCloseButton, recreate: true); closeButton.onClick.AddListener(() => this.Close()); var escWinComponent = Common.RemoveComponent <EscWinComponent>(goCloseButton, recreate: true); escWinComponent.escEvent = new EscWinComponent.EscCompEvent(); escWinComponent.escEvent.AddListener(() => this.Close()); // modify summary bar this.summaryBar = Common.GetChild(this.window, "AllQuquLevelBack"); if (!this.summaryBar) { throw new Exception("Failed to get child 'AllQuquLevelBack' from QuquBox.instance.ququBoxWindow"); } this.summaryBar.name = "MajordomoSummary"; var horizontalLayoutGroup = this.summaryBar.AddComponent <HorizontalLayoutGroup>(); horizontalLayoutGroup.padding = new RectOffset(20, 20, 0, 0); var summaryItem = Common.GetChild(this.summaryBar, "AllQuquLevelText"); if (!summaryItem) { throw new Exception("Failed to get child 'AllQuquLevelText' from 'AllQuquLevelBack'"); } summaryItem.name = "MajordomoSummaryItem"; var textSummary = summaryItem.GetComponent <Text>(); if (!textSummary) { throw new Exception("Failed to get Text component from 'AllQuquLevelText'"); } textSummary.color = MajordomoWindow.TEXT_COLOR_DEFAULT; TaiwuCommon.SetFont(textSummary); Common.RemoveComponent <SetFont>(summaryItem); for (int i = 1; i < N_SUMMARY_ITEMS; ++i) { var currSummaryItem = UnityEngine.Object.Instantiate(summaryItem, this.summaryBar.transform); currSummaryItem.SetActive(true); currSummaryItem.name = "MajordomoSummaryItem"; Common.RemoveComponent <SetFont>(currSummaryItem); } }
private GameObject CreateButton(string name, string label, UnityEngine.Events.UnityAction callback, GameObject parent) { // clone & modify button // 此函数的触发条件就是 BuildingWindow.instance 存在 var studySkillButton = Common.GetChild(BuildingWindow.instance.studyActor, "StudySkill,0"); if (!studySkillButton) { throw new Exception("Failed to get child 'StudySkill,0' from HomeSystem.instance.studyActor"); } var goButton = UnityEngine.Object.Instantiate(studySkillButton, parent.transform); goButton.SetActive(true); goButton.name = name; goButton.tag = "Untagged"; var button = goButton.AddComponent <Button>(); button.onClick.AddListener(callback); goButton.AddComponent <PointerClick>(); Common.RemoveChildren(goButton, new List <string> { "StudySkillIcon,0" }); // modify button background var buttonBack = Common.GetChild(goButton, "StudyEffectBack"); if (!buttonBack) { throw new Exception("Failed to get child 'StudyEffectBack' from 'StudySkill,0'"); } buttonBack.name = "ButtonBack"; var image = buttonBack.GetComponent <Image>(); image.color = PanelCharts.BTN_BG_COLOR_UNSELECTED; var rectTransform = buttonBack.GetComponent <RectTransform>(); rectTransform.anchorMin = new Vector2(0, 0); rectTransform.anchorMax = new Vector2(1, 1); rectTransform.offsetMin = new Vector2(0, 0); rectTransform.offsetMax = new Vector2(0, 0); // modify button text var buttonText = Common.GetChild(goButton, "StudyEffectText"); if (!buttonText) { throw new Exception("Failed to get child 'StudyEffectText' from 'StudySkill,0'"); } buttonText.name = "ButtonText"; rectTransform = buttonText.GetComponent <RectTransform>(); rectTransform.anchorMin = new Vector2(0, 0); rectTransform.anchorMax = new Vector2(1, 1); rectTransform.offsetMin = new Vector2(0, 0); rectTransform.offsetMax = new Vector2(0, 0); var text = buttonText.GetComponent <Text>(); if (!text) { throw new Exception("Failed to get Text component from 'StudyEffectText'"); } text.text = label; text.color = PanelCharts.BTN_COLOR_UNSELECTED; TaiwuCommon.SetFont(text); Common.RemoveComponent <SetFont>(buttonText); return(goButton); }
private void CreatePanel() { // 此函数的触发条件就是 BuildingWindow.Start, 所以 BuildingWindow 的实例一定存在 var ququBox = BuildingWindow.instance.GetComponentInChildren <QuquBox>(); // clone & modify panel var oriPanel = Common.GetChild(ququBox.ququBoxWindow, "QuquBoxHolder"); this.panel = UnityEngine.Object.Instantiate(oriPanel, this.parent.transform); this.panel.SetActive(true); this.panel.name = "MajordomoPanelLogs"; var rectTransform = this.panel.GetComponent <RectTransform>(); rectTransform.anchorMin = new Vector2(0, 0); rectTransform.anchorMax = new Vector2(1, 1); rectTransform.offsetMin = new Vector2(0, 0); rectTransform.offsetMax = new Vector2(0, 0); Common.RemoveComponent <GridLayoutGroup>(this.panel); Common.RemoveChildren(this.panel); // clone & modify message view var goActorMenu = Resources.Load <GameObject>("OldScenePrefabs/ActorMenu"); var actorMenu = goActorMenu.GetComponentInChildren <ActorMenu>(); var oriMessageView = Common.GetChild(actorMenu.actorMassage, "ActorMassageView"); if (!oriMessageView) { throw new Exception("Failed to get child 'ActorMassageView' from ActorMenu.actorMassage"); } var messageView = UnityEngine.Object.Instantiate(oriMessageView, this.panel.transform); messageView.SetActive(true); messageView.name = "MajordomoMessageView"; // modify message view port var viewPort = Common.GetChild(messageView, "ActorMassageViewport"); if (!viewPort) { throw new Exception("Failed to get child 'ActorMassageViewport' from 'ActorMassageView'"); } viewPort.name = "MajordomoMessageViewport"; // get message content, create message content item this.messageContent = Common.GetChild(viewPort, "ActorMassageText"); if (!this.messageContent) { throw new Exception("Failed to get child 'ActorMassageText' from 'ActorMassageViewport'"); } this.messageContent.name = "MajordomoMessageContent"; var messageContentItem = UnityEngine.Object.Instantiate(this.messageContent, this.messageContent.transform); messageContentItem.SetActive(true); messageContentItem.name = "MajordomoMessageContentItem"; // modify message content Common.RemoveComponent <Text>(this.messageContent); Common.RemoveComponent <SetFont>(this.messageContent); var verticalLayoutGroup = this.messageContent.AddComponent <VerticalLayoutGroup>(); verticalLayoutGroup.childForceExpandWidth = false; verticalLayoutGroup.childForceExpandHeight = false; // modify message content item var text = messageContentItem.GetComponent <Text>(); TaiwuCommon.SetFont(text); text.text = string.Empty; Common.RemoveComponent <ContentSizeFitter>(messageContentItem); Common.RemoveComponent <SetFont>(messageContentItem); // modify message scroll bar var scrollbar = Common.GetChild(messageView, "ActorMassageScrollbar"); if (!scrollbar) { throw new Exception("Failed to get child 'ActorMassageScrollbar' from 'ActorMassageView'"); } scrollbar.name = "MajordomoMessageScrollbar"; // clone & modify page text var oriPageText = Common.GetChild(actorMenu.actorMassage, "PageText"); if (!oriPageText) { throw new Exception("Failed to get child 'PageText' from ActorMenu.actorMassage"); } var pageText = UnityEngine.Object.Instantiate(oriPageText, this.panel.transform); pageText.SetActive(true); pageText.name = "MajordomoPageText"; Common.TranslateUI(pageText, 0, 20); this.textMessagePage = pageText.GetComponent <Text>(); if (!this.textMessagePage) { throw new Exception("Failed to get Text component from 'PageText'"); } TaiwuCommon.SetFont(this.textMessagePage); Common.RemoveComponent <SetFont>(pageText); // clone & modify page button prev var oriPageButtonPrev = Common.GetChild(actorMenu.actorMassage, "Page-Button"); if (!oriPageButtonPrev) { throw new Exception("Failed to get child 'Page-Button' from ActorMenu.actorMassage"); } var pageButtonPrev = UnityEngine.Object.Instantiate(oriPageButtonPrev, this.panel.transform); pageButtonPrev.SetActive(true); pageButtonPrev.name = "MajordomoPageButtonPrev"; Common.TranslateUI(pageButtonPrev, 0, 20); var btnPrev = Common.RemoveComponent <Button>(pageButtonPrev, recreate: true); btnPrev.onClick.AddListener(() => this.ChangeMessagePage(next: false)); // clone & modify page button next var oriPageButtonNext = Common.GetChild(actorMenu.actorMassage, "Page+Button"); if (!oriPageButtonNext) { throw new Exception("Failed to get child 'Page+Button' from ActorMenu.actorMassage"); } var pageButtonNext = UnityEngine.Object.Instantiate(oriPageButtonNext, this.panel.transform); pageButtonNext.SetActive(true); pageButtonNext.name = "MajordomoPageButtonNext"; Common.TranslateUI(pageButtonNext, 0, 20); var btnNext = Common.RemoveComponent <Button>(pageButtonNext, recreate: true); btnNext.onClick.AddListener(() => this.ChangeMessagePage(next: true)); }
private void CreateMainWindow() { // clone & modify main window Debug.Assert(QuquBox.instance.ququBoxWindow); this.window = UnityEngine.Object.Instantiate( QuquBox.instance.ququBoxWindow, QuquBox.instance.ququBoxWindow.transform.parent); this.window.SetActive(true); this.window.name = "MajordomoWindow"; Common.RemoveComponent <QuquBox>(this.window); Common.RemoveChildren(this.window, new List <string> { "ChooseItemMask", "ItemsBack" }); // modify main holder this.mainHolder = Common.GetChild(this.window, "QuquBoxHolder"); Debug.Assert(this.mainHolder); this.mainHolder.name = "MajordomoWindowMainHolder"; Common.RemoveComponent <GridLayoutGroup>(this.mainHolder); Common.RemoveChildren(this.mainHolder); // clone & modify menu this.menu = UnityEngine.Object.Instantiate(this.mainHolder, this.window.transform); this.menu.SetActive(true); this.menu.name = "MajordomoWindowMenu"; Common.RemoveChildren(this.menu); // resize main holder & menu var rectTransform = this.mainHolder.GetComponent <RectTransform>(); float width = rectTransform.offsetMax.x - rectTransform.offsetMin.x; float mainHolderWidth = width * 0.9f; float menuWidth = width - mainHolderWidth; rectTransform.offsetMin = new Vector2(rectTransform.offsetMin.x + menuWidth, rectTransform.offsetMin.y); rectTransform = this.menu.GetComponent <RectTransform>(); rectTransform.offsetMax = new Vector2(rectTransform.offsetMax.x - mainHolderWidth, rectTransform.offsetMax.y); // set menu layout int menuItemWidth = 70; int menuItemMargin = 20; var gridLayoutGroup = Common.RemoveComponent <GridLayoutGroup>(this.menu, recreate: true); gridLayoutGroup.padding = new RectOffset(menuItemMargin, menuItemMargin, menuItemMargin, menuItemMargin); gridLayoutGroup.cellSize = new Vector2(menuItemWidth, menuItemWidth); gridLayoutGroup.spacing = new Vector2(menuItemMargin, menuItemMargin); gridLayoutGroup.startAxis = GridLayoutGroup.Axis.Vertical; gridLayoutGroup.childAlignment = TextAnchor.UpperCenter; // modify close button var goCloseButton = Common.GetChild(this.window, "CloseQuquBoxButton"); Debug.Assert(goCloseButton); goCloseButton.name = "MajordomoWindowCloseButton"; var closeButton = Common.RemoveComponent <Button>(goCloseButton, recreate: true); closeButton.onClick.AddListener(() => this.Close()); var escWinComponent = Common.RemoveComponent <EscWinComponent>(goCloseButton, recreate: true); escWinComponent.escEvent = new EscWinComponent.EscCompEvent(); escWinComponent.escEvent.AddListener(() => this.Close()); // modify summary bar var goSummaryBack = Common.GetChild(this.window, "AllQuquLevelBack"); Debug.Assert(goSummaryBack); goSummaryBack.name = "MajordomoWindowSummaryBack"; var goSummary = Common.GetChild(goSummaryBack, "AllQuquLevelText"); Debug.Assert(goSummary); goSummary.name = "MajordomoWindowSummary"; this.textSummary = goSummary.GetComponent <Text>(); Debug.Assert(this.textSummary); TaiwuCommon.SetFont(this.textSummary); Common.RemoveComponent <SetFont>(goSummary); }
private void CreateMessagePage() { this.CreateMessagePageMenuControls(); // clone & modify message view Debug.Assert(ActorMenu.instance.actorMassage); var oriMessageView = Common.GetChild(ActorMenu.instance.actorMassage, "ActorMassageView"); Debug.Assert(oriMessageView); var messageView = UnityEngine.Object.Instantiate(oriMessageView, this.mainHolder.transform); messageView.SetActive(true); messageView.name = "MajordomoMessageView"; // modify message view port var viewPort = Common.GetChild(messageView, "ActorMassageViewport"); Debug.Assert(viewPort); viewPort.name = "MajordomoMessageViewport"; // get message content, create message content item this.messageContent = Common.GetChild(viewPort, "ActorMassageText"); Debug.Assert(this.messageContent); this.messageContent.name = "MajordomoMessageContent"; var messageContentItem = UnityEngine.Object.Instantiate(this.messageContent, this.messageContent.transform); messageContentItem.SetActive(true); messageContentItem.name = "MajordomoMessageContentItem0"; // modify message content Common.RemoveComponent <Text>(this.messageContent); Common.RemoveComponent <SetFont>(this.messageContent); var verticalLayoutGroup = this.messageContent.AddComponent <VerticalLayoutGroup>(); verticalLayoutGroup.childForceExpandWidth = false; verticalLayoutGroup.childForceExpandHeight = false; // modify message content item var text = messageContentItem.GetComponent <Text>(); TaiwuCommon.SetFont(text); text.text = string.Empty; Common.RemoveComponent <ContentSizeFitter>(messageContentItem); Common.RemoveComponent <SetFont>(messageContentItem); // modify message scroll bar var scrollbar = Common.GetChild(messageView, "ActorMassageScrollbar"); Debug.Assert(scrollbar); scrollbar.name = "MajordomoMessageScrollbar"; // clone & modify page text var oriPageText = Common.GetChild(ActorMenu.instance.actorMassage, "PageText"); Debug.Assert(oriPageText); var pageText = UnityEngine.Object.Instantiate(oriPageText, this.mainHolder.transform); pageText.SetActive(true); pageText.name = "MajordomoPageText"; Common.TranslateUI(pageText, 0, 20); this.textMessagePage = pageText.GetComponent <Text>(); Debug.Assert(this.textMessagePage); TaiwuCommon.SetFont(this.textMessagePage); Common.RemoveComponent <SetFont>(pageText); // clone & modify page button prev var oriPageButtonPrev = Common.GetChild(ActorMenu.instance.actorMassage, "Page-Button"); Debug.Assert(oriPageButtonPrev); var pageButtonPrev = UnityEngine.Object.Instantiate(oriPageButtonPrev, this.mainHolder.transform); pageButtonPrev.SetActive(true); pageButtonPrev.name = "MajordomoPageButtonPrev"; Common.TranslateUI(pageButtonPrev, 0, 20); var btnPrev = Common.RemoveComponent <Button>(pageButtonPrev, recreate: true); btnPrev.onClick.AddListener(() => this.ChangeMessagePage(next: false)); // clone & modify page button next var oriPageButtonNext = Common.GetChild(ActorMenu.instance.actorMassage, "Page+Button"); Debug.Assert(oriPageButtonNext); var pageButtonNext = UnityEngine.Object.Instantiate(oriPageButtonNext, this.mainHolder.transform); pageButtonNext.SetActive(true); pageButtonNext.name = "MajordomoPageButtonNext"; Common.TranslateUI(pageButtonNext, 0, 20); var btnNext = Common.RemoveComponent <Button>(pageButtonNext, recreate: true); btnNext.onClick.AddListener(() => this.ChangeMessagePage(next: true)); }
/// <summary> /// 为所有厢房安排工作人员 /// </summary> private void AssignBedroomWorkers() { // 厢房 ID -> 该厢房辅助的建筑信息列表 // bedroomIndex -> [BuildingWorkInfo, ] var bedroomsForWork = Bedroom.GetBedroomsForWork(this.partId, this.placeId, this.buildings, this.attrCandidates, this.workerAttrs); // 更新辅助类厢房的优先级 // 辅助类厢房优先级 = 基础优先级 + SUM(辅助建筑优先级) // bedroomIndex -> priority var auxiliaryBedroomsPriorities = new Dictionary <int, int>(); foreach (var entry in bedroomsForWork) { int bedroomIndex = entry.Key; var relatedBuildings = entry.Value; int basePriority = 7; int priority = basePriority * WORKING_PRIORITY_STEP_SIZE + relatedBuildings.Select(info => info.priority).Sum(); auxiliaryBedroomsPriorities[bedroomIndex] = priority; } // 对于辅助类厢房,按优先级依次分配合适的人选 MajordomoWindow.instance.AppendMessage(this.currDate, Message.IMPORTANCE_LOWEST, TaiwuCommon.SetColor(TaiwuCommon.COLOR_DARK_GRAY, "开始指派辅助类厢房……")); var sortedAuxiliaryBedrooms = auxiliaryBedroomsPriorities.OrderByDescending(entry => entry.Value).Select(entry => entry.Key); foreach (int bedroomIndex in sortedAuxiliaryBedrooms) { int selectedWorkerId = this.SelectAuxiliaryBedroomWorker(bedroomIndex, bedroomsForWork[bedroomIndex]); if (selectedWorkerId >= 0) { Original.SetBuildingWorker(this.partId, this.placeId, bedroomIndex, selectedWorkerId); } Output.LogAuxiliaryBedroomAndWorker(bedroomIndex, bedroomsForWork[bedroomIndex], auxiliaryBedroomsPriorities[bedroomIndex], selectedWorkerId, this.partId, this.placeId, this.currDate, this.workerAttrs); } // 对于一般厢房,按优先级依次分配合适的人选 MajordomoWindow.instance.AppendMessage(this.currDate, Message.IMPORTANCE_LOWEST, TaiwuCommon.SetColor(TaiwuCommon.COLOR_DARK_GRAY, "开始指派一般厢房……")); var sortedBedrooms = this.buildings.Where(entry => entry.Value.IsBedroom()) .OrderByDescending(entry => entry.Value.priority).Select(entry => entry.Value); foreach (var info in sortedBedrooms) { if (this.excludedBuildings.Contains(info.buildingIndex)) { continue; } int selectedWorkerId = this.SelectBuildingWorker(info.buildingIndex, info.requiredAttrId); if (selectedWorkerId >= 0) { Original.SetBuildingWorker(this.partId, this.placeId, info.buildingIndex, selectedWorkerId); } Output.LogBuildingAndWorker(info, selectedWorkerId, this.partId, this.placeId, this.currDate, this.workerAttrs); } }
private GameObject CreateMenuButton(string name, UnityEngine.Events.UnityAction callback, string iconPath, string label) { // clone & modify button Debug.Assert(HomeSystem.instance.studyActor); var studySkillButton = Common.GetChild(HomeSystem.instance.studyActor, "StudySkill,0"); Debug.Assert(studySkillButton); var goMenuButton = UnityEngine.Object.Instantiate(studySkillButton, this.menu.transform); goMenuButton.SetActive(true); goMenuButton.name = name; goMenuButton.tag = "Untagged"; var button = goMenuButton.AddComponent <Button>(); button.onClick.AddListener(callback); goMenuButton.AddComponent <PointerClick>(); // modify button background var buttonBack = Common.GetChild(goMenuButton, "StudyEffectBack"); Debug.Assert(buttonBack); buttonBack.name = "MajordomoMenuButtonBack"; var rectTransform = buttonBack.GetComponent <RectTransform>(); rectTransform.offsetMin = new Vector2(rectTransform.offsetMin.x - 10, rectTransform.offsetMin.y); rectTransform.offsetMax = new Vector2(rectTransform.offsetMax.x + 10, rectTransform.offsetMax.y); // modify button icon var buttonIcon = Common.GetChild(goMenuButton, "StudySkillIcon,0"); Debug.Assert(buttonIcon); buttonIcon.name = "MajordomoMenuButtonIcon"; var buttonIconImage = buttonIcon.GetComponent <Image>(); buttonIconImage.sprite = ResourceLoader.CreateSpriteFromImage(iconPath); if (!buttonIconImage.sprite) { throw new Exception($"Failed to create sprite: {iconPath}"); } // modify button text var buttonText = Common.GetChild(goMenuButton, "StudyEffectText"); Debug.Assert(buttonText); buttonText.name = "MajordomoMenuButtonText"; rectTransform = buttonText.GetComponent <RectTransform>(); rectTransform.offsetMin = new Vector2(rectTransform.offsetMin.x - 10, rectTransform.offsetMin.y); rectTransform.offsetMax = new Vector2(rectTransform.offsetMax.x + 10, rectTransform.offsetMax.y); var text = buttonText.GetComponent <Text>(); Debug.Assert(text); text.text = label; TaiwuCommon.SetFont(text); Common.RemoveComponent <SetFont>(buttonText); return(goMenuButton); }