public FCBuildingWindow(SettlementFC settlement, int buildingSlot) { factionfc = Find.World.GetComponent <FactionFC>(); buildingList = new List <BuildingFCDef>(); foreach (BuildingFCDef building in DefDatabase <BuildingFCDef> .AllDefsListForReading.Where(def => def.RequiredModsLoaded)) { if (building.defName != "Empty" && building.defName != "Construction") { //If not a building that shouldn't appear on the list if (building.techLevel <= factionfc.techLevel) { //If building techlevel requirement is met if (building.applicableBiomes.Count == 0 || building.applicableBiomes.Any() && building.applicableBiomes.Contains(settlement.biome)) { //If building meets the biome requirements buildingList.Add(building); } } } } buildingList.Sort(FactionColonies.CompareBuildingDef); forcePause = false; draggable = true; doCloseX = true; preventCameraMotion = false; this.settlement = settlement; this.buildingSlot = buildingSlot; buildingDef = settlement.buildings[buildingSlot]; }
public override void DoWindowContents(Rect inRect) { //grab before anchor/font GameFont fontBefore = Text.Font; TextAnchor anchorBefore = Text.Anchor; //Buildings for (int i = 0; i < buildingList.Count; i++) { BuildingFCDef building = buildingList[i]; newBuildingWindow = new Rect(BaseBuildingWindow.x, BaseBuildingWindow.y + (i * (rowHeight)) + scroll, BaseBuildingWindow.width, BaseBuildingWindow.height); newBuildingIcon = new Rect(BaseBuildingIcon.x, BaseBuildingIcon.y + (i * (rowHeight)) + scroll, BaseBuildingIcon.width, BaseBuildingIcon.height); newBuildingLabel = new Rect(BaseBuildingLabel.x, BaseBuildingLabel.y + (i * (rowHeight)) + scroll, BaseBuildingLabel.width, BaseBuildingLabel.height); newBuildingDesc = new Rect(BaseBuildingDesc.x, BaseBuildingDesc.y + (i * (rowHeight)) + scroll, BaseBuildingDesc.width, BaseBuildingDesc.height); if (Widgets.ButtonInvisible(newBuildingWindow)) { //If click on building List <FloatMenuOption> list = new List <FloatMenuOption>(); if (building == buildingDef) { //if the same building list.Add(new FloatMenuOption("Destroy".Translate(), delegate { settlement.deconstructBuilding(buildingSlot); Find.WindowStack.TryRemove(this); Find.WindowStack.WindowOfType <SettlementWindowFc>().windowUpdateFc(); })); } else { //if not the same building list.Add(new FloatMenuOption("Build".Translate(), delegate { if (!settlement.validConstructBuilding(building, buildingSlot, settlement)) { return; } FCEvent tmpEvt = new FCEvent(true) { def = FCEventDefOf.constructBuilding, source = settlement.mapLocation, planetName = settlement.planetName, building = building, buildingSlot = buildingSlot }; int triggerTime = building.constructionDuration; if (factionfc.hasPolicy(FCPolicyDefOf.isolationist)) { triggerTime /= 2; } tmpEvt.timeTillTrigger = Find.TickManager.TicksGame + triggerTime; Find.World.GetComponent <FactionFC>().addEvent(tmpEvt); PaymentUtil.paySilver(Convert.ToInt32(building.cost)); settlement.deconstructBuilding(buildingSlot); Messages.Message(building.label + " " + "WillBeConstructedIn".Translate() + " " + (tmpEvt.timeTillTrigger - Find.TickManager.TicksGame).ToTimeString(), MessageTypeDefOf.PositiveEvent); settlement.buildings[buildingSlot] = BuildingFCDefOf.Construction; Find.WindowStack.TryRemove(this); Find.WindowStack.WindowOfType <SettlementWindowFc>().windowUpdateFc(); })); } FloatMenu menu = new FloatMenu(list); Find.WindowStack.Add(menu); } Widgets.DrawMenuSection(newBuildingWindow); Widgets.DrawMenuSection(newBuildingIcon); Widgets.DrawLightHighlight(newBuildingIcon); Widgets.ButtonImage(newBuildingIcon, building.Icon); Text.Font = GameFont.Small; Widgets.ButtonTextSubtle(newBuildingLabel, ""); Widgets.Label(newBuildingLabel, " " + building.LabelCap + " - " + "Cost".Translate() + ": " + building.cost); Text.Font = GameFont.Tiny; Widgets.Label(newBuildingDesc, building.desc); } //Top Window Widgets.DrawMenuSection(TopWindow); Widgets.DrawHighlight(TopWindow); Widgets.DrawMenuSection(TopIcon); Widgets.DrawLightHighlight(TopIcon); Widgets.DrawBox(new Rect(0, 0, 400, 500)); Widgets.ButtonImage(TopIcon, buildingDef.Icon); Widgets.ButtonTextSubtle(TopName, ""); Text.Font = GameFont.Medium; Text.Anchor = TextAnchor.UpperLeft; Widgets.Label(new Rect(TopName.x + 5, TopName.y, TopName.width, TopName.height), buildingDef.LabelCap); Widgets.DrawMenuSection(new Rect(TopDescription.x - 5, TopDescription.y - 5, TopDescription.width, TopDescription.height)); Text.Font = GameFont.Small; Widgets.Label(TopDescription, buildingDef.desc); Widgets.DrawLineHorizontal(0, TopWindow.y + TopWindow.height, 400); //reset anchor/font Text.Font = fontBefore; Text.Anchor = anchorBefore; if (Event.current.type == EventType.ScrollWheel) { scrollWindow(Event.current.delta.y); } }