Merge pull request #548 from NQNStudios:talk-keys

Better editing for talk node keys

* The fields start out empty, and it is *allowed* to keep *one of them* empty. (A node only needs one key to be useful, right?
* When the node is saved, empty strings are replaced with `"    "`. If this is not harmless to the game logic, then I'll need to make the game aware that either key might be `"    "`.
* You cannot type more than 4 characters in these fields (unless there's a way to insert characters I'm not aware of).
* If you put 'buy' in a field, it automatically becomes 'purc'.
* There is a note next to the response keys (kind of squished in the corner) enumerating the special logic of the in-game Buy and Sell buttons.
This commit is contained in:
2025-02-02 13:57:55 -05:00
committed by GitHub
5 changed files with 57 additions and 13 deletions

View File

@@ -442,16 +442,18 @@ void cTextField::handleInput(cKey key, bool record) {
handleInput(deleteKey);
contents = getText();
}
if(aTextInsert* ins = dynamic_cast<aTextInsert*>(current_action.get()))
ins->append(key.c);
else {
if(current_action) history.add(current_action);
aTextInsert* new_ins = new aTextInsert(*this, insertionPoint);
new_ins->append(key.c);
current_action.reset(new_ins);
if(maxChars < 0 || contents.size() < maxChars){
if(aTextInsert* ins = dynamic_cast<aTextInsert*>(current_action.get()))
ins->append(key.c);
else {
if(current_action) history.add(current_action);
aTextInsert* new_ins = new aTextInsert(*this, insertionPoint);
new_ins->append(key.c);
current_action.reset(new_ins);
}
contents.insert(contents.begin() + insertionPoint, char(key.c));
selectionPoint = ++insertionPoint;
}
contents.insert(contents.begin() + insertionPoint, char(key.c));
selectionPoint = ++insertionPoint;
} else switch(key.k) {
case key_enter: break; // Shouldn't be receiving this anyway
case key_left: case key_word_left:
@@ -681,6 +683,9 @@ bool cTextField::parseAttribute(ticpp::Attribute& attr, std::string tagName, std
} else if(name == "tab-order"){
attr.GetValue(&tabOrder);
return true;
} else if(name == "max-chars"){
attr.GetValue(&maxChars);
return true;
}
return cControl::parseAttribute(attr, tagName, fname);
}

View File

@@ -90,6 +90,10 @@ private:
rectangle text_rect;
std::vector<snippet_t> snippets;
int ip_row, ip_col;
/// Setting maxChars AFTER the player has a chance to type in the field would be a bad idea.
/// So would calling setText() with a string longer than maxChars.
/// Really, it should probably only be set in xml, as the attribute "max-chars".
int maxChars = -1;
friend class aTextInsert;
friend class aTextDelete;
};