Ejemplo n.º 1
0
 private void EditItem(object sender, RoutedEventArgs e)
 {
     if ((Selection.Start.Parent is Span) && ((Selection.Start.Parent as Span).Inlines.FirstInline as InlineUIContainer).Child is TextBlock item)
     {
         if (item.ToolTip as string == "Selector")
         {
             AddSelectorTextUI.selector.Text = item.Text;
             AddSelectorTextUI.Editor        = this;
             Window.ShowDialog(AddSelectorTextUI, AddSelectorTextUI.apply, AddSelectorTextUI.cancel);
         }
         else
         {
             AddObjectiveTextUI.selector.Text  = (item.ToolTip as string).Substring(4);
             AddObjectiveTextUI.objective.Text = item.Text;
             Window.ShowDialog(AddObjectiveTextUI, AddObjectiveTextUI.apply, AddSelectorTextUI.cancel);
         }
     }
     else
     {
         JsonEventInfo info = ((Selection.Start.Parent as Inline).Parent as Inline).ToolTip as JsonEventInfo;
         AddEventUI.ClickEvtType.SelectedIndex = info.ClickEventName == null ? 3 : (int)info.ClickEventName;
         AddEventUI.HoverEvtType.SelectedIndex = info.HoverEventName == null ? 4 : (int)info.HoverEventName;
         AddEventUI.ClickEvtValue.Text         = info.ClickEventValue;
         AddEventUI.HoverEvtValue.Text         = info.HoverEventValue;
         AddEventUI.Editor = this;
         AddEventUI.IsEdit = true;
         Window.ShowDialog(AddEventUI, AddEventUI.apply, AddEventUI.cancel);
     }
 }
Ejemplo n.º 2
0
        void UpdateJsonEventInfo(JsonEventInfo info)
        {
            switch (ClickEvtType.SelectedIndex)
            {
            case 0: info.ClickEventName = ClickEvents.OpenUrl; break;

            case 1: info.ClickEventName = ClickEvents.RunCommand; break;

            case 2: info.ClickEventName = ClickEvents.SuggestCommand; break;
            }
            if (info.ClickEventName != null)
            {
                info.ClickEventValue = ClickEvtValue.Text;
            }
            else
            {
                info.ClickEventValue = null;
            }
            switch (HoverEvtType.SelectedIndex)
            {
            case 0: info.HoverEventName = HoverEvents.ShowText; break;

            case 1: info.HoverEventName = HoverEvents.ShowAchievements; break;

            case 2: info.HoverEventName = HoverEvents.ShowItem; break;

            case 3: info.HoverEventName = HoverEvents.ShowEntity; break;
            }
            if (info.HoverEventName != null)
            {
                info.HoverEventValue = HoverEvtValue.Text;
            }
            else
            {
                info.HoverEventValue = null;
            }
        }
Ejemplo n.º 3
0
        private void Apply_Click(object sender, RoutedEventArgs e)
        {
            TextPointer SelectionStart = Editor.Selection.Start, SelectionEnd = Editor.Selection.End;

            if (IsEdit)
            {
                UpdateJsonEventInfo(((SelectionStart.Parent as Inline).Parent as Inline).ToolTip as JsonEventInfo);
            }
            else
            {
                if (Editor.Selection.Text == "")
                {
                    return;
                }
                JsonEventInfo info = new JsonEventInfo();
                if ((SelectionStart.Parent as Inline).Parent == (SelectionEnd.Parent as Inline).Parent && (SelectionStart.Parent as Inline).Parent is Span)
                {
                    object jei  = ((SelectionStart.Parent as Inline).Parent as Span).ToolTip;
                    Span   tmp1 = new Span(((SelectionStart.Parent as Inline).Parent as Span).ContentStart, SelectionStart)
                    {
                        ToolTip = jei
                    };
                    Span tmp2 = new Span(SelectionEnd, ((SelectionEnd.Parent as Inline).Parent as Span).ElementEnd)
                    {
                        ToolTip = jei
                    };
                }
                else
                {
                    if (SelectionStart.Parent is Span)
                    {
                        JsonEventInfo i         = (SelectionStart.Parent as Span).ToolTip as JsonEventInfo;
                        TextPointer   spanstart = (SelectionStart.Parent as Span).ContentStart;
                        Span          s         = new Span(spanstart, Editor.Selection.Start)
                        {
                            ToolTip = i
                        };
                    }
                    if (SelectionEnd.Parent is Span)
                    {
                        JsonEventInfo i       = (SelectionEnd.Parent as Span).ToolTip as JsonEventInfo;
                        TextPointer   spanend = (SelectionEnd.Parent as Span).ContentEnd;
                        Span          s       = new Span(Editor.Selection.End, spanend)
                        {
                            ToolTip = i
                        };
                    }
                }

                Span evt = new Span(Editor.Selection.Start, Editor.Selection.End)
                {
                    Background = EventBrush, ToolTip = info
                };
                UpdateJsonEventInfo(info);

                List <Span>          spans      = new List <Span>();
                IEnumerator <Inline> enumerator = evt.Inlines.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    if (enumerator.Current is Span)
                    {
                        spans.Add(enumerator.Current as Span);
                    }
                }
                foreach (Span s in spans)
                {
                    List <Inline> items = new List <Inline>(s.Inlines);
                    s.Inlines.Clear();
                    foreach (Inline i in items)
                    {
                        evt.Inlines.InsertAfter(s, i);
                    }
                    evt.Inlines.Remove(s);
                }
            }
        }
