Ejemplo n.º 1
0
 void SetupScrollBar()
 {
     // Item list scroll bar (e.g. items in character inventory)
     itemListScrollBar = new VerticalScrollBar
     {
         Position     = new Vector2(1, 18),
         Size         = new Vector2(6, itemListPanelRect.height - 35),
         DisplayUnits = listDisplayUnits
     };
     Components.Add(itemListScrollBar);
     itemListScrollBar.OnScroll += ItemsScrollBar_OnScroll;
 }
        void Setup()
        {
            // Cut out red up/down arrows
            Texture2D arrowTexture = ImageReader.GetTexture(redArrowsTextureName);

            arrowUpTexture   = ImageReader.GetSubTexture(arrowTexture, upArrowRect, arrowsFullSize);
            arrowDownTexture = ImageReader.GetSubTexture(arrowTexture, downArrowRect, arrowsFullSize);

            // Drop down button
            dropDownToggleButton = DaggerfallUI.AddButton(new Rect(0, 0, 7, 7), this);
            dropDownToggleButton.BackgroundColor   = new Color(0.2f, 0.2f, 0.2f, 0.5f);//0.5f);
            dropDownToggleButton.OnMouseClick     += DropdownButton_OnMouseClick;
            dropDownToggleButton.Hotkey            = DaggerfallShortcut.GetBinding(DaggerfallShortcut.Buttons.OptionsDropdown);
            dropDownToggleButton.BackgroundTexture = arrowUpTexture;

            // Dropdown options panel
            dropdownPanel                 = new Panel();
            dropdownPanel.Position        = new Vector2(0, dropDownToggleButton.Position.y + dropDownToggleButton.Size.y);
            dropdownPanel.Size            = new Vector2(50, 30);
            dropdownPanel.BackgroundColor = Color.black;
            dropdownPanel.Enabled         = false;
            dropdownPanel.Outline.Enabled = true;
            this.Components.Add(dropdownPanel);

            dropdownList                = new ListBox();
            dropdownList.Position       = new Vector2(2, 2);
            dropdownList.ShadowPosition = Vector2.zero;
            dropdownList.RowsDisplayed  = unitsDisplayed;
            SetBackground(dropdownList, Color.black, "pauseDropdownListBackgroundColor");
            dropdownList.OnSelectItem     += DropdownList_OnUseSelectedItem;
            dropdownList.SelectedTextColor = dropdownList.TextColor;
            dropdownList.OnScroll         += DropdownList_OnScroll;
            dropdownPanel.Components.Add(dropdownList);

            AddOptions();
            var height = dropdownList.HeightContent();

            dropdownList.Size  = new Vector2(maxTextWidth, height > 80 ? 80 : height);
            dropdownPanel.Size = new Vector2(dropdownList.Size.x + 6, dropdownList.Size.y + 3);

            dropdownScroller              = new VerticalScrollBar();
            dropdownScroller.Position     = new Vector2(maxTextWidth, 2);
            dropdownScroller.Size         = new Vector2(5, dropdownPanel.Size.y - 3);
            dropdownScroller.DisplayUnits = unitsDisplayed;
            dropdownScroller.TotalUnits   = dropdownList.Count;
            dropdownScroller.OnScroll    += SavesScroller_OnScroll;
            dropdownPanel.Components.Add(dropdownScroller);
        }
