From af1c14ebc050fb76efe75c8023a76d645cdd7563 Mon Sep 17 00:00:00 2001 From: DeepWolf413 Date: Mon, 20 Jun 2022 22:35:20 +0200 Subject: [PATCH 1/4] Implemented Screen. --- LemonUI.SHV/Control.hpp | 368 ++++++++++++++++++++++++++++++++ LemonUI.SHV/LemonUI.SHV.vcxproj | 3 + LemonUI.SHV/PointF.cpp | 16 ++ LemonUI.SHV/PointF.hpp | 2 + LemonUI.SHV/Screen.cpp | 108 ++++++++++ LemonUI.SHV/Screen.hpp | 126 +++++++++++ 6 files changed, 623 insertions(+) create mode 100644 LemonUI.SHV/Control.hpp create mode 100644 LemonUI.SHV/Screen.cpp create mode 100644 LemonUI.SHV/Screen.hpp 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/LemonUI.SHV.vcxproj b/LemonUI.SHV/LemonUI.SHV.vcxproj index 5ddc4b8..d249a13 100644 --- a/LemonUI.SHV/LemonUI.SHV.vcxproj +++ b/LemonUI.SHV/LemonUI.SHV.vcxproj @@ -13,15 +13,18 @@ + + + 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..6defbd3 --- /dev/null +++ b/LemonUI.SHV/Screen.cpp @@ -0,0 +1,108 @@ +#include "Screen.hpp" + +#include + +#include "Control.hpp" +#include "SizeF.hpp" + +namespace LemonUI::Screen +{ + float GetAspectRatio() + { + return GRAPHICS::GET_ASPECT_RATIO_(false); + } + + PointF GetCursorPositionRelative() + { + float cursorX = PAD::GET_CONTROL_NORMAL(0, Control::CursorX); + float cursorY = PAD::GET_CONTROL_NORMAL(0, Control::CursorY); + + return {cursorX, cursorY}; + } + + void 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 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 IsCursorInArea(const PointF& pos, const SizeF& size) + { + IsCursorInArea(pos.GetX(), pos.GetY(), size.GetWidth(), size.GetHeight()); + } + + bool IsCursorInArea(float x, float y, float width, float height) + { + PointF cursor = GetCursorPositionRelative(); + + float realWidth, realHeight; + ToRelative(width, height, realWidth, realHeight); + PointF realPos = GetRealPosition(x, y); + } + + PointF GetRealPosition(const PointF& og) + { + return GetRealPosition(og.GetX(), og.GetY()); + } + + PointF 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 ShowCursorThisFrame() + { + HUD::SET_MOUSE_CURSOR_ACTIVE_THIS_FRAME_(); + } + + void 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 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 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(); +} From 13093d79996037c217b7b65107f91f416a5d101c Mon Sep 17 00:00:00 2001 From: DeepWolf413 Date: Mon, 20 Jun 2022 22:51:47 +0200 Subject: [PATCH 2/4] Cleaned up Sound class. I changed the string parameters for SetFile, SetSet, and the constructor to 'const std::string&' so it is being sent as a reference instead. Before the changes it would make a copy of the string being sent as an argument. And the const basically marks it as not being changed in the scope of the function/constructor. --- LemonUI.SHV/Sound.cpp | 10 +++++----- LemonUI.SHV/Sound.hpp | 16 ++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) 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; }; } From 12990f1dde61dcc6aa17696040b5b16a257d223d Mon Sep 17 00:00:00 2001 From: DeepWolf413 Date: Mon, 20 Jun 2022 23:08:00 +0200 Subject: [PATCH 3/4] Forgot to return IsCursorInArea, and complete it.. I also removed Screen from the namespace to keep things consistent with the rest of the project (other cpp files currently only has LemonUI in the namespace). --- LemonUI.SHV/Screen.cpp | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/LemonUI.SHV/Screen.cpp b/LemonUI.SHV/Screen.cpp index 6defbd3..520ccfd 100644 --- a/LemonUI.SHV/Screen.cpp +++ b/LemonUI.SHV/Screen.cpp @@ -5,14 +5,14 @@ #include "Control.hpp" #include "SizeF.hpp" -namespace LemonUI::Screen +namespace LemonUI { - float GetAspectRatio() + float Screen::GetAspectRatio() { return GRAPHICS::GET_ASPECT_RATIO_(false); } - PointF GetCursorPositionRelative() + PointF Screen::GetCursorPositionRelative() { float cursorX = PAD::GET_CONTROL_NORMAL(0, Control::CursorX); float cursorY = PAD::GET_CONTROL_NORMAL(0, Control::CursorY); @@ -20,7 +20,7 @@ namespace LemonUI::Screen return {cursorX, cursorY}; } - void ToAbsolute(const float relativeX, const float relativeY, float& absoluteX, float& absoluteY) + 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(); @@ -30,7 +30,7 @@ namespace LemonUI::Screen absoluteY = 1080.0f * relativeY; } - void ToRelative(const float absoluteX, const float absoluteY, float& relativeX, float& 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(); @@ -40,26 +40,29 @@ namespace LemonUI::Screen relativeY = absoluteY / 1080.0f; } - bool IsCursorInArea(const PointF& pos, const SizeF& size) + bool Screen::IsCursorInArea(const PointF& pos, const SizeF& size) { - IsCursorInArea(pos.GetX(), pos.GetY(), size.GetWidth(), size.GetHeight()); + return IsCursorInArea(pos.GetX(), pos.GetY(), size.GetWidth(), size.GetHeight()); } - bool IsCursorInArea(float x, float y, float width, float height) + bool Screen::IsCursorInArea(const float x, const float y, const float width, const float height) { - PointF cursor = GetCursorPositionRelative(); + const PointF cursor = GetCursorPositionRelative(); float realWidth, realHeight; ToRelative(width, height, realWidth, realHeight); - PointF realPos = GetRealPosition(x, y); + 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 GetRealPosition(const PointF& og) + PointF Screen::GetRealPosition(const PointF& og) { return GetRealPosition(og.GetX(), og.GetY()); } - PointF GetRealPosition(const float x, const float y) + PointF Screen::GetRealPosition(const float x, const float y) { float relativeX, relativeY; // Convert the resolution to relative @@ -76,12 +79,12 @@ namespace LemonUI::Screen return {absoluteX, absoluteY}; } - void ShowCursorThisFrame() + void Screen::ShowCursorThisFrame() { HUD::SET_MOUSE_CURSOR_ACTIVE_THIS_FRAME_(); } - void SetElementAlignment(const Alignment horizontal, const GFXAlignment vertical) + void Screen::SetElementAlignment(const Alignment horizontal, const GFXAlignment vertical) { switch (horizontal) { @@ -95,13 +98,13 @@ namespace LemonUI::Screen } } - void SetElementAlignment(const GFXAlignment horizontal, const GFXAlignment vertical) + 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 ResetElementAlignment() + void Screen::ResetElementAlignment() { GRAPHICS::RESET_SCRIPT_GFX_ALIGN(); } From 7374afb20b77226d626c9154e921ec310cbdf915 Mon Sep 17 00:00:00 2001 From: DeepWolf413 Date: Mon, 20 Jun 2022 23:16:34 +0200 Subject: [PATCH 4/4] Implemented Controls. --- LemonUI.SHV/Controls.cpp | 44 ++++++++++++++++++++++++++++ LemonUI.SHV/Controls.h | 52 +++++++++++++++++++++++++++++++++ LemonUI.SHV/LemonUI.SHV.vcxproj | 2 ++ 3 files changed, 98 insertions(+) create mode 100644 LemonUI.SHV/Controls.cpp create mode 100644 LemonUI.SHV/Controls.h 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 d249a13..a2a40e1 100644 --- a/LemonUI.SHV/LemonUI.SHV.vcxproj +++ b/LemonUI.SHV/LemonUI.SHV.vcxproj @@ -12,6 +12,7 @@ + @@ -21,6 +22,7 @@ +