6#include "absl/status/status.h"
7#include "absl/strings/str_cat.h"
8#include "absl/strings/str_format.h"
18#include "imgui/misc/cpp/imgui_stdlib.h"
27 std::string bankSTR = bank ?
"1st" :
"2nd";
29 bank ? absl::StrFormat(
"%X4", pos & 0xFFFF)
30 : absl::StrFormat(
"%X4", (pos -
kTextData2) & 0xFFFF);
31 std::string message = absl::StrFormat(
32 "There is too much text data in the %s block to save.\n"
33 "Available: %X4 | Used: %s",
34 bankSTR, space, posSTR);
41using ImGui::BeginChild;
42using ImGui::BeginTable;
46using ImGui::InputTextMultiline;
50using ImGui::Separator;
51using ImGui::TableHeadersRow;
52using ImGui::TableNextColumn;
53using ImGui::TableSetupColumn;
55using ImGui::TextWrapped;
58 ImGuiTableFlags_Borders |
59 ImGuiTableFlags_Resizable;
70 for (
int i = 0; i < 0x4000; i++) {
97 TableSetupColumn(
"List");
98 TableSetupColumn(
"Contents");
99 TableSetupColumn(
"Font Atlas");
100 TableSetupColumn(
"Commands");
120 return absl::OkStatus();
125 if (BeginChild(
"##MessagesList", ImVec2(0, 0),
true,
126 ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
129 TableSetupColumn(
"ID");
130 TableSetupColumn(
"Contents");
131 TableSetupColumn(
"Data");
151 PushID(expanded_message.ID + 0x18D);
152 if (Button(
util::HexWord(expanded_message.ID + 0x18D).c_str())) {
163 TextWrapped(
"%s",
util::HexLong(expanded_message.Address).c_str());
175 ImVec2(ImGui::GetContentRegionAvail().x, 0))) {
178 temp.erase(std::remove(temp.begin(), temp.end(),
'\n'), temp.end());
185 ImGui::BeginChild(
"##MessagePreview", ImVec2(0, 0),
true, 1);
186 Text(
"Message Preview");
187 if (Button(
"View Palette")) {
188 ImGui::OpenPopup(
"Palette");
190 if (ImGui::BeginPopup(
"Palette")) {
195 BeginChild(
"CurrentGfxFont", ImVec2(348, 0),
true,
196 ImGuiWindowFlags_NoScrollWithMouse);
202 if (ImGui::IsWindowHovered()) {
203 float wheel = ImGui::GetIO().MouseWheel;
206 }
else if (wheel < 0 &&
236 ImGui::BeginChild(
"##ExpandedMessageSettings", ImVec2(0, 100),
true,
237 ImGuiWindowFlags_AlwaysVerticalScrollbar);
238 ImGui::Text(
"Expanded Messages");
239 static std::string expanded_message_path =
"";
240 if (ImGui::Button(
"Load Expanded Message")) {
242 if (!expanded_message_path.empty()) {
244 static Rom expanded_message_rom;
245 if (!expanded_message_rom.
LoadFromFile(expanded_message_path,
false)
247 context_->popup_manager->Show(
"Error");
256 parsed_expanded_messages[expanded_message.ID]);
262 ImGui::Text(
"Expanded Path: %s", expanded_message_path.c_str());
264 if (ImGui::Button(
"Add New Message")) {
271 if (ImGui::Button(
"Save Expanded Messages")) {
280 ImGui::BeginChild(
"##TextCommands",
281 ImVec2(0, ImGui::GetContentRegionAvail().y / 2),
true,
282 ImGuiWindowFlags_AlwaysVerticalScrollbar);
283 static uint8_t command_parameter = 0;
285 for (
const auto& text_element : TextCommands) {
286 if (Button(text_element.GenericToken.c_str())) {
288 text_element.GetParamToken(command_parameter));
291 TextWrapped(
"%s", text_element.Description.c_str());
298 ImGui::BeginChild(
"##SpecialChars",
299 ImVec2(0, ImGui::GetContentRegionAvail().y / 2),
true,
300 ImGuiWindowFlags_AlwaysVerticalScrollbar);
301 for (
const auto& text_element : SpecialChars) {
302 if (Button(text_element.GenericToken.c_str())) {
306 TextWrapped(
"%s", text_element.Description.c_str());
313 if (ImGui::BeginChild(
"##DictionaryChild",
314 ImVec2(0, ImGui::GetContentRegionAvail().y),
true,
315 ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
317 TableSetupColumn(
"ID");
318 TableSetupColumn(
"Contents");
324 Text(
"%s", dictionary.Contents.c_str());
347 std::vector<uint8_t> backup =
rom()->
vector();
355 bool in_second_bank =
false;
358 for (
const auto value : message.Data) {
365 return absl::InternalError(DisplayTextOverflowError(pos,
true));
370 in_second_bank =
true;
382 std::copy(backup.begin(), backup.end(),
rom()->mutable_data());
383 return absl::InternalError(DisplayTextOverflowError(pos,
false));
388 return absl::OkStatus();
393 std::copy(expanded_message.Data.begin(), expanded_message.Data.end(),
401 return absl::OkStatus();
410 return absl::OkStatus();
415 if (ImGui::GetClipboardText() !=
nullptr) {
419 return absl::OkStatus();
428 return absl::OkStatus();
440 return absl::OkStatus();
446 return absl::OkStatus();
469 if (ImGui::Begin(
"Find Text",
nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
470 static char find_text[256] =
"";
471 ImGui::InputText(
"Search", find_text, IM_ARRAYSIZE(find_text));
473 if (ImGui::Button(
"Find Next")) {
478 if (ImGui::Button(
"Find All")) {
483 if (ImGui::Button(
"Replace")) {
493 return absl::OkStatus();
The Rom class is used to load, save, and modify Rom data.
absl::Status LoadFromFile(const std::string &filename, bool z3_load=true)
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)
const uint8_t kMessageTerminator
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 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)