示例#1
0
            protected override VisualLineText CreateInstance(int length)
            {
                var res = new ClickVisualLineText(Text, ParentVisualLine, length);

                res.Clicked += Clicked;
                return(res);
            }
示例#2
0
            /// Constructs an element at the specified offset.
            /// May return null if no element should be constructed.
            public override VisualLineElement ConstructElement(int offset)
            {
                Match m = FindMatch(offset, regex);

                if (m.Success && m.Index == 0)
                {
                    UndertaleData data = (Application.Current.MainWindow as MainWindow).Data;
                    bool          func = (offset + m.Length + 1 < CurrentContext.VisualLine.LastDocumentLine.EndOffset) &&
                                         (CurrentContext.Document.GetCharAt(offset + m.Length) == '(');
                    UndertaleNamedResource val = null;

                    var doc      = CurrentContext.Document;
                    var textArea = CurrentContext.TextView.GetService(typeof(TextArea)) as TextArea;
                    var editor   = textArea.GetService(typeof(TextEditor)) as TextEditor;
                    var parent   = VisualTreeHelper.GetParent(editor);
                    do
                    {
                        if ((parent as FrameworkElement) is UserControl)
                        {
                            break;
                        }
                        parent = VisualTreeHelper.GetParent(parent);
                    } while (parent != null);

                    // Process the content of this identifier/function
                    if (func)
                    {
                        val = data.Scripts.ByName(m.Value);
                        if (val == null)
                        {
                            val = data.Functions.ByName(m.Value);
                        }
                    }
                    else
                    {
                        val = data.ByName(m.Value);
                    }
                    if (val == null)
                    {
                        if (offset >= 7)
                        {
                            if (CurrentContext.Document.GetText(offset - 7, 7) == "global.")
                            {
                                return(new ColorVisualLineText(m.Value, CurrentContext.VisualLine, m.Length,
                                                               new SolidColorBrush(Color.FromRgb(0xF9, 0x7B, 0xF9))));
                            }
                        }
                        if (data.BuiltinList.Constants.ContainsKey(m.Value))
                        {
                            return(new ColorVisualLineText(m.Value, CurrentContext.VisualLine, m.Length,
                                                           new SolidColorBrush(Color.FromRgb(0xFF, 0x80, 0x80))));
                        }
                        if (data.BuiltinList.GlobalNotArray.ContainsKey(m.Value) ||
                            data.BuiltinList.Instance.ContainsKey(m.Value) ||
                            data.BuiltinList.GlobalArray.ContainsKey(m.Value))
                        {
                            return(new ColorVisualLineText(m.Value, CurrentContext.VisualLine, m.Length,
                                                           new SolidColorBrush(Color.FromRgb(0x58, 0xE3, 0x5A))));
                        }
                        if ((parent as UndertaleCodeEditor).CurrentDecompiledLocals.Contains(m.Value))
                        {
                            return(new ColorVisualLineText(m.Value, CurrentContext.VisualLine, m.Length,
                                                           new SolidColorBrush(Color.FromRgb(0xFF, 0xF8, 0x99))));
                        }
                        return(null);
                    }

                    var line = new ClickVisualLineText(m.Value, CurrentContext.VisualLine, m.Length,
                                                       func ? null : new SolidColorBrush(Color.FromRgb(0xFF, 0x80, 0x80)));
                    line.Clicked += (text) =>
                    {
                        (Application.Current.MainWindow as MainWindow).ChangeSelection(val);
                    };

                    return(line);
                }

                return(null);
            }
