Пример #1
0
 public SelectButton(string id, ICommand command, Rectangle bounds, Color hover,
                     Color fill, Color border, Color font, string text, SelectionGroup parent, SelectionType selectionType
                     ) : base(id, command, bounds, hover, fill, border, font, text)
 {
     groupType   = selectionType;
     this.parent = parent;
 }
Пример #2
0
 public SelectionMenu(string id, string title, List <MenuElement> elements,
                      SelectionGroup ships, SelectionGroup diff, SelectionGroup levels
                      ) : base(id, title, elements)
 {
     selectShipButtons       = ships;
     selectDifficultyButtons = diff;
     selectLevelButtons      = levels;
 }
Пример #3
0
        public Menu CreateSelectMenu(string fileName, Dictionary <string, Shape> shipList, Dictionary <string, Level> levelList)
        {
            JObject            menuObj      = Util.Deserialize(dirPath + fileName);
            string             id           = menuObj.Value <string>("id").ToLower();
            string             title        = menuObj.Value <string>("title");
            JArray             textBoxesObj = menuObj.Value <JArray>("textBoxes");
            JArray             buttonsObj   = menuObj.Value <JArray>("buttons");
            JArray             colorsObj    = menuObj.Value <JArray>("elementColors");
            List <MenuElement> elements     = menuElementFac.Create(textBoxesObj, buttonsObj, colorsObj, menuModule, id);

            int sw = SwinGame.ScreenHeight();
            int sh = SwinGame.ScreenWidth();

            List <Rectangle> shipSelectionBounds       = CreateSelectionBounds(0.1f * sw, 0.2f * sh, 0.05f * sw, 0.01f * sh, 0.2f * sw, 0.04f * sh);
            List <Rectangle> difficultySelectionBounds = CreateSelectionBounds(0.1f * sw, 0.32f * sh, 0.05f * sw, 0.01f * sh, 0.2f * sw, 0.04f * sh);
            List <Rectangle> levelSelectionBounds      = CreateSelectionBounds(0.1f * sw, 0.44f * sh, 0.05f * sw, 0.01f * sh, 0.2f * sw, 0.04f * sh);

            SelectionGroup shipSelection       = new SelectionGroup(SelectionType.Ship);
            SelectionGroup difficultySelection = new SelectionGroup(SelectionType.Difficulty);
            SelectionGroup levelSelection      = new SelectionGroup(SelectionType.Level);

            //create ship selection buttons
            int n = shipList.Count > shipSelectionBounds.Count ? shipSelectionBounds.Count : shipList.Count;

            for (int i = 0; i < n; ++i)
            {
                string shipId = shipList.ElementAt(i).Key;
                shipSelection.Add(menuElementFac.CreateSelectButton(id, shipId, shipSelectionBounds[i], SelectionType.Ship, shipId, shipSelection, menuModule));
            }

            //create level selection buttons
            n = levelList.Count > levelSelectionBounds.Count ? levelSelectionBounds.Count : levelList.Count;
            int count = 0;

            for (int i = 0; i < n; ++i)
            {
                string levelId = levelList.ElementAt(i).Key;

                //only allow level to be selected if it has been set to playable
                if (levelList.ElementAt(i).Value.Playable)
                {
                    levelSelection.Add(menuElementFac.CreateSelectButton(id, levelId, levelSelectionBounds[count], SelectionType.Level, levelId, levelSelection, menuModule));
                    count++;
                }
            }

            //difficulty buttons
            difficultySelection.Add(menuElementFac.CreateSelectButton("easy", "Easy", difficultySelectionBounds[0], SelectionType.Difficulty, "easy", difficultySelection, menuModule));
            difficultySelection.Add(menuElementFac.CreateSelectButton("medium", "Medium", difficultySelectionBounds[1], SelectionType.Difficulty, "medium", difficultySelection, menuModule));
            difficultySelection.Add(menuElementFac.CreateSelectButton("hard", "Hard", difficultySelectionBounds[2], SelectionType.Difficulty, "hard", difficultySelection, menuModule));

            MenuCommandFactory menuCommandFac = new MenuCommandFactory(menuModule);

            return(new SelectionMenu(id, title, elements, shipSelection, difficultySelection, levelSelection));
        }
Пример #4
0
        /// <summary>
        /// built on runtime to allow the plaeyr to choose different data selections
        /// </summary>
        /// <returns></returns>
        public SelectButton CreateSelectButton(string id, string label, Rectangle bounds, SelectionType type, string payload, SelectionGroup parent, IMenuModule menuModule)
        {
            MenuCommandFactory menuCommandFac = new MenuCommandFactory(menuModule);
            ICommand           command;

            switch (type)
            {
            case SelectionType.Difficulty:
                command = new SelectDifficultyCommand(menuModule, payload);
                break;

            case SelectionType.Level:
                command = new SelectLevelCommand(menuModule, payload);
                break;

            case SelectionType.Ship:
                command = new SelectShipCommand(menuModule, payload);
                break;

            default:
                command = null;
                break;
            }
            Color hover  = Color.Orange;
            Color fill   = Color.Grey;
            Color border = Color.White;
            Color font   = Color.White;

            return(new SelectButton(id, command, bounds, hover, fill, border, font, payload, parent, type));
        }