Пример #1
0
 public MainForm()
 {
     InitializeComponent();
     //NewConsole.Init();
     Font10Converter.Init();
     TexBmpConv.Init();
 }
Пример #2
0
        /// <summary>
        /// Gets the index of the character which exceeds the specified width in the specified font.
        /// </summary>
        /// <param name="font">Font by which to measure characters</param>
        /// <param name="s">The string to measure</param>
        /// <param name="width">The width to check against</param>
        /// <param name="ignoreColours">Whether or not to ignore c:XXXXXX and c tags' width.</param>
        /// <returns></returns>
        public static int GetIndexWhereWidthExceeds(sNFTR font, string s, int width, bool ignoreColours)
        {
            int l = 0;

            ushort[] codes = Font10Converter.GetCodes(s);
            for (int i = 0; i < codes.Length; ++i)
            {
                if (codes[i] == '<' && codes.Length >= i + 2 && codes[i + 1] == 'c')
                {
                    if (codes[i + 2] == ':')
                    {
                        i += 10 - 1;                         // -1 to account for the continue;
                        continue;
                    }
                    else if (codes[i + 2] == '>')
                    {
                        i += 3 - 1;                         // -1 to account for the continue;
                        continue;
                    }
                }
                int idx = TexBmpConv.IndexFromCode(codes[i]);
                l += font.hdwc.info[idx].pixel_width + font.hdwc.info[idx].pixel_start;
                if (l >= width)
                {
                    return(i);
                }
            }
            return(s.Length);
        }
Пример #3
0
        public static int GetStringWidth(sNFTR font, string s)
        {
            int l = 0;

            ushort[] codes = Font10Converter.GetCodes(s);
            for (int i = 0; i < codes.Length; ++i)
            {
                int idx = TexBmpConv.IndexFromCode(codes[i]);
                l += font.hdwc.info[idx].pixel_width;
            }
            return(l);
        }
Пример #4
0
        public byte[] ToByteArray()
        {
            List <byte> ret = new List <byte>();

            for (int j = 0; j < args.Count; ++j)
            {
                ret.AddRange(Font10Converter.GetBytes(args[j]));
                ret.Add(0);
            }
            ret.Add(0x0D);
            //NewConsole.WriteLine(ret);
            return(ret.ToArray());
        }
