public void RandomData() { var random = new Random(); for (int i = 0; i < 100; i++) { Data.Add(new CityNeighbourhood() { Name = "Rand" + i, Location = new Point(random.Next(512), random.Next(512)) } ); } CityNeighbourhood.Init(Data); }
public override void Update(UpdateState state) { mp = state.MouseState.Position.ToVector2(); var md = state.MouseState.LeftButton == ButtonState.Pressed; CtrlDown = state.CtrlDown; ShiftDown = state.ShiftDown; if (md != MouseWasDown) { if (md) { if (ShiftDown) { var neigh = new CityNeighbourhood() { Location = new Point(256, 256), Name = "Neigh" + EditTarget.Count }; EditTarget.Add(neigh); Selected = neigh; } else { var closest = EditTarget.OrderBy(x => (City.Get2DFromTile(x.Location.X, x.Location.Y) - state.MouseState.Position.ToVector2()).Length()).FirstOrDefault(); if (closest != null && (City.Get2DFromTile(closest.Location.X, closest.Location.Y) - state.MouseState.Position.ToVector2()).Length() < 16) { if (CtrlDown) { EditTarget.Remove(closest); City.NeighGeom.Generate(GameFacade.GraphicsDevice); } else { Selected = closest; } } } } else { Selected = null; } MouseWasDown = md; } if (state.NewKeys.Contains(Keys.R)) { var proj = City.EstTileAtPosWithScroll(state.MouseState.Position.ToVector2(), null); var near = City.NeighGeom.NhoodNearest(proj); if (near != -1) { var nhood = City.NeighGeom.Data[near]; UIAlert.Prompt(new UIAlertOptions() { Message = "Rename this neighbourhood to what?", TextEntry = true }, (result, alert) => { if (result) { nhood.Name = alert.ResponseText; } }); } } if (state.NewKeys.Contains(Keys.C)) { var proj = City.EstTileAtPosWithScroll(state.MouseState.Position.ToVector2(), null); var near = City.NeighGeom.NhoodNearest(proj); if (near != -1) { var nhood = City.NeighGeom.Data[near]; UIAlert.Prompt(new UIAlertOptions() { Message = "Change this neighbourhood colour to what?", GenericAddition = new UIColorPicker() }, (result, alert) => { if (result) { var col = int.Parse(alert.ResponseText); nhood.Color = new Color(col >> 16, (col >> 8) & 0xFF, col & 0xFF); } }); } } if (state.NewKeys.Contains(Keys.F10)) { if (state.ShiftDown) { using (var file = System.IO.File.Open("Content/edit_neigh.json", System.IO.FileMode.Create, System.IO.FileAccess.Write)) using (var writer = new System.IO.StreamWriter(file)) writer.Write(Newtonsoft.Json.JsonConvert.SerializeObject(EditTarget, Newtonsoft.Json.Formatting.Indented)); } else { using (var file = System.IO.File.Open("Content/edit_neigh.json", System.IO.FileMode.Open, System.IO.FileAccess.Read)) using (var reader = new System.IO.StreamReader(file)) { EditTarget = JsonConvert.DeserializeObject <List <CityNeighbourhood> >(reader.ReadToEnd()); CityNeighbourhood.Init(EditTarget); City.NeighGeom.Data = EditTarget; City.NeighGeom.Generate(GameFacade.GraphicsDevice); } } } }