public InventoryScreen(ScreenComponent manager) : base(manager) { player = manager.Player; IsOverlay = true; Texture2D panelBackground = manager.Content.Load<Texture2D>("Textures/panel"); Background = NineTileBrush.FromSingleTexture(panelBackground, 30, 30); HorizontalAlignment = HorizontalAlignment.Center; VerticalAlignment = VerticalAlignment.Center; Width = 600; Height = 400; Label headLine = new Label(manager); headLine.Text = "Inventory"; headLine.Font = Skin.Current.HeadlineFont; headLine.HorizontalAlignment = HorizontalAlignment.Left; headLine.VerticalAlignment = VerticalAlignment.Top; Controls.Add(headLine); Button closeButton = Button.TextButton(Manager, "Close"); closeButton.LeftMouseClick += (s, e) => { Manager.NavigateBack(); }; Controls.Add(closeButton); //counter = new LabelControl(ScreenManager) //{ // Font = ScreenManager.NormalText, // Color = Color.Black, // Position = new Index2(((ScreenManager.ScreenSize.X - 600) / 2) + 100, // ((ScreenManager.ScreenSize.Y - 400) / 2) + 140), //}; //Controls.Add(counter); }
public InventoryScreen(ScreenComponent manager) : base(manager) { player = manager.Player; IsOverlay = true; Texture2D panelBackground = manager.Game.Content.LoadTexture2DFromFile("./Assets/OctoAwesome.Client/panel.png", manager.GraphicsDevice); Background = NineTileBrush.FromSingleTexture(panelBackground, 30, 30); HorizontalAlignment = HorizontalAlignment.Center; VerticalAlignment = VerticalAlignment.Center; Width = 600; Height = 400; Label headLine = new Label(manager); headLine.Text = Languages.OctoClient.Inventory; headLine.Font = Skin.Current.HeadlineFont; headLine.HorizontalAlignment = HorizontalAlignment.Left; headLine.VerticalAlignment = VerticalAlignment.Top; Controls.Add(headLine); Button closeButton = Button.TextButton(manager, Languages.OctoClient.Close); closeButton.LeftMouseClick += (s, e) => { manager.NavigateBack(); }; Controls.Add(closeButton); //counter = new LabelControl(ScreenManager) //{ // Font = ScreenManager.NormalText, // Color = Color.Black, // Position = new Index2(((ScreenManager.ScreenSize.X - 600) / 2) + 100, // ((ScreenManager.ScreenSize.Y - 400) / 2) + 140), //}; //Controls.Add(counter); Title = Languages.OctoClient.Inventory; }
public OctoGame() : base() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; this.Window.Title = "OctoAwesome"; graphics.PreferredBackBufferWidth = 1280; graphics.PreferredBackBufferHeight = 720; this.IsMouseVisible = false; this.Window.AllowUserResizing = true; this.TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 15); int viewrange; if (int.TryParse(ConfigurationManager.AppSettings["Viewrange"], out viewrange)) { if (viewrange < 1) throw new NotSupportedException("Viewrange in app.config darf nicht kleiner 1 sein"); SceneComponent.VIEWRANGE = viewrange; } int viewheight; if (int.TryParse(ConfigurationManager.AppSettings["Viewheight"], out viewheight)) { if (viewheight < 1) throw new NotSupportedException("Viewheight in app.config darf nicht kleiner 1 sein"); SceneComponent.VIEWHEIGHT = viewheight; } ResourceManager.CacheSize = ((viewrange * 2) + 1) * ((viewrange * 2) + 1) * ((viewheight * 2) + 1) * 2; input = new InputComponent(this); input.UpdateOrder = 1; Components.Add(input); simulation = new SimulationComponent(this); simulation.UpdateOrder = 3; Components.Add(simulation); player = new PlayerComponent(this, input, simulation); player.UpdateOrder = 2; Components.Add(player); camera = new CameraComponent(this, player); camera.UpdateOrder = 4; Components.Add(camera); scene = new SceneComponent(this, player, camera); scene.UpdateOrder = 5; scene.DrawOrder = 1; Components.Add(scene); hud = new HudComponent(this, player, scene, input); hud.UpdateOrder = 6; hud.DrawOrder = 2; Components.Add(hud); }
public SceneComponent(Game game, PlayerComponent player, CameraComponent camera) : base(game) { this.player = player; this.camera = camera; cache = new Cache<Index3, IChunk>(10, loadChunk, null); }
public HudComponent(Game game, PlayerComponent player, SceneComponent scene) : base(game) { Player = player; Scene = scene; controls.Add(toolbar = new Toolbar(this)); controls.Add(debugInfos = new DebugInfos(this)); controls.Add(compass = new Compass(this)); }
public ScreenManagerComponent(Game game, InputComponent input, PlayerComponent player) : base(game) { this.input = input; this.input.OnKeyDown += input_OnKeyDown; this.input.OnKeyUp += input_OnKeyUp; this.input.OnLeftMouseUp += input_OnLeftMouseUp; screens.Add("inventory", new InventoryScreen(this, player)); }
public HudComponent(Game game, PlayerComponent player, SceneComponent scene, InputComponent input) : base(game) { Player = player; Scene = scene; Input = input; controls.Add(toolbar = new Toolbar(this, Player)); controls.Add(debugInfos = new DebugInfos(this, Player)); controls.Add(compass = new Compass(this, Player)); controls.Add(miniMap = new MiniMap(this, Scene)); }
public OctoGame() : base() { graphics = new GraphicsDeviceManager(this); graphics.PreferredBackBufferWidth = 1080; graphics.PreferredBackBufferHeight = 720; Content.RootDirectory = "Content"; Window.Title = "OctoAwesome"; IsMouseVisible = true; Window.AllowUserResizing = true; TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 15); int viewrange; if (int.TryParse(SettingsManager.Get("Viewrange"), out viewrange)) { if (viewrange < 1) throw new NotSupportedException("Viewrange in app.config darf nicht kleiner 1 sein"); SceneControl.VIEWRANGE = viewrange; } Simulation = new SimulationComponent(this); Simulation.UpdateOrder = 4; Components.Add(Simulation); Player = new PlayerComponent(this); Player.UpdateOrder = 2; Components.Add(Player); Camera = new CameraComponent(this); Camera.UpdateOrder = 3; Components.Add(Camera); Screen = new ScreenComponent(this); Screen.UpdateOrder = 1; Screen.DrawOrder = 1; Components.Add(Screen); Window.ClientSizeChanged += (s, e) => { if (Window.ClientBounds.Height == graphics.PreferredBackBufferHeight && Window.ClientBounds.Width == graphics.PreferredBackBufferWidth) return; graphics.PreferredBackBufferHeight = Window.ClientBounds.Height; graphics.PreferredBackBufferWidth = Window.ClientBounds.Width; graphics.ApplyChanges(); }; }
public ToolbarControl(ScreenComponent screenManager) : base(screenManager) { Player = screenManager.Player; toolTextures = new Dictionary<string, Texture2D>(); // toolTextures = new Texture2D[Player.Tools.Length]; // int index = 0; foreach (var item in DefinitionManager.GetItemDefinitions()) { using (MemoryStream stream = new MemoryStream()) { System.Drawing.Bitmap bitmap = item.Icon; bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png); stream.Seek(0, SeekOrigin.Begin); toolTextures.Add(item.GetType().FullName, Texture2D.FromStream(ScreenManager.GraphicsDevice, stream)); } } }
public SceneControl(ScreenComponent manager, string style = "") : base(manager, style) { player = manager.Player; camera = manager.Camera; Manager = manager; simpleShader = manager.Game.Content.Load<Effect>("simple"); sunTexture = manager.Game.Content.LoadTexture2DFromFile("./Assets/OctoAwesome.Client/sun.png", manager.GraphicsDevice); List<Bitmap> bitmaps = new List<Bitmap>(); var definitions = DefinitionManager.Instance.GetBlockDefinitions(); foreach (var definition in definitions) bitmaps.AddRange(definition.Textures); int size = (int)Math.Ceiling(Math.Sqrt(bitmaps.Count)); Bitmap blocks = new Bitmap(size * TEXTURESIZE, size * TEXTURESIZE); using (Graphics g = Graphics.FromImage(blocks)) { int counter = 0; foreach (var bitmap in bitmaps) { int x = counter % size; int y = (int)(counter / size); g.DrawImage(bitmap, new System.Drawing.Rectangle(TEXTURESIZE * x, TEXTURESIZE * y, TEXTURESIZE, TEXTURESIZE)); counter++; } } using (MemoryStream stream = new MemoryStream()) { blocks.Save(stream, ImageFormat.Png); stream.Seek(0, SeekOrigin.Begin); blockTextures = Texture2D.FromStream(manager.GraphicsDevice, stream); } planet = ResourceManager.Instance.GetPlanet(0); // TODO: evtl. Cache-Size (Dimensions) VIEWRANGE + 1 int range = ((int)Math.Pow(2, VIEWRANGE) - 2) / 2; localChunkCache = new LocalChunkCache(ResourceManager.Instance.GlobalChunkCache, VIEWRANGE, range); chunkRenderer = new ChunkRenderer[ (int)Math.Pow(2, VIEWRANGE) * (int)Math.Pow(2, VIEWRANGE), planet.Size.Z]; orderedChunkRenderer = new List<ChunkRenderer>( (int)Math.Pow(2, VIEWRANGE) * (int)Math.Pow(2, VIEWRANGE) * planet.Size.Z); for (int i = 0; i < chunkRenderer.GetLength(0); i++) { for (int j = 0; j < chunkRenderer.GetLength(1); j++) { ChunkRenderer renderer = new ChunkRenderer(simpleShader, manager.GraphicsDevice, camera.Projection, blockTextures); chunkRenderer[i, j] = renderer; orderedChunkRenderer.Add(renderer); } } backgroundThread = new Thread(BackgroundLoop); backgroundThread.Priority = ThreadPriority.Lowest; backgroundThread.IsBackground = true; backgroundThread.Start(); selectionLines = new[] { new VertexPositionColor(new Vector3(-0.001f, +1.001f, +1.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(+1.001f, +1.001f, +1.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(-0.001f, -0.001f, +1.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(+1.001f, -0.001f, +1.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(-0.001f, +1.001f, -0.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(+1.001f, +1.001f, -0.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(-0.001f, -0.001f, -0.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(+1.001f, -0.001f, -0.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), }; billboardVertices = new[] { new VertexPositionTexture(new Vector3(-0.5f, 0.5f, 0), new Vector2(0, 0)), new VertexPositionTexture(new Vector3(0.5f, 0.5f, 0), new Vector2(1, 0)), new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0), new Vector2(0, 1)), new VertexPositionTexture(new Vector3(0.5f, 0.5f, 0), new Vector2(1, 0)), new VertexPositionTexture(new Vector3(0.5f, -0.5f, 0), new Vector2(1, 1)), new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0), new Vector2(0, 1)), }; selectionIndeces = new short[] { 0, 1, 0, 2, 1, 3, 2, 3, 4, 5, 4, 6, 5, 7, 6, 7, 0, 4, 1, 5, 2, 6, 3, 7 }; sunEffect = new BasicEffect(manager.GraphicsDevice); sunEffect.TextureEnabled = true; selectionEffect = new BasicEffect(manager.GraphicsDevice); selectionEffect.VertexColorEnabled = true; MiniMapTexture = new RenderTarget2D(manager.GraphicsDevice, 128, 128, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8); // , false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.PreserveContents); miniMapProjectionMatrix = Matrix.CreateOrthographic(128, 128, 1, 10000); }
public ScreenComponent(Game game, PlayerComponent player, CameraComponent camera) : base(game) { Player = player; Camera = camera; }
public CameraComponent(Game game, PlayerComponent player) : base(game) { this.player = player; }
public SceneControl(ScreenComponent manager, string style = "") : base(manager, style) { player = manager.Player; camera = manager.Camera; Manager = manager; simpleShader = manager.Game.Content.Load<Effect>("simple"); sunTexture = manager.Game.Content.Load<Texture2D>("Textures/sun"); List<Bitmap> bitmaps = new List<Bitmap>(); var definitions = DefinitionManager.GetBlockDefinitions(); foreach (var definition in definitions) bitmaps.AddRange(definition.Textures); int size = (int)Math.Ceiling(Math.Sqrt(bitmaps.Count)); Bitmap blocks = new Bitmap(size * TEXTURESIZE, size * TEXTURESIZE); using (Graphics g = Graphics.FromImage(blocks)) { int counter = 0; foreach (var bitmap in bitmaps) { int x = counter % size; int y = (int)(counter / size); g.DrawImage(bitmap, new System.Drawing.Rectangle(TEXTURESIZE * x, TEXTURESIZE * y, TEXTURESIZE, TEXTURESIZE)); counter++; } } using (MemoryStream stream = new MemoryStream()) { blocks.Save(stream, ImageFormat.Png); stream.Seek(0, SeekOrigin.Begin); blockTextures = Texture2D.FromStream(manager.GraphicsDevice, stream); } planet = ResourceManager.Instance.GetPlanet(0); _manager = ResourceManager.Instance.GetManagerForPlanet(planet.Id); chunkRenderer = new ChunkRenderer[ (int)Math.Pow(2, VIEWRANGE) * (int)Math.Pow(2, VIEWRANGE), planet.Size.Z]; for (int i = 0; i < chunkRenderer.GetLength(0); i++) for (int j = 0; j < chunkRenderer.GetLength(1); j++) chunkRenderer[i, j] = new ChunkRenderer(simpleShader, manager.GraphicsDevice, camera.Projection, blockTextures); // Entfernungsarray erzeugen //for (int x = -VIEWRANGE; x <= VIEWRANGE; x++) // for (int y = -VIEWRANGE; y <= VIEWRANGE; y++) // for (int z = 0; z <= planet.Size.Z; z++) // distances.Add(new Index3(x, y, z)); //distances = distances.OrderBy(d => d.LengthSquared()).ToList(); backgroundThread = new Thread(BackgroundLoop); backgroundThread.Priority = ThreadPriority.Lowest; backgroundThread.IsBackground = true; backgroundThread.Start(); selectionLines = new[] { new VertexPositionColor(new Vector3(-0.001f, +1.001f, +1.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(+1.001f, +1.001f, +1.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(-0.001f, -0.001f, +1.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(+1.001f, -0.001f, +1.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(-0.001f, +1.001f, -0.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(+1.001f, +1.001f, -0.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(-0.001f, -0.001f, -0.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(+1.001f, -0.001f, -0.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), }; billboardVertices = new[] { new VertexPositionTexture(new Vector3(-0.5f, 0.5f, 0), new Vector2(0, 0)), new VertexPositionTexture(new Vector3(0.5f, 0.5f, 0), new Vector2(1, 0)), new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0), new Vector2(0, 1)), new VertexPositionTexture(new Vector3(0.5f, 0.5f, 0), new Vector2(1, 0)), new VertexPositionTexture(new Vector3(0.5f, -0.5f, 0), new Vector2(1, 1)), new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0), new Vector2(0, 1)), }; selectionIndeces = new short[] { 0, 1, 0, 2, 1, 3, 2, 3, 4, 5, 4, 6, 5, 7, 6, 7, 0, 4, 1, 5, 2, 6, 3, 7 }; sunEffect = new BasicEffect(manager.GraphicsDevice); sunEffect.TextureEnabled = true; selectionEffect = new BasicEffect(manager.GraphicsDevice); selectionEffect.VertexColorEnabled = true; MiniMapTexture = new RenderTarget2D(manager.GraphicsDevice, 128, 128, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8); // , false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.PreserveContents); miniMapProjectionMatrix = Matrix.CreateOrthographic(128, 128, 1, 10000); }
public InventoryScreen(ScreenComponent manager) : base(manager) { assets = manager.Game.Assets; foreach (var item in DefinitionManager.Instance.GetItemDefinitions()) { Texture2D texture = manager.Game.Assets.LoadTexture(item.GetType(), item.Icon); toolTextures.Add(item.GetType().FullName, texture); } player = manager.Player; IsOverlay = true; Background = new BorderBrush(Color.Black * 0.5f); backgroundBrush = new BorderBrush(Color.Black); hoverBrush = new BorderBrush(Color.Brown); Texture2D panelBackground = assets.LoadTexture(typeof(ScreenComponent), "panel"); Grid grid = new Grid(manager) { Width = 800, Height = 500, }; grid.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Fixed, Width = 600 }); grid.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Fixed, Width = 200 }); grid.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Parts, Height = 1 }); grid.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Fixed, Height = 100 }); Controls.Add(grid); inventory = new InventoryControl(manager) { HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, Background = NineTileBrush.FromSingleTexture(panelBackground, 30, 30), Padding = Border.All(20), }; grid.AddControl(inventory, 0, 0); StackPanel infoPanel = new StackPanel(manager) { HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, Background = NineTileBrush.FromSingleTexture(panelBackground, 30, 30), Padding = Border.All(20), Margin = Border.All(10, 0, 0, 0), }; nameLabel = new Label(manager); infoPanel.Controls.Add(nameLabel); massLabel = new Label(manager); infoPanel.Controls.Add(massLabel); volumeLabel = new Label(manager); infoPanel.Controls.Add(volumeLabel); grid.AddControl(infoPanel, 1, 0); Grid toolbar = new Grid(manager) { Margin = Border.All(0, 10, 0, 0), Height = 100, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, Background = NineTileBrush.FromSingleTexture(panelBackground, 30, 30), }; toolbar.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Parts, Width = 1 }); for (int i = 0; i < Player.TOOLCOUNT; i++) toolbar.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Fixed, Width = 50 }); toolbar.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Parts, Width = 1 }); toolbar.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Parts, Height = 1 }); images = new Image[Player.TOOLCOUNT]; for (int i = 0; i < Player.TOOLCOUNT; i++) { Image image = images[i] = new Image(manager) { Width = 42, Height = 42, Background = backgroundBrush, HorizontalAlignment = HorizontalAlignment.Center, Tag = i, Padding = Border.All(2), }; image.StartDrag += (e) => { InventorySlot slot = player.ActorHost.Player.Tools[(int)image.Tag]; if (slot != null) { e.Handled = true; e.Icon = toolTextures[slot.Definition.GetType().FullName]; e.Content = slot; e.Sender = toolbar; } }; image.DropEnter += (e) => { image.Background = hoverBrush; }; image.DropLeave += (e) => { image.Background = backgroundBrush; }; image.EndDrop += (e) => { e.Handled = true; if (e.Sender is Grid) // && ShiftPressed { // Swap int targetIndex = (int)image.Tag; InventorySlot targetSlot = player.ActorHost.Player.Tools[targetIndex]; int sourceIndex = -1; InventorySlot sourceSlot = e.Content as InventorySlot; for (int j = 0; j < player.ActorHost.Player.Tools.Length; j++) { if (player.ActorHost.Player.Tools[j] == sourceSlot) { sourceIndex = j; break; } } SetTool(sourceSlot, targetIndex); SetTool(targetSlot, sourceIndex); } else { // Inventory Drop InventorySlot slot = e.Content as InventorySlot; SetTool(slot, (int)image.Tag); } }; toolbar.AddControl(image, i + 1, 0); } grid.AddControl(toolbar, 0, 1, 2); Title = Languages.OctoClient.Inventory; }
public CameraComponent(OctoGame game) : base(game) { player = game.Player; }
public DebugControl(ScreenComponent screenManager) : base(screenManager) { framebuffer = new float[buffersize]; Player = screenManager.Player; //Get ResourceManager for further Information later... resMan = ResourceManager.Instance; //Brush for Debug Background BorderBrush bg = new BorderBrush(Color.Black * 0.2f); //The left side of the Screen leftView = new StackPanel(ScreenManager) { Background = bg, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, }; //The right Side of the Screen rightView = new StackPanel(ScreenManager) { Background = bg, HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Top, }; //Creating all Labels devText = new Label(ScreenManager); devText.Text = Languages.OctoClient.DevelopmentVersion; leftView.Controls.Add(devText); loadedChunks = new Label(ScreenManager); leftView.Controls.Add(loadedChunks); loadedInfo = new Label(ScreenManager); leftView.Controls.Add(loadedInfo); position = new Label(ScreenManager); rightView.Controls.Add(position); rotation = new Label(ScreenManager); rightView.Controls.Add(rotation); fps = new Label(ScreenManager); rightView.Controls.Add(fps); controlInfo = new Label(ScreenManager); leftView.Controls.Add(controlInfo); activeTool = new Label(ScreenManager); rightView.Controls.Add(activeTool); flyInfo = new Label(ScreenManager); rightView.Controls.Add(flyInfo); //This Label gets added to the root and is set to Bottom Left box = new Label(ScreenManager); box.VerticalAlignment = VerticalAlignment.Bottom; box.HorizontalAlignment = HorizontalAlignment.Left; box.TextColor = Color.White; Controls.Add(box); //Add the left & right side to the root Controls.Add(leftView); Controls.Add(rightView); //Label Setup - Set Settings for all Labels in one place foreach (Control control in leftView.Controls) { control.HorizontalAlignment = HorizontalAlignment.Left; if (control is Label) { ((Label)control).TextColor = Color.White; } } foreach (Control control in rightView.Controls) { control.HorizontalAlignment = HorizontalAlignment.Right; if (control is Label) { ((Label)control).TextColor = Color.White; } } }
public ScreenComponent(Game game, PlayerComponent player, CameraComponent camera) : base(game) { Player = player; Camera = camera; TitlePrefix = "OctoAwesome"; }
public SceneControl(ScreenComponent manager, string style = "") : base(manager, style) { player = manager.Player; camera = manager.Camera; assets = manager.Game.Assets; Manager = manager; simpleShader = manager.Game.Content.Load<Effect>("simple"); sunTexture = assets.LoadTexture(typeof(ScreenComponent), "sun"); //List<Bitmap> bitmaps = new List<Bitmap>(); var definitions = DefinitionManager.Instance.GetBlockDefinitions(); int textureCount = 0; foreach (var definition in definitions) { textureCount += definition.Textures.Length; } int bitmapSize = 128; blockTextures = new Texture2DArray(manager.GraphicsDevice, 1, bitmapSize, bitmapSize, textureCount); int layer = 0; foreach (var definition in definitions) { foreach (var bitmap in definition.Textures) { System.Drawing.Bitmap texture = manager.Game.Assets.LoadBitmap(definition.GetType(), bitmap); var scaled = texture;//new Bitmap(bitmap, new System.Drawing.Size(bitmapSize, bitmapSize)); int[] data = new int[scaled.Width * scaled.Height]; var bitmapData = scaled.LockBits(new System.Drawing.Rectangle(0, 0, scaled.Width, scaled.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); System.Runtime.InteropServices.Marshal.Copy(bitmapData.Scan0, data, 0, data.Length); blockTextures.SetData(data, layer); scaled.UnlockBits(bitmapData); layer++; } } /*int size = (int)Math.Ceiling(Math.Sqrt(bitmaps.Count)); Bitmap blocks = new Bitmap(size * TEXTURESIZE, size * TEXTURESIZE); using (Graphics g = Graphics.FromImage(blocks)) { int counter = 0; foreach (var bitmap in bitmaps) { int x = counter % size; int y = (int)(counter / size); g.DrawImage(bitmap, new System.Drawing.Rectangle(TEXTURESIZE * x, TEXTURESIZE * y, TEXTURESIZE, TEXTURESIZE)); counter++; } } using (MemoryStream stream = new MemoryStream()) { blocks.Save(stream, ImageFormat.Png); stream.Seek(0, SeekOrigin.Begin); blockTextures = Texture2D.FromStream(manager.GraphicsDevice, stream); }*/ planet = ResourceManager.Instance.GetPlanet(0); // TODO: evtl. Cache-Size (Dimensions) VIEWRANGE + 1 int range = ((int)Math.Pow(2, VIEWRANGE) - 2) / 2; localChunkCache = new LocalChunkCache(ResourceManager.Instance.GlobalChunkCache, VIEWRANGE, range); chunkRenderer = new ChunkRenderer[ (int)Math.Pow(2, VIEWRANGE) * (int)Math.Pow(2, VIEWRANGE), planet.Size.Z]; orderedChunkRenderer = new List<ChunkRenderer>( (int)Math.Pow(2, VIEWRANGE) * (int)Math.Pow(2, VIEWRANGE) * planet.Size.Z); for (int i = 0; i < chunkRenderer.GetLength(0); i++) { for (int j = 0; j < chunkRenderer.GetLength(1); j++) { ChunkRenderer renderer = new ChunkRenderer(simpleShader, manager.GraphicsDevice, camera.Projection, blockTextures); chunkRenderer[i, j] = renderer; orderedChunkRenderer.Add(renderer); } } backgroundThread = new Thread(BackgroundLoop); backgroundThread.Priority = ThreadPriority.Lowest; backgroundThread.IsBackground = true; backgroundThread.Start(); var selectionVertices = new[] { new VertexPositionColor(new Vector3(-0.001f, +1.001f, +1.001f), Color.Black * 0.5f), new VertexPositionColor(new Vector3(+1.001f, +1.001f, +1.001f), Color.Black * 0.5f), new VertexPositionColor(new Vector3(-0.001f, -0.001f, +1.001f), Color.Black * 0.5f), new VertexPositionColor(new Vector3(+1.001f, -0.001f, +1.001f), Color.Black * 0.5f), new VertexPositionColor(new Vector3(-0.001f, +1.001f, -0.001f), Color.Black * 0.5f), new VertexPositionColor(new Vector3(+1.001f, +1.001f, -0.001f), Color.Black * 0.5f), new VertexPositionColor(new Vector3(-0.001f, -0.001f, -0.001f), Color.Black * 0.5f), new VertexPositionColor(new Vector3(+1.001f, -0.001f, -0.001f), Color.Black * 0.5f), }; var billboardVertices = new[] { new VertexPositionTexture(new Vector3(-0.5f, 0.5f, 0), new Vector2(0, 0)), new VertexPositionTexture(new Vector3(0.5f, 0.5f, 0), new Vector2(1, 0)), new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0), new Vector2(0, 1)), new VertexPositionTexture(new Vector3(0.5f, 0.5f, 0), new Vector2(1, 0)), new VertexPositionTexture(new Vector3(0.5f, -0.5f, 0), new Vector2(1, 1)), new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0), new Vector2(0, 1)), }; var selectionIndices = new short[] { 0, 1, 0, 2, 1, 3, 2, 3, 4, 5, 4, 6, 5, 7, 6, 7, 0, 4, 1, 5, 2, 6, 3, 7 }; selectionLines = new VertexBuffer(manager.GraphicsDevice, VertexPositionColor.VertexDeclaration, selectionVertices.Length); selectionLines.SetData(selectionVertices); selectionIndexBuffer = new IndexBuffer(manager.GraphicsDevice, DrawElementsType.UnsignedShort, selectionIndices.Length); selectionIndexBuffer.SetData(selectionIndices); billboardVertexbuffer = new VertexBuffer(manager.GraphicsDevice, VertexPositionTexture.VertexDeclaration, billboardVertices.Length); billboardVertexbuffer.SetData(billboardVertices); sunEffect = new BasicEffect(manager.GraphicsDevice); sunEffect.TextureEnabled = true; selectionEffect = new BasicEffect(manager.GraphicsDevice); selectionEffect.VertexColorEnabled = true; MiniMapTexture = new RenderTarget2D(manager.GraphicsDevice, 128, 128, PixelInternalFormat.Rgb8); // , false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.PreserveContents); miniMapProjectionMatrix = Matrix.CreateOrthographic(128, 128, 1, 10000); }
public OctoGame() { //graphics = new GraphicsDeviceManager(this); //graphics.PreferredBackBufferWidth = 1080; //graphics.PreferredBackBufferHeight = 720; //Content.RootDirectory = "Content"; Title = "OctoAwesome"; IsMouseVisible = true; Icon = Properties.Resources.octoawesome; //Window.AllowUserResizing = true; Settings = new Settings(); ResourceManager.Settings = Settings; //TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 15); int width = 1080, height = 720; if (Settings.KeyExists("Width")) width = Settings.Get<int>("Width"); if (Settings.KeyExists("Height")) height = Settings.Get<int>("Height"); Window.ClientSize = new Size(width, height); if (Settings.KeyExists("EnableFullscreen") && Settings.Get<bool>("EnableFullscreen")) Window.Fullscreen = true; if (Settings.KeyExists("Viewrange")) { var viewrange = Settings.Get<int>("Viewrange"); if (viewrange < 1) throw new NotSupportedException("Viewrange in app.config darf nicht kleiner 1 sein"); SceneControl.VIEWRANGE = viewrange; } Assets = new AssetComponent(this); Components.Add(Assets); Simulation = new SimulationComponent(this); Simulation.UpdateOrder = 4; Components.Add(Simulation); Player = new PlayerComponent(this); Player.UpdateOrder = 2; Components.Add(Player); Camera = new CameraComponent(this); Camera.UpdateOrder = 3; Components.Add(Camera); Screen = new ScreenComponent(this); Screen.UpdateOrder = 1; Screen.DrawOrder = 1; Components.Add(Screen); KeyMapper = new KeyMapper(Screen, Settings); /*Resize += (s, e) => { //if (Window.ClientBounds.Height == graphics.PreferredBackBufferHeight && // Window.ClientBounds.Width == graphics.PreferredBackBufferWidth) // return; //graphics.PreferredBackBufferHeight = Window.ClientBounds.Height; //graphics.PreferredBackBufferWidth = Window.ClientBounds.Width; //graphics.ApplyChanges(); };*/ SetKeyBindings(); }
public SceneComponent(Game game, PlayerComponent player, CameraComponent camera) : base(game) { this.player = player; this.camera = camera; }
public CompassControl(ScreenComponent screenManager) : base(screenManager) { Player = screenManager.Player; compassTexture = ScreenManager.Content.LoadTexture2DFromFile("./Assets/OctoAwesome.Client/compass.png", ScreenManager.GraphicsDevice); }