Vehicle control additions & fixes (#1926)

* Removed summon distance & car only check
* Changed raw UI elements to components.
* Added selection methods
* feat(VehicleController): add translation strings

Co-authored-by: Yimura <24669514+Yimura@users.noreply.github.com>
This commit is contained in:
DayibBaba
2023-11-04 00:22:07 +01:00
committed by GitHub
parent 6ed257f67c
commit 5d391acfe0
4 changed files with 157 additions and 143 deletions

View File

@ -42,31 +42,29 @@ namespace big
{
for (int lockindex = 0; lockindex < MAX_VEHICLE_LOCK_STATES; lockindex++)
{
if (ImGui::Selectable(locknames[lockindex]))
{
g_fiber_pool->queue_job([=] {
components::selectable(locknames[lockindex], false, [lockindex] {
g_vehicle_control_service.vehicle_operation([lockindex] {
vehicle::change_vehicle_door_lock_state(g_vehicle_control_service.m_controlled_vehicle.handle, eDoorId::VEH_EXT_DOOR_INVALID_ID, (eVehicleLockState)lockindex);
});
};
});
}
ImGui::EndCombo();
}
ImGui::SameLine();
if (components::button("OPEN_ALL_DOORS"_T))
{
g_fiber_pool->queue_job([=] {
g_vehicle_control_service.operate_door(eDoorId::VEH_EXT_DOOR_INVALID_ID, true);
components::button("OPEN_ALL_DOORS"_T, [] {
g_vehicle_control_service.vehicle_operation([] {
vehicle::operate_vehicle_door(g_vehicle_control_service.m_controlled_vehicle.handle, eDoorId::VEH_EXT_DOOR_INVALID_ID, true);
});
}
});
ImGui::SameLine();
if (components::button("CLOSE_ALL_DOORS"_T))
{
g_fiber_pool->queue_job([=] {
g_vehicle_control_service.operate_door(eDoorId::VEH_EXT_DOOR_INVALID_ID, false);
components::button("CLOSE_ALL_DOORS"_T, [] {
g_vehicle_control_service.vehicle_operation([] {
vehicle::operate_vehicle_door(g_vehicle_control_service.m_controlled_vehicle.handle, eDoorId::VEH_EXT_DOOR_INVALID_ID, false);
});
}
});
ImGui::EndGroup();
@ -84,12 +82,11 @@ namespace big
{
for (int lockindex = 0; lockindex < MAX_VEHICLE_LOCK_STATES; lockindex++)
{
if (ImGui::Selectable(locknames[lockindex]))
{
g_fiber_pool->queue_job([=] {
components::selectable(locknames[lockindex], false, [i, lockindex] {
g_vehicle_control_service.vehicle_operation([i, lockindex] {
vehicle::change_vehicle_door_lock_state(g_vehicle_control_service.m_controlled_vehicle.handle, (eDoorId)i, (eVehicleLockState)lockindex);
});
};
});
}
ImGui::EndCombo();
}
@ -97,17 +94,17 @@ namespace big
ImGui::SameLine(300);
const auto button_label = g_vehicle_control_service.m_controlled_vehicle.doors[i].open ? "CLOSE"_T : "OPEN"_T;
if (components::button(button_label))
{
g_fiber_pool->queue_job([=] {
g_vehicle_control_service.operate_door((eDoorId)i,
components::button(button_label, [i] {
g_vehicle_control_service.vehicle_operation([i] {
vehicle::operate_vehicle_door(g_vehicle_control_service.m_controlled_vehicle.handle,
(eDoorId)i,
!g_vehicle_control_service.m_controlled_vehicle.doors[i].open);
});
}
});
ImGui::PopID();
}
ImGui::EndGroup();
}
@ -124,11 +121,11 @@ namespace big
ImGui::Spacing();
ImGui::SetNextItemWidth(200);
components::button("VIEW_VEHICLE_CONTROL_ROLL_DOWN_ALL"_T, [] {
g_vehicle_control_service.operate_window(eWindowId::WINDOW_INVALID_ID, true);
vehicle::operate_vehicle_window(g_vehicle_control_service.m_controlled_vehicle.handle, eWindowId::WINDOW_INVALID_ID, true);
});
ImGui::SameLine();
components::button("VIEW_VEHICLE_CONTROL_ROLL_UP_ALL"_T, [] {
g_vehicle_control_service.operate_window(eWindowId::WINDOW_INVALID_ID, false);
vehicle::operate_vehicle_window(g_vehicle_control_service.m_controlled_vehicle.handle, eWindowId::WINDOW_INVALID_ID, false);
});
ImGui::EndGroup();
@ -143,11 +140,11 @@ namespace big
ImGui::Text(windownames[i]);
ImGui::SameLine(300);
components::button("VIEW_VEHICLE_CONTROL_ROLL_DOWN"_T, [i] {
g_vehicle_control_service.operate_window((eWindowId)i, true);
vehicle::operate_vehicle_window(g_vehicle_control_service.m_controlled_vehicle.handle, (eWindowId)i, true);
});
ImGui::SameLine();
components::button("VIEW_VEHICLE_CONTROL_ROLL_UP"_T, [i] {
g_vehicle_control_service.operate_window((eWindowId)i, false);
vehicle::operate_vehicle_window(g_vehicle_control_service.m_controlled_vehicle.handle, (eWindowId)i, false);
});
ImGui::PopID();
}
@ -162,37 +159,36 @@ namespace big
"BACK"_T.data(),
};
if (components::button("VEHICLE_CONTROLLER_TOGGLE_LIGHTS"_T))
{
g_fiber_pool->queue_job([=] {
g_vehicle_control_service.operate_lights(!g_vehicle_control_service.m_controlled_vehicle.headlights, false);
components::button("VEHICLE_CONTROLLER_TOGGLE_LIGHTS"_T, [] {
g_vehicle_control_service.vehicle_operation([=] {
vehicle::operate_vehicle_headlights(g_vehicle_control_service.m_controlled_vehicle.handle,
!g_vehicle_control_service.m_controlled_vehicle.headlights,
false);
});
}
});
ImGui::SameLine();
if (components::button("VEHICLE_CONTROLLER_TOGGLE_HIGH_BEAMS"_T))
{
g_fiber_pool->queue_job([=] {
g_vehicle_control_service.operate_lights(g_vehicle_control_service.m_controlled_vehicle.headlights,
components::button("VEHICLE_CONTROLLER_TOGGLE_HIGH_BEAMS"_T, [] {
g_vehicle_control_service.vehicle_operation([=] {
vehicle::operate_vehicle_headlights(g_vehicle_control_service.m_controlled_vehicle.handle,
g_vehicle_control_service.m_controlled_vehicle.headlights,
!g_vehicle_control_service.m_controlled_vehicle.highbeams);
});
}
if (components::button("VEHICLE_CONTROLLER_INTERIOR_LIGHTS_ON"_T))
{
g_fiber_pool->queue_job([=] {
if (g.window.vehicle_control.operation_animation)
g_vehicle_control_service.animated_vehicle_operation(self::ped);
});
components::button("VEHICLE_CONTROLLER_INTERIOR_LIGHTS_ON"_T, [] {
g_vehicle_control_service.vehicle_operation([] {
VEHICLE::SET_VEHICLE_INTERIORLIGHT(g_vehicle_control_service.m_controlled_vehicle.handle, true);
});
}
});
ImGui::SameLine();
if (components::button("VEHICLE_CONTROLLER_INTERIOR_LIGHTS_OFF"_T))
{
g_fiber_pool->queue_job([=] {
if (g.window.vehicle_control.operation_animation)
g_vehicle_control_service.animated_vehicle_operation(self::ped);
components::button("VEHICLE_CONTROLLER_INTERIOR_LIGHTS_OFF"_T, [] {
g_vehicle_control_service.vehicle_operation([] {
VEHICLE::SET_VEHICLE_INTERIORLIGHT(g_vehicle_control_service.m_controlled_vehicle.handle, false);
});
}
});
ImGui::Text("VEHICLE_CONTROLLER_NEON_LIGHTS"_T.data());
ImGui::Separator();
@ -202,7 +198,11 @@ namespace big
if (ImGui::Checkbox(neonnames[i], &g_vehicle_control_service.m_controlled_vehicle.neons[i]))
{
g_fiber_pool->queue_job([=] {
g_vehicle_control_service.operate_neons(i, g_vehicle_control_service.m_controlled_vehicle.neons[i]);
g_vehicle_control_service.vehicle_operation([i] {
vehicle::operate_vehicle_neons(g_vehicle_control_service.m_controlled_vehicle.handle,
i,
!g_vehicle_control_service.m_controlled_vehicle.neons[i]);
});
});
}
}
@ -258,49 +258,47 @@ namespace big
if (g_vehicle_control_service.m_controlled_vehicle.isconvertible)
{
if (components::button(g_vehicle_control_service.m_controlled_vehicle.convertibelstate ? "VIEW_VEHICLE_CONTROL_RAISE"_T : "VIEW_VEHICLE_CONTROL_LOWER"_T))
{
g_fiber_pool->queue_job([=] {
if (g.window.vehicle_control.operation_animation)
g_vehicle_control_service.animated_vehicle_operation(self::ped);
components::button(g_vehicle_control_service.m_controlled_vehicle.convertibelstate ? "VIEW_VEHICLE_CONTROL_RAISE"_T : "VIEW_VEHICLE_CONTROL_LOWER"_T, [] {
g_vehicle_control_service.vehicle_operation([] {
if (g_vehicle_control_service.m_controlled_vehicle.convertibelstate > 0)
VEHICLE::RAISE_CONVERTIBLE_ROOF(g_vehicle_control_service.m_controlled_vehicle.handle, false);
else
VEHICLE::LOWER_CONVERTIBLE_ROOF(g_vehicle_control_service.m_controlled_vehicle.handle, false);
});
}
});
ImGui::SameLine();
ImGui::Text(std::format("{}: {}", "VIEW_VEHICLE_CONTROL_CONVERTIBLE_STATE"_T, convertiblestates[g_vehicle_control_service.m_controlled_vehicle.convertibelstate]).c_str());
ImGui::Text(std::format("{}: {}",
"VIEW_VEHICLE_CONTROL_CONVERTIBLE_STATE"_T,
convertiblestates[g_vehicle_control_service.m_controlled_vehicle.convertibelstate])
.c_str());
}
if (ImGui::Checkbox(g_vehicle_control_service.m_controlled_vehicle.engine ? "VIEW_DEBUG_ANIMATIONS_STOP"_T.data() : "SETTINGS_NOTIFY_GTA_THREADS_START"_T.data(),
if (ImGui::Checkbox(g_vehicle_control_service.m_controlled_vehicle.engine ?
"VIEW_DEBUG_ANIMATIONS_STOP"_T.data() :
"SETTINGS_NOTIFY_GTA_THREADS_START"_T.data(),
&g_vehicle_control_service.m_controlled_vehicle.engine))
{
g_fiber_pool->queue_job([=] {
if (g.window.vehicle_control.operation_animation)
g_vehicle_control_service.animated_vehicle_operation(self::ped);
if (entity::take_control_of(g_vehicle_control_service.m_controlled_vehicle.handle))
g_vehicle_control_service.vehicle_operation([] {
VEHICLE::SET_VEHICLE_ENGINE_ON(g_vehicle_control_service.m_controlled_vehicle.handle,
!g_vehicle_control_service.m_controlled_vehicle.engine,
true,
false);
});
});
}
ImGui::SameLine();
ImGui::Text(std::format("{}: {}", "VIEW_VEHICLE_CONTROL_ENGINE"_T, g_vehicle_control_service.m_controlled_vehicle.engine ? "VIEW_VEHICLE_CONTROL_ENGINE_RUNNING"_T : "OFF"_T).c_str());
ImGui::Text(
std::format("{}: {}", "VIEW_VEHICLE_CONTROL_ENGINE"_T, g_vehicle_control_service.m_controlled_vehicle.engine ? "VIEW_VEHICLE_CONTROL_ENGINE_RUNNING"_T : "OFF"_T)
.c_str());
components::button(g_vehicle_control_service.m_driver_performing_task ? "CANCEL"_T : "VIEW_VEHICLE_CONTROL_SUMMON"_T, [] {
if (!g_vehicle_control_service.m_driver_performing_task)
{
if (g.window.vehicle_control.operation_animation)
g_vehicle_control_service.animated_vehicle_operation(self::ped);
g_vehicle_control_service.summon_vehicle();
}
g_vehicle_control_service.vehicle_operation([] {
g_vehicle_control_service.summon_vehicle();
});
else
g_vehicle_control_service.m_driver_performing_task = false;
});
@ -308,7 +306,9 @@ namespace big
if (g_vehicle_control_service.m_driver_performing_task)
{
ImGui::SameLine();
ImGui::Text(std::format("{}: {}", "VIEW_SELF_CUSTOM_TELEPORT_DISTANCE"_T, g_vehicle_control_service.m_distance_to_destination).c_str());
ImGui::Text(std::format("{}: {}", "VIEW_SELF_CUSTOM_TELEPORT_DISTANCE"_T, g_vehicle_control_service.m_distance_to_destination)
.c_str());
ImGui::Text(std::format("{}: {}", "OUTFIT_TASK"_T, g_vehicle_control_service.m_currentask).c_str());
}
@ -318,14 +318,23 @@ namespace big
g.window.vehicle_control.operation_animation);
bool_command render_veh_dist("vehcontrolrendervehdist", "VIEW_VEHICLE_CONTROL_RENDER_DISTANCE_ON_VEHICLE", "VIEW_VEHICLE_CONTROL_RENDER_DISTANCE_ON_VEHICLE_DESC",
g.window.vehicle_control.render_distance_on_veh);
float_command max_summon_dist("vehcontrolmaxsummondist", "VIEW_VEHICLE_CONTROL_MAX_SUMMON_DISTANCE", "VIEW_VEHICLE_CONTROL_MAX_SUMMON_DISTANCE_DESC",
g.window.vehicle_control.max_summon_range, 10.f, 250.f);
bool_command show_vehicle_info("vehcontrolshowvehinfo", "VIEW_VEHICLE_CONTROL_SHOW_VEHICLE_INFO", "VIEW_VEHICLE_CONTROL_SHOW_VEHICLE_INFO_DESC",
g.window.vehicle_control.show_info);
void render_settings_tab()
{
components::command_checkbox<"vehcontroluseanims">();
components::command_checkbox<"vehcontrolrendervehdist">();
components::command_float_slider<"vehcontrolmaxsummondist">();
components::command_checkbox<"vehcontrolshowvehinfo">();
ImGui::SeparatorText("VIEW_VEHICLE_CONTROL_SELECTION_MODE"_T.data());
ImGui::RadioButton("VIEW_VEHICLE_CONTROL_SELECTION_MODE_LAST_DRIVEN"_T.data(), (int*)&g_vehicle_control_service.m_selection_mode, (int)eControlledVehSelectionMode::LAST_DRIVEN);
ImGui::SameLine();
ImGui::RadioButton("VIEW_VEHICLE_CONTROL_SELECTION_MODE_PERSONAL_VEHICLE"_T.data(),
(int*)&g_vehicle_control_service.m_selection_mode,
(int)eControlledVehSelectionMode::PERSONAL);
ImGui::SameLine();
ImGui::RadioButton("VIEW_VEHICLE_CONTROL_SELECTION_MODE_CLOSEST"_T.data(), (int*)&g_vehicle_control_service.m_selection_mode, (int)eControlledVehSelectionMode::CLOSEST);
}
void view::vehicle_control()
@ -340,6 +349,15 @@ namespace big
if (g_vehicle_control_service.m_controlled_vehicle_exists)
{
ImGui::Text(g_vehicle_control_service.m_controlled_vehicle.model_name);
if (g.window.vehicle_control.show_info)
{
ImGui::Text(std::vformat("VIEW_VEHICLE_CONTROL_HEALTH_N_PASSENGERS"_T,
std::make_format_args(g_vehicle_control_service.m_controlled_vehicle.ptr->m_health,
g_vehicle_control_service.m_controlled_vehicle.ptr->m_num_of_passengers,
g_vehicle_control_service.m_controlled_vehicle.ptr->m_max_passengers))
.c_str());
}
ImGui::Separator();
ImGui::Spacing();
if (ImGui::BeginTabBar("##vehiclecontroltabbar"))
@ -386,7 +404,6 @@ namespace big
ImGui::EndTabItem();
}
ImGui::EndTabBar();
}
}