/// <summary> /// Calculate the correct position and size of a tab button, based on the /// index it is due to be placed at. /// </summary> /// <param name="index"> /// The index of the tab button /// </param> protected void CalculateTabButtonSizePosition(int index) { var btn = d_tabButtonVector[index]; // relative height is always 1.0 for buttons since they are embedded in a // panel of the correct height already var position = new UVector2(UDim.Absolute(0.0f), UDim.Absolute(0.0f)); var size = new USize(UDim.Absolute(0.0f), UDim.Relative(1.0f)); // x position is based on previous button if (index == 0) { // First button position.d_x = UDim.Absolute(d_firstTabOffset); } else { var prevButton = d_tabButtonVector[index - 1]; // position is prev pos + width position.d_x = prevButton.GetArea().d_max.d_x; } size.d_width = UDim.Absolute(btn.GetRenderedString().GetHorizontalExtent(btn)) + GetTabTextPadding() + GetTabTextPadding(); btn.SetPosition(position); btn.SetSize(size); var leftX = position.d_x.d_offset; btn.SetVisible((leftX < GetPixelSize().Width) && (leftX + btn.GetPixelSize().Width > 0)); btn.Invalidate(false); }
/// <summary> /// set the movement range of the thumb for the vertical axis. /// /// The values specified here are relative to the parent window for the thumb, and are specified in whichever /// metrics mode is active for the widget. /// </summary> /// <param name="min"> /// the minimum setting for the thumb on the vertical axis. /// </param> /// <param name="max"> /// the maximum setting for the thumb on the vertical axis. /// </param> public void SetVertRange(float min, float max) { // ensure min <= max, swap if not. if (min > max) { var tmp = min; max = min; min = tmp; } _vertMax = max; _vertMin = min; // validate current position. var cp = CoordConverter.AsRelative(GetYPosition(), GetParentPixelSize().Height); if (cp < min) { SetYPosition(UDim.Relative(min)); } else if (cp > max) { SetYPosition(UDim.Relative(max)); } }
// Overridden from Window protected override void InitialiseComponents() { // get horizontal scrollbar var horzScrollbar = GetHorzScrollbar(); // get vertical scrollbar var vertScrollbar = GetVertScrollbar(); // get scrolled container widget var container = GetScrolledContainer(); // do a bit of initialisation container.BanPropertyFromXML("MouseInputPropagationEnabled"); container.BanPropertyFromXML("ContentArea"); container.BanPropertyFromXML("ContentPaneAutoSized"); horzScrollbar.BanPropertyFromXML("AlwaysOnTop"); vertScrollbar.BanPropertyFromXML("AlwaysOnTop"); horzScrollbar.SetAlwaysOnTop(true); vertScrollbar.SetAlwaysOnTop(true); // container pane is always same size as this parent pane, // scrolling is actually implemented via positioning and clipping tricks. container.SetSize(new USize(UDim.Relative(1.0f), UDim.Relative(1.0f))); // subscribe to events we need to hear about vertScrollbar.ScrollPositionChanged += HandleScrollChange; horzScrollbar.ScrollPositionChanged += HandleScrollChange; container.ContentChanged += HandleContentAreaChange; container.AutoSizeSettingChanged += HandleAutoSizePaneChanged; // finalise setup ConfigureScrollbars(); }
public override void UpdateThumb() { var w = (Scrollbar)Window; var wlf = GetLookNFeel(); var area = wlf.GetNamedArea("ThumbTrackArea").GetArea().GetPixelRect(w); var theThumb = w.GetThumb(); var posExtent = w.GetDocumentSize() - w.GetPageSize(); float slideExtent; if (_vertical) { slideExtent = area.Height - theThumb.GetPixelSize().Height; theThumb.SetVertRange(area.Top / w.GetPixelSize().Height, (area.Top + slideExtent) / w.GetPixelSize().Height); theThumb.SetPosition( new UVector2(UDim.Absolute(area.Left), UDim.Relative((area.Top + (w.GetScrollPosition() * (slideExtent / posExtent))) / w.GetPixelSize().Height))); } else { slideExtent = area.Width - theThumb.GetPixelSize().Width; theThumb.SetHorzRange(area.Left / w.GetPixelSize().Width, (area.Left + slideExtent) / w.GetPixelSize().Width); theThumb.SetPosition( new UVector2( UDim.Relative((area.Left + (w.GetScrollPosition() * (slideExtent / posExtent))) / w.GetPixelSize().Width), UDim.Absolute(area.Top))); } }
public TestWindow() { Size = new USize(UDim.Relative(0.5f)); Position = new UVector2(UDim.Absolute(200), UDim.Absolute(50)); Title = "MY BEAUTIJFUL TEST WINDOW!?"; CanClose = true; Icon = "Inventory"; }
/// <summary> /// Constructor for Window base class /// </summary> /// <param name="type"> /// String object holding Window type (usually provided by WindowFactory). /// </param> /// <param name="name"> /// String object holding unique name for the Window. /// </param> protected LayoutContainer(string type, string name) : base(type, name) { _needsLayouting = false; _clientChildContentArea = new CachedRectf(this, (e, v) => ((LayoutContainer)e).GetClientChildContentAreaImpl(v)); // layout should take the whole window by default I think SetSize(new USize(UDim.Relative(1), UDim.Relative(1))); ChildAdded += HandleChildAdded; ChildRemoved += HandleChildRemoved; }
public HotbarPanel() : base("PanelAlt1", false) { Size = new USize(UDim.Relative(0.2f), UDim.Absolute(41f)); Position = new UVector2(UDim.Relative(0.4f), new UDim(1f, -41f)); InterestedKeys.Add(Keys.D1); InterestedKeys.Add(Keys.D2); InterestedKeys.Add(Keys.D3); InterestedKeys.Add(Keys.D4); InterestedKeys.Add(Keys.D5); InterestedKeys.Add(Keys.D6); InterestedKeys.Add(Keys.D7); InterestedKeys.Add(Keys.D8); InterestedKeys.Add(Keys.D9); InterestedKeys.Add(Keys.D0); SelectedIndex = 1; }
/// <summary> /// Setup size and position for the item widgets attached to this ItemListbox /// </summary> protected override void LayoutItemWidgets() { float y = 0f; float widest = 0f; foreach (var entry in ListItems) { var pxs = entry.GetItemPixelSize(); if (pxs.Width > widest) { widest = pxs.Width; } entry.SetArea(new URect(new UVector2(UDim.Absolute(0), UDim.Absolute(y)), new UVector2(UDim.Relative(1), UDim.Absolute(y + pxs.Height)))); y += pxs.Height; } // reconfigure scrollbars ConfigureScrollbars(new Sizef(widest, y)); }
// overridden from Slider base class. public override void UpdateThumb() { var w = (Slider)Window; // get area the thumb is supposed to use as it's area. var wlf = GetLookNFeel(); var area = wlf.GetNamedArea("ThumbTrackArea").GetArea().GetPixelRect(w); // get accesss to the thumb var theThumb = w.GetThumb(); var pixelSize = w.GetPixelSize(); var thumbRelXPos = pixelSize.Width == 0.0f ? 0.0f : (area.Left / pixelSize.Width); var thumbRelYPos = pixelSize.Height == 0.0f ? 0.0f : (area.Top / pixelSize.Height); // get base location for thumb widget var thumbPosition = new UVector2(UDim.Relative(thumbRelXPos), UDim.Relative(thumbRelYPos)); // Is this a vertical slider if (_vertical) { // pixel extent of total available area the thumb moves in var slideExtent = area.Height - theThumb.GetPixelSize().Height; // Set range of motion for the thumb widget if (pixelSize.Height != 0.0f) { theThumb.SetVertRange(area.Top / pixelSize.Height, (area.Top + slideExtent) / pixelSize.Height); } else { theThumb.SetVertRange(0.0f, 0.0f); } // calculate vertical positon for thumb var thumbOffset = w.GetCurrentValue() * (slideExtent / w.GetMaxValue()); if (pixelSize.Height != 0.0f) { thumbPosition.d_y.d_scale += (_reversed ? thumbOffset : slideExtent - thumbOffset) / pixelSize.Height; } } // Horizontal slider else { // pixel extent of total available area the thumb moves in var slideExtent = area.Width - theThumb.GetPixelSize().Width; // Set range of motion for the thumb widget if (pixelSize.Width != 0.0f) { theThumb.SetHorzRange(area.Left / pixelSize.Width, (area.Left + slideExtent) / pixelSize.Width); } else { theThumb.SetHorzRange(0.0f, 0.0f); } // calculate horizontal positon for thumb var thumbOffset = w.GetCurrentValue() * (slideExtent / w.GetMaxValue()); if (pixelSize.Width != 0.0f) { thumbPosition.d_x.d_scale += (_reversed ? slideExtent - thumbOffset : thumbOffset) / pixelSize.Width; } } // set new position for thumb. theThumb.SetPosition(thumbPosition); }
/// <summary> /// Constructor for DefaultWindows. /// </summary> /// <param name="type"></param> /// <param name="name"></param> public DefaultWindow(string type, string name) : base(type, name) { //SetMaxSize(new USize(UDim.Absolute(Single.MaxValue), UDim.Absolute(Single.MaxValue))); SetSize(new USize(UDim.Relative(1.0f), UDim.Relative(1.0f))); }
protected override void LoadContent() { _camera2D = new Camera2D(GraphicsDevice.Viewport); Services.AddService(_camera2D); Services.AddService(_penumbra); Services.AddService(_timeService = new TimeService(Services)); Services.AddService(GraphicsDevice); Services.AddService(_aiService = new AIService(Services, Content)); var mapService = new MapService(); Services.AddService(mapService); _gameObjectManager = new GameObjectManager(); Services.AddService(_gameObjectManager); _pathFindingService = new PathFindingService(mapService, _gameObjectManager); _character = new PlayerCharacter(Services); _character.LoadContent(Content); Services.AddService(_character); _spriteBatch = new SpriteBatch(GraphicsDevice); Services.AddService(_uiManager = new UIManager(Services, Content)); //var mapGenerator = new MapGenerator(Services, GraphicsDevice, Guid.NewGuid().GetHashCode(), Content); var mapGenerator = new MapGenerator(Services, GraphicsDevice, -425262119, Content); _map = mapGenerator.Generate(400, 400); //_map = mapGenerator.Generate(100, 100); mapService.Map = _map; _character.Position = _map.StartPosition; _gameObjectManager.LoadAll(Content); _pathFindingService = new PathFindingService(mapService, _gameObjectManager); _pathFindingService.Initialize(); Services.AddService(_pathFindingService); _mapRenderer = new MapRenderer(Services, _map); _mapRenderer.LoadContent(Content); _uiManager.Initialize(); _uiManager.AddVisual(new HotbarPanel()); _uiManager.AddVisual(new TimePanel(Services) { Position = new UVector2(UDim.Relative(0.01f), UDim.Relative(0.5f)) }); _chicken = new Chicken(Services); _chicken.LoadContent(Content); _chicken.Position = _character.Position + new Vector2(4f * 32f, 4f * 32f); _gameObjectManager.AddGameObject(_chicken); _gameObjectManager.AddGameObject(_character); _temp = new PrimitiveRectangle(GraphicsDevice, Color.Black, false); }