From f150cc0bbca2c09c93164253d0740809be812001 Mon Sep 17 00:00:00 2001 From: scawful Date: Wed, 24 Jul 2024 00:42:16 -0400 Subject: [PATCH] update message editor --- src/app/editor/message/message_editor.cc | 35 ++++++++++-------------- src/app/editor/message/message_editor.h | 5 ++-- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/app/editor/message/message_editor.cc b/src/app/editor/message/message_editor.cc index 3ad74433..3ca0e7b3 100644 --- a/src/app/editor/message/message_editor.cc +++ b/src/app/editor/message/message_editor.cc @@ -180,7 +180,7 @@ void MessageEditor::DrawCurrentMessage() { absl::Status MessageEditor::Initialize() { for (int i = 0; i < 100; i++) { - widthArray[i] = rom()->data()[kCharactersWidth + i]; + width_array[i] = rom()->data()[kCharactersWidth + i]; } previewColors.AddColor(0x7FFF); // White @@ -417,7 +417,7 @@ absl::Status MessageEditor::Save() { std::vector backup = rom()->vector(); for (int i = 0; i < 100; i++) { - RETURN_IF_ERROR(rom()->Write(kCharactersWidth + i, widthArray[i])); + RETURN_IF_ERROR(rom()->Write(kCharactersWidth + i, width_array[i])); } int pos = kTextData; @@ -434,11 +434,7 @@ absl::Status MessageEditor::Save() { // Make sure we didn't go over the space available in the first block. // 0x7FFF available. if ((!inSecondBank & pos) > kTextDataEnd) { - DisplayTextOverflowError(pos, true); - // *rom()->data() = backup.data(); - // rom()->data() = (uint8_t[])backup.Clone(); - return absl::InternalError( - "Too much text data in the first block to save."); + return absl::InternalError(DisplayTextOverflowError(pos, true)); } // Switch to the second block. @@ -456,11 +452,8 @@ absl::Status MessageEditor::Save() { // Verify that we didn't go over the space available for the second block. // 0x14BF available. if ((inSecondBank & pos) > kTextData2End) { - DisplayTextOverflowError(pos, false); // rom()->data() = backup; - // return true; - return absl::InternalError( - "Too much text data in the second block to save."); + return absl::InternalError(DisplayTextOverflowError(pos, false)); } RETURN_IF_ERROR(rom()->Write(pos, 0xFF)); // , true, "End of text" @@ -492,8 +485,10 @@ TextElement MessageEditor::FindMatchingSpecial(uint8_t value) { MessageEditor::DictionaryEntry MessageEditor::GetDictionaryFromID( uint8_t value) { - // return AllDictionaries.First(dictionary = > dictionary.ID == value); - return AllDictionaries[0]; + if (value < 0 || value >= AllDictionaries.size()) { + return DictionaryEntry(); + } + return AllDictionaries[value]; } uint8_t MessageEditor::FindDictionaryEntry(uint8_t value) { @@ -578,7 +573,7 @@ void MessageEditor::DrawCharacterToPreview(std::vector text) { DrawTileToPreview(text_pos, text_line * 16, srcx, srcy, 0, false, false, 1, 2); - text_pos += widthArray[value]; + text_pos += width_array[value]; } else if (value == 0x74) { text_pos = 0; text_line = 0; @@ -608,12 +603,8 @@ void MessageEditor::DrawCharacterToPreview(std::vector text) { // characters. DrawStringToPreview("(NAME)"); } else if (value >= DICTOFF && value < (DICTOFF + 97)) { - // DictionaryEntry dictionaryEntry = - // GetDictionaryFromID((uint8_t)(value - DICTOFF)); - // auto dictionaryEntry = GetDictionaryFromID(value - DICTOFF); - // if (dictionaryEntry != null) { - // DrawCharacterToPreview(dictionaryEntry.Data); - // } + auto dictionaryEntry = GetDictionaryFromID(value - DICTOFF); + DrawCharacterToPreview(dictionaryEntry.Data); } } } @@ -662,7 +653,7 @@ void MessageEditor::DrawTileToPreview(int x, int y, int srcx, int srcy, int pal, } } -void MessageEditor::DisplayTextOverflowError(int pos, bool bank) { +std::string MessageEditor::DisplayTextOverflowError(int pos, bool bank) { int space = bank ? kTextDataEnd - kTextData : kTextData2End - kTextData2; string bankSTR = bank ? "1st" : "2nd"; string posSTR = bank ? absl::StrFormat("%X4", pos & 0xFFFF) @@ -671,8 +662,10 @@ void MessageEditor::DisplayTextOverflowError(int pos, bool bank) { "There is too much text data in the %s block to save.\n" "Available: %X4 | Used: %s", bankSTR, space, posSTR); + return message; } + } // namespace editor } // namespace app } // namespace yaze diff --git a/src/app/editor/message/message_editor.h b/src/app/editor/message/message_editor.h index c7a457dd..f5414075 100644 --- a/src/app/editor/message/message_editor.h +++ b/src/app/editor/message/message_editor.h @@ -425,6 +425,7 @@ class MessageEditor : public Editor, public SharedRom { int Length; std::string Token; + DictionaryEntry() = default; DictionaryEntry(uint8_t i, std::string s) : Contents(s), ID(i), Length(s.length()) { Token = absl::StrFormat("[%s:%00X]", DICTIONARYTOKEN, ID); @@ -490,11 +491,11 @@ class MessageEditor : public Editor, public SharedRom { void DrawStringToPreview(string str); void DrawMessagePreview(); - void DisplayTextOverflowError(int pos, bool bank); + std::string DisplayTextOverflowError(int pos, bool bank); static const std::vector AllDicts; - uint8_t widthArray[100]; + uint8_t width_array[100]; string romname = ""; int text_line = 0;