コード例 #1
0
        private Menu CreateMenu(string title, EventHandler setChoice, params string[] menuTexts)
        {
            Menu menu = new Menu(Canvas.Palette)
            {
                Title          = title,
                X              = 163,
                Y              = 39,
                Width          = 114,
                TitleColour    = 3,
                ActiveColour   = 11,
                TextColour     = 5,
                DisabledColour = 8,
                FontId         = 6,
                IndentTitle    = 2,
                RowHeight      = 8
            };

            Menu.Item menuItem;
            for (int i = 0; i < menuTexts.Length; i++)
            {
                menu.Items.Add(menuItem = new Menu.Item(menuTexts[i], i));
                menuItem.Selected      += setChoice;
            }
            return(menu);
        }
コード例 #2
0
ファイル: ChooseTech.cs プロジェクト: AlexFolland/CivOne
        public override bool HasUpdate(uint gameTick)
        {
            if (_update)
            {
                _update = false;

                Picture background = _menuGfx.GetPart(44, 35, 156, _menuHeight);
                Picture.ReplaceColours(background, new byte[] { 7, 22 }, new byte[] { 11, 3 });

                Menu menu = new Menu(Canvas.Palette, background)
                {
                    X            = 83,
                    Y            = 92,
                    Width        = 156,
                    ActiveColour = 11,
                    TextColour   = 5,
                    FontId       = 0
                };

                Menu.Item menuItem;
                for (int i = 0; i < _availableAdvances.Length; i++)
                {
                    menu.Items.Add(menuItem = new Menu.Item(_availableAdvances[i].Name, i));
                    menuItem.Selected      += AdvanceChoice;
                    menuItem.RightClick    += AdvanceContext;
                }
                AddMenu(menu);
                return(true);
            }
            return(true);
        }
コード例 #3
0
        private Menu CreateMenu(string title, EventHandler setChoice, params string[] menuTexts)
        {
            int  width  = GetMenuWidth(title, menuTexts);
            int  height = GetMenuHeight(title, menuTexts);
            Menu menu   = new Menu(Canvas.Palette)
            {
                Title          = title,
                X              = (320 - width) / 2,
                Y              = (200 - height) / 2,
                Width          = width,
                TitleColour    = 15,
                ActiveColour   = 11,
                TextColour     = 5,
                DisabledColour = 8,
                FontId         = MenuFont,
                IndentTitle    = 2
            };

            Menu.Item menuItem;
            for (int i = 0; i < menuTexts.Length; i++)
            {
                menu.Items.Add(menuItem = new Menu.Item(menuTexts[i], i));
                menuItem.Selected      += setChoice;
            }
            return(menu);
        }
コード例 #4
0
        private void CreateMenu()
        {
            if (HasMenu)
            {
                return;
            }
            Menu menu = new Menu(Canvas.Palette)
            {
                X              = 103,
                Y              = 144,
                Width          = 116,
                ActiveColour   = 11,
                TextColour     = 5,
                DisabledColour = 8,
                FontId         = 0
            };

            Menu.Item[] menuItems = new Menu.Item[5];
            menu.Items.Add(menuItems[0] = new Menu.Item("Start a New Game"));
            menu.Items.Add(menuItems[1] = new Menu.Item("Load a Saved Game"));
            menu.Items.Add(menuItems[2] = new Menu.Item("EARTH"));
            menu.Items.Add(menuItems[3] = new Menu.Item("Customize World"));
            menu.Items.Add(menuItems[4] = new Menu.Item("View Hall of Fame")
            {
                Enabled = false
            });

            menuItems[0].Selected += StartNewGame;
            menuItems[1].Selected += LoadSavedGame;
            menuItems[2].Selected += Earth;
            menuItems[3].Selected += CustomizeWorld;

            AddMenu(menu);
        }
