diff --git a/LemonUI.SHV/Control.hpp b/LemonUI.SHV/Control.hpp new file mode 100644 index 0000000..07057d9 --- /dev/null +++ b/LemonUI.SHV/Control.hpp @@ -0,0 +1,368 @@ +#pragma once + +namespace LemonUI +{ + enum Control + { + NextCamera, + LookLeftRight, + LookUpDown, + LookUpOnly, + LookDownOnly, + LookLeftOnly, + LookRightOnly, + CinematicSlowMo, + FlyUpDown, + FlyLeftRight, + ScriptedFlyZUp, + ScriptedFlyZDown, + WeaponWheelUpDown, + WeaponWheelLeftRight, + WeaponWheelNext, + WeaponWheelPrev, + SelectNextWeapon, + SelectPrevWeapon, + SkipCutscene, + CharacterWheel, + MultiplayerInfo, + Sprint, + Jump, + Enter, + Attack, + Aim, + LookBehind, + Phone, + SpecialAbility, + SpecialAbilitySecondary, + MoveLeftRight, + MoveUpDown, + MoveUpOnly, + MoveDownOnly, + MoveLeftOnly, + MoveRightOnly, + Duck, + SelectWeapon, + Pickup, + SniperZoom, + SniperZoomInOnly, + SniperZoomOutOnly, + SniperZoomInSecondary, + SniperZoomOutSecondary, + Cover, + Reload, + Talk, + Detonate, + HUDSpecial, + Arrest, + AccurateAim, + Context, + ContextSecondary, + WeaponSpecial, + WeaponSpecial2, + Dive, + DropWeapon, + DropAmmo, + ThrowGrenade, + VehicleMoveLeftRight, + VehicleMoveUpDown, + VehicleMoveUpOnly, + VehicleMoveDownOnly, + VehicleMoveLeftOnly, + VehicleMoveRightOnly, + VehicleSpecial, + VehicleGunLeftRight, + VehicleGunUpDown, + VehicleAim, + VehicleAttack, + VehicleAttack2, + VehicleAccelerate, + VehicleBrake, + VehicleDuck, + VehicleHeadlight, + VehicleExit, + VehicleHandbrake, + VehicleHotwireLeft, + VehicleHotwireRight, + VehicleLookBehind, + VehicleCinCam, + VehicleNextRadio, + VehiclePrevRadio, + VehicleNextRadioTrack, + VehiclePrevRadioTrack, + VehicleRadioWheel, + VehicleHorn, + VehicleFlyThrottleUp, + VehicleFlyThrottleDown, + VehicleFlyYawLeft, + VehicleFlyYawRight, + VehiclePassengerAim, + VehiclePassengerAttack, + VehicleSpecialAbilityFranklin, + VehicleStuntUpDown, + VehicleCinematicUpDown, + VehicleCinematicUpOnly, + VehicleCinematicDownOnly, + VehicleCinematicLeftRight, + VehicleSelectNextWeapon, + VehicleSelectPrevWeapon, + VehicleRoof, + VehicleJump, + VehicleGrapplingHook, + VehicleShuffle, + VehicleDropProjectile, + VehicleMouseControlOverride, + VehicleFlyRollLeftRight, + VehicleFlyRollLeftOnly, + VehicleFlyRollRightOnly, + VehicleFlyPitchUpDown, + VehicleFlyPitchUpOnly, + VehicleFlyPitchDownOnly, + VehicleFlyUnderCarriage, + VehicleFlyAttack, + VehicleFlySelectNextWeapon, + VehicleFlySelectPrevWeapon, + VehicleFlySelectTargetLeft, + VehicleFlySelectTargetRight, + VehicleFlyVerticalFlightMode, + VehicleFlyDuck, + VehicleFlyAttackCamera, + VehicleFlyMouseControlOverride, + VehicleSubTurnLeftRight, + VehicleSubTurnLeftOnly, + VehicleSubTurnRightOnly, + VehicleSubPitchUpDown, + VehicleSubPitchUpOnly, + VehicleSubPitchDownOnly, + VehicleSubThrottleUp, + VehicleSubThrottleDown, + VehicleSubAscend, + VehicleSubDescend, + VehicleSubTurnHardLeft, + VehicleSubTurnHardRight, + VehicleSubMouseControlOverride, + VehiclePushbikePedal, + VehiclePushbikeSprint, + VehiclePushbikeFrontBrake, + VehiclePushbikeRearBrake, + MeleeAttackLight, + MeleeAttackHeavy, + MeleeAttackAlternate, + MeleeBlock, + ParachuteDeploy, + ParachuteDetach, + ParachuteTurnLeftRight, + ParachuteTurnLeftOnly, + ParachuteTurnRightOnly, + ParachutePitchUpDown, + ParachutePitchUpOnly, + ParachutePitchDownOnly, + ParachuteBrakeLeft, + ParachuteBrakeRight, + ParachuteSmoke, + ParachutePrecisionLanding, + Map, + SelectWeaponUnarmed, + SelectWeaponMelee, + SelectWeaponHandgun, + SelectWeaponShotgun, + SelectWeaponSmg, + SelectWeaponAutoRifle, + SelectWeaponSniper, + SelectWeaponHeavy, + SelectWeaponSpecial, + SelectCharacterMichael, + SelectCharacterFranklin, + SelectCharacterTrevor, + SelectCharacterMultiplayer, + SaveReplayClip, + SpecialAbilityPC, + PhoneUp, + PhoneDown, + PhoneLeft, + PhoneRight, + PhoneSelect, + PhoneCancel, + PhoneOption, + PhoneExtraOption, + PhoneScrollForward, + PhoneScrollBackward, + PhoneCameraFocusLock, + PhoneCameraGrid, + PhoneCameraSelfie, + PhoneCameraDOF, + PhoneCameraExpression, + FrontendDown, + FrontendUp, + FrontendLeft, + FrontendRight, + FrontendRdown, + FrontendRup, + FrontendRleft, + FrontendRright, + FrontendAxisX, + FrontendAxisY, + FrontendRightAxisX, + FrontendRightAxisY, + FrontendPause, + FrontendPauseAlternate, + FrontendAccept, + FrontendCancel, + FrontendX, + FrontendY, + FrontendLb, + FrontendRb, + FrontendLt, + FrontendRt, + FrontendLs, + FrontendRs, + FrontendLeaderboard, + FrontendSocialClub, + FrontendSocialClubSecondary, + FrontendDelete, + FrontendEndscreenAccept, + FrontendEndscreenExpand, + FrontendSelect, + ScriptLeftAxisX, + ScriptLeftAxisY, + ScriptRightAxisX, + ScriptRightAxisY, + ScriptRUp, + ScriptRDown, + ScriptRLeft, + ScriptRRight, + ScriptLB, + ScriptRB, + ScriptLT, + ScriptRT, + ScriptLS, + ScriptRS, + ScriptPadUp, + ScriptPadDown, + ScriptPadLeft, + ScriptPadRight, + ScriptSelect, + CursorAccept, + CursorCancel, + CursorX, + CursorY, + CursorScrollUp, + CursorScrollDown, + EnterCheatCode, + InteractionMenu, + MpTextChatAll, + MpTextChatTeam, + MpTextChatFriends, + MpTextChatCrew, + PushToTalk, + CreatorLS, + CreatorRS, + CreatorLT, + CreatorRT, + CreatorMenuToggle, + CreatorAccept, + CreatorDelete, + Attack2, + RappelJump, + RappelLongJump, + RappelSmashWindow, + PrevWeapon, + NextWeapon, + MeleeAttack1, + MeleeAttack2, + Whistle, + MoveLeft, + MoveRight, + MoveUp, + MoveDown, + LookLeft, + LookRight, + LookUp, + LookDown, + SniperZoomIn, + SniperZoomOut, + SniperZoomInAlternate, + SniperZoomOutAlternate, + VehicleMoveLeft, + VehicleMoveRight, + VehicleMoveUp, + VehicleMoveDown, + VehicleGunLeft, + VehicleGunRight, + VehicleGunUp, + VehicleGunDown, + VehicleLookLeft, + VehicleLookRight, + ReplayStartStopRecording, + ReplayStartStopRecordingSecondary, + ScaledLookLeftRight, + ScaledLookUpDown, + ScaledLookUpOnly, + ScaledLookDownOnly, + ScaledLookLeftOnly, + ScaledLookRightOnly, + ReplayMarkerDelete, + ReplayClipDelete, + ReplayPause, + ReplayRewind, + ReplayFfwd, + ReplayNewmarker, + ReplayRecord, + ReplayScreenshot, + ReplayHidehud, + ReplayStartpoint, + ReplayEndpoint, + ReplayAdvance, + ReplayBack, + ReplayTools, + ReplayRestart, + ReplayShowhotkey, + ReplayCycleMarkerLeft, + ReplayCycleMarkerRight, + ReplayFOVIncrease, + ReplayFOVDecrease, + ReplayCameraUp, + ReplayCameraDown, + ReplaySave, + ReplayToggletime, + ReplayToggletips, + ReplayPreview, + ReplayToggleTimeline, + ReplayTimelinePickupClip, + ReplayTimelineDuplicateClip, + ReplayTimelinePlaceClip, + ReplayCtrl, + ReplayTimelineSave, + ReplayPreviewAudio, + VehicleDriveLook, + VehicleDriveLook2, + VehicleFlyAttack2, + RadioWheelUpDown, + RadioWheelLeftRight, + VehicleSlowMoUpDown, + VehicleSlowMoUpOnly, + VehicleSlowMoDownOnly, + VehicleHydraulicsControlToggle, + VehicleHydraulicsControlLeft, + VehicleHydraulicsControlRight, + VehicleHydraulicsControlUp, + VehicleHydraulicsControlDown, + VehicleHydraulicsControlLeftRight, + VehicleHydraulicsControlUuDown, + SwitchVisor, + VehicleMeleeHold, + VehicleMeleeLeft, + VehicleMeleeRight, + MapPointOfInterest, + ReplaySnapmaticPhoto, + VehicleCarJump, + VehicleRocketBoost, + VehicleParachute, + VehicleBikeWings, + VehicleFlyBombBay, + VehicleFlyCounter, + VehicleFlyTransform, + QuadLocoReverse, + RespawnFaster, + HudmarkerSelect + }; +} diff --git a/LemonUI.SHV/Controls.cpp b/LemonUI.SHV/Controls.cpp new file mode 100644 index 0000000..1446d9e --- /dev/null +++ b/LemonUI.SHV/Controls.cpp @@ -0,0 +1,44 @@ +#include "Controls.h" + +#include + +namespace LemonUI +{ + bool Controls::IsUsingController() + { + return !PAD::IS_USING_KEYBOARD_(2); + } + + bool Controls::IsJustPressed(const Control control) + { + return PAD::IS_DISABLED_CONTROL_JUST_PRESSED(0, control); + } + + bool Controls::IsPressed(const Control control) + { + return PAD::IS_DISABLED_CONTROL_PRESSED(0, control); + } + + void Controls::DisableAll(const int inputGroup) + { + PAD::DISABLE_ALL_CONTROL_ACTIONS(inputGroup); + } + + void Controls::EnableThisFrame(const Control control) + { + PAD::ENABLE_CONTROL_ACTION(0, control); + } + + void Controls::EnableThisFrame(const std::vector& controls) + { + for (const auto control : controls) + { + EnableThisFrame(control); + } + } + + void Controls::DisableThisFrame(const Control control) + { + PAD::DISABLE_CONTROL_ACTION(0, control, true); + } +} diff --git a/LemonUI.SHV/Controls.h b/LemonUI.SHV/Controls.h new file mode 100644 index 0000000..f04ddbb --- /dev/null +++ b/LemonUI.SHV/Controls.h @@ -0,0 +1,52 @@ +#pragma once +#include + +#include "Control.hpp" + +/** + * \brief Tools for dealing with controls. + */ +namespace LemonUI::Controls +{ + /** + * \brief Gets if the player used a controller for the last input. + */ + bool IsUsingController(); + + /** + * \brief Checks if a control was pressed during the last frame. + * \param control The control to check. + * \return true if the control was pressed, false otherwise. + */ + bool IsJustPressed(Control control); + + /** + * \brief Checks if a control is currently pressed. + * \param control The control to check. + * \return true if the control is pressed, false otherwise. + */ + bool IsPressed(Control control); + + /** + * \brief Disables all of the controls during the next frame. + */ + void DisableAll(int inputGroup = 0); + + /** + * \brief Enables a control during the next frame. + * \param control The control to enable. + */ + void EnableThisFrame(Control control); + + /** + * \brief Enables a specific set of controls during the next frame. + * \param controls The controls to enable. + */ + void EnableThisFrame(const std::vector& controls); + + /** + * \brief Disables a control during the next frame. + * \param control The control to disable. + */ + void DisableThisFrame(Control control); +} \ No newline at end of file diff --git a/LemonUI.SHV/LemonUI.SHV.vcxproj b/LemonUI.SHV/LemonUI.SHV.vcxproj index 5ddc4b8..a2a40e1 100644 --- a/LemonUI.SHV/LemonUI.SHV.vcxproj +++ b/LemonUI.SHV/LemonUI.SHV.vcxproj @@ -12,16 +12,21 @@ + + + + + diff --git a/LemonUI.SHV/PointF.cpp b/LemonUI.SHV/PointF.cpp index 1ee14d8..955694b 100644 --- a/LemonUI.SHV/PointF.cpp +++ b/LemonUI.SHV/PointF.cpp @@ -1,5 +1,7 @@ #include "PointF.hpp" +#include "Screen.hpp" + namespace LemonUI { PointF::PointF(const float x, const float y) @@ -32,4 +34,18 @@ namespace LemonUI { y_ = y; } + + PointF PointF::ToRelative() const + { + float relativeX, relativeY; + Screen::ToRelative(GetX(), GetY(), relativeX, relativeY); + return {relativeX, relativeY}; + } + + PointF PointF::ToAbsolute() const + { + float absoluteX, absoluteY; + Screen::ToAbsolute(GetX(), GetY(), absoluteX, absoluteY); + return {absoluteX, absoluteY}; + } } diff --git a/LemonUI.SHV/PointF.hpp b/LemonUI.SHV/PointF.hpp index 2706919..403bec3 100644 --- a/LemonUI.SHV/PointF.hpp +++ b/LemonUI.SHV/PointF.hpp @@ -14,5 +14,7 @@ namespace LemonUI float GetY() const; void SetX(float x); void SetY(float y); + PointF ToRelative() const; + PointF ToAbsolute() const; }; } diff --git a/LemonUI.SHV/Screen.cpp b/LemonUI.SHV/Screen.cpp new file mode 100644 index 0000000..520ccfd --- /dev/null +++ b/LemonUI.SHV/Screen.cpp @@ -0,0 +1,111 @@ +#include "Screen.hpp" + +#include + +#include "Control.hpp" +#include "SizeF.hpp" + +namespace LemonUI +{ + float Screen::GetAspectRatio() + { + return GRAPHICS::GET_ASPECT_RATIO_(false); + } + + PointF Screen::GetCursorPositionRelative() + { + float cursorX = PAD::GET_CONTROL_NORMAL(0, Control::CursorX); + float cursorY = PAD::GET_CONTROL_NORMAL(0, Control::CursorY); + + return {cursorX, cursorY}; + } + + void Screen::ToAbsolute(const float relativeX, const float relativeY, float& absoluteX, float& absoluteY) + { + // Get the real width based on the aspect ratio + const float width = 1080.0f * GetAspectRatio(); + + // And save the correct values + absoluteX = width * relativeX; + absoluteY = 1080.0f * relativeY; + } + + void Screen::ToRelative(const float absoluteX, const float absoluteY, float& relativeX, float& relativeY) + { + // Get the real width based on the aspect ratio + const float width = 1080.0f * GetAspectRatio(); + + // And save the correct values + relativeX = absoluteX / width; + relativeY = absoluteY / 1080.0f; + } + + bool Screen::IsCursorInArea(const PointF& pos, const SizeF& size) + { + return IsCursorInArea(pos.GetX(), pos.GetY(), size.GetWidth(), size.GetHeight()); + } + + bool Screen::IsCursorInArea(const float x, const float y, const float width, const float height) + { + const PointF cursor = GetCursorPositionRelative(); + + float realWidth, realHeight; + ToRelative(width, height, realWidth, realHeight); + const PointF realPos = GetRealPosition(x, y).ToRelative(); + const bool isX = cursor.GetX() >= realPos.GetX() && cursor.GetX() <= realPos.GetX() + realWidth; + const bool isY = cursor.GetY() > realPos.GetY() && cursor.GetY() < realPos.GetY() + realHeight; + return isX && isY; + } + + PointF Screen::GetRealPosition(const PointF& og) + { + return GetRealPosition(og.GetX(), og.GetY()); + } + + PointF Screen::GetRealPosition(const float x, const float y) + { + float relativeX, relativeY; + // Convert the resolution to relative + ToRelative(x, y, relativeX, relativeY); + + // Request the real location of the position + float realX = 0; + float realY = 0; + + GRAPHICS::GET_SCRIPT_GFX_POSITION_(relativeX, relativeY, &realX, &realY); + + float absoluteX, absoluteY; + ToAbsolute(realX, realY, absoluteX, absoluteY); + return {absoluteX, absoluteY}; + } + + void Screen::ShowCursorThisFrame() + { + HUD::SET_MOUSE_CURSOR_ACTIVE_THIS_FRAME_(); + } + + void Screen::SetElementAlignment(const Alignment horizontal, const GFXAlignment vertical) + { + switch (horizontal) + { + case Alignment::Left: + SetElementAlignment(GFXAlignment::Left, vertical); + break; + case Alignment::Right: + case Alignment::Center: + SetElementAlignment(GFXAlignment::Right, vertical); + break; + } + } + + void Screen::SetElementAlignment(const GFXAlignment horizontal, const GFXAlignment vertical) + { + GRAPHICS::SET_SCRIPT_GFX_ALIGN(horizontal, vertical); + GRAPHICS::SET_SCRIPT_GFX_ALIGN_PARAMS(0, 0, 0, 0); + } + + void Screen::ResetElementAlignment() + { + GRAPHICS::RESET_SCRIPT_GFX_ALIGN(); + } +} diff --git a/LemonUI.SHV/Screen.hpp b/LemonUI.SHV/Screen.hpp new file mode 100644 index 0000000..b8e4f12 --- /dev/null +++ b/LemonUI.SHV/Screen.hpp @@ -0,0 +1,126 @@ +#pragma once +#include "Alignment.hpp" +#include "PointF.hpp" + +namespace LemonUI +{ + class SizeF; +} + +/** + * \brief Contains a set of tools to work with the screen information. + */ +namespace LemonUI::Screen +{ + /** + * \brief Represents the internal alignment of screen elements. + */ + enum GFXAlignment + { + /** + * \brief Vertical Alignment to the Bottom. + */ + Bottom = 66, + /** + * \brief Vertical Alignment to the Top. + */ + Top = 84, + /** + * \brief Centered Vertically or Horizontally. + */ + Center = 67, + /** + * \brief Horizontal Alignment to the Left. + */ + Left = 76, + /** + * \brief Horizontal Alignment to the Right. + */ + Right = 82 + }; + + /** + * \brief The Aspect Ratio of the screen resolution. + */ + float GetAspectRatio(); + + /** + * \brief The location of the cursor on screen between 0 and 1. + */ + PointF GetCursorPositionRelative(); + + /** + * \brief Converts a relative resolution into one scaled to 1080p. + * \param relativeX The relative value of X. + * \param relativeY The relative value of Y. + * \param absoluteX The value of X scaled to 1080p. + * \param absoluteY The value of Y scaled to 1080p. + */ + void ToAbsolute(float relativeX, float relativeY, float& absoluteX, float& absoluteY); + + /** + * \brief Converts a relative resolution into one scaled to 1080p. + * \param absoluteX The 1080p based X coord. + * \param absoluteY The 1080p based Y coord. + * \param relativeX The value of X converted to relative. + * \param relativeY The value of Y converted to relative. + */ + void ToRelative(float absoluteX, float absoluteY, float& relativeX, float& relativeY); + + /** + * \brief Checks if the cursor is inside of the specified area. + * \param pos The start of the area. + * \param size The size of the area to check. + * \return true if the cursor is in the specified bounds, false otherwise. + */ + bool IsCursorInArea(const PointF& pos, const SizeF& size); + + /** + * \brief Checks if the cursor is inside of the specified area. + * \param x The start X position. + * \param y The start Y position. + * \param width The height of the search area from X. + * \param height The height of the search area from Y. + * \return true if the cursor is in the specified bounds, false otherwise. + */ + bool IsCursorInArea(float x, float y, float width, float height); + + /** + * \brief Converts the specified position into one that is aware of 'SetElementAlignment(GFXAlignment, GFXAlignment)'. + * \param og The original 1080p based position. + * \return A new 1080p based position that is aware of the the Alignment. + */ + PointF GetRealPosition(const PointF& og); + + /** + * \brief Converts the specified position into one that is aware of 'SetElementAlignment(GFXAlignment, GFXAlignment)'. + * \param x The 1080p based X position. + * \param y The 1080p based Y position. + * \return A new 1080p based position that is aware of the the Alignment. + */ + PointF GetRealPosition(float x, float y); + + /** + * \brief Shows the cursor during the current game frame. + */ + void ShowCursorThisFrame(); + + /** + * \brief Sets the alignment of game elements like 'Elements.ScaledRectangle', 'Elements.ScaledText' and 'Elements.ScaledTexture'. + * \param horizontal The Horizontal alignment of the items. + * \param vertical The vertical alignment of the items. + */ + void SetElementAlignment(Alignment horizontal, GFXAlignment vertical); + + /** + * \brief Sets the alignment of game elements like 'Elements.ScaledRectangle', 'Elements.ScaledText' and 'Elements.ScaledTexture'. + * \param horizontal The Horizontal alignment of the items. + * \param vertical The vertical alignment of the items. + */ + void SetElementAlignment(GFXAlignment horizontal, GFXAlignment vertical); + + /** + * \brief Resets the alignment of the game elements. + */ + void ResetElementAlignment(); +} diff --git a/LemonUI.SHV/Sound.cpp b/LemonUI.SHV/Sound.cpp index f01576b..19f7f3f 100644 --- a/LemonUI.SHV/Sound.cpp +++ b/LemonUI.SHV/Sound.cpp @@ -4,7 +4,7 @@ namespace LemonUI { - Sound::Sound(std::string set, std::string file) + Sound::Sound(const std::string& set, const std::string& file) { this->set = set; this->file = file; @@ -15,7 +15,7 @@ namespace LemonUI return this->set; } - void Sound::SetSet(std::string set) + void Sound::SetSet(const std::string& set) { this->set = set; } @@ -25,15 +25,15 @@ namespace LemonUI return this->file; } - void Sound::SetFile(std::string file) + void Sound::SetFile(const std::string& file) { this->file = file; } - void Sound::PlayFrontend() + void Sound::PlayFrontend() const { AUDIO::PLAY_SOUND_FRONTEND(-1, file.c_str(), set.c_str(), false); - int id = AUDIO::GET_SOUND_ID(); + const int id = AUDIO::GET_SOUND_ID(); AUDIO::RELEASE_SOUND_ID(id); } } diff --git a/LemonUI.SHV/Sound.hpp b/LemonUI.SHV/Sound.hpp index 8268f66..c60e272 100644 --- a/LemonUI.SHV/Sound.hpp +++ b/LemonUI.SHV/Sound.hpp @@ -5,18 +5,18 @@ namespace LemonUI { class Sound { - private: - std::string set; - std::string file; - public: - Sound(std::string set, std::string file); + Sound(const std::string& set, const std::string& file); std::string GetSet(); - void SetSet(std::string); + void SetSet(const std::string& set); std::string GetFile(); - void SetFile(std::string); + void SetFile(const std::string& file); - void PlayFrontend(); + void PlayFrontend() const; + + private: + std::string set; + std::string file; }; }