// todo; figure out blueprint flipping //public void Flip() //{ // _position.x = -_position.x; //} public Designator_Build CreateLocalDesignatorCopy() { // create a new copy var designator = new Designator_Build(BuildableDef); // apply stuffdef & rotation if (_thingDef != null) { // set stuff def if (_stuff == null) { designator.SetStuffDef(GenStuff.DefaultStuffFor(_thingDef)); } else { designator.SetStuffDef(_stuff); } // set rotation through reflection Resources.SetDesignatorRotation(designator, _rotation); } return(designator); }
// RimWorld.BuildCopyCommandUtility public static Command PlaceRuneBlueprint(BuildableDef buildable, ThingDef stuff) { Designator_Build des = RuneUtility.FindAllowedDesignator(buildable); if (des == null) { return(null); } if (!des.Visible) { return(null); } Command_Action command_Action = new Command_Action(); command_Action.action = delegate { SoundDefOf.SelectDesignator.PlayOneShotOnCamera(null); des.SetStuffDef(stuff); Find.DesignatorManager.Select(des); }; command_Action.defaultLabel = buildable.label.Translate(); command_Action.defaultDesc = buildable.description.Translate(); command_Action.icon = des.icon; command_Action.iconProportions = des.iconProportions; command_Action.iconDrawScale = des.iconDrawScale; command_Action.iconTexCoords = des.iconTexCoords; if (stuff != null) { command_Action.defaultIconColor = stuff.stuffProps.color; } else { command_Action.defaultIconColor = buildable.IconDrawColor; } command_Action.hotKey = KeyBindingDefOf.Misc11; return(command_Action); }
public bool BuildingDesignatorControl() { if (Find.CurrentMap == null || Find.DesignatorManager == null) { return(true); } var Dem = Find.DesignatorManager.SelectedDesignator; if (Dem != null && Dem is Designator_Build) { if (Event.current.type == EventType.MouseDown && Event.current.button == 2) { //Better than UI.mousecell MiddleClickCell = Find.CameraDriver.MapPosition; } //Middle click to select designator if (Event.current.type == EventType.MouseUp && Event.current.button == 2 && MiddleClickCell == Find.CameraDriver.MapPosition) { Thing targetThing = null; IntVec3 UICell = UI.MouseCell(); Map map = Find.CurrentMap; if (map == null) { return(false); } if (!UICell.InBounds(map)) { return(false); } //Search for blueprints if (targetThing == null) { targetThing = UICell.GetFirstThing <Blueprint>(map); } //Search for frames if (targetThing == null) { targetThing = UICell.GetFirstThing <Frame>(map); } //Search for Buildings if (targetThing == null) { targetThing = UICell.GetFirstBuilding(map); } //Can't find things if (targetThing == null) { //SoundDefOf.ClickReject.PlayOneShotOnCamera(); Event.current.Use(); return(false); } //Find designator Designator_Build Desig = null; Desig = BuildCopyCommandUtility.FindAllowedDesignator(targetThing.def); if (Desig == null && (targetThing is Blueprint || targetThing is Frame)) { Desig = BuildCopyCommandUtility.FindAllowedDesignator(targetThing.def.entityDefToBuild); } if ((targetThing.def.BuildableByPlayer || targetThing.def.entityDefToBuild?.BuildableByPlayer == true) && Desig != null) { //Set stuff if (targetThing.Stuff != null) { Desig.SetStuffDef(targetThing.Stuff); } if ((targetThing as Blueprint_Build)?.stuffToUse != null) { Desig.SetStuffDef((targetThing as Blueprint_Build).stuffToUse); } if ((targetThing as Blueprint_Install)?.Stuff != null) { Desig.SetStuffDef((targetThing as Blueprint_Install).Stuff); } if ((targetThing as Frame)?.Stuff != null) { Desig.SetStuffDef((targetThing as Frame).Stuff); } Find.DesignatorManager.Select(Desig); SoundDefOf.Click.PlayOneShotOnCamera(); } else { //SoundDefOf.ClickReject.PlayOneShotOnCamera(); } Event.current.Use(); return(false); } //Cancel drag //First, absorb Right click event, handle it manually if (Event.current.type == EventType.MouseDown && Event.current.button == 1) { Event.current.Use(); } if (IsCancelDragging) { GenUI.DrawMouseAttachment(CancelIcon, string.Empty, 0); } if (Input.GetMouseButton(1)) { if (IsCancelDragging) { //RenderCancelHighlights(); } else { //Start cancel dragging IsCancelDragging = true; DragStart = UI.MouseCell(); SoundDefOf.Click.PlayOneShotOnCamera(null); } } //Right click up else if (Event.current.type == EventType.MouseUp && Event.current.button == 1) { IsCancelDragging = false; selectedThings.Clear(); Event.current.Use(); if (selectedThings.Any()) { selectedThings.Do(delegate(Thing t) { t.Destroy(DestroyMode.Cancel); }); SoundDefOf.Designate_Cancel.PlayOneShotOnCamera(); } else { SoundDefOf.CancelMode.PlayOneShotOnCamera(null); Find.DesignatorManager.Deselect(); return(false); } } //While cancel dragging, left click to abort if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && IsCancelDragging) { selectedThings.Clear(); IsCancelDragging = false; SoundDefOf.CancelMode.PlayOneShotOnCamera(null); Find.DesignatorManager.Deselect(); Event.current.Use(); return(false); } //Drag to place blueprints var BuildDesignator = (Designator_Build)Dem; if (BuildDesignator.DraggableDimensions != 0) { return(true); } if (Event.current.type == EventType.MouseDown && Event.current.button == 0) { PreviousCell = IntVec3.Invalid; ClickedFlag = true; Event.current.Use(); } if (Event.current.type == EventType.MouseUp && Event.current.button == 0) { PreviousCell = IntVec3.Invalid; ClickedFlag = false; Event.current.Use(); } if (Input.GetMouseButton(0) && !Mouse.IsInputBlockedNow && PreviousCell != UI.MouseCell() && ClickedFlag) { var acceptanceReport = BuildDesignator.CanDesignateCell(UI.MouseCell()); if (DebugSettings.godMode && acceptanceReport.Accepted) //Handle god mode { Traverse t = Traverse.Create(BuildDesignator); BuildableDef entDef = t.Field("entDef").GetValue <BuildableDef>(); Rot4 rot = t.Field("placingRot").GetValue <Rot4>(); CellRect cellRect = GenAdj.OccupiedRect(UI.MouseCell(), rot, entDef.Size); foreach (IntVec3 c in cellRect) { var thinglist = c.GetThingList(Find.CurrentMap); for (int i = 0; i < thinglist.Count; i++) { var thing3 = thinglist[i]; if (!GenConstruct.CanPlaceBlueprintOver(entDef, thing3.def)) { acceptanceReport = new AcceptanceReport("SpaceAlreadyOccupied_DevFail"); } } } } if (acceptanceReport.Accepted) { BuildDesignator.DesignateSingleCell(UI.MouseCell()); BuildDesignator.Finalize(true); } else { //If this is first cell clicked if (PreviousCell == IntVec3.Invalid) { Messages.Message(acceptanceReport.Reason, MessageTypeDefOf.SilentInput, false); BuildDesignator.Finalize(false); } } PreviousCell = UI.MouseCell(); //Event.current.Use(); } return(false); } else //This is not Building designator { IsCancelDragging = false; return(true); } }