Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Windows;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Media;
- namespace WpfApp1.Logic
- {
- public class ThreatToInlinesConverter : IValueConverter
- {
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- Event t = (Event)value;
- List<Run> inlines = new List<Run>();
- Color zoneColor = Color.FromRgb(0, 0, 0);
- Color textColor = Color.FromRgb(200, 0, 160);
- string zone = "";
- string phase = "";
- if (t.Time / 60 > 10)
- {
- inlines.Add(new Run(" "));
- }
- switch (t.Types)
- {
- case Types.LineBreak:
- inlines.Add(new Run($""));
- return inlines;
- case Types.Start:
- inlines.Add(new Run($" 0:00 Enemy activity detected. Please begin 1st phase."));
- return inlines;
- case Types.PhaseEnd:
- switch (t.Phase)
- {
- case Phase.first:
- phase = "1st";
- break;
- case Phase.second:
- phase = "2nd";
- break;
- case Phase.third:
- phase = "3rd";
- break;
- default:
- throw new ArgumentOutOfRangeException();
- }
- switch (t.PhaseStep)
- {
- case PhaseStep.one:
- inlines.Add(new Run($" {t.Time / 60}:{(t.Time % 60).ToString("D2")} {phase} phase ends in one minute."));
- break;
- case PhaseStep.two:
- inlines.Add(new Run($" {t.Time / 60}:{(t.Time % 60).ToString("D2")} {phase} phase ends in twenty seconds."));
- break;
- case PhaseStep.three:
- switch (t.Phase)
- {
- case Phase.first:
- inlines.Add(new Run($" {t.Time / 60}:{(t.Time % 60).ToString("D2")} {phase} ends in 5, 4, 3, 2, 1 ... 2nd phase."));
- break;
- case Phase.second:
- inlines.Add(new Run($" {t.Time / 60}:{(t.Time % 60).ToString("D2")} {phase} ends in 5, 4, 3, 2, 1 ... 3rd phase."));
- break;
- case Phase.third:
- inlines.Add(new Run($" {t.Time / 60}:{(t.Time % 60).ToString("D2")} {phase} ends in 5, 4, 3, 2, 1. Mission Complete."));
- break;
- }
- break;
- default:
- throw new ArgumentOutOfRangeException();
- }
- return inlines;
- case Types.DataTransfer:
- 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) });
- return inlines;
- case Types.IncomingData:
- inlines.Add(new Run($" {t.Time / 60}:{(t.Time % 60).ToString("D2")} Incoming data.") { Foreground = new SolidColorBrush(textColor) });
- return inlines;
- case Types.CommunicationOutage:
- inlines.Add(new Run($" {t.Time / 60}:{(t.Time % 60).ToString("D2")} Communication system down ...") { Foreground = new SolidColorBrush(textColor) });
- return inlines;
- case Types.CommunicationRestored:
- inlines.Add(new Run($" {t.Time / 60}:{(t.Time % 60).ToString("D2")} ... communications restored.") { Foreground = new SolidColorBrush(textColor) });
- return inlines;
- case Types.Threat:
- switch (t.Zone)
- {
- case Zone.Red:
- zoneColor = Color.FromRgb(255, 0, 0);
- zone = " Red";
- break;
- case Zone.Blue:
- zoneColor = Color.FromRgb(0, 0, 255);
- zone = " Blue";
- break;
- case Zone.White:
- zoneColor = Color.FromRgb(255, 255, 255);
- zone = " White";
- break;
- case Zone.Internal:
- zoneColor = Color.FromRgb(20, 128, 20);
- textColor = Color.FromRgb(20, 128, 20);
- break;
- default:
- throw new ArgumentOutOfRangeException();
- }
- if (t.Unconfirmed == 1)
- {
- inlines.Add(new Run($"[{t.Time / 60}:{(t.Time % 60).ToString("D2")}] [ Unconfirmed: Time T+{t.T} ") { Foreground = new SolidColorBrush(textColor) });
- }
- else
- {
- inlines.Add(new Run($" {t.Time / 60}:{(t.Time % 60).ToString("D2")} Time T+{t.T} ") { Foreground = new SolidColorBrush(textColor) });
- }
- if (t.Severe == 1)
- inlines.Add(new Run("serious ") { Foreground = new SolidColorBrush(textColor), FontWeight = FontWeights.Bold });
- if (t.Zone == Zone.Internal)
- inlines.Add(new Run("internal ") { Foreground = new SolidColorBrush(textColor) });
- inlines.Add(new Run("Threat ") { Foreground = new SolidColorBrush(textColor) });
- if (t.Zone != Zone.Internal)
- {
- inlines.Add(new Run("in zone ") { Foreground = new SolidColorBrush(textColor) });
- inlines.Add(new Run(zone) { Foreground = new SolidColorBrush(zoneColor), FontWeight = FontWeights.Bold });
- }
- if (t.Unconfirmed == 1)
- {
- inlines.Add(new Run("]") { Foreground = new SolidColorBrush(textColor) });
- }
- return inlines;
- }
- return inlines;
- }
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement