Skip to content

Commit

Permalink
feat(radar): convert input to new Lua input system
Browse files Browse the repository at this point in the history
Move the input control registration from C++ to Lua.

From a user-perspective, the move also includes moving the
configuration into a new "Ship HUD" controls page, as well as changing
the default key bindings away from the arrow-keys.

TODO: Add an axis to control the radar zoom level.
  • Loading branch information
mwerle committed Nov 15, 2024
1 parent fcf3e0f commit e2b015d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
4 changes: 4 additions & 0 deletions data/lang/input-core/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@
"description": "Header for the ShipControls input page.",
"message": "Ship - Controls"
},
"PAGE_SHIP_HUD": {
"description": "Header for the ShipHUD input page.",
"message": "Ship - HUD"
},
"PAGE_SHIP_VIEW": {
"description": "Header for the ShipView input page.",
"message": "Ship - View"
Expand Down
20 changes: 16 additions & 4 deletions data/pigui/modules/radar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@ local DEFAULT_RADAR_SIZE = 10000
local shouldDisplay2DRadar = false
local blobSize = 6.0

local input_group = 'ShipHUD.RadarControl'
local keys = {
radar_toggle_mode = Input.GetActionBinding('BindRadarToggleMode'),
radar_reset = Input.GetActionBinding('BindRadarZoomReset'),
radar_reset = Input.RegisterActionBinding('BindRadarZoomReset', input_group, { activator = { key = Input.keys['slash'] } }),
radar_toggle_mode = Input.RegisterActionBinding('BindRadarToggleMode', input_group, { activator = { key = Input.keys['semicolon'] } }),
-- TODO: Convert to Axis?
radar_zoom_in = Input.GetActionBinding('BindRadarZoomIn'),
radar_zoom_out = Input.GetActionBinding('BindRadarZoomOut'),
radar_zoom_in = Input.RegisterActionBinding('BindRadarZoomIn', input_group, { activator = { key = Input.keys['comma'] } }),
radar_zoom_out = Input.RegisterActionBinding('BindRadarZoomOut', input_group, { activator = { key = Input.keys['period'] } }),
}
local input_frame = Input.CreateInputFrame("ShipHudRadar", true)
input_frame:AddAction(keys.radar_reset)
input_frame:AddAction(keys.radar_toggle_mode)
input_frame:AddAction(keys.radar_zoom_in)
input_frame:AddAction(keys.radar_zoom_out)

local function getColorFor(item)
local body = item.body
Expand Down Expand Up @@ -370,8 +376,14 @@ local function displayRadar()

end -- function displayRadar()

-- enable radar input frame on game start
Event.Register("onGameStart", function()
input_frame:AddToStack()
end)

-- reset radar to default at game end
Event.Register("onGameEnd", function()
input_frame:RemoveFromStack()
shouldDisplay2DRadar = false
radar2d:resetZoom()
radar3d:resetZoom()
Expand Down
7 changes: 0 additions & 7 deletions src/ship/PlayerShipController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,6 @@ REGISTER_INPUT_BINDING(PlayerShipController)
auto landingGroup = controlsPage->GetBindingGroup("LandingControl");
input->AddActionBinding("BindToggleLandingGear", landingGroup, Action({ SDLK_n }));
input->AddAxisBinding("BindControlLandingGear", landingGroup, Axis());

auto radarGroup = controlsPage->GetBindingGroup("RadarControl");
input->AddActionBinding("BindRadarZoomReset", radarGroup, Action({ SDLK_DOWN }));
input->AddActionBinding("BindRadarToggleMode", radarGroup, Action({ SDLK_UP }));
input->AddActionBinding("BindRadarZoomIn", radarGroup, Action({ SDLK_LEFT }));
input->AddActionBinding("BindRadarZoomOut", radarGroup, Action({ SDLK_RIGHT }));
input->AddAxisBinding("BindRadarZoom", radarGroup, Axis());
}

PlayerShipController::PlayerShipController() :
Expand Down

0 comments on commit e2b015d

Please sign in to comment.