private void CEL_OnAnimEnd(FLCPlayer player) { player.BackgroundTexture = null; animPlaying = false; if (questionsAnswered == questionCount) { EndQuestions(); } else { backgroundBitmap.Palette.Set(roguePaletteIndex, 0, 0, rogueBlue); backgroundBitmap.Palette.Set(magePaletteIndex, 0, 0, mageBlue); backgroundBitmap.Palette.Set(warriorPaletteIndex, 0, 0, warriorBlue); nativeTexture = new Texture2D(backgroundBitmap.Width, backgroundBitmap.Height, TextureFormat.ARGB32, false); if (!nativeTexture) { throw new Exception("CreateCharClassQuestions: Could not load native texture."); } nativeTexture.SetPixels32(backgroundImg.GetColor32(backgroundBitmap, 0)); nativeTexture.Apply(false, true); nativeTexture.filterMode = DaggerfallUI.Instance.GlobalFilterMode; NativePanel.BackgroundTexture = nativeTexture; DisplayQuestion(questionIndices[questionsAnswered]); } }
/// <summary> /// Loads IMG file to texture using a subrect of source image. /// Origin of source image (0,0) is bottom-left corner. /// </summary> public static Texture2D GetTextureFromImg(string name, Rect subRect, TextureFormat format = TextureFormat.ARGB32, bool readOnly = true) { ImgFile imgFile = new ImgFile(Path.Combine(DaggerfallUnity.Instance.Arena2Path, name), FileUsage.UseMemory, readOnly); imgFile.LoadPalette(Path.Combine(DaggerfallUnity.Instance.Arena2Path, imgFile.PaletteName)); DFBitmap bitmap = imgFile.GetDFBitmap(); Color32[] colors = imgFile.GetColor32(bitmap, 0); // Invert Y as Unity textures have origin 0,0 at bottom-left and UI expects top-left subRect.y = bitmap.Height - subRect.height; Color32[] newColors = new Color32[(int)subRect.width * (int)subRect.height]; ImageProcessing.CopyColors( ref colors, ref newColors, new DFSize(bitmap.Width, bitmap.Height), new DFSize((int)subRect.width, (int)subRect.height), new DFPosition((int)subRect.x, (int)subRect.y), new DFPosition(0, 0), new DFSize((int)subRect.width, (int)subRect.height)); Texture2D texture = new Texture2D((int)subRect.width, (int)subRect.height, format, false); texture.SetPixels32(newColors, 0); texture.Apply(false, true); texture.filterMode = DaggerfallUI.Instance.GlobalFilterMode; return(texture); }
Texture2D GetTextureFromImg(ImgFile img) { DFBitmap bitmap = img.GetDFBitmap(); Texture2D texture = new Texture2D(bitmap.Width, bitmap.Height, TextureFormat.ARGB32, false); texture.SetPixels32(img.GetColor32(bitmap, 0)); texture.Apply(false, true); return(texture); }
public static Texture2D GetTextureFromImg(ImgFile img, TextureFormat format = TextureFormat.ARGB32, bool readOnly = true) { DFBitmap bitmap = img.GetDFBitmap(); Texture2D texture = new Texture2D(bitmap.Width, bitmap.Height, format, false); texture.SetPixels32(img.GetColor32(bitmap, 0)); texture.Apply(false, readOnly); texture.filterMode = DaggerfallUI.Instance.GlobalFilterMode; return(texture); }
private void LoadNightSky() { const int width = 512; const int height = 219; // Get night sky matching sky index int nightSky; if (SkyIndex >= 0 && SkyIndex <= 7) { nightSky = 3; } else if (SkyIndex >= 8 && SkyIndex <= 15) { nightSky = 1; } else if (SkyIndex >= 16 && SkyIndex <= 23) { nightSky = 2; } else { nightSky = 0; } string filename = string.Format("NITE{0:00}I0.IMG", nightSky); imgFile = new ImgFile(Path.Combine(dfUnity.Arena2Path, filename), FileUsage.UseMemory, true); imgFile.Palette.Load(Path.Combine(dfUnity.Arena2Path, imgFile.PaletteName)); // Get sky bitmap DFBitmap dfBitmap = imgFile.GetDFBitmap(0, 0); // Draw stars if (ShowStars) { for (int i = 0; i < dfBitmap.Data.Length; i++) { // Stars should only be drawn over clear sky indices int index = dfBitmap.Data[i]; if (index > 16 && index < 32) { if (random.NextDouble() < starChance) { dfBitmap.Data[i] = starColorIndices[random.Next(0, starColorIndices.Length)]; } } } } // Get sky colour array Color32[] colors = imgFile.GetColor32(dfBitmap); // Fix seam on right side of night skies for (int y = 0; y < height; y++) { int pos = y * width + width - 2; colors[pos + 1] = colors[pos]; } skyColors.west = colors; skyColors.east = colors; skyColors.clearColor = skyColors.west[0]; }
protected override void Setup() { if (IsSetup) { return; } // Set background backgroundImg = new ImgFile(Path.Combine(DaggerfallUnity.Arena2Path, nativeImgName), FileUsage.UseMemory, true); backgroundBitmap = backgroundImg.GetDFBitmap(0, 0); nativeTexture = new Texture2D(backgroundBitmap.Width, backgroundBitmap.Height, TextureFormat.ARGB32, false); if (!nativeTexture) { throw new Exception("CreateCharClassQuestions: Could not load native texture."); } nativeTexture.SetPixels32(backgroundImg.GetColor32(backgroundBitmap, 0)); nativeTexture.Apply(false, true); nativeTexture.filterMode = DaggerfallUI.Instance.GlobalFilterMode; NativePanel.BackgroundTexture = nativeTexture; // Load both scroll images as one contiguous list of textures scrollFile0 = new GfxFile(Path.Combine(DaggerfallUnity.Instance.Arena2Path, scroll0FileName), FileUsage.UseMemory, true); scrollFile1 = new GfxFile(Path.Combine(DaggerfallUnity.Instance.Arena2Path, scroll1FileName), FileUsage.UseMemory, true); scrollFile0.Palette = backgroundBitmap.Palette; scrollFile1.Palette = backgroundBitmap.Palette; scrollTextures = new List <Texture2D>(); for (int i = 0; i < scrollFile0.frames.Length; i++) { scrollTextures.Add(TextureReader.CreateFromAPIImage(scrollFile0, 0, i, 0)); scrollTextures.Last().filterMode = DaggerfallUI.Instance.GlobalFilterMode; } for (int i = scrollFile0.frames.Length; i < scrollFile0.frames.Length + scrollFile1.frames.Length; i++) { scrollTextures.Add(TextureReader.CreateFromAPIImage(scrollFile1, 0, i - scrollFile0.frames.Length, 0)); scrollTextures.Last().filterMode = DaggerfallUI.Instance.GlobalFilterMode; } // Position scroll image on screen questionScroll.Position = new Vector2(0, 120f); questionScroll.Size = new Vector2(scrollTextures[0].width, scrollTextures[0].height); questionScroll.BackgroundTexture = scrollTextures[0]; questionScroll.Parent = NativePanel; textArea.Position = new Vector2(leftTextOffset, 120f + topTextOffset); textArea.Size = new Vector2(scrollTextures[0].width, scrollTextures[0].height - topTextOffset * 2f); textArea.Parent = NativePanel; NativePanel.Components.Add(textArea); NativePanel.Components.Add(questionScroll); // Setup question label questionIndices = GetQuestions(); DisplayQuestion(questionIndices[questionsAnswered]); // Handle scrolling NativePanel.OnMouseScrollDown += NativePanel_OnMouseScrollDown; NativePanel.OnMouseScrollUp += NativePanel_OnMouseScrollUp; questionScroll.OnMouseDown += QuestionScroll_OnMouseDown; questionScroll.OnMouseUp += QuestionScroll_OnMouseUp; // Setup animations rogueAnim.SetTransparentColor(0, 0, 10); rogueAnim.TransparencyEnabled = true; rogueAnim.Load("ROGUE.CEL"); rogueAnim.Size = new Vector2(rogueAnim.FLCFile.Header.Width, rogueAnim.FLCFile.Header.Height); rogueAnim.Position = new Vector2(1f, 1f); rogueAnim.BackgroundColor = Color.clear; rogueAnim.OnAnimEnd += CEL_OnAnimEnd; mageAnim.SetTransparentColor(0, 0, 10); mageAnim.TransparencyEnabled = true; mageAnim.Load("MAGE.CEL"); mageAnim.Size = new Vector2(mageAnim.FLCFile.Header.Width, mageAnim.FLCFile.Header.Height); mageAnim.Position = new Vector2(79f, 1f); mageAnim.BackgroundColor = Color.clear; mageAnim.OnAnimEnd += CEL_OnAnimEnd; warriorAnim.SetTransparentColor(0, 0, 10); warriorAnim.TransparencyEnabled = true; warriorAnim.Load("WARRIOR.CEL"); warriorAnim.Size = new Vector2(warriorAnim.FLCFile.Header.Width, warriorAnim.FLCFile.Header.Height); warriorAnim.Position = new Vector2(110f, 1f); warriorAnim.BackgroundColor = Color.clear; warriorAnim.OnAnimEnd += CEL_OnAnimEnd; rogueAnim.Loop = mageAnim.Loop = warriorAnim.Loop = false; NativePanel.Components.Add(rogueAnim); NativePanel.Components.Add(mageAnim); NativePanel.Components.Add(warriorAnim); IsSetup = true; }