示例#1
0
        private bool UpdateMenu(bool menuChanged)
        {
            var selectionMade = false;

            Clear();

            var windowLayout = new CLayout(0, 0, Orientation.Vertical, true)
            {
                Padding = screenResX / 128
            };
            var infoLayout = new CLayout(0, 0, Orientation.Horizontal, true)
            {
                PaddingLeft   = screenResX / 25,
                PaddingRight  = screenResX / 25,
                PaddingTop    = screenResY / 48,
                PaddingBottom = screenResY / 48
            };
            var mainLayout = new CLayout(0, 0, Orientation.Horizontal, true);
            var menuLayout = new CLayout(0, 0, Orientation.Vertical, true)
            {
                FillParent = true
            };

            _menuSidebarLayout = new CLayout(0, 0, Orientation.Vertical, true)
            {
                Padding      = screenResX / 64,
                PaddingRight = screenResX / 128 * 3
            };

            // titlebar
            if (_titlebar != null)
            {
                AddItem(_titlebar);
            }

            // menu scrolling
            if (menuColumnCount == 1)
            {
                menu_max_item_count = (screenResY / menu_item_height) - (_currentMenu == "show_game_info" ? 10 : 3) + (_statusbar == null ? 1 : 0);
            }
            else if (menuColumnCount > 0)
            {
                menu_max_item_count = menuColumnCount * _menuItems.Count;
            }
            else
            {
                menu_max_item_count = 0;
            }
            if (_currentMenuItem < menu_first_item_shown)
            {
                menu_first_item_shown = _currentMenuItem;
            }
            if (_currentMenuItem > menu_first_item_shown + menu_max_item_count - 1)
            {
                menu_first_item_shown = _currentMenuItem - menu_max_item_count + 1;
            }
            var menu_last_item_shown = Math.Min(menu_first_item_shown + menu_max_item_count, menu_first_item_shown + menuRowsCount);

            // menu items display
            for (var yCounter = menu_first_item_shown; yCounter < menu_last_item_shown; yCounter++)
            {
                var rowLayout = new CLayout(0, 0, Orientation.Horizontal, true);
                for (var xCounter = 0; xCounter < _menuStrings.Count; xCounter++)
                {
                    var pointer = yCounter + xCounter * _menuStrings[0].Count;
                    if (pointer == _currentMenuItem && _menuItems[pointer].IsFocusable)
                    {
                        selectionMade = true;
                        if (!_isMenuTextReader)
                        {
                            _menuItems[pointer].ForeColor   = menu_selected_font_color;
                            _menuItems[pointer].BackColor   = menu_selected_backcolor;
                            _menuItems[pointer].BorderColor = menu_font_color;
                            _menuItems[pointer].SetFocus();
                        }
                        else
                        {
                            _menuItems[pointer].ForeColor = _menuItems[pointer].IsFocusable ? menu_font_color : menu_selected_font_color;
                            _menuItems[pointer].BackColor = _menuItems[pointer].BorderColor = Color.TransparentWhite;
                        }
                    }
                    else
                    {
                        _menuItems[pointer].ForeColor = _menuItems[pointer].IsFocusable ? menu_font_color : menu_selected_font_color;
                        _menuItems[pointer].BackColor = _menuItems[pointer].BorderColor = Color.TransparentWhite;
                    }
                    rowLayout.AddItem(_menuItems[pointer]);
                }
                menuLayout.AddItem(rowLayout);
            }

            //if (_currentMenu == "show_game_info")
            if (_additionalInfo != string.Empty)
            {
                // game info (snapshot)
                if (_additionalData != string.Empty)
                {
                    var currentSnapshotPath = _snapshotPath + _additionalData + ".png";
                    if (_previousSnapshotPath != currentSnapshotPath)
                    {
                        _previousSnapshotPath = currentSnapshotPath;
                        _snapshotImage.LoadImage(_previousSnapshotPath);
                    }
                    infoLayout.AddItem(_snapshotImage);
                }
                infoLayout.AddItem(_additionalInfoLayout);
                windowLayout.AddItem(infoLayout);
            }
            else
            {
                if (_showSideBar)
                {
                    // sidebar
                    var currentIconPath = _iconPath + _menuItems[_currentMenuItem].KeyName + ".png";
                    if (_previousIconPath != currentIconPath)
                    {
                        _previousIconPath = currentIconPath;
                        if (File.Exists(_previousIconPath))
                        {
                            _iconImage.LoadImage(_previousIconPath);
                        }
                        else
                        {
                            _iconImage.LoadImage("*feel");
                        }
                    }
                    _menuSidebarLayout.AddItem(_iconImage);
                    mainLayout.AddItem(_menuSidebarLayout);
                }
            }
            BorderColor = menu_font_color;

            mainLayout.AddItem(menuLayout);
            windowLayout.AddItem(mainLayout);
            AddItem(windowLayout);

            // statusbar
            if (_statusbar != null)
            {
                AddItem(_statusbar);
            }

            if (menuChanged)
            {
                StartTransition(CDrawable.Transition.FadeIn);
            }
            else
            {
                ResetPendingTransitions();
            }

            // define max layout sizes
            Update();

            // center menu + rearrange
            X = (screenResX - Width) / 2;
            Y = ((screenResY - Height) / 2);
            Update();

            return(selectionMade);
        }