コード例 #5
0
        private Menu CreateMenu(int y, string title, EventHandler setChoice, params string[] menuTexts)
        {
            Menu menu = new Menu(Canvas.Palette)
            {
                Title          = title,
                X              = 203,
                Y              = y,
                Width          = GetMenuWidth(title, menuTexts),
                TitleColour    = 15,
                ActiveColour   = 11,
                TextColour     = 79,
                DisabledColour = 8,
                FontId         = 0
            };

            Menu.Item menuItem;
            for (int i = 0; i < menuTexts.Length; i++)
            {
                menu.Items.Add(menuItem = new Menu.Item(menuTexts[i], i));
                menuItem.Selected      += setChoice;
            }
            menu.ActiveItem = 1;
            return(menu);
        }
コード例 #6
0
        public override bool KeyDown(KeyboardEventArgs args)
        {
            if (Cancel)
            {
                return(false);
            }

            char c = Char.ToUpper(args.KeyChar);

            if (args.Key == Key.Escape)
            {
                Console.WriteLine("Cancel");
                Cancel  = true;
                _update = true;
                return(true);
            }
            else if (_menu != null)
            {
                return(_menu.KeyDown(args));
            }
            else if (args.Key == Key.Enter)
            {
                _menu = new Menu(Canvas.Palette)
                {
                    Title        = "Select Load File...",
                    X            = 51,
                    Y            = 70,
                    Width        = 217,
                    TitleColour  = 12,
                    ActiveColour = 11,
                    TextColour   = 5,
                    FontId       = 0,
                    IndentTitle  = 2,
                    RowHeight    = 8
                };

                Menu.Item menuItem;

                int i = 0;
                foreach (SaveGameFile file in GetSaveGames())
                {
                    _menu.Items.Add(menuItem = new Menu.Item(file.Name, i++));
                    if (file.ValidFile)
                    {
                        menuItem.Selected += LoadSaveFile;
                    }
                    else
                    {
                        menuItem.Selected += LoadEmptyFile;
                    }
                }
                Cursor = MouseCursor.Pointer;
            }
            else if (c >= 'A' && c <= 'Z')
            {
                _driveLetter = c;
                _update      = true;
                return(true);
            }
            return(false);
        }
