Beispiel #1
0
 public EffectiveRatingsProfile(RatingsProfile original, RatingsProfile final, float[] multipliers, float[] metamultipliers)
 {
     this.original        = original;
     this.final           = final;
     this.multipliers     = multipliers;
     this.metamultipliers = metamultipliers;
 }
 public RatingsRadarChart(Context context, RatingsProfile profile, float[] multipliers = null, float[] metamultipliers = null)
 {
     this.context         = context;
     values               = profile.values;
     o_vals               = profile.o_vals;
     this.multipliers     = multipliers;
     this.metamultipliers = metamultipliers;
     SetSizeRequest(0, 0);
     SizeAllocated += DrawChart;
 }
Beispiel #3
0
		public RatingsMultiviewField (PropertyInfo property, object obj, Context context, DisplayableAttribute attribute) {

			this.context = context;
			BorderWidth = 5;

			// Nest containers
			VBox mainBox = new VBox();
			HBox navigation = new HBox();
			SquareContainer square = new SquareContainer();
			notebook = new Notebook { ShowTabs = false, ShowBorder = false };
			square.Add(notebook);
			mainBox.PackStart(navigation, false, false, 5);
			mainBox.PackStart(square, true, true, 0);
			Add(mainBox);

			// Navigation
			Label pageLabel = new Label("Table");
			ClickableEventBox leftArrow = new ClickableEventBox();
			leftArrow.Add(Graphics.GetIcon(IconTemplate.LeftArrow, new Gdk.Color(100, 100, 100), Graphics.textSize));
			leftArrow.Clicked += delegate {
				if (notebook.CurrentPage > 0) {
					notebook.CurrentPage--;
				} else {
					notebook.CurrentPage = notebook.NPages - 1;
				}
				pageLabel.Text = labels[notebook.CurrentPage];
			};
			ClickableEventBox rightArrow = new ClickableEventBox();
			rightArrow.Add(Graphics.GetIcon(IconTemplate.RightArrow, new Gdk.Color(100, 100, 100), Graphics.textSize));
			rightArrow.Clicked += delegate {
				if (notebook.CurrentPage < notebook.NPages - 1) {
					notebook.CurrentPage++;
				} else {
					notebook.CurrentPage = 0;
				}
				pageLabel.Text = labels[notebook.CurrentPage];
			};
			navigation.PackStart(leftArrow, false, false, 5);
			navigation.PackStart(pageLabel, true, true, 0);
			navigation.PackStart(rightArrow, false, false, 5);

			// Fill notebook
			RatingsProfile profile = ((Func<Context, RatingsProfile>)property.GetValue(obj))(context);
			RatingsRadarChart radar = new RatingsRadarChart(context.butCompact, profile, null, null);
			RatingsTable table = new RatingsTable(context.butCompact, profile);
			notebook.AppendPage(radar, null);
			notebook.AppendPage(UIFactory.Align(table, 0.5f, 0.5f, 0, 0), null);
		}
Beispiel #4
0
        public static bool TryParse(string text, out RatingsProfile?ratings)
        {
            ratings = null;
            int currentWrapper = 0;

            int[,] o_vals = new int[5, 9];
            string[] lines = text.Split('\n');
            if (!(lines.Length == 1 && lines[0] == ""))
            {
                foreach (string line in lines)
                {
                    if (!TryParseSingle(line.Trim(), out Tuple <int, float> rating))
                    {
                        return(false);
                    }
                    if (line[0] == '\t')
                    {
                        // An indented entry makes no sense if we aren't in a wrapper or it's trying to declare a wrapper
                        if (currentWrapper == 0 || rating.Item1 > 8)
                        {
                            return(false);
                        }
                        // Everything is fine? According to the currentWrapper, append the entry to the relevant ratings
                        o_vals[currentWrapper, rating.Item1] += Empower(rating.Item2);
                        o_vals[4, rating.Item1] += Empower(rating.Item2);
                    }
                    else
                    {
                        currentWrapper = 0;
                        if (rating.Item1 <= 8)                           //If it's a normal entry, append it to the base ratings.
                        {
                            o_vals[0, rating.Item1] += Empower(rating.Item2);
                            o_vals[4, rating.Item1] += Empower(rating.Item2);
                        }
                        else                             //Otherwise, it's a wrapper, so we "enter" it and log the wrapper metarating.
                        {
                            currentWrapper             = rating.Item1 - 8;
                            o_vals[currentWrapper, 0] += Empower(rating.Item2);
                        }
                    }
                }
            }
            ratings = new RatingsProfile(o_vals);
            return(true);
        }