示例#2
0
        public CLayout BuildTable(string message, TextAlign textAlign, int tableWidth)
        {
            var tableLayout = new CLayout(0, 0, CLayout.Orientation.Vertical, false);

            // split lines
            var lines     = message.Split('\n');
            var lineCount = lines.Length;

            // get column count
            var columnCount = 0;

            for (var lineNo = 0; lineNo < lineCount; lineNo++)
            {
                columnCount = Math.Max(columnCount, lines[lineNo].Split('§').Length);
            }

            // define column widths
            var columnWidth = new int[columnCount];
            var totalWidth  = 0;

            for (var lineNo = 0; lineNo < lineCount; lineNo++)
            {
                var curLine = lines[lineNo];
                if (curLine.Contains("|"))
                {
                    curLine = curLine.Split('|')[1];
                }
                // skip empty lines
                if (string.IsNullOrEmpty(curLine))
                {
                    continue;
                }

                // split row in columns
                var line = curLine.Split('§');
                totalWidth = 0;
                for (var colNo = 0; colNo < line.Length; colNo++)
                {
                    // track column width if current row has no "colspan"
                    if (line.Length == columnCount)
                    {
                        columnWidth[colNo] = Math.Max(columnWidth[colNo],
                                                      (int)(menu_sprite_font.MeasureString(Utils.StringCleanup(line[colNo])).X + 8));
                        totalWidth += columnWidth[colNo];
                    }
                }
            }
            // if table width supplied, resize all columns
            if (tableWidth > 0 && totalWidth != tableWidth)
            {
                for (var colNo = 0; colNo < columnWidth.Length; colNo++)
                {
                    columnWidth[colNo] = (int)((float)columnWidth[colNo] / (float)totalWidth * (float)tableWidth);
                }
            }

            // find message width
            var messageWidth = 0;

            for (var i = 0; i < columnCount; i++)
            {
                messageWidth += columnWidth[i];
            }

            var messageHeight = lineCount * menu_item_height;

            for (var lineNo = 0; lineNo < lineCount; lineNo++)
            {
                var row     = new CLayout(0, 0, CLayout.Orientation.Horizontal, true);
                var curLine = lines[lineNo];
                if (curLine.Contains("|"))
                {
                    row.KeyName     = curLine.Split('|')[0];
                    row.IsFocusable = curLine.Split('|').Length < 3;
                    curLine         = curLine.Split('|')[1];
                }
                var line = curLine.Split('§');
                row.Width   = messageWidth;
                row.Gravity = LayoutGravity.Left;
                for (var colNo = 0; colNo < line.Length; colNo++)
                {
                    CLabel lbl;
                    lbl = new CLabel(0, 0,
                                     columnWidth[colNo], menu_item_height, line[colNo], menu_font_name,
                                     menu_font_size, menu_font_style, menu_font_color, Color.TransparentWhite, textAlign, false)
                    {
                        Scrolling = false
                    };
                    // first row is table header
                    //if (lineNo == 0)
                    //{
                    //    lbl = new CLabel(0, 0,
                    //                        columnWidth[colNo], (int)(menu_item_height * 1), line[colNo], menu_font_name,
                    //                        menu_font_size + 1, menu_font_style, menu_selected_font_color, menu_selected_backcolor, textAlign, false);
                    //    lbl.BackColor = menu_selected_backcolor;
                    //    lbl.BorderColor = menu_font_color;
                    //}
                    //else
                    //    lbl = new CLabel(0, 0,
                    //                        columnWidth[colNo], menu_item_height, line[colNo], menu_font_name,
                    //                        menu_font_size, menu_font_style, menu_font_color, Color.TransparentWhite, textAlign, false);
                    row.AddItem(lbl);
                }
                tableLayout.AddItem(row);
            }
            tableLayout.Update();
            return(tableLayout);
        }