コード例 #7
0
        public override bool HasUpdate(uint gameTick)
        {
            if (_update)
            {
                _canvas.FillRectangle(0, 0, 0, 320, 200);

                List <string> menuItems      = new List <string>();
                string        menuHeaderText = $"What shall we build in {_city.Name}?";
                int           itemWidth      = Resources.Instance.GetTextSize(_fontId, menuHeaderText).Width;
                foreach (IProduction production in _pages[_page])
                {
                    string menuText = string.Empty;
                    if (production is IUnit)
                    {
                        IUnit unit  = (production as IUnit);
                        int   turns = ((int)unit.Price * 10) - _city.Shields;
                        if (_city.ShieldIncome > 1)
                        {
                            turns = (int)Math.Ceiling((double)turns / _city.ShieldIncome);
                        }
                        if (turns < 1)
                        {
                            turns = 1;
                        }
                        menuText = $"{unit.Name} ({turns} turns, ADM:{unit.Attack}/{unit.Defense}/{unit.Move})";
                        if (Resources.Instance.GetTextSize(_fontId, menuText).Width > itemWidth)
                        {
                            itemWidth = Resources.Instance.GetTextSize(_fontId, menuText).Width;
                        }
                    }
                    if (production is IBuilding)
                    {
                        IBuilding building = (production as IBuilding);
                        int       turns    = ((int)building.Price * 10) - _city.Shields;
                        if (_city.ShieldIncome > 1)
                        {
                            turns = (int)Math.Ceiling((double)turns / _city.ShieldIncome);
                        }
                        if (turns < 1)
                        {
                            turns = 1;
                        }
                        menuText = $"{building.Name} ({turns} turns)";
                        if (Resources.Instance.GetTextSize(_fontId, menuText).Width > itemWidth)
                        {
                            itemWidth = Resources.Instance.GetTextSize(_fontId, menuText).Width;
                        }
                    }
                    if (production is IWonder)
                    {
                        IWonder wonder = (production as IWonder);
                        int     turns  = ((int)wonder.Price * 10) - _city.Shields;
                        if (_city.ShieldIncome > 1)
                        {
                            turns = (int)Math.Ceiling((double)turns / _city.ShieldIncome);
                        }
                        if (turns < 1)
                        {
                            turns = 1;
                        }
                        menuText = $"{wonder.Name} ({turns} turns)";
                        if (Human.WonderObsolete(wonder))
                        {
                            menuText = $"*{menuText}";
                        }
                        if (Resources.Instance.GetTextSize(_fontId, menuText).Width > itemWidth)
                        {
                            itemWidth = Resources.Instance.GetTextSize(_fontId, menuText).Width;
                        }
                    }
                    menuItems.Add(menuText);
                }
                if (_pages.Count > 1)
                {
                    menuItems.Add("More...");
                }
                itemWidth += 10;

                int     width   = itemWidth + 14;
                int     height  = _menuHeight + 10 + Resources.Instance.GetFontHeight(_fontId);
                Picture menuGfx = new Picture(width, height);
                menuGfx.FillLayerTile(_background);
                menuGfx.AddBorder(15, 8, 0, 0, width, height);
                menuGfx.DrawText(menuHeaderText, _fontId, 15, 4, 4);
                menuGfx.DrawText($"(Help available)", 1, 10, width, height - Resources.Instance.GetFontHeight(1), TextAlign.Right);

                _canvas.FillRectangle(5, 80, 8, width + 2, height + 2);
                AddLayer(menuGfx, 81, 9);

                Picture background = menuGfx.GetPart(2, 3 + Resources.Instance.GetFontHeight(_fontId), itemWidth, Resources.Instance.GetFontHeight(_fontId) * menuItems.Count + 4);
                Picture.ReplaceColours(background, new byte[] { 7, 22 }, new byte[] { 11, 3 });

                Menu menu = new Menu(Canvas.Palette, background)
                {
                    X            = 83,
                    Y            = 12 + Resources.Instance.GetFontHeight(_fontId),
                    Width        = itemWidth,
                    ActiveColour = 11,
                    TextColour   = 5,
                    FontId       = _fontId
                };
                Menu.Item menuItem;
                int       i = 0;

                foreach (string item in menuItems)
                {
                    menu.Items.Add(menuItem = new Menu.Item(item, i++));
                    menuItem.Selected      += ProductionChoice;
                    menuItem.RightClick    += ProductionContext;
                }
                menu.Width     += 10;
                menu.MissClick += MenuCancel;
                menu.Cancel    += MenuCancel;

                AddMenu(menu);

                _update = false;
            }
            return(true);
        }
コード例 #8
0
        public override bool KeyDown(KeyboardEventArgs args)
        {
            if (_saving)
            {
                Destroy();
                return(true);
            }

            char c = Char.ToUpper(args.KeyChar);

            if (args.Key == Key.Escape)
            {
                Console.WriteLine("Cancel");
                Destroy();
                return(true);
            }
            else if (_menu != null)
            {
                return(_menu.KeyDown(args));
            }
            else if (args.Key == Key.Enter)
            {
                if (_gameId >= 0)
                {
                    SaveGameFile file = GetSaveGames().ToArray()[_gameId];
                    Game.Save(file.SveFile, file.MapFile);
                    _saving = true;
                    _update = true;
                    return(true);
                }

                _menu = new Menu(Canvas.Palette)
                {
                    Title        = "Select Save File...",
                    X            = 51,
                    Y            = 38,
                    Width        = 217,
                    TitleColour  = 12,
                    ActiveColour = 11,
                    TextColour   = 5,
                    FontId       = 0,
                    IndentTitle  = 2,
                    RowHeight    = 8
                };

                Menu.Item menuItem;

                int i = 0;
                foreach (SaveGameFile file in GetSaveGames().Take(4))
                {
                    _menu.Items.Add(menuItem = new Menu.Item(file.Name, i++));
                    menuItem.Selected       += SaveFile;
                }

                _menu.ActiveItem = SelectedGame;
                Cursor           = MouseCursor.Pointer;
            }
            else if (c >= 'A' && c <= 'Z')
            {
                _driveLetter = c;
                _update      = true;
                return(true);
            }
            return(false);
        }