public GameMaster(Faction faction, DwarfGame game, ComponentManager components, ChunkManager chunks, Camera camera, GraphicsDevice graphics, DwarfGUI gui) { Faction = faction; Initialize(game, components, chunks, camera, graphics, gui); VoxSelector.Selected += OnSelected; BodySelector.Selected += OnBodiesSelected; PlayState.Time.NewDay += Time_NewDay; }
public DiplomacyState(DwarfGame game, GameStateManager stateManager, PlayState play, Faction faction) : base(game, "DiplomacyState", stateManager) { EdgePadding = 32; Input = new InputManager(); PlayState = play; EnableScreensaver = false; InputManager.KeyReleasedCallback += InputManager_KeyReleasedCallback; Faction = faction; }
/// <summary> /// The main entry point for the application. /// </summary> private static void Main(string[] args) { try { var cwd = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); Directory.SetCurrentDirectory(new Uri(cwd).LocalPath); using (Stream stream = new FileStream("version.txt", FileMode.Open)) using (StreamReader reader = new StreamReader(stream)) Commit = reader.ReadToEnd(); } catch (Exception) { } System.Net.ServicePointManager.ServerCertificateValidationCallback = SSLCallback; #if CREATE_CRASH_LOGS try #endif #if !DEBUG try #endif { Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.InvariantCulture; //fbDeprofiler.DeProfiler.Load(); using (DwarfGame game = new DwarfGame()) { game.Run(); } SignalShutdown(); } #if CREATE_CRASH_LOGS catch (Exception exception) { WriteExceptionLog(exception); } #endif #if !DEBUG catch (Exception exception) { SDL2.SDL.SDL_ShowSimpleMessageBox(SDL2.SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_ERROR, "Unhandled Exception!", String.Format("An unhandled exception occurred in DwarfCorp. This has been reported to Completely Fair Games LLC.\n {0}", exception.ToString()), IntPtr.Zero); WriteExceptionLog(exception); } #endif }
public void RenderSunMoon(DwarfTime time, GraphicsDevice device, Camera camera, Viewport viewPort, float scale) { Matrix rot = Matrix.CreateRotationZ((-CosTime + 0.5f * (float)Math.PI)); SunPosition = new Vector3(1000, 100, 0); Vector3 moonPosition = new Vector3(-1000, 100, 0); SunPosition = Vector3.Transform(SunPosition, rot); moonPosition = Vector3.Transform(moonPosition, rot); SunPosition += camera.Position; moonPosition += camera.Position; Vector3 cameraFrameSun = Vector3.Transform(SunPosition, camera.ViewMatrix); Vector3 cameraFramMoon = Vector3.Transform(moonPosition, camera.ViewMatrix); Vector3 unProjectSun = viewPort.Project(SunPosition, camera.ProjectionMatrix, camera.ViewMatrix, Matrix.Identity); Vector3 unProjectMoon = viewPort.Project(moonPosition, camera.ProjectionMatrix, camera.ViewMatrix, Matrix.Identity); try { DwarfGame.SafeSpriteBatchBegin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone, null, Matrix.Identity); if (cameraFrameSun.Z > 0.999f) { DwarfGame.SpriteBatch.Draw(SunTexture, new Vector2(unProjectSun.X - SunTexture.Width / 2 * scale, unProjectSun.Y - SunTexture.Height / 2 * scale), null, Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 0.0f); } if (cameraFramMoon.Z > 0.999f) { DwarfGame.SpriteBatch.Draw(MoonTexture, new Vector2(unProjectMoon.X - SunTexture.Width / 2 * scale, unProjectMoon.Y - SunTexture.Height / 2 * scale), null, Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 0.0f); } } finally { DwarfGame.SpriteBatch.End(); } Vector3 sunDir = (camera.Position - SunPosition); sunDir.Normalize(); SunlightDir = sunDir; }
public override void Render(DwarfGame game, GraphicsDevice graphics, DwarfTime time) { NamedImageFrame frame = new NamedImageFrame("newgui/pointers", 32, 6, 0); // Draw a bounding box around the currently selected bodies. foreach (Body body in Player.BodySelector.CurrentBodies) { if (body.Tags.Contains("Resource")) { Drawer2D.DrawText(body.Name, body.Position, Color.White, Color.Black); BoundingBox bounds = body.BoundingBox; bounds.Min += Vector3.Up * 0.5f; bounds.Max += Vector3.Up * 0.5f; bounds = bounds.Expand(0.25f); Drawer3D.DrawBox(bounds, Color.Orange, 0.02f, false); Drawer2D.DrawSprite(frame, bounds.Center(), Vector2.One, Vector2.Zero, new Color(255, 255, 255, 100)); } } }
public override void Update(DwarfGame game, DwarfTime time) { if (World.UserInterface.IsCameraRotationModeActive()) { World.UserInterface.VoxSelector.Enabled = false; World.UserInterface.SetMouse(null); return; } if (Command == "Kill Things") { World.UserInterface.BodySelector.Enabled = true; World.UserInterface.VoxSelector.Enabled = false; } else { World.UserInterface.VoxSelector.SelectionType = GetSelectionTypeBySelectionBoxValue(Command); World.UserInterface.VoxSelector.Enabled = true; World.UserInterface.VoxSelector.DrawBox = true; World.UserInterface.VoxSelector.DrawVoxel = true; World.UserInterface.BodySelector.Enabled = false; } World.UserInterface.SetMouse(World.UserInterface.MousePointer); if (Command == "Repulse") { var location = World.UserInterface.VoxSelector.VoxelUnderMouse; var center = location.GetBoundingBox().Center(); foreach (var body in World.EnumerateIntersectingObjects(location.GetBoundingBox(), CollisionType.Dynamic)) { var delta = center - body.Position; delta.Normalize(); if (delta.Y < 0) { delta.Y = 0; } var transform = body.LocalTransform; transform.Translation += delta * (float)time.ElapsedGameTime.TotalSeconds * 5; body.LocalTransform = transform; } } }
public override void Update(DwarfGame game, DwarfTime time) { if (Player.IsCameraRotationModeActive()) { return; } Player.VoxSelector.Enabled = false; Player.BodySelector.Enabled = true; Player.BodySelector.AllowRightClickSelection = true; if (Player.World.IsMouseOverGui) { Player.World.SetMouse(Player.World.MousePointer); } else { Player.World.SetMouse(new Gum.MousePointer("mouse", 1, 6)); } }
private bool SaveThreadRoutine() { #if !DEBUG try { #endif Thread.CurrentThread.Name = "Save"; // Ensure we're using the invariant culture. Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; var worldDirectory = Directory.CreateDirectory(DwarfGame.GetWorldDirectory() + Path.DirectorySeparatorChar + Overworld.Name); var file = new NewOverworldFile(Game.GraphicsDevice, Overworld); file.WriteFile(worldDirectory.FullName); var gameFile = SaveGame.CreateFromWorld(this); var path = worldDirectory.FullName + Path.DirectorySeparatorChar + String.Format("{0}-{1}", (int)Overworld.InstanceSettings.Origin.X, (int)Overworld.InstanceSettings.Origin.Y); SaveGame.DeleteOldestSave(path, GameSettings.Current.MaxSaves, "Autosave"); gameFile.WriteFile(path); ComponentManager.CleanupSaveData(); lock (Renderer.ScreenshotLock) { Renderer.Screenshots.Add(new WorldRenderer.Screenshot() { FileName = path + Path.DirectorySeparatorChar + "screenshot.png", Resolution = new Point(128, 128) }); } #if !DEBUG } catch (Exception exception) { Console.Error.Write(exception.ToString()); Program.CaptureException(exception); throw new WaitStateException(exception.Message); } #endif return(true); }
public override void Render(DwarfTime gameTime) { try { DwarfGame.SafeSpriteBatchBegin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointWrap, DepthStencilState.Default, RasterizerState.CullNone, null, Matrix.Identity); float y = -CurrentScroll; int w = GameState.Game.GraphicsDevice.Viewport.Width; int h = GameState.Game.GraphicsDevice.Viewport.Height; Drawer2D.FillRect(DwarfGame.SpriteBatch, new Rectangle(Padding - 30, 0, w - Padding * 2 + 30, h), new Color(5, 5, 5, 150)); foreach (CreditEntry entry in Entries) { if (entry.Divider) { y += EntryHeight; continue; } if (y + EntryHeight < -EntryHeight * 2 || y + EntryHeight > GameState.Game.GraphicsDevice.Viewport.Height + EntryHeight * 2) { y += EntryHeight; continue; } Color color = entry.Color; if (entry.RandomFlash) { color = new Color(MathFunctions.RandVector3Box(-1, 1, -1, 1, -1, 1) * 0.5f + color.ToVector3()); } DwarfGame.SpriteBatch.DrawString(CreditsFont, entry.Role, new Vector2(w / 2 - Datastructures.SafeMeasure(CreditsFont, entry.Role).X - 5, y), color); DwarfGame.SpriteBatch.DrawString(CreditsFont, entry.Name, new Vector2(w / 2 + 5, y), color); y += EntryHeight; } } finally { DwarfGame.SpriteBatch.End(); } base.Render(gameTime); }
public override void Update(DwarfGame game, DwarfTime time) { if (Player.IsCameraRotationModeActive()) { Player.VoxSelector.Enabled = false; Player.World.SetMouse(null); Player.BodySelector.Enabled = false; return; } bool hasCook = BuildType.HasFlag(NewGui.BuildMenu.BuildTypes.Cook); if (!hasCook) { Player.VoxSelector.Enabled = true; Player.BodySelector.Enabled = false; if (Player.World.IsMouseOverGui) { Player.World.SetMouse(Player.World.MousePointer); } else { Player.World.SetMouse(new Gum.MousePointer("mouse", 1, 4)); } } else { Player.VoxSelector.Enabled = false; Player.BodySelector.Enabled = false; if (Player.World.IsMouseOverGui) { Player.World.SetMouse(Player.World.MousePointer); } else { Player.World.SetMouse(new Gum.MousePointer("mouse", 1, 11)); } } }
public override void Update(DwarfGame game, DwarfTime time) { if (Player.IsCameraRotationModeActive()) { return; } Player.VoxSelector.Enabled = false; Player.BodySelector.Enabled = true; Player.BodySelector.AllowRightClickSelection = true; PlayState.GUI.IsMouseVisible = true; if (PlayState.GUI.IsMouseOver()) { PlayState.GUI.MouseMode = GUISkin.MousePointer.Pointer; } else { PlayState.GUI.MouseMode = GUISkin.MousePointer.Gather; } }
/// <summary> /// The main entry point for the application. /// </summary> private static void Main(string[] args) { #if CREATE_CRASH_LOGS try #endif { using (DwarfGame game = new DwarfGame()) { game.Run(); } SignalShutdown(); } #if CREATE_CRASH_LOGS catch (Exception exception) { WriteExceptionLog(exception); } #endif }
public override void Update(DwarfGame game, DwarfTime time) { if (World.UserInterface.IsCameraRotationModeActive()) { return; } World.UserInterface.VoxSelector.Enabled = false; World.UserInterface.BodySelector.Enabled = true; World.UserInterface.BodySelector.AllowRightClickSelection = true; if (World.UserInterface.IsMouseOverGui) { World.UserInterface.SetMouse(World.UserInterface.MousePointer); } else { World.UserInterface.SetMouse(new Gui.MousePointer("mouse", 1, 6)); } }
public void Initialize(DwarfGame game, ComponentManager components, ChunkManager chunks, Camera camera, GraphicsDevice graphics, DwarfGUI gui) { RoomLibrary.InitializeStatics(); CameraController = camera; VoxSelector = new VoxelSelector(CameraController, chunks.Graphics, chunks); BodySelector = new BodySelector(CameraController, chunks.Graphics, components); GUI = gui; SelectedMinions = new List <CreatureAI>(); Spells = SpellLibrary.CreateSpellTree(); CreateTools(); InputManager.KeyReleasedCallback += OnKeyReleased; ToolBar = new MasterControls(GUI, GUI.RootComponent, this, TextureManager.GetTexture(ContentPaths.GUI.icons), graphics, game.Content.Load <SpriteFont>(ContentPaths.Fonts.Default)) { Master = this }; Debugger = new AIDebugger(GUI, this); }
public void Render(DwarfGame game, DwarfTime time, GraphicsDevice g) { CurrentTool.Render(game, g, time); VoxSelector.Render(); foreach (var m in Faction.Minions) { if (m.Creature.SelectionCircle != null) { m.Creature.SelectionCircle.IsVisible = false; } m.Creature.Sprite.DrawSilhouette = false; } ; foreach (CreatureAI creature in Faction.SelectedMinions) { if (creature.Creature.SelectionCircle != null) { creature.Creature.SelectionCircle.IsVisible = true; } creature.Creature.Sprite.DrawSilhouette = true; foreach (Task task in creature.Tasks) { if (task.IsFeasible(creature.Creature) == Task.Feasibility.Feasible) { task.Render(time); } } if (creature.CurrentTask != null) { creature.CurrentTask.Render(time); } } DwarfGame.SpriteBatch.Begin(); BodySelector.Render(DwarfGame.SpriteBatch); DwarfGame.SpriteBatch.End(); }
/// <summary> /// Constructor. /// Adds three default trackers. /// </summary> /// <param name="game"></param> public GamePerformance(DwarfGame game) { _game = game; trackers = new List <Tracker>(); internalTrackers = new Dictionary <string, Tracker>(); threadLoopTrackers = new Dictionary <ThreadIdentifier, ThreadLoopTracker>(); zoneList = new ConcurrentDictionary <string, TrackerZone>(); threadLoopLockObject = new Object(); internalTrackerLockObject = new Object(); zoneListLockObject = new Object(); internalWatch = Stopwatch.StartNew(); trackers.Add(new FramerateTracker(this)); trackers.Add(new UpdateTimeTracker(this)); trackers.Add(new RenderTimeTracker(this)); this.TrackReferenceType("Version", Program.Version); this.TrackReferenceType("Commit", Program.Commit); }
public override void Update(DwarfGame game, DwarfTime time) { if (Player.IsCameraRotationModeActive()) { Player.VoxSelector.Enabled = false; Player.World.SetMouse(null); return; } Player.VoxSelector.Enabled = true; Player.BodySelector.Enabled = false; Player.VoxSelector.SelectionType = VoxelSelectionType.SelectFilled; if (Player.World.IsMouseOverGui) { Player.World.SetMouse(Player.World.MousePointer); } else { Player.World.SetMouse(new Gum.MousePointer("mouse", 1, 3)); } }
public override void Render(DwarfGame game, GraphicsDevice graphics, DwarfTime time) { foreach (KeyValuePair <ulong, BuildOrder> kvp in Player.Faction.DigDesignations) { Voxel v = kvp.Value.Vox; BoundingBox box = v.GetBoundingBox(); Color drawColor = DigDesignationColor; if (kvp.Value.NumCreaturesAssigned == 0) { drawColor = UnreachableColor; } drawColor.R = (byte)(drawColor.R * Math.Abs(Math.Sin(time.TotalGameTime.TotalSeconds * DigDesignationGlowRate)) + 50); drawColor.G = (byte)(drawColor.G * Math.Abs(Math.Sin(time.TotalGameTime.TotalSeconds * DigDesignationGlowRate)) + 50); drawColor.B = (byte)(drawColor.B * Math.Abs(Math.Sin(time.TotalGameTime.TotalSeconds * DigDesignationGlowRate)) + 50); Drawer3D.DrawBox(box, drawColor, 0.05f, true); } }
public override void Update(DwarfGame game, DwarfTime time) { if (Player.IsCameraRotationModeActive()) { Player.VoxSelector.Enabled = false; Player.World.SetMouse(null); Player.BodySelector.Enabled = false; return; } switch (Mode) { case FarmMode.Tilling: Player.VoxSelector.Enabled = true; Player.VoxSelector.SelectionType = VoxelSelectionType.SelectFilled; Player.BodySelector.Enabled = false; break; case FarmMode.Planting: Player.VoxSelector.Enabled = true; Player.VoxSelector.SelectionType = VoxelSelectionType.SelectFilled; Player.BodySelector.Enabled = false; break; case FarmMode.Harvesting: Player.VoxSelector.Enabled = false; Player.BodySelector.Enabled = true; break; } if (Player.World.IsMouseOverGui) { Player.World.SetMouse(Player.World.MousePointer); } else { Player.World.SetMouse(new Gum.MousePointer("mouse", 1, 12)); } }
public override void Update(DwarfGame game, DwarfTime time) { if (World.UserInterface.IsCameraRotationModeActive()) { World.UserInterface.VoxSelector.Enabled = false; World.UserInterface.SetMouse(null); } else { World.UserInterface.VoxSelector.Enabled = true; World.UserInterface.BodySelector.Enabled = false; if (World.UserInterface.IsMouseOverGui) { World.UserInterface.SetMouse(World.UserInterface.MousePointer); } else { World.UserInterface.SetMouse(new Gui.MousePointer("mouse", 1, 4)); } MouseState mouse = Mouse.GetState(); if (mouse.RightButton == ButtonState.Pressed) { World.UserInterface.VoxSelector.SelectionType = VoxelSelectionType.SelectFilled; } else { World.UserInterface.VoxSelector.SelectionType = Arguments.Floor ? VoxelSelectionType.SelectFilled : VoxelSelectionType.SelectEmpty; } if (Arguments == null || !Library.GetVoxelType(Arguments.VoxelType).HasValue(out var vType))// || !World.CanBuildVoxel(vType)) { World.UserInterface.ShowToolPopup("Not enough resources."); World.UserInterface.ChangeTool("SelectUnits"); } } }
public override void Update(DwarfGame game, DwarfTime time) { if (World.UserInterface.IsCameraRotationModeActive()) { World.UserInterface.VoxSelector.Enabled = false; World.UserInterface.BodySelector.Enabled = false; World.UserInterface.SetMouse(null); return; } World.UserInterface.VoxSelector.Enabled = Options.Voxels.CheckState; World.UserInterface.BodySelector.Enabled = Options.Entities.CheckState; World.UserInterface.VoxSelector.SelectionType = VoxelSelectionType.SelectFilled; if (World.UserInterface.IsMouseOverGui) { World.UserInterface.SetMouse(World.UserInterface.MousePointer); } else { World.UserInterface.SetMouse(new Gui.MousePointer("mouse", 0, 0)); } }
public override void Render(DwarfGame game, GraphicsDevice graphics, DwarfTime time) { Color drawColor = ChopDesignationColor; float alpha = (float)Math.Abs(Math.Sin(time.TotalGameTime.TotalSeconds * ChopDesignationGlowRate)); drawColor.R = (byte)(Math.Min(drawColor.R * alpha + 50, 255)); drawColor.G = (byte)(Math.Min(drawColor.G * alpha + 50, 255)); drawColor.B = (byte)(Math.Min(drawColor.B * alpha + 50, 255)); foreach (BoundingBox box in Player.Faction.ChopDesignations.Select(d => d.GetBoundingBox())) { Drawer3D.DrawBox(box, drawColor, 0.05f * alpha + 0.05f, true); } foreach (Body tree in Player.BodySelector.CurrentBodies) { if (tree.Tags.Contains("Vegetation")) { Drawer3D.DrawBox(tree.BoundingBox, Color.LightGreen, 0.1f, false); } } }
public override void Render(DwarfGame game, GraphicsDevice graphics, DwarfTime time) { DwarfGame.SpriteBatch.Begin(); int i = 0; Viewport port = GameState.Game.GraphicsDevice.Viewport; foreach (CreatureAI creature in Player.SelectedMinions) { Drawer2D.DrawAlignedText(DwarfGame.SpriteBatch, creature.Stats.FullName, PlayState.GUI.SmallFont, Color.White, Drawer2D.Alignment.Right, new Rectangle(port.Width - 300, 68 + i * 24, 300, 24)); i++; } foreach (Body body in Player.BodySelector.CurrentBodies) { if (IsDwarf(body)) { Drawer2D.DrawRect(DwarfGame.SpriteBatch, body.GetScreenRect(PlayState.Camera), Color.White, 1.0f); } } DwarfGame.SpriteBatch.End(); }
public override void Update(DwarfGame game, DwarfTime time) { if (Player.IsCameraRotationModeActive()) { Player.VoxSelector.Enabled = false; PlayState.GUI.IsMouseVisible = false; return; } Player.VoxSelector.Enabled = true; PlayState.GUI.IsMouseVisible = true; Player.BodySelector.Enabled = false; Player.VoxSelector.SelectionType = VoxelSelectionType.SelectFilled; if (PlayState.GUI.IsMouseOver()) { PlayState.GUI.MouseMode = GUISkin.MousePointer.Pointer; } else { PlayState.GUI.MouseMode = GUISkin.MousePointer.Guard; } }
public override void Update(DwarfGame game, DwarfTime time) { Player.BodySelector.Enabled = false; Player.VoxSelector.Enabled = false; if (Player.IsCameraRotationModeActive()) { Player.VoxSelector.Enabled = false; PlayState.GUI.IsMouseVisible = false; Player.BodySelector.Enabled = false; return; } else { PlayState.GUI.IsMouseVisible = true; } if (CurrentSpell != null) { CurrentSpell.Update(time, Player.VoxSelector, Player.BodySelector); } PlayState.GUI.MouseMode = PlayState.GUI.IsMouseOver() ? GUISkin.MousePointer.Pointer : GUISkin.MousePointer.Magic; }
/// <summary> /// The main entry point for the application. /// </summary> private static void Main(string[] args) { try { var cwd = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); Directory.SetCurrentDirectory(new Uri(cwd).LocalPath); using (Stream stream = System.Reflection.Assembly.GetExecutingAssembly() .GetManifestResourceStream("DwarfCorp.version.txt")) using (StreamReader reader = new StreamReader(stream)) Commit = reader.ReadToEnd(); } catch (Exception) { } Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.InvariantCulture; #if !DEBUG try #endif { fbDeprofiler.DeProfiler.Load(); using (DwarfGame game = new DwarfGame()) { game.Run(); } SignalShutdown(); } #if !DEBUG catch (Exception exception) { WriteExceptionLog(exception); System.Windows.Forms.MessageBox.Show(String.Format("An unhandled exception occurred in DwarfCorp. This has been reported to Completely Fair Games LLC.\n {0}", exception.ToString()), "ERROR"); } #endif }
public override void Update(DwarfGame game, DwarfTime time) { World.UserInterface.VoxSelector.Enabled = false; World.UserInterface.BodySelector.Enabled = true; World.UserInterface.BodySelector.AllowRightClickSelection = false; World.UserInterface.SetMouse(World.UserInterface.MousePointer); // If no gui bit exists, go ahead and create it. If it does, update the selected entity part of it. if (InspectorGui == null) { InspectorGui = World.UserInterface.Gui.ConstructWidget(new EntityInspectionPanel()) as EntityInspectionPanel; InspectorGui.Rect = new Rectangle(0, 0, 256, 512); InspectorGui.Layout(); World.UserInterface.Gui.RootItem.AddChild(InspectorGui); InspectorGui.OnClose = (sender) => { InspectorGui = null; World.UserInterface.ChangeTool("SelectUnits"); }; } InspectorGui.SelectedEntity = SelectedEntity; }
public override void Render(DwarfGame game, GraphicsDevice graphics, DwarfTime time) { if (CurrentSpell != null) { CurrentSpell.Render(time); } }
public override void Update(DwarfGame game, DwarfTime time) { if (Player.IsCameraRotationModeActive()) { Player.VoxSelector.Enabled = false; Player.BodySelector.Enabled = false; PlayState.GUI.IsMouseVisible = false; return; } Player.VoxSelector.Enabled = false; Player.BodySelector.Enabled = true; Player.BodySelector.AllowRightClickSelection = true; PlayState.GUI.IsMouseVisible = true; if (PlayState.GUI.IsMouseOver()) { PlayState.GUI.MouseMode = GUISkin.MousePointer.Pointer; } else { PlayState.GUI.MouseMode = GUISkin.MousePointer.Attack; } }
public override void Render(DwarfGame game, GraphicsDevice graphics, DwarfTime time) { }
public void Render(DwarfGame game, DwarfTime time, GraphicsDevice g) { CurrentTool.Render(game, g, time); VoxSelector.Render(); foreach (CreatureAI creature in Faction.SelectedMinions) { //Drawer2D.DrawZAlignedRect(creature.Position + Vector3.Down * 0.5f, 0.25f, 0.25f, 2, new Color(255, 255, 255, 50)); creature.Creature.SelectionCircle.IsVisible = true; foreach(Task task in creature.Tasks) { task.Render(time); } if(creature.CurrentTask != null) { creature.CurrentTask.Render(time); } } DwarfGame.SpriteBatch.Begin(); BodySelector.Render(DwarfGame.SpriteBatch); DwarfGame.SpriteBatch.End(); }
public void UpdateInput(DwarfGame game, DwarfTime time) { KeyboardState keyState = Keyboard.GetState(); MouseState mouseState = Mouse.GetState(); if(!IsMouseOverGui()) { UpdateMouse(Mouse.GetState(), Keyboard.GetState(), game, time); VoxSelector.Update(); BodySelector.Update(); } }
public void UpdateMouse(MouseState mouseState, KeyboardState keyState, DwarfGame game, DwarfTime time) { if(KeyManager.RotationEnabled()) { PlayState.GUI.IsMouseVisible = false; } }
private void LoadFromFile() { SetLoadingMessage("Creating Sky..."); Renderer.Sky = new SkyRenderer(); #region Reading game file SetLoadingMessage("Loading " + Overworld.InstanceSettings.ExistingFile); var gameFile = SaveGame.LoadMetaFromDirectory(Overworld.InstanceSettings.ExistingFile); if (gameFile == null) { throw new InvalidOperationException("Game File does not exist."); } if (gameFile.Metadata.Version != Program.Version && !Program.CompatibleVersions.Contains(gameFile.Metadata.Version)) { throw new InvalidOperationException(String.Format("Game file is from version {0}. Compatible versions are {1}.", gameFile.Metadata.Version, TextGenerator.GetListString(Program.CompatibleVersions))); } Renderer.Sky.TimeOfDay = gameFile.Metadata.TimeOfDay; Renderer.PersistentSettings = gameFile.Metadata.RendererSettings; Time = gameFile.Metadata.Time; WorldSizeInChunks = new Point3(Overworld.InstanceSettings.Cell.Bounds.Width, Overworld.zLevels, Overworld.InstanceSettings.Cell.Bounds.Height); #endregion #region Initialize static data bool actionComplete = false; Game.DoLazyAction(new Action(() => { Renderer.InstanceRenderer = new InstanceRenderer(); Renderer.bloom = new BloomComponent(Game) { Settings = BloomSettings.PresetSettings[5] }; Renderer.bloom.Initialize(); SoundManager.Content = Content; if (PlanService != null) { PlanService.Restart(); } MonsterSpawner = new MonsterSpawner(this); EntityFactory.Initialize(this); }), () => { actionComplete = true; return(true); }); while (!actionComplete) { Thread.Sleep(10); } #endregion PlanService = new PlanService(); SetLoadingMessage("Creating Liquids ..."); #region liquids Renderer.WaterRenderer = new WaterRenderer(GraphicsDevice); #endregion #region Load Components // Create updateable systems. foreach (var updateSystemFactory in AssetManager.EnumerateModHooks(typeof(UpdateSystemFactoryAttribute), typeof(EngineModule), new Type[] { typeof(WorldManager) })) { UpdateSystems.Add(updateSystemFactory.Invoke(null, new Object[] { this }) as EngineModule); } ChunkManager = new ChunkManager(Content, this); Splasher = new Splasher(ChunkManager); Renderer.ChunkRenderer = new ChunkRenderer(ChunkManager); SetLoadingMessage("Loading Terrain..."); ChunkManager.LoadChunks(gameFile.LoadChunks(), ChunkManager); SetLoadingMessage("Loading Entities..."); gameFile.LoadPlayData(Overworld.InstanceSettings.ExistingFile, this); PersistentData = gameFile.PlayData.PersistentData; Renderer.Camera = gameFile.PlayData.Camera; if (gameFile.PlayData.Stats != null) { Stats = gameFile.PlayData.Stats; } ComponentManager = new ComponentManager(gameFile.PlayData.Components, this); foreach (var component in gameFile.PlayData.Components.SaveableComponents) { if (!ComponentManager.HasComponent(component.GlobalID) && ComponentManager.HasComponent(component.Parent.GlobalID)) { // Logically impossible. throw new InvalidOperationException("Component exists in save data but not in manager."); } } ConversationMemory = gameFile.PlayData.ConversationMemory; Factions = gameFile.PlayData.Factions; ComponentManager.World = this; Renderer.Sky.TimeOfDay = gameFile.Metadata.TimeOfDay; Time = gameFile.Metadata.Time; PlayerFaction = Factions.Factions["Player"]; EventScheduler = new Events.Scheduler(); TutorialManager = new Tutorial.TutorialManager(); TutorialManager.SetFromSaveData(gameFile.PlayData.TutorialSaveData); Renderer.Camera.World = this; #endregion SetLoadingMessage("Creating Particles ..."); Game.DoLazyAction(new Action(() => ParticleManager = new ParticleManager(ComponentManager))); SetLoadingMessage("Creating GameMaster ..."); TaskManager = new TaskManager(); TaskManager.World = this; Time.NewDay += (time) => PayEmployees(); DwarfGame.LogSentryBreadcrumb("Loading", "Started new game with an existing file."); if (gameFile.PlayData.Tasks != null) { TaskManager = gameFile.PlayData.Tasks; TaskManager.World = this; } if (PlayerFaction.Economy.Information == null) { throw new InvalidProgramException(); } if (MathFunctions.RandEvent(0.01f)) { SetLoadingMessage("Reticulating Splines..."); } ChunkManager.StartThreads(); SetLoadingMessage("Presimulating ..."); ShowingWorld = false; OnLoadedEvent(); Thread.Sleep(1000); ShowingWorld = true; SetLoadingMessage("Complete."); // GameFile is no longer needed. gameFile = null; LoadStatus = LoadingStatus.Success; }
public override void Update(DwarfGame game, DwarfTime time) { if (Player.IsCameraRotationModeActive()) { return; } Player.VoxSelector.Enabled = false; Player.BodySelector.Enabled = false; if (Player.World.IsMouseOverGui) { Player.World.SetMouse(Player.World.MousePointer); } else { Player.World.SetMouse(new Gui.MousePointer("mouse", 1, 9)); } MouseState mouse = Mouse.GetState(); if (State == ToolState.Selecting) { if (SelectedBody != null) { foreach (var tinter in SelectedBody.GetRoot().EnumerateAll().OfType <Tinter>()) { tinter.VertexColorTint = Color.White; tinter.Stipple = false; } } SelectedBody = Player.World.ComponentManager.SelectRootBodiesOnScreen(new Rectangle(mouse.X, mouse.Y, 1, 1), Player.World.Camera) .Where(body => body.Tags.Contains("Moveable")) .FirstOrDefault(); if (SelectedBody != null) { if (SelectedBody.IsReserved) { Player.World.ShowTooltip("Can't move this " + SelectedBody.Name + "\nIt is being used."); } else { Player.World.ShowTooltip("Left click and drag to move this " + SelectedBody.Name); foreach (var tinter in SelectedBody.GetRoot().EnumerateAll().OfType <Tinter>()) { tinter.VertexColorTint = Color.Blue; tinter.Stipple = false; } } if (mouse.LeftButton == ButtonState.Pressed) { StartDragging(SelectedBody); } } } else if (State == ToolState.Dragging) { if (SelectedBody == null) { throw new InvalidProgramException(); } var craftDetails = SelectedBody.GetRoot().GetComponent <CraftDetails>(); if (craftDetails != null && CraftLibrary.GetCraftable(craftDetails.CraftType).AllowRotation) { HandleOrientation(); Player.World.ShowToolPopup(String.Format("Press {0}/{1} to rotate.", ControlSettings.Mappings.RotateObjectLeft, ControlSettings.Mappings.RotateObjectRight)); } var voxelUnderMouse = Player.VoxSelector.VoxelUnderMouse; if (voxelUnderMouse.IsValid && voxelUnderMouse.IsEmpty) { var spawnOffset = Vector3.Zero; CraftItem craftItem = null; if (craftDetails != null) { craftItem = CraftLibrary.GetCraftable(craftDetails.CraftType); if (craftItem != null) { spawnOffset = craftItem.SpawnOffset; } else { Console.Error.WriteLine("{0} had no craft item.", craftDetails.CraftType); } } if (craftItem == null) { return; } SelectedBody.LocalPosition = voxelUnderMouse.WorldPosition + new Vector3(0.5f, 0.0f, 0.5f) + spawnOffset; SelectedBody.UpdateTransform(); if (OverrideOrientation) { SelectedBody.Orient(CurrentOrientation); } else { SelectedBody.OrientToWalls(); } SelectedBody.PropogateTransforms(); var validPlacement = ObjectHelper.IsValidPlacement(voxelUnderMouse, craftItem, Player, SelectedBody, "move", "moved"); foreach (var tinter in SelectedBody.GetRoot().EnumerateAll().OfType <Tinter>()) { tinter.VertexColorTint = validPlacement ? Color.Green : Color.Red; tinter.Stipple = true; } if (mouse.LeftButton == ButtonState.Released) { if (validPlacement) { } else { SelectedBody.LocalTransform = OrigTransform; SelectedBody.PropogateTransforms(); } foreach (var tinter in SelectedBody.GetRoot().EnumerateAll().OfType <Tinter>()) { tinter.VertexColorTint = Color.White; tinter.Stipple = false; } State = ToolState.Selecting; } } } }
public override void Render(DwarfGame game, GraphicsDevice graphics, DwarfTime time) { foreach (BuildOrder d in Player.Faction.GuardDesignations) { Voxel v = d.Vox; if (v.IsEmpty) { continue; } BoundingBox box = v.GetBoundingBox(); Color drawColor = GuardDesignationColor; if (d.NumCreaturesAssigned == 0) { drawColor = UnreachableColor; } drawColor.R = (byte)(Math.Min(drawColor.R * Math.Abs(Math.Sin(time.TotalGameTime.TotalSeconds * GuardDesignationGlowRate)) + 50, 255)); drawColor.G = (byte)(Math.Min(drawColor.G * Math.Abs(Math.Sin(time.TotalGameTime.TotalSeconds * GuardDesignationGlowRate)) + 50, 255)); drawColor.B = (byte)(Math.Min(drawColor.B * Math.Abs(Math.Sin(time.TotalGameTime.TotalSeconds * GuardDesignationGlowRate)) + 50, 255)); Drawer3D.DrawBox(box, drawColor, 0.05f, true); } }
public override void Update(DwarfGame game, DwarfTime time) { if (Player.IsCameraRotationModeActive()) { Player.VoxSelector.Enabled = false; PlayState.GUI.IsMouseVisible = false; Player.BodySelector.Enabled = false; return; } Player.VoxSelector.Enabled = true; Player.BodySelector.Enabled = false; PlayState.GUI.IsMouseVisible = true; PlayState.GUI.MouseMode = PlayState.GUI.IsMouseOver() ? GUISkin.MousePointer.Pointer : GUISkin.MousePointer.Build; }
public override void Update(DwarfGame game, DwarfTime time) { PlayState.GUI.IsMouseVisible = true; Player.VoxSelector.Enabled = false; Player.BodySelector.Enabled = true; Player.BodySelector.AllowRightClickSelection = false; PlayState.GUI.MouseMode = GUISkin.MousePointer.Pointer; }
public void Initialize(DwarfGame game, ComponentManager components, ChunkManager chunks, Camera camera, GraphicsDevice graphics, DwarfGUI gui) { RoomLibrary.InitializeStatics(); CameraController = camera; VoxSelector = new VoxelSelector(CameraController, chunks.Graphics, chunks); BodySelector = new BodySelector(CameraController, chunks.Graphics, components); GUI = gui; SelectedMinions = new List<CreatureAI>(); Spells = SpellLibrary.CreateSpellTree(); CreateTools(); InputManager.KeyReleasedCallback += OnKeyReleased; ToolBar = new MasterControls(GUI, GUI.RootComponent, this, TextureManager.GetTexture(ContentPaths.GUI.icons), graphics, game.Content.Load<SpriteFont>(ContentPaths.Fonts.Default)) { Master = this }; Debugger = new AIDebugger(GUI, this); }
public WorldSetupState(DwarfGame game, GameStateManager stateManager) : base(game, "WorldSetupState", stateManager) { IsInitialized = false; }
public void Update(MouseState mouseState, KeyboardState keyState, DwarfGame game, DwarfTime time) { PlayState.GUI.IsMouseVisible = true; }
public override void Render(DwarfGame game, GraphicsDevice graphics, DwarfTime time) { Player.Faction.RoomBuilder.Render(time, PlayState.ChunkManager.Graphics); }
public override void Render(DwarfGame game, GraphicsDevice graphics, DwarfTime time) { Color drawColor = DesignationColor; float alpha = (float)Math.Abs(Math.Sin(time.TotalGameTime.TotalSeconds * GlowRate)); drawColor.R = (byte)(Math.Min(drawColor.R * alpha + 50, 255)); drawColor.G = (byte)(Math.Min(drawColor.G * alpha + 50, 255)); drawColor.B = (byte)(Math.Min(drawColor.B * alpha + 50, 255)); foreach (BoundingBox box in Player.Faction.AttackDesignations.Select(d => d.GetBoundingBox())) { Drawer3D.DrawBox(box, drawColor, 0.05f * alpha + 0.05f, true); } }
public void Update(DwarfGame game, DwarfTime time) { if(CurrentToolMode != ToolMode.God) { CurrentToolMode = ToolBar.CurrentMode; } CurrentTool.Update(game, time); if(GameSettings.Default.EnableAIDebugger) { if(Debugger != null) { Debugger.Update(time); } } if (!PlayState.Paused) { } else { CameraController.LastWheel = Mouse.GetState().ScrollWheelValue; } UpdateInput(game, time); if (Faction.Minions.Any(m => m.IsDead && m.TriggersMourning)) { CreatureAI deadMinion = null; foreach (CreatureAI minion in Faction.Minions) { minion.AddThought(Thought.ThoughtType.FriendDied); if (minion.IsDead) { deadMinion = minion; } } if (deadMinion != null) { PlayState.AnnouncementManager.Announce( deadMinion.Stats.FullName + " (" + deadMinion.Stats.CurrentLevel.Name + ")" + " died!", "One of our employees has died!"); Faction.Economy.Company.StockPrice -= MathFunctions.Rand(0, 0.5f); } } Faction.Minions.RemoveAll(m => m.IsDead); UpdateRooms(); }
public override void Render(DwarfGame game, GraphicsDevice graphics, DwarfTime time) { DwarfGame.SpriteBatch.Begin(); int i = 0; Viewport port = GameState.Game.GraphicsDevice.Viewport; foreach (CreatureAI creature in Player.SelectedMinions) { Drawer2D.DrawAlignedText(DwarfGame.SpriteBatch, creature.Stats.FullName, PlayState.GUI.SmallFont, Color.White, Drawer2D.Alignment.Right, new Rectangle(port.Width - 300, i * 24, 300, 24)); i++; } DwarfGame.SpriteBatch.End(); }
public DwarfGUI(DwarfGame game, SpriteFont defaultFont, SpriteFont titleFont, SpriteFont smallFont, InputManager input) { EnableMouseEvents = true; IsMouseVisible = true; MouseMode = GUISkin.MousePointer.Pointer; SmallFont = smallFont; Graphics = game.GraphicsDevice; this.game = game; RootComponent = new GUIComponent(this, null) { LocalBounds = new Rectangle(0, 0, 0, 0) }; DefaultFont = defaultFont; Skin = new GUISkin(TextureManager.GetTexture(ContentPaths.GUI.gui_widgets), 32, 32, TextureManager.GetTexture(ContentPaths.GUI.pointers), 16, 16); Skin.SetDefaults(); TitleFont = titleFont; GlobalOffset = Vector2.Zero; FocusComponent = null; Input = input; DrawAfter = new List<GUIComponent>(); DefaultTextColor = new Color(48, 27, 0); DefaultStrokeColor = Color.Transparent; DebugDraw = false; ToolTipManager = new ToolTipManager(this); LastScrollWheel = 0; }
public override void Render2D(DwarfGame game, DwarfTime time) { }
public abstract void Update(DwarfGame game, DwarfTime time);
public abstract void Render(DwarfGame game, GraphicsDevice graphics, DwarfTime time);