public SpriteManToolsWindow() { saveSpriteNames = new SaveSpriteSheetNames(); replaceSpriteNames = new ReplaceSpriteSheetNames(); saveManagerState = new SaveSpriteManState(); convertSheetToState = new ConvertSheetToState(); loadManagerState = new LoadSpriteManState(); }
public ToolModel([NotNull] IEditorTool tool) { if (tool == null) { throw new ArgumentNullException("tool"); } Tool = tool; }
/// <summary> /// Raises the <see cref="DrawingToolSelected"/> event. /// </summary> /// <param name="oldTool">A reference to the previously selected tool.</param> /// <param name="tool">A reference to the currently selected tool.</param> /// <param name="map">A reference to the <see cref="GridMap"/> associated with the tool change.</param> public void OnDrawingToolSelected(IEditorTool <GridMapEditor> oldTool, IEditorTool <GridMapEditor> tool, GridMap map) { if (this.DrawingToolSelected != null) { this.DrawingToolSelected(this, new ToolChangedArgs <GridMapEditor> { OldTool = oldTool, Tool = tool, Map = map }); } }
/// <summary> /// Raises the <see cref="EditorDrawingToolSelected"/> event. /// </summary> /// <param name="oldTool">A reference to the previously selected tool.</param> /// <param name="tool">A reference to the currently selected tool.</param> public void OnEditorDrawingToolSelected(IEditorTool <IMapEditor> oldTool, IEditorTool <IMapEditor> tool) { var handler = this.EditorDrawingToolSelected; if (handler != null) { handler(this, new ToolChangedArgs <IMapEditor> { OldTool = oldTool, Tool = tool }); } }
/// <summary> /// Sets teh second point /// </summary> /// <param name="p1"></param> /// <param name="secondaryTool"></param> public void VSetP2(Coordinates p2, IEditorTool secondaryTool) { this.p2 = p2; this.SetP2 = true; if (secondaryTool != null && secondaryTool is PointAnalysisTool) { PointAnalysisTool pat = (PointAnalysisTool)secondaryTool; pat.Save.Add(p2); } }
/// <summary> /// Raises the <see cref="LayerToolSelected"/> event. /// </summary> /// <param name="oldTool">A reference to the previously selected tool.</param> /// <param name="tool">A reference to the currently selected tool.</param> public void OnLayerToolSelected(IEditorTool <ILayerEditor> oldTool, IEditorTool <ILayerEditor> tool) { var handler = this.LayerToolSelected; if (handler != null) { handler(this, new ToolChangedArgs <ILayerEditor> { OldTool = oldTool, Tool = tool }); } }
/// <summary> /// Sets teh first point /// </summary> /// <param name="p1"></param> /// <param name="secondaryTool"></param> public void VSetP1(Coordinates p1, IEditorTool secondaryTool) { this.SetP1 = true; this.p1 = p1; if (secondaryTool != null && secondaryTool is PointAnalysisTool) { PointAnalysisTool pat = (PointAnalysisTool)secondaryTool; pat.Save = new List <Coordinates>(); pat.Save.Add(p1); } }
public void SetCurrentTool([NotNull] IEditorTool tool) { if (tool == null) { throw new ArgumentNullException("tool"); } var current = _activeTool; if (current != null) { current.Selected = false; } _activeTool = tool; tool.Selected = true; }
/// <summary> /// Resets values /// </summary> /// <param name="secondaryTool"></param> public void Reset(IEditorTool secondaryTool) { this.p1 = null; this.p2 = null; this.p3 = null; this.SetP1 = false; this.SetP2 = false; this.SetP3 = false; if (secondaryTool != null && secondaryTool is PointAnalysisTool) { PointAnalysisTool pat = (PointAnalysisTool)secondaryTool; pat.Save = new List <Coordinates>(); } }
/// <summary> /// Registers a tool with the <see cref="Map2DService"/> service. /// </summary> /// <param name="tool">A reference to a tool that implements the <see cref="IEditorTool{T}"/> interface.</param> public void Register(IEditorTool <IMapEditor> tool) { // if tool is null throw exception if (tool == null) { throw new ArgumentNullException("tool"); } // throw exception if tool already added if (this.HasTool(tool.Uid)) { throw new ArgumentException(LocalizationManager.Instance.Get("ERR_ToolWithSameUidAlreadyRegistered")); } // add the tool this.tools.Add(tool); }
public void OnEnable() { settings = new SettingsLoader(); settings.Load(); var settingsPanel = new SettingsEditorTool(() => settings.Value as ArtWindowSettings); request = new RequestTool(); request.onChange += Repaint; request.onReset += Repaint; target = new Target(); target.onChange += ShowAllTools; target.onReset += HideAllTools; history = new History(() => target.Value, settings.Value); target.onChange += () => history.Add(target.Value); history.onSelect += x => target.Value = x as Sample; var layers = new Layers(() => target.Value); leftPanel = new ToolBox() { layers, request as IEditorTool }; rightPanel = new ToolBox() { settingsPanel, history as IEditorTool, }; centerPanel = new ToolBox() { new Preview(() => target.Value, layers, settings.Value, () => request.ActiveRequest?.texture), }; history.LoadSavedData(); }
protected virtual void AddToolBar(string barName, IEditorTool tool) { if (ToolbarTitleList == null) { ToolbarTitleList = new List <string>(); } if (!ToolbarTitleList.Contains(barName)) { ToolbarTitleList.Add(barName); } ToolbarTitles = ToolbarTitleList.ToArray(); int key = ToolbarTitleList.Count - 1; if (!BarToolsDic.ContainsKey(key)) { BarToolsDic.Add(key, new List <IEditorTool>()); } BarToolsDic[key].Add(tool); testList.Add(tool); }
/// <summary> /// When the <see cref="GameObject"/> is unselected this method will clean up resources. /// </summary> public void OnDisable() { if (this.currentTool != null) { this.currentTool.Shutdown(); GridMappingService.Instance.OnDrawingToolSelected(this.currentTool, null, this.target as GridMap); this.currentTool = null; } GridMappingService.Instance.CurrentMaterialChanged -= this.GridMappingServiceCurrentMaterialChanged; // unload resource images from the rotationContentForXAxis field. foreach (var content in this.rotationContentForXAxis) { try { Resources.UnloadAsset(content.image); } catch { } } // unload resource images from the rotationContentForYAxis field. foreach (var content in this.rotationContentForYAxis) { try { Resources.UnloadAsset(content.image); } catch { } } // unload resource images from the rotationContentForZAxis field. foreach (var content in this.rotationContentForZAxis) { try { Resources.UnloadAsset(content.image); } catch { } } // clear the loaded prefabs list if (this.loadedPrefabs != null) { foreach (var prefab in this.loadedPrefabs) { // remove reference to prefab prefab.Value.Clear(); } this.loadedPrefabs.Clear(); } this.loadedPrefabs = null; this.hasBeenEnabled = false; }
/// <summary> /// Handles the <see cref="Map2DService.ToolsChanged"/> event. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">An System.EventArgs that contains no event data.</param> private void UpdateToolList(object sender, EventArgs e) { // rebuild the tool list var settings = SettingsManager.Instance; // get added tools from settings var drawToolSetting = settings.GetSetting(GlobalConstants.Map2DDrawingToolListKey, string.Empty); var addedTools = drawToolSetting.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); // attempt to create each tool string errors = null; var list = new List <IEditorTool <IMapEditor> >(); foreach (var tool in addedTools) { try { // get the type var type = Type.GetType(tool, true); if (type == null) { continue; } // attempt to create the type var temp = type.Assembly.CreateInstance(tool) as IEditorTool <IMapEditor>; if (temp != null) { list.Add(temp); } } catch (Exception ex) { // log the error message errors += string.Format("{0}\r\n", ex.Message); } } // get map and service references var service = Map2DService.Instance; // shut down and remove reference to the current drawing tool if present if (this.currentTool != null) { this.currentTool.Shutdown(); this.currentTool = null; service.OnEditorDrawingToolSelected(null, null); } // get tool manager service & remove all existing tools and register new ones // based of the tools that were just created this.tools.Clear(); foreach (var x in list) { if (!this.HasTool(x.Uid)) { this.Register(x); } } // if there was a drawing tool specified before try to make it the current tool again if (this.drawingToolIndex != Guid.Empty) { var toolReference = this.HasTool(this.drawingToolIndex) ? this.GetTool(this.drawingToolIndex) : null; if (toolReference != null) { this.currentTool = toolReference; this.currentTool.Startup(this); service.OnEditorDrawingToolSelected(null, this.currentTool); } } // remember to update the window for immediate results this.Repaint(); // report any errors as warning in the console if (errors != null) { Debug.LogWarning(string.Format(LocalizationManager.Instance.Get("ERR_ErrorsOccurredUpdatingToolList"), errors)); } }
/// <summary> /// Handles the <see cref="GridMappingService.DrawingToolChanged"/> event. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">An System.EventArgs that contains no event data.</param> private void UpdateDrawingToolList(object sender, EventArgs e) { // rebuild the tool list var settings = SettingsManager.Instance; // setup default tool list values var defaultTools = new[] { typeof(Pencil).FullName, typeof(PrefabInformation).FullName, typeof(PrefabPicker).FullName, typeof(Rectangle).FullName }; // get added tools from settings var drawToolSetting = settings.GetSetting(GlobalConstants.DrawingToolListKey, string.Join(",", defaultTools)); var strings = drawToolSetting.Split( new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); var addedTools = strings.Select(item => item.Trim()).ToList(); // attempt to create each tool string errors = null; var list = new List<IEditorTool<GridMapEditor>>(); foreach (var tool in addedTools) { try { // get the type var type = Type.GetType(tool, true); if (type == null) { continue; } // attempt to create the type var temp = type.Assembly.CreateInstance(tool) as IEditorTool<GridMapEditor>; if (temp != null) { list.Add(temp); } } catch (Exception ex) { // log the error message errors += string.Format("{0}\r\n", ex.Message); } } // get map and service references var map = this.target as GridMap; var gridMappingService = GridMappingService.Instance; // shut down and remove reference to the current drawing tool if present if (this.currentTool != null) { this.currentTool.Shutdown(); this.currentTool = null; gridMappingService.OnDrawingToolSelected(null, null, map); } // get tool manager service & remove all existing tools and register new ones // based of the tools that were just created var manager = DrawingToolManager.Instance; manager.Clear(); list.ForEach(x => { if (!manager.HasTool(x.Uid)) { manager.Register(x); } }); // if there was a drawing tool specified before try to make it the current tool again if (this.drawingToolIndex != Guid.Empty) { var toolReference = manager.HasTool(this.drawingToolIndex) ? manager.GetTool(this.drawingToolIndex) : null; if (toolReference != null) { this.currentTool = toolReference; this.currentTool.Startup(this); gridMappingService.OnDrawingToolSelected(null, this.currentTool, map); } } // remember to update the inspector for immediate results Helpers.RedrawInspector(); // report any errors as warning in the console if (errors != null) { Debug.LogWarning(string.Format("Errors occurred while updating the tool list\r\n{0}", errors)); } }
/// <summary> /// When mouse clicked /// </summary> /// <param name="e"></param> protected override void OnMouseClick(MouseEventArgs e) { #region Left if (e.Button == MouseButtons.Left) { if (this.CurrentEditorTool is RulerTool) { RulerTool ruler = (RulerTool)this.CurrentEditorTool; if (ruler.Initial == null) { ruler.Initial = transform.GetWorldPoint(new PointF(e.X, e.Y)); if (this.SecondaryEditorTool != null && this.SecondaryEditorTool is PointAnalysisTool) { PointAnalysisTool pat = ((PointAnalysisTool)this.SecondaryEditorTool); pat.Save = new List<Coordinates>(); pat.Save.Add(ruler.Initial.Value); } } else if (ruler.Current != null) { ruler.Initial = null; ruler.Current = null; if (this.SecondaryEditorTool != null && this.SecondaryEditorTool is PointAnalysisTool) { PointAnalysisTool pat = ((PointAnalysisTool)this.SecondaryEditorTool); pat.Save = null; } } } else if (this.CurrentEditorTool is SparseTool) { ((SparseTool)this.CurrentEditorTool).Click(transform.GetWorldPoint(new PointF(e.X, e.Y))); } else if (this.CurrentEditorTool is AngleMeasureTool) { AngleMeasureTool amt = (AngleMeasureTool)this.CurrentEditorTool; if (amt.SetP1 == false) { amt.VSetP1(transform.GetWorldPoint(new PointF(e.X, e.Y)), this.SecondaryEditorTool); } else if (amt.SetP2 == false) { amt.VSetP2(transform.GetWorldPoint(new PointF(e.X, e.Y)), this.SecondaryEditorTool); } else if (amt.SetP3 == false) { amt.VSetP3(this.SecondaryEditorTool); } } else if (this.CurrentEditorTool is WaypointAdjustmentTool) { if (((WaypointAdjustmentTool)this.CurrentEditorTool).CheckInMove) { this.CurrentEditorTool = new WaypointAdjustmentTool(this.transform); } else { // create display object filter for waypoints DisplayObjectFilter dof = delegate(IDisplayObject target) { // check if target is network object if (target is IGenericWaypoint && target is IDisplayObject) return true; else return false; }; // perform hit test HitTestResult htr = this.HitTest(transform.GetWorldPoint(new PointF(e.X, e.Y)), dof); // check for validity if (htr.Hit) { // set adjust ((WaypointAdjustmentTool)this.CurrentEditorTool).SetWaypoint(htr.DisplayObject, ((IGenericWaypoint)htr.DisplayObject).Position); } } } else if (this.CurrentEditorTool is IntersectionPulloutTool) { IntersectionPulloutTool tool = (IntersectionPulloutTool)this.CurrentEditorTool; // get key current KeyStateInfo shiftKey = KeyboardInfo.GetKeyState(Keys.ShiftKey); if (!shiftKey.IsPressed) { if (tool.Mode == InterToolboxMode.SafetyZone) { // create display object filter for waypoints DisplayObjectFilter dof = delegate(IDisplayObject target) { // check if target is network object if (target is ArbiterLane) return true; else return false; }; // perform hit test HitTestResult htr = this.HitTest(transform.GetWorldPoint(new PointF(e.X, e.Y)), dof); // check for validity if (htr.Hit) { // set undo tool.ed.SaveUndoPoint(); // get lane ArbiterLane al = (ArbiterLane)htr.DisplayObject; // get point on lane LinePath.PointOnPath end = al.GetClosestPoint(transform.GetWorldPoint(new PointF(e.X, e.Y))); ArbiterWaypoint aw = al.GetClosestWaypoint(al.LanePath().GetPoint(end), 5); if (aw != null && aw.IsExit == true) { end = al.GetClosestPoint(aw.Position); } double dist = -30; LinePath.PointOnPath begin = al.LanePath().AdvancePoint(end, ref dist); if (dist != 0) { EditorOutput.WriteLine("safety zone too close to start of lane, setting start to start of lane"); begin = al.LanePath().StartPoint; } ArbiterSafetyZone asz = new ArbiterSafetyZone(al, end, begin); al.SafetyZones.Add(asz); al.Way.Segment.RoadNetwork.DisplayObjects.Add(asz); al.Way.Segment.RoadNetwork.ArbiterSafetyZones.Add(asz); if (aw != null && aw.IsExit == true) { asz.isExit = true; asz.Exit = aw; } // add to display this.displayObjects.Add(asz); } } else if (tool.Mode == InterToolboxMode.Helpers) { // create display object filter for waypoints DisplayObjectFilter dof = delegate(IDisplayObject target) { // check if target is network object if (target is ArbiterLane) return true; else return false; }; // perform hit test HitTestResult htr = this.HitTest(transform.GetWorldPoint(new PointF(e.X, e.Y)), dof); // check for validity if (htr.Hit) { // get lane ArbiterLane al = (ArbiterLane)htr.DisplayObject; // get point on lane tool.WrappingHelpers.Add(al.GetClosest(transform.GetWorldPoint(new PointF(e.X, e.Y)))); } } else if (tool.Mode == InterToolboxMode.Box) { // clicked point Coordinates c = transform.GetWorldPoint(new PointF(e.X, e.Y)); // add points if (tool.WrapInitial == null) { tool.WrapInitial = c; } else if (tool.WrapFinal != null && !tool.WrapInitial.Equals(c)) { tool.FinalizeIntersection(); } } } } else if (this.CurrentEditorTool is ZoneTool) { // get key current KeyStateInfo shiftKey = KeyboardInfo.GetKeyState(Keys.ShiftKey); ZoneTool zt = (ZoneTool)this.CurrentEditorTool; if (zt.moveNode != null) { zt.moveNode = null; zt.Reset(false); } else { if (!shiftKey.IsPressed) { // get key current KeyStateInfo wKey = KeyboardInfo.GetKeyState(Keys.W); if (!wKey.IsPressed) { // clicked point Coordinates c = transform.GetWorldPoint(new PointF(e.X, e.Y)); zt.Click(c); } else { // clicked point Coordinates c = transform.GetWorldPoint(new PointF(e.X, e.Y)); if (zt.zt.current != null && zt.zt.current.Perimeter.PerimeterPolygon.IsInside(c)) { zt.ed.SaveUndoPoint(); zt.BeginMove(c); } } } } } this.Invalidate(); } #endregion #region Right else if (e.Button == MouseButtons.Right) { if (this.CurrentEditorTool is ZoneTool) { // clicked point Coordinates c = transform.GetWorldPoint(new PointF(e.X, e.Y)); ZoneTool zt = (ZoneTool)this.CurrentEditorTool; if (zt.zt.current != null && zt.zt.current.Perimeter.PerimeterPolygon.IsInside(c)) { zt.RightClick(c); this.Invalidate(); if (zt.rightClickNode != null || zt.rightClickEdge != null) { this.removeToolStripMenuItem.Enabled = true; this.zoneContextMenuStrip.Show(this, e.X, e.Y); } else { this.removeToolStripMenuItem.Enabled = false; this.zoneContextMenuStrip.Show(this, e.X, e.Y); } } } else if (this.CurrentEditorTool != null && this.CurrentEditorTool is PartitionTools) { PartitionTools pt = (PartitionTools)this.CurrentEditorTool; if (!pt.RemoveUserWaypointMode) { // create display object filter for waypoints DisplayObjectFilter dof = delegate(IDisplayObject target) { // check if target is network object if (target is ArbiterLanePartition) return true; else return false; }; HitTestResult htr = this.HitTest(transform.GetWorldPoint(new PointF(e.X, e.Y)), dof); if (htr.DisplayObject != null && htr.DisplayObject is ArbiterLanePartition && htr.Hit) { this.selected = htr.DisplayObject; this.selected.Selected = SelectionType.SingleSelected; this.partitionContextMenuStrip.Show(this, e.X, e.Y); pt.HitPoint = transform.GetWorldPoint(new PointF(e.X, e.Y)); } else if (this.selected != null) { this.selected.Selected = SelectionType.NotSelected; } } else { // create display object filter for waypoints DisplayObjectFilter dof = delegate(IDisplayObject target) { // check if target is network object if (target is ArbiterUserWaypoint) return true; else return false; }; HitTestResult htr = this.HitTest(transform.GetWorldPoint(new PointF(e.X, e.Y)), dof); if (htr.DisplayObject != null && htr.DisplayObject is ArbiterUserWaypoint && htr.Hit) { this.selected = htr.DisplayObject; this.selected.Selected = SelectionType.SingleSelected; this.userWaypointContextMenuStrip.Show(this, e.X, e.Y); } else if (this.selected != null) { this.selected.Selected = SelectionType.NotSelected; } } this.Invalidate(); } else { // perform hit test HitTestResult htr = this.HitTest(transform.GetWorldPoint(new PointF(e.X, e.Y)), DrawingUtility.DefaultFilter); if (htr.DisplayObject == null) { } else if (htr.DisplayObject is ArbiterIntersection) { this.intersectionContextMenuStrip.Show(this, e.X, e.Y); this.selected = htr.DisplayObject; } else if (this.CurrentEditorTool is IntersectionPulloutTool && ((IntersectionPulloutTool)this.CurrentEditorTool).Mode == InterToolboxMode.SafetyZone) { // create display object filter for waypoints DisplayObjectFilter dof = delegate(IDisplayObject target) { // check if target is network object if (target is ArbiterSafetyZone) return true; else return false; }; htr = this.HitTest(transform.GetWorldPoint(new PointF(e.X, e.Y)), dof); if (htr.DisplayObject is ArbiterSafetyZone) { this.safetyZoneContextMenu.Show(this, e.X, e.Y); this.selected = htr.DisplayObject; } } } } #endregion }
/// <summary> /// Draws the editor tool bar. /// </summary> private void DrawToolBar() { GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); var values = new IEditorTool <IMapEditor> [this.tools.Count]; var i = 0; foreach (var editorTool in this.tools) { values[i++] = editorTool; } var settings = SettingsManager.Instance; var size = settings.GetSetting(GlobalConstants.Map2DDrawingModeButtonSizeKey, 64.0f); var buttonsPerRow = settings.GetSetting(GlobalConstants.Map2DDrawModeButtonsPerRowKey, 20); ControlGrid.DrawGenericGrid( (toolArray, index, style, options) => { var tool = toolArray[index]; if (tool.DrawTool()) { return(tool); } var result = GUILayout.Toggle(this.drawingToolIndex == tool.Uid, tool.ButtonContent, style, options); // detect a tool change if (result && this.drawingToolIndex != tool.Uid) { // if there is a current tool shut it down if (this.currentTool != null) { this.currentTool.Shutdown(); } // store reference to the old tool var oldTool = this.currentTool; // save index to tool this.drawingToolIndex = tool.Uid; // set current tool this.currentTool = tool; this.currentTool.Startup(this); // save tool UID as the last tool used settings.SetValue(GlobalConstants.Map2DLastEditorDrawingToolUidKey, this.currentTool.Uid.ToString()); // notify service so code hooks can receive notifications Map2DService.Instance.OnEditorDrawingToolSelected(oldTool, tool); } // return same tool reference return(tool); }, values, buttonsPerRow, GUI.skin.button, GUILayout.Height(size), GUILayout.Width(size)); GUILayout.EndHorizontal(); }
/// <summary> /// Draws the layer toolbar. /// </summary> private void DrawToolBar() { GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); var values = new IEditorTool<ILayerEditor>[this.tools.Count]; var i = 0; foreach (var editorTool in this.tools) { values[i++] = editorTool; } var settings = SettingsManager.Instance; var size = settings.GetSetting(GlobalConstants.Map2DLayerButtonSizeKey, 64.0f); var buttonsPerRow = settings.GetSetting(GlobalConstants.Map2DDrawModeButtonsPerRowKey, 20); ControlGrid.DrawGenericGrid( (toolArray, index, style, options) => { var tool = toolArray[index]; if (tool.DrawTool()) { return tool; } var result = GUILayout.Toggle(this.drawingToolIndex == tool.Uid, tool.ButtonContent, style, options); // detect a tool change if (result && this.drawingToolIndex != tool.Uid) { // if there is a current tool shut it down if (this.currentTool != null) { this.currentTool.Shutdown(); } // store reference to the old tool var oldTool = this.currentTool; // save index to tool this.drawingToolIndex = tool.Uid; // set current tool this.currentTool = tool; this.currentTool.Startup(this); // save tool UID as the last tool used settings.SetValue(GlobalConstants.Map2DLastLayerDrawingToolUidKey, this.currentTool.Uid.ToString()); // notify service so code hooks can receive notifications Map2DService.Instance.OnLayerToolSelected(oldTool, tool); } // return same tool reference return tool; }, values, buttonsPerRow, GUI.skin.button, GUILayout.Height(size), GUILayout.Width(size)); GUILayout.EndHorizontal(); }
/// <summary> /// Registers a tool with the <see cref="DrawingToolManager"/>. /// </summary> /// <param name="tool">A reference to a tool that implements the <see cref="IEditorTool{T}"/> interface.</param> public void Register(IEditorTool<GridMapEditor> tool) { // if tool is null throw exception if (tool == null) { throw new ArgumentNullException("tool"); } // throw exception if tool already added if (this.tools.Any(x => x.Uid == tool.Uid)) { throw new ArgumentException(LocalizationManager.Instance.Get("ERR_ToolWithSameUidAlreadyRegistered")); } // add the tool this.tools.Add(tool); }
/// <summary> /// Raises the <see cref="EditorDrawingToolSelected"/> event. /// </summary> /// <param name="oldTool">A reference to the previously selected tool.</param> /// <param name="tool">A reference to the currently selected tool.</param> public void OnEditorDrawingToolSelected(IEditorTool<IMapEditor> oldTool, IEditorTool<IMapEditor> tool) { var handler = this.EditorDrawingToolSelected; if (handler != null) { handler(this, new ToolChangedArgs<IMapEditor> { OldTool = oldTool, Tool = tool }); } }
/// <summary> /// Handles the <see cref="Map2DService.ToolsChanged"/> event. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">An System.EventArgs that contains no event data.</param> private void UpdateToolList(object sender, EventArgs e) { // rebuild the tool list var settings = SettingsManager.Instance; // get added tools from settings var drawToolSetting = settings.GetSetting(GlobalConstants.Map2DLayerToolListKey, string.Empty); var addedTools = drawToolSetting.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); // attempt to create each tool string errors = null; var list = new List<IEditorTool<ILayerEditor>>(); foreach (var tool in addedTools) { try { // get the type var type = Type.GetType(tool, true); if (type == null) { continue; } // attempt to create the type var temp = type.Assembly.CreateInstance(tool) as IEditorTool<ILayerEditor>; if (temp != null) { list.Add(temp); } } catch (Exception ex) { // log the error message errors += string.Format("{0}\r\n", ex.Message); } } // get map and service references var service = Map2DService.Instance; // shut down and remove reference to the current drawing tool if present if (this.currentTool != null) { this.currentTool.Shutdown(); this.currentTool = null; service.OnLayerToolSelected(null, null); } // get tool manager service & remove all existing tools and register new ones // based of the tools that were just created this.tools.Clear(); foreach (var x in list) { if (!this.HasTool(x.Uid)) { this.Register(x); } } // if there was a drawing tool specified before try to make it the current tool again if (this.drawingToolIndex != Guid.Empty) { var toolReference = this.HasTool(this.drawingToolIndex) ? this.GetTool(this.drawingToolIndex) : null; if (toolReference != null) { this.currentTool = toolReference; this.currentTool.Startup(this); service.OnLayerToolSelected(null, this.currentTool); } } // remember to update the window for immediate results this.Repaint(); // report any errors as warning in the console if (errors != null) { Debug.LogWarning(string.Format(LocalizationManager.Instance.Get("ERR_ErrorsOccurredUpdatingToolList"), errors)); } }
/// <summary> /// Sets teh third point /// </summary> /// <param name="p1"></param> /// <param name="secondaryTool"></param> public void VSetP3(IEditorTool secondaryTool) { this.Reset(secondaryTool); }
private void ShowSection(IEditorTool tool) { tool.ShowGUI(); }
protected virtual void AddTool(IEditorTool tool) { AddToolBar("Default", tool); }
/// <summary> /// When the <see cref="GameObject"/> is selected set the current tool to the view tool. /// </summary> public void OnEnable() { EditorCallbackService.Instance.Register(() => { if (this.target == null) { return; } Tools.current = Tool.View; Tools.viewTool = ViewTool.FPS; // get reference to the GridMapping component var map = (GridMap)this.target; this.gameObjects = new GridMapGameObjectTracker(map, true, false); // load prefabs specified in the resources folder this.loadedPrefabs = new Dictionary<string, List<PrefabDataModel>>(); this.LoadPrefabs(); // load rotation texture resources this.LoadContent(); // load settings this.LoadSettings(); GridMappingService.Instance.CurrentMaterialChanged += this.GridMappingServiceCurrentMaterialChanged; GridMappingService.Instance.DrawingToolChanged += this.UpdateDrawingToolList; // register tools from settings this.UpdateDrawingToolList(this, EventArgs.Empty); var settings = SettingsManager.Instance; var lastUid = settings.GetSetting(GlobalConstants.LastDrawingToolUidKey, string.Empty); var restoreLast = settings.GetSetting(GlobalConstants.RestoreLastDrawingToolKey, false); Guid guid; try { guid = !string.IsNullOrEmpty(lastUid) ? new Guid(lastUid) : Pencil.GetUid(); } catch { // something went wrong default to pencil and report the warning guid = Pencil.GetUid(); var local = LocalizationManager.Instance; Debug.LogWarning(local.Get("ERR_FailedToGetLastToolUID")); } // setup current tool if restoreLast is true var manager = DrawingToolManager.Instance; this.drawingToolIndex = restoreLast && manager.HasTool(guid) ? guid : Guid.Empty; // if drawing tool index has a guid attempt to make it the current tool if (this.drawingToolIndex != Guid.Empty) { this.currentTool = manager.GetTool(this.drawingToolIndex); this.currentTool.Startup(this); } // we are now considered to be enabled this.hasBeenEnabled = true; // be sure to raise the DrawingToolSelected GridMappingService.Instance.OnDrawingToolSelected(null, this.currentTool, this.target as GridMap); // remember to refresh the inspector widow Helpers.RedrawInspector(); }); }
/// <summary> /// Raises the <see cref="LayerToolSelected"/> event. /// </summary> /// <param name="oldTool">A reference to the previously selected tool.</param> /// <param name="tool">A reference to the currently selected tool.</param> public void OnLayerToolSelected(IEditorTool<ILayerEditor> oldTool, IEditorTool<ILayerEditor> tool) { var handler = this.LayerToolSelected; if (handler != null) { handler(this, new ToolChangedArgs<ILayerEditor> { OldTool = oldTool, Tool = tool }); } }
/// <summary> /// Draw the drawing mode buttons. /// </summary> private void DrawDrawingToolButtons() { var values = DrawingToolManager.Instance.Tools.ToArray(); var settings = SettingsManager.Instance; var size = settings.GetSetting(GlobalConstants.DrawingModeButtonSizeKey, 64.0f); var buttonsPerRow = settings.GetSetting(GlobalConstants.DrawModeButtonsPerRowKey, 3); Controls.ControlGrid.DrawGenericGrid( (tools, index, style, options) => { var tool = tools[index]; var result = GUILayout.Toggle(this.drawingToolIndex == tool.Uid, tool.ButtonContent, style, options); // detect a tool change if (result && this.drawingToolIndex != tool.Uid) { // if there is a current tool shut it down if (this.currentTool != null) { this.currentTool.Shutdown(); } // store reference to the old tool var oldTool = this.currentTool; // save index to tool this.drawingToolIndex = tool.Uid; // set current tool this.currentTool = tool; this.currentTool.Startup(this); // save tool UID as the last tool used settings.SetValue(GlobalConstants.LastDrawingToolUidKey, this.currentTool.Uid.ToString()); // notify service so code hooks can receive notifications GridMappingService.Instance.OnDrawingToolSelected(oldTool, tool, this.target as GridMap); } // return same tool reference return tool; }, values, buttonsPerRow, GUI.skin.button, GUILayout.Height(size), GUILayout.Width(size)); }
/// <summary> /// Raises the <see cref="DrawingToolSelected"/> event. /// </summary> /// <param name="oldTool">A reference to the previously selected tool.</param> /// <param name="tool">A reference to the currently selected tool.</param> /// <param name="map">A reference to the <see cref="GridMap"/> associated with the tool change.</param> public void OnDrawingToolSelected(IEditorTool<GridMapEditor> oldTool, IEditorTool<GridMapEditor> tool, GridMap map) { if (this.DrawingToolSelected != null) { this.DrawingToolSelected(this, new ToolChangedArgs<GridMapEditor> { OldTool = oldTool, Tool = tool, Map = map }); } }