public static void Initialise() { MoreToolsBtn = null; MoreToolsPanel = null; MoreButtons = new Dictionary <string, UIButton>(); MIT = MoveItTool.instance; }
// Constructor for FindIt object public CloneActionFindIt(PrefabInfo prefab) { m_oldSelection = selection; m_states.Clear(); Vector3 position = MoveItTool.RaycastMouseLocation(); InstanceState state = new InstanceState(); if (prefab is BuildingInfo) { state = new BuildingState { isSubInstance = false, isHidden = false, flags = Building.Flags.Completed }; state.Info.Prefab = prefab; InstanceID id = new InstanceID { Building = 1, Type = InstanceType.Building }; state.instance = new MoveableBuilding(id); } else if (prefab is PropInfo) { state = new PropState { fixedHeight = false, single = false, }; state.Info.Prefab = prefab; InstanceID id = new InstanceID { Prop = 1, Type = InstanceType.Prop }; state.instance = new MoveableProp(id); } else if (prefab is TreeInfo) { state = new TreeState { fixedHeight = false, single = false, }; state.Info.Prefab = prefab; InstanceID id = new InstanceID { Tree = 1, Type = InstanceType.Tree }; state.instance = new MoveableTree(id); } state.position = position; state.terrainHeight = position.y; m_states.Add(state); center = position; }
public void Paste(InstanceID original, InstanceID target, int id) { InstanceID cloneID = target; cloneID.NetLane = (uint)id + 1; MoveItTool.PO.visibleObjects.Add(cloneID.NetLane, GetPOById((uint)id + 1)); MoveableProc cloneInstance = new MoveableProc(cloneID) { }; Action.selection.Add(cloneInstance); if (ActionQueue.instance.current is CloneActionBase ca) { ca.m_clones.Add(cloneInstance); ca.m_origToClone.Add(new MoveableProc(original), cloneInstance); } else { Log.Debug($"Current action is {ActionQueue.instance.current.GetType()}, not CloneActionBase"); } MoveItTool.SetToolState(); MoveItTool.instance.ProcessSensitivityMode(false); Log.Info($"Cloned PO {original.NetLane} to #{cloneInstance.id.NetLane} (new method)"); }
public MoveableNode GetNodeByDistance(bool furthest = false) { Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); Vector3 clickPos = MoveItTool.RaycastMouseLocation(mouseRay); if (Vector3.Distance(StartNode.position, clickPos) < Vector3.Distance(EndNode.position, clickPos)) { if (furthest) { return(EndNode); } else { return(StartNode); } } else { if (furthest) { return(StartNode); } else { return(EndNode); } } }
public void Add(Instance instance) { Debug.Log($"Adding:{MoveItTool.InstanceIDDebug(instance.id)}"); if (!selection.Contains(instance)) { m_newSelection.Add(instance); } }
public IEnumerator <object> RetrieveClone(MoveableProc original, Vector3 position, float angle, Action action) { const uint MaxAttempts = 1000_000; CloneAction ca = (CloneAction)action; Type[] types = new Type[] { tPO, tPO.MakeByRefType(), typeof(uint).MakeByRefType() }; object[] paramList = new[] { original.m_procObj.GetProceduralObject(), null, null }; MethodInfo retrieve = tPOMoveIt.GetMethod("TryRetrieveClone", BindingFlags.Public | BindingFlags.Static, null, types, null); uint c = 0; while (c < MaxAttempts && !(bool)retrieve.Invoke(null, paramList)) { //if (c % 100 == 0) //{ // BindingFlags f = BindingFlags.Static | BindingFlags.Public; // object queueObj = tPOMoveIt.GetField("queuedCloning", f).GetValue(null); // int queueCount = (int)queueObj.GetType().GetProperty("Count").GetValue(queueObj, null); // object doneObj = tPOMoveIt.GetField("doneCloning", f).GetValue(null); // int doneCount = (int)doneObj.GetType().GetProperty("Count").GetValue(doneObj, null); //} c++; yield return(new WaitForSeconds(0.05f)); } if (c == MaxAttempts) { throw new Exception($"Failed to clone object #{original.m_procObj.Id}! [PO-F4]"); } PO_Object clone = new PO_Object(paramList[1]) { POColor = original.m_procObj.POColor }; InstanceID cloneID = default; cloneID.NetLane = clone.Id; MoveItTool.PO.visibleObjects.Add(cloneID.NetLane, clone); MoveableProc cloneInstance = new MoveableProc(cloneID) { position = position, angle = angle }; Action.selection.Add(cloneInstance); ca.m_clones.Add(cloneInstance); ca.m_origToClone.Add(original, cloneInstance); MoveItTool.SetToolState(); MoveItTool.instance.ProcessSensitivityMode(false); yield return(new WaitForSeconds(0.25f)); Debug.Log($"Cloned PO {original.m_procObj.Id} to #{clone.Id}"); MoveItTool.POProcessing--; }
//internal static Assembly GetNSAssembly() //{ // Log.Debug($"AAB01 GetNSAssembly"); // try // { // foreach (PluginManager.PluginInfo pluginInfo in Singleton<PluginManager>.instance.GetPluginsInfo()) // { // try // { // Log.Debug($"AAB02 GetNSAssembly"); // Log.Debug($"AAB02.1 {pluginInfo}"); // Log.Debug($"AAB02.2 {pluginInfo.userModInstance ?? "<null>"}"); // Log.Debug($"AAB02.3 {pluginInfo.userModInstance?.GetType()}"); // Log.Debug($"AAB02.4 {pluginInfo.userModInstance?.GetType().Name}"); // if (pluginInfo.userModInstance?.GetType().Name.ToLower() == "networkskinsmod" && pluginInfo.isEnabled) // { // Log.Debug($"AAB03 GetNSAssembly"); // // Network Skins 1 - unsupported - uses CimTools // if (pluginInfo.GetAssemblies().Any(mod => mod.GetName().Name.ToLower() == "cimtools")) // { // Log.Debug($"AAB04 GetNSAssembly"); // break; // } // Log.Debug($"AAB05 GetNSAssembly"); // foreach (Assembly assembly in pluginInfo.GetAssemblies()) // { // Log.Debug($"AAB06 GetNSAssembly"); // if (assembly.GetName().Name.ToLower() == "networkskins") // { // Log.Debug($"AAB07 GetNSAssembly"); // return assembly; // } // } // } // } // catch (ReflectionTypeLoadException) // { // Log.Debug($"AAB09 ReflectionTypeLoadException"); // } // If the plugin parsing fails, go to next plugin // catch (NullReferenceException) // { // Log.Debug($"AAB10 NullReferenceException"); // } // If the plugin parsing fails, go to next plugin // } // Log.Debug($"AAB08 GetNSAssembly"); // } // catch (ReflectionTypeLoadException) // { // Log.Debug($"AAB11 ReflectionTypeLoadException"); // } // If the plugin parsing fails, go to next plugin // catch (NullReferenceException) // { // Log.Debug($"AAB12 NullReferenceException"); // } // If the plugin parsing fails, go to next plugin // return null; //} internal static string getVersionText() { if (MoveItTool.GetAssembly("networkskinsmod", "networkskins", "cimtools") != null) { return(Str.integration_NS2_Found); } return(Str.integration_NS2_Notfound); }
public void DoImplementation(bool skipPO = false) { m_oldSelection = selection; Bounds bounds = GetTotalBounds(false); foreach (InstanceState state in m_states) { if (skipPO && state is ProcState) { continue; } if (state is BuildingState) { continue; } if (state.instance.isValid) { state.instance.Delete(); } } // Remove buildings last so attached nodes are cleaned up foreach (InstanceState state in m_states) { if (skipPO && state is ProcState) { continue; } if (!(state is BuildingState)) { continue; } if (state.instance.isValid) { state.instance.Delete(); } } UpdateArea(bounds); selection = new HashSet <Instance>(); MoveItTool.m_debugPanel.UpdatePanel(); MoveItTool.UpdatePillarMap(); }
public override void Undo() { if (m_clones == null) { return; } Bounds bounds = GetTotalBounds(false); foreach (Instance instance in m_clones) { instance.Delete(); } m_clones = null; // Restore selection selection = m_oldSelection; MoveItTool.m_debugPanel.UpdatePanel(); UpdateArea(bounds); MoveItTool.UpdatePillarMap(); }
public override void RenderOverlay(RenderManager.CameraInfo cameraInfo, Color toolColor, Color despawnColor) { if (!isValid) { return; } ushort node = id.NetNode; NetManager netManager = NetManager.instance; NetInfo netInfo = nodeBuffer[node].Info; Vector3 position = nodeBuffer[node].m_position; // NON-STOCK CODE STARTS if (MoveItTool.IsCSUROffset(netInfo)) { var tmpDir = MoveItTool.GetNodeDir(node); tmpDir = new Vector3(tmpDir.z, tmpDir.y, -tmpDir.x); position = tmpDir * (netInfo.m_halfWidth + netInfo.m_pavementWidth) / 2f + position; } // NON-STOCK CODE ENDS Randomizer randomizer = new Randomizer(node); float alpha = 1f; NetTool.CheckOverlayAlpha(netInfo, ref alpha); toolColor.a *= alpha; // NON-STOCK CODE STARTS if (MoveItTool.IsCSUROffset(netInfo)) { RenderManager.instance.OverlayEffect.DrawCircle(cameraInfo, toolColor, position, Mathf.Max(6f, netInfo.m_halfWidth - netInfo.m_pavementWidth), -1f, 1280f, false, true); } else { RenderManager.instance.OverlayEffect.DrawCircle(cameraInfo, toolColor, position, Mathf.Max(6f, netInfo.m_halfWidth * 2f), -1f, 1280f, false, true); } // NON-STOCK CODE ENDS }
internal NS_Manager() { Enabled = false; Assembly = MoveItTool.GetAssembly("networkskinsmod", "networkskins", "cimtools"); if (Assembly != null) { tNS = Assembly.GetType("NetworkSkins.Skins.NetworkSkin"); if (tNS == null) { throw new Exception("Type NetworkSkins not found (Failed [NS-F2])"); } tNSM = Assembly.GetType("NetworkSkins.Skins.NetworkSkinManager"); if (tNSM == null) { throw new Exception("Type NetworkSkinManager not found (Failed [NS-F3])"); } tNSModifier = Assembly.GetType("NetworkSkins.Skins.NetworkSkinModifier"); if (tNSModifier == null) { throw new Exception("Type NetworkSkinModifier not found (Failed [NS-F4])"); } tListSkins = typeof(List <>).MakeGenericType(new Type[] { tNS }); tListMods = typeof(List <>).MakeGenericType(new Type[] { tNSModifier }); tDictMods = typeof(Dictionary <,>).MakeGenericType(new Type[] { typeof(NetInfo), tListMods }); NSM = tNSM.GetProperty("instance", BindingFlags.Public | BindingFlags.Static).GetValue(null, null); if (NSM == null) { throw new Exception("Object NetworkSkinManager not found (Failed [NS-F5])"); } Enabled = true; } }
protected HashSet <InstanceState> ProcessPillars(HashSet <InstanceState> states, bool makeClone) { if (!MoveItTool.advancedPillarControl) { return(states); } HashSet <ushort> nodesWithAttachments = new HashSet <ushort>(); var watch = new System.Diagnostics.Stopwatch(); watch.Start(); foreach (InstanceState instanceState in states) { if (instanceState is NodeState ns && ((NetNode)(ns.instance.data)).m_building > 0 && ((buildingBuffer[((NetNode)(ns.instance.data)).m_building].m_flags & Building.Flags.Hidden) != Building.Flags.Hidden)) { nodesWithAttachments.Add(ns.instance.id.NetNode); //Debug.Log($"Node {ns.instance.id.NetNode} found"); } } HashSet <InstanceState> newStates = new HashSet <InstanceState>(states); foreach (InstanceState instanceState in states) { ushort buildingId = instanceState.instance.id.Building; if (instanceState is BuildingState originalState && MoveItTool.m_pillarMap.ContainsKey(buildingId) && MoveItTool.m_pillarMap[buildingId] > 0) { ushort nodeId = MoveItTool.m_pillarMap[buildingId]; if (nodesWithAttachments.Contains(nodeId)) // The node is also selected { //Debug.Log($"Pillar {buildingId} for selected node {nodeId}"); continue; } MoveableBuilding original = (MoveableBuilding)instanceState.instance; buildingBuffer[buildingId].m_flags |= Building.Flags.Hidden; selection.Remove(original); newStates.Remove(originalState); BuildingState cloneState = null; if (makeClone) { MoveableBuilding clone = original.Duplicate(); selection.Add(clone); cloneState = (BuildingState)clone.SaveToState(); newStates.Add(cloneState); Debug.Log($"Pillar {buildingId} for node {nodeId} duplicated to {clone.id.Building}"); } else { Debug.Log($"Pillar {buildingId} for node {nodeId} hidden"); } pillarsOriginalToClone.Add(originalState, cloneState); original.isHidden = true; } } if (pillarsOriginalToClone.Count > 0) { MoveItTool.UpdatePillarMap(); } states = newStates; watch.Stop(); Debug.Log($"Pillars handled in {watch.ElapsedMilliseconds} ms\nSelected nodes:{nodesWithAttachments.Count}, total selection:{states.Count}, dups mapped:{pillarsOriginalToClone.Count}"); PillarsProcessed = true; return(states); }
public override void Do() { Vector3 PoR; Matrix4x4 matrix = default; Bounds bounds = GetTotalBounds(); float angleDelta; System.Random random = new System.Random(); BuildingManager buildingManager = Singleton <BuildingManager> .instance; angleDelta = 0 - GetAngle() + newAngle; PoR = bounds.center; foreach (InstanceState state in m_states) { if (state.instance.isValid) { if (state.instance is MoveableBuilding mb) { if (Mathf.Abs(Singleton <TerrainManager> .instance.SampleOriginalRawHeightSmooth(mb.position) - mb.position.y) > 0.01f) { mb.AddFixedHeightFlag(mb.id.Building); } else { mb.RemoveFixedHeightFlag(mb.id.Building); } if (this is AlignIndividualAction) { angleDelta = 0 - mb.angle + newAngle; PoR = state.position; } else if (this is AlignRandomAction) { angleDelta = 0 - mb.angle + (float)(random.NextDouble() * Math.PI * 2); PoR = state.position; } matrix.SetTRS(PoR, Quaternion.AngleAxis(angleDelta * Mathf.Rad2Deg, Vector3.down), Vector3.one); mb.Transform(state, ref matrix, 0f, angleDelta, PoR, followTerrain); BuildingInfo prefab = (BuildingInfo)state.Info.Prefab; ushort id = mb.id.Building; Building building = buildingManager.m_buildings.m_buffer[id]; if (prefab.m_hasParkingSpaces != VehicleInfo.VehicleType.None) { buildingManager.UpdateParkingSpaces(id, ref building); } buildingManager.UpdateBuildingRenderer(id, true); } else if (state.instance is MoveableProp mp) { if (this is AlignIndividualAction) { angleDelta = 0 - mp.angle + newAngle; PoR = state.position; } else if (this is AlignRandomAction) { angleDelta = 0 - mp.angle + (float)(random.NextDouble() * Math.PI * 2); PoR = state.position; } matrix.SetTRS(PoR, Quaternion.AngleAxis(angleDelta * Mathf.Rad2Deg, Vector3.down), Vector3.one); mp.Transform(state, ref matrix, 0f, angleDelta, PoR, followTerrain); } else if (state.instance is MoveableNode mn) { if (this is AlignIndividualAction) { angleDelta = 0 - mn.angle + newAngle; PoR = state.position; } else if (this is AlignRandomAction) { angleDelta = 0 - mn.angle + (float)(random.NextDouble() * Math.PI * 2); PoR = state.position; } matrix.SetTRS(PoR, Quaternion.AngleAxis(angleDelta * Mathf.Rad2Deg, Vector3.down), Vector3.one); mn.Transform(state, ref matrix, 0f, angleDelta, PoR, followTerrain); } else if (state.instance is MoveableProc mpo) { if (this is AlignIndividualAction) { angleDelta = 0 - mpo.angle + newAngle; PoR = state.position; } else if (this is AlignRandomAction) { angleDelta = 0 - mpo.angle + (float)(random.NextDouble() * Math.PI * 2); PoR = state.position; } matrix.SetTRS(PoR, Quaternion.AngleAxis(angleDelta * Mathf.Rad2Deg, Vector3.down), Vector3.one); mpo.Transform(state, ref matrix, 0f, angleDelta, PoR, followTerrain); } else if (state.instance is MoveableTree mt) { if (this is AlignIndividualAction || this is AlignRandomAction) { continue; } matrix.SetTRS(PoR, Quaternion.AngleAxis(angleDelta * Mathf.Rad2Deg, Vector3.down), Vector3.one); mt.Transform(state, ref matrix, 0f, angleDelta, PoR, followTerrain); } } } // Move segments after nodes, for updated positions foreach (InstanceState state in m_states) { if (state.instance.isValid) { if (state.instance is MoveableSegment ms) { if (this is AlignIndividualAction) { angleDelta = 0 - ms.angle + newAngle; PoR = state.position; } else if (this is AlignRandomAction) { angleDelta = 0 - ms.angle + (float)(random.NextDouble() * Math.PI * 2); PoR = state.position; } matrix.SetTRS(PoR, Quaternion.AngleAxis(angleDelta * Mathf.Rad2Deg, Vector3.down), Vector3.one); ms.Transform(state, ref matrix, 0f, angleDelta, PoR, followTerrain); } } } MoveItTool.SetToolState(); UpdateArea(bounds); UpdateArea(GetTotalBounds(false)); }
public static void MoreToolsClicked(string name, bool simAlt = false, bool simShift = false) { MoveItTool.instance.DeactivateTool(); MoveItTool.m_isLowSensitivity = false; switch (name) { case "MoveIt_MoreToolsBtn": if (MoreToolsPanel.isVisible) { MoreToolsPanel.isVisible = false; } else { MoreToolsPanel.isVisible = true; } UpdateMoreTools(); break; case "MoveIt_LoadBtn": UILoadWindow.Open(); break; case "MoveIt_SaveBtn": if (MoveItTool.IsExportSelectionValid()) { UISaveWindow.Open(); } else { UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel").SetMessage(Str.xml_SelectionInvalidTitle, Str.xml_SelectionInvalidMessage, false); } break; case "MoveIt_AlignHeightBtn": m_activeToolMenu = MoreButtons["MoveIt_HeightBtn"]; MIT.ProcessAligning(MoveItTool.MT_Tools.Height); break; case "MoveIt_AlignMirrorBtn": m_activeToolMenu = MoreButtons["MoveIt_OthersBtn"]; MIT.ProcessAligning(MoveItTool.MT_Tools.Mirror); break; case "MoveIt_AlignTerrainHeightBtn": if (MoveItTool.ToolState == MoveItTool.ToolStates.Cloning || MoveItTool.ToolState == MoveItTool.ToolStates.RightDraggingClone) { MIT.StopCloning(); } AlignTerrainHeightAction atha = new AlignTerrainHeightAction(); ActionQueue.instance.Push(atha); ActionQueue.instance.Do(); CheckCloseMenu(); MIT.DeactivateTool(); break; case "MoveIt_AlignSlopeBtn": if (simShift) { m_activeToolMenu = MoreButtons["MoveIt_HeightBtn"]; MIT.ProcessAligning(MoveItTool.MT_Tools.Slope); break; } if (MoveItTool.ToolState == MoveItTool.ToolStates.Cloning || MoveItTool.ToolState == MoveItTool.ToolStates.RightDraggingClone) { MIT.StopCloning(); } AlignSlopeAction asa = new AlignSlopeAction { followTerrain = MoveItTool.followTerrain, mode = AlignSlopeAction.Modes.Auto }; if (simAlt) { asa.mode = AlignSlopeAction.Modes.Quick; } ActionQueue.instance.Push(asa); ActionQueue.instance.Do(); CheckCloseMenu(); MIT.DeactivateTool(); break; case "MoveIt_AlignLineBtn": if (MoveItTool.ToolState == MoveItTool.ToolStates.Cloning || MoveItTool.ToolState == MoveItTool.ToolStates.RightDraggingClone) { MIT.StopCloning(); } LineAction la = new LineAction { followTerrain = MoveItTool.followTerrain, mode = LineAction.Modes.Spaced, }; if (simShift) { la.mode = LineAction.Modes.Unspaced; } ActionQueue.instance.Push(la); ActionQueue.instance.Do(); CheckCloseMenu(); MIT.DeactivateTool(); break; case "MoveIt_AlignIndividualBtn": m_activeToolMenu = MoreButtons["MoveIt_RotateBtn"]; MIT.ProcessAligning(MoveItTool.MT_Tools.Inplace); break; case "MoveIt_AlignGroupBtn": m_activeToolMenu = MoreButtons["MoveIt_RotateBtn"]; MIT.ProcessAligning(MoveItTool.MT_Tools.Group); break; case "MoveIt_AlignRandomBtn": if (MoveItTool.ToolState == MoveItTool.ToolStates.Cloning || MoveItTool.ToolState == MoveItTool.ToolStates.RightDraggingClone) { MIT.StopCloning(); } AlignRandomAction ara = new AlignRandomAction { followTerrain = MoveItTool.followTerrain }; ActionQueue.instance.Push(ara); ActionQueue.instance.Do(); CheckCloseMenu(); MIT.DeactivateTool(); break; case "MoveIt_ConvertToPOBtn": if (MoveItTool.PO.Enabled && MoveItTool.ToolState == MoveItTool.ToolStates.Default) { MoveItTool.PO.StartConvertAction(); } CheckCloseMenu(); MIT.DeactivateTool(); break; case "MoveIt_ResetObjectBtn": MIT.StartReset(); CheckCloseMenu(); MIT.DeactivateTool(); break; case "MoveIt_MoveToBtn": m_activeToolMenu = MoreButtons["MoveIt_OthersBtn"]; if (!MoveItTool.instance.StartTool(MoveItTool.ToolStates.ToolActive, MoveItTool.MT_Tools.MoveTo)) { m_activeToolMenu = null; break; } MoveToAction mta = new MoveToAction { followTerrain = MoveItTool.followTerrain }; ActionQueue.instance.Push(mta); MoveItTool.m_moveToPanel.Visible(true); CheckCloseMenu(); break; default: Log.Debug($"Invalid Tool clicked ({name})"); break; } }
public override void Start() { UIMoreTools.Initialise(); instance = this; UICheckBox checkBox = null; atlas = UIUtils.GetAtlas("Ingame"); size = new Vector2(41, 41); relativePosition = new Vector2(GetUIView().GetScreenResolution().x - 340, -41); name = "MoveIt_ToolOptionPanel"; DebugUtils.Log("ToolOptionPanel position: " + absolutePosition); #region Follow Terrain m_followTerrain = AddUIComponent <UIMultiStateButton>(); m_followTerrain.atlas = GetFollowTerrainAtlas(); m_followTerrain.name = "MoveIt_FollowTerrain"; m_followTerrain.tooltip = Str.baseUI_FollowTerrain_Tooltip; m_followTerrain.playAudioEvents = true; m_followTerrain.size = new Vector2(36, 36); m_followTerrain.spritePadding = new RectOffset(); m_followTerrain.backgroundSprites[0].disabled = "ToggleBaseDisabled"; m_followTerrain.backgroundSprites[0].hovered = "ToggleBaseHovered"; m_followTerrain.backgroundSprites[0].normal = "ToggleBase"; m_followTerrain.backgroundSprites[0].pressed = "ToggleBasePressed"; m_followTerrain.backgroundSprites.AddState(); m_followTerrain.backgroundSprites[1].disabled = "ToggleBaseDisabled"; m_followTerrain.backgroundSprites[1].hovered = ""; m_followTerrain.backgroundSprites[1].normal = "ToggleBaseFocused"; m_followTerrain.backgroundSprites[1].pressed = "ToggleBasePressed"; m_followTerrain.foregroundSprites[0].normal = "FollowTerrain_disabled"; m_followTerrain.foregroundSprites.AddState(); m_followTerrain.foregroundSprites[1].normal = "FollowTerrain"; m_followTerrain.relativePosition = Vector2.zero; m_followTerrain.activeStateIndex = MoveItTool.followTerrain ? 1 : 0; m_followTerrain.eventClicked += (c, p) => { MoveItTool.followTerrain = (m_followTerrain.activeStateIndex == 1); MoveItTool.followTerrainModeEnabled.value = (m_followTerrain.activeStateIndex == 1); }; #endregion #region Snapping m_snapping = AddUIComponent <UIMultiStateButton>(); m_snapping.atlas = UIUtils.GetAtlas("Ingame"); m_snapping.name = "MoveIt_Snapping"; m_snapping.tooltip = Str.baseUI_ToggleSnapping_Tooltip; m_snapping.playAudioEvents = true; m_snapping.size = new Vector2(36, 36); m_snapping.spritePadding = new RectOffset(); m_snapping.backgroundSprites[0].disabled = "ToggleBaseDisabled"; m_snapping.backgroundSprites[0].hovered = "ToggleBaseHovered"; m_snapping.backgroundSprites[0].normal = "ToggleBase"; m_snapping.backgroundSprites[0].pressed = "ToggleBasePressed"; m_snapping.backgroundSprites.AddState(); m_snapping.backgroundSprites[1].disabled = "ToggleBaseDisabled"; m_snapping.backgroundSprites[1].hovered = ""; m_snapping.backgroundSprites[1].normal = "ToggleBaseFocused"; m_snapping.backgroundSprites[1].pressed = "ToggleBasePressed"; m_snapping.foregroundSprites[0].disabled = "SnappingDisabled"; m_snapping.foregroundSprites[0].hovered = "SnappingHovered"; m_snapping.foregroundSprites[0].normal = "Snapping"; m_snapping.foregroundSprites[0].pressed = "SnappingPressed"; m_snapping.foregroundSprites.AddState(); m_snapping.foregroundSprites[1].disabled = "SnappingDisabled"; m_snapping.foregroundSprites[1].hovered = ""; m_snapping.foregroundSprites[1].normal = "SnappingFocused"; m_snapping.foregroundSprites[1].pressed = "SnappingPressed"; m_snapping.relativePosition = m_followTerrain.relativePosition + new Vector3(m_followTerrain.width, 0); m_snapping.activeStateIndex = (MoveItTool.instance != null && MoveItTool.instance.snapping) ? 1 : 0; m_snapping.eventClicked += (c, p) => { if (MoveItTool.instance != null) { MoveItTool.instance.snapping = (m_snapping.activeStateIndex == 1); } }; #endregion m_tabStrip = AddUIComponent <UITabstrip>(); m_tabStrip.size = new Vector2(36, 72); m_tabStrip.relativePosition = m_snapping.relativePosition + new Vector3(m_snapping.width, 0); #region Single Select m_single = m_tabStrip.AddTab("MoveIt_Single", null, false); m_single.group = m_tabStrip; m_single.atlas = UIUtils.GetAtlas("Ingame"); m_single.tooltip = Str.baseUI_Single_Tooltip; m_single.playAudioEvents = true; m_single.size = new Vector2(36, 36); m_single.normalBgSprite = "OptionBase"; m_single.focusedBgSprite = "OptionBaseFocused"; m_single.hoveredBgSprite = "OptionBaseHovered"; m_single.pressedBgSprite = "OptionBasePressed"; m_single.disabledBgSprite = "OptionBaseDisabled"; m_single.text = "•"; m_single.textScale = 1.5f; m_single.textPadding = new RectOffset(0, 1, 4, 0); m_single.textColor = new Color32(119, 124, 126, 255); m_single.hoveredTextColor = new Color32(110, 113, 114, 255); m_single.pressedTextColor = new Color32(172, 175, 176, 255); m_single.focusedTextColor = new Color32(187, 224, 235, 255); m_single.disabledTextColor = new Color32(66, 69, 70, 255); #endregion #region Marquee Select m_marquee = m_tabStrip.AddTab("MoveIt_Marquee", null, false); m_marquee.group = m_tabStrip; m_marquee.atlas = UIUtils.GetAtlas("Ingame"); m_marquee.tooltip = Str.baseUI_Marquee_Tooltip; m_marquee.playAudioEvents = true; m_marquee.size = new Vector2(36, 36); m_marquee.normalBgSprite = "OptionBase"; m_marquee.focusedBgSprite = "OptionBaseFocused"; m_marquee.hoveredBgSprite = "OptionBaseHovered"; m_marquee.pressedBgSprite = "OptionBasePressed"; m_marquee.disabledBgSprite = "OptionBaseDisabled"; m_marquee.normalFgSprite = "ZoningOptionMarquee"; m_marquee.relativePosition = m_single.relativePosition + new Vector3(m_single.width, 0); #region filtersPanel m_filtersPanel = AddUIComponent(typeof(UIPanel)) as UIPanel; m_filtersPanel.atlas = UIUtils.GetAtlas("Ingame"); m_filtersPanel.backgroundSprite = "SubcategoriesPanel"; m_filtersPanel.clipChildren = true; m_filtersPanel.size = new Vector2(150, 235); m_filtersPanel.isVisible = false; UIFilters.FilterPanel = m_filtersPanel; void OnDoubleClick(UIComponent c, UIMouseEventParameter p) { foreach (UICheckBox cb in UIFilters.FilterCBs) { cb.isChecked = false; Filters.SetFilter(cb.name, false); } ((UICheckBox)c).isChecked = true; Filters.SetFilter(c.name, true); UIFilters.RefreshFilters(); } void OnPickerClick(UIComponent c, UIMouseEventParameter p) { MoveItTool.SetToolState(MoveItTool.ToolStates.Picking); UIFilters.UpdatePickerButton(2); } void OnPickerDoubleClick(UIComponent c, UIMouseEventParameter p) { Filters.Picker = new PickerFilter(); Filters.SetFilter("Picker", false); MoveItTool.SetToolState(); UIFilters.UpdatePickerButton(1); } #region Standard Filters m_filtersPanelList = m_filtersPanel.AddUIComponent(typeof(UIPanel)) as UIPanel; m_filtersPanelList.name = "m_filtersPanelList"; m_picker = UIUtils.CreateButton(m_filtersPanel); m_picker.relativePosition = new Vector3(122, 9); m_picker.size = new Vector2(20, 20); m_picker.atlas = GetIconsAtlas(); m_picker.normalFgSprite = "EyeDropper"; m_picker.normalBgSprite = "OptionsDropboxListbox"; m_picker.hoveredBgSprite = "OptionsDropboxListboxFocused"; m_picker.pressedBgSprite = "OptionsDropboxListboxHovered"; m_picker.eventClick += OnPickerClick; m_picker.eventDoubleClick += OnPickerDoubleClick; m_picker.name = "mit_pickerButton"; checkBox = UIFilters.CreateFilterCB(m_filtersPanelList, "Picker", Str.filter_Picker, false); checkBox.width -= 21; UIFilters.UpdatePickerLabel(Str.filter_Picker, Str.filter_Picker_Tooltip, UIFilters.InactiveLabelColor, false); checkBox.eventDoubleClick += OnDoubleClick; checkBox = UIFilters.CreateFilterCB(m_filtersPanelList, "Buildings", Str.filter_Buildings); checkBox.eventDoubleClick += OnDoubleClick; checkBox = UIFilters.CreateFilterCB(m_filtersPanelList, "Props", Str.filter_Props); checkBox.eventDoubleClick += OnDoubleClick; checkBox = UIFilters.CreateFilterCB(m_filtersPanelList, "Decals", Str.filter_Decals); checkBox.eventDoubleClick += OnDoubleClick; checkBox = UIFilters.CreateFilterCB(m_filtersPanelList, "Surfaces", Str.filter_Surfaces); checkBox.eventDoubleClick += OnDoubleClick; checkBox = UIFilters.CreateFilterCB(m_filtersPanelList, "Trees", Str.filter_Trees); checkBox.eventDoubleClick += OnDoubleClick; if (MoveItTool.PO.Enabled) { if (MoveItTool.PO.Active) { m_filtersPanel.height += 20f; } checkBox = UIFilters.CreateFilterCB(m_filtersPanelList, "PO", Str.filter_PO); checkBox.eventDoubleClick += OnDoubleClick; checkBox.isVisible = MoveItTool.PO.Active; } checkBox = UIFilters.CreateFilterCB(m_filtersPanelList, "Nodes", Str.filter_Nodes); checkBox.eventDoubleClick += OnDoubleClick; checkBox = UIFilters.CreateFilterCB(m_filtersPanelList, "Segments", Str.filter_Segments); checkBox.eventDoubleClick += OnDoubleClick; #endregion #region Network Filters UIButton btnNetworks = UIFilters.CreateToggleNFBtn(); void OnDoubleClickNetworkFilter(UIComponent c, UIMouseEventParameter p) { foreach (UICheckBox cb in UIFilters.NetworkCBs) { cb.isChecked = false; Filters.SetNetworkFilter(cb.name, false); } ((UICheckBox)c).isChecked = true; Filters.SetNetworkFilter(c.name, true); UIFilters.RefreshFilters(); } checkBox = UIFilters.CreateNetworkFilterCB(m_filtersPanelList, "Roads", Str.filter_Roads); checkBox.eventDoubleClick += OnDoubleClickNetworkFilter; checkBox = UIFilters.CreateNetworkFilterCB(m_filtersPanelList, "Tracks", Str.filter_Tracks); checkBox.eventDoubleClick += OnDoubleClickNetworkFilter; checkBox = UIFilters.CreateNetworkFilterCB(m_filtersPanelList, "Paths", Str.filter_Paths); checkBox.eventDoubleClick += OnDoubleClickNetworkFilter; checkBox = UIFilters.CreateNetworkFilterCB(m_filtersPanelList, "Fences", Str.filter_Fences); checkBox.eventDoubleClick += OnDoubleClickNetworkFilter; checkBox = UIFilters.CreateNetworkFilterCB(m_filtersPanelList, "Powerlines", Str.filter_Powerlines); checkBox.eventDoubleClick += OnDoubleClickNetworkFilter; checkBox = UIFilters.CreateNetworkFilterCB(m_filtersPanelList, "Others", Str.filter_Others); checkBox.eventDoubleClick += OnDoubleClickNetworkFilter; UIFilters.RefreshFilters(); #endregion m_filtersPanelList.padding = new RectOffset(10, 10, 10, 10); m_filtersPanelList.autoLayoutDirection = LayoutDirection.Vertical; m_filtersPanelList.autoLayoutPadding = new RectOffset(0, 0, 0, 5); m_filtersPanelList.autoLayout = true; m_filtersPanelList.relativePosition = new Vector3(0, 0, 0); m_filtersPanel.autoLayout = false; m_filtersPanel.absolutePosition = m_marquee.absolutePosition + new Vector3(-47, -5 - m_filtersPanel.height); #endregion m_marquee.eventButtonStateChanged += (c, p) => { MoveItTool.marqueeSelection = p == UIButton.ButtonState.Focused; m_filtersPanel.isVisible = MoveItTool.marqueeSelection; if (UIChangesWindow.instance != null) { UIChangesWindow.instance.RefreshPosition(); } }; m_marquee.eventDoubleClick += (UIComponent c, UIMouseEventParameter p) => { bool newChecked = false; foreach (UICheckBox cb in m_filtersPanel.GetComponentsInChildren <UICheckBox>()) { if (cb.name == "Picker") { continue; } if (!cb.isChecked) { newChecked = true; break; } } foreach (UICheckBox cb in m_filtersPanel.GetComponentsInChildren <UICheckBox>()) { if (cb.name == "Picker") { cb.isChecked = false; Filters.SetAnyFilter(cb.name, false); } else { cb.isChecked = newChecked; Filters.SetAnyFilter(cb.name, newChecked); } } UIFilters.RefreshFilters(); }; #endregion #region Copy m_copy = AddUIComponent <UIButton>(); m_copy.name = "MoveIt_Copy"; m_copy.group = m_tabStrip; m_copy.atlas = GetIconsAtlas(); m_copy.tooltip = Str.baseUI_Clone_Tooltip;; m_copy.playAudioEvents = true; m_copy.size = new Vector2(36, 36); m_copy.normalBgSprite = "OptionBase"; m_copy.hoveredBgSprite = "OptionBaseHovered"; m_copy.pressedBgSprite = "OptionBasePressed"; m_copy.disabledBgSprite = "OptionBaseDisabled"; m_copy.normalFgSprite = "Copy"; m_copy.relativePosition = m_tabStrip.relativePosition + new Vector3(m_single.width + m_marquee.width, 0); m_copy.eventClicked += (c, p) => { if (MoveItTool.instance != null) { if (MoveItTool.ToolState == MoveItTool.ToolStates.Cloning) { MoveItTool.instance.StopCloning(); } else { if (Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt)) { if (Action.HasSelection()) { DuplicateAction action = new DuplicateAction(); if (action.Count > 0) { ActionQueue.instance.Push(action); ActionQueue.instance.Do(); } } } else { MoveItTool.instance.StartCloning(); } } } }; #endregion #region Bulldoze m_bulldoze = AddUIComponent <UIButton>(); m_bulldoze.name = "MoveIt_Bulldoze"; m_bulldoze.group = m_tabStrip; m_bulldoze.atlas = GetIconsAtlas(); m_bulldoze.tooltip = Str.baseUI_Bulldoze_Tooltip; m_bulldoze.playAudioEvents = true; m_bulldoze.size = new Vector2(36, 36); m_bulldoze.normalBgSprite = "OptionBase"; m_bulldoze.hoveredBgSprite = "OptionBaseHovered"; m_bulldoze.pressedBgSprite = "OptionBasePressed"; m_bulldoze.disabledBgSprite = "OptionBaseDisabled"; m_bulldoze.normalFgSprite = "Bulldoze"; m_bulldoze.relativePosition = m_copy.relativePosition + new Vector3(m_copy.width, 0); m_bulldoze.eventClicked += (c, p) => { if (MoveItTool.instance != null) { MoveItTool.instance.StartBulldoze(); } }; #endregion #region More Tools #region More Tools Container m_moreTools = AddUIComponent <UIButton>(); UIMoreTools.MoreToolsBtn = m_moreTools; m_moreTools.name = "MoveIt_MoreToolsBtn"; m_moreTools.group = m_tabStrip; m_moreTools.atlas = GetIconsAtlas(); m_moreTools.tooltip = Str.baseUI_Toolbox_Tooltip; m_moreTools.playAudioEvents = true; m_moreTools.size = new Vector2(36, 36); m_moreTools.normalBgSprite = "OptionBase"; m_moreTools.hoveredBgSprite = "OptionBaseHovered"; m_moreTools.pressedBgSprite = "OptionBasePressed"; m_moreTools.disabledBgSprite = "OptionBaseDisabled"; m_moreTools.normalFgSprite = "MoreTools"; m_moreTools.relativePosition = m_bulldoze.relativePosition + new Vector3(m_bulldoze.width, 0); m_moreTools.eventClicked += (UIComponent c, UIMouseEventParameter p) => { UIMoreTools.MoreToolsClicked(m_moreTools.name); }; m_moreToolsPanel = AddUIComponent <UIPanel>(); UIMoreTools.MoreToolsPanel = m_moreToolsPanel; m_moreToolsPanel.name = "mtPanel"; m_moreToolsPanel.autoLayout = false; m_moreToolsPanel.clipChildren = true; m_moreToolsPanel.size = new Vector2(36, 132); m_moreToolsPanel.isVisible = false; m_moreToolsPanel.absolutePosition = m_moreTools.absolutePosition + new Vector3(0, 10 - m_moreToolsPanel.height); m_moreTools.zOrder = m_moreToolsPanel.zOrder + 10; // The vertical shade UIPanel mtpBackground = m_moreToolsPanel.AddUIComponent <UIPanel>(); mtpBackground.name = "mtpBackground"; mtpBackground.clipChildren = true; mtpBackground.relativePosition = new Vector3(5, 10); mtpBackground.atlas = UIUtils.GetAtlas("Ingame"); mtpBackground.backgroundSprite = "InfoPanelBack"; mtpBackground.size = m_moreToolsPanel.size - new Vector2(10, 10); UIPanel mtpContainer = m_moreToolsPanel.AddUIComponent <UIPanel>(); mtpContainer.name = "mtpContainer"; mtpContainer.autoLayoutDirection = LayoutDirection.Vertical; mtpContainer.autoLayoutPadding = new RectOffset(0, 0, 0, 4); mtpContainer.autoLayout = true; mtpContainer.relativePosition = Vector3.zero; mtpContainer.size = m_moreToolsPanel.size; mtpContainer.eventMouseEnter += (UIComponent c, UIMouseEventParameter p) => { if (MoveItTool.marqueeSelection) { m_filtersPanel.isVisible = false; } }; mtpContainer.eventMouseLeave += (UIComponent c, UIMouseEventParameter p) => { if (MoveItTool.marqueeSelection) { m_filtersPanel.isVisible = true; } }; UIMoreTools.MoreButtons.Clear(); UIMoreTools.MoreSubButtons.Clear(); #endregion try { AddMoreButtonCallback?.Invoke(this, m_moreTools, mtpBackground, mtpContainer); } catch (Exception e) { Log.Error(e); } #region More Tools / Toolbox buttons UIMoreToolsBtn othersBtn = new UIMoreToolsBtn(this, "MoveIt_OthersBtn", Str.toolbox_OtherTools_Tooltip, "MenuOthers", mtpContainer, "m_mtOthersList", (MoveItTool.PO.Enabled ? 7.25f : 6.25f)); if (MoveItTool.PO.Enabled) { othersBtn.CreateSubButton("MoveIt_ConvertToPOBtn", Str.toolbox_ConvertToPO, "ConvertToPO"); } othersBtn.CreateSubButton("MoveIt_AlignLineBtn", Str.toolbox_LineUpObjects, "AlignLine"); othersBtn.CreateSubButton("MoveIt_AlignMirrorBtn", Str.toolbox_MirrorObjects, "AlignMirror"); othersBtn.CreateSubButton("MoveIt_ResetObjectBtn", Str.toolbox_ResetObjects, "ResetObject"); othersBtn.CreateSubButton("MoveIt_MoveToBtn", Str.toolbox_SetPosition, "MoveTo"); othersBtn.CreateSubSeparator("MoveIt_FileSeparator"); othersBtn.CreateSubButton("MoveIt_LoadBtn", Str.toolbox_ImportSelection, "Load"); othersBtn.CreateSubButton("MoveIt_SaveBtn", Str.toolbox_ExportSelection, "Save"); othersBtn.UpdateWidth(); UIMoreToolsBtn rotateBtn = new UIMoreToolsBtn(this, "MoveIt_RotateBtn", Str.toolbox_RotationTools_Tooltip, "MenuRotate", mtpContainer, "m_mtRotateList", 3f); rotateBtn.CreateSubButton("MoveIt_AlignRandomBtn", Str.toolbox_RotateRandomly, "AlignRandom"); rotateBtn.CreateSubButton("MoveIt_AlignGroupBtn", Str.toolbox_RotateAtCentre, "AlignGroup"); rotateBtn.CreateSubButton("MoveIt_AlignIndividualBtn", Str.toolbox_RotateInPlace, "AlignIndividual"); rotateBtn.UpdateWidth(); UIMoreToolsBtn heightBtn = new UIMoreToolsBtn(this, "MoveIt_HeightBtn", Str.toolbox_HeightTools_Tooltip, "MenuHeight", mtpContainer, "m_mtHeightList", 3f); heightBtn.CreateSubButton("MoveIt_AlignSlopeBtn", Str.toolbox_SlopeObjects, "AlignSlope"); heightBtn.CreateSubButton("MoveIt_AlignTerrainHeightBtn", Str.toolbox_ToTerrainHeight, "AlignTerrainHeight"); heightBtn.CreateSubButton("MoveIt_AlignHeightBtn", Str.toolbox_ToObjectHeight, "AlignHeight"); heightBtn.UpdateWidth(); #endregion #endregion #region View Options m_viewOptions = AddUIComponent <UIPanel>(); m_viewOptions.atlas = UIUtils.GetAtlas("Ingame"); m_viewOptions.backgroundSprite = "InfoPanelBack"; m_viewOptions.size = new Vector2(44f, 80f); m_viewOptions.absolutePosition = new Vector3(GetUIView().GetScreenResolution().x - m_viewOptions.width, absolutePosition.y - m_viewOptions.height - 8f); grid = m_viewOptions.AddUIComponent <UIMultiStateButton>(); grid.atlas = GetIconsAtlas(); grid.name = "MoveIt_GridView"; grid.tooltip = Str.baseUI_ToggleGrid_Tooltip; grid.playAudioEvents = true; grid.size = new Vector2(36, 36); grid.spritePadding = new RectOffset(); grid.backgroundSprites[0].disabled = "OptionBaseDisabled"; grid.backgroundSprites[0].hovered = "OptionBaseHovered"; grid.backgroundSprites[0].normal = "OptionBase"; grid.backgroundSprites[0].pressed = "OptionBasePressed"; grid.backgroundSprites.AddState(); grid.backgroundSprites[1].disabled = "OptionBaseDisabled"; grid.backgroundSprites[1].hovered = ""; grid.backgroundSprites[1].normal = "OptionBaseFocused"; grid.backgroundSprites[1].pressed = "OptionBasePressed"; grid.foregroundSprites[0].normal = "Grid"; grid.foregroundSprites.AddState(); grid.foregroundSprites[1].normal = "GridFocused"; grid.relativePosition = new Vector3(4f, 4f); grid.activeStateIndex = 0; grid.eventClicked += (c, p) => { MoveItTool.gridVisible = (grid.activeStateIndex == 1); }; underground = m_viewOptions.AddUIComponent <UIMultiStateButton>(); underground.atlas = UIUtils.GetAtlas("Ingame"); underground.name = "MoveIt_UndergroundView"; underground.tooltip = Str.baseUI_ToggleUnderground_Tooltip; underground.playAudioEvents = true; underground.size = new Vector2(36, 36); underground.spritePadding = new RectOffset(); underground.backgroundSprites[0].disabled = "OptionBaseDisabled"; underground.backgroundSprites[0].hovered = "OptionBaseHovered"; underground.backgroundSprites[0].normal = "OptionBase"; underground.backgroundSprites[0].pressed = "OptionBasePressed"; underground.backgroundSprites.AddState(); underground.backgroundSprites[1].disabled = "OptionBaseDisabled"; underground.backgroundSprites[1].hovered = ""; underground.backgroundSprites[1].normal = "OptionBaseFocused"; underground.backgroundSprites[1].pressed = "OptionBasePressed"; underground.foregroundSprites[0].normal = "BulldozerOptionPipes"; underground.foregroundSprites.AddState(); underground.foregroundSprites[1].normal = "BulldozerOptionPipesFocused"; underground.relativePosition = new Vector3(4f, 40f); underground.activeStateIndex = 0; underground.eventClicked += (c, p) => { MoveItTool.tunnelVisible = (underground.activeStateIndex == 1); }; if (MoveItTool.PO.Enabled) { PO_button = m_viewOptions.AddUIComponent <UIMultiStateButton>(); PO_button.atlas = GetIconsAtlas(); PO_button.name = "MoveIt_PO_button"; PO_button.tooltip = Str.baseUI_TogglePO_Tooltip; PO_button.playAudioEvents = true; PO_button.size = new Vector2(36, 36); PO_button.spritePadding = new RectOffset(); PO_button.backgroundSprites[0].disabled = "OptionBaseDisabled"; PO_button.backgroundSprites[0].hovered = "OptionBaseHovered"; PO_button.backgroundSprites[0].normal = "OptionBase"; PO_button.backgroundSprites[0].pressed = "OptionBasePressed"; PO_button.backgroundSprites.AddState(); PO_button.backgroundSprites[1].disabled = "OptionBaseDisabled"; PO_button.backgroundSprites[1].hovered = ""; PO_button.backgroundSprites[1].normal = "OptionBaseFocused"; PO_button.backgroundSprites[1].pressed = "OptionBasePressed"; PO_button.foregroundSprites[0].normal = "PO"; PO_button.foregroundSprites.AddState(); PO_button.foregroundSprites[1].normal = "POFocused"; PO_button.relativePosition = new Vector3(4f, 76f); PO_button.activeStateIndex = 0; PO_button.eventClicked += (c, p) => { MoveItTool.PO.InitialiseTool(); }; m_viewOptions.height += 36; m_viewOptions.absolutePosition += new Vector3(0, -36); } #endregion }
public override void RenderOverlay(RenderManager.CameraInfo cameraInfo, Color toolColor, Color despawnColor) { if (!isValid) { return; } ushort segment = id.NetSegment; NetInfo netInfo = segmentBuffer[segment].Info; ushort startNode = segmentBuffer[segment].m_startNode; ushort endNode = segmentBuffer[segment].m_endNode; bool smoothStart = ((nodeBuffer[startNode].m_flags & NetNode.Flags.Middle) != NetNode.Flags.None); bool smoothEnd = ((nodeBuffer[endNode].m_flags & NetNode.Flags.Middle) != NetNode.Flags.None); Bezier3 bezier; bezier.a = nodeBuffer[startNode].m_position; bezier.d = nodeBuffer[endNode].m_position; // NON-STOCK CODE STARTS if (MoveItTool.IsCSUROffset(netInfo)) { var tmpDir = segmentBuffer[segment].m_startDirection; if ((segmentBuffer[segment].m_flags & NetSegment.Flags.Invert) != NetSegment.Flags.None) { tmpDir = -tmpDir; } tmpDir = new Vector3(tmpDir.z, tmpDir.y, -tmpDir.x); bezier.a = tmpDir * (netInfo.m_halfWidth + netInfo.m_pavementWidth) / 2f + bezier.a; tmpDir = segmentBuffer[segment].m_endDirection; if ((segmentBuffer[segment].m_flags & NetSegment.Flags.Invert) != NetSegment.Flags.None) { tmpDir = -tmpDir; } tmpDir = new Vector3(-tmpDir.z, tmpDir.y, tmpDir.x); bezier.d = tmpDir * (netInfo.m_halfWidth + netInfo.m_pavementWidth) / 2f + bezier.d; } // NON-STOCK CODE ENDS NetSegment.CalculateMiddlePoints( bezier.a, segmentBuffer[segment].m_startDirection, bezier.d, segmentBuffer[segment].m_endDirection, smoothStart, smoothEnd, out bezier.b, out bezier.c); // NON-STOCK CODE STARTS if (MoveItTool.IsCSUROffset(netInfo)) { RenderManager.instance.OverlayEffect.DrawBezier(cameraInfo, toolColor, bezier, (netInfo.m_halfWidth - netInfo.m_pavementWidth) * 4f / 3f, 100000f, -100000f, -1f, 1280f, false, true); } else { RenderManager.instance.OverlayEffect.DrawBezier(cameraInfo, toolColor, bezier, netInfo.m_halfWidth * 4f / 3f, 100000f, -100000f, -1f, 1280f, false, true); } // NON-STOCK CODE ENDS Segment3 segment1, segment2; segment1.a = nodeBuffer[startNode].m_position; segment2.a = nodeBuffer[endNode].m_position; segment1.b = GetControlPoint(segment); segment2.b = segment1.b; // NON-STOCK CODE STARTS if (MoveItTool.IsCSUROffset(netInfo)) { var tmpDir = segmentBuffer[segment].m_startDirection; if ((segmentBuffer[segment].m_flags & NetSegment.Flags.Invert) != NetSegment.Flags.None) { tmpDir = -tmpDir; } tmpDir = new Vector3(tmpDir.z, tmpDir.y, -tmpDir.x); segment1.a = tmpDir * (netInfo.m_halfWidth + netInfo.m_pavementWidth) / 2f + segment1.a; tmpDir = segmentBuffer[segment].m_endDirection; if ((segmentBuffer[segment].m_flags & NetSegment.Flags.Invert) != NetSegment.Flags.None) { tmpDir = -tmpDir; } tmpDir = new Vector3(-tmpDir.z, tmpDir.y, tmpDir.x); segment2.a = tmpDir * (netInfo.m_halfWidth + netInfo.m_pavementWidth) / 2f + segment2.a; tmpDir = (segmentBuffer[segment].m_startDirection - segmentBuffer[segment].m_endDirection) / 2; if ((segmentBuffer[segment].m_flags & NetSegment.Flags.Invert) != NetSegment.Flags.None) { tmpDir = -tmpDir; } tmpDir = new Vector3(tmpDir.z, tmpDir.y, -tmpDir.x); segment1.b = tmpDir * (netInfo.m_halfWidth + netInfo.m_pavementWidth) / 2f + segment1.b; segment2.b = segment1.b; } // NON-STOCK CODE ENDS toolColor.a = toolColor.a / 2; RenderManager.instance.OverlayEffect.DrawSegment(cameraInfo, toolColor, segment1, segment2, 0, 10f, -1f, 1280f, false, true); // NON-STOCK CODE STARTS if (MoveItTool.IsCSUROffset(netInfo)) { RenderManager.instance.OverlayEffect.DrawCircle(cameraInfo, toolColor, segment1.b, (netInfo.m_halfWidth - netInfo.m_pavementWidth) / 2f, -1f, 1280f, false, true); } else { RenderManager.instance.OverlayEffect.DrawCircle(cameraInfo, toolColor, segment1.b, netInfo.m_halfWidth / 2f, -1f, 1280f, false, true); } // NON-STOCK CODE ENDS }
public override void Start() { instance = this; atlas = UIUtils.GetAtlas("Ingame"); size = new Vector2(41, 41); relativePosition = new Vector2(GetUIView().GetScreenResolution().x - 448, -41); name = "MoveIt_ToolOptionPanel"; DebugUtils.Log("ToolOptionPanel position: " + absolutePosition); // Group m_group = AddUIComponent <UIButton>(); m_group.name = "MoveIt_Group"; m_group.group = m_tabStrip; m_group.atlas = GetIconsAtlas(); m_group.tooltip = "Group"; m_group.playAudioEvents = true; m_group.size = new Vector2(36, 36); m_group.normalBgSprite = "OptionBase"; m_group.hoveredBgSprite = "OptionBaseHovered"; m_group.pressedBgSprite = "OptionBasePressed"; m_group.disabledBgSprite = "OptionBaseDisabled"; m_group.normalFgSprite = "Group"; m_group.relativePosition = Vector2.zero; m_group.isVisible = false; //TODO: temporary // Save m_save = AddUIComponent <UIButton>(); m_save.name = "MoveIt_Save"; m_save.group = m_tabStrip; m_save.atlas = GetIconsAtlas(); m_save.tooltip = "Export"; m_save.playAudioEvents = true; m_save.size = new Vector2(36, 36); m_save.normalBgSprite = "OptionBase"; m_save.hoveredBgSprite = "OptionBaseHovered"; m_save.pressedBgSprite = "OptionBasePressed"; m_save.disabledBgSprite = "OptionBaseDisabled"; m_save.normalFgSprite = "Save"; m_save.disabledFgSprite = "Save_disabled"; m_save.relativePosition = m_group.relativePosition + new Vector3(m_group.width, 0); m_save.eventClicked += (c, p) => { if (MoveItTool.IsExportSelectionValid()) { UISaveWindow.Open(); } else { UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel").SetMessage("Selection invalid", "The selection is empty or invalid.", false); } }; // Load m_load = AddUIComponent <UIButton>(); m_load.name = "MoveIt_Load"; m_load.group = m_tabStrip; m_load.atlas = GetIconsAtlas(); m_load.tooltip = "Import"; m_load.playAudioEvents = true; m_load.size = new Vector2(36, 36); m_load.normalBgSprite = "OptionBase"; m_load.hoveredBgSprite = "OptionBaseHovered"; m_load.pressedBgSprite = "OptionBasePressed"; m_load.disabledBgSprite = "OptionBaseDisabled"; m_load.normalFgSprite = "Load"; m_load.relativePosition = m_save.relativePosition + new Vector3(m_save.width, 0); m_load.eventClicked += (c, p) => { UILoadWindow.Open(); }; // Follow Terrain m_followTerrain = AddUIComponent <UIMultiStateButton>(); m_followTerrain.atlas = GetFollowTerrainAtlas(); m_followTerrain.name = "MoveIt_FollowTerrain"; m_followTerrain.tooltip = "Follow Terrain"; m_followTerrain.playAudioEvents = true; m_followTerrain.size = new Vector2(36, 36); m_followTerrain.spritePadding = new RectOffset(); m_followTerrain.backgroundSprites[0].disabled = "ToggleBaseDisabled"; m_followTerrain.backgroundSprites[0].hovered = "ToggleBaseHovered"; m_followTerrain.backgroundSprites[0].normal = "ToggleBase"; m_followTerrain.backgroundSprites[0].pressed = "ToggleBasePressed"; m_followTerrain.backgroundSprites.AddState(); m_followTerrain.backgroundSprites[1].disabled = "ToggleBaseDisabled"; m_followTerrain.backgroundSprites[1].hovered = ""; m_followTerrain.backgroundSprites[1].normal = "ToggleBaseFocused"; m_followTerrain.backgroundSprites[1].pressed = "ToggleBasePressed"; m_followTerrain.foregroundSprites[0].normal = "FollowTerrain_disabled"; m_followTerrain.foregroundSprites.AddState(); m_followTerrain.foregroundSprites[1].normal = "FollowTerrain"; m_followTerrain.relativePosition = m_load.relativePosition + new Vector3(m_load.width + m_load.width / 2, 0); m_followTerrain.activeStateIndex = MoveItTool.followTerrain ? 1 : 0; m_followTerrain.eventClicked += (c, p) => { MoveItTool.followTerrain = (m_followTerrain.activeStateIndex == 1); }; // Snapping m_snapping = AddUIComponent <UIMultiStateButton>(); m_snapping.atlas = UIUtils.GetAtlas("Ingame"); m_snapping.name = "MoveIt_Snapping"; m_snapping.tooltip = "Toggle Snapping"; m_snapping.playAudioEvents = true; m_snapping.size = new Vector2(36, 36); m_snapping.spritePadding = new RectOffset(); m_snapping.backgroundSprites[0].disabled = "ToggleBaseDisabled"; m_snapping.backgroundSprites[0].hovered = "ToggleBaseHovered"; m_snapping.backgroundSprites[0].normal = "ToggleBase"; m_snapping.backgroundSprites[0].pressed = "ToggleBasePressed"; m_snapping.backgroundSprites.AddState(); m_snapping.backgroundSprites[1].disabled = "ToggleBaseDisabled"; m_snapping.backgroundSprites[1].hovered = ""; m_snapping.backgroundSprites[1].normal = "ToggleBaseFocused"; m_snapping.backgroundSprites[1].pressed = "ToggleBasePressed"; m_snapping.foregroundSprites[0].disabled = "SnappingDisabled"; m_snapping.foregroundSprites[0].hovered = "SnappingHovered"; m_snapping.foregroundSprites[0].normal = "Snapping"; m_snapping.foregroundSprites[0].pressed = "SnappingPressed"; m_snapping.foregroundSprites.AddState(); m_snapping.foregroundSprites[1].disabled = "SnappingDisabled"; m_snapping.foregroundSprites[1].hovered = ""; m_snapping.foregroundSprites[1].normal = "SnappingFocused"; m_snapping.foregroundSprites[1].pressed = "SnappingPressed"; m_snapping.relativePosition = m_followTerrain.relativePosition + new Vector3(m_followTerrain.width, 0); m_snapping.activeStateIndex = (MoveItTool.instance != null && MoveItTool.instance.snapping) ? 1 : 0; m_snapping.eventClicked += (c, p) => { if (MoveItTool.instance != null) { MoveItTool.instance.snapping = (m_snapping.activeStateIndex == 1); } }; m_tabStrip = AddUIComponent <UITabstrip>(); m_tabStrip.size = new Vector2(36, 72); m_tabStrip.relativePosition = m_snapping.relativePosition + new Vector3(m_snapping.width, 0); m_single = m_tabStrip.AddTab("MoveIt_Single", null, false); m_single.group = m_tabStrip; m_single.atlas = UIUtils.GetAtlas("Ingame"); m_single.tooltip = "Single Selection"; m_single.playAudioEvents = true; m_single.size = new Vector2(36, 36); m_single.normalBgSprite = "OptionBase"; m_single.focusedBgSprite = "OptionBaseFocused"; m_single.hoveredBgSprite = "OptionBaseHovered"; m_single.pressedBgSprite = "OptionBasePressed"; m_single.disabledBgSprite = "OptionBaseDisabled"; m_single.text = "•"; m_single.textScale = 1.5f; m_single.textPadding = new RectOffset(0, 1, 4, 0); m_single.textColor = new Color32(119, 124, 126, 255); m_single.hoveredTextColor = new Color32(110, 113, 114, 255); m_single.pressedTextColor = new Color32(172, 175, 176, 255); m_single.focusedTextColor = new Color32(187, 224, 235, 255); m_single.disabledTextColor = new Color32(66, 69, 70, 255); m_marquee = m_tabStrip.AddTab("MoveIt_Marquee", null, false); m_marquee.group = m_tabStrip; m_marquee.atlas = UIUtils.GetAtlas("Ingame"); m_marquee.tooltip = "Marquee Selection"; m_marquee.playAudioEvents = true; m_marquee.size = new Vector2(36, 36); m_marquee.normalBgSprite = "OptionBase"; m_marquee.focusedBgSprite = "OptionBaseFocused"; m_marquee.hoveredBgSprite = "OptionBaseHovered"; m_marquee.pressedBgSprite = "OptionBasePressed"; m_marquee.disabledBgSprite = "OptionBaseDisabled"; m_marquee.normalFgSprite = "ZoningOptionMarquee"; m_marquee.relativePosition = m_single.relativePosition + new Vector3(m_single.width, 0); filtersPanel = AddUIComponent(typeof(UIPanel)) as UIPanel; filtersPanel.atlas = UIUtils.GetAtlas("Ingame"); filtersPanel.backgroundSprite = "SubcategoriesPanel"; filtersPanel.clipChildren = true; filtersPanel.size = new Vector2(150, 140); filtersPanel.isVisible = false; void OnDoubleClick(UIComponent c, UIMouseEventParameter p) { foreach (UIComponent comp in filtersPanel.components) { UICheckBox box = comp as UICheckBox; if (box != null && box != c) { box.isChecked = false; } } ((UICheckBox)c).isChecked = true; } UICheckBox checkBox = UIUtils.CreateCheckBox(filtersPanel); checkBox.label.text = "Buildings"; checkBox.isChecked = true; checkBox.eventCheckChanged += (c, p) => { MoveItTool.filterBuildings = p; }; checkBox.eventDoubleClick += OnDoubleClick; checkBox = UIUtils.CreateCheckBox(filtersPanel); checkBox.label.text = "Props"; checkBox.isChecked = true; checkBox.eventCheckChanged += (c, p) => { MoveItTool.filterProps = p; }; checkBox.eventDoubleClick += OnDoubleClick; checkBox = UIUtils.CreateCheckBox(filtersPanel); checkBox.label.text = "Decals"; checkBox.isChecked = true; checkBox.eventCheckChanged += (c, p) => { MoveItTool.filterDecals = p; }; checkBox.eventDoubleClick += OnDoubleClick; checkBox = UIUtils.CreateCheckBox(filtersPanel); checkBox.label.text = "Trees"; checkBox.isChecked = true; checkBox.eventCheckChanged += (c, p) => { MoveItTool.filterTrees = p; }; checkBox.eventDoubleClick += OnDoubleClick; checkBox = UIUtils.CreateCheckBox(filtersPanel); checkBox.label.text = "Nodes"; checkBox.isChecked = true; checkBox.eventCheckChanged += (c, p) => { MoveItTool.filterNodes = p; }; checkBox.eventDoubleClick += OnDoubleClick; checkBox = UIUtils.CreateCheckBox(filtersPanel); checkBox.label.text = "Segments"; checkBox.isChecked = true; checkBox.eventCheckChanged += (c, p) => { MoveItTool.filterSegments = p; }; checkBox.eventDoubleClick += OnDoubleClick; filtersPanel.padding = new RectOffset(10, 10, 10, 10); filtersPanel.autoLayoutDirection = LayoutDirection.Vertical; filtersPanel.autoLayoutPadding = new RectOffset(0, 0, 0, 5); filtersPanel.autoLayout = true; filtersPanel.height = 160; filtersPanel.absolutePosition = m_marquee.absolutePosition - new Vector3(57, filtersPanel.height + 5); m_marquee.eventButtonStateChanged += (c, p) => { MoveItTool.marqueeSelection = p == UIButton.ButtonState.Focused; filtersPanel.isVisible = MoveItTool.marqueeSelection; if (UITipsWindow.instance != null) { UITipsWindow.instance.RefreshPosition(); } }; m_alignHeight = AddUIComponent <UIButton>(); m_alignHeight.name = "MoveIt_AlignHeight"; m_alignHeight.group = m_tabStrip; m_alignHeight.atlas = GetIconsAtlas(); m_alignHeight.tooltip = "Align Heights"; m_alignHeight.playAudioEvents = true; m_alignHeight.size = new Vector2(36, 36); m_alignHeight.normalBgSprite = "OptionBase"; m_alignHeight.hoveredBgSprite = "OptionBaseHovered"; m_alignHeight.pressedBgSprite = "OptionBasePressed"; m_alignHeight.disabledBgSprite = "OptionBaseDisabled"; m_alignHeight.normalFgSprite = "AlignHeight"; m_alignHeight.relativePosition = m_tabStrip.relativePosition + new Vector3(m_single.width + m_marquee.width, 0); m_alignHeight.eventClicked += (c, p) => { if (MoveItTool.instance != null) { if (MoveItTool.instance.toolState == MoveItTool.ToolState.AligningHeights) { MoveItTool.instance.StopAligningHeights(); } else { MoveItTool.instance.StartAligningHeights(); } } }; m_copy = AddUIComponent <UIButton>(); m_copy.name = "MoveIt_Copy"; m_copy.group = m_tabStrip; m_copy.atlas = GetIconsAtlas(); m_copy.tooltip = "Copy"; m_copy.playAudioEvents = true; m_copy.size = new Vector2(36, 36); m_copy.normalBgSprite = "OptionBase"; m_copy.hoveredBgSprite = "OptionBaseHovered"; m_copy.pressedBgSprite = "OptionBasePressed"; m_copy.disabledBgSprite = "OptionBaseDisabled"; m_copy.normalFgSprite = "Copy"; m_copy.relativePosition = m_alignHeight.relativePosition + new Vector3(m_alignHeight.width, 0); m_copy.eventClicked += (c, p) => { if (MoveItTool.instance != null) { if (MoveItTool.instance.toolState == MoveItTool.ToolState.Cloning) { MoveItTool.instance.StopCloning(); } else { MoveItTool.instance.StartCloning(); } } }; m_bulldoze = AddUIComponent <UIButton>(); m_bulldoze.name = "MoveIt_Bulldoze"; m_bulldoze.group = m_tabStrip; m_bulldoze.atlas = GetIconsAtlas(); m_bulldoze.tooltip = "Bulldoze"; m_bulldoze.playAudioEvents = true; m_bulldoze.size = new Vector2(36, 36); m_bulldoze.normalBgSprite = "OptionBase"; m_bulldoze.hoveredBgSprite = "OptionBaseHovered"; m_bulldoze.pressedBgSprite = "OptionBasePressed"; m_bulldoze.disabledBgSprite = "OptionBaseDisabled"; m_bulldoze.normalFgSprite = "Bulldoze"; m_bulldoze.relativePosition = m_copy.relativePosition + new Vector3(m_copy.width, 0); m_bulldoze.eventClicked += (c, p) => { if (MoveItTool.instance != null) { MoveItTool.instance.StartBulldoze(); } }; // View options UIPanel viewOptions = AddUIComponent <UIPanel>(); viewOptions.atlas = UIUtils.GetAtlas("Ingame"); viewOptions.backgroundSprite = "InfoPanelBack"; viewOptions.size = new Vector2(44f, 80f); viewOptions.absolutePosition = new Vector3(GetUIView().GetScreenResolution().x - viewOptions.width, absolutePosition.y - viewOptions.height - 8f); grid = viewOptions.AddUIComponent <UIMultiStateButton>(); grid.atlas = GetIconsAtlas(); grid.name = "MoveIt_GridView"; grid.tooltip = "Toggle Grid"; grid.playAudioEvents = true; grid.size = new Vector2(36, 36); grid.spritePadding = new RectOffset(); grid.backgroundSprites[0].disabled = "OptionBaseDisabled"; grid.backgroundSprites[0].hovered = "OptionBaseHovered"; grid.backgroundSprites[0].normal = "OptionBase"; grid.backgroundSprites[0].pressed = "OptionBasePressed"; grid.backgroundSprites.AddState(); grid.backgroundSprites[1].disabled = "OptionBaseDisabled"; grid.backgroundSprites[1].hovered = ""; grid.backgroundSprites[1].normal = "OptionBaseFocused"; grid.backgroundSprites[1].pressed = "OptionBasePressed"; grid.foregroundSprites[0].normal = "Grid"; grid.foregroundSprites.AddState(); grid.foregroundSprites[1].normal = "GridFocused"; grid.relativePosition = new Vector3(4f, 4f); grid.activeStateIndex = 0; grid.eventClicked += (c, p) => { MoveItTool.gridVisible = (grid.activeStateIndex == 1); }; underground = viewOptions.AddUIComponent <UIMultiStateButton>(); underground.atlas = UIUtils.GetAtlas("Ingame"); underground.name = "MoveIt_UndergroundView"; underground.tooltip = "Toogle Underground View"; underground.playAudioEvents = true; underground.size = new Vector2(36, 36); underground.spritePadding = new RectOffset(); underground.backgroundSprites[0].disabled = "OptionBaseDisabled"; underground.backgroundSprites[0].hovered = "OptionBaseHovered"; underground.backgroundSprites[0].normal = "OptionBase"; underground.backgroundSprites[0].pressed = "OptionBasePressed"; underground.backgroundSprites.AddState(); underground.backgroundSprites[1].disabled = "OptionBaseDisabled"; underground.backgroundSprites[1].hovered = ""; underground.backgroundSprites[1].normal = "OptionBaseFocused"; underground.backgroundSprites[1].pressed = "OptionBasePressed"; underground.foregroundSprites[0].normal = "BulldozerOptionPipes"; underground.foregroundSprites.AddState(); underground.foregroundSprites[1].normal = "BulldozerOptionPipesFocused"; underground.relativePosition = new Vector3(4f, 40f); underground.activeStateIndex = 0; underground.eventClicked += (c, p) => { MoveItTool.tunnelVisible = (underground.activeStateIndex == 1); }; }
public override void Do() { if (MoveItTool.POProcessing > 0) { return; } MoveItTool.instance.m_lastInstance = null; m_clones = new HashSet <Instance>(); m_origToCloneUpdate = new Dictionary <Instance, Instance>(); m_nodeOrigToClone = new Dictionary <ushort, ushort>(); m_stateToClone = new Dictionary <InstanceState, Instance>(); m_InstanceID_origToClone = new Dictionary <InstanceID, InstanceID>(); matrix4x.SetTRS(center + moveDelta, Quaternion.AngleAxis(angleDelta * Mathf.Rad2Deg, Vector3.down), Vector3.one); // Clone nodes first foreach (InstanceState state in m_states) { if (state is NodeState) { Instance clone = state.instance.Clone(state, ref matrix4x, moveDelta.y, angleDelta, center, followTerrain, m_nodeOrigToClone, this); if (clone != null) { m_clones.Add(clone); m_stateToClone.Add(state, clone); m_InstanceID_origToClone.Add(state.instance.id, clone.id); m_origToCloneUpdate.Add(state.instance.id, clone.id); m_nodeOrigToClone.Add(state.instance.id.NetNode, clone.id.NetNode); } } } // Clone everything else except PO foreach (InstanceState state in m_states) { if (!(state is NodeState || state is ProcState)) { Instance clone = state.instance.Clone(state, ref matrix4x, moveDelta.y, angleDelta, center, followTerrain, m_nodeOrigToClone, this); if (clone == null) { Log.Debug($"Failed to clone {state}"); continue; } m_clones.Add(clone); m_stateToClone.Add(state, clone); m_InstanceID_origToClone.Add(state.instance.id, clone.id); m_origToCloneUpdate.Add(state.instance.id, clone.id); ; if (state is SegmentState segmentState) { MoveItTool.NS.SetSegmentModifiers(clone.id.NetSegment, segmentState); if (segmentState.LaneIDs != null) { // old version does not store lane ids var clonedLaneIds = MoveableSegment.GetLaneIds(clone.id.NetSegment); DebugUtils.AssertEq(clonedLaneIds.Count, segmentState.LaneIDs.Count, "clonedLaneIds.Count, segmentState.LaneIDs.Count"); for (int i = 0; i < clonedLaneIds.Count; ++i) { var lane0 = new InstanceID { NetLane = segmentState.LaneIDs[i] }; var lane = new InstanceID { NetLane = clonedLaneIds[i] }; // Log.Debug($"Mapping lane:{lane0.NetLane} to {lane.NetLane}"); m_InstanceID_origToClone.Add(lane0, lane); } } } } } // Clone PO foreach (InstanceState state in m_states) { if (state is ProcState) { _ = state.instance.Clone(state, ref matrix4x, moveDelta.y, angleDelta, center, followTerrain, m_nodeOrigToClone, this); } } if (m_origToClone != null) { Dictionary <Instance, Instance> toReplace = new Dictionary <Instance, Instance>(); foreach (Instance key in m_origToClone.Keys) { toReplace.Add(m_origToClone[key], m_origToCloneUpdate[key]); DebugUtils.Log("To replace: " + m_origToClone[key].id.RawData + " -> " + m_origToCloneUpdate[key].id.RawData); } ActionQueue.instance.ReplaceInstancesForward(toReplace); } m_origToClone = m_origToCloneUpdate; // Select clones selection = m_clones; MoveItTool.m_debugPanel.UpdatePanel(); UpdateArea(GetTotalBounds(false)); try { MoveItTool.UpdatePillarMap(); } catch (Exception e) { DebugUtils.Log("CloneActionBase.Do failed"); DebugUtils.LogException(e); } }
public void UndoImplementation(bool reset = false) { if (m_states == null) { return; } Dictionary <Instance, Instance> toReplace = new Dictionary <Instance, Instance>(); Dictionary <ushort, ushort> clonedNodes = new Dictionary <ushort, ushort>(); var stateToClone = new Dictionary <InstanceState, Instance>(); var InstanceID_origToClone = new Dictionary <InstanceID, InstanceID>(); Building[] buildingBuffer = BuildingManager.instance.m_buildings.m_buffer; // Recreate nodes foreach (InstanceState state in m_states) { try { if (state.instance.id.Type == InstanceType.NetNode) { Instance clone = state.instance.Clone(state, null); toReplace.Add(state.instance, clone); stateToClone.Add(state, clone); InstanceID_origToClone.Add(state.instance.id, clone.id); clonedNodes.Add(state.instance.id.NetNode, clone.id.NetNode); ActionQueue.instance.UpdateNodeIdInStateHistory(state.instance.id.NetNode, clone.id.NetNode); } } catch (Exception e) { Debug.Log($"Undo Bulldoze failed on {(state is InstanceState ? state.prefabName : "unknown")}\n{e}"); } } // Recreate everything except nodes and segments foreach (InstanceState state in m_states) { try { if (state.instance.id.Type == InstanceType.NetNode) { continue; } if (state.instance.id.Type == InstanceType.NetSegment) { continue; } if (state is ProcState) { continue; } Instance clone = state.instance.Clone(state, clonedNodes); toReplace.Add(state.instance, clone); stateToClone.Add(state, clone); InstanceID_origToClone.Add(state.instance.id, clone.id); if (state.instance.id.Type == InstanceType.Prop) { PropManager.instance.m_props.m_buffer[clone.id.Prop].FixedHeight = ((PropState)state).fixedHeight; } else if (state.instance.id.Type == InstanceType.Building) { // Add attached nodes to the clonedNode list so other segments reconnect BuildingState buildingState = state as BuildingState; List <ushort> origNodeIds = new List <ushort>(); MoveableBuilding cb = clone as MoveableBuilding; ushort cloneNodeId = ((Building)cb.data).m_netNode; if (reset) { ushort cloneId = cb.id.Building; buildingBuffer[cloneId].m_flags = buildingBuffer[cloneId].m_flags & ~Building.Flags.BurnedDown; buildingBuffer[cloneId].m_flags = buildingBuffer[cloneId].m_flags & ~Building.Flags.Collapsed; buildingBuffer[cloneId].m_flags = buildingBuffer[cloneId].m_flags & ~Building.Flags.Abandoned; buildingBuffer[cloneId].m_flags = buildingBuffer[cloneId].m_flags | Building.Flags.Active; Thread.Sleep(50); } if (cloneNodeId != 0) { int c = 0; foreach (InstanceState i in buildingState.subStates) { if (i is NodeState ns) { InstanceID instanceID = default; instanceID.RawData = ns.id; origNodeIds.Insert(c++, instanceID.NetNode); } } c = 0; while (cloneNodeId != 0) { ushort origNodeId = origNodeIds[c]; NetNode clonedAttachedNode = Singleton <NetManager> .instance.m_nodes.m_buffer[cloneNodeId]; if (clonedAttachedNode.Info.GetAI() is TransportLineAI) { cloneNodeId = clonedAttachedNode.m_nextBuildingNode; continue; } if (clonedNodes.ContainsKey(origNodeId)) { Debug.Log($"Node #{origNodeId} is already in clone list!"); } clonedNodes.Add(origNodeId, cloneNodeId); cloneNodeId = clonedAttachedNode.m_nextBuildingNode; if (++c > 32768) { CODebugBase <LogChannel> .Error(LogChannel.Core, "Nodes: Invalid list detected!\n" + Environment.StackTrace); break; } } } } } catch (Exception e) { Debug.Log($"Undo Bulldoze failed on {(state is InstanceState ? state.prefabName : "unknown")}\n{e}"); } } // Recreate segments foreach (InstanceState state in m_states) { try { if (state is SegmentState segmentState) { if (!clonedNodes.ContainsKey(segmentState.startNodeId)) { InstanceID instanceID = InstanceID.Empty; instanceID.NetNode = segmentState.startNodeId; // Don't clone if node is missing if (!((Instance)instanceID).isValid) { continue; } clonedNodes.Add(segmentState.startNodeId, segmentState.startNodeId); } if (!clonedNodes.ContainsKey(segmentState.endNodeId)) { InstanceID instanceID = InstanceID.Empty; instanceID.NetNode = segmentState.endNodeId; // Don't clone if node is missing if (!((Instance)instanceID).isValid) { continue; } clonedNodes.Add(segmentState.endNodeId, segmentState.endNodeId); } Instance clone = state.instance.Clone(state, clonedNodes); toReplace.Add(state.instance, clone); stateToClone.Add(state, clone); InstanceID_origToClone.Add(state.instance.id, clone.id); MoveItTool.NS.SetSegmentModifiers(clone.id.NetSegment, segmentState); } } catch (Exception e) { Debug.Log($"Undo Bulldoze failed on {(state is InstanceState ? state.prefabName : "unknown")}\n{e}"); } } // clone integrations. foreach (var item in stateToClone) { foreach (var data in item.Key.IntegrationData) { try { data.Key.Paste(item.Value.id, data.Value, InstanceID_origToClone); } catch (Exception e) { InstanceID sourceInstanceID = item.Key.instance.id; InstanceID targetInstanceID = item.Value.id; Debug.LogError($"integration {data.Key} Failed to paste from " + $"{sourceInstanceID.Type}:{sourceInstanceID.Index} to {targetInstanceID.Type}:{targetInstanceID.Index}"); DebugUtils.LogException(e); } } } if (replaceInstances) { ReplaceInstances(toReplace); ActionQueue.instance.ReplaceInstancesBackward(toReplace); selection = new HashSet <Instance>(); foreach (Instance i in m_oldSelection) { if (i is MoveableProc) { continue; } selection.Add(i); } MoveItTool.m_debugPanel.UpdatePanel(); } // Does not check MoveItTool.advancedPillarControl, because even if disabled now advancedPillarControl may have been active earlier in action queue foreach (KeyValuePair <BuildingState, BuildingState> pillarClone in pillarsOriginalToClone) { BuildingState originalState = pillarClone.Key; originalState.instance.isHidden = false; buildingBuffer[originalState.instance.id.Building].m_flags &= ~Building.Flags.Hidden; selection.Add(originalState.instance); m_states.Add(originalState); } if (pillarsOriginalToClone.Count > 0) { MoveItTool.UpdatePillarMap(); } }
public override void Start() { UIMoreTools.Initialise(); instance = this; UICheckBox checkBox = null; atlas = UIUtils.GetAtlas("Ingame"); size = new Vector2(41, 41); relativePosition = new Vector2(GetUIView().GetScreenResolution().x - 448, -41); name = "MoveIt_ToolOptionPanel"; DebugUtils.Log("ToolOptionPanel position: " + absolutePosition); #region Group // Group m_group = AddUIComponent <UIButton>(); m_group.name = "MoveIt_Group"; m_group.group = m_tabStrip; m_group.atlas = GetIconsAtlas(); m_group.tooltip = "Group"; m_group.playAudioEvents = true; m_group.size = new Vector2(36, 36); m_group.normalBgSprite = "OptionBase"; m_group.hoveredBgSprite = "OptionBaseHovered"; m_group.pressedBgSprite = "OptionBasePressed"; m_group.disabledBgSprite = "OptionBaseDisabled"; m_group.normalFgSprite = "Group"; m_group.relativePosition = Vector2.zero; m_group.isVisible = false; //TODO: temporary #endregion #region Save m_save = AddUIComponent <UIButton>(); m_save.name = "MoveIt_Save"; m_save.group = m_tabStrip; m_save.atlas = GetIconsAtlas(); m_save.tooltip = "Export"; m_save.playAudioEvents = true; m_save.size = new Vector2(36, 36); m_save.normalBgSprite = "OptionBase"; m_save.hoveredBgSprite = "OptionBaseHovered"; m_save.pressedBgSprite = "OptionBasePressed"; m_save.disabledBgSprite = "OptionBaseDisabled"; m_save.normalFgSprite = "Save"; m_save.disabledFgSprite = "Save_disabled"; m_save.relativePosition = m_group.relativePosition + new Vector3(m_group.width, 0); m_save.eventClicked += (c, p) => { if (MoveItTool.IsExportSelectionValid()) { UISaveWindow.Open(); } else { UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel").SetMessage("Selection invalid", "The selection is empty or invalid.", false); } }; #endregion #region Load m_load = AddUIComponent <UIButton>(); m_load.name = "MoveIt_Load"; m_load.group = m_tabStrip; m_load.atlas = GetIconsAtlas(); m_load.tooltip = "Import"; m_load.playAudioEvents = true; m_load.size = new Vector2(36, 36); m_load.normalBgSprite = "OptionBase"; m_load.hoveredBgSprite = "OptionBaseHovered"; m_load.pressedBgSprite = "OptionBasePressed"; m_load.disabledBgSprite = "OptionBaseDisabled"; m_load.normalFgSprite = "Load"; m_load.relativePosition = m_save.relativePosition + new Vector3(m_save.width, 0); m_load.eventClicked += (c, p) => { UILoadWindow.Open(); }; #endregion #region Follow Terrain m_followTerrain = AddUIComponent <UIMultiStateButton>(); m_followTerrain.atlas = GetFollowTerrainAtlas(); m_followTerrain.name = "MoveIt_FollowTerrain"; m_followTerrain.tooltip = "Follow Terrain"; m_followTerrain.playAudioEvents = true; m_followTerrain.size = new Vector2(36, 36); m_followTerrain.spritePadding = new RectOffset(); m_followTerrain.backgroundSprites[0].disabled = "ToggleBaseDisabled"; m_followTerrain.backgroundSprites[0].hovered = "ToggleBaseHovered"; m_followTerrain.backgroundSprites[0].normal = "ToggleBase"; m_followTerrain.backgroundSprites[0].pressed = "ToggleBasePressed"; m_followTerrain.backgroundSprites.AddState(); m_followTerrain.backgroundSprites[1].disabled = "ToggleBaseDisabled"; m_followTerrain.backgroundSprites[1].hovered = ""; m_followTerrain.backgroundSprites[1].normal = "ToggleBaseFocused"; m_followTerrain.backgroundSprites[1].pressed = "ToggleBasePressed"; m_followTerrain.foregroundSprites[0].normal = "FollowTerrain_disabled"; m_followTerrain.foregroundSprites.AddState(); m_followTerrain.foregroundSprites[1].normal = "FollowTerrain"; m_followTerrain.relativePosition = m_load.relativePosition + new Vector3(m_load.width + m_load.width / 2, 0); m_followTerrain.activeStateIndex = MoveItTool.followTerrain ? 1 : 0; m_followTerrain.eventClicked += (c, p) => { MoveItTool.followTerrain = (m_followTerrain.activeStateIndex == 1); MoveItTool.followTerrainModeEnabled.value = (m_followTerrain.activeStateIndex == 1); }; #endregion #region Snapping m_snapping = AddUIComponent <UIMultiStateButton>(); m_snapping.atlas = UIUtils.GetAtlas("Ingame"); m_snapping.name = "MoveIt_Snapping"; m_snapping.tooltip = "Toggle Snapping"; m_snapping.playAudioEvents = true; m_snapping.size = new Vector2(36, 36); m_snapping.spritePadding = new RectOffset(); m_snapping.backgroundSprites[0].disabled = "ToggleBaseDisabled"; m_snapping.backgroundSprites[0].hovered = "ToggleBaseHovered"; m_snapping.backgroundSprites[0].normal = "ToggleBase"; m_snapping.backgroundSprites[0].pressed = "ToggleBasePressed"; m_snapping.backgroundSprites.AddState(); m_snapping.backgroundSprites[1].disabled = "ToggleBaseDisabled"; m_snapping.backgroundSprites[1].hovered = ""; m_snapping.backgroundSprites[1].normal = "ToggleBaseFocused"; m_snapping.backgroundSprites[1].pressed = "ToggleBasePressed"; m_snapping.foregroundSprites[0].disabled = "SnappingDisabled"; m_snapping.foregroundSprites[0].hovered = "SnappingHovered"; m_snapping.foregroundSprites[0].normal = "Snapping"; m_snapping.foregroundSprites[0].pressed = "SnappingPressed"; m_snapping.foregroundSprites.AddState(); m_snapping.foregroundSprites[1].disabled = "SnappingDisabled"; m_snapping.foregroundSprites[1].hovered = ""; m_snapping.foregroundSprites[1].normal = "SnappingFocused"; m_snapping.foregroundSprites[1].pressed = "SnappingPressed"; m_snapping.relativePosition = m_followTerrain.relativePosition + new Vector3(m_followTerrain.width, 0); m_snapping.activeStateIndex = (MoveItTool.instance != null && MoveItTool.instance.snapping) ? 1 : 0; m_snapping.eventClicked += (c, p) => { if (MoveItTool.instance != null) { MoveItTool.instance.snapping = (m_snapping.activeStateIndex == 1); } }; #endregion m_tabStrip = AddUIComponent <UITabstrip>(); m_tabStrip.size = new Vector2(36, 72); m_tabStrip.relativePosition = m_snapping.relativePosition + new Vector3(m_snapping.width, 0); #region Single Select m_single = m_tabStrip.AddTab("MoveIt_Single", null, false); m_single.group = m_tabStrip; m_single.atlas = UIUtils.GetAtlas("Ingame"); m_single.tooltip = "Single Selection"; m_single.playAudioEvents = true; m_single.size = new Vector2(36, 36); m_single.normalBgSprite = "OptionBase"; m_single.focusedBgSprite = "OptionBaseFocused"; m_single.hoveredBgSprite = "OptionBaseHovered"; m_single.pressedBgSprite = "OptionBasePressed"; m_single.disabledBgSprite = "OptionBaseDisabled"; m_single.text = "•"; m_single.textScale = 1.5f; m_single.textPadding = new RectOffset(0, 1, 4, 0); m_single.textColor = new Color32(119, 124, 126, 255); m_single.hoveredTextColor = new Color32(110, 113, 114, 255); m_single.pressedTextColor = new Color32(172, 175, 176, 255); m_single.focusedTextColor = new Color32(187, 224, 235, 255); m_single.disabledTextColor = new Color32(66, 69, 70, 255); #endregion #region Marquee Select m_marquee = m_tabStrip.AddTab("MoveIt_Marquee", null, false); m_marquee.group = m_tabStrip; m_marquee.atlas = UIUtils.GetAtlas("Ingame"); m_marquee.tooltip = "Marquee Selection"; m_marquee.playAudioEvents = true; m_marquee.size = new Vector2(36, 36); m_marquee.normalBgSprite = "OptionBase"; m_marquee.focusedBgSprite = "OptionBaseFocused"; m_marquee.hoveredBgSprite = "OptionBaseHovered"; m_marquee.pressedBgSprite = "OptionBasePressed"; m_marquee.disabledBgSprite = "OptionBaseDisabled"; m_marquee.normalFgSprite = "ZoningOptionMarquee"; m_marquee.relativePosition = m_single.relativePosition + new Vector3(m_single.width, 0); #endregion #region filtersPanel m_filtersPanel = AddUIComponent(typeof(UIPanel)) as UIPanel; m_filtersPanel.atlas = UIUtils.GetAtlas("Ingame"); m_filtersPanel.backgroundSprite = "SubcategoriesPanel"; m_filtersPanel.clipChildren = true; m_filtersPanel.size = new Vector2(150, 235); m_filtersPanel.isVisible = false; UIFilters.FilterPanel = m_filtersPanel; void OnDoubleClick(UIComponent c, UIMouseEventParameter p) { foreach (UICheckBox cb in UIFilters.FilterCBs) { cb.isChecked = false; Filters.SetFilter(cb.name, false); } ((UICheckBox)c).isChecked = true; Filters.SetFilter(c.name, true); UIFilters.RefreshFilters(); } void OnPickerClick(UIComponent c, UIMouseEventParameter p) { MoveItTool.instance.ToolState = MoveItTool.ToolStates.Picking; UIFilters.UpdatePickerButton(2); } void OnPickerDoubleClick(UIComponent c, UIMouseEventParameter p) { Filters.Picker = new PickerFilter(); Filters.SetFilter("Picker", false); MoveItTool.instance.ToolState = MoveItTool.ToolStates.Default; UIFilters.UpdatePickerButton(1); } #region Standard Filters m_filtersPanelList = m_filtersPanel.AddUIComponent(typeof(UIPanel)) as UIPanel; m_filtersPanelList.name = "m_filtersPanelList"; m_picker = UIUtils.CreateButton(m_filtersPanel); m_picker.relativePosition = new Vector3(122, 9); m_picker.size = new Vector2(20, 20); m_picker.atlas = GetIconsAtlas(); m_picker.normalFgSprite = "EyeDropper"; m_picker.normalBgSprite = "OptionsDropboxListbox"; m_picker.hoveredBgSprite = "OptionsDropboxListboxFocused"; m_picker.pressedBgSprite = "OptionsDropboxListboxHovered"; m_picker.eventClick += OnPickerClick; m_picker.eventDoubleClick += OnPickerDoubleClick; m_picker.name = "mit_pickerButton"; checkBox = UIFilters.CreateFilterCB(m_filtersPanelList, "Picker", null, false); checkBox.width -= 21; UIFilters.UpdatePickerLabel("Picker", "Pick an object to filter for objects of the same type", UIFilters.InactiveLabelColor, false); checkBox.eventDoubleClick += OnDoubleClick; checkBox = UIFilters.CreateFilterCB(m_filtersPanelList, "Buildings"); checkBox.eventDoubleClick += OnDoubleClick; checkBox = UIFilters.CreateFilterCB(m_filtersPanelList, "Props"); checkBox.eventDoubleClick += OnDoubleClick; checkBox = UIFilters.CreateFilterCB(m_filtersPanelList, "Decals"); checkBox.eventDoubleClick += OnDoubleClick; checkBox = UIFilters.CreateFilterCB(m_filtersPanelList, "Surfaces"); checkBox.eventDoubleClick += OnDoubleClick; checkBox = UIFilters.CreateFilterCB(m_filtersPanelList, "Trees"); checkBox.eventDoubleClick += OnDoubleClick; if (MoveItTool.PO.Enabled) { if (MoveItTool.PO.Active) { m_filtersPanel.height += 20f; } checkBox = UIFilters.CreateFilterCB(m_filtersPanelList, "PO"); checkBox.eventDoubleClick += OnDoubleClick; checkBox.isVisible = MoveItTool.PO.Active; } checkBox = UIFilters.CreateFilterCB(m_filtersPanelList, "Nodes"); checkBox.eventDoubleClick += OnDoubleClick; checkBox = UIFilters.CreateFilterCB(m_filtersPanelList, "Segments"); checkBox.eventDoubleClick += OnDoubleClick; #endregion #region Network Filters UIButton btnNetworks = UIFilters.CreateToggleNFBtn(); void OnDoubleClickNetworkFilter(UIComponent c, UIMouseEventParameter p) { foreach (UICheckBox cb in UIFilters.NetworkCBs) { cb.isChecked = false; Filters.SetNetworkFilter(cb.name, false); } ((UICheckBox)c).isChecked = true; Filters.SetNetworkFilter(c.name, true); UIFilters.RefreshFilters(); } checkBox = UIFilters.CreateNetworkFilterCB(m_filtersPanelList, "Roads"); checkBox.eventDoubleClick += OnDoubleClickNetworkFilter; checkBox = UIFilters.CreateNetworkFilterCB(m_filtersPanelList, "Tracks"); checkBox.eventDoubleClick += OnDoubleClickNetworkFilter; checkBox = UIFilters.CreateNetworkFilterCB(m_filtersPanelList, "Paths"); checkBox.eventDoubleClick += OnDoubleClickNetworkFilter; checkBox = UIFilters.CreateNetworkFilterCB(m_filtersPanelList, "Fences"); checkBox.eventDoubleClick += OnDoubleClickNetworkFilter; checkBox = UIFilters.CreateNetworkFilterCB(m_filtersPanelList, "Powerlines"); checkBox.eventDoubleClick += OnDoubleClickNetworkFilter; checkBox = UIFilters.CreateNetworkFilterCB(m_filtersPanelList, "Others"); checkBox.eventDoubleClick += OnDoubleClickNetworkFilter; UIFilters.RefreshFilters(); #endregion m_filtersPanelList.padding = new RectOffset(10, 10, 10, 10); m_filtersPanelList.autoLayoutDirection = LayoutDirection.Vertical; m_filtersPanelList.autoLayoutPadding = new RectOffset(0, 0, 0, 5); m_filtersPanelList.autoLayout = true; m_filtersPanelList.relativePosition = new Vector3(0, 0, 0); m_filtersPanel.autoLayout = false; m_filtersPanel.absolutePosition = m_marquee.absolutePosition + new Vector3(-47, -5 - m_filtersPanel.height); #endregion m_marquee.eventButtonStateChanged += (c, p) => { MoveItTool.marqueeSelection = p == UIButton.ButtonState.Focused; m_filtersPanel.isVisible = MoveItTool.marqueeSelection; if (UIChangesWindow.instance != null) { UIChangesWindow.instance.RefreshPosition(); } }; m_marquee.eventDoubleClick += (UIComponent c, UIMouseEventParameter p) => { bool newChecked = false; foreach (UICheckBox cb in m_filtersPanel.GetComponentsInChildren <UICheckBox>()) { if (cb.name == "Picker") { continue; } if (!cb.isChecked) { newChecked = true; break; } } foreach (UICheckBox cb in m_filtersPanel.GetComponentsInChildren <UICheckBox>()) { if (cb.name == "Picker") { cb.isChecked = false; Filters.SetAnyFilter(cb.name, false); } else { cb.isChecked = newChecked; Filters.SetAnyFilter(cb.name, newChecked); } } UIFilters.RefreshFilters(); }; #region Copy m_copy = AddUIComponent <UIButton>(); m_copy.name = "MoveIt_Copy"; m_copy.group = m_tabStrip; m_copy.atlas = GetIconsAtlas(); m_copy.tooltip = "Copy (Alt+Click to duplicate in-place)"; m_copy.playAudioEvents = true; m_copy.size = new Vector2(36, 36); m_copy.normalBgSprite = "OptionBase"; m_copy.hoveredBgSprite = "OptionBaseHovered"; m_copy.pressedBgSprite = "OptionBasePressed"; m_copy.disabledBgSprite = "OptionBaseDisabled"; m_copy.normalFgSprite = "Copy"; m_copy.relativePosition = m_tabStrip.relativePosition + new Vector3(m_single.width + m_marquee.width, 0); m_copy.eventClicked += (c, p) => { if (MoveItTool.instance != null) { if (MoveItTool.instance.ToolState == MoveItTool.ToolStates.Cloning) { MoveItTool.instance.StopCloning(); } else { if (Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt)) { if (Action.selection.Count > 0) { DuplicateAction action = new DuplicateAction(); if (action.Count > 0) { ActionQueue.instance.Push(action); ActionQueue.instance.Do(); } } } else { MoveItTool.instance.StartCloning(); } } } }; #endregion #region Bulldoze m_bulldoze = AddUIComponent <UIButton>(); m_bulldoze.name = "MoveIt_Bulldoze"; m_bulldoze.group = m_tabStrip; m_bulldoze.atlas = GetIconsAtlas(); m_bulldoze.tooltip = "Bulldoze"; m_bulldoze.playAudioEvents = true; m_bulldoze.size = new Vector2(36, 36); m_bulldoze.normalBgSprite = "OptionBase"; m_bulldoze.hoveredBgSprite = "OptionBaseHovered"; m_bulldoze.pressedBgSprite = "OptionBasePressed"; m_bulldoze.disabledBgSprite = "OptionBaseDisabled"; m_bulldoze.normalFgSprite = "Bulldoze"; m_bulldoze.relativePosition = m_copy.relativePosition + new Vector3(m_copy.width, 0); m_bulldoze.eventClicked += (c, p) => { if (MoveItTool.instance != null) { if (Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt)) { MoveItTool.instance.StartReset(); } else { MoveItTool.instance.StartBulldoze(); } } }; #endregion #region More Tools m_moreTools = AddUIComponent <UIButton>(); UIMoreTools.MoreToolsBtn = m_moreTools; m_moreTools.name = "MoveIt_MoreToolsBtn"; m_moreTools.group = m_tabStrip; m_moreTools.atlas = GetIconsAtlas(); m_moreTools.tooltip = "More Tools"; m_moreTools.playAudioEvents = true; m_moreTools.size = new Vector2(36, 36); m_moreTools.normalBgSprite = "OptionBase"; m_moreTools.hoveredBgSprite = "OptionBaseHovered"; m_moreTools.pressedBgSprite = "OptionBasePressed"; m_moreTools.disabledBgSprite = "OptionBaseDisabled"; m_moreTools.normalFgSprite = "MoreTools"; m_moreTools.relativePosition = m_bulldoze.relativePosition + new Vector3(m_bulldoze.width, 0); m_moreTools.eventClicked += UIMoreTools.MoreToolsClicked; m_moreToolsPanel = AddUIComponent <UIPanel>(); UIMoreTools.MoreToolsPanel = m_moreToolsPanel; m_moreToolsPanel.name = "mtPanel"; m_moreToolsPanel.autoLayout = false; m_moreToolsPanel.clipChildren = true; m_moreToolsPanel.size = new Vector2(36, 322 + (MoveItTool.PO.Enabled ? 40 : 0)); m_moreToolsPanel.isVisible = false; m_moreToolsPanel.absolutePosition = m_moreTools.absolutePosition + new Vector3(0, 10 - m_moreToolsPanel.height); m_moreTools.zOrder = m_moreToolsPanel.zOrder + 10; // The vertical shade UIPanel mtpBackground = m_moreToolsPanel.AddUIComponent <UIPanel>(); mtpBackground.name = "mtpBackground"; mtpBackground.clipChildren = true; mtpBackground.relativePosition = new Vector3(5, 10); mtpBackground.atlas = UIUtils.GetAtlas("Ingame"); mtpBackground.backgroundSprite = "InfoPanelBack"; mtpBackground.size = m_moreToolsPanel.size - new Vector2(10, 10); UIPanel mtpContainer = m_moreToolsPanel.AddUIComponent <UIPanel>(); mtpContainer.name = "mtpContainer"; mtpContainer.autoLayoutDirection = LayoutDirection.Vertical; mtpContainer.autoLayoutPadding = new RectOffset(0, 0, 0, 3); mtpContainer.autoLayout = true; mtpContainer.relativePosition = Vector3.zero; mtpContainer.size = m_moreToolsPanel.size; UIMoreTools.MoreButtons.Clear(); if (MoveItTool.PO.Enabled) { UIMoreTools.MoreButtons.Add("MoveIt_ConvertToPOBtn", mtpContainer.AddUIComponent <UIButton>()); UIButton convertToPO = UIMoreTools.MoreButtons["MoveIt_ConvertToPOBtn"]; convertToPO.name = "MoveIt_ConvertToPOBtn"; convertToPO.atlas = GetIconsAtlas(); convertToPO.tooltip = "Convert To PO - tries to convert all selected\nbuildings and props into Procedural Objects."; convertToPO.playAudioEvents = true; convertToPO.size = new Vector2(36, 36); convertToPO.normalBgSprite = "OptionBase"; convertToPO.hoveredBgSprite = "OptionBaseHovered"; convertToPO.pressedBgSprite = "OptionBasePressed"; convertToPO.disabledBgSprite = "OptionBaseDisabled"; convertToPO.normalFgSprite = "ConvertToPO"; convertToPO.eventClicked += UIMoreTools.MoreToolsClicked; } UIMoreTools.MoreButtons.Add("MoveIt_ResetObjectBtn", mtpContainer.AddUIComponent <UIButton>()); UIButton resetObject = UIMoreTools.MoreButtons["MoveIt_ResetObjectBtn"]; resetObject.name = "MoveIt_ResetObjectBtn"; resetObject.atlas = GetIconsAtlas(); resetObject.tooltip = "Reset - Rebuild selected objects, repairing them and changing size/color variations."; resetObject.playAudioEvents = true; resetObject.size = new Vector2(36, 36); resetObject.normalBgSprite = "OptionBase"; resetObject.hoveredBgSprite = "OptionBaseHovered"; resetObject.pressedBgSprite = "OptionBasePressed"; resetObject.disabledBgSprite = "OptionBaseDisabled"; resetObject.normalFgSprite = "ResetObject"; resetObject.eventClicked += UIMoreTools.MoreToolsClicked; UIMoreTools.MoreButtons.Add("MoveIt_AlignMirrorBtn", mtpContainer.AddUIComponent <UIButton>()); UIButton alignMirror = UIMoreTools.MoreButtons["MoveIt_AlignMirrorBtn"]; alignMirror.name = "MoveIt_AlignMirrorBtn"; alignMirror.atlas = GetIconsAtlas(); alignMirror.tooltip = "Align Mirror - Click on a network segment to set the\nmirror axis to create a mirrored copy of selection"; alignMirror.playAudioEvents = true; alignMirror.size = new Vector2(36, 36); alignMirror.normalBgSprite = "OptionBase"; alignMirror.hoveredBgSprite = "OptionBaseHovered"; alignMirror.pressedBgSprite = "OptionBasePressed"; alignMirror.disabledBgSprite = "OptionBaseDisabled"; alignMirror.normalFgSprite = "AlignMirror"; alignMirror.eventClicked += UIMoreTools.MoreToolsClicked; UIMoreTools.MoreButtons.Add("MoveIt_AlignRandomBtn", mtpContainer.AddUIComponent <UIButton>()); UIButton alignRandom = UIMoreTools.MoreButtons["MoveIt_AlignRandomBtn"]; alignRandom.name = "MoveIt_AlignRandomBtn"; alignRandom.atlas = GetIconsAtlas(); alignRandom.tooltip = "Random - Immediately rotate valid objects randomly"; alignRandom.playAudioEvents = true; alignRandom.size = new Vector2(36, 36); alignRandom.normalBgSprite = "OptionBase"; alignRandom.hoveredBgSprite = "OptionBaseHovered"; alignRandom.pressedBgSprite = "OptionBasePressed"; alignRandom.disabledBgSprite = "OptionBaseDisabled"; alignRandom.normalFgSprite = "AlignRandom"; alignRandom.eventClicked += UIMoreTools.MoreToolsClicked; UIMoreTools.MoreButtons.Add("MoveIt_AlignGroupBtn", mtpContainer.AddUIComponent <UIButton>()); UIButton alignGroup = UIMoreTools.MoreButtons["MoveIt_AlignGroupBtn"]; alignGroup.name = "MoveIt_AlignGroupBtn"; alignGroup.atlas = GetIconsAtlas(); alignGroup.tooltip = "Align as Group - click on an object to rotate\nselection around a central point to face\nobject's direction"; alignGroup.playAudioEvents = true; alignGroup.size = new Vector2(36, 36); alignGroup.normalBgSprite = "OptionBase"; alignGroup.hoveredBgSprite = "OptionBaseHovered"; alignGroup.pressedBgSprite = "OptionBasePressed"; alignGroup.disabledBgSprite = "OptionBaseDisabled"; alignGroup.normalFgSprite = "AlignGroup"; alignGroup.eventClicked += UIMoreTools.MoreToolsClicked; UIMoreTools.MoreButtons.Add("MoveIt_AlignIndividualBtn", mtpContainer.AddUIComponent <UIButton>()); UIButton alignIndividual = UIMoreTools.MoreButtons["MoveIt_AlignIndividualBtn"]; alignIndividual.name = "MoveIt_AlignIndividualBtn"; alignIndividual.atlas = GetIconsAtlas(); alignIndividual.tooltip = "Align In-Place - click on an object to\nrotate selected items to face that direction"; alignIndividual.playAudioEvents = true; alignIndividual.size = new Vector2(36, 36); alignIndividual.normalBgSprite = "OptionBase"; alignIndividual.hoveredBgSprite = "OptionBaseHovered"; alignIndividual.pressedBgSprite = "OptionBasePressed"; alignIndividual.disabledBgSprite = "OptionBaseDisabled"; alignIndividual.normalFgSprite = "AlignIndividual"; alignIndividual.eventClicked += UIMoreTools.MoreToolsClicked; UIMoreTools.MoreButtons.Add("MoveIt_AlignSlopeBtn", mtpContainer.AddUIComponent <UIButton>()); UIButton alignSlope = UIMoreTools.MoreButtons["MoveIt_AlignSlopeBtn"]; alignSlope.name = "MoveIt_AlignSlopeBtn"; alignSlope.atlas = GetIconsAtlas(); alignSlope.tooltip = "Align Slope - click on 2 objects to define\nthe slope axis to move selected objects\nup/down to that height"; alignSlope.playAudioEvents = true; alignSlope.size = new Vector2(36, 36); alignSlope.normalBgSprite = "OptionBase"; alignSlope.hoveredBgSprite = "OptionBaseHovered"; alignSlope.pressedBgSprite = "OptionBasePressed"; alignSlope.disabledBgSprite = "OptionBaseDisabled"; alignSlope.normalFgSprite = "AlignSlope"; alignSlope.eventClicked += UIMoreTools.MoreToolsClicked; UIMoreTools.MoreButtons.Add("MoveIt_AlignTerrainHeightBtn", mtpContainer.AddUIComponent <UIButton>()); UIButton alignTerrainHeight = UIMoreTools.MoreButtons["MoveIt_AlignTerrainHeightBtn"]; alignTerrainHeight.name = "MoveIt_AlignTerrainHeightBtn"; alignTerrainHeight.atlas = GetIconsAtlas(); alignTerrainHeight.tooltip = "Immediately Align objects to Terrain Height"; alignTerrainHeight.playAudioEvents = true; alignTerrainHeight.size = new Vector2(36, 36); alignTerrainHeight.normalBgSprite = "OptionBase"; alignTerrainHeight.hoveredBgSprite = "OptionBaseHovered"; alignTerrainHeight.pressedBgSprite = "OptionBasePressed"; alignTerrainHeight.disabledBgSprite = "OptionBaseDisabled"; alignTerrainHeight.normalFgSprite = "AlignTerrainHeight"; alignTerrainHeight.eventClicked += UIMoreTools.MoreToolsClicked; UIMoreTools.MoreButtons.Add("MoveIt_AlignHeightBtn", mtpContainer.AddUIComponent <UIButton>()); UIButton alignHeight = UIMoreTools.MoreButtons["MoveIt_AlignHeightBtn"]; alignHeight.name = "MoveIt_AlignHeightBtn"; alignHeight.atlas = GetIconsAtlas(); alignHeight.tooltip = "Align Height - click on an object to move\nselected objects up/down to that height"; alignHeight.playAudioEvents = true; alignHeight.size = new Vector2(36, 36); alignHeight.normalBgSprite = "OptionBase"; alignHeight.hoveredBgSprite = "OptionBaseHovered"; alignHeight.pressedBgSprite = "OptionBasePressed"; alignHeight.disabledBgSprite = "OptionBaseDisabled"; alignHeight.normalFgSprite = "AlignHeight"; alignHeight.eventClicked += UIMoreTools.MoreToolsClicked; #endregion #region View Options m_viewOptions = AddUIComponent <UIPanel>(); m_viewOptions.atlas = UIUtils.GetAtlas("Ingame"); m_viewOptions.backgroundSprite = "InfoPanelBack"; m_viewOptions.size = new Vector2(44f, 80f); m_viewOptions.absolutePosition = new Vector3(GetUIView().GetScreenResolution().x - m_viewOptions.width, absolutePosition.y - m_viewOptions.height - 8f); grid = m_viewOptions.AddUIComponent <UIMultiStateButton>(); grid.atlas = GetIconsAtlas(); grid.name = "MoveIt_GridView"; grid.tooltip = "Toggle Grid"; grid.playAudioEvents = true; grid.size = new Vector2(36, 36); grid.spritePadding = new RectOffset(); grid.backgroundSprites[0].disabled = "OptionBaseDisabled"; grid.backgroundSprites[0].hovered = "OptionBaseHovered"; grid.backgroundSprites[0].normal = "OptionBase"; grid.backgroundSprites[0].pressed = "OptionBasePressed"; grid.backgroundSprites.AddState(); grid.backgroundSprites[1].disabled = "OptionBaseDisabled"; grid.backgroundSprites[1].hovered = ""; grid.backgroundSprites[1].normal = "OptionBaseFocused"; grid.backgroundSprites[1].pressed = "OptionBasePressed"; grid.foregroundSprites[0].normal = "Grid"; grid.foregroundSprites.AddState(); grid.foregroundSprites[1].normal = "GridFocused"; grid.relativePosition = new Vector3(4f, 4f); grid.activeStateIndex = 0; grid.eventClicked += (c, p) => { MoveItTool.gridVisible = (grid.activeStateIndex == 1); }; underground = m_viewOptions.AddUIComponent <UIMultiStateButton>(); underground.atlas = UIUtils.GetAtlas("Ingame"); underground.name = "MoveIt_UndergroundView"; underground.tooltip = "Toogle Underground View"; underground.playAudioEvents = true; underground.size = new Vector2(36, 36); underground.spritePadding = new RectOffset(); underground.backgroundSprites[0].disabled = "OptionBaseDisabled"; underground.backgroundSprites[0].hovered = "OptionBaseHovered"; underground.backgroundSprites[0].normal = "OptionBase"; underground.backgroundSprites[0].pressed = "OptionBasePressed"; underground.backgroundSprites.AddState(); underground.backgroundSprites[1].disabled = "OptionBaseDisabled"; underground.backgroundSprites[1].hovered = ""; underground.backgroundSprites[1].normal = "OptionBaseFocused"; underground.backgroundSprites[1].pressed = "OptionBasePressed"; underground.foregroundSprites[0].normal = "BulldozerOptionPipes"; underground.foregroundSprites.AddState(); underground.foregroundSprites[1].normal = "BulldozerOptionPipesFocused"; underground.relativePosition = new Vector3(4f, 40f); underground.activeStateIndex = 0; underground.eventClicked += (c, p) => { MoveItTool.tunnelVisible = (underground.activeStateIndex == 1); }; if (MoveItTool.PO.Enabled) { PO_button = m_viewOptions.AddUIComponent <UIMultiStateButton>(); PO_button.atlas = GetIconsAtlas(); PO_button.name = "MoveIt_PO_button"; PO_button.tooltip = "Toggle Procedural Objects"; PO_button.playAudioEvents = true; PO_button.size = new Vector2(36, 36); PO_button.spritePadding = new RectOffset(); PO_button.backgroundSprites[0].disabled = "OptionBaseDisabled"; PO_button.backgroundSprites[0].hovered = "OptionBaseHovered"; PO_button.backgroundSprites[0].normal = "OptionBase"; PO_button.backgroundSprites[0].pressed = "OptionBasePressed"; PO_button.backgroundSprites.AddState(); PO_button.backgroundSprites[1].disabled = "OptionBaseDisabled"; PO_button.backgroundSprites[1].hovered = ""; PO_button.backgroundSprites[1].normal = "OptionBaseFocused"; PO_button.backgroundSprites[1].pressed = "OptionBasePressed"; PO_button.foregroundSprites[0].normal = "PO"; PO_button.foregroundSprites.AddState(); PO_button.foregroundSprites[1].normal = "POFocused"; PO_button.relativePosition = new Vector3(4f, 76f); PO_button.activeStateIndex = 0; PO_button.eventClicked += (c, p) => { MoveItTool.PO.Active = (PO_button.activeStateIndex == 1); if (MoveItTool.PO.Active) { if (MoveItTool.instance.ToolState == MoveItTool.ToolStates.Cloning) { MoveItTool.instance.StopCloning(); } MoveItTool.PO.ToolEnabled(); ActionQueue.instance.Push(new TransformAction()); } else { Action.ClearPOFromSelection(); } UIFilters.POToggled(); }; m_viewOptions.height += 36; m_viewOptions.absolutePosition += new Vector3(0, -36); } #endregion }
public IEnumerator <object> RetrieveClone(MoveableProc original, Vector3 position, float angle, Action action) { const uint MaxAttempts = 100_000; CloneActionBase ca = (CloneActionBase)action; if (!(original.m_procObj is PO_Object)) { Log.Info($"PO Cloning failed: object not found"); MoveItTool.POProcessing--; yield break; } Type[] types = new Type[] { tPO, tPO.MakeByRefType(), typeof(uint).MakeByRefType() }; object originalObject = original.m_procObj.GetProceduralObject(); object[] paramList = new[] { originalObject, null, null }; MethodInfo retrieve = tPOMoveIt.GetMethod("TryRetrieveClone", BindingFlags.Public | BindingFlags.Static, null, types, null); if (retrieve == null) { Log.Info($"PO Cloning failed: retrieve not found"); MoveItTool.POProcessing--; yield break; } uint c = 0; while (c < MaxAttempts && !(bool)retrieve.Invoke(null, paramList)) { //if (c % 100 == 0) //{ // BindingFlags f = BindingFlags.Static | BindingFlags.Public; // object queueObj = tPOMoveIt.GetField("queuedCloning", f).GetValue(null); // int queueCount = (int)queueObj.GetType().GetProperty("Count").GetValue(queueObj, null); // object doneObj = tPOMoveIt.GetField("doneCloning", f).GetValue(null); // int doneCount = (int)doneObj.GetType().GetProperty("Count").GetValue(doneObj, null); //} c++; yield return(new WaitForSeconds(0.05f)); } if (c == MaxAttempts) { throw new Exception($"Failed to clone object #{original.m_procObj.Id}! [PO-F4]"); } try { PO_Object clone = new PO_Object(paramList[1]) { POColor = original.m_procObj.POColor }; if (original.m_procObj.Group != null && action is CloneActionBase cloneAction) { if (!cloneAction.m_POGroupMap.ContainsKey(original.m_procObj.Group)) { Log.Debug($"Clone Error: {original.m_procObj.Id}'s group isn't in group map"); } else { clone.Group = cloneAction.m_POGroupMap[original.m_procObj.Group]; clone.Group.AddObject(clone); if (original.m_procObj.isGroupRoot()) { clone.Group.SetNewRoot(clone); } } } InstanceID cloneID = default; cloneID.NetLane = clone.Id; MoveItTool.PO.visibleObjects.Add(cloneID.NetLane, clone); MoveableProc cloneInstance = new MoveableProc(cloneID) { position = position, angle = angle }; Action.selection.Add(cloneInstance); ca.m_clones.Add(cloneInstance); ca.m_origToClone.Add(original, cloneInstance); MoveItTool.SetToolState(); MoveItTool.instance.ProcessSensitivityMode(false); Log.Info($"Cloned PO {original.m_procObj.Id} to #{clone.Id}"); } catch (Exception e) { Log.Error($"Exception when cloning PO:\n{e}"); } yield return(new WaitForSeconds(0.25f)); MoveItTool.POProcessing--; }
public override void Do() { if (MoveItTool.POProcessing > 0) { return; } MoveItTool.instance.m_lastInstance = null; m_clones = new HashSet <Instance>(); m_origToCloneUpdate = new Dictionary <Instance, Instance>(); m_nodeOrigToClone = new Dictionary <ushort, ushort>(); var stateToClone = new Dictionary <InstanceState, Instance>(); var InstanceID_origToClone = new Dictionary <InstanceID, InstanceID>(); matrix4x.SetTRS(center + moveDelta, Quaternion.AngleAxis(angleDelta * Mathf.Rad2Deg, Vector3.down), Vector3.one); // Clone nodes first foreach (InstanceState state in m_states) { if (state is NodeState) { Instance clone = state.instance.Clone(state, ref matrix4x, moveDelta.y, angleDelta, center, followTerrain, m_nodeOrigToClone, this); if (clone != null) { m_clones.Add(clone); stateToClone.Add(state, clone); InstanceID_origToClone.Add(state.instance.id, clone.id); m_origToCloneUpdate.Add(state.instance.id, clone.id); m_nodeOrigToClone.Add(state.instance.id.NetNode, clone.id.NetNode); } } } // Clone everything else except PO foreach (InstanceState state in m_states) { if (!(state is NodeState || state is ProcState)) { Instance clone = state.instance.Clone(state, ref matrix4x, moveDelta.y, angleDelta, center, followTerrain, m_nodeOrigToClone, this); if (clone == null) { Debug.Log($"Failed to clone {state}"); continue; } m_clones.Add(clone); stateToClone.Add(state, clone); InstanceID_origToClone.Add(state.instance.id, clone.id); m_origToCloneUpdate.Add(state.instance.id, clone.id); ; if (state is SegmentState segmentState) { MoveItTool.NS.SetSegmentModifiers(clone.id.NetSegment, segmentState); if (segmentState.LaneIDs != null) { // old version does not store lane ids var clonedLaneIds = MoveableSegment.GetLaneIds(clone.id.NetSegment); DebugUtils.AssertEq(clonedLaneIds.Count, segmentState.LaneIDs.Count, "clonedLaneIds.Count, segmentState.LaneIDs.Count"); for (int i = 0; i < clonedLaneIds.Count; ++i) { var lane0 = new InstanceID { NetLane = segmentState.LaneIDs[i] }; var lane = new InstanceID { NetLane = clonedLaneIds[i] }; // Debug.Log($"Mapping lane:{lane0.NetLane} to {lane.NetLane}"); InstanceID_origToClone.Add(lane0, lane); } } } } } // backward compatibility. // Clone NodeController after segments have been added. foreach (var item in stateToClone) { if (item.Key is NodeState nodeState) { Instance clone = item.Value; ushort nodeID = clone.id.NetNode; MoveItTool.NodeController.PasteNode(nodeID, nodeState); } } // Clone TMPE rules // TODO remove when TMPE switches to integration foreach (var state in m_states) { if (state is NodeState nodeState) { MoveItTool.TMPE.Paste(nodeState.TMPE_NodeRecord, InstanceID_origToClone); } else if (state is SegmentState segmentState) { MoveItTool.TMPE.Paste(segmentState.TMPE_SegmentRecord, InstanceID_origToClone); MoveItTool.TMPE.Paste(segmentState.TMPE_SegmentStartRecord, InstanceID_origToClone); MoveItTool.TMPE.Paste(segmentState.TMPE_SegmentEndRecord, InstanceID_origToClone); } } // Clone PO foreach (InstanceState state in m_states) { if (state is ProcState) { _ = state.instance.Clone(state, ref matrix4x, moveDelta.y, angleDelta, center, followTerrain, m_nodeOrigToClone, this); } } // clone integrations. foreach (var item in stateToClone) { foreach (var data in item.Key.IntegrationData) { try { data.Key.Paste(item.Value.id, data.Value, InstanceID_origToClone); } catch (Exception e) { InstanceID sourceInstanceID = item.Key.instance.id; InstanceID targetInstanceID = item.Value.id; Debug.LogError($"integration {data.Key} Failed to paste from " + $"{sourceInstanceID.Type}:{sourceInstanceID.Index} to {targetInstanceID.Type}:{targetInstanceID.Index}"); DebugUtils.LogException(e); } } } if (m_origToClone != null) { Dictionary <Instance, Instance> toReplace = new Dictionary <Instance, Instance>(); foreach (Instance key in m_origToClone.Keys) { toReplace.Add(m_origToClone[key], m_origToCloneUpdate[key]); DebugUtils.Log("To replace: " + m_origToClone[key].id.RawData + " -> " + m_origToCloneUpdate[key].id.RawData); } ActionQueue.instance.ReplaceInstancesForward(toReplace); } m_origToClone = m_origToCloneUpdate; // Select clones selection = m_clones; MoveItTool.m_debugPanel.UpdatePanel(); UpdateArea(GetTotalBounds(false)); MoveItTool.UpdatePillarMap(); }
private string DumpElement(object element, int depth = 0) { depth++; if (depth > 10) { return(""); } try { if (element == null || element is ValueType || element is string) { Write(FormatValue(element)); } else if (element is Instance ins) { Write($"Instance {MoveItTool.InstanceIDDebug(ins.id)}:{ins.Info.Prefab}"); } else if (element is IInfo info) { Write($"IInfo {info.Name}"); } else { var objectType = element.GetType(); if (!typeof(IEnumerable).IsAssignableFrom(objectType)) { Write("{{{0}}}", objectType.FullName); _hashListOfFoundElements.Add(element.GetHashCode()); _level++; } IEnumerable enumerableElement = element as IEnumerable; if (enumerableElement != null) { foreach (object item in enumerableElement) { if (item is IEnumerable && !(item is string)) { _level++; DumpElement(item, depth); _level--; } else { if (!AlreadyTouched(item)) { DumpElement(item, depth); } else { Write("{{{0}}} <-- bidirectional reference found", item.GetType().FullName); } } } } else { MemberInfo[] members = element.GetType().GetMembers(BindingFlags.Public | BindingFlags.Instance); foreach (var memberInfo in members) { var fieldInfo = memberInfo as FieldInfo; var propertyInfo = memberInfo as PropertyInfo; if (fieldInfo == null && propertyInfo == null) { continue; } var type = fieldInfo != null ? fieldInfo.FieldType : propertyInfo.PropertyType; object value = fieldInfo != null ? fieldInfo.GetValue(element) : propertyInfo.GetValue(element, null); if (type.IsValueType || type == typeof(string)) { Write("{0}: {1}", memberInfo.Name, FormatValue(value)); } else { var isEnumerable = typeof(IEnumerable).IsAssignableFrom(type); Write("{0}: {1}", memberInfo.Name, isEnumerable ? "..." : "{ }"); var alreadyTouched = !isEnumerable && AlreadyTouched(value); _level++; if (!alreadyTouched) { DumpElement(value, depth); } else { Write("{{{0}}} <-- bidirectional reference found", value.GetType().FullName); } _level--; } } } if (!typeof(IEnumerable).IsAssignableFrom(objectType)) { _level--; } } } catch (TargetParameterCountException e) { Log.Error($"ObjectDumper failed - TargetParameterCountException\n{e}"); } return(_stringBuilder.ToString()); }
public override void Start() { instance = this; atlas = UIUtils.GetAtlas("Ingame"); size = new Vector2(41, 41); relativePosition = new Vector2(GetUIView().GetScreenResolution().x - 448, -41); name = "MoveIt_ToolOptionPanel"; DebugUtils.Log("ToolOptionPanel position: " + absolutePosition); #region Group // Group m_group = AddUIComponent <UIButton>(); m_group.name = "MoveIt_Group"; m_group.group = m_tabStrip; m_group.atlas = GetIconsAtlas(); m_group.tooltip = "Group"; m_group.playAudioEvents = true; m_group.size = new Vector2(36, 36); m_group.normalBgSprite = "OptionBase"; m_group.hoveredBgSprite = "OptionBaseHovered"; m_group.pressedBgSprite = "OptionBasePressed"; m_group.disabledBgSprite = "OptionBaseDisabled"; m_group.normalFgSprite = "Group"; m_group.relativePosition = Vector2.zero; m_group.isVisible = false; //TODO: temporary #endregion #region Save m_save = AddUIComponent <UIButton>(); m_save.name = "MoveIt_Save"; m_save.group = m_tabStrip; m_save.atlas = GetIconsAtlas(); m_save.tooltip = "Export"; m_save.playAudioEvents = true; m_save.size = new Vector2(36, 36); m_save.normalBgSprite = "OptionBase"; m_save.hoveredBgSprite = "OptionBaseHovered"; m_save.pressedBgSprite = "OptionBasePressed"; m_save.disabledBgSprite = "OptionBaseDisabled"; m_save.normalFgSprite = "Save"; m_save.disabledFgSprite = "Save_disabled"; m_save.relativePosition = m_group.relativePosition + new Vector3(m_group.width, 0); m_save.eventClicked += (c, p) => { if (MoveItTool.IsExportSelectionValid()) { UISaveWindow.Open(); } else { UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel").SetMessage("Selection invalid", "The selection is empty or invalid.", false); } }; #endregion #region Load m_load = AddUIComponent <UIButton>(); m_load.name = "MoveIt_Load"; m_load.group = m_tabStrip; m_load.atlas = GetIconsAtlas(); m_load.tooltip = "Import"; m_load.playAudioEvents = true; m_load.size = new Vector2(36, 36); m_load.normalBgSprite = "OptionBase"; m_load.hoveredBgSprite = "OptionBaseHovered"; m_load.pressedBgSprite = "OptionBasePressed"; m_load.disabledBgSprite = "OptionBaseDisabled"; m_load.normalFgSprite = "Load"; m_load.relativePosition = m_save.relativePosition + new Vector3(m_save.width, 0); m_load.eventClicked += (c, p) => { UILoadWindow.Open(); }; #endregion #region Follow Terrain m_followTerrain = AddUIComponent <UIMultiStateButton>(); m_followTerrain.atlas = GetFollowTerrainAtlas(); m_followTerrain.name = "MoveIt_FollowTerrain"; m_followTerrain.tooltip = "Follow Terrain"; m_followTerrain.playAudioEvents = true; m_followTerrain.size = new Vector2(36, 36); m_followTerrain.spritePadding = new RectOffset(); m_followTerrain.backgroundSprites[0].disabled = "ToggleBaseDisabled"; m_followTerrain.backgroundSprites[0].hovered = "ToggleBaseHovered"; m_followTerrain.backgroundSprites[0].normal = "ToggleBase"; m_followTerrain.backgroundSprites[0].pressed = "ToggleBasePressed"; m_followTerrain.backgroundSprites.AddState(); m_followTerrain.backgroundSprites[1].disabled = "ToggleBaseDisabled"; m_followTerrain.backgroundSprites[1].hovered = ""; m_followTerrain.backgroundSprites[1].normal = "ToggleBaseFocused"; m_followTerrain.backgroundSprites[1].pressed = "ToggleBasePressed"; m_followTerrain.foregroundSprites[0].normal = "FollowTerrain_disabled"; m_followTerrain.foregroundSprites.AddState(); m_followTerrain.foregroundSprites[1].normal = "FollowTerrain"; m_followTerrain.relativePosition = m_load.relativePosition + new Vector3(m_load.width + m_load.width / 2, 0); m_followTerrain.activeStateIndex = MoveItTool.followTerrain ? 1 : 0; m_followTerrain.eventClicked += (c, p) => { MoveItTool.followTerrain = (m_followTerrain.activeStateIndex == 1); MoveItTool.followTerrainModeEnabled.value = (m_followTerrain.activeStateIndex == 1); }; #endregion #region Snapping m_snapping = AddUIComponent <UIMultiStateButton>(); m_snapping.atlas = UIUtils.GetAtlas("Ingame"); m_snapping.name = "MoveIt_Snapping"; m_snapping.tooltip = "Toggle Snapping"; m_snapping.playAudioEvents = true; m_snapping.size = new Vector2(36, 36); m_snapping.spritePadding = new RectOffset(); m_snapping.backgroundSprites[0].disabled = "ToggleBaseDisabled"; m_snapping.backgroundSprites[0].hovered = "ToggleBaseHovered"; m_snapping.backgroundSprites[0].normal = "ToggleBase"; m_snapping.backgroundSprites[0].pressed = "ToggleBasePressed"; m_snapping.backgroundSprites.AddState(); m_snapping.backgroundSprites[1].disabled = "ToggleBaseDisabled"; m_snapping.backgroundSprites[1].hovered = ""; m_snapping.backgroundSprites[1].normal = "ToggleBaseFocused"; m_snapping.backgroundSprites[1].pressed = "ToggleBasePressed"; m_snapping.foregroundSprites[0].disabled = "SnappingDisabled"; m_snapping.foregroundSprites[0].hovered = "SnappingHovered"; m_snapping.foregroundSprites[0].normal = "Snapping"; m_snapping.foregroundSprites[0].pressed = "SnappingPressed"; m_snapping.foregroundSprites.AddState(); m_snapping.foregroundSprites[1].disabled = "SnappingDisabled"; m_snapping.foregroundSprites[1].hovered = ""; m_snapping.foregroundSprites[1].normal = "SnappingFocused"; m_snapping.foregroundSprites[1].pressed = "SnappingPressed"; m_snapping.relativePosition = m_followTerrain.relativePosition + new Vector3(m_followTerrain.width, 0); m_snapping.activeStateIndex = (MoveItTool.instance != null && MoveItTool.instance.snapping) ? 1 : 0; m_snapping.eventClicked += (c, p) => { if (MoveItTool.instance != null) { MoveItTool.instance.snapping = (m_snapping.activeStateIndex == 1); } }; #endregion m_tabStrip = AddUIComponent <UITabstrip>(); m_tabStrip.size = new Vector2(36, 72); m_tabStrip.relativePosition = m_snapping.relativePosition + new Vector3(m_snapping.width, 0); #region Single Select m_single = m_tabStrip.AddTab("MoveIt_Single", null, false); m_single.group = m_tabStrip; m_single.atlas = UIUtils.GetAtlas("Ingame"); m_single.tooltip = "Single Selection"; m_single.playAudioEvents = true; m_single.size = new Vector2(36, 36); m_single.normalBgSprite = "OptionBase"; m_single.focusedBgSprite = "OptionBaseFocused"; m_single.hoveredBgSprite = "OptionBaseHovered"; m_single.pressedBgSprite = "OptionBasePressed"; m_single.disabledBgSprite = "OptionBaseDisabled"; m_single.text = "•"; m_single.textScale = 1.5f; m_single.textPadding = new RectOffset(0, 1, 4, 0); m_single.textColor = new Color32(119, 124, 126, 255); m_single.hoveredTextColor = new Color32(110, 113, 114, 255); m_single.pressedTextColor = new Color32(172, 175, 176, 255); m_single.focusedTextColor = new Color32(187, 224, 235, 255); m_single.disabledTextColor = new Color32(66, 69, 70, 255); #endregion #region Marquee Select m_marquee = m_tabStrip.AddTab("MoveIt_Marquee", null, false); m_marquee.group = m_tabStrip; m_marquee.atlas = UIUtils.GetAtlas("Ingame"); m_marquee.tooltip = "Marquee Selection"; m_marquee.playAudioEvents = true; m_marquee.size = new Vector2(36, 36); m_marquee.normalBgSprite = "OptionBase"; m_marquee.focusedBgSprite = "OptionBaseFocused"; m_marquee.hoveredBgSprite = "OptionBaseHovered"; m_marquee.pressedBgSprite = "OptionBasePressed"; m_marquee.disabledBgSprite = "OptionBaseDisabled"; m_marquee.normalFgSprite = "ZoningOptionMarquee"; m_marquee.relativePosition = m_single.relativePosition + new Vector3(m_single.width, 0); #endregion #region filtersPanel filtersPanel = AddUIComponent(typeof(UIPanel)) as UIPanel; filtersPanel.atlas = UIUtils.GetAtlas("Ingame"); filtersPanel.backgroundSprite = "SubcategoriesPanel"; filtersPanel.clipChildren = true; filtersPanel.size = new Vector2(150, 140); filtersPanel.isVisible = false; UIFilters.FilterPanel = filtersPanel; void OnDoubleClick(UIComponent c, UIMouseEventParameter p) { foreach (UICheckBox cb in UIFilters.FilterCBs) { cb.isChecked = false; Filters.SetFilter(cb.name, false); } ((UICheckBox)c).isChecked = true; Filters.SetFilter(c.name, true); UIFilters.RefreshFilters(); } #region Standard Filters UICheckBox checkBox = UIFilters.CreateFilterCB(filtersPanel, "Buildings"); checkBox.eventDoubleClick += OnDoubleClick; checkBox = UIFilters.CreateFilterCB(filtersPanel, "Props"); checkBox.eventDoubleClick += OnDoubleClick; checkBox = UIFilters.CreateFilterCB(filtersPanel, "Decals"); checkBox.eventDoubleClick += OnDoubleClick; checkBox = UIFilters.CreateFilterCB(filtersPanel, "Surfaces"); checkBox.eventDoubleClick += OnDoubleClick; checkBox = UIFilters.CreateFilterCB(filtersPanel, "Trees"); checkBox.eventDoubleClick += OnDoubleClick; if (MoveItTool.PO.Enabled) { if (MoveItTool.PO.Active) { filtersPanel.height += 20f; } checkBox = UIFilters.CreateFilterCB(filtersPanel, "PO"); checkBox.eventDoubleClick += OnDoubleClick; checkBox.isVisible = MoveItTool.PO.Active; } checkBox = UIFilters.CreateFilterCB(filtersPanel, "Nodes"); checkBox.eventDoubleClick += OnDoubleClick; checkBox = UIFilters.CreateFilterCB(filtersPanel, "Segments"); checkBox.eventDoubleClick += OnDoubleClick; #endregion #region Network Filters UIButton btnNetworks = UIFilters.CreateToggleNFBtn(); void OnDoubleClickNetworkFilter(UIComponent c, UIMouseEventParameter p) { foreach (UICheckBox cb in UIFilters.NetworkCBs) { cb.isChecked = false; Filters.SetNetworkFilter(cb.name, false); } ((UICheckBox)c).isChecked = true; Filters.SetNetworkFilter(c.name, true); UIFilters.RefreshFilters(); } checkBox = UIFilters.CreateNetworkFilterCB(filtersPanel, "Roads"); checkBox.eventDoubleClick += OnDoubleClickNetworkFilter; checkBox = UIFilters.CreateNetworkFilterCB(filtersPanel, "Tracks"); checkBox.eventDoubleClick += OnDoubleClickNetworkFilter; checkBox = UIFilters.CreateNetworkFilterCB(filtersPanel, "Paths"); checkBox.eventDoubleClick += OnDoubleClickNetworkFilter; checkBox = UIFilters.CreateNetworkFilterCB(filtersPanel, "Fences"); checkBox.eventDoubleClick += OnDoubleClickNetworkFilter; checkBox = UIFilters.CreateNetworkFilterCB(filtersPanel, "Powerlines"); checkBox.eventDoubleClick += OnDoubleClickNetworkFilter; checkBox = UIFilters.CreateNetworkFilterCB(filtersPanel, "Others"); checkBox.eventDoubleClick += OnDoubleClickNetworkFilter; UIFilters.RefreshFilters(); #endregion filtersPanel.padding = new RectOffset(10, 10, 10, 10); filtersPanel.autoLayoutDirection = LayoutDirection.Vertical; filtersPanel.autoLayoutPadding = new RectOffset(0, 0, 0, 5); filtersPanel.autoLayout = true; filtersPanel.height = 210; filtersPanel.absolutePosition = m_marquee.absolutePosition + new Vector3(-47, -5 - filtersPanel.height); #endregion m_marquee.eventButtonStateChanged += (c, p) => { MoveItTool.marqueeSelection = p == UIButton.ButtonState.Focused; filtersPanel.isVisible = MoveItTool.marqueeSelection; if (UITipsWindow.instance != null) { UITipsWindow.instance.RefreshPosition(); } }; m_marquee.eventDoubleClick += (UIComponent c, UIMouseEventParameter p) => { bool newChecked = false; foreach (UICheckBox cb in filtersPanel.GetComponentsInChildren <UICheckBox>()) { if (!cb.isChecked) { newChecked = true; break; } } foreach (UICheckBox cb in filtersPanel.GetComponentsInChildren <UICheckBox>()) { cb.isChecked = newChecked; Filters.SetAnyFilter(cb.label.text, newChecked); } }; #region Copy m_copy = AddUIComponent <UIButton>(); m_copy.name = "MoveIt_Copy"; m_copy.group = m_tabStrip; m_copy.atlas = GetIconsAtlas(); m_copy.tooltip = "Copy"; m_copy.playAudioEvents = true; m_copy.size = new Vector2(36, 36); m_copy.normalBgSprite = "OptionBase"; m_copy.hoveredBgSprite = "OptionBaseHovered"; m_copy.pressedBgSprite = "OptionBasePressed"; m_copy.disabledBgSprite = "OptionBaseDisabled"; m_copy.normalFgSprite = "Copy"; m_copy.relativePosition = m_tabStrip.relativePosition + new Vector3(m_single.width + m_marquee.width, 0); m_copy.eventClicked += (c, p) => { if (MoveItTool.instance != null) { if (MoveItTool.instance.ToolState == MoveItTool.ToolStates.Cloning) { MoveItTool.instance.StopCloning(); } else { MoveItTool.instance.StartCloning(); } } }; #endregion #region Bulldoze m_bulldoze = AddUIComponent <UIButton>(); m_bulldoze.name = "MoveIt_Bulldoze"; m_bulldoze.group = m_tabStrip; m_bulldoze.atlas = GetIconsAtlas(); m_bulldoze.tooltip = "Bulldoze"; m_bulldoze.playAudioEvents = true; m_bulldoze.size = new Vector2(36, 36); m_bulldoze.normalBgSprite = "OptionBase"; m_bulldoze.hoveredBgSprite = "OptionBaseHovered"; m_bulldoze.pressedBgSprite = "OptionBasePressed"; m_bulldoze.disabledBgSprite = "OptionBaseDisabled"; m_bulldoze.normalFgSprite = "Bulldoze"; m_bulldoze.relativePosition = m_copy.relativePosition + new Vector3(m_copy.width, 0); m_bulldoze.eventClicked += (c, p) => { if (MoveItTool.instance != null) { MoveItTool.instance.StartBulldoze(); } }; #endregion #region Align Tools m_alignTools = AddUIComponent <UIButton>(); UIAlignTools.AlignToolsBtn = m_alignTools; m_alignTools.name = "MoveIt_AlignToolsBtn"; m_alignTools.group = m_tabStrip; m_alignTools.atlas = GetIconsAtlas(); m_alignTools.tooltip = "Alignment Tools"; m_alignTools.playAudioEvents = true; m_alignTools.size = new Vector2(36, 36); m_alignTools.normalBgSprite = "OptionBase"; m_alignTools.hoveredBgSprite = "OptionBaseHovered"; m_alignTools.pressedBgSprite = "OptionBasePressed"; m_alignTools.disabledBgSprite = "OptionBaseDisabled"; m_alignTools.normalFgSprite = "AlignTools"; m_alignTools.relativePosition = m_bulldoze.relativePosition + new Vector3(m_bulldoze.width, 0); m_alignTools.eventClicked += UIAlignTools.AlignToolsClicked; alignToolsPanel = AddUIComponent <UIPanel>(); UIAlignTools.AlignToolsPanel = alignToolsPanel; alignToolsPanel.autoLayout = false; alignToolsPanel.clipChildren = true; alignToolsPanel.size = new Vector2(36, 242); // Previous:238 alignToolsPanel.isVisible = false; alignToolsPanel.absolutePosition = m_alignTools.absolutePosition + new Vector3(0, 10 - alignToolsPanel.height); m_alignTools.zOrder = alignToolsPanel.zOrder + 10; UIPanel atpBackground = alignToolsPanel.AddUIComponent <UIPanel>(); atpBackground.size = new Vector2(26, 236); atpBackground.clipChildren = true; atpBackground.relativePosition = new Vector3(5, 10); atpBackground.atlas = UIUtils.GetAtlas("Ingame"); atpBackground.backgroundSprite = "InfoPanelBack"; UIPanel atpContainer = alignToolsPanel.AddUIComponent <UIPanel>(); atpContainer.autoLayoutDirection = LayoutDirection.Vertical; atpContainer.autoLayoutPadding = new RectOffset(0, 0, 0, 3); atpContainer.autoLayout = true; atpContainer.relativePosition = Vector3.zero; UIAlignTools.AlignButtons.Clear(); UIAlignTools.AlignButtons.Add("MoveIt_AlignRandomBtn", atpContainer.AddUIComponent <UIButton>()); UIButton alignRandom = UIAlignTools.AlignButtons["MoveIt_AlignRandomBtn"]; alignRandom.name = "MoveIt_AlignRandomBtn"; alignRandom.atlas = GetIconsAtlas(); alignRandom.tooltip = "Immediate rotate valid items randomly"; alignRandom.playAudioEvents = true; alignRandom.size = new Vector2(36, 36); alignRandom.normalBgSprite = "OptionBase"; alignRandom.hoveredBgSprite = "OptionBaseHovered"; alignRandom.pressedBgSprite = "OptionBasePressed"; alignRandom.disabledBgSprite = "OptionBaseDisabled"; alignRandom.normalFgSprite = "AlignRandom"; alignRandom.eventClicked += UIAlignTools.AlignToolsClicked; UIAlignTools.AlignButtons.Add("MoveIt_AlignGroupBtn", atpContainer.AddUIComponent <UIButton>()); UIButton alignGroup = UIAlignTools.AlignButtons["MoveIt_AlignGroupBtn"]; alignGroup.name = "MoveIt_AlignGroupBtn"; alignGroup.atlas = GetIconsAtlas(); alignGroup.tooltip = "Align as Group - rotate around a central point"; alignGroup.playAudioEvents = true; alignGroup.size = new Vector2(36, 36); alignGroup.normalBgSprite = "OptionBase"; alignGroup.hoveredBgSprite = "OptionBaseHovered"; alignGroup.pressedBgSprite = "OptionBasePressed"; alignGroup.disabledBgSprite = "OptionBaseDisabled"; alignGroup.normalFgSprite = "AlignGroup"; alignGroup.eventClicked += UIAlignTools.AlignToolsClicked; UIAlignTools.AlignButtons.Add("MoveIt_AlignIndividualBtn", atpContainer.AddUIComponent <UIButton>()); UIButton alignIndividual = UIAlignTools.AlignButtons["MoveIt_AlignIndividualBtn"]; alignIndividual.name = "MoveIt_AlignIndividualBtn"; alignIndividual.atlas = GetIconsAtlas(); alignIndividual.tooltip = "Align In-Place - rotate selected items"; alignIndividual.playAudioEvents = true; alignIndividual.size = new Vector2(36, 36); alignIndividual.normalBgSprite = "OptionBase"; alignIndividual.hoveredBgSprite = "OptionBaseHovered"; alignIndividual.pressedBgSprite = "OptionBasePressed"; alignIndividual.disabledBgSprite = "OptionBaseDisabled"; alignIndividual.normalFgSprite = "AlignIndividual"; alignIndividual.eventClicked += UIAlignTools.AlignToolsClicked; UIAlignTools.AlignButtons.Add("MoveIt_AlignSlopeBtn", atpContainer.AddUIComponent <UIButton>()); UIButton alignSlope = UIAlignTools.AlignButtons["MoveIt_AlignSlopeBtn"]; alignSlope.name = "MoveIt_AlignSlopeBtn"; alignSlope.atlas = GetIconsAtlas(); alignSlope.tooltip = "Align Slope"; alignSlope.playAudioEvents = true; alignSlope.size = new Vector2(36, 36); alignSlope.normalBgSprite = "OptionBase"; alignSlope.hoveredBgSprite = "OptionBaseHovered"; alignSlope.pressedBgSprite = "OptionBasePressed"; alignSlope.disabledBgSprite = "OptionBaseDisabled"; alignSlope.normalFgSprite = "AlignSlope"; alignSlope.eventClicked += UIAlignTools.AlignToolsClicked; UIAlignTools.AlignButtons.Add("MoveIt_AlignTerrainHeightBtn", atpContainer.AddUIComponent <UIButton>()); UIButton alignTerrainHeight = UIAlignTools.AlignButtons["MoveIt_AlignTerrainHeightBtn"]; alignTerrainHeight.name = "MoveIt_AlignTerrainHeightBtn"; alignTerrainHeight.atlas = GetIconsAtlas(); alignTerrainHeight.tooltip = "Immediately Align to Terrain Height"; alignTerrainHeight.playAudioEvents = true; alignTerrainHeight.size = new Vector2(36, 36); alignTerrainHeight.normalBgSprite = "OptionBase"; alignTerrainHeight.hoveredBgSprite = "OptionBaseHovered"; alignTerrainHeight.pressedBgSprite = "OptionBasePressed"; alignTerrainHeight.disabledBgSprite = "OptionBaseDisabled"; alignTerrainHeight.normalFgSprite = "AlignTerrainHeight"; alignTerrainHeight.eventClicked += UIAlignTools.AlignToolsClicked; UIAlignTools.AlignButtons.Add("MoveIt_AlignHeightBtn", atpContainer.AddUIComponent <UIButton>()); UIButton alignHeight = UIAlignTools.AlignButtons["MoveIt_AlignHeightBtn"]; alignHeight.name = "MoveIt_AlignHeightBtn"; alignHeight.atlas = GetIconsAtlas(); alignHeight.tooltip = "Align Height"; alignHeight.playAudioEvents = true; alignHeight.size = new Vector2(36, 36); alignHeight.normalBgSprite = "OptionBase"; alignHeight.hoveredBgSprite = "OptionBaseHovered"; alignHeight.pressedBgSprite = "OptionBasePressed"; alignHeight.disabledBgSprite = "OptionBaseDisabled"; alignHeight.normalFgSprite = "AlignHeight"; alignHeight.eventClicked += UIAlignTools.AlignToolsClicked; #endregion #region View Options viewOptions = AddUIComponent <UIPanel>(); viewOptions.atlas = UIUtils.GetAtlas("Ingame"); viewOptions.backgroundSprite = "InfoPanelBack"; viewOptions.size = new Vector2(44f, 80f); viewOptions.absolutePosition = new Vector3(GetUIView().GetScreenResolution().x - viewOptions.width, absolutePosition.y - viewOptions.height - 8f); grid = viewOptions.AddUIComponent <UIMultiStateButton>(); grid.atlas = GetIconsAtlas(); grid.name = "MoveIt_GridView"; grid.tooltip = "Toggle Grid"; grid.playAudioEvents = true; grid.size = new Vector2(36, 36); grid.spritePadding = new RectOffset(); grid.backgroundSprites[0].disabled = "OptionBaseDisabled"; grid.backgroundSprites[0].hovered = "OptionBaseHovered"; grid.backgroundSprites[0].normal = "OptionBase"; grid.backgroundSprites[0].pressed = "OptionBasePressed"; grid.backgroundSprites.AddState(); grid.backgroundSprites[1].disabled = "OptionBaseDisabled"; grid.backgroundSprites[1].hovered = ""; grid.backgroundSprites[1].normal = "OptionBaseFocused"; grid.backgroundSprites[1].pressed = "OptionBasePressed"; grid.foregroundSprites[0].normal = "Grid"; grid.foregroundSprites.AddState(); grid.foregroundSprites[1].normal = "GridFocused"; grid.relativePosition = new Vector3(4f, 4f); grid.activeStateIndex = 0; grid.eventClicked += (c, p) => { MoveItTool.gridVisible = (grid.activeStateIndex == 1); }; underground = viewOptions.AddUIComponent <UIMultiStateButton>(); underground.atlas = UIUtils.GetAtlas("Ingame"); underground.name = "MoveIt_UndergroundView"; underground.tooltip = "Toogle Underground View"; underground.playAudioEvents = true; underground.size = new Vector2(36, 36); underground.spritePadding = new RectOffset(); underground.backgroundSprites[0].disabled = "OptionBaseDisabled"; underground.backgroundSprites[0].hovered = "OptionBaseHovered"; underground.backgroundSprites[0].normal = "OptionBase"; underground.backgroundSprites[0].pressed = "OptionBasePressed"; underground.backgroundSprites.AddState(); underground.backgroundSprites[1].disabled = "OptionBaseDisabled"; underground.backgroundSprites[1].hovered = ""; underground.backgroundSprites[1].normal = "OptionBaseFocused"; underground.backgroundSprites[1].pressed = "OptionBasePressed"; underground.foregroundSprites[0].normal = "BulldozerOptionPipes"; underground.foregroundSprites.AddState(); underground.foregroundSprites[1].normal = "BulldozerOptionPipesFocused"; underground.relativePosition = new Vector3(4f, 40f); underground.activeStateIndex = 0; underground.eventClicked += (c, p) => { MoveItTool.tunnelVisible = (underground.activeStateIndex == 1); }; if (MoveItTool.PO.Enabled) { PO_button = viewOptions.AddUIComponent <UIMultiStateButton>(); PO_button.atlas = GetIconsAtlas(); PO_button.name = "MoveIt_PO_button"; PO_button.tooltip = "Toggle Procedural Objects"; PO_button.playAudioEvents = true; PO_button.size = new Vector2(36, 36); PO_button.spritePadding = new RectOffset(); PO_button.backgroundSprites[0].disabled = "OptionBaseDisabled"; PO_button.backgroundSprites[0].hovered = "OptionBaseHovered"; PO_button.backgroundSprites[0].normal = "OptionBase"; PO_button.backgroundSprites[0].pressed = "OptionBasePressed"; PO_button.backgroundSprites.AddState(); PO_button.backgroundSprites[1].disabled = "OptionBaseDisabled"; PO_button.backgroundSprites[1].hovered = ""; PO_button.backgroundSprites[1].normal = "OptionBaseFocused"; PO_button.backgroundSprites[1].pressed = "OptionBasePressed"; PO_button.foregroundSprites[0].normal = "PO"; PO_button.foregroundSprites.AddState(); PO_button.foregroundSprites[1].normal = "POFocused"; PO_button.relativePosition = new Vector3(4f, 76f); PO_button.activeStateIndex = 0; PO_button.eventClicked += (c, p) => { MoveItTool.PO.Active = (PO_button.activeStateIndex == 1); if (MoveItTool.PO.Active) { MoveItTool.PO.ToolEnabled(); ActionQueue.instance.Push(new TransformAction()); } else { Action.ClearPOFromSelection(); } UIFilters.POToggled(); }; if (!MoveItTool.HidePO) { viewOptions.height += 36; viewOptions.absolutePosition += new Vector3(0, -36); } else { PO_button.isVisible = false; } } #endregion MoveItTool.debugPanel = new DebugPanel(); }