Skip to content

Commit

Permalink
add option to disable mouse click input
Browse files Browse the repository at this point in the history
  • Loading branch information
fallahn committed Jul 9, 2024
1 parent 5954a55 commit 07c99ec
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 7 deletions.
4 changes: 2 additions & 2 deletions samples/golf/buildnumber.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#ifndef BUILD_NUMBER_H_
#define BUILD_NUMBER_H_

#define BUILDNUMBER 6767
#define BUILDNUMBER_STR "6767"
#define BUILDNUMBER 6771
#define BUILDNUMBER_STR "6771"

#endif /* BUILD_NUMBER_H_ */
5 changes: 5 additions & 0 deletions samples/golf/src/GolfGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,10 @@ void GolfGame::loadPreferences()
{
m_sharedData.useLensFlare = prop.getValue<bool>();
}
else if (name == "use_mouse_action")
{
m_sharedData.useMouseAction = prop.getValue<bool>();
}
}
}
}
Expand Down Expand Up @@ -1562,6 +1566,7 @@ void GolfGame::savePreferences()
cfg.addProperty("press_hold").setValue(m_sharedData.pressHold);
cfg.addProperty("use_tts").setValue(m_sharedData.useTTS);
cfg.addProperty("use_flare").setValue(m_sharedData.useLensFlare);
cfg.addProperty("use_mouse_action").setValue(m_sharedData.useMouseAction);
cfg.save(path);


