Beispiel #1
0
 protected override IEnumerable <GameObject> CreateObjs()
 {
     yield return(OptionPicker.Create("Pick Map",
                                      new Transform2
     {
         Size = new Size2(120, 40),
         Center = new Vector2(800, 30)
     },
                                      new MapOptions(map => Navigate.To(new MapEditor(map, new MapEvents(GetProjContentPath(map), new TeleportEvent())))).Get().ToArray()));
 }
Beispiel #2
0
 private void InitEditPanel()
 {
     _editPanel = Entity.Create("Edit Panel",
                                new Transform2
     {
         Size     = new Size2(200, 900),
         ZIndex   = ZIndex.Max - 13,
         Location = new Vector2(1400, 0)
     })
                  .Add((o, r) => new Texture(r.CreateRectangle(Color.FromNonPremultiplied(70, 70, 70, 255), o)))
                  .AttachTo(CurrentViewport.Position)
                  .Add(OptionPicker.Create("Add Teleport", new Transform2
     {
         Size     = new Size2(180, 60),
         Location = new Vector2(1410, 10),
         ZIndex   = ZIndex.Max - 12
     },
                                           new MapOptions(map => Navigate.To(new MapTeleportSelector(map, new TilePosition(_selectedTile.World), _events, _path))).Get().ToArray()));
 }
        /// <summary>
        /// Builds the control(s) to select product options.
        /// </summary>
        /// <param name="product">The product to build the controls for</param>
        /// <param name="phOptions">The place holder control where the controls will be added.</param>
        /// <param name="showAllOptions">If true, all options are made available even if they are out of stock or otherwise unavailable.</param>
        /// <returns>The controls are added to phOptions, and the return value is a dictionary of currently selected options.  The key is the option ID, the value is the choice ID selected.</returns>
        public static Dictionary <int, int> BuildProductOptions(Product product, PlaceHolder phOptions, bool showAllOptions)
        {
            Dictionary <int, int> selectedChoices = new Dictionary <int, int>();

            if ((product.ProductOptions.Count > 0))
            {
                Page                  page           = phOptions.Page;
                HttpRequest           request        = HttpContext.Current.Request;
                IList <ProductOption> productOptions = product.ProductOptions;
                int optionCount = productOptions.Count;

                // DETERMINE THE SELECTED CHOICES
                string baseId = phOptions.UniqueID.Substring(0, phOptions.UniqueID.Length - phOptions.ID.Length);
                for (int i = 0; i < optionCount; i++)
                {
                    Option option         = productOptions[i].Option;
                    string selectedChoice = request.Form[baseId + "option" + i];
                    if (!string.IsNullOrEmpty(selectedChoice))
                    {
                        int choiceId = AlwaysConvert.ToInt(selectedChoice);
                        if (choiceId != 0)
                        {
                            selectedChoices.Add(option.Id, choiceId);
                        }
                    }
                }

                for (int i = 0; i < optionCount; i++)
                {
                    Option option = productOptions[i].Option;
                    // CREATE A LABEL FOR THE ATTRIBUTE
                    phOptions.Controls.Add(new LiteralControl("<tr><th class=\"rowHeader\"" + (option.ShowThumbnails ? " valign=\"top\"" : string.Empty) + ">" + option.Name + ":</th>"));
                    phOptions.Controls.Add(new LiteralControl("<td align=\"left\">"));
                    if (option.ShowThumbnails)
                    {
                        // CREATE THE OPTION PICKER CONTROL TO THE PLACEHOLDER
                        OptionPicker picker = new OptionPicker();
                        picker.ID       = "option" + i;
                        picker.CssClass = "optionPicker";
                        // WE ALWAYS HAVE TO POSTBACK FOR THUMBNAIL PICKER
                        picker.AutoPostBack          = true;
                        picker.OptionId              = option.Id;
                        picker.SelectedChoices       = new Dictionary <int, int>(selectedChoices);
                        picker.ForceToLoadAllChoices = showAllOptions;
                        // ADD THE CONTROL TO THE PLACEHOLDER
                        phOptions.Controls.Add(picker);
                        if (selectedChoices.ContainsKey(option.Id))
                        {
                            picker.SelectedChoiceId = selectedChoices[option.Id];
                        }
                        // ADD VALIDATOR
                        OptionPickerValidator aspOptionsValidator = new OptionPickerValidator();
                        aspOptionsValidator.ID = "optionValidator" + i;
                        aspOptionsValidator.ControlToValidate = picker.ID;
                        aspOptionsValidator.ValidationGroup   = "AddToBasket";
                        aspOptionsValidator.Text         = "*";
                        aspOptionsValidator.ErrorMessage = string.Format("Please make your selection for {0}.", option.Name);
                        phOptions.Controls.Add(new LiteralControl("&nbsp;"));
                        phOptions.Controls.Add(aspOptionsValidator);
                    }
                    else
                    {
                        // CREATE A DROPDOWN FOR THE OPTIONS
                        DropDownList           aspOptions          = new DropDownList();
                        RequiredFieldValidator aspOptionsValidator = new RequiredFieldValidator();
                        aspOptions.ID           = "option" + i;
                        aspOptions.AutoPostBack = true;
                        aspOptionsValidator.ID  = "optionValidator" + i;
                        aspOptionsValidator.ControlToValidate = aspOptions.ID;
                        aspOptionsValidator.ValidationGroup   = "AddToBasket";
                        aspOptionsValidator.Text         = "*";
                        aspOptionsValidator.ErrorMessage = string.Format("Please make your selection for {0}.", option.Name);
                        aspOptions.Items.Add(option.HeaderText);
                        // GET THE COLLECTION OF CHOICES THAT ARE AVAILABLE FOR THE CURRENT SELECTIONS
                        IList <OptionChoice> availableOptions;
                        if (!showAllOptions && i < ProductVariant.MAXIMUM_ATTRIBUTES)
                        {
                            availableOptions = OptionChoiceDataSource.GetAvailableChoices(product.Id, option.Id, selectedChoices);
                        }
                        else
                        {
                            availableOptions = option.Choices;
                        }
                        // ADD AVAILABLE CHOICES TO THE LIST
                        foreach (OptionChoice choice in availableOptions)
                        {
                            aspOptions.Items.Add(new ListItem(choice.Name, choice.Id.ToString()));
                        }
                        // ADD THE CONTROL TO THE PLACEHOLDER
                        phOptions.Controls.Add(aspOptions);
                        phOptions.Controls.Add(new LiteralControl("&nbsp;"));
                        phOptions.Controls.Add(aspOptionsValidator);
                        // SEE WHETHER A VALID VALUE FOR THIS FIELD IS PRESENT IN FORM POST
                        if (selectedChoices.ContainsKey(option.Id))
                        {
                            ListItem selectedItem = aspOptions.Items.FindByValue(selectedChoices[option.Id].ToString());
                            if (selectedItem != null)
                            {
                                selectedItem.Selected = true;
                            }
                        }
                    }
                    phOptions.Controls.Add(new LiteralControl("</td></tr>"));
                    // KEEP LOOPING UNTIL WE REACH THE END OR WE COME TO AN OPTION THAT IS NOT SELECTED
                }
            }
            //RETURN SELECTED OPTIONS
            return(selectedChoices);
        }