public void ResolveResources(ResourceManager M59ResourceManager, bool RaiseChangedEvent) { if (OverlayFile != String.Empty) { if (RaiseChangedEvent) { Resource = M59ResourceManager.GetObject(OverlayFile); if (resource != null) animation.GroupMax = resource.FrameSets.Count; } else { resource = M59ResourceManager.GetObject(OverlayFile); if (resource != null) animation.GroupMax = resource.FrameSets.Count; } } }
/// <summary> /// Returns a name based on a name convention for textures. /// Basically the bgf filename, the frameindex added, /// and a dummy extension to potentially load it from a file /// Example: "grd00024-0.png" /// </summary> /// <param name="TextureFile"></param> /// <param name="FrameIndex"></param> /// <returns></returns> public static string GetNameForTexture(BgfFile TextureFile, int FrameIndex) { return TextureFile.Filename + '-' + FrameIndex + FileExtensions.PNG; }
public void ResolveResources(ResourceManager M59ResourceManager, bool RaiseChangedEvent) { if (OverlayFile != String.Empty) { if (RaiseChangedEvent) { Resource = M59ResourceManager.GetObject(OverlayFile); if (resource != null) { animation.GroupMax = resource.FrameSets.Count; motionAnimation.GroupMax = resource.FrameSets.Count; } } else { resource = M59ResourceManager.GetObject(OverlayFile); if (resource != null) { animation.GroupMax = resource.FrameSets.Count; motionAnimation.GroupMax = resource.FrameSets.Count; } } } foreach (SubOverlay obj in subOverlays) obj.ResolveResources(M59ResourceManager, false); foreach (SubOverlay obj in motionSubOverlays) obj.ResolveResources(M59ResourceManager, false); }
public void ResolveResources(ResourceManager M59ResourceManager, bool RaiseChangedEvent) { if (RaiseChangedEvent) { Resource = M59ResourceManager.GetRoomTexture(textureNum); } else { resource = M59ResourceManager.GetRoomTexture(textureNum); } }
/// <summary> /// Returns a name based on a name convention for Mogre from Bgf. /// </summary> /// <param name="TextureFile"></param> /// <param name="FrameIndex"></param> /// <param name="ScrollSpeed"></param> /// <returns></returns> public static string GetNameForMaterial(BgfFile TextureFile, int FrameIndex, V2 ScrollSpeed) { // examplereturn (0 is index in bgf) // Room/grd00352-0 string matName = "Room/" + TextureFile.Filename + "-" + FrameIndex; // add appendix for scrollspeed // Room/grd00352-0-SCROLL-1.0-0.0 matName += "-SCROLL-" + ScrollSpeed.X.ToString() + "-" + ScrollSpeed.Y.ToString(); return matName; }
/// <summary> /// Stars loading all roomtextures in a background thread. /// </summary> protected void LoadThreadRoomTextures() { IEnumerator<KeyValuePair<string, BgfFile>> it = RoomTextures.GetEnumerator(); BgfFile file; while (it.MoveNext()) { // load file = new BgfFile(Path.Combine(RoomTexturesFolder, it.Current.Key)); file.DecompressAll(); // update RoomTextures.TryUpdate(it.Current.Key, file, null); queueAsyncFilesLoaded.Enqueue(it.Current.Key); } }
static void Main() { // .net stuff Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // initialize color palettes PalettesGDI.Initialize(); // init bgf data model CurrentFile = new BgfFile(); CurrentFile.Frames.AllowEdit = true; // init roomobject model for viewer RoomObject = new RoomObject(); RoomObject.Resource = CurrentFile; // init imagecomposer for this roomobject ImageComposer = new ImageComposerGDI<RoomObject>(); ImageComposer.UseViewerFrame = true; ImageComposer.DataSource = RoomObject; // init mainform MainForm = new MainForm(); MainForm.FormClosed += OnMainFormFormClosed; MainForm.Show(); // init shrinkform SettingsForm = new SettingsForm(); SettingsForm.DataBindings.Add("Version", CurrentFile, "Version"); SettingsForm.DataBindings.Add("ShrinkFactor", CurrentFile, "ShrinkFactor"); SettingsForm.DataBindings.Add("Name", CurrentFile, "Name"); // init addframsetindexform AddFrameSetIndexForm = new AddFrameSetIndexForm(); // init ticker stopWatch = new Stopwatch(); stopWatch.Start(); // set running IsRunning = true; // start mainthread loop while (IsRunning) { long oldTick = Tick; // update current tick Tick = stopWatch.ElapsedTicks / MSTICKDIVISOR; long span = Tick - oldTick; // update roomobject if (IsPlaying) RoomObject.Tick(Tick, span); // process window messages / events Application.DoEvents(); // sleep Thread.Sleep(1); } }
public virtual void ResolveResources(ResourceManager M59ResourceManager, bool RaiseChangedEvent) { if (OverlayFile != String.Empty) { if (RaiseChangedEvent) { Resource = M59ResourceManager.GetObject(OverlayFile); } else { resource = M59ResourceManager.GetObject(OverlayFile); } if (resource != null) animation.GroupMax = resource.FrameSets.Count; } foreach (SubOverlay obj in subOverlays) obj.ResolveResources(M59ResourceManager, false); // appearance update ProcessAppearance(true); }
/// <summary> /// Tries to retrieve a BGF file from the RoomTextures dictionary. /// Will load the file from disk, if not yet loaded. /// </summary> /// <param name="File"></param> /// <returns></returns> public BgfFile GetRoomTexture(string File) { BgfFile bgfFile = null; // if the file is known if (RoomTextures.TryGetValue(File, out bgfFile)) { // haven't loaded it yet? if (bgfFile == null) { // load it bgfFile = new BgfFile(RoomTexturesFolder + "/" + File); // update the registry RoomTextures.TryUpdate(File, bgfFile, null); } } return bgfFile; }
public override void Clear(bool RaiseChangedEvent) { base.Clear(RaiseChangedEvent); if (RaiseChangedEvent) { OverlayFileRID = 0; NameRID = 0; LightFlags = 0; LightIntensity = 0; LightColor = 0; FirstAnimationType = 0; ColorTranslation = 0; Effect = 0; if (animation != null) animation.PropertyChanged -= OnAnimationPropertyChanged; Animation = new AnimationNone(); animation.PropertyChanged += OnAnimationPropertyChanged; Name = String.Empty; OverlayFile = String.Empty; Resource = null; } else { overlayFileRID = 0; nameRID = 0; lightFlags = 0; lightIntensity = 0; lightColor = 0; firstAnimationType = 0; colorTranslation = 0; effect = 0; if (animation != null) animation.PropertyChanged -= OnAnimationPropertyChanged; animation = new AnimationNone(); animation.PropertyChanged += OnAnimationPropertyChanged; name = String.Empty; overlayFile = String.Empty; resource = null; } flags.Clear(RaiseChangedEvent); subOverlays.Clear(); }
/// <summary> /// Updates values of this instance to values taken from parameter instance. /// </summary> /// <param name="Model"></param> /// <param name="RaiseChangedEvent"></param> public override void UpdateFromModel(ObjectBase Model, bool RaiseChangedEvent) { base.UpdateFromModel(Model, RaiseChangedEvent); if (RaiseChangedEvent) { OverlayFileRID = Model.OverlayFileRID; NameRID = Model.NameRID; Flags.UpdateFromModel(Model.Flags, RaiseChangedEvent); LightFlags = Model.LightFlags; LightIntensity = Model.LightIntensity; LightColor = Model.LightColor; FirstAnimationType = Model.FirstAnimationType; ColorTranslation = Model.ColorTranslation; Effect = Model.Effect; if (Animation != null) Animation.PropertyChanged -= OnAnimationPropertyChanged; Animation = Model.Animation; Animation.PropertyChanged += OnAnimationPropertyChanged; subOverlays.Clear(); subOverlays.AddRange(Model.SubOverlays); Name = Model.Name; OverlayFile = Model.OverlayFile; Resource = Model.Resource; } else { overlayFileRID = Model.OverlayFileRID; nameRID = Model.NameRID; Flags.UpdateFromModel(Model.Flags, RaiseChangedEvent); lightFlags = Model.LightFlags; lightIntensity = Model.LightIntensity; lightColor = Model.LightColor; firstAnimationType = Model.FirstAnimationType; colorTranslation = Model.ColorTranslation; effect = Model.Effect; if (animation != null) animation.PropertyChanged -= OnAnimationPropertyChanged; animation = Model.Animation; animation.PropertyChanged += OnAnimationPropertyChanged; subOverlays.Clear(); subOverlays.AddRange(Model.SubOverlays); name = Model.Name; overlayFile = Model.OverlayFile; resource = Model.Resource; } // appearance update ProcessAppearance(true); }
private void btnOK_Click(object sender, EventArgs e) { if (Directory.Exists(txtSource.Text) && Directory.Exists(txtTarget.Text)) { string[] files = Directory.GetFiles(txtSource.Text, "*.bgf"); switch (Mode) { case SourceTargetMode.Extract: foreach (string file in files) { try { BgfFile bgf = new BgfFile(file); bgf.WriteXml(txtTarget.Text + "\\" + bgf.Filename); txtLog.Text += "Extracted " + bgf.Filename + ".bgf" + Environment.NewLine; } catch (Exception) { txtLog.Text += "Error with file " + file; } } break; case SourceTargetMode.Decompress: foreach (string file in files) { try { BgfFile bgf = new BgfFile(file); foreach (BgfBitmap bitmap in bgf.Frames) bitmap.IsCompressed = false; bgf.Save(txtTarget.Text + "\\" + bgf.Filename + ".bgf"); txtLog.Text += "Decompressed " + bgf.Filename + ".bgf" + Environment.NewLine; } catch (Exception) { txtLog.Text += "Error with file " + file; } } break; case SourceTargetMode.SetVersion9: foreach (string file in files) { try { BgfFile bgf = new BgfFile(file); bgf.Version = BgfFile.VERSION9; bgf.Save(txtTarget.Text + "\\" + bgf.Filename + ".bgf"); txtLog.Text += "Converted " + bgf.Filename + ".bgf" + " to V9 (crush32)" + Environment.NewLine; } catch (Exception) { txtLog.Text += "Error with file " + file; } } break; case SourceTargetMode.SetVersion10: foreach (string file in files) { try { BgfFile bgf = new BgfFile(file); bgf.Version = BgfFile.VERSION10; bgf.Save(txtTarget.Text + "\\" + bgf.Filename + ".bgf"); txtLog.Text += "Converted " + bgf.Filename + ".bgf" + " to V10 (zlib)" + Environment.NewLine; } catch (Exception) { txtLog.Text += "Error with file " + file; } } break; } } }
/// <summary> /// Sets lower texture to another num /// </summary> /// <param name="TextureNum"></param> /// <param name="TextureFile"></param> public void SetUpperTexture(ushort TextureNum, BgfFile TextureFile) { ushort group = (animation != null) ? animation.CurrentGroup : (ushort)1; int frameidx = 0; string oldmaterial = MaterialNameUpper; UpperTexture = TextureNum; ResourceUpper = TextureFile; if (ResourceUpper != null && ResourceUpper.Frames.Count > 0) { frameidx = ResourceUpper.GetFrameIndex(group, 0); frameidx = Math.Max(frameidx, 0); if (ResourceUpper.Frames.Count > frameidx) { TextureUpper = ResourceUpper.Frames[frameidx]; SpeedUpper = GetWallScrollSpeed(TextureUpper.Width, TextureUpper.Height); } else { TextureUpper = null; SpeedUpper = V2.ZERO; } TextureNameUpper = RooFile.GetNameForTexture( ResourceUpper, frameidx); MaterialNameUpper = RooFile.GetNameForMaterial( ResourceUpper, frameidx, SpeedUpper); } else { TextureUpper = null; SpeedUpper = V2.ZERO; TextureNameUpper = null; MaterialNameUpper = null; } if (TextureChanged != null) TextureChanged(this, new WallTextureChangedEventArgs(this, WallPartType.Upper, oldmaterial)); }
/// <summary> /// Sets middle texture to another num /// </summary> /// <param name="TextureNum"></param> /// <param name="TextureFile"></param> /// <param name="ResetAnimation"></param> public void SetMiddleTexture(ushort TextureNum, BgfFile TextureFile, bool ResetAnimation = true) { ushort group = (animation != null) ? animation.CurrentGroup : (ushort)1; int frameidx = 0; string oldmaterial = MaterialNameMiddle; MiddleTexture = TextureNum; ResourceMiddle = TextureFile; if (ResourceMiddle != null && ResourceMiddle.Frames.Count > 0) { // possibly reset animation if (animation != null && ResetAnimation) { animation.SetValues(1, ResourceMiddle.FrameSets.Count, false); group = animation.CurrentGroup; } frameidx = ResourceMiddle.GetFrameIndex(group, 0); frameidx = Math.Max(frameidx, 0); if (ResourceMiddle.Frames.Count > frameidx) { TextureMiddle = ResourceMiddle.Frames[frameidx]; SpeedMiddle = GetWallScrollSpeed(TextureMiddle.Width, TextureMiddle.Height); } else { TextureMiddle = null; SpeedMiddle = V2.ZERO; } TextureNameMiddle = RooFile.GetNameForTexture( ResourceMiddle, frameidx); MaterialNameMiddle = RooFile.GetNameForMaterial( ResourceMiddle, frameidx, SpeedMiddle); } else { TextureMiddle = null; SpeedMiddle = V2.ZERO; TextureNameMiddle = null; MaterialNameMiddle = null; } if (TextureChanged != null) TextureChanged(this, new WallTextureChangedEventArgs(this, WallPartType.Middle, oldmaterial)); }
/// <summary> /// Sets the ceiling texture to another num /// </summary> /// <param name="TextureNum"></param> /// <param name="TextureFile"></param> public void SetCeilingTexture(ushort TextureNum, BgfFile TextureFile) { string oldmaterial = MaterialNameCeiling; CeilingTexture = TextureNum; ResourceCeiling = TextureFile; if (ResourceCeiling != null && ResourceCeiling.Frames.Count > 0) { TextureCeiling = ResourceCeiling.Frames[0]; SpeedCeiling = GetSectorScrollSpeed(false, TextureCeiling.Width, TextureCeiling.Height); TextureNameCeiling = RooFile.GetNameForTexture( ResourceCeiling, 0); MaterialNameCeiling = RooFile.GetNameForMaterial( ResourceCeiling, 0, SpeedCeiling); } else { TextureCeiling = null; TextureNameCeiling = null; MaterialNameCeiling = null; SpeedCeiling = V2.ZERO; } if (TextureChanged != null) TextureChanged(this, new SectorTextureChangedEventArgs(this, false, oldmaterial)); }
/// <summary> /// Sets the floor texture to another num /// </summary> /// <param name="TextureNum"></param> /// <param name="TextureFile"></param> public void SetFloorTexture(ushort TextureNum, BgfFile TextureFile) { string oldmaterial = MaterialNameFloor; FloorTexture = TextureNum; ResourceFloor = TextureFile; if (ResourceFloor != null && ResourceFloor.Frames.Count > 0) { TextureFloor = ResourceFloor.Frames[0]; SpeedFloor = GetSectorScrollSpeed(true, TextureFloor.Width, TextureFloor.Height); TextureNameFloor = RooFile.GetNameForTexture( ResourceFloor, 0); MaterialNameFloor = RooFile.GetNameForMaterial( ResourceFloor, 0, SpeedFloor); } else { TextureFloor = null; TextureNameFloor = null; MaterialNameFloor = null; SpeedFloor = V2.ZERO; } if (TextureChanged != null) TextureChanged(this, new SectorTextureChangedEventArgs(this, true, oldmaterial)); }