Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Lua: UIMenu
- Removed "DisEnableControls".. old method.. stupid and confusing.. outrageous
- Added cleaner menu:DisableNonMenuControls() method
- Added Controls class to handle controls with cleaner interface. you can add remove controls in `Controls.NecessaryControlsKeyboard` and `Controls.NecessaryControlsGamePad`
  • Loading branch information
manups4e committed Aug 3, 2023
1 parent df48048 commit 8b94bde
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 70 deletions.
96 changes: 96 additions & 0 deletions ScaleformUI_Lua/src/Elements/Controls.lua
@@ -0,0 +1,96 @@
Controls = setmetatable({
NecessaryControlsKeyboard = {
201, -- FrontendAccept
195, -- FrontendAxisX
196, -- FrontendAxisY
187, -- FrontendDown
188, -- FrontendUp
189, -- FrontendLeft
190, -- FrontendRight
202, -- FrontendCancel
217, -- FrontendSelect
242, -- CursorScrollDown
241, -- CursorScrollUp
239, -- CursorX
240, -- CursorY
237, -- CursorAccept
238, -- CursorCancel
31, -- MoveUpDown
30, -- MoveLeftRight
21, -- Sprint
22, -- Jump
23, -- Enter
75, -- VehicleExit
71, -- VehicleAccelerate
72, -- VehicleBrake
59, -- VehicleMoveLeftRight
89, -- VehicleFlyYawLeft
9, -- FlyLeftRight
8, -- FlyUpDown
90, -- VehicleFlyYawRight
76 -- VehicleHandbrake
},

NecessaryControlsGamePad = {
201, -- FrontendAccept
195, -- FrontendAxisX
196, -- FrontendAxisY
187, -- FrontendDown
188, -- FrontendUp
189, -- FrontendLeft
190, -- FrontendRight
202, -- FrontendCancel
217, -- FrontendSelect
242, -- CursorScrollDown
241, -- CursorScrollUp
239, -- CursorX
240, -- CursorY
237, -- CursorAccept
238, -- CursorCancel
31, -- MoveUpDown
30, -- MoveLeftRight
21, -- Sprint
22, -- Jump
23, -- Enter
75, -- VehicleExit
71, -- VehicleAccelerate
72, -- VehicleBrake
59, -- VehicleMoveLeftRight
89, -- VehicleFlyYawLeft
9, -- FlyLeftRight
8, -- FlyUpDown
90, -- VehicleFlyYawRight
76, -- VehicleHandbrake
2, -- LookUpDown
1, -- LookLeftRight
25, -- Aim
24, -- Attack
71, -- VehicleAccelerate
72, -- VehicleBrake
59, -- VehicleMoveLeftRight
31, -- MoveUpDown
30, -- MoveLeftRight
75, -- VehicleExit
}
}, Controls)


function Controls:ToggleAll(toggle)
if toggle then
EnableAllControlActions(0)
EnableAllControlActions(1)
EnableAllControlActions(2)
else
DisableAllControlActions(2)

