Invoke View::ExecCommand
from the console window
This commit is contained in:
parent
bb7c84b2c2
commit
cacec5b470
@ -79,8 +79,7 @@ namespace spades {
|
||||
return;
|
||||
}
|
||||
field.CommandSent();
|
||||
// TODO: Execute the command
|
||||
viewer.AddLine("TODO: " + field.Text, true);
|
||||
helper.ExecCommand(field.Text);
|
||||
field.Text = "";
|
||||
}
|
||||
}
|
||||
|
@ -16,20 +16,48 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenSpades. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <Core/Debug.h>
|
||||
|
||||
#include "ConsoleCommand.h"
|
||||
#include "ConsoleHelper.h"
|
||||
#include "ConsoleScreen.h"
|
||||
|
||||
namespace spades {
|
||||
namespace gui {
|
||||
ConsoleHelper::ConsoleHelper(ConsoleScreen *scr) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
(void)scr;
|
||||
// TODO
|
||||
parentWeak = scr;
|
||||
}
|
||||
|
||||
ConsoleHelper::~ConsoleHelper() {}
|
||||
|
||||
void ConsoleHelper::ConsoleScreenDestroyed() {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
// TODO
|
||||
parentWeak = nullptr;
|
||||
}
|
||||
|
||||
Handle<ConsoleScreen> ConsoleHelper::GetParent() { return {parentWeak, true}; }
|
||||
|
||||
void ConsoleHelper::ExecCommand(const std::string &text) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
auto parent = GetParent();
|
||||
if (!parent) {
|
||||
return;
|
||||
}
|
||||
|
||||
SPLog("Command: %s", text.c_str());
|
||||
try {
|
||||
auto const command = ConsoleCommand::Parse(text);
|
||||
|
||||
if (!parent->ExecCommand(command)) {
|
||||
SPLog("Unknown command: '%s'", command->GetName().c_str());
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
SPLog("An exception was thrown while executing a console command: %s", e.what());
|
||||
}
|
||||
}
|
||||
} // namespace gui
|
||||
} // namespace spades
|
||||
|
@ -30,6 +30,16 @@ namespace spades {
|
||||
public:
|
||||
ConsoleHelper(ConsoleScreen *scr);
|
||||
void ConsoleScreenDestroyed();
|
||||
|
||||
/** Execute a console command. */
|
||||
void ExecCommand(const std::string &);
|
||||
|
||||
private:
|
||||
~ConsoleHelper();
|
||||
/** A weak reference to the owning `ConsoleScreen`. */
|
||||
ConsoleScreen *parentWeak;
|
||||
/** Get a strong reference to the owning `ConsoleScreen`. */
|
||||
Handle<ConsoleScreen> GetParent();
|
||||
};
|
||||
} // namespace gui
|
||||
} // namespace spades
|
||||
|
@ -35,6 +35,7 @@ namespace spades {
|
||||
* functionality which can be invoked anytime by using a hotkey.
|
||||
*/
|
||||
class ConsoleScreen : public View {
|
||||
friend class ConsoleHelper;
|
||||
public:
|
||||
ConsoleScreen(Handle<client::IRenderer>, Handle<client::IAudioDevice>,
|
||||
Handle<client::FontManager>, Handle<View>);
|
||||
|
@ -45,6 +45,11 @@ namespace spades {
|
||||
asMETHOD(gui::ConsoleHelper, Release),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterObjectMethod(
|
||||
"ConsoleHelper", "void ExecCommand(const string& in)",
|
||||
asMETHOD(gui::ConsoleHelper, ExecCommand), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user