Topic was automatically imported from the old Question2Answer platform.
Asked By
Iroh
Hello There,
I am developing a game for a german company in which they use many option buttons.
Sadly they also have a fixed resolution for the game. In one of the optionButtons, the options should show all the letters of the alphabet, meaning that it has more options then space in the screen.
Since the game should run on Android devices, im wondering how can I make the options scroll with a touch input, because I’m able to scroll using the mouse wheel but no dragging function…
I tried making a scrollcontainer for the whole scene, but the client didn’t like it.
Is there any way I can scroll or make them grow horizontaly or is there any other options I may use ?
@Royerson’s answer got me halfway there (Thanks!), but I ran into issues with the popup erroneously selecting items when I mean to be dragging. I use Godot C# Mono, but here is my code that is working OK for me by tracking the drag state.
using Godot;
using System;
public class DraggableOptionButton : OptionButton{
private PopupMenu popup;
private Boolean wasJustDragging = false;
public Boolean PopupIsVisible { get {
return this.popup.Visible;}}
```
public override void _Ready(){
this.popup = this.GetPopup();
this.popup.HideOnItemSelection = false;
this.popup.HideOnCheckableItemSelection = false;
this.popup.Connect("gui_input", this, nameof(this.OnPopupGuiInput));
}
public void OnPopupGuiInput(InputEvent @event){
this.popup.HideOnItemSelection = false;
this.popup.HideOnCheckableItemSelection = false;
if(@event is InputEventScreenDrag){
var dragEvent = (InputEventScreenDrag)@event;
this.popup.RectPosition += new Vector2(0, dragEvent.Relative.y);
//If we're dragging, set this flag to not release popup until we're done
this.wasJustDragging = true;}
if(@event is InputEventMouseButton){
if(!this.wasJustDragging){
//If we weren't just dragging, release the popup for normal input
this.popup.HideOnItemSelection = true;
this.popup.HideOnCheckableItemSelection = true;}
this.wasJustDragging = false;}
}
```
}
Thanks for this, works great!
This is the GDScript version just to save somebody else some typing
extends OptionButton
onready var popup = get_popup()
var was_just_dragging = false
func _ready():
popup.hide_on_item_selection = false
popup.hide_on_checkable_item_selection = false
popup.connect("gui_input", self, "_on_popup_gui_input")
func _on_popup_gui_input(event):
popup.hide_on_item_selection = false
popup.hide_on_checkable_item_selection = false
if event is InputEventScreenDrag:
self.popup.rect_position += Vector2(0, event.relative.y)
was_just_dragging = true
if event is InputEventMouseButton:
if not was_just_dragging:
popup.hide_on_item_selection = true
popup.hide_on_checkable_item_selection = true
was_just_dragging = false