6#include "absl/status/status.h"
7#include "absl/strings/str_cat.h"
8#include "absl/strings/str_format.h"
19#include "imgui/misc/cpp/imgui_stdlib.h"
28 std::string bankSTR = bank ?
"1st" :
"2nd";
30 bank ? absl::StrFormat(
"%X4", pos & 0xFFFF)
31 : absl::StrFormat(
"%X4", (pos -
kTextData2) & 0xFFFF);
32 std::string message = absl::StrFormat(
33 "There is too much text data in the %s block to save.\n"
34 "Available: %X4 | Used: %s",
35 bankSTR, space, posSTR);
42using ImGui::BeginChild;
43using ImGui::BeginTable;
47using ImGui::InputTextMultiline;
51using ImGui::Separator;
52using ImGui::TableHeadersRow;
53using ImGui::TableNextColumn;
54using ImGui::TableSetupColumn;
56using ImGui::TextWrapped;
59 ImGuiTableFlags_Borders |
60 ImGuiTableFlags_Resizable;
71 for (
int i = 0; i < 0x4000; i++) {
98 TableSetupColumn(
"List");
99 TableSetupColumn(
"Contents");
100 TableSetupColumn(
"Font Atlas");
101 TableSetupColumn(
"Commands");
121 return absl::OkStatus();
126 if (BeginChild(
"##MessagesList", ImVec2(0, 0),
true,
127 ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
130 TableSetupColumn(
"ID");
131 TableSetupColumn(
"Contents");
132 TableSetupColumn(
"Data");
152 PushID(expanded_message.ID + 0x18D);
153 if (Button(
util::HexWord(expanded_message.ID + 0x18D).c_str())) {
164 TextWrapped(
"%s",
util::HexLong(expanded_message.Address).c_str());
176 ImVec2(ImGui::GetContentRegionAvail().x, 0))) {
179 temp.erase(std::remove(temp.begin(), temp.end(),
'\n'), temp.end());
186 ImGui::BeginChild(
"##MessagePreview", ImVec2(0, 0),
true, 1);
187 Text(
"Message Preview");
188 if (Button(
"View Palette")) {
189 ImGui::OpenPopup(
"Palette");
191 if (ImGui::BeginPopup(
"Palette")) {
196 BeginChild(
"CurrentGfxFont", ImVec2(348, 0),
true,
197 ImGuiWindowFlags_NoScrollWithMouse);
203 if (ImGui::IsWindowHovered()) {
204 float wheel = ImGui::GetIO().MouseWheel;
207 }
else if (wheel < 0 &&
237 ImGui::BeginChild(
"##ExpandedMessageSettings", ImVec2(0, 100),
true,
238 ImGuiWindowFlags_AlwaysVerticalScrollbar);
239 ImGui::Text(
"Expanded Messages");
240 static std::string expanded_message_path =
"";
241 if (ImGui::Button(
"Load Expanded Message")) {
243 if (!expanded_message_path.empty()) {
248 context_->popup_manager->Show(
"Error");
254 ImGui::Text(
"Expanded Path: %s", expanded_message_path.c_str());
256 if (ImGui::Button(
"Add New Message")) {
263 if (ImGui::Button(
"Save Expanded Messages")) {
272 ImGui::BeginChild(
"##TextCommands",
273 ImVec2(0, ImGui::GetContentRegionAvail().y / 2),
true,
274 ImGuiWindowFlags_AlwaysVerticalScrollbar);
275 static uint8_t command_parameter = 0;
277 for (
const auto& text_element : TextCommands) {
278 if (Button(text_element.GenericToken.c_str())) {
280 text_element.GetParamToken(command_parameter));
283 TextWrapped(
"%s", text_element.Description.c_str());
290 ImGui::BeginChild(
"##SpecialChars",
291 ImVec2(0, ImGui::GetContentRegionAvail().y / 2),
true,
292 ImGuiWindowFlags_AlwaysVerticalScrollbar);
293 for (
const auto& text_element : SpecialChars) {
294 if (Button(text_element.GenericToken.c_str())) {
298 TextWrapped(
"%s", text_element.Description.c_str());
305 if (ImGui::BeginChild(
"##DictionaryChild",
306 ImVec2(0, ImGui::GetContentRegionAvail().y),
true,
307 ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
309 TableSetupColumn(
"ID");
310 TableSetupColumn(
"Contents");
316 Text(
"%s", dictionary.Contents.c_str());
339 std::vector<uint8_t> backup =
rom()->
vector();
347 bool in_second_bank =
false;
350 for (
const auto value : message.Data) {
357 return absl::InternalError(DisplayTextOverflowError(pos,
true));
362 in_second_bank =
true;
374 std::copy(backup.begin(), backup.end(),
rom()->mutable_data());
375 return absl::InternalError(DisplayTextOverflowError(pos,
false));
380 return absl::OkStatus();
385 std::copy(expanded_message.Data.begin(), expanded_message.Data.end(),
393 return absl::OkStatus();
402 return absl::OkStatus();
407 if (ImGui::GetClipboardText() !=
nullptr) {
411 return absl::OkStatus();
420 return absl::OkStatus();
432 return absl::OkStatus();
438 return absl::OkStatus();
461 if (ImGui::Begin(
"Find Text",
nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
462 static char find_text[256] =
"";
463 ImGui::InputText(
"Search", find_text, IM_ARRAYSIZE(find_text));
465 if (ImGui::Button(
"Find Next")) {
470 if (ImGui::Button(
"Find All")) {
475 if (ImGui::Button(
"Replace")) {
485 return absl::OkStatus();
auto palette_group() const
static std::string ShowOpenFileDialog()
ShowOpenFileDialog opens a file dialog and returns the selected filepath.
The Renderer class represents the renderer for the Yaze application.
void CreateAndRenderBitmap(int width, int height, int depth, const std::vector< uint8_t > &data, gfx::Bitmap &bitmap, gfx::SnesPalette &palette)
void UpdateBitmap(gfx::Bitmap *bitmap)
std::vector< std::string > parsed_messages_
absl::Status Copy() override
std::vector< MessageData > expanded_messages_
absl::Status Find() override
absl::Status SaveExpandedMessages()
absl::Status Update() override
void DrawExpandedMessageSettings()
absl::Status Paste() override
gui::Canvas current_font_gfx16_canvas_
gui::Canvas font_gfx_canvas_
absl::Status Undo() override
absl::Status Load() override
std::array< uint8_t, 0x4000 > raw_font_gfx_data_
void Initialize() override
absl::Status Cut() override
void DrawMessagePreview()
Rom expanded_message_bin_
std::vector< MessageData > list_of_texts_
gfx::SnesPalette font_preview_colors_
MessageData current_message_
MessagePreview message_preview_
gui::TextBox message_text_box_
void DrawCurrentMessage()
void DrawSpecialCharacters()
absl::Status Redo() override
gfx::Bitmap current_font_gfx16_bitmap_
gfx::Bitmap font_gfx_bitmap_
absl::Status Save() override
#define PRINT_IF_ERROR(expression)
#define RETURN_IF_ERROR(expression)
std::string DisplayTextOverflowError(int pos, bool bank)
Editors are the view controllers for the application.
constexpr int kCharactersWidth
std::vector< MessageData > ReadAllTextData(uint8_t *rom, int pos)
absl::Status LoadExpandedMessages(std::string &expanded_message_path, std::vector< std::string > &parsed_messages, std::vector< MessageData > &expanded_messages, std::vector< DictionaryEntry > &dictionary)
constexpr int kCurrentMessageWidth
constexpr int kCurrentMessageHeight
constexpr uint8_t kBlockTerminator
constexpr int kFontGfxMessageSize
std::vector< std::string > ParseMessageData(std::vector< MessageData > &message_data, const std::vector< DictionaryEntry > &dictionary_entries)
constexpr uint8_t kMessageTerminator
constexpr int kFontGfxMessageDepth
constexpr int kTextData2End
std::vector< DictionaryEntry > BuildDictionaryEntries(Rom *rom)
std::vector< uint8_t > ParseMessageToData(std::string str)
constexpr uint8_t kWidthArraySize
constexpr ImGuiTableFlags kMessageTableFlags
constexpr int kTextDataEnd
std::vector< uint8_t > SnesTo8bppSheet(std::span< uint8_t > sheet, int bpp, int num_sheets)
void EndCanvas(Canvas &canvas)
void BeginCanvas(Canvas &canvas, ImVec2 child_size)
void MemoryEditorPopup(const std::string &label, std::span< uint8_t > memory)
IMGUI_API bool DisplayPalette(gfx::SnesPalette &palette, bool loaded)
bool InputHexByte(const char *label, uint8_t *data, float input_width, bool no_step)
std::string HexWord(uint16_t word, HexStringParams params)
std::string HexLong(uint32_t dword, HexStringParams params)
Main namespace for the application.
absl::StatusOr< gfx::Bitmap > LoadFontGraphics(const Rom &rom)