#SpinBox Tweaking

1 messages · Page 1 of 1 (latest)

ionic mica
#

So I am going down a rabbithole and I know there must be a better way.
I am trying to combine a SpinBox with a HSlider, I basically want to be able to drag left and right to change the value and I want to change the background of the SpinBox to show where the value is much like with a HSlider. I also want drag and the buttons to round to a certain step size but to be able to type in numbers with more precision. Is there a way to do that without essentially rewriting the spinbox control? Also the step size should change dynamically but I can just have a listener update it on each value change.

To make the progress bar look work I'd have to override draw right and then draw the whole thing? Setting the step size dynamicaly while draging is easy enough, but how do I make that work with the buttons? I am sure there must be an easier solution I am not thinking off, and that someone has run into the same problem before me.

Also I'd like it to be smart about units which I can handle with a suffix (like kg, ton, g etc) but how to handle user entry of the suffix if they change it? At the moment the suffix disapears while editing, and I'd have to do some clamping of values and some trickery to change the display sensibly like switching from 1000kg to 1 ton, the internal value would still be 1000, so I'd need to fully divorce the displayed value from the actual internal game value. So while I am at is is there an easier way to handle that or is the maintaining a game value and a displayed value the best approach?

ripe notch
#

So, you're asking for a million things. If I'm understanding what you're going for, we could accomplish most of them with just pure code. The choice between spinbox and hslider are up to you, but graphically everything is handled differently anyway. So, if graphics are your main concern, neither choice is better, and if the function is your concern, neither choice is better.

Maybe if you have an example of what you're trying to replicate? Or even some code you've already tried?

ionic mica
#

So at the moment I have this, a Spinbox with a linked HSlider below this. But it takes up a lot of vertical space and the user needs to click on the slider to drag the values back and forth. The second pictiure is more what I want with the Texture of the Spinbox indicating where in the range it is. Also in the second picture one of the slideboxes is at 40kg if I grad it below 1kg it will switch to showing 1000g, of if I got over 1000kg it switches to tons. I'm workign on a similar system but it is a bit finiky at the moment. When I click in game to edit a slider at say 40kg the kg disapears. and if I enter say 40g that doesn't work, but if I type 0.04 then it will properly convert. Is there a way to accept units inside the spinbox? At the momet I am listening to value changed which only gets a float not the unit entered.

ripe notch
#

Alright, I don't normally do this, but I just made it for you. Here's the scenetree

#
extends HBoxContainer

var button_held : int = 0
var mouse_held : bool = false

func _process(delta: float) -> void:
    if button_held:
        # -1 if less than button, 1 if more than button
        step_progress(button_held)


func _on_progress_bar_gui_input(event: InputEvent) -> void:
    if event is InputEventMouseButton and event.is_pressed():
        mouse_held = true
    if event is InputEventMouseButton and event.is_released():
                mouse_held = false
    if mouse_held and event is InputEventMouseMotion:
        if event.relative.x > 0:
            step_progress(1)
        else:
            step_progress(-1)


func step_progress(direction : int) -> void:
    $ProgressBar.value += direction * $ProgressBar.step


func _on_less_button_down() -> void:
    button_held = -1


func _on_less_button_up() -> void:
    button_held = 0


func _on_more_button_down() -> void:
    button_held = 1


func _on_more_button_up() -> void:
    button_held = 0

All the code. It's a bit over-engineered, but should work for everything you're looking for. You'll have to connect the relevant signals otherwise it won't detect input. As far as getting the values to work with prefixes, that's a pretty simple problem you can work out with math. I can help you with that tomorrow if you can't figure it out, just DM me.

ionic mica
#

Thank you that is way more than I expected.

ripe notch
# ionic mica Thank you that is way more than I expected.

No problem! Once I had the example to follow it didn't take that long. It's a pretty cool menu item too, so maybe I'll use it for my own game too.

Like I said, if you're still having trouble with the math for the conversion, let me know!

ionic mica
#

I am making some tweaks to it but I will share the code here once I have it functional, this definitly put me on the right path compared to what I was doign before.