diff --git a/src/app/editor/message/message_data.cc b/src/app/editor/message/message_data.cc index bdd12b87..abcd6150 100644 --- a/src/app/editor/message/message_data.cc +++ b/src/app/editor/message/message_data.cc @@ -48,7 +48,10 @@ std::optional FindMatchingSpecial(uint8_t value) { ParsedElement FindMatchingElement(const std::string &str) { std::smatch match; - for (auto &text_element : TextCommands) { + std::vector commands_and_chars = TextCommands; + commands_and_chars.insert(commands_and_chars.end(), SpecialChars.begin(), + SpecialChars.end()); + for (auto &text_element : commands_and_chars) { match = text_element.MatchMe(str); if (match.size() > 0) { if (text_element.HasArgument) { @@ -104,7 +107,6 @@ std::vector ParseMessageToData(std::string str) { std::vector bytes; std::string temp_string = str; int pos = 0; - while (pos < temp_string.size()) { // Get next text fragment. if (temp_string[pos] == '[') { @@ -138,7 +140,6 @@ std::vector ParseMessageToData(std::string str) { uint8_t bb = FindMatchingCharacter(temp_string[pos++]); if (bb != 0xFF) { - util::logf("Error parsing message: %s", temp_string); bytes.push_back(bb); } } @@ -190,8 +191,8 @@ std::string ReplaceAllDictionaryWords(std::string str, return temp; } -DictionaryEntry FindRealDictionaryEntry(uint8_t value, - std::vector dictionary) { +DictionaryEntry FindRealDictionaryEntry( + uint8_t value, std::vector dictionary) { for (const auto &entry : dictionary) { if (entry.ID + DICTOFF == value) { return entry; diff --git a/src/app/editor/message/message_data.h b/src/app/editor/message/message_data.h index 227982da..43abd090 100644 --- a/src/app/editor/message/message_data.h +++ b/src/app/editor/message/message_data.h @@ -83,8 +83,8 @@ constexpr uint8_t kLine3 = 0x76; std::vector BuildDictionaryEntries(Rom *rom); std::string ReplaceAllDictionaryWords(std::string str, std::vector dictionary); -DictionaryEntry FindRealDictionaryEntry(uint8_t value, - std::vector dictionary); +DictionaryEntry FindRealDictionaryEntry( + uint8_t value, std::vector dictionary); // Inserted into commands to protect them from dictionary replacements. const std::string CHEESE = "\uBEBE"; @@ -119,10 +119,6 @@ struct MessageData { ContentsParsed = other.ContentsParsed; } - std::string ToString() const { - return absl::StrFormat("%0X - %s", ID, ContentsParsed); - } - std::string OptimizeMessageForDictionary( std::string message_string, const std::vector &dictionary) { @@ -197,10 +193,6 @@ struct TextElement { } } - std::string ToString() const { - return absl::StrFormat("%s %s", GenericToken, Description); - } - std::smatch MatchMe(std::string dfrag) const { std::regex pattern(StrictPattern); std::smatch match; diff --git a/src/app/editor/message/message_editor.cc b/src/app/editor/message/message_editor.cc index 36afb65e..0c3f964c 100644 --- a/src/app/editor/message/message_editor.cc +++ b/src/app/editor/message/message_editor.cc @@ -143,7 +143,10 @@ void MessageEditor::DrawCurrentMessage() { Button(absl::StrCat("Message ", current_message_.ID).c_str()); if (InputTextMultiline("##MessageEditor", &message_text_box_.text, ImVec2(ImGui::GetContentRegionAvail().x, 0))) { - current_message_.Data = ParseMessageToData(message_text_box_.text); + std::string temp = message_text_box_.text; + // Strip newline characters. + temp.erase(std::remove(temp.begin(), temp.end(), '\n'), temp.end()); + current_message_.Data = ParseMessageToData(temp); DrawMessagePreview(); } Separator(); @@ -159,7 +162,7 @@ void MessageEditor::DrawCurrentMessage() { ImGui::EndPopup(); } gui::BeginPadding(1); - BeginChild("CurrentGfxFont", ImVec2(344, 0), true, + BeginChild("CurrentGfxFont", ImVec2(348, 0), true, ImGuiWindowFlags_NoScrollWithMouse); current_font_gfx16_canvas_.DrawBackground(); gui::EndPadding(); @@ -202,13 +205,14 @@ void MessageEditor::DrawFontAtlas() { void MessageEditor::DrawExpandedMessageSettings() { ImGui::BeginChild("##ExpandedMessageSettings", ImVec2(0, 100), true, ImGuiWindowFlags_AlwaysVerticalScrollbar); - // Input for the address of the expanded messages - ImGui::InputText("Address", &expanded_message_address_, - ImGuiInputTextFlags_CharsHexadecimal); - + ImGui::Text("Expanded Messages"); + static std::string expanded_message_path = ""; if (ImGui::Button("Load Expanded Message")) { - // Load the expanded message from the address. - // TODO: Implement this. + expanded_message_path = core::FileDialogWrapper::ShowOpenFileDialog(); + if (!expanded_message_path.empty()) { + // Load the expanded message from the path. + // TODO: Implement this. + } } EndChild(); } @@ -217,9 +221,12 @@ void MessageEditor::DrawTextCommands() { ImGui::BeginChild("##TextCommands", ImVec2(0, ImGui::GetWindowContentRegionMax().y / 3), true, ImGuiWindowFlags_AlwaysVerticalScrollbar); + static uint8_t command_parameter = 0; + gui::InputHexByte("Command Parameter", &command_parameter); for (const auto& text_element : TextCommands) { if (Button(text_element.GenericToken.c_str())) { - message_text_box_.text.append(text_element.GenericToken); + message_text_box_.text.append( + text_element.GetParamToken(command_parameter)); } SameLine(); TextWrapped("%s", text_element.Description.c_str()); diff --git a/src/app/editor/message/message_editor.h b/src/app/editor/message/message_editor.h index d5d5e295..af529a04 100644 --- a/src/app/editor/message/message_editor.h +++ b/src/app/editor/message/message_editor.h @@ -62,16 +62,14 @@ class MessageEditor : public Editor { private: Rom* rom_; - bool data_loaded_ = false; bool case_sensitive_ = false; bool match_whole_word_ = false; - - std::string expanded_message_address_ = ""; std::string search_text_ = ""; std::array raw_font_gfx_data_; std::vector parsed_messages_; std::vector list_of_texts_; + std::vector expanded_messages_; MessageData current_message_; MessagePreview message_preview_; diff --git a/src/app/editor/message/message_preview.cc b/src/app/editor/message/message_preview.cc index 1796db83..275646f2 100644 --- a/src/app/editor/message/message_preview.cc +++ b/src/app/editor/message/message_preview.cc @@ -32,14 +32,16 @@ void MessagePreview::DrawTileToPreview(int x, int y, int srcx, int srcy, } } -void MessagePreview::DrawStringToPreview(std::string str) { - for (const auto c : str) { +void MessagePreview::DrawStringToPreview(const std::string& str) { + for (const auto& c : str) { DrawCharacterToPreview(c); } } void MessagePreview::DrawCharacterToPreview(char c) { - DrawCharacterToPreview(FindMatchingCharacter(c)); + std::vector text; + text.push_back(FindMatchingCharacter(c)); + DrawCharacterToPreview(text); } void MessagePreview::DrawCharacterToPreview(const std::vector& text) { @@ -87,7 +89,8 @@ void MessagePreview::DrawCharacterToPreview(const std::vector& text) { } else if (value == 0x6A) { // Includes parentheses to be longer, since player names can be up to 6 // characters. - DrawStringToPreview("(NAME)"); + const std::string name = "(NAME)"; + DrawStringToPreview(name); } else if (value >= DICTOFF && value < (DICTOFF + 97)) { int pos = value - DICTOFF; if (pos < 0 || pos >= all_dictionaries_.size()) { diff --git a/src/app/editor/message/message_preview.h b/src/app/editor/message/message_preview.h index 1ffd44f4..1efecbea 100644 --- a/src/app/editor/message/message_preview.h +++ b/src/app/editor/message/message_preview.h @@ -20,7 +20,7 @@ struct MessagePreview { void DrawTileToPreview(int x, int y, int srcx, int srcy, int pal, int sizex = 1, int sizey = 1); - void DrawStringToPreview(std::string str); + void DrawStringToPreview(const std::string& str); void DrawCharacterToPreview(char c); void DrawCharacterToPreview(const std::vector& text);