mirror of https://github.com/OpenRCT2/OpenRCT2.git
Create progress bar widget
This commit is contained in:
parent
eaba5f356c
commit
ae88b7b0fc
|
@ -1067,6 +1067,7 @@ static void InputWidgetLeft(const ScreenCoordsXY& screenCoords, WindowBase* w, W
|
|||
case WindowWidgetType::LabelCentred:
|
||||
case WindowWidgetType::Label:
|
||||
case WindowWidgetType::Groupbox:
|
||||
case WindowWidgetType::ProgressBar:
|
||||
case WindowWidgetType::Placeholder:
|
||||
case WindowWidgetType::Last:
|
||||
// Non-interactive widget type
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include <cmath>
|
||||
#include <openrct2/Context.h>
|
||||
#include <openrct2/Game.h>
|
||||
#include <openrct2/Input.h>
|
||||
#include <openrct2/config/Config.h>
|
||||
#include <openrct2/drawing/Text.h>
|
||||
|
@ -32,6 +33,7 @@ static void WidgetTextCentred(DrawPixelInfo& dpi, WindowBase& w, WidgetIndex wid
|
|||
static void WidgetText(DrawPixelInfo& dpi, WindowBase& w, WidgetIndex widgetIndex);
|
||||
static void WidgetTextInset(DrawPixelInfo& dpi, WindowBase& w, WidgetIndex widgetIndex);
|
||||
static void WidgetTextBoxDraw(DrawPixelInfo& dpi, WindowBase& w, WidgetIndex widgetIndex);
|
||||
static void WidgetProgressBarDraw(DrawPixelInfo& dpi, WindowBase& w, WidgetIndex widgetIndex);
|
||||
static void WidgetGroupboxDraw(DrawPixelInfo& dpi, WindowBase& w, WidgetIndex widgetIndex);
|
||||
static void WidgetCaptionDraw(DrawPixelInfo& dpi, WindowBase& w, WidgetIndex widgetIndex);
|
||||
static void WidgetCheckboxDraw(DrawPixelInfo& dpi, WindowBase& w, WidgetIndex widgetIndex);
|
||||
|
@ -108,6 +110,9 @@ void WidgetDraw(DrawPixelInfo& dpi, WindowBase& w, WidgetIndex widgetIndex)
|
|||
case WindowWidgetType::TextBox:
|
||||
WidgetTextBoxDraw(dpi, w, widgetIndex);
|
||||
break;
|
||||
case WindowWidgetType::ProgressBar:
|
||||
WidgetProgressBarDraw(dpi, w, widgetIndex);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -1189,6 +1194,37 @@ static void WidgetTextBoxDraw(DrawPixelInfo& dpi, WindowBase& w, WidgetIndex wid
|
|||
}
|
||||
}
|
||||
|
||||
static void WidgetProgressBarDraw(DrawPixelInfo& dpi, WindowBase& w, WidgetIndex widgetIndex)
|
||||
{
|
||||
const auto& widget = w.widgets[widgetIndex];
|
||||
|
||||
ScreenCoordsXY topLeft{ w.windowPos + ScreenCoordsXY{ widget.left, widget.top } };
|
||||
ScreenCoordsXY bottomRight{ w.windowPos + ScreenCoordsXY{ widget.right, widget.bottom } };
|
||||
|
||||
auto percentage = widget.content & 0xFF;
|
||||
auto lowerBlinkBounds = (widget.content >> 8) & 0xFF;
|
||||
auto upperBlinkBounds = (widget.content >> 16) & 0xFF;
|
||||
|
||||
auto isBlinking = (lowerBlinkBounds != upperBlinkBounds) && (percentage >= lowerBlinkBounds)
|
||||
&& (percentage <= upperBlinkBounds);
|
||||
|
||||
GfxFillRectInset(dpi, { topLeft, bottomRight }, w.colours[1], INSET_RECT_F_30);
|
||||
if (isBlinking)
|
||||
{
|
||||
if (GameIsNotPaused() && (gCurrentRealTimeTicks & 8))
|
||||
return;
|
||||
}
|
||||
|
||||
const auto barWidth = widget.width() - 2;
|
||||
const int32_t fillSize = (barWidth * percentage) / 100;
|
||||
if (fillSize > 0)
|
||||
{
|
||||
GfxFillRectInset(
|
||||
dpi, { topLeft + ScreenCoordsXY{ 1, 1 }, topLeft + ScreenCoordsXY{ fillSize + 1, widget.height() - 1 } },
|
||||
widget.colour, 0);
|
||||
}
|
||||
}
|
||||
|
||||
ImageId GetColourButtonImage(colour_t colour)
|
||||
{
|
||||
if (colour == COLOUR_INVISIBLE)
|
||||
|
@ -1200,3 +1236,9 @@ ImageId GetColourButtonImage(colour_t colour)
|
|||
return ImageId(SPR_PALETTE_BTN, colour).WithBlended(true);
|
||||
}
|
||||
}
|
||||
|
||||
void WidgetProgressBarSetNewPercentage(Widget& widget, uint8_t newPercentage)
|
||||
{
|
||||
widget.content &= ~0xFF;
|
||||
widget.content |= newPercentage;
|
||||
}
|
||||
|
|
|
@ -85,6 +85,23 @@ constexpr Widget MakeTab(const ScreenCoordsXY& origin, StringId tooltip = STR_NO
|
|||
return MakeWidget(origin, size, type, colour, content, tooltip);
|
||||
}
|
||||
|
||||
constexpr Widget MakeProgressBar(
|
||||
const ScreenCoordsXY& origin, const ScreenSize& size, colour_t colour, uint8_t lowerBlinkBound = 0,
|
||||
uint8_t upperBlinkBound = 0)
|
||||
{
|
||||
Widget out = {};
|
||||
out.left = origin.x;
|
||||
out.right = origin.x + size.width - 1;
|
||||
out.top = origin.y;
|
||||
out.bottom = origin.y + size.height - 1;
|
||||
out.type = WindowWidgetType::ProgressBar;
|
||||
out.colour = colour;
|
||||
out.content = 0 | (lowerBlinkBound << 8) | (upperBlinkBound << 16);
|
||||
out.tooltip = STR_NONE;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// NOLINTBEGIN
|
||||
#define MakeSpinnerWidgets(...) \
|
||||
MakeWidget(__VA_ARGS__), MakeSpinnerIncreaseWidget(__VA_ARGS__), MakeSpinnerDecreaseWidget(__VA_ARGS__)
|
||||
|
@ -154,3 +171,5 @@ void WidgetSetHoldable(WindowBase& w, WidgetIndex widgetIndex, bool value);
|
|||
void WidgetSetVisible(WindowBase& w, WidgetIndex widgetIndex, bool value);
|
||||
void WidgetSetPressed(WindowBase& w, WidgetIndex widgetIndex, bool value);
|
||||
void WidgetSetCheckboxValue(WindowBase& w, WidgetIndex widgetIndex, bool value);
|
||||
|
||||
void WidgetProgressBarSetNewPercentage(Widget& widget, uint8_t newPercentage);
|
||||
|
|
|
@ -112,6 +112,8 @@ namespace OpenRCT2::Scripting
|
|||
return "empty";
|
||||
case WindowWidgetType::Placeholder:
|
||||
return "placeholder";
|
||||
case WindowWidgetType::ProgressBar:
|
||||
return "progress_bar";
|
||||
case WindowWidgetType::Custom:
|
||||
return "custom";
|
||||
case WindowWidgetType::Last:
|
||||
|
|
|
@ -38,6 +38,7 @@ enum class WindowWidgetType : uint8_t
|
|||
Scroll = 22,
|
||||
Checkbox = 23,
|
||||
Placeholder = 25,
|
||||
ProgressBar = 29,
|
||||
Custom = 28,
|
||||
TextBox = 27,
|
||||
Last = 26,
|
||||
|
|
Loading…
Reference in New Issue