-
Notifications
You must be signed in to change notification settings - Fork 0
/
WidgetElement.xaml.cs
97 lines (93 loc) · 3.62 KB
/
WidgetElement.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace RPGcardsGenerator
{
/// <summary>
/// Logique d'interaction pour WidgetElement.xaml
/// </summary>
public partial class WidgetElement : UserControl
{
public IDrawableWidget Link;
public WidgetElement(IDrawableWidget widget)
{
InitializeComponent();
Link = widget;
var index = App.CurrentFile.Widgets.FindIndex((element) => element.Item2 == widget.Link);
if (index == 0)
upButton.IsEnabled = false;
if (index == App.CurrentFile.Widgets.Count - 1)
downButton.IsEnabled = false;
id.Text = App.CurrentFile.Widgets[index].Item1;
}
private void downButton_Click(object sender, RoutedEventArgs e)
{
{
var position = App.CurrentFile.Widgets.FindIndex(set => set.Item2 == Link.Link);
var curr = App.CurrentFile.Widgets[position];
App.CurrentFile.Widgets.RemoveAt(position);
App.CurrentFile.Widgets.Insert(position + 1, curr);
}
{
var position = App.Preview.ToDraw.IndexOf(Link);
App.Preview.ToDraw.RemoveAt(position);
App.Preview.ToDraw.Insert(position + 1, Link);
}
{
var panel = Parent as StackPanel;
var location = panel.Children.IndexOf(this);
panel.Children.Remove(this);
panel.Children.Insert(location + 1, this);
if (location == 0)
{
upButton.IsEnabled = true;
(panel.Children[0] as WidgetElement).upButton.IsEnabled = false;
}
if (location == App.CurrentFile.Widgets.Count - 2)
{
downButton.IsEnabled = false;
(panel.Children[App.CurrentFile.Widgets.Count - 2] as WidgetElement).downButton.IsEnabled = true;
}
}
}
private void upButton_Click(object sender, RoutedEventArgs e)
{
{
var position = App.CurrentFile.Widgets.FindIndex(set => set.Item2 == Link.Link);
var curr = App.CurrentFile.Widgets[position];
App.CurrentFile.Widgets.RemoveAt(position);
App.CurrentFile.Widgets.Insert(position - 1, curr);
}
{
var position = App.Preview.ToDraw.IndexOf(Link);
App.Preview.ToDraw.RemoveAt(position);
App.Preview.ToDraw.Insert(position - 1, Link);
}
{
var panel = Parent as StackPanel;
var location = panel.Children.IndexOf(this);
panel.Children.Remove(this);
panel.Children.Insert(location - 1, this);
if (location == 1)
{
upButton.IsEnabled = false;
(panel.Children[1] as WidgetElement).upButton.IsEnabled = true;
}
if (location == App.CurrentFile.Widgets.Count - 1)
{
downButton.IsEnabled = true;
(panel.Children[App.CurrentFile.Widgets.Count - 1] as WidgetElement).downButton.IsEnabled = false;
}
}
}
}
}