Ejemplo n.º 4
0
        public string GetJsonText()
        {
            List <MinecraftJsonText> group = new List <MinecraftJsonText>();

            foreach (Block b in Document.Blocks)
            {
                if (!(b is Paragraph))
                {
                    continue;
                }
                foreach (Inline inline in (b as Paragraph).Inlines)
                {
                    MinecraftJsonText text = new MinecraftJsonText();
                    if (inline is Run)
                    {
                        Run r = inline as Run;
                        if (r.Text == "")
                        {
                            continue;
                        }
                        text.ImportFontStyle(r, DefaultFontColor);
                    }
                    else if (inline is Span)
                    {
                        Span s = inline as Span;
                        if (s.Inlines.FirstInline is InlineUIContainer)
                        {
                            TextBlock r = (s.Inlines.FirstInline as InlineUIContainer).Child as TextBlock;
                            if (r.Text == "")
                            {
                                continue;
                            }
                            if (r.Background == JsonSelectorEditor.SelectorBrush)
                            {
                                text.Selector = r.Text;
                            }
                            else
                            {
                                text.Score = new Score {
                                    Objective = r.Text, Name = r.ToolTip as string
                                };
                            }
                            text.ImportFontStyle(r, DefaultFontColor);
                            text.Text = null;
                        }
                        else
                        {
                            JsonEventInfo evt = s.ToolTip as JsonEventInfo;
                            ClickEvent    click = null; HoverEvent hover = null;
                            if (evt.ClickEventName != null)
                            {
                                click = new ClickEvent {
                                    Action = (ClickEvents)evt.ClickEventName, Value = evt.ClickEventValue
                                }
                            }
                            ;
                            if (evt.HoverEventName != null)
                            {
                                hover = new HoverEvent {
                                    Action = (HoverEvents)evt.HoverEventName, Value = evt.HoverEventValue
                                }
                            }
                            ;

                            foreach (Inline element in s.Inlines)
                            {
                                MinecraftJsonText t = new MinecraftJsonText {
                                    ClickEvent = click, HoverEvent = hover
                                };
                                if (element is Run)
                                {
                                    Run r = element as Run;
                                    if (r.Text == "")
                                    {
                                        continue;
                                    }
                                    t.ImportFontStyle(r, DefaultFontColor);
                                }
                                else
                                {
                                    TextBlock r = ((element as Span).Inlines.FirstInline as InlineUIContainer).Child as TextBlock;
                                    if (r.Text == "")
                                    {
                                        continue;
                                    }
                                    t.ImportFontStyle(r, DefaultFontColor);
                                }
                                group.Add(t);
                            }
                        }
                    }
                    group.Add(text);
                }
                if (b != Document.Blocks.LastBlock)
                {
                    group.Add(new MinecraftJsonText {
                        Text = "\n"
                    });
                }
            }
            if (group.Count == 0)
            {
                return("");
            }
            else if (group.Count == 1)
            {
                return(group[0].GetJsonText());
            }
            else
            {
                return((new MinecraftJsonText {
                    Text = "", Extra = group.ToArray()
                }).GetJsonText());
            }
        }
    }
}