public PlayerHistoryDialog(ITranslations translations, PlayerHistory history) : base(translations, "PlayerHistoryDialog.ui", "playerhistory") { string intro, built; intro = Catalog.GetString("The graph below shows the player's game score evolution."); if (history.Games.Count < 2) { built = Catalog.GetString("You need more than one game session recorded to see the score evolution."); } else { built = String.Format(Catalog.GetPluralString("It is built using the results of {0} recorded game session.", "It is built using the results of the last {0} recorded game sessions.", history.Games.Count), history.Games.Count); } // Translators: "The graph below" + "It is built using" sentences label_playerhistory.Text = String.Format(Catalog.GetString("{0} {1}"), intro, built); drawing_area = new CairoPreview(translations, history); drawing_area.SetSizeRequest(history_preview.WidthRequest, history_preview.HeightRequest); history_preview.Add(drawing_area); drawing_area.Visible = true; checkbutton_total.Label = Catalog.GetString("Total"); checkbutton_logic.Label = GameTypesDescription.GetLocalized(translations, GameTypes.LogicPuzzle); checkbutton_calculation.Label = GameTypesDescription.GetLocalized(translations, GameTypes.Calculation); checkbutton_memory.Label = GameTypesDescription.GetLocalized(translations, GameTypes.Memory); checkbutton_verbal.Label = GameTypesDescription.GetLocalized(translations, GameTypes.VerbalAnalogy); checkbutton_total.Active = checkbutton_memory.Active = checkbutton_logic.Active = checkbutton_calculation.Active = checkbutton_verbal.Active = true; }
void LoadGames() { if (games_store != null) { return; } games_store = new ListStore(typeof(string), typeof(string), typeof(bool), typeof(Game), typeof(int)); games_store.SetSortFunc(0, new Gtk.TreeIterCompareFunc(GameSort)); games_store.SetSortColumnId(COL_TYPE, SortType.Ascending); // Data string type; Game game; for (int i = 0; i < games.Length; i++) { if (games [i].IsGame == false) { continue; } game = (Game)Activator.CreateInstance(games [i].TypeOf, true); game.Translations = Translations; game.Variant = games [i].Variant; type = GameTypesDescription.GetLocalized(Translations, game.Type); games_store.AppendValues(game.Name, type, true, game, i); } }
void DrawLegend(CairoContextEx cr, double x, double y) { const double line_size = 0.05, offset_x = 0.01, second_row = 0.05, space_hor = 0.35; double old_width; old_width = cr.LineWidth; cr.LineWidth = 0.01; cr.SetSourceColor(total_color); cr.MoveTo(x, y); cr.LineTo(x + line_size, y); cr.Stroke(); cr.SetSourceColor(text_color); cr.MoveTo(x + line_size + offset_x, y - 0.01); cr.ShowPangoText(Translations.GetString("Total")); cr.Stroke(); cr.SetSourceColor(logic_color); cr.MoveTo(x, y + second_row); cr.LineTo(x + line_size, y + second_row); cr.Stroke(); cr.SetSourceColor(text_color); cr.MoveTo(x + line_size + offset_x, y - 0.01 + second_row); cr.ShowPangoText(GameTypesDescription.GetLocalized(Translations, GameTypes.LogicPuzzle)); cr.Stroke(); x += space_hor; cr.SetSourceColor(memory_color); cr.MoveTo(x, y); cr.LineTo(x + line_size, y); cr.Stroke(); cr.SetSourceColor(text_color); cr.MoveTo(x + line_size + offset_x, y - 0.01); cr.ShowPangoText(GameTypesDescription.GetLocalized(Translations, GameTypes.Memory)); cr.Stroke(); cr.SetSourceColor(math_color); cr.MoveTo(x, y + second_row); cr.LineTo(x + line_size, y + second_row); cr.Stroke(); cr.SetSourceColor(text_color); cr.MoveTo(x + line_size + offset_x, y - 0.01 + second_row); cr.ShowPangoText(GameTypesDescription.GetLocalized(Translations, GameTypes.Calculation)); cr.Stroke(); x += space_hor; cr.SetSourceColor(verbal_color); cr.MoveTo(x, y); cr.LineTo(x + line_size, y); cr.Stroke(); cr.SetSourceColor(text_color); cr.MoveTo(x + line_size + offset_x, y - 0.01); cr.ShowPangoText(GameTypesDescription.GetLocalized(Translations, GameTypes.VerbalAnalogy)); cr.Stroke(); cr.LineWidth = old_width; }
public void Read(string file) { GameXmlDefinition game; string name, str, plural; bool processing_variant = false; int variant = 0; OptionDrawingObject option = null; DrawingObject last_drawing_object = null; string last_context = null; if (read == true) { return; } try { StreamReader stream = new StreamReader(file); XmlTextReaderLiteral reader = new XmlTextReaderLiteral(stream); game = null; while (reader.Read()) { // Strings are only used because msgctxt requirement if (reader.NodeType == XmlNodeType.Text) { const string CONTEXT_GLUE = "\u0004"; string text; text = reader.ReadString(); TextDrawingObject drawing_object = (TextDrawingObject)last_drawing_object; // GetText processes msgctxt as msgctxt + context_glue + text to retrieve them drawing_object.Text = last_context + CONTEXT_GLUE + text; // If the string does not exits, return regular English string without context if (GetText.StringExists(drawing_object.Text) == false) { drawing_object.Text = text; } continue; } name = reader.Name.ToLower(); switch (name) { case "games": break; case "type": if (reader.NodeType != XmlNodeType.Element) { break; } game.Type = GameTypesDescription.FromString(reader.ReadElementString()); break; case "game": if (reader.NodeType == XmlNodeType.Element) { game = new GameXmlDefinition(); } else if (reader.NodeType == XmlNodeType.EndElement) { games.Add(game); } break; case "_name": if (reader.NodeType != XmlNodeType.Element) { break; } game.Name = reader.ReadElementString(); break; case "difficulty": if (reader.NodeType != XmlNodeType.Element) { break; } str = reader.ReadElementString(); game.Difficulty = GameDifficultyDescription.FromString(str); break; case "svg": if (reader.NodeType != XmlNodeType.Element) { break; } ImageDrawingObject draw_image = new ImageDrawingObject(); if (processing_variant) { game.Variants[variant].AddDrawingObject(draw_image); } else { game.AddDrawingObject(draw_image); } draw_image.Filename = reader.GetAttribute("file"); str = reader.GetAttribute("x"); if (String.IsNullOrEmpty(str) == false) { draw_image.X = Double.Parse(str, CultureInfo.InvariantCulture); } else { draw_image.X = 0.1; } str = reader.GetAttribute("y"); if (String.IsNullOrEmpty(str) == false) { draw_image.Y = Double.Parse(str, CultureInfo.InvariantCulture); } else { draw_image.Y = 0.1; } str = reader.GetAttribute("width"); if (String.IsNullOrEmpty(str) == false) { draw_image.Width = Double.Parse(str, CultureInfo.InvariantCulture); } else { draw_image.Width = 0.8; } str = reader.GetAttribute("height"); if (String.IsNullOrEmpty(str) == false) { draw_image.Height = Double.Parse(str, CultureInfo.InvariantCulture); } else { draw_image.Height = 0.8; } break; case "string": case "_string": if (reader.NodeType != XmlNodeType.Element) { break; } TextDrawingObject draw_string = new TextDrawingObject(); last_drawing_object = draw_string; if (option != null) { option.AddDrawingObject(draw_string); } else { if (processing_variant) { game.Variants[variant].AddDrawingObject(draw_string); } else { game.AddDrawingObject(draw_string); } } last_context = reader.GetAttribute("msgctxt"); draw_string.Text = reader.GetAttribute("text"); if (String.IsNullOrEmpty(draw_string.Text)) { draw_string.Text = reader.GetAttribute("_text"); } str = reader.GetAttribute("x"); if (String.IsNullOrEmpty(str) == false) { draw_string.X = Double.Parse(str, CultureInfo.InvariantCulture); } else { draw_string.X = 0.1; } str = reader.GetAttribute("y"); if (String.IsNullOrEmpty(str) == false) { draw_string.Y = Double.Parse(str, CultureInfo.InvariantCulture); } else { draw_string.Y = 0.1; } str = reader.GetAttribute("centered"); if (String.Compare(str, "yes", true) == 0) { draw_string.Centered = true; } else { draw_string.Centered = false; } str = reader.GetAttribute("size"); if (String.IsNullOrEmpty(str) == false) { switch (str.ToLower()) { case "small": draw_string.Size = TextDrawingObject.Sizes.Small; break; case "medium": draw_string.Size = TextDrawingObject.Sizes.Medium; break; case "large": draw_string.Size = TextDrawingObject.Sizes.Large; break; case "x-large": draw_string.Size = TextDrawingObject.Sizes.XLarge; break; case "xx-large": draw_string.Size = TextDrawingObject.Sizes.XXLarge; break; default: Console.WriteLine("GameXmlFactory. Unsupported value for size attribute: {0}", str); break; } } break; case "_question": case "question": if (reader.NodeType != XmlNodeType.Element) { break; } // Create object if needed if (processing_variant) { if (game.Variants[variant].Question == null) { game.Variants[variant].Question = new LocalizableString(); } } else { if (game.Question == null) { game.Question = new LocalizableString(); } } plural = reader.GetAttribute("plural"); if (String.IsNullOrEmpty(plural) == false) // Plural { if (processing_variant) { game.Variants[variant].Question.PluralString = reader.ReadElementStringAsItIs(); game.Variants[variant].Question.Value = plural; } else { game.Question.PluralString = reader.ReadElementStringAsItIs(); game.Question.Value = plural; } } else { if (processing_variant) { game.Variants[variant].Question.String = reader.ReadElementStringAsItIs(); } else { game.Question.String = reader.ReadElementStringAsItIs(); } } break; case "rationale": case "_rationale": if (reader.NodeType != XmlNodeType.Element) { break; } // Create object if needed if (processing_variant) { if (game.Variants[variant].Rationale == null) { game.Variants[variant].Rationale = new LocalizableString(); } } else { if (game.Rationale == null) { game.Rationale = new LocalizableString(); } } plural = reader.GetAttribute("plural"); if (String.IsNullOrEmpty(plural) == false) // Plural { if (processing_variant) { game.Variants[variant].Rationale.PluralString = reader.ReadElementStringAsItIs(); game.Variants[variant].Rationale.Value = plural; } else { game.Rationale.PluralString = reader.ReadElementStringAsItIs(); game.Rationale.Value = plural; } } else { if (processing_variant) { game.Variants[variant].Rationale.String = reader.ReadElementStringAsItIs(); } else { game.Rationale.String = reader.ReadElementStringAsItIs(); } } break; case "answer": case "_answer": if (reader.NodeType != XmlNodeType.Element) { break; } if (processing_variant) { game.Variants[variant].AnswerText = reader.ReadElementString(); } else { game.AnswerText = reader.ReadElementString(); } break; case "_answer_show": case "answer_show": if (reader.NodeType != XmlNodeType.Element) { break; } if (processing_variant) { game.Variants[variant].AnswerShow = reader.ReadElementString(); } else { game.AnswerShow = reader.ReadElementString(); } break; case "answer_expression": if (reader.NodeType != XmlNodeType.Element) { break; } if (processing_variant) { game.Variants[variant].AnswerCheckExpression = reader.ReadElementString(); } else { game.AnswerCheckExpression = reader.ReadElementString(); } break; case "answer_checkattributes": if (reader.NodeType != XmlNodeType.Element) { break; } if (processing_variant) { game.Variants[variant].CheckAttributes = GameAnswerCheckAttributesDescription.FromString(reader.ReadElementString()); } else { game.CheckAttributes = GameAnswerCheckAttributesDescription.FromString(reader.ReadElementString()); } break; case "_tip": if (reader.NodeType != XmlNodeType.Element) { break; } if (processing_variant) { game.Variants[variant].Tip = reader.ReadElementStringAsItIs(); } else { game.Tip = reader.ReadElementStringAsItIs(); } break; case "variant": if (reader.NodeType == XmlNodeType.Element) { game.NewVariant(); variant = game.Variants.Count - 1; processing_variant = true; } else if (reader.NodeType == XmlNodeType.EndElement) { processing_variant = false; } break; case "variables": if (processing_variant) { game.Variants[variant].Variables = reader.ReadElementString(); } else { game.Variables = reader.ReadElementString(); } break; case "option": switch (reader.NodeType) { case XmlNodeType.Element: option = new OptionDrawingObject(); break; case XmlNodeType.EndElement: if (String.IsNullOrEmpty(option.AnswerText) && option.RandomizedOrder == false) { throw new InvalidOperationException("If the option is not randomized, you need to define an answer"); } option = null; break; default: // Do any processing break; } if (option == null) { break; } if (processing_variant) { game.Variants[variant].AddDrawingObject(option); } else { game.AddDrawingObject(option); } option.AnswerText = reader.GetAttribute("answer"); if (String.IsNullOrEmpty(option.AnswerText)) { option.AnswerText = reader.GetAttribute("_answer"); } str = reader.GetAttribute("x"); if (String.IsNullOrEmpty(str) == false) { option.X = Double.Parse(str, CultureInfo.InvariantCulture); } else { option.X = 0.1; } str = reader.GetAttribute("y"); if (String.IsNullOrEmpty(str) == false) { option.Y = Double.Parse(str, CultureInfo.InvariantCulture); } else { option.Y = 0.1; } str = reader.GetAttribute("width"); if (String.IsNullOrEmpty(str) == false) { option.Width = Double.Parse(str, CultureInfo.InvariantCulture); } else { option.Width = 0.1; } str = reader.GetAttribute("height"); if (String.IsNullOrEmpty(str) == false) { option.Height = Double.Parse(str, CultureInfo.InvariantCulture); } else { option.Height = 0.1; } str = reader.GetAttribute("order"); if (String.IsNullOrEmpty(str) == false) { option.RandomizedOrder = true; } str = reader.GetAttribute("correct"); if (String.Compare(str, "yes", true) == 0) { option.Correct = true; } if (option.X + option.Width > 1 || option.Y + option.Height > 1) { Console.WriteLine("GameXmlFactory. Wrong option size. x+width and y+height cannot be larger than 1"); } break; default: if (String.IsNullOrEmpty(name) == false) { Console.WriteLine("GameXmlFactory. Unsupported tag: {0}", name); } break; } } reader.Close(); stream.Dispose(); read = true; GameXml.Definitions = games; } catch (Exception e) { read = true; Console.WriteLine("GameXmlFactory. Error loading: {0}", e.Message); } }
public CustomGameDialog(GameManager manager) : base("CustomGameDialog.ui", "customgame") { Game game; selection_done = false; this.manager = manager; games = manager.AvailableGames; drawing_area = new GameDrawingArea(); drawing_area.UseSolutionArea = false; preview_vbox.Add(drawing_area); drawing_area.Visible = true; treeview.HeadersClickable = true; // Column: Game Name TreeViewColumn name_column = new TreeViewColumn(Catalog.GetString("Game Name"), new CellRendererText(), "text", 0); name_column.Expand = true; name_column.Clickable = true; name_column.Clicked += delegate(object sender, EventArgs args) { Gtk.SortType order; Gtk.TreeViewColumn column = (Gtk.TreeViewColumn)sender; if (column.SortOrder == Gtk.SortType.Ascending) { order = Gtk.SortType.Descending; } else { order = Gtk.SortType.Ascending; } column.SortOrder = order; games_store.SetSortColumnId(COL_NAME, order); }; treeview.AppendColumn(name_column); // Column: Type TreeViewColumn type_column = new TreeViewColumn(Catalog.GetString("Type"), new CellRendererText(), "text", 1); type_column.Expand = true; treeview.AppendColumn(type_column); type_column.Clickable = true; type_column.Clicked += delegate(object sender, EventArgs args) { Gtk.SortType order; Gtk.TreeViewColumn column = (Gtk.TreeViewColumn)sender; if (column.SortOrder == Gtk.SortType.Ascending) { order = Gtk.SortType.Descending; } else { order = Gtk.SortType.Ascending; } column.SortOrder = order; games_store.SetSortColumnId(COL_TYPE, order); }; // Column: Selected CellRendererToggle toggle_cell = new CellRendererToggle(); TreeViewColumn toggle_column = new TreeViewColumn(Catalog.GetString("Selected"), toggle_cell, "active", COL_ENABLED); toggle_cell.Activatable = true; toggle_cell.Toggled += OnActiveToggled; toggle_column.Expand = false; treeview.CursorChanged += OnCursorChanged; treeview.AppendColumn(toggle_column); if (games_store == null) { games_store = new ListStore(typeof(string), typeof(string), typeof(bool), typeof(Game), typeof(int)); games_store.SetSortFunc(0, new Gtk.TreeIterCompareFunc(GameSort)); games_store.SetSortColumnId(COL_TYPE, SortType.Ascending); // Data string type; for (int i = 0; i < games.Length; i++) { if (games [i].IsGame == false) { continue; } game = (Game)Activator.CreateInstance(games [i].TypeOf, true); game.Variant = games [i].Variant; type = GameTypesDescription.GetLocalized(game.Type); games_store.AppendValues(game.Name, type, true, game, i); } } treeview.Model = games_store; game = (Game)Activator.CreateInstance(games [0].TypeOf, true); game.Variant = 0; game.Begin(); drawing_area.Drawable = game; drawing_area.Question = game.Question; treeview.ColumnsAutosize(); }