Exemple #1
0
        public void TestCalculate()
        {
            double?[] inputData = new double?[] { 22.27, 22.19, 22.08, 22.17, 22.18,
                                                  22.13, 22.23, 22.43, 22.24, 22.29,
                                                  22.15, 22.39, 22.38, 22.61, 23.36,
                                                  24.05, 23.75, 23.83, 23.95, 23.63,
                                                  23.82, 23.87, 23.65, 23.19, 23.10,
                                                  23.33, 22.68, 23.10, 22.40, 22.17 };

            int len = inputData.Length;

            double?[] outData = new double?[len];

            int period = 1;

            Delt.Calculate(inputData, period, outData);
        }
Exemple #2
0
        void loadEmpire()
        {
            if (_stars != null)
            {
                return;                                 // already loaded in, can skip over since it's static
            }
            string  dir    = Path.GetDirectoryName(_lfd.FilePath) + "\\";
            LfdFile empire = new LfdFile(dir + "EMPIRE.LFD");

            _stars                    = (Delt)empire.Resources["DELTstars"];
            _empirePalette            = ((Pltt)empire.Resources["PLTTstandard"]).Palette;
            _empirePalette.Entries[0] = Color.Fuchsia;
            _stars.Palette            = _empirePalette;
            _tiesfx                   = new LfdFile(dir + "TIESFX.LFD");
            _tiesfx2                  = new LfdFile(dir + "TIESFX2.LFD");
            _tiespch                  = new LfdFile(dir + "TIESPCH.LFD");
            _tiespch2                 = new LfdFile(dir + "TIESPCH2.LFD");
        }
Exemple #3
0
        void cmdSave_Click(object sender, EventArgs e)
        {
            Text tex = (Text)_battle.Resources[0];
            Delt del = (Delt)_battle.Resources[1];

            del.Image           = _systemImage;
            tex.NumberOfStrings = (short)(_numMiss + 4);
            tex.Strings[0]      = txtBattle.Text + '\0' + txtCutscene.Text;
            tex.Strings[1]      = txtBTitle1.Text + '\0' + txtBTitle2.Text + '\0' + txtCTitle1.Text + '\0' + txtCTitle2.Text;
            tex.Strings[2]      = _deltName + '\0' + txtSystem.Text + '\0' + numFrameTop.Value + ' ' + numFrameHeight.Value
                                  + ' ' + numFrameLeft.Value + ' ' + numFrameWidth.Value;
            tex.Strings[3] = String.Join("\0", _missionFiles);
            for (int i = 0; i < _numMiss; i++)
            {
                tex.Strings[4 + i] = _missionDescriptions[i].Replace("\r\n", "\0");
            }
            try { _battle.Write(); }
            catch (Exception x) { System.Diagnostics.Debug.WriteLine("Battle save failure"); throw x; }
        }
Exemple #4
0
        public ImageForm(Delt delt, ColorPalette palette)
        {
            InitializeComponent();
            _palette       = palette;
            _resource      = delt.ToString();
            Width          = (delt.Width + 6 < 120 ? 120 : delt.Width + 6);
            Height         = delt.Height + 66;
            _image         = delt.Image;
            _image.Palette = palette;
            cmdSave.Top    = Height - 64;
            cmdClose.Top   = cmdSave.Top;
            cmdSave.Left   = Width / 2 - 52;
            cmdClose.Left  = cmdSave.Left + 56;
            pctImage.Size  = delt.Image.Size;
            Bitmap t = _image;

            t.MakeTransparent(Color.Fuchsia);
            pctImage.Image = t;
        }
        public void TestDelt()
        {
            double[] inputData = new double[] { 22.27, 22.19, 22.08, 22.17, 22.18,
                                                22.13, 22.23, 22.43, 22.24, 22.29,
                                                22.15, 22.39, 22.38, 22.61, 23.36,
                                                24.05, 23.75, 23.83, 23.95, 23.63,
                                                23.82, 23.87, 23.65, 23.19, 23.10,
                                                23.33, 22.68, 23.10, 22.40, 22.17 };

            int len = inputData.Length;

            double?[] outData = new double?[len];

            int period = 1;

            Delt.Calculate(inputData, period, outData);

            Console.WriteLine("result: " + ObjectHelper.ToJson(outData));
        }
