public override void OnMouseDown(MouseButtonDownEventArgs e) { if (Ui.UIHovering) { return; } if (e.Button != (int)MouseButton.Left) { return; } ITile tile = Input.GetTileUnderCursor(); if (tile == null) { return; } IntRect rect = GetBuildingRectangle(tile, BuildingType); if (BuildingType.CanBuild(rect.TopLeft(), Input.Player, Level) && cost.HasResources(Input.Player)) { if (Level.BuildBuilding(BuildingType, rect.TopLeft(), Quaternion.Identity, Input.Player) != null) { cost.TakeFrom(Input.Player); } } }
public override void OnMouseUp(MouseButtonUpEventArgs e) { if (e.Button != (int)MouseButton.Left || line == null) { return; } if (ui.UIHovering) { ClearSelection(); return; } ITile endTile = input.GetTileUnderCursor(); if (endTile == null) { ClearSelection(); return; } if (endTile != line[line.Count - 1]) { line = GetLine(line[0], endTile); } if (cost.HasResources(input.Player, line.Count) && line.All((tile) => BuildingType.CanBuild(GetBuildingRectangle(tile, BuildingType).TopLeft(), input.Player, Level))) { foreach (var tile in line) { IBuilding newBuilding = Level.BuildBuilding(BuildingType, GetBuildingRectangle(tile, BuildingType).TopLeft(), Quaternion.Identity, input.Player); if (newBuilding == null) { break; } else { cost.TakeFrom(input.Player); } } } ClearSelection(); }
protected void HighlightBuildingRectangle() { if (Ui.UIHovering) { return; } ITile tile = Input.GetTileUnderCursor(); if (tile == null) { return; } IntRect rect = GetBuildingRectangle(tile, BuildingType); Color color = BuildingType.CanBuild(rect.TopLeft(), Input.Player, Level) && cost.HasResources(Input.Player) ? AbleColor : UnableColor; Map.HighlightRectangle(rect, color); }
public override void OnMouseMove(MHUrhoMouseMovedEventArgs e) { if (line == null) { ITile tile = input.GetTileUnderCursor(); if (tile == null) { return; } Color color = BuildingType.CanBuild(GetBuildingRectangle(tile, BuildingType).TopLeft(), input.Player, Level) && cost.HasResources(input.Player) ? AbleColor : UnableColor; Level.Map.HighlightTileList(new [] { tile }, color); return; } UpdateHighlight(); }
void UpdateHighlight() { ITile endTile = input.GetTileUnderCursor(); if (endTile == null) { Level.Map.DisableHighlight(); } if (endTile != line[line.Count - 1]) { line = GetLine(line[0], endTile); } Level.Map.HighlightTileList(line, line.All((tile) => BuildingType.CanBuild(GetBuildingRectangle(tile, BuildingType).TopLeft(), input.Player, Level)) && cost.HasResources(input.Player, line.Count) ? AbleColor : UnableColor); }
public override void OnMouseDown(MouseButtonDownEventArgs e) { if (e.Button != (int)MouseButton.Left || Ui.UIHovering) { return; } ITile tile = Input.GetTileUnderCursor(); if (tile == null) { return; } IntRect rect = GetBuildingRectangle(tile, BuildingType); if (BuildingType.CanBuild(rect.TopLeft(), Input.Player, Level)) { IBuilding building = Level.BuildBuilding(BuildingType, rect.TopLeft(), Quaternion.Identity, Input.Player); Tree tree = (Tree)building.BuildingPlugin; tree.SetSize((sizeSlider.Value / sizeSlider.Range) + startSize); } }