diff --git a/Faceball2030/Editor.cpp b/Faceball2030/Editor.cpp index f0ccc65..9575482 100644 --- a/Faceball2030/Editor.cpp +++ b/Faceball2030/Editor.cpp @@ -108,29 +108,127 @@ void Editor::Update(float fElapsedTime){ void Editor::LoadLevelHandling() { if (!game->IsTextEntryEnabled()) { - if (game->GetKey(F1).bPressed || reEnableTextEntry) { - game->TextEntryEnable(true); + if (promptState == PromptState::NONE) { + if (game->GetKey(F1).bPressed) { + promptState = PromptState::ENTER_LEVEL; + game->TextEntryEnable(true); + } + if (game->GetKey(F2).bPressed) { + promptState = PromptState::ENTER_WIDTH; + game->TextEntryEnable(true,std::to_string(MAP_SIZE.x)); + } + } + if (reEnableTextEntry) { + switch (promptState) { + case PromptState::ENTER_LEVEL: { + game->TextEntryEnable(true); + }break; + case PromptState::ENTER_WIDTH: { + game->TextEntryEnable(true, std::to_string(MAP_SIZE.y)); + }break; + case PromptState::ENTER_HEIGHT: { + game->TextEntryEnable(true,std::to_string(MAP_SIZE.y)); + }break; + } reEnableTextEntry = false; } } else { game->FillRectDecal({ 0,0 }, { (float)game->ScreenWidth(),32 }, BLACK); - game->DrawStringDecal({ 0,0 }, "Enter Level (1-30): " + game->TextEntryGetString(), WHITE, { 4,4 }); + switch (promptState) { + case PromptState::ENTER_LEVEL: { + game->DrawStringDecal({ 0,0 }, "Enter Level (1-30): " + game->TextEntryGetString(), WHITE, { 4,4 }); + }break; + case PromptState::ENTER_WIDTH: { + game->DrawStringDecal({ 0,0 }, "Enter Level Width: " + game->TextEntryGetString(), WHITE, { 4,4 }); + }break; + case PromptState::ENTER_HEIGHT: { + game->DrawStringDecal({ 0,0 }, "Enter Level Height: " + game->TextEntryGetString(), WHITE, { 4,4 }); + }break; + } } } void Editor::OnTextEntryComplete(const std::string& sText) { std::stringstream ss(game->TextEntryGetString()); - int level; - ss >> level; - if (level >= 1 && level <= 30) { - game->TextEntryEnable(false); - this->level = level; - LoadLevel(); - } - else { - reEnableTextEntry = true; + int input; + ss >> input; + switch (promptState) { + case PromptState::ENTER_LEVEL: { + if (input >= 1 && input <= 30) { + game->TextEntryEnable(false); + promptState = PromptState::NONE; + this->level = input; + LoadLevel(); + } + else { + reEnableTextEntry = true; + } + }break; + case PromptState::ENTER_WIDTH: { + if (input >= 1 && input <= 50) { + promptState = PromptState::ENTER_HEIGHT; + reEnableTextEntry = true; + this->MAP_SIZE.x = input; + if (MAP_SIZE.x == map[0].size()) { + break; //We don't care to resize the vecetor at this point. + } + if (MAP_SIZE.x < map[0].size()) { + for (int y = 0; y < map.size(); y++) { + std::vector& row = map[y]; + row.erase(row.begin() + MAP_SIZE.x, row.end()); + } + } + else { + for (int y = 0; y < map.size(); y++) { + std::vector& row = map[y]; + for (int x = map[y].size(); x < MAP_SIZE.x; x++) { + Tile t = {}; + if (x > 0) { + Tile& neighborW = map[y][x-1]; + t.wallW = neighborW.wallE; + } + row.push_back(t); + } + } + } + } + else { + reEnableTextEntry = true; + } + }break; + case PromptState::ENTER_HEIGHT: { + if (input >= 1 && input <= 50) { + game->TextEntryEnable(false); + promptState = PromptState::NONE; + this->MAP_SIZE.y = input; + if (MAP_SIZE.y == map.size()) { + break; //We don't care to resize the vecetor at this point. + } + if (MAP_SIZE.y < map.size()) { + map.erase(map.begin() + MAP_SIZE.y, map.end()); + } + else { + for (int y = map.size(); y < MAP_SIZE.y; y++) { + std::vector row; + for (int x = 0; x < MAP_SIZE.x; x++) { + Tile t = {}; + if (y > 0) { + Tile& neighborN = map[y - 1][x]; + t.wallN = neighborN.wallS; + } + row.push_back(t); + } + map.push_back(row); + } + } + } + else { + reEnableTextEntry = true; + } + }break; } + } void Editor::LoadLevel() { diff --git a/Faceball2030/Editor.h b/Faceball2030/Editor.h index 59a4394..907dd08 100644 --- a/Faceball2030/Editor.h +++ b/Faceball2030/Editor.h @@ -37,6 +37,13 @@ enum WallDirection { WEST = 8 };*/ +enum class PromptState { + NONE, + ENTER_LEVEL, + ENTER_WIDTH, + ENTER_HEIGHT, +}; + struct Tile { EnemyID enemyId=EnemyID::NONE; FacingDirection facingDir=FacingDirection::EAST; @@ -57,6 +64,7 @@ class Editor { std::vector> map; const vi2d GRID_SIZE = { 32,32 }; EnemyID selectedEnemy=SHOOTME; + PromptState promptState = PromptState::NONE; public: Editor() {} void Update(float fElapsedTime);