Auto-select newly created character in selection screen

After creating a character, automatically select it in the character
list instead of defaulting to the previously selected character.

Changes:
- Added selectCharacterByName() method to CharacterScreen
- Store created character name in Application
- On creation success, auto-select the new character by name
- Falls back to saved selection if new character name doesn't match
This commit is contained in:
Kelsi 2026-02-09 22:51:13 -08:00
parent 743b9c7333
commit 5afc9a57d1
4 changed files with 39 additions and 4 deletions

View file

@ -56,16 +56,31 @@ void CharacterScreen::render(game::GameHandler& gameHandler) {
// Restore last-selected character (once per screen visit)
if (!restoredLastCharacter) {
uint64_t lastGuid = loadLastCharacter();
if (lastGuid != 0) {
// Priority 1: Select newly created character if set
if (!newlyCreatedCharacterName.empty()) {
for (size_t i = 0; i < characters.size(); ++i) {
if (characters[i].guid == lastGuid) {
if (characters[i].name == newlyCreatedCharacterName) {
selectedCharacterIndex = static_cast<int>(i);
selectedCharacterGuid = lastGuid;
selectedCharacterGuid = characters[i].guid;
saveLastCharacter(characters[i].guid);
newlyCreatedCharacterName.clear();
break;
}
}
}
// Priority 2: Restore last selected character
if (selectedCharacterIndex < 0) {
uint64_t lastGuid = loadLastCharacter();
if (lastGuid != 0) {
for (size_t i = 0; i < characters.size(); ++i) {
if (characters[i].guid == lastGuid) {
selectedCharacterIndex = static_cast<int>(i);
selectedCharacterGuid = lastGuid;
break;
}
}
}
}
// Fall back to first character if nothing matched
if (selectedCharacterIndex < 0) {
selectedCharacterIndex = 0;
@ -298,6 +313,12 @@ void CharacterScreen::setStatus(const std::string& message) {
statusMessage = message;
}
void CharacterScreen::selectCharacterByName(const std::string& name) {
newlyCreatedCharacterName = name;
restoredLastCharacter = false; // Allow re-selection in render()
selectedCharacterIndex = -1;
}
ImVec4 CharacterScreen::getFactionColor(game::Race race) const {
// Alliance races: blue
if (race == game::Race::HUMAN ||