public void Arrange(GUIGroup element) { Thickness t = element.Margin; Point l = element.Location; double x = element.Location.X + t.Left; double y = element.Location.Y + t.Top; double w = _orientation != Orientation.Horizontal ? Math.Max(0, element.Width - t.Width) : 0; double h = _orientation == Orientation.Horizontal ? Math.Max(0, element.Height - t.Height) : 0; foreach (var child in element.Children) { if (child.Visibility == Visibility.Collapsed) { continue; } if (_orientation == Orientation.Horizontal) { ApplyAlignment(child, t, x, y, w = child.Width, h); x += w + _spacing.Width; continue; } ApplyAlignment(child, t, x, y, w, h = child.Height); y += h + _spacing.Height; } }
/// <summary> /// Try to locate the list element in a collection of gui controls /// </summary> /// <param name="collection">The collection where we browse in</param> /// <returns>The list if found, null otherwise</returns> private GUIListControl GetListControl(GUIControlCollection collection) { if (collection != null && collection.Count > 0) { //Get the control that holds all the list items foreach (GUIControl c in collection) { if (c.GetType() == typeof(GUIListControl)) { GUIListControl list = (GUIListControl)c; return(list); } else if (c.GetType() == typeof(GUIGroup)) { GUIGroup group = (GUIGroup)c; //Control type group, can have child elements GUIListControl list = GetListControl(group.Children); if (list != null) { //Found list in group type group, return it return(list); } } } } return(null); }
//private void ApplyAlignment(FrameworkElement element, Thickness t, double x, double y, double w, double h) //{ // Rect rect = new Rect(x, y, element.Width, element.Height); // switch (element.HorizontalAlignment) // { // case HorizontalAlignment.Center: // rect.X = x + w / 2 - element.Width / 2; // break; // case HorizontalAlignment.Right: // rect.X = x + w - element.Width; // break; // case HorizontalAlignment.Stretch: // rect.Width = w - t.Right; // break; // } // switch (element.VerticalAlignment) // { // case VerticalAlignment.Center: // rect.Y = y + h / 2 - element.Height / 2; // break; // case VerticalAlignment.Bottom: // rect.Y = h - element.Height; // break; // case VerticalAlignment.Stretch: // rect.Height = h - t.Bottom; // break; // } // element.Arrange(rect); //} public void Arrange(GUIGroup element) { Point l = element.Location; Rect r = new Rect(); Thickness t = element.Margin; int index = 0; foreach (var child in element.Children) { if (child.Visibility == Visibility.Collapsed) { continue; } double angle = (++index * 2 * Math.PI) / element.Children.Count; r.Width = child.Width; r.Height = child.Height; r.X = t.Left + _spacing.Width + ((_size.Width - t.Width - (_spacing.Width * 2)) / 2) + (int)(Math.Sin(angle) * _radius) - (r.Width / 2); r.Y = t.Top + _spacing.Height + ((_size.Height - t.Height - (_spacing.Height * 2)) / 2) - (int)(Math.Cos(angle) * _radius) - (r.Height / 2); child.Arrange(r); } }
public Size Measure(GUIGroup element, Size availableSize) { double w = 0; double h = 0; foreach (var child in element.Children) { if (child.Visibility == Visibility.Collapsed) { continue; } child.Measure(availableSize); w = _orientation != Orientation.Horizontal ? Math.Max(w, child.Width) : w + child.Width + _spacing.Width; h = _orientation == Orientation.Horizontal ? Math.Max(h, child.Height) : h + child.Height + _spacing.Height; } Thickness t = element.Margin; _size.Width = w + t.Width; _size.Height = h + t.Height; return(_size); }
public Size Measure(GUIGroup element, Size availableSize) { double w = 0; double h = 0; foreach (var child in element.Children) { if (child.Visibility == Visibility.Collapsed) { continue; } child.Measure(availableSize); w = Math.Max(w, child.Width); h = Math.Max(h, child.Height); } Thickness t = element.Margin; _radius = (Math.Min(w + _spacing.Width * element.Children.Count, h + _spacing.Height * element.Children.Count) / 2); _radius -= Math.Max(w, h) / 2; _size.Width = (int)(2 * _radius) - w + t.Width; _size.Height = (int)(2 * _radius) - h + t.Height; return(_size); }
/// <summary> /// Generates the elements of a window, which are stored in the UIElementCollection /// </summary> protected void GenerateElements() { _imageElementList = new List <BaseElement>(); _elementList = new List <BaseElement>(); foreach (var uiElement in _controlList) { GUIControl controlElement = uiElement; if (controlElement != null) { if (controlElement.GetType() == typeof(GUIGroup)) { GUIGroup groupElement = controlElement as GUIGroup; if (groupElement != null) { foreach (var uiElement2 in groupElement.Children) { GUIControl groupControlElement = uiElement2; if (groupControlElement != null) { AnalyzeElement(groupControlElement); } } } } else { AnalyzeElement(controlElement); } } } }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); texture = Content.Load <Texture2D>("Square"); font = Content.Load <SpriteFont>("Font"); GUIGroup group = new GUIGroup(); exitButton = new Button(); exitButton.Texture = texture; exitButton.Text = "Exit"; exitButton.Bounds = new Rectangle(50, 50, 300, 20); exitButton.Action += ExitGame; group.Children.Add(exitButton); Checkbox optionBox = new Checkbox(); optionBox.Texture = texture; optionBox.Box = texture; optionBox.Bounds = new Rectangle(50, 75, 300, 20); optionBox.Text = "Full Screen"; optionBox.Action += MakeFullScreen; group.Children.Add(optionBox); guiElements.Add(group); scenes.Add("Menu", new Scene(MainMenuUpdate, MainMenuDraw)); scenes.Add("Play", new Scene(PlayUpdate, PlayDraw)); currentScene = scenes["Menu"]; }
public GUIGroup RemoveUnit(PlayerUnit p) { GUIGroup ret = new GUIGroup(); ret.AddUnit(p); this.Units.RemoveAll(delegate(PlayerUnit p1) { return(p1.Info.GroupId == p.Info.GroupId); }); return(ret); }
private GUIGroup UnitExistsInPlayerGroup(Enemy unit) { GUIGroup group = _EnemyGroups.Find(delegate(GUIGroup g) { return(g.EnemyUnits.Contains(unit)); }); //Debug.Log(string.Format("Finding group containing unit:{0}. Found:{1}", unit.Info.Id, group != null ? group.ToString() : "no group!")); return(group); }
public void RemoveFromGroup(Enemy enemy) { GUIGroup g = UnitExistsInPlayerGroup(enemy); if (g != null) { g.RemoveUnit(enemy); } }
public void Arrange(GUIGroup element) { Thickness t = element.Margin; Point l = element.Location; double x = l.X + t.Left; double y = l.Y + t.Top; double w = _orientation != Orientation.Horizontal ? Math.Max(0, element.Width - t.Width) : 0; double h = _orientation == Orientation.Horizontal ? Math.Max(0, element.Height - t.Height) : 0; if (_orientation == Orientation.Horizontal && (element.GroupAlignment == Alignment.ALIGN_RIGHT || element.GroupAlignment == Alignment.ALIGN_CENTER)) { double fullWidth = 0; foreach (var child in element.Children) { if (child.Visibility == Visibility.Collapsed) { continue; } if (child is GUIFadeLabel) { fullWidth += ((GUIFadeLabel)child).Width + _spacing.Width; } else if (child is GUILabelControl) { fullWidth += ((GUILabelControl)child).Width + _spacing.Width; } else { fullWidth += child.Width + _spacing.Width; } } x = Math.Max(0, x + (element.Width - fullWidth)); } foreach (var child in element.Children) { if (child.Visibility == Visibility.Collapsed) { continue; } if (_orientation == Orientation.Horizontal) { ApplyAlignment(child, t, x, y, w = child.Width, h); x += w + _spacing.Width; continue; } ApplyAlignment(child, t, x, y, w, h = child.Height); y += h + _spacing.Height; } }
public GUIGroup RemoveUnit(Enemy e) { GUIGroup ret = new GUIGroup(); ret.AddUnit(e); this.EnemyUnits.Remove(e); if (this.EnemyUnits.Count == 0) { GameManager.Instance.GUIManager.RemoveGroup(this); } return(ret); }
public void Arrange(GUIGroup element) { Point location = element.Location; Thickness t = element.Margin; int rows = _rows; int cols = _cols; if (rows > 0) { cols = (element.Children.Count + rows - 1) / rows; } else { rows = (element.Children.Count + cols - 1) / cols; } double w = (element.Width - t.Width - (cols - 1) * _spacing.Width) / cols; double h = (element.Height - t.Height - (rows - 1) * _spacing.Height) / rows; double y = element.Location.Y + t.Top; for (int row = 0; row < rows; row++) { double x = element.Location.X + t.Left; for (int col = 0; col < cols; col++) { int index = _orientation == Orientation.Vertical ? col * rows + row : row * cols + col; if (index < element.Children.Count) { var component = element.Children[index]; if (component.Visibility == Visibility.Collapsed) { continue; } ApplyAlignment(component, t, x, y, w, h); } x += w + _spacing.Width; } y += h + _spacing.Height; } }
public static GUIGroup operator +(GUIGroup a, GUIGroup b) { GUIGroup ret = new GUIGroup(); ret.IsEnemy = a.IsEnemy || b.IsEnemy; if (!ret.IsEnemy) { ret.Units.AddRange(a.Units); ret.Units.AddRange(b.Units); } else { ret.EnemyUnits.AddRange(a.EnemyUnits); ret.EnemyUnits.AddRange(b.EnemyUnits); } //Debug.Log(string.Format("New group created. a:{0} with {1} units and b:{2} with {3} units became {4} with {5} units", a.Name, a.Units.Count, //b.Name, b.Units.Count, //ret.Name, ret.Units.Count)); ret.Expanded = a.Expanded || b.Expanded; return(ret); }
public Size Measure(GUIGroup element, Size availableSize) { double w = 0; double h = 0; int rows = _rows; int cols = _cols; if (rows > 0) { cols = (element.Children.Count + rows - 1) / rows; } else { rows = (element.Children.Count + cols - 1) / cols; } foreach (var child in element.Children) { if (child.Visibility == Visibility.Collapsed) { continue; } child.Measure(availableSize); w = Math.Max(w, child.Width); h = Math.Max(h, child.Height); } Thickness t = element.Margin; _size.Width = (w * cols + _spacing.Width * (cols - 1)) + t.Width; _size.Height = (h * rows + _spacing.Height * (rows - 1)) + t.Height; return(_size); }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); transforms = new List <Transform>(); cameras = new List <Camera>(); font = Content.Load <SpriteFont>("Font"); texture = Content.Load <Texture2D>("Square"); terrain = new TerrainRenderer(Content.Load <Texture2D>("PacManHeightMap"), Vector2.One * 100, Vector2.One * 200); terrain.NormalMap = Content.Load <Texture2D>("PacManNormalMap"); terrain.Transform = new Transform(); terrain.Transform.LocalScale *= new Vector3(1.7f, 1.5f, 1f); effect = Content.Load <Effect>("TerrainShader"); effect.Parameters["AmbientColor"].SetValue(new Vector3(0.2f, 0.2f, 0.2f)); effect.Parameters["DiffuseColor"].SetValue(new Vector3(0.1f, 0.1f, 0.1f)); effect.Parameters["SpecularColor"].SetValue(new Vector3(0.2f, 0.2f, 0.2f)); effect.Parameters["Shininess"].SetValue(20f); camera = new Camera(); camera.Transform = new Transform(); camera.Transform.LocalPosition += Vector3.Up * 50; camera.Transform.Rotate(Vector3.Right, -MathHelper.PiOver2); camera.Position = new Vector2(-0.10f, 0f); camera.Size = new Vector2(1f, 1f); camera.AspectRatio = camera.Viewport.AspectRatio; light = new Light(); light.Transform = new Transform(); light.Transform.LocalPosition = Vector3.Backward * 5 + Vector3.Right * 5 + Vector3.Up * 5; random = new Random(); pacman = new Pacman(terrain, Content, camera, GraphicsDevice, light); pacman.Transform.LocalScale = new Vector3(2f, 2f, 2f); Inky = new Ghost(terrain, Content, camera, GraphicsDevice, light, random); Blinky = new Ghost(terrain, Content, camera, GraphicsDevice, light, random); Pinky = new Ghost(terrain, Content, camera, GraphicsDevice, light, random); Clyde = new Ghost(terrain, Content, camera, GraphicsDevice, light, random); Blue = new Ghost(terrain, Content, camera, GraphicsDevice, light, random); powerUp = new Box(Content, camera, GraphicsDevice, light); cameras.Add(camera); GUIGroup group = new GUIGroup(); Button gameButton = new Button(); gameButton.Texture = texture; gameButton.Text = "Play Game!"; gameButton.Bounds = new Rectangle(0, 1, 300, 20); //exitButton.Action += ExitGame; gameButton.Action += playScreen; //guiElements.Add(exitButton); Changed to GUIGroup group.Children.Add(gameButton); CheckBox optionBox = new CheckBox(); optionBox.Texture = texture; optionBox.Box = texture; optionBox.Bounds = new Rectangle(0, 25, 300, 20); optionBox.Text = "Full Screen"; optionBox.Action += MakeFullScreen; group.Children.Add(optionBox); guiElements.Add(group); scenes.Add("Menu", new Scene(MainMenuUpdate, MainMenuDraw)); scenes.Add("Play", new Scene(PlayUpdate, PlayDraw)); scenes.Add("Credits", new Scene(CreditsUpdate, CreditsDraw)); currentScene = scenes["Menu"]; }
public Size Measure(GUIGroup element, Size availableSize) { Thickness t = element.Margin; double tableContentHeight = 0; // Calculated overall table height less vertical spacing. int cols = _cols; // User specified number of table columns. int i = 0; // Index for retrieving child controls. int c = 1; // Current column number. double rowHeight = 0d; // Current row height. GUIControl child; Cell TableCell; while (i < element.Children.Count) { c = 1; while (c <= cols) { if (i >= element.Children.Count) { break; // Bailout if we run out of controls while looking at the last row. } child = element.Children[i]; if (child.Visibility == Visibility.Collapsed) { i++; // Advance to the next control. continue; } // Get the table cell details for this child. TableCell = GetCell((GUIControl)child); if (TableCell.TargetCol > 0 && TableCell.TargetCol < c) { // We have passed the target column in this row. // Advance to the next row. c = cols + 1; continue; } if (TableCell.TargetCol > c) { // Advance to the specified column. c = TableCell.TargetCol; } child.Measure(availableSize); rowHeight = Math.Max(rowHeight, (double)child.Height * TableCell.RowSpan); // Advance column index according to specified column span. c += TableCell.ColSpan - 1; // Columns with no span specify the exact desired width of the column. if (TableCell.ColSpan == 1) { ((Column)_columns[c - 1]).width = (double)child.Width; ((Column)_columns[c - 1]).isCalculated = false; } i++; // Advance to the next control. c++; // Advance to the next column. } // Recalculate column width for each column with unspecified width. double span = 0; int count = 0; foreach (Column col in _columns) { if (!col.isCalculated) { span += col.width; count++; } } if (count > 0) { span = (_width - span) / (cols - count); foreach (Column col in _columns) { if (col.isCalculated) { col.width = span; } } } tableContentHeight += rowHeight; _rowHeight.Add(rowHeight); // Store the row height. rowHeight = 0; // Reset for next row. } // for (int x = 0; x <= _columns.Count - 1; x++) // { // Log.Info("TableLayout.Measure: columns[{0}]={1}, calc={2}", x, ((Column)_columns[x]).width, ((Column)_columns[x]).isCalculated); // } _size.Width = _width; // Table is fixed width. _size.Height = (tableContentHeight + _spacing.Height * (_rowHeight.Count - 1)) + t.Height; return(_size); }
public void Arrange(GUIGroup element) { Thickness t = element.Margin; int rows = _rowHeight.Count; // Calculated number of table rows. int cols = _cols; // User specified number of table columns. int i = 0; // Index for retrieving child controls. GUIControl child; Cell TableCell; double x = element.Location.X + t.Left; double y = element.Location.Y + t.Top; double w = 0; double h = 0; double ch = 0; for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { if (i >= element.Children.Count) { break; // Bailout if we run out of controls while looking at the last row. } child = element.Children[i]; if (child.Visibility == Visibility.Collapsed) { i++; // Advance to the next control. continue; } // Get the table cell details for this child. TableCell = GetCell((GUIControl)child); // If the target column is not the current column then move the x position to the target column position. // A target column value of 0 indicates no target column preference is set. if (TableCell.TargetCol > 0 && c != TableCell.TargetCol - 1) { // Check whether the target column in the current row. if (c < TableCell.TargetCol - 1) // Target column value is 1-based. { for (int a = c; a < TableCell.TargetCol - 1; a++) { x += ((Column)_columns[a]).width + _spacing.Width; } c = TableCell.TargetCol - 1; } else if (TableCell.TargetCol - 1 >= 0) { // Advance to the next row to set the target column. c = cols; continue; } } if (TableCell.ColSpan > 1) { // When spanning columns we must add the spacing. w = 0; for (int a = c; a <= c + TableCell.ColSpan - 1; a++) { w += ((Column)_columns[a]).width + _spacing.Width; // Log.Info("TableLayout.Arrange: spanning spanWidth={0:0.000}, colWidth={1:0.000}, w={2:0.000}", _spacing.Width, ((Column)_columns[a]).width, w); } w -= _spacing.Width; } else { w = ((Column)_columns[c]).width; // Log.Info("TableLayout.Arrange: w={0:0.000}", w); } h = (double)_rowHeight[r]; ch = child.Height * TableCell.RowSpan; //Log.Info("TableLayout.Arrange: (c={0}, r={1}) x={2:0.000},y={3:0.000},w={4:0.000}", c + 1, r + 1, x, y, w); ApplyAlignment(child, t, x, y, w, ch); // Move to the last column in the span. c += TableCell.ColSpan - 1; // Move to the start of the next column. x += w + _spacing.Width; i++; // Advance to the next control. } x = element.Location.X + t.Left; y += h + _spacing.Height; } }
public void RemoveGroup(GUIGroup guiGroup) { _EnemyGroups.Remove(guiGroup); }
protected override void OnPageLoad() { //Tools.LogMessage("entering OnPageLoad()"); base.OnPageLoad(); m_level = 0; m_prevIndex.Clear(); m_currentScore = null; bgwTimer = new BackgroundWorker(); bgwTimer.WorkerSupportsCancellation = true; bgwTimer.DoWork += new DoWorkEventHandler(bgwTimer_DoWork); bgwTimer.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgwTimer_RunWorkerCompleted); // prepare live parameters m_liveEnabled = File.Exists(Config.GetFile(Config.Dir.Config, LiveSettingsFileName)); string liveSkinIcon = GUIGraphicsContext.Skin + @"\Media\ScoreCenterLive.png"; if (File.Exists(liveSkinIcon)) { m_livePinImage = liveSkinIcon; } liveSkinIcon = GUIGraphicsContext.Skin + @"\Media\ScoreCenterLiveDisabled.png"; if (File.Exists(liveSkinIcon)) { m_livePinImageDisabled = liveSkinIcon; } if (lblLiveStatus != null) { m_liveLabelDefaultColor = lblLiveStatus.TextColor; } ShowNextButton(false); ShowNextPrevScoreButtons(false); GUIWaitCursor.Init(); GUIWaitCursor.Show(); m_scoreGroup = new GUIGroup(this.GetID); m_scoreGroup.WindowId = this.GetID; this.Children.Add(m_scoreGroup); System.Threading.ThreadPool.QueueUserWorkItem(delegate(object state) { try { ReadSettings(); ScoreFactory.Instance.CacheExpiration = m_center.Setup.CacheExpiration; GUIPropertyManager.SetProperty("#ScoreCenter.Title", m_center.Setup.Name); SetScoreProperties(null); // update UpdateSettings(false, false); #region Set HOME BaseScore homeScore = m_center.GetHomeScore(); if (homeScore == null) { LoadScores(""); } else { m_level = m_center.GetLevel(homeScore) - 1; LoadScores(homeScore.Parent); m_level++; DisplayScore(homeScore); SetScoreProperties(homeScore); m_currentScore = homeScore; } #endregion SetLiveStatus(); GUIControl.FocusControl(GetID, lstDetails.GetID); bgwTimer.RunWorkerAsync(); } catch (Exception exc) { Tools.LogError("Error occured while executing the OnPageLoad: ", exc); } finally { GUIWaitCursor.Hide(); } }); }