readme
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
#ifndef STAT_BAR_CLASS
|
||||
#define STAT_BAR_CLASS
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
class Font;
|
||||
class Box;
|
||||
class ImageBox;
|
||||
class TextBox;
|
||||
class Texture;
|
||||
|
||||
// A labelled bar for something like health or stamina, the label sitting just above it
|
||||
class StatBar {
|
||||
public:
|
||||
struct Style {
|
||||
glm::vec3 fillColor = glm::vec3(1.0f);
|
||||
glm::vec3 lowColor = glm::vec3(1.0f); // what the fill turns as it runs low
|
||||
float lowFraction = 0.3f; // starts turning below this much of full
|
||||
float width = 300.0f;
|
||||
float height = 16.0f;
|
||||
bool showLoss = true; // sudden drops flash and linger before draining, for hits
|
||||
float labelSize = 0.4f; // font size of the label
|
||||
|
||||
// With these it's drawn from images instead: fillImage cropped to how full it is, darkened underneath for
|
||||
// the empty part, and frameImage over the top. Both stretch to width by height. Colors only tint the fill.
|
||||
Texture* fillImage = nullptr;
|
||||
Texture* frameImage = nullptr;
|
||||
};
|
||||
|
||||
// Makes its GUI, and GUI draws in the order it was made, so make this before whatever should cover it
|
||||
StatBar(Font* font, const Style& style);
|
||||
|
||||
// Once a frame, dt in real time. position is the top left of the label in pixels.
|
||||
// reset jumps straight to fraction without showing a loss, like when it starts showing someone else.
|
||||
// dimmed greys the fill out, for when it can't be used right now.
|
||||
void Update(float dt, float opacity, float fraction, const std::string& text, const glm::vec2& position,
|
||||
bool reset = false, bool dimmed = false);
|
||||
|
||||
// The label and the bar together, in pixels
|
||||
float GetHeight() const;
|
||||
float GetWidth() const { return style.width; }
|
||||
|
||||
private:
|
||||
Style style;
|
||||
Box* background = nullptr;
|
||||
Box* trail = nullptr;
|
||||
Box* fill = nullptr;
|
||||
ImageBox* frame = nullptr; // only drawn from images
|
||||
TextBox* label = nullptr;
|
||||
|
||||
float fraction = 1.0f;
|
||||
float trailFraction = 1.0f;
|
||||
float trailWait = 0.0f; // how long until the trail starts draining
|
||||
float flash = 0.0f; // 1 just after a sudden drop, fades to 0
|
||||
float dim = 0.0f; // eased toward dimmed
|
||||
|
||||
bool Images() const { return style.fillImage != nullptr; }
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user