1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
group . m_buttons = { }
group . m_enabled = true
return group
end
if ( button == clickedButton ) then
else
end
else
if ( button == clickedButton ) then
else
end
end
end
if not self . m_enabled then
return
end
-- For now only the LMB will be allowed to click radio buttons.
if ( buttonId == 1 )
then
-- Set all buttons in the group to unpressed, and unlocked.
-- If the button is disabled externally (maybe it isn't a valid option at this time)
-- then set it to unpressed, but disabled.
do
end
-- Set the clicked button to pressed and lock it down (so that it stays pressed.)
self . m_clickedButton = button
end
end
if ( button )
then
if ( self . m_buttons [ button ] == nil )
then
-- Remember the original handler so that its call can be forced.
self . m_buttons [ button ] = { originalHandler = originalHandler , isValidOption = true } -- newly added buttons always start as valid options for now.
-- This throws away return values from the original function, which is most likely ok in the case of a click handler.
then
end
end
end
end
end
-- This changes the enabled state of the entire radio group, but must still take into account
-- whether each button is a valid option...for example, enabling a radio group that has certain
-- invalid options must remember to keep those options disabled.
do
end
end
end
-- Allow external control over whether individual buttons are valid options
-- within the group. Invalid options will force those buttons to appear disabled.
local buttonData = self . m_buttons [ button ]
if ( buttonData and ( isValidOption ~= buttonData . isValidOption ) ) then
buttonData . isValidOption = isValidOption
-- NOTE: This doesn't update the state of the clicked button, because that could
-- potentially call a click handler that shouldn't be called at this time, or cause
-- more data to need to be updated externally...it's a best practice to first figure
-- out which buttons need to be validOptions, and then allow the clicked button to change.
end
end
do
-- Restore the button to its correct state, as if it hadn't been added to the radio group
-- Since "valid option" is set externally, just use that to figure out the current enabled state.
-- Reset handler, it's ok if this is nil, it means there was no original handler
-- so there shouldn't be one now...
end
self . m_buttons = { }
self . m_clickedButton = nil
end
local buttonData = self . m_buttons [ button ]
if ( buttonData and buttonData . isValidOption )
then
end
end
return self . m_clickedButton
end
-- Just change the state of the button group to reflect the current state of the data;
-- this shouldn't actually call any click handlers.
-- Find the button that's actually the clicked button from backing data
self . m_clickedButton = nil
do
self . m_clickedButton = button
break
end
end
-- Update the state of all the buttons and reassign the currently clicked button
local clickedButton = self . m_clickedButton
do
end
end |