./building_purchase.lua

  1.  
  2.  
  3. local Building_purchase_subs 		= { } 
  4. local Building_purchasing_data 	= { } 
  5. local Menu_sound_confirm			= game_audio_get_audio_id("SYS_HUD_CONF_SERIOUS")	-- Confirmation/warning dialog opens 
  6. local Building_purchase_sound 	= game_audio_get_audio_id("SYS_MENU_BUY_BUILDING") 
  7.  
  8. local Mouse_input_tracker 
  9. local Bg_mask 
  10.  
  11. local Input_tracker = {} 
  12.  
  13. local City_control_meter = -1 
  14.  
  15. function building_purchase_init() 
  16. 	 
  17. 	--Find and hide objects until we need them... 
  18. 	vint_set_property(vint_object_find("ctrl_info_grp"), "visible", false) 
  19. 	vint_set_property(vint_object_find("guns"), "visible", false) 
  20. 	vint_set_property(vint_object_find("main"), "visible", false) 
  21. 	 
  22. 	Input_tracker = Vdo_input_tracker:new() 
  23. 	Input_tracker:add_input("pause", "building_purchase_pause", 50) 
  24. 	 
  25. 	bg_saints_show(false) 
  26.  
  27. 	--Initialize VDO for district control. 
  28. 	City_control_meter = Vdo_city_control:new("control_meter") 
  29. 	 
  30. 	Building_purchase_subs[0] = vint_subscribe_to_input_event("all_unassigned",	"bp_nothing") 
  31. 	 
  32. 	vint_dataresponder_request("shop_purchase_get_shop_info", "update_building_purchase_text", 0) 
  33. 	 
  34. 	--Set bg saints screen type... 
  35. 	bg_saints_set_type(BG_TYPE_COMPLETION) 
  36. 	 
  37. 	if game_get_platform() == "PC" then 
  38. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  39. 		local doc_handle = vint_document_find("building_purchase") 
  40. 		Bg_mask = Vdo_base_object:new("bg_clickable", 0, doc_handle) 
  41. 		Mouse_input_tracker:add_mouse_input("mouse_move", "building_purchase_mouse_move", 0, Bg_mask.handle) 
  42. 		Mouse_input_tracker:add_mouse_input("mouse_click", "building_purchase_mouse_click", 0, Bg_mask.handle) 
  43. 		Mouse_input_tracker:subscribe(false) 
  44. 	end 
  45. end 
  46.  
  47. function building_purchase_pause(event) 
  48. 	dialog_open_pause_display() 
  49. end 
  50.  
  51. function building_purchase_clean() 
  52. 	game_UI_audio_play("UI_Main_Menu_Select") 
  53. 	 
  54. 	--Autosave after building purchase... 
  55. 	game_autosave() 
  56. 	 
  57. 	pop_screen() 
  58. end 
  59.  
  60. function building_not_enough_money() 
  61. 	pop_screen() 
  62. end 
  63.  
  64. function building_purchase_cleanup() 
  65. 	for index, value in pairs(Building_purchase_subs) do 
  66. 		vint_unsubscribe_to_input_event(value) 
  67. 	end 
  68. 	 
  69. -- DAD - 8/12/11 - Clean up is called from vint_doc destroy... we don't want to pop extra screens. 
  70. --	pop_screen() 
  71. end 
  72.  
  73. -- Percentages should be sent in as numbers between 0 and 100, cause we'll floor them an print as text 
  74. function update_building_purchase_text(building_name, description_txt, store_cost, player_cash, profit, control_pct, control_pct_new, control_pct_increase, district, discount, is_store) 
  75. 	Building_purchasing_data.name = building_name 
  76. 	Building_purchasing_data.description_txt = description_txt 
  77. 	Building_purchasing_data.store_cost = store_cost 
  78. 	Building_purchasing_data.player_cash = player_cash 
  79. 	Building_purchasing_data.control_pct = control_pct 
  80. 	Building_purchasing_data.control_pct_new = control_pct_new 
  81. 	Building_purchasing_data.control_pct_increase = control_pct_increase 
  82. 	Building_purchasing_data.control_district = district 
  83. 	Building_purchasing_data.discount = discount 
  84. 	Building_purchasing_data.is_store = is_store 
  85. 	Building_purchasing_data.profit = profit 
  86. 	 
  87. 	--Set control Percentage to start with...  
  88. 	if Building_purchasing_data.control_pct == nil then 
  89. 		Building_purchasing_data.control_pct = 0 
  90. 		debug_print("vint", "warning: no control percentage assigned to this property/building\n") 
  91. 	end 
  92. 	 
  93. 	if Building_purchasing_data.control_pct_new == nil then 
  94. 		Building_purchasing_data.control_pct_new = 0 
  95. 		debug_print("vint", "warning: no control percentage assigned to this property/building\n") 
  96. 	end 
  97. 	 
  98. 	if Building_purchasing_data.profit == nil then 
  99. 		Building_purchasing_data.profit = 10 
  100. 		debug_print("vint", "warning: no profit assigned to this property/building\n") 
  101. 	end 
  102. 	 
  103. 	if Building_purchasing_data.control_district == nil then 
  104. 		Building_purchasing_data.control_district = "EMPTY DISTRICT NAME" 
  105. 		debug_print("vint", "warning: no district name assigned to this property/building\n") 
  106. 	end 
  107. 	 
  108. 	if Building_purchasing_data.discount == nil then 
  109. 		Building_purchasing_data.discount = 10 
  110. 		debug_print("vint", "warning: no profit assigned to this property/building\n") 
  111. 	end		 
  112. 	 
  113. 	if player_cash < store_cost then 
  114. 		-- Show Dialog that says you can't afford it. 
  115. 		local header = "MENU_TITLE_NOTICE" 
  116. 		local body = "HUD_SHOP_INSUFFICIENT_FUNDS" 
  117.  
  118. 		dialog_box_message(header, body, nil, nil, "building_not_enough_money") 
  119. 	else 
  120. 		--	Ask player if they really want to purchase it. 
  121. 		local header = "MENU_TITLE_CONFIRM" 
  122. 		local body 
  123. 		local insert_values = { [0] = building_name, [1] = format_cash(store_cost) } 
  124. 		body = vint_insert_values_in_string("BUILDING_PURCHASE_BUILDING", insert_values) 
  125. 		dialog_box_confirmation(header, body, "building_purchased") 
  126. 	end 
  127. end 
  128.  
  129. function building_purchased(result, action)	 
  130. 	if result == 0 then 
  131. 	 
  132. 		--Set Text Items and Prepare animations... Starts from top of the screen to bottom... GO!!! 
  133. 	 
  134. 		--Store Title 
  135. 		local store_title_txt_h = vint_object_find("store_title_txt") 
  136. 		vint_set_property(store_title_txt_h, "text_tag_crc", Building_purchasing_data.name) 
  137. 				 
  138. 		--Resize long strings to fit 
  139. 		vint_set_property(store_title_txt_h, "scale", 1, 1) 
  140. 		local max_width = 442 
  141. 		local text_width, text_height = element_get_actual_size(store_title_txt_h) 
  142. 		 
  143. 		if text_width >= max_width then 
  144. 			local text_scale = max_width/text_width 
  145. 			vint_set_property(store_title_txt_h, "scale", text_scale, 1) 
  146. 		end 
  147.  
  148. 		--Set control Percentage to start with...  
  149. 		City_control_meter:update(0.01 * Building_purchasing_data.control_pct, false) 
  150. 		 
  151. 		--Set callback to play control up during the animation... 
  152. 		local control_meter_twn_end_h = vint_object_find("control_meter_end_twn") 
  153. 		vint_set_property(control_meter_twn_end_h, "end_event", "building_purchase_control_anim") 
  154. 		 
  155. 		--Set text using values/tag cool guy stuff... 
  156. 		local values, tag 
  157. 		 
  158. 		--Control Increase... 
  159. 		local control_increase_txt_h = vint_object_find("control_increase_txt") 
  160. 		local new_pct = Building_purchasing_data.control_pct_increase 
  161. 		values = { [0] = floor(new_pct + 0.5)} 
  162. 		tag = vint_insert_values_in_string("BUILDING_PURCHASE_CONTROL_INCREASE", values)			--LOCALIZE EXAMPLE: "10% CONTROL INCREASE" 
  163. 		vint_set_property(control_increase_txt_h, "text_tag", tag) 
  164. 		 
  165. 		--Hoods taken over... 
  166. 		local control_increase_gang_txt_h = vint_object_find("control_increase_gang_txt") 
  167. 		--values = { [0] = Building_purchasing_data.control_district} 
  168. 		--tag = vint_insert_values_in_string("{0} DISTRICT", values)			--LOCALIZE EXAMPLE: "DECKERS DISTRICT" 
  169. 		vint_set_property(control_increase_gang_txt_h, "text_tag", Building_purchasing_data.control_district ) 
  170. 		 
  171. 		--Cash Earned /Day 
  172. 		local cash_txt_h = vint_object_find("cash_day_text") 
  173. 		values = { [0] = format_cash(Building_purchasing_data.profit)} 
  174. 		tag = vint_insert_values_in_string("BUILDING_PURCHASE_CASH_PER_HOUR", values)					--LOCALIZE EXAMPLE: "$3,000 PER HOUR" 
  175. 		vint_set_property(cash_txt_h, "text_tag", tag) 
  176. 		 
  177. 		--Discount Earned /Day 
  178. 		local discount_text_h = vint_object_find("discount_text") 
  179. 		values = { [0] = floor(Building_purchasing_data.discount + 0.5)} 
  180. 		tag = vint_insert_values_in_string("BUILDING_PURCHASE_DISCOUNT", values)			--LOCALIZE EXAMPLE: "10% DISCOUNT" 
  181. 		vint_set_property(discount_text_h, "text_tag", tag) 
  182. 		 
  183. 		--Set button on the interface 
  184. 		local button = Vdo_hint_button:new("ctrl_btn") 
  185. 		button:set_button(CTRL_MENU_BUTTON_A)	 
  186. 		 
  187. 		local button_highlight_h = vint_object_find("ctrl_btn_highlight") 
  188. 		vint_set_property(button_highlight_h, "image", CTRL_MENU_BUTTON_A) 
  189. 		if game_is_active_input_gamepad() == false then 
  190. 			vint_set_property(button.handle, "visible", false) 
  191. 			vint_set_property(button_highlight_h, "visible", false) 
  192. 		end 
  193.  
  194. 		--Show Base Items... 
  195. 		vint_set_property(vint_object_find("ctrl_info_grp"), "visible", true) 
  196. 		vint_set_property(vint_object_find("guns"), "visible", true) 
  197. 		vint_set_property(vint_object_find("main"), "visible", true) 
  198. 		 
  199. 		--Play all animations in... 
  200. 		local twn_h = vint_object_find("purchase_anchor_twn") 
  201. 		vint_set_property(twn_h, "start_event", "building_purchase_play_audio") 
  202. 		 
  203. 		bg_saints_animate() 
  204. 		lua_play_anim(vint_object_find("text_anim")) 
  205. 		 
  206. 		--vint_set_property(vint_object_find("left_shadow"),"visible",true) 
  207. 		--vint_set_property(vint_object_find("right_shadow"),"visible",true) 
  208. 		 
  209. 		bg_saints_show(true) 
  210. 		 
  211. 		shop_purchase_purchase_shop() 
  212. 		 
  213. 		Building_purchase_subs[1] = vint_subscribe_to_input_event("select", "building_purchase_clean")	 
  214. 		if Mouse_input_tracker ~= nil then 
  215. 			Mouse_input_tracker:subscribe(true)		 
  216. 		end 
  217. 	else 
  218. 		pop_screen() 
  219. 	end 
  220. end 
  221.  
  222. function building_purchase_play_audio() 
  223. 	game_UI_audio_play("UI_Buy_Building_Screen") 
  224. end 
  225.  
  226. --Animates in the city control... this is for a  callback from a tween 
  227. function building_purchase_control_anim(tween_h, event) 
  228. 	City_control_meter:update(0.01 * Building_purchasing_data.control_pct_new, true) 
  229. end 
  230.  
  231. function building_purchase_mouse_click(event, target_handle) 
  232. 	building_purchase_clean() 
  233. end 
  234.  
  235. function building_purchase_mouse_move(event, target_handle) 
  236. end 
  237.  
  238.