Exemple #6
0
 public BattleForm(Settings config)
 {
     InitializeComponent();
     //this.Height = 342;
     if (!config.TieInstalled)
     {
         MessageBox.Show("TIE95 installation not found, Battle function not available", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         this.Close();
         return;
     }
     else
     {
         _installPath = config.TiePath;
         // dummy bitmap to create a 256 color palette
         //palette definition
         // start with EMPIRE.PLTTstandard
         Pltt standard = (Pltt)(new LfdFile(_installPath + "\\RESOURCE\\EMPIRE.LFD").Resources["PLTTstandard"]);
         // then open up TOURDESK for the rest
         LfdFile tourdesk = new LfdFile(_installPath + "\\RESOURCE\\TOURDESK.LFD");
         Pltt    toddesk  = (Pltt)tourdesk.Resources["PLTTtoddesk"];
         _systemPalette = Pltt.ConvertToPalette(new Pltt[] { standard, toddesk });
         Delt galaxy = (Delt)tourdesk.Resources["DELTgalaxy"];
         galaxy.Palette       = _systemPalette;
         _galaxyImage         = galaxy.Image;
         picGalaxy.Image      = _galaxyImage;
         picGalaxy.Size       = _galaxyImage.Size;
         numFrameLeft.Maximum = _galaxyImage.Width - 1;
         numFrameTop.Maximum  = _galaxyImage.Height - 1;
     }
     _battlePath = _installPath + "\\RESOURCE\\Battle1.lfd";
     opnMission.InitialDirectory = _installPath + "\\MISSION";
     try { loadFile(_battlePath); }
     catch (Exception x)
     {
         MessageBox.Show(x.Message + " Battle function not available", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
 }
Exemple #7
0
        /// <summary>Paint a box around the extents of the image</summary>
        /// <param name="index">Block index</param>
        public void BoxImage(int index)
        {
            // TODO: fix BoxImage so it'll only highlight if currently visible
            string str = lstBlocks.Items[index].ToString();

            str = str.Replace("*", "");
            Resource img = _lfd.Resources[str];

            if (img == null)
            {
                if (lstBlocks.Items[index].ToString() == _stars.ToString() + "*")
                {
                    img = _stars;
                }
                else
                {
                    return;
                }
            }
            Debug.WriteLine("boxing...");
            Graphics g       = pctView.CreateGraphics();
            Pen      pnFrame = new Pen(Color.Red);

            if (img.Type == Resource.ResourceType.Delt)
            {
                Delt d = (Delt)img;
                g.DrawRectangle(pnFrame, _images[index].X, _images[index].Y, d.Width - 1, d.Height - 1);
                Debug.WriteLine("L:" + _images[index].X + " T:" + _images[index].Y + " W:" + d.Width + " H:" + d.Height);
            }
            else if (img.Type == Resource.ResourceType.Anim)
            {
                Anim a = (Anim)img;
                g.DrawRectangle(pnFrame, _images[index].X, _images[index].Y, a.Width - 1, a.Height - 1);
                Debug.WriteLine("L:" + _images[index].X + " T:" + _images[index].Y + " W:" + a.Width + " H:" + a.Height);
            }
            // again, skip CUST for now
            g.Dispose();
        }
        public async Task<IndSingleValueEntity[]> GetDelt(string code, int period = 1, int start = 0, int end = 0, string type = "day")
        {
            TickerEntity[] tickers = await base.getTickerEntityArray(code, start, end, type);
            List<IndSingleValueEntity> outList = new List<IndSingleValueEntity>();

            int len = tickers.Length;

            double[] close = tickers.Select(t => (double)t.C).ToArray();
            double?[] outDelt = new double?[len];

            Delt.Calculate(close, period, outDelt);

            for (int i = 0; i < len; i++)
            {
                outList.Add(new IndSingleValueEntity
                {
                    T = tickers[i].T,
                    P = tickers[i].P,
                    V = outDelt[i]
                });
            }

            return outList.Where(r => (start == 0 || r.P >= start) && (end == 0 || r.P <= end)).ToArray();
        }
Exemple #9
0
 public OfficerPreviewForm(Questions questions)
 {
     try
     {
         string path = new Settings().TiePath + "\\RESOURCE\\";
         _empire = new LfdFile(path + "EMPIRE.LFD");
         _talk   = new LfdFile(path + "TALK.LFD");
     }
     catch (System.IO.FileNotFoundException)
     {
         MessageBox.Show("TIE resource files not found, preview unavailable", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         Close();
     }
     _questions = questions;
     InitializeComponent();
     #region Pltt assignments
     Pltt         standard = (Pltt)_empire.Resources["PLTTstandard"];
     Pltt         offcr21  = (Pltt)_talk.Resources["PLTToffcr21"];
     Pltt         offbak   = (Pltt)_talk.Resources["PLTToffbak"];
     Pltt         ssrobe9  = (Pltt)_talk.Resources["PLTTssrobe9"];
     Pltt         ssbak    = (Pltt)_talk.Resources["PLTTssbak"];
     Pltt         doffbak  = (Pltt)_talk.Resources["PLTTdoffbak"];
     Pltt         dssbak   = (Pltt)_talk.Resources["PLTTdssbak"];
     ColorPalette brf_off  = Pltt.ConvertToPalette(new Pltt[] { standard, offcr21, offbak });
     ColorPalette brf_ss   = Pltt.ConvertToPalette(new Pltt[] { standard, ssrobe9, ssbak });
     ColorPalette dbrf_off = Pltt.ConvertToPalette(new Pltt[] { standard, offcr21, doffbak });
     ColorPalette dbrf_ss  = Pltt.ConvertToPalette(new Pltt[] { standard, ssrobe9, dssbak });
     ((Delt)_talk.Resources["DELToffbak"]).Palette = brf_off;
     Delt temp = (Delt)_talk.Resources["DELTofftxt"];
     temp.Palette = brf_off;
     temp.Image.MakeTransparent(Color.Black);
     ((Delt)_talk.Resources["DELTdoffbak"]).Palette = dbrf_off;
     temp         = (Delt)_talk.Resources["DELTdofftxt"];
     temp.Palette = dbrf_off;
     temp.Image.MakeTransparent(Color.Black);
     temp         = (Delt)_talk.Resources["DELToffcr21"];
     temp.Palette = brf_off;
     temp.Image.MakeTransparent(Color.Black);
     ((Anim)_talk.Resources["ANIMeyes"]).SetPalette(brf_off);
     ((Anim)_talk.Resources["ANIMmouth"]).SetPalette(brf_off);
     ((Delt)_talk.Resources["DELTssbak"]).Palette = brf_ss;
     temp         = (Delt)_talk.Resources["DELTsstxt"];
     temp.Palette = brf_ss;
     temp.Image.MakeTransparent(Color.Black);
     ((Delt)_talk.Resources["DELTdssbak"]).Palette = dbrf_ss;
     temp         = (Delt)_talk.Resources["DELTdsstxt"];
     temp.Palette = dbrf_ss;
     temp.Image.MakeTransparent(Color.Black);
     temp         = (Delt)_talk.Resources["DELTssrobe9"];
     temp.Palette = brf_ss;
     temp.Image.MakeTransparent(Color.Black);
     ((Anim)_talk.Resources["ANIMssface"]).SetPalette(brf_ss);
     // offcr21, eyes, mouth, ssrobe9 and ssface technically change between brf and dbrf, but not really
     ((LfdReader.Font)_empire.Resources[_fontID]).SetColor(_normalText);
     #endregion
     #region array declarations
     _opts[0] = optPreOff;
     _opts[1] = optPreSec;
     _opts[2] = optPostOff;
     _opts[3] = optPostSec;
     for (int i = 0; i < 4; i++)
     {
         _opts[i].CheckedChanged += new EventHandler(optsArr_CheckedChanged);
     }
     _opts[0].Checked = true;
     #endregion
 }
Exemple #10
0
        void loadBackAndQuestions()
        {
            Graphics g       = Graphics.FromImage(_preview);
            Delt     offcr21 = ((Delt)_talk.Resources["DELToffcr21"]);
            Delt     ssrobe9 = ((Delt)_talk.Resources["DELTssrobe9"]);
            Anim     eyes    = ((Anim)_talk.Resources["ANIMeyes"]);
            Anim     ssface  = ((Anim)_talk.Resources["ANIMssface"]);
            Anim     mouth   = ((Anim)_talk.Resources["ANIMmouth"]);

            switch (_qaSet)
            {
            // original graphics are 320x200, shift values come from the appropriate FILM
            case 0:
                Delt offbak = ((Delt)_talk.Resources["DELToffbak"]);
                Delt offtxt = ((Delt)_talk.Resources["DELTofftxt"]);
                g.DrawImageUnscaled(offbak.Image, 0, 0);
                g.DrawImageUnscaled(offtxt.Image, offtxt.Left, offtxt.Top);
                g.DrawImageUnscaled(offcr21.Image, offcr21.Left, offcr21.Top + 10);
                g.DrawImageUnscaled(eyes.Frames[0].Image, eyes.Left, eyes.Top);
                g.DrawImageUnscaled(mouth.Frames[0].Image, mouth.Left, mouth.Top);
                break;

            case 1:
                Delt ssbak = ((Delt)_talk.Resources["DELTssbak"]);
                Delt sstxt = ((Delt)_talk.Resources["DELTsstxt"]);
                g.DrawImageUnscaled(ssbak.Image, 0, 0);
                g.DrawImageUnscaled(sstxt.Image, sstxt.Left, sstxt.Top);
                g.DrawImageUnscaled(ssrobe9.Image, ssrobe9.Left - 24, ssrobe9.Top + 12);
                g.DrawImageUnscaled(ssface.Frames[0].Image, ssface.Left - 24, ssface.Top + 12);
                break;

            case 2:
                Delt doffbak = ((Delt)_talk.Resources["DELTdoffbak"]);
                Delt dofftxt = ((Delt)_talk.Resources["DELTdofftxt"]);
                g.DrawImageUnscaled(doffbak.Image, 0, 0);
                g.DrawImageUnscaled(dofftxt.Image, dofftxt.Left, dofftxt.Top);
                g.DrawImageUnscaled(offcr21.Image, offcr21.Left, offcr21.Top + 10);
                g.DrawImageUnscaled(eyes.Frames[0].Image, eyes.Left, eyes.Top);
                g.DrawImageUnscaled(mouth.Frames[0].Image, mouth.Left, mouth.Top);
                break;

            case 3:
                Delt dssbak = ((Delt)_talk.Resources["DELTdssbak"]);
                Delt dsstxt = ((Delt)_talk.Resources["DELTdsstxt"]);
                g.DrawImageUnscaled(dssbak.Image, 0, 0);
                g.DrawImageUnscaled(dsstxt.Image, dsstxt.Left, dsstxt.Top);
                g.DrawImageUnscaled(ssrobe9.Image, ssrobe9.Left - 24, ssrobe9.Top + 12);
                g.DrawImageUnscaled(ssface.Frames[0].Image, ssface.Left - 24, ssface.Top + 12);
                break;
            }
            g.Dispose();
            ((LfdReader.Font)_empire.Resources[_fontID]).SetColor(_normalText);
            int used = 0;

            for (_selectedIndex = 4; _selectedIndex > -1; _selectedIndex--)
            {
                _indexes[_selectedIndex] = 255;
                string q = _currentQuestion;
                if (q != "" || _currentAnswer != "")
                {
                    displayString(q, 122, (short)(145 + (4 - used) * 10));
                    _indexes[4 - used] = (byte)_selectedIndex;
                    used++;
                }
            }
            pctPreview.Invalidate();
        }
Exemple #11
0
        /// <summary>Opens the LFD and reads it into the program</summary>
        /// <param name="path">The full filename of the LFD to open</param>
        void loadFile(string path)
        {
            _battle = new LfdFile(path);
            Text txt = (Text)_battle.Resources[0];

            txtBattle.Text   = "";
            txtCutscene.Text = "";
            txtBTitle1.Text  = "";
            txtBTitle2.Text  = "";
            txtCTitle1.Text  = "";
            txtCTitle2.Text  = "";
            txtSystem.Text   = "";
            lstMiss.Items.Clear();
            _missionFiles        = new string[8];
            _missionDescriptions = new string[8];
            lblBattle.Text       = txt.Name;
            _numMiss             = txt.NumberOfStrings - 4;
            // Titles
            string[] strTemp = txt.Strings[0].Split('\0');
            txtBattle.Text   = strTemp[0];
            txtCutscene.Text = strTemp[1];
            // Text
            strTemp         = txt.Strings[1].Split('\0');
            txtBTitle1.Text = strTemp[0];
            txtBTitle2.Text = strTemp[1];
            txtCTitle1.Text = strTemp[2];
            if (strTemp.Length == 4)
            {
                txtCTitle2.Text = strTemp[3];                                   // TFW's fault, either left off, or only appends '\0', not '\0\0'
            }
            // System
            strTemp        = txt.Strings[2].Split('\0');
            _deltName      = strTemp[0];
            txtSystem.Text = strTemp[1];
            #region Image Frame
            _loading = true;
            string[] str_frame = strTemp[2].Split(' ');
            numFrameTop.Value    = Convert.ToInt32(str_frame[0]);
            numFrameHeight.Value = Convert.ToInt32(str_frame[1]);
            numFrameLeft.Value   = Convert.ToInt32(str_frame[2]);
            numFrameWidth.Value  = Convert.ToInt32(str_frame[3]);
            _loading             = false;
            drawFrame();
            #endregion
            // Missions
            strTemp = txt.Strings[3].Split('\0');
            for (int i = 0; i < strTemp.Length; i++)
            {
                _missionFiles[i] = strTemp[i];
            }
            for (int i = 0; i < _numMiss; i++)
            {
                lstMiss.Items.Add(_missionFiles[i]);
            }
            // Descriptions
            for (int i = 0; i < _numMiss; i++)
            {
                _missionDescriptions[i] = txt.Strings[4 + i];
                _missionDescriptions[i] = _missionDescriptions[i].TrimEnd('\0').Replace("\0", "\r\n");
            }
            txtDesc.Text = _missionDescriptions[0];
            #region System image
            try
            {
                Delt delSystem = (Delt)_battle.Resources[1];
                delSystem.Palette = _systemPalette;
                _systemImage      = delSystem.Image;
                picSystem.Image   = _systemImage;
                picSystem.Size    = _systemImage.Size;
            }
            catch (Exception x)
            {
                MessageBox.Show(x.Message + "  System image unavailable.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            #endregion
        }
Exemple #12
0
        void performEvents()
        {
            if (_time == 0)
            {
                for (int i = 0; i < _images.Length; i++)
                {
                    _images[i].StartTime      = -1;
                    _images[i].Layer          = _unused;
                    _images[i].ProcessedImage = null;
                    _images[i].Frame          = 0;
                }
            }

            // Process Animate and Move updates prior to potentially reassigning values
            for (int b = 0; b < _images.Length; b++)
            {
                if (_images[b].StartTime == -1 || _images[b].StartTime > _time)
                {
                    continue;
                }

                if (_images[b].StartTime < _time)
                {
                    _images[b].X += _images[b].XRate;
                    _images[b].Y += _images[b].YRate;
                    if (_images[b].FrameRate != 0)
                    {
                        var res = _lfd.Resources[lstBlocks.Items[b].ToString()];
                        if (res != null && res.Type == Resource.ResourceType.Anim)
                        {
                            Anim a = (Anim)res;
                            if (_images[b].Frame + _images[b].FrameRate >= a.NumberOfFrames)
                            {
                                _images[b].Frame = (short)(a.NumberOfFrames - 1);
                            }
                            else if (_images[b].Frame + _images[b].FrameRate < 0)
                            {
                                _images[b].Frame = 0;
                            }
                            else
                            {
                                _images[b].Frame += _images[b].FrameRate;
                            }

                            _images[b].ProcessedImage = (Bitmap)a.Frames[_images[b].Frame].Image.Clone();
                            _images[b].ProcessedImage.RotateFlip(_images[b].FlipType);
                            _images[b].ProcessedImage.MakeTransparent(Color.Fuchsia);
                        }
                    }
                }
            }

            bool needToSort = false;

            for (int ev = 0; ev < _events.Count; ev++)
            {
                if (_events[ev].Time > _time)
                {
                    break;
                }
                if (_events[ev].Time < _time)
                {
                    continue;
                }

                Event e = _events[ev];

                if (e.LoadPalette)
                {
                    loadPltt(_film.Blocks[e.BlockIndex].ToString());
                }

                if (_film.Blocks[e.BlockIndex].TypeNum == 3)
                {
                    if (e.ToggleDisplay && !e.Display)
                    {
                        _images[e.BlockIndex].IsVisible = false;
                        needToSort = true;
                    }
                    else if (e.ToggleDisplay && e.Display)
                    {
                        _images[e.BlockIndex].IsVisible = true;
                        _images[e.BlockIndex].StartTime = (short)_time;
                        needToSort = true;
                    }

                    if (e.FlipX && e.FlipY)
                    {
                        _images[e.BlockIndex].FlipType = RotateFlipType.RotateNoneFlipXY;
                    }
                    else if (e.FlipX)
                    {
                        _images[e.BlockIndex].FlipType = RotateFlipType.RotateNoneFlipX;
                    }
                    else if (e.FlipY)
                    {
                        _images[e.BlockIndex].FlipType = RotateFlipType.RotateNoneFlipY;
                    }
                    _images[e.BlockIndex].XRate = e.XRate;
                    _images[e.BlockIndex].YRate = e.YRate;
                    if (e.Left != e.Right)
                    {
                        _images[e.BlockIndex].Window = new Rectangle(e.Left, e.Top, e.Right - e.Left + 1, e.Bottom - e.Top + 1);
                    }

                    if (_images[e.BlockIndex].ProcessedImage == null)
                    {
                        // this prevents Layer from being redefined, assuming it never gets reset
                        _images[e.BlockIndex].Layer = e.Layer;

                        if (_film.Blocks[e.BlockIndex].ToString() == _stars.ToString())
                        {
                            _images[e.BlockIndex].ProcessedImage = (Bitmap)_stars.Image.Clone();
                            // DELTstars is at 0,0, so we can just use these, which default to 0,0 anyway
                            _images[e.BlockIndex].X = e.X;
                            _images[e.BlockIndex].Y = e.Y;
                            _images[e.BlockIndex].ProcessedImage.RotateFlip(_images[e.BlockIndex].FlipType);
                        }
                        else
                        {
                            for (int r = 0; r < _lfd.Resources.Count; r++)
                            {
                                if (_lfd.Resources[r].ToString() == _film.Blocks[e.BlockIndex].ToString())
                                {
                                    if (_lfd.Resources[r].Type == Resource.ResourceType.Delt)
                                    {
                                        Delt d = (Delt)_lfd.Resources[r];
                                        d.Palette = _palette;
                                        _images[e.BlockIndex].ProcessedImage = (Bitmap)d.Image.Clone();
                                        _images[e.BlockIndex].X = (short)(d.Left + e.X);
                                        _images[e.BlockIndex].Y = (short)(d.Top + e.Y);
                                        _images[e.BlockIndex].ProcessedImage.RotateFlip(_images[e.BlockIndex].FlipType);
                                    }
                                    else if (_lfd.Resources[r].Type == Resource.ResourceType.Anim)
                                    {
                                        Anim a = (Anim)_lfd.Resources[r];
                                        a.SetPalette(_palette);
                                        a.RelativePosition = true;

                                        // either going to define the frame, or set a motion
                                        if (e.Frame != -1)
                                        {
                                            _images[e.BlockIndex].Frame = e.Frame;
                                        }
                                        _images[e.BlockIndex].FrameRate      = e.Framerate;
                                        _images[e.BlockIndex].ProcessedImage = (Bitmap)a.Frames[_images[e.BlockIndex].Frame].Image.Clone();
                                        _images[e.BlockIndex].X = (short)(a.Left + e.X);
                                        _images[e.BlockIndex].Y = (short)(a.Top + e.Y);
                                        _images[e.BlockIndex].ProcessedImage.RotateFlip(_images[e.BlockIndex].FlipType);
                                    }
                                    // currently no CUST processing, but I think it's the same as DELT
                                    break;
                                }
                            }
                        }
                        _images[e.BlockIndex].ProcessedImage.MakeTransparent(Color.Fuchsia);
                    }
                    else
                    {
                        if (e.Layer != 0)
                        {
                            Debug.WriteLine("Layer reassignment: " + lstBlocks.Items[e.BlockIndex].ToString() + " Time: " + e.Time);
                        }

                        var res = _lfd.Resources[lstBlocks.Items[e.BlockIndex].ToString()];
                        if (res != null && res.Type == Resource.ResourceType.Anim)
                        {
                            Anim a = (Anim)res;
                            a.SetPalette(_palette);
                            a.RelativePosition = true;

                            if (e.Frame != -1)
                            {
                                _images[e.BlockIndex].Frame = e.Frame;
                            }
                            if (e.Framerate != _unused)
                            {
                                _images[e.BlockIndex].FrameRate = e.Framerate;
                            }
                            _images[e.BlockIndex].ProcessedImage = (Bitmap)a.Frames[_images[e.BlockIndex].Frame].Image.Clone();
                            if (e.SetPosition)
                            {
                                _images[e.BlockIndex].X = (short)(a.Left + e.X);
                                _images[e.BlockIndex].Y = (short)(a.Top + e.Y);
                            }
                            _images[e.BlockIndex].ProcessedImage.RotateFlip(_images[e.BlockIndex].FlipType);
                            _images[e.BlockIndex].ProcessedImage.MakeTransparent(Color.Fuchsia);
                        }
                        else if (res != null && res.Type == Resource.ResourceType.Delt && e.SetPosition)
                        {
                            Delt d = (Delt)res;
                            _images[e.BlockIndex].X = (short)(d.Left + e.X);
                            _images[e.BlockIndex].Y = (short)(d.Top + e.Y);
                        }
                    }
                }

                if (e.Start && _isPlaying)
                {
                    playWav(e.BlockIndex, e.Volume, e.Balance);
                }
            }
            if (needToSort)
            {
                sortLayers();
            }

            // TODO: View transitions
            // TODO: audio looping
        }
 public OfficerPreviewForm(Questions questions, int officer, int question, Settings config)
 {
     try
     {
         string path = config.TiePath + "\\RESOURCE\\";
         _empire = new LfdFile(path + "EMPIRE.LFD");
         _talk   = new LfdFile(path + "TALK.LFD");
     }
     catch (System.IO.FileNotFoundException)
     {
         MessageBox.Show("TIE resource files not found, preview unavailable", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         Close();
     }
     _questions = questions;
     InitializeComponent();
     #region Pltt assignments
     Pltt         standard = (Pltt)_empire.Resources["PLTTstandard"];
     Pltt         offcr21  = (Pltt)_talk.Resources["PLTToffcr21"];
     Pltt         offbak   = (Pltt)_talk.Resources["PLTToffbak"];
     Pltt         ssrobe9  = (Pltt)_talk.Resources["PLTTssrobe9"];
     Pltt         ssbak    = (Pltt)_talk.Resources["PLTTssbak"];
     Pltt         doffbak  = (Pltt)_talk.Resources["PLTTdoffbak"];
     Pltt         dssbak   = (Pltt)_talk.Resources["PLTTdssbak"];
     ColorPalette brf_off  = Pltt.ConvertToPalette(new Pltt[] { standard, offcr21, offbak });
     ColorPalette brf_ss   = Pltt.ConvertToPalette(new Pltt[] { standard, ssrobe9, ssbak });
     ColorPalette dbrf_off = Pltt.ConvertToPalette(new Pltt[] { standard, offcr21, doffbak });
     ColorPalette dbrf_ss  = Pltt.ConvertToPalette(new Pltt[] { standard, ssrobe9, dssbak });
     ((Delt)_talk.Resources["DELToffbak"]).Palette = brf_off;
     Delt temp = (Delt)_talk.Resources["DELTofftxt"];
     temp.Palette = brf_off;
     temp.Image.MakeTransparent(Color.Black);
     ((Delt)_talk.Resources["DELTdoffbak"]).Palette = dbrf_off;
     temp         = (Delt)_talk.Resources["DELTdofftxt"];
     temp.Palette = dbrf_off;
     temp.Image.MakeTransparent(Color.Black);
     temp         = (Delt)_talk.Resources["DELToffcr21"];
     temp.Palette = brf_off;
     temp.Image.MakeTransparent(Color.Black);
     ((Anim)_talk.Resources["ANIMeyes"]).SetPalette(brf_off);
     ((Anim)_talk.Resources["ANIMmouth"]).SetPalette(brf_off);
     ((Delt)_talk.Resources["DELTssbak"]).Palette = brf_ss;
     temp         = (Delt)_talk.Resources["DELTsstxt"];
     temp.Palette = brf_ss;
     temp.Image.MakeTransparent(Color.Black);
     ((Delt)_talk.Resources["DELTdssbak"]).Palette = dbrf_ss;
     temp         = (Delt)_talk.Resources["DELTdsstxt"];
     temp.Palette = dbrf_ss;
     temp.Image.MakeTransparent(Color.Black);
     temp         = (Delt)_talk.Resources["DELTssrobe9"];
     temp.Palette = brf_ss;
     temp.Image.MakeTransparent(Color.Black);
     ((Anim)_talk.Resources["ANIMssface"]).SetPalette(brf_ss);
     // offcr21, eyes, mouth, ssrobe9 and ssface technically change between brf and dbrf, but not really
     ((LfdReader.Font)_empire.Resources[_fontID]).SetColor(_normalText);
     #endregion
     #region array declarations
     _opts[0] = optPreOff;
     _opts[1] = optPreSec;
     _opts[2] = optPostOff;
     _opts[3] = optPostSec;
     for (int i = 0; i < 4; i++)
     {
         _opts[i].CheckedChanged += new EventHandler(optsArr_CheckedChanged);
     }
     #endregion
     _activeColor = _normalText;
     if (officer < 0 || officer >= 4)
     {
         officer = 0;
     }
     _opts[officer].Checked = true;
     if (question >= 0 && question <= 4)
     {
         _selectedIndex = -1;  //Prevent "selecting" the wrong question when drawing the selection highlight.
         loadBackAndQuestions();
         for (int i = 0; i < _indexes.Length; i++)
         {
             if (question == _indexes[i])
             {
                 displayQuestion(i);  //This will set the actual _selectedIndex
             }
         }
     }
 }
        void loadBackAndQuestions()
        {
            #region graphics
            Graphics g       = Graphics.FromImage(_preview);
            Delt     offcr21 = ((Delt)_talk.Resources["DELToffcr21"]);
            Delt     ssrobe9 = ((Delt)_talk.Resources["DELTssrobe9"]);
            Anim     eyes    = ((Anim)_talk.Resources["ANIMeyes"]);
            Anim     ssface  = ((Anim)_talk.Resources["ANIMssface"]);
            Anim     mouth   = ((Anim)_talk.Resources["ANIMmouth"]);
            switch (_qaSet)
            {
            // original graphics are 320x200, shift values come from the appropriate FILM
            case 0:
                Delt offbak = ((Delt)_talk.Resources["DELToffbak"]);
                Delt offtxt = ((Delt)_talk.Resources["DELTofftxt"]);
                g.DrawImageUnscaled(offbak.Image, 0, 0);
                g.DrawImageUnscaled(offtxt.Image, offtxt.Left, offtxt.Top);
                g.DrawImageUnscaled(offcr21.Image, offcr21.Left, offcr21.Top + 10);
                g.DrawImageUnscaled(eyes.Frames[0].Image, eyes.Left, eyes.Top);
                g.DrawImageUnscaled(mouth.Frames[0].Image, mouth.Left, mouth.Top);
                break;

            case 1:
                Delt ssbak = ((Delt)_talk.Resources["DELTssbak"]);
                Delt sstxt = ((Delt)_talk.Resources["DELTsstxt"]);
                g.DrawImageUnscaled(ssbak.Image, 0, 0);
                g.DrawImageUnscaled(sstxt.Image, sstxt.Left, sstxt.Top);
                g.DrawImageUnscaled(ssrobe9.Image, ssrobe9.Left - 24, ssrobe9.Top + 12);
                g.DrawImageUnscaled(ssface.Frames[0].Image, ssface.Left - 24, ssface.Top + 12);
                break;

            case 2:
                Delt doffbak = ((Delt)_talk.Resources["DELTdoffbak"]);
                Delt dofftxt = ((Delt)_talk.Resources["DELTdofftxt"]);
                g.DrawImageUnscaled(doffbak.Image, 0, 0);
                g.DrawImageUnscaled(dofftxt.Image, dofftxt.Left, dofftxt.Top);
                g.DrawImageUnscaled(offcr21.Image, offcr21.Left, offcr21.Top + 10);
                g.DrawImageUnscaled(eyes.Frames[0].Image, eyes.Left, eyes.Top);
                g.DrawImageUnscaled(mouth.Frames[0].Image, mouth.Left, mouth.Top);
                break;

            case 3:
                Delt dssbak = ((Delt)_talk.Resources["DELTdssbak"]);
                Delt dsstxt = ((Delt)_talk.Resources["DELTdsstxt"]);
                g.DrawImageUnscaled(dssbak.Image, 0, 0);
                g.DrawImageUnscaled(dsstxt.Image, dsstxt.Left, dsstxt.Top);
                g.DrawImageUnscaled(ssrobe9.Image, ssrobe9.Left - 24, ssrobe9.Top + 12);
                g.DrawImageUnscaled(ssface.Frames[0].Image, ssface.Left - 24, ssface.Top + 12);
                break;
            }
            g.Dispose();
            #endregion graphics

            int   used     = 0;
            int   curIndex = _selectedIndex;
            Color active   = _activeColor;
            ((LfdReader.Font)_empire.Resources[_fontID]).SetColor(_normalText);
            for (_selectedIndex = 4; _selectedIndex > -1; _selectedIndex--)
            {
                _indexes[_selectedIndex] = 255;
                string q = _currentQuestion;
                if (q != "" || _currentAnswer != "")
                {
                    if (q == "")
                    {
                        q = "(empty question)";      //[JB] Display a placeholder for empty questions.
                    }
                    if (curIndex == _selectedIndex)
                    {
                        q = "[" + q + "]";  //[JB] Simulate highlighting of selected question.
                    }
                    displayString(q, 122, (short)(145 + (4 - used) * 10));
                    _indexes[4 - used] = (byte)_selectedIndex;
                    used++;
                }
            }
            _activeColor   = active;
            _selectedIndex = curIndex;  //[JB] Restore selected index.  This allows highlighting to remain functional.
            pctPreview.Invalidate();
        }