Poke_Transporter_GB/include/dbg/debug_menu.h
Philippe Symons 1d57c10333 Replace text_data_table with FileContainerReader
text_data_table was very similar in concept to FileContainerReader.

But FileContainerReader is generally more flexible, as it allows you to split up your table into several chunks.
This takes away the worry of these files getting too big to compress.

However, we now have a maintenance duty for the text_tables file, which maps a table index to the list of chunks.

We also need to be careful about every use of FileContainerReader::getPointerToFileInDecompressionBuffer().

Using it is fine when you're dealing with a single chunk or if you're sure the file doesn't span multiple chunks.
But the moment you seek to a different chunk, any pointer obtained from getPointerToFileInDecompressionBuffer()
becomes stale as the decompression buffer gets overwritten.

Still, this function is necessary for high memory pressure situations, such as mystery_gift_builder, because we can't maintain
multiple lineBuffers there.
2026-05-20 13:31:28 +02:00

104 lines
3.1 KiB
C++

#ifndef _DEBUG_MENU_H
#define _DEBUG_MENU_H
#include "vertical_menu.h"
// This file contains the implementation of the debug menu.
// But it doesn't actually define the entries or callback functions.
// For the menu entries, check debug_menu_entries.cpp
// For the callback functions, check debug_menu_functions.cpp
typedef void (*on_execute_callback)(void *context, unsigned user_param);
/**
* @brief This struct represents the metadata associated to a single toggle option of a single row in the debug menu.
*/
typedef struct option_data
{
const char *text;
unsigned value;
} option_data;
/**
* @brief This struct represents a single row in the debug menu. Each row has a label and a set of options.
*
*/
typedef struct debug_menu_row_data
{
/**
* @brief a charset with which to render the text in this row.
*/
const u16 *charset;
/**
* @brief The text to be shown. This is just a plain old C string,
* because we don't need translations in the debug menu.
*/
const char *labelText;
/**
* @brief Toggle options below (optional):
*/
struct {
/**
* @brief Number of options. If this is 0, then this row will just be a label with no options to select.
*/
u8 num_options;
/**
* @brief The actual array of options alongside their values.
* Note: if you want the widget to free() the array when the widget is getting destroyed,
* set the should_free_on_destruct flag.
*/
const option_data *options;
/**
* @brief This callback will be fired when the user selects an option. (just with LEFT/RIGHT)
*/
on_execute_callback on_option_activate;
/**
* @brief The initial selected option index.
* But this field will get maintained by the widget to track the current selected index.
*/
u8 selected_option_index;
/**
* @brief This flag indicates whether the widget should call free() on the options pointer when the widget is getting destroyed.
*/
bool should_free_on_destruct;
} option_section;
/**
* @brief A callback that you can set to execute when the user selects this row and presses the A button. (optional)
*/
on_execute_callback on_execute;
/**
* @brief Context for the on_option-activate and on_execute callbacks. (optional)
*/
void *context;
/**
* @brief This user_param will be passed as an argument to the on_execute callback. (optional)
*/
unsigned user_param;
} debug_menu_row_data;
/**
* @brief This class is responsible for rendering and handling input for a single row in the vertical_menu based
* debug menu.
*/
class debug_menu_row_widget : public i_item_widget
{
public:
debug_menu_row_widget(const debug_menu_row_data &data);
virtual ~debug_menu_row_widget();
void render_item(FileContainerReader &text_table, unsigned x, unsigned y, bool is_focused) override;
MenuInputHandleState handle_input() override;
protected:
private:
debug_menu_row_data data_;
};
void show_debug_menu();
#endif