/// <summary> /// When overridden in the derived class, allows for handling resetting the state of this <see cref="Tool"/>. /// For simplicity, all default values should be constant, no matter the current state. /// </summary> protected override void HandleResetState() { base.HandleResetState(); _mouseOverMap = null; _mousePos = Vector2.Zero; }
/// <summary> /// Handles when the mouse button is raised on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseUp(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { var cursorPos = e.Position(); var worldPos = camera.ToWorld(cursorPos); // Create entity if (e.Button == MouseButtons.Right) { Type createType = null; // Create using same type as the last entity, if possible if (Input.IsCtrlDown) { createType = _lastCreatedType; } // Display selection dialog if (createType == null) { using (var frm = new EntityTypeUITypeEditorForm(_lastCreatedType)) { if (frm.ShowDialog(sender as IWin32Window) == DialogResult.OK) { createType = frm.SelectedItem; } } } // Create the type if (createType != null) { _lastCreatedType = null; try { // Create the Entity var entity = (Entity)Activator.CreateInstance(createType); map.AddEntity(entity); entity.Size = new Vector2(64); entity.Position = worldPos - (entity.Size / 2f); GridAligner.Instance.Fit(entity); _lastCreatedType = createType; } catch (Exception ex) { const string errmsg = "Failed to create entity of type `{0}` on map `{1}`. Exception: {2}"; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, createType, map, ex); } Debug.Fail(string.Format(errmsg, createType, map, ex)); } } } base.MapContainer_MouseUp(sender, map, camera, e); }
/// <summary> /// Handles when the mouse moves over a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseMove(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { _mouseOverMap = map; var worldPos = camera.ToWorld(e.Position()); if (IsSelecting) { // Expand selection area _selectionEnd = worldPos; } else { // Create the tooltip var font = ToolTipFont; if (ShowObjectToolTip && font != null) { var hoverEntity = GetObjUnderCursor(map, worldPos); if (hoverEntity == null) { // Nothing under the cursor that we are allowed to select _toolTip = string.Empty; _toolTipObject = null; } else if (_toolTipObject != hoverEntity) { // Something found under the cursor _toolTipObject = hoverEntity; _toolTipPos = e.Position(); _toolTip = GetObjectToolTip(hoverEntity) ?? hoverEntity.ToString(); // Make sure the text stays in the view area const int toolTipPadding = 4; var toolTipSize = font.MeasureString(_toolTip); if (_toolTipPos.X < toolTipPadding) { _toolTipPos.X = toolTipPadding; } else if (_toolTipPos.X + toolTipSize.X + toolTipPadding > camera.Size.X) { _toolTipPos.X = camera.Size.X - toolTipSize.X - toolTipPadding; } if (_toolTipPos.Y < toolTipPadding) { _toolTipPos.Y = toolTipPadding; } else if (_toolTipPos.Y + toolTipSize.Y + toolTipPadding > camera.Size.Y) { _toolTipPos.Y = camera.Size.Y - toolTipSize.Y - toolTipPadding; } } } } base.MapContainer_MouseMove(sender, map, camera, e); }
// Use this for initialization void Start() { S = this; eMap = transform.parent.GetComponent <EditorMap>(); RectTransform recT = GetComponent <RectTransform>(); miniMapRooms = new EditorMiniMapRoom[EditorMap.mapSize, EditorMap.mapSize]; for (int j = 0; j < EditorMap.mapSize; j++) { for (int i = 0; i < EditorMap.mapSize; i++) { GameObject go = Instantiate(miniMapRoomPrefab); RectTransform rt = go.GetComponent <RectTransform>(); EditorMiniMapRoom emmr = go.GetComponent <EditorMiniMapRoom>(); miniMapRooms[i, j] = emmr; emmr.sprite = spriteOff; emmr.x = i; emmr.y = j; rt.SetParent(recT); rt.anchoredPosition = new Vector2(i * 32, j * 22); } } HighlightRoom(); }
/// <summary> /// Handles when a key is raised on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_KeyUp(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, KeyEventArgs e) { // Handle deletes if (e.KeyCode == Keys.Delete) { // Only delete when it is an Entity that is on this map var removed = new List <object>(); foreach (var x in SOM.SelectedObjects.OfType <ILight>().ToImmutable()) { if (map.Lights.Contains(x)) { map.RemoveLight(x); removed.Add(x); // Remove the graphic and effect from the map var msc = MapScreenControl.TryFindInstance(map); if (msc != null) { var dm = msc.DrawingManager; if (dm != null) { dm.LightManager.Remove(x); } } } } SOM.SetManySelected(SOM.SelectedObjects.Except(removed).ToImmutable()); } base.MapContainer_KeyUp(sender, map, camera, e); }
/// <summary> /// Handles when a key is raised on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_KeyUp(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, KeyEventArgs e) { // Handle deletes if (e.KeyCode == Keys.Delete) { // Only delete when it is an Entity that is on this map var removed = new List<object>(); foreach (var x in SOM.SelectedObjects.OfType<Entity>().ToImmutable()) { if (map.Spatial.CollectionContains(x)) { map.RemoveEntity(x); if (!x.IsDisposed) x.Dispose(); removed.Add(x); } } SOM.SetManySelected(SOM.SelectedObjects.Except(removed).ToImmutable()); } base.MapContainer_KeyUp(sender, map, camera, e); }
/// <summary> /// Handles when a key is raised on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_KeyUp(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, KeyEventArgs e) { // Handle deletes if (e.KeyCode == Keys.Delete) { // Only delete when it is an Entity that is on this map var removed = new List <object>(); foreach (var x in SOM.SelectedObjects.OfType <Entity>().ToImmutable()) { if (map.Spatial.CollectionContains(x)) { map.RemoveEntity(x); if (!x.IsDisposed) { x.Dispose(); } removed.Add(x); } } SOM.SetManySelected(SOM.SelectedObjects.Except(removed).ToImmutable()); } base.MapContainer_KeyUp(sender, map, camera, e); }
// Use this for initialization void Awake() { S = this; // Initialize the private Singleton #if (UsePlayerPrefsForFileName) // Read the most recent fileName from PlayerPrefs if (PlayerPrefs.HasKey("fileName")) { mapNameInput.text = PlayerPrefs.GetString("fileName"); } #endif ROOM_HAS_CONTENT = new bool[mapSize, mapSize]; // Set up EditorTiles for each position on the map float x0 = size / 8f; float y0 = size / 8f; for (int j = 0; j < roomH; j++) { for (int i = 0; i < roomW; i++) { GameObject go = Instantiate(uiTilePrefab); go.name = i.ToString("D3") + "x" + j.ToString("D3"); EditorTile et = go.GetComponent <EditorTile>(); et.x = i; et.y = j; RectTransform rt = go.GetComponent <RectTransform>(); rt.SetParent(mapAnchor); rt.anchoredPosition = new Vector2(x0 + (i * size), y0 + (j * size)); roomTiles[i, j] = et; } } // LoadMap(); }
IEnumerable <MapGrh> GetFillMapGrhs(EditorMap map, Vector2 worldPos) { MapGrh mapGrh = MapGrhPencilTool.GetGrhToSelect(map, worldPos); HashSet <MapGrh> ret = new HashSet <MapGrh>(); GetFillMapGrhs(map, mapGrh, ret); return(ret.ToArray()); }
/// <summary> /// Handles both mouse clicks and moves (does the place/deletes of grhs). /// </summary> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> void HandleMouseClickAndMove(EditorMap map, ICamera2D camera, MouseEventArgs e) { // Update some vars var cursorPos = e.Position(); _mouseOverMap = map; _mousePos = cursorPos; // Don't do any place/deletes while selecting if (IsSelecting) { return; } Vector2 worldPos = camera.ToWorld(cursorPos); // Handle mouse if (e.Button == MouseButtons.Left) { if (!Input.IsShiftDown) { // Place grh PlaceMapGrhAtScreenPos(map, camera, cursorPos, !Input.IsCtrlDown); } else { // Select grh under cursor var grhToSelect = GetGrhToSelect(map, worldPos); if (grhToSelect != null) { GlobalState.Instance.Map.SetGrhToPlace(grhToSelect.Grh.GrhData.GrhIndex); GlobalState.Instance.Map.Layer = grhToSelect.MapRenderLayer; GlobalState.Instance.Map.LayerDepth = grhToSelect.LayerDepth; } } } else if (e.Button == MouseButtons.Right) { if (!Input.IsShiftDown) { // Delete from current layer var grhToDelete = GetGrhToSelect(map, worldPos, mustBeOnLayer: GlobalState.Instance.Map.Layer); if (grhToDelete != null) { map.RemoveMapGrh(grhToDelete); } } else { // Delete from all layers var grhToSelect = GetGrhToSelect(map, worldPos); if (grhToSelect != null) { map.RemoveMapGrh(grhToSelect); } } } }
/// <summary> /// When overridden in the derived class, gets if this cursor can select the given object. /// </summary> /// <param name="map">The map containing the object to be selected.</param> /// <param name="obj">The object to try to select.</param> /// <returns> /// True if the <paramref name="obj"/> can be selected and handled by this cursor; otherwise false. /// </returns> protected override bool CanSelect(EditorMap map, object obj) { if (Input.IsKeyDown(_placeMapGrhKey)) { return(false); } return((obj is MapGrh) && base.CanSelect(map, obj)); }
/// <summary> /// Handles when the mouse moves over a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseMove(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { base.MapContainer_MouseMove(sender, map, camera, e); var cursorPos = e.Position(); _mouseOverMap = map; _mousePos = cursorPos; }
/// <summary> /// Gets the selectable object currently under the cursor. /// </summary> /// <param name="map">The <see cref="EditorMap"/>.</param> /// <param name="worldPos">The world position.</param> /// <returns>The selectable object currently under the cursor, or null if none.</returns> protected override object GetObjUnderCursor(EditorMap map, Vector2 worldPos) { var closestLight = map.Lights.MinElementOrDefault(x => worldPos.QuickDistance(x.Center)); if (closestLight == null) return null; if (worldPos.QuickDistance(closestLight.Center) > 10) return null; return closestLight; }
private void PartTreeView_AfterSelect(object sender, TreeViewEventArgs e) { if (!m_mapNodeMap.ContainsKey(e.Node)) { return; } m_selectedMap = m_mapNodeMap[e.Node]; PartDescLabel.Text = "Parts List: " + m_selectedMap.Name; UpdateImageBox(true, true); }
/// <summary> /// Handles the KeyDown event of this Cursor tool. If the Control key is down then it will shift any selected <see cref="ISpatial"/>'s to the direction of the pressed arrow keys. /// </summary> protected override void MapContainer_KeyDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, KeyEventArgs e) { var som = GlobalState.Instance.Map.SelectedObjsManager; if (!e.Control) { return; } switch (e.KeyCode) { case Keys.Left: { var left = new Vector2(-1, 0); foreach (var entity in som.SelectedObjects.OfType <ISpatial>()) { entity.TryMove(entity.Position + left); } } break; case Keys.Right: { var right = new Vector2(1, 0); foreach (var entity in som.SelectedObjects.OfType <ISpatial>()) { entity.TryMove(entity.Position + right); } } break; case Keys.Up: { var up = new Vector2(0, -1); foreach (var entity in som.SelectedObjects.OfType <ISpatial>()) { entity.TryMove(entity.Position + up); } } break; case Keys.Down: { var down = new Vector2(0, 1); foreach (var entity in som.SelectedObjects.OfType <ISpatial>()) { entity.TryMove(entity.Position + down); } } break; } }
/// <summary> /// Handles both mouse clicks and moves. /// </summary> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> void HandleMouseClickAndMove(EditorMap map, ICamera2D camera, MouseEventArgs e) { // Update some vars var cursorPos = e.Position(); _mouseOverMap = map; _mousePos = cursorPos; var globalState = GlobalState.Instance; var currentGrhData = globalState.Map.GrhToPlace.GrhData; Vector2 worldPos = camera.ToWorld(cursorPos); // Handle mouse if (e.Button == MouseButtons.Left) { if (!Input.IsShiftDown) { // Fill if (currentGrhData != null) { var mapGrhsToReplace = GetFillMapGrhs(map, worldPos); foreach (var mapGrh in mapGrhsToReplace) { mapGrh.Grh.SetGrh(currentGrhData); } } } else { // Select grh under cursor var grhToSelect = MapGrhPencilTool.GetGrhToSelect(map, worldPos); if (grhToSelect != null) { globalState.Map.SetGrhToPlace(grhToSelect.Grh.GrhData.GrhIndex); globalState.Map.Layer = grhToSelect.MapRenderLayer; globalState.Map.LayerDepth = grhToSelect.LayerDepth; } } } else if (e.Button == MouseButtons.Right) { // Fill-delete if (currentGrhData != null) { var mapGrhsToReplace = GetFillMapGrhs(map, worldPos); foreach (var mapGrh in mapGrhsToReplace) { map.RemoveMapGrh(mapGrh); } } } }
/// <summary> /// Handles the KeyDown event of this Cursor tool. If the Control key is down then it will shift any selected <see cref="ISpatial"/>'s to the direction of the pressed arrow keys. /// </summary> protected override void MapContainer_KeyDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, KeyEventArgs e) { if (!e.Alt && !e.Shift && !e.Control) { int?num = e.KeyCode.GetNumericKeyAsValue(); if (num.HasValue && num.Value > 0 && num.Value < 10) { GlobalState.Instance.SetGrhFromHotkey(num.Value); } } base.MapContainer_KeyDown(sender, map, camera, e); }
/// <summary> /// Handles when a key is pressed on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_KeyDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, KeyEventArgs e) { if (map != null) { // Save (Ctrl + Shift + S) if (e.KeyCode == Keys.S && e.Control && e.Shift) { MapHelper.SaveMapAs(map, false); return; } } base.MapContainer_KeyDown(sender, map, camera, e); }
void GetFillMapGrhs(EditorMap map, MapGrh mapGrh, HashSet <MapGrh> ret) { if (mapGrh == null || !ret.Add(mapGrh)) { return; } Rectangle rect = new Rectangle(mapGrh.Position.X - 1, mapGrh.Position.Y - 1, mapGrh.Size.X + 2, mapGrh.Size.Y + 2); foreach (var mg in map.Spatial.GetMany <MapGrh>(rect, x => x.Grh != null && x.Grh.GrhData == mapGrh.Grh.GrhData)) { GetFillMapGrhs(map, mg, ret); } }
void NewMap() { System.Windows.Forms.SaveFileDialog dialog = new System.Windows.Forms.SaveFileDialog(); dialog.FileName = "New Map.json"; System.Windows.Forms.DialogResult result = dialog.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { ReadJson jsonReader = new ReadJson(); WriteJson jsonWrite = new WriteJson(); jsonWrite.WriteData(dialog.FileName, jsonReader.ReadData("Data/EmptyMap.json")); map = new EditorMap(jsonReader.ReadData("Data/EmptyMap.json"), ref cam); currentMapPath = dialog.FileName; } }
public void OnPointerClick(PointerEventData eventData) { if (eventData.button == PointerEventData.InputButton.Left) { EditorMap.ChangeTile(this); } else if (eventData.button == PointerEventData.InputButton.Middle) { // Do nothing } else if (eventData.button == PointerEventData.InputButton.Right) { EditorMap.CopyTile(this); } }
void LoadMap() { System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog(); dialog.Multiselect = false; dialog.RestoreDirectory = false; dialog.Filter = "JSON Files (.json)|*.json"; System.Windows.Forms.DialogResult result = dialog.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { ReadJson jsonReader = new ReadJson(); map = new EditorMap(jsonReader.ReadData(dialog.FileName), ref cam); currentMapPath = dialog.FileName; } }
protected override void Initialize() { niveaux = MapXml.getListNiveauxName(); currentState = GameState.Start; nView = new NiveauxView(Content); nController = new NiveauxController(); mController = new MainController(); mView = new MainView(Content); menu = new Menu(Content); editor = new EditorMap(600, 600); viewEditor = new EditorMapView(Content); controllerEditor = new EditorMapController(); base.Initialize(); }
/// <summary> /// Gets the selectable object currently under the cursor. /// </summary> /// <param name="map">The <see cref="EditorMap"/>.</param> /// <param name="worldPos">The world position.</param> /// <returns>The selectable object currently under the cursor, or null if none.</returns> protected override object GetObjUnderCursor(EditorMap map, Vector2 worldPos) { var closestLight = map.Lights.MinElementOrDefault(x => worldPos.QuickDistance(x.Center)); if (closestLight == null) { return(null); } if (worldPos.QuickDistance(closestLight.Center) > 10) { return(null); } return(closestLight); }
/// <summary> /// Handles when the mouse button is raised on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseUp(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { if (IsSelecting && IsSelectMouseButton(e.Button)) { // End the mass selection _selectionEnd = camera.ToWorld(e.Position()); var area = Rectangle.FromPoints(_selectionStart, _selectionEnd); MapContainer_AreaSelected(map, camera, area, e); _isSelecting = false; _selectionStart = Vector2.Zero; _selectionEnd = Vector2.Zero; } base.MapContainer_MouseUp(sender, map, camera, e); }
public void MakeCustomStageClicked(int try_count) { Debug.Log("connect try : " + try_count); if (try_count >= 5) { //AWSManager.instance.ConnectWithAWS(true); return; } string title_regex = "^[a-zA-Z가-힣0-9]{1}[a-zA-Z가-힣0-9\\s]{0,6}[a-zA-Z가-힣0-9]{1}$"; Regex regex = new Regex(title_regex); if (regex.IsMatch(titleInputField.text)) { //AWSManager.instance.ConnectWithAWS(false); Debug.Log("match"); Map newMap = GameController.instance.GetMap(); newMap.map_title = titleInputField.text.ToString(); EditorMap editorMap = new EditorMap(map: newMap, nick: AWSManager.instance.userInfo.nickname, moveCount: move); JsonAdapter.instance.CreateEditorMap(editorMap, CreateEditorMapCallback); //AWSManager.instance.CreateEditorMap(newMap, move, dif, CreateEditorMapCallback ); //성공 시 로비로 이동 //실패 시 --> 연결 문제 --> 재시도 //재시도 횟수 ?번이상일 시 통신 문제 출력 } else { Debug.Log("no match"); titleInputField.text = ""; StopAllCoroutines(); StartCoroutine(WarningText()); } //Web Request }
/// <summary> /// Handles what happens when an area of the map is selected. /// </summary> protected override void MapContainer_AreaSelected(EditorMap map, ICamera2D camera, Rectangle selectionArea, MouseEventArgs e) { var gridAligner = GridAligner.Instance; if ((e.Button & MouseButtons.Left) != 0) { var grhDataToPlace = GlobalState.Instance.Map.GrhToPlace.GrhData; if (grhDataToPlace == null) { return; } // Place sprites over the selection area if ((Control.ModifierKeys & Keys.Control) == 0) { // Place on grid Vector2 startPos = gridAligner.Align(new Vector2(selectionArea.Left, selectionArea.Top)); Vector2 endPos = gridAligner.Align(new Vector2(selectionArea.Right, selectionArea.Bottom)); for (int x = (int)startPos.X; x <= endPos.X; x += (int)gridAligner.GridSize.X) { for (int y = (int)startPos.Y; y <= endPos.Y; y += (int)gridAligner.GridSize.Y) { PlaceMapGrhAtWorldPos(map, new Vector2(x, y), true, grhDataToPlace); } } } else { // Place freely Vector2 startPos = new Vector2(selectionArea.Left, selectionArea.Top); Vector2 endPos = new Vector2(selectionArea.Right, selectionArea.Bottom) - grhDataToPlace.Size; for (int x = (int)startPos.X; x <= (int)endPos.X; x += (int)grhDataToPlace.Size.X) { for (int y = (int)startPos.Y; y <= (int)endPos.Y; y += (int)grhDataToPlace.Size.Y) { PlaceMapGrhAtWorldPos(map, new Vector2(x, y), false, grhDataToPlace); } } } } }
public void CheckRoomImage() { if (EditorMap.MAP == null) { return; } // Check to see if this room has content. // It might be better if this chunk of code was elsewhere, but it will work here. - JB int x0, y0; Vector2 mLoc = EditorMap.RoomToMap(x, y); x0 = (int)mLoc.x; y0 = (int)mLoc.y; bool contentInRoom = false; for (int i = x0 + 1; i < x0 + EditorMap.ROOM_W - 1; i++) { for (int j = y0 + 1; j < y0 + EditorMap.ROOM_H - 1; j++) { if (EditorMap.MAP[i, j] != 0) { contentInRoom = true; break; } } } EditorMap.ROOM_HAS_CONTENT[x, y] = contentInRoom; // This chunk of code should definitely be here. - JB if (EditorMap.ROOM_X == x && EditorMap.ROOM_Y == y) { sprite = EditorMiniMap.SPRITE_ON; } else if (EditorMap.ROOM_HAS_CONTENT[x, y]) { sprite = EditorMiniMap.SPRITE_GRAY; } else { sprite = EditorMiniMap.SPRITE_OFF; } }
/// <summary> /// Gets if the given object is visible according to the drawing filter currently being used. /// Objects that are never drawn or are never filtered always return true, even if they are not actually visible. /// </summary> /// <param name="map">The current map.</param> /// <param name="obj">The object to check if visible.</param> /// <returns>True if the <paramref name="obj"/> is visible or not applicable to the map drawing filter; otherwise false.</returns> protected virtual bool IsObjectVisible(EditorMap map, object obj) { var drawable = obj as IDrawable; if (drawable == null) { return(true); } if (map == null) { return(true); } if (map.DrawFilter == null) { return(true); } return(map.DrawFilter(drawable)); }
/// <summary> /// Handles when the mouse button is raised on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseUp(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { if (IsSelecting && e.Button == SelectMouseButton) { // End the mass selection _selectionEnd = camera.ToWorld(e.Position()); var area = Rectangle.FromPoints(_selectionStart, _selectionEnd); var selected = CursorSelectObjects(map, area); GlobalState.Instance.Map.SelectedObjsManager.SetManySelected(selected); _isSelecting = false; _selectionStart = Vector2.Zero; _selectionEnd = Vector2.Zero; } base.MapContainer_MouseUp(sender, map, camera, e); }
public IEnumerator InfiniteMAP(int level, System.Action <Map> callback) { UnityWebRequest www = UnityWebRequest.Get(PrivateData.ec2 + "map/difficulty?difficulty=" + level + "&nickname=" + GameManager.instance.id); yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); callback(null); } else { // Show results as text Debug.Log(www.downloadHandler.text); // Or retrieve results as binary data byte[] results = www.downloadHandler.data; //Get data and convert to samplemap list.. string fixdata = JsonHelper.fixJson(www.downloadHandler.text); EditorMap[] datas = JsonHelper.FromJson <EditorMap>(fixdata); EditorMap selectedData = datas[Random.Range(0, datas.Length)]; //editorMap.Initialize(selectedData); Debug.Log(editorMap.mapsizeH + "," + editorMap.mapsizeW + "," + editorMap.startPositionA); liveMap = editorMap; callback(liveMap); //selectedData.DataToString();//Debug.Log liveMap.gameObject.SetActive(true); MakeMap(liveMap.mapsizeH, liveMap.mapsizeW, liveMap.parfait); } yield break; }
public void CreateEditorMap(EditorMap editorMap, BooleanCallback callback) { var json = JsonUtility.ToJson(editorMap); StartCoroutine(API_POST("editorMap/insert", json, (connect, response) => { if (connect) { //성공알림 Debug.Log("success create editorMap"); //xml.database.userFriend.Add(editorMap); Debug.Log(response); callback(true); } else { Debug.LogError(response); callback(false); //재시도 } })); }
/// <summary> /// Gets the map objects to select in the given region. /// </summary> /// <param name="map">The <see cref="EditorMap"/>.</param> /// <param name="selectionArea">The selection box area.</param> /// <returns>The objects to select.</returns> protected override IEnumerable<object> CursorSelectObjects(EditorMap map, Rectangle selectionArea) { return map.Lights.Where(x => x.Intersects(selectionArea)).Cast<object>(); }
/// <summary> /// Handles when a mouse button is pressed on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { // Terminate any current area selection when any mouse button is pressed _selectionStart = Vector2.Zero; _selectionEnd = Vector2.Zero; _isSelecting = false; var worldPos = camera.ToWorld(e.Position()); var underCursor = GetObjUnderCursor(map, worldPos); GlobalState.Instance.Map.SelectedObjsManager.SetSelected(underCursor); if (e.Button == SelectMouseButton && ((Control.ModifierKeys & SelectKey) != 0)) { // Start area selection _selectionStart = worldPos; _selectionEnd = _selectionStart; _isSelecting = true; } base.MapContainer_MouseDown(sender, map, camera, e); }
/// <summary> /// Handles when a mouse button is pressed on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { base.MapContainer_MouseDown(sender, map, camera, e); if (IsSelecting) return; // Left-click if (e.Button == MouseButtons.Left) { // Place light if (Input.IsKeyDown(_placeLightKey)) { var msc = MapScreenControl.TryFindInstance(map); if (msc != null) { var dm = msc.DrawingManager; if (dm != null) { var pos = camera.ToWorld(e.Position()); pos = GridAligner.Instance.Align(pos); var light = new Light { Center = pos, IsEnabled = true, Tag = map }; map.AddLight(light); dm.LightManager.Add(light); } } } } }
/// <summary> /// When overridden in the derived class, gets if this cursor can select the given object. /// </summary> /// <param name="map">The map containing the object to be selected.</param> /// <param name="obj">The object to try to select.</param> /// <returns> /// True if the <paramref name="obj"/> can be selected and handled by this cursor; otherwise false. /// </returns> protected override bool CanSelect(EditorMap map, object obj) { if (Input.IsKeyDown(_placeMapGrhKey)) return false; return (obj is MapGrh) && base.CanSelect(map, obj); }
void GetFillMapGrhs(EditorMap map, MapGrh mapGrh, HashSet<MapGrh> ret) { if (mapGrh == null || !ret.Add(mapGrh)) return; Rectangle rect = new Rectangle(mapGrh.Position.X - 1, mapGrh.Position.Y - 1, mapGrh.Size.X + 2, mapGrh.Size.Y + 2); foreach (var mg in map.Spatial.GetMany<MapGrh>(rect, x => x.Grh != null && x.Grh.GrhData == mapGrh.Grh.GrhData)) { GetFillMapGrhs(map, mg, ret); } }
protected virtual void OnMapChanged(EditorMap oldValue, EditorMap newValue) { Text = string.Format("NPC Spawns (Map: {0})", newValue != null ? newValue.ToString() : "None"); lstSpawns.Map = newValue; }
protected virtual void OnMapChanged(EditorMap oldValue, EditorMap newValue) { Text = string.Format("BG Images (Map: {0})", newValue != null ? newValue.ToString() : "None"); RebuildList(); }
static string GetFormText(EditorMap map) { return "Map properties: " + (map == null ? "(No map loaded)" : map.ToString()); }
protected virtual void OnMapChanged(EditorMap oldValue, EditorMap newValue) { Text = GetFormText(newValue); pg.SelectedObject = newValue; }
/// <summary> /// When overridden in the derived class, gets if this cursor can select the given object. /// </summary> /// <param name="map">The map containing the object to be selected.</param> /// <param name="obj">The object to try to select.</param> /// <returns> /// True if the <paramref name="obj"/> can be selected and handled by this cursor; otherwise false. /// </returns> protected override bool CanSelect(EditorMap map, object obj) { return false; }
/// <summary> /// Handles the KeyDown event of this Cursor tool. If the Control key is down then it will shift any selected <see cref="ISpatial"/>'s to the direction of the pressed arrow keys. /// </summary> protected override void MapContainer_KeyDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, KeyEventArgs e) { if (!e.Alt && !e.Shift && !e.Control) { int? num = e.KeyCode.GetNumericKeyAsValue(); if (num.HasValue && num.Value > 0 && num.Value < 10) { GlobalState.Instance.SetGrhFromHotkey(num.Value); } } base.MapContainer_KeyDown(sender, map, camera, e); }
/// <summary> /// Handles when the mouse wheel is moved while over a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseWheel(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { // Change the current depth int modDepth = 0; if (e.Delta < 0) modDepth = -1; else if (e.Delta > 0) modDepth = 1; if (modDepth != 0) { var currDepth = GlobalState.Instance.Map.LayerDepth; short newDepth = (short)(currDepth + modDepth).Clamp(short.MinValue, short.MaxValue); GlobalState.Instance.Map.LayerDepth = newDepth; } base.MapContainer_MouseWheel(sender, map, camera, e); }
/// <summary> /// Handles when the mouse moves over a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseMove(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { HandleMouseClickAndMove(map, camera, e); base.MapContainer_MouseMove(sender, map, camera, e); }
/// <summary> /// When overridden in the derived class, gets if this cursor can select the given object. /// </summary> /// <param name="map">The map containing the object to be selected.</param> /// <param name="obj">The object to try to select.</param> /// <returns> /// True if the <paramref name="obj"/> can be selected and handled by this cursor; otherwise false. /// </returns> protected override bool CanSelect(EditorMap map, object obj) { return (obj is Entity) && !(obj is CharacterEntity) && !(obj is WallEntity) && base.CanSelect(map, obj); }
IEnumerable<MapGrh> GetFillMapGrhs(EditorMap map, Vector2 worldPos) { MapGrh mapGrh = MapGrhPencilTool.GetGrhToSelect(map, worldPos); HashSet<MapGrh> ret = new HashSet<MapGrh>(); GetFillMapGrhs(map, mapGrh, ret); return ret.ToArray(); }
/// <summary> /// Handles when the mouse wheel is moved while over a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseWheel(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { int modDepth = 0; if (e.Delta < 0) modDepth = -1; else if (e.Delta > 0) modDepth = 1; if (modDepth != 0) { // Change layer depth, making sure it is clamped in the needed range foreach (var mapGrh in GlobalState.Instance.Map.SelectedObjsManager.SelectedObjects.OfType<MapGrh>()) { if (map.Spatial.CollectionContains(mapGrh)) { mapGrh.LayerDepth = (short)(mapGrh.LayerDepth + modDepth).Clamp(short.MinValue, short.MaxValue); } } GlobalState.Instance.Map.SelectedObjsManager.UpdateFocused(); } base.MapContainer_MouseWheel(sender, map, camera, e); }
/// <summary> /// Handles when the mouse moves over a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseMove(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { _mouseOverMap = map; var worldPos = camera.ToWorld(e.Position()); if (IsSelecting) { // Expand selection area _selectionEnd = worldPos; } else { // Create the tooltip var font = ToolTipFont; if (ShowObjectToolTip && font != null) { var hoverEntity = GetObjUnderCursor(map, worldPos); if (hoverEntity == null) { // Nothing under the cursor that we are allowed to select _toolTip = string.Empty; _toolTipObject = null; } else if (_toolTipObject != hoverEntity) { // Something found under the cursor _toolTipObject = hoverEntity; _toolTipPos = e.Position(); _toolTip = GetObjectToolTip(hoverEntity) ?? hoverEntity.ToString(); // Make sure the text stays in the view area const int toolTipPadding = 4; var toolTipSize = font.MeasureString(_toolTip); if (_toolTipPos.X < toolTipPadding) _toolTipPos.X = toolTipPadding; else if (_toolTipPos.X + toolTipSize.X + toolTipPadding > camera.Size.X) _toolTipPos.X = camera.Size.X - toolTipSize.X - toolTipPadding; if (_toolTipPos.Y < toolTipPadding) _toolTipPos.Y = toolTipPadding; else if (_toolTipPos.Y + toolTipSize.Y + toolTipPadding > camera.Size.Y) _toolTipPos.Y = camera.Size.Y - toolTipSize.Y - toolTipPadding; } } } base.MapContainer_MouseMove(sender, map, camera, e); }
/// <summary> /// Handles when the mouse button is raised on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseUp(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { var cursorPos = e.Position(); var worldPos = camera.ToWorld(cursorPos); // Create entity if (e.Button == MouseButtons.Right) { Type createType = null; // Create using same type as the last entity, if possible if (Input.IsCtrlDown) createType = _lastCreatedType; // Display selection dialog if (createType == null) { using (var frm = new EntityTypeUITypeEditorForm(_lastCreatedType)) { if (frm.ShowDialog(sender as IWin32Window) == DialogResult.OK) createType = frm.SelectedItem; } } // Create the type if (createType != null) { _lastCreatedType = null; try { // Create the Entity var entity = (Entity)Activator.CreateInstance(createType); map.AddEntity(entity); entity.Size = new Vector2(64); entity.Position = worldPos - (entity.Size / 2f); GridAligner.Instance.Fit(entity); _lastCreatedType = createType; } catch (Exception ex) { const string errmsg = "Failed to create entity of type `{0}` on map `{1}`. Exception: {2}"; if (log.IsErrorEnabled) log.ErrorFormat(errmsg, createType, map, ex); Debug.Fail(string.Format(errmsg, createType, map, ex)); } } } base.MapContainer_MouseUp(sender, map, camera, e); }
/// <summary> /// Handles when a mouse button is pressed on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { var wasMapGrhPlaced = false; if (e.Button == MouseButtons.Left) { // Left-click if (Input.IsKeyDown(_placeMapGrhKey)) { PlaceMapGrh(map, camera, e.Position(), TileMode); wasMapGrhPlaced = true; } } base.MapContainer_MouseDown(sender, map, camera, e); if (wasMapGrhPlaced) SOM.Clear(); }
/// <summary> /// Handles when the mouse moves over a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseMove(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { base.MapContainer_MouseMove(sender, map, camera, e); var cursorPos = e.Position(); _mouseOverMap = map; _mousePos = cursorPos; // Support dragging operations when using TileMode if (TileMode) { if (Input.IsKeyDown(_placeMapGrhKey)) { if (e.Button == MouseButtons.Left) { // Drag placement PlaceMapGrh(map, camera, e.Position(), true); } else if (e.Button == MouseButtons.Right) { // Drag delete var worldPos = camera.ToWorld(e.Position()); worldPos = GridAligner.Instance.Align(worldPos, true); var worldPosArea = worldPos.ToRectangle(Vector2.One, false); var toDelete = map.Spatial.GetMany<MapGrh>(worldPosArea, x => IsObjectVisible(map, x)); foreach (var x in toDelete) { map.RemoveMapGrh(x); } } } } }
/// <summary> /// When overridden in the derived class, gets if this cursor can select the given object. /// </summary> /// <param name="map">The map containing the object to be selected.</param> /// <param name="obj">The object to try to select.</param> /// <returns> /// True if the <paramref name="obj"/> can be selected and handled by this cursor; otherwise false. /// </returns> protected override bool CanSelect(EditorMap map, object obj) { return (obj is MapGrh) && base.CanSelect(map, obj); }
/// <summary> /// Handles when the mouse wheel is moved while over a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseWheel(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { if (e.Delta == 0) return; // Only change depth on selected MapGrh if only one is selected var focusedMapGrh = GlobalState.Instance.Map.SelectedObjsManager.SelectedObjects.FirstOrDefault() as MapGrh; if (focusedMapGrh == null) return; // Require the MapGrh to be on the map the scroll event took place on if (!map.Spatial.CollectionContains(focusedMapGrh)) return; // Change layer depth, making sure it is clamped in the needed range focusedMapGrh.LayerDepth = (short)(focusedMapGrh.LayerDepth + e.Delta).Clamp(short.MinValue, short.MaxValue); base.MapContainer_MouseWheel(sender, map, camera, e); }
/// <summary> /// When overridden in the derived class, gets if this cursor can select the given object. /// </summary> /// <param name="map">The map containing the object to be selected.</param> /// <param name="obj">The object to try to select.</param> /// <returns>True if the <paramref name="obj"/> can be selected and handled by this cursor; otherwise false.</returns> protected virtual bool CanSelect(EditorMap map, object obj) { return IsObjectVisible(map, obj); }