示例#3
0
            /// Constructs an element at the specified offset.
            /// May return null if no element should be constructed.
            public override VisualLineElement ConstructElement(int offset)
            {
                Match m = FindMatch(offset, regex);

                if (m.Success && m.Index == 0)
                {
                    var line     = new ClickVisualLineText(m.Value, CurrentContext.VisualLine, m.Length);
                    var doc      = CurrentContext.Document;
                    var textArea = CurrentContext.TextView.GetService(typeof(TextArea)) as TextArea;
                    var editor   = textArea.GetService(typeof(TextEditor)) as TextEditor;
                    var parent   = VisualTreeHelper.GetParent(editor);
                    do
                    {
                        if ((parent as FrameworkElement) is UserControl)
                        {
                            break;
                        }
                        parent = VisualTreeHelper.GetParent(parent);
                    } while (parent != null);
                    line.Clicked += (text) =>
                    {
                        if (text.EndsWith("."))
                        {
                            return;
                        }
                        if (int.TryParse(text, out int id))
                        {
                            (parent as UndertaleCodeEditor).DecompiledFocused = true;
                            UndertaleData data = (Application.Current.MainWindow as MainWindow).Data;

                            List <UndertaleObject> possibleObjects = new List <UndertaleObject>();
                            if (id >= 0)
                            {
                                if (id < data.Sprites.Count)
                                {
                                    possibleObjects.Add(data.Sprites[id]);
                                }
                                if (id < data.Rooms.Count)
                                {
                                    possibleObjects.Add(data.Rooms[id]);
                                }
                                if (id < data.GameObjects.Count)
                                {
                                    possibleObjects.Add(data.GameObjects[id]);
                                }
                                if (id < data.Backgrounds.Count)
                                {
                                    possibleObjects.Add(data.Backgrounds[id]);
                                }
                                if (id < data.Scripts.Count)
                                {
                                    possibleObjects.Add(data.Scripts[id]);
                                }
                                if (id < data.Paths.Count)
                                {
                                    possibleObjects.Add(data.Paths[id]);
                                }
                                if (id < data.Fonts.Count)
                                {
                                    possibleObjects.Add(data.Fonts[id]);
                                }
                                if (id < data.Sounds.Count)
                                {
                                    possibleObjects.Add(data.Sounds[id]);
                                }
                                if (id < data.Shaders.Count)
                                {
                                    possibleObjects.Add(data.Shaders[id]);
                                }
                                if (id < data.Timelines.Count)
                                {
                                    possibleObjects.Add(data.Timelines[id]);
                                }
                            }

                            ContextMenu contextMenu = new ContextMenu();
                            foreach (UndertaleObject obj in possibleObjects)
                            {
                                MenuItem item = new MenuItem();
                                item.Header = obj.ToString().Replace("_", "__");
                                item.Click += (sender2, ev2) =>
                                {
                                    if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift)
                                    {
                                        (Application.Current.MainWindow as MainWindow).ChangeSelection(obj);
                                    }
                                    else
                                    {
                                        doc.Replace(line.ParentVisualLine.StartOffset + line.RelativeTextOffset,
                                                    text.Length, (obj as UndertaleNamedResource).Name.Content, null);
                                        (parent as UndertaleCodeEditor).DecompiledChanged = true;
                                    }
                                };
                                contextMenu.Items.Add(item);
                            }
                            if (id > 0x00050000)
                            {
                                MenuItem item = new MenuItem();
                                item.Header = "0x" + id.ToString("X6") + " (color)";
                                item.Click += (sender2, ev2) =>
                                {
                                    if (!((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift))
                                    {
                                        doc.Replace(line.ParentVisualLine.StartOffset + line.RelativeTextOffset,
                                                    text.Length, "0x" + id.ToString("X6"), null);
                                        (parent as UndertaleCodeEditor).DecompiledChanged = true;
                                    }
                                };
                                contextMenu.Items.Add(item);
                            }
                            BuiltinList list  = (Application.Current.MainWindow as MainWindow).Data.BuiltinList;
                            var         myKey = list.Constants.FirstOrDefault(x => x.Value == (double)id).Key;
                            if (myKey != null)
                            {
                                MenuItem item = new MenuItem();
                                item.Header = myKey.Replace("_", "__") + " (constant)";
                                item.Click += (sender2, ev2) =>
                                {
                                    if (!((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift))
                                    {
                                        doc.Replace(line.ParentVisualLine.StartOffset + line.RelativeTextOffset,
                                                    text.Length, myKey, null);
                                        (parent as UndertaleCodeEditor).DecompiledChanged = true;
                                    }
                                };
                                contextMenu.Items.Add(item);
                            }
                            contextMenu.Items.Add(new MenuItem()
                            {
                                Header = id + " (number)", IsEnabled = false
                            });

                            contextMenu.IsOpen = true;
                        }
                    };
                    return(line);
                }

                return(null);
            }