void EditorString::ParseDot(const std::string& line) { std::string command = line; command.erase(0, 1); E_STATE changedstate = ParseMode(command[0]); if(changedstate != M_FIRST) { m_state = changedstate; return; } if(!command.compare("c")) { m_sock->Send("Text cleared.\n"); m_strings.clear(); return; } if(!command.compare("q")) { m_sock->Send("Quitting now.\n"); m_state = M_DONE; return; } if(!command.compare("h")) { m_sock->Send("Some descriptive help text goes here.\n"); return; } m_sock->Sendf("Unknown dot command '%s'.\n", command.c_str()); return; }
void CInputManagerImplementation::LoadCommandsFromFile(const std::string& path) { m_FileName = path; m_Actions.clear(); m_Axis.clear(); CXMLTreeNode l_XML; if (l_XML.LoadFile(path.c_str())) { CXMLTreeNode l_Input = l_XML["input"]; if (l_Input.Exists()) { for (int i = 0; i < l_Input.GetNumChildren(); ++i) { CXMLTreeNode l_Element = l_Input(i); if (l_Element.GetName() == std::string("action")) { CXMLTreeNode &l_Action = l_Element; Action action = {}; action.name = l_Action.GetPszProperty("name"); std::string type = l_Action.GetPszProperty("type", "KEYBOARD"); action.inputType = ParseInputType(type); action.mode = ParseMode(l_Action.GetPszProperty("mode", "ON_PRESS", false)); action.triggersAxis = l_Action.GetBoolProperty("triggers_axis", false, false); action.axisName = l_Action.GetPszProperty("axis", "", false); action.axisValue = l_Action.GetFloatProperty("axis_value", 1, false); switch (action.inputType) { case KEYBOARD: action.keyboard.key = l_Action.GetPszProperty("key", "A")[0]; action.keyboard.needsAlt = l_Action.GetBoolProperty("needs_alt", false, false); action.keyboard.needsCtrl = l_Action.GetBoolProperty("needs_ctrl", false, false); break; case MOUSE: action.mouse.button = ParseMouseButton(l_Action.GetPszProperty("mouse_button", "LEFT")); break; // TODO: Mouse y Gamepad // Pista: para parsear botones del gamepad, usad las constantes: // podeis tener más de una a la vez usando "XINPUT_GAMEPAD_A | XINPUT_GAMEPAD_B", por ejemplo. // pero para que eso funcione bién con ON_PRESS tendréis que mejorar la lógica de esta clase o ser frame perfect pulsando botones // XINPUT_GAMEPAD_DPAD_UP // XINPUT_GAMEPAD_DPAD_DOWN // XINPUT_GAMEPAD_DPAD_LEFT // XINPUT_GAMEPAD_DPAD_RIGHT // XINPUT_GAMEPAD_START // XINPUT_GAMEPAD_BACK // XINPUT_GAMEPAD_LEFT_THUMB // XINPUT_GAMEPAD_RIGHT_THUMB // XINPUT_GAMEPAD_LEFT_SHOULDER // XINPUT_GAMEPAD_RIGHT_SHOULDER // XINPUT_GAMEPAD_A // XINPUT_GAMEPAD_B // XINPUT_GAMEPAD_X // XINPUT_GAMEPAD_Y // } m_Actions.push_back(action); } else if (l_Element.GetName() == std::string("axis")) { CXMLTreeNode &l_Axis = l_Element; Axis axis = {}; axis.name = l_Axis.GetPszProperty("name"); std::string type = l_Axis.GetPszProperty("type", "MOUSE"); axis.inputType = ParseInputType(type); switch (axis.inputType) { case GAMEPAD: axis.gamepad.axis = ParseGamepadAxis(l_Axis.GetPszProperty("gamepad_axis", "X")); axis.gamepad.gamepadNumber = l_Axis.GetIntProperty("gamepad_number", 0, false); break; case MOUSE: axis.mouse.axis = ParseMouseAxis(l_Axis.GetPszProperty("mouse_axis", "X")); axis.mouse.scale = l_Axis.GetFloatProperty("mouse_scale", 1, false); break; } m_Axis.push_back(axis); // TODO: parse axis } } } } EndFrame(); }
void CInputManagerImplementation::LoadCommandsFromFile(const std::string& path) { m_Actions.clear(); { Action action = { "MOVE_FWD", KEYBOARD, Action::WHILE_PRESSED }; action.keyboard.key = VK_SHIFT; action.keyboard.needsAlt = false; action.keyboard.needsCtrl = false; action.triggersAxis = true; action.axisName = "MOVE_FWD"; action.axisValue = 1; m_Actions.push_back(action); } { Action action = { "MOVE_FASTFW", KEYBOARD, Action::WHILE_PRESSED }; action.keyboard.key = 'W'; action.keyboard.needsAlt = false; action.keyboard.needsCtrl = false; action.triggersAxis = true; action.axisName = "RunAxis"; action.axisValue = 1; m_Actions.push_back(action); } { Action action = { "MOVE_FASTBW", KEYBOARD, Action::WHILE_PRESSED }; action.keyboard.key = 'S'; action.keyboard.needsAlt = false; action.keyboard.needsCtrl = false; action.triggersAxis = true; action.axisName = "RunAxis"; action.axisValue = -1; m_Actions.push_back(action); } { Action action = { "STRAFE_LEFT", KEYBOARD, Action::WHILE_PRESSED }; action.keyboard.key = 'A'; action.keyboard.needsAlt = false; action.keyboard.needsCtrl = false; action.triggersAxis = true; action.axisName = "STRAFE"; action.axisValue = -1; m_Actions.push_back(action); } { Action action = { "STRAFE_RIGHT", KEYBOARD, Action::WHILE_PRESSED }; action.keyboard.key = 'D'; action.keyboard.needsAlt = false; action.keyboard.needsCtrl = false; action.triggersAxis = true; action.axisName = "STRAFE"; action.axisValue = 1; m_Actions.push_back(action); } { Action action = { "JUMP", KEYBOARD, Action::WHILE_PRESSED }; action.keyboard.key = VK_SPACE; action.keyboard.needsAlt = false; action.keyboard.needsCtrl = false; action.triggersAxis = true; action.axisName = "JUMPAxis"; action.axisValue = 1; m_Actions.push_back(action); } { Action action = { "COACH", KEYBOARD, Action::WHILE_PRESSED }; action.keyboard.key = 'C'; action.keyboard.needsAlt = false; action.keyboard.needsCtrl = false; action.triggersAxis = true; action.axisName = "JUMPAxis"; action.axisValue = -1; m_Actions.push_back(action); } { Action action = { "SWITCH_CAMERA", KEYBOARD, Action::ON_PRESS }; action.keyboard.key = VK_TAB; action.keyboard.needsAlt = false; action.keyboard.needsCtrl = false; m_Actions.push_back(action); } { Action action = { "ACTION", KEYBOARD, Action::ON_PRESS }; action.keyboard.key = 'E'; action.keyboard.needsAlt = false; action.keyboard.needsCtrl = false; m_Actions.push_back(action); } { Action action = { "NEXT_LEVEL_ACTIVE", KEYBOARD, Action::WHILE_PRESSED }; action.keyboard.key = VK_F9; action.keyboard.needsAlt = false; action.keyboard.needsCtrl = false; m_Actions.push_back(action); } { Action action = { "BACK", KEYBOARD, Action::ON_PRESS }; action.keyboard.key = VK_ESCAPE; action.keyboard.needsAlt = false; action.keyboard.needsCtrl = false; m_Actions.push_back(action); } { Action action = { "DIVIDE_3_QUARTERS", KEYBOARD, Action::ON_PRESS }; action.keyboard.key = '1'; action.keyboard.needsAlt = false; action.keyboard.needsCtrl = false; m_Actions.push_back(action); } { Action action = { "DIVIDE_1_HALF", KEYBOARD, Action::ON_PRESS }; action.keyboard.key = '2'; action.keyboard.needsAlt = false; action.keyboard.needsCtrl = false; m_Actions.push_back(action); } { Action action = { "DIVIDE_1_QUARTER", KEYBOARD, Action::ON_PRESS }; action.keyboard.key = '3'; action.keyboard.needsAlt = false; action.keyboard.needsCtrl = false; m_Actions.push_back(action); } { Action action = { "REUNITE", KEYBOARD, Action::ON_PRESS }; action.keyboard.key = '4'; action.keyboard.needsAlt = false; action.keyboard.needsCtrl = false; m_Actions.push_back(action); } { Action action = { "MULTI_CONTROL_TOGGLE", KEYBOARD, Action::ON_PRESS }; action.keyboard.key = 'T'; action.keyboard.needsAlt = false; action.keyboard.needsCtrl = false; m_Actions.push_back(action); } { Action action = { "THROW_DIVISION", KEYBOARD, Action::ON_PRESS }; action.keyboard.key = 'G'; action.keyboard.needsAlt = false; action.keyboard.needsCtrl = false; m_Actions.push_back(action); } { Action action = { "FIXCAMERA", KEYBOARD, Action::ON_PRESS }; action.keyboard.key = 'P'; action.keyboard.needsAlt = false; action.keyboard.needsCtrl = false; action.triggersAxis = true; action.axisValue = -1; action.axisName = "FIXED_CAMERA"; m_Actions.push_back(action); } { Action action = { "MOUSE_PRESSED", MOUSE, Action::ON_PRESS }; action.mouse.button = Action::LEFT; m_Actions.push_back(action); } { Action action = { "MOUSE_DOWN", MOUSE, Action::WHILE_PRESSED }; action.mouse.button = Action::LEFT; m_Actions.push_back(action); } { Action action = { "MOUSE_RELEASED", MOUSE, Action::ON_RELEASE }; action.mouse.button = Action::LEFT; m_Actions.push_back(action); } { Action action = { "MOVE_CAMERA", MOUSE, Action::WHILE_PRESSED }; action.mouse.button = Action::RIGHT; m_Actions.push_back(action); } { Axis axis = { "X_AXIS", MOUSE }; axis.mouse.axis = MouseAxis::X; axis.mouse.scale = 0.05f; m_Axis.push_back(axis); } { Axis axis = { "Y_AXIS", MOUSE }; axis.mouse.axis = MouseAxis::Y; axis.mouse.scale = 0.01f; m_Axis.push_back(axis); } { Axis axis = { "ZOOM", MOUSE }; axis.mouse.axis = MouseAxis::WHEEL; axis.mouse.scale = 0.05f; m_Axis.push_back(axis); } { Axis axis = { "X_AXIS", GAMEPAD }; axis.gamepad.axis = GamepadAxis::LEFT_X; axis.gamepad.gamepadNumber = 0; m_Axis.push_back(axis); } { Axis axis = { "Y_AXIS", GAMEPAD }; axis.gamepad.axis = GamepadAxis::LEFT_Y; axis.gamepad.gamepadNumber = 0; m_Axis.push_back(axis); } //*/ CXMLTreeNode l_XML; if (l_XML.LoadFile(path.c_str())) { CXMLTreeNode l_Input = l_XML["input"]; if (l_Input.Exists()) { for (int i = 0; i < l_Input.GetNumChildren(); ++i) { CXMLTreeNode l_Element = l_Input(i); if (l_Element.GetName() == std::string("action")) { CXMLTreeNode &l_Action = l_Element; Action action = {}; action.name = l_Action.GetPszProperty("name"); std::string type = l_Action.GetPszProperty("type", "KEYBOARD"); action.inputType = ParseInputType(type); action.mode = ParseMode(l_Action.GetPszProperty("mode", "ON_PRESS", false)); action.triggersAxis = l_Action.GetBoolProperty("triggers_axis", false, false); action.axisName = l_Action.GetPszProperty("axis", "", false); action.axisValue = l_Action.GetFloatProperty("axis_value", 1, false); switch (action.inputType) { case KEYBOARD: action.keyboard.key = l_Action.GetPszProperty("key", "A")[0]; action.keyboard.needsAlt = l_Action.GetBoolProperty("needs_alt", false, false); action.keyboard.needsCtrl = l_Action.GetBoolProperty("needs_ctrl", false, false); break; case MOUSE: { auto key = l_Action.GetPszProperty("key", "LEFT"); if (key == "RIGHT") { action.mouse.button = Action::MouseButton::RIGHT; } else if (key == "CENTER") { action.mouse.button = Action::MouseButton::CENTER; } else { action.mouse.button = Action::MouseButton::LEFT; } break; } // TODO: Mouse y Gamepad // Pista: para parsear botones del gamepad, usad las constantes: // podeis tener más de una a la vez usando "XINPUT_GAMEPAD_A | XINPUT_GAMEPAD_B", por ejemplo. // pero para que eso funcione bién con ON_PRESS tendréis que mejorar la lógica de esta clase o ser frame perfect pulsando botones // XINPUT_GAMEPAD_DPAD_UP // XINPUT_GAMEPAD_DPAD_DOWN // XINPUT_GAMEPAD_DPAD_LEFT // XINPUT_GAMEPAD_DPAD_RIGHT // XINPUT_GAMEPAD_START // XINPUT_GAMEPAD_BACK // XINPUT_GAMEPAD_LEFT_THUMB // XINPUT_GAMEPAD_RIGHT_THUMB // XINPUT_GAMEPAD_LEFT_SHOULDER // XINPUT_GAMEPAD_RIGHT_SHOULDER // XINPUT_GAMEPAD_A // XINPUT_GAMEPAD_B // XINPUT_GAMEPAD_X // XINPUT_GAMEPAD_Y // } m_Actions.push_back(action); } else if (l_Element.GetName() == std::string("axis")) { // TODO: parse axis } } } } //*/ EndFrame(); }
void EditorString::OnLine(const std::string& line) { if(!line.compare("~")) { m_sock->Send("Allright, done!\n"); m_state = M_DONE; } if(line[0] == '.') { ParseDot(line); return; } switch(m_state) { default: { Global::Get()->bug("EditorString::OnLine(), default m_state!\n"); m_sock->Send("BUG! Disconnecting you now...\n"); m_sock->SetCloseAndDelete(); return; } /* default */ case M_FIRST: { m_state = M_WAITING_FOR_INPUT; m_sock->Send("Welcome to the string editor.\n"); // fallthrough } /* case M_FIRST: */ case M_WAITING_FOR_INPUT: { if(line.size() == 0) { m_sock->Send("Please choose an editing mode.\n"); m_sock->Send("If you need help please type '.h'.\n"); return; } char mode; if(line[0] == '.') mode = line[1]; else mode = line[0]; E_STATE choice = ParseMode(mode); if(choice == M_FIRST) m_state = M_WAITING_FOR_INPUT; else m_state = choice; OnLine(Global::Get()->EmptyString); return; } /* case M_WAITING_FOR_INPUT: */ case M_APPEND: { if(line.size() == 0) { m_sock->Sendf("If you want to append a newline type '.n' on an empty line.\n"); return; } m_strings.push_back(line); return; } /* case M_APPEND: */ case M_REPLACE: { if(line.size() == 0) { m_sock->Send("Not yet implemented - Alturin 30-12-2007.\n"); return; } return; } case M_VIEW: { if(line.size() != 0) { m_sock->Send("At the moment all you can do here is hit enter to show the entire string.\n"); return; } m_sock->Send(String::Get()->unlines(m_strings, " ")); return; } case M_DONE: { m_sock->PopEditor(); return; } /* case M_DONE: */ } /* switch(state) */ }
void CInputManagerImplementation::LoadCommandsFromFile(const std::string& path) { m_Actions.clear(); /* { Action action = { "MOVE_LEFT", Action::KEYBOARD }; action.keyboard.mode = Action::WHILE_PRESSED; action.keyboard.key = 'A'; action.keyboard.needsAlt = false; action.keyboard.needsCtrl = false; m_Actions.push_back(action); } { Action action = { "MOVE_RIGHT", Action::KEYBOARD }; action.keyboard.mode = Action::WHILE_PRESSED; action.keyboard.key = 'D'; action.keyboard.needsAlt = false; action.keyboard.needsCtrl = false; m_Actions.push_back(action); } { Action action = { "MOVE_UP", Action::KEYBOARD }; action.keyboard.mode = Action::WHILE_PRESSED; action.keyboard.key = 'W'; action.keyboard.needsAlt = false; action.keyboard.needsCtrl = false; m_Actions.push_back(action); } { Action action = { "MOVE_DOWN", Action::KEYBOARD }; action.keyboard.mode = Action::WHILE_PRESSED; action.keyboard.key = 'S'; action.keyboard.needsAlt = false; action.keyboard.needsCtrl = false; m_Actions.push_back(action); } */ CXMLTreeNode l_XML; if (l_XML.LoadFile(path.c_str())) { CXMLTreeNode l_Input = l_XML["input"]; if (l_Input.Exists()) { for (int i = 0; i < l_Input.GetNumChildren(); ++i) { CXMLTreeNode l_Action = l_Input(i); Action action = {}; action.name = l_Action.GetPszProperty("name"); std::string type = l_Action.GetPszProperty("type", "KEYBOARD"); action.inputType = ParseInputType(type); switch (action.inputType) { case Action::KEYBOARD: action.keyboard.mode = ParseMode(l_Action.GetPszProperty("mode", "ON_PRESS")); action.keyboard.key = l_Action.GetPszProperty("key", "A")[0]; action.keyboard.needsAlt = l_Action.GetBoolProperty("needs_alt", false, false); action.keyboard.needsCtrl = l_Action.GetBoolProperty("needs_ctrl", false, false); break; } m_Actions.push_back(action); } } } //*/ EndFrame(); }