DaxSoft

Dax Core i2.0

Feb 21st, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 116.43 KB | None | 0 0
  1. #==============================================================================
  2. # * Dax Core
  3. #==============================================================================
  4. # Autor : Dax Aquatic X
  5. # Versão : Core i2.0
  6. # Site : www.dax-soft.weebly.com
  7. # Suporte : [email protected]
  8. #==============================================================================
  9. # Um Core com vários módulos e métodos que facilitará na hora de programar os
  10. # seus scripts, bom proveito.
  11. #==============================================================================
  12. # Conteúdo :
  13. #==============================================================================
  14. # i :
  15. # - API
  16. # - String
  17. # - Integer
  18. # - Float
  19. # - Color
  20. # - ColorBasic
  21. # - DMath
  22. # - Key
  23. # - Mouse
  24. # - Entries
  25. # - Rpg Module
  26. # - Read
  27. # - DRGSS
  28. # - Rect
  29. # - Sprite
  30. # - Bitmap : method (save) by Gab!
  31. # - Object
  32. # - Touch_Picture
  33. # - Simple_Touch_Picture
  34. # - Sprite_Text
  35. # - Text_Base
  36. # - Touch_Icon
  37. # - Simple_Touch_Icon
  38. # - Touch_Text
  39. # - Simple_Touch_Text
  40. # - Opacity
  41. # - DString
  42. # - Background
  43. # - Window_Base
  44. # - Map
  45. # - User32
  46. # - VS
  47. # - Sound Base
  48. # - Disable Script
  49. # - Regexp Symbols
  50. # - Enumerables
  51. #==============================================================================
  52. # • TAGS : Para facilitar a localização dos códigos e explicações. Para acessar
  53. # o comando para localizar, basta apertar Ctrl+F.
  54. #==============================================================================
  55. # :api -> Ir até módulos das API;
  56. # :user32 -> Ir até módulo User32;
  57. # :enumerables -> Ir até add-ons para Enumerables.
  58. # :string -> Ir até add-ons para a classe String.
  59. # :integer -> Ir até add-ons para a classe Integer.
  60. # :float -> Ir até add-ons para a classe Float.
  61. # :color -> Ir até add-ons para a classe Color.
  62. # :rect -> Ir até add-ons para a classe Rect.
  63. # :dmath -> Ir até o módulo DMath.
  64. # :colorbasic -> Ir até o módulo ColorBasic.
  65. # :key -> Ir até o módulo Key.
  66. # :sprite -> Ir até add-ons para a classe Sprite.
  67. # :bitmap -> Ir até add-ons para a classe Bitmap.
  68. # :mouse -> Ir até o módulo Mouse.
  69. # :object -> Ir até add-ons para a classe Object.
  70. # :entries -> Ir até a classe Entries.
  71. # :text_base -> Ir até a classe Text Base.
  72. # :drgss -> Ir até o módulo DRGSS.
  73. # :outline_fill_rect -> Ir até a classe OutlineFillRect
  74. # :backupsystem -> Ir até o método de backup. Para fazer backup só chamar o
  75. # método backup.
  76. # :dstring -> Ir até o módulo DString.
  77. # :scenemanager -> Ir até add-ons para o módulo SceneManager.
  78. # :sprite_text -> Ir até a classe Sprite_Text.
  79. # :opacity -> Ir até o módulo Opacity.
  80. # :rpg -> Ir até o módulo Rpg.
  81. # :shortcut -> Ir até o método Shortcut.
  82. # :read -> Ir até o módulo Read.
  83. # :background -> Ir até o módulo Background.
  84. # :window_base -> Ir até add-ons para a classe Window_Base.
  85. # :map -> Ir até o módulo Map.
  86. # :vs -> Ir até o módulo VS.
  87. # :sound_base -> Ir até o módulo Sound_Base.
  88. # :position -> Ir até a classe Positions.
  89. #==============================================================================
  90. module Dax
  91. extend self
  92. #----------------------------------------------------------------------------
  93. # Ajuste aqui as configurações básicas da fonte padrão do jogo.
  94. #----------------------------------------------------------------------------
  95. Font.default_name = ["Arial"] # Nome padrão da fonte do jogo.
  96. Font.default_size = 18 # Tamanho padrão da fonte do jogo.
  97. Font.default_bold = true # true - Para usar negrito | false - para não usar.
  98. Font.default_italic = false # true - Para usar italico | false - para não usar.
  99. Font.default_shadow = false # true - Para usar sombra na fonte | false - para não usar.
  100. Font.default_outline = true # true - Para usar borda da fonte | false - para não usar.
  101. Font.default_out_color = Color.new(0, 0, 0) # Cor da fonte padrão da borda da fonte.
  102. Font.default_color = Color.new(255, 255, 255) # Cor da fonte padrão.
  103. #----------------------------------------------------------------------------
  104. # * Constantes e variáveis
  105. #----------------------------------------------------------------------------
  106. @register = {} # Armazena os scripts criados que foram registrados.
  107. @benchmark = "" # Armazena os testes conclusos de benchmark.
  108. # A imagem do ícone do Mouse tem que estar na pasta System. Basta você
  109. # por o nome da imagem dentro das áspas. Caso você queira usar um ícone
  110. # do Rpg Maker no lugar de uma imagem, basta você por o id do ícone no lugar
  111. # das áspas.
  112. Mouse_Name = ""
  113. #----------------------------------------------------------------------------
  114. # * Somente executará o bloco caso estiver registrado o script.
  115. #----------------------------------------------------------------------------
  116. # Exemplo:
  117. # Dax.required_script(:teste) { # Só irá executar caso estiver registrado.
  118. # methods...
  119. # }
  120. #----------------------------------------------------------------------------
  121. def required_script(symbol, &block)
  122. block.call if @register.has_key?(symbol) and block_given?
  123. end
  124. #----------------------------------------------------------------------------
  125. # * Método de registrar scripts :
  126. #----------------------------------------------------------------------------
  127. # ** Este método tem de ser definido alguns valores como :
  128. # symbol - nome do script, que é posto em símbolo : Ex - :arrow
  129. # name - nome do autor do script, que é posto em áspas
  130. # version - versão do script;
  131. # data - data do script;
  132. # Dax.register(symbol, name, version, data)
  133. # ** Você pode usá-lo para somente registrar o nome do script.
  134. # Dax.register(symbol)
  135. #----------------------------------------------------------------------------
  136. def register(*args)
  137. if @register.has_key?(args[0])
  138. @register[args[0]][:version] = args[1]
  139. @register[args[0]][:data] = args[2]
  140. else
  141. @register[args[0]] = {name: args[1], version: args[2], data: args[3], script: nil}
  142. end
  143. end
  144. #----------------------------------------------------------------------------
  145. # * Método de verificar se o objeto existe.
  146. #----------------------------------------------------------------------------
  147. # Dax.required_class("Objeto") { }
  148. # Dentro das chaves você poem o script.
  149. # * Exemplo :
  150. # Dax.required_class("Window_Base") {
  151. # class Window_Base < Window
  152. # def example
  153. # self.x = self.x + self.width
  154. # end
  155. # end
  156. # }
  157. #----------------------------------------------------------------------------
  158. # Executa o bloco se o objeto existir.
  159. #----------------------------------------------------------------------------
  160. def required_class(name, &block)
  161. eval("block.call if defined?(name)")
  162. end
  163. #----------------------------------------------------------------------------
  164. # • Fazer benchmark de um bloco. O resultado será impresso no Console do
  165. # Maker.
  166. #----------------------------------------------------------------------------
  167. # Dax.benchmark(name(opcional)) { BLOCO }
  168. #----------------------------------------------------------------------------
  169. def benchmark(name="", &block)
  170. time = Time.now
  171. block.call
  172. print "Benchmark: #{(time - Time.now).abs.to_f} segundos!\r\n"
  173. @benchmark += "#{name} : #{(time - Time.now).to_f} segundos!\r\n"
  174. end
  175. #----------------------------------------------------------------------------
  176. # • Salva os testes de benchmark.
  177. #----------------------------------------------------------------------------
  178. def benchmark_save
  179. File.open("Benchmark.txt", "a+") do |file|
  180. file.write(@benchmark)
  181. file.close
  182. end
  183. end
  184. #----------------------------------------------------------------------------
  185. # • Requirir um arquivo.
  186. # arquivo : Arquivo...
  187. #----------------------------------------------------------------------------
  188. def require(arquivo)
  189. $: << "./"
  190. Kernel.send(:require, arquivo)
  191. end
  192. #----------------------------------------------------------------------------
  193. # * Somente executa um bloco case existir um arquivo.
  194. #----------------------------------------------------------------------------
  195. # Dax.required_file("arquivo.tipo") { # Exemplo.
  196. # Métodos;
  197. # }
  198. #----------------------------------------------------------------------------
  199. def required_file(filename, &block)
  200. block.call if FileTest.exist?(filename)
  201. end
  202. #----------------------------------------------------------------------------
  203. # * Remove uma [Classe], exemplo: Dax.remove(:Scene_Menu)
  204. #----------------------------------------------------------------------------
  205. def remove(symbol_name)
  206. Object.send(:remove_const, symbol_name)
  207. end
  208. #----------------------------------------------------------------------------
  209. # * Retorna a variável [$RGSS_SCRIPT]
  210. #----------------------------------------------------------------------------
  211. def rgss_script
  212. return $RGSS_SCRIPTS
  213. end
  214. #----------------------------------------------------------------------------
  215. # * Tela chéia
  216. #----------------------------------------------------------------------------
  217. def full_screen
  218. res = Win32API.new 'user32', 'keybd_event', %w(l l l l), ''
  219. res.call(18,0,0,0)
  220. res.call(13,0,0,0)
  221. res.call(13,0,2,0)
  222. res.call(18,0,2,0)
  223. end
  224. end
  225. Dax.register(:dax)
  226. #==============================================================================
  227. # * API : Módulo que armazena informações de algumas APIS.
  228. #==============================================================================
  229. Dax.register(:api)
  230. module API
  231. extend self
  232. # Permite acessar as teclas do teclado.
  233. GetKeyState = Win32API.new('user32', 'GetAsyncKeyState', 'i', 'i')
  234. # Permite ativar/desativar o ícone do mouse.
  235. MouseShowCursor = Win32API.new("user32", "ShowCursor", "i", "i")
  236. # Permite achar a posição do mouse.
  237. CursorPosition = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
  238. # Permite achar o tamanho da screen.
  239. ScreenToClient = Win32API.new('user32', 'ScreenToClient', %w(l p), 'i')
  240. # Permite fazer a leitura do game.ini.
  241. ReadIni = Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l')
  242. # Permite achar o tamando da window.
  243. FindWindow = Win32API.new('user32', 'FindWindowA', %w(p p), 'l')
  244. # API da Message Box.
  245. MessageBoxA = Win32API.new('user32', 'MessageBoxA', %w(p p p i), 'i')
  246. # Recupera uma string especificada de um arquivo em inicialização.
  247. GetPrivateProfileString = Win32API.new('kernel32', 'GetPrivateProfileStringA',%w(p p p p l p),'l')
  248. # Get Systeme Metrics
  249. GetSystemMetrics = Win32API.new("user32", "GetSystemMetrics", "i", "i")
  250. # Posição da janela.
  251. SetWindowPos = Win32API.new("user32", "SetWindowPos", "lliiiii", "i")
  252. # Obtem o 'Rect' da janela.
  253. GetWindowRect = Win32API.new('user32','GetWindowRect',%w(l p),'i')
  254. # Define a Win32API do comando print
  255. MessageBoxW = Win32API.new("user32", "MessageBoxW", "LPPL", "L")
  256. # Caps Lock
  257. CapsLock = Win32API.new("user32", "GetKeyState", "i", "i").call(20) != 0
  258. # State Key
  259. StateKey = Win32API.new("user32", "GetKeyState", ["i"], "i")
  260. # SetCursorPos
  261. SetCursorPos = Win32API.new("user32", "SetCursorPos", "ll", "i")
  262. SetCursorPos = Win32API.new("user32", "SetCursorPos", "ii", "i")
  263. GetKeyboardState = Win32API.new('user32', 'GetKeyboardState', ['P'], 'V')
  264. GetAsyncKeyState = Win32API.new('user32', 'GetAsyncKeyState', 'i', 'i')
  265. # Criar uma nova pasta.
  266. CreateDirectory = Win32API.new("kernel32", "CreateDirectory", "p", "lll")
  267. # Remover uma pasta existente.
  268. RemoveDirectory = Win32API.new("kernel32", "RemoveDirectory", "p", "l")
  269. WideCharToMultiByte = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
  270. MultiByteToWideChar = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
  271. # retorna para a data do ponteiro.
  272. def copymen(len)
  273. buf = "\0" * len
  274. Win32API.new("kernel32", "RtlMoveMemory", "ppl", "").call(buf, self, len)
  275. buf
  276. end
  277. # Shell
  278. Open = Win32API.new('shell32', 'ShellExecute', 'LPPPPI', 'L')
  279. def open_file(name)
  280. API::Open.call(0, 'open', "#{name}.exe", 0, 0, 1)
  281. end
  282. # Converter texto
  283. def convert_text(text, from, to)
  284. size = MultiByteToWideChar.(from, 0, text, -1, nil, 0)
  285. buffer = [].pack("x#{size*2}")
  286. MultiByteToWideChar.(from, 0, text, -1, buffer, buffer.size/2)
  287. size = WideCharToMultiByte.(to, 0, buffer, -1, nil, 0, nil, nil)
  288. second_buffer = [].pack("x#{size}")
  289. WideCharToMultiByte.(to, 0, buffer, -1, second_buffer, second_buffer.size, nil, nil)
  290. second_buffer.delete!("\000") if to == 65001
  291. second_buffer.delete!("\x00") if to == 0
  292. return second_buffer
  293. end
  294. end
  295. #==============================================================================
  296. # • User32
  297. #==============================================================================
  298. Dax.register(:user32, "Dax", 1.0, "18/05/13")
  299. module User32
  300.  
  301. GSM = Win32API.new('user32', 'GetSystemMetrics', 'I', 'I')
  302. SetWindowPos = Win32API.new('user32', 'SetWindowPos', 'LLIIIII', 'I')
  303. SetWindowLong = Win32API.new('user32', 'SetWindowLong', 'LIL', 'L')
  304. Keybd_Event = Win32API.new('user32', 'keybd_event', 'LLLL', '')
  305. FindWindow = Win32API.new('user32', 'FindWindow', 'PP', 'L')
  306. GetDesktopWindow = Win32API.new('user32', 'GetDesktopWindow', '', 'L')
  307. GetWindowInfo = Win32API.new('user32', 'GetWindowInfo', 'LP', 'I')
  308. SetForegroundWindow = Win32API.new('user32', 'SetForegroundWindow', 'L', 'L')
  309. GetCursorPos = Win32API.new('user32', 'GetCursorPos', 'P', 'I')
  310. ShowCursor = Win32API.new('user32', 'ShowCursor', 'L', 'L')
  311. ScreenToClient = Win32API.new('user32', 'ScreenToClient', 'LP', 'I')
  312. GetKeyState = Win32API.new('user32', 'GetKeyState', 'I', 'I')
  313. GetAsyncKeyState = Win32API.new('user32', 'GetAsyncKeyState', 'I', 'I')
  314.  
  315.  
  316. # GSM Constants: Visit the site: microsoft msdn
  317. # http://msdn.microsoft.com/en-us/library/ms724385(VS.85).aspx
  318. SM_CXSCREEN = 0 # Width of the current master screen resolution
  319. SM_CYSCREEN = 1 # Height of the current master screen resolution
  320.  
  321. SM_CXVSCROLL = 2 # Width of a vertical scroll bar
  322. SM_CYHSCROLL = 3 # Height of a horizontal scroll bar
  323.  
  324. SM_CYCAPTION = 4 # Height of a caption area
  325.  
  326. SM_CXBORDER = 5 # Width of a window border
  327. SM_CYBORDER = 6 # Height of a window border
  328.  
  329. SM_CXDLGFRAME = 7
  330. SM_CXFIXEDFRAME = 7 # Width of non-resizable captioned window frame
  331. SM_CYDLGFRAME = 8
  332. SM_CYFIXEDFRAME = 8 # Height of non-resizable captioned window frame
  333.  
  334. SM_CYVTHUMB = 9 # Height of a thumb button on vertical scrollbars
  335. SM_CXHTHUMB = 10 # Width of a thumb button on horizontal scrollbars
  336.  
  337. SM_CXICON = 11 # Default width of an icon
  338. SM_CYICON = 12 # Default height of an icon
  339.  
  340. SM_CXCURSOR = 13 # Width of a cursor
  341. SM_CYCURSOR = 14 # Height of a cursor
  342.  
  343. SM_CYMENU = 15 # Height of a single-line menu bar
  344.  
  345. SM_CXFULLSCREEN = 16 # Width of client rect for a full-screen window
  346. SM_CYFULLSCREEN = 17 # Height of client rect for a full-screen window
  347.  
  348. SM_CYKANJIWINDOW = 18 # Height of kanji window at bottom of screen, if there
  349.  
  350. SM_MOUSEPRESENT = 19 # Non-zero if mouse is present; 0 if not
  351.  
  352. SM_CYVSCROLL = 20 # Height of the arrow bitmap on vertical scrollbars
  353. SM_CXHSCROLL = 21 # Width of the arrow bitmap on horizontal scrollbars
  354.  
  355. SM_DEBUG = 22 # Non-zero if debug User.exe is installed; 0 if not
  356. SM_SWAPBUTTON = 23 # Non-zero if mouse button values are swapped
  357.  
  358. SM_CXMIN = 28 # Minimum width of a window
  359. SM_CYMIN = 29 # Minimum height of a window
  360.  
  361. SM_CXSIZE = 30 # Width of a button in a window caption or title bar
  362. SM_CYSIZE = 31 # Height of a button in a window caption or title bar
  363.  
  364. SM_CXFRAME = 32
  365. SM_CXSIZEFRAME = 32 # Width of the sizing border around a resizable window
  366. SM_CYFRAME = 33
  367. SM_CYSIZEFRAME = 33 # Height of the sizing border around a resizable window
  368.  
  369. SM_CXMINTRACK = 34 # Minimum "tracking" width of a window
  370. SM_CYMINTRACK = 35 # Minimum "tracking" height of a window
  371.  
  372. SM_CXDOUBLECLK = 36 # Width of rect which second click must be in for double
  373. SM_CYDOUBLECLK = 37 # Hght of rect which second click must be in for double
  374.  
  375. SM_CXICONSPACING = 38 # Width of a grid cell for items in large icon view
  376. SM_CYICONSPACING = 39 # Height of a grid cell for items in large icon view
  377.  
  378. SM_MENUDROPALIGNMENT = 40 # 0 if drop-down menus are left-aligned...
  379.  
  380. SM_PENWINDOWS = 41 # Non-zero if Microsoft Windows for Pen computing
  381. # extensions are installed; 0 if not
  382.  
  383. SM_DBCSENABLED = 42 # Non-zero if user32.dll supports DBCS; 0 if not
  384.  
  385. SM_CMOUSEBUTTONS = 43 # Number of available mouse buttons, or 0 for no mouse
  386.  
  387. SM_SECURE = 44 # Always returns 0
  388.  
  389. SM_CXEDGE = 45 # Width of a 3-D style border
  390. SM_CYEDGE = 46 # Height of a 3-D style border
  391.  
  392. SM_CXMINSPACING = 47 # Width of a grid cell for minimized windows
  393. SM_CYMINSPACING = 48 # Height of a grid cell for minimized windows
  394.  
  395. SM_CXSMICON = 49 # Recommended width of a small icon
  396. SM_CYSMICON = 50 # Recommended height of a small icon
  397.  
  398. SM_CYSMCAPTION = 51 # Height of a small caption
  399. SM_CXSMSIZE = 52 # Width of small caption buttons
  400. SM_CYSMSIZE = 53 # Height of small caption buttons
  401. SM_CXMENUSIZE = 54 # Width of menu bar buttons
  402. SM_CYMENUSIZE = 55 # Height of menu bar buttons
  403.  
  404. SM_ARRANGE = 56 # Flags about how system the arranges minimized windows
  405. SM_CXMINIMIZED = 57 # Width of a minimized window
  406. SM_CYMINIMIZED = 58 # Height of a minimized window
  407.  
  408. SM_CXMAXTRACK = 59 # Default maximum width of resizable windows
  409. SM_CYMAXTRACK = 60 # Default maximum height of resizable windows
  410. SM_CXMAXIMIZED = 61 # Default width of maximized top-level window
  411. SM_CYMAXIMIZED = 62 # Default height of maximized top-level window
  412.  
  413. SM_NETWORK = 63 # The least significant bit is set if a network is
  414. # present; otherwise, it is cleared
  415.  
  416. SM_CLEANBOOT = 67 # System boot type; 0:Normal, 1:Safe, 2:Safe w/network
  417.  
  418. SM_CXDRAG = 68
  419. SM_CYDRAG = 69 # Number of pixels mouse can move before initiating drag
  420.  
  421. SM_SHOWSOUNDS = 70 # Non-zero if user requires visible output; 0 if not
  422.  
  423. SM_CXMENUCHECK = 71 # Width of the default menu check-mark bitmap
  424. SM_CYMENUCHECK = 72 # Height of the default menu check-mark bitmap
  425.  
  426. SM_SLOWMACHINE = 73 # Non-zero if system has a slow processor; 0 if not
  427. # No, seriously, that's what Microsoft said!
  428.  
  429. SM_MIDEASTENABLED = 74 # Non-zero if system can use Hebrew, Arabic languages
  430.  
  431. SM_MOUSEWHEELPRESENT = 75 # Nonzero mouse has vertical scroll wheel; 0 if not
  432.  
  433. SM_XVIRTUALSCREEN = 76 # Coordinates of the left side of the virtual screen
  434. SM_YVIRTUALSCREEN = 77 # Coordinates of the top of the virtual screen
  435. SM_CXVIRTUALSCREEN = 78 # Virtual width of all screens put together
  436. SM_CYVIRTUALSCREEN = 79 # Virtual height of all screen put together
  437. SM_CMONITORS = 80 # Numbers of display monitors on a desktop
  438. SM_SAMEDISPLAYFORMAT = 81 # Non-zero if all screen use same color depth...
  439.  
  440. # SetWindowPos constants
  441. HWND_NOTOPMOST = -2 # Make window not always on top (and bring to front)
  442. HWND_TOPMOST = -1 # Put window in front and make it always on top
  443. HWND_TOP = 0 # Put window in front of all non-topmost windows
  444. HWND_BOTTOM = 1 # Put window behind all other windows
  445.  
  446. SWP_NOSIZE = 0x0001 # Keep current size (ignores w and h)
  447. SWP_NOMOVE = 0x0002 # Keep current position (ignores X and Y)
  448. SWP_NOZORDER = 0x0004 # Keep current Z order (ignores hWndInsertAfter)
  449. SWP_NOREDRAW = 0x0008 # Does NOT redraw changes
  450. SWP_NOACTIVATE = 0x0010 # Does NOT automatically activate the window
  451. SWP_FRAMECHANGED = 0x0020 # Applies new frame styles set with SetWindowLong
  452. SWP_SHOWWINDOW = 0x0040 # Displays the window
  453. SWP_HIDEWINDOW = 0x0080 # Hides the window
  454. SWP_NOCOPYBITS = 0x0100 # Discards the entire contents of the client area
  455. SWP_NOOWNERZORDER = 0x0200 # Doesn't change the window display order
  456. SWP_NOSENDCHANGING = 0x0400 # Don't send WM_WINDOWPOSCHANGING
  457. SWP_DEFERERASE = 0x2000 # Prevents generation of the WM_SYNCPAINT message
  458. SWP_ASYNCWINDOWPOS = 0x4000 # Use if calling thread does not own the window
  459.  
  460. # SetWindowLong constants
  461. GWL_USERDATA = -21 # Sets data reserved for use by the application
  462. GWL_EXSTYLE = -20 # Sets a new extended window style
  463. GWL_STYLE = -16 # Sets a new window style
  464. GWL_ID = -12 # Sets a new identifier of the window
  465. GWL_HWNDPARENT = -8 # Sets a new parent hWnd
  466. GWL_HINSTANCE = -6 # Sets a new application instance handle
  467. GWL_WNDPROC = -4 # Sets a new addr for the window calling procedure
  468. # Only available when the hWnd parameter identifies a dialog box:
  469. DWL_MSGRESULT = 0 # Sets the return message of the dialog box proc
  470. DWL_DLGPROC = 4 # Sets the new address of the dialog box proc
  471. DWL_USER = 8 # Sets new extra information private to application
  472.  
  473. # Window Styles (SetWindowLong(hWnd, GWL_STYLE, WS_*))
  474. WS_OVERLAPPED = 0x00000000 # Overlapped window has title and border
  475. WS_TABSTOP = 0x00010000 # Can receive focus from TAB key
  476. WS_GROUP = 0x00020000 # First control of group of controls
  477. WS_MAXIMIZEBOX = 0x00010000 # Has a mazimize button
  478. WS_MINIMIZEBOX = 0x00020000 # Has a minimize button
  479. WS_THICKFRAME = 0x00040000 # Has sizing border
  480. WS_SYSMENU = 0x00080000 # Has buttons on title bar (reqs WS_CAPTION)
  481. WS_HSCROLL = 0x00100000 # Has horizontal scroll bar
  482. WS_VSCROLL = 0x00200000 # Has vertical scroll bar
  483. WS_DLGFRAME = 0x00400000 # Dialog-style border. Cannot have title bar
  484. WS_BORDER = 0x00800000 # Thin border
  485. WS_CAPTION = 0x00C00000 # Has a title bar (implies WS_BORDER)
  486. WS_MAXIMIZE = 0x01000000 # Initially maximized
  487. WS_CLIPCHILDREN = 0x02000000 # Exclude area for children when drawing
  488. WS_CLIPSIBLINGS = 0x04000000 # Exclude sibling client rects when drawing
  489. WS_DISABLED = 0x08000000 # Initially disabled (no input)
  490. WS_VISIBLE = 0x10000000 # Initially visible
  491. WS_MINIMIZE = 0x20000000 # Initially minimized
  492. WS_CHILD = 0x40000000 # Child cannot have menu bar or WS_POPUP
  493. WS_POPUP = 0x80000000 # Popup window
  494. # Window style aliases
  495. WS_OVERLAPPEDWINDOW = WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_THICKFRAME|
  496. WS_MINIMIZEBOX|WS_MAXIMIZEBOX
  497. WS_POPUPWINDOW = WS_POPUP|WS_BORDER|WS_SYSMENU
  498. WS_CHILDWINDOW = WS_CHILD
  499. WS_TILED = WS_OVERLAPPED
  500. WS_ICONIC = WS_MINIMIZE
  501. WS_SIZEBOX = WS_THICKFRAME
  502. WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW
  503. end
  504. #==============================================================================
  505. # • Enumerables;
  506. #==============================================================================
  507. Dax.register(:enumerables)
  508. module Enumerables
  509. #----------------------------------------------------------------------------
  510. # • Retorna a uma nova array com todos os resultados retirando os zeros.
  511. #----------------------------------------------------------------------------
  512. def select_map(&aProc)
  513. map(&aProc).reject { |e| e.nil? }
  514. end
  515. end
  516. #==============================================================================
  517. # * String
  518. #==============================================================================
  519. Dax.register(:string)
  520. class String
  521. #----------------------------------------------------------------------------
  522. # * Método com a função de decodificar a base 64.
  523. #----------------------------------------------------------------------------
  524. def decode_base64
  525. self.unpack("m")[0]
  526. end
  527. #----------------------------------------------------------------------------
  528. # * Obtem a palavra do méio de uma frase/palavra
  529. #----------------------------------------------------------------------------
  530. def get_string_between(start_at, end_at)
  531. my_string = " #{self}"
  532. ini = my_string.index(start_at)
  533. return my_string if ini == 0
  534. ini += start_at.length
  535. length = my_string.index(end_at, ini).to_i - ini
  536. return my_string[ini,length]
  537. end
  538. #--------------------------------------------------------------------------
  539. # * retorna self em ASCII-8BIT
  540. #--------------------------------------------------------------------------
  541. def to_ascii
  542. API.convert_text(self, 65001, 0)
  543. end
  544. #--------------------------------------------------------------------------
  545. # * converte self em ASCII-8BIT
  546. #--------------------------------------------------------------------------
  547. def to_ascii!
  548. self.replace(self.to_ascii)
  549. end
  550. #--------------------------------------------------------------------------
  551. # * retorna self para UTF8
  552. #--------------------------------------------------------------------------
  553. def to_utf8
  554. API.convert_text(self, 0, 65001)
  555. end
  556. #--------------------------------------------------------------------------
  557. # * converte self em UTF8
  558. #--------------------------------------------------------------------------
  559. def to_utf8!
  560. self.replace(self.to_utf8)
  561. end
  562. #--------------------------------------------------------------------------
  563. # * Extrai os números.
  564. #--------------------------------------------------------------------------
  565. def extract_numbers
  566. self.scan(/-*\d+/).collect{|n|n.to_i}
  567. end
  568. end
  569. #==============================================================================
  570. # * Integer
  571. #==============================================================================
  572. Dax.register(:integer)
  573. class Integer
  574. #----------------------------------------------------------------------------
  575. # * Transformar o valor em porcentagem : Útil para fazer barras como por exemplo
  576. # barras de HP.
  577. # a : Valor atual.
  578. # b : Valor máximo.
  579. #----------------------------------------------------------------------------
  580. def to_p(a, b)
  581. self * a / b
  582. end
  583. #----------------------------------------------------------------------------
  584. # * Grid On : Multiplica o número pelo tamanho de uma grid.
  585. #----------------------------------------------------------------------------
  586. def grid_on(grid_size=32)
  587. return self * grid_size
  588. end
  589. #----------------------------------------------------------------------------
  590. # * Grid Off : Divide o número pelo tamanho de uma grid.
  591. #----------------------------------------------------------------------------
  592. def grid_off(grid_size=32)
  593. return self / grid_size
  594. end
  595. end
  596. #==============================================================================
  597. # * Float
  598. #==============================================================================
  599. Dax.register(:float)
  600. class Float
  601. #----------------------------------------------------------------------------
  602. # * Transformar em porcentagem :
  603. # a : Valor atual.
  604. # b : Valor máximo.
  605. #----------------------------------------------------------------------------
  606. def to_p(a, b)
  607. self * a / b
  608. end
  609. end
  610. #==============================================================================
  611. # * Color
  612. #==============================================================================
  613. Dax.register(:color)
  614. class Color
  615. #----------------------------------------------------------------------------
  616. # • Diminui a opacidade da cor, deixando-a opaca..
  617. #----------------------------------------------------------------------------
  618. def opacity
  619. self.set(self.red, self.green, self.blue, 128)
  620. end
  621. #----------------------------------------------------------------------------
  622. # • Inverte as cores.
  623. #----------------------------------------------------------------------------
  624. def invert!
  625. self.set(255-self.red, 255-self.green, 255-self.blue, self.alpha)
  626. end
  627. #----------------------------------------------------------------------------
  628. # • Reverter as cores.
  629. #----------------------------------------------------------------------------
  630. def revert
  631. colors = [self.red, self.green, self.blue, self.alpha].reverse!
  632. self.set(*colors)
  633. end
  634. #----------------------------------------------------------------------------
  635. # • Converte para string.
  636. #----------------------------------------------------------------------------
  637. def to_s
  638. "red: #{self.red}\nblue: #{self.blue}\ngreen: #{self.green}\nalpha: #{self.alpha}"
  639. end
  640. #----------------------------------------------------------------------------
  641. # • Comparar cores, retorna a [true] se for igual.. returna a [false] se não
  642. # for igual.
  643. #----------------------------------------------------------------------------
  644. def ==(color)
  645. (self.red == color.red and self.green == color.green and self.blue == color.blue and
  646. self.alpha == color.alpha) ? true : false
  647. end
  648. #----------------------------------------------------------------------------
  649. # • Retorna os valores da classe [COLOR] para hash;;
  650. #----------------------------------------------------------------------------
  651. def to_h
  652. return {
  653. red: self.red, green: self.green, blue: self.blue, alpha: self.alpha,
  654. }
  655. end
  656. #----------------------------------------------------------------------------
  657. # • Retorna os valores da classe [COLOR] para array;;
  658. #----------------------------------------------------------------------------
  659. def to_a
  660. return [self.red, self.green, self.blue, self.alpha]
  661. end
  662. end
  663. #==============================================================================
  664. # * ColorBasic
  665. #==============================================================================
  666. Dax.register(:colorbasic)
  667. module ColorBasic
  668. extend self
  669. #----------------------------------------------------------------------------
  670. # • Cores Hexadécimais
  671. # * ColorBasic.hex("ffffff") #=> 255, 255, 255 | Branco.
  672. #----------------------------------------------------------------------------
  673. def hex(color)
  674. Color.new(*color.scan(/../).map { |color| color.to_i(16)})
  675. end
  676. #----------------------------------------------------------------------------
  677. # • Cores em Index
  678. #----------------------------------------------------------------------------
  679. def [](id)
  680. case id
  681. when -1 then Color.new(255, 255, 255) # White
  682. when 0 then Color.new(240, 248, 255) # Alice Blue
  683. when 1 then Color.new(250, 235, 215) # Antique_White
  684. when 2 then Color.new(0, 255, 255) # Aqua
  685. when 3 then Color.new(127, 255, 255) # Aqua Marine
  686. when 4 then Color.new(240, 255, 255) # Azure
  687. when 5 then Color.new(245, 245, 220) # Beige
  688. when 6 then Color.new(255, 228, 196) # Bisque
  689. when 7 then Color.new(0, 0, 0) # Black
  690. when 8 then Color.new(255, 235, 205) # Blanchedalmond
  691. when 9 then Color.new(0, 0, 255) # Blue
  692. when 10 then Color.new(138, 43, 226) # Blue Violet
  693. when 11 then Color.new(165, 42, 42) # Brown
  694. when 12 then Color.new(222, 184, 135) # Burly Wood
  695. when 13 then Color.new(93, 158, 160) # Cadet Blue
  696. when 14 then Color.new(127, 255, 0) # Chatreuse
  697. when 15 then Color.new(210, 105, 30) # Chocolate
  698. when 16 then Color.new(255, 127, 80) # Coral
  699. when 17 then Color.new(100, 149, 237) # Corn Flower Blue
  700. when 18 then Color.new(255, 248, 220) # CornSilk
  701. when 19 then Color.new(220, 20, 60) # Crimson
  702. when 20 then Color.new(0, 255, 255) # Cyan
  703. when 21 then Color.new(0, 0, 139) # DarkBlue
  704. when 22 then Color.new(0, 139, 139) # DarkCyan
  705. when 23 then Color.new(184, 134, 11) # DarkGoldEnrod
  706. when 24 then Color.new(169, 169, 169) # Dark Gray
  707. when 25 then Color.new(0, 100, 0) # Dark Green
  708. when 26 then Color.new(189, 183, 107) # Dark Khaki
  709. when 27 then Color.new(139, 0, 139) # Dark Magenta
  710. when 28 then Color.new(85, 107, 47) # Dark Oliver Green
  711. when 29 then Color.new(255, 140, 0) # Dark Orange
  712. when 30 then Color.new(153, 50, 204) # Dark orchid
  713. when 31 then Color.new(139, 0, 0) # Dark Red
  714. when 32 then Color.new(233, 150, 120) # Dark Salmon
  715. when 33 then Color.new(143, 188, 143) # Dark Sea Green
  716. when 34 then Color.new(72, 61, 139) # Dark Slate Blue
  717. when 35 then Color.new(255, 255, 0) # Yellow
  718. when 36 then Color.new(255, 0, 0) # Red
  719. when 37 then Color.new(0, 255, 0) # Green
  720. when 38 then Color.new(255, 128, 0) # Orange
  721. end
  722. end
  723. #----------------------------------------------------------------------------
  724. # • Cor padrão.
  725. #----------------------------------------------------------------------------
  726. def default
  727. return self.hex "ffffff"
  728. end
  729. #----------------------------------------------------------------------------
  730. # • * Forma uma cor aleátoria, retornando para um objeto de Cor.
  731. #----------------------------------------------------------------------------
  732. def rand
  733. return Color.new(rand(256), rand(256), rand(256))
  734. end
  735. end
  736. #==============================================================================
  737. # • Rect
  738. #==============================================================================
  739. Dax.register(:rect)
  740. class Rect
  741. #----------------------------------------------------------------------------
  742. # • Verificar se está na área.
  743. #----------------------------------------------------------------------------
  744. def in?(x, y)
  745. x.between?(self.x, self.x + self.width) &&
  746. y.between?(self.y, self.y + self.height)
  747. end
  748. end
  749. #==============================================================================
  750. # • DMath
  751. #==============================================================================
  752. Dax.register(:dmath, 'Dax', 1.5, '04/05/13')
  753. module DMath
  754. extend self
  755. #----------------------------------------------------------------------------
  756. # • Clamp.
  757. #----------------------------------------------------------------------------
  758. def clamp(num, low, high)
  759. return num < low ? low : num > high ? high : low
  760. end
  761. #----------------------------------------------------------------------------
  762. # • Centralizar um objeto n'outro.
  763. #----------------------------------------------------------------------------
  764. def centralize_object(object, object_for_centralize)
  765. x = object.x + (object.width - object_for_centralize.width) / 2
  766. y = object.y + (object.height - object_for_centralize.height) / 2
  767. return x, y
  768. end
  769. #----------------------------------------------------------------------------
  770. # • Centralizar um objeto n'outro.
  771. #----------------------------------------------------------------------------
  772. def centralize_x(objectx, objectwidth, object_for_centralizewidth)
  773. return objectx + (objectwidth - object_for_centralizewidth) / 2
  774. end
  775. #----------------------------------------------------------------------------
  776. # • Centralizar um objeto n'outro.
  777. #----------------------------------------------------------------------------
  778. def centralize_y(objecty=0, objectheight = 0, object_for_centralizeheight=0)
  779. return objecty + (objectheight - object_for_centralizeheight) / 2
  780. end
  781. #----------------------------------------------------------------------------
  782. # • Rotc | Rotacionar.
  783. #----------------------------------------------------------------------------
  784. def rotc(vmn, v, vmx, c = 100)
  785. ((v - vmn) * c) / (vmx - vmn)
  786. end
  787. #----------------------------------------------------------------------------
  788. # • Obter o X do centro da tela para um determinado objeto|sprite,bitmap.
  789. #----------------------------------------------------------------------------
  790. def get_x_center_screen(width)
  791. return (Graphics.width - width) / 2
  792. end
  793. #----------------------------------------------------------------------------
  794. # • Obter o Y do centro da tela para um determinado objeto|sprite,bitmap.
  795. #----------------------------------------------------------------------------
  796. def get_y_center_screen(height)
  797. return (Graphics.height - height) / 2
  798. end
  799. #--------------------------------------------------------------------------
  800. # • Verifica se um objeto está na área. Círculo | Circle
  801. #--------------------------------------------------------------------------
  802. def circle(object, object2, size)
  803. ( (object.x - object2.x) ** 2) + ( (object.y - object2.y) ** 2) <= (size ** 2)
  804. end
  805. #----------------------------------------------------------------------------
  806. # • Converter em graus, multiplique a variável com isto.
  807. #----------------------------------------------------------------------------
  808. def graus
  809. 360 / (2 * Math::PI)
  810. end
  811. #----------------------------------------------------------------------------
  812. # • Radiano
  813. #----------------------------------------------------------------------------
  814. def radian(degree)
  815. return (degree.to_f/180) * Math::PI
  816. end
  817. #----------------------------------------------------------------------------
  818. # • Degree
  819. #----------------------------------------------------------------------------
  820. def degree(radian)
  821. return (radian.to_f/Math::PI) * 180
  822. end
  823. #----------------------------------------------------------------------------
  824. # • Para 4 decimals.
  825. #----------------------------------------------------------------------------
  826. def to_4_dec(n)
  827. ((n * 1000).ceil) / 1000
  828. end
  829. #----------------------------------------------------------------------------
  830. # • Área de um triângulo.
  831. #----------------------------------------------------------------------------
  832. def triangle_area(*args)
  833. x, y, x2, y2, x3, y3 = *args
  834. return (x2 - x) * (y3 - y) - (x3 - x) * (y2 - y)
  835. end
  836. #----------------------------------------------------------------------------
  837. # • Calcular distância para scripts como sensor.
  838. #----------------------------------------------------------------------------
  839. def distance_sensor(target, target2)
  840. return (target.x - target2.x).abs + (target.y - target2.y).abs
  841. end
  842. end
  843. #==============================================================================
  844. # • Keyboard | Método para usar todas as teclas do teclado.
  845. #==============================================================================
  846. Dax.register(:key, "Dax", 1.0)
  847. module Key
  848. extend self
  849. #--------------------------------------------------------------------------
  850. # * Chaves diversos.
  851. #--------------------------------------------------------------------------
  852. CANCEL = 0x03 # Control-Break Processing
  853. BACKSPACE = 0x08 # Backspace Key
  854. TAB = 0x09 # Tab Key
  855. CLEAR = 0x0C # Clear Key
  856. ENTER = 0x0D # Enter Key
  857. SHIFT = 0x10 # Shift Key
  858. CONTROL = 0x11 # Ctrl Key
  859. MENU = 0x12 # Alt Key
  860. PAUSE = 0x13 # Pause Key
  861. ESC = 0x1B # Esc Key
  862. CONVERT = 0x1C # IME Convert Key
  863. NONCONVERT = 0x1D # IME Nonconvert Key
  864. ACCEPT = 0x1E # IME Accept Key
  865. SPACE = 0x20 # Space Bar Key (Space, usually blank)
  866. PRIOR = 0x21 # Page Up Key
  867. NEXT = 0x22 # Page Down Key
  868. ENDS = 0x23 # End Key
  869. HOME = 0x24 # Home Key
  870. LEFT = 0x25 # Left Arrow Key
  871. UP = 0x26 # Up Arrow Key
  872. RIGHT = 0x27 # Right Arrow Key
  873. DOWN = 0x28 # Down Arrow Key
  874. SELECT = 0x29 # Select Key
  875. PRINT = 0x2A # Print Key
  876. EXECUTE = 0x2B # Execute Key
  877. SNAPSHOT = 0x2C # Print Screen Key
  878. DELETE = 0x2E # Delete Key
  879. HELP = 0x2F # Help Key
  880. LSHIFT = 0xA0 # Left Shift Key
  881. RSHIFT = 0xA1 # Right Shift Key
  882. LCONTROL = 0xA2 # Left Control Key (Ctrl)
  883. RCONTROL = 0xA3 # Right Control Key (Ctrl)
  884. LMENU = 0xA4 # Left Menu Key (Alt)
  885. RMENU = 0xA5 # Right Menu Key (Alt)
  886. PACKET = 0xE7 # Used to Pass Unicode Characters as Keystrokes
  887. MOUSE_RIGHT = 0x01 # Button Mouse Right
  888. MOUSE_LEFT = 0x02 # Button Mouse Left
  889. MOUSE_MIDDLE = 0x04 # Button Mouse Middle
  890. #--------------------------------------------------------------------------
  891. # * Chaves de números.
  892. #--------------------------------------------------------------------------
  893. N0 = 0x30 # 0 Key
  894. N1 = 0x31 # 1 Key
  895. N2 = 0x32 # 2 Key
  896. N3 = 0x33 # 3 Key
  897. N4 = 0x34 # 4 Key
  898. N5 = 0x35 # 5 Key
  899. N6 = 0x36 # 6 Key
  900. N7 = 0x37 # 7 Key
  901. N8 = 0x38 # 8 Key
  902. N9 = 0x39 # 9 Key
  903. #--------------------------------------------------------------------------
  904. # * Chaves de letras
  905. #--------------------------------------------------------------------------
  906. A = 0x41 # A Key
  907. B = 0x42 # B Key
  908. C = 0x43 # C Key
  909. D = 0x44 # D Key
  910. E = 0x45 # E Key
  911. F = 0x46 # F Key
  912. G = 0x47 # G Key
  913. H = 0x48 # H Key
  914. I = 0x49 # I Key
  915. J = 0x4A # J Key
  916. K = 0x4B # K Key
  917. L = 0x4C # L Key
  918. M = 0x4D # M Key
  919. N = 0x4E # N Key
  920. O = 0x4F # O Key
  921. P = 0x50 # P Key
  922. Q = 0x51 # Q Key
  923. R = 0x52 # R Key
  924. S = 0x53 # S Key
  925. T = 0x54 # T Key
  926. U = 0x55 # U Key
  927. V = 0x56 # V Key
  928. W = 0x57 # W Key
  929. X = 0x58 # X Key
  930. Y = 0x59 # Y Key
  931. Z = 0x5A # Z Key
  932. #--------------------------------------------------------------------------
  933. # * Chaves de windows
  934. #--------------------------------------------------------------------------
  935. LWIN = 0x5B # Left Windows Key (Natural keyboard)
  936. RWIN = 0x5C # Right Windows Key (Natural Keyboard)
  937. APPS = 0x5D # Applications Key (Natural keyboard)
  938. SLEEP = 0x5F # Computer Sleep Key
  939. BROWSER_BACK = 0xA6 # Browser Back Key
  940. BROWSER_FORWARD = 0xA7 # Browser Forward Key
  941. BROWSER_REFRESH = 0xA8 # Browser Refresh Key
  942. BROWSER_STOP = 0xA9 # Browser Stop Key
  943. BROWSER_SEARCH = 0xAA # Browser Search Key
  944. BROWSER_FAVORITES = 0xAB # Browser Favorites Key
  945. BROWSER_HOME = 0xAC # Browser Start and Home Key
  946. VOLUME_MUTE = 0xAD # Volume Mute Key
  947. VOLUME_DOWN = 0xAE # Volume Down Key
  948. VOLUME_UP = 0xAF # Volume Up Key
  949. MEDIA_NEXT_TRACK = 0xB0 # Next Track Key
  950. MEDIA_PREV_TRACK = 0xB1 # Previous Track Key
  951. MEDIA_STOP = 0xB2 # Stop Media Key
  952. MEDIA_PLAY_PAUSE = 0xB3 # Play/Pause Media Key
  953. LAUNCH_MAIL = 0xB4 # Start Mail Key
  954. LAUNCH_MEDIA_SELECT = 0xB5 # Select Media Key
  955. LAUNCH_APP1 = 0xB6 # Start Application 1 Key
  956. LAUNCH_APP2 = 0xB7 # Start Application 2 Key
  957. PROCESSKEY = 0xE5 # IME Process Key
  958. ATTN = 0xF6 # Attn Key
  959. CRSEL = 0xF7 # CrSel Key
  960. EXSEL = 0xF8 # ExSel Key
  961. EREOF = 0xF9 # Erase EOF Key
  962. PLAY = 0xFA # Play Key
  963. ZOOM = 0xFB # Zoom Key
  964. PA1 = 0xFD # PA1 Key
  965. #--------------------------------------------------------------------------
  966. # * Chaves do Numpad
  967. #--------------------------------------------------------------------------
  968. NUMPAD0 = 0x60 # Numeric Keypad 0 Key
  969. NUMPAD1 = 0x61 # Numeric Keypad 1 Key
  970. NUMPAD2 = 0x62 # Numeric Keypad 2 Key
  971. NUMPAD3 = 0x63 # Numeric Keypad 3 Key
  972. NUMPAD4 = 0x64 # Numeric Keypad 4 Key
  973. NUMPAD5 = 0x65 # Numeric Keypad 5 Key
  974. NUMPAD6 = 0x66 # Numeric Keypad 6 Key
  975. NUMPAD7 = 0x67 # Numeric Keypad 7 Key
  976. NUMPAD8 = 0x68 # Numeric Keypad 8 Key
  977. NUMPAD9 = 0x69 # Numeric Keypad 9 Key
  978. MULTIPLY = 0x6A # Multiply Key (*)
  979. ADD = 0x6B # Add Key (+)
  980. SEPARATOR = 0x6C # Separator Key
  981. SUBTRACT = 0x6D # Subtract Key (-)
  982. DECIMAL = 0x6E # Decimal Key (.)
  983. DIVIDE = 0x6F # Divide Key (/)
  984. #--------------------------------------------------------------------------
  985. # * Chaves de funções
  986. #--------------------------------------------------------------------------
  987. F1 = 0x70 # F1 Key
  988. F2 = 0x71 # F2 Key
  989. F3 = 0x72 # F3 Key
  990. F4 = 0x73 # F4 Key
  991. F5 = 0x74 # F5 Key
  992. F6 = 0x75 # F6 Key
  993. F7 = 0x76 # F7 Key
  994. F8 = 0x77 # F8 Key
  995. F9 = 0x78 # F9 Key
  996. F10 = 0x79 # F10 Key
  997. F11 = 0x7A # F11 Key
  998. F12 = 0x7B # F12 Key
  999. F13 = 0x7C # F13 Key
  1000. F14 = 0x7D # F14 Key
  1001. F15 = 0x7E # F15 Key
  1002. F16 = 0x7F # F16 Key
  1003. F17 = 0x80 # F17 Key
  1004. F18 = 0x81 # F18 Key
  1005. F19 = 0x82 # F19 Key
  1006. F20 = 0x83 # F20 Key
  1007. F21 = 0x84 # F21 Key
  1008. F22 = 0x85 # F22 Key
  1009. F23 = 0x86 # F23 Key
  1010. F24 = 0x87 # F24 Key
  1011. #--------------------------------------------------------------------------
  1012. # * Chaves alternativas
  1013. #--------------------------------------------------------------------------
  1014. CAPITAL = 0x14 # Caps Lock Key
  1015. KANA = 0x15 # IME Kana Mode Key
  1016. HANGUL = 0x15 # IME Hangul Mode Key
  1017. JUNJA = 0x17 # IME Junja Mode Key
  1018. FINAL = 0x18 # IME Final Mode Key
  1019. HANJA = 0x19 # IME Hanja Mode Key
  1020. KANJI = 0x19 # IME Kanji Mode Key
  1021. MODECHANGE = 0x1F # IME Mode Change Request Key
  1022. INSERT = 0x2D # Insert Key
  1023. NUMLOCK = 0x90 # Num Lock Key
  1024. SCROLL = 0x91 # Scroll Lock Key
  1025. #--------------------------------------------------------------------------
  1026. # * Chaves OEM, variadas
  1027. #--------------------------------------------------------------------------
  1028. OEM_1 = 0xBA # Misc Characters (; : in USA 101/102 Keyboards)
  1029. OEM_PLUS = 0xBB # + = Key
  1030. OEM_COMMA = 0xBC # , < Key
  1031. OEM_MINUS = 0xBD # - _ Key
  1032. OEM_PERIOD = 0xBE # . > Key
  1033. OEM_2 = 0xBF # Misc Characters (/ ? in USA 101/102 Keyboards)
  1034. OEM_3 = 0xC0 # Misc Characters (` ~ in USA 101/102 Keyboards)
  1035. OEM_4 = 0xDB # Misc Characters ([ { in USA 101/102 Keyboards)
  1036. OEM_5 = 0xDC # Misc Characters (\ | in USA 101/102 Keyboards)
  1037. OEM_6 = 0xDD # Misc Characters (] } in USA 101/102 Keyboards)
  1038. OEM_7 = 0xDE # Misc Characters (' " in USA 101/102 Keyboards)
  1039. OEM_8 = 0xDF # Misc Characters (Varies by Keyboard)
  1040. OEM_9 = 0xE1 # OEM Specific
  1041. OEM_10 = 0x92 # OEM Specific
  1042. OEM_11 = 0x93 # OEM Specific
  1043. OEM_12 = 0x94 # OEM Specific
  1044. OEM_13 = 0x95 # OEM Specific
  1045. OEM_14 = 0x96 # OEM Specific
  1046. OEM_15 = 0xE3 # OEM Specific
  1047. OEM_16 = 0xE4 # OEM Specific
  1048. OEM_17 = 0xE6 # OEM Specific
  1049. OEM_18 = 0xE9 # OEM Specific
  1050. OEM_19 = 0xEA # OEM Specific
  1051. OEM_20 = 0xEB # OEM Specific
  1052. OEM_21 = 0xEC # OEM Specific
  1053. OEM_22 = 0xED # OEM Specific
  1054. OEM_23 = 0xEE # OEM Specific
  1055. OEM_24 = 0xEF # OEM Specific
  1056. OEM_25 = 0xF1 # OEM Specific
  1057. OEM_26 = 0xF2 # OEM Specific
  1058. OEM_27 = 0xF3 # OEM Specific
  1059. OEM_28 = 0xF4 # OEM Specific
  1060. OEM_29 = 0xF5 # OEM Specific
  1061. OEM_102 = 0xE2 # Angle Bracket or Backslash on RT-102 Keyboards
  1062. OEM_CLEAR = 0xFE # Clear Key
  1063. #--------------------------------------------------------------------------
  1064. # * Variáveis do módulo.
  1065. #--------------------------------------------------------------------------
  1066. @unpack_string = 'b'*256
  1067. @last_array = '0'*256
  1068. @press = Array.new(256, false)
  1069. @trigger = Array.new(256, false)
  1070. @repeat = Array.new(256, false)
  1071. @release = Array.new(256, false)
  1072. @repeat_counter = Array.new(256, 0)
  1073. @getKeyboardState = API::GetKeyboardState
  1074. @getAsyncKeyState = API::GetAsyncKeyState
  1075. @getKeyboardState.call(@last_array)
  1076. @last_array = @last_array.unpack(@unpack_string)
  1077. for i in 0...@last_array.size
  1078. @press[i] = @getAsyncKeyState.call(i) == 0 ? false : true
  1079. end
  1080. #--------------------------------------------------------------------------
  1081. # * Atualização dos objetos do módulo.
  1082. #--------------------------------------------------------------------------
  1083. def update
  1084. @trigger = Array.new(256, false)
  1085. @repeat = Array.new(256, false)
  1086. @release = Array.new(256, false)
  1087. array = '0'*256
  1088. @getKeyboardState.call(array)
  1089. array = array.unpack(@unpack_string)
  1090. for i in 0...array.size
  1091. if array[i] != @last_array[i]
  1092. @press[i] = @getAsyncKeyState.call(i) == 0 ? false : true
  1093. if @repeat_counter[i] <= 0 && @press[i]
  1094. @repeat[i] = true
  1095. @repeat_counter[i] = 15
  1096. end
  1097. if !@press[i]
  1098. @release[i] = true
  1099. else
  1100. @trigger[i] = true
  1101. end
  1102. else
  1103. if @press[i] == true
  1104. @press[i] = @getAsyncKeyState.call(i) == 0 ? false : true
  1105. @release[i] = true if !@press[i]
  1106. end
  1107. if @repeat_counter[i] > 0 && @press[i] == true
  1108. @repeat_counter[i] -= 1
  1109. elsif @repeat_counter[i] <= 0 && @press[i] == true
  1110. @repeat[i] = true
  1111. @repeat_counter[i] = 3
  1112. elsif @repeat_counter[i] != 0
  1113. @repeat_counter[i] = 0
  1114. end
  1115. end
  1116. end
  1117. @last_array = array
  1118. end
  1119. #--------------------------------------------------------------------------
  1120. # * Get Key Pressed State
  1121. # key : key index
  1122. #--------------------------------------------------------------------------
  1123. def press?(key)
  1124. return @press[key]
  1125. end
  1126. #--------------------------------------------------------------------------
  1127. # * Get Key Triggered State
  1128. # key : key index
  1129. #--------------------------------------------------------------------------
  1130. def trigger?(key)
  1131. return @trigger[key]
  1132. end
  1133. #--------------------------------------------------------------------------
  1134. # * Get Key Repeated State
  1135. # key : key index
  1136. #--------------------------------------------------------------------------
  1137. def repeat?(key)
  1138. return @repeat[key]
  1139. end
  1140. #--------------------------------------------------------------------------
  1141. # * Get Key Released State
  1142. # key : key index
  1143. #--------------------------------------------------------------------------
  1144. def release?(key)
  1145. return @release[key]
  1146. end
  1147. end
  1148. #==============================================================================
  1149. # • Sprite
  1150. #==============================================================================
  1151. Dax.register(:sprite)
  1152. class Sprite
  1153. #----------------------------------------------------------------------------
  1154. # • Variáveis públicas da instância.
  1155. #----------------------------------------------------------------------------
  1156. attr_accessor :clone_sprite
  1157. #----------------------------------------------------------------------------
  1158. # • Novo método.
  1159. #----------------------------------------------------------------------------
  1160. alias new_initialize initialize
  1161. def initialize(viewport=nil)
  1162. @clone_sprite = []
  1163. if viewport.is_a?(String)
  1164. new_initialize(nil)
  1165. if viewport.match(/S: ([^>]*)/)
  1166. self.bitmap = Cache.system($1.to_s)
  1167. elsif viewport.match(/P: ([^>]*)/)
  1168. self.bitmap = Cache.picture($1.to_s)
  1169. elsif viewport.match(/G: ([^>]*)/)
  1170. self.bitmap = Bitmap.new("Graphics/#{$1.to_s}")
  1171. else
  1172. self.bitmap = Bitmap.new(viewport)
  1173. end
  1174. elsif viewport.is_a?(Array)
  1175. if viewport.size == 2
  1176. new_initialize(nil)
  1177. self.bitmap = Bitmap.new(viewport[0], viewport[1])
  1178. elsif viewport.size == 5
  1179. new_initialize(nil)
  1180. self.bitmap = Bitmap.new(viewport[0], viewport[1])
  1181. self.x, self.y, self.z = viewport[2], viewport[3], viewport[4]
  1182. end
  1183. elsif viewport.is_a?(Viewport) or viewport.nil?
  1184. new_initialize(viewport)
  1185. end
  1186. end
  1187. #----------------------------------------------------------------------------
  1188. # • Slide pela direita.
  1189. # * speed : Velocidade | point : Ponto da coordenada X que irá chegar.
  1190. #----------------------------------------------------------------------------
  1191. def slide_right(speed, point)
  1192. self.x += speed unless self.x >= point
  1193. end
  1194. #----------------------------------------------------------------------------
  1195. # • Slide pela esquerda.
  1196. # * speed : Velocidade | point : Ponto da coordenada X que irá chegar.
  1197. #----------------------------------------------------------------------------
  1198. def slide_left(speed, point)
  1199. self.x -= speed unless self.x <= point
  1200. end
  1201. #----------------------------------------------------------------------------
  1202. # • Slide por cima.
  1203. # * speed : Velocidade | point : Ponto da coordenada Y que irá chegar.
  1204. #----------------------------------------------------------------------------
  1205. def slide_up(speed, point)
  1206. self.y -= speed unless self.y <= point
  1207. end
  1208. #----------------------------------------------------------------------------
  1209. # • Slide por baixo.
  1210. # * speed : Velocidade | point : Ponto da coordenada Y que irá chegar.
  1211. #----------------------------------------------------------------------------
  1212. def slide_down(speed, point)
  1213. self.y += speed unless self.y >= point
  1214. end
  1215. #----------------------------------------------------------------------------
  1216. # • Define aqui uma posição fixa para um objeto.
  1217. #----------------------------------------------------------------------------
  1218. def position(command=0)
  1219. return if command.nil?
  1220. case command
  1221. when 0 then self.x = 0
  1222. when 1 then self.x = (Graphics.width - self.width) / 2
  1223. when 2 then self.x = Graphics.width - self.width
  1224. when 3 then self.y = 0
  1225. when 4 then self.y = (Graphics.height - self.height) / 2
  1226. when 5 then self.y = Graphics.height - self.height
  1227. when :center
  1228. self.x = (Graphics.width - self.width) / 2
  1229. self.y = Graphics.height / 2 - self.height / 2
  1230. when :center_left
  1231. self.x = 0
  1232. self.y = (Graphics.height - self.height) / 2
  1233. when :center_right
  1234. self.x = Graphics.width - self.height
  1235. self.y = (Graphics.height - self.height) / 2
  1236. end
  1237. end
  1238. #----------------------------------------------------------------------------
  1239. # • Tamanho geral
  1240. #----------------------------------------------------------------------------
  1241. def size
  1242. return self.width + self.height
  1243. end
  1244. #----------------------------------------------------------------------------
  1245. # • Rect
  1246. #----------------------------------------------------------------------------
  1247. def rect
  1248. return self.bitmap.rect
  1249. end
  1250. #----------------------------------------------------------------------------
  1251. # • Base para função de clone.
  1252. # * depht : Prioridade no mapa.
  1253. # * clone_bitmap : Se irá clonar o bitmap.
  1254. #----------------------------------------------------------------------------
  1255. def clone(depht=0, clone_bitmap=false)
  1256. @clone_sprite.delete_if { |bitmap| bitmap.disposed? }
  1257. cloned = Sprite.new(self.viewport)
  1258. cloned.x, cloned.y = self.x, self.y
  1259. cloned.bitmap = self.bitmap
  1260. cloned.bitmap = self.bitmap.clone if clone_bitmap
  1261. unless depht == 0
  1262. cloned.z = self.z + depht
  1263. else
  1264. @clone_sprite.each { |sprite| sprite.z -= 1 }
  1265. cloned.z = self.z - 1
  1266. end
  1267. cloned.src_rect.set(self.src_rect)
  1268. ["zoom_x", "zoom_y", "angle", "mirror", "opacity", "blend_type", "visible",
  1269. "bush_depht", "bush_opacity", "ox", "oy"].each { |meth|
  1270. eval("cloned.#{meth} = self.#{meth}")
  1271. }
  1272. cloned.color.set(color)
  1273. cloned.tone.set(tone)
  1274. after_clone(cloned)
  1275. @clone_sprite.push(cloned)
  1276. return cloned
  1277. end
  1278. #----------------------------------------------------------------------------
  1279. # • Efeito após ter clonado.
  1280. #----------------------------------------------------------------------------
  1281. def after_clone(clone)
  1282. end
  1283. end
  1284. #==============================================================================
  1285. # • Bitmap
  1286. #==============================================================================
  1287. Dax.register(:bitmap)
  1288. class Bitmap
  1289. #-------------------------------------------------------------------------
  1290. # Desenhar meter... Gradient
  1291. #-------------------------------------------------------------------------
  1292. def draw_meter_line(x, y, min, max, width = 156, height = 4,
  1293. bar_start = Color.new(255, 0, 0, 192), bar_end = Color.new(255, 255, 0, 192),
  1294. background = Color.new(0, 0, 0, 128))
  1295. w = width * min / max
  1296. 4.times do
  1297. fill_rect(x + 8, y + 4, width, height / 4, background)
  1298. draw_gradient_line(x, y, x + w, y, height / 4, bar_start, bar_end)
  1299. x -= 1
  1300. y += height / 4
  1301. end
  1302. end
  1303. #----------------------------------------------------------------------------
  1304. # • Definir gradiente..
  1305. #----------------------------------------------------------------------------
  1306. def gradient_color(colors, width, percentage)
  1307. width_per = ((width * 1.0) * percentage)
  1308. width_per = width_per.round
  1309. if colors.size == 1
  1310. return colors[0]
  1311. elsif colors.size > 1
  1312. i = 0
  1313. sections_per = (1.0 / colors.size)
  1314. equationa = (sections_per * colors.size)
  1315. equationb = (sections_per * (colors.size - 1))
  1316. if equationa >= percentage and equationb < percentage
  1317. i = (colors.size - 1)
  1318. else
  1319. for j in 0..(colors.size - 1)
  1320. equationc = (sections_per * (j + 1))
  1321. equationd = (sections_per * (j + 2))
  1322. if equationc < percentage and equationd > percentage
  1323. i = j + 1
  1324. end
  1325. end
  1326. end
  1327. if i == (colors.size - 1)
  1328. for k in 0..width
  1329. if k == width_per
  1330. r = colors[i - 1].red * (width - k) / width + colors[i].red * k / width
  1331. g = colors[i - 1].green * (width - k) / width + colors[i].green * k / width
  1332. b = colors[i - 1].blue * (width - k) / width + colors[i].blue * k / width
  1333. a = colors[i - 1].alpha * (width - k) / width + colors[i].alpha * k / width
  1334. return Color.new(r,g,b,a)
  1335. end
  1336. end
  1337. else
  1338. for k in 0..width
  1339. if k == width_per
  1340. r = colors[i].red * (width - k) / width + colors[i + 1].red * k / width
  1341. g = colors[i].green * (width - k) / width + colors[i + 1].green * k / width
  1342. b = colors[i].blue * (width - k) / width + colors[i + 1].blue * k / width
  1343. a = colors[i].alpha * (width - k) / width + colors[i + 1].alpha * k / width
  1344. return Color.new(r,g,b,a)
  1345. end
  1346. end
  1347. end
  1348. elsif colors.size < 1
  1349. msgbox 'ERROR : No Colors Were Supplied'
  1350. exit
  1351. end
  1352. end
  1353. #----------------------------------------------------------------------------
  1354. # • Barra.
  1355. #----------------------------------------------------------------------------
  1356. def bar(color, actual, max, borda=1)
  1357. rate = self.width.to_p(actual, max)
  1358. self.fill_rect(borda, borda, rate-(borda*2), self.height-(borda*2),
  1359. color)
  1360. end
  1361. #----------------------------------------------------------------------------
  1362. # • Barra em forma de gradient;.
  1363. #----------------------------------------------------------------------------
  1364. def gradient_bar(color, actual, max, borda=1)
  1365. rate = self.width.to_p(actual, max)
  1366. self.gradient_fill_rect(borda, borda, rate-(borda*2), self.height-(borda*2),
  1367. color[0], color[1], 2)
  1368. end
  1369. #----------------------------------------------------------------------------
  1370. # • Efeito de Shader Sill
  1371. #----------------------------------------------------------------------------
  1372. def shader_sill
  1373. ra = 500
  1374. re = 0 ; gr = 0 ; bl = 0
  1375. for i in 1..(self.height-1)
  1376. for j in 1..(self.width-1)
  1377. for m in -1..1
  1378. for n in -1..1
  1379. if m != 0 and n != 0
  1380. a = self.get_pixel(j+m,i+n)
  1381. re = re + a.red
  1382. gr = gr + a.green
  1383. bl = bl + a.blue
  1384. end
  1385. end
  1386. end
  1387. b = self.get_pixel(j,i)
  1388. re = (b.red-re/8).abs
  1389. gr = (b.green-gr/8).abs
  1390. bl = (b.blue-bl/8).abs
  1391. self.set_pixel(j,i,Color.new(0, 0, 0, b.alpha) )
  1392. end
  1393. end
  1394. end
  1395. #--------------------------------------------------------------------------
  1396. # * Desenho do gráfico do personagem
  1397. # character_name : nome do gráfico do personagem
  1398. # character_index : índice do gráfico de personagem
  1399. # x : coordenada X
  1400. # y : coordenada Y
  1401. #--------------------------------------------------------------------------
  1402. def draw_character(character_name, character_index, x, y)
  1403. return unless character_name
  1404. bitmap = Cache.character(character_name)
  1405. sign = character_name[/^[\!\$]./]
  1406. if sign && sign.include?('$')
  1407. cw = bitmap.width / 3
  1408. ch = bitmap.height / 4
  1409. else
  1410. cw = bitmap.width / 12
  1411. ch = bitmap.height / 8
  1412. end
  1413. n = character_index
  1414. src_rect = Rect.new((n%4*3+1)*cw, (n/4*4)*ch, cw, ch)
  1415. self.blt(x - cw / 2, y - ch, bitmap, src_rect)
  1416. end
  1417. #--------------------------------------------------------------------------
  1418. # * Desenho do gráfico de personagem do herói
  1419. # actor : herói
  1420. # x : coordenada X
  1421. # y : coordenada Y
  1422. #--------------------------------------------------------------------------
  1423. def draw_actor_graphic(actor, x, y)
  1424. draw_character(actor.character_name, actor.character_index, x, y)
  1425. end
  1426. #----------------------------------------------------------------------------
  1427. # • Limpar uma área num formato de círculo.
  1428. #----------------------------------------------------------------------------
  1429. def clear_rect_circle(x, y, r)
  1430. rr = r*r
  1431. for i in 0...r
  1432. adj = Math.sqrt(rr - (i*i)).ceil
  1433. xd = x - adj
  1434. wd = 2 * adj
  1435. self.clear_rect(xd, y-i, wd, 1)
  1436. self.clear_rect(xd, y+i, wd, 1)
  1437. end
  1438. end
  1439. #----------------------------------------------------------------------------
  1440. # • Novo modo de desenhar textos. Configurações já especificadas.
  1441. #----------------------------------------------------------------------------
  1442. def draw_text_rect(*args)
  1443. self.draw_text(self.rect, *args)
  1444. end
  1445. #----------------------------------------------------------------------------
  1446. # • Salvar em png.
  1447. # --- Autor : Gab! ---
  1448. #----------------------------------------------------------------------------
  1449. def save(file_name)
  1450. def chunk(type, data)
  1451. [data.size, type, data, Zlib.crc32(type + data)].pack("NA4A*N")
  1452. end
  1453. img_data = ""
  1454. width, height = self.width, self.height
  1455. for j in 0...(height)
  1456. img_data << "\0"
  1457. for i in 0...(width)
  1458. pos_c = self.get_pixel(i, j)
  1459. img_data << [pos_c.red, pos_c.green, pos_c.blue, pos_c.alpha].pack("C*")
  1460. end
  1461. end
  1462. c = [
  1463. "\x89PNG\r\n\x1a\n",
  1464. chunk("IHDR", [width, height, 8, 6, 0, 0, 0].pack("N2C5")),
  1465. chunk("IDAT", Zlib::Deflate.deflate(img_data)),
  1466. chunk("IEND", "")
  1467. ]
  1468. File.open(file_name, "wb"){|file| c.each{|chunk| file.write(chunk) }}
  1469. end
  1470. #----------------------------------------------------------------------------
  1471. # • Efeito negativo.
  1472. #----------------------------------------------------------------------------
  1473. def negative
  1474. for i in 0...(self.width)
  1475. for j in 0...(self.height)
  1476. pix = self.get_pixel(i, j)
  1477. pix.red = (pix.red - 255) * -1
  1478. pix.blue = (pix.blue - 255) * -1
  1479. pix.green = (pix.green - 255) * -1
  1480. self.set_pixel(i, j, pix)
  1481. end
  1482. end
  1483. end
  1484. #----------------------------------------------------------------------------
  1485. # • Grayscale
  1486. #----------------------------------------------------------------------------
  1487. def grayscale(rect = Rect.new(0, 0, self.width, self.height))
  1488. for i in rect.x...rect.x + rect.width
  1489. for j in rect.y...rect.y + rect.height
  1490. colour = self.get_pixel(i,j)
  1491. grey_pixel = (colour.red*0.3 + colour.green*0.59 + colour.blue*0.11)
  1492. colour.red = colour.green = colour.blue = grey_pixel
  1493. self.set_pixel(i,j,colour)
  1494. end
  1495. end
  1496. end
  1497. #----------------------------------------------------------------------------
  1498. # • Novo fornecedor de pixel.
  1499. #----------------------------------------------------------------------------
  1500. def set_pixel_s(x, y, color, size)
  1501. for i in 0...size
  1502. self.set_pixel(x+i, y, color)
  1503. self.set_pixel(x-i, y, color)
  1504. self.set_pixel(x, y+i, color)
  1505. self.set_pixel(x, y-i, color)
  1506. self.set_pixel(x+i, y+i, color)
  1507. self.set_pixel(x-i, y-i, color)
  1508. self.set_pixel(x+i, y-i, color)
  1509. self.set_pixel(x-i, y+i, color)
  1510. end
  1511. end
  1512. #----------------------------------------------------------------------------
  1513. # • Desenhar uma linha.
  1514. #----------------------------------------------------------------------------
  1515. def draw_line(start_x, start_y, end_x, end_y, color, size=1)
  1516. set_pixel_s(start_x, start_y, color, size)
  1517. distance = (start_x - end_x).abs + (start_y - end_y).abs
  1518. for i in 1..distance
  1519. x = (start_x + 1.0 * (end_x - start_x) * i / distance).to_i
  1520. y = (start_y + 1.0 * (end_y - start_y) * i / distance).to_i
  1521. set_pixel_s(x, y, color, size)
  1522. end
  1523. set_pixel_s(end_x, end_y, color, size)
  1524. end
  1525. #----------------------------------------------------------------------------
  1526. # • draw_bar_gauge(x, y, current, current_max, border, colors)
  1527. # x : Coordenadas X.
  1528. # y : Coordenadas Y.
  1529. # current : Valor atual da barra.
  1530. # current_max : Valor maxímo da barra.
  1531. # border : Expressura da borda.
  1532. # colors : Cores. [0, 1, 2]
  1533. #----------------------------------------------------------------------------
  1534. # Permite adicionar uma barra.
  1535. #----------------------------------------------------------------------------
  1536. def draw_bar_gauge(x, y, current, current_max, colors=[])
  1537. cw = self.width.to_p(current, current_max)
  1538. ch = self.height
  1539. self.gradient_fill_rect(x, y, self.width, self.height, colors[0], colors[1])
  1540. src_rect = Rect.new(0, 0, cw, ch)
  1541. self.blt(x, y, self, src_rect)
  1542. end
  1543. #----------------------------------------------------------------------------
  1544. # • draw_icon(icon_index, x, y, enabled)
  1545. # icon_index : ID do ícone.
  1546. # x : Coordenadas X.
  1547. # y : Coordenadas Y.
  1548. # enabled : Habilitar flag, translucido quando false
  1549. #----------------------------------------------------------------------------
  1550. #----------------------------------------------------------------------------
  1551. def draw_icon(icon_index, x, y, enabled = true)
  1552. icon_index = icon_index.nil? ? 0 : icon_index
  1553. bitmap = Cache.system("Iconset")
  1554. rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  1555. self.blt(x, y, bitmap, rect, enabled ? 255 : 128)
  1556. end
  1557. #----------------------------------------------------------------------------
  1558. # • draw_gradation_gauge(x, y, width, height, current, current_max, border, colors, align)
  1559. # x : Coordenadas X.
  1560. # y : Coordenadas Y.
  1561. # width : Largura da barra.
  1562. # height : Altura da barra.
  1563. # current : Valor atual da barra.
  1564. # current_max : Valor maxímo da barra.
  1565. # border : Expressura da borda.
  1566. # colors : Cores. [0, 1, 2]
  1567. # align : Alinhamento.
  1568. #----------------------------------------------------------------------------
  1569. # Permite adicionar uma barra.
  1570. #----------------------------------------------------------------------------
  1571. def draw_gradation_gauge(x, y, current, current_max, border, colors=[])
  1572. cw = self.width.to_p(current, current_max)
  1573. ch = self.height
  1574. self.fill_rect(x, y, self.width, self.height, colors[0])
  1575. self.gradient_fill_rect(x+border, y+border, self.width-(border/2), self.height-(border/2), colors[1], colors[2])
  1576. src_rect = Rect.new(0, 0, cw, ch)
  1577. self.blt(x, y, self, src_rect)
  1578. end
  1579. #--------------------------------------------------------------------------
  1580. # • Desenho do gráfico de rosto
  1581. # face_name : nome do gráfico de face
  1582. # face_index : índice do gráfico de face
  1583. # x : coordenada X
  1584. # y : coordenada Y
  1585. # enabled : habilitar flag, translucido quando false
  1586. #--------------------------------------------------------------------------
  1587. def draw_face(face_name, face_index, x, y, enabled = true)
  1588. bitmap = Cache.face(face_name)
  1589. rect = Rect.new(face_index % 4 * 96, face_index / 4 * 96, 96, 96)
  1590. self.blt(x, y, bitmap, rect, enabled ? 255 : 128)
  1591. end
  1592. #--------------------------------------------------------------------------
  1593. # • Desenho do gráfico de face do herói
  1594. # actor : herói
  1595. # x : coordenada X
  1596. # y : coordenada Y
  1597. # enabled : habilitar flag, translucido quando false
  1598. #--------------------------------------------------------------------------
  1599. def draw_actor_face(actor, x, y, enabled = true)
  1600. draw_face(actor.face_name, actor.face_index, x, y, enabled)
  1601. end
  1602. #--------------------------------------------------------------------------
  1603. # • Desenho do nível
  1604. # actor : herói
  1605. # x : coordenada X
  1606. # y : coordenada Y
  1607. #--------------------------------------------------------------------------
  1608. def draw_actor_level(actor, x, y)
  1609. self.font.name = "Comic Sans MS"
  1610. self.font.color = ColorBasic[35]
  1611. self.font.size = 18
  1612. self.draw_text(x, y, 32, 20, Vocab::level_a)
  1613. self.font.size = 22
  1614. draw_text(x + 16, y, 32, 20, actor.level, 2)
  1615. end
  1616. #----------------------------------------------------------------------------
  1617. # • Desenhar um círuclo preenchido.
  1618. #----------------------------------------------------------------------------
  1619. def fill_circle(x, y, r, c)
  1620. rr = r*r
  1621. for i in 0...r
  1622. adj = Math.sqrt(rr - (i*i)).ceil
  1623. xd = x - adj
  1624. wd = 2 * adj
  1625. self.fill_rect(xd, y-i, wd, 1, c)
  1626. self.fill_rect(xd, y+i, wd, 1, c)
  1627. end
  1628. end
  1629. #----------------------------------------------------------------------------
  1630. # • Desenhar um triângulo preenchido
  1631. #----------------------------------------------------------------------------
  1632. def fill_triangle3(pts, c, pos=[0, 0])
  1633. return if pts.size != 3
  1634. pts.sort! {|a, b| a[1] - b[1]}
  1635. pt1, pt2, pt3 = pts
  1636. dxt = (pt3[0] - pt1[0]) / 2
  1637. dyt = (pt3[1] - pt1[1]) / 2
  1638. dxm = pt2[0] - pt1[0]
  1639. dym = pt2[1] - pt1[1]
  1640. dm = dym.abs
  1641. if dm > 0 and dyt != 0
  1642. for i in 0...(dm+2)
  1643. ix = ((dxm*i) / (dm+1))
  1644. iy = ((dym*i) / (dm+1))
  1645. edx = ix - (dxt * iy / dyt)
  1646. self.fill_rect(ix+pt1[0]-[edx,0].max-2+pos[0], iy+pt1[1]+pos[1], edx.abs+4, 1, c)
  1647. end
  1648. end
  1649. dxm = pt2[0] - pt3[0]
  1650. dym = pt2[1] - pt3[1]
  1651. dm = dym.abs
  1652. if dm > 0 and dyt != 0
  1653. for i in 0...(dm+2)
  1654. ix = ((dxm*i) / (dm+1))
  1655. iy = ((dym*i) / (dm+1))
  1656. edx = ix - (dxt * iy / dyt)
  1657. self.fill_rect(ix+pt3[0]-[edx,0].max-2+pos[0], iy+pt3[1]+pos[1], edx.abs+4, 1, c)
  1658. end
  1659. end
  1660. end
  1661. #----------------------------------------------------------------------------
  1662. # • Desenhar um polígono.
  1663. #----------------------------------------------------------------------------
  1664. def fill_polygon(pts, c, pos=[0, 0])
  1665. return if pts.size <= 2
  1666. n = pts.size - 2
  1667. for i in 0...n
  1668. self.fill_triangle3(pts[i..(i + 2)], c, pos)
  1669. end
  1670. end
  1671. end
  1672. #==============================================================================
  1673. # • Mouse
  1674. #==============================================================================
  1675. Dax.register(:mouse, "Dax", 1.1)
  1676. module Mouse
  1677. extend self
  1678. #--------------------------------------------------------------------------
  1679. # • Inicialização dos objetos.
  1680. #--------------------------------------------------------------------------
  1681. def start
  1682. @cursor = Sprite.new
  1683. @cursor.z = 100000
  1684. @cursor.bitmap = Bitmap.new(1, 1)
  1685. x = Dax::Mouse_Name == "" ? 1 : 0
  1686. API::MouseShowCursor.call(x)
  1687. @dgraphic = Dax::Mouse_Name
  1688. graphic Dax::Mouse_Name
  1689. update
  1690. end
  1691. #----------------------------------------------------------------------------
  1692. # • visible = (boolean)
  1693. # * boolean : true ou false
  1694. # Tornar vísivel ou não o cursor do Mouse.
  1695. #----------------------------------------------------------------------------
  1696. def visible=(boolean)
  1697. API::MouseShowCursor.call(boolean.visible.boolean_number)
  1698. end
  1699. #--------------------------------------------------------------------------
  1700. # • graphic(graphic_set)
  1701. # graphic_set : Se for número é um ícone; Se for string é uma imagem.
  1702. #--------------------------------------------------------------------------
  1703. def graphic(graphic_set)
  1704. return if graphic_set == "" or graphic_set.nil?
  1705. if graphic_set.is_a?(Fixnum)
  1706. @cursor.bitmap = Bitmap.new(24, 24)
  1707. @cursor.bitmap.draw_icon(graphic_set.to_i, 0, 0)
  1708. else
  1709. @cursor.bitmap = Cache.picture(graphic_set.to_s)
  1710. end
  1711. @dgraphic = graphic_set
  1712. end
  1713. #--------------------------------------------------------------------------
  1714. # • show(visible)
  1715. # visible : True - para mostrar o mouse | False - para esconder o mouse.
  1716. #--------------------------------------------------------------------------
  1717. def show(visible=true)
  1718. @cursor.visible = visible
  1719. end
  1720. #--------------------------------------------------------------------------
  1721. # • update (Atualização das coordenadas)
  1722. #--------------------------------------------------------------------------
  1723. def update
  1724. return if @cursor.nil?
  1725. @cursor.x, @cursor.y = position
  1726. end
  1727. #--------------------------------------------------------------------------
  1728. # • cursor
  1729. #--------------------------------------------------------------------------
  1730. def cursor
  1731. @cursor
  1732. end
  1733. #--------------------------------------------------------------------------
  1734. # • x (Coordenada X do Mouse)
  1735. #--------------------------------------------------------------------------
  1736. def x
  1737. @cursor.x
  1738. end
  1739. #--------------------------------------------------------------------------
  1740. # • y (Coordenada Y do Mouse)
  1741. #--------------------------------------------------------------------------
  1742. def y
  1743. @cursor.y
  1744. end
  1745. #--------------------------------------------------------------------------
  1746. # • position (Posição do Mouse!)
  1747. #--------------------------------------------------------------------------
  1748. def position
  1749. x, y = get_client_position
  1750. return x, y
  1751. end
  1752. #--------------------------------------------------------------------------
  1753. # • get_client_position (Posição original do Mouse!)
  1754. #--------------------------------------------------------------------------
  1755. def get_client_position
  1756. pos = [0, 0].pack('ll')
  1757. API::CursorPosition.call(pos)
  1758. API::ScreenToClient.call(WINDOW, pos)
  1759. return pos.unpack('ll')
  1760. end
  1761. #--------------------------------------------------------------------------
  1762. # • find_window (Tamanho da window)
  1763. #--------------------------------------------------------------------------
  1764. def find_window
  1765. game_name = '\0' * 256
  1766. API::ReadIni.call('Game', 'Title', '', game_name, 255, '.\\Game.ini')
  1767. game_name.delete!('\0') ensure game_name
  1768. return API::FindWindow.call('RGSS Player', game_name)
  1769. end
  1770. #--------------------------------------------------------------------------
  1771. # • Verificação se o mouse está na área de um determinado objeto.
  1772. #--------------------------------------------------------------------------
  1773. def in_area?(object_sprite)
  1774. return @cursor.x.between?(object_sprite.x, object_sprite.x + object_sprite.width) &&
  1775. @cursor.y.between?(object_sprite.y, object_sprite.y + object_sprite.height)
  1776. end
  1777. #----------------------------------------------------------------------------
  1778. # • Mudar posição do cursor.
  1779. #----------------------------------------------------------------------------
  1780. def set_mouse(pos)
  1781. SetCursorPos.call(pos.x, pos.y)
  1782. update
  1783. @cursor.x = @pos.x
  1784. @cursor.y = @pos.y
  1785. end
  1786. WINDOW = find_window
  1787. end
  1788.  
  1789. #==============================================================================
  1790. # • Object
  1791. #==============================================================================
  1792. Dax.register(:object)
  1793. class Object
  1794. #----------------------------------------------------------------------------
  1795. # • O que irá ocorrer caso o mouse esteja sobre uma sprite.
  1796. # Tem que ser um objeto Sprite.
  1797. #----------------------------------------------------------------------------
  1798. def if_mouse_over(&block)
  1799. return unless self.is_a?(Sprite) or block_given?
  1800. over ||= false
  1801. if Mouse.in_area?(self)
  1802. block.call
  1803. over = true
  1804. else
  1805. over = false
  1806. end
  1807. yield over
  1808. end
  1809. #----------------------------------------------------------------------------
  1810. # • O que irá ocorrer caso o mouse esteja sobre uma sprite, e ao clicar.
  1811. # Tem que ser um objeto Sprite.
  1812. # * button : Button : (:right - botão direito do mouse | :left - botão esq.)
  1813. #----------------------------------------------------------------------------
  1814. def if_mouse_click(button=:left, &block)
  1815. return unless self.is_a?(Sprite) or block_given?
  1816. button = button == :left ? 0x01 : button == :right ? 0x02 : 0x01
  1817. block.call if Mouse.in_area?(self) and trigger?(button)
  1818. end
  1819. #----------------------------------------------------------------------------
  1820. # • Profunda cópia
  1821. #----------------------------------------------------------------------------
  1822. def deep_clone
  1823. Marshal.load(Marshal.dump(self))
  1824. end
  1825. #----------------------------------------------------------------------------
  1826. # * Trigger ou Repeat
  1827. #----------------------------------------------------------------------------
  1828. def trigger_or_repeat?(key)
  1829. trigger?(key) or repeat?(key)
  1830. end
  1831. #----------------------------------------------------------------------------
  1832. # • Trigger
  1833. # * key : Chave.
  1834. # Você também pode usá-lo como condição para executar tal bloco;
  1835. #----------------------------------------------------------------------------
  1836. # trigger?(key) { bloco que irá executar }
  1837. #----------------------------------------------------------------------------
  1838. def trigger?(key, &block)
  1839. ckey = key.is_a?(Symbol) ? Input.trigger?(key) : Key.trigger?(key)
  1840. return ckey unless block_given?
  1841. block.call if ckey
  1842. end
  1843. #----------------------------------------------------------------------------
  1844. # • Press
  1845. #----------------------------------------------------------------------------
  1846. def press?(key, &block)
  1847. ckey = key.is_a?(Symbol) ? Input.press?(key) : Key.press?(key)
  1848. return ckey unless block_given?
  1849. block.call if ckey
  1850. end
  1851. #----------------------------------------------------------------------------
  1852. # • Repeat
  1853. #----------------------------------------------------------------------------
  1854. def repeat?(key)
  1855. ckey = key.is_a?(Symbol) ? Input.repeat?(key) : Key.repeat?(key)
  1856. return ckey unless block_given?
  1857. block.call if ckey
  1858. end
  1859. #----------------------------------------------------------------------------
  1860. # • Retorna em forma de número.. os valores Boolean.
  1861. #----------------------------------------------------------------------------
  1862. def boolean_number
  1863. return self ? 1 : 0
  1864. end
  1865. #----------------------------------------------------------------------------
  1866. # • Converte para a classe Position.
  1867. #----------------------------------------------------------------------------
  1868. def position
  1869. return Position.new(self, self) if self.is_class?(Numeric)
  1870. return Position.new(self.x, self.y) if self.is_class?(Sprite) or self.is_class?(Window_Base)
  1871. return Position.new(0, 0)
  1872. end
  1873. end
  1874. #==============================================================================
  1875. # • Entries
  1876. #==============================================================================
  1877. Dax.register(:entries)
  1878. class Entries
  1879. #----------------------------------------------------------------------------
  1880. # • Variável pública da instância.
  1881. #----------------------------------------------------------------------------
  1882. attr_accessor :file
  1883. attr_reader :get_number
  1884. attr_reader :get_file
  1885. attr_reader :get_array
  1886. attr_reader :name
  1887. #----------------------------------------------------------------------------
  1888. # • Inicialização dos objetos.
  1889. #----------------------------------------------------------------------------
  1890. def initialize(directory, typefile)
  1891. return unless FileTest.directory?(directory)
  1892. @file = Dir.glob(directory + "/*.{" + typefile + "}")
  1893. @file.each_index { |i| @get_number = i.to_i }
  1894. @file.each { |i| @get_file = i.to_s }
  1895. @file.each_with_index { |i| @get_array = i }
  1896. @name = split @file[0]
  1897. end
  1898. #----------------------------------------------------------------------------
  1899. # • Split | Separar
  1900. #----------------------------------------------------------------------------
  1901. def split(file)
  1902. file.to_s.split('/').last
  1903. end
  1904. #----------------------------------------------------------------------------
  1905. # • Obter nome.
  1906. #----------------------------------------------------------------------------
  1907. def name(id)
  1908. return split(@file[id])
  1909. end
  1910. end
  1911. #==============================================================================
  1912. # • TextBase
  1913. #==============================================================================
  1914. Dax.register(:text_base)
  1915. class TextBase
  1916. #----------------------------------------------------------------------------
  1917. # • Inicialização dos objetos.
  1918. #----------------------------------------------------------------------------
  1919. def initialize
  1920. @text = ""
  1921. end
  1922. #----------------------------------------------------------------------------
  1923. # • Adicionar texto.
  1924. #----------------------------------------------------------------------------
  1925. def text=(text_add)
  1926. @text += text_add
  1927. end
  1928. #----------------------------------------------------------------------------
  1929. # • Adicionar uma nova linha.
  1930. #----------------------------------------------------------------------------
  1931. def text(text, nspace=0)
  1932. @text += "\r\n" + (" " * nspace) + text
  1933. end
  1934. #----------------------------------------------------------------------------
  1935. # • Adicionar comentário;
  1936. #----------------------------------------------------------------------------
  1937. def comment=(text_add, comment="#")
  1938. @text += comment + text_add
  1939. end
  1940. #----------------------------------------------------------------------------
  1941. # • Adicionar uma nova linha como comentário.
  1942. #----------------------------------------------------------------------------
  1943. def comment(text, nspace=0, comment="#")
  1944. @text += "\r\n" + (" " * nspace) + comment + text
  1945. end
  1946. #----------------------------------------------------------------------------
  1947. # • Salvar o texto.
  1948. #----------------------------------------------------------------------------
  1949. def save(filename="")
  1950. _file = File.open(filename, "a+").each { |file|
  1951. file.write(@text.to_s)
  1952. file.close
  1953. }
  1954. end
  1955. end
  1956. #==============================================================================
  1957. # • DRGSS | Comandos do RGSS...
  1958. #==============================================================================
  1959. Dax.register(:drgss)
  1960. module DRGSS
  1961. extend self
  1962. #----------------------------------------------------------------------------
  1963. # • Deleta a pasta, os arquivos.
  1964. #----------------------------------------------------------------------------
  1965. def recursive_delete(dir)
  1966. files = []
  1967. Dir.foreach(dir) do |fname|
  1968. next if fname == '.' || fname == '..'
  1969. path = dir + '/' + fname
  1970. if File.directory?(path)
  1971. puts "dir #{path}"
  1972. recursive_delete(path)
  1973. else
  1974. puts "file #{path}"
  1975. files << path
  1976. end
  1977. end
  1978. files.each do |path|
  1979. msgbox "delete file #{path}"
  1980. end
  1981. msgbox "delete dir #{dir}"
  1982. Dir.rmdir(dir)
  1983. end
  1984. #----------------------------------------------------------------------------
  1985. # • Deleta tudo.. Só use caso você saiba o que está fazendo
  1986. #----------------------------------------------------------------------------
  1987. def delete(directory)
  1988. if File.directory?(directory)
  1989. Dir.foreach(directory) do |file_or_directory|
  1990. File.delete(directory+"/"+file_or_directory) if file_or_directory != "." and file_or_directory != ".."
  1991. end
  1992. else
  1993. begin
  1994. File.delete(directory) if File.new(directory).stat.size == 0
  1995. rescue
  1996. msgbox "#{$!} Error in deleting zero size file "
  1997. end
  1998. end
  1999. end
  2000. #----------------------------------------------------------------------------
  2001. # • Extrair scripts.
  2002. #----------------------------------------------------------------------------
  2003. def extract_scripts(type=".txt",options={})
  2004. except = options[:except] || []
  2005. folder = options[:folder] || ""
  2006. id = 0 #
  2007. $RGSS_SCRIPTS.each do |script|
  2008. name = script[1]
  2009. data = script[3]
  2010. next if except.include? name or name.empty? or data.empty?
  2011. filename = sprintf("%03d", id) + "_" + name
  2012. p "Writing: #{filename}"
  2013. File.open(folder+filename+"#{type}", "wb") do |file|
  2014. file.write data
  2015. end
  2016. id += 1
  2017. end
  2018. end
  2019. #----------------------------------------------------------------------------
  2020. # • Carregar scripts.
  2021. #----------------------------------------------------------------------------
  2022. def load_scripts(type=".txt",options={})
  2023. skip = options[:skip] || []
  2024. folder = options[:folder] || ""
  2025. begin
  2026. Dir.foreach(folder) do |file|
  2027. file_id = file[0,3].to_i
  2028. break if file_id == options[:limit]
  2029. next if file == "." or file == ".." or File.extname(file) != "#{type}" or skip.include?(file_id)
  2030. r = load (folder+"#{file}")
  2031. p "Loaded: #{r}"
  2032. end
  2033. end
  2034. end
  2035. end
  2036. #==============================================================================
  2037. # • OutlineFillRect
  2038. #==============================================================================
  2039. Dax.register(:outline_fill_rect)
  2040. class OutlineFillRect < Sprite
  2041. #----------------------------------------------------------------------------
  2042. # • Inicialização dos objetos.
  2043. #----------------------------------------------------------------------------
  2044. def initialize(object, max=2, color=ColorBasic[-1])
  2045. super([object.width, object.height])
  2046. @object = object
  2047. self.x, self.y, self.z = object.x, object.y, object.z
  2048. self.bitmap.fill_rect(0, 0, max, self.height, color)
  2049. self.bitmap.fill_rect(self.width-max, 0, max, self.height, color)
  2050. self.bitmap.fill_rect(0, 0, self.width, max, color)
  2051. self.bitmap.fill_rect(0, self.height-max, self.width, max, color)
  2052. end
  2053. #----------------------------------------------------------------------------
  2054. # • Renovação dos objetos.
  2055. #----------------------------------------------------------------------------
  2056. def dispose
  2057. self.bitmap.dispose unless self.bitmap.disposed?
  2058. super
  2059. end
  2060. #----------------------------------------------------------------------------
  2061. # • Atualização das coordenadas.
  2062. #----------------------------------------------------------------------------
  2063. def update
  2064. self.x, self.y, self.z = @object.x, @object.y, @object.z
  2065. end
  2066. end
  2067. #==============================================================================
  2068. # • BackupSystem
  2069. #==============================================================================
  2070. Dax.register :backupsystem
  2071. $BACKUP = <<_SCRIPT_
  2072. if $TEST
  2073. time = Time.now
  2074. Dir.mkdir('Backup') unless File.directory?('Backup')
  2075. ftype = 'rvdata2'
  2076. flist = Dir.glob('./Data/*.{' + ftype + '}')
  2077. flist.each_index do |i|
  2078. flist[i] = flist[i].split('/').last
  2079. save_data(load_data('Data/' + flist[i]), 'Backup' + '/' + flist[i])
  2080. end
  2081. print("Backup em:" + (Time.now - time).to_s + ' segundos')
  2082. end
  2083. _SCRIPT_
  2084. class Object
  2085. #----------------------------------------------------------------------------
  2086. # • Realizar backup;
  2087. #----------------------------------------------------------------------------
  2088. def backup
  2089. eval($BACKUP)
  2090. end
  2091. end
  2092. #==============================================================================
  2093. # • BackString
  2094. #==============================================================================
  2095. Dax.register :dstring
  2096. module DString
  2097. extend self
  2098. #----------------------------------------------------------------------------
  2099. # • Deletar a útlima letra de uma string..
  2100. #----------------------------------------------------------------------------
  2101. def backslash(text)
  2102. text2 = ""
  2103. text = text.to_s.split(//)
  2104. text[text.size-1] = "" unless text[0].to_s.empty?
  2105. for i in 0..text.size-1
  2106. text2 += text[i].to_s
  2107. end
  2108. return text2
  2109. end
  2110. end
  2111. #==============================================================================
  2112. # * SceneManager
  2113. #==============================================================================
  2114. Dax.register :scenemanager
  2115. class << SceneManager
  2116. #----------------------------------------------------------------------------
  2117. # • Chama uma scene através de uma palavra.;
  2118. #----------------------------------------------------------------------------
  2119. def symbol(scene_symbol)
  2120. eval("self.call(#{scene_symbol.to_s})")
  2121. end
  2122. end
  2123. #==============================================================================
  2124. # • Sprite_Text
  2125. #==============================================================================
  2126. Dax.register(:sprite_text)
  2127. class Sprite_Text < Sprite
  2128. #----------------------------------------------------------------------------
  2129. # • Variáveis públicas da instância.
  2130. #----------------------------------------------------------------------------
  2131. attr_accessor :text # Mudar de texto...
  2132. #----------------------------------------------------------------------------
  2133. # • Inicialização dos objetos.
  2134. #----------------------------------------------------------------------------
  2135. def initialize(x, y, width, height, text, align=0)
  2136. super([width, height])
  2137. self.x, self.y = x, y
  2138. @text = text
  2139. self.bitmap.draw_text_rect(@text, align)
  2140. end
  2141. #----------------------------------------------------------------------------
  2142. # • Renovação dos objetos.
  2143. #----------------------------------------------------------------------------
  2144. def dispose
  2145. self.bitmap.dispose
  2146. super
  2147. end
  2148. #----------------------------------------------------------------------------
  2149. # • Atualização dos objetos.
  2150. #----------------------------------------------------------------------------
  2151. def update
  2152. self.bitmap.clear
  2153. super
  2154. self.bitmap.draw_text_rect(@text)
  2155. end
  2156. end
  2157. #==============================================================================
  2158. # • Opacity
  2159. #==============================================================================
  2160. Dax.register(:opacity)
  2161. module Opacity
  2162. extend self
  2163. @key ||= {}
  2164. #----------------------------------------------------------------------------
  2165. # • Efeito de opacidade + e -.
  2166. #----------------------------------------------------------------------------
  2167. def sprite_opacity(sprite, speed, max, min, hash=nil)
  2168. @key[hash.nil? ? hash.__id__ : hash] || false
  2169. unless @key[hash]
  2170. sprite.opacity += speed unless sprite.opacity >= max
  2171. @key[hash] = sprite.opacity >= max
  2172. else
  2173. sprite.opacity -= speed unless sprite.opacity <= min
  2174. @key[hash] = false if sprite.opacity <= min
  2175. end
  2176. end
  2177. #----------------------------------------------------------------------------
  2178. # • Efeito de opacidade por fora.
  2179. #----------------------------------------------------------------------------
  2180. def sprite_opacity_out(sprite, speed, max)
  2181. sprite.opacity += speed unless sprite.opacity >= max
  2182. end
  2183. #----------------------------------------------------------------------------
  2184. # • Efeito de opacidade por dentro.
  2185. #----------------------------------------------------------------------------
  2186. def sprite_opacity_in(sprite, speed, min)
  2187. sprite.opacity -= speed unless sprite.opacity <= min
  2188. end
  2189. #--------------------------------------------------------------------------
  2190. # • Efeito de fade out em massa
  2191. # time : duração (em milesegundo)
  2192. #--------------------------------------------------------------------------
  2193. def fadeout_all(time = 1000)
  2194. RPG::BGM.fade(time)
  2195. RPG::BGS.fade(time)
  2196. RPG::ME.fade(time)
  2197. Graphics.fadeout(time * Graphics.frame_rate / 1000)
  2198. RPG::BGM.stop
  2199. RPG::BGS.stop
  2200. RPG::ME.stop
  2201. end
  2202. end
  2203. #==============================================================================
  2204. # • Rpg
  2205. #==============================================================================
  2206. Dax.register(:rpg)
  2207. module Rpg
  2208. def self.data_manager
  2209. end
  2210. #============================================================================
  2211. # • Hud
  2212. #============================================================================
  2213. module Hud
  2214.  
  2215. end
  2216. #============================================================================
  2217. # • Menu
  2218. #============================================================================
  2219. module Menu
  2220. extend self
  2221. def include_item?(item)
  2222. item.is_a?(RPG::Item) && !item.key_item?
  2223. end
  2224. #--------------------------------------------------------------------------
  2225. # • Cursor...
  2226. #--------------------------------------------------------------------------
  2227. def cursor_up(variable, max)
  2228. variable += 1 unless variable > max
  2229. variable = 0 if variable > max
  2230. return variable
  2231. end
  2232. #--------------------------------------------------------------------------
  2233. # • Cursor...
  2234. #--------------------------------------------------------------------------
  2235. def cursor_down(variable, max)
  2236. variable -= 1 unless variable < 0
  2237. variable = max if variable < 0
  2238. return variable
  2239. end
  2240. end
  2241. #============================================================================
  2242. # • Battle
  2243. #============================================================================
  2244. module Battle
  2245. end
  2246. #============================================================================
  2247. # • Title
  2248. #============================================================================
  2249. module Title
  2250. end
  2251. end
  2252. #==============================================================================
  2253. # • String
  2254. #==============================================================================
  2255. Dax.register :shortcut
  2256. class String
  2257. #----------------------------------------------------------------------------
  2258. # • Comandos.
  2259. #----------------------------------------------------------------------------
  2260. def shortcut
  2261. if self.match(/G: ([^>]*)/)
  2262. return "Graphics/#{$1}"
  2263. elsif self.match(/C:(\w+):([^>]*)/)
  2264. case $1
  2265. when "S"
  2266. return Cache.system($2.to_s)
  2267. when "P"
  2268. return Cache.picture($2.to_s)
  2269. when "Pl"
  2270. return Cache.parallax($2.to_s)
  2271. when "C"
  2272. return Cache.character($2.to_s)
  2273. when "A"
  2274. return Cache.animation($2.to_s)
  2275. when "B1"
  2276. return Cache.battleback1($2.to_s)
  2277. when "B2"
  2278. return Cache.battleback2($2.to_s)
  2279. when "B"
  2280. return Cache.battler($2.to_s)
  2281. when "F"
  2282. return Cache.face($2.to_s)
  2283. when "T1"
  2284. return Cache.title1($2.to_s)
  2285. when "T2"
  2286. return Cache.title2($2.to_s)
  2287. when "T"
  2288. return Cache.tileset($2.to_s)
  2289. end
  2290. end
  2291. end
  2292. end
  2293. #==============================================================================
  2294. # • Txt
  2295. #==============================================================================
  2296. Dax.register(:read, "Dax")
  2297. module Read
  2298. extend self
  2299. #----------------------------------------------------------------------------
  2300. # • Verificar valor numérico após uma palavra em um arquivo.
  2301. #----------------------------------------------------------------------------
  2302. def numeric(file, tag)
  2303. IO.readlines(file).each do |line|
  2304. return $1.to_i if line.match(/#{tag} (\d+)/)
  2305. end
  2306. end
  2307. #----------------------------------------------------------------------------
  2308. # • Verificar valor de uma palavra(string única) após uma palavra em um arquivo
  2309. #----------------------------------------------------------------------------
  2310. def string(file, tag)
  2311. IO.readlines(file).each do |line|
  2312. return $1.to_s if line.match(/#{tag} (\w+)/)
  2313. end
  2314. end
  2315. #----------------------------------------------------------------------------
  2316. # • Verificar um conteúdo após uma palavra de um arquivo.
  2317. #----------------------------------------------------------------------------
  2318. def content(file, tag)
  2319. IO.readlines(file).each do |line|
  2320. return $1 if line.match(/#{tag} ([^>]*)/)
  2321. end
  2322. end
  2323. #----------------------------------------------------------------------------
  2324. # • Multiplo número..
  2325. #----------------------------------------------------------------------------
  2326. def multiple_numeric(file, tag)
  2327. IO.readlines(file).each do |line|
  2328. return [$1.to_i, $2.to_i] if line.match(/#{tag} (\d+), (\d+)/)
  2329. end
  2330. end
  2331. #----------------------------------------------------------------------------
  2332. # • Multiplo string..
  2333. #----------------------------------------------------------------------------
  2334. def multiple_string(file, tag)
  2335. IO.readlines(file).each do |line|
  2336. return [$1.to_s, $2.to_s] if line.match(/#{tag} (\w+), (\w+)/)
  2337. end
  2338. end
  2339. #----------------------------------------------------------------------------
  2340. # • Triplo número.
  2341. #----------------------------------------------------------------------------
  2342. def triple_numeric(file, tag)
  2343. IO.readlines(file).each do |line|
  2344. return [$1.to_i, $2.to_i, $3.to_i] if line.match(/#{tag} (\d+), (\d+), (\d+)/)
  2345. end
  2346. end
  2347. #----------------------------------------------------------------------------
  2348. # • Triplo string.
  2349. #----------------------------------------------------------------------------
  2350. def triple_string(file, tag)
  2351. IO.readlines(file).each do |line|
  2352. return [$1.to_s, $2.to_s, $3.to_s] if line.match(/#{tag} (\w+), (\w+), (\w+)/)
  2353. end
  2354. end
  2355. # true or false
  2356. def of(file, tag)
  2357. IO.readlines(file).each do |line|
  2358. return $1.to_s == "true" ? true : false if line.match(/#{tag} ([^>]*)/)
  2359. end
  2360. end
  2361. end
  2362.  
  2363. #==============================================================================
  2364. # • Background
  2365. #==============================================================================
  2366. Dax.register :background
  2367. module Background
  2368. extend self
  2369. #----------------------------------------------------------------------------
  2370. # • Plano de fundo padrão...
  2371. #----------------------------------------------------------------------------
  2372. def default(alpha=128)
  2373. @background = Sprite.new
  2374. @background.bitmap = SceneManager.background_bitmap
  2375. @background.color.set(16, 16, 16, alpha)
  2376. end
  2377. #----------------------------------------------------------------------------
  2378. # • Plano de fundo padrão renovado.
  2379. #----------------------------------------------------------------------------
  2380. def default_dispose
  2381. return if @background.nil?
  2382. @background.dispose
  2383. end
  2384. end
  2385. #==============================================================================
  2386. # * Window_Base
  2387. #==============================================================================
  2388. Dax.register(:window_base)
  2389. Dax.required_class("Window_Base") {
  2390. class Window_Base < Window
  2391. #----------------------------------------------------------------------------
  2392. # • Slide pela direita.
  2393. # * speed : Velocidade | point : Ponto da coordenada X que irá chegar.
  2394. #----------------------------------------------------------------------------
  2395. def slide_right(speed, point)
  2396. self.x += speed unless self.x >= point
  2397. end
  2398. #----------------------------------------------------------------------------
  2399. # • Slide pela esquerda.
  2400. # * speed : Velocidade | point : Ponto da coordenada X que irá chegar.
  2401. #----------------------------------------------------------------------------
  2402. def slide_left(speed, point)
  2403. self.x -= speed unless self.x <= point
  2404. end
  2405. #----------------------------------------------------------------------------
  2406. # • Slide por cima.
  2407. # * speed : Velocidade | point : Ponto da coordenada Y que irá chegar.
  2408. #----------------------------------------------------------------------------
  2409. def slide_up(speed, point)
  2410. self.y -= speed unless self.y <= point
  2411. end
  2412. #----------------------------------------------------------------------------
  2413. # • Slide por baixo.
  2414. # * speed : Velocidade | point : Ponto da coordenada Y que irá chegar.
  2415. #----------------------------------------------------------------------------
  2416. def slide_down(speed, point)
  2417. self.y += speed unless self.y >= point
  2418. end
  2419. end
  2420. }
  2421. #==============================================================================
  2422. # • Map
  2423. #==============================================================================
  2424. Dax.register(:map)
  2425. module Map
  2426. extend self
  2427. #----------------------------------------------------------------------------
  2428. # • Mapeiar área.
  2429. # map : Objeto [SPRITE].. que será escaniado..
  2430. # scan_sprite : Objeto [SPRITE].. que irá projetar o scan.
  2431. # color : Cor do scan.
  2432. #----------------------------------------------------------------------------
  2433. def char_area(map, scan_sprite, color=ColorBasic[-1])
  2434. _table = Table.new(map.width, map.height)
  2435. for x in 0..._table.xsize
  2436. for y in 0..._table.ysize
  2437. next if map.bitmap.get_pixel(x, y).alpha == 0
  2438. scan_sprite.bitmap.set_pixel(x, y, color)
  2439. end
  2440. end
  2441. end
  2442. #----------------------------------------------------------------------------
  2443. # • Colidir com determinada cor de um objeto sprite.
  2444. # ar : [largura, altura, bloqueio da esquerda, bloqueio de cima]
  2445. # object : Objeto a colidir. [SPRITE]
  2446. # map : Mapa. [SPRITE]
  2447. # color : Cor, na qual quando o objeto colidir com está cor.. ativa.
  2448. #---------------------------------------------------------------------------
  2449. def collide_with_color(object, map, color, ar=[28,30,30,30])
  2450. (ar[0]...object.width).each { |w| (ar[1]...object.height).each { |h|
  2451. _r = map.bitmap.get_pixel(object.x+w, object.y+h) == color[:right]
  2452. _l = map.bitmap.get_pixel(object.x+ar[2]-w, object.y+h) == color[:left]
  2453. _d = map.bitmap.get_pixel(object.x+w, object.y+h) == color[:down]
  2454. _u = map.bitmap.get_pixel(object.x+w, object.y+ar[3]-h) == color[:up]
  2455. return {right: _r, left: _l, down: _d, up: _u}
  2456. }}
  2457. end
  2458. end
  2459. #==============================================================================
  2460. # • VS | Variables & Switches
  2461. #==============================================================================
  2462. Dax.register(:vs)
  2463. module VS
  2464. #----------------------------------------------------------------------------
  2465. # • Função do módulo.
  2466. #----------------------------------------------------------------------------
  2467. module_function
  2468. #----------------------------------------------------------------------------
  2469. # • Desligar a quantia predestinada de switches...
  2470. #----------------------------------------------------------------------------
  2471. def off_switche(value=9999)
  2472. Dax.required_class("$game_switches"){value.times { |index| $game_switches[index] = false }
  2473. $game_switches.on_change}
  2474. end
  2475. #----------------------------------------------------------------------------
  2476. # • Ativar a quantia predestinada de switches...
  2477. #----------------------------------------------------------------------------
  2478. def on_switche(value=9999)
  2479. Dax.required_class("$game_switches"){value.times { |index| $game_switches[index] = true }
  2480. $game_switches.on_change}
  2481. end
  2482. #----------------------------------------------------------------------------
  2483. # • Salvar as variáveis do jogo em um arquivo
  2484. # *args : IDs delas.. exemplo: 1, 2, 3, 4
  2485. #----------------------------------------------------------------------------
  2486. def save_game_variable(*args)
  2487. Dax.required_class("$game_variables"){
  2488. Dax.required_file("savedGameVariables.rvdata2"){File.delete("savedGameVariables.rvdata2")}
  2489. i = [*args]
  2490. sgv = [{}]
  2491. (0...i.size-1).each { |index| sgv[0][index] = $game_variables[index] }
  2492. save_data(sgv, "savedGameVariables.rvdata2")
  2493. }
  2494. end
  2495. #----------------------------------------------------------------------------
  2496. # • Carregar as variáveis do jogo dum arquivo
  2497. # *args : IDs delas.. exemplo: 1, 2, 3, 4
  2498. #----------------------------------------------------------------------------
  2499. def load_game_variable(*args)
  2500. Dax.required_class("$game_variables"){
  2501. Dax.required_file("savedGameVariables.rvdata2"){
  2502. i = [*args]
  2503. sgv = load_data("savedGameVariables.rvdata2")
  2504. (0...i.size-1).each { |index| $game_variables[index] = sgv[0][index]}
  2505.  
  2506. }}
  2507. end
  2508. #----------------------------------------------------------------------------
  2509. # • Salvar as switches do jogo em um arquivo
  2510. # *args : IDs delas.. exemplo: 1, 2, 3, 4
  2511. #----------------------------------------------------------------------------
  2512. def save_switches_variable(*args)
  2513. Dax.required_class("$game_switches"){
  2514. Dax.required_file("savedGameSwitches.rvdata2"){File.delete("savedGameSwitches.rvdata2")}
  2515. i = [*args]
  2516. sgs= [{}]
  2517. (0...i.size-1).each { |index| sgs[0][index] = $game_switches[index] }
  2518. save_data(sgs, "savedGameSwitches.rvdata2")
  2519. }
  2520. end
  2521. #----------------------------------------------------------------------------
  2522. # • Carregar as variáveis do jogo dum arquivo
  2523. # *args : IDs delas.. exemplo: 1, 2, 3, 4
  2524. #----------------------------------------------------------------------------
  2525. def load_game_variable(*args)
  2526. Dax.required_class("$game_switches"){
  2527. Dax.required_file("savedGameSwitches.rvdata2"){
  2528. i = [*args]
  2529. sgs = load_data("savedGameSwitches.rvdata2")
  2530. (0...i.size-1).each { |index| $game_switches[index] = sgs[0][index]}
  2531.  
  2532. }}
  2533. end
  2534. end
  2535. #==============================================================================
  2536. # • Sound Base
  2537. #==============================================================================
  2538. Dax.register(:sound_base)
  2539. module Sound_Base
  2540. #----------------------------------------------------------------------------
  2541. # • Função do módulo.
  2542. #----------------------------------------------------------------------------
  2543. module_function
  2544. #----------------------------------------------------------------------------
  2545. # • Executar um som.
  2546. #----------------------------------------------------------------------------
  2547. def play(name, volume, pitch, type = :se)
  2548. case type
  2549. when :se ; RPG::SE.new(name, volume, pitch).play rescue valid?(name)
  2550. when :me ; RPG::ME.new(name, volume, pitch).play rescue valid?(name)
  2551. when :bgm ; RPG::BGM.new(name, volume, pitch).play rescue valid?(name)
  2552. when :bgs ; RPG::BGS.new(name, volume, pitch).play rescue valid?(name)
  2553. end
  2554. end
  2555. #----------------------------------------------------------------------------
  2556. # • Validar som.
  2557. #----------------------------------------------------------------------------
  2558. def valid?(name)
  2559. raise("Arquivo de som não encontrado: #{name}")
  2560. exit
  2561. end
  2562. end
  2563. #==============================================================================
  2564. # • Position.
  2565. #==============================================================================
  2566. Dax.register :position
  2567. class Position
  2568. #----------------------------------------------------------------------------
  2569. # • Variáveis públicas da instância.
  2570. #----------------------------------------------------------------------------
  2571. attr_accessor :x # Variável que retorna ao valor que indica a posição X.
  2572. attr_accessor :y # Variável que retorna ao valor que indica a posição Y.
  2573. #----------------------------------------------------------------------------
  2574. # • Inicialização dos objetos.
  2575. #----------------------------------------------------------------------------
  2576. def initialize(x, y)
  2577. @x = x || 0
  2578. @y = y || 0
  2579. end
  2580. #----------------------------------------------------------------------------
  2581. # • Somar com outra posição.
  2582. #----------------------------------------------------------------------------
  2583. def +(position)
  2584. position = position.position unless position.is_a?(Position)
  2585. Position.new(self.x + position.x, self.y + position.y)
  2586. end
  2587. #----------------------------------------------------------------------------
  2588. # • Subtrair com outra posição.
  2589. #----------------------------------------------------------------------------
  2590. def -(position)
  2591. position = position.position unless position.is_a?(Position)
  2592. Position.new(self.x - position.x, self.y - position.y)
  2593. end
  2594. #----------------------------------------------------------------------------
  2595. # • Multiplicar com outra posição.
  2596. #----------------------------------------------------------------------------
  2597. def *(position)
  2598. position = position.position unless position.is_a?(Position)
  2599. Position.new(self.x * position.x, self.y * position.y)
  2600. end
  2601. #----------------------------------------------------------------------------
  2602. # • Dividir com outra posição.
  2603. #----------------------------------------------------------------------------
  2604. def /(position)
  2605. position = position.position unless position.is_a?(Position)
  2606. return if (self.x or position.x or self.y or position.y) <= 0
  2607. Position.new(self.x / position.x, self.y / position.y)
  2608. end
  2609. #----------------------------------------------------------------------------
  2610. # • Comparar com outra posição.
  2611. #----------------------------------------------------------------------------
  2612. def ==(position)
  2613. position = position.position unless position.is_a?(Position)
  2614. return self.x == position.x && self.y == position.y
  2615. end
  2616. #----------------------------------------------------------------------------
  2617. # • Converter em string.
  2618. #----------------------------------------------------------------------------
  2619. def to_s
  2620. return "position x: #{self.x}\nposition y: #{self.y}"
  2621. end
  2622. end
  2623. #==============================================================================
  2624. # • Desativar scripts : Para fazer, basta por no nome do script da lista,
  2625. # [D].
  2626. #==============================================================================
  2627. Dax.register(:disable_script)
  2628. Dax.rgss_script.each_with_index { |data, index|
  2629. $RGSS_SCRIPTS.at(index)[2] = $RGSS_SCRIPTS.at(index)[3] = "" if data.at(1).include?("[D]")
  2630. }
  2631. #==============================================================================
  2632. # * DataManager
  2633. #==============================================================================
  2634. class << DataManager
  2635. alias :new_init :init
  2636. def init
  2637. Rpg.data_manager
  2638. Mouse.start
  2639. new_init
  2640. end
  2641. end
  2642. #==============================================================================
  2643. # * Input
  2644. #==============================================================================
  2645. class << Input
  2646. alias :upft :update
  2647. def update
  2648. upft
  2649. Key.update
  2650. end
  2651. end
  2652.  
  2653. class << Graphics
  2654. alias :uptf :update
  2655. def update
  2656. uptf
  2657. Mouse.update
  2658. end
  2659. end
  2660.  
  2661. __END__
  2662. :regexp_symbol
  2663. #==============================================================================
  2664. # • Regexp Symbol
  2665. #==============================================================================
  2666.  
  2667. Símbolos:
  2668.  
  2669. [x]|[abc] : Um único caractér de: a, b ou c
  2670. [^x]|[^abc] : Qualquer caractér exceto: a, b, ou c
  2671. [a-z] : Um único caractér no intervalo de a...z
  2672. [a-zA-Z] : Um único caractér no intervalo de a...z ou A...Z
  2673. ^ : Começo da linha.
  2674. $ : Fim da linha.
  2675. \A : Começo da string.
  2676. \z : Fim da string.
  2677. . : Um único caractér
  2678. \s : Qualquer carácter com espaço
  2679. \S : Qualquer carácter sem espaço
  2680. \d : Qualquer dígito
  2681. \D : Qualquer um que não seja um dígito
  2682. \w : Qualquer palavra
  2683. \W : Qualquer um que não seja uma palavra.
  2684. \b : Qualquer limite de palavra.
  2685. (...) : Capturar tudo fechado.
  2686. (x|y)|(a|b) : A(X) ou B(Y)
  2687. x? : Zero ou um de x.
  2688. x* : Zero ou mais de x.
  2689. x+ : Um ou mais de x.
  2690. x{3} : Exatamente 3 de x.
  2691. x{3,} : Exatamente 3 ou mais de um de x.
  2692. x{3,6} : Entre 3 e 6 de x.
  2693.  
  2694. Opções:
  2695.  
  2696. /i : Sem case sensitive
  2697. /m : Para mais de uma linha
  2698. /x : Ingnorar espaços brancos
  2699. /o : Executar o #{...}, alterações apenas uma vez.
  2700.  
  2701. ==============================================================================
  2702. **** Método : 'if_mouse_over'
  2703. O que esse método trata? Trata-se de que quando o Mouse estiver por cima de
  2704. determinado objeto.. algo irá acontecer.
  2705. Como eu configuro a ação que irá ocorrer caso o Mouse esteja por cima de
  2706. determinado objeto?
  2707. Bom, o método só irá funcionar com objetos que são da classe [Sprite], e ele
  2708. retorna a um bloco(somente se definir)! Exemplo:
  2709. sprite.if_mouse_over # Chamou o método.. Mais agora para definir o bloco basta
  2710. usar as {chaves} e dentro da chave o bloco que irá ser executado. Ex:
  2711. sprite.if_mouse_over {
  2712. Comando que irá se executar caso o Mouse esteja por cima do determinado objeto.
  2713. }
  2714. Certo, mais agora como faço uma condição para fazer uma ação de que.. Se
  2715. o Mouse esteja por cima de determinado objeto acontece algo, e quando ele não
  2716. estiver ele executa outra coisa?
  2717. Simples basta chamar a variável 'over', como chamar? Após o '{' usa-se
  2718. |over| .. Essa variável retorna caso o Mouse esteja por cima ou não de um objeto
  2719. com os valores true or false.. Um exemplo abaixo.
  2720. sprite.if_mouse_over { |over|
  2721. sprite.opacity = over ? 255 : 128
  2722. }
  2723. # O Exemplo acima.. Quando o Mouse estiver por cima.. a opacidade ficará com o
  2724. valor de '255'.. e quando não estiver ficará em '128'.
  2725. ==============================================================================
  2726. *** Método : 'if_mouse_click'
  2727. O que esse método trata? Trata-se de que quando o Mouse estiver por cima de
  2728. determinado objeto e a clicar nele(com o botão direito/esquerdo). algo irá acontecer
  2729. Como eu configuro a ação que irá ocorrer caso o Mouse esteja por cima de
  2730. determinado objeto ao ser clicado? O mesmo método do de cima.
  2731. Bom, o método só irá funcionar com objetos que são da classe [Sprite], e ele
  2732. retorna a um bloco(somente se definir)! Exemplo:
  2733. sprite.if_mouse_click(button) {
  2734. Comando que irá se executar caso o sprite seja clicado com o Mouse.
  2735. }
  2736. * button * O button naturalmente e o botão esquerdo.. Então se quiser não
  2737. precisa o configurar.. Mais caso queira olhe abaixo os valores a por em ()
  2738. button : Button : (:right - botão direito do mouse | :left - botão esq.)
  2739. Um Exemplo abaixo :
  2740. sprite.if_mouse_click { msgbox("Você clicou em mim!") }
Add Comment
Please, Sign In to add comment