Beispiel #5
0
 public static bool TryParseCompact(string text, out RatingsProfile?ratings)
 {
     ratings       = null;
     int[,] o_vals = new int[5, 9];
     string[] lines = text.Split('\n');
     if (!(lines.Length == 1 && lines[0] == ""))
     {
         foreach (string line in lines)
         {
             if (line.Contains("/"))
             {
                 string[] parts = line.Split('/');
                 if (!Enum.TryParse(parts[0], true, out ClassificationSymbols wrapper))
                 {
                     return(false);
                 }
                 if (!TryParseSingle(parts[1], out Tuple <int, float> content))
                 {
                     return(false);
                 }
                 o_vals[(int)wrapper - 8, content.Item1] += Empower(content.Item2);
                 o_vals[4, content.Item1] += Empower(content.Item2);
             }
             else
             {
                 if (!TryParseSingle(line.Trim(), out Tuple <int, float> rating))
                 {
                     return(false);
                 }
                 o_vals[0, rating.Item1] += Empower(rating.Item2);
                 o_vals[4, rating.Item1] += Empower(rating.Item2);
             }
         }
     }
     ratings = new RatingsProfile(o_vals);
     return(true);
 }
Beispiel #6
0
        public RatingsTable(Context context, RatingsProfile profile, float[] multipliers = null, float[] metamultipliers = null) : base(7, 10, false)
        {
            float[,] values = profile.values;
            int[,] o_vals   = profile.o_vals;

            ColumnSpacing = 5;
            RowSpacing    = 5;
            BorderWidth   = 10;

            Attach(new HSeparator(), 0, 7, 1, 2);
            Attach(new VSeparator(), 1, 2, 0, 10);

            //Row labels and multipliers
            for (uint i = 1; i <= 8; i++)
            {
                Label classLabel = new Label(" " + Ratings.symbols[i])
                {
                    HasTooltip  = true,
                    TooltipText = Enum.GetName(typeof(Classification), i)
                };
                Attach(classLabel, 0, 1, i + 1, i + 2);
            }
            //Fill in columns, including labels, numbers and multipliers
            for (uint i = 0; i < 5; i++)
            {
                //Row label
                Label rowLabel = new Label(deploymentRows[i]);
                rowLabel.SetAlignment(0.5f, 1f);
                Attach(rowLabel, i + 2, i + 3, 0, 1);
                //Numbers
                for (uint j = 1; j <= 8; j++)
                {
                    Label numberLabel = new Label();
                    if (o_vals[i, j] == Ratings.O_NULL)
                    {
                        numberLabel.Text = "-";
                    }
                    else
                    {
                        numberLabel.Text = values[i, j].ToString("0.0");
                    }
                    numberLabel.SetAlignment(1, 1);
                    Attach(numberLabel, i + 2, i + 3, j + 1, j + 2);
                }
            }

            if (multipliers != null && metamultipliers != null)
            {
                //Row multipliers
                for (uint i = 1; i <= 8; i++)
                {
                    Label multiplier = new Label {
                        UseMarkup   = true,
                        Markup      = "<small> ×" + multipliers[i].ToString("0.00") + "</small>",
                        HasTooltip  = true,
                        TooltipText = multiplierExplain[i]
                    };
                    multiplier.SetAlignment(1, 0);
                    Attach(multiplier, 7, 8, i + 1, i + 2);
                }

                //Column metamultipliers
                for (uint i = 0; i < 4; i++)
                {
                    Label multiplier = new Label {
                        UseMarkup   = true,
                        Markup      = "<small>  ×" + metamultipliers[i].ToString("0.00") + ((i == 3) ? ", fix" : "") + "</small>",
                        HasTooltip  = true,
                        TooltipText = metamultiplierExplain[i],
                        Angle       = -90
                    };
                    multiplier.SetAlignment(0, 0);
                    Attach(multiplier, i + 2, i + 3, 10, 11);
                }
            }
        }
        public RatingsListField(PropertyInfo property, object obj, Context context, DisplayableAttribute attribute) : base(0, 0, 1, 1)
        {
            RatingsProfile profile = ((Func <Context, RatingsProfile>)property.GetValue(obj))(context);

            float[,] values = profile.values;
            int[,] o_vals   = profile.o_vals;

            Gtk.Alignment alignment = new Gtk.Alignment(0, 0, 1, 0);

            if (context.vertical && !context.compact)
            {
                Frame frame = new Frame(UIFactory.ToReadable(property.Name));
                VBox  box   = new VBox(false, 4)
                {
                    BorderWidth = 5
                };
                frame.Add(box);
                alignment.Add(frame);

                for (int i = 1; i <= 8; i++)
                {
                    if (o_vals[0, i] != Ratings.O_NULL)
                    {
                        Label ratingLabel = new Label(Ratings.PrintSingle(i, values[0, i]));
                        ratingLabel.SetAlignment(0, 0);
                        box.PackStart(ratingLabel);
                    }
                }

                for (int k = 1; k <= 3; k++)
                {
                    if (o_vals[k, 0] != Ratings.O_NULL)
                    {
                        Label wrapperLabel = new Label(Ratings.PrintSingle(k + 8, values[k, 0]));
                        wrapperLabel.SetAlignment(0, 0);

                        VBox ratingBox = new VBox(false, 5)
                        {
                            BorderWidth = 5
                        };
                        Frame ratingFrame = new Frame {
                            LabelWidget = wrapperLabel, Child = ratingBox
                        };

                        for (int i = 1; i <= 8; i++)
                        {
                            if (o_vals[k, i] != Ratings.O_NULL)
                            {
                                Label ratingLabel = new Label(Ratings.PrintSingle(i, values[k, i]));
                                ratingLabel.SetAlignment(0, 0);
                                ratingBox.PackStart(ratingLabel, false, false, 0);
                            }
                        }

                        box.PackStart(ratingFrame);
                    }
                }
            }
            else
            {
                Box box;
                if (context.compact)
                {
                    box = new VBox(false, 0)
                    {
                        BorderWidth = 5
                    };
                }
                else
                {
                    box = new HBox(false, 0)
                    {
                        BorderWidth = 5
                    };
                }
                alignment.Add(box);
                for (int i = 1; i <= 8; i++)
                {
                    if (o_vals[0, i] != Ratings.O_NULL)
                    {
                        bool  comma       = !context.compact && box.Children.Length > 0;
                        Label ratingLabel = new Label((comma ? ", " : "")                         //Commas to delimit ratings
                                                      + Ratings.PrintSingle(i, values[0, i]));
                        ratingLabel.SetAlignment(0, 0);
                        box.PackStart(ratingLabel, false, false, 0);
                    }
                }
                for (int k = 1; k <= 3; k++)
                {
                    if (o_vals[k, 0] != Ratings.O_NULL)
                    {
                        bool  comma       = !context.compact && box.Children.Length > 0;
                        Label ratingLabel = new Label((comma ? ", " : "")                         //Commas to delimit ratings
                                                      + Ratings.PrintSingle(k + 8, values[k, 0], true));
                        ratingLabel.SetAlignment(0, 0);
                        List <String> subratings = new List <String>();
                        for (int i = 1; i <= 8; i++)
                        {
                            if (o_vals[k, i] != Ratings.O_NULL)
                            {
                                subratings.Add(Ratings.PrintSingle(i, values[k, i]));
                            }
                        }
                        ratingLabel.TooltipText = String.Join("\n", subratings);
                        box.PackStart(ratingLabel, false, false, 0);
                    }
                }
            }
            if (attribute.EditAuthorized(obj))
            {
                ClickableEventBox clickableEventBox = new ClickableEventBox {
                    Child = alignment
                };
                clickableEventBox.DoubleClicked += delegate {
                    // The property this is attached to gets the *current ratings*, not the *base ratings*, which are
                    // what we logically want to let the user manipulate. Hence, the optional arg supplied is the name
                    // of the base profile.
                    PropertyInfo      baseProfileProperty = obj.GetType().GetProperty((string)attribute.arg);
                    TextEditingDialog dialog = new TextEditingDialog(
                        "Edit ratings",
                        (Window)Toplevel,
                        delegate {
                        RatingsProfile baseProfile = (RatingsProfile)baseProfileProperty.GetValue(obj);
                        return(Ratings.Print(baseProfile.values, baseProfile.o_vals));
                    },
                        delegate(string input) {
                        if (Ratings.TryParse(input, out RatingsProfile? newRatings))
                        {
                            baseProfileProperty.SetValue(obj, (RatingsProfile)newRatings);
                            IDependable dependable = obj as IDependable;
                            if (dependable != null)
                            {
                                DependencyManager.Flag(dependable);
                                DependencyManager.TriggerAllFlags();
                            }
                            return(true);
                        }
                        return(false);
                    }
                        );
                };
                Add(clickableEventBox);
            }
            else
            {
                Add(alignment);
            }
        }