Пример #5
0
        private void loadSPT()
        {
            if (sptReader == null)
            {
                return;
            }
            panel1.Controls.Clear();
            lastElement = null;
            Edited      = false;

            // data structure set up
            int id = 0;

            root           = new SPTBlock(0);
            blockHierarchy = new Stack <SPTBlock>();
            blockHierarchy.Push(root);
            SPTCommand c;

            // case-specific flags
            bool needNewBlock      = true;
            bool checkNameWinClose = false;

            while ((c = SPTCommand.FromStream(sptReader, id++, blockHierarchy.Peek())) != null)
            {
                // pre loop logic
                if (c.GetArg(0)[0] == '{')
                {
                    SPTBlock b = new SPTBlock(id);
                    b.Elements.Add(c);
                    blockHierarchy.Peek().Elements.Add(b);
                    blockHierarchy.Push(b);
                    continue;
                }
                else if (c.GetArg(0)[0] == '}')
                {
                    blockHierarchy.Pop().Elements.Add(c);
                    continue;
                }
                blockHierarchy.Peek().Elements.Add(c);
                if (!(c.GetArg(0).Equals("message") || c.GetArg(0).Equals("message0")))
                {
                    needNewBlock = true;
                }
                ////

                if (c.GetArg(0).Equals("message") || c.GetArg(0).Equals("message0"))                 // start of message set
                {
                    if (needNewBlock)
                    {
                        if (c.GetArg(1) != "mbox0")
                        {
                            addTranslatable(new Note("Found non-mbox0 message box, tell me about this", id));
                        }
                        addTranslatable(new MessageBlock());
                        needNewBlock = false;
                    }
                    for (int i = 2; i < c.ArgCount; ++i)
                    {
                        string msg = c.GetArg(i);
                        if (i + 1 < c.ArgCount)
                        {
                            msg += "§";
                        }
                        lastElement.JapText += msg;
                    }
                    lastElement.JapText += "¶\r\n";
                    lastElement.commands.Add(c);
                }
                else if (c.GetArg(0).Equals("nameset0"))                 // setting talker name
                {
                    if (c.GetArg(1).Equals("N0"))
                    {
                        addTranslatable(new Nameplate());
                        lastElement.JapText = c.GetArg(2);
                        lastElement.commands.Add(c);
                    }
                }
                else if (c.GetArg(0).Equals("nameset"))                 // check for azuma talking
                {
                    if (c.GetArg(1).Equals("N0") && c.GetArg(2).StartsWith("00_"))
                    {
                        if (lastElement != null && lastElement.JapText.Equals("NO NAME:"))                         //it removes nameplate for azuma, have to ignore for this
                        {
                            panel1.Controls.Remove(lastElement);
                        }
                        lastElement = ((panel1.Controls.Count - 1 >= 0) ? (Translatable)panel1.Controls[panel1.Controls.Count - 1] : null);
                        addTranslatable(new Note("AZUMA:"));
                    }
                }
                else if (c.GetArg(0).Equals("actortext0") && c.GetArg(1).Equals("name_win"))                 // check if name window being hidden
                {
                    checkNameWinClose = true;
                    continue;
                }
                else if (c.GetArg(0).Equals("actordisp0") && c.GetArg(1).Equals("name_win") && c.GetArg(2).Equals("false") && checkNameWinClose)
                {
                    addTranslatable(new Note("NO NAME:"));
                }
                else if (c.GetArg(0).Equals("scriptcall0") && c.GetArg(1).Equals("select"))
                {
                    int nopts = Convert.ToInt32(c.GetArg(2));
                    addTranslatable(new Note("SELECTION (" + nopts + "):"));
                    GenericTranslatable t = new GenericTranslatable(c);
                    for (int i = 0; i < nopts + 1; ++i)
                    {
                        t.AddArg(new GenericTArgOpts(3 + i, (i > 0)));
                    }
                    addTranslatable(t);
                }
                else if (c.GetArg(0).Equals("scriptcall"))
                {
                    addTranslatable(new Note("Note: This script calls \"" + c.GetArg(1) + ".spt\"."));
                }
                else if (c.GetArg(0).StartsWith("ifselect") || (c.ArgCount > 1 && c.GetArg(1).StartsWith("ifselect")))
                {
                    addTranslatable(new Note("IF-SELECT:"));
                    GenericTranslatable t = new GenericTranslatable(c);
                    t.AddArg(new GenericTArgOpts(c.GetArg(0).StartsWith("ifselect") ? 1 : 2, true));
                    addTranslatable(t);
                }
                else
                {
                    // some non-known command. try finding japanese text.
                    // arg 0 is always english command - it won't have japanese text.
                    bool done = false;
                    if (c.ArgCount > 1)
                    {
                        for (int i = 1; i < c.ArgCount && !done; ++i)
                        {
                            string arg = c.GetArg(i);
                            // check if one of the first 3 characters is japanese
                            for (int j = 0; j < Math.Min(3, arg.Length); ++j)
                            {
                                if (Font10Converter.IsJapanese(arg[j]))
                                {
                                    addTranslatable(new Note("Unidentified Japanese text detected, tell me about this. Full command shown.", id));
                                    GenericTranslatable t = new GenericTranslatable(c);
                                    for (int k = 0; k < c.ArgCount; ++k)
                                    {
                                        t.AddArg((GenericTArgOpts)k);
                                    }
                                    addTranslatable(t);
                                    done = true;
                                    break;
                                }
                            }
                        }
                    }
                }

                ////
                checkNameWinClose = false;
                // post loop logic
            }
            panel1.Focus();             // so the scroll bar works more intuitively
            UpdateFromMemory();
            status("Loaded \"" + txtSPTPath.Text.Substring(txtSPTPath.Text.LastIndexOf('\\') + 1) + "\"");
        }