Add AssOverrideBlockComment

Nothing actually wants to treat comments as plain text, so using the
same type for both just makes things more complex.
This commit is contained in:
Thomas Goyne 2012-12-30 09:04:43 -08:00
parent 1f1cb36b6d
commit 8f765f3955
8 changed files with 26 additions and 37 deletions

View File

@ -216,8 +216,7 @@ std::auto_ptr<boost::ptr_vector<AssDialogueBlock>> AssDialogue::ParseTags() cons
if (work.size() && work.find('\\') == std::string::npos) {
//We've found an override block with no backslashes
//We're going to assume it's a comment and not consider it an override block
//Currently we'll treat this as a plain text block, but feel free to create a new class
Blocks.push_back(new AssDialogueBlockPlain("{" + work + "}"));
Blocks.push_back(new AssDialogueBlockComment(work));
}
else {
// Create block

View File

@ -45,6 +45,7 @@
enum AssBlockType {
BLOCK_BASE,
BLOCK_PLAIN,
BLOCK_COMMENT,
BLOCK_OVERRIDE,
BLOCK_DRAWING
};
@ -89,6 +90,12 @@ public:
AssDialogueBlockPlain(std::string const& text = std::string()) : AssDialogueBlock(text) { }
};
class AssDialogueBlockComment : public AssDialogueBlock {
public:
AssBlockType GetType() const override { return BLOCK_COMMENT; }
AssDialogueBlockComment(std::string const& text = std::string()) : AssDialogueBlock("{" + text + "}") { }
};
class AssDialogueBlockDrawing : public AssDialogueBlock {
public:
int Scale;

View File

@ -109,18 +109,14 @@ void AssKaraoke::ParseSyllables(AssDialogue *line, Syllable &syl) {
for (auto& block : blocks) {
std::string text = block.GetText();
if (dynamic_cast<AssDialogueBlockPlain*>(&block)) {
// treat comments as overrides rather than dialogue
if (boost::starts_with(text, "{"))
syl.ovr_tags[syl.text.size()] += text;
else
syl.text += text;
}
else if (dynamic_cast<AssDialogueBlockDrawing*>(&block)) {
if (dynamic_cast<AssDialogueBlockPlain*>(&block))
syl.text += text;
else if (dynamic_cast<AssDialogueBlockComment*>(&block))
syl.ovr_tags[syl.text.size()] += text;
else if (dynamic_cast<AssDialogueBlockDrawing*>(&block))
// drawings aren't override tags but they shouldn't show up in the
// stripped text so pretend they are
syl.ovr_tags[syl.text.size()] += text;
}
else if (AssDialogueBlockOverride *ovr = dynamic_cast<AssDialogueBlockOverride*>(&block)) {
bool in_tag = false;
for (auto& tag : ovr->Tags) {

View File

@ -205,15 +205,13 @@ void set_tag(AssDialogue *line, boost::ptr_vector<AssDialogueBlock> &blocks, std
AssDialogueBlock *block = &blocks[blockn];
if (dynamic_cast<AssDialogueBlockDrawing*>(block))
--blockn;
else if ((plain = dynamic_cast<AssDialogueBlockPlain*>(block))) {
else if (dynamic_cast<AssDialogueBlockComment*>(block)) {
// Cursor is in a comment block, so try the previous block instead
if (boost::starts_with(plain->GetText(), "{")) {
--blockn;
start = line->Text.get().rfind('{', start);
}
else
break;
--blockn;
start = line->Text.get().rfind('{', start);
}
else if ((plain = dynamic_cast<AssDialogueBlockPlain*>(block)))
break;
else {
ovr = dynamic_cast<AssDialogueBlockOverride*>(block);
assert(ovr);

View File

@ -55,11 +55,7 @@ static void add_hotkey(wxSizer *sizer, wxWindow *parent, const char *command, wx
// Skip over override blocks, comments, and whitespace between blocks
static bool bad_block(AssDialogueBlock &block) {
if (block.GetType() != BLOCK_PLAIN) return true;
std::string text = block.GetText();
if (boost::all(text, boost::is_space())) return true;
if (boost::starts_with(text, "{") && boost::ends_with(text, "}")) return true;
return false;
return block.GetType() != BLOCK_PLAIN || boost::all(block.GetText(), boost::is_space());
}
DialogTranslation::DialogTranslation(agi::Context *c)
@ -256,7 +252,7 @@ void DialogTranslation::UpdateDisplay() {
original_text->SetUnicodeStyling(cur_size, block.GetText().size(), 1);
}
}
else if (block.GetType() == BLOCK_OVERRIDE)
else
original_text->AppendTextRaw(block.GetText().c_str());
++i;
}

View File

@ -80,7 +80,7 @@ void FontCollector::ProcessDialogueLine(const AssDialogue *line, int index) {
else if (AssDialogueBlockPlain *txt = dynamic_cast<AssDialogueBlockPlain *>(&block)) {
wxString text(to_wx(txt->GetText()));
if (text.empty() || (text.size() >= 2 && text.StartsWith("{") && text.EndsWith("}")))
if (text.empty())
continue;
if (overriden)
@ -100,7 +100,7 @@ void FontCollector::ProcessDialogueLine(const AssDialogue *line, int index) {
chars.insert(cur);
}
}
// Do nothing with drawing blocks
// Do nothing with drawing and comment blocks
}
}

View File

@ -287,10 +287,6 @@ namespace
{
wxString text = to_wx(b.GetText());
// Skip comments
if (text.size() > 1 && text[0] =='{' && text.Last() == '}')
continue;
text.Replace("\\t", " ");
while (special_char_search.Matches(text))
@ -354,7 +350,7 @@ namespace
break;
default:
// ignore block, we don't want to output it (drawing or unknown)
// ignore block, we don't want to output it (drawing or comment)
break;
}
}

View File

@ -553,12 +553,7 @@ void VisualToolBase::SetOverride(AssDialogue* line, std::string const& tag, wxSt
boost::ptr_vector<AssDialogueBlock> blocks(line->ParseTags());
AssDialogueBlock *block = &blocks.front();
// Get current block as plain or override
assert(dynamic_cast<AssDialogueBlockDrawing*>(block) == nullptr);
if (dynamic_cast<AssDialogueBlockPlain*>(block))
line->Text = "{" + to_wx(tag) + value + "}" + line->Text;
else if (AssDialogueBlockOverride *ovr = dynamic_cast<AssDialogueBlockOverride*>(block)) {
if (AssDialogueBlockOverride *ovr = dynamic_cast<AssDialogueBlockOverride*>(block)) {
// Remove old of same
for (size_t i = 0; i < ovr->Tags.size(); i++) {
std::string const& name = ovr->Tags[i].Name;
@ -571,6 +566,8 @@ void VisualToolBase::SetOverride(AssDialogue* line, std::string const& tag, wxSt
line->UpdateText(blocks);
}
else
line->Text = "{" + to_wx(tag) + value + "}" + line->Text;
}
// If only export worked