./store_crib_cash.lua

  1. --[[ 
  2. CRIB_CASH_TRANSFER_FROM_BANK 
  3. CRIB_CASH_PLAYER_CASH 
  4. CRIB_CASH_INCOME						==INCOME PER DAY 
  5. CRIB_CASH_TRANSFER_CAP				==TRANSFER CAP 
  6. CRIB_CASH_READY						==Ready 
  7. CRIB_CASH_TRANSFER					==Transfering 
  8. CRIB_CASH_TRANSFER_COMPLETE		==TRANSFER COMPLETE 
  9. CRIB_CASH_DO_TRANSFER				==TRANSFER 
  10. CRIB_CASH_DO_CONTINUE				==CONTINUE 
  11. ]] 
  12. --Globals... 
  13. local Hint_bar 
  14. local Input_tracker 
  15. local Crib_cash_mouse_input_tracker 
  16.  
  17. local Crib_cash_data = {} 
  18.  
  19.  
  20. local CRIB_CASH_SUCCESS	= 0 
  21. local CRIB_CASH_WARNING = 1 
  22. --Screen states... 
  23. local CRIB_CASH_SCREEN_STATE_PRE_TRANSFER 	= 0 
  24. local CRIB_CASH_SCREEN_STATE_TRANSFERING	 	= 1  
  25. local CRIB_CASH_SCREEN_STATE_POST_TRANSFER 	= 2 
  26.  
  27. local CRIB_CASH_COLOR_PRIMARY = {R=16/255, G=102/255, B=148/255} 
  28.  
  29. local Crib_cash_screen_state = CRIB_CASH_SCREEN_STATE_PRE_TRANSFER		 --Set current screen state... 
  30.  
  31. function store_crib_cash_init() 
  32.  
  33. 	local screen_grp_h = vint_object_find("screen_grp") 
  34. 	vint_set_property(screen_grp_h, "alpha", 0) 
  35. 	 
  36. 	--Populate hint bar... 
  37. 	local hints = { {CTRL_MENU_BUTTON_A, "CRIB_CASH_DO_TRANSFER"}} 
  38. 	Hint_bar = Vdo_hint_bar:new("hint_bar") 
  39. 	Hint_bar:set_hints(hints) 
  40. 	Hint_bar:set_visible(false) 
  41.  
  42. 	Input_tracker = Vdo_input_tracker:new() 
  43. 	Input_tracker:add_input("select", "store_crib_input", 50) 
  44. 	Input_tracker:add_input("map", "store_crib_input", 50) 
  45. 	Input_tracker:add_input("back", "store_crib_input", 50) 
  46. 	Input_tracker:add_input("all_unassigned", "store_crib_input", 50) 
  47. 	Input_tracker:subscribe(true) 
  48. 	 
  49. 	-- Initialize mouse inputs 
  50. 	if game_get_platform() == "PC" then 
  51. 		Crib_cash_mouse_input_tracker = Vdo_input_tracker:new() 
  52. 		Hint_bar:add_mouse_inputs("store_crib_cash", Crib_cash_mouse_input_tracker) 
  53. 		Crib_cash_mouse_input_tracker:subscribe(true) 
  54. 	end 
  55. 	 
  56. 	--Fake populate... (should be done with dataresponder) ... 
  57. 	--store_crib_cash_populate(5000,50000,1500,5000) 
  58. 	vint_dataresponder_request("store_crib_cash_request_data", "store_crib_cash_populate", 0) 
  59. 	 
  60. 	local cell_complete_h = vint_object_find("cell_complete_grp") 
  61. 	vint_set_property(cell_complete_h, "alpha", 0) 
  62. 	 
  63. 	local transfer_h 					= vint_object_find("transfer_cash") 
  64. 	vint_set_property(transfer_h, "visible", false) 
  65. 	 
  66. 	--transfer_h 					= vint_object_find("transfer_bank") 
  67. 	--vint_set_property(transfer_h, "visible", false) 
  68.  
  69. 	local trans_in_event_tween = vint_object_find("cell_fade_wait") 
  70. 	if Crib_cash_data.cash_from_bank <= 0 then 
  71. 		vint_set_property(trans_in_event_tween,"end_event","store_crib_cash_popup") 
  72. 	else 
  73. 		vint_set_property(trans_in_event_tween,"end_event","store_crib_cash_cb") 
  74. 	end 
  75. 	 
  76. 	cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_CASH, CELL_SCREEN_MAIN, store_crib_cash_nothing) 
  77. end 
  78.  
  79.  
  80. function store_crib_cash_nothing() 
  81. end 
  82.  
  83.  
  84. function store_crib_cash_cleanup() 
  85. end 
  86.  
  87. function store_crib_cash_cb(tween_h) 
  88. 	vint_object_destroy(vint_object_parent(tween_h)) 
  89. 	 
  90. 	--Do transfer... 
  91. 	crib_get_cash_stash() -- C function call 
  92. 	thread_new("store_crib_cash_transfer") 
  93. 	 
  94. end 
  95.  
  96. function store_crib_cash_popup( popup_type ) 
  97. 	local popup_title_h = vint_object_find("popup_title") 
  98. 	local popup_text_h = vint_object_find("popup_text") 
  99. 	local popup_grp_h = vint_object_find("popup_grp") 
  100. 	local success_grp_h = vint_object_find("success_grp") 
  101. 	local popup_background_h = vint_object_find("popup_background") 
  102. 	 
  103. 	if popup_type == CRIB_CASH_SUCCESS then 
  104. 		vint_set_property(success_grp_h, "visible", true) 
  105. 		vint_set_property(popup_background_h, "visible", false) 
  106. 		vint_set_property(popup_grp_h, "visible", false) 
  107. 	else 
  108. 		vint_set_property(popup_grp_h, "visible", true) 
  109. 		vint_set_property(success_grp_h, "visible", false) 
  110. 		vint_set_property(popup_title_h, "text_tag", "MENU_TITLE_WARNING") 
  111. 		vint_set_property(popup_text_h, "text_tag", "MENU_ACCOUNT_EMPTY") 
  112. 		game_UI_audio_play("UI_HUD_Help") 
  113. 	end 
  114. 	 
  115. 	local popup_fill_h = vint_object_find("popup_fill") 
  116. 	local popup_border_h = vint_object_find("popup_border") 
  117. 	local text_w,text_h = vint_get_property(popup_text_h, "screen_size") 
  118. 	local popup_fill_w,crap = vint_get_property(popup_fill_h, "screen_size") 
  119. 	local popup_border_w,crap = vint_get_property(popup_border_h, "screen_size") 
  120. 	 
  121. 	vint_set_property(popup_fill_h, "screen_size", popup_fill_w, text_h + 20) 
  122. 	vint_set_property(popup_border_h, "screen_size", popup_border_w, text_h + 59) 
  123. 	 
  124. 	--Populate hint bar... 
  125. 	local hints = { {CTRL_MENU_BUTTON_A, "PAUSE_MENU_ACCEPT"}} 
  126. 	Hint_bar = Vdo_hint_bar:new("hint_bar") 
  127. 	Hint_bar:set_hints(hints) 
  128. 	Hint_bar:set_visible(true) 
  129. 		 
  130. 	local popup_anim_h = vint_object_find("popup_anim") 
  131. 	lua_play_anim(popup_anim_h, 0) 
  132. 	 
  133. 	Crib_cash_screen_state = CRIB_CASH_SCREEN_STATE_POST_TRANSFER 
  134. end 
  135.  
  136. ------------------------------------------------------------------------------- 
  137. -- Called by C++ via data responder 
  138. -- 
  139. -- cash_from_bank		how much the bank is paying the player 
  140. -- player_cash			how much cash the player has before withdrawl 
  141. --	daily_cash			how much cash the player earns per day... 
  142. -- transfer_cap		How much cash the bank can max out on. 
  143. ------------------------------------------------------------------------------- 
  144. function store_crib_cash_populate(cash_from_bank, player_cash, daily_cash, transfer_cap)	 
  145. 	local bank_val_txt_h 			= vint_object_find("bank_val_txt") 
  146. 	local player_cash_val_txt_h 	= vint_object_find("player_cash_val_txt") 
  147. 	local perday_val_txt_h 			= vint_object_find("perday_val_txt") 
  148. 	local transfer_cap_val_txt_h 	= vint_object_find("transfer_cap_val_txt") 
  149. 	 
  150. 	vint_set_property(bank_val_txt_h, "text_tag", "$" .. format_cash(cash_from_bank)) 
  151. 	vint_set_property(player_cash_val_txt_h, "text_tag", "$" .. format_cash(player_cash)) 
  152. 	vint_set_property(perday_val_txt_h, "text_tag", "$" .. format_cash(daily_cash)) 
  153. 	vint_set_property(transfer_cap_val_txt_h, "text_tag", "$" .. format_cash(transfer_cap)) 
  154. 	 
  155. 	local transfer_h = vint_object_find("transfer_bank") 
  156. 	if cash_from_bank > 0 then 
  157. 		vint_set_property(transfer_h, "visible", true) 
  158. 	else	 
  159. 		vint_set_property(transfer_h, "visible", false) 
  160. 	end 
  161. 	 
  162. 	--Store off to process later... 
  163. 	Crib_cash_data = { 
  164. 		cash_from_bank	= cash_from_bank, 
  165. 		player_cash = player_cash,  
  166. 		daily_cash = daily_cash,   
  167. 		transfer_cap = transfer_cap, 
  168. 	} 
  169. end 
  170.  
  171. ------------------------------------------------------------------------------- 
  172. -- Process input 
  173. ------------------------------------------------------------------------------- 
  174. function store_crib_input(event) 
  175. 	if event == "back" or event == "select" or event == "map" then 
  176. 		if Crib_cash_screen_state == CRIB_CASH_SCREEN_STATE_POST_TRANSFER then 
  177. 			Input_tracker:subscribe(false) 
  178. 			Crib_cash_mouse_input_tracker:subscribe(false) 
  179. 			store_crib_cash_exit() 
  180. 		end 
  181. 	end 
  182. end 
  183.  
  184.  
  185. function store_crib_cash_exit() 
  186. 	cell_transition_screen(CELL_STATE_PORTRAIT,  CELL_SCREEN_MAIN, CELL_SCREEN_CASH, store_crib_cash_exit_final) 
  187. end 
  188.  
  189. function store_crib_cash_exit_final() 
  190. 	pop_screen() 
  191. end 
  192.  
  193. ------------------------------------------------------------------------------- 
  194. -- Cash transfer action... 
  195. ------------------------------------------------------------------------------- 
  196. function store_crib_cash_transfer() 
  197. 	Crib_cash_screen_state = CRIB_CASH_SCREEN_STATE_TRANSFERING 
  198. 	 
  199. 	--init stuff 
  200. 	local start_cash = 0 									-- $ amount to start cash from... 
  201. 	local cash_end = Crib_cash_data.cash_from_bank 	-- $ amount to end cash on... 
  202. 	local cash_this_frame = -1								-- How much cash gets displayed in the current frame...	 
  203. 	local bank_cash_this_frame	= -1						--	 
  204. 	local pct_this_frame	 = -1								-- How much cash gets displayed in the current frame...	 
  205. 	local is_complete = false								-- Is the screen complete? 
  206.  
  207. 	--local amt_min = 100 
  208. 	--local amt_max = 20000 
  209.  
  210. 	local time_max = 1200 
  211. 	local init_time = floor(vint_get_time_index() * 1000) 
  212. 	local cur_time = init_time 
  213. 	local time_to_count = time_max 
  214.  
  215. 	local bank_val_txt_h 			= vint_object_find("bank_val_txt") 
  216. 	local player_cash_val_txt_h 	= vint_object_find("player_cash_val_txt") 
  217. 	local transfer_bank_h 					= vint_object_find("transfer_bank") 
  218. 	local transfer_cash_h 					= vint_object_find("transfer_cash") 
  219. 	local transfer_scale_x, transfer_scale_y = vint_get_property(transfer_cash_h, "scale") 
  220. 	vint_set_property(transfer_cash_h, "visible", true) 
  221. 	vint_set_property(transfer_bank_h, "visible", true) 
  222. 	 
  223. 	game_UI_audio_play("UI_Cell_Cash_Transfer") 
  224. 	Hint_bar:set_visible(false) 
  225. 	 
  226. 	if cash_end > 0 then 
  227. 		 
  228. 		while is_complete == false do 
  229. 		 
  230. 			local cur_time = floor(vint_get_time_index() * 1000) - init_time 
  231. 							 
  232. 			--set my values 
  233. 			pct_this_frame	= (cur_time / time_to_count) 
  234. 			cash_this_frame = cash_end * pct_this_frame 
  235. 			bank_cash_this_frame = cash_end - cash_this_frame 
  236. 			 
  237. 			if cur_time >= time_to_count then 
  238. 				--force the values to end 
  239. 				vint_set_property(player_cash_val_txt_h, "text_tag", "$" .. format_cash(cash_end + Crib_cash_data.player_cash )) 
  240. 				vint_set_property(bank_val_txt_h, "text_tag", "$" .. "0") 
  241. 				vint_set_property(transfer_cash_h, "scale", transfer_scale_x, transfer_scale_y ) 
  242. 				vint_set_property(transfer_bank_h, "scale", 0, transfer_scale_y ) 
  243. 				 
  244. 				--End Loop 
  245. 				is_complete = true 
  246. 			else 
  247. 				 
  248. 				vint_set_property(player_cash_val_txt_h, "text_tag", "$" .. format_cash(cash_this_frame + Crib_cash_data.player_cash)) 
  249. 				vint_set_property(bank_val_txt_h, "text_tag", "$" .. format_cash(bank_cash_this_frame)) 
  250. 				vint_set_property(transfer_cash_h, "scale", transfer_scale_x * pct_this_frame, transfer_scale_y ) 
  251. 				vint_set_property(transfer_bank_h, "scale", transfer_scale_x * (1 - pct_this_frame), transfer_scale_y ) 
  252. 		 
  253. 			end 
  254. 			thread_yield() 
  255. 			 
  256. 			store_crib_cash_popup(CRIB_CASH_SUCCESS) 
  257. 				 
  258. 		end 
  259. 		 
  260. 	end 
  261. 	 
  262. 	Crib_cash_screen_state = CRIB_CASH_SCREEN_STATE_POST_TRANSFER 
  263. end 
  264.  
  265.  
  266. -- ===================================== 
  267. --       Mouse Specific Functions 
  268. -- ===================================== 
  269.  
  270. function store_crib_cash_mouse_click(event, target_handle) 
  271. 	-- Check if the user clicked on the hint bar button 
  272. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  273. 	if hint_index ~= 0 then 
  274. 		store_crib_input("select") 
  275. 	end 
  276. end 
  277.  
  278. function store_crib_cash_mouse_move(event, target_handle) 
  279. 	-- Reset all highlights 
  280. 	Hint_bar:set_highlight(0) 
  281. 	 
  282. 	-- Check if the mouse is over the hint bar buttons 
  283. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  284. 	if hint_index ~= 0 then 
  285. 		Hint_bar:set_highlight(hint_index, CRIB_CASH_COLOR_PRIMARY) 
  286. 		return 
  287. 	end 
  288. end