./vint_bugs.lua

  1. R_meter = 0 
  2. local Respect_level 	= 0 
  3. local Respect_pct 	= 0 
  4. local Respect_total 	= 0  
  5. local RESPECT_PER_LEVEL = 7000 
  6.  
  7. local Input_tracker 
  8. Bugs_mouse_Input_tracker = -1 
  9.  
  10.  
  11. local LIST_SIZE = 400 
  12. local LIST_ITEMS = 10 
  13. local LIST_SCALE = .8 
  14. Bugs_megalist = {} 
  15. List_data = {} 
  16.  
  17. function vint_bugs_init() 
  18. 	local doc_h = vint_document_find("vint_bugs") 
  19. 	debug_print("vint", "doc_h" .. doc_h .. "\n") 
  20. 	R_meter = Vdo_respect_meter:new("r_object", 0, 0, "vint_bugs.lua", "R_meter") 
  21. 	Respect_level = 0 
  22. 	Respect_pct = 0 
  23. 	Respect_total = 0  
  24. 	r_update_respect() 
  25. 	 
  26. 	for i = 1, 20 do 
  27. 		List_data[i] = {id = i, 	type = TYPE_BUTTON, label = "MENU ITEM " .. i, is_new = true} 
  28. 	end 
  29. 	 
  30. 	Bugs_megalist = Vdo_mega_list:new("bugs_megalist", 0, doc_h) 
  31. 	Bugs_megalist:set_highlight_color(COLOR_CHEATS_PRIMARY, COLOR_CHEATS_SECONDARY)	 
  32. 	Bugs_megalist:draw_items(List_data, 1, LIST_SIZE, LIST_ITEMS, .9, false) 
  33.  
  34. 	Input_tracker =  Vdo_input_tracker:new() 
  35. 	Input_tracker:add_input("select", "r_add_respect", 50) 
  36. 	Input_tracker:add_input("back", "r_remove_respect", 50) 
  37. 	Input_tracker:add_input("nav_up", "megalist_nav_up", 50) 
  38. 	Input_tracker:add_input("nav_down", "megalist_nav_down", 50) 
  39. 	Input_tracker:add_input("alt_select", "r_add_respect_double", 50) 
  40. 	Input_tracker:add_input("exit", "r_remove_respect_double", 50) 
  41. 	Input_tracker:subscribe(true) 
  42. 	 
  43. 	if game_get_platform() == "PC" then 
  44. 		Bugs_mouse_Input_tracker = Vdo_input_tracker:new() 
  45. 		Bugs_megalist:add_mouse_inputs("vint_bugs", Bugs_mouse_Input_tracker) 
  46. 		Bugs_mouse_Input_tracker:subscribe(true) 
  47. 		debug_print("vint", "HELLO: " .. var_to_string(Bugs_mouse_Input_tracker) .. "\n") 
  48. 	end 
  49. 	 
  50. 	local text_grp_1_h = vint_object_find("text_grp_1") 
  51. 	local text_1_h = vint_object_find("text_1_txt", text_grp_1_h) 
  52. 	local text_1_bg_h = vint_object_find("text_1_bg") 
  53. 	local width, height = element_get_actual_size(text_1_h) 
  54. 	element_set_actual_size(text_1_bg_h, width, height) 
  55. 	 
  56. 	local text_grp_2_h = vint_object_find("text_grp_2") 
  57. 	local text_2_h = vint_object_find("text_2_txt", text_grp_2_h) 
  58. 	local text_2_bg_h = vint_object_find("text_2_bg") 
  59. 	local width, height = element_get_actual_size(text_2_h) 
  60. 	element_set_actual_size(text_2_bg_h, width, height) 
  61. 	 
  62. 	local text_grp_3_h = vint_object_find("text_grp_3") 
  63. 	local text_3_h = vint_object_find("text_3_txt", text_grp_3_h) 
  64. 	local text_3_bg_h = vint_object_find("text_3_bg") 
  65. 	local width, height = element_get_actual_size(text_3_h) 
  66. 	element_set_actual_size(text_3_bg_h, width, height) 
  67. end 
  68. function vint_bugs_cleanup() 
  69. 	Input_tracker:subscribe(false) 
  70. end 
  71.  
  72.  
  73. ------------------------------------------------------------------------------- 
  74. -- Mouse Inputs 
  75. --  
  76. function vint_bugs_mouse_click(event, target_handle) 
  77. 	-- If the target_handle matches a button, activate it 
  78. 	local new_index = Bugs_megalist:get_button_index(target_handle) 
  79. 	if new_index ~= 0 then 
  80. 		-- Enter an option if the target_handle is in the List 
  81. 		Bugs_megalist:set_selection(new_index) 
  82. 		--Click event? 
  83. 	end 
  84. end 
  85.  
  86. function vint_bugs_mouse_move(event, target_handle) 
  87. 	local new_index = Bugs_megalist:get_button_index(target_handle) 
  88. 	if new_index ~= 0 then 
  89. 		-- Set the button as the new selected highlight 
  90. 		Bugs_megalist:set_selection(new_index) 
  91.  
  92. 		local current_data = Bugs_megalist:return_selected_data() 
  93.  
  94. 		debug_print("vint", "new_index:"	.. new_index .. "\n") 
  95. 		Bugs_megalist:move_cursor(0, true) 
  96. 		if current_data.is_new then 
  97. 			Bugs_mouse_Input_tracker:remove_all() 
  98. 			Bugs_megalist:remove_new_flag(new_index) 
  99. 			Bugs_megalist:move_cursor(0, true) 
  100. 			 
  101. 			--Re add inputs... 
  102. 			if game_get_platform() == "PC" then 
  103. 				Bugs_mouse_Input_tracker:remove_all() 
  104. 				Bugs_megalist:add_mouse_inputs("vint_bugs", Bugs_mouse_Input_tracker) 
  105. 				Bugs_mouse_Input_tracker:subscribe(true) 
  106. 			end 
  107. 			 
  108. 			 
  109. 		end 
  110. 		 
  111.  
  112. 	end	 
  113. end 
  114.  
  115. function vint_bugs_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines) 
  116. 	if scroll_lines ~= 0 then 
  117. 		if Bugs_megalist:get_scroll_region_handle() == target_handle then 
  118. 			Bugs_megalist:scroll_list(scroll_lines * -1) 
  119. 			Bugs_megalist:update_mouse_inputs("vint_bugs", Bugs_mouse_Input_tracker) 
  120. 		end 
  121. 	end 
  122. end 
  123.  
  124. function vint_bugs_mouse_drag(event, target_handle, mouse_x, mouse_y) 
  125. 	if Bugs_megalist.scrollbar.tab.handle == target_handle then 
  126. 		local new_start_index = Bugs_megalist.scrollbar:drag_scrolltab(mouse_y, Bugs_megalist.num_buttons - (Bugs_megalist.max_buttons - 1)) 
  127. 		Bugs_megalist:scroll_list(0, new_start_index) 
  128. 	end 
  129. end 
  130.  
  131. function vint_bugs_mouse_drag_release(event, target_handle, mouse_x, mouse_y) 
  132. 	if Bugs_megalist.scrollbar.tab.handle == target_handle then 
  133. 		local start_index = Bugs_megalist:get_visible_indices() 
  134. 		Bugs_megalist.scrollbar:release_scrolltab(start_index, Bugs_megalist.num_buttons - (Bugs_megalist.max_buttons - 1)) 
  135. 		Bugs_megalist:update_mouse_inputs("vint_bugs", Bugs_mouse_Input_tracker) 
  136. 	end 
  137. end 
  138.  
  139.  
  140. function r_update_respect() 
  141. 	 
  142. 	R_meter:update_respect(Respect_total, Respect_pct, Respect_level, Show_upgrade) 
  143. 	debug_print("vint", "Respect_total: " .. var_to_string(Respect_total) .. "\n") 
  144. 	debug_print("vint", "Respect_pct: " .. var_to_string(Respect_pct) .. "\n") 
  145. 	debug_print("vint", "Respect_level: " .. var_to_string(Respect_level) .. "\n") 
  146. 	debug_print("vint", "SHOW UPGRADE: " .. var_to_string(Show_upgrade) .. "\n") 
  147. end 
  148.  
  149.  
  150. Show_upgrade = false 
  151. Show_upgrade_thread = 0 
  152.  
  153. function show_upgrade_func() 
  154. 	thread_yield(3) 
  155. 	Show_upgrade = false 
  156. 	R_meter:game_is_finished_showing_upgrades() 
  157. 	r_update_respect() 
  158. 	Show_upgrade_thread = 0 
  159. end 
  160.  
  161. function respect_total_update(respect) 
  162. 	Respect_total = Respect_total + respect 
  163. 	 
  164. 	if Respect_total > 400000 or Respect_total < 0 then 
  165. 		Respect_total = 1 
  166. 		debug_print("vint", "RELOAD DOC!! reset\n") 
  167. 	end 
  168. 	local current_level = Respect_level 
  169. 	 
  170. 	Respect_level = floor(Respect_total / RESPECT_PER_LEVEL) 
  171. 	 
  172.  
  173. 	if current_level < Respect_level then 
  174. 		if Show_upgrade_thread == 0 then 
  175. 			Show_upgrade = true 
  176. 			Show_upgrade_thread = thread_new("show_upgrade_func") 
  177. 		end 
  178. 	end 
  179.  
  180. 	Respect_pct = (Respect_total % RESPECT_PER_LEVEL) / RESPECT_PER_LEVEL 
  181. end 
  182.  
  183.  
  184. function r_add_respect()  
  185. 	respect_total_update(1000) 
  186. 	r_update_respect() 
  187. end 
  188. function r_add_respect_double()  
  189. 	respect_total_update(4000) 
  190. 	r_update_respect() 
  191. end 
  192.  
  193. function r_remove_respect() 
  194. 	respect_total_update(-1000) 
  195. 	r_update_respect() 
  196. end 
  197. function r_remove_respect_double() 
  198. 	respect_total_update(-4000) 
  199. 	r_update_respect() 
  200. end 
  201.  
  202. function megalist_nav_up() 
  203. 	Bugs_megalist:move_cursor(-1) 
  204. end 
  205. function megalist_nav_down() 
  206. 	Bugs_megalist:move_cursor(1) 
  207. end 
  208.  
  209. function test_numbers() 
  210. 	local text_field_h = vint_object_find("text_field") 
  211. 	for i = 1000, 2000 do 
  212. 		vint_set_property(text_field_h, "text_tag", i) 
  213. 		thread_yield() 
  214. 	end 
  215. end 
  216.  
  217. function test_numbers_commas() 
  218. 	local text_field_h = vint_object_find("text_field") 
  219. 	 
  220. 	local do_test = true 
  221. 	local value = 0 
  222. 	while do_test do 
  223. 		value = value + rand_int(60,99) 
  224. 		local formated_value = format_cash(value) 
  225. 		vint_set_property(text_field_h, "text_tag", formated_value) 
  226. 		thread_yield() 
  227. 		if value > 40000 then 
  228. 			do_test = false 
  229. 		end 
  230. 	end 
  231. end 
  232.  
  233. function test_numbers_periods() 
  234. 	local text_field_h = vint_object_find("text_field") 
  235. 	 
  236. 	local do_test = true 
  237. 	local value_1 = 0 
  238. 	local value_2 = 0 
  239. 	local value_3 = 0 
  240. 	while do_test do 
  241. 		value_1 = value_1 + rand_int(1,99) 
  242. 		value_2 = value_2 + rand_int(1,99) 
  243. 		value_3 = value_3 + rand_int(1,99) 
  244. 		local formated_value = value_1 .. "." .. value_2 .. "." .. value_2 
  245. 		vint_set_property(text_field_h, "text_tag", formated_value) 
  246. 		thread_yield() 
  247. 		if value_1 + value_2 + value_3 > 100000 then 
  248. 			do_test = false 
  249. 		end 
  250. 	end 
  251. end 
  252.  
  253. function test_timer() 
  254. 	local text_field_h = vint_object_find("text_field") 
  255. 	 
  256. 	local do_test = true 
  257. 	local value = 0 
  258. 	while do_test do 
  259. 		value = value + 1 
  260. 		local formated_value = format_clock(value) 
  261. 		vint_set_property(text_field_h, "text_tag", formated_value) 
  262. 		thread_yield() 
  263. 		if value > 3000 then 
  264. 			do_test = false 
  265. 		end 
  266. 	end 
  267. end