GameCreateFriendViewModel.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. using System.Collections.Generic;
  2. using System.Collections.ObjectModel;
  3. using Avalonia;
  4. using Avalonia.Controls;
  5. using Avalonia.Controls.Shapes;
  6. using Avalonia.Layout;
  7. using Avalonia.Media;
  8. using HelloItQuantum.Function;
  9. using HelloItQuantum.Models;
  10. using HelloItQuantum.Views;
  11. namespace HelloItQuantum.ViewModels
  12. {
  13. public class GameCreateFriendViewModel : MainWindowViewModel
  14. {
  15. Dictionary<int, Color> keyValueColor = new Dictionary<int, Color>
  16. {
  17. { 0, Color.Parse("#0036A0") },
  18. { 1, Color.Parse("#F26527") },
  19. { 2, Color.Parse("#B21E22") },
  20. { 3, Color.Parse("#006838") }
  21. };
  22. public void GoBack() => PageSwitch.View = new PlaySectionView();
  23. #region Object and Property for Xaml
  24. ObservableCollection<FriendElement> listElements = new ObservableCollection<FriendElement>();
  25. public ObservableCollection<FriendElement> ListElements { get => listElements; set => SetProperty(ref listElements, value); }
  26. Panel pChildrens = new Panel();
  27. public Panel PChildrens { get => pChildrens; set => SetProperty(ref pChildrens, value); }
  28. bool isVisibleHello = false;
  29. public bool IsVisibleHello { get => isVisibleHello; set => SetProperty(ref isVisibleHello, value); }
  30. string btnContent = "ÑÎÇÄÀÒÜ";
  31. public string BtnContent { get => btnContent; set => SetProperty(ref btnContent, value); }
  32. SolidColorBrush btnColor = new SolidColorBrush(Color.Parse("#7CBE41"));
  33. public SolidColorBrush BtnColor { get => btnColor; set => SetProperty(ref btnColor, value); }
  34. #endregion
  35. public void ClickCreateElement()
  36. {
  37. FriendElement friendElement = new FriendElement();
  38. ObservableCollection<Ellipse> lColors = new ObservableCollection<Ellipse>();
  39. ObservableCollection<ComboBoxItem> lElements = new ObservableCollection<ComboBoxItem>();
  40. ObservableCollection<ComboBoxItem> lNavigateOne = new ObservableCollection<ComboBoxItem>();
  41. ObservableCollection<ComboBoxItem> lNavigateTwo = new ObservableCollection<ComboBoxItem>();
  42. for (int i = 0; i < 7; i++)
  43. {
  44. lElements.Add(Converts.GenericToItem(CreateElFriend.CreateElement(i, Color.Parse("#293558"))));
  45. }
  46. friendElement.CbElement = lElements;
  47. foreach (var item in keyValueColor)
  48. {
  49. lColors.Add(CreateElFriend.CreateEllipse(50, item.Value));
  50. }
  51. friendElement.CbColor = lColors;
  52. lNavigateOne.Add(Converts.GenericToItem(CreateElFriend.CreateSvgImage("/Assets/ImgCreateFriend/no_shift.svg", 30, null)));
  53. lNavigateOne.Add(Converts.GenericToItem(CreateElFriend.CreateSvgImage("/Assets/ImgCreateFriend/left.svg", 30, null)));
  54. lNavigateOne.Add(Converts.GenericToItem(CreateElFriend.CreateSvgImage("/Assets/ImgCreateFriend/right.svg", 30, null)));
  55. friendElement.CbNavigateOne = lNavigateOne;
  56. lNavigateTwo.Add(Converts.GenericToItem(CreateElFriend.CreateSvgImage("/Assets/ImgCreateFriend/no_shift.svg", 30, null)));
  57. lNavigateTwo.Add(Converts.GenericToItem(CreateElFriend.CreateSvgImage("/Assets/ImgCreateFriend/top.svg", 30, null)));
  58. lNavigateTwo.Add(Converts.GenericToItem(CreateElFriend.CreateSvgImage("/Assets/ImgCreateFriend/bottom.svg", 30, null)));
  59. friendElement.CbNavigateTwo = lNavigateTwo;
  60. friendElement.Id = ListElements.Count;
  61. ListElements.Add(friendElement);
  62. UpdateDrawing(ListElements.Count - 1);
  63. }
  64. public void ClickCreateFriend()
  65. {
  66. if (btnContent == "ÑÎÇÄÀÒÜ" && PChildrens.Children.Count > 1)
  67. {
  68. WorkWithFile.UpdateValueGameProgress(3, 100, CurrentUser);
  69. IsVisibleHello = true;
  70. BtnContent = "ÇÀÍÎÂÎ";
  71. BtnColor = new SolidColorBrush(Color.Parse("#F26527"));
  72. }
  73. else if (btnContent == "ÇÀÍÎÂÎ")
  74. {
  75. IsVisibleHello = false;
  76. BtnContent = "ÑÎÇÄÀÒÜ";
  77. BtnColor = new SolidColorBrush(Color.Parse("#7CBE41"));
  78. PChildrens.Children.Clear();
  79. ListElements.Clear();
  80. }
  81. }
  82. public void Delete(int id)
  83. {
  84. pChildrens.Children.RemoveAt(id);
  85. ListElements.RemoveAt(id);
  86. for (int i = 0; i < ListElements.Count; i++)
  87. {
  88. ListElements[i].Id = i;
  89. }
  90. }
  91. public void UpdateDrawing(int id)
  92. {
  93. Color color = keyValueColor[ListElements[id].SelectedColorIndex];
  94. int indexEl = ListElements[id].SelectedElementIndex;
  95. Control element = CreateElFriend.CreateElement(indexEl, color);
  96. if (id < pChildrens.Children.Count)
  97. pChildrens.Children[id] = element; //Èçìåíÿåì ýëåìåíò
  98. else
  99. pChildrens.Children.Add(element); //Äîáàâëÿåì íîâûé
  100. UpdateNavigate(id);
  101. }
  102. public void UpdateNavigate(int id)
  103. {
  104. int element = ListElements[id].SelectedElementIndex;
  105. pChildrens.Children[id].Margin = new Thickness(0, 0, 0, 0);
  106. if (element >= 3 && element <= 6)
  107. {
  108. int margin = (element == 3 || element == 4) ? 27 : 24;
  109. switch (ListElements[id].SelectedNavigateOne)
  110. {
  111. case 1:
  112. pChildrens.Children[id].HorizontalAlignment = HorizontalAlignment.Left;
  113. pChildrens.Children[id].Margin = new Thickness(margin, 0, 0, 0);
  114. break;
  115. case 2:
  116. pChildrens.Children[id].HorizontalAlignment = HorizontalAlignment.Right;
  117. pChildrens.Children[id].Margin = new Thickness(0, 0, margin, 0);
  118. break;
  119. default: pChildrens.Children[id].HorizontalAlignment = HorizontalAlignment.Center; break;
  120. }
  121. if (element == 5 || element == 6)
  122. {
  123. switch (ListElements[id].SelectedNavigateTwo)
  124. {
  125. case 1:
  126. pChildrens.Children[id].VerticalAlignment = VerticalAlignment.Top;
  127. pChildrens.Children[id].Margin = new Thickness(pChildrens.Children[id].Margin.Left, 40, pChildrens.Children[id].Margin.Right, 0);
  128. break;
  129. case 2:
  130. pChildrens.Children[id].VerticalAlignment = VerticalAlignment.Bottom;
  131. pChildrens.Children[id].Margin = new Thickness(pChildrens.Children[id].Margin.Left, 0, pChildrens.Children[id].Margin.Right, 40);
  132. break;
  133. default: pChildrens.Children[id].VerticalAlignment = VerticalAlignment.Center; break;
  134. }
  135. }
  136. else
  137. {
  138. pChildrens.Children[id].VerticalAlignment = VerticalAlignment.Bottom;
  139. }
  140. }
  141. else
  142. {
  143. pChildrens.Children[id].HorizontalAlignment = HorizontalAlignment.Center;
  144. pChildrens.Children[id].VerticalAlignment = VerticalAlignment.Center;
  145. }
  146. }
  147. /// <summary>
  148. /// Âèäèìîñòü äîïîëíèòåëüíîãî ïàðàìåòðà äëÿ ñäâèãà ôèãóðû
  149. /// </summary>
  150. /// <param name="id"></param>
  151. public void UpdateVisible(int id)
  152. {
  153. if (ListElements[id].SelectedElementIndex == 5 || ListElements[id].SelectedElementIndex == 6)
  154. {
  155. ListElements[id].IsVisibleNavigateOne = true;
  156. ListElements[id].IsVisibleNavigateTwo = true;
  157. }
  158. else if (ListElements[id].SelectedElementIndex == 3 || ListElements[id].SelectedElementIndex == 4)
  159. {
  160. ListElements[id].IsVisibleNavigateOne = true;
  161. ListElements[id].IsVisibleNavigateTwo = false;
  162. }
  163. else
  164. {
  165. ListElements[id].IsVisibleNavigateOne = false;
  166. ListElements[id].IsVisibleNavigateTwo = false;
  167. }
  168. }
  169. }
  170. }