示例#3
0
        public int ShowMessage(string message, TextAlign textAlign, int previousMessageHeight, int maxRows)
        {
            // split lines
            var lines     = message.Split('\n');
            var lineCount = Math.Min(lines.Length, maxRows);

            // get column count
            var columnCount = 0;

            for (var lineNo = 0; lineNo < lineCount; lineNo++)
            {
                columnCount = Math.Max(columnCount, lines[lineNo].Split('§').Length);
            }

            // define column widths
            var columnWidth = new int[columnCount];

            for (var lineNo = 0; lineNo < lineCount; lineNo++)
            {
                // skip empty lines
                if (string.IsNullOrEmpty(lines[lineNo]))
                {
                    continue;
                }

                // split row in columns
                var line = lines[lineNo].Split('§');
                for (var colNo = 0; colNo < line.Length; colNo++)
                {
                    // track column width if current row has no "colspan"
                    if (line.Length == columnCount)
                    {
                        columnWidth[colNo] = Math.Max(columnWidth[colNo],
                                                      (int)(menu_sprite_font.MeasureString(Utils.StringCleanup(line[colNo])).X *(lineNo == 0 ? 1.2 : 1) + 8));
                    }
                }
            }

            // find message width
            var messageWidth = 0;

            for (var i = 0; i < columnCount; i++)
            {
                messageWidth += columnWidth[i];
            }

            var messageHeight = lineCount * menu_item_height;

            if (previousMessageHeight == 0)
            {
                // first message: clear
                messageItems.Clear();
            }
            else
            {
                // appended message: re-position previous message
                foreach (var item in messageItems)
                {
                    item.Y -= ((messageHeight + (menu_item_height / 2)) / 2);
                }
            }

            var lblX = (screenResX - messageWidth) / 2;
            var lblY = (previousMessageHeight / 2) + (screenResY - messageHeight + (menu_item_height / 2)) / 2;

            var column = new CLayout(lblX, lblY, CLayout.Orientation.Vertical, true);

            for (var lineNo = 0; lineNo < lineCount; lineNo++)
            {
                if (!string.IsNullOrEmpty(lines[lineNo]))
                {
                    var line = lines[lineNo].Split('§');
                    var row  = new CLayout(lblX, lblY, CLayout.Orientation.Horizontal, true);
                    row.Width = messageWidth;
                    for (var colNo = 0; colNo < line.Length; colNo++)
                    {
                        CLabel lbl;
                        // first row is table header
                        if (lineNo == 0)
                        {
                            lbl = new CLabel(0, 0,
                                             columnWidth[colNo], (int)(menu_item_height * 1.2), line[colNo], menu_font_name,
                                             menu_font_size + 1, menu_font_style, menu_selected_font_color, menu_selected_backcolor, textAlign, false);
                            lbl.BorderColor = menu_font_color;
                        }
                        else
                        {
                            lbl = new CLabel(0, 0,
                                             columnWidth[colNo], menu_item_height, line[colNo], menu_font_name,
                                             menu_font_size, menu_font_style, menu_font_color, menu_backcolor, textAlign, false);
                        }
                        lbl.FillParent = line.Length != columnCount;
                        row.AddItem(lbl);
                    }
                    lblY += row.Height;
                    column.AddItem(row);
                }
            }
            messageItems.Add(column);
            column.Update();

            _showMessage = true;
            return(messageHeight);
        }