Expand Down
2 changes: 1 addition & 1 deletion samples/golf/src/golf/InputParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ void InputParser::handleEvent(const cro::Event& evt)
m_mouseWheel += evt.wheel.y;
}
else if (evt.type == SDL_MOUSEBUTTONDOWN
&& !Social::isSteamdeck())
&& m_sharedData.useMouseAction)
{
m_inputFlags |= InputFlag::Action;
}
Expand Down
1 change: 1 addition & 0 deletions samples/golf/src/golf/OptionsEnum.inl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ enum OptionsIndex
CtrlLB,
CtrlInvX,
CtrlInvY,
CtrlMouseAction,
CtrlVib,
CtrlAltPower,
CtrlSwg,
Expand Down
48 changes: 44 additions & 4 deletions samples/golf/src/golf/OptionsState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3038,6 +3038,7 @@ void OptionsState::buildControlMenu(cro::Entity parent, cro::Entity buttonEnt, c
auto mouseText = createText(glm::vec2(20.f, 96.f), st.str());
createText(glm::vec2(26.f, 63.f), "Invert X");
createText(glm::vec2(26.f, 47.f), "Invert Y");
createText(glm::vec2(26.f, 31.f), "Mouse Action");
createText(glm::vec2(112.f, 63.f), "Use Vibration");
createText(glm::vec2(112.f, 47.f), "Hold For Power");
createText(glm::vec2(112.f, 31.f), "Enable Swingput");
Expand Down Expand Up @@ -3365,7 +3366,7 @@ void OptionsState::buildControlMenu(cro::Entity parent, cro::Entity buttonEnt, c
entity.setLabel("With either trigger held, pull back on a thumbstick to charge the power.\nPush forward on the stick to make your shot. Timing is important!");
entity.getComponent<cro::UIInput>().setSelectionIndex(CtrlSwg);
entity.getComponent<cro::UIInput>().setNextIndex(CtrlRight, WindowAdvanced);
entity.getComponent<cro::UIInput>().setPrevIndex(CtrlReset, CtrlAltPower);
entity.getComponent<cro::UIInput>().setPrevIndex(CtrlMouseAction, CtrlAltPower);
entity.getComponent<cro::UIInput>().callbacks[cro::UIInput::ButtonDown] = uiSystem.addCallback(
[&](cro::Entity, cro::ButtonEvent evt) mutable
{
Expand Down Expand Up @@ -3401,7 +3402,7 @@ void OptionsState::buildControlMenu(cro::Entity parent, cro::Entity buttonEnt, c
entity = createSquareHighlight(glm::vec2(11.f, 38.f));
entity.setLabel("Invert the controller Y axis when in camera mode");
entity.getComponent<cro::UIInput>().setSelectionIndex(CtrlInvY);
entity.getComponent<cro::UIInput>().setNextIndex(CtrlAltPower, CtrlReset);
entity.getComponent<cro::UIInput>().setNextIndex(CtrlAltPower, CtrlMouseAction);
entity.getComponent<cro::UIInput>().setPrevIndex(CtrlB, CtrlInvX);
entity.getComponent<cro::UIInput>().callbacks[cro::UIInput::ButtonDown] = uiSystem.addCallback(
[&](cro::Entity e, cro::ButtonEvent evt) mutable
Expand Down Expand Up @@ -3435,17 +3436,56 @@ void OptionsState::buildControlMenu(cro::Entity parent, cro::Entity buttonEnt, c
parent.getComponent<cro::Transform>().addChild(entity.getComponent<cro::Transform>());


//enable mouse click for action button
entity = createSquareHighlight(glm::vec2(11.f, 22.f));
entity.setLabel("Allow using Left Mouse Button as Action Button");
entity.getComponent<cro::UIInput>().setSelectionIndex(CtrlMouseAction);
entity.getComponent<cro::UIInput>().setNextIndex(CtrlSwg, CtrlReset);
entity.getComponent<cro::UIInput>().setPrevIndex(CtrlSwg, CtrlInvY);
entity.getComponent<cro::UIInput>().callbacks[cro::UIInput::ButtonDown] = uiSystem.addCallback(
[&](cro::Entity e, cro::ButtonEvent evt) mutable
{
if (activated(evt))
{
m_sharedData.useMouseAction = !m_sharedData.useMouseAction;
m_audioEnts[AudioID::Back].getComponent<cro::AudioEmitter>().play();

m_scene.getActiveCamera().getComponent<cro::Camera>().active = true;
}
});

entity = m_scene.createEntity();
entity.addComponent<cro::Transform>().setPosition(glm::vec3(13.f, 24.f, HighlightOffset));
entity.addComponent<cro::Drawable2D>().getVertexData() =
{
cro::Vertex2D(glm::vec2(0.f, 7.f), TextGoldColour),
cro::Vertex2D(glm::vec2(0.f), TextGoldColour),
cro::Vertex2D(glm::vec2(7.f), TextGoldColour),
cro::Vertex2D(glm::vec2(7.f, 0.f), TextGoldColour)
};
entity.getComponent<cro::Drawable2D>().updateLocalBounds();
entity.addComponent<cro::Callback>().active = true;
entity.getComponent<cro::Callback>().function =
[&](cro::Entity e, float)
{
float scale = m_sharedData.useMouseAction ? 1.f : 0.f;
e.getComponent<cro::Transform>().setScale(glm::vec2(scale));
};
parent.getComponent<cro::Transform>().addChild(entity.getComponent<cro::Transform>());



//reset to defaults
entity = m_scene.createEntity();
entity.addComponent<cro::Transform>().setPosition(glm::vec3(32.f, 11.f, HighlightOffset));
entity.addComponent<cro::Transform>().setPosition(glm::vec3(32.f, -1.f, HighlightOffset));
entity.addComponent<cro::AudioEmitter>() = m_menuSounds.getEmitter("switch");
entity.addComponent<cro::Drawable2D>();
entity.addComponent<cro::Sprite>() = spriteSheet.getSprite("small_highlight");
entity.getComponent<cro::Sprite>().setColour(cro::Colour::Transparent);
entity.addComponent<cro::UIInput>().setGroup(MenuID::Controls);
entity.getComponent<cro::UIInput>().setSelectionIndex(CtrlReset);
entity.getComponent<cro::UIInput>().setNextIndex(CtrlSwg, WindowCredits);
entity.getComponent<cro::UIInput>().setPrevIndex(CtrlA, CtrlInvY);
entity.getComponent<cro::UIInput>().setPrevIndex(CtrlA, CtrlMouseAction);
auto bounds = entity.getComponent<cro::Sprite>().getTextureBounds();
entity.getComponent<cro::UIInput>().area = bounds;
entity.getComponent<cro::UIInput>().callbacks[cro::UIInput::Selected] = uiSystem.addCallback(
Expand Down
1 change: 1 addition & 0 deletions samples/golf/src/golf/SharedStateData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ struct SharedStateData final
bool pressHold = false; //press and hold the action button to select power
bool useTTS = false;
bool useLensFlare = true;
bool useMouseAction = true;

std::int32_t baseState = 0; //used to tell which state we're returning to from errors etc
std::unique_ptr<cro::ResourceCollection> sharedResources;
Expand Down

0 comments on commit 07c99ec

Please sign in to comment.