Ejemplo n.º 3
0
        int GetSafeScrollIndex(VerticalScrollBar scroller, bool delayScrollUp)
        {
            // Get current scroller index
            int scrollIndex = scroller.ScrollIndex;

            if (scrollIndex < 0)
            {
                scrollIndex = 0;
            }

            // Ensure scroll index within current range
            if (!delayScrollUp && scrollIndex + scroller.DisplayUnits > scroller.TotalUnits || scrollIndex >= scroller.TotalUnits)
            {
                scrollIndex = scroller.TotalUnits - scroller.DisplayUnits;
                if (scrollIndex < 0)
                {
                    scrollIndex = 0;
                }
                scroller.Reset(scroller.DisplayUnits, scroller.TotalUnits, scrollIndex);
            }
            return(scrollIndex);
        }
        protected override void Setup()
        {
            base.Setup();

            // Load native texture
            nativeTexture = DaggerfallUI.GetTextureFromImg(nativeImgName);
            if (!nativeTexture)
                throw new Exception("DaggerfallClassSelectWindow: Could not load native texture.");

            // Create panel for picker
            pickerPanel.Size = new Vector2(nativeTexture.width, nativeTexture.height);
            pickerPanel.HorizontalAlignment = HorizontalAlignment.Center;
            pickerPanel.VerticalAlignment = VerticalAlignment.Middle;
            pickerPanel.BackgroundTexture = nativeTexture;
            pickerPanel.BackgroundTextureLayout = TextureLayout.StretchToFill;
            NativePanel.Components.Add(pickerPanel);

            // Create list box
            listBox.Position = new Vector2(26, 27);
            listBox.Size = new Vector2(138, 72);
            listBox.OnUseSelectedItem += ListBox_OnUseSelectedItem;
            pickerPanel.Components.Add(listBox);

            // Add previous button
            Button previousButton = DaggerfallUI.AddButton(new Rect(179, 10, 9, 9), pickerPanel);
            previousButton.OnMouseClick += PreviousButton_OnMouseClick;

            // Add next button
            Button nextButton = DaggerfallUI.AddButton(new Rect(179, 108, 9, 9), pickerPanel);
            nextButton.OnMouseClick += NextButton_OnMouseClick;

            // Add scrollbar
            scrollBar = new VerticalScrollBar();
            scrollBar.Position = new Vector2(181, 23);
            scrollBar.Size = new Vector2(5, 82);
            scrollBar.OnScrollUp += ScrollBar_OnScrollUp;
            scrollBar.OnScrollDown += ScrollBar_OnScrollDown;
            pickerPanel.Components.Add(scrollBar);
        }
        /// <summary>
        /// Gets safe scroll index.
        /// Scroller will be adjust to always be inside display range where possible.
        /// </summary>
        int GetSafeScrollIndex(VerticalScrollBar scroller)
        {
            // Get current scroller index
            int scrollIndex = scroller.ScrollIndex;
            if (scrollIndex < 0)
                scrollIndex = 0;

            // Ensure scroll index within current range
            if (scrollIndex + scroller.DisplayUnits > scroller.TotalUnits)
            {
                scrollIndex = scroller.TotalUnits - scroller.DisplayUnits;
                if (scrollIndex < 0) scrollIndex = 0;
                scroller.Reset(scroller.DisplayUnits, scroller.TotalUnits, scrollIndex);
            }

            return scrollIndex;
        }
        void SetupScrollBars()
        {
            // Local items list scroll bar (e.g. items in character inventory)
            localItemsScrollBar = new VerticalScrollBar();
            localItemsScrollBar.Position = new Vector2(164, 66);
            localItemsScrollBar.Size = new Vector2(6, 117);
            localItemsScrollBar.DisplayUnits = listDisplayUnits;
            localItemsScrollBar.OnScroll += LocalItemsScrollBar_OnScroll;
            NativePanel.Components.Add(localItemsScrollBar);

            // Remote items list scroll bar (e.g. wagon, shop, loot pile, etc.)
            remoteItemsScrollBar = new VerticalScrollBar();
            remoteItemsScrollBar.Position = new Vector2(262, 66);
            remoteItemsScrollBar.Size = new Vector2(6, 117);
            remoteItemsScrollBar.DisplayUnits = listDisplayUnits;
            remoteItemsScrollBar.OnScroll += RemoteItemsScrollBar_OnScroll;
            NativePanel.Components.Add(remoteItemsScrollBar);
        }