private void DrawFactionName(Rect inRect) { Text.Anchor = TextAnchor.MiddleLeft; Text.Font = GameFont.Medium; if (faction != null && faction.name != null) { Widgets.Label(new Rect(7, 32, 200, 40), faction.name); } if (Widgets.ButtonImage(new Rect(210, 37, 20, 20), TexLoad.iconCustomize)) { //if click faction customize button //Log.Message("Faction customize clicked"); Faction fact = FactionColonies.getPlayerColonyFaction(); if (fact != null) { Find.WindowStack.Add(new FactionCustomizeWindowFc(faction)); } else { Messages.Message("No faction created to customize", MessageTypeDefOf.RejectInput); } } }
// public static void Patch(Harmony harmony) { Type typ = FactionColonies.returnUnknownTypeFromName("AndroidTiers.PawnGroupMakerUtility_Patch"); //Get type inside of type Type[] types = typ.GetNestedTypes(BindingFlags.Public | BindingFlags.Static); foreach (Type t in types) { Log.Message(t.ToString()); if (t.ToString() == "AndroidTiers.PawnGroupMakerUtility_Patch+GeneratePawns_Patch") { typ = t; //Log.Message("found" + t.ToString()); break; } } MethodInfo originalpre = typ.GetMethod("Listener", BindingFlags.Static | BindingFlags.NonPublic); Log.Message("2"); //var prefix = typeof(Android_Tiers_Patches).GetMethod("Prefix"); MethodInfo prefix = typeof(Android_Tiers_Patches).GetMethod("Prefix"); // List<MethodInfo> list = typeof(Android_Tiers_Patches).GetMethods(); foreach (MethodInfo info in typeof(Android_Tiers_Patches).GetMethods()) { if (info.Name == "Prefix") { prefix = info; } } Log.Message("2"); harmony.Patch(originalpre, prefix: new HarmonyMethod(prefix)); }
public void Process() { if (fireSupportType == "fireSupport") { if (ShouldFire) { IntVec3 spawnCenter = SemiRandomSpawnCenter; LocalTargetInfo info = new LocalTargetInfo(spawnCenter); ThingDef def = new ThingDef(); if (FactionColonies.IsModLoaded("CETeam.CombatExtended")) { DoCombatExtendedLaunch(spawnCenter, def); } else { def = expendProjectile().projectileWhenLoaded; Projectile projectile = (Projectile)GenSpawn.Spawn(def, sourceLocation, map); projectile.Launch(null, info, info, ProjectileHitFlags.All); } } } timeRunning++; }
private void DrawColonySettlementCreationButton(Rect inRect) { Rect button = new Rect(InitialSize.x - 215, 40, 190, 20); Text.Anchor = TextAnchor.MiddleLeft; Text.Font = GameFont.Small; Faction gfaction = FactionColonies.getPlayerColonyFaction(); if (gfaction != null) { if (Widgets.ButtonText(button, "CreateNewColony".Translate())) { Find.WindowStack.Add(new CreateColonyWindowFc()); //Move player to world map Find.World.renderer.wantedMode = WorldRenderMode.Planet; Messages.Message("SelectTile".Translate(), MessageTypeDefOf.NegativeEvent); } } else //create new faction { if (Widgets.ButtonText(button, "Create New Faction")) { FactionColonies.createPlayerColonyFaction(); faction.factionCreated = true; Find.WindowStack.Add(new FactionCustomizeWindowFc(faction)); //Initial release - Autocreate faction if (Find.CurrentMap.Parent != null && Find.WorldObjects.WorldObjectAt <WorldSettlementFC>(Find.CurrentMap.Parent.Tile) != null) { Messages.Message("SetAsFactionCapital".Translate(Find.WorldObjects.SettlementAt(Find.CurrentMap.Parent.Tile).Name), MessageTypeDefOf.NeutralEvent); } } } }
public void attemptToAssignSquad(SettlementFC settlement, MilSquadFC squad) { if (FactionColonies.calculateMilitaryLevelPoints(settlement.settlementMilitaryLevel) >= squad.equipmentTotalCost) { if (squadExists(settlement)) { settlement.militarySquad.OutfitSquad(squad); } else { //create new squad createMercenarySquad(settlement); settlement.militarySquad.OutfitSquad(squad); } Messages.Message(squad.name + "'s loadout has been assigned to " + settlement.name, MessageTypeDefOf.TaskCompletion); } else { Messages.Message("That squad exceeds the settlement's max allotted cost", MessageTypeDefOf.RejectInput); } }
public void DrawButtons(int x, int y, int length, int size, int set) { Text.Anchor = TextAnchor.MiddleCenter; Text.Font = GameFont.Tiny; if (set == 1) { for (int i = 0; i < buttons.Count(); i++) { if (Widgets.ButtonText(new Rect(x, y + ((size + 10) * i), length, size), buttons[i])) { //If click a button button if (buttons[i] == "UpgradeTown".Translate()) { //if click upgrade town button Find.WindowStack.Add(new settlementUpgradeWindowFC(settlement)); //Log.Message(buttons[i]); } if (buttons[i] == "GoToLocation".Translate()) { //if click go to location //Log.Message(buttons[i]); Find.WindowStack.TryRemove(this); settlement.goTo(); } if (buttons[i] == "AreYouSureRemove".Translate()) { //if click to delete colony Find.WindowStack.TryRemove(this); FactionColonies.removePlayerSettlement(settlement); } if (buttons[i] == "DeleteSettlement".Translate()) { //if click town log button //Log.Message(buttons[i]); buttons[i] = "AreYouSureRemove".Translate(); } if (buttons[i] == "PrisonersMenu".Translate()) { Find.WindowStack.Add(new FCPrisonerMenu(settlement)); //put prisoner window here. } if (buttons[i] == "Military".Translate()) { List <FloatMenuOption> list = new List <FloatMenuOption>(); list.Add(new FloatMenuOption(TranslatorFormattedStringExtensions.Translate("ToggleAutoDefend", settlement.autoDefend.ToString()), delegate { settlement.autoDefend = !settlement.autoDefend; })); if (settlement.isUnderAttack == true) { FCEvent evt = MilitaryUtilFC.returnMilitaryEventByLocation(settlement.mapLocation); list.Add(new FloatMenuOption(TranslatorFormattedStringExtensions.Translate("SettlementDefendingInformation", evt.militaryForceDefending.homeSettlement.name, evt.militaryForceDefending.militaryLevel), null, MenuOptionPriority.High)); list.Add(new FloatMenuOption("ChangeDefendingForce".Translate(), delegate { List <FloatMenuOption> settlementList = new List <FloatMenuOption>(); SettlementFC homeSettlement = settlement; settlementList.Add(new FloatMenuOption(TranslatorFormattedStringExtensions.Translate("ResetToHomeSettlement", homeSettlement.settlementMilitaryLevel), delegate { MilitaryUtilFC.changeDefendingMilitaryForce(evt, homeSettlement); }, MenuOptionPriority.High)); foreach (SettlementFC settlement in Find.World.GetComponent <FactionFC>().settlements) { if (settlement.isMilitaryValid() == true && settlement != homeSettlement) { //if military is valid to use. settlementList.Add(new FloatMenuOption(settlement.name + " " + "ShortMilitary".Translate() + " " + settlement.settlementMilitaryLevel + " - " + "FCAvailable".Translate() + ": " + (!settlement.isMilitaryBusySilent()).ToString(), delegate { if (settlement.isMilitaryBusy() == true) { //military is busy } else { MilitaryUtilFC.changeDefendingMilitaryForce(evt, settlement); } }, MenuOptionPriority.Default, null, null, 0f, null, null )); } } if (settlementList.Count == 0) { settlementList.Add(new FloatMenuOption("NoValidMilitaries".Translate(), null)); } FloatMenu floatMenu2 = new FloatMenu(settlementList); floatMenu2.vanishIfMouseDistant = true; Find.WindowStack.Add(floatMenu2); //set to raid settlement here })); FloatMenu floatMenu = new FloatMenu(list); floatMenu.vanishIfMouseDistant = true; Find.WindowStack.Add(floatMenu); } else { list.Add(new FloatMenuOption("SettlementNotBeingAttacked".Translate(), null)); FloatMenu menu = new FloatMenu(list); Find.WindowStack.Add(menu); } } } } } //set two buttons }
public static militaryForce createMilitaryForceFromFaction(Faction faction, bool handicap) { double militaryLevel; double efficiency; switch (faction.def.techLevel) { case TechLevel.Undefined: militaryLevel = 1; efficiency = .5; break; case TechLevel.Animal: militaryLevel = 2; efficiency = .5; break; case TechLevel.Neolithic: militaryLevel = 3; efficiency = 1; break; case TechLevel.Medieval: militaryLevel = 4; efficiency = 1.2; break; case TechLevel.Industrial: militaryLevel = 4; efficiency = 1.2; break; case TechLevel.Spacer: militaryLevel = 5; efficiency = 1.3; break; case TechLevel.Ultra: militaryLevel = 6; efficiency = 1.3; break; case TechLevel.Archotech: militaryLevel = 6; efficiency = 1.5; break; default: militaryLevel = 1; efficiency = 1; Log.Message("Defaulted createMilitaryForceFromEnemyFaction switch case - Empire Mod"); break; } if (faction.def.defName == "VFEI_Insect") { militaryLevel = 4; efficiency = 1.2; } double value = militaryLevel + FactionColonies.randomAttackModifier(); if (handicap) { value = Math.Min(value, (2 + Math.Round((double)(Find.TickManager.TicksGame - Find.World.GetComponent <FactionFC>().timeStart - GenDate.TicksPerSeason) / GenDate.TicksPerSeason))); //Log.Message(value.ToString()); } militaryForce returnForce = new militaryForce(value, efficiency, null, faction); return(returnForce); }
private List <FloatMenuOption> DeploymentOptions(SettlementFC settlement) => new List <FloatMenuOption> { new FloatMenuOption("walkIntoMapDeploymentOption".Translate(), delegate { FactionColonies.CallinAlliedForces(settlement, false); }), DropPodDeploymentOption(settlement) };
public override void DrawTab(Rect rect) { Rect SelectionBar = new Rect(5, 45, 200, 30); Rect importButton = new Rect(5, SelectionBar.y + SelectionBar.height + 10, 200, 30); Rect nameTextField = new Rect(5, importButton.y + importButton.height + 10, 250, 30); Rect isCivilian = new Rect(5, nameTextField.y + nameTextField.height + 10, 100, 30); Rect isTrader = new Rect(isCivilian.x, isCivilian.y + isCivilian.height + 5, isCivilian.width, isCivilian.height); Rect unitIcon = new Rect(560, 235, 120, 120); Rect animalIcon = new Rect(560, 335, 120, 120); Rect ApparelHead = new Rect(600, 140, 50, 50); Rect ApparelTorsoSkin = new Rect(700, 170, 50, 50); Rect ApparelBelt = new Rect(700, 240, 50, 50); Rect ApparelLegs = new Rect(700, 310, 50, 50); Rect AnimalCompanion = new Rect(500, 160, 50, 50); Rect ApparelTorsoShell = new Rect(500, 230, 50, 50); Rect ApparelTorsoMiddle = new Rect(500, 310, 50, 50); Rect EquipmentWeapon = new Rect(440, 230, 50, 50); Rect ApparelWornItems = new Rect(440, 385, 330, 175); Rect EquipmentTotalCost = new Rect(450, 50, 350, 40); Rect ResetButton = new Rect(700, 50, 100, 30); Rect DeleteButton = new Rect(ResetButton.x, ResetButton.y + ResetButton.height + 5, ResetButton.width, ResetButton.height); Rect SavePawn = new Rect(DeleteButton.x, DeleteButton.y + DeleteButton.height + 5, DeleteButton.width, DeleteButton.height); Rect ChangeRace = new Rect(325, ResetButton.y, SavePawn.width, SavePawn.height); Rect RollNewPawn = new Rect(325, ResetButton.y + SavePawn.height + 5, SavePawn.width, SavePawn.height); if (Widgets.CustomButtonText(ref SelectionBar, selectedText, Color.gray, Color.white, Color.black)) { List <FloatMenuOption> Units = new List <FloatMenuOption> { new FloatMenuOption("Create New Unit", delegate { MilUnitFC newUnit = new MilUnitFC(false) { name = $"New Unit {util.units.Count() + 1}" }; selectedText = newUnit.name; selectedUnit = newUnit; util.units.Add(newUnit); newUnit.unequipAllEquipment(); }) }; //Option to create new unit //Create list of selectable units foreach (MilUnitFC unit in util.units) { void action() { selectedText = unit.name; selectedUnit = unit; } //Prevent units being modified when their squads are deployed FactionFC factionFC = Find.World.GetComponent <FactionFC>(); List <MilSquadFC> squadsContainingUnit = factionFC?.militaryCustomizationUtil?.squads.Where(squad => squad?.units != null && squad.units.Contains(unit)).ToList(); List <SettlementFC> settlementsContainingSquad = factionFC?.settlements?.Where(settlement => settlement?.militarySquad?.outfit != null && squadsContainingUnit.Any(squad => settlement.militarySquad.outfit == squad)).ToList(); if ((settlementsContainingSquad?.Count ?? 0) > 0) { if (settlementsContainingSquad.Any(settlement => settlement.militarySquad.isDeployed)) { Units.Add(new FloatMenuOption(unit.name, delegate { Messages.Message("CantBeModified".Translate(unit.name, "ReasonDeployed".Translate()), MessageTypeDefOf.NeutralEvent, false); })); continue; } else if (settlementsContainingSquad.Any(settlement => settlement.isUnderAttack && settlementsContainingSquad.Contains(settlement.worldSettlement.defenderForce.homeSettlement))) { Units.Add(new FloatMenuOption(unit.name, delegate { Messages.Message("CantBeModified".Translate(unit.name, "ReasonDefending".Translate()), MessageTypeDefOf.NeutralEvent, false); })); continue; } } if (unit.defaultPawn.equipment.Primary != null) { Units.Add(new FloatMenuOption(unit.name, action, unit.defaultPawn.equipment.Primary.def)); } else { Units.Add(new FloatMenuOption(unit.name, action)); } } FloatMenu selection = new Searchable_FloatMenu(Units); Find.WindowStack.Add(selection); } if (Widgets.ButtonText(importButton, "importUnit".Translate())) { Find.WindowStack.Add(new Dialog_ManageUnitExportsFC( FactionColoniesMilitary.SavedUnits.ToList())); } //Worn Items Widgets.DrawMenuSection(ApparelWornItems); //set text anchor and font GameFont fontBefore = Text.Font; TextAnchor anchorBefore = Text.Anchor; Text.Font = GameFont.Tiny; Text.Anchor = TextAnchor.UpperCenter; //if unit is not selected Widgets.Label(new Rect(new Vector2(ApparelHead.x, ApparelHead.y - 15), ApparelHead.size), "fcLabelHead".Translate()); Widgets.DrawMenuSection(ApparelHead); Widgets.Label( new Rect(new Vector2(ApparelTorsoSkin.x, ApparelTorsoSkin.y - 15), ApparelTorsoSkin.size), "fcLabelShirt".Translate()); Widgets.DrawMenuSection(ApparelTorsoSkin); Widgets.Label( new Rect(new Vector2(ApparelTorsoMiddle.x, ApparelTorsoMiddle.y - 15), ApparelTorsoMiddle.size), "fcLabelChest".Translate()); Widgets.DrawMenuSection(ApparelTorsoMiddle); Widgets.Label( new Rect(new Vector2(ApparelTorsoShell.x, ApparelTorsoShell.y - 15), ApparelTorsoShell.size), "fcLabelOver".Translate()); Widgets.DrawMenuSection(ApparelTorsoShell); Widgets.Label(new Rect(new Vector2(ApparelBelt.x, ApparelBelt.y - 15), ApparelBelt.size), "fcLabelBelt".Translate()); Widgets.DrawMenuSection(ApparelBelt); Widgets.Label(new Rect(new Vector2(ApparelLegs.x, ApparelLegs.y - 15), ApparelLegs.size), "fcLabelPants".Translate()); Widgets.DrawMenuSection(ApparelLegs); Widgets.Label( new Rect(new Vector2(EquipmentWeapon.x, EquipmentWeapon.y - 15), EquipmentWeapon.size), "fcLabelWeapon".Translate()); Widgets.DrawMenuSection(EquipmentWeapon); Widgets.Label( new Rect(new Vector2(AnimalCompanion.x, AnimalCompanion.y - 15), AnimalCompanion.size), "fcLabelAnimal".Translate()); Widgets.DrawMenuSection(AnimalCompanion); //Reset Text anchor and font Text.Font = fontBefore; Text.Anchor = anchorBefore; //if unit is selected if (selectedUnit == null) { return; } Text.Font = GameFont.Tiny; Text.Anchor = TextAnchor.UpperCenter; if (Widgets.ButtonText(ResetButton, "resetUnitToDefaultButton".Translate())) { selectedUnit.unequipAllEquipment(); } if (Widgets.ButtonText(DeleteButton, "deleteUnitButton".Translate())) { selectedUnit.removeUnit(); util.checkMilitaryUtilForErrors(); selectedUnit = null; selectedText = "selectAUnitButton".Translate(); //Reset Text anchor and font Text.Font = fontBefore; Text.Anchor = anchorBefore; return; } if (Widgets.ButtonText(RollNewPawn, "rollANewUnitButton".Translate())) { selectedUnit.generateDefaultPawn(); selectedUnit.unequipAllEquipment(); } if (Widgets.ButtonText(ChangeRace, "changeUnitRaceButton".Translate())) { List <string> races = new List <string>(); List <FloatMenuOption> options = new List <FloatMenuOption>(); foreach (PawnKindDef def in DefDatabase <PawnKindDef> .AllDefsListForReading.Where(def => def.IsHumanLikeRace() && !races.Contains(def.race.label) && faction.raceFilter.Allows(def.race))) { if (def.race == ThingDefOf.Human && def.LabelCap != "Colonist") { continue; } races.Add(def.race.label); string optionStr = def.race.label.CapitalizeFirst() + " - Cost: " + Math.Floor(def.race.BaseMarketValue * FactionColonies.militaryRaceCostMultiplier); options.Add(new FloatMenuOption(optionStr, delegate { selectedUnit.pawnKind = def; selectedUnit.generateDefaultPawn(); selectedUnit.changeTick(); })); } if (!options.Any()) { options.Add(new FloatMenuOption("changeUnitRaceNoRaces".Translate(), null)); } options.Sort(FactionColonies.CompareFloatMenuOption); FloatMenu menu = new Searchable_FloatMenu(options); Find.WindowStack.Add(menu); } if (Widgets.ButtonText(SavePawn, "exportUnitButton".Translate())) { // TODO: confirm FactionColoniesMilitary.SaveUnit(new SavedUnitFC(selectedUnit)); Messages.Message("ExportUnit".Translate(), MessageTypeDefOf.TaskCompletion); } //Unit Name selectedUnit.name = Widgets.TextField(nameTextField, selectedUnit.name); Widgets.CheckboxLabeled(isCivilian, "unitIsCivilianLabel".Translate(), ref selectedUnit.isCivilian); Widgets.CheckboxLabeled(isTrader, "unitIsTraderLabel".Translate(), ref selectedUnit.isTrader); selectedUnit.setTrader(selectedUnit.isTrader); selectedUnit.setCivilian(selectedUnit.isCivilian); //Reset Text anchor and font Text.Font = fontBefore; Text.Anchor = anchorBefore; //Draw Pawn if (selectedUnit.defaultPawn != null) { if (selectedUnit.animal != null) { //Widgets.DrawTextureFitted(animalIcon, selectedUnit.animal.race.graphicData.Graphic.MatNorth.mainTexture, 1); } Widgets.ThingIcon(unitIcon, selectedUnit.defaultPawn); } //Animal Companion if (Widgets.ButtonInvisible(AnimalCompanion)) { List <FloatMenuOption> list = (from animal in DefDatabase <PawnKindDef> .AllDefs where animal.IsAnimalAndAllowed() select new FloatMenuOption(animal.LabelCap + " - Cost: " + Math.Floor(animal.race.BaseMarketValue * FactionColonies.militaryAnimalCostMultiplier), delegate { //Do add animal code here selectedUnit.animal = animal; }, animal.race.uiIcon, Color.white)).ToList(); list.Sort(FactionColonies.CompareFloatMenuOption); list.Insert(0, new FloatMenuOption("unitActionUnequipThing".Translate(), delegate { //unequip here selectedUnit.animal = null; })); FloatMenu menu = new Searchable_FloatMenu(list); Find.WindowStack.Add(menu); } //Weapon Equipment if (Widgets.ButtonInvisible(EquipmentWeapon)) { List <FloatMenuOption> list = (from thing in DefDatabase <ThingDef> .AllDefs where thing.IsWeapon && thing.BaseMarketValue != 0 && FactionColonies.canCraftItem(thing) where true select new FloatMenuOption(thing.LabelCap + " - Cost: " + thing.BaseMarketValue, delegate { if (thing.MadeFromStuff) { //If made from stuff List <FloatMenuOption> stuffList = (from stuff in DefDatabase <ThingDef> .AllDefs where stuff.IsStuff && thing.stuffCategories.SharesElementWith(stuff.stuffProps.categories) select new FloatMenuOption(stuff.LabelCap + " - Total Value: " + StatWorker_MarketValue.CalculatedBaseMarketValue( thing, stuff), delegate { selectedUnit.equipWeapon( ThingMaker.MakeThing(thing, stuff) as ThingWithComps); })).ToList(); stuffList.Sort(FactionColonies.CompareFloatMenuOption); FloatMenu stuffWindow = new Searchable_FloatMenu(stuffList); Find.WindowStack.Add(stuffWindow); } else { //If not made from stuff selectedUnit.equipWeapon(ThingMaker.MakeThing(thing) as ThingWithComps); } }, thing)).ToList(); list.Sort(FactionColonies.CompareFloatMenuOption); list.Insert(0, new FloatMenuOption("unitActionUnequipThing".Translate(), delegate { selectedUnit.unequipWeapon(); })); FloatMenu menu = new Searchable_FloatMenu(list); Find.WindowStack.Add(menu); } //headgear Slot if (Widgets.ButtonInvisible(ApparelHead)) { List <FloatMenuOption> headgearList = new List <FloatMenuOption>(); foreach (ThingDef thing in DefDatabase <ThingDef> .AllDefs) { if (thing.IsApparel) { if (thing.apparel.layers.Contains(ApparelLayerDefOf.Overhead) && FactionColonies.canCraftItem(thing)) { headgearList.Add(new FloatMenuOption( thing.LabelCap + " - Cost: " + thing.BaseMarketValue, delegate { if (thing.MadeFromStuff) { //If made from stuff List <FloatMenuOption> stuffList = new List <FloatMenuOption>(); foreach (ThingDef stuff in DefDatabase <ThingDef> .AllDefs) { if (stuff.IsStuff && thing.stuffCategories.SharesElementWith(stuff.stuffProps .categories)) { stuffList.Add(new FloatMenuOption( stuff.LabelCap + " - Total Value: " + (StatWorker_MarketValue.CalculatedBaseMarketValue(thing, stuff)), delegate { selectedUnit.wearEquipment( ThingMaker.MakeThing(thing, stuff) as Apparel, true); })); } } stuffList.Sort(FactionColonies.CompareFloatMenuOption); FloatMenu stuffWindow = new Searchable_FloatMenu(stuffList); Find.WindowStack.Add(stuffWindow); } else { //If not made from stuff selectedUnit.wearEquipment(ThingMaker.MakeThing(thing) as Apparel, true); } }, thing)); } } } headgearList.Sort(FactionColonies.CompareFloatMenuOption); headgearList.Insert(0, new FloatMenuOption("unitActionUnequipThing".Translate(), delegate { //Remove old foreach (Apparel apparel in selectedUnit.defaultPawn.apparel.WornApparel .Where(apparel => apparel.def.apparel.layers.Contains(ApparelLayerDefOf.Overhead))) { selectedUnit.defaultPawn.apparel.Remove(apparel); break; } })); FloatMenu menu = new Searchable_FloatMenu(headgearList); Find.WindowStack.Add(menu); } //Torso Shell Slot if (Widgets.ButtonInvisible(ApparelTorsoShell)) { List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (ThingDef thing in DefDatabase <ThingDef> .AllDefs) { if (thing.IsApparel) { if (thing.apparel.layers.Contains(ApparelLayerDefOf.Shell) && thing.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso) && FactionColonies.canCraftItem(thing)) //CHANGE THIS { list.Add(new FloatMenuOption(thing.LabelCap + " - Cost: " + thing.BaseMarketValue, delegate { if (thing.MadeFromStuff) { //If made from stuff List <FloatMenuOption> stuffList = new List <FloatMenuOption>(); foreach (ThingDef stuff in DefDatabase <ThingDef> .AllDefs) { if (stuff.IsStuff && thing.stuffCategories.SharesElementWith(stuff.stuffProps .categories)) { stuffList.Add(new FloatMenuOption( stuff.LabelCap + " - Total Value: " + (StatWorker_MarketValue.CalculatedBaseMarketValue(thing, stuff)), delegate { selectedUnit.wearEquipment( ThingMaker.MakeThing(thing, stuff) as Apparel, true); })); } } stuffList.Sort(FactionColonies.CompareFloatMenuOption); FloatMenu stuffWindow = new Searchable_FloatMenu(stuffList); Find.WindowStack.Add(stuffWindow); } else { //If not made from stuff selectedUnit.wearEquipment(ThingMaker.MakeThing(thing) as Apparel, true); } }, thing)); } } } list.Sort(FactionColonies.CompareFloatMenuOption); list.Insert(0, new FloatMenuOption("unitActionUnequipThing".Translate(), delegate { //Remove old foreach (Apparel apparel in selectedUnit.defaultPawn.apparel.WornApparel) { if (apparel.def.apparel.layers.Contains(ApparelLayerDefOf.Shell) && apparel.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso)) //CHANGE THIS { selectedUnit.defaultPawn.apparel.Remove(apparel); break; } } })); FloatMenu menu = new Searchable_FloatMenu(list); Find.WindowStack.Add(menu); } //Torso Middle Slot if (Widgets.ButtonInvisible(ApparelTorsoMiddle)) { List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (ThingDef thing in DefDatabase <ThingDef> .AllDefs) { if (thing.IsApparel) { if (thing.apparel.layers.Contains(ApparelLayerDefOf.Middle) && thing.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso) && FactionColonies.canCraftItem(thing)) //CHANGE THIS { list.Add(new FloatMenuOption(thing.LabelCap + " - Cost: " + thing.BaseMarketValue, delegate { if (thing.MadeFromStuff) { //If made from stuff List <FloatMenuOption> stuffList = new List <FloatMenuOption>(); foreach (ThingDef stuff in DefDatabase <ThingDef> .AllDefs) { if (stuff.IsStuff && thing.stuffCategories.SharesElementWith(stuff.stuffProps .categories)) { stuffList.Add(new FloatMenuOption( stuff.LabelCap + " - Total Value: " + (StatWorker_MarketValue.CalculatedBaseMarketValue(thing, stuff)), delegate { selectedUnit.wearEquipment( ThingMaker.MakeThing(thing, stuff) as Apparel, true); })); } } stuffList.Sort(FactionColonies.CompareFloatMenuOption); FloatMenu stuffWindow = new Searchable_FloatMenu(stuffList); Find.WindowStack.Add(stuffWindow); } else { //If not made from stuff selectedUnit.wearEquipment(ThingMaker.MakeThing(thing) as Apparel, true); } }, thing)); } } } list.Sort(FactionColonies.CompareFloatMenuOption); list.Insert(0, new FloatMenuOption("unitActionUnequipThing".Translate(), delegate { //Remove old foreach (Apparel apparel in selectedUnit.defaultPawn.apparel.WornApparel) { if (apparel.def.apparel.layers.Contains(ApparelLayerDefOf.Middle) && apparel.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso)) //CHANGE THIS { selectedUnit.defaultPawn.apparel.Remove(apparel); break; } } })); FloatMenu menu = new Searchable_FloatMenu(list); Find.WindowStack.Add(menu); } //Torso Skin Slot if (Widgets.ButtonInvisible(ApparelTorsoSkin)) { List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (ThingDef thing in DefDatabase <ThingDef> .AllDefs) { if (thing.IsApparel) { if (thing.apparel.layers.Contains(ApparelLayerDefOf.OnSkin) && thing.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso) && FactionColonies.canCraftItem(thing)) //CHANGE THIS { list.Add(new FloatMenuOption(thing.LabelCap + " - Cost: " + thing.BaseMarketValue, delegate { if (thing.MadeFromStuff) { //If made from stuff List <FloatMenuOption> stuffList = new List <FloatMenuOption>(); foreach (ThingDef stuff in DefDatabase <ThingDef> .AllDefs) { if (stuff.IsStuff && thing.stuffCategories.SharesElementWith(stuff.stuffProps .categories)) { stuffList.Add(new FloatMenuOption( stuff.LabelCap + " - Total Value: " + (StatWorker_MarketValue.CalculatedBaseMarketValue(thing, stuff)), delegate { selectedUnit.wearEquipment( ThingMaker.MakeThing(thing, stuff) as Apparel, true); })); } } stuffList.Sort(FactionColonies.CompareFloatMenuOption); FloatMenu stuffWindow = new Searchable_FloatMenu(stuffList); Find.WindowStack.Add(stuffWindow); } else { //If not made from stuff selectedUnit.wearEquipment(ThingMaker.MakeThing(thing) as Apparel, true); } }, thing)); } } } list.Sort(FactionColonies.CompareFloatMenuOption); list.Insert(0, new FloatMenuOption("unitActionUnequipThing".Translate(), delegate { //Remove old foreach (Apparel apparel in selectedUnit.defaultPawn.apparel.WornApparel) { if (apparel.def.apparel.layers.Contains(ApparelLayerDefOf.OnSkin) && apparel.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso)) //CHANGE THIS { selectedUnit.defaultPawn.apparel.Remove(apparel); break; } } })); FloatMenu menu = new Searchable_FloatMenu(list); Find.WindowStack.Add(menu); } //Pants Slot if (Widgets.ButtonInvisible(ApparelLegs)) { List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (ThingDef thing in DefDatabase <ThingDef> .AllDefs) { if (thing.IsApparel) { if (thing.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Legs) && thing.apparel.layers.Contains(ApparelLayerDefOf.OnSkin) && FactionColonies.canCraftItem(thing)) //CHANGE THIS { list.Add(new FloatMenuOption(thing.LabelCap + " - Cost: " + thing.BaseMarketValue, delegate { if (thing.MadeFromStuff) { //If made from stuff List <FloatMenuOption> stuffList = new List <FloatMenuOption>(); foreach (ThingDef stuff in DefDatabase <ThingDef> .AllDefs) { if (stuff.IsStuff && thing.stuffCategories.SharesElementWith(stuff.stuffProps .categories)) { stuffList.Add(new FloatMenuOption( stuff.LabelCap + " - Total Value: " + (StatWorker_MarketValue.CalculatedBaseMarketValue(thing, stuff)), delegate { selectedUnit.wearEquipment( ThingMaker.MakeThing(thing, stuff) as Apparel, true); })); } } stuffList.Sort(FactionColonies.CompareFloatMenuOption); FloatMenu stuffWindow = new Searchable_FloatMenu(stuffList); Find.WindowStack.Add(stuffWindow); } else { //If not made from stuff selectedUnit.wearEquipment(ThingMaker.MakeThing(thing) as Apparel, true); } }, thing)); } } } list.Sort(FactionColonies.CompareFloatMenuOption); list.Insert(0, new FloatMenuOption("unitActionUnequipThing".Translate(), delegate { //Remove old foreach (Apparel apparel in selectedUnit.defaultPawn.apparel.WornApparel) { if (apparel.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Legs) && apparel.def.apparel.layers.Contains(ApparelLayerDefOf.OnSkin)) //CHANGE THIS { selectedUnit.defaultPawn.apparel.Remove(apparel); break; } } })); FloatMenu menu = new Searchable_FloatMenu(list); Find.WindowStack.Add(menu); } //Apparel Belt Slot if (Widgets.ButtonInvisible(ApparelBelt)) { List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (ThingDef thing in DefDatabase <ThingDef> .AllDefs) { if (thing.IsApparel) { if (thing.apparel.layers.Contains(ApparelLayerDefOf.Belt) && FactionColonies.canCraftItem(thing)) { list.Add(new FloatMenuOption(thing.LabelCap + " - Cost: " + thing.BaseMarketValue, delegate { if (thing.MadeFromStuff) { //If made from stuff List <FloatMenuOption> stuffList = new List <FloatMenuOption>(); foreach (ThingDef stuff in DefDatabase <ThingDef> .AllDefs) { if (stuff.IsStuff && thing.stuffCategories.SharesElementWith(stuff.stuffProps .categories)) { stuffList.Add(new FloatMenuOption( stuff.LabelCap + " - Total Value: " + (StatWorker_MarketValue.CalculatedBaseMarketValue(thing, stuff)), delegate { selectedUnit.wearEquipment( ThingMaker.MakeThing(thing, stuff) as Apparel, true); })); } } stuffList.Sort(FactionColonies.CompareFloatMenuOption); FloatMenu stuffWindow = new Searchable_FloatMenu(stuffList); Find.WindowStack.Add(stuffWindow); } else { //If not made from stuff //Remove old equipment foreach (Apparel apparel in selectedUnit.defaultPawn.apparel .WornApparel) { if (apparel.def.apparel.layers.Contains(ApparelLayerDefOf.Belt)) { selectedUnit.defaultPawn.apparel.Remove(apparel); break; } } selectedUnit.wearEquipment(ThingMaker.MakeThing(thing) as Apparel, true); } }, thing)); } } } list.Sort(FactionColonies.CompareFloatMenuOption); list.Insert(0, new FloatMenuOption("unitActionUnequipThing".Translate(), delegate { //Remove old foreach (Apparel apparel in selectedUnit.defaultPawn.apparel.WornApparel) { if (apparel.def.apparel.layers.Contains(ApparelLayerDefOf.Belt)) { selectedUnit.defaultPawn.apparel.Remove(apparel); break; } } })); FloatMenu menu = new Searchable_FloatMenu(list); Find.WindowStack.Add(menu); } //worn items float totalCost = 0; int i = 0; totalCost += (float)Math.Floor(selectedUnit.defaultPawn.def.BaseMarketValue * FactionColonies.militaryRaceCostMultiplier); foreach (Thing thing in selectedUnit.defaultPawn.apparel.WornApparel.Concat(selectedUnit.defaultPawn .equipment.AllEquipmentListForReading)) { Rect tmp = new Rect(ApparelWornItems.x, ApparelWornItems.y + i * 25, ApparelWornItems.width, 25); i++; totalCost += thing.MarketValue; if (Widgets.CustomButtonText(ref tmp, thing.LabelCap + " Cost: " + thing.MarketValue, Color.white, Color.black, Color.black)) { Find.WindowStack.Add(new Dialog_InfoCard(thing)); } } if (selectedUnit.animal != null) { Widgets.ButtonImage(AnimalCompanion, selectedUnit.animal.race.uiIcon); totalCost += (float)Math.Floor(selectedUnit.animal.race.BaseMarketValue * FactionColonies.militaryAnimalCostMultiplier); } foreach (Thing thing in selectedUnit.defaultPawn.apparel.WornApparel) { //Log.Message(thing.Label); if (thing.def.apparel.layers.Contains(ApparelLayerDefOf.Overhead)) { Widgets.ButtonImage(ApparelHead, thing.def.uiIcon); } if (thing.def.apparel.layers.Contains(ApparelLayerDefOf.Belt)) { Widgets.ButtonImage(ApparelBelt, thing.def.uiIcon); } if (thing.def.apparel.layers.Contains(ApparelLayerDefOf.Shell) && thing.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso)) { Widgets.ButtonImage(ApparelTorsoShell, thing.def.uiIcon); } if (thing.def.apparel.layers.Contains(ApparelLayerDefOf.Middle) && thing.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso)) { Widgets.ButtonImage(ApparelTorsoMiddle, thing.def.uiIcon); } if (thing.def.apparel.layers.Contains(ApparelLayerDefOf.OnSkin) && thing.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso)) { Widgets.ButtonImage(ApparelTorsoSkin, thing.def.uiIcon); } if (thing.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Legs) && thing.def.apparel.layers.Contains(ApparelLayerDefOf.OnSkin)) { Widgets.ButtonImage(ApparelLegs, thing.def.uiIcon); } } foreach (Thing thing in selectedUnit.defaultPawn.equipment.AllEquipmentListForReading) { Widgets.ButtonImage(EquipmentWeapon, thing.def.uiIcon); } totalCost = (float)Math.Ceiling(totalCost); Widgets.Label(EquipmentTotalCost, "totalEquipmentCostLabel".Translate() + totalCost); }
public override void DoWindowContents(Rect inRect) { //grab before anchor/font GameFont fontBefore = Text.Font; TextAnchor anchorBefore = Text.Anchor; //Settlement Tax Collection Header Text.Anchor = TextAnchor.MiddleLeft; Text.Font = GameFont.Medium; Widgets.Label(labelFaction, header); Text.Font = GameFont.Small; Widgets.Label(labelFactionName, "FactionName".Translate() + ":"); name = Widgets.TextField(textfieldName, name); Widgets.Label(labelFactionTitle, "FactionTitle".Translate() + ":"); title = Widgets.TextField(textfieldTitle, title); Widgets.Label(labelFactionIcon, "FactionIcon".Translate()); if (Widgets.ButtonImage(buttonIcon, tempFactionIcon)) { List <FloatMenuOption> list = TexLoad.factionIcons.Select(texture => new FloatMenuOption(texture.name, delegate { tempFactionIcon = texture; tempFactionIconPath = texture.name; }, texture, Color.white)).ToList(); FloatMenu menu = new FloatMenu(list); Find.WindowStack.Add(menu); } if (Widgets.ButtonTextSubtle(buttonAllowedRaces, "AllowedRaces".Translate())) { List <FloatMenuOption> list = new List <FloatMenuOption> { new FloatMenuOption("Enable All", delegate { faction.resetRaceFilter(); }) }; List <string> races = new List <string>(); foreach (PawnKindDef def in DefDatabase <PawnKindDef> .AllDefsListForReading.Where(def => def.IsHumanlikeWithLabelRace() && !races.Contains(def.race.label))) { if (def.race.label == "Human" && def.LabelCap != "Colonist") { continue; } races.Add(def.race.label); list.Add(new FloatMenuOption( def.race.label.CapitalizeFirst() + " - Allowed: " + faction.raceFilter.Allows(def.race), delegate { if (faction.raceFilter.AllowedThingDefs.Count() == 1 && faction.raceFilter.Allows(def.race)) { Messages.Message("CannotHaveLessThanOneRace".Translate(), MessageTypeDefOf.RejectInput); } else if (faction.raceFilter.AllowedThingDefs.Count() > 0) { if (!faction.raceFilter.SetAllow(def.race, !faction.raceFilter.Allows(def.race))) { Messages.Message(new Message("InvalidFaction".Translate(), MessageTypeDefOf.RejectInput)); } } else { Log.Message("Empire Error - Zero races available for faction - Report this"); Log.Message("Resetting race filter"); faction.resetRaceFilter(); } })); } FloatMenu menu = new FloatMenu(list); Find.WindowStack.Add(menu); } if (Widgets.ButtonText(buttonConfirm, "ConfirmChanges".Translate())) { Faction fact = FactionColonies.getPlayerColonyFaction(); faction.title = title; faction.name = name; fact.Name = name; faction.name = name; faction.factionIconPath = tempFactionIconPath; faction.factionIcon = tempFactionIcon; faction.updateFactionRaces(); faction.factionBackup = fact; faction.updateFactionIcon(ref fact, "FactionIcons/" + tempFactionIconPath); if (!traitsChosen) { //check each trait bool. If true and does not exist already, add to factionfc if (boolMilitaristic) { faction.policies.Add(new FCPolicy(FCPolicyDefOf.militaristic)); } if (boolPacifist) { faction.policies.Add(new FCPolicy(FCPolicyDefOf.pacifist)); } if (boolAuthoritarian) { faction.policies.Add(new FCPolicy(FCPolicyDefOf.authoritarian)); } if (boolEgalitarian) { faction.policies.Add(new FCPolicy(FCPolicyDefOf.egalitarian)); } if (boolIsolationist) { faction.policies.Add(new FCPolicy(FCPolicyDefOf.isolationist)); } if (boolExpansionist) { faction.policies.Add(new FCPolicy(FCPolicyDefOf.expansionist)); } if (boolTechnocrat) { faction.policies.Add(new FCPolicy(FCPolicyDefOf.technocratic)); } if (boolFeudal) { faction.policies.Add(new FCPolicy(FCPolicyDefOf.feudal)); } } Find.WindowStack.TryRemove(this); } if (!traitsChosen) { switch (faction.policies.Count()) { case 0: case 1: alertText = "FCSelectTraits0".Translate(); break; case 2: alertText = "FCSelectTraits2".Translate(); break; } } else { alertText = "FCTraitsChosen".Translate(); } Widgets.Label(labelPickTrait, alertText); Texture2D icon = TexLoad.iconLoyalty; if (boolMilitaristic) { icon = FCPolicyDefOf.militaristic.IconLight; } else { icon = FCPolicyDefOf.militaristic.IconDark; } if (buttonMilitaristic.Contains(Event.current.mousePosition)) { TooltipHandler.TipRegion(buttonMilitaristic, returnPolicyText(FCPolicyDefOf.militaristic)); } if (Widgets.ButtonImage(buttonMilitaristic, icon)) { if (numberTraitsSelected <= 1 || boolMilitaristic) { //Continue if (boolPacifist == false) { boolMilitaristic = !boolMilitaristic; if (boolMilitaristic) { numberTraitsSelected += 1; } else { numberTraitsSelected -= 1; } policyText = returnPolicyText(FCPolicyDefOf.militaristic); } else { Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput); } } else { Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput); } } if (boolAuthoritarian) { icon = FCPolicyDefOf.authoritarian.IconLight; } else { icon = FCPolicyDefOf.authoritarian.IconDark; } if (buttonAuthoritarian.Contains(Event.current.mousePosition)) { TooltipHandler.TipRegion(buttonAuthoritarian, returnPolicyText(FCPolicyDefOf.authoritarian)); } if (Widgets.ButtonImage(buttonAuthoritarian, icon)) { if (numberTraitsSelected <= 1 || boolAuthoritarian) { //Continue if (boolEgalitarian == false) { boolAuthoritarian = !boolAuthoritarian; if (boolAuthoritarian) { numberTraitsSelected += 1; } else { numberTraitsSelected -= 1; } policyText = returnPolicyText(FCPolicyDefOf.authoritarian); } else { Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput); } } else { Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput); } } if (boolIsolationist) { icon = FCPolicyDefOf.isolationist.IconLight; } else { icon = FCPolicyDefOf.isolationist.IconDark; } if (buttonIsolationist.Contains(Event.current.mousePosition)) { TooltipHandler.TipRegion(buttonIsolationist, returnPolicyText(FCPolicyDefOf.isolationist)); } if (Widgets.ButtonImage(buttonIsolationist, icon)) { if (numberTraitsSelected <= 1 || boolIsolationist) { //Continue if (boolExpansionist == false) { boolIsolationist = !boolIsolationist; if (boolIsolationist) { numberTraitsSelected += 1; } else { numberTraitsSelected -= 1; } policyText = returnPolicyText(FCPolicyDefOf.isolationist); } else { Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput); } } else { Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput); } } if (boolFeudal) { icon = FCPolicyDefOf.feudal.IconLight; } else { icon = FCPolicyDefOf.feudal.IconDark; } if (buttonFeudal.Contains(Event.current.mousePosition)) { TooltipHandler.TipRegion(buttonFeudal, returnPolicyText(FCPolicyDefOf.feudal)); } if (Widgets.ButtonImage(buttonFeudal, icon)) { if (numberTraitsSelected <= 1 || boolFeudal) { //Continue if (boolTechnocrat == false) { boolFeudal = !boolFeudal; if (boolFeudal) { numberTraitsSelected += 1; } else { numberTraitsSelected -= 1; } policyText = returnPolicyText(FCPolicyDefOf.feudal); } else { Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput); } } else { Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput); } } if (boolPacifist) { icon = FCPolicyDefOf.pacifist.IconLight; } else { icon = FCPolicyDefOf.pacifist.IconDark; } if (buttonPacifist.Contains(Event.current.mousePosition)) { TooltipHandler.TipRegion(buttonPacifist, returnPolicyText(FCPolicyDefOf.pacifist)); } if (Widgets.ButtonImage(buttonPacifist, icon)) { if (numberTraitsSelected <= 1 || boolPacifist) { //Continue if (boolMilitaristic == false) { boolPacifist = !boolPacifist; if (boolPacifist) { numberTraitsSelected += 1; } else { numberTraitsSelected -= 1; } policyText = returnPolicyText(FCPolicyDefOf.pacifist); } else { Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput); } } else { Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput); } } if (boolEgalitarian) { icon = FCPolicyDefOf.egalitarian.IconLight; } else { icon = FCPolicyDefOf.egalitarian.IconDark; } if (buttonEgalitarian.Contains(Event.current.mousePosition)) { TooltipHandler.TipRegion(buttonEgalitarian, returnPolicyText(FCPolicyDefOf.egalitarian)); } if (Widgets.ButtonImage(buttonEgalitarian, icon)) { if (numberTraitsSelected <= 1 || boolEgalitarian) { //Continue if (boolAuthoritarian == false) { boolEgalitarian = !boolEgalitarian; if (boolEgalitarian) { numberTraitsSelected += 1; } else { numberTraitsSelected -= 1; } policyText = returnPolicyText(FCPolicyDefOf.egalitarian); } else { Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput); } } else { Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput); } } if (boolExpansionist) { icon = FCPolicyDefOf.expansionist.IconLight; } else { icon = FCPolicyDefOf.expansionist.IconDark; } if (buttonExpansionist.Contains(Event.current.mousePosition)) { TooltipHandler.TipRegion(buttonExpansionist, returnPolicyText(FCPolicyDefOf.expansionist)); } if (Widgets.ButtonImage(buttonExpansionist, icon)) { if (numberTraitsSelected <= 1 || boolExpansionist) { //Continue if (boolIsolationist == false) { boolExpansionist = !boolExpansionist; if (boolExpansionist) { numberTraitsSelected += 1; } else { numberTraitsSelected -= 1; } policyText = returnPolicyText(FCPolicyDefOf.expansionist); } else { Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput); } } else { Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput); } } if (boolTechnocrat) { icon = FCPolicyDefOf.technocratic.IconLight; } else { icon = FCPolicyDefOf.technocratic.IconDark; } if (buttonTechnocrat.Contains(Event.current.mousePosition)) { TooltipHandler.TipRegion(buttonTechnocrat, returnPolicyText(FCPolicyDefOf.technocratic)); } if (Widgets.ButtonImage(buttonTechnocrat, icon)) { if (numberTraitsSelected <= 1 || boolTechnocrat) { //Continue if (boolFeudal == false) { boolTechnocrat = !boolTechnocrat; if (boolTechnocrat) { numberTraitsSelected += 1; } else { numberTraitsSelected -= 1; } policyText = returnPolicyText(FCPolicyDefOf.technocratic); } else { Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput); } } else { Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput); } } //Widgets.DrawMenuSection(menusectionTrait); //Widgets.Label(menusectionTrait, policyText); //reset anchor/font Text.Font = fontBefore; Text.Anchor = anchorBefore; }
public void DrawButtons(int x, int y, int length, int size, int set) { Text.Anchor = TextAnchor.MiddleCenter; Text.Font = GameFont.Tiny; if (set == 1) { for (int i = 0; i < buttons.Count(); i++) { if (Widgets.ButtonText(new Rect(x, y + ((size + 10) * i), length, size), buttons[i])) { //If click a button button if (buttons[i] == "UpgradeTown".Translate()) { //if click upgrade town button Find.WindowStack.Add(new SettlementUpgradeWindowFc(settlement)); //Log.Message(buttons[i]); } if (buttons[i] == "AreYouSureRemove".Translate()) { //if click to delete colony Find.WindowStack.TryRemove(this); FactionColonies.removePlayerSettlement(settlement); } if (buttons[i] == "DeleteSettlement".Translate()) { //if click town log button //Log.Message(buttons[i]); buttons[i] = "AreYouSureRemove".Translate(); } if (buttons[i] == "FCSpecialActions".Translate()) { List <FloatMenuOption> list = new List <FloatMenuOption> { //Add to all new FloatMenuOption("GoToLocation".Translate(), delegate { Find.WindowStack.TryRemove(this); settlement.goTo(); }) }; if (factionfc.hasPolicy(FCPolicyDefOf.authoritarian)) { list.Add(new FloatMenuOption("FCBuyLoyalty".Translate(), delegate { Find.WindowStack.Add(new FCWindow_Pay_Silver(settlement)); })); } if (factionfc.hasPolicy(FCPolicyDefOf.egalitarian)) { list.Add(new FloatMenuOption("FCGiveTaxBreak".Translate(), delegate { if (settlement.trait_Egalitarian_TaxBreak_Enabled == false) { Find.WindowStack.Add(new FCWindow_Confirm_TaxBreak(settlement)); } else { Messages.Message( "FCAlreadyGivingTaxBreak".Translate(Math.Round( (settlement.trait_Egalitarian_TaxBreak_Tick + GenDate.TicksPerDay * 10 - Find.TickManager.TicksGame) / (double)GenDate.TicksPerDay, 1)), MessageTypeDefOf.RejectInput); } })); } if (list.Count() == 0) { list.Add(new FloatMenuOption("No special actions to take", delegate { })); } Find.WindowStack.Add(new FloatMenu(list)); } if (buttons[i] == "PrisonersMenu".Translate()) { Find.WindowStack.Add(new FCPrisonerMenu(settlement)); } if (buttons[i] == "Military".Translate()) { List <FloatMenuOption> list = new List <FloatMenuOption> { new FloatMenuOption( "ToggleAutoDefend".Translate(settlement.autoDefend.ToString()), delegate { settlement.autoDefend = !settlement.autoDefend; Messages.Message("autoDefendWarning".Translate(), MessageTypeDefOf.CautionInput); }) }; if (settlement.isUnderAttack) { FCEvent evt = MilitaryUtilFC.returnMilitaryEventByLocation(settlement.mapLocation); list.Add(new FloatMenuOption( "SettlementDefendingInformation".Translate( evt.militaryForceDefending.homeSettlement.name, evt.militaryForceDefending.militaryLevel), null, MenuOptionPriority.High)); list.Add(new FloatMenuOption("ChangeDefendingForce".Translate(), delegate { List <FloatMenuOption> settlementList = new List <FloatMenuOption>(); SettlementFC homeSettlement = settlement; settlementList.Add(new FloatMenuOption( "ResetToHomeSettlement".Translate(homeSettlement.settlementMilitaryLevel), delegate { MilitaryUtilFC.changeDefendingMilitaryForce(evt, homeSettlement); }, MenuOptionPriority.High)); foreach (SettlementFC settlement in Find.World.GetComponent <FactionFC>().settlements ) { if (settlement.isMilitaryValid() && settlement != homeSettlement) { //if military is valid to use. settlementList.Add(new FloatMenuOption( settlement.name + " " + "ShortMilitary".Translate() + " " + settlement.settlementMilitaryLevel + " - " + "FCAvailable".Translate() + ": " + (!settlement.isMilitaryBusySilent()).ToString(), delegate { if (settlement.isMilitaryBusy()) { //military is busy } else { MilitaryUtilFC.changeDefendingMilitaryForce(evt, settlement); } } )); } } if (settlementList.Count == 0) { settlementList.Add(new FloatMenuOption("NoValidMilitaries".Translate(), null)); } Find.WindowStack.Add(new FloatMenuSearchable(settlementList) { vanishIfMouseDistant = true }); //set to raid settlement here })); Find.WindowStack.Add(new FloatMenu(list)); } else { list.Add(new FloatMenuOption("SettlementNotBeingAttacked".Translate(), null)); Find.WindowStack.Add(new FloatMenu(list)); } } } } } //set two buttons }
private void DrawFactionButtons(Rect inRect, int buttonSize) //Used to draw a list of buttons from the 'buttons' list { Text.Anchor = TextAnchor.MiddleCenter; Text.Font = GameFont.Small; for (int i = 0; i < buttons.Count; i++) { if (Widgets.ButtonText(new Rect(140, 110 + ((buttonSize + 5) * i), 170, buttonSize), buttons[i])) { if (buttons[i] == "FCOverview".Translate()) { //if click trade policy button //Log.Message(buttons[i]); Log.Message("Success"); Find.WindowStack.Add(new FCWindow_Overview()); } if (buttons[i] == "Military".Translate()) { if (FactionColonies.getPlayerColonyFaction() == null) { Messages.Message(new Message("NoFactionForMilitary".Translate(), MessageTypeDefOf.RejectInput)); } else { Find.WindowStack.Add(new MilitaryCustomizationWindowFc()); } } if (buttons[i] == "Actions".Translate()) { List <FloatMenuOption> list = new List <FloatMenuOption>(); list.Add(new FloatMenuOption("TaxDeliveryMap".Translate(), delegate { List <FloatMenuOption> list2 = new List <FloatMenuOption>(); list2.Add(new FloatMenuOption("SetMap".Translate(), delegate { List <FloatMenuOption> settlementList = new List <FloatMenuOption>(); foreach (Map map in Find.Maps) { if (map.IsPlayerHome) { settlementList.Add(new FloatMenuOption(map.Parent.LabelCap, delegate { faction.taxMap = map; Find.LetterStack.ReceiveLetter("Map Set!", "The tax delivery map has been set to the player colony of " + map.Parent.LabelCap + ".\n All taxes and other goods will be delivered there", LetterDefOf.NeutralEvent); } )); } } if (settlementList.Count == 0) { settlementList.Add(new FloatMenuOption("No valid settlements to use.", null)); } FloatMenu floatMenu2 = new FloatMenu(settlementList); floatMenu2.vanishIfMouseDistant = true; Find.WindowStack.Add(floatMenu2); })); FloatMenu floatMenu = new FloatMenu(list2); floatMenu.vanishIfMouseDistant = true; Find.WindowStack.Add(floatMenu); })); list.Add(new FloatMenuOption("SetCapital".Translate(), delegate { faction.setCapital(); })); list.Add(new FloatMenuOption("ActivateResearch".Translate(), delegate { faction.updateDailyResearch(); })); list.Add(new FloatMenuOption("ResearchLevel".Translate(), delegate { Messages.Message("CurrentResearchLevel".Translate(faction.techLevel.ToString(), faction.returnNextTechToLevel()), MessageTypeDefOf.NeutralEvent); })); if (faction.hasPolicy(FCPolicyDefOf.technocratic)) { list.Add(new FloatMenuOption("FCSendResearchItems".Translate(), delegate { if (Find.ColonistBar.GetColonistsInOrder().Count > 0) { Pawn playerNegotiator = Find.ColonistBar.GetColonistsInOrder()[0]; //Log.Message(playerNegotiator.Name + " Negotiator"); FCTrader_Research trader = new FCTrader_Research(); Find.WindowStack.Add(new Dialog_Trade(playerNegotiator, trader)); } else { Log.Message("Where are all the colonists?"); } })); } if (faction.hasPolicy(FCPolicyDefOf.feudal)) { list.Add(new FloatMenuOption("FCRequestMercenary".Translate(), delegate { if (faction.traitFeudalBoolCanUseMercenary) { faction.traitFeudalBoolCanUseMercenary = false; faction.traitFeudalTickLastUsedMercenary = Find.TickManager.TicksGame; PawnGenerationRequest request = FCPawnGenerator.WorkerOrMilitaryRequest; request.ColonistRelationChanceFactor = 20f; Pawn pawn = PawnGenerator.GeneratePawn(request); IncidentParms parms = new IncidentParms { target = Find.CurrentMap, faction = FactionColonies.getPlayerColonyFaction(), points = 999, raidArrivalModeForQuickMilitaryAid = true, raidNeverFleeIndividual = true, raidForceOneIncap = true, raidArrivalMode = PawnsArrivalModeDefOf.CenterDrop, raidStrategy = RaidStrategyDefOf.ImmediateAttackFriendly }; parms.raidArrivalModeForQuickMilitaryAid = true; PawnsArrivalModeWorker_EdgeWalkIn worker = new PawnsArrivalModeWorker_EdgeWalkIn(); worker.TryResolveRaidSpawnCenter(parms); worker.Arrive(new List <Pawn> { pawn }, parms); Find.LetterStack.ReceiveLetter("FCMercenaryJoined".Translate(), "FCMercenaryJoinedText".Translate(pawn.NameFullColored), LetterDefOf.PositiveEvent, new LookTargets(pawn)); pawn.SetFaction(Faction.OfPlayer); } else { Messages.Message("FCActionMercenaryOnCooldown".Translate(((faction.traitFeudalTickLastUsedMercenary + GenDate.TicksPerSeason) - Find.TickManager.TicksGame).ToTimeString()), MessageTypeDefOf.RejectInput); } })); } FloatMenu menu = new FloatMenu(list); Find.WindowStack.Add(menu); } } } }
public override void DoWindowContents(Rect inRect) { //grab before anchor/font GameFont fontBefore = Text.Font; TextAnchor anchorBefore = Text.Anchor; //top label Text.Font = GameFont.Small; Text.Anchor = TextAnchor.MiddleCenter; Text.Anchor = TextAnchor.MiddleLeft; int i = 0; foreach (FCPrisoner prisoner in prisoners) { Rect Box; Rect PawnIcon; Rect PawnName; Rect PawnHealth; Rect PawnUnrest; Rect PawnWorkload; Rect ButtonInfo; Rect ButtonAction; Box = optionBox; PawnIcon = optionPawnIcon; PawnName = optionPawnName; PawnHealth = optionPawnHealth; PawnUnrest = optionPawnUnrest; PawnWorkload = optionPawnWorkload; ButtonInfo = optionButtonInfo; ButtonAction = optionButtonAction; Box.y += scroll + optionHeight * i; PawnIcon.y += scroll + optionHeight * i; PawnName.y += scroll + optionHeight * i; PawnHealth.y += scroll + optionHeight * i; PawnUnrest.y += scroll + optionHeight * i; PawnWorkload.y += scroll + optionHeight * i; ButtonInfo.y += scroll + optionHeight * i; ButtonAction.y += scroll + optionHeight * i; //display stuff now Widgets.DrawMenuSection(Box); //on every other box if (i % 2 == 0) { Widgets.DrawHighlight(Box); } //show pawn; Widgets.ThingIcon(PawnIcon, prisoner.prisoner); //Pawn Name Widgets.Label(PawnName, prisoner.prisoner.Name.ToString()); //Pawn Health Widgets.Label(PawnHealth, "Health".Translate().CapitalizeFirst() + " " + prisoner.health); //Pawn Unrest //Widgets.Label(PawnUnrest, "Unrest".Translate().CapitalizeFirst() + " " + prisoner.unrest); //Pawn Workload string workload; switch (prisoner.workload) { case FCWorkLoad.Heavy: workload = "FCHeavy".Translate().CapitalizeFirst(); break; case FCWorkLoad.Medium: workload = "FCMedium".Translate().CapitalizeFirst(); break; case FCWorkLoad.Light: workload = "FCLight".Translate().CapitalizeFirst(); break; default: workload = "null"; break; } if (Widgets.ButtonText(PawnWorkload, "FCWorkload".Translate().CapitalizeFirst() + ": " + workload)) { List <FloatMenuOption> list = new List <FloatMenuOption>(); list.Add(new FloatMenuOption("FCHeavy".Translate().CapitalizeFirst() + " - " + "FCHeavyExplanation".Translate(), delegate { prisoner.workload = FCWorkLoad.Heavy; })); list.Add(new FloatMenuOption("FCMedium".Translate().CapitalizeFirst() + " - " + "FCMediumExplanation".Translate(), delegate { prisoner.workload = FCWorkLoad.Medium; })); list.Add(new FloatMenuOption("FCLight".Translate().CapitalizeFirst() + " - " + "FCLightExplanation".Translate(), delegate { prisoner.workload = FCWorkLoad.Light; })); FloatMenu menu = new FloatMenu(list); Find.WindowStack.Add(menu); } //Info Button if (Widgets.ButtonTextSubtle(ButtonInfo, "ViewInfo".Translate())) { Pawn pawn = new Pawn(); pawn = prisoner.prisoner; if (prisoner.healthTracker != null) { prisoner.prisoner.health = prisoner.healthTracker; } else { prisoner.prisoner.health = new Pawn_HealthTracker(prisoner.prisoner); prisoner.healthTracker = new Pawn_HealthTracker(prisoner.prisoner); } pawn.health = prisoner.healthTracker; Find.WindowStack.Add(new Dialog_InfoCard(pawn)); } //Action button if (Widgets.ButtonTextSubtle(ButtonAction, "Actions".Translate())) { List <FloatMenuOption> list = new List <FloatMenuOption>(); list.Add(new FloatMenuOption("SellPawn".Translate() + " $" + prisoner.prisoner.MarketValue + " " + "SellPawnInfo".Translate(), delegate { settlement.addSilverIncome(prisoner.prisoner.MarketValue); //reset window prisoners.Remove(prisoner); WindowUpdate(); return; })); list.Add(new FloatMenuOption("ReturnToPlayer".Translate(), delegate { if (prisoner.healthTracker != null) { prisoner.prisoner.health = prisoner.healthTracker; } else { prisoner.prisoner.health = new Pawn_HealthTracker(prisoner.prisoner); prisoner.healthTracker = new Pawn_HealthTracker(prisoner.prisoner); } if (!HealthUtility.TryAnesthetize(prisoner.prisoner)) { HealthUtility.DamageUntilDowned(prisoner.prisoner, false); } if (prisoner.prisoner.guest == null) { prisoner.prisoner.guest = new Pawn_GuestTracker(); } prisoner.prisoner.guest.guestStatusInt = GuestStatus.Prisoner; FieldInfo hostFaction = typeof(Pawn_GuestTracker).GetField("hostFactionInt", BindingFlags.NonPublic | BindingFlags.Instance); hostFaction.SetValue(prisoner.prisoner.guest, Find.FactionManager.OfPlayer); DeliveryEvent.CreateDeliveryEvent(new FCEvent { location = Find.AnyPlayerHomeMap.Tile, source = settlement.mapLocation, planetName = settlement.planetName, goods = new List <Thing> { prisoner.prisoner }, customDescription = "aPrisonerIsBeingDeliveredToYou".Translate(), timeTillTrigger = Find.TickManager.TicksGame + FactionColonies.ReturnTicksToArrive(settlement.mapLocation, Find.AnyPlayerHomeMap.Tile) }); //reset window prisoners.Remove(prisoner); WindowUpdate(); return; })); FloatMenu menu = new FloatMenu(list); Find.WindowStack.Add(menu); } //increment i i++; } Text.Font = fontBefore; Text.Anchor = anchorBefore; if (Event.current.type == EventType.ScrollWheel) { scrollWindow(Event.current.delta.y); } }
private void DrawResources(int x, int y, int spacing) { foreach (ResourceType resourceType in ResourceUtils.resourceTypes) { ResourceFC resource = settlement.getResource(resourceType); float rectY = scroll + y + 70 + (int)resourceType * (45 + spacing); //Don't draw if outside view if ((int)resourceType * ScrollSpacing + scroll < 0) { continue; } bool titheDisabled = false; if (ShouldTitheBeLockedForResouceType(resourceType)) { titheDisabled = true; } else if (Widgets.ButtonImage(new Rect(x - 15, scroll + y + 65 + (int)resourceType * (45 + spacing) + 8, 20, 20), TexLoad.iconCustomize)) { TitheCustomizationClicked(resource, resourceType); } Widgets.Checkbox(new Vector2(x + 8, scroll + y + 65 + (int)resourceType * (45 + spacing) + 8), ref resource.isTithe, 24, titheDisabled); DoTitheCheckboxAction(resource.isTithe != resource.isTitheBool, resource); DoResourceDescriptionButton(resource, resourceType, x, y, spacing); //Production Efficiency Widgets.DrawBox(new Rect(x + 80, rectY, 100, 20)); Widgets.FillableBar(new Rect(x + 80, rectY, 100, 20), (float)Math.Min(resource.baseProductionMultiplier, 1.0)); Widgets.Label(new Rect(x + 80, scroll + y + 90 + (int)resourceType * (45 + spacing), 100, 20), "Workers".Translate() + ": " + resource.assignedWorkers); if (Widgets.ButtonText(new Rect(x + 80, scroll + y + 90 + (int)resourceType * (45 + spacing), 20, 20), "<")) { IncreaseWorkers(resourceType, true); } if (Widgets.ButtonText(new Rect(x + 160, scroll + y + 90 + (int)resourceType * (45 + spacing), 20, 20), ">")) { IncreaseWorkers(resourceType); } //Base Production Widgets.Label(new Rect(x + 195, rectY, 45, 40), FactionColonies.FloorStat(resource.baseProduction)); //Final Modifier Widgets.Label(new Rect(x + 250, rectY, 50, 40), FactionColonies.FloorStat(resource.endProductionMultiplier)); //Final Base Widgets.Label(new Rect(x + 310, rectY, 45, 40), (FactionColonies.FloorStat(resource.endProduction))); //Est Income Widgets.Label(new Rect(x + 365, rectY, 45, 40), (FactionColonies.FloorStat(resource.endProduction * LoadedModManager .GetMod <FactionColoniesMod>().GetSettings <FactionColonies>().silverPerResource))); //Tithe Percentage resource.returnTaxPercentage(); string taxPercentage = FactionColonies.FloorStat(resource.taxPercentage) + "%"; Widgets.Label(new Rect(x + 420, rectY, 45, 40), taxPercentage); } }
private void DrawFactionButtons(Rect inRect, int buttonSize) //Used to draw a list of buttons from the 'buttons' list { Text.Anchor = TextAnchor.MiddleCenter; Text.Font = GameFont.Small; for (int i = 0; i < buttons.Count; i++) { if (Widgets.ButtonText(new Rect(140, 110 + ((buttonSize + 5) * i), 170, buttonSize), buttons[i])) { if (buttons[i] == "FCOverview".Translate()) { //if click trade policy button //Log.Message(buttons[i]); Log.Message("Success"); Find.WindowStack.Add(new FCWindow_Overview()); } if (buttons[i] == "Military".Translate()) { if (FactionColonies.getPlayerColonyFaction() == null) { Messages.Message(new Message("NoFactionForMilitary".Translate(), MessageTypeDefOf.RejectInput)); } else { Find.WindowStack.Add(new militaryCustomizationWindowFC()); } } if (buttons[i] == "Actions".Translate()) { List <FloatMenuOption> list = new List <FloatMenuOption>(); list.Add(new FloatMenuOption("TaxDeliveryMap".Translate(), delegate { List <FloatMenuOption> list2 = new List <FloatMenuOption>(); list2.Add(new FloatMenuOption("SetMap".Translate(), delegate { List <FloatMenuOption> settlementList = new List <FloatMenuOption>(); foreach (Map map in Find.Maps) { if (map.IsPlayerHome) { settlementList.Add(new FloatMenuOption(map.Parent.LabelCap, delegate { faction.taxMap = map; Find.LetterStack.ReceiveLetter("Map Set!", "The tax delivery map has been set to the player colony of " + map.Parent.LabelCap + ".\n All taxes and other goods will be delivered there", LetterDefOf.NeutralEvent); } )); } } if (settlementList.Count == 0) { settlementList.Add(new FloatMenuOption("No valid settlements to use.", null)); } FloatMenu floatMenu2 = new FloatMenu(settlementList); floatMenu2.vanishIfMouseDistant = true; Find.WindowStack.Add(floatMenu2); })); FloatMenu floatMenu = new FloatMenu(list2); floatMenu.vanishIfMouseDistant = true; Find.WindowStack.Add(floatMenu); })); list.Add(new FloatMenuOption("SetCapital".Translate(), delegate { faction.setCapital(); })); list.Add(new FloatMenuOption("ActivateResearch".Translate(), delegate { faction.updateDailyResearch(); })); list.Add(new FloatMenuOption("ResearchLevel".Translate(), delegate { Messages.Message("CurrentResearchLevel".Translate(faction.techLevel.ToString(), faction.returnNextTechToLevel()), MessageTypeDefOf.NeutralEvent); })); if (faction.hasPolicy(FCPolicyDefOf.technocratic)) { list.Add(new FloatMenuOption("FCSendResearchItems".Translate(), delegate { if (Find.ColonistBar.GetColonistsInOrder().Count > 0) { Pawn playerNegotiator = Find.ColonistBar.GetColonistsInOrder()[0]; //Log.Message(playerNegotiator.Name + " Negotiator"); FCTrader_Research trader = new FCTrader_Research(); Find.WindowStack.Add(new Dialog_Trade(playerNegotiator, trader)); } else { Log.Message("Where are all the colonists?"); } })); } if (faction.hasPolicy(FCPolicyDefOf.feudal)) { list.Add(new FloatMenuOption("FCRequestMercenary".Translate(), delegate { if (faction.traitFeudalBoolCanUseMercenary) { faction.traitFeudalBoolCanUseMercenary = false; faction.traitFeudalTickLastUsedMercenary = Find.TickManager.TicksGame; List <PawnKindDef> listKindDef = new List <PawnKindDef>(); foreach (ThingDef def in Find.World.GetComponent <FactionFC>().raceFilter.AllowedThingDefs) { listKindDef.Add(def.race.AnyPawnKind); } PawnGroupMaker groupMaker = FactionColonies.getPlayerColonyFaction().def.pawnGroupMakers.RandomElement(); PawnGroupMakerParms group = new PawnGroupMakerParms(); group.groupKind = groupMaker.kindDef; group.faction = FactionColonies.getPlayerColonyFaction(); group.dontUseSingleUseRocketLaunchers = true; group.generateFightersOnly = true; group.points = 2000; group.raidStrategy = RaidStrategyDefOf.ImmediateAttackFriendly; PawnKindDef pawnkind = new PawnKindDef(); PawnKindDef kind = groupMaker.GeneratePawns(group).RandomElement().kindDef; pawnkind = listKindDef.RandomElement(); pawnkind.techHediffsTags = kind.techHediffsTags; pawnkind.apparelTags = kind.apparelTags; pawnkind.isFighter = kind.isFighter; pawnkind.combatPower = kind.combatPower; pawnkind.gearHealthRange = kind.gearHealthRange; pawnkind.weaponTags = kind.weaponTags; pawnkind.apparelMoney = kind.apparelMoney; pawnkind.weaponMoney = kind.weaponMoney; pawnkind.apparelAllowHeadgearChance = kind.apparelAllowHeadgearChance; pawnkind.techHediffsMoney = kind.techHediffsMoney; pawnkind.label = kind.label; Pawn pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(pawnkind, Find.FactionManager.OfPlayer, PawnGenerationContext.NonPlayer, -1, false, false, false, false, true, false, 20f)); IncidentParms parms = new IncidentParms(); parms.target = Find.CurrentMap; parms.faction = FactionColonies.getPlayerColonyFaction(); parms.points = 999; parms.raidArrivalModeForQuickMilitaryAid = true; parms.raidNeverFleeIndividual = true; parms.raidForceOneIncap = true; parms.raidArrivalMode = PawnsArrivalModeDefOf.CenterDrop; parms.raidStrategy = RaidStrategyDefOf.ImmediateAttackFriendly; parms.raidArrivalModeForQuickMilitaryAid = true; PawnsArrivalModeWorker_EdgeWalkIn worker = new PawnsArrivalModeWorker_EdgeWalkIn(); worker.TryResolveRaidSpawnCenter(parms); worker.Arrive(new List <Pawn> { pawn }, parms); Find.LetterStack.ReceiveLetter("FCMercenaryJoined".Translate(), "FCMercenaryJoinedText".Translate(pawn.NameFullColored), LetterDefOf.PositiveEvent, new LookTargets(pawn)); } else { Messages.Message("FCActionMercenaryOnCooldown".Translate(((faction.traitFeudalTickLastUsedMercenary + GenDate.TicksPerSeason) - Find.TickManager.TicksGame).ToStringTicksToDays()), MessageTypeDefOf.RejectInput); } })); } FloatMenu menu = new FloatMenu(list); Find.WindowStack.Add(menu); } } } }
public override void DrawTab(Rect rect) { //set text anchor and font GameFont fontBefore = Text.Font; TextAnchor anchorBefore = Text.Anchor; float projectileBoxHeight = 30; Rect SelectionBar = new Rect(5, 45, 200, 30); Rect nameTextField = new Rect(5, 90, 250, 30); Rect floatRangeAccuracyLabel = new Rect(nameTextField.x, nameTextField.y + nameTextField.height + 5, nameTextField.width, (float)(nameTextField.height * 1.5)); Rect floatRangeAccuracy = new Rect(floatRangeAccuracyLabel.x, floatRangeAccuracyLabel.y + floatRangeAccuracyLabel.height + 5, floatRangeAccuracyLabel.width, floatRangeAccuracyLabel.height); Rect UnitStandBase = new Rect(140, 200, 50, 30); Rect TotalCost = new Rect(325, 50, 450, 20); Rect numberProjectiles = new Rect(TotalCost.x, TotalCost.y + TotalCost.height + 5, TotalCost.width, TotalCost.height); Rect duration = new Rect(numberProjectiles.x, numberProjectiles.y + numberProjectiles.height + 5, numberProjectiles.width, numberProjectiles.height); Rect ResetButton = new Rect(700 - 2, 100, 100, 30); Rect DeleteButton = new Rect(ResetButton.x, ResetButton.y + ResetButton.height + 5, ResetButton.width, ResetButton.height); Rect PointRefButton = new Rect(DeleteButton.x, DeleteButton.y + DeleteButton.height + 5, DeleteButton.width, DeleteButton.height); //Up here to make sure it goes behind other layers if (selectedSupport != null) { DrawFireSupportBox(10, 230, 30); } Widgets.DrawMenuSection(new Rect(0, 0, 800, 225)); //If firesupport is not selected if (Widgets.CustomButtonText(ref SelectionBar, selectedText, Color.gray, Color.white, Color.black)) { List <FloatMenuOption> supports = new List <FloatMenuOption>(); //Option to create new firesupport supports.Add(new FloatMenuOption("Create New Fire Support", delegate { MilitaryFireSupport newFireSupport = new MilitaryFireSupport(); newFireSupport.name = "New Fire Support " + (util.fireSupportDefs.Count + 1); newFireSupport.setLoadID(); newFireSupport.projectiles = new List <ThingDef>(); selectedText = newFireSupport.name; selectedSupport = newFireSupport; util.fireSupportDefs.Add(newFireSupport); })); //Create list of selectable firesupports foreach (MilitaryFireSupport support in util.fireSupportDefs) { supports.Add(new FloatMenuOption(support.name, delegate { //Unit is selected selectedText = support.name; selectedSupport = support; })); } FloatMenu selection = new FloatMenuSearchable(supports); Find.WindowStack.Add(selection); } //if firesupport is selected if (selectedSupport != null) { //Need to adjust fireSupportMaxScroll = selectedSupport.projectiles.Count * projectileBoxHeight - 10 * projectileBoxHeight; Text.Anchor = TextAnchor.MiddleLeft; Text.Font = GameFont.Small; if (settlementPointReference != null) { Widgets.Label(TotalCost, "Total Fire Support Silver Cost: " + selectedSupport.returnTotalCost() + " / " + FactionColonies.calculateMilitaryLevelPoints(settlementPointReference .settlementMilitaryLevel) + " (Max Cost)"); } else { Widgets.Label(TotalCost, "Total Fire Support Silver Cost: " + selectedSupport.returnTotalCost() + " / " + "No Reference"); } Widgets.Label(numberProjectiles, "Number of Projectiles: " + selectedSupport.projectiles.Count); Widgets.Label(duration, "Duration of fire support: " + Math.Round(selectedSupport.projectiles.Count * .25, 2) + " seconds"); Widgets.Label(floatRangeAccuracyLabel, selectedSupport.accuracy + " = Accuracy of fire support (In tiles radius): Affecting cost by : " + selectedSupport.returnAccuracyCostPercentage() + "%"); selectedSupport.accuracy = Widgets.HorizontalSlider(floatRangeAccuracy, selectedSupport.accuracy, Math.Max(3, (15 - Find.World.GetComponent <FactionFC>().returnHighestMilitaryLevel())), 30, roundTo: 1); Text.Font = GameFont.Tiny; Text.Anchor = TextAnchor.UpperCenter; //Unit Name selectedSupport.name = Widgets.TextField(nameTextField, selectedSupport.name); if (Widgets.ButtonText(ResetButton, "Reset to Default")) { selectedSupport.projectiles = new List <ThingDef>(); } if (Widgets.ButtonText(DeleteButton, "Delete Support")) { selectedSupport.delete(); util.checkMilitaryUtilForErrors(); selectedSupport = null; selectedText = "Select A Fire Support"; //Reset Text anchor and font Text.Font = fontBefore; Text.Anchor = anchorBefore; return; } if (Widgets.ButtonText(PointRefButton, "Set Point Ref")) { List <FloatMenuOption> settlementList = new List <FloatMenuOption>(); foreach (SettlementFC settlement in Find.World.GetComponent <FactionFC>().settlements) { settlementList.Add(new FloatMenuOption( settlement.name + " - Military Level : " + settlement.settlementMilitaryLevel, delegate { //set points settlementPointReference = settlement; })); } if (!settlementList.Any()) { settlementList.Add(new FloatMenuOption("No Valid Settlements", null)); } FloatMenu floatMenu = new FloatMenu(settlementList); Find.WindowStack.Add(floatMenu); } //Reset Text anchor and font Text.Font = fontBefore; Text.Anchor = anchorBefore; } if (Event.current.type == EventType.ScrollWheel) { scrollWindow(Event.current.delta.y, fireSupportMaxScroll); } //Reset Text anchor and font Text.Font = fontBefore; Text.Anchor = anchorBefore; }
public void DrawProductionHeaderLower(int x, int y, int spacing) { Text.Anchor = TextAnchor.MiddleRight; Text.Font = GameFont.Small; //Assigned workers Widgets.Label(new Rect(x, y, 410, 30), "AssignedWorkers".Translate() + ": " + settlement.getTotalWorkers().ToString() + " / " + settlement.workersMax.ToString() + " / " + settlement.workersUltraMax.ToString()); Text.Anchor = TextAnchor.MiddleCenter; Text.Font = GameFont.Tiny; //Item Headers Widgets.DrawHighlight(new Rect(x, y + 30, 40, 40)); Widgets.Label(new Rect(x, y + 30, 40, 40), "IsTithe".Translate() + "?"); Widgets.DrawHighlight(new Rect(x + 80, y + 30, 100, 40)); Widgets.Label(new Rect(x + 80, y + 30, 100, 40), "ProductionEfficiency".Translate()); Widgets.DrawHighlight(new Rect(x + 195, y + 30, 45, 40)); Widgets.Label(new Rect(x + 195, y + 30, 45, 40), "Base".Translate()); Widgets.DrawHighlight(new Rect(x + 250, y + 30, 50, 40)); Widgets.Label(new Rect(x + 250, y + 30, 50, 40), "Modifier".Translate()); Widgets.DrawHighlight(new Rect(x + 310, y + 30, 45, 40)); Widgets.Label(new Rect(x + 310, y + 30, 45, 40), "Final".Translate()); Widgets.DrawHighlight(new Rect(x + 365, y + 30, 45, 40)); Widgets.Label(new Rect(x + 365, y + 30, 45, 40), "EstimatedProfit".Translate()); Widgets.DrawHighlight(new Rect(x + 420, y + 30, 45, 40)); Widgets.Label(new Rect(x + 420, y + 30, 45, 40), "TaxPercentage".Translate()); //Per resource foreach (ResourceType resourceType in ResourceUtils.resourceTypes) { ResourceFC resource = settlement.getResource(resourceType); float rectY = scroll + y + 70 + (int)resourceType * (45 + spacing); if ((int)resourceType * ScrollSpacing + scroll < 0) { //if outside view } else { //loop through each resource //isTithe bool disabled = false; switch (resourceType) { case ResourceType.Research: case ResourceType.Power: disabled = true; break; default: if (Widgets.ButtonImage(new Rect(x - 15, scroll + y + 65 + (int)resourceType * (45 + spacing) + 8, 20, 20), TexLoad.iconCustomize)) { //if click faction customize button if (resource.filter == null) { resource.filter = new ThingFilter(); PaymentUtil.resetThingFilter(settlement, resourceType); } List <FloatMenuOption> options = new List <FloatMenuOption> { new FloatMenuOption("Enable All", delegate { PaymentUtil.resetThingFilter(settlement, resourceType); resource.returnLowestCost(); }), new FloatMenuOption("Disable All", delegate { resource.filter.SetDisallowAll(); resource.returnLowestCost(); }) }; List <ThingDef> things = PaymentUtil.debugGenerateTithe(resourceType); foreach (ThingDef thing in things.Where(thing => thing.race?.animalType != AnimalType.Dryad)) { if (!FactionColonies.canCraftItem(thing)) { resource.filter.SetAllow(thing, false); } else { FloatMenuOption option = new FloatMenuOption(thing.LabelCap + " - Cost - " + thing.BaseMarketValue + " | Allowed: " + resource.filter.Allows(thing), delegate { resource.filter.SetAllow(thing, !resource.filter.Allows(thing)); resource.returnLowestCost(); }, thing); options.Add(option); } } Find.WindowStack.Add(new FloatMenuSearchable(options)); //Log.Message("Settlement customize clicked"); } break; } Widgets.Checkbox(new Vector2(x + 8, scroll + y + 65 + (int)resourceType * (45 + spacing) + 8), ref resource.isTithe, 24, disabled); if (resource.isTithe != resource.isTitheBool) { resource.isTitheBool = resource.isTithe; //Log.Message("changed tithe"); settlement.updateProfitAndProduction(); windowUpdateFc(); } //Icon if (Widgets.ButtonImage(new Rect(x + 45, scroll + y + 75 + (int)resourceType * (45 + spacing), 30, 30), resource.getIcon())) { Find.WindowStack.Add(new DescWindowFc("SettlementProductionOf".Translate() + ": " + resource.label, char.ToUpper(resource.label[0]) + resource.label.Substring(1))); } //Production Efficiency Widgets.DrawBox(new Rect(x + 80, rectY, 100, 20)); Widgets.FillableBar(new Rect(x + 80, rectY, 100, 20), (float)Math.Min(resource.baseProductionMultiplier, 1.0)); Widgets.Label(new Rect(x + 80, scroll + y + 90 + (int)resourceType * (45 + spacing), 100, 20), "Workers".Translate() + ": " + resource.assignedWorkers.ToString()); if (Widgets.ButtonText(new Rect(x + 80, scroll + y + 90 + (int)resourceType * (45 + spacing), 20, 20), "<")) { if (settlement.isUnderAttack) { Messages.Message("SettlementUnderAttack".Translate(), MessageTypeDefOf.RejectInput); return; } //if clicked to lower amount of workers settlement.increaseWorkers(resourceType, -1); windowUpdateFc(); } if (Widgets.ButtonText(new Rect(x + 160, scroll + y + 90 + (int)resourceType * (45 + spacing), 20, 20), ">")) { if (settlement.isUnderAttack) { Messages.Message("SettlementUnderAttack".Translate(), MessageTypeDefOf.RejectInput); return; } //if clicked to lower amount of workers settlement.increaseWorkers(resourceType, 1); windowUpdateFc(); } //Base Production Widgets.Label(new Rect(x + 195, rectY, 45, 40), FactionColonies.FloorStat(resource.baseProduction)); //Final Modifier Widgets.Label(new Rect(x + 250, rectY, 50, 40), FactionColonies.FloorStat(resource.endProductionMultiplier)); //Final Base Widgets.Label(new Rect(x + 310, rectY, 45, 40), (FactionColonies.FloorStat(resource.endProduction))); //Est Income Widgets.Label(new Rect(x + 365, rectY, 45, 40), (FactionColonies.FloorStat(resource.endProduction * LoadedModManager .GetMod <FactionColoniesMod>().GetSettings <FactionColonies>().silverPerResource))); //Tithe Percentage resource.returnTaxPercentage(); string taxPercentage = FactionColonies.FloorStat(resource.taxPercentage) + "%"; Widgets.Label(new Rect(x + 420, rectY, 45, 40), taxPercentage); } } //Scroll window for resources if (Event.current.type == EventType.ScrollWheel) { scrollWindow(Event.current.delta.y); } }
public override void DoWindowContents(Rect inRect) { //grab before anchor/font GameFont fontBefore = Text.Font; TextAnchor anchorBefore = Text.Anchor; //Settlement Tax Collection Header Text.Anchor = TextAnchor.MiddleLeft; Text.Font = GameFont.Medium; Widgets.Label(new Rect(3, 3, 300, 60), header); Text.Font = GameFont.Small; for (int i = 0; i < 4; i++) //for each field to customize { switch (i) { case 0: //faction name Widgets.Label(new Rect(xoffset + 3, yoffset + yspacing * i, length / 4, yspacing), "FactionName".Translate() + ": "); name = Widgets.TextField(new Rect(xoffset + 3 + length / 4 + 5, yoffset + yspacing * i, length / 2, yspacing), name); break; case 1: //faction title Widgets.Label(new Rect(xoffset + 3, yoffset + yspacing * i, length / 4, yspacing), "FactionTitle".Translate() + ": "); title = Widgets.TextField(new Rect(xoffset + 3 + length / 4 + 5, yoffset + yspacing * i, length / 2, yspacing), title); break; case 2: //faction icon Widgets.Label(new Rect(xoffset + 3, yoffset + yspacing * i, length / 4, yspacing), "FactionIcon".Translate() + ": "); if (Widgets.ButtonImage(new Rect(xoffset + 3 + length / 4 + 5, yoffset + yspacing * i, 40, 40), tempFactionIcon)) //change to faction icon { List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (KeyValuePair <string, Texture2D> pair in texLoad.factionIcons) { list.Add(new FloatMenuOption(pair.Key, delegate { tempFactionIcon = pair.Value; tempFactionIconPath = pair.Key; }, pair.Value, Color.white)); } FloatMenu menu = new FloatMenu(list); Find.WindowStack.Add(menu); //Messages.Message("ButtonNotAvailable".Translate() + ".", MessageTypeDefOf.CautionInput); //Log.Message("Faction icon select pressed"); //Open window to select new icon } break; case 3: if (Widgets.ButtonTextSubtle(new Rect(xoffset + 3 + length / 4 + 5, yoffset + yspacing * i + 15, length / 2, yspacing), "AllowedRaces".Translate())) //change to faction icon { List <string> races = new List <string>(); List <FloatMenuOption> list = new List <FloatMenuOption>(); list.Add(new FloatMenuOption("Enable All", delegate { faction.resetRaceFilter(); })); foreach (PawnKindDef def in DefDatabase <PawnKindDef> .AllDefsListForReading) { if (def.race.race.intelligence == Intelligence.Humanlike & races.Contains(def.race.label) == false && def.race.BaseMarketValue != 0) { if (def.race.label == "Human" && def.LabelCap != "Colonist") { } else { races.Add(def.race.label); list.Add(new FloatMenuOption(def.race.label.CapitalizeFirst() + " - Allowed: " + faction.raceFilter.Allows(def.race), delegate { if (faction.raceFilter.AllowedThingDefs.Count() == 1 && faction.raceFilter.Allows(def.race) == true) { Messages.Message("CannotHaveLessThanOneRace".Translate(), MessageTypeDefOf.RejectInput); } else if (faction.raceFilter.AllowedThingDefs.Count() > 1) { faction.raceFilter.SetAllow(def.race, !faction.raceFilter.Allows(def.race)); } else { Log.Message("Empire Error - Zero races available for faction - Report this"); Log.Message("Reseting race filter"); faction.resetRaceFilter(); } })); } } } FloatMenu menu = new FloatMenu(list); Find.WindowStack.Add(menu); //Messages.Message("ButtonNotAvailable".Translate() + ".", MessageTypeDefOf.CautionInput); //Log.Message("Faction icon select pressed"); //Open window to select new icon } break; } } if (Widgets.ButtonText(new Rect((InitialSize.x - 120 - 18) / 2, yoffset + InitialSize.y - 120, 120, 30), "ConfirmChanges".Translate())) { Faction fact = FactionColonies.getPlayerColonyFaction(); FactionFC component = Find.World.GetComponent <FactionFC>(); faction.title = title; faction.name = name; fact.Name = name; component.name = name; component.factionIconPath = tempFactionIconPath; component.factionIcon = tempFactionIcon; component.updateFactionRaces(); component.factionBackup = fact; faction.updateFactionIcon(ref fact, "FactionIcons/" + tempFactionIconPath); Find.LetterStack.ReceiveLetter("Note on Faction Icon", "Note: The faction icon on the world map will only update after a full restart of your game. Or pure luck.", LetterDefOf.NeutralEvent); Find.WindowStack.TryRemove(this); } //settlement buttons Text.Anchor = TextAnchor.UpperLeft; Text.Font = GameFont.Tiny; //0 tithe total string //1 source - -1 //2 due/delivery date //3 Silver (- || +) //4 tithe Widgets.Label(new Rect(xoffset + 2, yoffset - yspacing + 2, length - 4, height - 4 + yspacing * 2), desc); Widgets.DrawBox(new Rect(xoffset, yoffset - yspacing, length, height - yspacing)); //reset anchor/font Text.Font = fontBefore; Text.Anchor = anchorBefore; }
public static void SquadAI(ref MercenarySquadFC squad) { Faction playerFaction = Find.FactionManager.OfPlayer; Faction settlementFaction = FactionColonies.getPlayerColonyFaction(); FactionFC factionfc = Find.World.GetComponent <FactionFC>(); MilitaryCustomizationUtil militaryCustomizationUtil = factionfc.militaryCustomizationUtil; bool deployed = false; //Log.Message("1"); foreach (Mercenary merc in squad.DeployedMercenaries) { //If pawn is deployed deployed = true; if (!(squad.hitMap)) { squad.hitMap = true; } if (merc.pawn.health.State == PawnHealthState.Mobile) { //if pawn is up and moving if (squad.order != null && squad.order != MilitaryOrders.Leave) { if (squad.timeDeployed + 30000 >= Find.TickManager.TicksGame && merc.pawn.Faction != playerFaction) { merc.pawn.SetFaction(playerFaction); } } else { if (merc.pawn.drafter != null) { merc.pawn.drafter.Drafted = false; } if (merc.pawn.Faction != settlementFaction) { merc.pawn.SetFaction(settlementFaction); } } JobGiver_AIFightEnemies jobGiver = new JobGiver_AIFightEnemies(); ThinkResult result = jobGiver.TryIssueJobPackage(merc.pawn, new JobIssueParams()); bool isValid = result.IsValid; if (isValid) { //Log.Message("Success"); if (merc.pawn.jobs.curJob == null || ((merc.pawn.jobs.curJob.def == JobDefOf.Goto || merc.pawn.jobs.curJob.def != result.Job.def) && merc.pawn.jobs.curJob.def.defName != "ReloadWeapon" && merc.pawn.jobs.curJob.def.defName != "ReloadTurret" && !merc.pawn.Drafted)) { merc.pawn.jobs.StartJob(result.Job, JobCondition.Ongoing); //Log.Message(result.Job.ToString()); } } else { //Log.Message("Fail"); if (squad.timeDeployed + 30000 >= Find.TickManager.TicksGame) { if (merc.pawn.drafter == null || merc.pawn.Drafted == false) { if (squad.order == MilitaryOrders.Standby) { //Log.Message("Standby"); merc.pawn.mindState.forcedGotoPosition = squad.orderLocation; JobGiver_ForcedGoto jobGiver_Standby = new JobGiver_ForcedGoto(); ThinkResult resultStandby = jobGiver_Standby.TryIssueJobPackage(merc.pawn, new JobIssueParams()); bool isValidStandby = resultStandby.IsValid; if (isValidStandby) { //Log.Message("valid"); merc.pawn.jobs.StartJob(resultStandby.Job, JobCondition.InterruptForced); } } else if (squad.order == MilitaryOrders.Attack) { //Log.Message("Attack"); //If time is up, leave, else go home JobGiver_AIGotoNearestHostile jobGiver_Move = new JobGiver_AIGotoNearestHostile(); ThinkResult resultMove = jobGiver_Move.TryIssueJobPackage(merc.pawn, new JobIssueParams()); bool isValidMove = resultMove.IsValid; //Log.Message(resultMove.ToString()); if (isValidMove) { merc.pawn.jobs.StartJob(resultMove.Job, JobCondition.InterruptForced); } } else if (squad.order == MilitaryOrders.Leave) { JobGiver_ExitMapBest jobGiver_Rescue = new JobGiver_ExitMapBest(); ThinkResult resultLeave = jobGiver_Rescue.TryIssueJobPackage(merc.pawn, new JobIssueParams()); bool isValidLeave = resultLeave.IsValid; if (isValidLeave) { merc.pawn.jobs.StartJob(resultLeave.Job, JobCondition.InterruptForced); } } else if (squad.order == MilitaryOrders.RecoverWounded) { JobGiver_RescueNearby jobGiver_Rescue = new JobGiver_RescueNearby(); ThinkResult resultRescue = jobGiver_Rescue.TryIssueJobPackage(merc.pawn, new JobIssueParams()); bool isValidRescue = resultRescue.IsValid; if (isValidRescue) { merc.pawn.jobs.StartJob(resultRescue.Job, JobCondition.InterruptForced); } } } } else { if (merc.pawn.drafter != null) { merc.pawn.drafter.Drafted = false; } if (merc.pawn.Faction != settlementFaction) { merc.pawn.SetFaction(settlementFaction); } } } //end of if pawn is mobile } else { //if pawn is down or dead if (merc.pawn.health.Dead) //if pawn is on map and is dead { //squad.removeDroppedEquipment(); //squad.PassPawnToDeadMercenaries(merc); //squad.hasDead = true; } else { //If alive but downed if (merc.pawn.drafter != null) { merc.pawn.drafter.Drafted = false; } if (merc.pawn.Faction != settlementFaction) { merc.pawn.SetFaction(settlementFaction); } } } } //Log.Message("2"); foreach (Mercenary animal in squad.DeployedMercenaryAnimals) { //if on map deployed = true; if (animal.pawn.health.State == PawnHealthState.Mobile) { animal.pawn.mindState.duty = new PawnDuty(); animal.pawn.mindState.duty.def = DutyDefOf.Defend; animal.pawn.mindState.duty.attackDownedIfStarving = false; //animal.pawn.mindState.duty.radius = 2; animal.pawn.mindState.duty.focus = animal.handler.pawn; //If master is not dead JobGiver_AIFightEnemies jobGiver = new JobGiver_AIFightEnemies(); ThinkResult result = jobGiver.TryIssueJobPackage(animal.pawn, new JobIssueParams()); bool isValid = result.IsValid; if (isValid) { //Log.Message("att"); if (animal.pawn.jobs.curJob.def != result.Job.def) { animal.pawn.jobs.StartJob(result.Job, JobCondition.InterruptForced); } } else { animal.pawn.mindState.duty.def = DutyDefOf.Defend; animal.pawn.mindState.duty.radius = 2; animal.pawn.mindState.duty.focus = animal.handler.pawn; //if defend master not valid, follow master JobGiver_AIFollowEscortee jobGiverFollow = new JobGiver_AIFollowEscortee(); ThinkResult resultFollow = jobGiverFollow.TryIssueJobPackage(animal.pawn, new JobIssueParams()); bool isValidFollow = resultFollow.IsValid; if (isValidFollow) { //Log.Message("foloor"); if (animal.pawn.jobs.curJob.def != resultFollow.Job.def) { animal.pawn.jobs.StartJob(resultFollow.Job, JobCondition.Ongoing); } } else { JobGiver_ExitMapBest jobGiver_Rescue = new JobGiver_ExitMapBest(); ThinkResult resultLeave = jobGiver_Rescue.TryIssueJobPackage(animal.pawn, new JobIssueParams()); bool isValidLeave = resultLeave.IsValid; if (isValidLeave) { animal.pawn.jobs.StartJob(resultLeave.Job, JobCondition.InterruptForced); } } } } } if (deployed == false && squad.hitMap) { foreach (Mercenary merc in squad.mercenaries) { merc.pawn.SetFaction(settlementFaction); } squad.hasLord = false; squad.isDeployed = false; squad.removeDroppedEquipment(); if (squad.map != null) { squad.map.lordManager.RemoveLord(squad.lord); squad.lord = null; squad.map = null; } squad.hitMap = false; if (squad.isExtraSquad) { militaryCustomizationUtil.mercenarySquads.Remove(squad); //Log.Message("Squad deleted"); return; } squad.getSettlement.cooldownMilitary(); //Log.Message("Reseting Squad"); militaryCustomizationUtil.checkMilitaryUtilForErrors(); squad.OutfitSquad(squad.outfit); } }
public override void DrawTab(Rect rect) { //set text anchor and font GameFont fontBefore = Text.Font; TextAnchor anchorBefore = Text.Anchor; Rect SelectionBar = new Rect(5, 45, 200, 30); Rect importButton = new Rect(5, SelectionBar.y + SelectionBar.height + 10, 200, 30); Rect nameTextField = new Rect(5, importButton.y + importButton.height + 10, 250, 30); Rect isTrader = new Rect(5, nameTextField.y + nameTextField.height + 10, 130, 30); Rect UnitStandBase = new Rect(170, 220, 50, 30); Rect EquipmentTotalCost = new Rect(350, 50, 450, 40); Rect ResetButton = new Rect(700, 100, 100, 30); Rect DeleteButton = new Rect(ResetButton.x, ResetButton.y + ResetButton.height + 5, ResetButton.width, ResetButton.height); Rect PointRefButton = new Rect(DeleteButton.x, DeleteButton.y + DeleteButton.height + 5, DeleteButton.width, DeleteButton.height); Rect SaveSquadButton = new Rect(DeleteButton.x, PointRefButton.y + DeleteButton.height + 5, DeleteButton.width, DeleteButton.height); //If squad is not selected if (Widgets.CustomButtonText(ref SelectionBar, selectedText, Color.gray, Color.white, Color.black)) { //check null if (util.squads == null) { util.resetSquads(); } List <FloatMenuOption> squads = new List <FloatMenuOption> { new FloatMenuOption("Create New Squad", delegate { MilSquadFC newSquad = new MilSquadFC(true) { name = $"New Squad {(util.squads.Count + 1).ToString()}" }; selectedText = newSquad.name; selectedSquad = newSquad; selectedSquad.newSquad(); util.squads.Add(newSquad); }) }; //Create list of selectable units squads.AddRange(util.squads.Select(squad => new FloatMenuOption(squad.name, delegate { //Unit is selected selectedText = squad.name; selectedSquad = squad; selectedSquad.updateEquipmentTotalCost(); }))); FloatMenu selection = new Searchable_FloatMenu(squads); Find.WindowStack.Add(selection); } if (Widgets.ButtonText(importButton, "Import Squad")) { Find.WindowStack.Add(new Dialog_ManageSquadExportsFC( FactionColoniesMilitary.SavedSquads.ToList())); } //if squad is selected if (selectedSquad != null) { Text.Anchor = TextAnchor.MiddleLeft; Text.Font = GameFont.Small; if (settlementPointReference != null) { Widgets.Label(EquipmentTotalCost, "Total Squad Equipment Cost: " + selectedSquad.equipmentTotalCost + " / " + FactionColonies .calculateMilitaryLevelPoints(settlementPointReference .settlementMilitaryLevel) + " (Max Cost)"); } else { Widgets.Label(EquipmentTotalCost, "Total Squad Equipment Cost: " + selectedSquad.equipmentTotalCost + " / " + "No Reference"); } Text.Font = GameFont.Tiny; Text.Anchor = TextAnchor.UpperCenter; Widgets.CheckboxLabeled(isTrader, "is Trader Caravan", ref selectedSquad.isTraderCaravan); selectedSquad.setTraderCaravan(selectedSquad.isTraderCaravan); //Unit Name selectedSquad.name = Widgets.TextField(nameTextField, selectedSquad.name); if (Widgets.ButtonText(ResetButton, "Reset to Default")) { selectedSquad.newSquad(); } if (Widgets.ButtonText(DeleteButton, "Delete Squad")) { selectedSquad.deleteSquad(); util.checkMilitaryUtilForErrors(); selectedSquad = null; selectedText = "Select A Squad"; //Reset Text anchor and font Text.Font = fontBefore; Text.Anchor = anchorBefore; return; } if (Widgets.ButtonText(PointRefButton, "Set Point Ref")) { List <FloatMenuOption> settlementList = Find.World.GetComponent <FactionFC>() .settlements.Select(settlement => new FloatMenuOption(settlement.name + " - Military Level : " + settlement.settlementMilitaryLevel, delegate { //set points settlementPointReference = settlement; })) .ToList(); if (!settlementList.Any()) { settlementList.Add(new FloatMenuOption("No Valid Settlements", null)); } FloatMenu floatMenu = new FloatMenu(settlementList) { vanishIfMouseDistant = true }; Find.WindowStack.Add(floatMenu); } if (Widgets.ButtonText(SaveSquadButton, "Export Squad")) { // TODO: Confirm if squad with name already exists FactionColoniesMilitary.SaveSquad(new SavedSquadFC(selectedSquad)); Messages.Message("ExportSquad".Translate(), MessageTypeDefOf.TaskCompletion); } //for (int k = 0; k < 30; k++) //{ // Widgets.ButtonImage(new Rect(UnitStandBase.x + (k * 15), UnitStandBase.y + ((k % 5) * 70), 50, 20), texLoad.unitCircle); //} for (int k = 0; k < 30; k++) { if (Widgets.ButtonImage(new Rect(UnitStandBase.x + k % 6 * 80, UnitStandBase.y + (k - k % 6) / 5 * 70, 50, 20), TexLoad.unitCircle)) { int click = k; //Option to clear unit slot List <FloatMenuOption> units = new List <FloatMenuOption> { new FloatMenuOption("clearUnitSlot".Translate(), delegate { //Log.Message(selectedSquad.units.Count().ToString()); //Log.Message(click.ToString()); selectedSquad.units[click] = new MilUnitFC(true); selectedSquad.updateEquipmentTotalCost(); selectedSquad.ChangeTick(); }) }; //Create list of selectable units units.AddRange(util.units.Select(unit => new FloatMenuOption(unit.name + " - Cost: " + unit.equipmentTotalCost, delegate { //Unit is selected selectedSquad.units[click] = unit; selectedSquad.updateEquipmentTotalCost(); selectedSquad.ChangeTick(); }))); FloatMenu selection = new Searchable_FloatMenu(units); Find.WindowStack.Add(selection); } if (selectedSquad.units[k].isBlank) { continue; } if (selectedSquad.units.ElementAt(k).animal != null) { Widgets.ButtonImage( new Rect(UnitStandBase.x + 15 + ((k % 6) * 80), UnitStandBase.y - 45 + (k - k % 6) / 5 * 70, 60, 60), selectedSquad.units.ElementAt(k).animal.race.uiIcon); } Widgets.ThingIcon( new Rect(UnitStandBase.x - 5 + ((k % 6) * 80), UnitStandBase.y - 45 + (k - k % 6) / 5 * 70, 60, 60), selectedSquad.units.ElementAt(k).defaultPawn); if (selectedSquad.units.ElementAt(k).defaultPawn.equipment.AllEquipmentListForReading.Count > 0) { Widgets.ThingIcon( new Rect(UnitStandBase.x - 5 + ((k % 6) * 80), UnitStandBase.y - 15 + (k - k % 6) / 5 * 70, 40, 40), selectedSquad.units.ElementAt(k).defaultPawn.equipment.AllEquipmentListForReading[0]); } Widgets.Label( new Rect(UnitStandBase.x - 15 + ((k % 6) * 80), UnitStandBase.y - 65 + (k - k % 6) / 5 * 70, 80, 60), selectedSquad.units.ElementAt(k).name); } //Reset Text anchor and font Text.Font = fontBefore; Text.Anchor = anchorBefore; } //Reset Text anchor and font Text.Font = fontBefore; Text.Anchor = anchorBefore; }
public override void DoWindowContents(Rect inRect) { //grab before anchor/font GameFont fontBefore = Text.Font; TextAnchor anchorBefore = Text.Anchor; //Settlement Tax Collection Header Text.Anchor = TextAnchor.MiddleLeft; Text.Font = GameFont.Medium; Widgets.Label(new Rect(3, 3, 300, 60), header); Text.Font = GameFont.Small; for (int i = 0; i < 3; i++) //for each field to customize { switch (i) { case 0: //faction name Widgets.Label(new Rect(xoffset + 3, yoffset + yspacing * i, length / 4, yspacing), "FactionName".Translate() + ": "); name = Widgets.TextField(new Rect(xoffset + 3 + length / 4 + 5, yoffset + yspacing * i, length / 2, yspacing), name); break; case 1: //faction title Widgets.Label(new Rect(xoffset + 3, yoffset + yspacing * i, length / 4, yspacing), "FactionTitle".Translate() + ": "); title = Widgets.TextField(new Rect(xoffset + 3 + length / 4 + 5, yoffset + yspacing * i, length / 2, yspacing), title); break; case 2: //faction icon Widgets.Label(new Rect(xoffset + 3, yoffset + yspacing * i, length / 4, yspacing), "FactionIcon".Translate() + ": "); if (Widgets.ButtonImage(new Rect(xoffset + 3 + length / 4 + 5, yoffset + yspacing * i, 40, 40), texLoad.iconUnrest)) //change to faction icon { Messages.Message("ButtonNotAvailable".Translate() + ".", MessageTypeDefOf.CautionInput); //Log.Message("Faction icon select pressed"); //Open window to select new icon } break; } } if (Widgets.ButtonText(new Rect((InitialSize.x - 120 - 18) / 2, yoffset + InitialSize.y - 120, 120, 30), "ConfirmChanges".Translate())) { faction.title = title; faction.name = name; FactionColonies.getPlayerColonyFaction().Name = name; Find.World.GetComponent <FactionFC>().name = name; Find.WindowStack.TryRemove(this); } //settlement buttons Text.Anchor = TextAnchor.UpperLeft; Text.Font = GameFont.Tiny; //0 tithe total string //1 source - -1 //2 due/delivery date //3 Silver (- || +) //4 tithe Widgets.Label(new Rect(xoffset + 2, yoffset - yspacing + 2, length - 4, height - 4 + yspacing * 2), desc); Widgets.DrawBox(new Rect(xoffset, yoffset - yspacing, length, height - yspacing * 2)); //reset anchor/font Text.Font = fontBefore; Text.Anchor = anchorBefore; }
/// <summary> /// If the dev mode is enabled, despawnes all squads and disables their deployment /// </summary> private void DoDebugCommand() { foreach (MercenarySquadFC squad in faction.militaryCustomizationUtil.DeployedSquads) { foreach (Mercenary merc in squad.mercenaries.Concat(squad.animals)) { if (merc?.pawn?.Map != null) { merc?.animal?.pawn?.Destroy(); merc.pawn.Destroy(); } } try { foreach (Pawn pawn in Find.CurrentMap.mapPawns.SpawnedPawnsInFaction(FactionColonies.getPlayerColonyFaction())) { pawn.Destroy(); } } catch { } squad.isDeployed = false; squad.InitiateCooldownEvent(); } }
public override void DrawTab(Rect rect) { Rect SettlementBox = new Rect(5, 45, 535, settlementHeight); Rect SettlementName = new Rect(SettlementBox.x + 5, SettlementBox.y + 5, 250, 25); Rect MilitaryLevel = new Rect(SettlementName.x, SettlementName.y + 30, 250, 25); Rect AssignedSquad = new Rect(MilitaryLevel.x, MilitaryLevel.y + 30, 250, 25); Rect isBusy = new Rect(AssignedSquad.x, AssignedSquad.y + 30, 250, 25); Rect buttonSetSquad = new Rect(SettlementBox.x + SettlementBox.width - 265, SettlementBox.y + 5, 100, 25); Rect buttonViewSquad = new Rect(buttonSetSquad.x, buttonSetSquad.y + 3 + buttonSetSquad.height, buttonSetSquad.width, buttonSetSquad.height); Rect buttonDeploySquad = new Rect(buttonViewSquad.x, buttonViewSquad.y + 3 + buttonViewSquad.height, buttonSetSquad.width, buttonSetSquad.height); Rect buttonResetPawns = new Rect(buttonDeploySquad.x, buttonDeploySquad.y + 3 + buttonDeploySquad.height, buttonSetSquad.width, buttonSetSquad.height); Rect buttonOrderFireSupport = new Rect(buttonSetSquad.x + 125 + 5, SettlementBox.y + 5, 125, 25); //set text anchor and font GameFont fontBefore = Text.Font; TextAnchor anchorBefore = Text.Anchor; int count = 0; foreach (SettlementFC settlement in Find.World.GetComponent <FactionFC>().settlements) { Text.Font = GameFont.Small; Widgets.DrawMenuSection(new Rect(SettlementBox.x, SettlementBox.y + (SettlementBox.height + settlementYSpacing) * count + scroll, SettlementBox.width, SettlementBox.height)); //click on settlement name if (Widgets.ButtonTextSubtle( new Rect(SettlementName.x, SettlementName.y + (SettlementBox.height + settlementYSpacing) * count + scroll, SettlementName.width, SettlementName.height), settlement.name)) { Find.WindowStack.Add(new SettlementWindowFc(settlement)); } Widgets.Label( new Rect(MilitaryLevel.x, MilitaryLevel.y + (SettlementBox.height + settlementYSpacing) * count + scroll, MilitaryLevel.width, MilitaryLevel.height * 2), "Mil Level: " + settlement.settlementMilitaryLevel + " - Max Squad Cost: " + FactionColonies.calculateMilitaryLevelPoints(settlement.settlementMilitaryLevel)); if (settlement.militarySquad != null) { if (settlement.militarySquad.outfit != null) { Widgets.Label( new Rect(AssignedSquad.x, AssignedSquad.y + (SettlementBox.height + settlementYSpacing) * count + scroll, AssignedSquad.width, AssignedSquad.height), "Assigned Squad: " + settlement.militarySquad.outfit.name); //settlement.militarySquad.name); } else { Widgets.Label( new Rect(AssignedSquad.x, AssignedSquad.y + (SettlementBox.height + settlementYSpacing) * count + scroll, AssignedSquad.width, AssignedSquad.height), "No assigned Squad"); //settlement.militarySquad.name); } } else { Widgets.Label( new Rect(AssignedSquad.x, AssignedSquad.y + (SettlementBox.height + settlementYSpacing) * count + scroll, AssignedSquad.width, AssignedSquad.height), "No assigned Squad"); } Widgets.Label( new Rect(isBusy.x, isBusy.y + (SettlementBox.height + settlementYSpacing) * count + scroll, isBusy.width, isBusy.height), "Available: " + (!settlement.isMilitaryBusySilent())); Text.Font = GameFont.Tiny; //Set Squad Button if (Widgets.ButtonText( new Rect(buttonSetSquad.x, buttonSetSquad.y + (SettlementBox.height + settlementYSpacing) * count + scroll, buttonSetSquad.width, buttonSetSquad.height), "Set Squad")) { //check null if (util.squads == null) { util.resetSquads(); } List <FloatMenuOption> squads = new List <FloatMenuOption>(); squads.AddRange(util.squads .Select(squad => new FloatMenuOption(squad.name + " - Total Equipment Cost: " + squad.equipmentTotalCost, delegate { //Unit is selected util.attemptToAssignSquad(settlement, squad); }))); if (!squads.Any()) { squads.Add(new FloatMenuOption("No Available Squads", null)); } FloatMenu selection = new FloatMenuSearchable(squads); Find.WindowStack.Add(selection); } //View Squad if (Widgets.ButtonText( new Rect(buttonViewSquad.x, buttonViewSquad.y + (SettlementBox.height + settlementYSpacing) * count + scroll, buttonViewSquad.width, buttonViewSquad.height), "View Squad")) { Messages.Message("This is currently not implemented.", MessageTypeDefOf.RejectInput); } //Deploy Squad if (Widgets.ButtonText( new Rect(buttonDeploySquad.x, buttonDeploySquad.y + (SettlementBox.height + settlementYSpacing) * count + scroll, buttonDeploySquad.width, buttonDeploySquad.height), "Deploy Squad")) { if (!(settlement.isMilitaryBusy()) && settlement.isMilitarySquadValid()) { Find.WindowStack.Add(new FloatMenu(DeploymentOptions(settlement))); } else if (settlement.isMilitaryBusy() && settlement.isMilitarySquadValid() && faction.hasPolicy(FCPolicyDefOf.militaristic)) { if ((faction.traitMilitaristicTickLastUsedExtraSquad + GenDate.TicksPerDay * 5) <= Find.TickManager.TicksGame) { int cost = (int)Math.Round(settlement.militarySquad.outfit.updateEquipmentTotalCost() * .2); List <FloatMenuOption> options = new List <FloatMenuOption>(); options.Add(new FloatMenuOption("Deploy Secondary Squad - $" + cost + " silver", delegate { if (PaymentUtil.getSilver() >= cost) { List <FloatMenuOption> deploymentOptions = new List <FloatMenuOption>(); deploymentOptions.Add(new FloatMenuOption("Walk into map", delegate { FactionColonies.CallinAlliedForces(settlement, false, cost); Find.WindowStack.currentlyDrawnWindow.Close(); })); //check if medieval only bool medievalOnly = LoadedModManager.GetMod <FactionColoniesMod>() .GetSettings <FactionColonies>().medievalTechOnly; if (!medievalOnly && (DefDatabase <ResearchProjectDef> .GetNamed("TransportPod", false)?.IsFinished ?? false)) { deploymentOptions.Add(new FloatMenuOption("Drop-Pod", delegate { FactionColonies.CallinAlliedForces(settlement, true, cost); Find.WindowStack.currentlyDrawnWindow.Close(); })); } Find.WindowStack.Add(new FloatMenu(deploymentOptions)); } else { Messages.Message("NotEnoughSilverToDeploySquad".Translate(), MessageTypeDefOf.RejectInput); } })); Find.WindowStack.Add(new FloatMenu(options)); } else { Messages.Message( "XDaysToRedeploy".Translate(Math.Round( ((faction.traitMilitaristicTickLastUsedExtraSquad + GenDate.TicksPerDay * 5) - Find.TickManager.TicksGame).TicksToDays(), 1)), MessageTypeDefOf.RejectInput); } } } //Reset Squad if (Widgets.ButtonText( new Rect(buttonResetPawns.x, buttonResetPawns.y + (SettlementBox.height + settlementYSpacing) * count + scroll, buttonResetPawns.width, buttonResetPawns.height), "Reset Pawns")) { FloatMenuOption confirm = new FloatMenuOption("Are you sure? Click to confirm", delegate { if (settlement.militarySquad != null) { Messages.Message("Pawns have been regenerated for the squad", MessageTypeDefOf.NeutralEvent); settlement.militarySquad.initiateSquad(); } else { Messages.Message("There is no pawns to reset. Assign a squad first.", MessageTypeDefOf.RejectInput); } }); List <FloatMenuOption> list = new List <FloatMenuOption>(); list.Add(confirm); Find.WindowStack.Add(new FloatMenu(list)); } //Order Fire Support if (Widgets.ButtonText( new Rect(buttonOrderFireSupport.x, buttonOrderFireSupport.y + (SettlementBox.height + settlementYSpacing) * count + scroll, buttonOrderFireSupport.width, buttonOrderFireSupport.height), "Order Fire Support")) { List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (MilitaryFireSupport support in util.fireSupportDefs) { float cost = support.returnTotalCost(); FloatMenuOption option = new FloatMenuOption(support.name + " - $" + cost, delegate { if (support.returnTotalCost() <= FactionColonies.calculateMilitaryLevelPoints(settlement.settlementMilitaryLevel)) { if (settlement.buildings.Contains(BuildingFCDefOf.artilleryOutpost)) { if (settlement.artilleryTimer <= Find.TickManager.TicksGame) { if (PaymentUtil.getSilver() >= cost) { FactionColonies.FireSupport(settlement, support); Find.WindowStack.TryRemove(typeof(MilitaryCustomizationWindowFc)); } else { Messages.Message( "You lack the required amount of silver to use that firesupport option!", MessageTypeDefOf.RejectInput); } } else { Messages.Message( "That firesupport option is on cooldown for another " + (settlement.artilleryTimer - Find.TickManager.TicksGame) .ToStringTicksToDays(), MessageTypeDefOf.RejectInput); } } else { Messages.Message( "The settlement requires an artillery outpost to be built to use that firesupport option", MessageTypeDefOf.RejectInput); } } else { Messages.Message( "The settlement requires a higher military level to use that fire support!", MessageTypeDefOf.RejectInput); } }); list.Add(option); } if (!list.Any()) { list.Add(new FloatMenuOption("No fire supports currently made. Make one", delegate { })); } FloatMenu menu = new FloatMenuSearchable(list); Find.WindowStack.Add(menu); } count++; } //Reset Text anchor and font Text.Font = fontBefore; Text.Anchor = anchorBefore; if (Event.current.type == EventType.ScrollWheel) { scrollWindow(Event.current.delta.y, settlementMaxScroll); } }
//Drawing public override void DoWindowContents(Rect inRect) { FactionFC faction = Find.World.GetComponent <FactionFC>(); faction.roadBuilder.displayPaths(); if (Find.WorldSelector.selectedTile != -1 && Find.WorldSelector.selectedTile != currentTileSelected) { currentTileSelected = Find.WorldSelector.selectedTile; //Log.Message("Current: " + currentTileSelected + ", Selected: " + Find.WorldSelector.selectedTile); currentBiomeSelected = DefDatabase <BiomeResourceDef> .GetNamed(Find.WorldGrid.tiles[currentTileSelected].biome.ToString(), false); //default biome if (currentBiomeSelected == default(BiomeResourceDef)) { //Log Modded Biome currentBiomeSelected = BiomeResourceDefOf.defaultBiome; } currentHillinessSelected = DefDatabase <BiomeResourceDef> .GetNamed(Find.WorldGrid.tiles[currentTileSelected].hilliness.ToString()); if (currentBiomeSelected.canSettle == true && currentHillinessSelected.canSettle == true && currentTileSelected != 1) { timeToTravel = FactionColonies.ReturnTicksToArrive(Find.World.GetComponent <FactionFC>().capitalLocation, currentTileSelected); } else { timeToTravel = 0; } } //grab before anchor/font GameFont fontBefore = Text.Font; TextAnchor anchorBefore = Text.Anchor; int silverToCreateSettlement = (int)(traitUtilsFC.cycleTraits(new double(), "createSettlementMultiplier", Find.World.GetComponent <FactionFC>().traits, "multiply") * (FactionColonies.silverToCreateSettlement + (500 * (Find.World.GetComponent <FactionFC>().settlements.Count() + Find.World.GetComponent <FactionFC>().settlementCaravansList.Count())) + (traitUtilsFC.cycleTraits(new double(), "createSettlementBaseCost", Find.World.GetComponent <FactionFC>().traits, "add")))); //Draw Label Text.Font = GameFont.Medium; Text.Anchor = TextAnchor.MiddleCenter; Widgets.Label(new Rect(0, 0, 268, 40), "SettleANewColony".Translate()); //hori line Widgets.DrawLineHorizontal(0, 40, 300); //Upper menu Widgets.DrawMenuSection(new Rect(5, 45, 258, 220)); DrawLabelBox(10, 50, 100, 100, "TravelTime".Translate(), GenDate.ToStringTicksToDays(timeToTravel)); DrawLabelBox(153, 50, 100, 100, "InitialCost".Translate(), silverToCreateSettlement + " " + "Silver".Translate()); //Lower Menu label Text.Font = GameFont.Medium; Text.Anchor = TextAnchor.MiddleCenter; Widgets.Label(new Rect(0, 270, 268, 40), "BaseProductionStats".Translate()); //Lower menu Widgets.DrawMenuSection(new Rect(5, 310, 258, 220)); //Draw production Text.Font = GameFont.Small; Text.Anchor = TextAnchor.MiddleCenter; //Production headers Widgets.Label(new Rect(40, 310, 60, 25), "Base".Translate()); Widgets.Label(new Rect(110, 310, 60, 25), "Modifier".Translate()); Widgets.Label(new Rect(180, 310, 60, 25), "Final".Translate()); if (currentTileSelected != -1) { for (int i = 0; i < Find.World.GetComponent <FactionFC>().returnNumberResource(); i++) { int height = 15; if (Widgets.ButtonImage(new Rect(20, 335 + i * (5 + height), height, height), faction.returnResourceByInt(i).getIcon())) { Find.WindowStack.Add(new descWindowFC("SettlementProductionOf".Translate() + ": " + faction.returnResourceByInt(i).label, char.ToUpper(faction.returnResourceByInt(i).label[0]) + faction.returnResourceByInt(i).label.Substring(1))); } Widgets.Label(new Rect(40, 335 + i * (5 + height), 60, height + 2), (currentBiomeSelected.BaseProductionAdditive[i] + currentHillinessSelected.BaseProductionAdditive[i]).ToString()); Widgets.Label(new Rect(110, 335 + i * (5 + height), 60, height + 2), (currentBiomeSelected.BaseProductionMultiplicative[i] * currentHillinessSelected.BaseProductionMultiplicative[i]).ToString()); Widgets.Label(new Rect(180, 335 + i * (5 + height), 60, height + 2), ((currentBiomeSelected.BaseProductionAdditive[i] + currentHillinessSelected.BaseProductionAdditive[i]) * (currentBiomeSelected.BaseProductionMultiplicative[i] * currentHillinessSelected.BaseProductionMultiplicative[i])).ToString()); } } //Settle button Text.Font = GameFont.Small; Text.Anchor = TextAnchor.MiddleCenter; int buttonLength = 130; if (Widgets.ButtonText(new Rect((InitialSize.x - 32 - buttonLength) / 2f, 535, buttonLength, 32), "Settle".Translate() + ": (" + silverToCreateSettlement + ")")) //add inital cost { //if click button to settle if (PaymentUtil.getSilver() >= silverToCreateSettlement) //if have enough monies to make new settlement { StringBuilder reason = new StringBuilder(); if (!TileFinder.IsValidTileForNewSettlement(currentTileSelected, reason) || currentTileSelected == -1 || Find.World.GetComponent <FactionFC>().checkSettlementCaravansList(currentTileSelected.ToString())) { //Alert Error to User Messages.Message(reason.ToString() ?? "CaravanOnWay".Translate() + "!", MessageTypeDefOf.NegativeEvent); } else { //Else if valid tile PaymentUtil.paySilver(silverToCreateSettlement); //if PROCESS MONEY HERE //create settle event FCEvent tmp = FCEventMaker.MakeEvent(FCEventDefOf.settleNewColony); tmp.location = currentTileSelected; tmp.planetName = Find.World.info.name; tmp.timeTillTrigger = Find.TickManager.TicksGame + timeToTravel; tmp.source = Find.World.GetComponent <FactionFC>().capitalLocation; Find.World.GetComponent <FactionFC>().addEvent(tmp); Find.World.GetComponent <FactionFC>().settlementCaravansList.Add(tmp.location.ToString()); Messages.Message("CaravanSentToLocation".Translate() + " " + GenDate.ToStringTicksToDays((tmp.timeTillTrigger - Find.TickManager.TicksGame)) + "!", MessageTypeDefOf.PositiveEvent); // when event activate FactionColonies.createPlayerColonySettlement(currentTileSelected); } } else { //if don't have enough monies to make settlement Messages.Message("NotEnoughSilverToSettle".Translate() + "!", MessageTypeDefOf.NeutralEvent); } } //reset anchor/font Text.Font = fontBefore; Text.Anchor = anchorBefore; }
public static militaryForce createMilitaryForceFromSettlement(SettlementFC settlement) { //get efficiency from traits and settlement efficiency. double militaryLevel = settlement.settlementMilitaryLevel; double efficiency = traitUtilsFC.cycleTraits(new double(), "militaryMultiplierCombatEfficiency", Find.World.GetComponent <FactionFC>().traits, "multiply") * traitUtilsFC.cycleTraits(new double(), "militaryMultiplierCombatEfficiency", settlement.traits, "multiply"); militaryForce returnForce = new militaryForce(militaryLevel, efficiency, settlement, FactionColonies.getPlayerColonyFaction()); return(returnForce); //create and return force. }
public override bool HandlesThingDef(ThingDef thingDef) { FactionFC factionfc = Find.World.GetComponent <FactionFC>(); return(!FactionColonies.canCraftItem(thingDef, true)); }
public void DrawProductionHeaderLower(int x, int y, int spacing) { Text.Anchor = TextAnchor.MiddleRight; Text.Font = GameFont.Small; //Assigned workers Widgets.Label(new Rect(x, y, 410, 30), "AssignedWorkers".Translate() + ": " + settlement.getTotalWorkers().ToString() + " / " + settlement.workersMax.ToString() + " / " + settlement.workersUltraMax.ToString()); Text.Anchor = TextAnchor.MiddleCenter; Text.Font = GameFont.Tiny; //Item Headers Widgets.DrawHighlight(new Rect(x, y + 30, 40, 40)); Widgets.Label(new Rect(x, y + 30, 40, 40), "IsTithe".Translate() + "?"); Widgets.DrawHighlight(new Rect(x + 80, y + 30, 100, 40)); Widgets.Label(new Rect(x + 80, y + 30, 100, 40), "ProductionEfficiency".Translate()); Widgets.DrawHighlight(new Rect(x + 195, y + 30, 45, 40)); Widgets.Label(new Rect(x + 195, y + 30, 45, 40), "Base".Translate()); Widgets.DrawHighlight(new Rect(x + 250, y + 30, 50, 40)); Widgets.Label(new Rect(x + 250, y + 30, 50, 40), "Modifier".Translate()); Widgets.DrawHighlight(new Rect(x + 310, y + 30, 45, 40)); Widgets.Label(new Rect(x + 310, y + 30, 45, 40), "Final".Translate()); Widgets.DrawHighlight(new Rect(x + 365, y + 30, 45, 40)); Widgets.Label(new Rect(x + 365, y + 30, 45, 40), "EstimatedProfit".Translate()); Widgets.DrawHighlight(new Rect(x + 420, y + 30, 45, 40)); Widgets.Label(new Rect(x + 420, y + 30, 45, 40), "TaxPercentage".Translate()); //Per resource for (int i = 0; i < settlement.getNumberResource(); i++) { ResourceFC resource = settlement.returnResourceByInt(i); if ((i * scrollSpacing) + scroll < 0) { //if outside view } else { //loop through each resource //isTithe bool disabled = false; switch (i) { case 6: case 7: disabled = true; break; } switch (i) { case 0: //food case 1: case 2: case 3: case 4: case 5: case 8: if (Widgets.ButtonImage(new Rect(x - 15, scroll + y + 65 + (i * (45 + spacing)) + 8, 20, 20), texLoad.iconCustomize)) { //if click faction customize button int k = i; if (resource.filter == null) { resource.filter = new ThingFilter(); PaymentUtil.resetThingFilter(settlement, i); } List <FloatMenuOption> options = new List <FloatMenuOption>(); options.Add(new FloatMenuOption("Enable All", delegate { PaymentUtil.resetThingFilter(settlement, k); resource.returnLowestCost(); })); options.Add(new FloatMenuOption("Disable All", delegate { resource.filter.SetDisallowAll(); resource.returnLowestCost(); })); List <ThingDef> things = PaymentUtil.debugGenerateTithe(i); foreach (ThingDef thing in things) { FloatMenuOption option; if (!FactionColonies.canCraftItem(thing)) { resource.filter.SetAllow(thing, false); } else { option = new FloatMenuOption(thing.LabelCap + " - Cost - " + thing.BaseMarketValue + " | Allowed: " + resource.filter.Allows(thing), delegate { resource.filter.SetAllow(thing, !resource.filter.Allows(thing)); resource.returnLowestCost(); }, thing); options.Add(option); } } FloatMenu menu = new FloatMenu(options); Find.WindowStack.Add(menu); //Log.Message("Settlement customize clicked"); } break; } Widgets.Checkbox(new Vector2(x + 8, scroll + y + 65 + (i * (45 + spacing)) + 8), ref settlement.returnResourceByInt(i).isTithe, 24, disabled); if (settlement.returnResourceByInt(i).isTithe != settlement.returnResourceByInt(i).isTitheBool) { settlement.returnResourceByInt(i).isTitheBool = settlement.returnResourceByInt(i).isTithe; //Log.Message("changed tithe"); settlement.updateProfitAndProduction(); WindowUpdateFC(); } //Icon if (Widgets.ButtonImage(new Rect(x + 45, scroll + y + 75 + (i * (45 + spacing)), 30, 30), settlement.returnResourceByInt(i).getIcon())) { Find.WindowStack.Add(new descWindowFC("SettlementProductionOf".Translate() + ": " + settlement.returnResourceByInt(i).label, char.ToUpper(settlement.returnResourceByInt(i).label[0]) + settlement.returnResourceByInt(i).label.Substring(1))); } ; //Production Efficiency Widgets.DrawBox(new Rect(x + 80, scroll + y + 70 + (i * (45 + spacing)), 100, 20)); Widgets.FillableBar(new Rect(x + 80, scroll + y + 70 + (i * (45 + spacing)), 100, 20), (float)Math.Min(settlement.returnResourceByInt(i).baseProductionMultiplier, 1.0)); Widgets.Label(new Rect(x + 80, scroll + y + 90 + (i * (45 + spacing)), 100, 20), "Workers".Translate() + ": " + settlement.returnResourceByInt(i).assignedWorkers.ToString()); if (Widgets.ButtonText(new Rect(x + 80, scroll + y + 90 + (i * (45 + spacing)), 20, 20), "<")) { //if clicked to lower amount of workers settlement.increaseWorkers(i, -1); WindowUpdateFC(); } if (Widgets.ButtonText(new Rect(x + 160, scroll + y + 90 + (i * (45 + spacing)), 20, 20), ">")) { //if clicked to lower amount of workers settlement.increaseWorkers(i, 1); WindowUpdateFC(); } //Base Production Widgets.Label(new Rect(x + 195, scroll + y + 70 + (i * (45 + spacing)), 45, 40), FactionColonies.FloorStat(settlement.returnResourceByInt(i).baseProduction)); //Final Modifier Widgets.Label(new Rect(x + 250, scroll + y + 70 + (i * (45 + spacing)), 50, 40), FactionColonies.FloorStat(settlement.returnResourceByInt(i).endProductionMultiplier)); //Final Base Widgets.Label(new Rect(x + 310, scroll + y + 70 + (i * (45 + spacing)), 45, 40), (FactionColonies.FloorStat(settlement.returnResourceByInt(i).endProduction))); //Est Income Widgets.Label(new Rect(x + 365, scroll + y + 70 + (i * (45 + spacing)), 45, 40), (FactionColonies.FloorStat(settlement.returnResourceByInt(i).endProduction *LoadedModManager.GetMod <FactionColoniesMod>().GetSettings <FactionColonies>().silverPerResource))); //Tithe Percentage Widgets.Label(new Rect(x + 420, scroll + y + 70 + (i * (45 + spacing)), 45, 40), FactionColonies.FloorStat(settlement.returnResourceByInt(i).taxPercentage) + "%"); } } //Scroll window for resources if (Event.current.type == EventType.ScrollWheel) { scrollWindow(Event.current.delta.y); } }
public IEnumerable <Thing> ColonyThingsWillingToBuy(Pawn playerNegotiator) { foreach (Map map in Find.Maps) { if (map.IsPlayerHome) { foreach (Thing thing in map.listerThings.AllThings) { if (thing.IsInAnyStorage() == true && thing.def.category == ThingCategory.Item && TradeUtility.PlayerSellableNow(thing, this) && !FactionColonies.canCraftItem(thing.def, true)) { yield return(thing); } } } } }
private static void Postfix(ref Pawn __instance, ref IEnumerable <Gizmo> __result) { var output = __result.ToList(); if (__result == null || __instance?.Faction == null || !output.Any() || !(__instance.Map.Parent is WorldSettlementFC)) { return; } var found = __instance; var pawnDraftController = __instance.drafter ?? new Pawn_DraftController(__instance); var settlementFc = (WorldSettlementFC)__instance.Map.Parent; if (__instance.Faction.Equals(FactionColonies.getPlayerColonyFaction())) { var draftColonists = new Command_Toggle { hotKey = KeyBindingDefOf.Command_ColonistDraft, isActive = () => false, toggleAction = () => { if (pawnDraftController.pawn.Faction.Equals(Faction.OfPlayer)) { return; } pawnDraftController.pawn.SetFaction(Faction.OfPlayer); pawnDraftController.Drafted = true; }, defaultDesc = "CommandToggleDraftDesc".Translate(), icon = TexCommand.Draft, turnOnSound = SoundDefOf.DraftOn, groupKey = 81729172, defaultLabel = "CommandDraftLabel".Translate() }; if (pawnDraftController.pawn.Downed) { draftColonists.Disable("IsIncapped".Translate( (NamedArgument)pawnDraftController.pawn.LabelShort, (NamedArgument)pawnDraftController.pawn)); } draftColonists.tutorTag = "Draft"; output.Add(draftColonists); } else if (__instance.Faction.Equals(Faction.OfPlayer) && __instance.Drafted && !settlementFc.supporting.Any(caravan => caravan.pawns.Any(pawn => pawn.Equals(found)))) { foreach (Command_Toggle action in output.Where(gizmo => gizmo is Command_Toggle)) { if (action.hotKey != KeyBindingDefOf.Command_ColonistDraft) { continue; } var index = output.IndexOf(action); action.toggleAction = () => { found.SetFaction(FactionColonies.getPlayerColonyFaction()); //settlementFc.worldSettlement.defenderLord.AddPawn(__instance); }; output[index] = action; break; } } __result = output; }
public override void DoWindowContents(Rect inRect) { //grab before anchor/font GameFont fontBefore = Text.Font; TextAnchor anchorBefore = Text.Anchor; //Settlement Tax Collection Header Text.Anchor = TextAnchor.MiddleLeft; Text.Font = GameFont.Medium; Widgets.Label(labelFaction, header); Text.Font = GameFont.Small; Widgets.Label(labelFactionName, "FactionName".Translate() + ":"); name = Widgets.TextField(textfieldName, name); Widgets.Label(labelFactionTitle, "FactionTitle".Translate() + ":"); title = Widgets.TextField(textfieldTitle, title); Widgets.Label(labelFactionIcon, "FactionIcon".Translate()); if (Widgets.ButtonImage(buttonIcon, tempFactionIcon)) { List <FloatMenuOption> list = TexLoad.factionIcons.Select(texture => new FloatMenuOption(texture.name, delegate { tempFactionIcon = texture; tempFactionIconPath = texture.name; }, texture, Color.white)).ToList(); FloatMenu menu = new FloatMenu(list); Find.WindowStack.Add(menu); } if (Widgets.ButtonText(buttonConfirm, "ConfirmChanges".Translate())) { Faction fact = FactionColonies.getPlayerColonyFaction(); faction.title = title; faction.name = name; fact.Name = name; faction.name = name; faction.factionIconPath = tempFactionIconPath; faction.factionIcon = tempFactionIcon; faction.updateFactionRaces(); faction.factionBackup = fact; faction.updateFactionIcon(ref fact, "FactionIcons/" + tempFactionIconPath); if (!traitsChosen) { //check each trait bool. If true and does not exist already, add to factionfc if (boolMilitaristic) { faction.policies.Add(new FCPolicy(FCPolicyDefOf.militaristic)); } if (boolPacifist) { faction.policies.Add(new FCPolicy(FCPolicyDefOf.pacifist)); } if (boolAuthoritarian) { faction.policies.Add(new FCPolicy(FCPolicyDefOf.authoritarian)); } if (boolEgalitarian) { faction.policies.Add(new FCPolicy(FCPolicyDefOf.egalitarian)); } if (boolIsolationist) { faction.policies.Add(new FCPolicy(FCPolicyDefOf.isolationist)); } if (boolExpansionist) { faction.policies.Add(new FCPolicy(FCPolicyDefOf.expansionist)); } if (boolTechnocrat) { faction.policies.Add(new FCPolicy(FCPolicyDefOf.technocratic)); } if (boolFeudal) { faction.policies.Add(new FCPolicy(FCPolicyDefOf.feudal)); } } Find.WindowStack.TryRemove(this); } if (!traitsChosen) { switch (faction.policies.Count()) { case 0: case 1: alertText = "FCSelectTraits0".Translate(); break; case 2: alertText = "FCSelectTraits2".Translate(); break; } } else { alertText = "FCTraitsChosen".Translate(); } Widgets.Label(labelPickTrait, alertText); Texture2D icon = TexLoad.iconLoyalty; if (boolMilitaristic) { icon = FCPolicyDefOf.militaristic.IconLight; } else { icon = FCPolicyDefOf.militaristic.IconDark; } if (buttonMilitaristic.Contains(Event.current.mousePosition)) { TooltipHandler.TipRegion(buttonMilitaristic, returnPolicyText(FCPolicyDefOf.militaristic)); } if (Widgets.ButtonImage(buttonMilitaristic, icon)) { if (numberTraitsSelected <= 1 || boolMilitaristic) { //Continue if (boolPacifist == false) { boolMilitaristic = !boolMilitaristic; if (boolMilitaristic) { numberTraitsSelected += 1; } else { numberTraitsSelected -= 1; } policyText = returnPolicyText(FCPolicyDefOf.militaristic); } else { Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput); } } else { Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput); } } if (boolAuthoritarian) { icon = FCPolicyDefOf.authoritarian.IconLight; } else { icon = FCPolicyDefOf.authoritarian.IconDark; } if (buttonAuthoritarian.Contains(Event.current.mousePosition)) { TooltipHandler.TipRegion(buttonAuthoritarian, returnPolicyText(FCPolicyDefOf.authoritarian)); } if (Widgets.ButtonImage(buttonAuthoritarian, icon)) { if (numberTraitsSelected <= 1 || boolAuthoritarian) { //Continue if (boolEgalitarian == false) { boolAuthoritarian = !boolAuthoritarian; if (boolAuthoritarian) { numberTraitsSelected += 1; } else { numberTraitsSelected -= 1; } policyText = returnPolicyText(FCPolicyDefOf.authoritarian); } else { Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput); } } else { Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput); } } if (boolIsolationist) { icon = FCPolicyDefOf.isolationist.IconLight; } else { icon = FCPolicyDefOf.isolationist.IconDark; } if (buttonIsolationist.Contains(Event.current.mousePosition)) { TooltipHandler.TipRegion(buttonIsolationist, returnPolicyText(FCPolicyDefOf.isolationist)); } if (Widgets.ButtonImage(buttonIsolationist, icon)) { if (numberTraitsSelected <= 1 || boolIsolationist) { //Continue if (boolExpansionist == false) { boolIsolationist = !boolIsolationist; if (boolIsolationist) { numberTraitsSelected += 1; } else { numberTraitsSelected -= 1; } policyText = returnPolicyText(FCPolicyDefOf.isolationist); } else { Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput); } } else { Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput); } } if (boolFeudal) { icon = FCPolicyDefOf.feudal.IconLight; } else { icon = FCPolicyDefOf.feudal.IconDark; } if (buttonFeudal.Contains(Event.current.mousePosition)) { TooltipHandler.TipRegion(buttonFeudal, returnPolicyText(FCPolicyDefOf.feudal)); } if (Widgets.ButtonImage(buttonFeudal, icon)) { if (numberTraitsSelected <= 1 || boolFeudal) { //Continue if (boolTechnocrat == false) { boolFeudal = !boolFeudal; if (boolFeudal) { numberTraitsSelected += 1; } else { numberTraitsSelected -= 1; } policyText = returnPolicyText(FCPolicyDefOf.feudal); } else { Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput); } } else { Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput); } } if (boolPacifist) { icon = FCPolicyDefOf.pacifist.IconLight; } else { icon = FCPolicyDefOf.pacifist.IconDark; } if (buttonPacifist.Contains(Event.current.mousePosition)) { TooltipHandler.TipRegion(buttonPacifist, returnPolicyText(FCPolicyDefOf.pacifist)); } if (Widgets.ButtonImage(buttonPacifist, icon)) { if (numberTraitsSelected <= 1 || boolPacifist) { //Continue if (boolMilitaristic == false) { boolPacifist = !boolPacifist; if (boolPacifist) { numberTraitsSelected += 1; } else { numberTraitsSelected -= 1; } policyText = returnPolicyText(FCPolicyDefOf.pacifist); } else { Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput); } } else { Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput); } } if (boolEgalitarian) { icon = FCPolicyDefOf.egalitarian.IconLight; } else { icon = FCPolicyDefOf.egalitarian.IconDark; } if (buttonEgalitarian.Contains(Event.current.mousePosition)) { TooltipHandler.TipRegion(buttonEgalitarian, returnPolicyText(FCPolicyDefOf.egalitarian)); } if (Widgets.ButtonImage(buttonEgalitarian, icon)) { if (numberTraitsSelected <= 1 || boolEgalitarian) { //Continue if (boolAuthoritarian == false) { boolEgalitarian = !boolEgalitarian; if (boolEgalitarian) { numberTraitsSelected += 1; } else { numberTraitsSelected -= 1; } policyText = returnPolicyText(FCPolicyDefOf.egalitarian); } else { Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput); } } else { Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput); } } if (boolExpansionist) { icon = FCPolicyDefOf.expansionist.IconLight; } else { icon = FCPolicyDefOf.expansionist.IconDark; } if (buttonExpansionist.Contains(Event.current.mousePosition)) { TooltipHandler.TipRegion(buttonExpansionist, returnPolicyText(FCPolicyDefOf.expansionist)); } if (Widgets.ButtonImage(buttonExpansionist, icon)) { if (numberTraitsSelected <= 1 || boolExpansionist) { //Continue if (boolIsolationist == false) { boolExpansionist = !boolExpansionist; if (boolExpansionist) { numberTraitsSelected += 1; } else { numberTraitsSelected -= 1; } policyText = returnPolicyText(FCPolicyDefOf.expansionist); } else { Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput); } } else { Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput); } } if (boolTechnocrat) { icon = FCPolicyDefOf.technocratic.IconLight; } else { icon = FCPolicyDefOf.technocratic.IconDark; } if (buttonTechnocrat.Contains(Event.current.mousePosition)) { TooltipHandler.TipRegion(buttonTechnocrat, returnPolicyText(FCPolicyDefOf.technocratic)); } if (Widgets.ButtonImage(buttonTechnocrat, icon)) { if (numberTraitsSelected <= 1 || boolTechnocrat) { //Continue if (boolFeudal == false) { boolTechnocrat = !boolTechnocrat; if (boolTechnocrat) { numberTraitsSelected += 1; } else { numberTraitsSelected -= 1; } policyText = returnPolicyText(FCPolicyDefOf.technocratic); } else { Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput); } } else { Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput); } } //Widgets.DrawMenuSection(menusectionTrait); //Widgets.Label(menusectionTrait, policyText); //reset anchor/font Text.Font = fontBefore; Text.Anchor = anchorBefore; }