From 4dc9c0838ee717fcb524d634d05ad27594ac91b2 Mon Sep 17 00:00:00 2001 From: fallahn Date: Mon, 8 Apr 2024 10:55:21 +0100 Subject: [PATCH 01/24] update option menu to allow toggling Swingput --- libsocial/include/Social.hpp | 6 +- samples/golf/buildnumber.h | 4 +- samples/golf/src/GolfGame.cpp | 5 + samples/golf/src/golf/OptionsEnum.inl | 1 + samples/golf/src/golf/OptionsState.cpp | 53 +++++++++-- samples/golf/src/golf/SharedStateData.hpp | 1 + samples/golf/src/golf/Swingput.cpp | 111 +++++++++++----------- 7 files changed, 113 insertions(+), 68 deletions(-) diff --git a/libsocial/include/Social.hpp b/libsocial/include/Social.hpp index 7f12102a7..eb79e34f1 100644 --- a/libsocial/include/Social.hpp +++ b/libsocial/include/Social.hpp @@ -49,11 +49,11 @@ source distribution. //(ball started sending wind effect 1120 -> 1124) //(added night mode/weather 1141 -> 1150) //(player avatar data format changed 1153->1160) -static constexpr std::uint16_t CURRENT_VER = 1160; +static constexpr std::uint16_t CURRENT_VER = 1161; #ifdef __APPLE__ -static const std::string StringVer("1.16.0 (macOS beta)"); +static const std::string StringVer("1.16.1 (macOS beta)"); #else -static const std::string StringVer("1.16.0"); +static const std::string StringVer("1.16.1"); #endif struct HallEntry final diff --git a/samples/golf/buildnumber.h b/samples/golf/buildnumber.h index c9150065e..7109b3e31 100644 --- a/samples/golf/buildnumber.h +++ b/samples/golf/buildnumber.h @@ -3,7 +3,7 @@ #ifndef BUILD_NUMBER_H_ #define BUILD_NUMBER_H_ -#define BUILDNUMBER 5168 -#define BUILDNUMBER_STR "5168" +#define BUILDNUMBER 5172 +#define BUILDNUMBER_STR "5172" #endif /* BUILD_NUMBER_H_ */ diff --git a/samples/golf/src/GolfGame.cpp b/samples/golf/src/GolfGame.cpp index 93f813ea3..b1b146b26 100644 --- a/samples/golf/src/GolfGame.cpp +++ b/samples/golf/src/GolfGame.cpp @@ -1331,6 +1331,10 @@ void GolfGame::loadPreferences() { m_sharedData.useTTS = prop.getValue(); } + else if (name == "use_swingput") + { + m_sharedData.useSwingput = prop.getValue(); + } } } } @@ -1435,6 +1439,7 @@ void GolfGame::savePreferences() cfg.addProperty("fov").setValue(m_sharedData.fov); cfg.addProperty("vertex_snap").setValue(m_sharedData.vertexSnap); cfg.addProperty("mouse_speed").setValue(m_sharedData.mouseSpeed); + cfg.addProperty("use_swingput").setValue(m_sharedData.useSwingput); cfg.addProperty("invert_x").setValue(m_sharedData.invertX); cfg.addProperty("invert_y").setValue(m_sharedData.invertY); cfg.addProperty("show_beacon").setValue(m_sharedData.showBeacon); diff --git a/samples/golf/src/golf/OptionsEnum.inl b/samples/golf/src/golf/OptionsEnum.inl index 3f69cb32e..2538d960c 100644 --- a/samples/golf/src/golf/OptionsEnum.inl +++ b/samples/golf/src/golf/OptionsEnum.inl @@ -83,6 +83,7 @@ enum OptionsIndex CtrlInvY, CtrlVib, CtrlAltPower, + CtrlSwg, CtrlReset, CtrlDown, CtrlLeft, diff --git a/samples/golf/src/golf/OptionsState.cpp b/samples/golf/src/golf/OptionsState.cpp index 10c12278c..16b957b20 100644 --- a/samples/golf/src/golf/OptionsState.cpp +++ b/samples/golf/src/golf/OptionsState.cpp @@ -2855,7 +2855,7 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& entity = createHighlight(Positions[Highlight::AimRight], InputBinding::Right); entity.getComponent().setSelectionIndex(CtrlRight); entity.getComponent().setNextIndex(CtrlA, CtrlDown); - entity.getComponent().setPrevIndex(CtrlReset, CtrlRight); + entity.getComponent().setPrevIndex(CtrlAltPower, CtrlRight); entity.getComponent().callbacks[cro::UIInput::Selected] = uiSystem.addCallback( [&,infoEnt, buttonChangeEnt](cro::Entity e) mutable { @@ -2904,7 +2904,7 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& entity = createHighlight(Positions[Highlight::LowerCam], InputBinding::Down); entity.getComponent().setSelectionIndex(CtrlDown); entity.getComponent().setNextIndex(CtrlA, TabAchievements); - entity.getComponent().setPrevIndex(CtrlReset, CtrlRight); + entity.getComponent().setPrevIndex(CtrlSwg, CtrlRight); entity.getComponent().callbacks[cro::UIInput::Selected] = uiSystem.addCallback( [&, infoEnt, buttonChangeEnt](cro::Entity e) mutable { @@ -3163,6 +3163,7 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& createText(glm::vec2(32.f, 47.f), "Invert Y"); createText(glm::vec2(118.f, 63.f), "Use Vibration"); createText(glm::vec2(118.f, 47.f), "Hold For Power"); + createText(glm::vec2(118.f, 31.f), "Enable Swingput"); //TODO don't duplicate these as they already exist in the AV menu auto selectedID = uiSystem.addCallback([infoEnt](cro::Entity e) mutable @@ -3444,7 +3445,7 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& entity = createSquareHighlight(glm::vec2(103.f, 38.f)); entity.setLabel("When enabled press and hold Action to select stroke power\nelse use the default 2-tap method when disabled"); entity.getComponent().setSelectionIndex(CtrlAltPower); - entity.getComponent().setNextIndex(CtrlLeft, CtrlReset); + entity.getComponent().setNextIndex(CtrlRight, CtrlSwg); entity.getComponent().setPrevIndex(CtrlInvY, CtrlVib); entity.getComponent().callbacks[cro::UIInput::ButtonDown] = uiSystem.addCallback( [&](cro::Entity, cro::ButtonEvent evt) mutable @@ -3478,12 +3479,48 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& parent.getComponent().addChild(entity.getComponent()); + //swingput enable + entity = createSquareHighlight(glm::vec2(103.f, 22.f)); + entity.setLabel("Enables analogue swing with triggers and thumbstick.\n(EXPERIMENTAL) May cause frustration."); + entity.getComponent().setSelectionIndex(CtrlSwg); + entity.getComponent().setNextIndex(CtrlDown, WindowAdvanced); + entity.getComponent().setPrevIndex(CtrlReset, CtrlAltPower); + entity.getComponent().callbacks[cro::UIInput::ButtonDown] = uiSystem.addCallback( + [&](cro::Entity, cro::ButtonEvent evt) mutable + { + if (activated(evt)) + { + m_sharedData.useSwingput = !m_sharedData.useSwingput; + m_audioEnts[AudioID::Back].getComponent().play(); + + m_scene.getActiveCamera().getComponent().active = true; + } + }); + entity = m_scene.createEntity(); + entity.addComponent().setPosition(glm::vec3(105.f, 24.f, HighlightOffset)); + entity.addComponent().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().updateLocalBounds(); + entity.addComponent().active = true; + entity.getComponent().function = + [&](cro::Entity e, float) + { + float scale = m_sharedData.useSwingput ? 1.f : 0.f; + e.getComponent().setScale(glm::vec2(scale)); + }; + parent.getComponent().addChild(entity.getComponent()); + //invert Y entity = createSquareHighlight(glm::vec2(17.f, 38.f)); entity.setLabel("Invert the controller Y axis when playing Billiards"); entity.getComponent().setSelectionIndex(CtrlInvY); - entity.getComponent().setNextIndex(CtrlRight, WindowAdvanced); + entity.getComponent().setNextIndex(CtrlAltPower, CtrlReset); entity.getComponent().setPrevIndex(CtrlB, CtrlInvX); entity.getComponent().callbacks[cro::UIInput::ButtonDown] = uiSystem.addCallback( [&](cro::Entity e, cro::ButtonEvent evt) mutable @@ -3519,15 +3556,15 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& //reset to defaults entity = m_scene.createEntity(); - entity.addComponent().setPosition(glm::vec3(83.f, 11.f, HighlightOffset)); + entity.addComponent().setPosition(glm::vec3(38.f, 11.f, HighlightOffset)); entity.addComponent() = m_menuSounds.getEmitter("switch"); entity.addComponent(); entity.addComponent() = spriteSheet.getSprite("small_highlight"); entity.getComponent().setColour(cro::Colour::Transparent); entity.addComponent().setGroup(MenuID::Controls); entity.getComponent().setSelectionIndex(CtrlReset); - entity.getComponent().setNextIndex(CtrlDown, WindowCredits); - entity.getComponent().setPrevIndex(CtrlA, CtrlVib); + entity.getComponent().setNextIndex(CtrlSwg, WindowCredits); + entity.getComponent().setPrevIndex(CtrlA, CtrlInvY); auto bounds = entity.getComponent().getTextureBounds(); entity.getComponent().area = bounds; entity.getComponent().callbacks[cro::UIInput::Selected] = uiSystem.addCallback( @@ -4088,7 +4125,7 @@ void OptionsState::createButtons(cro::Entity parent, std::int32_t menuID, std::u downLeftB = TabAV; downRightA = TabAchievements; downRightB = TabStats; - upLeftA = CtrlInvY; + upLeftA = CtrlReset; upLeftB = CtrlReset; upRightA = CtrlA; upRightB = CtrlA; diff --git a/samples/golf/src/golf/SharedStateData.hpp b/samples/golf/src/golf/SharedStateData.hpp index 1700a6b1f..baaba7ea2 100644 --- a/samples/golf/src/golf/SharedStateData.hpp +++ b/samples/golf/src/golf/SharedStateData.hpp @@ -242,6 +242,7 @@ struct SharedStateData final bool vertexSnap = false; float mouseSpeed = 1.f; float swingputThreshold = 0.1f; + bool useSwingput = false; bool invertX = false; bool invertY = false; bool showBeacon = true; diff --git a/samples/golf/src/golf/Swingput.cpp b/samples/golf/src/golf/Swingput.cpp index 4751fd909..7c0e40f95 100644 --- a/samples/golf/src/golf/Swingput.cpp +++ b/samples/golf/src/golf/Swingput.cpp @@ -58,7 +58,7 @@ namespace Swingput::Swingput(const SharedStateData& sd) : m_sharedData (sd), - m_enabled (false), + m_enabled (-1), m_backPoint (0.f), m_activePoint (0.f), m_frontPoint (0.f), @@ -97,7 +97,8 @@ Swingput::Swingput(const SharedStateData& sd) //public bool Swingput::handleEvent(const cro::Event& evt) { - if (m_enabled == -1) + if (m_enabled == -1 + || !m_sharedData.useSwingput) { return false; } @@ -159,59 +160,59 @@ bool Swingput::handleEvent(const cro::Event& evt) //we allow either trigger or either stick //to aid handedness of players case SDL_CONTROLLERAXISMOTION: - //if (cro::GameController::controllerID(evt.caxis.which) == activeControllerID(m_enabled)) - //{ - // switch (evt.caxis.axis) - // { - // default: break; - // case SDL_CONTROLLER_AXIS_TRIGGERLEFT: - // case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: - // if (evt.caxis.value > MinTriggerMove) - // { - // startStroke(MaxControllerVelocity); - // } - // else - // { - // endStroke(); - // } - - // if (evt.caxis.axis == SDL_CONTROLLER_AXIS_TRIGGERLEFT) - // { - // m_lastLT = evt.caxis.value; - // } - // else - // { - // m_lastRT = evt.caxis.value; - // } - - // return (evt.caxis.value > MinTriggerMove); - // case SDL_CONTROLLER_AXIS_LEFTY: - // case SDL_CONTROLLER_AXIS_RIGHTY: - - // if (std::abs(evt.caxis.value) > MinStickMove) - // { - // if (m_state == State::Swing) - // { - // m_activePoint.y = std::pow((static_cast(-evt.caxis.value) / ControllerAxisRange), 7.f) * (MaxSwingputDistance / 2.f); - // return true; - // } - // } - // return false; - // case SDL_CONTROLLER_AXIS_LEFTX: - // case SDL_CONTROLLER_AXIS_RIGHTX: - // //just set this and we'll have - // //whichever value was present when - // //the swing is finished - - // if (std::abs(evt.caxis.value) > MinStickMove - // && m_state == State::Swing) - // { - // m_activePoint.x = (static_cast(evt.caxis.value) / ControllerAxisRange) * MaxAccuracy; - // return true; - // } - // return false; - // } - //} + if (cro::GameController::controllerID(evt.caxis.which) == activeControllerID(m_enabled)) + { + switch (evt.caxis.axis) + { + default: break; + case SDL_CONTROLLER_AXIS_TRIGGERLEFT: + case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: + if (evt.caxis.value > MinTriggerMove) + { + startStroke(MaxControllerVelocity); + } + else + { + endStroke(); + } + + if (evt.caxis.axis == SDL_CONTROLLER_AXIS_TRIGGERLEFT) + { + m_lastLT = evt.caxis.value; + } + else + { + m_lastRT = evt.caxis.value; + } + + return (evt.caxis.value > MinTriggerMove); + case SDL_CONTROLLER_AXIS_LEFTY: + case SDL_CONTROLLER_AXIS_RIGHTY: + + if (std::abs(evt.caxis.value) > MinStickMove) + { + if (m_state == State::Swing) + { + m_activePoint.y = std::pow((static_cast(-evt.caxis.value) / ControllerAxisRange), 7.f) * (MaxSwingputDistance / 2.f); + return true; + } + } + return false; + case SDL_CONTROLLER_AXIS_LEFTX: + case SDL_CONTROLLER_AXIS_RIGHTX: + //just set this and we'll have + //whichever value was present when + //the swing is finished + + if (std::abs(evt.caxis.value) > MinStickMove + && m_state == State::Swing) + { + m_activePoint.x = (static_cast(evt.caxis.value) / ControllerAxisRange) * MaxAccuracy; + return true; + } + return false; + } + } return isActive(); } From 7ad276ef4ea3c997c3a242966743d1a87c9973bd Mon Sep 17 00:00:00 2001 From: fallahn Date: Mon, 8 Apr 2024 11:47:24 +0100 Subject: [PATCH 02/24] read input from secondary controllers when only one local player exists --- samples/golf/buildnumber.h | 4 ++-- samples/golf/golf.aps | Bin 295000 -> 295000 bytes samples/golf/golf.rc | 8 ++++---- samples/golf/src/golf/GolfStateUI.cpp | 7 +++++-- samples/golf/src/golf/InputParser.cpp | 6 ++++-- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/samples/golf/buildnumber.h b/samples/golf/buildnumber.h index 7109b3e31..cfd7fb2ae 100644 --- a/samples/golf/buildnumber.h +++ b/samples/golf/buildnumber.h @@ -3,7 +3,7 @@ #ifndef BUILD_NUMBER_H_ #define BUILD_NUMBER_H_ -#define BUILDNUMBER 5172 -#define BUILDNUMBER_STR "5172" +#define BUILDNUMBER 5173 +#define BUILDNUMBER_STR "5173" #endif /* BUILD_NUMBER_H_ */ diff --git a/samples/golf/golf.aps b/samples/golf/golf.aps index be9df166b1cc04b3cef51d8324cef8a8a7a6a46a..bd62ffd017de6055c32e7e60fe0108c071675d08 100644 GIT binary patch delta 49 zcmcc7AatWasG)_ig{g&k3(LGJPDTa+21W)32FC5nt5}#B84b6uu4V}a(f?~$BAEei C8x7t7 delta 49 zcmcc7AatWasG)_ig{g&k3(LGJP6h@621W)T*uK1qg_)7jVEgK7mS7P5zlJ4}831n2 B4cY(z diff --git a/samples/golf/golf.rc b/samples/golf/golf.rc index 6912a1b3f..1788905ab 100644 --- a/samples/golf/golf.rc +++ b/samples/golf/golf.rc @@ -61,8 +61,8 @@ IDI_ICON1 ICON "icon.ico" // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,16,0,0 - PRODUCTVERSION 1,16,0,0 + FILEVERSION 1,16,1,0 + PRODUCTVERSION 1,16,1,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -79,12 +79,12 @@ BEGIN BEGIN VALUE "CompanyName", "Trederia" VALUE "FileDescription", "Super Video Golf" - VALUE "FileVersion", "1.16.0.0" + VALUE "FileVersion", "1.16.1.0" VALUE "InternalName", "golf.exe" VALUE "LegalCopyright", "Copyright (C) 2024 Trederia Games" VALUE "OriginalFilename", "golf.exe" VALUE "ProductName", "Super Video Golf" - VALUE "ProductVersion", "1.16.0.0" + VALUE "ProductVersion", "1.16.1.0" END END BLOCK "VarFileInfo" diff --git a/samples/golf/src/golf/GolfStateUI.cpp b/samples/golf/src/golf/GolfStateUI.cpp index 3adee342e..9024b2083 100644 --- a/samples/golf/src/golf/GolfStateUI.cpp +++ b/samples/golf/src/golf/GolfStateUI.cpp @@ -4870,7 +4870,8 @@ bool GolfState::EmoteWheel::handleEvent(const cro::Event& evt) else if (evt.type == SDL_CONTROLLERBUTTONDOWN) { auto controllerID = activeControllerID(sharedData.inputBinding.playerID); - if (cro::GameController::controllerID(evt.cbutton.which) == controllerID) + if (cro::GameController::controllerID(evt.cbutton.which) == controllerID + || sharedData.localConnectionData.playerCount == 1) { switch (evt.cbutton.button) { @@ -4915,7 +4916,9 @@ bool GolfState::EmoteWheel::handleEvent(const cro::Event& evt) } else if (evt.type == SDL_CONTROLLERBUTTONUP) { - auto controllerID = activeControllerID(sharedData.inputBinding.playerID); + //the controller ID is actually used to select the play name in this case + auto controllerID = activeControllerID(sharedData.localConnectionData.playerCount == 1 ? 0 : + sharedData.inputBinding.playerID); /*if (cro::GameController::controllerID(evt.cbutton.which) == controllerID) { diff --git a/samples/golf/src/golf/InputParser.cpp b/samples/golf/src/golf/InputParser.cpp index d568655c8..708e277d3 100644 --- a/samples/golf/src/golf/InputParser.cpp +++ b/samples/golf/src/golf/InputParser.cpp @@ -251,7 +251,8 @@ void InputParser::handleEvent(const cro::Event& evt) { auto controllerID = activeControllerID(m_inputBinding.playerID); if (!m_isCPU && - evt.cbutton.which == cro::GameController::deviceID(controllerID)) + (evt.cbutton.which == cro::GameController::deviceID(controllerID) + || m_sharedData.localConnectionData.playerCount == 1)) //allow input from any controller if only one local player { if (evt.cbutton.button == m_inputBinding.buttons[InputBinding::Action]) { @@ -304,7 +305,8 @@ void InputParser::handleEvent(const cro::Event& evt) { auto controllerID = activeControllerID(m_inputBinding.playerID); if (!m_isCPU && - evt.cbutton.which == cro::GameController::deviceID(controllerID)) + (evt.cbutton.which == cro::GameController::deviceID(controllerID) + || m_sharedData.localConnectionData.playerCount == 1)) { if (evt.cbutton.button == m_inputBinding.buttons[InputBinding::Action]) { From 098e2144732f573e01aca38f2faef49cc55cc140 Mon Sep 17 00:00:00 2001 From: fallahn Date: Mon, 8 Apr 2024 15:06:03 +0100 Subject: [PATCH 03/24] allow zooming minimap with kp multiply --- crogine/src/core/App.cpp | 4 +- samples/golf/buildnumber.h | 4 +- samples/golf/src/golf/GolfState.cpp | 19 +++++++- samples/golf/src/golf/GolfState.hpp | 1 + samples/golf/src/golf/GolfStateUI.cpp | 65 +++++++++++++++++++++++++-- 5 files changed, 84 insertions(+), 9 deletions(-) diff --git a/crogine/src/core/App.cpp b/crogine/src/core/App.cpp index 437883aa9..30e087122 100644 --- a/crogine/src/core/App.cpp +++ b/crogine/src/core/App.cpp @@ -271,7 +271,9 @@ App::App(std::uint32_t styleFlags) m_instance = this; //maps the steam deck rear buttons to the controller paddles - auto mapResult = SDL_GameControllerAddMapping("03000000de2800000512000011010000,Steam Deck,platform:Linux,crc:17f6,a:b3,b:b4,x:b5,y:b6,back:b11,guide:b13,start:b12,leftstick:b14,rightstick:b15,leftshoulder:b7,rightshoulder:b8,dpup:b16,dpdown:b17,dpleft:b18,dpright:b19,misc1:b2,paddle1:b21,paddle2:b20,paddle3:b23,paddle4:b22,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a9,righttrigger:a8,"); + //auto mapResult = SDL_GameControllerAddMapping("03000000de2800000512000011010000,Steam Deck,platform:Linux,crc:17f6,a:b3,b:b4,x:b5,y:b6,back:b11,guide:b13,start:b12,leftstick:b14,rightstick:b15,leftshoulder:b7,rightshoulder:b8,dpup:b16,dpdown:b17,dpleft:b18,dpright:b19,misc1:b2,paddle1:b21,paddle2:b20,paddle3:b23,paddle4:b22,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a9,righttrigger:a8"); + auto mapResult = SDL_GameControllerAddMapping("03000000de2800000512000011010000,Steam Deck,a:b3,b:b4,back:b11,dpdown:b17,dpleft:b18,dpright:b19,dpup:b16,guide:b13,leftshoulder:b7,leftstick:b14,lefttrigger:a9,leftx:a0,lefty:a1,misc1:b2,paddle1:b21,paddle2:b20,paddle3:b23,paddle4:b22,rightshoulder:b8,rightstick:b15,righttrigger:a8,rightx:a2,righty:a3,start:b12,x:b5,y:b6,platform:Linux"); + //auto mapResult = SDL_GameControllerAddMapping("03000000de2800000512000010010000,Steam Deck,a:b3,b:b4,back:b11,dpdown:b17,dpleft:b18,dpright:b19,dpup:b16,guide:b13,leftshoulder:b7,leftstick:b14,lefttrigger:a9,leftx:a0,lefty:a1,rightshoulder:b8,rightstick:b15,righttrigger:a8,rightx:a2,righty:a3,start:b12,x:b5,y:b6,platform:Linux"); if (mapResult == -1) { LogE << SDL_GetError() << std::endl; diff --git a/samples/golf/buildnumber.h b/samples/golf/buildnumber.h index cfd7fb2ae..4571c2ceb 100644 --- a/samples/golf/buildnumber.h +++ b/samples/golf/buildnumber.h @@ -3,7 +3,7 @@ #ifndef BUILD_NUMBER_H_ #define BUILD_NUMBER_H_ -#define BUILDNUMBER 5173 -#define BUILDNUMBER_STR "5173" +#define BUILDNUMBER 5190 +#define BUILDNUMBER_STR "5190" #endif /* BUILD_NUMBER_H_ */ diff --git a/samples/golf/src/golf/GolfState.cpp b/samples/golf/src/golf/GolfState.cpp index 0c8bb0b07..153d7fa7f 100644 --- a/samples/golf/src/golf/GolfState.cpp +++ b/samples/golf/src/golf/GolfState.cpp @@ -429,12 +429,22 @@ bool GolfState::handleEvent(const cro::Event& evt) } }; + const auto toggleMiniZoom = [&]() + { + auto& [_, dir] = m_mapRoot.getComponent().getUserData>(); + dir = (dir == 0) ? 1 : 0; + m_mapRoot.getComponent().active = true; + }; + if (evt.type == SDL_KEYUP) { //hideMouse(); //TODO this should only react to current keybindings switch (evt.key.keysym.sym) { default: break; + case SDLK_KP_MULTIPLY: + toggleMiniZoom(); + break; case SDLK_2: if (!m_textChat.isVisible() && !m_holeData[m_currentHole].puttFromTee) @@ -721,9 +731,14 @@ bool GolfState::handleEvent(const cro::Event& evt) switch (evt.cbutton.button) { default: break; - case cro::GameController::ButtonLeftStick: + case cro::GameController::ButtonRightStick: + //can't use sticks because they are used on the emote wheel //showMapOverview(); break; + case cro::GameController::ButtonTrackpad: + case cro::GameController::PaddleR5: + toggleMiniZoom(); + break; case cro::GameController::ButtonBack: if (!m_textChat.isVisible()) { @@ -744,7 +759,7 @@ bool GolfState::handleEvent(const cro::Event& evt) case cro::GameController::ButtonA: toggleQuitReady(); break; - case cro::GameController::ButtonTrackpad: + //case cro::GameController::ButtonTrackpad: case cro::GameController::PaddleR4: m_textChat.toggleWindow(true, true); break; diff --git a/samples/golf/src/golf/GolfState.hpp b/samples/golf/src/golf/GolfState.hpp index d85b1ba81..863c4a8f5 100644 --- a/samples/golf/src/golf/GolfState.hpp +++ b/samples/golf/src/golf/GolfState.hpp @@ -543,6 +543,7 @@ class GolfState final : public cro::State, public cro::GuiClient, public cro::Co //----------- cro::Entity m_mapCam; + cro::Entity m_mapRoot; cro::RenderTexture m_mapTexture; cro::MultiRenderTexture m_mapTextureMRT; //hack to create images for map explorer diff --git a/samples/golf/src/golf/GolfStateUI.cpp b/samples/golf/src/golf/GolfStateUI.cpp index 9024b2083..826e88c2a 100644 --- a/samples/golf/src/golf/GolfStateUI.cpp +++ b/samples/golf/src/golf/GolfStateUI.cpp @@ -997,7 +997,7 @@ void GolfState::buildUI() float textureRatio = 1.f; //pixels per metre in the minimap texture * 2 }; entity = m_uiScene.createEntity(); - entity.addComponent().setPosition({ 0.f, 82.f }); + entity.addComponent();// .setPosition({ 0.f, 82.f }); entity.getComponent().setRotation(-90.f * cro::Util::Const::degToRad); entity.getComponent().setOrigin({ 0.f, 0.f, 0.1f }); entity.getComponent().setScale(glm::vec2(0.05f, 0.f)); @@ -1120,7 +1120,64 @@ void GolfState::buildUI() } e.getComponent().setScale(glm::vec2(1.f / ratio, newScale / ratio)); }; - infoEnt.getComponent().addChild(entity.getComponent()); + + m_mapRoot = m_uiScene.createEntity(); + m_mapRoot.addComponent().addChild(entity.getComponent()); + m_mapRoot.addComponent().setUserData>(0.f, 1); + m_mapRoot.getComponent().function = + [](cro::Entity e, float dt) + { + auto& [progress, dir] = e.getComponent().getUserData>(); + if (dir == 0) + { + //bigger + progress = std::min(1.f, progress + (dt * 8.f)); + if (progress == 1) + { + e.getComponent().active = false; + } + } + else + { + progress = std::max(0.f, progress - (dt * 8.f)); + if (progress == 0) + { + e.getComponent().active = false; + } + } + + static constexpr glm::vec2 offset(0.5299f, 0.84799f); //1/8 map size, rotated 90deg, normalised + static constexpr float l = 47.167f;// glm::length(offset); //aww no constexpr + + const auto p = cro::Util::Easing::easeOutExpo(progress); + auto o = offset * l * p; + o.x = std::round(o.x); + o.y = std::round(o.y); + + e.getComponent().setScale(glm::vec2(1.f + p)); + e.getComponent().setOrigin(o); + }; + + + /*registerWindow([&]() + { + if (ImGui::Begin("Zoom")) + { + static float scale = 1.f; + + + if (ImGui::SliderFloat("Scale", &scale, 1.f, 2.f)) + { + m_mapRoot.getComponent().setScale(glm::vec2(scale)); + m_mapRoot.getComponent().setOrigin(offset * (scale - 1.f)); + } + + + } + ImGui::End(); + });*/ + + infoEnt.getComponent().addChild(m_mapRoot.getComponent()); auto mapEnt = entity; m_minimapEnt = entity; @@ -1457,7 +1514,7 @@ void GolfState::buildUI() //callback for the UI camera when window is resized - auto updateView = [&, trophyEnt, courseEnt, infoEnt, spinEnt, windEnt, windEnt2, mapEnt, greenEnt, rootNode](cro::Camera& cam) mutable + auto updateView = [&, trophyEnt, courseEnt, infoEnt, spinEnt, windEnt, windEnt2, greenEnt, rootNode](cro::Camera& cam) mutable { auto size = glm::vec2(GolfGame::getActiveTarget()->getSize()); cam.setOrthographic(0.f, size.x, 0.f, size.y, -3.5f, 20.f); @@ -1480,7 +1537,7 @@ void GolfState::buildUI() const auto uiSize = size / m_viewScale; auto mapSize = glm::vec2(MapSize / 2u); mapSize /= 2.f; - mapEnt.getComponent().setPosition({ uiSize.x - mapSize.y - 2.f, uiSize.y - mapSize.x - (UIBarHeight + 2.f), -0.05f }); //map sprite is rotated 90 + m_mapRoot.getComponent().setPosition({ uiSize.x - mapSize.y - 2.f, uiSize.y - mapSize.x - (UIBarHeight + 2.f), -0.05f }); //map sprite is rotated 90 greenEnt.getComponent().setPosition({ 2.f, uiSize.y - std::floor(MapSize.y * 0.6f) - UIBarHeight - 2.f, 0.1f }); From 24d2a1b33fa22cf0ee8df05c15d7bd5ee1f2286c Mon Sep 17 00:00:00 2001 From: fallahn Date: Tue, 9 Apr 2024 09:31:04 +0100 Subject: [PATCH 04/24] change keybind for minimap zoom --- samples/golf/buildnumber.h | 4 ++-- samples/golf/src/golf/GolfState.cpp | 5 +---- samples/golf/src/golf/OptionsState.cpp | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/samples/golf/buildnumber.h b/samples/golf/buildnumber.h index 4571c2ceb..4ad67fb9b 100644 --- a/samples/golf/buildnumber.h +++ b/samples/golf/buildnumber.h @@ -3,7 +3,7 @@ #ifndef BUILD_NUMBER_H_ #define BUILD_NUMBER_H_ -#define BUILDNUMBER 5190 -#define BUILDNUMBER_STR "5190" +#define BUILDNUMBER 5191 +#define BUILDNUMBER_STR "5191" #endif /* BUILD_NUMBER_H_ */ diff --git a/samples/golf/src/golf/GolfState.cpp b/samples/golf/src/golf/GolfState.cpp index 153d7fa7f..d41cab29a 100644 --- a/samples/golf/src/golf/GolfState.cpp +++ b/samples/golf/src/golf/GolfState.cpp @@ -489,10 +489,7 @@ bool GolfState::handleEvent(const cro::Event& evt) closeMessage(); break; case SDLK_F6: - //logCSV(); - /*m_activeAvatar->model.getComponent().active = true; - m_activeAvatar->model.getComponent().setHidden(false);*/ - //m_sharedData.clientConnection.netClient.sendPacket(PacketID::ServerCommand, std::uint16_t(ServerCommand::NextHole), net::NetFlag::Reliable); + toggleMiniZoom(); break; case SDLK_F8: if (evt.key.keysym.mod & KMOD_SHIFT) diff --git a/samples/golf/src/golf/OptionsState.cpp b/samples/golf/src/golf/OptionsState.cpp index 16b957b20..ab8bd1958 100644 --- a/samples/golf/src/golf/OptionsState.cpp +++ b/samples/golf/src/golf/OptionsState.cpp @@ -3481,7 +3481,7 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& //swingput enable entity = createSquareHighlight(glm::vec2(103.f, 22.f)); - entity.setLabel("Enables analogue swing with triggers and thumbstick.\n(EXPERIMENTAL) May cause frustration."); + entity.setLabel("Enables analogue swing with triggers and thumbstick.\n(EXPERIMENTAL) May cause some frustration."); entity.getComponent().setSelectionIndex(CtrlSwg); entity.getComponent().setNextIndex(CtrlDown, WindowAdvanced); entity.getComponent().setPrevIndex(CtrlReset, CtrlAltPower); From 084375aa701e6366654b7c7532cfd14d149a1a2f Mon Sep 17 00:00:00 2001 From: fallahn Date: Tue, 9 Apr 2024 13:37:08 +0100 Subject: [PATCH 05/24] re-write swingput for mouse control --- samples/golf/buildnumber.h | 4 +- samples/golf/src/golf/DrivingStateUI.cpp | 2 +- samples/golf/src/golf/GolfState.cpp | 9 +- samples/golf/src/golf/GolfStateUI.cpp | 2 +- samples/golf/src/golf/InputBinding.hpp | 2 + samples/golf/src/golf/InputParser.cpp | 45 +++-- samples/golf/src/golf/InputParser.hpp | 4 +- samples/golf/src/golf/Swingput.cpp | 234 ++++++++++++----------- samples/golf/src/golf/Swingput.hpp | 29 +-- 9 files changed, 173 insertions(+), 158 deletions(-) diff --git a/samples/golf/buildnumber.h b/samples/golf/buildnumber.h index 4ad67fb9b..9d6890848 100644 --- a/samples/golf/buildnumber.h +++ b/samples/golf/buildnumber.h @@ -3,7 +3,7 @@ #ifndef BUILD_NUMBER_H_ #define BUILD_NUMBER_H_ -#define BUILDNUMBER 5191 -#define BUILDNUMBER_STR "5191" +#define BUILDNUMBER 5214 +#define BUILDNUMBER_STR "5214" #endif /* BUILD_NUMBER_H_ */ diff --git a/samples/golf/src/golf/DrivingStateUI.cpp b/samples/golf/src/golf/DrivingStateUI.cpp index ac000d3b2..c4efd8adc 100644 --- a/samples/golf/src/golf/DrivingStateUI.cpp +++ b/samples/golf/src/golf/DrivingStateUI.cpp @@ -807,7 +807,7 @@ void DrivingState::createUI() cam.viewport = { 0.f, 0.f, 1.f, 1.f }; m_viewScale = glm::vec2(getViewScale()); - m_inputParser.setMouseScale(m_viewScale.x); + //m_inputParser.setMouseScale(m_viewScale.x); glm::vec2 courseScale(m_sharedData.pixelScale ? m_viewScale.x : 1.f); diff --git a/samples/golf/src/golf/GolfState.cpp b/samples/golf/src/golf/GolfState.cpp index d41cab29a..078dfceba 100644 --- a/samples/golf/src/golf/GolfState.cpp +++ b/samples/golf/src/golf/GolfState.cpp @@ -800,7 +800,14 @@ bool GolfState::handleEvent(const cro::Event& evt) } else if (evt.type == SDL_MOUSEBUTTONDOWN) { - if (evt.button.button == SDL_BUTTON_RIGHT) + if (evt.button.button == SDL_BUTTON_LEFT) + { + toggleQuitReady(); + } + } + else if (evt.type == SDL_MOUSEBUTTONUP) + { + if (evt.button.button == SDL_BUTTON_LEFT) { closeMessage(); } diff --git a/samples/golf/src/golf/GolfStateUI.cpp b/samples/golf/src/golf/GolfStateUI.cpp index 826e88c2a..1367a7209 100644 --- a/samples/golf/src/golf/GolfStateUI.cpp +++ b/samples/golf/src/golf/GolfStateUI.cpp @@ -1521,7 +1521,7 @@ void GolfState::buildUI() cam.viewport = { 0.f, 0.f, 1.f, 1.f }; m_viewScale = glm::vec2(getViewScale()); - m_inputParser.setMouseScale(m_viewScale.x); + //m_inputParser.setMouseScale(m_viewScale.x); glm::vec2 courseScale(m_sharedData.pixelScale ? m_viewScale.x : 1.f); diff --git a/samples/golf/src/golf/InputBinding.hpp b/samples/golf/src/golf/InputBinding.hpp index 253b7100b..e12eb9b0b 100644 --- a/samples/golf/src/golf/InputBinding.hpp +++ b/samples/golf/src/golf/InputBinding.hpp @@ -53,6 +53,8 @@ namespace InputFlag CamModifier = SpinMenu, SwitchView = EmoteWheel, + Swingput = 0x400, + All = 0xFFFF }; } diff --git a/samples/golf/src/golf/InputParser.cpp b/samples/golf/src/golf/InputParser.cpp index 708e277d3..2d69585b0 100644 --- a/samples/golf/src/golf/InputParser.cpp +++ b/samples/golf/src/golf/InputParser.cpp @@ -139,7 +139,7 @@ void InputParser::handleEvent(const cro::Event& evt) }; if (m_active && - !m_swingput.handleEvent(evt)) + !m_swingput.handleEvent(evt, m_inputFlags, static_cast(m_state))) { //apply to input mask if (evt.type == SDL_KEYDOWN @@ -849,19 +849,6 @@ void InputParser::updateStroke(float dt) if (m_active) { - if (m_swingput.process(dt)) - { - //we took our shot - m_power = m_swingput.getPower(); - m_hook = m_swingput.getHook(); - - m_powerbarDirection = 1.f; - m_state = State::Flight; - - auto* msg = cro::App::postMessage(MessageID::GolfMessage); - msg->type = GolfEvent::HitBall; - } - m_inputFlags &= m_enableFlags; switch (m_state) @@ -974,7 +961,8 @@ void InputParser::updateStroke(float dt) m_powerbarDirection = -1.f; } - if (m_sharedData.pressHold) + if (m_sharedData.pressHold + && ((m_inputFlags & InputFlag::Swingput) == 0)) { if ((m_inputFlags & InputFlag::Action) == 0 && (m_prevFlags & InputFlag::Action)) { @@ -993,9 +981,23 @@ void InputParser::updateStroke(float dt) { m_powerbarDirection = 1.f; - m_state = State::Stroke; - m_doubleTapClock.restart(); - beginIcon(); + if (m_inputFlags & InputFlag::Swingput) + { + //take shot immediately + m_state = State::Flight; + m_hook = m_swingput.getHook(); + + auto* msg = cro::App::postMessage(MessageID::GolfMessage); + msg->type = GolfEvent::HitBall; + + //TODO read hook value from swingput + } + else + { + m_state = State::Stroke; + m_doubleTapClock.restart(); + beginIcon(); + } } } } @@ -1076,6 +1078,13 @@ void InputParser::updateStroke(float dt) } } + //if the input is flagged as being from the swingput, + //automatically reset the flag as if the button was released + if ((m_inputFlags & InputFlag::Swingput) != 0) + { + m_inputFlags &= ~(InputFlag::Action | InputFlag::Swingput); + } + m_prevDisabledFlags = disabledFlags; } diff --git a/samples/golf/src/golf/InputParser.hpp b/samples/golf/src/golf/InputParser.hpp index bf8b7f1cf..656fc0cff 100644 --- a/samples/golf/src/golf/InputParser.hpp +++ b/samples/golf/src/golf/InputParser.hpp @@ -78,8 +78,8 @@ class InputParser final bool isAiming() const { return m_state == InputParser::State::Aim; } bool isSwingputActive() const { return m_swingput.isActive() && m_state != State::Drone; } - float getSwingputPosition() const { return m_swingput.getActivePoint().y; } - void setMouseScale(float scale) { CRO_ASSERT(scale > 0, ""); m_swingput.setMouseScale(scale); } + float getSwingputPosition() const { return m_swingput.getGaugePosition(); } + //void setMouseScale(float scale) { CRO_ASSERT(scale > 0, ""); m_swingput.setMouseScale(scale); } void setMaxRotation(float); float getMaxRotation() const { return m_maxRotation; } diff --git a/samples/golf/src/golf/Swingput.cpp b/samples/golf/src/golf/Swingput.cpp index 7c0e40f95..8d874e8ea 100644 --- a/samples/golf/src/golf/Swingput.cpp +++ b/samples/golf/src/golf/Swingput.cpp @@ -1,6 +1,6 @@ /*----------------------------------------------------------------------- -Matt Marchant 2022 +Matt Marchant 2022 - 2024 http://trederia.blogspot.com Super Video Golf - zlib licence. @@ -28,6 +28,7 @@ source distribution. -----------------------------------------------------------------------*/ #include "Swingput.hpp" +#include "InputBinding.hpp" #include "GameConsts.hpp" #include "SharedStateData.hpp" @@ -46,29 +47,42 @@ namespace }debugOutput; #endif - constexpr float MaxControllerVelocity = 3000.f; - constexpr float MaxMouseVelocity = 1700.f; - constexpr float MaxAccuracy = 20.f; + //constexpr float MaxControllerVelocity = 3000.f; + //constexpr float MaxMouseVelocity = 1700.f; + //constexpr float MaxAccuracy = 20.f; //constexpr float CommitDistance = 4.f;// 0.01f; //TODO make this user variable - constexpr float ControllerAxisRange = 32767.f; + //constexpr float ControllerAxisRange = 32767.f; + //constexpr std::int16_t MinStickMove = 8000; + + //these we do use constexpr std::int16_t MinTriggerMove = 16000; - constexpr std::int16_t MinStickMove = 8000; + + constexpr std::int32_t MaxMouseDraw = 20; + constexpr std::int32_t MaxMouseSwing = -20; + constexpr std::int32_t MaxMouseHook = 120; + + constexpr std::int16_t MaxControllerDraw = (std::numeric_limits::max() / 3) * 2; + constexpr std::int16_t MaxControllerSwing = -std::numeric_limits::max() / 2; + + //horrible hack to match up with InputParser::State + struct StateID final + { + enum + { + Aim, Power + }; + }; } Swingput::Swingput(const SharedStateData& sd) : m_sharedData (sd), m_enabled (-1), - m_backPoint (0.f), - m_activePoint (0.f), - m_frontPoint (0.f), - m_power (0.f), + m_mouseMovement (0), m_hook (0.f), - m_maxVelocity (1.f), - m_mouseScale (1.f), + m_gaugePosition (0.f), m_lastLT (0), - m_lastRT (0), - m_elapsedTime (0.f) + m_lastRT (0) { #ifdef CRO_DEBUG_ //registerWindow([&]() @@ -95,7 +109,7 @@ Swingput::Swingput(const SharedStateData& sd) } //public -bool Swingput::handleEvent(const cro::Event& evt) +bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std::int32_t state) { if (m_enabled == -1 || !m_sharedData.useSwingput) @@ -103,20 +117,16 @@ bool Swingput::handleEvent(const cro::Event& evt) return false; } - const auto startStroke = [&](float maxVelocity) + const auto startStroke = [&]() { if (m_state == State::Inactive && (m_lastLT < MinTriggerMove) && (m_lastRT < MinTriggerMove)) { m_state = State::Swing; - m_backPoint = { 0.f, 0.f }; - m_activePoint = { 0.f, 0.f }; - m_frontPoint = { 0.f, 0.f }; - m_power = 0.f; + m_mouseMovement = { 0,0 }; m_hook = 0.f; - - m_maxVelocity = maxVelocity; + m_gaugePosition = 0.f; cro::App::getWindow().setMouseCaptured(true); } @@ -125,7 +135,6 @@ bool Swingput::handleEvent(const cro::Event& evt) const auto endStroke = [&]() { m_state = State::Inactive; - m_activePoint = { 0.f, 0.f }; }; switch (evt.type) @@ -134,7 +143,7 @@ bool Swingput::handleEvent(const cro::Event& evt) case SDL_MOUSEBUTTONDOWN: if (evt.button.button == SDL_BUTTON_RIGHT) { - startStroke(MaxMouseVelocity); + startStroke(); return true; } return false; @@ -147,13 +156,45 @@ bool Swingput::handleEvent(const cro::Event& evt) return false; case SDL_MOUSEMOTION: //TODO we need to scale this down relative to the game buffer size - switch (m_state) + //or use some sort of mouse sensitivity + if (m_state == State::Swing) { - default: break; - case State::Swing: - m_activePoint.x = std::clamp(m_activePoint.x + (static_cast(evt.motion.xrel) / 10.f/* / m_mouseScale*/), -MaxAccuracy, MaxAccuracy); - m_activePoint.y = std::clamp(m_activePoint.y - (static_cast(evt.motion.yrel)/* / m_mouseScale*/), -(MaxSwingputDistance / 2.f), MaxSwingputDistance / 2.f); - return true; + switch (state) + { + default: break; + case StateID::Aim: + if (evt.motion.yrel > 1) + { + //measure this then trigger action + //once a certain distance is met + m_mouseMovement.y += evt.motion.yrel; + if (m_mouseMovement.y > MaxMouseDraw) + { + inputFlags |= (InputFlag::Action | InputFlag::Swingput); + } + } + break; + case StateID::Power: + if (evt.motion.yrel < -4) + { + //measure the distance as it's travelled + //as well as the X axis for accuracy + m_mouseMovement.x += evt.motion.xrel; + m_mouseMovement.y += evt.motion.yrel; + + if (m_mouseMovement.y < MaxMouseSwing) + { + inputFlags |= (InputFlag::Action | InputFlag::Swingput); + m_hook = std::clamp(static_cast(m_mouseMovement.x) / MaxMouseHook, -1.f, 1.f); + m_hook += 1.f; + m_hook /= 2.f; + + m_state = State::Inactive; + } + } + break; + } + setGaugeFromMouse(); } return false; @@ -169,7 +210,7 @@ bool Swingput::handleEvent(const cro::Event& evt) case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: if (evt.caxis.value > MinTriggerMove) { - startStroke(MaxControllerVelocity); + startStroke(); } else { @@ -188,28 +229,42 @@ bool Swingput::handleEvent(const cro::Event& evt) return (evt.caxis.value > MinTriggerMove); case SDL_CONTROLLER_AXIS_LEFTY: case SDL_CONTROLLER_AXIS_RIGHTY: - - if (std::abs(evt.caxis.value) > MinStickMove) + if (m_state == State::Swing) { - if (m_state == State::Swing) + //one of the triggers is held + if (state == StateID::Aim) + { + //pulling back should create a button press - as this + //should more or less immediately change state to power + //we *shouldn't* get multiple presses. InputParser will + //reset these flags for us automatically. + if (evt.caxis.value > MaxControllerDraw) + { + inputFlags |= (InputFlag::Action | InputFlag::Swingput); + m_tempoTimer.restart(); + } + } + else if (state == StateID::Power) { - m_activePoint.y = std::pow((static_cast(-evt.caxis.value) / ControllerAxisRange), 7.f) * (MaxSwingputDistance / 2.f); - return true; + //pushing forward rapidly should create a button press + //the swingput flag should tell the InputParser to skip + //the accuracy stage... + if (evt.caxis.value < MaxControllerSwing) + { + //TODO measure the tempo of the swing and use it to set the accuracy + LogI << "Tempo is " << m_tempoTimer.restart() << std::endl; + + inputFlags |= (InputFlag::Action | InputFlag::Swingput); + m_state = State::Inactive; + } } + setGaugeFromController(evt.caxis.value); } + return false; case SDL_CONTROLLER_AXIS_LEFTX: case SDL_CONTROLLER_AXIS_RIGHTX: - //just set this and we'll have - //whichever value was present when - //the swing is finished - if (std::abs(evt.caxis.value) > MinStickMove - && m_state == State::Swing) - { - m_activePoint.x = (static_cast(evt.caxis.value) / ControllerAxisRange) * MaxAccuracy; - return true; - } return false; } } @@ -219,77 +274,34 @@ bool Swingput::handleEvent(const cro::Event& evt) return isActive(); } -bool Swingput::process(float) +void Swingput::setEnabled(std::int32_t enabled) { - switch (m_state) - { - default: break; - case State::Swing: - { - //moving down - if (m_activePoint.y < m_frontPoint.y) - { - m_backPoint = m_activePoint; - } - - //started moving back up so time the ascent - if (m_activePoint.y > m_backPoint.y - && m_frontPoint.y == m_backPoint.y) - { - m_timer.restart(); - } - - //we've done full stroke. - if (m_activePoint.y > (MaxSwingputDistance / 2.f) - /*CommitDistance*/m_sharedData.swingputThreshold) - { - m_state = State::Summarise; - m_elapsedTime = m_timer.restart(); - } + m_enabled = enabled; + m_lastLT = 0; + m_lastRT = 0; +} - m_frontPoint = m_activePoint; +//private +void Swingput::setGaugeFromMouse() +{ + //gauge id +/- MaxSwingputDistance / 2 + //but also INVERTED from the actual values *sigh* + float norm = 0.f; + if (m_mouseMovement.y > 0) + { + //draw + norm = std::min(1.f, static_cast(m_mouseMovement.y) / MaxMouseDraw) * -1.f; } - return false; - case State::Summarise: - m_state = State::Inactive; - -#ifdef CRO_DEBUG_ - debugOutput.distance = (m_frontPoint.y - m_backPoint.y); - debugOutput.velocity = debugOutput.distance / (m_elapsedTime + 0.0001f); //potential NaN - debugOutput.accuracy = (m_frontPoint.x - m_backPoint.x); - m_power = std::clamp(debugOutput.velocity / m_maxVelocity, 0.f, 1.f); - m_hook = std::clamp(debugOutput.accuracy / MaxAccuracy, -1.f, 1.f); - - //travelling a shorter distance doesn't imply lower - //velocity so we need to create a distance based modifier - float multiplier = debugOutput.distance / MaxSwingputDistance; - -#else - float distance = (m_frontPoint.y - m_backPoint.y); - float velocity = distance / (m_elapsedTime + 0.0001f); //potential NaN - float accuracy = (m_frontPoint.x - m_backPoint.x); - m_power = std::clamp(velocity / m_maxVelocity, 0.f, 1.f); - m_hook = std::clamp(accuracy / MaxAccuracy, -1.f, 1.f); - - //travelling a shorter distance doesn't imply lower - //velocity so we need to create a distance based modifier - float multiplier = distance / MaxSwingputDistance; -#endif - - //hmm have to double convert this because the input parser - //actually calcs it to 0-1 and converts back to -1 1 on return - m_hook += 1.f; - m_hook /= 2.f; - - m_power *= multiplier; - - return true; + else + { + //swing + norm = std::min(1.f, static_cast(m_mouseMovement.y) / MaxMouseSwing); } - return false; + m_gaugePosition = (MaxSwingputDistance / 2.f) * norm; } -void Swingput::setEnabled(std::int32_t enabled) +void Swingput::setGaugeFromController(std::int16_t position) { - m_enabled = enabled; - m_lastLT = 0; - m_lastRT = 0; + const float norm = (static_cast(position) / std::numeric_limits::max()) * -1.f; + m_gaugePosition = (MaxSwingputDistance / 2.f) * norm; } \ No newline at end of file diff --git a/samples/golf/src/golf/Swingput.hpp b/samples/golf/src/golf/Swingput.hpp index 11fa5fa19..b66e96797 100644 --- a/samples/golf/src/golf/Swingput.hpp +++ b/samples/golf/src/golf/Swingput.hpp @@ -44,24 +44,15 @@ class Swingput final : public cro::GuiClient explicit Swingput(const SharedStateData&); //returns true if this consumed the event - bool handleEvent(const cro::Event&); - - //returns true if the shot was taken and result - //is ready in power/hook - bool process(float); - + bool handleEvent(const cro::Event&, std::uint16_t& flags, std::int32_t state); bool isActive() const { return m_state != State::Inactive; } //set to -1 to deactivate, else current player ID void setEnabled(std::int32_t enabled); std::int32_t getEnabled() const { return m_enabled; } - float getPower() const { return m_power; } float getHook() const { return m_hook; } - - glm::vec2 getBackPoint() const { return m_backPoint; } - glm::vec2 getActivePoint() const { return m_activePoint; } - glm::vec2 getFrontPoint() const { return m_frontPoint; } + float getGaugePosition() const { return m_gaugePosition; } struct State final { @@ -76,21 +67,15 @@ class Swingput final : public cro::GuiClient }; std::int32_t getState() const { return m_state; } - void setMouseScale(float scale) { m_mouseScale = scale; } - private: const SharedStateData& m_sharedData; std::int32_t m_enabled; - glm::vec2 m_backPoint; - glm::vec2 m_activePoint; - glm::vec2 m_frontPoint; + glm::ivec2 m_mouseMovement; + cro::HiResTimer m_tempoTimer; - float m_power; float m_hook; - - float m_maxVelocity; //depends on controller or mouse input - float m_mouseScale; + float m_gaugePosition; std::int16_t m_lastLT; std::int16_t m_lastRT; @@ -101,6 +86,6 @@ class Swingput final : public cro::GuiClient "Inactive", "Swing", "Summarise" }; - cro::HiResTimer m_timer; - float m_elapsedTime; + void setGaugeFromMouse(); + void setGaugeFromController(std::int16_t); }; \ No newline at end of file From a100ea00c51a5f33629a4ea942fa8187b2b8711b Mon Sep 17 00:00:00 2001 From: fallahn Date: Tue, 9 Apr 2024 14:13:27 +0100 Subject: [PATCH 06/24] hook up sensitivity slider in options to swingput mouse control --- samples/golf/buildnumber.h | 4 ++-- samples/golf/src/golf/CommonConsts.hpp | 6 +++--- samples/golf/src/golf/OptionsState.cpp | 20 ++++++++++++-------- samples/golf/src/golf/SharedStateData.hpp | 2 +- samples/golf/src/golf/Swingput.cpp | 22 +++++++++++----------- samples/golf/src/golf/Swingput.hpp | 2 +- 6 files changed, 30 insertions(+), 26 deletions(-) diff --git a/samples/golf/buildnumber.h b/samples/golf/buildnumber.h index 9d6890848..88a4dfc47 100644 --- a/samples/golf/buildnumber.h +++ b/samples/golf/buildnumber.h @@ -3,7 +3,7 @@ #ifndef BUILD_NUMBER_H_ #define BUILD_NUMBER_H_ -#define BUILDNUMBER 5214 -#define BUILDNUMBER_STR "5214" +#define BUILDNUMBER 5219 +#define BUILDNUMBER_STR "5219" #endif /* BUILD_NUMBER_H_ */ diff --git a/samples/golf/src/golf/CommonConsts.hpp b/samples/golf/src/golf/CommonConsts.hpp index a078afa24..ba037e176 100644 --- a/samples/golf/src/golf/CommonConsts.hpp +++ b/samples/golf/src/golf/CommonConsts.hpp @@ -1,6 +1,6 @@ /*----------------------------------------------------------------------- -Matt Marchant 2021 - 2023 +Matt Marchant 2021 - 2024 http://trederia.blogspot.com Super Video Golf - zlib licence. @@ -54,8 +54,8 @@ namespace ConstVal static constexpr float MinMouseSpeed = 0.5f; static constexpr float MaxMouseSpeed = 2.f; - static constexpr float MinSwingputThresh = 0.2f; - static constexpr float MaxSwingputThresh = 10.f; + static constexpr float MinSwingputThresh = 0.1f; + static constexpr float MaxSwingputThresh = 2.f; static constexpr std::int32_t MaxProfiles = 64; static constexpr std::uint32_t MaxBalls = 64u; diff --git a/samples/golf/src/golf/OptionsState.cpp b/samples/golf/src/golf/OptionsState.cpp index ab8bd1958..713686edc 100644 --- a/samples/golf/src/golf/OptionsState.cpp +++ b/samples/golf/src/golf/OptionsState.cpp @@ -3151,7 +3151,7 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& }; std::stringstream ss; ss.precision(2); - ss << "Swingput Threshold " << m_sharedData.swingputThreshold; + ss << "Swingput Mouse Sensitivity " << m_sharedData.swingputThreshold; auto swingputText = createText(glm::vec2(20.f, 124.f), ss.str()); @@ -3244,7 +3244,7 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& std::stringstream ss; ss.precision(2); - ss << "Swingput Threshold " << m_sharedData.swingputThreshold; + ss << "Swingput Mouse Sensitivity " << m_sharedData.swingputThreshold; swingputText.getComponent().setString(ss.str()); }; swingputSlider.getComponent().function = @@ -3293,12 +3293,13 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& { if (activated(evt)) { + m_sharedData.swingputThreshold = std::max(ConstVal::MinSwingputThresh, m_sharedData.swingputThreshold - 0.1f); + std::stringstream ss; ss.precision(2); - ss << "Swingput Threshold " << m_sharedData.swingputThreshold; + ss << "Swingput Mouse Sensitivity " << m_sharedData.swingputThreshold; swingputText.getComponent().setString(ss.str()); - m_sharedData.swingputThreshold = std::max(ConstVal::MinSwingputThresh, m_sharedData.swingputThreshold - 0.6f); m_audioEnts[AudioID::Accept].getComponent().play(); } }); @@ -3313,12 +3314,13 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& { if (activated(evt)) { + m_sharedData.swingputThreshold = std::min(ConstVal::MaxSwingputThresh, m_sharedData.swingputThreshold + 0.1f); + std::stringstream ss; ss.precision(2); - ss << "Swingput Threshold " << m_sharedData.swingputThreshold; + ss << "Swingput Mouse Sensitivity " << m_sharedData.swingputThreshold; swingputText.getComponent().setString(ss.str()); - m_sharedData.swingputThreshold = std::min(ConstVal::MaxSwingputThresh, m_sharedData.swingputThreshold + 0.6f); m_audioEnts[AudioID::Back].getComponent().play(); } }); @@ -3334,12 +3336,13 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& { if (activated(evt)) { + m_sharedData.mouseSpeed = std::max(ConstVal::MinMouseSpeed, m_sharedData.mouseSpeed - 0.1f); + std::stringstream st; st.precision(2); st << "Look Speed (Billiards) " << m_sharedData.mouseSpeed; mouseText.getComponent().setString(st.str()); - m_sharedData.mouseSpeed = std::max(ConstVal::MinMouseSpeed, m_sharedData.mouseSpeed - 0.1f); m_audioEnts[AudioID::Accept].getComponent().play(); } }); @@ -3354,12 +3357,13 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& { if (activated(evt)) { + m_sharedData.mouseSpeed = std::min(ConstVal::MaxMouseSpeed, m_sharedData.mouseSpeed + 0.1f); + std::stringstream st; st.precision(2); st << "Look Speed (Billiards) " << m_sharedData.mouseSpeed; mouseText.getComponent().setString(st.str()); - m_sharedData.mouseSpeed = std::min(ConstVal::MaxMouseSpeed, m_sharedData.mouseSpeed + 0.1f); m_audioEnts[AudioID::Back].getComponent().play(); } }); diff --git a/samples/golf/src/golf/SharedStateData.hpp b/samples/golf/src/golf/SharedStateData.hpp index baaba7ea2..966635e33 100644 --- a/samples/golf/src/golf/SharedStateData.hpp +++ b/samples/golf/src/golf/SharedStateData.hpp @@ -241,7 +241,7 @@ struct SharedStateData final float fov = MinFOV; bool vertexSnap = false; float mouseSpeed = 1.f; - float swingputThreshold = 0.1f; + float swingputThreshold = 1.f; bool useSwingput = false; bool invertX = false; bool invertY = false; diff --git a/samples/golf/src/golf/Swingput.cpp b/samples/golf/src/golf/Swingput.cpp index 8d874e8ea..95e639a9d 100644 --- a/samples/golf/src/golf/Swingput.cpp +++ b/samples/golf/src/golf/Swingput.cpp @@ -58,9 +58,9 @@ namespace //these we do use constexpr std::int16_t MinTriggerMove = 16000; - constexpr std::int32_t MaxMouseDraw = 20; - constexpr std::int32_t MaxMouseSwing = -20; - constexpr std::int32_t MaxMouseHook = 120; + constexpr float MaxMouseDraw = 20.f; + constexpr float MaxMouseSwing = -20.f; + constexpr float MaxMouseHook = 120.f; constexpr std::int16_t MaxControllerDraw = (std::numeric_limits::max() / 3) * 2; constexpr std::int16_t MaxControllerSwing = -std::numeric_limits::max() / 2; @@ -124,7 +124,7 @@ bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std && (m_lastRT < MinTriggerMove)) { m_state = State::Swing; - m_mouseMovement = { 0,0 }; + m_mouseMovement = { 0.f,0.f }; m_hook = 0.f; m_gaugePosition = 0.f; @@ -167,7 +167,7 @@ bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std { //measure this then trigger action //once a certain distance is met - m_mouseMovement.y += evt.motion.yrel; + m_mouseMovement.y += static_cast(evt.motion.yrel) * m_sharedData.swingputThreshold; if (m_mouseMovement.y > MaxMouseDraw) { inputFlags |= (InputFlag::Action | InputFlag::Swingput); @@ -179,13 +179,13 @@ bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std { //measure the distance as it's travelled //as well as the X axis for accuracy - m_mouseMovement.x += evt.motion.xrel; - m_mouseMovement.y += evt.motion.yrel; + m_mouseMovement.x += static_cast(evt.motion.xrel); //hmm this is going to be dependent on screen resolution + m_mouseMovement.y += static_cast(evt.motion.yrel) * m_sharedData.swingputThreshold; if (m_mouseMovement.y < MaxMouseSwing) { inputFlags |= (InputFlag::Action | InputFlag::Swingput); - m_hook = std::clamp(static_cast(m_mouseMovement.x) / MaxMouseHook, -1.f, 1.f); + m_hook = std::clamp(m_mouseMovement.x / MaxMouseHook, -1.f, 1.f); m_hook += 1.f; m_hook /= 2.f; @@ -284,18 +284,18 @@ void Swingput::setEnabled(std::int32_t enabled) //private void Swingput::setGaugeFromMouse() { - //gauge id +/- MaxSwingputDistance / 2 + //gauge is +/- MaxSwingputDistance / 2 //but also INVERTED from the actual values *sigh* float norm = 0.f; if (m_mouseMovement.y > 0) { //draw - norm = std::min(1.f, static_cast(m_mouseMovement.y) / MaxMouseDraw) * -1.f; + norm = std::min(1.f, m_mouseMovement.y / MaxMouseDraw) * -1.f; } else { //swing - norm = std::min(1.f, static_cast(m_mouseMovement.y) / MaxMouseSwing); + norm = std::min(1.f, m_mouseMovement.y / MaxMouseSwing); } m_gaugePosition = (MaxSwingputDistance / 2.f) * norm; } diff --git a/samples/golf/src/golf/Swingput.hpp b/samples/golf/src/golf/Swingput.hpp index b66e96797..289c045e2 100644 --- a/samples/golf/src/golf/Swingput.hpp +++ b/samples/golf/src/golf/Swingput.hpp @@ -71,7 +71,7 @@ class Swingput final : public cro::GuiClient const SharedStateData& m_sharedData; std::int32_t m_enabled; - glm::ivec2 m_mouseMovement; + glm::vec2 m_mouseMovement; cro::HiResTimer m_tempoTimer; float m_hook; From 4a5c321a141f35d549edbdd4f3c29fb59f1a8ecc Mon Sep 17 00:00:00 2001 From: fallahn Date: Tue, 9 Apr 2024 22:23:16 +0100 Subject: [PATCH 07/24] polish up swingput with a controller --- samples/golf/buildnumber.h | 4 +- samples/golf/src/golf/InputParser.cpp | 6 +- samples/golf/src/golf/OptionsState.cpp | 2 +- samples/golf/src/golf/Swingput.cpp | 85 +++++++++++++++++--------- samples/golf/src/golf/Swingput.hpp | 1 + 5 files changed, 62 insertions(+), 36 deletions(-) diff --git a/samples/golf/buildnumber.h b/samples/golf/buildnumber.h index 88a4dfc47..2c119f16e 100644 --- a/samples/golf/buildnumber.h +++ b/samples/golf/buildnumber.h @@ -3,7 +3,7 @@ #ifndef BUILD_NUMBER_H_ #define BUILD_NUMBER_H_ -#define BUILDNUMBER 5219 -#define BUILDNUMBER_STR "5219" +#define BUILDNUMBER 5247 +#define BUILDNUMBER_STR "5247" #endif /* BUILD_NUMBER_H_ */ diff --git a/samples/golf/src/golf/InputParser.cpp b/samples/golf/src/golf/InputParser.cpp index 2d69585b0..77487c3bc 100644 --- a/samples/golf/src/golf/InputParser.cpp +++ b/samples/golf/src/golf/InputParser.cpp @@ -1,6 +1,6 @@ /*----------------------------------------------------------------------- -Matt Marchant 2021 - 2023 +Matt Marchant 2021 - 2024 http://trederia.blogspot.com Super Video Golf - zlib licence. @@ -383,7 +383,7 @@ void InputParser::handleEvent(const cro::Event& evt) }*/ } - else + else if ((m_inputFlags & InputFlag::Swingput) == 0) { m_inputFlags = 0; } @@ -1082,7 +1082,7 @@ void InputParser::updateStroke(float dt) //automatically reset the flag as if the button was released if ((m_inputFlags & InputFlag::Swingput) != 0) { - m_inputFlags &= ~(InputFlag::Action | InputFlag::Swingput); + m_inputFlags &= ~(InputFlag::Action | InputFlag::Cancel | InputFlag::Swingput); } m_prevDisabledFlags = disabledFlags; diff --git a/samples/golf/src/golf/OptionsState.cpp b/samples/golf/src/golf/OptionsState.cpp index 713686edc..cdc7634af 100644 --- a/samples/golf/src/golf/OptionsState.cpp +++ b/samples/golf/src/golf/OptionsState.cpp @@ -3485,7 +3485,7 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& //swingput enable entity = createSquareHighlight(glm::vec2(103.f, 22.f)); - entity.setLabel("Enables analogue swing with triggers and thumbstick.\n(EXPERIMENTAL) May cause some frustration."); + entity.setLabel("Enables analogue swing with triggers and thumbstick.\n(BETA)"); entity.getComponent().setSelectionIndex(CtrlSwg); entity.getComponent().setNextIndex(CtrlDown, WindowAdvanced); entity.getComponent().setPrevIndex(CtrlReset, CtrlAltPower); diff --git a/samples/golf/src/golf/Swingput.cpp b/samples/golf/src/golf/Swingput.cpp index 95e639a9d..11119c661 100644 --- a/samples/golf/src/golf/Swingput.cpp +++ b/samples/golf/src/golf/Swingput.cpp @@ -47,15 +47,6 @@ namespace }debugOutput; #endif - //constexpr float MaxControllerVelocity = 3000.f; - //constexpr float MaxMouseVelocity = 1700.f; - //constexpr float MaxAccuracy = 20.f; - //constexpr float CommitDistance = 4.f;// 0.01f; //TODO make this user variable - - //constexpr float ControllerAxisRange = 32767.f; - //constexpr std::int16_t MinStickMove = 8000; - - //these we do use constexpr std::int16_t MinTriggerMove = 16000; constexpr float MaxMouseDraw = 20.f; @@ -76,13 +67,14 @@ namespace } Swingput::Swingput(const SharedStateData& sd) - : m_sharedData (sd), - m_enabled (-1), - m_mouseMovement (0), - m_hook (0.f), - m_gaugePosition (0.f), - m_lastLT (0), - m_lastRT (0) + : m_sharedData (sd), + m_enabled (-1), + m_mouseMovement (0), + m_hook (0.f), + m_gaugePosition (0.f), + m_lastLT (0), + m_lastRT (0), + m_strokeStartPosition (0) { #ifdef CRO_DEBUG_ //registerWindow([&]() @@ -125,8 +117,9 @@ bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std { m_state = State::Swing; m_mouseMovement = { 0.f,0.f }; - m_hook = 0.f; + m_hook = 0.5f; m_gaugePosition = 0.f; + m_strokeStartPosition = 0; cro::App::getWindow().setMouseCaptured(true); } @@ -135,19 +128,26 @@ bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std const auto endStroke = [&]() { m_state = State::Inactive; + + if (state == StateID::Power) + { + //cancel the shot + inputFlags |= (InputFlag::Cancel | InputFlag::Swingput); + } }; switch (evt.type) { default: return isActive(); case SDL_MOUSEBUTTONDOWN: - if (evt.button.button == SDL_BUTTON_RIGHT) + /*if (evt.button.button == SDL_BUTTON_RIGHT) { startStroke(); return true; - } + }*/ return false; case SDL_MOUSEBUTTONUP: + return false; //disable for now if (evt.button.button == SDL_BUTTON_RIGHT) { endStroke(); @@ -155,8 +155,8 @@ bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std } return false; case SDL_MOUSEMOTION: + return false; //TODO we need to scale this down relative to the game buffer size - //or use some sort of mouse sensitivity if (m_state == State::Swing) { switch (state) @@ -172,6 +172,9 @@ bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std { inputFlags |= (InputFlag::Action | InputFlag::Swingput); } + + setGaugeFromMouse(); + return true; } break; case StateID::Power: @@ -191,10 +194,12 @@ bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std m_state = State::Inactive; } + + setGaugeFromMouse(); + return true; } break; } - setGaugeFromMouse(); } return false; @@ -212,7 +217,7 @@ bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std { startStroke(); } - else + else if(evt.caxis.value > 4000) //some arbitrary deadzone { endStroke(); } @@ -241,8 +246,11 @@ bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std if (evt.caxis.value > MaxControllerDraw) { inputFlags |= (InputFlag::Action | InputFlag::Swingput); - m_tempoTimer.restart(); + m_strokeStartPosition = evt.caxis.value; } + + setGaugeFromController(evt.caxis.value); + return true; } else if (state == StateID::Power) { @@ -251,21 +259,38 @@ bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std //the accuracy stage... if (evt.caxis.value < MaxControllerSwing) { - //TODO measure the tempo of the swing and use it to set the accuracy - LogI << "Tempo is " << m_tempoTimer.restart() << std::endl; - inputFlags |= (InputFlag::Action | InputFlag::Swingput); m_state = State::Inactive; + + const float t = m_tempoTimer.restart(); + m_hook = 0.5f + ((0.033f - std::min(t, 0.066f)) / 2.f); + + auto x = cro::GameController::getAxisPosition(activeControllerID(m_enabled), + evt.caxis.axis == cro::GameController::AxisLeftY ? cro::GameController::AxisLeftX : cro::GameController::AxisRightX); + const float xAmount = std::pow(std::clamp(static_cast(x) / 10000.f, -1.f, 1.f), 3.f); //TODO vary this between 3 and 11 based on player level + + m_hook += (xAmount * 0.122f); } - } - setGaugeFromController(evt.caxis.value); + + //see if we started moving back after beginning the power mode + if (evt.caxis.value < m_strokeStartPosition) + { + m_tempoTimer.restart(); + + //prevent this triggering again + m_strokeStartPosition = std::numeric_limits::min(); + } + + setGaugeFromController(evt.caxis.value); + return true; + } } return false; - case SDL_CONTROLLER_AXIS_LEFTX: + /*case SDL_CONTROLLER_AXIS_LEFTX: case SDL_CONTROLLER_AXIS_RIGHTX: - return false; + return false;*/ } } return isActive(); diff --git a/samples/golf/src/golf/Swingput.hpp b/samples/golf/src/golf/Swingput.hpp index 289c045e2..5f23a753e 100644 --- a/samples/golf/src/golf/Swingput.hpp +++ b/samples/golf/src/golf/Swingput.hpp @@ -79,6 +79,7 @@ class Swingput final : public cro::GuiClient std::int16_t m_lastLT; std::int16_t m_lastRT; + std::int16_t m_strokeStartPosition; std::int32_t m_state = State::Inactive; const std::array StateStrings = From cbe4fd978469e1733bea02d9d73c64debb53242b Mon Sep 17 00:00:00 2001 From: fallahn Date: Wed, 10 Apr 2024 10:08:35 +0100 Subject: [PATCH 08/24] set swingput accuracy based on current clubset remove mouse settings for swingput from options window --- samples/golf/buildnumber.h | 4 +- samples/golf/src/golf/OptionsState.cpp | 132 ++++++++++++------------- samples/golf/src/golf/Swingput.cpp | 8 +- 3 files changed, 74 insertions(+), 70 deletions(-) diff --git a/samples/golf/buildnumber.h b/samples/golf/buildnumber.h index 2c119f16e..fe3a85b89 100644 --- a/samples/golf/buildnumber.h +++ b/samples/golf/buildnumber.h @@ -3,7 +3,7 @@ #ifndef BUILD_NUMBER_H_ #define BUILD_NUMBER_H_ -#define BUILDNUMBER 5247 -#define BUILDNUMBER_STR "5247" +#define BUILDNUMBER 5259 +#define BUILDNUMBER_STR "5259" #endif /* BUILD_NUMBER_H_ */ diff --git a/samples/golf/src/golf/OptionsState.cpp b/samples/golf/src/golf/OptionsState.cpp index cdc7634af..5c7931ca5 100644 --- a/samples/golf/src/golf/OptionsState.cpp +++ b/samples/golf/src/golf/OptionsState.cpp @@ -3149,21 +3149,21 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& return e; }; - std::stringstream ss; + /*std::stringstream ss; ss.precision(2); ss << "Swingput Mouse Sensitivity " << m_sharedData.swingputThreshold; - auto swingputText = createText(glm::vec2(20.f, 124.f), ss.str()); + auto swingputText = createText(glm::vec2(20.f, 124.f), ss.str());*/ std::stringstream st; st.precision(2); st << "Look Speed (Billiards) " << m_sharedData.mouseSpeed; - auto mouseText = createText(glm::vec2(20.f, 92.f), st.str()); - createText(glm::vec2(32.f, 63.f), "Invert X"); - createText(glm::vec2(32.f, 47.f), "Invert Y"); - createText(glm::vec2(118.f, 63.f), "Use Vibration"); - createText(glm::vec2(118.f, 47.f), "Hold For Power"); - createText(glm::vec2(118.f, 31.f), "Enable Swingput"); + auto mouseText = createText(glm::vec2(20.f, 124.f), st.str()); + createText(glm::vec2(32.f, 79.f), "Invert X"); + createText(glm::vec2(32.f, 63.f), "Invert Y"); + createText(glm::vec2(118.f, 79.f), "Use Vibration"); + createText(glm::vec2(118.f, 63.f), "Hold For Power"); + createText(glm::vec2(118.f, 47.f), "Enable Swingput"); //TODO don't duplicate these as they already exist in the AV menu auto selectedID = uiSystem.addCallback([infoEnt](cro::Entity e) mutable @@ -3236,7 +3236,7 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& return entity; }; - auto swingputSlider = createSlider({ 35.f, 109.f }); + /*auto swingputSlider = createSlider({ 35.f, 109.f }); swingputSlider.getComponent().getUserData().onActivate = [&, swingputText](float distance) mutable { @@ -3254,10 +3254,10 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& float amount = (m_sharedData.swingputThreshold - ConstVal::MinSwingputThresh) / (ConstVal::MaxSwingputThresh - ConstVal::MinSwingputThresh); e.getComponent().setPosition({ pos.x + (width * amount), pos.y }); - }; + };*/ //mouse speed slider - createSlider(glm::vec2(35.f, 77.f)); + createSlider(glm::vec2(35.f, 109.f));//77 auto createSquareHighlight = [&](glm::vec2 pos) @@ -3284,53 +3284,53 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& }; //swingput down - entity = createSquareHighlight(glm::vec2(17.f, 103.f)); - entity.getComponent().setSelectionIndex(CtrlThreshL); - entity.getComponent().setNextIndex(CtrlThreshR, CtrlLookL); - entity.getComponent().setPrevIndex(CtrlLB, TabAV); - entity.getComponent().callbacks[cro::UIInput::ButtonDown] = uiSystem.addCallback( - [&, swingputText](cro::Entity, cro::ButtonEvent evt) mutable - { - if (activated(evt)) - { - m_sharedData.swingputThreshold = std::max(ConstVal::MinSwingputThresh, m_sharedData.swingputThreshold - 0.1f); - - std::stringstream ss; - ss.precision(2); - ss << "Swingput Mouse Sensitivity " << m_sharedData.swingputThreshold; - swingputText.getComponent().setString(ss.str()); - - m_audioEnts[AudioID::Accept].getComponent().play(); - } - }); - - //swingput up - entity = createSquareHighlight(glm::vec2(184.f, 103.f)); - entity.getComponent().setSelectionIndex(CtrlThreshR); - entity.getComponent().setNextIndex(CtrlRB, CtrlLookR); - entity.getComponent().setPrevIndex(CtrlThreshL, TabAchievements); - entity.getComponent().callbacks[cro::UIInput::ButtonDown] = uiSystem.addCallback( - [&, swingputText](cro::Entity, cro::ButtonEvent evt) mutable - { - if (activated(evt)) - { - m_sharedData.swingputThreshold = std::min(ConstVal::MaxSwingputThresh, m_sharedData.swingputThreshold + 0.1f); + //entity = createSquareHighlight(glm::vec2(17.f, 103.f)); + //entity.getComponent().setSelectionIndex(CtrlThreshL); + //entity.getComponent().setNextIndex(CtrlThreshR, CtrlLookL); + //entity.getComponent().setPrevIndex(CtrlLB, TabAV); + //entity.getComponent().callbacks[cro::UIInput::ButtonDown] = uiSystem.addCallback( + // [&, swingputText](cro::Entity, cro::ButtonEvent evt) mutable + // { + // if (activated(evt)) + // { + // m_sharedData.swingputThreshold = std::max(ConstVal::MinSwingputThresh, m_sharedData.swingputThreshold - 0.1f); + + // std::stringstream ss; + // ss.precision(2); + // ss << "Swingput Mouse Sensitivity " << m_sharedData.swingputThreshold; + // swingputText.getComponent().setString(ss.str()); + + // m_audioEnts[AudioID::Accept].getComponent().play(); + // } + // }); + + ////swingput up + //entity = createSquareHighlight(glm::vec2(184.f, 103.f)); + //entity.getComponent().setSelectionIndex(CtrlThreshR); + //entity.getComponent().setNextIndex(CtrlRB, CtrlLookR); + //entity.getComponent().setPrevIndex(CtrlThreshL, TabAchievements); + //entity.getComponent().callbacks[cro::UIInput::ButtonDown] = uiSystem.addCallback( + // [&, swingputText](cro::Entity, cro::ButtonEvent evt) mutable + // { + // if (activated(evt)) + // { + // m_sharedData.swingputThreshold = std::min(ConstVal::MaxSwingputThresh, m_sharedData.swingputThreshold + 0.1f); - std::stringstream ss; - ss.precision(2); - ss << "Swingput Mouse Sensitivity " << m_sharedData.swingputThreshold; - swingputText.getComponent().setString(ss.str()); + // std::stringstream ss; + // ss.precision(2); + // ss << "Swingput Mouse Sensitivity " << m_sharedData.swingputThreshold; + // swingputText.getComponent().setString(ss.str()); - m_audioEnts[AudioID::Back].getComponent().play(); - } - }); + // m_audioEnts[AudioID::Back].getComponent().play(); + // } + // }); //mouse speed down - entity = createSquareHighlight(glm::vec2(17.f, 71.f)); + entity = createSquareHighlight(glm::vec2(17.f, 103.f));//71 entity.getComponent().setSelectionIndex(CtrlLookL); entity.getComponent().setNextIndex(CtrlLookR, CtrlInvX); - entity.getComponent().setPrevIndex(CtrlLB, CtrlThreshL); + entity.getComponent().setPrevIndex(CtrlLB, /*CtrlThreshL*/TabAV); entity.getComponent().callbacks[cro::UIInput::ButtonDown] = uiSystem.addCallback( [&, mouseText](cro::Entity, cro::ButtonEvent evt) mutable { @@ -3348,10 +3348,10 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& }); //mouse speed up - entity = createSquareHighlight(glm::vec2(184.f, 71.f)); + entity = createSquareHighlight(glm::vec2(184.f, 103.f));//71 entity.getComponent().setSelectionIndex(CtrlLookR); entity.getComponent().setNextIndex(CtrlUp, CtrlVib); - entity.getComponent().setPrevIndex(CtrlLookL, CtrlThreshR); + entity.getComponent().setPrevIndex(CtrlLookL, /*CtrlThreshR*/TabAchievements); entity.getComponent().callbacks[cro::UIInput::ButtonDown] = uiSystem.addCallback( [&, mouseText](cro::Entity, cro::ButtonEvent evt) mutable { @@ -3369,7 +3369,7 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& }); //invert X - entity = createSquareHighlight(glm::vec2(17.f, 54.f)); + entity = createSquareHighlight(glm::vec2(17.f, 70.f)); entity.setLabel("Invert the controller X axis when playing Billiards"); entity.getComponent().setSelectionIndex(CtrlInvX); entity.getComponent().setNextIndex(CtrlVib, CtrlInvY); @@ -3388,7 +3388,7 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& //centre entity = m_scene.createEntity(); - entity.addComponent().setPosition(glm::vec3(19.f, 56.f, HighlightOffset)); + entity.addComponent().setPosition(glm::vec3(19.f, 72.f, HighlightOffset)); entity.addComponent().getVertexData() = { cro::Vertex2D(glm::vec2(0.f, 7.f), TextGoldColour), @@ -3408,10 +3408,10 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& //rumble enable - entity = createSquareHighlight(glm::vec2(103.f, 54.f)); + entity = createSquareHighlight(glm::vec2(103.f, 70.f)); entity.setLabel("Enable or disable controller vibration"); entity.getComponent().setSelectionIndex(CtrlVib); - entity.getComponent().setNextIndex(CtrlLeft, CtrlAltPower); + entity.getComponent().setNextIndex(CtrlUp, CtrlAltPower); entity.getComponent().setPrevIndex(CtrlInvX, CtrlLookR); entity.getComponent().callbacks[cro::UIInput::ButtonDown] = uiSystem.addCallback( [&](cro::Entity, cro::ButtonEvent evt) mutable @@ -3426,7 +3426,7 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& }); entity = m_scene.createEntity(); - entity.addComponent().setPosition(glm::vec3(105.f, 56.f, HighlightOffset)); + entity.addComponent().setPosition(glm::vec3(105.f, 72.f, HighlightOffset)); entity.addComponent().getVertexData() = { cro::Vertex2D(glm::vec2(0.f, 7.f), TextGoldColour), @@ -3446,10 +3446,10 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& //alt power input - entity = createSquareHighlight(glm::vec2(103.f, 38.f)); + entity = createSquareHighlight(glm::vec2(103.f, 54.f)); entity.setLabel("When enabled press and hold Action to select stroke power\nelse use the default 2-tap method when disabled"); entity.getComponent().setSelectionIndex(CtrlAltPower); - entity.getComponent().setNextIndex(CtrlRight, CtrlSwg); + entity.getComponent().setNextIndex(CtrlLeft, CtrlSwg); entity.getComponent().setPrevIndex(CtrlInvY, CtrlVib); entity.getComponent().callbacks[cro::UIInput::ButtonDown] = uiSystem.addCallback( [&](cro::Entity, cro::ButtonEvent evt) mutable @@ -3464,7 +3464,7 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& }); //y'know if we defined these first we could capture them and update them in the button callback... entity = m_scene.createEntity(); - entity.addComponent().setPosition(glm::vec3(105.f, 40.f, HighlightOffset)); + entity.addComponent().setPosition(glm::vec3(105.f, 56.f, HighlightOffset)); entity.addComponent().getVertexData() = { cro::Vertex2D(glm::vec2(0.f, 7.f), TextGoldColour), @@ -3484,10 +3484,10 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& //swingput enable - entity = createSquareHighlight(glm::vec2(103.f, 22.f)); + entity = createSquareHighlight(glm::vec2(103.f, 38.f)); entity.setLabel("Enables analogue swing with triggers and thumbstick.\n(BETA)"); entity.getComponent().setSelectionIndex(CtrlSwg); - entity.getComponent().setNextIndex(CtrlDown, WindowAdvanced); + entity.getComponent().setNextIndex(CtrlRight, WindowAdvanced); entity.getComponent().setPrevIndex(CtrlReset, CtrlAltPower); entity.getComponent().callbacks[cro::UIInput::ButtonDown] = uiSystem.addCallback( [&](cro::Entity, cro::ButtonEvent evt) mutable @@ -3501,7 +3501,7 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& } }); entity = m_scene.createEntity(); - entity.addComponent().setPosition(glm::vec3(105.f, 24.f, HighlightOffset)); + entity.addComponent().setPosition(glm::vec3(105.f, 40.f, HighlightOffset)); entity.addComponent().getVertexData() = { cro::Vertex2D(glm::vec2(0.f, 7.f), TextGoldColour), @@ -3521,7 +3521,7 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& //invert Y - entity = createSquareHighlight(glm::vec2(17.f, 38.f)); + entity = createSquareHighlight(glm::vec2(17.f, 54.f)); entity.setLabel("Invert the controller Y axis when playing Billiards"); entity.getComponent().setSelectionIndex(CtrlInvY); entity.getComponent().setNextIndex(CtrlAltPower, CtrlReset); @@ -3539,7 +3539,7 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& }); entity = m_scene.createEntity(); - entity.addComponent().setPosition(glm::vec3(19.f, 40.f, HighlightOffset)); + entity.addComponent().setPosition(glm::vec3(19.f, 56.f, HighlightOffset)); entity.addComponent().getVertexData() = { cro::Vertex2D(glm::vec2(0.f, 7.f), TextGoldColour), diff --git a/samples/golf/src/golf/Swingput.cpp b/samples/golf/src/golf/Swingput.cpp index 11119c661..92319dcd5 100644 --- a/samples/golf/src/golf/Swingput.cpp +++ b/samples/golf/src/golf/Swingput.cpp @@ -28,6 +28,7 @@ source distribution. -----------------------------------------------------------------------*/ #include "Swingput.hpp" +#include "Clubs.hpp" #include "InputBinding.hpp" #include "GameConsts.hpp" #include "SharedStateData.hpp" @@ -267,9 +268,12 @@ bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std auto x = cro::GameController::getAxisPosition(activeControllerID(m_enabled), evt.caxis.axis == cro::GameController::AxisLeftY ? cro::GameController::AxisLeftX : cro::GameController::AxisRightX); - const float xAmount = std::pow(std::clamp(static_cast(x) / 10000.f, -1.f, 1.f), 3.f); //TODO vary this between 3 and 11 based on player level + //higher level club sets require better accuracy + //https://www.desmos.com/calculator/u8hmy5q3mz + static constexpr std::array LevelMultipliers = { 19.f, 11.f, 7.f }; + const float xAmount = std::pow(std::clamp(static_cast(x) / 12000.f, -1.f, 1.f), LevelMultipliers[Club::getClubLevel()]); - m_hook += (xAmount * 0.122f); + m_hook += (xAmount * 0.244f); } //see if we started moving back after beginning the power mode From 36a1a718fcf9d080818b89fbbb8e5a9acfa557a5 Mon Sep 17 00:00:00 2001 From: fallahn Date: Wed, 10 Apr 2024 10:56:50 +0100 Subject: [PATCH 09/24] add idle detection for letting go of thumbstick mid-swingput --- samples/golf/buildnumber.h | 4 +-- samples/golf/src/golf/InputParser.cpp | 2 ++ samples/golf/src/golf/Swingput.cpp | 48 ++++++++++++++++++++++++--- samples/golf/src/golf/Swingput.hpp | 12 ++++++- 4 files changed, 58 insertions(+), 8 deletions(-) diff --git a/samples/golf/buildnumber.h b/samples/golf/buildnumber.h index fe3a85b89..30743a0b7 100644 --- a/samples/golf/buildnumber.h +++ b/samples/golf/buildnumber.h @@ -3,7 +3,7 @@ #ifndef BUILD_NUMBER_H_ #define BUILD_NUMBER_H_ -#define BUILDNUMBER 5259 -#define BUILDNUMBER_STR "5259" +#define BUILDNUMBER 5263 +#define BUILDNUMBER_STR "5263" #endif /* BUILD_NUMBER_H_ */ diff --git a/samples/golf/src/golf/InputParser.cpp b/samples/golf/src/golf/InputParser.cpp index 77487c3bc..e2d7c1031 100644 --- a/samples/golf/src/golf/InputParser.cpp +++ b/samples/golf/src/golf/InputParser.cpp @@ -843,6 +843,8 @@ void InputParser::updateDistanceEstimation() void InputParser::updateStroke(float dt) { + m_swingput.assertIdled(dt, m_inputFlags, static_cast(m_state)); + //catch the inputs that where filtered by the //enable flags so we can raise their own event for them auto disabledFlags = (m_inputFlags & ~m_enableFlags); diff --git a/samples/golf/src/golf/Swingput.cpp b/samples/golf/src/golf/Swingput.cpp index 92319dcd5..fe864df6c 100644 --- a/samples/golf/src/golf/Swingput.cpp +++ b/samples/golf/src/golf/Swingput.cpp @@ -75,7 +75,11 @@ Swingput::Swingput(const SharedStateData& sd) m_gaugePosition (0.f), m_lastLT (0), m_lastRT (0), - m_strokeStartPosition (0) + m_strokeStartPosition (0), + m_activeStick (SDL_CONTROLLER_AXIS_INVALID), + m_lastAxisposition (0), + m_cancelTimer (0.f), + m_inCancelZone (false) { #ifdef CRO_DEBUG_ //registerWindow([&]() @@ -129,6 +133,7 @@ bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std const auto endStroke = [&]() { m_state = State::Inactive; + m_activeStick = SDL_CONTROLLER_AXIS_INVALID; if (state == StateID::Power) { @@ -248,6 +253,7 @@ bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std { inputFlags |= (InputFlag::Action | InputFlag::Swingput); m_strokeStartPosition = evt.caxis.value; + m_activeStick = evt.caxis.axis; } setGaugeFromController(evt.caxis.value); @@ -285,16 +291,28 @@ bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std m_strokeStartPosition = std::numeric_limits::min(); } + + //check if this is the active axis and if it's in the cancel + //zone - ie the user let go of the stick before swinging + if (evt.caxis.axis == m_activeStick) + { + m_inCancelZone = (evt.caxis.value < cro::GameController::RightThumbDeadZone && evt.caxis.value > -cro::GameController::RightThumbDeadZone); + + //reset the timer if we entered the zon forthe first time + if (m_inCancelZone && m_lastAxisposition > cro::GameController::RightThumbDeadZone) + { + //TODO do we need to check if it was below the deadzone? We should only be travelling in one dir + m_cancelTimer = 0.f; + } + m_lastAxisposition = evt.caxis.value; + } + setGaugeFromController(evt.caxis.value); return true; } } return false; - /*case SDL_CONTROLLER_AXIS_LEFTX: - case SDL_CONTROLLER_AXIS_RIGHTX: - - return false;*/ } } return isActive(); @@ -303,6 +321,26 @@ bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std return isActive(); } +void Swingput::assertIdled(float dt, std::uint16_t& inputFlags, std::int32_t state) +{ + if (state == StateID::Power + && m_activeStick != SDL_CONTROLLER_AXIS_INVALID) + { + if (m_inCancelZone) + { + static constexpr float Timeout = 0.8f; + m_cancelTimer += dt; + + if (m_cancelTimer > Timeout) + { + inputFlags |= (InputFlag::Cancel | InputFlag::Swingput); + m_state = State::Inactive; + m_activeStick = SDL_CONTROLLER_AXIS_INVALID; + } + } + } +} + void Swingput::setEnabled(std::int32_t enabled) { m_enabled = enabled; diff --git a/samples/golf/src/golf/Swingput.hpp b/samples/golf/src/golf/Swingput.hpp index 5f23a753e..385f34180 100644 --- a/samples/golf/src/golf/Swingput.hpp +++ b/samples/golf/src/golf/Swingput.hpp @@ -1,6 +1,6 @@ /*----------------------------------------------------------------------- -Matt Marchant 2022 +Matt Marchant 2022 - 2024 http://trederia.blogspot.com Super Video Golf - zlib licence. @@ -47,6 +47,10 @@ class Swingput final : public cro::GuiClient bool handleEvent(const cro::Event&, std::uint16_t& flags, std::int32_t state); bool isActive() const { return m_state != State::Inactive; } + //checksto see if an active swing was cancelled by letting go of + //the thumbstick must be called by input parser at top of processing + void assertIdled(float, std::uint16_t& flags, std::int32_t state); + //set to -1 to deactivate, else current player ID void setEnabled(std::int32_t enabled); std::int32_t getEnabled() const { return m_enabled; } @@ -81,6 +85,12 @@ class Swingput final : public cro::GuiClient std::int16_t m_lastRT; std::int16_t m_strokeStartPosition; + //used to track if we should cancel from letting go of the stick + std::int32_t m_activeStick; + std::int16_t m_lastAxisposition; + float m_cancelTimer; + bool m_inCancelZone; + std::int32_t m_state = State::Inactive; const std::array StateStrings = { From 13a74e666572d4db3d252657639b41e88c526e4a Mon Sep 17 00:00:00 2001 From: fallahn Date: Wed, 10 Apr 2024 20:01:19 +0100 Subject: [PATCH 10/24] fine tune swingput --- samples/golf/buildnumber.h | 4 ++-- samples/golf/src/golf/Swingput.cpp | 22 ++++++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/samples/golf/buildnumber.h b/samples/golf/buildnumber.h index 30743a0b7..dc4e52e99 100644 --- a/samples/golf/buildnumber.h +++ b/samples/golf/buildnumber.h @@ -3,7 +3,7 @@ #ifndef BUILD_NUMBER_H_ #define BUILD_NUMBER_H_ -#define BUILDNUMBER 5263 -#define BUILDNUMBER_STR "5263" +#define BUILDNUMBER 5271 +#define BUILDNUMBER_STR "5271" #endif /* BUILD_NUMBER_H_ */ diff --git a/samples/golf/src/golf/Swingput.cpp b/samples/golf/src/golf/Swingput.cpp index fe864df6c..4cb516060 100644 --- a/samples/golf/src/golf/Swingput.cpp +++ b/samples/golf/src/golf/Swingput.cpp @@ -209,6 +209,16 @@ bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std } return false; + case SDL_CONTROLLERBUTTONDOWN: + if (cro::GameController::controllerID(evt.cbutton.which) == activeControllerID(m_enabled)) + { + if (evt.cbutton.button == cro::GameController::ButtonB + && m_state == State::Swing) + { + endStroke(); + } + } + return false; //we allow either trigger or either stick //to aid handedness of players case SDL_CONTROLLERAXISMOTION: @@ -223,7 +233,7 @@ bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std { startStroke(); } - else if(evt.caxis.value > 4000) //some arbitrary deadzone + else if (evt.caxis.value < 8000) //some arbitrary deadzone { endStroke(); } @@ -277,9 +287,9 @@ bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std //higher level club sets require better accuracy //https://www.desmos.com/calculator/u8hmy5q3mz static constexpr std::array LevelMultipliers = { 19.f, 11.f, 7.f }; - const float xAmount = std::pow(std::clamp(static_cast(x) / 12000.f, -1.f, 1.f), LevelMultipliers[Club::getClubLevel()]); + const float xAmount = std::pow(std::clamp(static_cast(x) / 22000.f, -1.f, 1.f), LevelMultipliers[Club::getClubLevel()]); - m_hook += (xAmount * 0.244f); + m_hook += (xAmount * 0.122f); } //see if we started moving back after beginning the power mode @@ -298,7 +308,7 @@ bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std { m_inCancelZone = (evt.caxis.value < cro::GameController::RightThumbDeadZone && evt.caxis.value > -cro::GameController::RightThumbDeadZone); - //reset the timer if we entered the zon forthe first time + //reset the timer if we entered the zone for the first time if (m_inCancelZone && m_lastAxisposition > cro::GameController::RightThumbDeadZone) { //TODO do we need to check if it was below the deadzone? We should only be travelling in one dir @@ -328,13 +338,13 @@ void Swingput::assertIdled(float dt, std::uint16_t& inputFlags, std::int32_t sta { if (m_inCancelZone) { - static constexpr float Timeout = 0.8f; + static constexpr float Timeout = 0.08f; m_cancelTimer += dt; if (m_cancelTimer > Timeout) { inputFlags |= (InputFlag::Cancel | InputFlag::Swingput); - m_state = State::Inactive; + //m_state = State::Inactive; m_activeStick = SDL_CONTROLLER_AXIS_INVALID; } } From dd209a3189ab33c7c1ab4d6a749ee683c9c1faf8 Mon Sep 17 00:00:00 2001 From: fallahn Date: Wed, 10 Apr 2024 20:43:37 +0100 Subject: [PATCH 11/24] tweak swingput for steam deck --- samples/golf/buildnumber.h | 4 ++-- samples/golf/src/golf/Swingput.cpp | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/samples/golf/buildnumber.h b/samples/golf/buildnumber.h index dc4e52e99..1761e4876 100644 --- a/samples/golf/buildnumber.h +++ b/samples/golf/buildnumber.h @@ -3,7 +3,7 @@ #ifndef BUILD_NUMBER_H_ #define BUILD_NUMBER_H_ -#define BUILDNUMBER 5271 -#define BUILDNUMBER_STR "5271" +#define BUILDNUMBER 5274 +#define BUILDNUMBER_STR "5274" #endif /* BUILD_NUMBER_H_ */ diff --git a/samples/golf/src/golf/Swingput.cpp b/samples/golf/src/golf/Swingput.cpp index 4cb516060..9a3161bc8 100644 --- a/samples/golf/src/golf/Swingput.cpp +++ b/samples/golf/src/golf/Swingput.cpp @@ -233,7 +233,7 @@ bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std { startStroke(); } - else if (evt.caxis.value < 8000) //some arbitrary deadzone + else if (evt.caxis.value < 6000) //some arbitrary deadzone { endStroke(); } @@ -266,7 +266,11 @@ bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std m_activeStick = evt.caxis.axis; } - setGaugeFromController(evt.caxis.value); + if (evt.caxis.value > cro::GameController::RightThumbDeadZone + || evt.caxis.value < -cro::GameController::RightThumbDeadZone) + { + setGaugeFromController(evt.caxis.value); + } return true; } else if (state == StateID::Power) @@ -315,9 +319,9 @@ bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std m_cancelTimer = 0.f; } m_lastAxisposition = evt.caxis.value; + setGaugeFromController(evt.caxis.value); } - setGaugeFromController(evt.caxis.value); return true; } } From 2874843424a94d915fafce625a84146bd3f26c62 Mon Sep 17 00:00:00 2001 From: fallahn Date: Thu, 11 Apr 2024 10:24:14 +0100 Subject: [PATCH 12/24] fix crash when randomising player avatars --- samples/golf/buildnumber.h | 4 ++-- samples/golf/src/golf/CareerState.cpp | 2 +- samples/golf/src/golf/PlayerColours.hpp | 2 +- samples/golf/src/golf/ProfileState.cpp | 3 +-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/samples/golf/buildnumber.h b/samples/golf/buildnumber.h index 1761e4876..bde68ff50 100644 --- a/samples/golf/buildnumber.h +++ b/samples/golf/buildnumber.h @@ -3,7 +3,7 @@ #ifndef BUILD_NUMBER_H_ #define BUILD_NUMBER_H_ -#define BUILDNUMBER 5274 -#define BUILDNUMBER_STR "5274" +#define BUILDNUMBER 5279 +#define BUILDNUMBER_STR "5279" #endif /* BUILD_NUMBER_H_ */ diff --git a/samples/golf/src/golf/CareerState.cpp b/samples/golf/src/golf/CareerState.cpp index eb62350a8..a6eef10d7 100644 --- a/samples/golf/src/golf/CareerState.cpp +++ b/samples/golf/src/golf/CareerState.cpp @@ -333,7 +333,7 @@ void CareerState::buildScene() //check if we just completed a league, and if we did and it's //one less than max leagues, increment our current round id - auto currIdx = m_sharedData.leagueRoundID - 1; + auto currIdx = std::max(0, m_sharedData.leagueRoundID - 1); if (currIdx == m_maxLeagueIndex - 1) { if (Career::instance().getLeagueTables()[currIdx].getCurrentIteration() == 0) diff --git a/samples/golf/src/golf/PlayerColours.hpp b/samples/golf/src/golf/PlayerColours.hpp index b2804585f..5d5243ab6 100644 --- a/samples/golf/src/golf/PlayerColours.hpp +++ b/samples/golf/src/golf/PlayerColours.hpp @@ -67,7 +67,7 @@ namespace pc cro::Colour(0xadd9b7ff), cro::Colour(0x6eb39dff), cro::Colour(0x30555bff), - cro::Colour(0x1a1e2dff), + cro::Colour(0x1a1e3fff), cro::Colour(0x284e43ff), cro::Colour(0x467e3eff), cro::Colour(0x93ab52ff), diff --git a/samples/golf/src/golf/ProfileState.cpp b/samples/golf/src/golf/ProfileState.cpp index af73136cd..6050dc517 100644 --- a/samples/golf/src/golf/ProfileState.cpp +++ b/samples/golf/src/golf/ProfileState.cpp @@ -1171,7 +1171,7 @@ void ProfileState::buildScene() if (activated(evt)) { //randomise hair - setHairIndex(cro::Util::Random::value(0u, m_sharedData.hairInfo.size() - 1)); + setHairIndex(cro::Util::Random::value(0u, m_avatarHairModels.size() - 1)); //randomise avatar setAvatarIndex(cro::Util::Random::value(0u, m_sharedData.avatarInfo.size() - 1)); @@ -1326,7 +1326,6 @@ void ProfileState::buildScene() m_audioEnts[AudioID::Accept].getComponent().play(); m_lastSelected = e.getComponent().getSelectionIndex(); - LogI << "Last selected set to " << m_lastSelected << std::endl; } }); From f94859a2b3fbc0cda4278554b689dd3e80f929c6 Mon Sep 17 00:00:00 2001 From: fallahn Date: Thu, 11 Apr 2024 10:40:51 +0100 Subject: [PATCH 13/24] add XP award for nice Swingput timing --- samples/golf/buildnumber.h | 4 ++-- samples/golf/src/golf/GolfState.cpp | 3 +++ samples/golf/src/golf/MessageIDs.hpp | 1 + samples/golf/src/golf/Swingput.cpp | 7 +++++++ samples/golf/src/golf/XPAwardStrings.hpp | 2 ++ 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/samples/golf/buildnumber.h b/samples/golf/buildnumber.h index bde68ff50..da3514d63 100644 --- a/samples/golf/buildnumber.h +++ b/samples/golf/buildnumber.h @@ -3,7 +3,7 @@ #ifndef BUILD_NUMBER_H_ #define BUILD_NUMBER_H_ -#define BUILDNUMBER 5279 -#define BUILDNUMBER_STR "5279" +#define BUILDNUMBER 5280 +#define BUILDNUMBER_STR "5280" #endif /* BUILD_NUMBER_H_ */ diff --git a/samples/golf/src/golf/GolfState.cpp b/samples/golf/src/golf/GolfState.cpp index 078dfceba..68f144097 100644 --- a/samples/golf/src/golf/GolfState.cpp +++ b/samples/golf/src/golf/GolfState.cpp @@ -1185,6 +1185,9 @@ void GolfState::handleMessage(const cro::Message& msg) switch (data.type) { default: break; + case GolfEvent::NiceTiming: + Social::awardXP(10, XPStringID::NiceTiming); + break; case GolfEvent::HitBall: { hitBall(); diff --git a/samples/golf/src/golf/MessageIDs.hpp b/samples/golf/src/golf/MessageIDs.hpp index 35b42ec9a..635a71a63 100644 --- a/samples/golf/src/golf/MessageIDs.hpp +++ b/samples/golf/src/golf/MessageIDs.hpp @@ -65,6 +65,7 @@ struct GolfEvent final SlicedBall, BallLanded, Scored, + NiceTiming, NiceShot, PowerShot, DriveComplete, diff --git a/samples/golf/src/golf/Swingput.cpp b/samples/golf/src/golf/Swingput.cpp index 9a3161bc8..0ac7ac226 100644 --- a/samples/golf/src/golf/Swingput.cpp +++ b/samples/golf/src/golf/Swingput.cpp @@ -32,6 +32,7 @@ source distribution. #include "InputBinding.hpp" #include "GameConsts.hpp" #include "SharedStateData.hpp" +#include "MessageIDs.hpp" #include #include @@ -286,6 +287,12 @@ bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std const float t = m_tempoTimer.restart(); m_hook = 0.5f + ((0.033f - std::min(t, 0.066f)) / 2.f); + if (std::floor(t * 1000.f) == 33.f) + { + auto* msg = cro::App::postMessage(cl::MessageID::GolfMessage); + msg->type = GolfEvent::NiceTiming; + } + auto x = cro::GameController::getAxisPosition(activeControllerID(m_enabled), evt.caxis.axis == cro::GameController::AxisLeftY ? cro::GameController::AxisLeftX : cro::GameController::AxisRightX); //higher level club sets require better accuracy diff --git a/samples/golf/src/golf/XPAwardStrings.hpp b/samples/golf/src/golf/XPAwardStrings.hpp index 5e0840904..3d8ad0fe3 100644 --- a/samples/golf/src/golf/XPAwardStrings.hpp +++ b/samples/golf/src/golf/XPAwardStrings.hpp @@ -39,6 +39,7 @@ struct XPStringID final NiceOn, NearMiss, GreatAccuracy, + NiceTiming, OnTheFairway, DroneHit, CourseComplete, @@ -79,6 +80,7 @@ static inline const std::array XPStrings = std::string("Nice On!"), "Near Miss", "Great Accuracy", + "Nice Timing!" "Fairway", "Drone Hit!", "Course Complete", From c91aa844881830ea16a47926db945d0f077753c9 Mon Sep 17 00:00:00 2001 From: fallahn Date: Thu, 11 Apr 2024 12:01:54 +0100 Subject: [PATCH 14/24] refactor swingput meter creation into single function --- samples/golf/buildnumber.h | 4 +- samples/golf/src/golf/DrivingState.hpp | 1 - samples/golf/src/golf/DrivingStateUI.cpp | 78 ++---------------------- samples/golf/src/golf/GameConsts.hpp | 75 +++++++++++++++++++++++ samples/golf/src/golf/GolfState.hpp | 1 - samples/golf/src/golf/GolfStateUI.cpp | 78 ++---------------------- samples/golf/src/golf/OptionsState.cpp | 2 +- samples/golf/src/golf/Swingput.cpp | 7 ++- 8 files changed, 92 insertions(+), 154 deletions(-) diff --git a/samples/golf/buildnumber.h b/samples/golf/buildnumber.h index da3514d63..0facb7ab4 100644 --- a/samples/golf/buildnumber.h +++ b/samples/golf/buildnumber.h @@ -3,7 +3,7 @@ #ifndef BUILD_NUMBER_H_ #define BUILD_NUMBER_H_ -#define BUILDNUMBER 5280 -#define BUILDNUMBER_STR "5280" +#define BUILDNUMBER 5289 +#define BUILDNUMBER_STR "5289" #endif /* BUILD_NUMBER_H_ */ diff --git a/samples/golf/src/golf/DrivingState.hpp b/samples/golf/src/golf/DrivingState.hpp index 1c3348f3e..fc0519402 100644 --- a/samples/golf/src/golf/DrivingState.hpp +++ b/samples/golf/src/golf/DrivingState.hpp @@ -215,7 +215,6 @@ class DrivingState final : public cro::State, public cro::GuiClient cro::Entity m_mapCam; cro::SimpleQuad m_flagQuad; void createUI(); - void createSwingMeter(cro::Entity); void createGameOptions(); void createSummary(); void updateMinimap(); diff --git a/samples/golf/src/golf/DrivingStateUI.cpp b/samples/golf/src/golf/DrivingStateUI.cpp index c4efd8adc..698686903 100644 --- a/samples/golf/src/golf/DrivingStateUI.cpp +++ b/samples/golf/src/golf/DrivingStateUI.cpp @@ -242,7 +242,11 @@ void DrivingState::createUI() entity.addComponent(); entity.addComponent(); auto infoEnt = entity; - createSwingMeter(entity); + + entity = m_uiScene.createEntity(); + createSwingputMeter(entity, m_inputParser); + infoEnt.getComponent().addChild(entity.getComponent()); + //createSwingMeter(entity); auto& font = m_sharedData.sharedResources->fonts.get(FontID::UI); @@ -886,78 +890,6 @@ void DrivingState::createUI() createSummary(); } -void DrivingState::createSwingMeter(cro::Entity root) -{ - static constexpr float Width = 4.f; - static constexpr float Height = 40.f; - auto entity = m_uiScene.createEntity(); - entity.addComponent(); - entity.addComponent().setVertexData( - { - cro::Vertex2D(glm::vec2(-Width, -Height), SwingputDark), - cro::Vertex2D(glm::vec2(Width, -Height), SwingputDark), - cro::Vertex2D(glm::vec2(-Width, -0.5f), SwingputDark), - cro::Vertex2D(glm::vec2(Width, -0.5f), SwingputDark), - - cro::Vertex2D(glm::vec2(-Width, -0.5f), TextNormalColour), - cro::Vertex2D(glm::vec2(Width, -0.5f), TextNormalColour), - cro::Vertex2D(glm::vec2(-Width, 0.5f), TextNormalColour), - cro::Vertex2D(glm::vec2(Width, 0.5f), TextNormalColour), - - cro::Vertex2D(glm::vec2(-Width, 0.5f), SwingputDark), - cro::Vertex2D(glm::vec2(Width, 0.5f), SwingputDark), - cro::Vertex2D(glm::vec2(-Width, Height), SwingputDark), - cro::Vertex2D(glm::vec2(Width, Height), SwingputDark), - - - cro::Vertex2D(glm::vec2(-Width, -Height), SwingputLight), - cro::Vertex2D(glm::vec2(Width, -Height), SwingputLight), - cro::Vertex2D(glm::vec2(-Width, 0.f), SwingputLight), - cro::Vertex2D(glm::vec2(Width, 0.f), SwingputLight), - }); - entity.addComponent().active = true; - entity.getComponent().setUserData(0.f); - entity.getComponent().function = - [&](cro::Entity e, float dt) - { - auto& verts = e.getComponent().getVertexData(); - float height = verts[14].position.y; - float targetAlpha = -0.01f; - - if (m_inputParser.isSwingputActive()) - { - height = m_inputParser.getSwingputPosition() * ((Height * 2.f) / MaxSwingputDistance); - targetAlpha = 1.f; - } - - auto& currentAlpha = e.getComponent().getUserData(); - const float InSpeed = dt * 6.f; - const float OutSpeed = m_inputParser.getPower() < 0.5 ? InSpeed : dt * 0.5f; - if (currentAlpha <= targetAlpha) - { - currentAlpha = std::min(1.f, currentAlpha + InSpeed); - } - else - { - currentAlpha = std::max(0.f, currentAlpha - OutSpeed); - } - - for (auto& v : verts) - { - v.colour.setAlpha(currentAlpha); - } - verts[14].position.y = height; - verts[15].position.y = height; - }; - - entity.addComponent().ID = CommandID::UI::UIElement; - entity.addComponent().depth = 0.2f; - entity.getComponent().relativePosition = { 1.f, 0.f }; - entity.getComponent().absolutePosition = { -10.f, 50.f }; - - root.getComponent().addChild(entity.getComponent()); -} - void DrivingState::createGameOptions() { const auto centreSprite = [](cro::Entity e) diff --git a/samples/golf/src/golf/GameConsts.hpp b/samples/golf/src/golf/GameConsts.hpp index b257712de..0f1cd2f12 100644 --- a/samples/golf/src/golf/GameConsts.hpp +++ b/samples/golf/src/golf/GameConsts.hpp @@ -32,6 +32,9 @@ source distribution. #include "Terrain.hpp" #include "MenuConsts.hpp" #include "SharedStateData.hpp" +#include "InputParser.hpp" +#include "MenuConsts.hpp" +#include "CommandIDs.hpp" #include "../GolfGame.hpp" #include @@ -43,7 +46,9 @@ source distribution. #include #include #include +#include #include +#include #include #include #include @@ -677,6 +682,76 @@ static inline std::vector getStrokeIndicatorVerts() }; } +static inline void createSwingputMeter(cro::Entity entity, InputParser& inputParser) +{ + static constexpr float Width = 4.f; + static constexpr float Height = 40.f; + + entity.addComponent(); + entity.addComponent().setVertexData( + { + cro::Vertex2D(glm::vec2(-Width, -Height), SwingputDark), + cro::Vertex2D(glm::vec2(Width, -Height), SwingputDark), + cro::Vertex2D(glm::vec2(-Width, -0.5f), SwingputDark), + cro::Vertex2D(glm::vec2(Width, -0.5f), SwingputDark), + + cro::Vertex2D(glm::vec2(-Width, -0.5f), TextNormalColour), + cro::Vertex2D(glm::vec2(Width, -0.5f), TextNormalColour), + cro::Vertex2D(glm::vec2(-Width, 0.5f), TextNormalColour), + cro::Vertex2D(glm::vec2(Width, 0.5f), TextNormalColour), + + cro::Vertex2D(glm::vec2(-Width, 0.5f), SwingputDark), + cro::Vertex2D(glm::vec2(Width, 0.5f), SwingputDark), + cro::Vertex2D(glm::vec2(-Width, Height), SwingputDark), + cro::Vertex2D(glm::vec2(Width, Height), SwingputDark), + + + cro::Vertex2D(glm::vec2(-Width, -Height), SwingputLight), + cro::Vertex2D(glm::vec2(Width, -Height), SwingputLight), + cro::Vertex2D(glm::vec2(-Width, 0.f), SwingputLight), + cro::Vertex2D(glm::vec2(Width, 0.f), SwingputLight), + }); + entity.addComponent().active = true; + entity.getComponent().setUserData(0.f); + entity.getComponent().function = + [&](cro::Entity e, float dt) + { + auto& verts = e.getComponent().getVertexData(); + float height = verts[14].position.y; + float targetAlpha = -0.01f; + + if (inputParser.isSwingputActive()) + { + height = inputParser.getSwingputPosition() * ((Height * 2.f) / MaxSwingputDistance); + targetAlpha = 1.f; + } + + auto& currentAlpha = e.getComponent().getUserData(); + const float InSpeed = dt * 6.f; + const float OutSpeed = inputParser.getPower() < 0.5 ? InSpeed : dt * 0.5f; + if (currentAlpha <= targetAlpha) + { + currentAlpha = std::min(1.f, currentAlpha + InSpeed); + } + else + { + currentAlpha = std::max(0.f, currentAlpha - OutSpeed); + } + + for (auto& v : verts) + { + v.colour.setAlpha(currentAlpha); + } + verts[14].position.y = height; + verts[15].position.y = height; + }; + + entity.addComponent().ID = CommandID::UI::UIElement; + entity.addComponent().depth = 0.2f; + entity.getComponent().relativePosition = { 1.f, 0.f }; + entity.getComponent().absolutePosition = { -10.f, 50.f }; +} + //applies material data loaded in a model definition such as texture info to custom materials static inline void applyMaterialData(const cro::ModelDefinition& modelDef, cro::Material::Data& dest, std::size_t matID = 0) { diff --git a/samples/golf/src/golf/GolfState.hpp b/samples/golf/src/golf/GolfState.hpp index 863c4a8f5..f65f53c57 100644 --- a/samples/golf/src/golf/GolfState.hpp +++ b/samples/golf/src/golf/GolfState.hpp @@ -460,7 +460,6 @@ class GolfState final : public cro::State, public cro::GuiClient, public cro::Co std::uint8_t m_readyQuitFlags; void buildUI(); - void createSwingMeter(cro::Entity); void showCountdown(std::uint8_t); void createScoreboard(); void updateScoreboard(bool updatePardiff = true); diff --git a/samples/golf/src/golf/GolfStateUI.cpp b/samples/golf/src/golf/GolfStateUI.cpp index 1367a7209..22f7922dd 100644 --- a/samples/golf/src/golf/GolfStateUI.cpp +++ b/samples/golf/src/golf/GolfStateUI.cpp @@ -288,7 +288,11 @@ void GolfState::buildUI() entity.addComponent(); entity.addComponent(); auto infoEnt = entity; - createSwingMeter(infoEnt); + + entity = m_uiScene.createEntity(); + createSwingputMeter(entity, m_inputParser); + infoEnt.getComponent().addChild(entity.getComponent()); + m_textChat.setRootNode(infoEnt); auto& font = m_sharedData.sharedResources->fonts.get(FontID::UI); @@ -1596,78 +1600,6 @@ void GolfState::buildUI() m_emoteWheel.build(infoEnt, m_uiScene, m_resources.textures); } -void GolfState::createSwingMeter(cro::Entity root) -{ - static constexpr float Width = 4.f; - static constexpr float Height = 40.f; - auto entity = m_uiScene.createEntity(); - entity.addComponent(); - entity.addComponent().setVertexData( - { - cro::Vertex2D(glm::vec2(-Width, -Height), SwingputDark), - cro::Vertex2D(glm::vec2(Width, -Height), SwingputDark), - cro::Vertex2D(glm::vec2(-Width, -0.5f), SwingputDark), - cro::Vertex2D(glm::vec2(Width, -0.5f), SwingputDark), - - cro::Vertex2D(glm::vec2(-Width, -0.5f), TextNormalColour), - cro::Vertex2D(glm::vec2(Width, -0.5f), TextNormalColour), - cro::Vertex2D(glm::vec2(-Width, 0.5f), TextNormalColour), - cro::Vertex2D(glm::vec2(Width, 0.5f), TextNormalColour), - - cro::Vertex2D(glm::vec2(-Width, 0.5f), SwingputDark), - cro::Vertex2D(glm::vec2(Width, 0.5f), SwingputDark), - cro::Vertex2D(glm::vec2(-Width, Height), SwingputDark), - cro::Vertex2D(glm::vec2(Width, Height), SwingputDark), - - - cro::Vertex2D(glm::vec2(-Width, -Height), SwingputLight), - cro::Vertex2D(glm::vec2(Width, -Height), SwingputLight), - cro::Vertex2D(glm::vec2(-Width, 0.f), SwingputLight), - cro::Vertex2D(glm::vec2(Width, 0.f), SwingputLight), - }); - entity.addComponent().active = true; - entity.getComponent().setUserData(0.f); - entity.getComponent().function = - [&](cro::Entity e, float dt) - { - auto& verts = e.getComponent().getVertexData(); - float height = verts[14].position.y; - float targetAlpha = -0.01f; - - if (m_inputParser.isSwingputActive()) - { - height = m_inputParser.getSwingputPosition() * ((Height * 2.f) / MaxSwingputDistance); - targetAlpha = 1.f; - } - - auto& currentAlpha = e.getComponent().getUserData(); - const float InSpeed = dt * 6.f; - const float OutSpeed = m_inputParser.getPower() < 0.5 ? InSpeed : dt * 0.5f; - if (currentAlpha <= targetAlpha) - { - currentAlpha = std::min(1.f, currentAlpha + InSpeed); - } - else - { - currentAlpha = std::max(0.f, currentAlpha - OutSpeed); - } - - for (auto& v : verts) - { - v.colour.setAlpha(currentAlpha); - } - verts[14].position.y = height; - verts[15].position.y = height; - }; - - entity.addComponent().ID = CommandID::UI::UIElement; - entity.addComponent().depth = 0.2f; - entity.getComponent().relativePosition = { 1.f, 0.f }; - entity.getComponent().absolutePosition = { -10.f, 50.f }; - - root.getComponent().addChild(entity.getComponent()); -} - void GolfState::showCountdown(std::uint8_t seconds) { m_roundEnded = true; diff --git a/samples/golf/src/golf/OptionsState.cpp b/samples/golf/src/golf/OptionsState.cpp index 5c7931ca5..6c6cd4f43 100644 --- a/samples/golf/src/golf/OptionsState.cpp +++ b/samples/golf/src/golf/OptionsState.cpp @@ -3485,7 +3485,7 @@ void OptionsState::buildControlMenu(cro::Entity parent, const cro::SpriteSheet& //swingput enable entity = createSquareHighlight(glm::vec2(103.f, 38.f)); - entity.setLabel("Enables analogue swing with triggers and thumbstick.\n(BETA)"); + 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().setSelectionIndex(CtrlSwg); entity.getComponent().setNextIndex(CtrlRight, WindowAdvanced); entity.getComponent().setPrevIndex(CtrlReset, CtrlAltPower); diff --git a/samples/golf/src/golf/Swingput.cpp b/samples/golf/src/golf/Swingput.cpp index 0ac7ac226..6e3bcd192 100644 --- a/samples/golf/src/golf/Swingput.cpp +++ b/samples/golf/src/golf/Swingput.cpp @@ -147,14 +147,15 @@ bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std { default: return isActive(); case SDL_MOUSEBUTTONDOWN: - /*if (evt.button.button == SDL_BUTTON_RIGHT) + //return false; //disable for now + if (evt.button.button == SDL_BUTTON_RIGHT) { startStroke(); return true; - }*/ + } return false; case SDL_MOUSEBUTTONUP: - return false; //disable for now + //return false; //disable for now if (evt.button.button == SDL_BUTTON_RIGHT) { endStroke(); From f174e9e03773ff9a76740c3629f004a9125b05ec Mon Sep 17 00:00:00 2001 From: fallahn Date: Thu, 11 Apr 2024 13:33:17 +0100 Subject: [PATCH 15/24] fix typo in XP strings array --- samples/golf/buildnumber.h | 4 ++-- samples/golf/src/golf/Swingput.cpp | 4 ++-- samples/golf/src/golf/XPAwardStrings.hpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/samples/golf/buildnumber.h b/samples/golf/buildnumber.h index 0facb7ab4..a1f2c14e5 100644 --- a/samples/golf/buildnumber.h +++ b/samples/golf/buildnumber.h @@ -3,7 +3,7 @@ #ifndef BUILD_NUMBER_H_ #define BUILD_NUMBER_H_ -#define BUILDNUMBER 5289 -#define BUILDNUMBER_STR "5289" +#define BUILDNUMBER 5291 +#define BUILDNUMBER_STR "5291" #endif /* BUILD_NUMBER_H_ */ diff --git a/samples/golf/src/golf/Swingput.cpp b/samples/golf/src/golf/Swingput.cpp index 6e3bcd192..dfcf500b5 100644 --- a/samples/golf/src/golf/Swingput.cpp +++ b/samples/golf/src/golf/Swingput.cpp @@ -147,7 +147,7 @@ bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std { default: return isActive(); case SDL_MOUSEBUTTONDOWN: - //return false; //disable for now + return false; //disable for now if (evt.button.button == SDL_BUTTON_RIGHT) { startStroke(); @@ -155,7 +155,7 @@ bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std } return false; case SDL_MOUSEBUTTONUP: - //return false; //disable for now + return false; //disable for now if (evt.button.button == SDL_BUTTON_RIGHT) { endStroke(); diff --git a/samples/golf/src/golf/XPAwardStrings.hpp b/samples/golf/src/golf/XPAwardStrings.hpp index 3d8ad0fe3..811e13bb7 100644 --- a/samples/golf/src/golf/XPAwardStrings.hpp +++ b/samples/golf/src/golf/XPAwardStrings.hpp @@ -80,7 +80,7 @@ static inline const std::array XPStrings = std::string("Nice On!"), "Near Miss", "Great Accuracy", - "Nice Timing!" + "Nice Timing!", "Fairway", "Drone Hit!", "Course Complete", From 43f2bc3a34891226d327a19acd3bfd36371945e0 Mon Sep 17 00:00:00 2001 From: fallahn Date: Fri, 12 Apr 2024 09:38:02 +0100 Subject: [PATCH 16/24] allow switching courses in lobby with prev/next club key binding allow switching profile selection with prev/next club key binding --- samples/golf/buildnumber.h | 4 +- samples/golf/src/golf/MenuState.cpp | 69 +++++++++++++++++++---------- 2 files changed, 47 insertions(+), 26 deletions(-) diff --git a/samples/golf/buildnumber.h b/samples/golf/buildnumber.h index a1f2c14e5..b7c87cdd6 100644 --- a/samples/golf/buildnumber.h +++ b/samples/golf/buildnumber.h @@ -3,7 +3,7 @@ #ifndef BUILD_NUMBER_H_ #define BUILD_NUMBER_H_ -#define BUILDNUMBER 5291 -#define BUILDNUMBER_STR "5291" +#define BUILDNUMBER 5292 +#define BUILDNUMBER_STR "5292" #endif /* BUILD_NUMBER_H_ */ diff --git a/samples/golf/src/golf/MenuState.cpp b/samples/golf/src/golf/MenuState.cpp index cf086541b..c65def073 100644 --- a/samples/golf/src/golf/MenuState.cpp +++ b/samples/golf/src/golf/MenuState.cpp @@ -580,6 +580,38 @@ MenuState::~MenuState() //public bool MenuState::handleEvent(const cro::Event& evt) { + const auto doNext = [&]() + { + if (m_sharedData.hosting + && m_currentMenu == MenuID::Lobby + && m_lobbyWindowEntities[LobbyEntityID::HoleSelection].getComponent().getScale().x != 0) + { + nextCourse(); + } + else if (m_currentMenu == MenuID::Avatar) + { + auto i = m_rosterMenu.profileIndices[m_rosterMenu.activeIndex]; + i = (i + 1) % m_profileData.playerProfiles.size(); + setProfileIndex(i); + } + }; + + const auto doPrev = [&]() + { + if (m_sharedData.hosting + && m_currentMenu == MenuID::Lobby + && m_lobbyWindowEntities[LobbyEntityID::HoleSelection].getComponent().getScale().x != 0) + { + prevCourse(); + } + else if (m_currentMenu == MenuID::Avatar) + { + auto i = m_rosterMenu.profileIndices[m_rosterMenu.activeIndex]; + i = (i + (m_profileData.playerProfiles.size() - 1)) % m_profileData.playerProfiles.size(); + setProfileIndex(i); + } + }; + const auto showOptions = [&]() { if (m_currentMenu == MenuID::Lobby) @@ -743,6 +775,17 @@ bool MenuState::handleEvent(const cro::Event& evt) if (evt.type == SDL_KEYUP) { setChatHint(false, 0); + + if (evt.key.keysym.sym == m_sharedData.inputBinding.keys[InputBinding::PrevClub]) + { + doPrev(); + } + else if (evt.key.keysym.sym == m_sharedData.inputBinding.keys[InputBinding::NextClub]) + { + doNext(); + } + + switch (evt.key.keysym.sym) { default: break; @@ -915,32 +958,10 @@ bool MenuState::handleEvent(const cro::Event& evt) quitMenu(); break; case cro::GameController::ButtonRightShoulder: - if (m_sharedData.hosting - && m_currentMenu == MenuID::Lobby - && m_lobbyWindowEntities[LobbyEntityID::HoleSelection].getComponent().getScale().x != 0) - { - nextCourse(); - } - else if (m_currentMenu == MenuID::Avatar) - { - auto i = m_rosterMenu.profileIndices[m_rosterMenu.activeIndex]; - i = (i + 1) % m_profileData.playerProfiles.size(); - setProfileIndex(i); - } + doNext(); break; case cro::GameController::ButtonLeftShoulder: - if (m_sharedData.hosting - && m_currentMenu == MenuID::Lobby - && m_lobbyWindowEntities[LobbyEntityID::HoleSelection].getComponent().getScale().x != 0) - { - prevCourse(); - } - else if (m_currentMenu == MenuID::Avatar) - { - auto i = m_rosterMenu.profileIndices[m_rosterMenu.activeIndex]; - i = (i + (m_profileData.playerProfiles.size() - 1)) % m_profileData.playerProfiles.size(); - setProfileIndex(i); - } + doPrev(); break; case cro::GameController::ButtonGuide: togglePreviousScoreCard(); From 303f20178d853073876223f360c0c8c301133d03 Mon Sep 17 00:00:00 2001 From: fallahn Date: Fri, 12 Apr 2024 12:18:31 +0100 Subject: [PATCH 17/24] add text hint to free play lobby for course switching --- samples/golf/buildnumber.h | 4 +- samples/golf/src/golf/CommandIDs.hpp | 3 +- samples/golf/src/golf/MenuCreation.cpp | 121 +++++++++++++++++++++++++ samples/golf/src/golf/MenuState.cpp | 39 +++++++- 4 files changed, 162 insertions(+), 5 deletions(-) diff --git a/samples/golf/buildnumber.h b/samples/golf/buildnumber.h index b7c87cdd6..f257dd7bf 100644 --- a/samples/golf/buildnumber.h +++ b/samples/golf/buildnumber.h @@ -3,7 +3,7 @@ #ifndef BUILD_NUMBER_H_ #define BUILD_NUMBER_H_ -#define BUILDNUMBER 5292 -#define BUILDNUMBER_STR "5292" +#define BUILDNUMBER 5312 +#define BUILDNUMBER_STR "5312" #endif /* BUILD_NUMBER_H_ */ diff --git a/samples/golf/src/golf/CommandIDs.hpp b/samples/golf/src/golf/CommandIDs.hpp index 85f60c4ae..d37a07762 100644 --- a/samples/golf/src/golf/CommandIDs.hpp +++ b/samples/golf/src/golf/CommandIDs.hpp @@ -115,7 +115,8 @@ struct CommandID final CourseType = 0x80000, MetricClub = 0x100000, //used in the stats viewer for club labels ImperialClub = 0x200000, - ChatHint = 0x400000 + ChatHint = 0x400000, + CourseHint = 0x800000 }; }; }; \ No newline at end of file diff --git a/samples/golf/src/golf/MenuCreation.cpp b/samples/golf/src/golf/MenuCreation.cpp index 618cde857..b0a3df16e 100644 --- a/samples/golf/src/golf/MenuCreation.cpp +++ b/samples/golf/src/golf/MenuCreation.cpp @@ -1743,6 +1743,127 @@ void MenuState::createLobbyMenu(cro::Entity parent, std::uint32_t mouseEnter, st auto bgEnt = entity; auto bgBounds = bounds; + + //shows a button hint for switching courses if hosting + entity = m_uiScene.createEntity(); + entity.addComponent().setPosition({ (bgBounds.width / 2.f) - 180.f, bgBounds.height - 15.f, -0.2f }); + entity.addComponent(); + entity.addComponent() = spriteSheetV2.getSprite("button_hint"); + entity.addComponent().active = true; + entity.getComponent().function = + [&](cro::Entity e, float dt) + { + static constexpr float HideOffset = 16.f; + float target = HideOffset; + if (m_sharedData.hosting) + { + //hmm, seems a funny way to tell which page we're on + //but it does the job I guess + if (m_lobbyWindowEntities[LobbyEntityID::HoleSelection].getComponent().getScale().x != 0) + { + target = 0.f; + } + } + + const float Speed = 56.f * dt; + auto origin = e.getComponent().getOrigin(); + if (target > origin.y) + { + origin.y = std::min(target, origin.y + Speed); + } + else + { + origin.y = std::max(target, origin.y - Speed); + } + e.getComponent().setOrigin(origin); + }; + bgEnt.getComponent().addChild(entity.getComponent()); + auto buttonEnt = entity; + + //button icons + struct IconCallback final + { + void operator()(cro::Entity e, float) + { + if (cro::GameController::isConnected(0)) + { + if (cro::GameController::hasPSLayout(0)) + { + e.getComponent().play(1); + } + else + { + e.getComponent().play(0); + } + } + e.getComponent().active = false; + } + }; + entity = m_uiScene.createEntity(); + entity.addComponent().setPosition({ 12.f, 0.f, 0.1f }); + entity.addComponent().setFacing(cro::Drawable2D::Facing::Back); + entity.addComponent() = spriteSheetV2.getSprite("lb"); + entity.addComponent(); + entity.addComponent().active = false; //set true but the UI command + entity.getComponent().function = IconCallback(); + entity.addComponent().ID = CommandID::Menu::CourseHint; + buttonEnt.getComponent().addChild(entity.getComponent()); + + entity = m_uiScene.createEntity(); + entity.addComponent().setPosition({ 330.f, 0.f, 0.1f }); + entity.addComponent().setFacing(cro::Drawable2D::Facing::Back); + entity.addComponent(); + entity.addComponent() = spriteSheetV2.getSprite("rb"); + entity.addComponent(); + entity.addComponent().active = false; + entity.getComponent().function = IconCallback(); + entity.addComponent().ID = CommandID::Menu::CourseHint; + buttonEnt.getComponent().addChild(entity.getComponent()); + + + //button texts + struct TextCallback final + { + std::int32_t keybind = InputBinding::PrevClub; + const SharedStateData& sharedData; + explicit TextCallback(std::int32_t kb, const SharedStateData& sd) : keybind(kb), sharedData(sd) {} + + void operator()(cro::Entity e, float) + { + auto s = cro::Keyboard::keyString(sharedData.inputBinding.keys[keybind]); + e.getComponent().setString(s); + e.getComponent().active = false; + } + }; + entity = m_uiScene.createEntity(); + entity.addComponent().setPosition({ 23.f, 9.f, 0.1f }); + entity.addComponent(); + entity.addComponent(font).setString("X"); + entity.getComponent().setFillColour(TextNormalColour); + entity.getComponent().setShadowColour(LeaderboardTextDark); + entity.getComponent().setShadowOffset({ 1.f, -1.f }); + entity.getComponent().setCharacterSize(UITextSize); + entity.getComponent().setAlignment(cro::Text::Alignment::Centre); + entity.addComponent().active = false; //command sets this to true so we only update on switch + entity.getComponent().function = TextCallback(InputBinding::PrevClub, m_sharedData); + entity.addComponent().ID = CommandID::Menu::CourseHint; + buttonEnt.getComponent().addChild(entity.getComponent()); + + entity = m_uiScene.createEntity(); + entity.addComponent().setPosition({ 337.f, 9.f, 0.1f }); + entity.addComponent(); + entity.addComponent(font).setString("Y"); + entity.getComponent().setFillColour(TextNormalColour); + entity.getComponent().setShadowColour(LeaderboardTextDark); + entity.getComponent().setShadowOffset({ 1.f, -1.f }); + entity.getComponent().setCharacterSize(UITextSize); + entity.getComponent().setAlignment(cro::Text::Alignment::Centre); + entity.addComponent().active = false; + entity.getComponent().function = TextCallback(InputBinding::NextClub, m_sharedData); + entity.addComponent().ID = CommandID::Menu::CourseHint; + buttonEnt.getComponent().addChild(entity.getComponent()); + + #ifdef USE_GNS //scrolls info about the selected course auto& labelFont = m_sharedData.sharedResources->fonts.get(FontID::Label); diff --git a/samples/golf/src/golf/MenuState.cpp b/samples/golf/src/golf/MenuState.cpp index c65def073..c09c234e8 100644 --- a/samples/golf/src/golf/MenuState.cpp +++ b/samples/golf/src/golf/MenuState.cpp @@ -639,7 +639,7 @@ bool MenuState::handleEvent(const cro::Event& evt) } }; - const auto setChatHint = + const auto setChatHint = //also sets the hint icons for switching courses [&](bool controller, std::int32_t joyID) { cro::Command cmd; @@ -653,7 +653,7 @@ bool MenuState::handleEvent(const cro::Event& evt) { e.getComponent().setScale(glm::vec2(1.f)); m_uiScene.getActiveCamera().getComponent().active = true; - if (cro::GameController::hasPSLayout(/*cro::GameController::controllerID(joyID)*/0)) + if (cro::GameController::hasPSLayout(0)) { e.getComponent().play(1); } @@ -684,6 +684,40 @@ bool MenuState::handleEvent(const cro::Event& evt) }; } m_uiScene.getSystem()->sendCommand(cmd); + + //update the hint about switching courses + cmd.targetFlags = CommandID::Menu::CourseHint; + if (controller) + { + cmd.action = [](cro::Entity e, float) + { + if (e.hasComponent()) + { + e.getComponent().setFacing(cro::Drawable2D::Facing::Front); + e.getComponent().active = true; //updates the animation + } + else + { + e.getComponent().setFacing(cro::Drawable2D::Facing::Back); + } + }; + } + else + { + cmd.action = [](cro::Entity e, float) + { + if (e.hasComponent()) + { + e.getComponent().setFacing(cro::Drawable2D::Facing::Back); + } + else + { + e.getComponent().setFacing(cro::Drawable2D::Facing::Front); + e.getComponent().active = true; //updates the string + } + }; + } + m_uiScene.getSystem()->sendCommand(cmd); }; const auto quitMenu = @@ -1012,6 +1046,7 @@ bool MenuState::handleEvent(const cro::Event& evt) else if (evt.type == SDL_MOUSEMOTION) { cro::App::getWindow().setMouseCaptured(false); + setChatHint(false, 0); } else if (evt.type == SDL_CONTROLLERAXISMOTION) { From a2925e6d0a6e55b7b27aa9a501730ca698ec4ed5 Mon Sep 17 00:00:00 2001 From: fallahn Date: Fri, 12 Apr 2024 13:19:11 +0100 Subject: [PATCH 18/24] add toggling minimap zoom with left stick button --- samples/golf/buildnumber.h | 4 ++-- samples/golf/src/golf/GolfState.cpp | 7 ++++++ samples/golf/src/golf/InputBinding.hpp | 1 + samples/golf/src/golf/InputParser.cpp | 31 ++++++++++++++++++++++++++ samples/golf/src/golf/InputParser.hpp | 2 ++ samples/golf/src/golf/MessageIDs.hpp | 1 + 6 files changed, 44 insertions(+), 2 deletions(-) diff --git a/samples/golf/buildnumber.h b/samples/golf/buildnumber.h index f257dd7bf..477554538 100644 --- a/samples/golf/buildnumber.h +++ b/samples/golf/buildnumber.h @@ -3,7 +3,7 @@ #ifndef BUILD_NUMBER_H_ #define BUILD_NUMBER_H_ -#define BUILDNUMBER 5312 -#define BUILDNUMBER_STR "5312" +#define BUILDNUMBER 5314 +#define BUILDNUMBER_STR "5314" #endif /* BUILD_NUMBER_H_ */ diff --git a/samples/golf/src/golf/GolfState.cpp b/samples/golf/src/golf/GolfState.cpp index 68f144097..51e7c5aae 100644 --- a/samples/golf/src/golf/GolfState.cpp +++ b/samples/golf/src/golf/GolfState.cpp @@ -1175,6 +1175,13 @@ void GolfState::handleMessage(const cro::Message& msg) setActiveCamera(data.data); } break; + case SceneEvent::RequestToggleMinimap: + { + auto& [_, dir] = m_mapRoot.getComponent().getUserData>(); + dir = (dir == 0) ? 1 : 0; + m_mapRoot.getComponent().active = true; + } + break; } } break; diff --git a/samples/golf/src/golf/InputBinding.hpp b/samples/golf/src/golf/InputBinding.hpp index e12eb9b0b..87ead0110 100644 --- a/samples/golf/src/golf/InputBinding.hpp +++ b/samples/golf/src/golf/InputBinding.hpp @@ -54,6 +54,7 @@ namespace InputFlag SwitchView = EmoteWheel, Swingput = 0x400, + MiniMap = 0x800, All = 0xFFFF }; diff --git a/samples/golf/src/golf/InputParser.cpp b/samples/golf/src/golf/InputParser.cpp index e2d7c1031..b31f92c85 100644 --- a/samples/golf/src/golf/InputParser.cpp +++ b/samples/golf/src/golf/InputParser.cpp @@ -202,6 +202,12 @@ void InputParser::handleEvent(const cro::Event& evt) { toggleDroneCam(); } + + else if (evt.key.keysym.sym == SDLK_PAGEUP) + { + m_inputFlags |= InputFlag::MiniMap; + m_minimapToggleTimer.restart(); + } } else if (evt.type == SDL_KEYUP) { @@ -246,6 +252,11 @@ void InputParser::handleEvent(const cro::Event& evt) { m_inputFlags &= ~InputFlag::SpinMenu; } + + else if (evt.key.keysym.sym == SDLK_PAGEUP) + { + m_inputFlags &= ~InputFlag::MiniMap; + } } else if (evt.type == SDL_CONTROLLERBUTTONDOWN) { @@ -299,6 +310,12 @@ void InputParser::handleEvent(const cro::Event& evt) { toggleDroneCam(); } + //people say this happens accidentally, so let's use a timer + else if (evt.cbutton.button == cro::GameController::ButtonLeftStick) + { + m_inputFlags |= InputFlag::MiniMap; + m_minimapToggleTimer.restart(); + } } } else if (evt.type == SDL_CONTROLLERBUTTONUP) @@ -353,6 +370,11 @@ void InputParser::handleEvent(const cro::Event& evt) { m_inputFlags &= ~InputFlag::Down; } + + else if (evt.cbutton.button == cro::GameController::ButtonLeftStick) + { + m_inputFlags &= ~InputFlag::MiniMap; + } } } @@ -651,6 +673,15 @@ void InputParser::update(float dt) } else { + //if the stick is held, toggle the mini map + if ((m_inputFlags & InputFlag::MiniMap) + && m_minimapToggleTimer.elapsed() > cro::seconds(0.5f)) + { + cro::App::postMessage(MessageID::SceneMessage)->type = SceneEvent::RequestToggleMinimap; + + m_inputFlags &= ~InputFlag::MiniMap; + } + //drone controls handle controller independently checkControllerInput(); checkMouseInput(); diff --git a/samples/golf/src/golf/InputParser.hpp b/samples/golf/src/golf/InputParser.hpp index 656fc0cff..a29d9b626 100644 --- a/samples/golf/src/golf/InputParser.hpp +++ b/samples/golf/src/golf/InputParser.hpp @@ -169,6 +169,8 @@ class InputParser final void checkMouseInput(); glm::vec2 getRotationalInput(std::int32_t xAxis, std::int32_t yAxis) const; //used for drone cam and spin amount + cro::Clock m_minimapToggleTimer; + cro::Clock m_iconTimer; bool m_iconActive; void beginIcon(); diff --git a/samples/golf/src/golf/MessageIDs.hpp b/samples/golf/src/golf/MessageIDs.hpp index 635a71a63..3853e6bc6 100644 --- a/samples/golf/src/golf/MessageIDs.hpp +++ b/samples/golf/src/golf/MessageIDs.hpp @@ -104,6 +104,7 @@ struct SceneEvent TransitionStart, TransitionComplete, RequestSwitchCamera, + RequestToggleMinimap, PlayerIdle, PlayerRotate, PlayerBad, From f1a2b425ed7b10d09488c5c7554dd27a51c6db2a Mon Sep 17 00:00:00 2001 From: fallahn Date: Fri, 12 Apr 2024 14:09:44 +0100 Subject: [PATCH 19/24] increase hitbox area of selection buttons --- samples/golf/buildnumber.h | 4 ++-- samples/golf/src/golf/MenuCreation.cpp | 8 ++++---- samples/golf/src/golf/ProfileState.cpp | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/samples/golf/buildnumber.h b/samples/golf/buildnumber.h index 477554538..b0442723e 100644 --- a/samples/golf/buildnumber.h +++ b/samples/golf/buildnumber.h @@ -3,7 +3,7 @@ #ifndef BUILD_NUMBER_H_ #define BUILD_NUMBER_H_ -#define BUILDNUMBER 5314 -#define BUILDNUMBER_STR "5314" +#define BUILDNUMBER 5317 +#define BUILDNUMBER_STR "5317" #endif /* BUILD_NUMBER_H_ */ diff --git a/samples/golf/src/golf/MenuCreation.cpp b/samples/golf/src/golf/MenuCreation.cpp index b0a3df16e..91a5a6f83 100644 --- a/samples/golf/src/golf/MenuCreation.cpp +++ b/samples/golf/src/golf/MenuCreation.cpp @@ -4038,8 +4038,8 @@ void MenuState::addCourseSelectButtons() buttonEnt.addComponent().absolutePosition = { 6.f, 101.f }; buttonEnt.getComponent().depth = 0.01f; bounds = buttonEnt.getComponent().getTextureBounds(); - bounds.bottom -= 6.f; - bounds.height += 12.f; + bounds.bottom -= 16.f; + bounds.height += 32.f; buttonEnt.addComponent().area = bounds; buttonEnt.getComponent().setGroup(MenuID::Lobby); buttonEnt.getComponent().setSelectionIndex(CoursePrev); @@ -4068,8 +4068,8 @@ void MenuState::addCourseSelectButtons() buttonEnt.addComponent().absolutePosition = { 159.f, 101.f }; buttonEnt.getComponent().depth = 0.01f; bounds = buttonEnt.getComponent().getTextureBounds(); - bounds.bottom -= 6.f; - bounds.height += 12.f; + bounds.bottom -= 16.f; + bounds.height += 32.f; buttonEnt.addComponent().area = bounds; buttonEnt.getComponent().setGroup(MenuID::Lobby); buttonEnt.getComponent().setSelectionIndex(CourseNext); diff --git a/samples/golf/src/golf/ProfileState.cpp b/samples/golf/src/golf/ProfileState.cpp index 6050dc517..6e3325aea 100644 --- a/samples/golf/src/golf/ProfileState.cpp +++ b/samples/golf/src/golf/ProfileState.cpp @@ -1061,8 +1061,8 @@ void ProfileState::buildScene() [](cro::Entity e) { auto bounds = e.getComponent().area; - bounds.bottom -= 8.f; - bounds.height += 16.f; + bounds.bottom -= 16.f; + bounds.height += 32.f; e.getComponent().area = bounds; }; From 856a599c27a392056de948f04d0bd34015088611 Mon Sep 17 00:00:00 2001 From: fallahn Date: Fri, 12 Apr 2024 14:40:27 +0100 Subject: [PATCH 20/24] add hint label to profile editor --- samples/golf/buildnumber.h | 4 +-- samples/golf/src/golf/ProfileState.cpp | 47 ++++++++++++++++++++++++-- samples/golf/src/golf/ProfileState.hpp | 2 +- 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/samples/golf/buildnumber.h b/samples/golf/buildnumber.h index b0442723e..5a5008110 100644 --- a/samples/golf/buildnumber.h +++ b/samples/golf/buildnumber.h @@ -3,7 +3,7 @@ #ifndef BUILD_NUMBER_H_ #define BUILD_NUMBER_H_ -#define BUILDNUMBER 5317 -#define BUILDNUMBER_STR "5317" +#define BUILDNUMBER 5324 +#define BUILDNUMBER_STR "5324" #endif /* BUILD_NUMBER_H_ */ diff --git a/samples/golf/src/golf/ProfileState.cpp b/samples/golf/src/golf/ProfileState.cpp index 6e3325aea..6f1360c0e 100644 --- a/samples/golf/src/golf/ProfileState.cpp +++ b/samples/golf/src/golf/ProfileState.cpp @@ -815,8 +815,22 @@ void ProfileState::buildScene() e.getComponent().setColour(cro::Colour::White); e.getComponent().active = true; m_audioEnts[AudioID::Accept].getComponent().play(); + + const auto& str = e.getLabel(); + if (str.empty()) + { + m_menuEntities[EntityID::TipText].getComponent().setString(" "); + } + else + { + m_menuEntities[EntityID::TipText].getComponent().setString(str); + } + }); + auto unselected = uiSystem.addCallback([&](cro::Entity e) + { + e.getComponent().setColour(cro::Colour::Transparent); + m_menuEntities[EntityID::TipText].getComponent().setString(" "); }); - auto unselected = uiSystem.addCallback([](cro::Entity e) {e.getComponent().setColour(cro::Colour::Transparent); }); const auto createButton = [&](const std::string& spriteID, glm::vec2 position, std::int32_t selectionIndex) { @@ -860,6 +874,7 @@ void ProfileState::buildScene() entity.getComponent().setNextIndex(ButtonHairBrowse, ButtonHairColour); entity.getComponent().setPrevIndex(ButtonName, ButtonRandomise); + entity.setLabel("Open Steam Workshop In Overlay"); #endif //colour swatch - this has its own update function @@ -1026,6 +1041,7 @@ void ProfileState::buildScene() //hat select button entity = m_uiScene.createEntity(); + entity.setLabel("Open Headwear Browser"); entity.addComponent().setPosition({163.f, 214.f, 0.5f}); entity.addComponent(); entity.addComponent() = spriteSheet.getSprite("hat_select"); @@ -1044,6 +1060,8 @@ void ProfileState::buildScene() { e.getComponent().setTextureRect(rect); m_audioEnts[AudioID::Select].getComponent().play(); + + m_menuEntities[EntityID::TipText].getComponent().setString(e.getLabel()); }); entity.getComponent().callbacks[cro::UIInput::ButtonUp] = uiSystem.addCallback([&](cro::Entity, const cro::ButtonEvent& evt) @@ -1081,6 +1099,7 @@ void ProfileState::buildScene() }); hairLeft.getComponent().setNextIndex(ButtonHairBrowse, ButtonPrevBody); hairLeft.getComponent().setPrevIndex(ButtonHairColour, ButtonPrevBody); + hairLeft.setLabel("Previous Headwear"); expandHitbox(hairLeft); auto hairRight = createButton("arrow_right", glm::vec2(234.f, 156.f), ButtonNextHair); @@ -1096,6 +1115,7 @@ void ProfileState::buildScene() }); hairRight.getComponent().setNextIndex(ButtonPrevBall, ButtonNextBody); hairRight.getComponent().setPrevIndex(ButtonHairBrowse, ButtonNextBody); + hairRight.setLabel("Next Headwear"); expandHitbox(hairRight); auto avatarLeft = createButton("arrow_left", glm::vec2(87.f, 110.f), ButtonPrevBody); @@ -1110,6 +1130,7 @@ void ProfileState::buildScene() }); avatarLeft.getComponent().setNextIndex(ButtonNextBody, ButtonPrevHair); avatarLeft.getComponent().setPrevIndex(ButtonTopDark, ButtonPrevHair); + avatarLeft.setLabel("Previous Avatar"); expandHitbox(avatarLeft); auto avatarRight = createButton("arrow_right", glm::vec2(234.f, 110.f), ButtonNextBody); @@ -1124,6 +1145,7 @@ void ProfileState::buildScene() }); avatarRight.getComponent().setNextIndex(ButtonPrevBall, ButtonNextHair); avatarRight.getComponent().setPrevIndex(ButtonPrevBody, ButtonNextHair); + avatarRight.setLabel("Next Avatar"); expandHitbox(avatarRight); //checkbox @@ -1139,6 +1161,7 @@ void ProfileState::buildScene() }); southPaw.getComponent().setNextIndex(ButtonSaveClose, ButtonRandomise); southPaw.getComponent().setPrevIndex(ButtonSaveClose, ButtonBottomLight); + southPaw.setLabel("Use Left Handed Avatar"); auto innerEnt = m_uiScene.createEntity(); innerEnt.addComponent().setPosition(glm::vec3(19.f, 52.f, 0.1f)); @@ -1261,6 +1284,7 @@ void ProfileState::buildScene() }); ballLeft.getComponent().setNextIndex(ButtonBallSelect, ButtonBallColour); ballLeft.getComponent().setPrevIndex(ButtonNextHair, ButtonName); + ballLeft.setLabel("Previous Ball"); expandHitbox(ballLeft); //toggles the ball browser @@ -1281,6 +1305,7 @@ void ProfileState::buildScene() }); ballThumb.getComponent().setNextIndex(ButtonNextBall, ButtonBallColour); ballThumb.getComponent().setPrevIndex(ButtonPrevBall, ButtonName); + ballThumb.setLabel("Open Ball Browser"); auto ballRight = createButton("arrow_right", glm::vec2(382.f, 144.f), ButtonNextBall); ballRight.getComponent().callbacks[cro::UIInput::ButtonUp] = @@ -1295,6 +1320,7 @@ void ProfileState::buildScene() }); ballRight.getComponent().setNextIndex(ButtonDescUp, ButtonBallColourReset); ballRight.getComponent().setPrevIndex(ButtonBallSelect, ButtonName); + ballRight.setLabel("Next Ball"); expandHitbox(ballRight); @@ -1328,6 +1354,7 @@ void ProfileState::buildScene() m_lastSelected = e.getComponent().getSelectionIndex(); } }); + ballColour.setLabel("Choose Ball Tint"); entity = m_uiScene.createEntity(); entity.addComponent().setPosition({ 316.f, 78.f, 0.1f }); @@ -1370,6 +1397,7 @@ void ProfileState::buildScene() m_audioEnts[AudioID::Back].getComponent().play(); } }); + ballColourReset.setLabel("Reset Ball Tint"); //updates the profile icon @@ -1777,7 +1805,7 @@ void ProfileState::buildScene() //help string bounds = bgEnt.getComponent().getTextureBounds(); entity = m_uiScene.createEntity(); - entity.addComponent().setPosition({bounds.width / 2.f, 14.f, 0.1f}); + entity.addComponent().setPosition({/*bounds.width / 2.f*/164.f, 14.f, 0.1f}); entity.addComponent(); entity.addComponent(smallFont); entity.getComponent().setFillColour(TextNormalColour); @@ -1788,6 +1816,21 @@ void ProfileState::buildScene() m_menuEntities[EntityID::HelpText] = entity; + //button help string + entity = m_uiScene.createEntity(); + entity.addComponent().setPosition({bounds.width - 126.f, 14.f, 0.1f }); + entity.addComponent(); + entity.addComponent(smallFont); + entity.getComponent().setFillColour(TextNormalColour); + entity.getComponent().setShadowColour(LeaderboardTextDark); + entity.getComponent().setShadowOffset({ 1.f, -1.f }); + entity.getComponent().setCharacterSize(InfoTextSize); + entity.getComponent().setAlignment(cro::Text::Alignment::Centre); + //entity.getComponent().setString("This is some test text. Hello!"); + bgEnt.getComponent().addChild(entity.getComponent()); + m_menuEntities[EntityID::TipText] = entity; + + CallbackContext ctx; ctx.spriteSheet.loadFromFile("assets/golf/sprites/avatar_browser.spt", m_resources.textures); ctx.createArrow = diff --git a/samples/golf/src/golf/ProfileState.hpp b/samples/golf/src/golf/ProfileState.hpp index 2d0710d8b..12e02bca7 100644 --- a/samples/golf/src/golf/ProfileState.hpp +++ b/samples/golf/src/golf/ProfileState.hpp @@ -117,7 +117,7 @@ class ProfileState final : public cro::State, public cro::GuiClient Root, HelpText, Mugshot, NameText, Swatch, AvatarPreview, - BioText, + BioText, TipText, BallBrowser, HairBrowser, From e055475622e8765730e9b0876d6f736358c285dc Mon Sep 17 00:00:00 2001 From: fallahn Date: Sat, 13 Apr 2024 09:18:50 +0100 Subject: [PATCH 21/24] prevent new profile creator trying to pick locked cosmetics at random --- libsocial/include/Input.hpp | 3 ++- samples/golf/buildnumber.h | 4 +-- samples/golf/src/golf/MenuAvatars.cpp | 9 ++++--- samples/golf/src/golf/MenuCreation.cpp | 1 - samples/golf/src/golf/MenuCustomisation.cpp | 27 +++++++++++++++++++-- samples/golf/src/golf/MenuState.hpp | 7 ++++++ samples/golf/src/golf/Swingput.cpp | 5 ++-- 7 files changed, 45 insertions(+), 11 deletions(-) diff --git a/libsocial/include/Input.hpp b/libsocial/include/Input.hpp index 3257218f3..445410046 100644 --- a/libsocial/include/Input.hpp +++ b/libsocial/include/Input.hpp @@ -133,7 +133,8 @@ namespace Progress { std::array buffer = {}; std::size_t i = 0u; - while (file.file->read(file.file, &buffer[i], 1, 1)) + while (file.file->read(file.file, &buffer[i], 1, 1) + && i < buffer.size() - 1) //TODO this is covering up a bug where the file being read was too large... { i++; } diff --git a/samples/golf/buildnumber.h b/samples/golf/buildnumber.h index 5a5008110..78ce34cdd 100644 --- a/samples/golf/buildnumber.h +++ b/samples/golf/buildnumber.h @@ -3,7 +3,7 @@ #ifndef BUILD_NUMBER_H_ #define BUILD_NUMBER_H_ -#define BUILDNUMBER 5324 -#define BUILDNUMBER_STR "5324" +#define BUILDNUMBER 5326 +#define BUILDNUMBER_STR "5326" #endif /* BUILD_NUMBER_H_ */ diff --git a/samples/golf/src/golf/MenuAvatars.cpp b/samples/golf/src/golf/MenuAvatars.cpp index 5690be9ca..615d0dcf1 100644 --- a/samples/golf/src/golf/MenuAvatars.cpp +++ b/samples/golf/src/golf/MenuAvatars.cpp @@ -942,9 +942,12 @@ void MenuState::createAvatarMenu(cro::Entity parent) { profile.avatarFlags[i] = static_cast(cro::Util::Random::value(0u, pc::PairCounts[i] - 1)); } - profile.skinID = m_sharedData.avatarInfo[cro::Util::Random::value(0u, m_sharedData.avatarInfo.size() - 1)].uid; - profile.ballID = m_sharedData.ballInfo[cro::Util::Random::value(0u, m_sharedData.ballInfo.size() - 1)].uid; - profile.hairID = m_sharedData.hairInfo[cro::Util::Random::value(0u, m_sharedData.hairInfo.size() - 1)].uid; + + //don't allow locked items duh + profile.skinID = m_cosmeticIDs.avatars[cro::Util::Random::value(0u, m_cosmeticIDs.avatars.size() - 1)]; + profile.ballID = m_cosmeticIDs.balls[cro::Util::Random::value(0u, m_cosmeticIDs.balls.size() - 1)]; + profile.hairID = m_cosmeticIDs.hair[cro::Util::Random::value(0u, m_cosmeticIDs.hair.size() - 1)]; + profile.flipped = cro::Util::Random::value(0, 1) == 0 ? false : true; profile.saveProfile(); m_profileData.activeProfileIndex = m_profileData.playerProfiles.size() - 1; diff --git a/samples/golf/src/golf/MenuCreation.cpp b/samples/golf/src/golf/MenuCreation.cpp index 91a5a6f83..eae1a8fab 100644 --- a/samples/golf/src/golf/MenuCreation.cpp +++ b/samples/golf/src/golf/MenuCreation.cpp @@ -1812,7 +1812,6 @@ void MenuState::createLobbyMenu(cro::Entity parent, std::uint32_t mouseEnter, st entity = m_uiScene.createEntity(); entity.addComponent().setPosition({ 330.f, 0.f, 0.1f }); entity.addComponent().setFacing(cro::Drawable2D::Facing::Back); - entity.addComponent(); entity.addComponent() = spriteSheetV2.getSprite("rb"); entity.addComponent(); entity.addComponent().active = false; diff --git a/samples/golf/src/golf/MenuCustomisation.cpp b/samples/golf/src/golf/MenuCustomisation.cpp index 4fc322d17..483254ec4 100644 --- a/samples/golf/src/golf/MenuCustomisation.cpp +++ b/samples/golf/src/golf/MenuCustomisation.cpp @@ -522,6 +522,15 @@ void MenuState::createBallScene() }), m_sharedData.ballInfo.end()); } + + //store valid/unlocked IDs so the new profile randomiser can pick one + for (const auto& i : m_sharedData.ballInfo) + { + if (!i.locked) + { + m_cosmeticIDs.balls.push_back(i.uid); + } + } } std::int32_t MenuState::indexFromBallID(std::uint32_t ballID) @@ -631,6 +640,14 @@ void MenuState::parseAvatarDirectory() } + //store the unlocked UIDs so the new profile can pick only unlocked avatars + for (const auto& i : m_sharedData.avatarInfo) + { + if (!i.locked) + { + m_cosmeticIDs.avatars.push_back(i.uid); + } + } //load hair models @@ -750,8 +767,14 @@ void MenuState::parseAvatarDirectory() } } - - + //honestly these are probably already sorted above, but let's just get this done + for (const auto& i : m_sharedData.hairInfo) + { + if (!i.locked) + { + m_cosmeticIDs.hair.push_back(i.uid); + } + } //these are just used in the player preview window diff --git a/samples/golf/src/golf/MenuState.hpp b/samples/golf/src/golf/MenuState.hpp index 3478187be..b9aad55d3 100644 --- a/samples/golf/src/golf/MenuState.hpp +++ b/samples/golf/src/golf/MenuState.hpp @@ -108,6 +108,13 @@ class MenuState final : public cro::State, public cro::GuiClient, public cro::Co std::int32_t m_connectedClientCount; std::int32_t m_connectedPlayerCount; + struct CosmeticID final + { + std::vector balls; + std::vector hair; + std::vector avatars; + }m_cosmeticIDs; + TextChat m_textChat; MatchMaking m_matchMaking; cro::ResourceCollection m_resources; diff --git a/samples/golf/src/golf/Swingput.cpp b/samples/golf/src/golf/Swingput.cpp index dfcf500b5..e773f261e 100644 --- a/samples/golf/src/golf/Swingput.cpp +++ b/samples/golf/src/golf/Swingput.cpp @@ -286,9 +286,10 @@ bool Swingput::handleEvent(const cro::Event& evt, std::uint16_t& inputFlags, std m_state = State::Inactive; const float t = m_tempoTimer.restart(); - m_hook = 0.5f + ((0.033f - std::min(t, 0.066f)) / 2.f); + m_hook = 0.5f + ((0.033f - std::min(t, 0.066f)) / 3.f); - if (std::floor(t * 1000.f) == 33.f) + const auto timing = std::floor(t * 1000.f); + if (timing == 33.f) { auto* msg = cro::App::postMessage(cl::MessageID::GolfMessage); msg->type = GolfEvent::NiceTiming; From 7665c46b2ad954861b7463ec8dd2abfef2784e98 Mon Sep 17 00:00:00 2001 From: fallahn Date: Sat, 13 Apr 2024 10:30:18 +0100 Subject: [PATCH 22/24] fix selecting last active league in non-steam build prefer the default golf ball when creating new profiles --- libsocial/include/Input.hpp | 16 +++++++++++----- samples/golf/buildnumber.h | 4 ++-- samples/golf/src/golf/CareerState.cpp | 3 ++- samples/golf/src/golf/MenuAvatars.cpp | 11 ++++++++++- samples/golf/src/golf/MenuConsts.hpp | 2 ++ samples/golf/src/golf/MenuCustomisation.cpp | 14 ++++++++++++++ 6 files changed, 41 insertions(+), 9 deletions(-) diff --git a/libsocial/include/Input.hpp b/libsocial/include/Input.hpp index 445410046..d72eae123 100644 --- a/libsocial/include/Input.hpp +++ b/libsocial/include/Input.hpp @@ -105,17 +105,20 @@ namespace Progress file.file = SDL_RWFromFile(path.c_str(), "wb"); if (file.file) { - file.file->write(file.file, &holeIndex, sizeof(holeIndex), 1); + static constexpr std::size_t MaxBytes = 26; //size of holeIndex + 18 scores. TODO this will make files INCOMPATIBLE cross platform if size_t is defined as a different size... + + auto written = file.file->write(file.file, &holeIndex, sizeof(holeIndex), 1); const auto scoreSize = std::min(std::size_t(18), holeScores.size()); for (auto i = 0u; i < scoreSize; ++i) { - file.file->write(file.file, &holeScores[i], 1, 1); + written += file.file->write(file.file, &holeScores[i], 1, 1); } - for (auto i = scoreSize; i < 18; ++i) + //for (auto i = scoreSize; i < 18; ++i) + while (written < MaxBytes) { std::uint8_t packing = 0; - file.file->write(file.file, &packing, 1, 1); + written += file.file->write(file.file, &packing, 1, 1); } } } @@ -131,10 +134,13 @@ namespace Progress file.file = SDL_RWFromFile(path.c_str(), "rb"); if (file.file) { + /*auto size = file.file->seek(file.file, 0, RW_SEEK_END); + file.file->seek(file.file, 0, RW_SEEK_SET);*/ + std::array buffer = {}; std::size_t i = 0u; while (file.file->read(file.file, &buffer[i], 1, 1) - && i < buffer.size() - 1) //TODO this is covering up a bug where the file being read was too large... + && i < buffer.size() - 1) //hm some existing files have 1 byte padding too many { i++; } diff --git a/samples/golf/buildnumber.h b/samples/golf/buildnumber.h index 78ce34cdd..4fa76c714 100644 --- a/samples/golf/buildnumber.h +++ b/samples/golf/buildnumber.h @@ -3,7 +3,7 @@ #ifndef BUILD_NUMBER_H_ #define BUILD_NUMBER_H_ -#define BUILDNUMBER 5326 -#define BUILDNUMBER_STR "5326" +#define BUILDNUMBER 5328 +#define BUILDNUMBER_STR "5328" #endif /* BUILD_NUMBER_H_ */ diff --git a/samples/golf/src/golf/CareerState.cpp b/samples/golf/src/golf/CareerState.cpp index a6eef10d7..f07d8e272 100644 --- a/samples/golf/src/golf/CareerState.cpp +++ b/samples/golf/src/golf/CareerState.cpp @@ -334,7 +334,8 @@ void CareerState::buildScene() //check if we just completed a league, and if we did and it's //one less than max leagues, increment our current round id auto currIdx = std::max(0, m_sharedData.leagueRoundID - 1); - if (currIdx == m_maxLeagueIndex - 1) + if (currIdx != 0 && + currIdx == m_maxLeagueIndex - 1) { if (Career::instance().getLeagueTables()[currIdx].getCurrentIteration() == 0) { diff --git a/samples/golf/src/golf/MenuAvatars.cpp b/samples/golf/src/golf/MenuAvatars.cpp index 615d0dcf1..cb852dfee 100644 --- a/samples/golf/src/golf/MenuAvatars.cpp +++ b/samples/golf/src/golf/MenuAvatars.cpp @@ -945,8 +945,17 @@ void MenuState::createAvatarMenu(cro::Entity parent) //don't allow locked items duh profile.skinID = m_cosmeticIDs.avatars[cro::Util::Random::value(0u, m_cosmeticIDs.avatars.size() - 1)]; - profile.ballID = m_cosmeticIDs.balls[cro::Util::Random::value(0u, m_cosmeticIDs.balls.size() - 1)]; profile.hairID = m_cosmeticIDs.hair[cro::Util::Random::value(0u, m_cosmeticIDs.hair.size() - 1)]; + //prefer the white ball by default + if (std::find(m_cosmeticIDs.balls.begin(), m_cosmeticIDs.balls.end(), DefaultBallID) != m_cosmeticIDs.balls.end()) + { + profile.ballID = DefaultBallID; + } + else + { + profile.ballID = m_cosmeticIDs.balls[cro::Util::Random::value(0u, m_cosmeticIDs.balls.size() - 1)]; + + } profile.flipped = cro::Util::Random::value(0, 1) == 0 ? false : true; profile.saveProfile(); diff --git a/samples/golf/src/golf/MenuConsts.hpp b/samples/golf/src/golf/MenuConsts.hpp index 26c1ea90f..8d93f663e 100644 --- a/samples/golf/src/golf/MenuConsts.hpp +++ b/samples/golf/src/golf/MenuConsts.hpp @@ -129,6 +129,8 @@ static constexpr std::array EmotePositions = glm::vec3(24.f, -24.f, 0.15f) }; +static constexpr std::uint32_t DefaultBallID = 1714267008; + static constexpr std::uint32_t LargeTextSize = 64; static constexpr std::uint32_t MediumTextSize = 32; static constexpr std::uint32_t SmallTextSize = 16; diff --git a/samples/golf/src/golf/MenuCustomisation.cpp b/samples/golf/src/golf/MenuCustomisation.cpp index 483254ec4..1f6def81f 100644 --- a/samples/golf/src/golf/MenuCustomisation.cpp +++ b/samples/golf/src/golf/MenuCustomisation.cpp @@ -522,6 +522,20 @@ void MenuState::createBallScene() }), m_sharedData.ballInfo.end()); } + //put the default ball at the front - this doesn't work??? + //if (const auto b = std::find_if(m_sharedData.ballInfo.cbegin(), m_sharedData.ballInfo.cend(), [](const auto& inf) {return inf.uid == DefaultBallID;}); + // b != m_sharedData.ballInfo.cend()) + //{ + // //std::swap(m_sharedData.ballInfo.begin(), b); + // const auto pos = std::distance(m_sharedData.ballInfo.cbegin(), b); + // const auto old = m_sharedData.ballInfo[0]; + // m_sharedData.ballInfo[0] = m_sharedData.ballInfo[pos]; + // m_sharedData.ballInfo[pos] = old; + + // const auto oldModel = m_ballModels[0]; + // m_ballModels[0] = m_ballModels[pos]; + // m_ballModels[pos] = oldModel; + //} //store valid/unlocked IDs so the new profile randomiser can pick one for (const auto& i : m_sharedData.ballInfo) From 4d8406607967362579584cf3085fcae9d5e20f0d Mon Sep 17 00:00:00 2001 From: fallahn Date: Sat, 13 Apr 2024 11:31:54 +0100 Subject: [PATCH 23/24] update lobby menu layout --- samples/golf/buildnumber.h | 4 ++-- samples/golf/src/golf/MenuCreation.cpp | 18 +++++++++++++----- samples/golf/src/golf/ProfileState.cpp | 3 ++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/samples/golf/buildnumber.h b/samples/golf/buildnumber.h index 4fa76c714..769148544 100644 --- a/samples/golf/buildnumber.h +++ b/samples/golf/buildnumber.h @@ -3,7 +3,7 @@ #ifndef BUILD_NUMBER_H_ #define BUILD_NUMBER_H_ -#define BUILDNUMBER 5328 -#define BUILDNUMBER_STR "5328" +#define BUILDNUMBER 5340 +#define BUILDNUMBER_STR "5340" #endif /* BUILD_NUMBER_H_ */ diff --git a/samples/golf/src/golf/MenuCreation.cpp b/samples/golf/src/golf/MenuCreation.cpp index eae1a8fab..26353e2db 100644 --- a/samples/golf/src/golf/MenuCreation.cpp +++ b/samples/golf/src/golf/MenuCreation.cpp @@ -1800,7 +1800,7 @@ void MenuState::createLobbyMenu(cro::Entity parent, std::uint32_t mouseEnter, st } }; entity = m_uiScene.createEntity(); - entity.addComponent().setPosition({ 12.f, 0.f, 0.1f }); + entity.addComponent().setPosition({ 67.f, -1.f, 0.1f }); entity.addComponent().setFacing(cro::Drawable2D::Facing::Back); entity.addComponent() = spriteSheetV2.getSprite("lb"); entity.addComponent(); @@ -1810,7 +1810,7 @@ void MenuState::createLobbyMenu(cro::Entity parent, std::uint32_t mouseEnter, st buttonEnt.getComponent().addChild(entity.getComponent()); entity = m_uiScene.createEntity(); - entity.addComponent().setPosition({ 330.f, 0.f, 0.1f }); + entity.addComponent().setPosition({ 273.f, -1.f, 0.1f }); entity.addComponent().setFacing(cro::Drawable2D::Facing::Back); entity.addComponent() = spriteSheetV2.getSprite("rb"); entity.addComponent(); @@ -1829,13 +1829,21 @@ void MenuState::createLobbyMenu(cro::Entity parent, std::uint32_t mouseEnter, st void operator()(cro::Entity e, float) { - auto s = cro::Keyboard::keyString(sharedData.inputBinding.keys[keybind]); + cro::String s; + if (keybind == InputBinding::PrevClub) + { + s = "< " + cro::Keyboard::keyString(sharedData.inputBinding.keys[keybind]); + } + else + { + s = cro::Keyboard::keyString(sharedData.inputBinding.keys[keybind]) + " >"; + } e.getComponent().setString(s); e.getComponent().active = false; } }; entity = m_uiScene.createEntity(); - entity.addComponent().setPosition({ 23.f, 9.f, 0.1f }); + entity.addComponent().setPosition({ 75.f, 9.f, 0.1f }); entity.addComponent(); entity.addComponent(font).setString("X"); entity.getComponent().setFillColour(TextNormalColour); @@ -1849,7 +1857,7 @@ void MenuState::createLobbyMenu(cro::Entity parent, std::uint32_t mouseEnter, st buttonEnt.getComponent().addChild(entity.getComponent()); entity = m_uiScene.createEntity(); - entity.addComponent().setPosition({ 337.f, 9.f, 0.1f }); + entity.addComponent().setPosition({ 285.f, 9.f, 0.1f }); entity.addComponent(); entity.addComponent(font).setString("Y"); entity.getComponent().setFillColour(TextNormalColour); diff --git a/samples/golf/src/golf/ProfileState.cpp b/samples/golf/src/golf/ProfileState.cpp index 6f1360c0e..03b40a4c5 100644 --- a/samples/golf/src/golf/ProfileState.cpp +++ b/samples/golf/src/golf/ProfileState.cpp @@ -1148,7 +1148,7 @@ void ProfileState::buildScene() avatarRight.setLabel("Next Avatar"); expandHitbox(avatarRight); - //checkbox + //southpaw checkbox auto southPaw = createButton("check_highlight", glm::vec2(17.f, 50.f), ButtonSouthPaw); southPaw.getComponent().callbacks[cro::UIInput::ButtonUp] = uiSystem.addCallback([&](cro::Entity, const cro::ButtonEvent& evt) @@ -1161,6 +1161,7 @@ void ProfileState::buildScene() }); southPaw.getComponent().setNextIndex(ButtonSaveClose, ButtonRandomise); southPaw.getComponent().setPrevIndex(ButtonSaveClose, ButtonBottomLight); + southPaw.getComponent().area.width *= 8.f; southPaw.setLabel("Use Left Handed Avatar"); auto innerEnt = m_uiScene.createEntity(); From 0addd18d01b4a5257f063f1988002e35eab05698 Mon Sep 17 00:00:00 2001 From: fallahn Date: Sat, 13 Apr 2024 11:35:06 +0100 Subject: [PATCH 24/24] tweak southpaw hitbox --- samples/golf/buildnumber.h | 4 ++-- samples/golf/src/golf/ProfileState.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/golf/buildnumber.h b/samples/golf/buildnumber.h index 769148544..f80f9fb00 100644 --- a/samples/golf/buildnumber.h +++ b/samples/golf/buildnumber.h @@ -3,7 +3,7 @@ #ifndef BUILD_NUMBER_H_ #define BUILD_NUMBER_H_ -#define BUILDNUMBER 5340 -#define BUILDNUMBER_STR "5340" +#define BUILDNUMBER 5341 +#define BUILDNUMBER_STR "5341" #endif /* BUILD_NUMBER_H_ */ diff --git a/samples/golf/src/golf/ProfileState.cpp b/samples/golf/src/golf/ProfileState.cpp index 03b40a4c5..a1baffdec 100644 --- a/samples/golf/src/golf/ProfileState.cpp +++ b/samples/golf/src/golf/ProfileState.cpp @@ -1161,7 +1161,7 @@ void ProfileState::buildScene() }); southPaw.getComponent().setNextIndex(ButtonSaveClose, ButtonRandomise); southPaw.getComponent().setPrevIndex(ButtonSaveClose, ButtonBottomLight); - southPaw.getComponent().area.width *= 8.f; + southPaw.getComponent().area.width *= 7.f; southPaw.setLabel("Use Left Handed Avatar"); auto innerEnt = m_uiScene.createEntity();