Terraria.Ja.GetDialog C# (CSharp) Method

GetDialog() public static method

public static GetDialog ( int l ) : string
l int
return string
        public static string GetDialog(int l)
        {
            if (language == null) return "";

            // ������擾
            Dictionary<int, string> dic;
            if (language.TryGetValue("dialogs", out dic))
            {
                // �e�L�X�g��擾
                var temp = "";
                if (dic.TryGetValue(l, out temp))
                {
                    // �S�p�󔒕����͉��s�R�[�h�ɕϊ�����
                    temp = temp.Replace('�@', '\n');

                    // �e�L�����N�^�[�̖��O��ϊ�����
                    var type_main = Type.GetType("Terraria.Main");
                    var fld_player = type_main.GetField("player");
                    var fld_myPlayer = type_main.GetField("myPlayer");
                    var fld_chrName = type_main.GetField("chrName");
                    var type_player = Type.GetType("Terraria.Player");
                    var fld_name = type_player.GetField("name");

                    var chrName = (string[])fld_chrName.GetValue(null);
                    var myPlayer = (int)fld_myPlayer.GetValue(null);
                    var player = (Object[])fld_player.GetValue(null);
                    var name = (string)fld_name.GetValue(player[myPlayer]);

                    temp = temp.Replace("{Player}", name);
                    temp = temp.Replace("{Nurse}", chrName[18]);
                    temp = temp.Replace("{Mechanic}", chrName[124]);
                    temp = temp.Replace("{Demolitionist}", chrName[38]);
                    temp = temp.Replace("{Guide}", chrName[22]);
                    temp = temp.Replace("{Merchant}", chrName[17]);
                    temp = temp.Replace("{Arms Dealer}", chrName[19]);
                    temp = temp.Replace("{Dryad}", chrName[20]);
                    temp = temp.Replace("{Goblin}", chrName[107]);

                    // ���s�R�[�h�ň�s���Ƃɕ�����
                    var strs = temp.Split(new char[] { '\n' });

                    // �P���C�����Ƃɏ������Ă����A�P�s�Q�T�����O��𒴂����玩���ʼn��s��}��
                    for (int x = 0; x < strs.Length; x++)
                    {
                        if (strs[x].Length <= MAX_NUM) continue;

                        int i = 0;
                        int j = 0;
                        bool not_newline = false;
                        while (true)
                        {
                            if (i >= strs[x].Length) break;
                            char c = strs[x][i];

                            // ���p�����̊Ԃ͉��s���Ȃ�
                            not_newline = (0x20 <= c && c <= 0x7D);

                            // �֑������̊Ԃ͉��s���Ȃ�
                            not_newline = not_newline || c == '�B' || c == '�A' || c == '�u' || c == '�v';

                            // ���p�����łȂ��A�ő啶�����𒴂��Ă�������s
                            if (!not_newline && (j / 2) >= (MAX_NUM - 1))
                            {
                                strs[x] = strs[x].Insert(i, "\n");
                                Console.WriteLine("�P���C���������F" + strs[x]);
                                j = 0;
                                i += 2;
                                continue;
                            }

                            i++;

                            // ���p�Ȃ�P�������A�S�p�Ȃ�Q�������Ƃ��ăJ�E���g
                            if (not_newline) j++;
                            else j += 2;
                        }
                    }

                    // �Ō�ɉ��s�R�[�h�ŘA��
                    var new_text = string.Join("\n", strs);
                    return new_text;
                }
            }
            return "";
        }

Usage Example

Exemplo n.º 1
0
        public static string dialog(int l)
        {
            // オリジナルのテキストを取得
            var type       = typeof(Terraria.Lang);
            var method     = type.GetMethod("_dialog");
            var str_origin = (string)method.Invoke(null, new object[] { l });

            // XML上のテキストを取得
            var str_ja = Ja.GetDialog(l);

            // 空でない方のテキストを返す
            return((str_ja == "") ? str_origin : str_ja);
        }