update message editor

This commit is contained in:
scawful
2024-07-24 00:42:16 -04:00
parent aec09fa8da
commit f150cc0bbc
2 changed files with 17 additions and 23 deletions

View File

@@ -180,7 +180,7 @@ void MessageEditor::DrawCurrentMessage() {
absl::Status MessageEditor::Initialize() { absl::Status MessageEditor::Initialize() {
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
widthArray[i] = rom()->data()[kCharactersWidth + i]; width_array[i] = rom()->data()[kCharactersWidth + i];
} }
previewColors.AddColor(0x7FFF); // White previewColors.AddColor(0x7FFF); // White
@@ -417,7 +417,7 @@ absl::Status MessageEditor::Save() {
std::vector<uint8_t> backup = rom()->vector(); std::vector<uint8_t> backup = rom()->vector();
for (int i = 0; i < 100; i++) { 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; 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. // Make sure we didn't go over the space available in the first block.
// 0x7FFF available. // 0x7FFF available.
if ((!inSecondBank & pos) > kTextDataEnd) { if ((!inSecondBank & pos) > kTextDataEnd) {
DisplayTextOverflowError(pos, true); return absl::InternalError(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.");
} }
// Switch to the second block. // 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. // Verify that we didn't go over the space available for the second block.
// 0x14BF available. // 0x14BF available.
if ((inSecondBank & pos) > kTextData2End) { if ((inSecondBank & pos) > kTextData2End) {
DisplayTextOverflowError(pos, false);
// rom()->data() = backup; // rom()->data() = backup;
// return true; return absl::InternalError(DisplayTextOverflowError(pos, false));
return absl::InternalError(
"Too much text data in the second block to save.");
} }
RETURN_IF_ERROR(rom()->Write(pos, 0xFF)); // , true, "End of text" 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( MessageEditor::DictionaryEntry MessageEditor::GetDictionaryFromID(
uint8_t value) { uint8_t value) {
// return AllDictionaries.First(dictionary = > dictionary.ID == value); if (value < 0 || value >= AllDictionaries.size()) {
return AllDictionaries[0]; return DictionaryEntry();
}
return AllDictionaries[value];
} }
uint8_t MessageEditor::FindDictionaryEntry(uint8_t value) { uint8_t MessageEditor::FindDictionaryEntry(uint8_t value) {
@@ -578,7 +573,7 @@ void MessageEditor::DrawCharacterToPreview(std::vector<uint8_t> text) {
DrawTileToPreview(text_pos, text_line * 16, srcx, srcy, 0, false, false, DrawTileToPreview(text_pos, text_line * 16, srcx, srcy, 0, false, false,
1, 2); 1, 2);
text_pos += widthArray[value]; text_pos += width_array[value];
} else if (value == 0x74) { } else if (value == 0x74) {
text_pos = 0; text_pos = 0;
text_line = 0; text_line = 0;
@@ -608,12 +603,8 @@ void MessageEditor::DrawCharacterToPreview(std::vector<uint8_t> text) {
// characters. // characters.
DrawStringToPreview("(NAME)"); DrawStringToPreview("(NAME)");
} else if (value >= DICTOFF && value < (DICTOFF + 97)) { } else if (value >= DICTOFF && value < (DICTOFF + 97)) {
// DictionaryEntry dictionaryEntry = auto dictionaryEntry = GetDictionaryFromID(value - DICTOFF);
// GetDictionaryFromID((uint8_t)(value - DICTOFF)); DrawCharacterToPreview(dictionaryEntry.Data);
// auto dictionaryEntry = GetDictionaryFromID(value - DICTOFF);
// if (dictionaryEntry != null) {
// 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; int space = bank ? kTextDataEnd - kTextData : kTextData2End - kTextData2;
string bankSTR = bank ? "1st" : "2nd"; string bankSTR = bank ? "1st" : "2nd";
string posSTR = bank ? absl::StrFormat("%X4", pos & 0xFFFF) 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" "There is too much text data in the %s block to save.\n"
"Available: %X4 | Used: %s", "Available: %X4 | Used: %s",
bankSTR, space, posSTR); bankSTR, space, posSTR);
return message;
} }
} // namespace editor } // namespace editor
} // namespace app } // namespace app
} // namespace yaze } // namespace yaze

View File

@@ -425,6 +425,7 @@ class MessageEditor : public Editor, public SharedRom {
int Length; int Length;
std::string Token; std::string Token;
DictionaryEntry() = default;
DictionaryEntry(uint8_t i, std::string s) DictionaryEntry(uint8_t i, std::string s)
: Contents(s), ID(i), Length(s.length()) { : Contents(s), ID(i), Length(s.length()) {
Token = absl::StrFormat("[%s:%00X]", DICTIONARYTOKEN, ID); Token = absl::StrFormat("[%s:%00X]", DICTIONARYTOKEN, ID);
@@ -490,11 +491,11 @@ class MessageEditor : public Editor, public SharedRom {
void DrawStringToPreview(string str); void DrawStringToPreview(string str);
void DrawMessagePreview(); void DrawMessagePreview();
void DisplayTextOverflowError(int pos, bool bank); std::string DisplayTextOverflowError(int pos, bool bank);
static const std::vector<DictionaryEntry> AllDicts; static const std::vector<DictionaryEntry> AllDicts;
uint8_t widthArray[100]; uint8_t width_array[100];
string romname = ""; string romname = "";
int text_line = 0; int text_line = 0;