public void UpdateProperties(MapObjectGroup selection) { int detailSolids = 0; int nonDetailSolids = 0; int hiddenSolids = 0; int nonHiddenSolids = 0; if (!selection.Empty) { Enabled = true; CustomOperation operation = new CustomOperation { OnSolid = (solid) => { // check hidden property if (solid.Hidden) { hiddenSolids++; } else { nonHiddenSolids++; } CheckState binairCheckstate = hiddenSolids == 0 ? CheckState.Unchecked : CheckState.Checked; hiddenSolid.CheckState = hiddenSolids > 0 && nonHiddenSolids > 0 ? CheckState.Indeterminate : binairCheckstate; // check detail property if (solid.Detail) { detailSolids++; } else { nonDetailSolids++; } binairCheckstate = detailSolids == 0 ? CheckState.Unchecked : CheckState.Checked; detailSolid.CheckState = detailSolids > 0 && nonDetailSolids > 0 ? CheckState.Indeterminate : binairCheckstate; } }; operation.OnMapObjectGroup = (group) => { group.MapObjectList.ForEach((subGroup) => subGroup.PerformOperation(operation)); }; selection.PerformOperation(operation); } else { detailSolid.CheckState = CheckState.Unchecked; hiddenSolid.CheckState = CheckState.Unchecked; Enabled = false; } }
public void Visit(MapObjectGroup mapObjectGroup) { foreach (MapObject brush in mapObjectGroup.MapObjectList) { brush.PerformOperation(this); } TranslateBounds(mapObjectGroup.Bounds); }
public void Visit(MapObjectGroup mapObjectGroup) { foreach (MapObject brush in mapObjectGroup.MapObjectList) { brush.PerformOperation(this); } mapObjectGroup.RegenerateBounds(); }
public override bool OnMouseDown(Point mouseCurPos, MouseButtons button, BaseViewport viewport) { MapObjectGroup selectedMapObjectGroup = controller.Selection; MapObject rootMapObject = controller.GetMapObjectIfHit(mouseCurPos.X, mouseCurPos.Y, viewport); if (viewport.ViewportType == BaseViewport.ViewportTypes.PERSPECTIVE) { if (rootMapObject == null) { SetAllFacesSelected(false); selectedMapObjectGroup.Clear(); } else { SolidFaceHitOperation operation = new SolidFaceHitOperation(viewport, mouseCurPos); rootMapObject.PerformOperation(operation); SolidFace hitFace = operation.hitFace; if (modifierKey == Keys.Control) { if (!AreAnyFacesSelected(rootMapObject)) { controller.Selection.Add(rootMapObject); } hitFace.Selected = !hitFace.Selected; if (!AreAnyFacesSelected(rootMapObject)) { controller.Selection.Remove(rootMapObject); } } else if (!hitFace.Selected) { SetAllFacesSelected(false); selectedMapObjectGroup.Clear(); hitFace.Selected = true; selectedMapObjectGroup.Add(rootMapObject); } } } else if (rootMapObject == null) // deselect faces when pressing in empty ortho viewport space { SetAllFacesSelected(false); controller.Selection.Clear(); } controller.UpdateUserInterface(); return(true); }
public void Visit(MapObjectGroup mapObjectGroup) { foreach (MapObject mapObject in mapObjectGroup) { mapObject.PerformOperation(this); // as soon as we have found a brush hit we can say that this group brush is hit! if (hasIntersected) { HitMapObject = mapObjectGroup; break; } } }
public void Import(FileStream stream, SceneDocument document) { StreamReader streamReader = new StreamReader(stream); JsonTextReader reader = new JsonTextReader(streamReader); JObject mapFile = (JObject)JToken.ReadFrom(reader); JToken mapobjects = mapFile["mapobjects"]; MapObjectGroup group = CreateGroup(mapobjects); group.MapObjectList.ForEach(document.AddMapObject); document.MapName = mapFile["name"].ToString(); }
public void Visit(MapObjectGroup mapObjectGroup) { // we only set the bounds for the top groupbrush // this way a child groupbrush wont change the rootBounds again if (rootBounds == null) { rootBounds = mapObjectGroup.Bounds; } foreach (MapObject brush in mapObjectGroup.MapObjectList) { brush.PerformOperation(this); } mapObjectGroup.RegenerateBounds(); }
/// <summary> /// Check if we hit the handles /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="viewport"></param> /// <returns></returns> private int GetGrableHandleHit(int x, int y, BaseViewport viewport) { MapObjectGroup selectedMapObjectGroup = controller.Selection; if (selectedMapObjectGroup.Empty) { return((int)SolidGrabHandles.HitStatus.None); } Matrix4 toGridMatrix = viewport.Camera.GetWorldMatrix().ClearTranslation(); SolidGrabHandles handles = controller.RubberBand.Handles; handles.CreateHandles(selectedMapObjectGroup, toGridMatrix, viewport.Zoom); return(handles.CheckHit(viewport.ViewportToRay(x, y))); }
void Start() { DOTween.Init(); var map = Deserialize <Map>(xmlMap.text); var mapLayer = new MapLayer(map.Layer.Name, map.Layer.Width, map.Layer.Height, map.Layer.Data.Text); var mapObjectGroup = new MapObjectGroup(map.Objectgroup.Name, map.Objectgroup.Object); for (var y = 0; y < mapLayer.height; y++) { for (var x = 0; x < mapLayer.width; x++) { var newTile = Instantiate(GetPrefab(mapLayer.GetTile(x, y)), transform); IntVector2 gridPosition = new IntVector2(x, y); newTile.transform.localPosition = gridPosition.GridToWorld(); newTile.name = $"{x},{y}"; var tile = newTile.AddComponent <Tile>(); tile.gridPosition = gridPosition; tile.OnClickTile = ClickTile; } } pathfinder = new Pathfinder(); pathfinder.Init(mapLayer.data, new List <int>() { (int)TileType.Grass }, HasWall, BlockedByOthers); pathIndicator = new List <GameObject>(); // player & enemy actors actors = new List <Actor>(); foreach (var obj in mapObjectGroup.objects) { GameObject newObject = Instantiate(GetObjectPrefab(obj.type), transform); newObject.transform.localPosition = obj.gridPosition.GridToWorld(); var actor = newObject.AddComponent <Actor>(); actors.Add(actor); actor.data = obj; actor.OnClickActor = ClickActor; } }
public void UpdateStatusBar(BaseViewport viewport) { editorStatusbarGrid.Text = viewport.GridSize > 0 ? string.Format(GridUnitsText, viewport.GridSize) : string.Empty; editorStatusbarZoom.Text = viewport.Zoom > 0.0f ? string.Format(ZoomText, Math.Round(1.0f / viewport.Zoom * 100.0f, 2)) : string.Empty; MapObjectGroup selectedMapObjectGroup = viewport.Controller.Selection; if (selectedMapObjectGroup.Empty) { ResetData(); return; } Vector3 center = selectedMapObjectGroup.Bounds.Center; editorStatusbarPositon.Text = string.Format(PositionText, Math.Round(center.X, 0), Math.Round(center.Y, 0), Math.Round(center.Z, 0)); Vector3 dimensions = selectedMapObjectGroup.Bounds.Max - selectedMapObjectGroup.Bounds.Min; editorStatusbarDimensions.Text = string.Format(DimensionsText, Math.Round(dimensions.X, 0), Math.Round(dimensions.Y, 0), Math.Round(dimensions.Z, 0)); }
/// <summary> /// Initializes the editor /// </summary> private void InitializeEditor() { // events Move += editorViewport.OnEditorMoves; Activated += editorViewport.OnEditorGotFocus; Deactivate += editorViewport.OnEditorLostFocus; Disposed += EditorForm_Dispose; editorViewport.OnViewportFocus += OnViewportFocus; textureSelector.ApplyButton.Click += OnApplySelectedTexture; textureSelector.ReplaceButton.Click += OnReplaceSelectedTexture; creationButtonsPanel.OnCreationButtonPressed = HandleGeometryBarItems; solidProperties.OnPropertiesChanged = OnSolidPropertiesChanged; textureProperties.OnPropertiesChanged = OnTexturePropertiesChanged; textureProperties.OnJustify = OnTexturePropertiesJustifyClicked; // initialization EditorSettings = new EditorSettings(); RubberBand = new RubberBand(); Selection = new MapObjectGroup(); CopyBoard = new MapObjectGroup(); CurrentTool = new SolidManipulationTool(); defaultMapSaver = new RuneMapExporter(); defaultMapLoader = new RuneMapImporter(); TextureCollection = new TextureCollection(EditorSettings.TextureFolder); if (!DesignMode) { EditorSettings.Load(); SetupSolidFactory(); solidProperties.UpdateProperties(Selection); editorViewport.SetController(this); textureSelector.TextureCollection = TextureCollection; CurrentTool.Initialize(this); Rotate = GeneralUtility.CreateCursor(Resources.rotate, 16, 16); NewDocument(); } }
public void UpdateProperties(MapObjectGroup selection) { ignoreChangedEvent = true; bool uShiftIsDifferent = false; bool vShiftIsDifferent = false; bool uScaleIsDifferent = false; bool vScaleIsDifferent = false; bool rotationIsDifferent = false; bool textureLockDifferent = false; int faceCount = 0; if (!selection.Empty) { CustomOperation operation = new CustomOperation { OnSolid = (solid) => solid.Faces.Where(f => f.Selected).ToList().ForEach((face) => { faceCount++; uScaleNumeric.Value = (decimal)face.TextureMapping.UScale; if (uScaleNumeric.Value != (decimal)face.TextureMapping.UScale) { uScaleIsDifferent = true; } vScaleNumeric.Value = (decimal)face.TextureMapping.VScale; if (vScaleNumeric.Value != (decimal)face.TextureMapping.VScale) { vScaleIsDifferent = true; } uShiftNumeric.Value = (decimal)face.TextureMapping.UShift; if (uShiftNumeric.Value != (decimal)face.TextureMapping.UShift) { uShiftIsDifferent = true; } vShiftNumeric.Value = (decimal)face.TextureMapping.VShift; if (vShiftNumeric.Value != (decimal)face.TextureMapping.VShift) { vShiftIsDifferent = true; } rotationNumeric.Value = (decimal)face.TextureMapping.Rotation; if (rotationNumeric.Value != (decimal)face.TextureMapping.Rotation) { rotationIsDifferent = true; } textureLockButton.Checked = face.TextureMapping.TextureLocked; if (textureLockButton.Checked != face.TextureMapping.TextureLocked) { textureLockDifferent = true; } }) }; operation.OnMapObjectGroup = (group) => { group.MapObjectList.ForEach((subGroup) => subGroup.PerformOperation(operation)); }; selection.PerformOperation(operation); } else { ResetValues(); } TreatAsOneCheckbox.Enabled = faceCount > 1; // check if we need to set default values if (uScaleIsDifferent) { uScaleNumeric.Value = TextureMapping.DefaultScaleValue; } if (vScaleIsDifferent) { vScaleNumeric.Value = TextureMapping.DefaultScaleValue; } if (uShiftIsDifferent) { vShiftNumeric.Value = TextureMapping.DefaultShiftValue; } if (vShiftIsDifferent) { vShiftNumeric.Value = TextureMapping.DefaultShiftValue; } if (rotationIsDifferent) { rotationNumeric.Value = TextureMapping.DefaultRotationValue; } if (textureLockDifferent) { textureLockButton.Checked = TextureMapping.DefaultTextureLockValue; } ignoreChangedEvent = false; }
public override bool OnMouseDown(Point mouseCurPos, MouseButtons button, BaseViewport viewport) { if (button == MouseButtons.Left) { currentActionViewport = viewport.ViewportType; MapObjectGroup selectedMapObjectGroup = controller.Selection; bool isControlPressed = modifierKey == Keys.Control; newHandlesHit = GetHandlesHitWithMouse(viewport, mouseCurPos); // Check if we hit a vertex handle if (newHandlesHit.Count > 0) { Action dragStartPositionAction = () => { // any vertex will do var first = newHandlesHit.First(); Solid solid = first.Key; int firstVertex = first.Value[0]; SetSelectDragAction(solid.VertexPositions[firstVertex], viewport); }; Action isAnySelected = () => { // if still any selected left, setSelectDrag bool selected = newHandlesHit.All((pair) => pair.Value.Any((index) => pair.Key.SelectedVertices.Contains(index))); if (selected) { dragStartPositionAction(); } }; bool anySelected = newHandlesHit.All((pair) => pair.Value.Any((index) => pair.Key.SelectedVertices.Contains(index))); if (isControlPressed) { foreach (KeyValuePair <Solid, List <int> > pair in newHandlesHit) { pair.Value.ForEach((index) => { if (pair.Key.SelectedVertices.Contains(index)) { pair.Key.SelectedVertices.Remove(index); } else { pair.Key.SelectedVertices.Add(index); } }); } isAnySelected(); } else if (anySelected) { dragStartPositionAction(); } else { ClearAllSelectedVertices(); foreach (KeyValuePair <Solid, List <int> > pair in newHandlesHit) { pair.Value.ForEach((index) => { if (!pair.Key.SelectedVertices.Contains(index)) { pair.Key.SelectedVertices.Add(index); } }); } isAnySelected(); } } else // if no handles hit, check if we hit a solid { MapObject rootMapObject = controller.GetMapObjectIfHit(mouseCurPos.X, mouseCurPos.Y, viewport); if (rootMapObject == null) { if (viewport.ViewportType == BaseViewport.ViewportTypes.PERSPECTIVE) { ClearAllSelectedVertices(); } else // no map object hit for orthographic set action to SelectMultiple { currentAction = VertexToolActionType.SelectMultiple; } } else { if (isControlPressed) { if (!rootMapObject.Selected) { rootMapObject.Selected = true; selectedMapObjectGroup.Add(rootMapObject); } else { DoSolidAction(rootMapObject, (solid) => { solid.SelectedVertices.Clear(); }); rootMapObject.Selected = false; selectedMapObjectGroup.Remove(rootMapObject); } } else if (!rootMapObject.Selected) { ClearAllSelectedVertices(); selectedMapObjectGroup.Clear(); rootMapObject.Selected = true; selectedMapObjectGroup.Add(rootMapObject); } else { // solid we hit was already selected so we set action to SelectMultiples currentAction = VertexToolActionType.SelectMultiple; } } } mouseDownPos = mouseCurPos; } return(true); }