|
8 | 8 | using SS14.Shared.Utility;
|
9 | 9 | using SS14.Shared.Maths;
|
10 | 10 | using System;
|
| 11 | +using OpenTK.Graphics; |
11 | 12 |
|
12 | 13 | namespace SS14.Client.Placement.Modes
|
13 | 14 | {
|
14 | 15 | public class SnapgridBorder : PlacementMode
|
15 | 16 | {
|
| 17 | + bool ongrid; |
| 18 | + float snapsize; |
| 19 | + |
16 | 20 | public SnapgridBorder(PlacementManager pMan) : base(pMan)
|
17 | 21 | {
|
18 | 22 | }
|
19 | 23 |
|
| 24 | + public override void Render() |
| 25 | + { |
| 26 | + base.Render(); |
| 27 | + if (ongrid) |
| 28 | + { |
| 29 | + var position = CluwneLib.ScreenToWorld(new Vector2i(0,0)); //Find world coordinates closest to screen origin |
| 30 | + var gridstart = CluwneLib.WorldToScreen(new Vector2( //Find snap grid closest to screen origin and convert back to screen coords |
| 31 | + (float)Math.Round((position.X / (double)snapsize), MidpointRounding.AwayFromZero) * snapsize, |
| 32 | + (float)Math.Round((position.Y / (double)snapsize), MidpointRounding.AwayFromZero) * snapsize)); |
| 33 | + for (float a = gridstart.X; a < CluwneLib.ScreenViewportSize.X; a += snapsize * 32) //Iterate through screen creating gridlines |
| 34 | + { |
| 35 | + CluwneLib.drawLine(a, 0, CluwneLib.ScreenViewportSize.Y, 90, 0.5f, Color4.Blue); |
| 36 | + } |
| 37 | + for (float a = gridstart.Y; a < CluwneLib.ScreenViewportSize.Y; a += snapsize * 32) |
| 38 | + { |
| 39 | + CluwneLib.drawLine(0, a, CluwneLib.ScreenViewportSize.X, 0, 0.5f, Color4.Blue); |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | + |
20 | 44 | public override bool Update(Vector2i mouseS, IMapManager currentMap)
|
21 | 45 | {
|
22 | 46 | if (currentMap == null) return false;
|
23 | 47 |
|
24 | 48 | mouseScreen = mouseS;
|
25 | 49 | mouseWorld = CluwneLib.ScreenToWorld(mouseScreen);
|
26 | 50 |
|
27 |
| - if (!currentMap.TryFindGridAt(mouseWorld, out IMapGrid currentgrid)) //Cant find a grid |
| 51 | + if (! (ongrid = currentMap.TryFindGridAt(mouseWorld, out IMapGrid currentgrid))) //Cant find a grid |
28 | 52 | return false;
|
29 | 53 |
|
30 | 54 | var mouselocal = currentgrid.WorldToLocal(mouseWorld); //Convert code to local grid coordinates
|
31 |
| - var snapsize = currentgrid.SnapSize; //Find snap size |
| 55 | + snapsize = currentgrid.SnapSize; //Find snap size. |
| 56 | + |
32 | 57 | mouselocal = new Vector2( //Round local coordinates onto the snap grid
|
33 | 58 | (float)Math.Round((mouselocal.X / (double)snapsize), MidpointRounding.AwayFromZero) * snapsize,
|
34 | 59 | (float)Math.Round((mouselocal.Y / (double)snapsize), MidpointRounding.AwayFromZero) * snapsize);
|
35 |
| - |
| 60 | + |
36 | 61 | //Convert back to original world and screen coordinates after applying offset
|
37 | 62 | mouseWorld = currentgrid.LocalToWorld(mouselocal) + new Vector2(pManager.CurrentPrototype.PlacementOffset.X, pManager.CurrentPrototype.PlacementOffset.Y);
|
38 | 63 | mouseScreen = (Vector2i)CluwneLib.WorldToScreen(mouseWorld);
|
|
0 commit comments