Advertisement
AlliedG

Gallery

Jan 21st, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.30 KB | None | 0 0
  1. #sb:nap_text_img_gallery [menu]
  2. =begin
  3. Napoleons Text Image Gallery
  4. Version: 1.00
  5. Commissioned by: AlliedG
  6. Author: Napoleon
  7.  
  8. About:
  9. - A basic image gallery (but with texts).
  10. - Supports locking and unlocking images.
  11. - Compatible with Yanfly's Menu Engine. Just set ADD_TO_MENU to false and
  12. configure the menu options in his script instead.
  13. - Supports saving & loading.
  14. - The menu-command is disabled when all images are locked.
  15.  
  16. Instructions:
  17. - Place below "▼ Materials" but above "▼ Main Process".
  18. - Script Calls:
  19. # id = the id of the image, if no id was specified in the settings-section then
  20. # the id is the filename.
  21. gallery_show(id)
  22. gallery_lock(id)
  23. gallery_unlock(id)
  24. gallery_lock_all
  25. gallery_unlock_all
  26.  
  27. Requires:
  28. - RPG Maker VX Ace
  29.  
  30. Terms of Use:
  31. - Attribution 3.0 Unported (CC BY 3.0)
  32. http://creativecommons.org/licenses/by/3.0/
  33. - Credits:
  34. AlliedG
  35. Napoleon
  36.  
  37. Version History:
  38. 1.00 (18 August 2014)
  39. - First Release
  40. =end
  41. #===============================================================================
  42. $imported ||= {}
  43. $imported[:nap_text_img_gallery] = 1.00
  44. module Nap; module Image_Gallery
  45. #===============================================================================
  46. # Settings
  47. #===============================================================================
  48. FOLDER = 'Pictures' # The folder that contains the images.
  49. DEFAULT_LOCKED = true # Lock images by default?
  50. CENTER_TEXT = true # Center the image display_name text?
  51. ADD_TO_MENU = false # Add a menu item for this script?
  52. MENU_TEXT = 'Gallery' # The menu display-text if ADD_TO_MENU is set to true.
  53.  
  54. # Enter your image data here. Images not entered will be ignored.
  55. # Optional settings:
  56. # id = your UNIQUE id. Both symbols and strings can be used (probably more but not tested).
  57. # display_name = the display name of this image in the menu. If left out then the filename is used for the display name instead.
  58. # locked = true/false. Defaults to DEFAULT_LOCKED.
  59. IMAGES = [ # Only :filename is required. Do not use duplicate ID's or you will overwrite the previous one.
  60. { :id => :battlefield, :filename => 'battlefield', :display_name => 'Oludian Battlefield', :locked => false},
  61. { :id => :grave, :filename => 'Grave_scene', :display_name => 'Elizabeth Grave', :locked => false},
  62. { :id => :road, :filename => 'arcton_road', :display_name => 'Arcton Road', :locked => false},
  63. { :id => :castle, :filename => 'arcton_castle', :display_name => 'Arcton Castle' },
  64. { :id => :newmont, :filename => 'newmont_port', :display_name => 'Newmont Port' },
  65. { :id => :fish, :filename => 'erika_fish', :display_name => 'Hungry Erika' },
  66. { :id => :misty, :filename => 'Misty_Cavern', :display_name => 'Misty Cavern' },
  67. { :id => :dasia, :filename => 'dasia_port', :display_name => 'Dasia Port' },
  68. { :id => :dasiaj, :filename => 'Dasia_Jungle', :display_name => 'Dasia Jungle' },
  69. ]
  70. #===============================================================================
  71. # Do not edit below this line!
  72. # Class Image
  73. #===============================================================================
  74. class Img
  75. attr_reader :id
  76. attr_accessor :filename
  77. attr_accessor :display_name
  78. attr_accessor :locked
  79. #---------------------------------------------------------------------------
  80. # Initialize
  81. #---------------------------------------------------------------------------
  82. def initialize(params={})
  83. raise 'Img.initialize: missing parameter!' if !([:filename].all? { |key| params.key?(key) })
  84. params = {:id => params[:filename], :display_name => params[:filename], :locked => DEFAULT_LOCKED}.merge(params)
  85. @id = params[:id]
  86. @filename = params[:filename]
  87. @display_name = params[:display_name]
  88. @locked = params[:locked]
  89. end
  90. #---------------------------------------------------------------------------
  91. # To String
  92. #---------------------------------------------------------------------------
  93. def to_s
  94. @display_name
  95. end
  96. end
  97. #===============================================================================
  98. # Image Data
  99. #===============================================================================
  100. class Image_Data
  101. attr_accessor :images
  102.  
  103. def [](key); @images[key]; end
  104. #---------------------------------------------------------------------------
  105. # Initialize
  106. #---------------------------------------------------------------------------
  107. def initialize
  108. reset
  109. end
  110. #---------------------------------------------------------------------------
  111. # Reset
  112. #---------------------------------------------------------------------------
  113. def reset
  114. @images = {}
  115. IMAGES.each { |img_hash|
  116. new_img = Img.new(img_hash)
  117. @images[new_img.id] = new_img
  118. }
  119. end
  120. #---------------------------------------------------------------------------
  121. # Visible Images
  122. #---------------------------------------------------------------------------
  123. def visible_images
  124. @images.values.select { |img| !img.locked}
  125. end
  126. end
  127. $image_data = Image_Data.new # Create the global data
  128. end; end
  129. #===============================================================================
  130. # Cache
  131. #===============================================================================
  132. module Cache
  133. #-----------------------------------------------------------------------------
  134. # Napoleons Image Gallery
  135. #-----------------------------------------------------------------------------
  136. def self.nap_img_gallery(filename)
  137. load_bitmap("Graphics/#{Nap::Image_Gallery::FOLDER}/", filename)
  138. end
  139. end
  140. #===============================================================================
  141. # Saving & Loading
  142. #===============================================================================
  143. module DataManager
  144. class << self
  145. alias nap_img_gallery_make_save_contents make_save_contents
  146. alias nap_img_gallery_extract_save_contents extract_save_contents
  147. end
  148. #-----------------------------------------------------------------------------
  149. # Make Save Contents [ALIAS]
  150. #-----------------------------------------------------------------------------
  151. def self.make_save_contents
  152. contents = nap_img_gallery_make_save_contents
  153. contents[:nap_img_gallery] = $image_data
  154. contents
  155. end
  156. #-----------------------------------------------------------------------------
  157. # Extract Save Contents [ALIAS]
  158. #-----------------------------------------------------------------------------
  159. def self.extract_save_contents(contents)
  160. nap_img_gallery_extract_save_contents(contents)
  161. $image_data = contents[:nap_img_gallery]
  162. end
  163. end
  164. #===============================================================================
  165. # Game Interpreter
  166. #===============================================================================
  167. class Game_Interpreter
  168. #-----------------------------------------------------------------------------
  169. # Gallery Show [NEW]
  170. #-----------------------------------------------------------------------------
  171. def gallery_show(id)
  172. SceneManager.call(Scene_fullscreen_img)
  173. SceneManager.scene.prepare($image_data[id])
  174. end
  175. #-----------------------------------------------------------------------------
  176. # Gallery Unlock [NEW]
  177. # *args: id of the image to unlock (can be more than one).
  178. #-----------------------------------------------------------------------------
  179. def gallery_unlock(*args)
  180. args.each { |id| $image_data[id].locked = false }
  181. end
  182. #-----------------------------------------------------------------------------
  183. # Unlock All [NEW]
  184. #-----------------------------------------------------------------------------
  185. def gallery_unlock_all
  186. $image_data.images.values.each { |img_data| img_data.locked = false }
  187. end
  188. #-----------------------------------------------------------------------------
  189. # Lock All [NEW]
  190. #-----------------------------------------------------------------------------
  191. def gallery_lock_all
  192. $image_data.images.values.each { |img_data| img_data.locked = true }
  193. end
  194. #-----------------------------------------------------------------------------
  195. # Gallery Lock [NEW]
  196. # *args: id of the image to lock (can be more than one).
  197. #-----------------------------------------------------------------------------
  198. def gallery_lock(*args)
  199. args.each { |id| $image_data[id].locked = true }
  200. end
  201. end
  202. #===============================================================================
  203. # Window Text Image Gallery
  204. #===============================================================================
  205. class Window_Text_Img_Gallery < Window_Selectable
  206. @@last_idx = -1
  207. def last_idx; @@last_idx; end
  208. def last_idx=(value); @@last_idx = value; end
  209. #-----------------------------------------------------------------------------
  210. # Initialize
  211. #-----------------------------------------------------------------------------
  212. def initialize
  213. @data = $image_data.visible_images
  214. super(0, 0, Graphics.width, Graphics.height)
  215. activate
  216. set_initial_selection
  217. refresh
  218. end
  219. #-----------------------------------------------------------------------------
  220. # Set Initial Selection
  221. #-----------------------------------------------------------------------------
  222. def set_initial_selection
  223. if (last_idx > 0) && (last_idx < item_max)
  224. select(last_idx)
  225. elsif item_max > 0
  226. select(0)
  227. end
  228. end
  229. #-----------------------------------------------------------------------------
  230. # Column Max
  231. #-----------------------------------------------------------------------------
  232. def col_max
  233. return 2
  234. end
  235. #--------------------------------------------------------------------------
  236. # Spacing
  237. #--------------------------------------------------------------------------
  238. def spacing
  239. return 16
  240. end
  241. #-----------------------------------------------------------------------------
  242. # Item Max
  243. #-----------------------------------------------------------------------------
  244. def item_max
  245. return @data.length
  246. end
  247. #-----------------------------------------------------------------------------
  248. # Update
  249. #-----------------------------------------------------------------------------
  250. def update
  251. super
  252. if Input.trigger?(:B)
  253. SceneManager.return
  254. Sound.play_cancel
  255. end
  256. end
  257. #-----------------------------------------------------------------------------
  258. # Draw Item
  259. #-----------------------------------------------------------------------------
  260. def draw_item(index)
  261. draw_text(item_rect_for_text(index), @data[index].display_name, Nap::Image_Gallery::CENTER_TEXT ? 1 : 0)
  262. end
  263. #-----------------------------------------------------------------------------
  264. # Ok Enabled?
  265. #-----------------------------------------------------------------------------
  266. def ok_enabled?
  267. true
  268. end
  269. #-----------------------------------------------------------------------------
  270. # Process Ok
  271. #-----------------------------------------------------------------------------
  272. def process_ok
  273. if current_item_enabled?
  274. Sound.play_ok
  275. Input.update
  276. on_ok
  277. else
  278. Sound.play_buzzer
  279. end
  280. end
  281. #-----------------------------------------------------------------------------
  282. # On Ok
  283. #-----------------------------------------------------------------------------
  284. def on_ok
  285. SceneManager.call(Scene_fullscreen_img)
  286. SceneManager.scene.prepare(@data[index])
  287. end
  288. #-----------------------------------------------------------------------------
  289. # Dispose
  290. #-----------------------------------------------------------------------------
  291. def dispose
  292. self.last_idx = index
  293. super
  294. end
  295. end # class Window_Text_Img_Gallery < Window_Selectable
  296. #===============================================================================
  297. # Scene Image Gallery
  298. #===============================================================================
  299. class Scene_Img_Gallery < Scene_Base
  300. #-----------------------------------------------------------------------------
  301. # Start
  302. #-----------------------------------------------------------------------------
  303. def start
  304. super
  305. @window = Window_Text_Img_Gallery.new
  306. end
  307. end
  308. #===============================================================================
  309. # Scene Full Screen Image
  310. #===============================================================================
  311. class Scene_fullscreen_img < Scene_Base
  312. #-----------------------------------------------------------------------------
  313. # Start
  314. #-----------------------------------------------------------------------------
  315. def start
  316. super
  317. @sprite = Sprite.new
  318. @sprite.z = 999
  319. @sprite.bitmap = Cache.nap_img_gallery(@data.filename)
  320. end
  321. #-----------------------------------------------------------------------------
  322. # Prepare
  323. #-----------------------------------------------------------------------------
  324. def prepare(data)
  325. @data = data
  326. end
  327. #-----------------------------------------------------------------------------
  328. # Update
  329. #-----------------------------------------------------------------------------
  330. def update
  331. super
  332. if Input.trigger?(:B)
  333. Sound.play_cancel
  334. SceneManager.return
  335. end
  336. end
  337. #-----------------------------------------------------------------------------
  338. # Terminate
  339. #-----------------------------------------------------------------------------
  340. def terminate
  341. super
  342. @sprite.dispose
  343. end
  344. end
  345. #===============================================================================
  346. # Window MenuCommand
  347. # For: Adding a menu item to the main menu
  348. #===============================================================================
  349. if Nap::Image_Gallery::ADD_TO_MENU
  350. class Window_MenuCommand < Window_Command
  351. #---------------------------------------------------------------------------
  352. # Text Image Gallery Enabled [NEW]
  353. #---------------------------------------------------------------------------
  354. def text_img_gallery_enabled
  355. $image_data.visible_images.length > 0
  356. end
  357. #---------------------------------------------------------------------------
  358. # Add Original Commands [ALIAS]
  359. #---------------------------------------------------------------------------
  360. alias nap_txt_img_gallery_add_original_commands add_original_commands
  361. def add_original_commands
  362. add_command(Nap::Image_Gallery::MENU_TEXT, :img_gallery, text_img_gallery_enabled )
  363. nap_txt_img_gallery_add_original_commands
  364. end
  365. end # class Window_MenuCommand < Window_Command
  366. end # if ADD_TO_MENU
  367. #===============================================================================
  368. # Scene Menu
  369. #===============================================================================
  370. class Scene_Menu < Scene_MenuBase
  371. #-----------------------------------------------------------------------------
  372. # Command Image Gallery [NEW]
  373. #-----------------------------------------------------------------------------
  374. def command_img_gallery
  375. SceneManager.call(Scene_Img_Gallery)
  376. end
  377.  
  378. if Nap::Image_Gallery::ADD_TO_MENU
  379. #---------------------------------------------------------------------------
  380. # Create Command Window [ALIAS]
  381. #---------------------------------------------------------------------------
  382. alias nap_txt_img_gallery_create_command_window create_command_window
  383. def create_command_window
  384. nap_txt_img_gallery_create_command_window
  385. @command_window.set_handler(:img_gallery, method(:command_img_gallery))
  386. end
  387. end # if ADD_TO_MENU
  388. end
  389. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement