Divergent/mods/Transition Between Location.../gamedata/scripts/ui_sr_teleport.script

174 lines
5.1 KiB
Plaintext

-- basic dynamic msg_box
-- alundaio
local ini = ini_file("sr_teleport_sections.ltx")
class "msg_box_ui" (CUIScriptWnd)
function msg_box_ui:__init(obj,disable_msg,item) super()
self:SetWndRect(Frect():set(0,0,1024,768))
self:SetAutoDelete(true)
self.name = obj and obj:name()
self.disable_msg = disable_msg
self.item = item
if (string.find(self.name,obj:id())) then
local story_name = get_object_story_id(obj:id())
self.name = story_name or self.name
end
if (not self.name or not ini:section_exist(self.name)) then
printf("sr_teleport_sections.ltx: section doesn't exist %s",obj and obj:name())
return
end
if (alife_storage_manager.get_state().opened_routes ~= true) then
if not (( txr_routes.scan_route(self.name)) or mlr_utils.load_var("routes_"..self.name)) then
actor_menu.set_msg(1, game.translate_string("st_route_unknown"),5)
self:InitCallBacks()
self:OnMsgCancel()
return
end
end
--[[
local enable = ini:r_string_ex(self.name,"enable")
enable = enable and xr_logic.pick_section_from_condlist(db.actor,obj,xr_logic.parse_condlist(obj,"enable",self.name,enable))
if (enable ~= "true") then
local reject_on_disable = ini:r_bool_ex(self.name,"reject_on_disabled",false)
if (reject_on_disable) then
local warning = ini:r_string_ex(self.name,"warning")
if (warning) then
actor_menu.set_msg(1, game.translate_string(warning),5)
end
self:InitCallBacks()
self:OnMsgCancel()
end
return
end
]]--
self.obj = obj
self.message_box = CUIMessageBoxEx()
self:Register(self.message_box, "msg_box")
self:InitCallBacks()
if not (is_empty(xr_combat_ignore.fighting_with_actor_npcs)) then
self:InitControls()
else
self:OnMsgOk()
end
end
function msg_box_ui:__finalize()
end
function msg_box_ui:InitCallBacks()
self:AddCallback("msg_box", ui_events.MESSAGE_BOX_OK_CLICKED, self.OnMsgOk, self)
self:AddCallback("msg_box", ui_events.MESSAGE_BOX_CANCEL_CLICKED, self.OnMsgCancel, self)
self:AddCallback("msg_box", ui_events.MESSAGE_BOX_YES_CLICKED, self.OnMsgOk, self)
self:AddCallback("msg_box", ui_events.MESSAGE_BOX_NO_CLICKED, self.OnMsgCancel, self)
end
function msg_box_ui:OnMsgOk()
local pos = ini:r_string_ex(self.name,"position")
local path = pos == nil and ini:r_string_ex(self.name,"path")
local point = path and patrol(path)
if not (pos or point) then
return
end
--if not (self.disable_msg) then
level.add_pp_effector("sleep_fade.ppe", 1313, false)
--end
local function travel()
if (ini:r_bool_ex(self.name,"autosave",false)) then
xr_effects.scenario_autosave(nil,nil,{ini:r_string_ex(self.name,"hint") or "moving"})
end
local p = pos and str_explode(pos,",")
pos = p and vector():set(tonumber(p[1]),tonumber(p[2]),tonumber(p[3]))
local allow_car = ini:r_bool_ex(self.name,"allow_vehicle",true)
if (allow_car) then
-- allow vehicles to teleport too
local car = db.actor:get_attached_vehicle()
if (car) then
car:force_set_position(pos or point and point:point(0))
else
db.actor:set_actor_position(pos or point and point:point(0))
end
else
-- If not wanting vehicles to teleport
local car = db.actor:get_attached_vehicle()
if (car) then
db.actor:detach_vehicle()
local cpos = ini:r_string_ex(self.name,"reject")
local cpath = cpos == nil and ini:r_string_ex(self.name,"reject_path")
local cpoint = cpath and patrol(cpath)
local cp = cpos and str_explode(cpos,",")
cpos = cp and vector():set(tonumber(cp[1]) or 0,tonumber(cp[2]) or 0,tonumber(cp[3]) or 0)
if (cpos or cpoint) then
TeleportObject(car:id(),cpos or cpoint and cpoint:point(0),cpoint and cpoint:level_vertex_id(0),cpoint and cpoint:game_vertex_id(0))
end
end
db.actor:set_actor_position(pos or point and point:point(0) or db.actor:position())
end
if (pos and p[4]) then
db.actor:set_actor_direction(tonumber(p[4]) or 0)
end
return true
end
SendScriptCallback("on_before_level_changing")
CreateTimeEvent(0,"delay_travel",3,travel)
end
function msg_box_ui:OnMsgCancel()
local pos = ini:r_string_ex(self.name,"reject")
local path = pos == nil and ini:r_string_ex(self.name,"reject_path")
local point = path and patrol(path)
if not (pos or point) then
return
end
local p = pos and str_explode(pos,",")
pos = p and vector():set(tonumber(p[1]) or 0,tonumber(p[2]) or 0,tonumber(p[3]) or 0)
db.actor:set_actor_position(pos or point and point:point(0) or db.actor:position())
if (pos and p[4]) then
db.actor:set_actor_direction(tonumber(p[4]) or 0)
return
end
db.actor:set_actor_direction(-device().cam_dir:getH())
end
function msg_box_ui:InitControls()
if (self.disable_msg) then
if (not self.item or db.actor:object(self.item)) then
self:OnMsgOk()
else
self:OnMsgCancel()
end
return
end
self.message_box:InitMessageBox("message_box_yes_no")
self.message_box:ShowDialog(true)
local next_level = game.translate_string(ini:r_string_ex(self.name,"hint") or "")
local msg_str = game.translate_string("st_level_changer_descr")
local str = strformat(msg_str, next_level)
self.message_box:SetText(str)
end