Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: Adding new panel and extra buttons #1509

Merged
merged 6 commits into from May 19, 2024
Merged

UI: Adding new panel and extra buttons #1509

merged 6 commits into from May 19, 2024

Conversation

TimGoll
Copy link
Member

@TimGoll TimGoll commented May 6, 2024

To support more features / actions in the F1 menu, additional UI elements have to be added. This is a PR that aims to bring the elements to the panels:

image
This is a simple button that can have any action attached

image
These are two new types of buttons that can be added to many elemens. A "run" button that is basically a normal button that performs an action and a "toggle" button that toggles between states. Both can have any color or any icon, shown here are the default colors and states.

This is how these elements are added:

local form2 = vgui.CreateTTT2Form(parent, "new UI elements")

form2:MakeButton({
    label = "some label",
    buttonLabel = "this button is clickable",
    OnClick = function(slf)
        print("I was pressed")
    end,
})

form2:MakeCheckBox({
    label = "generic convar with two extra buttons",
    convar = "ttt2b_grenade_trajectory_ui",
    enableToggle = true,
    enableRun = true,
    OnClickToggle = function(button, state)
        print("toggling", button, state)
    end,
    OnClickRun = function(button)
        print("running", button)
    end,
})

form2:MakeCheckBox({
    label = "generic convar with two extra buttons number two",
    convar = "ttt2c_grenade_trajectory_ui",
    enableToggle = true,
    enableRun = true,
    toggleInitialState = 2,
    OnClickToggle = function(button, state)
        print("toggling", button, state)
    end,
    OnClickRun = function(button)
        print("running", button)
    end,
})

form2:MakeCheckBox({
    label = "only a toggle button!",
    convar = "ttt2c_grenade_trajectory_ui",
    enableToggle = true,
    OnClickToggle = function(button, state)
        print("toggling", button, state)
    end,
})

form2:MakeSlider({
    label = "a slider can also have one or two extra buttons",
    convar = "ttt_ironsights_crosshair_opacity",
    min = 0,
    max = 1,
    decimal = 1,
    enableRun = true,
    OnClickRun = function(button)
        print("running", button)
    end,
})

form2:MakeComboBox({
    label = "the same is true for combo boxes",
    convar = "ttt_crosshair_mode",
    choices = {
        { title = TryT("choice_crosshair_mode_0"), value = 0 },
        { title = TryT("choice_crosshair_mode_1"), value = 1 },
        { title = TryT("choice_crosshair_mode_2"), value = 2 },
    },
    enableToggle = true,
    enableRun = true,
    OnClickToggle = function(button, state)
        print("toggling", button, state)
    end,
    OnClickRun = function(button)
        print("running", button)
    end,
})

form2:MakeTextEntry({
    label = "textboxes are neat too",
    convar = "ttt_crosshair_mode",
    enableToggle = true,
    enableRun = true,
    OnClickToggle = function(button, state)
        print("toggling", button, state)
    end,
    OnClickRun = function(button)
        print("running", button)
    end,
})

@TimGoll TimGoll added the type/enhancement Enhancement or simple change to existing functionality label May 6, 2024
@TimGoll TimGoll added this to the v0.14.0b milestone May 6, 2024
@TimGoll TimGoll marked this pull request as ready for review May 7, 2024 19:24
@TimGoll TimGoll changed the title UI: Adding new panel UI: Adding new panel and extra buttons May 9, 2024
@TimGoll TimGoll merged commit 2e6ae91 into master May 19, 2024
4 checks passed
@TimGoll TimGoll deleted the new-panel-elements branch May 19, 2024 13:22
TimGoll added a commit that referenced this pull request May 20, 2024
Added a run button to all bindings. When pressing the button, the
binding is executed, even if no key is added to that binding.


![image](https://github.com/TTT-2/TTT2/assets/13639408/08c43db4-4df6-4be4-bfd3-9f014e82525a)

It also fixes a small rendering issue introduced in #1509
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement Enhancement or simple change to existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants