Class GenericScreen

java.lang.Object
com.badlogic.gdx.scenes.scene2d.Actor
com.badlogic.gdx.scenes.scene2d.Group
com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup
com.badlogic.gdx.scenes.scene2d.ui.Table
gaiasky.gui.screen.GenericScreen
All Implemented Interfaces:
com.badlogic.gdx.scenes.scene2d.utils.Cullable, com.badlogic.gdx.scenes.scene2d.utils.Layout, IScreen

public abstract class GenericScreen extends com.badlogic.gdx.scenes.scene2d.ui.Table implements IScreen
Abstract base class for full-screen UI views within the application.

GenericScreen extends Table to provide a structured layout that occupies the entire application viewport. It handles common UI concerns such as managing modal overlays, input redirection, keyboard shortcuts (ESC, ENTER, TAB), gamepad listeners, and tabbed content interfaces.

This class provides a consistent framework for creating dialogs, menus, or main screens. It automatically manages the focus hierarchy, input processors, and event listeners when the screen is shown or hidden.

Key Features

  • Full-Viewport Layout: Takes up the whole application viewport by default.
  • Modal Support: Configurable modal behavior to capture and disable external input.
  • Input Management: Automatically backs up and restores previous mouse/keyboard/gamepad listeners when entering or leaving the screen.
  • Keyboard Shortcuts: Built-in support for ESC (close/cancel), ENTER (accept), and TAB (focus switching).
  • Tab System: Integrated support for tabbed interfaces with automatic listener setup.
  • Animation: Default fade-in/fade-out animations when showing/hiding.

Layout Structure

By default, the screen layout consists of four parts:

  1. Title: A top bar displaying the screen title.
  2. Content: The main area for UI elements.
  3. Buttons: A horizontal group containing the Accept and Cancel buttons (right-aligned).
  4. Tabs: Optional tabs line to support content switching, managed by the subclass.

Subclassing

To create a new screen, extend GenericScreen and:

  1. Override build(): Populate the content table with your UI actors.
  2. Override accept(): Define what happens when the Accept button is clicked.
  3. Override cancel(): Define what happens when the Cancel button is clicked.
  4. (Optional) Override setKeyboardFocus(): Set focus to a specific widget when the screen is shown.
See Also:
  • Table
  • Actor
  • Stage
  • Nested Class Summary

    Nested classes/interfaces inherited from class com.badlogic.gdx.scenes.scene2d.ui.Table

    com.badlogic.gdx.scenes.scene2d.ui.Table.Debug, com.badlogic.gdx.scenes.scene2d.ui.Table.DebugRect
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    com.badlogic.gdx.scenes.scene2d.ui.TextButton
     
    protected Runnable
     
    protected Set<com.badlogic.gdx.controllers.ControllerListener>
     
     
    protected com.badlogic.gdx.scenes.scene2d.ui.Table
     
    protected com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup
     
    com.badlogic.gdx.scenes.scene2d.ui.TextButton
     
    protected Runnable
     
    protected Runnable
     
    protected com.badlogic.gdx.scenes.scene2d.ui.Table
     
    protected boolean
     
    protected boolean
     
    protected boolean
     
    protected boolean
     
     
    protected com.badlogic.gdx.scenes.scene2d.InputListener
     
    protected boolean
     
    protected GenericScreen
     
     
    protected static final float
     
    protected static final float
     
    protected static final float
     
    protected static final float
     
    protected com.badlogic.gdx.utils.Array<OwnScrollPane>
     
    protected int
    Currently selected tab
    protected final com.badlogic.gdx.scenes.scene2d.ui.Skin
     
    protected final com.badlogic.gdx.scenes.scene2d.Stage
     
    protected com.badlogic.gdx.utils.Array<com.badlogic.gdx.scenes.scene2d.ui.TextButton>
    If this dialog has tabs, this list holds them.
    protected com.badlogic.gdx.utils.Array<com.badlogic.gdx.scenes.scene2d.Group>
    Actual actor for each tab.
    protected com.badlogic.gdx.scenes.scene2d.ui.Stack
    Tab contents stack.
     

    Fields inherited from class com.badlogic.gdx.scenes.scene2d.ui.Table

    backgroundBottom, backgroundLeft, backgroundRight, backgroundTop, debugActorColor, debugCellColor, debugTableColor

    Fields inherited from class com.badlogic.gdx.scenes.scene2d.Actor

    POOLS
  • Constructor Summary

    Constructors
    Constructor
    Description
    GenericScreen(String title, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, com.badlogic.gdx.scenes.scene2d.Stage stage)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract boolean
    The accept function, if any.
    com.badlogic.gdx.scenes.scene2d.ui.Button
     
    void
    act(float delta)
     
    void
    Adds a horizontal separator to the main content table with the default colspan of 1.
    void
    addSeparator(int colSpan)
    Adds a horizontal separator to the main content table with the given colspan.
    protected void
    addTabContent(com.badlogic.gdx.scenes.scene2d.Group tabContent)
    Add tab contents to the list of tabs.
    protected abstract void
    Build the content here.
    void
     
    protected abstract void
    The cancel function, if any.
    com.badlogic.gdx.scenes.scene2d.ui.Button
     
    boolean
    Closes the window with the accept action.
    boolean
    Closes the window with the cancel action.
    abstract void
     
    protected void
    enableComponents(boolean enabled, com.badlogic.gdx.scenes.scene2d.utils.Disableable... components)
    Sets the enabled property on the given components.
    void
     
    com.badlogic.gdx.scenes.scene2d.Group
     
    com.badlogic.gdx.scenes.scene2d.ui.Table
     
    com.badlogic.gdx.scenes.scene2d.Group
     
    com.badlogic.gdx.scenes.scene2d.ui.Table
     
    com.badlogic.gdx.scenes.scene2d.Group
     
    com.badlogic.gdx.scenes.scene2d.Stage
     
    com.badlogic.gdx.utils.Array<com.badlogic.gdx.scenes.scene2d.ui.TextButton>
     
    com.badlogic.gdx.scenes.scene2d.ui.Table
     
    boolean
     
    boolean
     
    boolean
     
    void
    Hides the dialog.
    void
    hide(com.badlogic.gdx.scenes.scene2d.Action action)
    Hides the dialog with the given action and then removes it from the stage.
    protected void
     
    void
    setAcceptButtonColor(com.badlogic.gdx.graphics.Color col)
     
    void
     
    void
    Sets a listener that runs when accept is clicked.
    void
    setAcceptText(String acceptText)
     
    void
    setCancelButtonColors(com.badlogic.gdx.graphics.Color textColor, com.badlogic.gdx.graphics.Color buttonColor)
     
    void
     
    void
    Sets a listener that runs when cancel is clicked.
    void
    setCancelText(String cancelText)
     
    void
    Sets a listener that runs when the dialog is closed.
    void
    Sets the keyboard focus, override in case you want to set the focus to a specific item.
    protected void
    Prepares the tab button listeners that make tab buttons actually change the content.
    show(com.badlogic.gdx.scenes.scene2d.Stage stage)
    Packs the dialog and adds it to the stage, centered with default fadeIn action.
    show(com.badlogic.gdx.scenes.scene2d.Stage stage, float x, float y)
    Packs the dialog and adds it to the stage at the specified position.
    show(com.badlogic.gdx.scenes.scene2d.Stage stage, com.badlogic.gdx.scenes.scene2d.Action action)
    Packs the dialog and adds it to the stage with custom action which can be null for instant show.
    protected void
    showDialogHook(com.badlogic.gdx.scenes.scene2d.Stage stage)
     
    boolean
     
    boolean
     
    void
    Override this method to update the contents of this dialog before displaying it.

    Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Table

    add, add, add, add, add, add, add, align, background, background, bottom, center, clearChildren, clip, clip, columnDefaults, debug, debug, debugActor, debugAll, debugCell, debugTable, defaults, draw, drawBackground, drawDebug, drawDebugBounds, getAlign, getBackground, getCell, getCells, getClip, getColumnMinWidth, getColumnPrefWidth, getColumns, getColumnWidth, getMinHeight, getMinWidth, getPadBottom, getPadBottomValue, getPadLeft, getPadLeftValue, getPadRight, getPadRightValue, getPadTop, getPadTopValue, getPadX, getPadY, getPrefHeight, getPrefWidth, getRow, getRowHeight, getRowMinHeight, getRowPrefHeight, getRows, getSkin, getTableDebug, hit, invalidate, layout, left, pad, pad, pad, pad, padBottom, padBottom, padLeft, padLeft, padRight, padRight, padTop, padTop, removeActor, removeActor, removeActorAt, reset, right, row, setBackground, setBackground, setClip, setDebug, setRound, setSkin, stack, top

    Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup

    childrenChanged, getMaxHeight, getMaxWidth, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, sizeChanged, validate

    Methods inherited from class com.badlogic.gdx.scenes.scene2d.Group

    addActor, addActorAfter, addActorAt, addActorBefore, applyTransform, applyTransform, clear, clear, clearChildren, computeTransform, drawChildren, drawDebugChildren, findActor, getChild, getChildren, getCullingArea, hasChildren, isTransform, localToDescendantCoordinates, resetTransform, resetTransform, setCullingArea, setDebug, setStage, setTransform, swapActor, swapActor, toString

    Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor

    addAction, addCaptureListener, addListener, ancestorsVisible, ascendantsVisible, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, fire, firstAscendant, getActions, getCaptureListeners, getColor, getDebug, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getTop, getTouchable, getUserObject, getWidth, getX, getX, getY, getY, getZIndex, hasActions, hasKeyboardFocus, hasParent, hasScrollFocus, isAscendantOf, isDescendantOf, isTouchable, isTouchFocusListener, isTouchFocusTarget, isVisible, localToActorCoordinates, localToAscendantCoordinates, localToParentCoordinates, localToScreenCoordinates, localToStageCoordinates, moveBy, notify, parentToLocalCoordinates, positionChanged, remove, removeAction, removeCaptureListener, removeListener, rotateBy, rotationChanged, scaleBy, scaleBy, scaleChanged, screenToLocalCoordinates, setBounds, setColor, setColor, setHeight, setName, setOrigin, setOrigin, setOriginX, setOriginY, setParent, setPosition, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setTouchable, setUserObject, setVisible, setWidth, setX, setX, setY, setY, setZIndex, sizeBy, sizeBy, stageToLocalCoordinates, toBack, toFront

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface IScreen

    getBottomGroup
    Modifier and Type
    Method
    Description
    com.badlogic.gdx.scenes.scene2d.Group
     
  • Field Details

    • pad34

      protected static final float pad34
      See Also:
    • pad20

      protected static final float pad20
      See Also:
    • pad18

      protected static final float pad18
      See Also:
    • pad10

      protected static final float pad10
      See Also:
    • stage

      protected final com.badlogic.gdx.scenes.scene2d.Stage stage
    • skin

      protected final com.badlogic.gdx.scenes.scene2d.ui.Skin skin
    • title

      public String title
    • acceptButton

      public com.badlogic.gdx.scenes.scene2d.ui.TextButton acceptButton
    • cancelButton

      public com.badlogic.gdx.scenes.scene2d.ui.TextButton cancelButton
    • me

      protected GenericScreen me
    • content

      protected com.badlogic.gdx.scenes.scene2d.ui.Table content
    • bottom

      protected com.badlogic.gdx.scenes.scene2d.ui.Table bottom
    • defaultMouseKbdListener

      protected boolean defaultMouseKbdListener
    • defaultGamepadListener

      protected boolean defaultGamepadListener
    • buttonGroup

      protected com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup buttonGroup
    • enterExit

      protected boolean enterExit
    • escExit

      protected boolean escExit
    • keysListener

      protected boolean keysListener
    • acceptListener

      protected Runnable acceptListener
    • cancelListener

      protected Runnable cancelListener
    • closeListener

      protected Runnable closeListener
    • mouseKbdListener

      protected AbstractMouseKbdListener mouseKbdListener
    • gamepadListener

      protected AbstractGamepadListener gamepadListener
    • tabButtons

      protected com.badlogic.gdx.utils.Array<com.badlogic.gdx.scenes.scene2d.ui.TextButton> tabButtons
      If this dialog has tabs, this list holds them.
    • selectedTab

      protected int selectedTab
      Currently selected tab
    • tabContents

      protected com.badlogic.gdx.utils.Array<com.badlogic.gdx.scenes.scene2d.Group> tabContents
      Actual actor for each tab.
    • tabStack

      protected com.badlogic.gdx.scenes.scene2d.ui.Stack tabStack
      Tab contents stack.
    • ignoreTouchDown

      protected com.badlogic.gdx.scenes.scene2d.InputListener ignoreTouchDown
    • scrolls

      protected com.badlogic.gdx.utils.Array<OwnScrollPane> scrolls
    • backupMouseKbdListeners

      protected Set<AbstractMouseKbdListener> backupMouseKbdListeners
    • backupGamepadListeners

      protected Set<com.badlogic.gdx.controllers.ControllerListener> backupGamepadListeners
  • Constructor Details

    • GenericScreen

      public GenericScreen(String title, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, com.badlogic.gdx.scenes.scene2d.Stage stage)
  • Method Details

    • setAcceptText

      public void setAcceptText(String acceptText)
    • setAcceptButtonStyle

      public void setAcceptButtonStyle(String style)
    • setAcceptButtonColor

      public void setAcceptButtonColor(com.badlogic.gdx.graphics.Color col)
    • setCancelText

      public void setCancelText(String cancelText)
    • setCancelButtonStyle

      public void setCancelButtonStyle(String style)
    • setCancelButtonColors

      public void setCancelButtonColors(com.badlogic.gdx.graphics.Color textColor, com.badlogic.gdx.graphics.Color buttonColor)
    • addTabContent

      protected void addTabContent(com.badlogic.gdx.scenes.scene2d.Group tabContent)
      Add tab contents to the list of tabs.
      Parameters:
      tabContent - The contents.
    • setUpTabListeners

      protected void setUpTabListeners()
      Prepares the tab button listeners that make tab buttons actually change the content. It also sets up the button group, which restricts the number of tabs that can be checked at once to one.
    • recalculateButtonSize

      protected void recalculateButtonSize()
    • buildSuper

      public void buildSuper()
    • build

      protected abstract void build()
      Build the content here.
    • closeAccept

      public boolean closeAccept()
      Closes the window with the accept action.
      Specified by:
      closeAccept in interface IScreen
    • closeCancel

      public boolean closeCancel()
      Closes the window with the cancel action.
      Specified by:
      closeCancel in interface IScreen
      Returns:
      Whether the cancel operation succeeded.
    • accept

      protected abstract boolean accept()
      The accept function, if any.
      Returns:
      True if the dialog must close after the call, false otherwise.
    • cancel

      protected abstract void cancel()
      The cancel function, if any.
    • show

      public GenericScreen show(com.badlogic.gdx.scenes.scene2d.Stage stage, com.badlogic.gdx.scenes.scene2d.Action action)
      Packs the dialog and adds it to the stage with custom action which can be null for instant show.
      Parameters:
      stage - The stage.
      action - Action to run.
      Returns:
      The generic dialog instance.
    • touch

      public void touch()
      Override this method to update the contents of this dialog before displaying it.
    • getCurrentContentContainer

      public com.badlogic.gdx.scenes.scene2d.Group getCurrentContentContainer()
      Specified by:
      getCurrentContentContainer in interface IScreen
    • getBottmGroup

      public com.badlogic.gdx.scenes.scene2d.Group getBottmGroup()
    • getButtonsGroup

      public com.badlogic.gdx.scenes.scene2d.Group getButtonsGroup()
      Specified by:
      getButtonsGroup in interface IScreen
    • show

      public GenericScreen show(com.badlogic.gdx.scenes.scene2d.Stage stage)
      Packs the dialog and adds it to the stage, centered with default fadeIn action.
    • showDialogHook

      protected void showDialogHook(com.badlogic.gdx.scenes.scene2d.Stage stage)
    • show

      public GenericScreen show(com.badlogic.gdx.scenes.scene2d.Stage stage, float x, float y)
      Packs the dialog and adds it to the stage at the specified position.
    • setKeyboardFocus

      public void setKeyboardFocus()
      Sets the keyboard focus, override in case you want to set the focus to a specific item.
    • getTitleTable

      public com.badlogic.gdx.scenes.scene2d.ui.Table getTitleTable()
    • hide

      public void hide(com.badlogic.gdx.scenes.scene2d.Action action)
      Hides the dialog with the given action and then removes it from the stage.
    • hide

      public void hide()
      Hides the dialog. Called automatically when a button is clicked. The default implementation fades out the dialog over 400 milliseconds and then removes it from the stage.
    • addSeparator

      public void addSeparator()
      Adds a horizontal separator to the main content table with the default colspan of 1.
    • addSeparator

      public void addSeparator(int colSpan)
      Adds a horizontal separator to the main content table with the given colspan.
      Parameters:
      colSpan - The column span to use.
    • setAcceptListener

      public void setAcceptListener(Runnable r)
      Sets a listener that runs when accept is clicked.
      Parameters:
      r - The listener.
    • hasAcceptRunnable

      public boolean hasAcceptRunnable()
    • setCancelListener

      public void setCancelListener(Runnable r)
      Sets a listener that runs when cancel is clicked.
      Parameters:
      r - The listener.
    • hasCancelRunnable

      public boolean hasCancelRunnable()
    • setCloseListener

      public void setCloseListener(Runnable r)
      Sets a listener that runs when the dialog is closed. It runs when either the accept or the cancel button is clicked.
      Parameters:
      r - The listener.
    • hasCloseRunnable

      public boolean hasCloseRunnable()
    • enableComponents

      protected void enableComponents(boolean enabled, com.badlogic.gdx.scenes.scene2d.utils.Disableable... components)
      Sets the enabled property on the given components.
      Parameters:
      enabled - The state to set.
      components - The components to enable or disable.
    • tabRight

      public boolean tabRight()
      Specified by:
      tabRight in interface IScreen
    • tabLeft

      public boolean tabLeft()
      Specified by:
      tabLeft in interface IScreen
    • focusFirstInputWidget

      public void focusFirstInputWidget()
    • getContent

      public com.badlogic.gdx.scenes.scene2d.ui.Table getContent()
    • getBottom

      public com.badlogic.gdx.scenes.scene2d.ui.Table getBottom()
    • getTabButtons

      public com.badlogic.gdx.utils.Array<com.badlogic.gdx.scenes.scene2d.ui.TextButton> getTabButtons()
    • dispose

      public abstract void dispose()
    • act

      public void act(float delta)
      Overrides:
      act in class com.badlogic.gdx.scenes.scene2d.Group
    • getStage

      public com.badlogic.gdx.scenes.scene2d.Stage getStage()
      Specified by:
      getStage in interface IScreen
      Overrides:
      getStage in class com.badlogic.gdx.scenes.scene2d.Actor
    • acceptButton

      public com.badlogic.gdx.scenes.scene2d.ui.Button acceptButton()
      Specified by:
      acceptButton in interface IScreen
    • cancelButton

      public com.badlogic.gdx.scenes.scene2d.ui.Button cancelButton()
      Specified by:
      cancelButton in interface IScreen