local Data = {
[0] = {
scenario = "M16_TXT_ADV_SC_00",
choices = {
[1] = {
label = "M16_TXT_ADV_SC_00_CH1",
target = 2,
type = TYPE_BUTTON,
},
[2] = {
label = "M16_TXT_ADV_SC_00_CH2",
target = 3,
type = TYPE_BUTTON,
},
[3] = {
label = "M16_TXT_ADV_SC_00_CH3",
target = 1,
type = TYPE_BUTTON,
},
[4] = {
label = "M16_TXT_ADV_SC_00_CH4",
target = 0,
type = TYPE_BUTTON,
},
},
sfx = "Scenario",
},
[1] = {
scenario = "M16_TXT_ADV_SC_01",
choices = {
[1] = {
label = "M16_TXT_ADV_SC_01_CH1",
target = 2,
type = TYPE_BUTTON,
},
[2] = {
label = "M16_TXT_ADV_SC_01_CH2",
target = 3,
type = TYPE_BUTTON,
},
[3] = {
label = "M16_TXT_ADV_SC_01_CH3",
target = 0,
type = TYPE_BUTTON,
},
},
sfx = "Neutral",
},
[2] = {
scenario = "M16_TXT_ADV_SC_02",
choices = {
[1] = {
label = "M16_TXT_ADV_SC_02_CH1",
target = 0,
type = TYPE_BUTTON,
},
},
sfx = "Dead",
},
[3] = {
scenario = "M16_TXT_ADV_SC_03",
choices = {
[1] = {
label = "M16_TXT_ADV_SC_03_CH1",
target = 6,
type = TYPE_BUTTON,
},
[2] = {
label = "M16_TXT_ADV_SC_03_CH2",
target = 4,
type = TYPE_BUTTON,
},
[3] = {
label = "M16_TXT_ADV_SC_03_CH3",
target = 5,
type = TYPE_BUTTON,
},
},
sfx = "Progress",
},
[4] = {
scenario = "M16_TXT_ADV_SC_04",
choices = {
[1] = {
label = "M16_TXT_ADV_SC_04_CH1",
target = 6,
type = TYPE_BUTTON,
},
[2] = {
label = "M16_TXT_ADV_SC_04_CH2",
target = 5,
type = TYPE_BUTTON,
},
},
sfx = "Neutral",
},
[5] = {
scenario = "M16_TXT_ADV_SC_05",
choices = {
[1] = {
label = "M16_TXT_ADV_SC_05_CH1",
target = 0,
type = TYPE_BUTTON,
},
},
sfx = "Dead",
},
[6] = {
scenario = "M16_TXT_ADV_SC_06",
choices = {
[1] = {
label = "M16_TXT_ADV_SC_06_CH1",
target = 9,
type = TYPE_BUTTON,
},
[2] = {
label = "M16_TXT_ADV_SC_06_CH2",
target = 8,
type = TYPE_BUTTON,
},
[3] = {
label = "M16_TXT_ADV_SC_06_CH3",
target = 7,
type = TYPE_BUTTON,
},
},
sfx = "Progress",
},
[7] = {
scenario = "M16_TXT_ADV_SC_07",
choices = {
[1] = {
label = "M16_TXT_ADV_SC_07_CH1",
target = 9,
type = TYPE_BUTTON,
},
[2] = {
label = "M16_TXT_ADV_SC_07_CH2",
target = 8,
type = TYPE_BUTTON,
},
},
sfx = "Neutral",
},
[8] = {
scenario = "M16_TXT_ADV_SC_08",
choices = {
[1] = {
label = "M16_TXT_ADV_SC_08_CH1",
target = 0,
type = TYPE_BUTTON,
},
},
sfx = "Dead",
},
[9] = {
scenario = "M16_TXT_ADV_SC_09",
choices = {
[1] = {
label = "M16_TXT_ADV_SC_09_CH1",
target = 10,
type = TYPE_BUTTON,
},
[2] = {
label = "M16_TXT_ADV_SC_09_CH2",
target = 11,
type = TYPE_BUTTON,
},
[3] = {
label = "M16_TXT_ADV_SC_09_CH3",
target = 12,
type = TYPE_BUTTON,
},
},
sfx = "Progress",
},
[10] = {
scenario = "M16_TXT_ADV_SC_10",
choices = {
[1] = {
label = "M16_TXT_ADV_SC_10_CH1",
target = 11,
type = TYPE_BUTTON,
},
[2] = {
label = "M16_TXT_ADV_SC_10_CH2",
target = 12,
type = TYPE_BUTTON,
},
},
sfx = "Neutral",
},
[11] = {
scenario = "M16_TXT_ADV_SC_11",
choices = {
[1] = {
label = "M16_TXT_ADV_SC_11_CH1",
target = 0,
type = TYPE_BUTTON,
},
},
sfx = "Dead",
},
[12] = {
scenario = "M16_TXT_ADV_SC_12",
choices = {
[1] = {
label = "M16_TXT_ADV_SC_12_CH2",
target = -1,
type = TYPE_BUTTON,
},
[2] = {
label = "M16_TXT_ADV_SC_12_CH1",
target = 0,
type = TYPE_BUTTON,
},
},
sfx = "Win",
},
}
local COLOR_TEXT_ADVENTURE_PRIMARY = {R = 220/255, G = 220/255, B = 220/255}
local COLOR_TEXT_ADVENTURE_SECONDARY = {R = 120/255, G = 120/255, B = 120/255}
local COLOR_TEXT_ADVENTURE_TERTIARY = {R = 90/255, G = 90/255, B = 90/255}
local Text_buffer = {}
local Max_text_buffer_length = 6
local Input_tracker
local Mouse_input_tracker
local Msn_text_adventure_doc_handle = -1
local Active_list
local Cur_scen = 0
local Cur_audio_id = -1
local Action = {}
function msn_text_adventure_init()
--Get doc handle
Msn_text_adventure_doc_handle = vint_document_find("msn_text_adventure")
--Handle Input Tracker
Input_tracker = Vdo_input_tracker:new()
Input_tracker:add_input("nav_up", "msn_text_adventure_nav_up", 50)
Input_tracker:add_input("nav_down", "msn_text_adventure_nav_down", 50)
Input_tracker:add_input("select", "msn_text_adventure_button_a", 50)
Input_tracker:subscribe(true)
-- Add mouse input subscriptions for the PC
if game_get_platform() == "PC" then
Mouse_input_tracker = Vdo_input_tracker:new()
end
--Setup megalist
Active_list = Vdo_mega_list:new("choice_list", 0, Msn_text_adventure_doc_handle)
Active_list:set_highlight_color(COLOR_TEXT_ADVENTURE_TERTIARY,COLOR_STORE_VEHICLE_SECONDARY,COLOR_STORE_VEHICLE_TERTIARY)
--Hide base text
local base_text = vint_object_find("base_text", 0, Msn_text_adventure_doc_handle)
vint_set_property(base_text, "visible", false)
local cursor_blink = Vdo_anim_object:new("cursor_blink", 0, Msn_text_adventure_doc_handle)
cursor_blink:play(0)
msn_text_adventure_update(Data)
end
function msn_text_adventure_cleanup()
for i = 1, #Text_buffer do
Text_buffer[i]:object_destroy()
end
end
function msn_text_adventure_update(data)
local base_text = vint_object_find("base_txt", 0, Msn_text_adventure_doc_handle)
vint_set_property(base_text, "visible", false)
--If we're on the first page play typing audio
if Cur_scen == 0 then
audio_stop(Cur_audio_id)
Cur_audio_id = audio_object_post_event("Text_Adventure", "Mission_16_Text_Adventure", Data[Cur_scen].sfx)
end
--Make current text first in the queue
if Text_buffer[1] ~= nil then
for i = Max_text_buffer_length, 1, -1 do
if Text_buffer[i] ~= nil then
Text_buffer[i+1] = Text_buffer[i]
end
end
end
Text_buffer[1] = Vdo_base_object:clone(base_text)
Text_buffer[1]:set_text(data[Cur_scen].scenario)
Text_buffer[1]:set_visible(true)
local move_width, move_height = Text_buffer[1]:get_actual_size()
local text_x, text_y
--Scroll text up if text exist
if Text_buffer[2] ~= nil then
text_x, text_y = Text_buffer[2]:get_anchor()
Text_buffer[2]:set_anchor(text_x, text_y - move_height)
Text_buffer[2]:set_color(COLOR_TEXT_ADVENTURE_TERTIARY.R,COLOR_TEXT_ADVENTURE_TERTIARY.G,COLOR_TEXT_ADVENTURE_TERTIARY.B)
--Delete items that go off the screen
if text_y < -200 then
Text_buffer[2]:object_destroy()
end
end
--Populate megalist
Active_list:draw_items(data[Cur_scen].choices, 1, 500, 4, .8)
--Update inputs if on pc...
if game_get_platform() == "PC" then
Mouse_input_tracker:remove_all()
Active_list:add_mouse_inputs("msn_text_adventure", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
end
function msn_text_adventure_button_a(event, acceleration)
--What choice did they pick?
local user_choice = Active_list:get_selection()
local previous_scen = Cur_scen
--Set cur_scene to target
Cur_scen = Data[Cur_scen].choices[user_choice].target
if Cur_scen == -1 then
msn_text_adventure_set_screen(12) -- count the success as a 12th screen
pop_screen()
return
end
if Cur_scen == 0 then
-- if the current scene is 0, and the previous was 0, the player decided to nap
if previous_scen == 0 then
msn_text_adventure_set_screen(Cur_scen)
end
else
msn_text_adventure_set_screen(Cur_scen)
end
audio_stop(Cur_audio_id)
Cur_audio_id = audio_object_post_event("Text_Adventure", "Mission_16_Text_Adventure", Data[Cur_scen].sfx)
--What is the string for that choice?
Action = Active_list:return_selected_data()
Text_buffer[1]:set_text(Action.label)
if Text_buffer[2] ~= nil then
Text_buffer[2]:object_destroy()
end
--Update text
msn_text_adventure_update(Data)
end
function msn_text_adventure_nav_up(event, acceleration)
Active_list:move_cursor(-1)
Cur_audio_id = audio_object_post_event("Text_Adventure", "Mission_16_Text_Adventure", "Navigation")
end
function msn_text_adventure_nav_down(event, acceleration)
Active_list:move_cursor(1)
Cur_audio_id = audio_object_post_event("Text_Adventure", "Mission_16_Text_Adventure", "Navigation")
end
-------------------------------------------------------------------------------
-- Mouse inputs
--
function msn_text_adventure_mouse_click(event, target_handle)
--Click item in megalist...
local new_index = Active_list:get_button_index(target_handle)
if new_index ~= 0 then
-- Enter an option if the target_handle is in the List
Active_list:set_selection(new_index)
msn_text_adventure_button_a()
end
end
function msn_text_adventure_mouse_move(event, target_handle)
--nav item in megalist...
local new_index = Active_list:get_button_index(target_handle)
if new_index ~= 0 then
-- Set the button as the new selected highlight
Active_list:set_selection(new_index)
Active_list:move_cursor(0, true)
end
end