private void InitTextures(BinaryReader reader) { if (SeekChunk(reader, 0x4D544558) == false) { return; } var size = reader.ReadInt32(); var bytes = reader.ReadBytes(size); var fullString = Encoding.ASCII.GetString(bytes); TextureNames.AddRange(fullString.Split(new[] { '\0' }, StringSplitOptions.RemoveEmptyEntries)); for (var i = 0; i < TextureNames.Count; ++i) { mTextures.Add(TextureManager.Instance.GetTexture(TextureNames[i])); TextureNames[i] = TextureNames[i].ToLowerInvariant(); } LoadSpecularTextures(); }
// texture paths according to (sub)directories and overall quantity of textures private static void TexturePathCreation() { TexturePaths.Add( GetTexturesFromDirectory(PathToTextures) ); TextureNames.Add(new string[TexturePaths[0].Length]); for (Int32 i = 1; i < GroupCount; ++i) { TexturePaths.Add( GetTexturesFromDirectory(PathToTextures + GroupNames[i] + "\\") ); TextureNames.Add(new string[TexturePaths[i].Length]); } foreach (string[] texturePath in TexturePaths) { TextureCount += texturePath.Length; } }
private void WriteTexFile() { using (var strm = FileManager.Instance.GetOutputStream(string.Format(@"World\Maps\{0}\{0}_{1}_{2}_tex0.adt", Continent, IndexX, IndexY))) { var writer = new BinaryWriter(strm); var texData = TextureNames.SelectMany(t => Encoding.ASCII.GetBytes(t).Concat(new byte[] {0})).ToArray(); CreateOrUpdateTexChunk(Chunks.Mtex, texData); foreach (var pair in mTexOrigChunks) { writer.Write(pair.Value.Signature); writer.Write(pair.Value.Size); writer.Write(pair.Value.Data); } foreach (var chunk in mChunks.Where(chunk => chunk != null)) { chunk.WriteTexChunks(writer); } } }
private static void DumpTexture(string propertyName) { if (!ResourcePackEditor.exists || ResourcePackEditor.instance.ActivePack == null) { Debug.Log("No pack selected!"); return; } var dumpDir = Path.Combine(ResourcePackEditor.instance.ActivePack.BuildingTexturesPath, "dump"); var prefab = GetSelectedPrefab(); if (prefab == null) { return; } if (prefab.m_material != null) { var texture = prefab.m_material.GetTexture(propertyName) as Texture2D; if (texture != null) { var textureName = TextureNames.GetReplacementTextureName(prefab.name, texture, propertyName, false); var fileName = Path.Combine(dumpDir, textureName + ".png"); DumpTexture2D(texture, fileName); } } if (prefab.m_lodMaterial != null) { var texture = prefab.m_lodMaterial.GetTexture(propertyName) as Texture2D; if (texture != null) { var textureName = TextureNames.GetReplacementTextureName(prefab.name, texture, propertyName, true); var fileName = Path.Combine(dumpDir, textureName + ".png"); DumpTexture2D(texture, fileName); } } }
public override void LongRangeScan() { if (LongRangeScanned == false) { SoundManager.CivAlert.Play(); LongRangeScanned = true; TextureNames textureName = (TextureNames)Random.Next((int)TextureNames.Star1, (int)TextureNames.Star7); TextureLink textureLink = TextureManager.Textures[textureName]; BaseSprite = new Sprite(BaseSprite.WorldLocation, textureLink.SpriteSheet, textureLink.SourceRectangle, Vector2.Zero); Color tint = new Color(Random.Next(1, 254), Random.Next(1, 254), Random.Next(1, 254)); BaseSprite.TintColor = tint; BaseSprite.AnimateWhenStopped = true; BaseSprite.CollisionRadius = 1; } }
/// (summary) /// Load the primatives and their vertex lists /// (/summary) /// (param name="fileReader")File stream(/param) /// (param name="offset")Start of list(/param) /// (param name="count")Number of primatives(/param) public void LoadPrimatives(BinaryReader fileReader, long offset, int count) { // Load the primatives list primitives = new Primitive[count]; fileReader.BaseStream.Seek(offset, SeekOrigin.Begin); for (int x = 0; x < count; x++) { // Create a new primative Primitive p = new Primitive(); // Load the properties fileReader.ReadInt32(); // Skip colour index p.VertexArray = new int[fileReader.ReadInt32()]; // Create vertex list fileReader.ReadInt32(); // Always Zero p.Offset = fileReader.ReadInt32(); // Offset to vertex array p.TextureName = ReadString(fileReader, fileReader.ReadInt32()); TextureNames.Add(p.TextureName); primitives[x] = p; // Skip three unknowns fileReader.ReadInt32(); fileReader.ReadInt32(); fileReader.ReadInt32(); } // Now for each primative, load the vertex list foreach (Primitive p in primitives) { fileReader.BaseStream.Seek(p.Offset, SeekOrigin.Begin); for (int x = 0; x < p.VertexArray.Length; x++) { // Read the ID of the vertex from the piece's vertex list p.VertexArray[x] = fileReader.ReadInt16(); // FIXED:- Was int16, not 32! } } }
/// <summary> /// Sets up the button with the correct information provided to the base class /// </summary> /// <param name="loc">The location to place the button</param> /// <param name="size">The size of the button</param> /// <param name="tex">The texture to give to the button</param> public OptionsButton(Vector2 loc, Vector2 size, TextureNames tex) : base(loc, size, tex) { }
public void SetTextures(string[] Textures) { TextureNames.Clear(); TextureNames.AddRange(Textures); HasTextureUpdate = true; }
public bool IsFlipped(TextureNames textureName) { return flipValues[(int)textureName]; }
// ---- METHODS ------------------------------------------------------------------------------------------------ void IResData.Load(ResFileLoader loader) { signature = loader.ReadString(4, Encoding.ASCII); uint materialAnimOffset = 0; ushort materialCount = 0; if (signature == "FMAA") { if (loader.ResFile.VersionMajor2 == 9) { Flags = loader.ReadEnum <MaterialAnimFlags>(true); loader.ReadUInt16(); } else { ((Switch.Core.ResFileSwitchLoader)loader).LoadHeaderBlock(); } Name = loader.LoadString(); Path = loader.LoadString(); BindModel = loader.Load <Model>(true); uint BindIndicesOffset = loader.ReadOffset(); materialAnimOffset = loader.ReadOffset(); uint unk = loader.ReadOffset(); //Empty section. Maybe set at runtime uint TextureNameArrayOffset = loader.ReadOffset(); UserData = loader.LoadDictValues <UserData>(); uint TextureBindArrayOffset = loader.ReadOffset(); if (loader.ResFile.VersionMajor2 != 9) { Flags = loader.ReadEnum <MaterialAnimFlags>(true); } ushort numUserData = 0; ushort CurveCount = 0; if (loader.ResFile.VersionMajor2 == 9) { FrameCount = loader.ReadInt32(); BakedSize = loader.ReadUInt32(); numUserData = loader.ReadUInt16(); materialCount = loader.ReadUInt16(); CurveCount = loader.ReadUInt16(); } else { numUserData = loader.ReadUInt16(); materialCount = loader.ReadUInt16(); CurveCount = loader.ReadUInt16(); FrameCount = loader.ReadInt32(); BakedSize = loader.ReadUInt32(); } ushort ShaderParamAnimCount = loader.ReadUInt16(); ushort TexturePatternAnimCount = loader.ReadUInt16(); ushort VisabiltyAnimCount = loader.ReadUInt16(); ushort TextureCount = loader.ReadUInt16(); if (loader.ResFile.VersionMajor2 == 9) { loader.ReadUInt16(); //padding } BindIndices = loader.LoadCustom(() => loader.ReadUInt16s(materialCount), BindIndicesOffset); var textureList = loader.LoadCustom(() => loader.LoadStrings(TextureCount), TextureNameArrayOffset); TextureBindArray = loader.LoadCustom(() => loader.ReadInt64s(TextureCount), TextureBindArrayOffset); if (textureList == null) { textureList = new List <string>(); } foreach (var tex in textureList) { TextureNames.Add(tex, new TextureRef() { Name = tex }); } } else if (signature == "FSHU") { if (loader.ResFile.Version >= 0x02040000) { Name = loader.LoadString(); Path = loader.LoadString(); Flags = (MaterialAnimFlags)loader.ReadUInt32(); if (loader.ResFile.Version >= 0x03040000) { FrameCount = loader.ReadInt32(); materialCount = loader.ReadUInt16(); ushort numUserData = loader.ReadUInt16(); int numParamAnim = loader.ReadInt32(); int numCurve = loader.ReadInt32(); BakedSize = loader.ReadUInt32(); } else { FrameCount = loader.ReadUInt16(); materialCount = loader.ReadUInt16(); UnknownValue = loader.ReadUInt32(); int numCurve = loader.ReadInt32(); BakedSize = loader.ReadUInt32(); int padding2 = loader.ReadInt32(); } BindModel = loader.Load <Model>(); BindIndices = loader.LoadCustom(() => loader.ReadUInt16s(materialCount)); materialAnimOffset = loader.ReadOffset(); UserData = loader.LoadDict <UserData>(); } else { Flags = (MaterialAnimFlags)loader.ReadUInt32(); FrameCount = loader.ReadInt16(); materialCount = loader.ReadUInt16(); ushort numUserData = loader.ReadUInt16(); ushort unk = loader.ReadUInt16(); BakedSize = loader.ReadUInt32(); Name = loader.LoadString(); Path = loader.LoadString(); BindModel = loader.Load <Model>(); BindIndices = loader.LoadCustom(() => loader.ReadUInt16s(materialCount)); materialAnimOffset = loader.ReadOffset(); } } else if (signature == "FTXP") { Name = loader.LoadString(); Path = loader.LoadString(); Flags = loader.ReadEnum <MaterialAnimFlags>(true); ushort numTextureRef = 0; if (loader.ResFile.Version >= 0x03040000) { ushort numUserData = loader.ReadUInt16(); FrameCount = loader.ReadInt32(); numTextureRef = loader.ReadUInt16(); materialCount = loader.ReadUInt16(); int numPatAnim = loader.ReadInt32(); int numCurve = loader.ReadInt32(); BakedSize = loader.ReadUInt32(); } else { FrameCount = loader.ReadUInt16(); numTextureRef = loader.ReadUInt16(); materialCount = loader.ReadUInt16(); ushort numUserData = loader.ReadUInt16(); int numPatAnim = loader.ReadInt16(); int numCurve = loader.ReadInt32(); BakedSize = loader.ReadUInt32(); loader.Seek(4); //padding } BindModel = loader.Load <Model>(); BindIndices = loader.LoadCustom(() => loader.ReadUInt16s(materialCount)); materialAnimOffset = loader.ReadOffset(); if (loader.ResFile.Version >= 0x03040000) { TextureNames = loader.LoadDict <TextureRef>(); } else { int TextureCount = 0; foreach (var patternAnim in MaterialAnimDataList) { foreach (var curve in patternAnim.Curves) { List <uint> frames = new List <uint>(); foreach (float key in curve.Keys) { frames.Add((uint)key); } TextureCount = (short)frames.Max(); } } var TextureRefNames = loader.LoadList <TextureRef>(numTextureRef); foreach (var texRef in TextureRefNames) { TextureNames.Add(texRef.Name, texRef); } } UserData = loader.LoadDict <UserData>(); } //Load materials and parse based on the signature of the section MaterialAnimDataList = loader.LoadCustom(() => { List <MaterialAnimData> materialAnims = new List <MaterialAnimData>(); for (int i = 0; i < materialCount; i++) { materialAnims.Add(new MaterialAnimData(loader, signature)); } return(materialAnims); }, materialAnimOffset); }
public void SetTexture(TextureNames textureName, int textureIndex) { textureValues[(int)textureName] = textureIndex; }
public static void AddTexture( TextureNames textureName, Texture2D spriteSheet, int x, int y, int width, int height ) { Textures.Add(textureName, new TextureLink(spriteSheet, x, y, width, height)); }
public override void Save() { if (mWasChanged == false) { return; } var hasMccv = mChunks.Any(c => c != null && c.HasMccv); if (hasMccv) { var wdt = WorldFrame.Instance.MapManager.CurrentWdt; if ((wdt.Flags & 2) == 0) { wdt.Flags |= 2; wdt.Save(WorldFrame.Instance.MapManager.Continent); } } using (var strm = FileManager.Instance.GetOutputStream(string.Format(@"World\Maps\{0}\{0}_{1}_{2}.adt", Continent, IndexX, IndexY))) { var writer = new BinaryWriter(strm); writer.Write(0x4D564552); // MVER writer.Write(4); writer.Write(18); writer.Write(0x4D484452); writer.Write(SizeCache <Mhdr> .Size); var headerStart = writer.BaseStream.Position; writer.Write(mHeader); var header = mHeader; var chunkInfos = mChunkOffsets.ToArray(); writer.Write(0x4D43494E); writer.Write(256 * SizeCache <Mcin> .Size); var mcinStart = writer.BaseStream.Position; writer.WriteArray(chunkInfos); header.ofsMcin = (int)(mcinStart - 28); header.ofsMtex = (int)(writer.BaseStream.Position - 20); writer.Write(0x4D544558); var textureData = new List <byte>(); writer.Write(TextureNames.Sum(t => { var data = Encoding.ASCII.GetBytes(t); textureData.AddRange(data); textureData.Add(0); return(data.Length + 1); })); writer.Write(textureData.ToArray()); header.ofsMmdx = (int)(writer.BaseStream.Position - 20); var m2NameData = new List <byte>(); writer.Write(0x4D4D4458); writer.Write(mDoodadNames.Sum(t => { var data = Encoding.ASCII.GetBytes(t); m2NameData.AddRange(data); m2NameData.Add(0); return(data.Length + 1); })); writer.Write(m2NameData.ToArray()); header.ofsMmid = (int)(writer.BaseStream.Position - 20); writer.Write(0x4D4D4944); writer.Write(mDoodadNameIds.Length * 4); writer.WriteArray(mDoodadNameIds); SaveChunk(0x4D574D4F, writer, out header.ofsMwmo); SaveChunk(0x4D574944, writer, out header.ofsMwid); if (mDoodadDefs != null && mDoodadDefs.Length > 0) { header.ofsMddf = (int)(writer.BaseStream.Position - 20); writer.Write(0x4D444446); writer.Write(mDoodadDefs.Length * SizeCache <Mddf> .Size); writer.WriteArray(mDoodadDefs); } else { header.ofsMddf = 0; } SaveChunk(0x4D4F4446, writer, out header.ofsModf); SaveChunk(0x4D48324F, writer, out header.ofsMh2o); for (var i = 0; i < mChunks.Count; ++i) { var startPos = writer.BaseStream.Position; mChunks[i].SaveChunk(writer); var endPos = writer.BaseStream.Position; chunkInfos[i].OfsMcnk = (int)startPos; chunkInfos[i].SizeMcnk = (int)(endPos - startPos); } SaveChunk(0x4D545846, writer, out header.ofsMtxf); SaveChunk(0x4D46424F, writer, out header.ofsMfbo); writer.BaseStream.Position = headerStart; writer.Write(header); writer.BaseStream.Position = mcinStart; writer.WriteArray(chunkInfos); } }
/// <summary> /// Sets up the button with all the required variables needed for a regular button, as well as a string for the text of the button /// </summary> /// <param name="text">The text of the button</param> /// <param name="topLeft">The location of the button as a Vector2</param> /// <param name="size">The size of the button as a Vector2</param> /// <param name="texString">The texture associated with the button (in the case of this button this texture will serve as the background and have the text displayed over it)</param> public TextButton(string text, Vector2 topLeft, Vector2 size, TextureNames texString) : base(topLeft, size, texString) { this.text = text; }
/// <summary> /// Gets a texture associated with a specified TextureNames item /// </summary> /// <param name="texDescription">The TextureNames item that describes the texture</param> /// <returns>The texture associated with that TextureNames item</returns> public static Texture2D getTexture(TextureNames texDescription) { return textures[texDescription]; }
/// <summary> /// Sets up the button with the correct information provided to the base class /// </summary> /// <param name="loc">The location to place the button</param> /// <param name="size">The size of the button</param> /// <param name="tex">The texture to give to the button</param> public RestartButton(Vector2 loc, Vector2 size, TextureNames tex) : base(loc, size, tex) { }
public int GetTexture(TextureNames textureName) { return(textureValues[(int)textureName]); }
/// <summary> /// Sets up the button, setting it to a given location, size and texture /// </summary> /// <param name="topLeft">The location to place the button as a Vector2</param> /// <param name="size">The size to make the button as a Vector2</param> /// <param name="texString">The TextureNames enum associated with the texture for the button</param> public Button(Vector2 topLeft, Vector2 size, TextureNames texString) { texture = Display.getTexture(texString); setLocation(topLeft, size); visible = true; }
public bool IsFlipped(TextureNames textureName) { return(flipValues[(int)textureName]); }
/// <summary> /// Initialses the OptionButton, taking the location, size, texture and option to be associated with and setting the button text to be the default "unset". /// </summary> /// <param name="topLeft">The location of the top left of the button as a Vector2</param> /// <param name="size">The size of the button as a Vector2</param> /// <param name="texture">The TextureNames associated with the texture for this button</param> /// <param name="option">The option associated with this button</param> public OptionButton(Vector2 topLeft, Vector2 size, TextureNames texture, MenuOption option) : base("unset", topLeft, size, texture) { associatedOption = option; }
public int GetTexture(TextureNames textureName) { return textureValues[(int)textureName]; }
public override void Initialize() { if (TextureNames == null) { throw new ArgumentNullException("DaytimeChange: Textures not set!"); } if (TextureNames.Count() < TEXTURE_COUNT) { throw new ArgumentException("DaytimeChange: Texture count less than " + TEXTURE_COUNT.ToString() + "!"); } sun = ResourceManager.Instance.CurrentScene.GetObject(SunID); lightDay = ResourceManager.Instance.CurrentScene.DirectionalLights[LightDayID]; lightNight = ResourceManager.Instance.CurrentScene.DirectionalLights[LightNightID]; ambient = ResourceManager.Instance.CurrentScene.AmbientLight; foreach (ObjectComponent comp in this.MyObject.Components) { if (comp.GetType() == typeof(CustomModel)) { myModel = (CustomModel)comp; if (myModel == null) { break; } if (myModel.Mat[0].GetType() != typeof(SkyboxMaterial)) { throw new InvalidOperationException("DaytimeChange: Skybox's material is not SkyboxMaterial!"); } myMaterial = (SkyboxMaterial)myModel.Mat[0]; break; } } if (sun == null || lightDay == null || lightNight == null || myModel == null || myMaterial == null || ambient == null) { throw new ArgumentNullException("DaytimeChange: Some of the objects do not exist!"); } foreach (ObjectComponent comp in sun.Components) { if (comp.GetType() == typeof(Billboard)) { if (((Billboard)comp).Mat != null) { sunMaterial = ((Billboard)comp).Mat; } } } startDaylightColor = lightDay.LightColor; startDaylightSpecular = lightDay.LightSpecularColor; startNightColor = lightNight.LightColor; startNightSpecular = lightNight.LightSpecularColor; startAmbientColor = ambient.LightColor; for (int i = 0; i < TEXTURE_COUNT; ++i) { if (TextureNames[i] != null) { textures[i] = ResourceManager.Instance.LoadTextureCube(TextureNames[i]); } } if (textures[0] != null) { myMaterial.CubeMap = textures[0]; } if (textures[1] != null) { myMaterial.CubeMap1 = textures[1]; } if (textures[2] != null) { myMaterial.CubeMap2 = textures[2]; } if (textures[3] != null) { myMaterial.CubeMap3 = textures[3]; } GameObject pt = ResourceManager.Instance.CurrentScene.GetObject("PlayerTime"); if (pt == null) { throw new ArgumentNullException("DaytimeChange: PlayerTime object does not exist!"); } foreach (ObjectComponent comp in pt.Components) { if (comp.GetType() == typeof(PlayerTime)) { cTime = (PlayerTime)comp; } } if (cTime == null) { throw new ArgumentNullException("DaytimeChange: PlayerTime object has no PlayerTime component!"); } long t = cTime.TotalMilliseconds; if (t >= SunriseMS - StateChangeMS && t <= SunsetMS + StateChangeMS) { switched = true; } else { switched = false; } startSunDiffuse = myMaterial.DiffuseColor; base.Initialize(); }
public void SetTexture(TextureNames textureName, int textureIndex) { textureValues[(int)textureName] = textureIndex; }
public static void AddTexture(TextureNames textureName, Texture2D spriteSheet, int x, int y, int width, int height) { Textures.Add(textureName, new TextureLink(spriteSheet, x, y, width, height)); }