/* Console::Command::execute * Executes the console command *******************************************************************/ void Console::Command::execute(vector<string> args) { // Only execute if we have the minimum args specified if (args.size() >= min_args) commandFunc(args); else logMessage(S_FMT("Missing command arguments, type \"cmdhelp %s\" for more information", CHR(name))); }
// Update input void UITerminal::updateInput(KeyHandler* mKeyH, MouseHandler* mMouseH){ UITransitionObject::updateInput(mKeyH, mMouseH); // Check for up arrow and add last command if (mKeyH->keyPressed(KEY_UP)){ line = lines[0].text; iteratorLoc = line.length(); } // Add text to the line std::string next = mKeyH->getPressedKey(); if (next.length() > 0){ // Set iterator to visible iteratorAlpha = 1.0f; blinkFade = true; // Add text to end of line if iterator is at the end if (iteratorLoc == line.length()){ line += next; iteratorLoc++; } // Add text to the middle of line if iterator is inside line else { line = line.substr(0, iteratorLoc) + next + line.substr(iteratorLoc, line.length()); iteratorLoc++; } } // Make sure line is not too long if (line.length() > maxTextLength){ line = line.substr(0, maxTextLength); iteratorLoc = maxTextLength; } // Check for backspace if (mKeyH->keyPressedHold(KEY_BACKSPACE)){ if (iteratorLoc > 0){ // Subtract text at end if iterator is at end of line if (iteratorLoc == line.length()){ line = line.substr(0, line.length() - 1); iteratorLoc--; } // Subtract text in the middle of line if iterator is inside line else { line = line.substr(0, iteratorLoc-1) + line.substr(iteratorLoc, line.length()); iteratorLoc--; } } } // Check for enter if (mKeyH->keyPressed(KEY_ENTER)){ iteratorLoc = 0; commandIssued = true; commandString = line; line.clear(); // Call command function if set if (useFunction){ commandIssued = false; commandFunc(commandString); } } // Check if user is trying to move iterator if (mKeyH->keyPressedHold(KEY_LEFT)){ iteratorLoc--; if (iteratorLoc < 0) iteratorLoc = 0; } if (mKeyH->keyPressedHold(KEY_RIGHT)){ iteratorLoc++; if (iteratorLoc > (int)line.length()) iteratorLoc = (int)line.length(); } }