Beispiel #1
0
    /// <summary>
    /// Loads the UI.Instance skin parameters from specified file
    /// </summary>
    /// <param id="file"></param>
    /// <returns></returns>
    private GUITextureConfig LoadGuiTextureConfig(string file)
    {
      string[] configData;

      GUITextureConfig config = new GUITextureConfig();

      FileInfo configFile = new FileInfo(file);
      using (StreamReader sr = new StreamReader(configFile.OpenRead()))
      {
        configData = sr.ReadToEnd().Split('\n');
      }

      UserControlState state;
      Direction texturePart;
      int texturePartIdx = 0;
      int offx;
      int offy;

      for (int i = 0; i < configData.Length; i++)
      {
        string[] line = configData[i].Split(':');
        if (line.Length < 2) continue;
        switch (line[0].ToUpper())
        {
          case "FILE":
            config.TextureFile = new FileInfo(configFile.DirectoryName + "\\" + line[1]);
            break;
          case "COORD":
            if (Enum.TryParse<Direction>(line[1], true, out texturePart))
            {
              texturePartIdx = (int)texturePart;
            }
            offx = int.Parse(line[2]);
            offy = int.Parse(line[3]);
            for (int j = 0; j < UserControl.UserControlStateCount; j++)
            {
              config.StartX[j, texturePartIdx] += offx;
              config.StartY[j, texturePartIdx] += offy;
            }
            config.Width[texturePartIdx] = int.Parse(line[4]);
            config.Height[texturePartIdx] = int.Parse(line[5]);
            break;
          case "STATE":
            state = (UserControlState)Enum.Parse(typeof(UserControlState), line[1], true);
            offx = int.Parse(line[2]);
            offy = int.Parse(line[3]);
            for (int j = 0; j < ((Misc.OmniDirection.Length + 1)); j++)
            {
              config.StartX[(int)state, j] += offx;
              config.StartY[(int)state, j] += offy;
            }
            break;
          case "FORMAT":
            for (int j = 1; j < line.Length; j++)
            {
              switch (line[j].ToUpper())
              {
                default:
                  break;
              }
            }
            break;
          default:
            break;
        }
      }

      return config;
    }
Beispiel #2
0
    /// <summary>
    /// Loads an UI.Instance skin specified with specified parameters
    /// </summary>
    /// <param id="config"></param>
    /// <returns></returns>
    private GUITexture LoadGuiTexture(GUITextureConfig config)
    {
      Texture2D[,] parts = new Texture2D[UserControl.UserControlStateCount, (Misc.OmniDirection.Length + 1)];

      Texture2D original = LoadTexture(config.TextureFile.FullName);
      Color[] originalData = new Color[original.Width * original.Height];
      original.GetData<Color>(originalData);

      Texture2D part;
      Color[] partData;

      for (int i = 0; i < (Misc.OmniDirection.Length + 1); i++)
      {
        if (i >= (Misc.OmniDirection.Length + 1) && config.Width[i] == 0) continue;
        for (int z = 0; z < UserControl.UserControlStateCount; z++)
        {
          part = Texture2D.New(original.GraphicsDevice, config.Width[i], config.Height[i], original.Format);
          partData = SubTexture(originalData, original.Width, config.StartX[z, i], config.StartY[z, i], config.Width[i], config.Height[i]);
          part.SetData<Color>(partData);
          parts[z, i] = part;
        }
      }

      return new GUITexture(parts);
    }