PokeMe64/include/widget/DialogWidget.h
Philippe Symons e51726eef9 Initial import of the first (extremely early) functional version.
It doesn't look like much, but it's functional ;-)

It can inject distribution pokémon into gen 1 and gen 2 original
cartridges and inject the GS ball in Pokémon Crystal.

That's it. But that was the minimal feature set I had in mind for the
project. In the Readme.md you can find the ideas I have for expanding
the project.

But the first priority is the UI, because it really looks bad right now.
(as I was mostly focused on building blocks and transfer pak
functionality. Not on making it looks good)
2024-07-19 21:46:11 +02:00

118 lines
3.8 KiB
C++
Executable File

#ifndef _DIALOGWIDGET_H
#define _DIALOGWIDGET_H
#include "widget/IWidget.h"
#include "core/Sprite.h"
#include "core/RDPQGraphics.h"
#define DIALOG_TEXT_SIZE 512
class AnimationManager;
typedef struct DialogData
{
char text[DIALOG_TEXT_SIZE];
// optional sprite of a character that is saying the dialog text
sprite_t* characterSprite;
SpriteRenderSettings characterSpriteSettings;
// bounds of the character sprite relative to the widget
Rectangle characterSpriteBounds;
bool characterSpriteVisible;
sprite_t* buttonSprite;
SpriteRenderSettings buttonSpriteSettings;
// bounds of the button sprite relative to the widget
Rectangle buttonSpriteBounds;
bool buttonSpriteVisible;
// The next Dialog
struct DialogData* next;
bool shouldReleaseWhenDone;
bool userAdvanceBlocked;
//TODO: dialog sound
} DialogData;
typedef struct DialogWidgetStyle
{
sprite_t* backgroundSprite;
SpriteRenderSettings backgroundSpriteSettings;
TextRenderSettings textSettings;
int marginLeft;
int marginRight;
int marginTop;
int marginBottom;
} DialogWidgetStyle;
/**
* This widget is used to display dialog text (usually at the bottom of the screen)
* You can specify a dialog sequence with the DialogData struct to be shown to the user.
*
* When the dialog has finished (after the user presses A when the last DialogData entry was shown)
* the onDialogFinished callback function (if any) will be triggered.
*
* If you press the A button, the DialogWidget advances to the next DialogData entry (if any)
* or (like I said before) triggers the onDialogFinished callback.
*/
class DialogWidget : public IWidget
{
public:
DialogWidget(AnimationManager& animationManager);
virtual ~DialogWidget();
const DialogWidgetStyle& getStyle() const;
void setStyle(const DialogWidgetStyle& style);
void setData(DialogData* data);
void appendDialogData(DialogData* data);
bool isFocused() const override;
void setFocused(bool isFocused) override;
bool isVisible() const override;
void setVisible(bool visible) override;
Rectangle getBounds() const override;
void setBounds(const Rectangle& bounds) override;
Dimensions getSize() const override;
/**
* @brief Sets a callback function that will be called when we run out of dialog
*/
void setOnDialogFinishedCallback(void (*onDialogFinishedCb)(void*), void* context);
/**
* @brief Advances the current dialog -> the next DialogData entry (if any) will be shown
* or the onDialogFinished callback will be triggered
*/
void advanceDialog();
bool handleUserInput(const joypad_inputs_t& userInput) override;
void render(RDPQGraphics& gfx, const Rectangle& parentBounds) override;
protected:
private:
/**
* @brief Indicates if the user is allowed to advance the dialog (yet)
* This could be used -for example- to restrict advancing until after a certain amount of time
* For example: waiting until a sound has played. (not implemented yet though)
*/
bool isAdvanceAllowed() const;
AnimationManager& animationManager_;
Rectangle bounds_;
DialogWidgetStyle style_;
DialogData* data_;
void (*onDialogFinishedCb_)(void*);
void *onDialogFinishedCbContext_;
bool focused_;
bool visible_;
bool btnAPressedOnPrevCheck_;
};
/**
* @brief This function sets the text field of the DialogData struct with snprintf
*
* @param data the DialogData struct to fill
* @param format the printf format string
* @param ... variable arguments to use within the snprintf call
*/
void setDialogDataText(DialogData& data, const char* format, ...);
#endif