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 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; }