void Unit_Tick(unit.events.BasicUnitEvent unitEvent) { if (!(unitEvent.unit.OutputInfo is UnitOutputInfoWPF outInfo)) { return; } double pixelPerTurnX = cellSize.X / unitEvent.unit.tickPerTurn; double pixelPerTurnY = cellSize.Y / unitEvent.unit.tickPerTurn; double length = UnitOutputInfoWPF.shiftX + unitEvent.unit.X * cellSize.X; if (unitEvent.unit.X > unitEvent.unit.NextX) { length -= unitEvent.unit.currTickOnCell * pixelPerTurnX; } else if (unitEvent.unit.X < unitEvent.unit.NextX) { length += unitEvent.unit.currTickOnCell * pixelPerTurnX; } Canvas.SetLeft(outInfo.grid, length); length = UnitOutputInfoWPF.shiftY + unitEvent.unit.Y * cellSize.Y; if (unitEvent.unit.Y > unitEvent.unit.NextY) { length -= unitEvent.unit.currTickOnCell * pixelPerTurnY; } else if (unitEvent.unit.Y < unitEvent.unit.NextY) { length += unitEvent.unit.currTickOnCell * pixelPerTurnY; } Canvas.SetTop(outInfo.grid, length); }
//---------------------------------------------- Events - unit ---------------------------------------------- void Unit_FirstTick(unit.events.BasicUnitEvent unitEvent) { if (!(unitEvent.unit.OutputInfo is UnitOutputInfoWPF outInfo)) { return; } Grid unitGrid = new Grid(); Shape unitShape = new Ellipse() { VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }; SetShapeStyle(unitShape, unitEvent.unit.PlayerId); Grid.SetZIndex(unitShape, 1); unitGrid.Children.Add(unitShape); TextBlock textBlock = new TextBlock { VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, Foreground = this.cityWarriorsCntStrokeColor, Text = unitEvent.unit.warriorsCnt.ToString(), }; Viewbox viewbox = new Viewbox() { VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, Child = textBlock, }; Grid.SetZIndex(viewbox, 2); unitGrid.Children.Add(viewbox); SetSizes(); mainGrid.SizeChanged += (a, b) => SetSizes(); mainCanvas.Children.Add(unitGrid); outInfo.grid = unitGrid; outInfo.shape = unitShape; outInfo.unitsCnt = textBlock; void SetSizes() { var s = GetSizeWithMod(this.unitSizeMod, unitIsSquere); unitGrid.Width = s.Item1; unitGrid.Height = s.Item2; unitShape.Width = s.Item1; unitShape.Height = s.Item2; viewbox.Width = s.Item1 * unitWarriorsCntRelativeMod; viewbox.Height = s.Item2 * unitWarriorsCntRelativeMod; } }