Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2015
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.15 KB | None | 0 0
  1. #==============================================================================
  2. # Modyfied Scene_Name
  3. # By Cyclope
  4. #------------------------------------------------------------------------------
  5. #´ Instructions
  6. # Place above main
  7. #------------------------------------------------------------------------------
  8. # Credit:
  9. # Nattmath (For making Scene_Name Leters Modification)
  10. # Blizzard (For making Custom Cotrols)
  11. # Cyclope (For modifying Scene_Name Leters Modification and Scene_Name)
  12. #==============================================================================
  13.  
  14. #==============================================================================
  15. # ** Window_Instructions
  16. #------------------------------------------------------------------------------
  17. # This window displays full status specs on the status screen.
  18. #==============================================================================
  19.  
  20. class Window_Instruction < Window_Base
  21. #--------------------------------------------------------------------------
  22. # * Object Initialization
  23. # actor : actor
  24. #--------------------------------------------------------------------------
  25. def initialize
  26. super( 0, 400, 640, 80)
  27. self.contents = Bitmap.new(width - 32, height - 32)
  28. refresh
  29. end
  30. #--------------------------------------------------------------------------
  31. # * Refresh
  32. #--------------------------------------------------------------------------
  33. def refresh
  34. self.contents.clear
  35. self.contents.font.name = "Arial"
  36. self.contents.font.size = 16
  37. self.contents.font.color = normal_color
  38. #Change this text to whatever instructions u want to have!
  39. self.contents.draw_text(26, 9, 500, 32, "Enter = OK")
  40. self.contents.draw_text(128, 9, 500, 32, "Esc/Backspace = Delete")
  41. self.contents.draw_text(336, 9, 500, 32, "abc... = Text")
  42. self.contents.draw_text(448, 9, 500, 32, "Shift = Uppercase")
  43. end
  44. end
  45. #==============================================================================
  46. # ** Window_TextName
  47. #------------------------------------------------------------------------------
  48. # super ( 224, 32, 224, 80)
  49. #==============================================================================
  50. class Window_TextName < Window_Base
  51. def initialize
  52. super ( 224, 32, 224, 80)
  53. self.contents = Bitmap.new(width - 32, height - 32)
  54. @actor = $game_actors[$game_temp.name_actor_id]
  55. refresh
  56. end
  57. def refresh
  58. self.contents.clear
  59. draw_actor_graphic(@actor, 20, 48)
  60. self.contents.font.name = "Arial"
  61. self.contents.font.size = 32
  62. self.contents.font.color = normal_color
  63. self.contents.draw_text(64, 0, 96, 32, "Слово:")
  64. end
  65. end
  66.  
  67. #==============================================================================
  68. # ** Window_NameEdit
  69. #------------------------------------------------------------------------------
  70. # This window is used to edit your name on the input name screen.
  71. #==============================================================================
  72.  
  73. class Window_NameEdit < Window_Base
  74.  
  75. #--------------------------------------------------------------------------
  76. # * Object Initialization
  77. # actor : actor
  78. # max_char : maximum number of characters
  79. #--------------------------------------------------------------------------
  80. def initialize(actor, max_char)
  81. super(16, 128, 608, 96)
  82. self.contents = Bitmap.new(width - 32, height - 32)
  83. @actor = actor
  84. @name = actor.name
  85. @max_char = max_char
  86. # Fit name within maximum number of characters
  87. name_array = @name.split(//)[0...@max_char]
  88. @name = ""
  89. for i in 0...name_array.size
  90. @name += name_array[i]
  91. end
  92. @default_name = @name
  93. @index = name_array.size
  94. refresh
  95. update_cursor_rect
  96. end
  97. #--------------------------------------------------------------------------
  98. # * Return to Default Name
  99. #--------------------------------------------------------------------------
  100. def restore_default
  101. @name = @default_name
  102. @index = @name.split(//).size
  103. refresh
  104. update_cursor_rect
  105. end
  106. #--------------------------------------------------------------------------
  107. # * Add Character
  108. # character : text character to be added
  109. #--------------------------------------------------------------------------
  110. def add(character)
  111. if @index < @max_char and character != ""
  112. @name += character
  113. @index += 1
  114. refresh
  115. update_cursor_rect
  116. end
  117. end
  118. #--------------------------------------------------------------------------
  119. # * Delete Character
  120. #--------------------------------------------------------------------------
  121. def back
  122. if @index > 0
  123. # Delete 1 text character
  124. name_array = @name.split(//)
  125. @name = ""
  126. for i in 0...name_array.size-1
  127. @name += name_array[i]
  128. end
  129. @index -= 1
  130. refresh
  131. update_cursor_rect
  132. end
  133. end
  134. #--------------------------------------------------------------------------
  135. # * Refresh
  136. #--------------------------------------------------------------------------
  137. def refresh
  138. self.contents.clear
  139. # Draw name
  140. self.contents.font.size = 42
  141. name_array = @name.split(//)
  142. for i in 0...@max_char
  143. c = name_array[i]
  144. if c == nil
  145. c = "_"
  146. end
  147. x = 304 - @max_char * 14 + i * 26
  148. self.contents.draw_text(x, 15, 28, 42, c, 1)
  149. end
  150. end
  151. #--------------------------------------------------------------------------
  152. # * Cursor Rectangle Update
  153. #--------------------------------------------------------------------------
  154. def update_cursor_rect
  155. x = 304 - @max_char * 14 + @index * 26
  156. self.cursor_rect.set(x, 55, 20, 5)
  157. end
  158. #--------------------------------------------------------------------------
  159. # * Frame Update
  160. #--------------------------------------------------------------------------
  161. def update
  162. super
  163. update_cursor_rect
  164. end
  165. end
  166.  
  167.  
  168. #==============================================================================
  169. # ** Window_NameInput
  170. #------------------------------------------------------------------------------
  171. # This window is used to select text characters on the input name screen.
  172. #==============================================================================
  173.  
  174. class Window_NameInput < Window_Base
  175. CHARACTER_TABLE =
  176. [
  177. "", ""
  178.  
  179. ]
  180. #--------------------------------------------------------------------------
  181. # * Object Initialization
  182. #--------------------------------------------------------------------------
  183. def initialize
  184. super(0, 128, 640, 0)
  185. self.contents = Bitmap.new(width - 32, height - 32)
  186. @index = 0
  187. refresh
  188. end
  189. #--------------------------------------------------------------------------
  190. # * Text Character Acquisition
  191. #--------------------------------------------------------------------------
  192. def character
  193. return CHARACTER_TABLE[@index]
  194. end
  195. #--------------------------------------------------------------------------
  196. # * Refresh
  197. #--------------------------------------------------------------------------
  198. def refresh
  199. self.contents.clear
  200. end
  201.  
  202. #--------------------------------------------------------------------------
  203. # * Frame Update
  204. #--------------------------------------------------------------------------
  205. def update
  206. super
  207. end
  208. end
  209. #==============================================================================
  210. # ** Scene_Name
  211. #------------------------------------------------------------------------------
  212. # This class performs name input screen processing.
  213. #==============================================================================
  214.  
  215. class Scene_Name
  216. #--------------------------------------------------------------------------
  217. # * Main Processing
  218. #--------------------------------------------------------------------------
  219. def main
  220. # Get actor
  221. @actor = $game_actors[$game_temp.name_actor_id]
  222. # Make windows
  223. @edit_window = Window_NameEdit.new(@actor, $game_temp.name_max_char)
  224. @edit_window.back_opacity = 160
  225. @input_window = Window_NameInput.new
  226. @inst_window = Window_Instruction.new
  227. @inst_window.back_opacity = 160
  228. @nametext_window = Window_TextName.new
  229. @nametext_window.back_opacity = 160
  230. @spriteset = Spriteset_Map.new
  231. # Execute transition
  232. Graphics.transition
  233. # Main loop
  234. loop do
  235. # Update game screen
  236. Graphics.update
  237. # Update input information
  238. Input.update
  239. # Frame update
  240. update
  241. # Abort loop if screen is changed
  242. if $scene != self
  243. break
  244. end
  245. end
  246. # Prepare for transition
  247. Graphics.freeze
  248. # Dispose of windows
  249. @edit_window.dispose
  250. @input_window.dispose
  251. @inst_window.dispose
  252. @nametext_window.dispose
  253. @spriteset.dispose
  254. end
  255. #--------------------------------------------------------------------------
  256. # * Frame Update
  257. #--------------------------------------------------------------------------
  258. def update
  259. # Update windows
  260. @edit_window.update
  261. @input_window.update
  262. @nametext_window.update
  263. @inst_window.update
  264. # If C button was pressed
  265. if Input.trigger?(Input::C)
  266. # If cursor position is at [OK]
  267. if @input_window.character == nil
  268. # If name is empty
  269. if @edit_window.name == ""
  270. # If name is empty
  271. if @edit_window.name == ""
  272. # Play buzzer SE
  273. $game_system.se_play($data_system.buzzer_se)
  274. return
  275. end
  276. # Play decision SE
  277. $game_system.se_play($data_system.decision_se)
  278. return
  279. end
  280. # Change actor name
  281. @actor.name = @edit_window.name
  282. # Play decision SE
  283. $game_system.se_play($data_system.decision_se)
  284. # Switch to map screen
  285. $scene = Scene_Map.new
  286. return
  287. end
  288. # If cursor position is at maximum
  289. if @edit_window.index == $game_temp.name_max_char
  290. # Play buzzer SE
  291. $game_system.se_play($data_system.buzzer_se)
  292. return
  293. end
  294. # If text character is empty
  295. if @input_window.character == ""
  296. # Play buzzer SE
  297. $game_system.se_play($data_system.buzzer_se)
  298. return
  299. end
  300. # Play decision SE
  301. $game_system.se_play($data_system.decision_se)
  302. # Add text character
  303. @edit_window.add(@input_window.character)
  304. return
  305. end
  306. end
  307. end
  308.  
  309. #==============================================================================
  310. # module Input
  311. #==============================================================================
  312.  
  313. module Input
  314.  
  315. #----------------------------------------------------------------------------
  316. # Simple ASCII table
  317. #----------------------------------------------------------------------------
  318. Key = {'A' => 65, 'B' => 66, 'C' => 67, 'D' => 68, 'E' => 69, 'F' => 70,
  319. 'G' => 71, 'H' => 72, 'I' => 73, 'J' => 74, 'K' => 75, 'L' => 76,
  320. 'M' => 77, 'N' => 78, 'O' => 79, 'P' => 80, 'Q' => 81, 'R' => 82,
  321. 'S' => 83, 'T' => 84, 'U' => 85, 'V' => 86, 'W' => 87, 'X' => 88,
  322. 'Y' => 89, 'Z' => 90,
  323. '0' => 48, '1' => 49, '2' => 50, '3' => 51, '4' => 52, '5' => 53,
  324. '6' => 54, '7' => 55, '8' => 56, '9' => 57,
  325. 'NumberPad 0' => 45, 'NumberPad 1' => 35, 'NumberPad 2' => 40,
  326. 'NumberPad 3' => 34, 'NumberPad 4' => 37, 'NumberPad 5' => 12,
  327. 'NumberPad 6' => 39, 'NumberPad 7' => 36, 'NumberPad 8' => 38,
  328. 'NumberPad 9' => 33,
  329. 'F1' => 112, 'F2' => 113, 'F3' => 114, 'F4' => 115, 'F5' => 116,
  330. 'F6' => 117, 'F7' => 118, 'F8' => 119, 'F9' => 120, 'F10' => 121,
  331. 'F11' => 122, 'F12' => 123,
  332. ';' => 186, '=' => 187, ',' => 188, '-' => 189, '.' => 190, '/' => 220,
  333. '\\' => 191, '\'' => 222, '[' => 219, ']' => 221, '`' => 192,
  334. 'Backspace' => 8, 'Tab' => 9, 'Enter' => 13, 'Shift' => 16,
  335. 'Left Shift' => 160, 'Right Shift' => 161, 'Left Ctrl' => 162,
  336. 'Right Ctrl' => 163, 'Left Alt' => 164, 'Right Alt' => 165,
  337. 'Ctrl' => 17, 'Alt' => 18, 'Esc' => 27, 'Space' => 32, 'Page Up' => 33,
  338. 'Page Down' => 34, 'End' => 35, 'Home' => 36, 'Insert' => 45,
  339. 'Delete' => 46, 'Arrow Left' => 37, 'Arrow Up' => 38,
  340. 'Arrow Right' => 39, 'Arrow Down' => 40,
  341. 'Mouse Left' => 1, 'Mouse Right' => 2, 'Mouse Middle' => 4,
  342. 'Mouse 4' => 5, 'Mouse 5' => 6}
  343. # default button configuration
  344. UP = [Key['Arrow Up']]
  345. LEFT = [Key['Arrow Left']]
  346. DOWN = [Key['Arrow Down']]
  347. RIGHT = [Key['Arrow Right']]
  348. A = [Key['Shift']]
  349. B = [Key['Esc'], Key['NumberPad 0'], Key['X']]
  350. C = [Key['Space'], Key['Enter'], Key['C']]
  351. X = [Key['A']]
  352. Y = [Key['S']]
  353. Z = [Key['D']]
  354. L = [Key['Q'], Key['Page Down']]
  355. R = [Key['W'], Key['Page Up']]
  356. F5 = [Key['F5']]
  357. F6 = [Key['F6']]
  358. F7 = [Key['F7']]
  359. F8 = [Key['F8']]
  360. F9 = [Key['F9']]
  361. SHIFT = [Key['Shift']]
  362. CTRL = [Key['Ctrl']]
  363. ALT = [Key['Alt']]
  364. # All keys
  365. ALL_KEYS = (0...256).to_a
  366. # Win32 API calls
  367. GetKeyboardState = Win32API.new('user32','GetKeyboardState', 'P', 'I')
  368. GetKeyboardLayout = Win32API.new('user32', 'GetKeyboardLayout','L', 'L')
  369. MapVirtualKeyEx = Win32API.new('user32', 'MapVirtualKeyEx', 'IIL', 'I')
  370. ToUnicodeEx = Win32API.new('user32', 'ToUnicodeEx', 'LLPPILL', 'L')
  371. # some other constants
  372. DOWN_STATE_MASK = 0x80
  373. DEAD_KEY_MASK = 0x80000000
  374. # data
  375. @state = "\0" * 256
  376. @triggered = Array.new(256, false)
  377. @pressed = Array.new(256, false)
  378. @released = Array.new(256, false)
  379. @repeated = Array.new(256, 0)
  380. #----------------------------------------------------------------------------
  381. # update
  382. # Updates input.
  383. #----------------------------------------------------------------------------
  384. def self.update
  385. # get current language layout
  386. @language_layout = GetKeyboardLayout.call(0)
  387. # get new keyboard state
  388. GetKeyboardState.call(@state)
  389. # for each key
  390. ALL_KEYS.each {|key|
  391. # if pressed state
  392. if @state[key] & DOWN_STATE_MASK == DOWN_STATE_MASK
  393. # not released anymore
  394. @released[key] = false
  395. # if not pressed yet
  396. if !@pressed[key]
  397. # pressed and triggered
  398. @pressed[key] = true
  399. @triggered[key] = true
  400. else
  401. # not triggered anymore
  402. @triggered[key] = false
  403. end
  404. # update of repeat counter
  405. @repeated[key] < 17 ? @repeated[key] += 1 : @repeated[key] = 15
  406. # not released yet
  407. elsif !@released[key]
  408. # if still pressed
  409. if @pressed[key]
  410. # not triggered, pressed or repeated, but released
  411. @triggered[key] = false
  412. @pressed[key] = false
  413. @repeated[key] = 0
  414. @released[key] = true
  415. end
  416. else
  417. # not released anymore
  418. @released[key] = false
  419. end}
  420. end
  421. #----------------------------------------------------------------------------
  422. # dir4
  423. # 4 direction check.
  424. #----------------------------------------------------------------------------
  425. def Input.dir4
  426. return 2 if Input.press?(DOWN)
  427. return 4 if Input.press?(LEFT)
  428. return 6 if Input.press?(RIGHT)
  429. return 8 if Input.press?(UP)
  430. return 0
  431. end
  432. #----------------------------------------------------------------------------
  433. # dir8
  434. # 8 direction check.
  435. #----------------------------------------------------------------------------
  436. def Input.dir8
  437. down = Input.press?(DOWN)
  438. left = Input.press?(LEFT)
  439. return 1 if down && left
  440. right = Input.press?(RIGHT)
  441. return 3 if down && right
  442. up = Input.press?(UP)
  443. return 7 if up && left
  444. return 9 if up && right
  445. return 2 if down
  446. return 4 if left
  447. return 6 if right
  448. return 8 if up
  449. return 0
  450. end
  451. #----------------------------------------------------------------------------
  452. # trigger?
  453. # Test if key was triggered once.
  454. #----------------------------------------------------------------------------
  455. def Input.trigger?(keys)
  456. keys = [keys] unless keys.is_a?(Array)
  457. return keys.any? {|key| @triggered[key]}
  458. end
  459. #----------------------------------------------------------------------------
  460. # press?
  461. # Test if key is being pressed.
  462. #----------------------------------------------------------------------------
  463. def Input.press?(keys)
  464. keys = [keys] unless keys.is_a?(Array)
  465. return keys.any? {|key| @pressed[key]}
  466. end
  467. #----------------------------------------------------------------------------
  468. # repeat?
  469. # Test if key is being pressed for repeating.
  470. #----------------------------------------------------------------------------
  471. def Input.repeat?(keys)
  472. keys = [keys] unless keys.is_a?(Array)
  473. return keys.any? {|key| @repeated[key] == 1 || @repeated[key] == 16}
  474. end
  475. #----------------------------------------------------------------------------
  476. # release?
  477. # Test if key was released.
  478. #----------------------------------------------------------------------------
  479. def Input.release?(keys)
  480. keys = [keys] unless keys.is_a?(Array)
  481. return keys.any? {|key| @released[key]}
  482. end
  483. #----------------------------------------------------------------------------
  484. # get_character
  485. # vk - virtual key
  486. # Gets the character from keyboard input using the input locale identifier
  487. # (formerly called keyboard layout handles).
  488. #----------------------------------------------------------------------------
  489. def self.get_character(vk)
  490. # get corresponding character from virtual key
  491. c = MapVirtualKeyEx.call(vk, 2, @language_layout)
  492. # stop if character is non-printable and not a dead key
  493. return '' if c < 32 && (c & DEAD_KEY_MASK != DEAD_KEY_MASK)
  494. # get scan code
  495. vsc = MapVirtualKeyEx.call(vk, 0, @language_layout)
  496. # result string is never longer than 2 bytes (Unicode)
  497. result = "\0" * 2
  498. # get input string from Win32 API
  499. length = ToUnicodeEx.call(vk, vsc, @state, result, 2, 0, @language_layout)
  500. return (length == 0 ? '' : result)
  501. end
  502. #----------------------------------------------------------------------------
  503. # get_input_string
  504. # Gets the string that was entered using the keyboard over the input locale
  505. # identifier (formerly called keyboard layout handles).
  506. #----------------------------------------------------------------------------
  507. def self.get_input_string
  508. result = ''
  509. # check every key
  510. ALL_KEYS.each {|key|
  511. # if repeated
  512. if self.repeat?(key)
  513. # get character from keyboard state
  514. c = self.get_character(key)
  515. # add character if there is a character
  516. result += c if c != ''
  517. end}
  518. # empty if result is empty
  519. return '' if result == ''
  520. # convert string from Unicode to UTF-8
  521. return self.unicode_to_utf8(result)
  522. end
  523. #----------------------------------------------------------------------------
  524. # get_input_string
  525. # string - string in Unicode format
  526. # Converts a string from Unicode format to UTF-8 format as RGSS does not
  527. # support Unicode.
  528. #----------------------------------------------------------------------------
  529. def self.unicode_to_utf8(string)
  530. result = ''
  531. string.unpack('S*').each {|c|
  532. # characters under 0x80 are 1 byte characters
  533. if c < 0x0080
  534. result += c.chr
  535. # other characters under 0x800 are 2 byte characters
  536. elsif c < 0x0800
  537. result += (0xC0 | (c >> 6)).chr
  538. result += (0x80 | (c & 0x3F)).chr
  539. # the rest are 3 byte characters
  540. else
  541. result += (0xE0 | (c >> 12)).chr
  542. result += (0x80 | ((c >> 12) & 0x3F)).chr
  543. result += (0x80 | (c & 0x3F)).chr
  544. end}
  545. return result
  546. end
  547.  
  548. end
  549.  
  550. #==============================================================================
  551. # ** Scene_Name Leters Modification Made By Nattmath and Improved Cyclope
  552. #------------------------------------------------------------------------------
  553. # Makes you imput stuf with the keyboard
  554. #==============================================================================
  555. class Scene_Name
  556.  
  557. alias name_input_update update
  558. def update
  559. (65...91).each{|i|
  560. if Input.trigger?(i)
  561. $game_system.se_play($data_system.decision_se)
  562. let = Input::Key.index(i)
  563. let = let.downcase unless Input.press?(Input::Key['Shift'])
  564. @edit_window.add(let)
  565. end}
  566. (48...58).each{|i|
  567. if Input.trigger?(i)
  568. $game_system.se_play($data_system.decision_se)
  569. let = Input::Key.index(i)
  570. @edit_window.add(let)
  571. end}
  572. (186...192).each{|i|
  573. if Input.trigger?(i)
  574. $game_system.se_play($data_system.decision_se)
  575. let = Input::Key.index(i)
  576. @edit_window.add(let)
  577. end}
  578. (219...222).each{|i|
  579. if Input.trigger?(i)
  580. $game_system.se_play($data_system.decision_se)
  581. let = Input::Key.index(i)
  582. @edit_window.add(let)
  583. end}
  584. if Input.trigger?(Input::Key['Backspace'])
  585. @edit_window.back
  586. end
  587. if Input.trigger?(Input::Key['Arrow Left'])
  588. @edit_window.back
  589. end
  590. if Input.trigger?(Input::Key['Enter'])
  591. # If name is empty
  592. if @edit_window.name == ""
  593. # Return to default name
  594. @edit_window.restore_default
  595. # If name is empty
  596. if @edit_window.name == ""
  597. # Play buzzer SE
  598. $game_system.se_play($data_system.buzzer_se)
  599. return
  600. end
  601. # Play decision SE
  602. $game_system.se_play($data_system.decision_se)
  603. return
  604. end
  605. # Change actor name
  606. @actor.name = @edit_window.name
  607. # Play decision SE
  608. $game_system.se_play($data_system.decision_se)
  609. # Switch to map screen
  610. $scene = Scene_Map.new
  611. end
  612. if Input.trigger?(Input::Key['Space'])
  613. @actor.name = @edit_window.name
  614. $game_system.se_play($data_system.decision_se)
  615. @edit_window.add(" ")
  616. end
  617. name_input_update
  618. end
  619. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement