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); } }
private Vector3 GetSnapDelta(Vector3 moveDelta, float angleDelta, Vector3 center, out bool autoCurve) { autoCurve = false; if (VectorUtils.XZ(moveDelta) == Vector2.zero) { return(moveDelta); } Vector3 newMoveDelta = moveDelta; NetManager netManager = NetManager.instance; NetSegment[] segmentBuffer = netManager.m_segments.m_buffer; NetNode[] nodeBuffer = netManager.m_nodes.m_buffer; Building[] buildingBuffer = BuildingManager.instance.m_buildings.m_buffer; Matrix4x4 matrix4x = default; matrix4x.SetTRS(center, Quaternion.AngleAxis(angleDelta * Mathf.Rad2Deg, Vector3.down), Vector3.one); bool snap = false; HashSet <InstanceState> newStates = null; if (ActionQueue.instance.current is TransformAction transformAction) { newStates = transformAction.CalculateStates(moveDelta, angleDelta, center, followTerrain); } if (ActionQueue.instance.current is CloneAction cloneAction) { newStates = cloneAction.CalculateStates(moveDelta, angleDelta, center, followTerrain); } // Snap to direction if (newStates.Count == 1) { foreach (InstanceState state in newStates) { if (state.instance.id.Type == InstanceType.NetSegment) { return(SnapSegmentDirections(state.instance.id.NetSegment, state.position, moveDelta)); } else if (state.instance.id.Type == InstanceType.NetNode) { if (TrySnapNodeDirections(state.instance.id.NetNode, state.position, moveDelta, out newMoveDelta, out autoCurve)) { DebugUtils.Log("Snap to direction: " + moveDelta + ", " + newMoveDelta); return(newMoveDelta); } } } } HashSet <ushort> ingnoreSegments = new HashSet <ushort>(); HashSet <ushort> segmentList = new HashSet <ushort>(); ushort[] closeSegments = new ushort[16]; // Get list of closest segments foreach (InstanceState state in newStates) { netManager.GetClosestSegments(state.position, closeSegments, out int closeSegmentCount); segmentList.UnionWith(closeSegments); if (ToolState != ToolStates.Cloning) { ingnoreSegments.UnionWith(state.instance.segmentList); } } float distanceSq = float.MaxValue; // Snap to node foreach (ushort segment in segmentList) { if (!ingnoreSegments.Contains(segment)) { foreach (InstanceState state in newStates) { if (state.instance.id.Type == InstanceType.NetNode) { float minSqDistance = segmentBuffer[segment].Info.GetMinNodeDistance() / 2f; minSqDistance *= minSqDistance; ushort startNode = segmentBuffer[segment].m_startNode; ushort endNode = segmentBuffer[segment].m_endNode; snap = TrySnapping(nodeBuffer[startNode].m_position, state.position, minSqDistance, ref distanceSq, moveDelta, ref newMoveDelta) || snap; snap = TrySnapping(nodeBuffer[endNode].m_position, state.position, minSqDistance, ref distanceSq, moveDelta, ref newMoveDelta) || snap; } } } } if (snap) { DebugUtils.Log("Snap to node: " + moveDelta + ", " + newMoveDelta); return(newMoveDelta); } // Snap to segment foreach (ushort segment in segmentList) { if (!ingnoreSegments.Contains(segment)) { foreach (InstanceState state in newStates) { if (state.instance.id.Type == InstanceType.NetNode) { float minSqDistance = segmentBuffer[segment].Info.GetMinNodeDistance() / 2f; minSqDistance *= minSqDistance; segmentBuffer[segment].GetClosestPositionAndDirection(state.position, out Vector3 testPos, out Vector3 direction); snap = TrySnapping(testPos, state.position, minSqDistance, ref distanceSq, moveDelta, ref newMoveDelta) || snap; } } } } if (snap) { DebugUtils.Log("Snap to segment: " + moveDelta + ", " + newMoveDelta); return(newMoveDelta); } // Snap to grid ushort block = 0; ushort previousBlock = 0; Vector3 refPosition = Vector3.zero; bool smallRoad = false; foreach (ushort segment in segmentList) { bool hasBlocks = segment != 0 && (segmentBuffer[segment].m_blockStartLeft != 0 || segmentBuffer[segment].m_blockStartRight != 0 || segmentBuffer[segment].m_blockEndLeft != 0 || segmentBuffer[segment].m_blockEndRight != 0); if (hasBlocks && !ingnoreSegments.Contains(segment)) { foreach (InstanceState state in newStates) { if (state.instance.id.Type != InstanceType.NetSegment) { Vector3 testPosition = state.position; if (state.instance.id.Type == InstanceType.Building) { ushort building = state.instance.id.Building; testPosition = GetBuildingSnapPoint(state.position, state.angle, buildingBuffer[building].Length, buildingBuffer[building].Width); } segmentBuffer[segment].GetClosestZoneBlock(testPosition, ref distanceSq, ref block); if (block != previousBlock) { refPosition = testPosition; if (state.instance.id.Type == InstanceType.NetNode) { if (nodeBuffer[state.instance.id.NetNode].Info.m_halfWidth <= 4f) { smallRoad = true; } } previousBlock = block; } } } } } if (block != 0) { Vector3 newPosition = refPosition; ZoneBlock zoneBlock = ZoneManager.instance.m_blocks.m_buffer[block]; SnapToBlock(ref newPosition, zoneBlock.m_position, zoneBlock.m_angle, smallRoad); DebugUtils.Log("Snap to grid: " + moveDelta + ", " + (moveDelta + newPosition - refPosition)); return(moveDelta + newPosition - refPosition); } // Snap to editor grid if ((ToolManager.instance.m_properties.m_mode & ItemClass.Availability.AssetEditor) != ItemClass.Availability.None) { Vector3 assetGridPosition = Vector3.zero; float testMagnitude = 0; foreach (InstanceState state in newStates) { Vector3 testPosition = state.position; if (state.instance.id.Type == InstanceType.Building) { ushort building = state.instance.id.Building; testPosition = GetBuildingSnapPoint(state.position, state.angle, buildingBuffer[building].Length, buildingBuffer[building].Width); } float x = Mathf.Round(testPosition.x / 8f) * 8f; float z = Mathf.Round(testPosition.z / 8f) * 8f; Vector3 newPosition = new Vector3(x, testPosition.y, z); float deltaMagnitude = (newPosition - testPosition).sqrMagnitude; if (assetGridPosition == Vector3.zero || deltaMagnitude < testMagnitude) { refPosition = testPosition; assetGridPosition = newPosition; deltaMagnitude = testMagnitude; } } DebugUtils.Log("Snap to grid: " + moveDelta + ", " + (moveDelta + assetGridPosition - refPosition)); return(moveDelta + assetGridPosition - refPosition); } return(moveDelta); }
private void OnLeftClick() { DebugUtils.Log("OnLeftClick: " + ToolState); if (POProcessing > 0) { return; } if (ToolState == ToolStates.Default || ToolState == ToolStates.DrawingSelection || ToolState == ToolStates.ToolActive) { Event e = Event.current; if (m_hoverInstance == null) { return; } #region Debug Ouput //Instance instance = m_hoverInstance; //InstanceID instanceID = instance.id; //Log.Debug($"instance:{(instance == null ? "null" : instance.GetType().ToString())}"); //if (instanceID.Building > 0) //{ // MoveableBuilding mb = (MoveableBuilding)instance; // string msg = $"{mb.id.Building}:{mb.Info.Name}\n"; // //Log.Debug(msg); // foreach (Instance subInstance in mb.subInstances) // { // msg += $" - {subInstance.id.Building}/{subInstance.id.NetNode}: {subInstance.Info.Name}\n"; // //Log.Debug(msg); // if (subInstance.id.Building > 0) // { // foreach (Instance subSubInstance in ((MoveableBuilding)subInstance).subInstances) // { // msg += $" - {subSubInstance.id.Building}/{subSubInstance.id.NetNode}: {subSubInstance.Info.Name}\n"; // //Log.Debug(msg); // } // } // } // msg += "End"; // Log.Debug(msg); //} #endregion if (!(ActionQueue.instance.current is SelectAction)) { ActionQueue.instance.Push(new SelectAction(Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))); } else { ActionQueue.instance.Invalidate(); } if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) //"if (e.shift)" apparently fails in Linux { if (e.alt && m_hoverInstance is MoveableSegment ms && FindOwnerBuilding(ms.id.NetSegment, 363f) == 0) { MoveableNode closest = ms.GetNodeByDistance(); MoveableNode furthest = ms.GetNodeByDistance(true); if (!Action.selection.Contains(closest)) { Action.selection.Add(closest); } else if (!Action.selection.Contains(furthest)) { Action.selection.Add(furthest); } else { Action.selection.Remove(furthest); } } else { if (Action.selection.Contains(m_hoverInstance)) { Action.selection.RemoveObject(m_hoverInstance); } else { Action.selection.AddObject(m_hoverInstance); } } } else { if (e.alt && m_hoverInstance is MoveableSegment ms && FindOwnerBuilding(ms.id.NetSegment, 363f) == 0) { MoveableNode closest = ms.GetNodeByDistance(); MoveableNode furthest = ms.GetNodeByDistance(true); if (Action.selection.Contains(closest) && !Action.selection.Contains(furthest)) { Action.selection.Clear(); Action.selection.Add(furthest); } else { Action.selection.Clear(); Action.selection.Add(closest); } }
public override void Do() { m_clones = new HashSet <Instance>(); Matrix4x4 matrix4x = default(Matrix4x4); matrix4x.SetTRS(center + moveDelta, Quaternion.AngleAxis(angleDelta * Mathf.Rad2Deg, Vector3.down), Vector3.one); Dictionary <Instance, Instance> clonedOrigin = new Dictionary <Instance, Instance>(); Dictionary <ushort, ushort> clonedNodes = new Dictionary <ushort, ushort>(); // Clone nodes first foreach (InstanceState state in m_states) { if (state.instance.id.Type == InstanceType.NetNode) { Instance clone = state.instance.Clone(state, ref matrix4x, moveDelta.y, angleDelta, center, followTerrain, clonedNodes); if (clone != null) { m_clones.Add(clone); clonedOrigin.Add(state.instance.id, clone.id); clonedNodes.Add(state.instance.id.NetNode, clone.id.NetNode); } } } // Clone everything else foreach (InstanceState state in m_states) { if (state.instance.id.Type != InstanceType.NetNode) { Instance clone = state.instance.Clone(state, ref matrix4x, moveDelta.y, angleDelta, center, followTerrain, clonedNodes); if (clone != null) { //if (state.instance.id.Type == InstanceType.Building) //{ // MoveableBuilding mb = (MoveableBuilding)state.instance; // Building b = (Building)mb.data; // Building c = (Building)clone.data; // InstanceID i1 = default(InstanceID); // i1.NetNode = b.m_netNode; // InstanceID i2 = default(InstanceID); // i2.NetNode = c.m_netNode; // Debug.Log($"SUBBUILDINGS\n{mb.id.Building}:{b.m_netNode} ({i1})\n{clone.id.Building}:{c.m_netNode} ({i2})"); //} m_clones.Add(clone); clonedOrigin.Add(state.instance.id, clone.id); } } } if (m_clonedOrigin != null) { Dictionary <Instance, Instance> toReplace = new Dictionary <Instance, Instance>(); foreach (Instance key in m_clonedOrigin.Keys) { toReplace.Add(m_clonedOrigin[key], clonedOrigin[key]); DebugUtils.Log("To replace: " + m_clonedOrigin[key].id.RawData + " -> " + clonedOrigin[key].id.RawData); } ActionQueue.instance.ReplaceInstancesForward(toReplace); } m_clonedOrigin = clonedOrigin; // Select clones selection = m_clones; //if (!_isImport) //{ // MoveItTool.m_debugPanel.Update(); //} UpdateArea(GetTotalBounds(false)); }
public override void Do() { if (MoveItTool.POProcessing) { return; } MoveItTool.instance.m_lastInstance = null; m_clones = new HashSet <Instance>(); m_origToCloneUpdate = new Dictionary <Instance, Instance>(); m_nodeOrigToClone = new Dictionary <ushort, ushort>(); matrix4x.SetTRS(center + moveDelta, Quaternion.AngleAxis(angleDelta * Mathf.Rad2Deg, Vector3.down), Vector3.one); // Clone nodes first foreach (InstanceState state in m_states) { if (state.instance.id.Type == InstanceType.NetNode) { Instance clone = state.instance.Clone(state, ref matrix4x, moveDelta.y, angleDelta, center, followTerrain, m_nodeOrigToClone, this); if (clone != null) { m_clones.Add(clone); m_origToCloneUpdate.Add(state.instance.id, clone.id); m_nodeOrigToClone.Add(state.instance.id.NetNode, clone.id.NetNode); } } } // Clone everything else foreach (InstanceState state in m_states) { if (state.instance.id.Type != InstanceType.NetNode) { Instance clone = state.instance.Clone(state, ref matrix4x, moveDelta.y, angleDelta, center, followTerrain, m_nodeOrigToClone, this); // Cloned PO returns null, because it is delayed if (clone != null) { //if (state.instance.id.Type == InstanceType.Building) //{ // MoveableBuilding mb = (MoveableBuilding)state.instance; // Building b = (Building)mb.data; // Building c = (Building)clone.data; // InstanceID i1 = default; // i1.NetNode = b.m_netNode; // InstanceID i2 = default; // i2.NetNode = c.m_netNode; // Debug.Log($"SUBBUILDINGS\n{mb.id.Building}:{b.m_netNode} ({i1})\n{clone.id.Building}:{c.m_netNode} ({i2})"); //} m_clones.Add(clone); m_origToCloneUpdate.Add(state.instance.id, clone.id); if (state is SegmentState segmentState) { MoveItTool.NS.SetSegmentModifiers(clone.id.NetSegment, segmentState); } } } } 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; //if (!_isImport) //{ MoveItTool.m_debugPanel.UpdatePanel(); //} UpdateArea(GetTotalBounds(false)); }
public void OnSettingsUI(UIHelperBase helper) { try { LocaleManager.eventLocaleChanged -= MoveItLoader.LocaleChanged; MoveItLoader.LocaleChanged(); LocaleManager.eventLocaleChanged += MoveItLoader.LocaleChanged; UIHelperBase group = helper.AddGroup(Name); UIPanel panel = ((UIHelper)group).self as UIPanel; UICheckBox checkBox = (UICheckBox)group.AddCheckbox(Str.options_AutoCloseToolbox, MoveItTool.autoCloseAlignTools.value, (b) => { MoveItTool.autoCloseAlignTools.value = b; if (UIMoreTools.MoreToolsPanel != null) { UIMoreTools.CloseMenu(); } }); checkBox.tooltip = Str.options_AutoCloseToolbox_Tooltip; group.AddSpace(10); checkBox = (UICheckBox)group.AddCheckbox(Str.options_PreferFastmove, MoveItTool.fastMove.value, (b) => { MoveItTool.fastMove.value = b; }); checkBox.tooltip = Str.options_PreferFastmove_Tooltip; group.AddSpace(10); checkBox = (UICheckBox)group.AddCheckbox(Str.options_UseCompass, MoveItTool.useCardinalMoves.value, (b) => { MoveItTool.useCardinalMoves.value = b; }); checkBox.tooltip = Str.options_UseCompass_Tooltip; group.AddSpace(10); checkBox = (UICheckBox)group.AddCheckbox(Str.options_RightClickCancel, MoveItTool.rmbCancelsCloning.value, (b) => { MoveItTool.rmbCancelsCloning.value = b; }); checkBox.tooltip = Str.options_RightClickCancel_Tooltip; group.AddSpace(10); checkBox = (UICheckBox)group.AddCheckbox(Str.options_AdvancedPillarControl, MoveItTool.advancedPillarControl.value, (b) => { MoveItTool.advancedPillarControl.value = b; }); checkBox.tooltip = Str.options_AdvancedPillarControl_Tooltip; group.AddSpace(10); checkBox = (UICheckBox)group.AddCheckbox(Str.options_AltForPillars, MoveItTool.altSelectNodeBuildings.value, (b) => { MoveItTool.altSelectNodeBuildings.value = b; }); group.AddSpace(10); group = helper.AddGroup(Str.options_ShortcutsGeneral); panel = ((UIHelper)group).self as UIPanel; group.AddSpace(10); ((UIPanel)((UIHelper)group).self).gameObject.AddComponent <OptionsKeymappingMain>(); group.AddSpace(10); group = helper.AddGroup(Str.options_ShortcutsToolbox); panel = ((UIHelper)group).self as UIPanel; group.AddSpace(10); ((UIPanel)((UIHelper)group).self).gameObject.AddComponent <OptionsKeymappingToolbox>(); group.AddSpace(10); group = helper.AddGroup(Str.options_ExtraOptions); panel = ((UIHelper)group).self as UIPanel; group.AddSpace(10); UIButton button = (UIButton)group.AddButton(Str.options_RemoveGhostNodes, MoveItTool.CleanGhostNodes); button.tooltip = Str.options_RemoveGhostNodes_Tooltip; group.AddSpace(10); button = (UIButton)group.AddButton(Str.options_ResetButtonPosition, () => { UIMoveItButton.savedX.value = -1000; UIMoveItButton.savedY.value = -1000; MoveItTool.instance?.m_button?.ResetPosition(); }); group.AddSpace(20); checkBox = (UICheckBox)group.AddCheckbox(Str.options_DisableDebugLogging, DebugUtils.hideDebugMessages.value, (b) => { DebugUtils.hideDebugMessages.value = b; }); checkBox.tooltip = Str.options_DisableDebugLogging_Tooltip; checkBox = (UICheckBox)group.AddCheckbox(Str.options_ShowDebugPanel, MoveItTool.showDebugPanel.value, (b) => { MoveItTool.showDebugPanel.value = b; if (MoveItTool.m_debugPanel != null) { MoveItTool.m_debugPanel.Visible(b); } }); checkBox.name = "MoveIt_DebugPanel"; group.AddSpace(5); UILabel nsLabel = panel.AddUIComponent <UILabel>(); nsLabel.name = "nsLabel"; nsLabel.text = NS_Manager.getVersionText(); group = helper.AddGroup(Str.options_ProceduralObjects); panel = ((UIHelper)group).self as UIPanel; UILabel poLabel = panel.AddUIComponent <UILabel>(); poLabel.name = "poLabel"; poLabel.text = PO_Manager.getVersionText(); // TODO add users of MoveITIntegration.dll here by name/description UILabel poWarning = panel.AddUIComponent <UILabel>(); poWarning.name = "poWarning"; poWarning.padding = new RectOffset(25, 0, 0, 15); poWarning.text = Str.options_PODeleteWarning; checkBox = (UICheckBox)group.AddCheckbox(Str.options_HidePODeletionWarning, !MoveItTool.POShowDeleteWarning.value, (b) => { MoveItTool.POShowDeleteWarning.value = !b; }); group.AddSpace(15); panel.gameObject.AddComponent <OptionsKeymappingPO>(); group.AddSpace(15); } catch (Exception e) { DebugUtils.Log("OnSettingsUI failed"); DebugUtils.LogException(e); } }
public void OnSettingsUI(UIHelperBase helper) { try { UIHelperBase group = helper.AddGroup(Name); UIPanel panel = ((UIPanel)((UIHelper)group).self) as UIPanel; UICheckBox checkBox = (UICheckBox)group.AddCheckbox("Hide tips", MoveItTool.hideTips.value, (b) => { MoveItTool.hideTips.value = b; if (UITipsWindow.instance != null) { UITipsWindow.instance.isVisible = false; } }); checkBox.tooltip = "Check this if you don't want to see the tips."; group.AddSpace(10); checkBox = (UICheckBox)group.AddCheckbox("Auto-close Align Tools menu", MoveItTool.autoCloseAlignTools.value, (b) => { MoveItTool.autoCloseAlignTools.value = b; if (UIAlignTools.AlignToolsPanel != null) { UIAlignTools.AlignToolsPanel.isVisible = false; } }); checkBox.tooltip = "Check this to close the Align Tools menu after choosing a tool."; group.AddSpace(10); checkBox = (UICheckBox)group.AddCheckbox("Prefer fast, low-detail moving (hold Shift to temporarily switch)", MoveItTool.fastMove.value, (b) => { MoveItTool.fastMove.value = b; }); checkBox.tooltip = "Helps you position objects when your frame-rate is poor."; group.AddSpace(10); checkBox = (UICheckBox)group.AddCheckbox("Select pylons and pillars by holding Alt only", MoveItTool.altSelectNodeBuildings.value, (b) => { MoveItTool.altSelectNodeBuildings.value = b; }); group.AddSpace(10); checkBox = (UICheckBox)group.AddCheckbox("Use cardinal movements", MoveItTool.useCardinalMoves.value, (b) => { MoveItTool.useCardinalMoves.value = b; }); checkBox.tooltip = "If checked, Up will move in the North direction, Down is South, Left is West, Right is East."; group.AddSpace(10); checkBox = (UICheckBox)group.AddCheckbox("Right click cancels cloning", MoveItTool.rmbCancelsCloning.value, (b) => { MoveItTool.rmbCancelsCloning.value = b; }); checkBox.tooltip = "If checked, Right click will cancel cloning instead of rotating 45°."; group.AddSpace(15); ((UIPanel)((UIHelper)group).self).gameObject.AddComponent <OptionsKeymappingMain>(); group.AddSpace(15); UIButton button = (UIButton)group.AddButton("Remove Ghost Nodes", _cleanGhostNodes); button.tooltip = "Use this button when in-game to remove ghost nodes (nodes with no segments attached). Note: this will clear Move It's undo history!"; group.AddSpace(20); checkBox = (UICheckBox)group.AddCheckbox("Disable debug messages logging", DebugUtils.hideDebugMessages.value, (b) => { DebugUtils.hideDebugMessages.value = b; }); checkBox.tooltip = "If checked, debug messages won't be logged."; checkBox = (UICheckBox)group.AddCheckbox("Show Move It debug panel\n", MoveItTool.showDebugPanel.value, (b) => { MoveItTool.showDebugPanel.value = b; if (MoveItTool.m_debugPanel != null) { MoveItTool.m_debugPanel.Visible(b); } }); checkBox.name = "MoveIt_DebugPanel"; UILabel debugLabel = panel.AddUIComponent <UILabel>(); debugLabel.name = "debugLabel"; debugLabel.text = "Shows information about the last highlighted object. Slightly decreases\nperformance, do not enable unless you have a specific reason.\n "; group.AddSpace(5); if (!MoveItTool.HidePO) { group = helper.AddGroup("Procedural Objects"); panel = ((UIPanel)((UIHelper)group).self) as UIPanel; UILabel poLabel = panel.AddUIComponent <UILabel>(); poLabel.name = "poLabel"; poLabel.text = PO_Manager.getVersionText(); UILabel poWarning = panel.AddUIComponent <UILabel>(); poWarning.name = "poWarning"; poWarning.text = "Procedural Objects (PO) support is in beta. At present you can not clone PO objects, \n" + "redo Convert-to-PO actions or undo Bulldoze actions. This means if you delete PO objects \n" + "with Move It, they are immediately PERMANENTLY gone.\n "; checkBox = (UICheckBox)group.AddCheckbox("Limit Move It to only PO objects selected in PO", MoveItTool.POOnlySelectedAreVisible.value, (b) => { MoveItTool.POOnlySelectedAreVisible.value = b; if (MoveItTool.PO != null) { MoveItTool.PO.ToolEnabled(); } }); checkBox.tooltip = "If you have a lot of PO objects (250 or more), this is recommended."; checkBox = (UICheckBox)group.AddCheckbox("Highlight unselected visible PO objects", MoveItTool.POHighlightUnselected.value, (b) => { MoveItTool.POHighlightUnselected.value = b; if (MoveItTool.PO != null) { MoveItTool.PO.ToolEnabled(); } }); checkBox.tooltip = "Show a faded purple circle around PO objects that aren't selected."; group.AddSpace(15); panel.gameObject.AddComponent <OptionsKeymappingPO>(); group.AddSpace(15); } } catch (Exception e) { DebugUtils.Log("OnSettingsUI failed"); DebugUtils.LogException(e); } }
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(); }
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 override void Start() { instance = this; 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); m_followTerrain = AddUIComponent <UIMultiStateButton>(); m_followTerrain.atlas = GetFollowTerrainAtlas(); m_followTerrain.name = "MoveIt_Snapping"; 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 = Vector2.zero; m_followTerrain.activeStateIndex = MoveItTool.followTerrain ? 1 : 0; m_followTerrain.eventClicked += (c, p) => { MoveItTool.followTerrain = (m_followTerrain.activeStateIndex == 1); }; 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; MouseEventHandler OnDoubleClick = (c, 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) { MoveItTool.instance.StartAligningHeight(); RefreshAlignHeightButton(); } }; 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) { 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\nWARNING: NO UNDO!"; 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(); } }; }
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); 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); } } } } // 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 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) { Instance clone = 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)); }
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>(); 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_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); m_origToCloneUpdate.Add(state.instance.id, clone.id); if (state is SegmentState segmentState) { MoveItTool.NS.SetSegmentModifiers(clone.id.NetSegment, segmentState); } } } // Clone PO foreach (InstanceState state in m_states) { if (state is ProcState) { Instance clone = 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)); }
private bool TrySnapNodeDirections(ushort node, Vector3 newPosition, Vector3 moveDelta, out Vector3 newMoveDelta, out bool autoCurve) { string snapType = ""; m_segmentGuide = default; NetManager netManager = NetManager.instance; NetSegment[] segmentBuffer = netManager.m_segments.m_buffer; NetNode[] nodeBuffer = netManager.m_nodes.m_buffer; float minSqDistance = nodeBuffer[node].Info.GetMinNodeDistance() / 2f; minSqDistance *= minSqDistance; autoCurve = false; newMoveDelta = moveDelta; float distanceSq = minSqDistance; bool snap = false; // Snap to curve for (int i = 0; i < 8; i++) { ushort segmentA = nodeBuffer[node].GetSegment(i); if (segmentA != 0) { for (int j = i + 1; j < 8; j++) { ushort segmentB = nodeBuffer[node].GetSegment(j); if (segmentB != 0 && segmentB != segmentA) { NetSegment segment = default; segment.m_startNode = segmentBuffer[segmentA].m_startNode == node ? segmentBuffer[segmentA].m_endNode : segmentBuffer[segmentA].m_startNode; segment.m_endNode = segmentBuffer[segmentB].m_startNode == node ? segmentBuffer[segmentB].m_endNode : segmentBuffer[segmentB].m_startNode; segment.m_startDirection = (nodeBuffer[segment.m_endNode].m_position - nodeBuffer[segment.m_startNode].m_position).normalized; segment.m_endDirection = -segment.m_startDirection; segment.GetClosestPositionAndDirection(newPosition, out Vector3 testPos, out Vector3 direction); // Straight if (TrySnapping(testPos, newPosition, minSqDistance, ref distanceSq, moveDelta, ref newMoveDelta)) { autoCurve = true; m_segmentGuide = segment; snapType = "Straight"; snap = true; } for (int k = 0; k < 8; k++) { ushort segmentC = nodeBuffer[segment.m_startNode].GetSegment(k); if (segmentC != 0 && segmentC != segmentA) { for (int l = 0; l < 8; l++) { ushort segmentD = nodeBuffer[segment.m_endNode].GetSegment(l); if (segmentD != 0 && segmentD != segmentB) { segment.m_startDirection = segmentBuffer[segmentC].m_startNode == segment.m_startNode ? -segmentBuffer[segmentC].m_startDirection : -segmentBuffer[segmentC].m_endDirection; segment.m_endDirection = segmentBuffer[segmentD].m_startNode == segment.m_endNode ? -segmentBuffer[segmentD].m_startDirection : -segmentBuffer[segmentD].m_endDirection; Vector2 A = VectorUtils.XZ(nodeBuffer[segment.m_endNode].m_position - nodeBuffer[segment.m_startNode].m_position).normalized; Vector2 B = VectorUtils.XZ(segment.m_startDirection); float side1 = A.x * B.y - A.y * B.x; B = VectorUtils.XZ(segment.m_endDirection); float side2 = A.x * B.y - A.y * B.x; if (Mathf.Sign(side1) != Mathf.Sign(side2) || (side1 != side2 && (side1 == 0 || side2 == 0)) || Vector2.Dot(A, VectorUtils.XZ(segment.m_startDirection)) < 0 || Vector2.Dot(A, VectorUtils.XZ(segment.m_endDirection)) > 0) { continue; } Bezier3 bezier = default; bezier.a = Singleton <NetManager> .instance.m_nodes.m_buffer[segment.m_startNode].m_position; bezier.d = Singleton <NetManager> .instance.m_nodes.m_buffer[segment.m_endNode].m_position; bool smoothStart = (Singleton <NetManager> .instance.m_nodes.m_buffer[segment.m_startNode].m_flags & NetNode.Flags.Middle) != NetNode.Flags.None; bool smoothEnd = (Singleton <NetManager> .instance.m_nodes.m_buffer[segment.m_endNode].m_flags & NetNode.Flags.Middle) != NetNode.Flags.None; NetSegment.CalculateMiddlePoints(bezier.a, segment.m_startDirection, bezier.d, segment.m_endDirection, smoothStart, smoothEnd, out bezier.b, out bezier.c); testPos = bezier.Position(0.5f); // Curve Middle if (TrySnapping(testPos, newPosition, minSqDistance, ref distanceSq, moveDelta, ref newMoveDelta)) { autoCurve = true; m_segmentGuide = segment; snapType = "Curve Middle"; snap = true; } else { segment.GetClosestPositionAndDirection(newPosition, out testPos, out direction); // Curve if (TrySnapping(testPos, newPosition, minSqDistance, ref distanceSq, moveDelta, ref newMoveDelta)) { autoCurve = true; m_segmentGuide = segment; snapType = "Curve"; snap = true; } } } } } } } } } } // Snap to tangent for (int i = 0; i < 8; i++) { ushort segment = nodeBuffer[node].GetSegment(i); if (segment != 0) { ushort testNode = segmentBuffer[segment].m_startNode == node ? segmentBuffer[segment].m_endNode : segmentBuffer[segment].m_startNode; Vector3 testPos = nodeBuffer[testNode].m_position; for (int j = 0; j < 8; j++) { ushort segmentA = nodeBuffer[testNode].GetSegment(j); if (segmentA != 0 && segmentA != segment) { // Straight Vector3 startDir = segmentBuffer[segmentA].m_startNode == testNode ? segmentBuffer[segmentA].m_startDirection : segmentBuffer[segmentA].m_endDirection; Vector3 offset = Line2.Offset(startDir, testPos - newPosition); offset = newPosition + offset - testPos; float num = offset.x * startDir.x + offset.z * startDir.z; if (TrySnapping(testPos + startDir * num, newPosition, minSqDistance, ref distanceSq, moveDelta, ref newMoveDelta)) { m_segmentGuide = default; m_segmentGuide.m_startNode = node; m_segmentGuide.m_endNode = testNode; m_segmentGuide.m_startDirection = startDir; m_segmentGuide.m_endDirection = -startDir; snapType = "Tangent Straight"; autoCurve = false; snap = true; } else { // 90° startDir = new Vector3(-startDir.z, startDir.y, startDir.x); offset = Line2.Offset(startDir, testPos - newPosition); offset = newPosition + offset - testPos; num = offset.x * startDir.x + offset.z * startDir.z; if (TrySnapping(testPos + startDir * num, newPosition, minSqDistance, ref distanceSq, moveDelta, ref newMoveDelta)) { m_segmentGuide = default; m_segmentGuide.m_startNode = node; m_segmentGuide.m_endNode = testNode; m_segmentGuide.m_startDirection = startDir; m_segmentGuide.m_endDirection = -startDir; snapType = "Tangent 90°"; autoCurve = false; snap = true; } } } } } } if (snap) { DebugUtils.Log("Snapping " + snapType + " " + autoCurve); } return(snap); }
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 void OnSettingsUI(UIHelperBase helper) { try { UIHelperBase group = helper.AddGroup(Name); UIPanel panel = ((UIPanel)((UIHelper)group).self) as UIPanel; UICheckBox checkBox = (UICheckBox)group.AddCheckbox("Auto-close Toolbox menu", MoveItTool.autoCloseAlignTools.value, (b) => { MoveItTool.autoCloseAlignTools.value = b; if (UIMoreTools.MoreToolsPanel != null) { UIMoreTools.CloseMenu(); } }); checkBox.tooltip = "Check this to close the Toolbox menu after choosing a tool."; group.AddSpace(10); checkBox = (UICheckBox)group.AddCheckbox("Prefer fast, low-detail moving (hold Shift to temporarily switch)", MoveItTool.fastMove.value, (b) => { MoveItTool.fastMove.value = b; }); checkBox.tooltip = "Helps you position objects when your frame-rate is poor."; group.AddSpace(10); checkBox = (UICheckBox)group.AddCheckbox("Hide selectors/overlays when in low-sensitivity mode", MoveItTool.hideSelectorsOnLowSensitivity.value, (b) => { MoveItTool.hideSelectorsOnLowSensitivity.value = b; }); checkBox.tooltip = "When holding control, the selection overlays are hidden"; group.AddSpace(10); checkBox = (UICheckBox)group.AddCheckbox("Select pylons and pillars by holding Alt only", MoveItTool.altSelectNodeBuildings.value, (b) => { MoveItTool.altSelectNodeBuildings.value = b; }); group.AddSpace(10); checkBox = (UICheckBox)group.AddCheckbox("Use cardinal movements", MoveItTool.useCardinalMoves.value, (b) => { MoveItTool.useCardinalMoves.value = b; }); checkBox.tooltip = "If checked, Up will move in the North direction, Down is South, Left is West, Right is East."; group.AddSpace(10); checkBox = (UICheckBox)group.AddCheckbox("Right click cancels cloning", MoveItTool.rmbCancelsCloning.value, (b) => { MoveItTool.rmbCancelsCloning.value = b; }); checkBox.tooltip = "If checked, Right click will cancel cloning instead of rotating 45°."; group.AddSpace(10); group = helper.AddGroup("General Shortcuts"); panel = ((UIPanel)((UIHelper)group).self) as UIPanel; group.AddSpace(10); ((UIPanel)((UIHelper)group).self).gameObject.AddComponent <OptionsKeymappingMain>(); group.AddSpace(10); group = helper.AddGroup("Toolbox Shortcuts"); panel = ((UIPanel)((UIHelper)group).self) as UIPanel; group.AddSpace(10); ((UIPanel)((UIHelper)group).self).gameObject.AddComponent <OptionsKeymappingToolbox>(); group.AddSpace(10); group = helper.AddGroup("Extra Options"); panel = ((UIPanel)((UIHelper)group).self) as UIPanel; group.AddSpace(10); UIButton button = (UIButton)group.AddButton("Remove Ghost Nodes", MoveItTool.CleanGhostNodes); button.tooltip = "Use this button when in-game to remove ghost nodes (nodes with no segments attached). Note: this will clear Move It's undo history!"; group.AddSpace(20); checkBox = (UICheckBox)group.AddCheckbox("Disable debug messages logging", DebugUtils.hideDebugMessages.value, (b) => { DebugUtils.hideDebugMessages.value = b; }); checkBox.tooltip = "If checked, debug messages won't be logged."; checkBox = (UICheckBox)group.AddCheckbox("Show Move It debug panel\n", MoveItTool.showDebugPanel.value, (b) => { MoveItTool.showDebugPanel.value = b; if (MoveItTool.m_debugPanel != null) { MoveItTool.m_debugPanel.Visible(b); } }); checkBox.name = "MoveIt_DebugPanel"; UILabel debugLabel = panel.AddUIComponent <UILabel>(); debugLabel.name = "debugLabel"; debugLabel.text = " Shows information about the last highlighted object. Slightly decreases\n" + " performance, do not enable unless you have a specific reason.\n "; group.AddSpace(5); UILabel nsLabel = panel.AddUIComponent <UILabel>(); nsLabel.name = "nsLabel"; nsLabel.text = NS_Manager.getVersionText(); UILabel ncLabel = panel.AddUIComponent <UILabel>(); ncLabel.name = "ncLabel"; ncLabel.text = NodeController_Manager.getVersionText(); UILabel tmpeLabel = panel.AddUIComponent <UILabel>(); tmpeLabel.name = "tmpeLabel"; tmpeLabel.text = TMPE_Manager.getVersionText(); group = helper.AddGroup("Procedural Objects"); panel = ((UIPanel)((UIHelper)group).self) as UIPanel; UILabel poLabel = panel.AddUIComponent <UILabel>(); poLabel.name = "poLabel"; poLabel.text = PO_Manager.getVersionText(); UILabel poWarning = panel.AddUIComponent <UILabel>(); poWarning.name = "poWarning"; poWarning.text = " Please note: you can not undo Bulldozed PO. This means if you delete \n" + " PO objects with Move It, they are immediately PERMANENTLY gone.\n "; checkBox = (UICheckBox)group.AddCheckbox("Hide the PO deletion warning", !MoveItTool.POShowDeleteWarning.value, (b) => { MoveItTool.POShowDeleteWarning.value = !b; }); checkBox = (UICheckBox)group.AddCheckbox("Highlight unselected visible PO objects", MoveItTool.POHighlightUnselected.value, (b) => { MoveItTool.POHighlightUnselected.value = b; if (MoveItTool.PO != null) { try { MoveItTool.PO.ToolEnabled(); } catch (ArgumentException e) { Debug.Log($"PO Integration failed:\n{e}"); } } }); checkBox.tooltip = "Show a faded purple circle around PO objects that aren't selected."; group.AddSpace(15); panel.gameObject.AddComponent <OptionsKeymappingPO>(); group.AddSpace(15); } catch (Exception e) { DebugUtils.Log("OnSettingsUI failed"); DebugUtils.LogException(e); } }
public bool Export(string filename) { string path = Path.Combine(saveFolder, filename + ".xml"); try { HashSet <Instance> selection = CloneActionBase.GetCleanSelection(out Vector3 center); if (selection.Count == 0) { return(false); } bool includesPO = false; //foreach (Instance ins in selection) //{ // if (ins is MoveableProc) // { // includesPO = true; // break; // } //} Selection selectionState = new Selection { version = ModInfo.version, center = center, includesPO = includesPO, states = new InstanceState[selection.Count] }; int i = 0; foreach (Instance instance in selection) { selectionState.states[i++] = instance.SaveToState(); } Directory.CreateDirectory(saveFolder); //Log.Debug($"selectionState:{selectionState.states.Length}\n" + ObjectDumper.Dump(selectionState)); using (FileStream stream = new FileStream(path, FileMode.OpenOrCreate)) { stream.SetLength(0); // Emptying the file XmlSerializer xmlSerializer = new XmlSerializer(typeof(Selection)); XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("", ""); xmlSerializer.Serialize(stream, selectionState, ns); } } catch (Exception e) { DebugUtils.Log("Couldn't export selection"); DebugUtils.LogException(e); UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel").SetMessage("Export failed", "The selection couldn't be exported to '" + path + "'\n\n" + e.Message, true); return(false); } return(true); }