mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-02 15:53:51 +00:00
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:
parent
743b9c7333
commit
5afc9a57d1
4 changed files with 39 additions and 4 deletions
|
|
@ -107,6 +107,7 @@ private:
|
||||||
|
|
||||||
AppState state = AppState::AUTHENTICATION;
|
AppState state = AppState::AUTHENTICATION;
|
||||||
bool running = false;
|
bool running = false;
|
||||||
|
std::string pendingCreatedCharacterName_; // Auto-select after character creation
|
||||||
bool playerCharacterSpawned = false;
|
bool playerCharacterSpawned = false;
|
||||||
bool npcsSpawned = false;
|
bool npcsSpawned = false;
|
||||||
bool spawnSnapToGround = true;
|
bool spawnSnapToGround = true;
|
||||||
|
|
|
||||||
|
|
@ -49,12 +49,18 @@ public:
|
||||||
*/
|
*/
|
||||||
void setStatus(const std::string& message);
|
void setStatus(const std::string& message);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select character by name (used after character creation)
|
||||||
|
*/
|
||||||
|
void selectCharacterByName(const std::string& name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// UI state
|
// UI state
|
||||||
int selectedCharacterIndex = -1;
|
int selectedCharacterIndex = -1;
|
||||||
bool characterSelected = false;
|
bool characterSelected = false;
|
||||||
uint64_t selectedCharacterGuid = 0;
|
uint64_t selectedCharacterGuid = 0;
|
||||||
bool restoredLastCharacter = false;
|
bool restoredLastCharacter = false;
|
||||||
|
std::string newlyCreatedCharacterName; // Auto-select this character if set
|
||||||
|
|
||||||
// Status
|
// Status
|
||||||
std::string statusMessage;
|
std::string statusMessage;
|
||||||
|
|
|
||||||
|
|
@ -581,6 +581,7 @@ void Application::setupUICallbacks() {
|
||||||
|
|
||||||
// Character create screen callbacks
|
// Character create screen callbacks
|
||||||
uiManager->getCharacterCreateScreen().setOnCreate([this](const game::CharCreateData& data) {
|
uiManager->getCharacterCreateScreen().setOnCreate([this](const game::CharCreateData& data) {
|
||||||
|
pendingCreatedCharacterName_ = data.name; // Store name for auto-selection
|
||||||
gameHandler->createCharacter(data);
|
gameHandler->createCharacter(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -591,9 +592,15 @@ void Application::setupUICallbacks() {
|
||||||
// Character create result callback
|
// Character create result callback
|
||||||
gameHandler->setCharCreateCallback([this](bool success, const std::string& msg) {
|
gameHandler->setCharCreateCallback([this](bool success, const std::string& msg) {
|
||||||
if (success) {
|
if (success) {
|
||||||
|
// Auto-select the newly created character
|
||||||
|
if (!pendingCreatedCharacterName_.empty()) {
|
||||||
|
uiManager->getCharacterScreen().selectCharacterByName(pendingCreatedCharacterName_);
|
||||||
|
pendingCreatedCharacterName_.clear();
|
||||||
|
}
|
||||||
setState(AppState::CHARACTER_SELECTION);
|
setState(AppState::CHARACTER_SELECTION);
|
||||||
} else {
|
} else {
|
||||||
uiManager->getCharacterCreateScreen().setStatus(msg, true);
|
uiManager->getCharacterCreateScreen().setStatus(msg, true);
|
||||||
|
pendingCreatedCharacterName_.clear();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,20 @@ void CharacterScreen::render(game::GameHandler& gameHandler) {
|
||||||
|
|
||||||
// Restore last-selected character (once per screen visit)
|
// Restore last-selected character (once per screen visit)
|
||||||
if (!restoredLastCharacter) {
|
if (!restoredLastCharacter) {
|
||||||
|
// Priority 1: Select newly created character if set
|
||||||
|
if (!newlyCreatedCharacterName.empty()) {
|
||||||
|
for (size_t i = 0; i < characters.size(); ++i) {
|
||||||
|
if (characters[i].name == newlyCreatedCharacterName) {
|
||||||
|
selectedCharacterIndex = static_cast<int>(i);
|
||||||
|
selectedCharacterGuid = characters[i].guid;
|
||||||
|
saveLastCharacter(characters[i].guid);
|
||||||
|
newlyCreatedCharacterName.clear();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Priority 2: Restore last selected character
|
||||||
|
if (selectedCharacterIndex < 0) {
|
||||||
uint64_t lastGuid = loadLastCharacter();
|
uint64_t lastGuid = loadLastCharacter();
|
||||||
if (lastGuid != 0) {
|
if (lastGuid != 0) {
|
||||||
for (size_t i = 0; i < characters.size(); ++i) {
|
for (size_t i = 0; i < characters.size(); ++i) {
|
||||||
|
|
@ -66,6 +80,7 @@ void CharacterScreen::render(game::GameHandler& gameHandler) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Fall back to first character if nothing matched
|
// Fall back to first character if nothing matched
|
||||||
if (selectedCharacterIndex < 0) {
|
if (selectedCharacterIndex < 0) {
|
||||||
selectedCharacterIndex = 0;
|
selectedCharacterIndex = 0;
|
||||||
|
|
@ -298,6 +313,12 @@ void CharacterScreen::setStatus(const std::string& message) {
|
||||||
statusMessage = 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 {
|
ImVec4 CharacterScreen::getFactionColor(game::Race race) const {
|
||||||
// Alliance races: blue
|
// Alliance races: blue
|
||||||
if (race == game::Race::HUMAN ||
|
if (race == game::Race::HUMAN ||
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue