示例#1
0
        public static void DoNotebox(string Line1, string Line2, int NoteboxIndex)
        {
            double scalefactorx=0, scalefactory=0;
            int lines = String.IsNullOrEmpty(Line2) ? 1 : 2;
            NoteBox nb = noteBoxColl[NoteboxIndex];
            NoteBoxLine nbl = nb.nblines.Find(delegate(NoteBoxLine n) { return n.maxLines.Equals(lines); });
            StringBuilder sb = new StringBuilder(1024);
            TimeSpan startTime, endTime;
            Line line;
            DialogueLine dl;
            nbStyleColl = new List<Style>(4);

            if (Form1.ResX > 0 && nb.resx > 0) scalefactorx = ((double)Form1.ResX / nb.resx);
            if (Form1.ResY > 0 && nb.resy > 0) scalefactory = ((double)Form1.ResY / nb.resy);
            if (scalefactorx == 0 && scalefactory != 0) scalefactorx = scalefactory;
            else if (scalefactory == 0 && scalefactorx != 0) scalefactory = scalefactorx;
            else if ((scalefactorx+scalefactory)==0) scalefactorx = scalefactory = 1.0;

            startTime = TimeSpan.Parse(Form1.FormMain.maskedTextNBStart.Text);
            endTime = TimeSpan.Parse(Form1.FormMain.maskedTextNBEnd.Text);

            Resscale rs = new Resscale(scalefactorx,scalefactory);

            for (int index = 0; index != nbl.lines.Count; index+=1) {
                line = new Line();
                line.lineType = LineType.dialogue;
                dl = (DialogueLine)(nbl.lines[index].Clone());
                dl.start = startTime;
                dl.end = endTime;
                line.line = dl;
                dl.text = dl.text.Replace("%line1%",Line1).Replace("%line2%",Line2);
                dl = rs.ScaleDialogue(dl);

                dl.style = nb.stylelist.Find(delegate(Style s) { return s.name.Equals(dl.style.name); });
                dl.style = (Style)(dl.style.Clone());
                if (nbStyleColl.Contains(dl.style) == false) nbStyleColl.Add(rs.ScaleStyle(dl.style));
                sb.AppendLine(dl.ToString());
            }
            Form1.FormMain.textNBOut.Text = sb.ToString().TrimEnd();

            sb = new StringBuilder(1024);
            for (int index = 0; index != nb.stylelist.Count; index+=1)
                sb.AppendLine(nb.stylelist[index].ToString());
            Form1.FormMain.textNBStyles.Text = sb.ToString().TrimEnd();
        }
示例#2
0
文件: Form1.cs 项目: Aegisub/SSATool
        private void cmdScale_Click(object sender, System.EventArgs e)
        {
            double XNum, XDen, YNum, YDen;
            bool XNumValid, XDenValid, YNumValid, YDenValid;

            XNumValid = double.TryParse(txtScaleXNumerator.Text, System.Globalization.NumberStyles.AllowDecimalPoint, Util.nfi, out XNum);
            XDenValid = double.TryParse(txtScaleXDenominator.Text, System.Globalization.NumberStyles.AllowDecimalPoint, Util.nfi, out XDen);
            YNumValid = double.TryParse(txtScaleYNumerator.Text, System.Globalization.NumberStyles.AllowDecimalPoint, Util.nfi, out YNum);
            YDenValid = double.TryParse(txtScaleYDenominator.Text, System.Globalization.NumberStyles.AllowDecimalPoint, Util.nfi, out YDen);

            if ((XNumValid && XDenValid) && (!YNumValid || !YDenValid)) {
                YNum = XNum;
                YDen = XDen;
                YNumValid = YDenValid = true;
            }
            else if ((YNumValid && YDenValid) && (!XNumValid || !XDenValid)) {
                XNum = YNum;
                XDen = YDen;
                XNumValid = XDenValid = true;
            }

            if (XNumValid && XDenValid && YNumValid && YDenValid) {
                double scalefactorx = XNum/XDen;
                double scalefactory = YNum/YDen;

                List<Line> newList = new List<Line>();
                Line line;
                Resscale rs = new Resscale(scalefactorx, scalefactory);
                Style s;
                DialogueLine dl;

                if (chkScalePlayRes.Checked) {
                    ResX = Convert.ToInt32(Math.Round(ResX * scalefactorx, 0), Util.nfi);
                    ResY = Convert.ToInt32(Math.Round(ResY * scalefactory, 0), Util.nfi);
                }

                for (int index = 0; index != lineColl.Count; index+=1) {
                    line = (Line)lineColl[index].Clone();
                    if (line.enabled == false) {
                        newList.Add(line);
                        continue;
                    }
                    else if (line.lineType == LineType.style && ((Style)line.line).enabled == true) {
                        s = (Style)line.line;
                        s = rs.ScaleStyle(s);
                    }

                    else if ((line.lineType == LineType.dialogue) && ((dl = (DialogueLine)line.line).style.enabled == true)) {
                        dl = rs.ScaleDialogue(dl);
                    }
                    newList.Add(line);
                }
                SetLineColl(newList);
            }
        }