mirror of
https://github.com/APercy/airutils.git
synced 2025-03-21 18:41:21 +00:00
improved formspecs
This commit is contained in:
parent
e74e27ca25
commit
d2d3c24468
3 changed files with 178 additions and 10 deletions
|
@ -29,6 +29,7 @@ end
|
||||||
|
|
||||||
function airutils.on_activate(self, staticdata, dtime_s)
|
function airutils.on_activate(self, staticdata, dtime_s)
|
||||||
airutils.actfunc(self, staticdata, dtime_s)
|
airutils.actfunc(self, staticdata, dtime_s)
|
||||||
|
self._flap = false
|
||||||
|
|
||||||
if staticdata ~= "" and staticdata ~= nil then
|
if staticdata ~= "" and staticdata ~= nil then
|
||||||
local data = minetest.deserialize(staticdata) or {}
|
local data = minetest.deserialize(staticdata) or {}
|
||||||
|
@ -253,6 +254,11 @@ function airutils.logic(self)
|
||||||
airutils.flap_off(self)
|
airutils.flap_off(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--landing light
|
||||||
|
if self._have_landing_lights then
|
||||||
|
airutils.landing_lights_operate(self)
|
||||||
|
end
|
||||||
|
|
||||||
if longit_speed == 0 and is_flying == false and is_attached == false and self._engine_running == false then
|
if longit_speed == 0 and is_flying == false and is_attached == false and self._engine_running == false then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,11 +14,6 @@ function airutils.getPlaneFromPlayer(player)
|
||||||
end
|
end
|
||||||
|
|
||||||
function airutils.pilot_formspec(name)
|
function airutils.pilot_formspec(name)
|
||||||
local basic_form = table.concat({
|
|
||||||
"formspec_version[3]",
|
|
||||||
"size[6.0,7.0]",
|
|
||||||
}, "")
|
|
||||||
|
|
||||||
local player = minetest.get_player_by_name(name)
|
local player = minetest.get_player_by_name(name)
|
||||||
local plane_obj = airutils.getPlaneFromPlayer(player)
|
local plane_obj = airutils.getPlaneFromPlayer(player)
|
||||||
if plane_obj == nil then
|
if plane_obj == nil then
|
||||||
|
@ -26,18 +21,92 @@ function airutils.pilot_formspec(name)
|
||||||
end
|
end
|
||||||
local ent = plane_obj:get_luaentity()
|
local ent = plane_obj:get_luaentity()
|
||||||
|
|
||||||
|
local extra_height = 0
|
||||||
|
|
||||||
|
local flap_is_down = "false"
|
||||||
|
local have_flaps = false
|
||||||
|
if ent._wing_angle_extra_flaps then
|
||||||
|
if ent._wing_angle_extra_flaps > 0 then
|
||||||
|
have_flaps = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if have_flaps then
|
||||||
|
if ent._flap then flap_is_down = "true" end
|
||||||
|
extra_height = extra_height + 0.5
|
||||||
|
end
|
||||||
|
|
||||||
|
local light = "false"
|
||||||
|
if ent._have_landing_lights then
|
||||||
|
if ent._land_light then light = "true" end
|
||||||
|
extra_height = extra_height + 0.5
|
||||||
|
end
|
||||||
|
|
||||||
|
if ent._have_copilot then extra_height = extra_height + 1.1 end
|
||||||
|
|
||||||
local yaw = "false"
|
local yaw = "false"
|
||||||
if ent._yaw_by_mouse then yaw = "true" end
|
if ent._yaw_by_mouse then yaw = "true" end
|
||||||
|
|
||||||
basic_form = basic_form.."button[1,1.0;4,1;turn_on;Start/Stop Engines]"
|
local basic_form = table.concat({
|
||||||
basic_form = basic_form.."button[1,2.1;4,1;hud;Show/Hide Gauges]"
|
"formspec_version[3]",
|
||||||
basic_form = basic_form.."button[1,3.2;4,1;inventory;Show Inventory]"
|
"size[6.0,"..(7.0+extra_height).."]",
|
||||||
basic_form = basic_form.."checkbox[1,4.7;yaw;Yaw by mouse;"..yaw.."]"
|
}, "")
|
||||||
basic_form = basic_form.."button[1,5.2;4,1;go_out;Go Out!]"
|
|
||||||
|
local ver_pos = 1.0
|
||||||
|
basic_form = basic_form.."button[1,"..ver_pos..";4,1;turn_on;Start/Stop Engines]"
|
||||||
|
ver_pos = ver_pos + 1.1
|
||||||
|
basic_form = basic_form.."button[1,"..ver_pos..";4,1;hud;Show/Hide Gauges]"
|
||||||
|
ver_pos = ver_pos + 1.1
|
||||||
|
basic_form = basic_form.."button[1,"..ver_pos..";4,1;inventory;Show Inventory]"
|
||||||
|
ver_pos = ver_pos + 1.5
|
||||||
|
|
||||||
|
if have_flaps then
|
||||||
|
basic_form = basic_form.."checkbox[1,"..ver_pos..";flap_is_down;Flaps down;"..flap_is_down.."]"
|
||||||
|
ver_pos = ver_pos + 0.5
|
||||||
|
end
|
||||||
|
|
||||||
|
if ent._have_landing_lights then
|
||||||
|
basic_form = basic_form.."checkbox[1,"..ver_pos..";light;Landing Light;"..light.."]"
|
||||||
|
ver_pos = ver_pos + 0.5
|
||||||
|
end
|
||||||
|
|
||||||
|
basic_form = basic_form.."checkbox[1,"..ver_pos..";yaw;Yaw by mouse;"..yaw.."]"
|
||||||
|
ver_pos = ver_pos + 0.5
|
||||||
|
|
||||||
|
if ent._have_copilot then
|
||||||
|
basic_form = basic_form.."button[1,"..ver_pos..";4,1;copilot_form;Co-pilot Manage]"
|
||||||
|
ver_pos = ver_pos + 1.1
|
||||||
|
end
|
||||||
|
|
||||||
|
basic_form = basic_form.."button[1,"..ver_pos..";4,1;go_out;Go Out!]"
|
||||||
|
|
||||||
minetest.show_formspec(name, "lib_planes:pilot_main", basic_form)
|
minetest.show_formspec(name, "lib_planes:pilot_main", basic_form)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function airutils.manage_copilot_formspec(name)
|
||||||
|
local player = minetest.get_player_by_name(name)
|
||||||
|
local plane_obj = airutils.getPlaneFromPlayer(player)
|
||||||
|
if plane_obj == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local ent = plane_obj:get_luaentity()
|
||||||
|
|
||||||
|
local pass_list = ""
|
||||||
|
for k, v in pairs(ent._passengers) do
|
||||||
|
pass_list = pass_list .. v .. ","
|
||||||
|
end
|
||||||
|
|
||||||
|
local basic_form = table.concat({
|
||||||
|
"formspec_version[3]",
|
||||||
|
"size[6,4.5]",
|
||||||
|
}, "")
|
||||||
|
|
||||||
|
basic_form = basic_form.."label[1,1.0;Bring a copilot:]"
|
||||||
|
basic_form = basic_form.."dropdown[1,1.5;4,0.6;copilot;"..pass_list..";0;false]"
|
||||||
|
basic_form = basic_form.."button[1,2.5;4,1;pass_control;Pass the Control]"
|
||||||
|
|
||||||
|
minetest.show_formspec(name, "lib_planes:manage_copilot", basic_form)
|
||||||
|
end
|
||||||
|
|
||||||
function airutils.pax_formspec(name)
|
function airutils.pax_formspec(name)
|
||||||
local basic_form = table.concat({
|
local basic_form = table.concat({
|
||||||
"formspec_version[3]",
|
"formspec_version[3]",
|
||||||
|
@ -152,6 +221,27 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
airutils.show_vehicle_trunk_formspec(ent, player, ent._trunk_slots)
|
airutils.show_vehicle_trunk_formspec(ent, player, ent._trunk_slots)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if fields.flap_is_down then
|
||||||
|
if fields.flap_is_down == "true" then
|
||||||
|
ent._flap = true
|
||||||
|
else
|
||||||
|
ent._flap = false
|
||||||
|
end
|
||||||
|
minetest.sound_play("airutils_collision", {
|
||||||
|
object = ent.object,
|
||||||
|
max_hear_distance = 15,
|
||||||
|
gain = 1.0,
|
||||||
|
fade = 0.0,
|
||||||
|
pitch = 0.5,
|
||||||
|
}, true)
|
||||||
|
end
|
||||||
|
if fields.light then
|
||||||
|
if ent._land_light == true then
|
||||||
|
ent._land_light = false
|
||||||
|
else
|
||||||
|
ent._land_light = true
|
||||||
|
end
|
||||||
|
end
|
||||||
if fields.yaw then
|
if fields.yaw then
|
||||||
if ent._yaw_by_mouse == true then
|
if ent._yaw_by_mouse == true then
|
||||||
ent._yaw_by_mouse = false
|
ent._yaw_by_mouse = false
|
||||||
|
@ -159,7 +249,61 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
ent._yaw_by_mouse = true
|
ent._yaw_by_mouse = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if fields.copilot_form then
|
||||||
|
airutils.manage_copilot_formspec(name)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
minetest.close_formspec(name, "lib_planes:pilot_main")
|
minetest.close_formspec(name, "lib_planes:pilot_main")
|
||||||
end
|
end
|
||||||
|
if formname == "lib_planes:manage_copilot" then
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local plane_obj = airutils.getPlaneFromPlayer(player)
|
||||||
|
if plane_obj == nil then
|
||||||
|
minetest.close_formspec(name, "lib_planes:manage_copilot")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local ent = plane_obj:get_luaentity()
|
||||||
|
|
||||||
|
if fields.copilot then
|
||||||
|
--look for a free seat first
|
||||||
|
local is_there_a_free_seat = false
|
||||||
|
for i = 2,1,-1
|
||||||
|
do
|
||||||
|
if ent._passengers[i] == nil then
|
||||||
|
is_there_a_free_seat = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
--then move the current copilot to a free seat
|
||||||
|
if ent.co_pilot and is_there_a_free_seat then
|
||||||
|
local copilot_player_obj = minetest.get_player_by_name(ent.co_pilot)
|
||||||
|
if copilot_player_obj then
|
||||||
|
airutils.dettach_pax(ent, copilot_player_obj)
|
||||||
|
airutils.attach_pax(ent, copilot_player_obj)
|
||||||
|
else
|
||||||
|
ent.co_pilot = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
--so bring the new copilot
|
||||||
|
if ent.co_pilot == nil then
|
||||||
|
local new_copilot_player_obj = minetest.get_player_by_name(fields.copilot)
|
||||||
|
if new_copilot_player_obj then
|
||||||
|
airutils.dettach_pax(ent, new_copilot_player_obj)
|
||||||
|
airutils.attach_pax(ent, new_copilot_player_obj, true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if fields.pass_control then
|
||||||
|
if ent._command_is_given == true then
|
||||||
|
--take the control
|
||||||
|
airutils.transfer_control(ent, false)
|
||||||
|
else
|
||||||
|
--trasnfer the control to student
|
||||||
|
airutils.transfer_control(ent, true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
minetest.close_formspec(name, "lib_planes:manage_copilot")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -832,3 +832,21 @@ function airutils.rescueConnectionFailedPassengers(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function airutils.landing_lights_operate(self)
|
||||||
|
if self._last_light_move == nil then self._last_light_move = 0.15 end
|
||||||
|
self._last_light_move = self._last_light_move + self.dtime
|
||||||
|
if self._last_light_move > 0.15 then
|
||||||
|
self._last_light_move = 0
|
||||||
|
if self._land_light == true and self._engine_running == true then
|
||||||
|
self._light_active_time = self._light_active_time + self.dtime
|
||||||
|
--minetest.chat_send_all(self._light_active_time)
|
||||||
|
if self._light_active_time > 24 then self._land_light = false end
|
||||||
|
airutils.put_light(self)
|
||||||
|
else
|
||||||
|
self._land_light = false
|
||||||
|
self._light_active_time = 0
|
||||||
|
airutils.remove_light(self)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue