1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using System.Linq; |
---|
4 | using System.IO; |
---|
5 | using Microsoft.Xna.Framework; |
---|
6 | using Microsoft.Xna.Framework.Audio; |
---|
7 | using Microsoft.Xna.Framework.Content; |
---|
8 | using Microsoft.Xna.Framework.GamerServices; |
---|
9 | using Microsoft.Xna.Framework.Graphics; |
---|
10 | using Microsoft.Xna.Framework.Input; |
---|
11 | using Microsoft.Xna.Framework.Media; |
---|
12 | using ALTK.GUI; |
---|
13 | |
---|
14 | namespace ALTK |
---|
15 | { |
---|
16 | /// <summary> |
---|
17 | /// This is a game component that implements IUpdateable. |
---|
18 | /// </summary> |
---|
19 | public class Loader : Microsoft.Xna.Framework.DrawableGameComponent |
---|
20 | { |
---|
21 | ContentManager content; |
---|
22 | |
---|
23 | public Loader(Game game) |
---|
24 | : base(game) |
---|
25 | { |
---|
26 | // TODO: Construct any child components here |
---|
27 | } |
---|
28 | |
---|
29 | /// <summary> |
---|
30 | /// Allows the game component to perform any initialization it needs to before starting |
---|
31 | /// to run. This is where it can query for any required services and load content. |
---|
32 | /// </summary> |
---|
33 | public override void Initialize() |
---|
34 | { |
---|
35 | // TODO: Add your initialization code here |
---|
36 | |
---|
37 | base.Initialize(); |
---|
38 | } |
---|
39 | |
---|
40 | public Texture2D loadTexture(string texturePath) |
---|
41 | { |
---|
42 | return Texture2D.FromStream(GraphicsDevice, File.OpenRead(ALTKConstants.TexturePath + texturePath + ".png")); |
---|
43 | } |
---|
44 | |
---|
45 | public SpriteFont loadFont(string fontName) |
---|
46 | { |
---|
47 | return content.Load<SpriteFont>(ALTK.ALTKConstants.FontPath + fontName); |
---|
48 | } |
---|
49 | |
---|
50 | public SoundEffect loadMusic(string musicPath) |
---|
51 | { |
---|
52 | return SoundEffect.FromStream(File.OpenRead(ALTKConstants.MusicPath + musicPath + ".wav")); |
---|
53 | } |
---|
54 | |
---|
55 | //public string loadTextFile(string filePath) |
---|
56 | //{ |
---|
57 | // if (File.Exists(ALTK.ConfigPath + filePath + ".txt")) |
---|
58 | // return File.ReadAllText(ALTK.ConfigPath + filePath + ".txt", System.Text.Encoding.GetEncoding("Windows-1252")); |
---|
59 | // else if (File.Exists(ALTK.BaseConfigPath + filePath + ".txt")) |
---|
60 | // return File.ReadAllText(ALTK.BaseConfigPath + filePath + ".txt", System.Text.Encoding.GetEncoding("Windows-1252")); |
---|
61 | // else |
---|
62 | // return "<Missing string: " + filePath + ">"; |
---|
63 | //} |
---|
64 | |
---|
65 | public Texture2D CreateBackgroundTexture(int Width, int Height, Color BackgroundColor) |
---|
66 | { |
---|
67 | Texture2D texture = new Texture2D(GraphicsDevice, Width, Height, false, SurfaceFormat.Color); |
---|
68 | |
---|
69 | Color[] color = new Color[Width * Height]; |
---|
70 | |
---|
71 | for (int i = 0; i < color.Length; i++) |
---|
72 | { |
---|
73 | color[i] = BackgroundColor; |
---|
74 | } |
---|
75 | |
---|
76 | texture.SetData(color); |
---|
77 | |
---|
78 | return texture; |
---|
79 | } |
---|
80 | |
---|
81 | protected override void LoadContent() |
---|
82 | { |
---|
83 | content = new ContentManager(Game.Services); |
---|
84 | content.RootDirectory = ALTKConstants.ContentPath; |
---|
85 | |
---|
86 | base.LoadContent(); |
---|
87 | } |
---|
88 | |
---|
89 | /// <summary> |
---|
90 | /// Allows the game component to update itself. |
---|
91 | /// </summary> |
---|
92 | /// <param name="gameTime">Provides a snapshot of timing values.</param> |
---|
93 | public override void Update(GameTime gameTime) |
---|
94 | { |
---|
95 | // TODO: Add your update code here |
---|
96 | |
---|
97 | base.Update(gameTime); |
---|
98 | } |
---|
99 | } |
---|
100 | } |
---|