public void Init() { mRendered = false; XUI ui = XUI.Instance(); mListenter_KeyUp = new XListener <XKeyInput.KeyUp>(1, eEventQueueFullBehaviour.Ignore, "WorldKeyUp"); XKeyInput.Instance().GetBroadcaster_KeyUp().Subscribe(mListenter_KeyUp); mListener_Button = new XListener <XUI.ButtonUpEvent>(1, eEventQueueFullBehaviour.Ignore, "WorldButton"); ui.GetBroadcaster_ButtonUpEvent().Subscribe(mListener_Button); mRegnerateMapButton = ui._CreateRectangularButton(new Vector2(30, 30), "Regenerate Map", XUI.eStyle.GameplayUI); mMapTypeButton = ui._CreateRectangularButton(new Vector2(30, 125), "Change Map Type", XUI.eStyle.GameplayUI); mMapSizeButton = ui._CreateRectangularButton(new Vector2(30, 220), "Change Map Size", XUI.eStyle.GameplayUI); /* * mMapSizeButton = ui.CreateRectangularButton( new Vector2( 30, 315 ), * "Hy0123456789012345678901234567890123456789", * XUI.eStyle.FontTest ); */ /* * String[] texts = { "Hello", "Goodbye", "Meatball Soup", "Four", "5" }; * String[] controls = { "Back", "Exit Game", "Quit Program, not really, i'm having fun" }; * mSelector = ui.CreateSelector( new Vector2( 1000, 400 ), "missing everything", XUI.eStyle.Frontend, XUI.eStyle.FrontendButton, * XUI.eStyle.FrontendTitle, XUI.eStyle.FrontendControl, texts, controls ); */ Generate(); }
public Selector(_Position pos, String title, eStyle style, eStyle button_style, eStyle title_style, long id, String[] texts) { mRenderEnabled = true; mID = id; mPos = pos.GetPosition(); mPosition = pos; mTitle = title; mStyle = style; mButtonStyle = button_style; mTitleStyle = title_style; this.mSelections = new _IButton[texts.Length]; // create a default button to see how big it is vertically // size and position border accordingly, factoring in width of largest button including title // destroy that button // create all the proper buttons in the right spot // create title 'button' as disabled button XUI xui_inst = XUI.Instance(); _IButton test = xui_inst._CreateRectangularButton(Vector2.Zero, "Test", style); xAABB2 button_size = test.GetAABB(); float button_size_y = button_size.GetSize().Y; xui_inst._DestroyButton(test); const float k_border_padding_scalar = 0.5f; float border_padding = k_border_padding_scalar * button_size_y; const float k_spacing_scalar = 0.2f; float spacing = k_spacing_scalar * button_size_y; // pad out the text strings so the buttons can be wide if the text is small int longest = GetLongestString(texts); PadButtonTexts(texts, longest); // create buttons PositionAndCreateButtons(texts, mSelections, border_padding, spacing, button_size_y, button_style, 0); // track largest float largest_x = GetWidest(mSelections); // create title button (non-functional) and see if it's the largest Vector2 title_pos = mPos + new Vector2(border_padding, border_padding); mTitleButton = xui_inst._CreateRectangularButton(title_pos, title, title_style); mTitleButton.SetActive(false); largest_x = Math.Max(largest_x, mTitleButton.GetAABB().GetSize().X); // calculate aabb const float title_padding_scalar = 4.0f; float title_padding = border_padding * title_padding_scalar; Vector2 title_padding_v = new Vector2(0, title_padding); float full_width = largest_x + 2 * border_padding; float full_height = button_size_y * (mSelections.Length) + (mSelections.Length - 1) * spacing + 2 * border_padding + title_padding; mAABB.Set(mPos, mPos + new Vector2(full_width, full_height)); // translate each button to be centered, and account for title CenterButtons(mSelections, largest_x, title_padding); CenterButton(mTitleButton, largest_x, 0); // if the selector has a non-trivial Position, fix it if (mPosition.IsCentered()) { // see where it is now, figure out where it should be, translate. // apply to aabb for selector plus translate all the buttons xCoord screen_dim = XRenderManager.Instance().GetScreenDim(); Vector2 span = mAABB.GetSize(); Vector2 screen_dim_vec = new Vector2(screen_dim.x, screen_dim.y); Vector2 edge = 0.5f * (screen_dim_vec - span); Translate(edge); } }