public Hex(Index2D inx, Point center, HexType type, int height) { r = GlobalConst.DEFAULT_r; a = 2d / Math.Sqrt(3) * r; index = inx; this.type = type; this.height = height; if (type != HexType.Empty) render = new HexRender(DisplayType.GAME_SimpleGround, height, center); }
public HexGrid(UIElementCollection ui, Action<List<Point>> onSelected) { _i = this; this.real_r = GlobalConst.DEFAULT_r; this.real_a = 2.0 / Math.Sqrt(3) * real_r; this.worldOrigin = new Point(0, 0); this.ui = ui; selectableHex = new HexRender(DisplayType.FUNC_Selectable); ui.Add(selectableHex); this.onSelected = onSelected; hexPen = new Pen { Brush = Brushes.BlueViolet, Thickness = 2, StartLineCap = PenLineCap.Round, EndLineCap = PenLineCap.Round }; }
private void DuringSelect(Point point) { selectCurrent = point; int[] size; var points = GetHexInWorldAreaFromScreen(selectStart, selectCurrent.X - selectStart.X, selectCurrent.Y - selectStart.Y, out size, true); selectableArea.RemoveAll((hex) => { ui.Remove(hex); return true; }); points.ForEach((p) => { var hex = new HexRender(DisplayType.FUNC_Selectable); hex.WorldCenter = p; selectableArea.Add(hex); }); selectableArea.ForEach((hex) => { hex.Refresh(); ui.Add(hex); }); }
public void OnSelect() { selectedArea.RemoveAll((hex) => { ui.Remove(hex); return true; }); if (selectableArea.Count == 0) { var selectedHex = new HexRender(DisplayType.FUNC_Selected); selectedHex.Refresh(selectableHex.WorldCenter); ui.Add(selectedHex); selectedArea.Add(selectedHex); } else selectedArea = new List<HexRender>(selectableArea); selectedArea.ForEach((hex) => { hex.DisplayType = DisplayType.FUNC_Selected; }); onSelected(selectedArea.ConvertAll((hex) => hex.WorldCenter)); }