Example #1
0
        private void AddNavigationItems()
        {
            foreach (NavigationInfo navigation in _context.Navigation)
            {
                if (navigation.GroupName == null)
                {
                    MenuDropDownItem menuItem = CollectionUtils.Find(
                        _context.Portal.MenuItems,
                        delegate(MenuDropDownItem item)
                            {
                                return StringUtils.CaseInsensitiveEquals(item.ItemId, navigation.GroupId);
                            });

                    if (menuItem == null)
                    {
                        menuItem = new MenuDropDownItem();
                        _context.Portal.MenuItems.Add(menuItem);
                    }

                    menuItem.ItemId = navigation.Id;
                    menuItem.NavUrl = navigation.NavUrl;
                    menuItem.Title = navigation.Caption ?? string.Empty;

                    if (navigation.Glyph != null)
                    {
                        string extension;

                        if (navigation.Glyph is Metafile) //vector
                        {
                            extension = "emf";
                        }
                        else if (navigation.Glyph.GetFrameCount(FrameDimension.Time) > 1 || //animated
                                 (navigation.Glyph.PixelFormat & PixelFormat.Indexed) == PixelFormat.Indexed) //indexed
                        {
                            extension = "gif";
                        }
                        else if ((navigation.Glyph.PixelFormat & PixelFormat.Alpha) == PixelFormat.Alpha) //transparency
                        {
                            extension = "png";
                        }
                        else
                        {
                            extension = "jpg";
                        }

                        string name = string.Format("{0}_{1}x{2}.{3}", navigation.SafeCaption, navigation.Glyph.Width, navigation.Glyph.Height, extension);
                        _context.GlobalImageResourceManager.AddUpdateResource(name, navigation.Glyph);
                        menuItem.SmallImageUrl = string.Format("[Localization.Global_Images:{0}]", name);
                    }

                    menuItem.Validate();
                    menuItem.Save();

                    navigation.Item = menuItem;
                }
                else
                {
                    NavigationGroup navGroup = CollectionUtils.Find(
                        _context.Portal.NavigationGroups,
                        delegate(NavigationGroup item)
                            {
                                return StringUtils.CaseInsensitiveEquals(item.ItemId, navigation.GroupId);
                            });

                    if (navGroup == null)
                    {
                        navGroup = new NavigationGroup();
                        _context.Portal.NavigationGroups.Add(navGroup);
                    }

                    navGroup.ItemId = navigation.GroupId;
                    navGroup.Title = navigation.GroupName;
                    navGroup.Description = navigation.GroupName;

                    NavigationItem navItem = CollectionUtils.Find(
                        navGroup.NavItems,
                        delegate(NavigationItem item)
                            {
                                return StringUtils.CaseInsensitiveEquals(item.ItemId, navigation.Id);
                            });

                    if (navItem == null)
                    {
                        navItem = new NavigationItem();
                        navGroup.NavItems.Add(navItem);
                    }

                    navItem.ItemId = navigation.Id;
                    navItem.NavUrl = navigation.NavUrl;
                    navItem.Title = navigation.Caption ?? string.Empty;
                    navItem.Description = navigation.Caption ?? string.Empty;

                    if (navigation.Glyph != null)
                    {
                        string extension;

                        if (navigation.Glyph is Metafile) //vector
                        {
                            extension = "emf";
                        }
                        else if (navigation.Glyph.GetFrameCount(FrameDimension.Time) > 1 || //animated
                                 (navigation.Glyph.PixelFormat & PixelFormat.Indexed) == PixelFormat.Indexed) //indexed
                        {
                            extension = "gif";
                        }
                        else if ((navigation.Glyph.PixelFormat & PixelFormat.Alpha) == PixelFormat.Alpha) //transparency
                        {
                            extension = "png";
                        }
                        else
                        {
                            extension = "jpg";
                        }

                        string name = string.Format("{0}_{1}x{2}.{3}", navigation.SafeCaption, navigation.Glyph.Width, navigation.Glyph.Height, extension);
                        _context.GlobalImageResourceManager.AddUpdateResource(name, navigation.Glyph);
                        navItem.LargeImageUrl = string.Format("[Localization.Global_Images:{0}]", name);
                    }

                    navItem.Validate();
                    navItem.Save();

                    navGroup.Validate();
                    navGroup.Save();

                    navigation.Item = navItem;
                }
            }

            _context.GlobalImageResourceManager.SaveAll();
        }
