./city_load.lua

  1. local IMAGE_DELAY = 5 
  2.  
  3. City_load_data = {  
  4. 		handles = { }, 
  5. } 
  6.  
  7. City_load_images = {	 
  8. 	"ui_mainmenu_load_01", 
  9. 	"ui_mainmenu_load_02", 
  10. 	"ui_mainmenu_load_03", 
  11. 	"ui_mainmenu_load_04", 
  12. 	"ui_mainmenu_load_05", 
  13. 	"ui_mainmenu_load_06", 
  14. 	"ui_mainmenu_load_07", 
  15. 	"ui_mainmenu_load_08", 
  16. 	"ui_mainmenu_load_09", 
  17. 	"ui_mainmenu_load_10", 
  18. 	"ui_mainmenu_load_11", 
  19. } 
  20.  
  21. City_load_current_images = {} 
  22. local City_load_doc_handle = -1 
  23.  
  24. function city_load_init() 
  25. 	City_load_doc_handle = vint_document_find("city_load") 
  26. 	local h = -1 
  27. 	City_load_data.handles.loading_grp_h = vint_object_find("loading_grp",0,City_load_doc_handle) 
  28. 	h = City_load_data.handles.loading_grp_h 
  29. 	City_load_data.handles.images_h = vint_object_find("images",0,City_load_doc_handle) 
  30. 	h = City_load_data.handles.images_h 
  31. 	City_load_data.handles.bmp1_h = vint_object_find("bmp1", h) 
  32. 	City_load_data.handles.bmp2_h = vint_object_find("bmp2", h) 
  33. 	City_load_data.handles.bmp3_h = vint_object_find("bmp3", h) 
  34. 	 
  35. 	--looping animation stuff 
  36. 	City_load_data.handles.transition2_h = vint_object_find("transition2",0,City_load_doc_handle) 
  37. 	h = City_load_data.handles.transition2_h 
  38. 	City_load_data.handles.load3_bmp1_out = vint_object_find("load3_bmp1_in", h) 
  39. 	local twn_h = City_load_data.handles.load3_bmp1_out 
  40. 	 
  41. 	vint_set_property(twn_h, "end_event", "city_load_transition") 
  42. 	 
  43. 	local loading_anim_h = vint_object_find("loading_anim",0,City_load_doc_handle) 
  44. 	local loading_twn_h = vint_object_find("loading_twn",loading_anim_h) 
  45. 	vint_set_property(loading_twn_h, "end_event", "vint_anim_loop_callback") 
  46. 	lua_play_anim(loading_anim_h,0,City_load_doc_handle) 
  47. 	 
  48. 	 
  49. 	--play animations... 
  50. 	local loading_pulse_anim_h = vint_object_find("loading_pulse_anim",0,City_load_doc_handle) 
  51. 	lua_play_anim(loading_pulse_anim_h,0,City_load_doc_handle) 
  52. 	 
  53. 	local loading_in_anim_h = vint_object_find("loading_in_anim",0,City_load_doc_handle) 
  54. 	lua_play_anim(loading_in_anim_h,0,City_load_doc_handle) 
  55. 	 
  56. 	 
  57. 	 
  58. 	local loading_images = {} 
  59. 	local random_num_values = {} 
  60. 	local random_num_count = 1 
  61. 	 
  62. 	local check_screen_fades = false 
  63. 	 
  64. 	--Make sure we don't try to load/unload our always loaded images 
  65. 	local screen_fade_doc_h = vint_document_find("screen_fade") 
  66. 	if screen_fade_doc_h ~= 0 then 
  67. 		--doc is loaded, now check if we are suing the always loaded images... 
  68. 		if Screen_fade_use_load_images then 
  69. 			check_screen_fades = true 
  70. 		end 
  71. 	end 
  72. 	 
  73. 	while #random_num_values < 3 do 
  74. 		local found_match = false 
  75. 		local random_num = rand_int(1,#City_load_images) 
  76. 		for i = 1, 3 do 
  77. 			if random_num == random_num_values[i] then 
  78. 				found_match = true 
  79. 			end 
  80. 		end 
  81. 		if found_match == false then 
  82. 			if check_screen_fades == true then 
  83. 				--loop through our loaded images and compare them against the city load images... 
  84. 				for idx, screen_fade_load_image in pairs(Screen_fade_loaded_images) do 
  85. 					if screen_fade_load_image == City_load_images[random_num] then 
  86. 						--Found match, don't add it to random_num_values. 
  87. 						found_match = true 
  88. 					end 
  89. 				end 
  90. 			end 
  91. 	 
  92. 			if found_match == false then 
  93. 				random_num_values[random_num_count] = random_num 
  94. 				random_num_count = random_num_count + 1 
  95. 			end 
  96. 		end 
  97. 	end 
  98. 	 
  99. 	local platform_file_ext = "" 
  100. 	if game_get_platform() == "PC" then 
  101. 		platform_file_ext = "_pc" 
  102. 	end 
  103.  
  104. 	for i = 1, #random_num_values do 
  105. 		loading_images[i] = City_load_images[random_num_values[i]] .. platform_file_ext 
  106. 	end 
  107. 	 
  108. 	local images = loading_images 
  109. 	City_load_current_images = images 
  110. 	 
  111. 	game_peg_load_with_cb("city_load_set_images", 3, images[1],  images[2], images[3])	 
  112. 	 
  113. end 
  114.  
  115. function city_load_set_images() 
  116. 	vint_set_property(City_load_data.handles.bmp1_h, "image", City_load_current_images[1]) 
  117. 	vint_set_property(City_load_data.handles.bmp2_h, "image", City_load_current_images[2]) 
  118. 	vint_set_property(City_load_data.handles.bmp3_h, "image", City_load_current_images[3]) 
  119. 	 
  120. 	--set up the wait time 
  121. 	local wait_anim_h = vint_object_find("wait_10_anim", 0, City_load_doc_handle) 
  122. 	local wait_twn_h = vint_object_find("wait_twn", wait_anim_h) 
  123. 	vint_set_property(wait_twn_h, "end_event", "city_load_show_images") 
  124. 	vint_set_property(wait_twn_h, "duration", IMAGE_DELAY) 
  125. 	 
  126. 	--hide the images until we have dealyed time 
  127. 	local images_h = vint_object_find("images", 0, City_load_doc_handle) 
  128. 	vint_set_property(images_h, "visible", false) 
  129. 	 
  130. 	lua_play_anim(wait_anim_h, 0, City_load_doc_handle) 
  131. 	 
  132. 	-- Tell C code that images are done loading 
  133. 	city_load_img_load_complete() 
  134. end 
  135.  
  136. function city_load_show_images() 
  137. 	local images_h = vint_object_find("images", 0, City_load_doc_handle) 
  138. 	vint_set_property(images_h, "visible", true) 
  139. 	lua_play_anim(City_load_data.handles.transition2_h, 0, City_load_doc_handle) 
  140. end 
  141.  
  142. function city_load_hide_images() 
  143. 	local images_h = vint_object_find("images", 0, City_load_doc_handle) 
  144. 	vint_set_property(images_h, "visible", false) 
  145. 	for i, v in pairs(City_load_current_images) do 
  146. 		game_peg_unload(v) 
  147. 	end	 
  148. end 
  149.  
  150. function city_load_transition() 
  151. 	vint_set_property(City_load_data.handles.bmp1_h, "alpha", 1) 
  152. 	vint_set_property(City_load_data.handles.bmp2_h, "alpha", 1) 
  153. 	vint_set_property(City_load_data.handles.bmp3_h, "alpha", 1) 
  154. 	debug_print("vint", "city_load_transition, end of anim reached, looping now \n") 
  155. 	lua_play_anim(City_load_data.handles.transition2_h, 0, City_load_doc_handle) 
  156. end 
  157.  
  158. function city_load_cleanup() 
  159. 	 for i, v in pairs(City_load_current_images) do 
  160. 		 game_peg_unload(v) 
  161. 	 end 
  162. end 
  163.