DaxSoft

Dax Core i1.8

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