void CreateDrawingObjects(GameXmlDefinitionVariant game) { OptionDrawingObject option; double x = 0, y = 0, width = 0, height = 0; bool first = true; int randomized_options = 0; if (game.DrawingObjects == null) return; // Calculate the size of container from the options and count the number of random options foreach (DrawingObject draw_object in game.DrawingObjects) { option = draw_object as OptionDrawingObject; if (option == null) continue; if (option.RandomizedOrder) randomized_options++; if (first == true) { x = option.X; y = option.Y; width = option.Width; height = option.Height; first = false; continue; } if (option.X < x) x = option.X; if (option.Y < y) y = option.Y; if (option.X + option.Width > width) width = option.X + option.Width; if (option.Y + option.Height > height) height = option.Y + option.Height; } if (first == true) return; // Randomize the order of the options if (randomized_options > 0) { OptionDrawingObject [] originals; ArrayListIndicesRandom random_indices; int index = 0; random_indices = new ArrayListIndicesRandom (randomized_options); originals = new OptionDrawingObject [randomized_options]; random_indices.Initialize (); // Backup originals for (int i = 0; i < game.DrawingObjects.Length; i++) { option = game.DrawingObjects[i] as OptionDrawingObject; if (option == null) continue; originals[index] = option.Copy (); index++; } // Swap index = 0; for (int i = 0; i < game.DrawingObjects.Length; i++) { option = game.DrawingObjects[i] as OptionDrawingObject; if (option == null) continue; option.CopyRandomizedProperties (originals [random_indices [index]]); index++; } } Container container = new Container (x, y, width - x, height - y); AddWidget (container); if (options == null) options = new List <OptionDrawingObject> (); int idx = 0; // Create drawing widgets objects foreach (DrawingObject draw_object in game.DrawingObjects) { option = draw_object as OptionDrawingObject; if (option == null) continue; DrawableArea drawable_area = new DrawableArea (option.Width, option.Height); drawable_area.X = option.X; drawable_area.Y = option.Y; // + i * 0.15; container.AddChild (drawable_area); drawable_area.Data = idx; drawable_area.DataEx = Answer.GetMultiOption (idx); options.Add (option); idx++; drawable_area.DrawEventHandler += DrawOption; } }
void CreateDrawingObjects(GameXmlDefinitionVariant game) { OptionDrawingObject option; double x = 0, y = 0, width = 0, height = 0; bool first = true; int randomized_options = 0; if (game.DrawingObjects == null) { return; } // Calculate the size of container from the options and count the number of random options foreach (DrawingObject draw_object in game.DrawingObjects) { option = draw_object as OptionDrawingObject; if (option == null) { continue; } if (option.RandomizedOrder) { randomized_options++; } if (first == true) { x = option.X; y = option.Y; width = option.Width; height = option.Height; first = false; continue; } if (option.X < x) { x = option.X; } if (option.Y < y) { y = option.Y; } if (option.X + option.Width > width) { width = option.X + option.Width; } if (option.Y + option.Height > height) { height = option.Y + option.Height; } } if (first == true) { return; } // Randomize the order of the options if (randomized_options > 0) { OptionDrawingObject [] originals; ArrayListIndicesRandom random_indices; int index = 0; random_indices = new ArrayListIndicesRandom(randomized_options); originals = new OptionDrawingObject [randomized_options]; random_indices.Initialize(); // Backup originals for (int i = 0; i < game.DrawingObjects.Length; i++) { option = game.DrawingObjects[i] as OptionDrawingObject; if (option == null) { continue; } originals[index] = option.Copy(); index++; } // Swap index = 0; for (int i = 0; i < game.DrawingObjects.Length; i++) { option = game.DrawingObjects[i] as OptionDrawingObject; if (option == null) { continue; } option.CopyRandomizedProperties(originals [random_indices [index]]); index++; } } Container container = new Container(x, y, width - x, height - y); AddWidget(container); if (options == null) { options = new List <OptionDrawingObject> (); } int idx = 0; // Create drawing widgets objects foreach (DrawingObject draw_object in game.DrawingObjects) { option = draw_object as OptionDrawingObject; if (option == null) { continue; } DrawableArea drawable_area = new DrawableArea(option.Width, option.Height); drawable_area.X = option.X; drawable_area.Y = option.Y; // + i * 0.15; container.AddChild(drawable_area); drawable_area.Data = idx; drawable_area.DataEx = Answer.GetMultiOption(idx); options.Add(option); idx++; drawable_area.DrawEventHandler += DrawOption; } }