local list = {}
if IsUsingKeyboard(2) then
list = self.NecessaryControlsKeyboard
else
list = self.NecessaryControlsGamePad
end
for _, control in pairs(list) do
EnableControlAction(0, control, true)
end
end
end
76 changes: 6 additions & 70 deletions ScaleformUI_Lua/src/Menus/UIMenu/UIMenu.lua
Expand Up @@ -138,6 +138,7 @@ function UIMenu.New(title, subTitle, x, y, glare, txtDictionary, txtName, altern
_Visible = false,
Dirty = false,
ReDraw = true,
disableNonMenuControls = true,
InstructionalButtons = {
InstructionalButton.New(GetLabelText("HUD_INPUT2"), -1, 176, 176, -1),
InstructionalButton.New(GetLabelText("HUD_INPUT3"), -1, 177, 177, -1)
Expand Down Expand Up @@ -188,53 +189,6 @@ function UIMenu.New(title, subTitle, x, y, glare, txtDictionary, txtName, altern
Back = "BACK",
Error = "ERROR",
},
EnabledControls = {
Controller = {
{ 0, 2 }, -- Look Up and Down
{ 0, 1 }, -- Look Left and Right
{ 0, 25 }, -- Aim
{ 0, 24 }, -- Attack
{ 0, 71 }, -- Accelerate Vehicle
{ 0, 72 }, -- Vehicle Brake
{ 0, 30 }, -- Move Left and Right
{ 0, 31 }, -- Move Up and Down
{ 0, 59 }, -- Move Vehicle Left and Right
{ 0, 75 }, -- Exit Vehicle
},
Keyboard = {
{ 0, 2 }, -- Look Up and Down
{ 0, 1 }, -- Look Left and Right
{ 0, 201 }, -- Select
{ 0, 195 }, -- X axis
{ 0, 196 }, -- Y axis
{ 0, 187 }, -- Down
{ 0, 188 }, -- Up
{ 0, 189 }, -- Left
{ 0, 190 }, -- Right
{ 0, 202 }, -- Back
{ 0, 217 }, -- Select
{ 0, 242 }, -- Scroll down
{ 0, 241 }, -- Scroll up
{ 0, 239 }, -- Cursor X
{ 0, 240 }, -- Cursor Y
{ 0, 237 },
{ 0, 238 },
{ 0, 31 }, -- Move Up and Down
{ 0, 30 }, -- Move Left and Right
{ 0, 21 }, -- Sprint
{ 0, 22 }, -- Jump
{ 0, 23 }, -- Enter
{ 0, 75 }, -- Exit Vehicle
{ 0, 71 }, -- Accelerate Vehicle
{ 0, 72 }, -- Vehicle Brake
{ 0, 59 }, -- Move Vehicle Left and Right
{ 0, 89 }, -- Fly Yaw Left
{ 0, 9 }, -- Fly Left and Right
{ 0, 8 }, -- Fly Up and Down
{ 0, 90 }, -- Fly Yaw Right
{ 0, 76 }, -- Vehicle Handbrake
},
},
}
}
_UIMenu.Pagination.itemsPerPage = 7
Expand Down Expand Up @@ -293,29 +247,13 @@ function UIMenu:CounterColor(color)
end
end

---DisEnableControls
---DisableNonMenuControls
---@param bool boolean
function UIMenu:DisEnableControls(bool)
function UIMenu:DisableNonMenuControls(bool)
if bool then
EnableAllControlActions(2)
self.disableNonMenuControls = bool
else
DisableAllControlActions(2)
end

if bool then
return
else
if not IsUsingKeyboard(2) then
for Index = 1, #self.Settings.EnabledControls.Controller do
EnableControlAction(self.Settings.EnabledControls.Controller[Index][1],
self.Settings.EnabledControls.Controller[Index][2], true)
end
else
for Index = 1, #self.Settings.EnabledControls.Keyboard do
EnableControlAction(self.Settings.EnabledControls.Keyboard[Index][1],
self.Settings.EnabledControls.Keyboard[Index][2], true)
end
end
return self.disableNonMenuControls
end
end

Expand Down Expand Up @@ -1291,9 +1229,7 @@ function UIMenu:Draw()

HideHudComponentThisFrame(19)

if self.Settings.ControlDisablingEnabled then
self:DisEnableControls(false)
end
Controls:ToggleAll(not self:DisableNonMenuControls())

ScaleformUI.Scaleforms._ui:Render2D()

Expand Down

7 comments on commit 8b94bde

@Local9
Copy link
Collaborator

@Local9 Local9 commented on 8b94bde Aug 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DisableNonMenuControls maybe DisableGameControls? and likely it'll be best set false by default? Just "Non Menu" doesn't feel like it fits right.

@manups4e
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 yeah.. the name is for now.. it can be changed 🤔

@manups4e
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also.. no it should not be set to false.. but to true.. as by default.. game controls are disabled and menu controls are enabled..

@Local9
Copy link
Collaborator

@Local9 Local9 commented on 8b94bde Aug 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we have keep remembering to set it to false to use GamePlayCamera? worth adding comments to that effect

@manups4e
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DisableGameControls it's already a good name.. it helps.. if true they're disabled.. if false they're not disabled

@Local9
Copy link
Collaborator

@Local9 Local9 commented on 8b94bde Aug 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, name is fine now, its the default setting. So by default the menu when being used will always block typical gameplay inputs unless the developer specifies they don't want to, my view is that it would be better to say the menu doesn't block game play inputs by default and that the developer should state they want to block game play inputs.

@manups4e
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

menu blocks everything except the input specified in the tables above

Please sign in to comment.