Skip to content

Commit

Permalink
enable support for multiple inputSchemes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bashar-Ahmed committed Jun 15, 2022
1 parent 61d9b37 commit 11d629d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
2 changes: 2 additions & 0 deletions rootex/core/input/input_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ void to_json(JSON::json& j, const InputScheme& s)
{
j["bools"] = s.bools;
j["floats"] = s.floats;
j["active"] = s.isActive;
}

void from_json(const JSON::json& j, InputScheme& s)
Expand All @@ -505,4 +506,5 @@ void from_json(const JSON::json& j, InputScheme& s)
InputDescription id = floatInput;
s.floats.push_back(id);
}
s.isActive = j.value("active",false);
}
1 change: 1 addition & 0 deletions rootex/core/input/input_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct InputScheme
{
Vector<InputDescription> bools;
Vector<InputDescription> floats;
bool isActive;
};

void to_json(JSON::json& j, const InputScheme& s);
Expand Down
27 changes: 18 additions & 9 deletions rootex/framework/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,17 @@ bool Scene::addChild(Ptr<Scene>& child)
if (findIt == m_ChildrenScenes.end())
{
child->m_ParentScene = this;
if (getID() != ROOT_SCENE_ID && getName() != "EditorCamera" && getName() != "EditorGrid")
{
for (auto&& inputScheme : child->getSettings().inputSchemes)
{
m_Settings.inputSchemes.insert(inputScheme);
}
}
m_ChildrenScenes.emplace_back(std::move(child));
ScriptSystem::GetSingleton()->addEnterScriptEntity(&m_ChildrenScenes.back()->getEntity());


}
else
{
Expand Down Expand Up @@ -493,13 +502,15 @@ void SceneSettings::draw()
ImGui::EndCombo();
}

ImGui::Text("Input Schemes");
ImGui::Text("Input Schemes:");
ImGui::Separator();
int i = 0;
const String* inputSchemeToRemove = nullptr;
for (auto& [name, inputScheme] : inputSchemes)
{
ImGui::PushID(i);

ImGui::Text(name.c_str());
ImGui::Checkbox("Active", &inputScheme.isActive);
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 100);
if (ImGui::ListBoxHeader(name.c_str()))
{
Expand Down Expand Up @@ -549,10 +560,6 @@ void SceneSettings::draw()

ImGui::ListBoxFooter();
}
if (ImGui::Button("Remove Scheme"))
{
inputSchemeToRemove = &name;
}

static int type = 0;
ImGui::Combo("Type", &type, "Bool\0Float\0");
Expand All @@ -573,8 +580,12 @@ void SceneSettings::draw()
inputScheme.floats.push_back(inputDesc);
}
}

if (ImGui::Button("Remove Scheme"))
{
inputSchemeToRemove = &name;
}
ImGui::PopID();
ImGui::Separator();
i++;
}

Expand All @@ -584,8 +595,6 @@ void SceneSettings::draw()
startScheme = "";
}

ImGui::Separator();

static String newSchemeName = "New Scheme";
ImGui::InputText("##New Scheme", &newSchemeName);
ImGui::SameLine();
Expand Down
8 changes: 7 additions & 1 deletion rootex/framework/systems/input_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ bool InputSystem::initialize(const JSON::json& systemData)
void InputSystem::setConfig(const SceneSettings& sceneSettings)
{
loadSchemes(sceneSettings.inputSchemes);
pushScheme(sceneSettings.startScheme);
for (auto&& inputScheme : sceneSettings.inputSchemes)
{
if (inputScheme.second.isActive)
{
pushScheme(inputScheme.first);
}
}
}

void InputSystem::update(float deltaMilliseconds)
Expand Down

0 comments on commit 11d629d

Please sign in to comment.