Example #2
0
        public static void LoadSidebar(Control contentPanel, int positionX, int width, int height)
        {
            #region Sidebar
            Sidebar.SidebarContainer = new ShadowedPanel
            {
                Location  = new Point(positionX, 0),
                Width     = width + 2 * Constants.BorderThickness,
                Height    = height + 2 * Constants.BorderThickness,
                BackColor = Color.Black,
            };
            Sidebar.SidebarContainer.DropShadow();
            contentPanel.Controls.Add(Sidebar.SidebarContainer);

            Sidebar.SidebarPanel = new Panel
            {
                Location  = new Point(Constants.BorderThickness, Constants.BorderThickness),
                Width     = width,
                Height    = height,
                BackColor = Constants.Colors.SidebarColor,
            };
            Sidebar.SidebarContainer.Controls.Add(Sidebar.SidebarPanel);
            #endregion

            int sidebarContentWidth       = width - Constants.Padding.Horizontal;
            int sidebarTotalContentHeight = Sidebar.SidebarPanel.Height - (int)(Constants.SidebarSeparatorHeight * 6.0) - Constants.Padding.Vertical;

            int currentStartingY = Constants.Padding.Top;

            #region Menu bar
            #region Container
            Sidebar.MenuContainer = new ShadowedPanel
            {
                Location  = new Point(Constants.Padding.Left, currentStartingY),
                Width     = sidebarContentWidth,
                Height    = (int)(sidebarTotalContentHeight * 0.05),
                BackColor = Color.Black,
            };
            Sidebar.MenuContainer.DropShadow();
            Sidebar.SidebarPanel.Controls.Add(Sidebar.MenuContainer);
            Sidebar.MenuPanel = new Panel
            {
                Location = new Point(Constants.BorderThickness, Constants.BorderThickness),
                Width    = Sidebar.MenuContainer.Width - 2 * Constants.BorderThickness,
                Height   = Sidebar.MenuContainer.Height - 2 * Constants.BorderThickness,
            };
            Sidebar.MenuContainer.Controls.Add(Sidebar.MenuPanel);
            Sidebar.Menu = new Menu
            {
                Padding   = new Padding(0),
                Dock      = DockStyle.Fill,
                BackColor = Constants.Colors.MenuBackColor
            };
            Sidebar.MenuPanel.Controls.Add(Sidebar.Menu);
            #endregion
            #region Items
            #region File
            var fileButton = new MenuItem("Файл", ImageController.LetterImagesActive['~'])
            {
                Width  = Sidebar.Menu.Width / 3,
                Height = Sidebar.Menu.Height
            };
            #region File dropdown items
            fileButton.DropDown = new MenuDropDown();
            var loadSubButton = new MenuDropDownItem("Отвори...", enabled: true);
            loadSubButton.Click += LoadSubButton_Click;
            fileButton.DropDownItems.Add(loadSubButton);

            var saveSubButton = new MenuDropDownItem("Запиши", enabled: true);
            saveSubButton.Click += SaveSubButton_Click;
            fileButton.DropDownItems.Add(saveSubButton);

            //TODO: fileButton.DropDownItems.Add(new MenuDropDownItem("Запиши като...", withSeparator: true, enabled: false));

            //TODO: fileButton.DropDownItems.Add(new MenuDropDownItem("Печат...", enabled: false));
            //TODO: fileButton.DropDownItems.Add(new MenuDropDownItem("Печат Инициализация...", withSeparator: true, enabled: false));

            //TODO: fileButton.DropDownItems.Add(new MenuDropDownItem("Последни Игри", withSeparator: true, enabled: false));

            var exitSubButton = new MenuDropDownItem("Изход", enabled: true);
            exitSubButton.Click += ExitSubButton_Click;
            //TODO: fileButton.DropDownItems.Add(exitSubButton);
            #endregion
            Sidebar.Menu.Items.Add(fileButton);
            #endregion
            #region Game
            var gameButton = new MenuItem("Игра", ImageController.LetterImagesActive['~'])
            {
                Width  = Sidebar.Menu.Width / 3,
                Height = Sidebar.Menu.Height
            };
            #region Game dropdown items
            gameButton.DropDown = new MenuDropDown();
            var newGameSubButton = new MenuDropDownItem("Нова Игра", enabled: true);
            newGameSubButton.Click += NewGameSubButton_Click;
            gameButton.DropDownItems.Add(newGameSubButton);
            //TODO: gameButton.DropDownItems.Add(new MenuDropDownItem("Нова Мрежова Игра...", withSeparator: true, enabled: false));
            //TODO: gameButton.DropDownItems.Add(new MenuDropDownItem("Играчи...", enabled: false));
            //TODO: gameButton.DropDownItems.Add(new MenuDropDownItem("Постижения", withSeparator: true, enabled: false));

            /*var dictionarySubButton = new MenuDropDownItem("Речник", enabled: true);
             * dictionarySubButton.Click += DictionarySubButton_Click;
             * gameButton.DropDownItems.Add(dictionarySubButton);*/
            /*var processWordsSubButton = new MenuDropDownItem("Валидация на думи", enabled: true);
             * processWordsSubButton.Click += (sender, args) => { WordController.ProcessPendingWords(); };
             * gameButton.DropDownItems.Add(processWordsSubButton);*/

            //TODO: gameButton.DropDownItems.Add(new MenuDropDownItem("Трудност", withSeparator: true, enabled: false));
            //TODO: gameButton.DropDownItems.Add(new MenuDropDownItem("Изглед", enabled: false));
            var soundsSubButton = new MenuDropDownItem("Звуци", isToggled: UserSettings.SoundsOn, enabled: true);
            soundsSubButton.Click += SoundsSubButton_Click;
            gameButton.DropDownItems.Add(soundsSubButton);
            #endregion
            Sidebar.Menu.Items.Add(gameButton);
            #endregion
            #region Help
            var helpButton = new MenuItem("Помощ", ImageController.LetterImagesActive['~'])
            {
                Width  = Sidebar.Menu.Width / 3,
                Height = Sidebar.Menu.Height
            };
            #region Help dropdown items
            helpButton.DropDown = new MenuDropDown();
            helpButton.DropDownItems.Add(new MenuDropDownItem("Индекс...", enabled: false));
            helpButton.DropDownItems.Add(new MenuDropDownItem("Правила...", withSeparator: true, enabled: false));
            helpButton.DropDownItems.Add(new MenuDropDownItem("Относно КръстоСловник...", enabled: false));
            #endregion
            //TODO: Sidebar.Menu.Items.Add(helpButton);
            #endregion
            #region Dictionary
            var dictionaryButton = new MenuItem("Речник", ImageController.LetterImagesActive['~'])
            {
                Width  = Sidebar.Menu.Width / 3,
                Height = Sidebar.Menu.Height
            };
            #region Dictionary dropdown items
            dictionaryButton.DropDown = new MenuDropDown();
            var addWordSubButton = new MenuDropDownItem("Добави дума", withSeparator: true, enabled: true);
            addWordSubButton.Click += AddWordSubButton_Click;
            dictionaryButton.DropDownItems.Add(addWordSubButton);

            var dictionarySubButton = new MenuDropDownItem("Отвори речник", enabled: true);
            dictionarySubButton.Click += DictionarySubButton_Click;
            dictionaryButton.DropDownItems.Add(dictionarySubButton);

            var processWordsSubButton = new MenuDropDownItem("Презареждане на думи", enabled: true);
            processWordsSubButton.Click += ProcessWordsButton_Click;
            dictionaryButton.DropDownItems.Add(processWordsSubButton);
            #endregion
            Sidebar.Menu.Items.Add(dictionaryButton);
            #endregion
            #endregion
            #endregion

            currentStartingY += Sidebar.MenuContainer.Height + (int)(1.5 * Constants.SidebarSeparatorHeight);

            #region Scoreboard
            Sidebar.ScoreboardContainer = new ShadowedPanel
            {
                Location  = new Point(Constants.Padding.Left, currentStartingY),
                Width     = sidebarContentWidth,
                Height    = (int)(sidebarTotalContentHeight * 0.25),
                BackColor = Constants.Colors.HandInnerColor,
            };
            Sidebar.ScoreboardContainer.DropShadow();
            Sidebar.SidebarPanel.Controls.Add(Sidebar.ScoreboardContainer);
            Sidebar.ScoreboardGrid = new Grid <Player.Player>(Constants.Fonts.ScoreboardGrid)
            {
                Location  = new Point(0, 0),
                Width     = sidebarContentWidth,
                Height    = Sidebar.ScoreboardContainer.Height,
                BackColor = Constants.Colors.GridBackColor
            };
            Sidebar.ScoreboardGrid.StylesApplied += new Grid <Player.Player> .ExtraStyleFilter((Grid <Player.Player> .Row row, Player.Player player) =>
            {
                if (player != null && player.IsInTurn)
                {
                    row.Font      = new Font(row.Font, FontStyle.Bold);
                    row.ForeColor = Constants.Colors.FontBlue;
                }
                else
                {
                    row.Font      = new Font(row.Font, FontStyle.Regular);
                    row.ForeColor = Color.Black;
                }
            });

            Sidebar.ScoreboardGrid.Columns.Add(new Grid <Player.Player> .Column(nameof(Player.Player.Avatar), null, 8, ContentAlignment.MiddleCenter, new Func <Player.Player, object, bool>((player, data) => player != null ? player.IsInTurn : false)));
            Sidebar.ScoreboardGrid.Columns.Add(new Grid <Player.Player> .Column(nameof(Player.Player.Name), "Играчи", 42, ContentAlignment.MiddleLeft));
            Sidebar.ScoreboardGrid.Columns.Add(new Grid <Player.Player> .Column(nameof(Player.Player.TurnsPlayed), "Ходове", 20, ContentAlignment.MiddleRight));
            Sidebar.ScoreboardGrid.Columns.Add(new Grid <Player.Player> .Column(nameof(Player.Player.Score), "Точки", 20, ContentAlignment.MiddleRight));
            Sidebar.ScoreboardGrid.Columns.Add(new Grid <Player.Player> .Column(null, null, 10, ContentAlignment.MiddleRight));
            Sidebar.ScoreboardGrid.Init(5, stretchRows: true);
            Sidebar.ScoreboardContainer.Controls.Add(Sidebar.ScoreboardGrid);
            #endregion

            currentStartingY += Sidebar.ScoreboardContainer.Height + (Constants.SidebarSeparatorHeight / 2);

            #region Turn player label
            // Center vertically while taking lack of shadow in consideration
            currentStartingY       += Constants.Shadows.DropShadowHeight / 2;
            Sidebar.TurnPlayerLabel = new Label
            {
                Location  = new Point(Constants.Padding.Left, currentStartingY),
                Width     = sidebarContentWidth + Constants.Shadows.DropShadowWidth,
                BackColor = Color.Transparent,
                ForeColor = Constants.Colors.FontBlack,
                Font      = new Font(Constants.Fonts.Default, FontStyle.Bold),
                TextAlign = ContentAlignment.TopLeft,
                Text      = Constants.Texts.TurnPlayer
            };
            Sidebar.TurnPlayerLabel.Height = Sidebar.TurnPlayerLabel.Font.Height;
            Sidebar.SidebarPanel.Controls.Add(Sidebar.TurnPlayerLabel);
            #endregion

            currentStartingY += Sidebar.TurnPlayerLabel.Height + (Constants.SidebarSeparatorHeight * 2);

            #region Hand
            Sidebar.HandPanelContainer = new Panel
            {
                Location  = new Point(Constants.Padding.Left - Constants.Shadows.DropShadowWidth, currentStartingY),
                Width     = sidebarContentWidth + 3 * Constants.Shadows.DropShadowWidth,
                Height    = (int)(Board.Board.SlotSize * 1.1) + Constants.Shadows.DropShadowWidth,
                BackColor = Color.Transparent
            };
            Sidebar.SidebarPanel.Controls.Add(Sidebar.HandPanelContainer);
            Sidebar.HandPanelOuter = new ShadowedPanel
            {
                Location  = new Point(0, (int)(Sidebar.HandPanelContainer.Height * 0.35) - Constants.Shadows.DropShadowWidth),
                Width     = Sidebar.HandPanelContainer.Width - Constants.Shadows.DropShadowWidth,
                Height    = Sidebar.HandPanelContainer.Height - (int)(Sidebar.HandPanelContainer.Height * 0.35),
                BackColor = Constants.Colors.HandOuterColor,
            };
            Sidebar.HandPanelOuter.DropShadow();
            Sidebar.HandPanelContainer.Controls.Add(Sidebar.HandPanelOuter);
            Sidebar.HandPanelInner = new Panel
            {
                Location  = new Point(4, 0),
                Width     = Sidebar.HandPanelOuter.Width - 8,
                Height    = (int)(Sidebar.HandPanelOuter.Height * 0.9),
                BackColor = Constants.Colors.HandInnerColor,
            };
            Sidebar.HandPanelOuter.Controls.Add(Sidebar.HandPanelInner);
            Sidebar.HandLocation = Sidebar.HandPanelContainer.GetLocationOnForm().PlusX(Sidebar.HandPanelInner.Location.X);
            #endregion

            currentStartingY += Sidebar.HandPanelContainer.Height;

            #region Pieces in deck label
            Sidebar.PiecesInDeckLabel = new Label
            {
                Location  = new Point(Constants.Padding.Left, currentStartingY),
                Width     = sidebarContentWidth + Constants.Shadows.DropShadowWidth,
                BackColor = Color.Transparent,
                ForeColor = Constants.Colors.FontBlack,
                Font      = Constants.Fonts.Default,
                TextAlign = ContentAlignment.TopLeft,
                Text      = Constants.Texts.PiecesInDeck
            };
            Sidebar.PiecesInDeckLabel.Height = Sidebar.PiecesInDeckLabel.Font.Height;
            Sidebar.SidebarPanel.Controls.Add(Sidebar.PiecesInDeckLabel);
            #endregion

            currentStartingY += Sidebar.PiecesInDeckLabel.Height + (Constants.SidebarSeparatorHeight * 2);

            #region Buttons
            Sidebar.ButtonsContainer = new Panel
            {
                Location = new Point(Constants.Padding.Left, currentStartingY),
                Width    = sidebarContentWidth + Constants.Shadows.DropShadowWidth,
                Height   = (int)(sidebarTotalContentHeight * 0.06),
            };
            Sidebar.SidebarPanel.Controls.Add(Sidebar.ButtonsContainer);
            Sidebar.ButtonConfirm = new ShadowedButton
            {
                Location  = new Point(0, 0),
                Width     = (int)(Sidebar.ButtonsContainer.Width * 0.35),
                Height    = Sidebar.ButtonsContainer.Height - Constants.Shadows.DropShadowWidth,
                BackColor = Constants.Colors.ButtonColorBackActive,
                ForeColor = Constants.Colors.ButtonColorForeActive,
                FlatStyle = FlatStyle.Flat,
                Text      = "Играй"
            };
            Sidebar.ButtonConfirm.DropShadow();
            Sidebar.ButtonConfirm.Click += ButtonConfirmClick;
            Sidebar.ButtonsContainer.Controls.Add(Sidebar.ButtonConfirm);
            Sidebar.ButtonReset = new ShadowedButton
            {
                Location  = new Point((int)(Sidebar.ButtonsContainer.Width * 0.45) - Constants.Shadows.DropShadowWidth, 0),
                Width     = (int)(Sidebar.ButtonsContainer.Width * 0.55),
                Height    = Sidebar.ButtonsContainer.Height - Constants.Shadows.DropShadowWidth,
                BackColor = Constants.Colors.ButtonColorBackActive,
                ForeColor = Constants.Colors.ButtonColorForeActive,
                FlatStyle = FlatStyle.Flat,
                Text      = "Прибери пуловете"
            };
            Sidebar.ButtonReset.DropShadow();
            Sidebar.ButtonReset.Click += ButtonResetClick;
            Sidebar.ButtonsContainer.Controls.Add(Sidebar.ButtonReset);
            #endregion

            currentStartingY += Sidebar.ButtonsContainer.Height + Constants.SidebarSeparatorHeight;

            #region Turn points label
            // Center vertically while taking lack of shadow in consideration
            currentStartingY += Constants.Shadows.DropShadowHeight / 2;

            Sidebar.TurnPointsLabel = new Label
            {
                Location  = new Point(Constants.Padding.Left, currentStartingY),
                Width     = sidebarContentWidth + Constants.Shadows.DropShadowWidth,
                BackColor = Color.Transparent,
                ForeColor = Constants.Colors.FontBlue,
                Font      = Constants.Fonts.TurnPointsLabel,
                TextAlign = ContentAlignment.BottomLeft,
                Text      = Constants.Texts.TurnPoints
            };
            Sidebar.TurnPointsLabel.Height = Sidebar.TurnPointsLabel.Font.Height;
            Sidebar.SidebarPanel.Controls.Add(Sidebar.TurnPointsLabel);
            Sidebar.ToolTip = new ToolTip();
            Sidebar.ToolTip.SetToolTip(Sidebar.TurnPointsLabel, Sidebar.TurnPointsLabel.Text);
            #endregion

            currentStartingY += Sidebar.TurnPointsLabel.Height + Constants.SidebarSeparatorHeight / 2;

            #region Current words/Highscores
            Sidebar.WordsContainer = new ShadowedPanel
            {
                Location  = new Point(Constants.Padding.Left, currentStartingY),
                Width     = sidebarContentWidth,
                Height    = Sidebar.SidebarPanel.Height - currentStartingY - Constants.Padding.Bottom, // Fill up remainder of the sidebar
                BackColor = Color.Transparent,
            };
            Sidebar.WordsContainer.DropShadow();
            Sidebar.SidebarPanel.Controls.Add(Sidebar.WordsContainer);

            #region Current words
            Sidebar.WordsGrid = new Grid <Word>(Constants.Fonts.WordsGrid)
            {
                Location  = new Point(0, 0),
                Width     = sidebarContentWidth,
                Height    = Sidebar.WordsContainer.Height,
                BackColor = Constants.Colors.GridBackColor,
                Visible   = true
            };
            Sidebar.WordsGrid.StylesApplied += new Grid <Word> .ExtraStyleFilter((Grid <Word> .Row row, Word word) =>
            {
                row.Font = new Font(row.Font, FontStyle.Bold);
                if (word != null)
                {
                    row.ForeColor = word.IsValid ? Constants.Colors.FontBlue : Constants.Colors.FontRed;
                }
            });

            Sidebar.WordsGrid.Columns.Add(new Grid <Word> .Column(nameof(Word.IsValid), null, 10, ContentAlignment.MiddleCenter, (word, data) => word != null ? word.IsValid : false));
            Sidebar.WordsGrid.Columns.Add(new Grid <Word> .Column(nameof(Word.Text), "Думи", 55, ContentAlignment.MiddleLeft));
            Sidebar.WordsGrid.Columns.Add(new Grid <Word> .Column(nameof(Word.Points), "Точки", 25, ContentAlignment.MiddleRight));
            Sidebar.WordsGrid.Columns.Add(new Grid <Word> .Column(null, null, 10, ContentAlignment.MiddleRight));
            Sidebar.WordsGrid.Init(12, stretchRows: true);
            Sidebar.WordsContainer.Controls.Add(Sidebar.WordsGrid);
            #endregion

            #region Highscores
            Sidebar.HighscoresGrid = new Grid <Score>(Constants.Fonts.WordsGrid)
            {
                Location  = new Point(0, 0),
                Width     = sidebarContentWidth,
                Height    = Sidebar.WordsContainer.Height,
                BackColor = Constants.Colors.GridBackColor,
                Visible   = false
            };
            Sidebar.HighscoresGrid.Columns.Add(new Grid <Score> .Column(null, null, 5, ContentAlignment.MiddleCenter));
            Sidebar.HighscoresGrid.Columns.Add(new Grid <Score> .Column(nameof(Score.Player), "Играч", 35, ContentAlignment.MiddleLeft));
            Sidebar.HighscoresGrid.Columns.Add(new Grid <Score> .Column(nameof(Score.Points), "Точки", 30, ContentAlignment.MiddleCenter));
            Sidebar.HighscoresGrid.Columns.Add(new Grid <Score> .Column(nameof(Score.Timestamp), "Дата", 25, ContentAlignment.MiddleRight, (score, data) => true, (score) => score?.Timestamp.ToString("dd.MM.yyyy")));
            Sidebar.HighscoresGrid.Columns.Add(new Grid <Score> .Column(null, null, 5, ContentAlignment.MiddleCenter));
            Sidebar.HighscoresGrid.Init(12, stretchRows: true);
            Sidebar.WordsContainer.Controls.Add(Sidebar.HighscoresGrid);
            #endregion
            #endregion
        }