DaxSoft

Dax Core i2.1

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