public void CopyLayout(CLayout masterLayout) { var counter = 0; foreach (var item in masterLayout._items) { if (_items.Count > counter) { _items[counter].X = item.X; _items[counter].Y = item.Y; _items[counter].Width = item.Width; _items[counter].Height = item.Height; } counter++; } }
public void ShowMenu(List <List <string> > menuCols, string titleText, string statusbarText, string currentMenu, string additionalData, string additionalInfo, bool menuChanged, string preselectedMenuKey, bool isWindowTextReader, string snapshotPath, string iconPath, bool showSideBar) { _currentMenu = currentMenu; _additionalData = additionalData; _additionalInfo = additionalInfo; _menuStrings = menuCols; menuColumnCount = menuCols.Count; _isMenuTextReader = isWindowTextReader; _snapshotPath = snapshotPath != string.Empty ? snapshotPath + (snapshotPath[snapshotPath.Length - 1] != '\\' ? "\\" : string.Empty) : string.Empty; _iconPath = iconPath; _showSideBar = showSideBar; Width = menu_min_width; menu_first_item_shown = 0; var currentCol = 0; var indent = menuCols.Count == 1 ? " " : string.Empty; _menuItems.Clear(); _titlebar = _statusbar = null; // create titlebar if (titleText != string.Empty) { _titlebar = new CLabel(0, 0, Width, (int)(menu_item_height * 1.2), titleText, menu_font_name, menu_font_size + 1, menu_font_style, menu_selected_font_color, menu_selected_backcolor, TextAlign.Left, false); _titlebar.BorderColor = menu_font_color; } // additional info _additionalInfoLayout = BuildTable(additionalInfo, TextAlign.Left, 0); _additionalInfoLayout.PaddingLeft = 10; var itemWidth = Width; var yCounter = 0; foreach (var menuRows in menuCols) { // on first column, decide menu size if (currentCol == 0) { var maxWidth = Width; foreach (var menuRow in menuRows) { var text = menuRow.Split('|').Length < 3 ? indent + menuRow.Split('|')[1] + indent : menuRow.Split('|')[1]; maxWidth = Math.Max(maxWidth, (int)menu_sprite_font.MeasureString(Utils.StringCleanup(text)).X + 8); } itemWidth = (int)Math.Min(maxWidth, _showSideBar && _currentMenu != "show_game_info" ? screenResX / 1.2 : screenResX - screenResX / 64) / menuColumnCount; } for (yCounter = 0; yCounter < menuRows.Count; yCounter++) { var menuRow = menuRows[yCounter]; var arr = menuRow.Split('|'); if (arr[1].StartsWith(("*#*T"))) { // process table var alignChar = arr[1].Substring("*#*T".Length, 1); var textAlign = alignChar == "L" ? TextAlign.Left : alignChar == "C" ? TextAlign.Center : TextAlign.Right; var tableString = string.Empty; for (; yCounter < menuRows.Count; yCounter++) { var tableRow = menuRows[yCounter].Split('|'); var rowString = menuRows[yCounter].Replace("*#*TL*#*", string.Empty). Replace("*#*TC*#*", string.Empty). Replace("*#*TR*#*", string.Empty). Replace("*#*/T*#*", string.Empty); tableString += rowString + "\n"; if (tableRow[1].Contains("*#*/T*#*")) { break; } } // remove last \n tableString = tableString.Substring(0, tableString.Length - 1); // inject table in menu _menuItems.AddRange(BuildTable(tableString, textAlign, itemWidth).Items); } else { // process item var lbl = new CLabel(0, 0, itemWidth, menu_item_height, arr.Length < 3 ? indent + arr[1] + indent : arr[1], menu_font_name, menu_font_size, menu_font_style, menu_font_color, Color.TransparentWhite, TextAlign.Left, arr.Length < 3 ? true : false); lbl.KeyName = arr[0]; lbl.Scrolling = false; _menuItems.Add(lbl); } } currentCol++; } menuRowsCount = yCounter; // create statusbar if (statusbarText != string.Empty) { _statusbar = new CLabel(0, 0, Width, (int)(menu_item_height * 0.9), statusbarText, menu_font_name, menu_font_size - 1, menu_font_style, menu_selected_font_color, menu_selected_backcolor, TextAlign.Right, false); _statusbar.BorderColor = menu_font_color; } _snapshotImage = new CImage(string.Empty, screenResX / 4, screenResY / 4, null, false, true, true); _snapshotImage.BorderColor = menu_font_color; _previousSnapshotPath = string.Empty; _iconImage = new CImage(string.Empty, screenResX / 12, screenResX / 12, null, false, true, false); _previousIconPath = string.Empty; StartTransition(CDrawable.Transition.FadeIn, 0); SelectMenuItem(preselectedMenuKey, menuChanged); }
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); }
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); }
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); }