Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Windows;
  5. using System.Windows.Data;
  6. using System.Windows.Documents;
  7. using System.Windows.Media;
  8.  
  9. namespace WpfApp1.Logic
  10. {
  11. public class ThreatToInlinesConverter : IValueConverter
  12. {
  13. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  14. {
  15. Event t = (Event)value;
  16. List<Run> inlines = new List<Run>();
  17.  
  18. Color zoneColor = Color.FromRgb(0, 0, 0);
  19. Color textColor = Color.FromRgb(200, 0, 160);
  20. string zone = "";
  21. string phase = "";
  22. if (t.Time / 60 > 10)
  23. {
  24. inlines.Add(new Run(" "));
  25. }
  26. switch (t.Types)
  27. {
  28. case Types.LineBreak:
  29. inlines.Add(new Run($""));
  30. return inlines;
  31.  
  32. case Types.Start:
  33. inlines.Add(new Run($" 0:00 Enemy activity detected. Please begin 1st phase."));
  34. return inlines;
  35.  
  36. case Types.PhaseEnd:
  37. switch (t.Phase)
  38. {
  39. case Phase.first:
  40. phase = "1st";
  41. break;
  42.  
  43. case Phase.second:
  44. phase = "2nd";
  45. break;
  46.  
  47. case Phase.third:
  48. phase = "3rd";
  49. break;
  50.  
  51. default:
  52. throw new ArgumentOutOfRangeException();
  53. }
  54. switch (t.PhaseStep)
  55. {
  56. case PhaseStep.one:
  57. inlines.Add(new Run($" {t.Time / 60}:{(t.Time % 60).ToString("D2")} {phase} phase ends in one minute."));
  58. break;
  59.  
  60. case PhaseStep.two:
  61. inlines.Add(new Run($" {t.Time / 60}:{(t.Time % 60).ToString("D2")} {phase} phase ends in twenty seconds."));
  62. break;
  63.  
  64. case PhaseStep.three:
  65. switch (t.Phase)
  66. {
  67. case Phase.first:
  68. inlines.Add(new Run($" {t.Time / 60}:{(t.Time % 60).ToString("D2")} {phase} ends in 5, 4, 3, 2, 1 ... 2nd phase."));
  69. break;
  70.  
  71. case Phase.second:
  72. inlines.Add(new Run($" {t.Time / 60}:{(t.Time % 60).ToString("D2")} {phase} ends in 5, 4, 3, 2, 1 ... 3rd phase."));
  73. break;
  74.  
  75. case Phase.third:
  76. inlines.Add(new Run($" {t.Time / 60}:{(t.Time % 60).ToString("D2")} {phase} ends in 5, 4, 3, 2, 1. Mission Complete."));
  77. break;
  78. }
  79. break;
  80.  
  81. default:
  82. throw new ArgumentOutOfRangeException();
  83. }
  84. return inlines;
  85.  
  86. case Types.DataTransfer:
  87. inlines.Add(new Run($" {t.Time / 60}:{(t.Time % 60).ToString("D2")} Data Transfer. Data transfer in 5, 4, 3, 2, 1.") { Foreground = new SolidColorBrush(textColor) });
  88. return inlines;
  89.  
  90. case Types.IncomingData:
  91. inlines.Add(new Run($" {t.Time / 60}:{(t.Time % 60).ToString("D2")} Incoming data.") { Foreground = new SolidColorBrush(textColor) });
  92. return inlines;
  93.  
  94. case Types.CommunicationOutage:
  95. inlines.Add(new Run($" {t.Time / 60}:{(t.Time % 60).ToString("D2")} Communication system down ...") { Foreground = new SolidColorBrush(textColor) });
  96. return inlines;
  97.  
  98. case Types.CommunicationRestored:
  99. inlines.Add(new Run($" {t.Time / 60}:{(t.Time % 60).ToString("D2")} ... communications restored.") { Foreground = new SolidColorBrush(textColor) });
  100. return inlines;
  101.  
  102. case Types.Threat:
  103. switch (t.Zone)
  104. {
  105. case Zone.Red:
  106. zoneColor = Color.FromRgb(255, 0, 0);
  107. zone = " Red";
  108. break;
  109.  
  110. case Zone.Blue:
  111. zoneColor = Color.FromRgb(0, 0, 255);
  112. zone = " Blue";
  113. break;
  114.  
  115. case Zone.White:
  116. zoneColor = Color.FromRgb(255, 255, 255);
  117. zone = " White";
  118. break;
  119.  
  120. case Zone.Internal:
  121. zoneColor = Color.FromRgb(20, 128, 20);
  122. textColor = Color.FromRgb(20, 128, 20);
  123. break;
  124.  
  125. default:
  126. throw new ArgumentOutOfRangeException();
  127. }
  128.  
  129. if (t.Unconfirmed == 1)
  130. {
  131. inlines.Add(new Run($"[{t.Time / 60}:{(t.Time % 60).ToString("D2")}] [ Unconfirmed: Time T+{t.T} ") { Foreground = new SolidColorBrush(textColor) });
  132. }
  133. else
  134. {
  135. inlines.Add(new Run($" {t.Time / 60}:{(t.Time % 60).ToString("D2")} Time T+{t.T} ") { Foreground = new SolidColorBrush(textColor) });
  136. }
  137. if (t.Severe == 1)
  138. inlines.Add(new Run("serious ") { Foreground = new SolidColorBrush(textColor), FontWeight = FontWeights.Bold });
  139. if (t.Zone == Zone.Internal)
  140. inlines.Add(new Run("internal ") { Foreground = new SolidColorBrush(textColor) });
  141.  
  142. inlines.Add(new Run("Threat ") { Foreground = new SolidColorBrush(textColor) });
  143. if (t.Zone != Zone.Internal)
  144. {
  145. inlines.Add(new Run("in zone ") { Foreground = new SolidColorBrush(textColor) });
  146. inlines.Add(new Run(zone) { Foreground = new SolidColorBrush(zoneColor), FontWeight = FontWeights.Bold });
  147. }
  148. if (t.Unconfirmed == 1)
  149. {
  150. inlines.Add(new Run("]") { Foreground = new SolidColorBrush(textColor) });
  151. }
  152. return inlines;
  153. }
  154. return inlines;
  155. }
  156. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  157. {
  158. throw new NotImplementedException();
  159. }
  160. }
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement