Package squidpony.squidgrid.gui.gdx
Class StarterKit
java.lang.Object
squidpony.squidgrid.gui.gdx.StarterKit
public class StarterKit extends Object
A convenience class that groups several commonly-used GUI classes into one object and provides ways to
initialize these kits for specific purposes, some of which would be a challenge to write without this code.
Created by Tommy Ettinger on 8/11/2016.
-
Field Summary
Fields Modifier and Type Field Description FilterBatch
batch
Used to draw lots of things, but mostly handled internally by the Stage.int
cellHeight
The height of a cell that holds one char, in "relative pixels," where the screen is expected to stretch so one relative pixel does not generally refer to one actual screen pixel (since high-DPI phones and laptops may make a single pixel virtually impossible to see with the naked eye).int
cellWidth
The width of a cell that holds one char, in "relative pixels," where the screen is expected to stretch so one relative pixel does not generally refer to one actual screen pixel (since high-DPI phones and laptops may make a single pixel virtually impossible to see with the naked eye).int
gridHeight
The number of grid spaces on the y axis.int
gridWidth
The number of grid spaces on the x axis.SparseLayers
layers
The main way to interact with a text-based grid as for roguelikes.GWTRNG
rng
Almost all of SquidLib comes into contact with randomness at some point, so this is a good place to show one way of handling that randomness.com.badlogic.gdx.scenes.scene2d.Stage
stage
All visible parts of this class are in the Stage, and if you add additional widget or scene2d.ui Actor values to your game, they should probably be added to this Stage.TextCellFactory
textFactory
One of the more critical parts of rendering text is what font to use, and textFactory should usually not be reassigned during a game because so many things depend on this value or a copy of it (so the change might not affect what it was expected to, and might break other things).com.badlogic.gdx.utils.viewport.Viewport
viewport
An important part of how this will be displayed; the viewport defaults to a displayed width ofcellWidth * gridWidth
and a displayed height ofcellHeight * gridHeight
, after cellWidth and cellHeight were doubled by default, and will be stretched or shrunk to fit the actual screen size. -
Constructor Summary
Constructors Constructor Description StarterKit(int gridWidth, int gridHeight, int cellWidth, int cellHeight)
Constructs a StarterKit with the given width and height in cells (gridWidth and gridHeight) and the given width and height for each letter (cellWidth and cellHeight), using a default font that is about half as wide as it is tall but can stretch to other aspect ratios.StarterKit(TextCellFactory textFactory, int gridWidth, int gridHeight, int cellWidth, int cellHeight)
Constructs a StarterKit with the given width and height in cells (gridWidth and gridHeight) and the given width and height for each letter (cellWidth and cellHeight), using the given TextCellFactory for the font.StarterKit(TextCellFactory textFactory, int gridWidth, int gridHeight, int cellWidth, int cellHeight, int additionalWidth, int additionalHeight)
Constructs a StarterKit with the given width and height in cells (gridWidth and gridHeight) and the given width and height for each letter (cellWidth and cellHeight), using the given TextCellFactory for the font; this overload also allows specifying additional space in pixels to be added to the right or bottom sides of the area with the grid of chars. -
Method Summary
Modifier and Type Method Description void
draw()
Not a complete drawing solution; so much of the logic related to drawing is specific to each game, like FOV being used to make certain things not render if they are out of sight, that this doesn't even try to guess at what a particular game needs for its rendering code.void
resize(int width, int height)
Not a complete resize method; this is meant to handle the resizing of this StarterKit only and should be called inside your main Game, ApplicationListener, etc.
-
Field Details
-
textFactory
One of the more critical parts of rendering text is what font to use, and textFactory should usually not be reassigned during a game because so many things depend on this value or a copy of it (so the change might not affect what it was expected to, and might break other things). -
layers
The main way to interact with a text-based grid as for roguelikes. A SquidLayers object stores a background and foreground SquidPanel, and this configures them as requested. -
gridWidth
The number of grid spaces on the x axis. -
gridHeight
The number of grid spaces on the y axis. -
cellWidth
The width of a cell that holds one char, in "relative pixels," where the screen is expected to stretch so one relative pixel does not generally refer to one actual screen pixel (since high-DPI phones and laptops may make a single pixel virtually impossible to see with the naked eye).
By default, this value is doubled to make stretching look more smooth. -
cellHeight
The height of a cell that holds one char, in "relative pixels," where the screen is expected to stretch so one relative pixel does not generally refer to one actual screen pixel (since high-DPI phones and laptops may make a single pixel virtually impossible to see with the naked eye).
By default, this value is doubled to make stretching look more smooth. -
stage
All visible parts of this class are in the Stage, and if you add additional widget or scene2d.ui Actor values to your game, they should probably be added to this Stage. -
batch
Used to draw lots of things, but mostly handled internally by the Stage. You may need to callbatch.begin()
andbatch.end()
in some cases where you want to render something that isn't a child of stage but is an Actor or similar render-able object. This can apply a filter fromFloatFilters
(or a customFloatFilter
) to all drawn colors. -
viewport
An important part of how this will be displayed; the viewport defaults to a displayed width ofcellWidth * gridWidth
and a displayed height ofcellHeight * gridHeight
, after cellWidth and cellHeight were doubled by default, and will be stretched or shrunk to fit the actual screen size. -
rng
Almost all of SquidLib comes into contact with randomness at some point, so this is a good place to show one way of handling that randomness. GWTRNG acts as a normal implementation ofIRNG
, can be "seeded" at the start to set the initial state, like any other RNG, but it can also have the current state acquired later withGWTRNG.getState()
or have the current state set in-place withGWTRNG.setState(long)
(note, this doesn't create a new RNG, like you would have to do to re-seed with java.util.Random). This can be useful to get a snapshot of the random sequence where you might want to take an action, undo it back to the snapshot, and try again. It can also be useful for saving the game and reloading it exactly, though the optional serialization in squidlib-extra also does this. You can pass a GWTRNG to anything that expects an IRNG, and you'll encounter a lot of methods that employ IRNG (and some that specifically require or preferIStatefulRNG
, which includes GWTRNG) throughout squidlib-util.
This field defaults to a GWTRNG seeded with the number SQUIDLIB (written in base 36), or 2252637788195L in base 10. Its algorithm can produce 2 to the 64 minus 1 numbers before repeating, and as the name might suggest, it should perform especially well on Google Web Toolkit for HTML deployment.
-
-
Constructor Details
-
StarterKit
Constructs a StarterKit with the given width and height in cells (gridWidth and gridHeight) and the given width and height for each letter (cellWidth and cellHeight), using a default font that is about half as wide as it is tall but can stretch to other aspect ratios.- Parameters:
gridWidth
- the width of the display area in cellsgridHeight
- the height of the display area in cellscellWidth
- the width of a single cell in pixels, before any stretching is appliedcellHeight
- the height of a single cell in pixels, before any stretching is applied
-
StarterKit
public StarterKit(TextCellFactory textFactory, int gridWidth, int gridHeight, int cellWidth, int cellHeight)Constructs a StarterKit with the given width and height in cells (gridWidth and gridHeight) and the given width and height for each letter (cellWidth and cellHeight), using the given TextCellFactory for the font. You can use any of the pre-constructed TextCellFactory objects inDefaultResources
, such asDefaultResources.getCrispLeanFamily()
,DefaultResources.getCrispDejaVuFont()
,DefaultResources.getCrispSlabFamily()
, orDefaultResources.getStretchableTypewriterFont()
, as long as you have the right assets available (their documentation says the exact files you need). While you can construct your own TextCellFactory given a BitmapFont, that won't work well as a distance field font unless you used some very unusual configuration making the font, so the font would only look good at one size or possibly a multiple of that size. The defaults are recommended for now; a separate project is used to make the distance field monospace fonts (tommyettinger/Glamer on GitHub) That project also serves as storage for fonts that were made with Glamer, and appropriately-licensed fonts are added to the "premade" folder once they are converted.
If you don't know what font to pick,DefaultResources.getCrispLeanFamily()
andDefaultResources.getCrispSlabFamily()
have the same (very large) character coverage, and have bold and italic modes that can be accessed withGDXMarkup
if you decide to use that later.- Parameters:
textFactory
- the TextCellFactory to use for the fontgridWidth
- the width of the display area in cellsgridHeight
- the height of the display area in cellscellWidth
- the width of a single cell in pixels, before any stretching is appliedcellHeight
- the height of a single cell in pixels, before any stretching is applied
-
StarterKit
public StarterKit(TextCellFactory textFactory, int gridWidth, int gridHeight, int cellWidth, int cellHeight, int additionalWidth, int additionalHeight)Constructs a StarterKit with the given width and height in cells (gridWidth and gridHeight) and the given width and height for each letter (cellWidth and cellHeight), using the given TextCellFactory for the font; this overload also allows specifying additional space in pixels to be added to the right or bottom sides of the area with the grid of chars. You can use any of the pre-constructed TextCellFactory objects inDefaultResources
, such asDefaultResources.getCrispLeanFamily()
DefaultResources.getCrispDejaVuFont()
,DefaultResources.getCrispSlabFamily()
, orDefaultResources.getStretchableTypewriterFont()
, as long as you have the right assets available (their documentation says the exact files you need). While you can construct your own TextCellFactory given a BitmapFont, that won't work well as a distance field font unless you used some very unusual configuration making the font, so the font would only look good at one size or possibly a multiple of that size. The defaults are recommended for now; a separate project is used to make the distance field monospace fonts (tommyettinger/Glamer on GitHub). That project also serves as storage for fonts that were made with Glamer, and appropriately-licensed fonts are added to the "premade" folder once they are converted.
If you don't know what font to pick,DefaultResources.getCrispLeanFamily()
andDefaultResources.getCrispSlabFamily()
have the same (very large) character coverage, and have bold and italic modes that can be accessed withGDXMarkup
if you decide to use that later.- Parameters:
textFactory
- the TextCellFactory to use for the fontgridWidth
- the width of the display area in cellsgridHeight
- the height of the display area in cellscellWidth
- the width of a single cell in pixels, before any stretching is appliedcellHeight
- the height of a single cell in pixels, before any stretching is appliedadditionalWidth
- the width in pixels to add to the stretched area, before any stretching is appliedadditionalHeight
- the height in pixels to add to the stretched area, before any stretching is applied
-
-
Method Details
-
draw
Not a complete drawing solution; so much of the logic related to drawing is specific to each game, like FOV being used to make certain things not render if they are out of sight, that this doesn't even try to guess at what a particular game needs for its rendering code. AnyTextCellFactory.Glyph
objects inlayers
will be rendered by that SparseLayers, but any that aren't stored in layers must be drawn separately (Glyph has aTextCellFactory.Glyph.draw(Batch, float)
method that must be called betweenBatch.begin()
andBatch.end()
, typically with begin() called before all Glyphs are drawn in a loop and then with end() called after).
Specifically, this applies the current viewport to the stage, draws the stage, and makes any actions or events related to the stage take effect. Should not be called inside aFilterBatch.begin()
block, since this calls it itself by drawing the stage, and also callsFilterBatch.end()
afterwards. -
resize
Not a complete resize method; this is meant to handle the resizing of this StarterKit only and should be called inside your main Game, ApplicationListener, etc. class' resize method.- Parameters:
width
- the new width of the screen; should be a parameter from the other resize() methodheight
- the new height of the screen; should be a parameter from the other resize() method
-