public void OnBecameInvisible() { currentBrush?.OnDisable(); currentBrush = null; LeaveEditorMode(); }
private void SwapMapBrushes(int newBrushId) { currentBrush.OnDisable(); currentBrush = mapBrushList[newBrushId]; currentBrush.OnEnable(this, currentEditor); CurrentBrushId = newBrushId; }
public bool SetHoverTerrain(int squareX, int squareY, IMapBrush brush, out Rectangle updateRectangle) { updateRectangle = new Rectangle(); if (squareX < 0 || squareX >= Width || squareY < 0 || squareY >= Width) { return(false); } MapState oldState = new MapState(stateHover.Width, stateHover.Height); oldState.CopyFrom(stateHover); if (!brush.NeedsDraw(state, squareX, squareY)) { ClearHoverTerrain(); updateRectangle = CalculateUpdateRectangle(oldState, stateHover); return(true); } if (!brush.NeedsDraw(stateHover, squareX, squareY)) { return(false); } ClearHoverTerrain(); brush.DrawAt(tileSet, stateHover, null /* rng */, squareX, squareY); updateRectangle = CalculateUpdateRectangle(oldState, stateHover); return(true); }
private void EnsureBrushEnabled() { if (currentBrush == null) { currentBrush = mapBrushList[CurrentBrushId]; } if (!currentBrush.IsEnabled()) { currentBrush.OnEnable(this, currentEditor); } }
public void LeaveEditorMode() { //Debug.Log("LeaveEditMode"); if (currentEditor != null) { currentEditor.LeaveEditMode(); } currentBrush?.OnDisable(); currentBrush = null; targetGameObject = null; //currentEditor = null; //currentData = null; }
public void SetTerrain(int squareX, int squareY, IMapBrush brush, out Rectangle updateRectangle) { updateRectangle = new Rectangle(); if (squareX < 0 || squareX >= Width || squareY < 0 || squareY >= Width) { return; } MapState oldState = new MapState(stateHover.Width, state.Height); oldState.CopyFrom(state); brush.DrawAt(tileSet, state, Rng, squareX, squareY); updateRectangle = CalculateUpdateRectangle(oldState, state); ClearHoverTerrain(); }
private void LoadBrushList() { var domain = AppDomain.CurrentDomain; var assemblies = domain.GetAssemblies(); var attrDictionary = new Dictionary <Type, MapBrushAttribute>(); var types = new List <Type>(); foreach (var a in assemblies) { foreach (var t in a.GetTypes()) { if (!types.Contains(t) && t.GetCustomAttribute(typeof(MapBrushAttribute)) is MapBrushAttribute attr) { attrDictionary.Add(t, attr); types.Add(t); } } } mapBrushList = new IMapBrush[types.Count]; mapBrushNames = new string[types.Count]; var sorted = types.OrderBy(t => attrDictionary[t].Order).ToList(); for (var i = 0; i < types.Count; i++) { var t = sorted[i]; if (Activator.CreateInstance(t) is IMapBrush brush) { mapBrushList[i] = brush; mapBrushNames[i] = attrDictionary[t].Name; } } if (CurrentBrushId > 0 && CurrentBrushId > mapBrushList.Length - 1) { CurrentBrushId = 0; } currentBrush = mapBrushList[CurrentBrushId]; }