public bool LoadZone(Zone zone) { var gameObject = new GameObject(1, 1, Settings.Config.ScreenFont); var animation = new AnimatedSurface("default", zone.Area.Width, zone.Area.Height); var frame = animation.CreateFrame(); frame.DefaultBackground = zone.DebugAppearance.Background; gameObject.Name = zone.Title; Settings.QuickEditor.TextSurface = frame; Settings.QuickEditor.Clear(); Settings.QuickEditor.Print(0, 0, zone.Title, Color.DarkGray); gameObject.Animation = animation; gameObject.Position = new Point(zone.Area.Left, zone.Area.Top); var resizable = new ResizableObject <Zone>(ResizableObject.ObjectType.Zone, gameObject, zone); resizable.RenderOffset = MainScreen.Instance.InnerBorderPosition - surface.RenderArea.Location; Zones.Add(resizable); ZonesPanel.RebuildListBox(); return(true); }
void Update() { if (Input.GetMouseButtonDown(0)) { m_LastMousePos = Input.mousePosition; //m_Ray = Camera.main.ScreenPointToRay(Input.mousePosition); // always resize current object m_CurrentObject = this.GetComponent <ResizableObject>(); m_StartScale = m_CurrentObject.transform.localScale; } if (Input.GetMouseButton(0)) { Vector3 deltaPosition = Input.mousePosition - m_LastMousePos; if (deltaPosition.magnitude > 1f) { if (m_CurrentObject && !m_AnimateScale) { m_ScaleFactor = deltaPosition.magnitude; m_AnimateScale = true; m_DeltaTime = 0f; } } m_draggingOut = isDraggingOut(m_CurrentObject.transform.position - m_LastMousePos, deltaPosition); m_LastMousePos = Input.mousePosition; } if (m_AnimateScale && m_DeltaTime < 1f) { m_DeltaTime += Time.deltaTime; if (m_CurrentObject) { if (!m_draggingOut) // invert scale factor when draggin in { m_ScaleFactor = 1 / m_ScaleFactor; } m_CurrentObject.transform.localScale = Vector3.Lerp( m_CurrentObject.transform.localScale, new Vector3(m_StartScale.x, 0) * m_ScaleFactor, m_DeltaTime); } m_AnimateScale = false; m_DeltaTime = 0f; } }
void Update() { if (Input.GetMouseButtonDown(0)) { m_LastMousePos = Input.mousePosition; m_Ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(m_Ray.origin, m_Ray.direction, out m_RayCastHit, Mathf.Infinity)) { ResizableObject obj = m_RayCastHit.collider.gameObject.GetComponent <ResizableObject>(); if (obj) { m_CurrentObject = obj; m_StartScale = obj.transform.localScale; } } } if (Input.GetMouseButton(0)) { Vector3 deltaPosition = Input.mousePosition - m_LastMousePos; if (deltaPosition.magnitude > 1f) { if (m_CurrentObject && !m_AnimateScale) { m_ScaleFactor = deltaPosition.magnitude; m_AnimateScale = true; m_DeltaTime = 0f; } } m_LastMousePos = Input.mousePosition; } if (m_AnimateScale && m_DeltaTime < 1f) { m_DeltaTime += Time.deltaTime; if (m_CurrentObject) { m_CurrentObject.transform.localScale = Vector3.Lerp(m_CurrentObject.transform.localScale, m_StartScale * m_ScaleFactor, m_DeltaTime); } } else { m_AnimateScale = false; m_DeltaTime = 0f; } }
public void RemoveGameObject(ResizableObject gameObject) { var otherObject = LinkedGameObjects[gameObject.GameObject]; GameObjectEditor foundDoc = null; foreach (var doc in MainScreen.Instance.OpenEditors) { if (doc is GameObjectEditor) { if (((GameObjectEditor)doc).GameObject == otherObject) { foundDoc = (GameObjectEditor)doc; } } } if (foundDoc != null) { MainScreen.Instance.RemoveEditor(foundDoc); LinkedGameObjects.Remove(gameObject.GameObject); Objects.Remove(gameObject); } }
public void RenameGameObject(ResizableObject gameObject, string newName) { gameObject.Name = newName; LinkedGameObjects[gameObject.GameObject].Name = newName; FixLinkedObjectTitles(); }
public void RemoveGameObject(ResizableObject gameObject) { var otherObject = LinkedGameObjects[gameObject.GameObject]; GameObjectEditor foundDoc = null; foreach (var doc in EditorConsoleManager.OpenEditors) if (doc is GameObjectEditor) if (((GameObjectEditor)doc).GameObject == otherObject) foundDoc = (GameObjectEditor)doc; if (foundDoc != null) { EditorConsoleManager.RemoveEditor(foundDoc); LinkedGameObjects.Remove(gameObject.GameObject); Objects.Remove(gameObject); } }
public bool LoadZone(Zone zone) { var gameObject = new GameObject(Settings.Config.ScreenFont); var animation = new AnimatedTextSurface("default", 10, 10); var frame = animation.CreateFrame(); frame.DefaultBackground = zone.DebugAppearance.Background; gameObject.Name = zone.Title; Settings.QuickEditor.TextSurface = frame; Settings.QuickEditor.Clear(); Settings.QuickEditor.Print(0, 0, zone.Title, Color.DarkGray); gameObject.Animation = animation; gameObject.Position = new Point(zone.Area.Left, zone.Area.Top); gameObject.Update(); var resizable = new ResizableObject<Zone>(ResizableObject.ObjectType.Zone, gameObject, zone); resizable.RenderOffset = consoleWrapper.Position - consoleWrapper.TextSurface.RenderArea.Location; Zones.Add(resizable); ZonesPanel.RebuildListBox(); return true; }
public void ProcessMouse(MouseConsoleState info, ISurface surface, bool isInBounds) { var editor = MainScreen.Instance.ActiveEditor as Editors.SceneEditor; if (editor != null && info.IsOnConsole && !isResizing && !isMoving) { var zones = editor.Zones.ToList(); zones.Reverse(); var allObjects = editor.Objects.Union(zones).ToList(); for (int i = 0; i < allObjects.Count; i++) { var area = allObjects[i].GameObject.Animation.RenderArea; area.Offset(allObjects[i].GameObject.Position - allObjects[i].GameObject.Animation.Center); area.Inflate(1, 1); var mousePosition = info.CellPosition; if (!area.Contains(mousePosition)) { continue; } if (movingEntity != null) { movingEntity.IsSelected = false; } movingEntity = allObjects[i]; movingEntity.IsSelected = true; if (!info.Mouse.LeftButtonDown) { return; } // Select the zone in the list box if (movingEntity.Type == ResizableObject.ObjectType.Zone && editor.ZonesPanel.SelectedGameObject != movingEntity) { editor.ZonesPanel.SelectedGameObject = movingEntity; } else if (movingEntity.Type == ResizableObject.ObjectType.GameObject && editor.GameObjectPanel.SelectedGameObject != movingEntity) { editor.GameObjectPanel.SelectedGameObject = movingEntity; } var gameObject = movingEntity.GameObject; var overlay = movingEntity.Overlay; var rules = movingEntity.Rules; lastLeftMouseDown = true; moveRight = false; moveTopRight = false; moveBottomRight = false; moveLeft = false; moveTopLeft = false; moveBottomLeft = false; moveTop = false; moveBottom = false; // Check and see if mouse is over me if (rules.AllowMove && info.CellPosition.X >= gameObject.Position.X && info.CellPosition.X <= gameObject.Position.X + gameObject.Animation.Width - 1 && info.CellPosition.Y >= gameObject.Position.Y && info.CellPosition.Y <= gameObject.Position.Y + gameObject.Animation.Height - 1) { if (movingEntity.Type == ResizableObject.ObjectType.GameObject) { editor.GameObjectPanel.SelectedGameObject = movingEntity; } clickOffset = info.CellPosition - gameObject.Position; isMoving = true; return; } else if (rules.AllowLeftRight && rules.AllowTopBottom && info.CellPosition.Y == overlay.Position.Y + overlay.Animation.Height - 1 && info.CellPosition.X == overlay.Position.X + overlay.Animation.Width - 1) { isResizing = true; moveBottomRight = true; resizeStartPosition = info.CellPosition; resizeBounds = new Point(gameObject.Position.X, gameObject.Position.Y); return; } else if (rules.AllowLeftRight && rules.AllowTopBottom && info.CellPosition.Y == overlay.Position.Y && info.CellPosition.X == overlay.Position.X + overlay.Animation.Width - 1) { isResizing = true; moveTopRight = true; resizeStartPosition = info.CellPosition; resizeBounds = new Point(gameObject.Position.X, gameObject.Position.Y + gameObject.Animation.Height - 1); return; } else if (rules.AllowLeftRight && info.CellPosition.X == overlay.Position.X + overlay.Animation.Width - 1) { isResizing = true; moveRight = true; resizeStartPosition = info.CellPosition; resizeBounds = new Point(gameObject.Position.X, 0); return; } else if (rules.AllowLeftRight && rules.AllowTopBottom && info.CellPosition.Y == overlay.Position.Y + overlay.Animation.Height - 1 && info.CellPosition.X == overlay.Position.X) { isResizing = true; moveBottomLeft = true; resizeStartPosition = info.CellPosition; resizeBounds = new Point(gameObject.Position.X + gameObject.Animation.Width - 1, gameObject.Position.Y); return; } else if (rules.AllowLeftRight && rules.AllowTopBottom && info.CellPosition.Y == overlay.Position.Y && info.CellPosition.X == overlay.Position.X) { isResizing = true; moveTopLeft = true; resizeStartPosition = info.CellPosition; resizeBounds = new Point(gameObject.Position.X + gameObject.Animation.Width - 1, gameObject.Position.Y + gameObject.Animation.Height - 1); return; } else if (rules.AllowLeftRight && info.CellPosition.X == overlay.Position.X) { isResizing = true; moveLeft = true; resizeStartPosition = info.CellPosition; resizeBounds = new Point(gameObject.Position.X + gameObject.Animation.Width - 1, 0); return; } else if (rules.AllowTopBottom && info.CellPosition.Y == overlay.Position.Y) { isResizing = true; moveTop = true; resizeStartPosition = info.CellPosition; resizeBounds = new Point(0, gameObject.Position.Y + gameObject.Animation.Height - 1); return; } else if (rules.AllowTopBottom && info.CellPosition.Y == overlay.Position.Y + overlay.Animation.Height - 1) { isResizing = true; moveBottom = true; resizeStartPosition = info.CellPosition; resizeBounds = new Point(0, gameObject.Position.Y); return; } } if (!info.Mouse.LeftButtonDown && movingEntity != null) { movingEntity.IsSelected = false; movingEntity = null; } } if (isResizing) { if (!info.Mouse.LeftButtonDown) { isResizing = false; return; } if (MainScreen.Instance.InnerEmptyBounds.Contains(info.WorldPosition)) { var cellPosition = info.ConsolePosition + surface.RenderArea.Location; if (moveRight && cellPosition.X > resizeBounds.X) { movingEntity.ResizeObject(cellPosition.X - movingEntity.GameObject.Position.X, movingEntity.GameObject.Animation.Height); } else if (moveBottomRight && cellPosition.X > resizeBounds.X && cellPosition.Y > resizeBounds.Y) { movingEntity.ResizeObject(cellPosition.X - movingEntity.GameObject.Position.X, cellPosition.Y - movingEntity.GameObject.Position.Y); } else if (moveTopRight && cellPosition.X > resizeBounds.X && cellPosition.Y < resizeBounds.Y) { movingEntity.ResizeObject(cellPosition.X - movingEntity.GameObject.Position.X, movingEntity.GameObject.Position.Y + movingEntity.GameObject.Animation.Height - (cellPosition.Y + 1), null, cellPosition.Y + 1); } else if (moveLeft && cellPosition.X < resizeBounds.X) { movingEntity.ResizeObject(movingEntity.GameObject.Position.X + movingEntity.GameObject.Animation.Width - (cellPosition.X + 1), movingEntity.GameObject.Animation.Height, cellPosition.X + 1, null); } else if (moveBottomLeft && cellPosition.X < resizeBounds.X && cellPosition.Y > resizeBounds.Y) { movingEntity.ResizeObject(movingEntity.GameObject.Position.X + movingEntity.GameObject.Animation.Width - (cellPosition.X + 1), cellPosition.Y - movingEntity.GameObject.Position.Y, cellPosition.X + 1, null); } else if (moveTopLeft && cellPosition.X < resizeBounds.X && cellPosition.Y < resizeBounds.Y) { movingEntity.ResizeObject(movingEntity.GameObject.Position.X + movingEntity.GameObject.Animation.Width - (cellPosition.X + 1), movingEntity.GameObject.Position.Y + movingEntity.GameObject.Animation.Height - (cellPosition.Y + 1), cellPosition.X + 1, cellPosition.Y + 1); } else if (moveTop && cellPosition.Y < resizeBounds.Y) { movingEntity.ResizeObject(movingEntity.GameObject.Animation.Width, movingEntity.GameObject.Position.Y + movingEntity.GameObject.Animation.Height - (cellPosition.Y + 1), null, cellPosition.Y + 1); } else if (moveBottom && cellPosition.Y > resizeBounds.Y) { movingEntity.ResizeObject(movingEntity.GameObject.Animation.Width, cellPosition.Y - movingEntity.GameObject.Position.Y); } } return; } else if (isMoving) { if (!info.Mouse.LeftButtonDown) { isMoving = false; return; } if (MainScreen.Instance.InnerEmptyBounds.Contains(info.WorldPosition)) { var cellPosition = info.ConsolePosition + surface.RenderArea.Location; movingEntity.GameObject.Position = cellPosition - clickOffset; movingEntity.ProcessOverlay(); } } lastLeftMouseDown = info.Mouse.LeftButtonDown; return; }
public void ProcessMouse(MouseInfo info, ITextSurface surface) { var editor = EditorConsoleManager.ActiveEditor as Editors.SceneEditor; if(editor != null && !isResizing && !isMoving) { var zones = editor.Zones.ToList(); zones.Reverse(); var allObjects = editor.Objects.Union(zones).ToList(); for (int i = 0; i < allObjects.Count; i++) { var area = allObjects[i].GameObject.Animation.RenderArea; area.Offset(allObjects[i].GameObject.Position - allObjects[i].GameObject.Animation.Center); area.Inflate(1, 1); var mousePosition = info.WorldLocation - allObjects[i].RenderOffset; if (!area.Contains(mousePosition)) continue; if (movingEntity != null) movingEntity.IsSelected = false; movingEntity = allObjects[i]; movingEntity.IsSelected = true; if (!info.LeftButtonDown) return; // Select the zone in the list box if (movingEntity.Type == ResizableObject.ObjectType.Zone && editor.ZonesPanel.SelectedGameObject != movingEntity) editor.ZonesPanel.SelectedGameObject = movingEntity; else if (movingEntity.Type == ResizableObject.ObjectType.GameObject && editor.GameObjectPanel.SelectedGameObject != movingEntity) editor.GameObjectPanel.SelectedGameObject = movingEntity; var gameObject = movingEntity.GameObject; var overlay = movingEntity.Overlay; var rules = movingEntity.Rules; lastLeftMouseDown = true; moveRight = false; moveTopRight = false; moveBottomRight = false; moveLeft = false; moveTopLeft = false; moveBottomLeft = false; moveTop = false; moveBottom = false; // Check and see if mouse is over me if (rules.AllowMove && info.ConsoleLocation.X >= gameObject.Position.X && info.ConsoleLocation.X <= gameObject.Position.X + gameObject.Width - 1 && info.ConsoleLocation.Y >= gameObject.Position.Y && info.ConsoleLocation.Y <= gameObject.Position.Y + gameObject.Height - 1) { if (movingEntity.Type == ResizableObject.ObjectType.GameObject) editor.GameObjectPanel.SelectedGameObject = movingEntity; clickOffset = info.ConsoleLocation - gameObject.Position; isMoving = true; return; } else if (rules.AllowLeftRight && rules.AllowTopBottom && info.ConsoleLocation.Y == overlay.Position.Y + overlay.Height - 1 && info.ConsoleLocation.X == overlay.Position.X + overlay.Width - 1) { isResizing = true; moveBottomRight = true; resizeStartPosition = info.ConsoleLocation; resizeBounds = new Point(gameObject.Position.X, gameObject.Position.Y); return; } else if (rules.AllowLeftRight && rules.AllowTopBottom && info.ConsoleLocation.Y == overlay.Position.Y && info.ConsoleLocation.X == overlay.Position.X + overlay.Width - 1) { isResizing = true; moveTopRight = true; resizeStartPosition = info.ConsoleLocation; resizeBounds = new Point(gameObject.Position.X, gameObject.Position.Y + gameObject.Height - 1); return; } else if (rules.AllowLeftRight && info.ConsoleLocation.X == overlay.Position.X + overlay.Width - 1) { isResizing = true; moveRight = true; resizeStartPosition = info.ConsoleLocation; resizeBounds = new Point(gameObject.Position.X, 0); return; } else if (rules.AllowLeftRight && rules.AllowTopBottom && info.ConsoleLocation.Y == overlay.Position.Y + overlay.Height - 1 && info.ConsoleLocation.X == overlay.Position.X) { isResizing = true; moveBottomLeft = true; resizeStartPosition = info.ConsoleLocation; resizeBounds = new Point(gameObject.Position.X + gameObject.Width - 1, gameObject.Position.Y); return; } else if (rules.AllowLeftRight && rules.AllowTopBottom && info.ConsoleLocation.Y == overlay.Position.Y && info.ConsoleLocation.X == overlay.Position.X) { isResizing = true; moveTopLeft = true; resizeStartPosition = info.ConsoleLocation; resizeBounds = new Point(gameObject.Position.X + gameObject.Width - 1, gameObject.Position.Y + gameObject.Height - 1); return; } else if (rules.AllowLeftRight && info.ConsoleLocation.X == overlay.Position.X) { isResizing = true; moveLeft = true; resizeStartPosition = info.ConsoleLocation; resizeBounds = new Point(gameObject.Position.X + gameObject.Width - 1, 0); return; } else if (rules.AllowTopBottom && info.ConsoleLocation.Y == overlay.Position.Y) { isResizing = true; moveTop = true; resizeStartPosition = info.ConsoleLocation; resizeBounds = new Point(0, gameObject.Position.Y + gameObject.Height - 1); return; } else if (rules.AllowTopBottom && info.ConsoleLocation.Y == overlay.Position.Y + overlay.Height - 1) { isResizing = true; moveBottom = true; resizeStartPosition = info.ConsoleLocation; resizeBounds = new Point(0, gameObject.Position.Y); return; } } if (!info.LeftButtonDown && movingEntity != null) { movingEntity.IsSelected = false; movingEntity = null; } } if (isResizing) { if (!info.LeftButtonDown) { isResizing = false; return; } if (moveRight && info.ConsoleLocation.X > resizeBounds.X) { movingEntity.ResizeObject(info.ConsoleLocation.X - movingEntity.GameObject.Position.X, movingEntity.GameObject.Height); } else if (moveBottomRight && info.ConsoleLocation.X > resizeBounds.X && info.ConsoleLocation.Y > resizeBounds.Y) { movingEntity.ResizeObject(info.ConsoleLocation.X - movingEntity.GameObject.Position.X, info.ConsoleLocation.Y - movingEntity.GameObject.Position.Y); } else if (moveTopRight && info.ConsoleLocation.X > resizeBounds.X && info.ConsoleLocation.Y < resizeBounds.Y) { movingEntity.ResizeObject(info.ConsoleLocation.X - movingEntity.GameObject.Position.X, movingEntity.GameObject.Position.Y + movingEntity.GameObject.Height - (info.ConsoleLocation.Y + 1), null, info.ConsoleLocation.Y + 1); } else if (moveLeft && info.ConsoleLocation.X < resizeBounds.X) { movingEntity.ResizeObject(movingEntity.GameObject.Position.X + movingEntity.GameObject.Width - (info.ConsoleLocation.X + 1), movingEntity.GameObject.Height, info.ConsoleLocation.X + 1, null); } else if (moveBottomLeft && info.ConsoleLocation.X < resizeBounds.X && info.ConsoleLocation.Y > resizeBounds.Y) { movingEntity.ResizeObject(movingEntity.GameObject.Position.X + movingEntity.GameObject.Width - (info.ConsoleLocation.X + 1), info.ConsoleLocation.Y - movingEntity.GameObject.Position.Y, info.ConsoleLocation.X + 1, null); } else if (moveTopLeft && info.ConsoleLocation.X < resizeBounds.X && info.ConsoleLocation.Y < resizeBounds.Y) { movingEntity.ResizeObject(movingEntity.GameObject.Position.X + movingEntity.GameObject.Width - (info.ConsoleLocation.X + 1), movingEntity.GameObject.Position.Y + movingEntity.GameObject.Height - (info.ConsoleLocation.Y + 1), info.ConsoleLocation.X + 1, info.ConsoleLocation.Y + 1); } else if (moveTop && info.ConsoleLocation.Y < resizeBounds.Y) { movingEntity.ResizeObject(movingEntity.GameObject.Width, movingEntity.GameObject.Position.Y + movingEntity.GameObject.Height - (info.ConsoleLocation.Y + 1), null, info.ConsoleLocation.Y + 1); } else if (moveBottom && info.ConsoleLocation.Y > resizeBounds.Y) { movingEntity.ResizeObject(movingEntity.GameObject.Width, info.ConsoleLocation.Y - movingEntity.GameObject.Position.Y); } return; } else if (isMoving) { if (!info.LeftButtonDown) { isMoving = false; return; } movingEntity.GameObject.Position = info.ConsoleLocation - clickOffset; movingEntity.ProcessOverlay(); } lastLeftMouseDown = info.LeftButtonDown; return; }