View difference between Paste ID: fHaPErrw and fbFhUn6s
SHOW: | | - or go back to the newest paste.
1
#===============================================================================#
2-
#                          Grid Inventory Script v1.1                           #
2+
#                          Grid Inventory Script v1.1                          #
3
#-------------------------------------------------------------------------------#
4-
#     Made by DarkSchneider (original script) and Gus (edit and bug fixes)      #
4+
#   Feito por DarkSchneider (script original) e Gus (edit e conserto de bugs)   #
5
#                                     ~~~                                       #
6-
#         Special credits to Schwarz for draw_line and Blizzard for the         #
6+
#     Agradecimentos especiais a Schwarz pelo draw_line e à Blizzard pelos      #
7-
#                     Diablo 1 graphics used in this demo                       #
7+
#                     gráficos do Diablo 1 usados nesta demo                    #
8
#-------------------------------------------------------------------------------#
9-
#                         Description and instructions                          #
9+
#                           Descrição e instruções                              #
10-
#  This script changes the inventory, making it grid-based, inspired on games   #
10+
#  Este script muda o inventário, transformando ele em um grid. Foi inspirado   #
11-
#  like Diablo, Resident Evil and Deus Ex. before installing it on your game,   #
11+
#  em jogos como Diablo, Resident Evil e Deus Ex. Antes de colocar ele no seu   #
12-
#  MAKE SURE YOU HAVE ADAPTED YOUR DATABASE. All the items should start their   #
12+
#  jogo, CERTIFIQUE-SE DE QUE VOCÊ ADAPTOU SUA DATABASE. Todos os itens devem   #
13-
#  names with the format [#x#], being the first number the item width and the   #
13+
#  começar com o formato [#x#], com o primeiro número sendo a largura do item   #
14-
#  second number the item height. See the demo's database for more info. Also   #
14+
#  e o segundo número a altura. Cheque a database da demo se precisar de mais   #
15-
#  if you have any questions or problems with this script you can email me at   #
15+
#  informações, e caso você tenha alguma dúvida ou pergunta sobre esse script   #
16-
#             scripts.gus@gmail.com and I'll try to help you out.               #
16+
#  mande um email para scripts.gus@gmail.com e eu tentarei te ajudar.           #
17
#===============================================================================#
18
19
#===============================================================================#
20-
# Customization variables and some info about them
20+
# Variáveis customizáveis e informações sobre elas
21
#===============================================================================#
22
module Grid_Variables
23-
	# Width of the grid, in number of tiles
23+
	# Largura do grid, em número de quadros
24
	GRID_WIDTH = 19
25-
	# Height of the grid, in number of tiles
25+
	# Altura do grid, em número de quadros
26
	GRID_HEIGHT = 12
27
	
28-
	# Color for items' backgrounds. (Red, Green, Blue, Opacity)
28+
	# Cor para o fundo dos itens (Vermelho, Verde, Azul, Opacidade)
29
	COLOR_ITEMS = Color.new(0,0,200,50)
30
	COLOR_WEAPONS = Color.new(200,0,0,50)
31
	COLOR_ARMORS = Color.new(0,200,0,50)
32
	
33-
	# Important items are items with a price of 0. They can't be sold, and, if 
33+
  # Itens importantes têm um preço de 0. Eles não podem ser vendidos, e se esta
34-
	# this variable is false, they won't be able to be discarded too.
34+
  # variável for verdadeira, eles também não vão poder ser descartados.
35
	CAN_DROP_IMPORTANT_ITEMS = false
36
	
37-
	# Big icons need to be exactly the size the item takes on the script, multi-
37+
  # Ícones grandes precisam ser exatamente do tamanho do item no script, vezes
38-
	# plied by 32. Take a look at the icons folder for clarification
38+
  # 32. Dê uma olhada na pasta de ícones se estiver com dúvidas
39
	USE_BIG_ICONS = true
40
	
41-
	# The big icons need to use exactly the same name as their item's icon, with 
41+
  # Os ícones grandes precisam ter exatamente o mesmo nome do ícone do item, com
42-
	# something in front of the name for identification. Default is "grid.". 
42+
  # alguma coisa na frente do nome para identificação. O padrão é "grid.".
43-
	# IMPORTANT: Set this to "" if you're not using the big icons.
43+
  # IMPORTANTE: Se não for usar os ícones grandes, mude o valor para ""
44
	BIG_ICONS_PREFIX = "grid."
45
	
46-
	# The mini help window is the little window that shows the item name. If your 
46+
  # A janela de mini ajuda é aquela janelinha que mostra o nome do item. Se o seu
47-
	# grid does not takes the entire window, you can set this to true.
47+
  # grid não toma a janela inteira, você pode deixar esse valor "true'
48
	MINIHELP_CAN_BE_OUTSIDE_GRID = false
49
	
50-
	# This preferably has to be a 640x480 (or whatever window size you're using) 
50+
  # Essa imagem preferencialmente tem que ser 640x480 (ou a resolução que você)
51-
	# picture, since it will allow you to change the dimensions without having to 
51+
  # está usando, já que assim você vai poder mudar as dimensões sem ter que editar
52-
	# edit the picture.
52+
  # a imagem.
53
	GRID_BG_LOCATION = RPG::Cache.picture("gridbg")
54
	
55-
	# When you replace an item, and then press esc, it will either do nothing 
55+
  # Quando você substitui um item e depois aperta esc, ou não vai acontecer nada
56-
	# (play buzzer se) or draw it anywhere. If you want the second, set this 
56+
  # (reproduzir SE de erro) ou ele vai ser colocado onde for possível. Se for 
57-
	# constant to false
57+
  # false ele vai permitir, true ele não fará nada
58
	ALLOW_ESC_REPLACING = false
59
end
60
61
#===============================================================================#
62
# Main class, replaces the original Scene_Item
63
#===============================================================================#
64
class Scene_Item
65
	# The original script tried to use one inventory for each actor, but RPG Maker
66-
	# doesn't supports that, so this is a workaround, easier than editing a lot of
66+
  # doesn't supports that, so this is a workaround, easier than editing a lot of
67-
	# code
67+
  # code
68
	def initialize(actor_index = 0)
69
		@actor_index = actor_index
70
	end
71
	
72
	def main
73-
		s1 = "Use"
73+
		s1 = "Usar"
74-
		s2 = "Move"
74+
		s2 = "Mover"
75-
		s3 = "Drop"
75+
		s3 = "Jogar"
76
		@command_window = Window_Command.new(96, [s1, s2 , s3])
77
		@command_window.active = false
78
		@command_window.visible = false
79
		@command_window.z = 120 # So the icons don't overlap the window
80
		@help_window = Window_Help.new 
81
		@grid = Window_Grid.new(@actor_index)
82
		@grid.active = true
83
		@grid.set = 0
84
		@grid.mode = nil
85
		# Associate help window
86
		@grid.help_window = @help_window
87
		# Make target window (set to invisible / inactive)
88
		@target_window = Window_Target.new
89
		@target_window.visible = false
90
		@target_window.active = false
91
		# Make target window for equiping items on the grid
92
		@target_equip = Window_Target_Equip.new
93
		@target_equip.visible = false
94
		@target_equip.active = false
95
		# To avoid problems when moving items
96
		@moving_item = false
97
		@call_methods = ""
98
		
99
		# Execute transition
100
		Graphics.transition
101
		# Main loop
102
		loop do
103
			# Update game screen
104
			Graphics.update
105
			# Update input information
106
			Input.update
107
			# Frame update
108
			update
109
			# Abort loop if screen is changed
110
			if $scene != self
111
				break
112
			end
113
		end	
114
		# Prepare for transition
115
		Graphics.freeze
116
		@cursor_icon.dispose if @cursor_icon != nil
117
		# Dispose of windows
118
		@command_window.dispose
119
		@help_window.dispose
120
		@target_window.dispose
121
		@target_equip.dispose
122
		@grid.dispose
123
	end
124
	#--------------------------------------------------------------------------
125
	# * Frame Update
126
	#--------------------------------------------------------------------------
127
	def update
128
		# Update windows
129
		@command_window.update
130
		@help_window.update
131
		@target_window.update
132
		@target_equip.update
133
		@grid.update
134
		@grid.movingItemUpdate(@moving_item)
135
		if @command_window.active
136
			# Disabling drop option if item price is 0
137
			if !Grid_Variables::CAN_DROP_IMPORTANT_ITEMS
138
				if @grid.item.price == 0
139
					@command_window.disable_item(2)
140
				else
141
					@command_window.enable_item(2)
142
				end
143
			end
144
			
145
			# Disabling use option if item isn't usable
146
			if !$game_party.item_can_use?(@grid.item.id) && @grid.item.is_a?(RPG::Item)
147
				@command_window.disable_item(0)
148
			else
149
				@command_window.enable_item(0)
150
			end
151
			
152
			update_command
153
			return
154
		end
155
		
156
		@command_window.x = @grid.x + (@grid.cursor_rect.x + 16) + (@grid.cursor_rect.width)
157
		@command_window.y = @grid.y + (@grid.cursor_rect.y + 16) - (@command_window.height/ 2) + (@grid.cursor_rect.height / 2) 
158
		@command_window.x = @grid.x + @grid.cursor_rect.x - @command_window.width + 16 if @grid.cursor_rect.x + @grid.cursor_rect.height >= ((Grid_Variables::GRID_WIDTH - 2)* 32)
159
		
160
		if @grid.active 
161
			if Input.trigger?(Input::C) && @grid.item != nil && !@moving_item
162
				# Play decision SE
163
				$game_system.se_play($data_system.decision_se)
164
				@command_window.active = true
165
				@command_window.visible = true
166
				@grid.active = false
167
			end
168
			
169
			# If B button was pressed
170
			if Input.trigger?(Input::B) && !@moving_item
171
				# Play cancel SE
172
				$game_system.se_play($data_system.cancel_se)
173
				# Switch to menu screen
174
				$scene = Scene_Menu.new(0)
175
				return
176
			end
177
			
178
			# Some methods have to be called here on the update, so this does the job
179
			case @call_methods
180
			when "use"
181
				use_item
182
			when "cancel moving"
183
				@cursor_icon = Cursor_Icon.new if @cursor_icon == nil
184
				@cursor_icon.visible = false
185
			when "move2"
186
				@cursor_icon.update
187
				update_move2
188
			end			
189
		end
190
		if @target_window.active
191
			update_target
192
			return
193
		elsif @target_equip.active
194
			update_target_equip
195
			return
196
		end
197
	end
198
	
199
	#--------------------------------------------------------------------------
200
	# * Command Window Update
201
	#--------------------------------------------------------------------------
202
	def update_command
203
		if Input.trigger?(Input::B)
204
			@command_window.active = false
205
			@command_window.visible = false
206
			@grid.active = true	
207
			return
208
		end
209
		if Input.trigger?(Input::C)
210
			# Branch by command window cursor position
211
			case @command_window.index
212
			when 0 # use
213
				# Play decision SE
214
				$game_system.se_play($data_system.decision_se)
215
				@call_methods = "use"
216
			when 1 # move
217
				# Play equip SE
218
				$game_system.se_play($data_system.equip_se)
219
				@cursor_icon = Cursor_Icon.new if @cursor_icon == nil
220
				@cursor_icon.visible = false
221
				move_item
222
			when 2 # drop
223
				if @grid.item != nil 
224
					if !Grid_Variables::CAN_DROP_IMPORTANT_ITEMS
225
						if @grid.item.price != 0
226
							# Play cancel SE
227
							$game_system.se_play($data_system.cancel_se)
228
							@grid.delete_item(true)
229
						else
230
							# Play buzzer SE
231
							$game_system.se_play($data_system.buzzer_se)
232
						end
233
					else
234
						@grid.delete_item(true)
235
					end
236
				end
237
			end
238
			@command_window.active = false
239
			@command_window.visible = false
240
			@grid.active = true
241
			return
242
		end
243
	end
244
	
245
	#--------------------------------------------------------------------------
246
	# * Frame Update (when item window is active)
247
	#--------------------------------------------------------------------------
248
	def use_item
249
		# Get currently selected data on the item window
250
		@item = @grid.item
251
		# If it's a weapon or armor
252
		if !@item.is_a?(RPG::Item)
253
			@grid.active = false
254
			@target_equip.x = @grid.x + @grid.cursor_rect.x + (@grid.cursor_rect.width / 2) >= 320 ? 0 : 304
255
			@target_equip.visible = true
256
			@target_equip.active = true		
257
			@target_equip.index = 0
258
			
259
			for i in 0...$game_party.actors.size
260
				if $game_party.actors[i].equippable?(@item)
261
					@target_equip.enable_actor(i)
262
				else
263
					@target_equip.disable_actor(i)
264
				end
265
			end
266
			
267
			@target_equip.refresh 
268
		else
269
			# If it can't be used
270
			unless $game_party.item_can_use?(@item.id)
271
				# Play buzzer SE
272
				$game_system.se_play($data_system.buzzer_se)
273
				@call_methods = ""
274
				return
275
			end
276
			
277
			# If effect scope is an ally
278
			if @item.scope >= 3
279
				# Activate target window
280
				@grid.active = false
281
				@target_window.x = @grid.x + @grid.cursor_rect.x + (@grid.cursor_rect.width / 2) >= 320 ? 0 : 304
282
				@target_window.visible = true
283
				@target_window.active = true
284
				# Set cursor position to effect scope (single / all)
285
				if @item.scope == 4 || @item.scope == 6
286
					@target_window.index = -1
287
				else
288
					@target_window.index = 0
289
				end
290-
				# If effect scope is other than an ally
290+
			# If effect scope is other than an ally
291
			else
292
				# If command event ID is valid
293
				if @item.common_event_id > 0
294
					# Command event call reservation
295
					$game_temp.common_event_id = @item.common_event_id
296
					# Play item use SE
297
					$game_system.se_play(@item.menu_se)
298
					# If consumable
299
					if @item.consumable
300
						# Decrease used items by 1
301
						$game_party.eraseDat(@item.id, "i", 1)
302
						# Draw item window item
303
						@grid.delete_item
304
					end
305
					# Switch to map screen
306
					$scene = Scene_Map.new
307
					return
308
				end
309
			end
310
		end
311
		@call_methods = ""
312
		return
313
	end
314
	#--------------------------------------------------------------------------
315
	# * Frame Update (when target window is active)
316
	#--------------------------------------------------------------------------
317
	def update_target
318
		# If B button was pressed
319
		if Input.trigger?(Input::B)
320
			# Play cancel SE
321
			$game_system.se_play($data_system.cancel_se)
322
			# If unable to use because items ran out
323
			unless $game_party.item_can_use?(@item.id) 
324
				# Remake item window contents
325
				@grid.refresh
326
			end
327
			# Erase target window
328
			@grid.active = true
329
			@target_window.visible = false
330
			@target_window.active = false
331
			return
332
		end
333
		# If C button was pressed
334
		if Input.trigger?(Input::C)
335
			# If items are used up
336
			if @grid.item_del?
337
				# Play buzzer SE
338
				$game_system.se_play($data_system.buzzer_se)
339
				return
340
			end
341
			# If target is all
342
			if @target_window.index == -1
343
				# Apply item effects to entire party
344
				used = false
345
				for i in $game_party.actors
346
					used |= i.item_effect(@item)
347
				end
348
			end
349
			# If single target
350
			if @target_window.index >= 0
351
				# Apply item use effects to target actor
352
				target = $game_party.actors[@target_window.index]
353
				used = target.item_effect(@item)
354
			end
355
			# If an item was used
356
			if used
357
				# Play item use SE
358
				$game_system.se_play(@item.menu_se)
359
				# If consumable
360
				if @item.consumable
361
					@grid.delete_item(true)
362
				end
363
				# Remake target window contents
364
				@target_window.refresh
365
				# If all party members are dead
366
				if $game_party.all_dead?
367
					# Switch to game over screen
368
					$scene = Scene_Gameover.new
369
					return
370
				end
371
				# If common event ID is valid
372
				if @item.common_event_id > 0
373
					# Common event call reservation
374
					$game_temp.common_event_id = @item.common_event_id
375
					# Switch to map screen
376
					$scene = Scene_Map.new
377
					return
378
				end
379
				
380
				if Input.trigger?(Input::B)
381
					# Erase target window
382
					@grid.active = true
383
					@target_window.visible = false
384
					@target_window.active = false
385
					return
386
				end
387
				
388
			end
389
			# If item wasn't used
390
			unless used
391
				# Play buzzer SE
392
				$game_system.se_play($data_system.buzzer_se)
393
			end
394
			return
395
		end
396
	end
397
	
398
	#--------------------------------------------------------------------------
399
	# * Frame Update (when target equip window is active)
400
	#--------------------------------------------------------------------------	
401
	def update_target_equip
402
		# If B button was pressed
403
		if Input.trigger?(Input::B)
404
			# Play cancel SE
405
			$game_system.se_play($data_system.cancel_se)
406
			# If unable to use because items ran out
407
			unless $game_party.item_can_use?(@item.id) 
408
				# Remake item window contents
409
				@grid.refresh
410
			end
411
			# Erase target window
412
			@grid.active = true
413
			@target_equip.visible = false
414
			@target_equip.active = false
415
			return
416
		end
417
		
418
		# If C button was pressed
419
		if Input.trigger?(Input::C)
420
			actor = @target_equip.index
421
			if @target_equip.disabled?(actor)
422
				# Play buzzer SE
423
				$game_system.se_play($data_system.buzzer_se)
424
				return
425
			end
426
			
427
			if @item.is_a?(RPG::Weapon)
428
				equipped = $data_weapons[$game_party.actors[actor].weapon_id]
429
				type = "w"
430
				itemKind = 0
431
			elsif @item.is_a?(RPG::Armor)
432
				type = "a"
433
				itemKind = $data_armors[@item.id].kind + 1 # +1 because weapons are already at index 0
434
				case $data_armors[@item.id].kind
435
				when 0
436
					equipped = $data_armors[$game_party.actors[actor].armor1_id]
437
				when 1
438
					equipped = $data_armors[$game_party.actors[actor].armor2_id]
439
				when 2
440
					equipped = $data_armors[$game_party.actors[actor].armor3_id]
441
				when 3
442
					equipped = $data_armors[$game_party.actors[actor].armor4_id]
443
				end
444
			else
445
				equipped = nil
446
			end
447
			
448
			# Check to see if the equipped item and the select item are the same, if 
449-
			# so pretend to switch
449+
      # so pretend to switch
450
			if equipped.id == @item.id
451
				# Play equip SE
452
				$game_system.se_play($data_system.equip_se)
453
				@grid.active = true
454
				@target_equip.visible = false
455
				@target_equip.active = false
456
				@call_methods = ""
457
				return
458
			end
459
			
460
			# if actor has an item equipped, we need a grid space verification
461
			if equipped != nil
462
				gridFull = @grid.checkWithoutDeleting(@item.id, type, equipped.id)
463
			end
464
			
465
			if !gridFull || equipped == nil
466
				# Play equip SE
467
				$game_system.se_play($data_system.equip_se)
468
				@grid.delete_item
469
				$game_party.actors[actor].grid_equip(itemKind, @item == nil ? 0 : @item.id)
470
				$game_party.eraseData(type, @item.id, 1)
471
				@grid.refresh
472
				@grid.active = true
473
				@target_equip.visible = false
474
				@target_equip.active = false
475
				@call_methods = ""
476
				return
477
			else
478
				# Play buzzer SE
479
				$game_system.se_play($data_system.buzzer_se)
480
			end
481
			
482
			if Input.trigger?(Input::B) 
483
				# Play cancel SE
484
				$game_system.se_play($data_system.cancel_se)
485
				@call_methods = ""
486
				return
487
			end
488
			return
489
		end
490
	end
491
	
492
	#--------------------------------------------------------------------------
493
	# * Frame Update (when moving item)
494
	#--------------------------------------------------------------------------
495
	def move_item
496
		if @grid.item != nil
497
			@grid.get_item
498
			# Setting the bitmaps for the Cursor_Icon
499
			if Grid_Variables::USE_BIG_ICONS
500
				bitmap = Bitmap.new(@grid.itemWidth * 32, @grid.itemHeight * 32)
501
				x, y = 0, 0
502
			else
503
				bitmap = Bitmap.new(32,32)
504
				x, y = 4 + ((@grid.itemWidth * 32) / 2) - 16, 4 + ((@grid.itemHeight * 32) / 2) - 16
505
			end
506
			
507
			
508
			bitmap.blt(0,0,@grid.contents,Rect.new(@grid.cursor_rect.x + x, 
509
					@grid.cursor_rect.y + y,@grid.cursor_rect.width,@grid.cursor_rect.height))
510
			
511
			@cursor_icon.refresh(bitmap, @grid.itemWidth, @grid.itemHeight)
512
			@grid.cursor_rect.width = @cursor_icon.bitmap.width
513
			@grid.cursor_rect.height = @cursor_icon.bitmap.height
514
			@cursor_icon.x = @grid.cursor_rect.x + @grid.x + 16
515
			@cursor_icon.y = @grid.cursor_rect.y + @grid.y + 16
516
			@cursor_icon.visible = true
517
			@grid.delete_item
518
			@moving_item = true
519
			@call_methods = "move2"
520
		end
521
		return
522
	end
523
	
524
	#--------------------------------------------------------------------------
525
	# * Frame Update (when replacing item)
526
	#--------------------------------------------------------------------------
527
	def replace_item
528
		@grid.updateItemSize
529
		@grid.get_item2
530
		@grid.delete_item_replace
531
		@grid.redraw_item("replace")
532
		@grid.transfer_get
533
		
534
		@grid.updateItemSizeFirstDraw(@grid.item_saved[0], @grid.item_saved[1])
535
		if @grid.item_saved[1] == "i" || @grid.item_saved[1] == "w" || @grid.item_saved[1] == "a"
536
			bitmap = RPG::Cache.icon(Grid_Variables::BIG_ICONS_PREFIX + @grid.item(@grid.item_saved[1], @grid.item_saved[0]).icon_name) 
537
		else
538
			bitmap = Bitmap.new(@grid.itemWidth * 32, @grid.itemHeight * 32)
539
		end
540
		
541
		if Grid_Variables::USE_BIG_ICONS
542
			x, y = 0, 0
543
		else
544
			x, y = 4 + ((@grid.itemWidth * 32) / 2) - 16, 4 + ((@grid.itemHeight * 32) / 2) - 16
545
		end
546
		
547
		bitmap.blt(0,0,Bitmap.new(@grid.itemWidth * 32, @grid.itemHeight * 32),Rect.new(@grid.item_saved[2] + x, 
548
				@grid.item_saved[3] + y,@grid.cursor_rect.width,@grid.cursor_rect.height))
549
		
550
		@cursor_icon.refresh(bitmap, @grid.itemWidth, @grid.itemHeight)
551
		@grid.cursor_rect.width = @cursor_icon.bitmap.width
552
		@grid.cursor_rect.height = @cursor_icon.bitmap.height
553
		@cursor_icon.x = @grid.cursor_rect.x + @grid.x + 16
554
		@cursor_icon.y = @grid.cursor_rect.y + @grid.y + 16
555
		@cursor_icon.visible = true
556
		@moving_item2 = true
557
		@call_methods = "move2"
558
	end
559
	
560
	#--------------------------------------------------------------------------
561
	# * Managing the Cursor_Icon and waiting for input
562
	#--------------------------------------------------------------------------
563
	def update_move2
564
		if Input.trigger?(Input::B)
565
			if !@moving_item2 # blocks esc if moving a replaced item
566
				# Play cancel SE
567
				$game_system.se_play($data_system.cancel_se)
568
				# Switch to menu screen
569
				@grid.redraw_item(false)
570
				#@grid.mode = 1
571
				@call_methods = "cancel moving"
572
				@moving_item = false
573
				return
574
			elsif @moving_item2 && !Grid_Variables::ALLOW_ESC_REPLACING
575
				$game_system.se_play($data_system.cancel_se)
576
				if !$game_party.isGridFull?(@grid.item_saved[0], @grid.item_saved[1])
577
					pos = $game_party.set_item(@grid.item_saved[0], @grid.item_saved[1], true)
578
					@grid.draw_item(@grid.item_saved[0], @grid.item_saved[1], pos[0] , pos[1])
579
				else
580
					$game_party.eraseData(@grid.item_saved[1], @grid.item_saved[0], 1)
581
				end
582
				@call_methods = "cancel moving"
583
				@moving_item = false
584
				@moving_item2 = false
585
			else
586
				$game_system.se_play($data_system.buzzer_se)
587
			end
588
		end
589
		
590
		@grid.cursor_rect.width = @cursor_icon.bitmap.width
591
		@grid.cursor_rect.height = @cursor_icon.bitmap.height
592
		@cursor_icon.x = @grid.cursor_rect.x + @grid.x + 16 
593
		@cursor_icon.y = @grid.cursor_rect.y + @grid.y + 16
594
		
595
		if @grid.empty?
596
			@cursor_icon.blink_on
597
			@cursor_icon.tone.set(155,0,0,0)
598
		else
599
			@cursor_icon.blink_off
600
			@cursor_icon.tone.set(155,0,0,255)
601
		end
602
		
603
		if Input.trigger?(Input::C)
604
			empty = @grid.empty?			
605
			if empty == true
606
				@grid.redraw_item
607
				@cursor_icon.visible = false
608
				
609
				# Play equip SE
610
				$game_system.se_play($data_system.equip_se)
611
				
612
				@call_methods = ""
613
				@moving_item = false
614
				@moving_item2 = false
615
			elsif empty == "replace"
616
				# Play equip SE
617
				$game_system.se_play($data_system.equip_se)
618
				@call_methods = ""
619
				replace_item
620
			else
621
				$game_system.se_play($data_system.buzzer_se)
622
			end
623
			return
624
		end
625
	end
626
end
627
628
#===============================================================================#
629
# This edit removes the [#x#] from the item name, and passes it to $data_grid
630
#===============================================================================#
631
class Scene_Title
632
	alias old_main main
633
	def main
634
		old_main
635
		
636
		$data_grid = [], [], [] # index 0: items, 1: weapons, 2: armors
637
		
638
		# Looping three times, each time for a different item type
639
		for i in 0..2
640
			case i
641
			when 0
642
				type = $data_items
643
			when 1
644
				type = $data_weapons
645
			when 2
646
				type = $data_armors
647
			end
648
			
649
			# Editing the item name and adding the item size to the grid
650
			for j in 0..type.length - 1
651
				if type[j] != nil && type[j].name[0,1] == "["
652
					$data_grid[i][j] = type[j].name.match(/\[(.*)\]/)[1]
653
					type[j].name = type[j].name.gsub(/\[(.*)\]/, "").lstrip
654
				end
655
			end
656
		end
657
	end
658
end
659
660
#===============================================================================#
661
# This edit is to avoid losing money when buying more itens than you can carry. 
662
# You will only be able to buy a number of items until your inventory is full, 
663
# and you will only be charged for those items.
664
#===============================================================================#
665
class Scene_Shop
666
	#--------------------------------------------------------------------------
667
	# * Frame Update
668
	#--------------------------------------------------------------------------
669
	def buy_item(item, number)
670
		if !$game_party.isGridFull?(item.id, "", item)
671
			
672
			case item
673
			when RPG::Item
674
				amountBought = $game_party.gain_item(item.id, number)
675
			when RPG::Weapon
676
				amountBought = $game_party.gain_weapon(item.id, number)
677
			when RPG::Armor
678
				amountBought = $game_party.gain_armor(item.id, number)
679
			end
680
			
681
			if amountBought != nil
682
				number = amountBought - 1
683
			end
684
			
685
			$game_party.lose_gold(number * @item.price)
686
			$game_system.se_play($data_system.shop_se)
687
		else
688
			$game_system.se_play($data_system.buzzer_se)
689
			@buy_window.gridFull
690
		end
691
	end
692
	
693
	# Edit to use buy_item instead of the default way
694
	def update_number
695
		if Input.trigger?(Input::B)
696
			$game_system.se_play($data_system.cancel_se)
697
			@number_window.active = false
698
			@number_window.visible = false
699
			case @command_window.index
700
			when 0  # Buy
701
				@buy_window.active = true
702
				@buy_window.visible = true
703
			when 1  # Sell
704
				@sell_window.active = true
705
				@sell_window.visible = true
706
				@status_window.visible = false
707
			end
708
			return
709
		end
710
		if Input.trigger?(Input::C)
711
			@number_window.active = false
712
			@number_window.visible = false
713
			case @command_window.index
714
			when 0  # Buy
715
				buy_item(@item, @number_window.number)
716
				@gold_window.refresh
717
				@status_window.refresh
718
				@buy_window.active = true
719
				@buy_window.visible = true
720
			when 1  # Sell
721
				$game_system.se_play($data_system.shop_se)
722
				$game_party.gain_gold(@number_window.number * (@item.price / 2))
723
				case @item
724
				when RPG::Item
725
					$game_party.lose_item(@item.id, @number_window.number)
726
				when RPG::Weapon
727
					$game_party.lose_weapon(@item.id, @number_window.number)
728
				when RPG::Armor
729
					$game_party.lose_armor(@item.id, @number_window.number)
730
				end
731
				@gold_window.refresh
732
				@sell_window.refresh
733
				@status_window.refresh
734
				@sell_window.active = true
735
				@sell_window.visible = true
736
				@status_window.visible = false
737
			end
738
			return
739
		end
740
	end
741
end
742
743
#===============================================================================#
744
# This edit is to show "Inventory is full!" on the shop help window
745
#===============================================================================#
746
class Window_ShopBuy < Window_Selectable
747
	def update_help
748
		# Removing the message if player presses up or down
749
		if @gridIsFull
750
			if Input.trigger?(Input::UP) || Input.trigger?(Input::DOWN)
751
				@gridIsFull = false
752
			end
753
		end
754
		
755
		@help_window.set_text(self.item == nil ? "" : self.item.description)
756-
		@help_window.set_text("Inventory is full!") if @gridIsFull
756+
		@help_window.set_text("Inventário está cheio!") if @gridIsFull
757
	end
758
	
759
	# Setting this for remote access later
760
	def gridFull
761
		@gridIsFull = true
762
	end
763
end
764
765
#===============================================================================#
766
# This edit is to show "Inventory is full!" on the equip help window
767
#===============================================================================#
768
class Scene_Equip
769
	def update_item
770
		# Se o botão B for pressionado
771
		if Input.trigger?(Input::B)
772
			# Reproduzir SE de cancelamento
773
			$game_system.se_play($data_system.cancel_se)
774
			# Ativar janela da direita
775
			@right_window.active = true
776
			@item_window.active = false
777
			@item_window.index = -1
778
			return
779
		end
780
		# Se o botão C for pressionado
781
		if Input.trigger?(Input::C)
782
			# Reproduzir SE de Equipamento
783
			$game_system.se_play($data_system.equip_se)
784
			# Selecionar dados escolhidos na janela de Item
785
			item = @item_window.item
786
			# Mudar Equipamento
787
			equip = @actor.equip(@right_window.index, item == nil ? 0 : item.id)
788
			@right_window.gridFull if equip == nil
789
			# Ativar janela da direita
790
			@right_window.active = true
791
			@item_window.active = false
792
			@item_window.index = -1
793
			# Recriar os conteúdos da janela de Itens e da direita
794
			@right_window.refresh
795
			@item_window.refresh
796
			return
797
		end
798
	end
799
end
800
801
#===============================================================================#
802
# Same as above
803
#===============================================================================#
804
class Window_EquipRight < Window_Selectable
805
	def update_help
806
		if @gridIsFull
807
			if Input.trigger?(Input::UP) || Input.trigger?(Input::DOWN)
808
				@gridIsFull = false
809
			end
810
		end
811
		@help_window.set_text(self.item == nil ? "" : self.item.description)
812-
		@help_window.set_text("Inventory is full!") if @gridIsFull
812+
		@help_window.set_text("Inventário está cheio!") if @gridIsFull
813
	end
814
	
815
	def gridFull
816
		@gridIsFull = true
817
	end
818
end
819
820
#===============================================================================#
821
# This is an edit to enable a command window item after it has been disabled. As 
822
# far as I know there is no default way to do this.
823
#===============================================================================#
824
class Window_Command < Window_Selectable
825
	def enable_item(index)
826
		draw_item(index, normal_color)
827
	end
828
end
829
830
#===============================================================================#
831
# This edit changes the behavior of Window_Selectable if the grid is active
832
#===============================================================================#
833
class Window_Selectable < Window_Base
834
	alias old_initialize initialize
835
	def initialize(x, y, width, height)
836
		old_initialize(x, y, width, height)
837
		if self.is_a?(Window_Grid)
838
			@x = 0
839
			@y = 0
840
		end
841
	end
842
	
843
	alias old_update update
844
	def update
845
		if !self.is_a?(Window_Grid)
846
			old_update
847
			return
848
		end
849
		super
850
		
851
		item = $game_party.actors[@actor_index].item_grid
852
		
853
		# If cursor is movable
854
		if self.active and @x >= 0	
855
			# Using special directional commands if the user is moving an item. Without
856-
			# this sometimes you might get crashes when moving items, since the script 
856+
      # this sometimes you might get crashes when moving items, since the script 
857-
			# can "teleport" your cursor to a coordinate that doesn't exists.
857+
      # can "teleport" your cursor to a coordinate that doesn't exists.
858
			if self.movingItem?
859
				if Input.repeat?(Input::DOWN)
860
					if @y == item.size - @itemHeight 
861
						@y = 0
862
					else
863
						@y += 1
864
					end
865
					
866
					$game_system.se_play($data_system.cursor_se)
867
				end
868
				if Input.repeat?(Input::UP)
869
					if @y == 0
870
						@y = item.size - @itemHeight
871
					else
872
						@y -= 1
873
					end
874
					
875
					$game_system.se_play($data_system.cursor_se)
876
				end
877
				if Input.repeat?(Input::RIGHT)
878
					if @x == item[@y].size - @itemWidth
879
						@x = 0
880
					else
881
						@x += 1 
882
					end
883
					$game_system.se_play($data_system.cursor_se)
884
				end
885
				if Input.repeat?(Input::LEFT)
886
					if @x == 0
887
						@x = item[@y].size - @itemWidth
888
					else
889
						@x -= 1
890
					end
891
					
892
					$game_system.se_play($data_system.cursor_se)
893
				end
894
			else
895
				# This makes the cursor select the entire item, no matter which slot it 
896-
				# is in
896+
        # is in
897
				if item[@y][@x][1][0,1] == "["
898
					itemSplit = item[@y][@x][1].gsub(/[\[\]]/, "").split('x')
899
					iH = itemSplit[0].to_i
900
					iW = itemSplit[1].to_i
901
					@x -= iW
902
					@y -= iH
903
				end
904
				
905
				if Input.repeat?(Input::DOWN)
906
					# if @y is at the last tile or above an item that is covering the last 
907-
					# tile (and this item exists)
907+
          # tile (and this item exists)
908
					if @y == item.size - 1 || (@y == item.size - @itemHeight && item[@y][@x][1] != "")
909
						@y = 0
910
					else
911
						@y += item[@y][@x][1] != "" ? @itemHeight : 1 #if the current slot is an item, add the item height, else add 1
912
					end
913
					
914
					$game_system.se_play($data_system.cursor_se)
915
				end
916
				
917
				if Input.repeat?(Input::UP)
918
					# since whenever the item is selected the @y goes to the top tile, 
919-
					# there's no need for special checks
919+
          # there's no need for special checks
920
					if @y == 0
921
						@y = item.size - 1
922
					else
923
						@y -= 1
924
					end
925
					
926
					$game_system.se_play($data_system.cursor_se)
927
				end
928
				
929
				if Input.repeat?(Input::RIGHT)
930
					# if @x is at the last tile or above an item that is covering the last
931-
					# tile (and this item exists)
931+
          # tile (and this item exists)
932
					if @x == item[@y].size - 1 || (@x == item[@y].size - @itemWidth && item[@y][@x][1] != "")
933
						@x = 0
934
					else
935
						@x += item[@y][@x][1] != "" ? @itemWidth : 1 #if the current slot is an item, add the item height, else add 1
936
					end
937
					
938
					$game_system.se_play($data_system.cursor_se)
939
				end
940
				
941
				if Input.repeat?(Input::LEFT)
942
					# since whenever the item is selected the @x goes to the top-left tile,
943-
					# there's no need for special checks
943+
          # there's no need for special checks
944
					if @x == 0
945
						@x = item[@y].size - 1
946
					else
947
						@x -= 1
948
					end
949
					
950
					$game_system.se_play($data_system.cursor_se)
951
				end
952
			end
953
		end
954
		# Update help text (update_help is defined by the subclasses)
955
		if self.active and @help_window != nil
956
			update_help
957
		end
958
		# Update cursor rectangle
959
		update_cursor_rect
960
	end
961
	
962
	def hide_cursor
963
		self.cursor_rect.empty
964
	end
965
end
966
967
#===============================================================================#
968
# The main grid window
969
#===============================================================================#
970
class Window_Grid < Window_Selectable
971
	
972
	attr_accessor :mode
973
	attr_reader :itemWidth
974
	attr_reader :itemHeight
975
	attr_reader :item_saved
976
	attr_reader :item_saved2
977
	
978
	def initialize(actor_index)
979
		# This will center the grid. Feel free to edit it if you don't want that
980
		super((640/2)-(((Grid_Variables::GRID_WIDTH * 32) + 32) / 2), # x
981
			32 + (480 / 2) - (((Grid_Variables::GRID_HEIGHT * 32) + 32) / 2), # y
982
			(Grid_Variables::GRID_WIDTH * 32)+33, # width
983
			(Grid_Variables::GRID_HEIGHT * 32)+33) # height
984
		
985
		self.contents = Bitmap.new(width - 32, height - 32) 
986
		self.opacity = 0
987
		# This window does nothing, it's there just to replace the otherwise black 
988-
		# background.
988+
    # background.
989
		@dummy_window = Window_Base.new(0, 64, 640, 480 - 64)
990
		@dummy_window.z = 0
991
		@window = Window_Base.new(x , y , width, height) 
992
		@window.contents = Bitmap.new(width - 32, height - 32)
993
		@window.z = self.z - 4
994
		@window.opacity = 0
995
		@grid_color = Sprite.new
996
		@grid_color.bitmap = Bitmap.new(width - 32, height - 32)
997
		@grid_color.x = self.x + 16
998
		@grid_color.y = self.y + 16
999
		@grid_color.z = @window.z + 2
1000
		@actor_index = actor_index
1001
		@mode = 0
1002
		@mini_help = Mini_Help.new
1003
		self.set = -1
1004
		n = self.contents.width / 32
1005
		m = self.contents.height / 32
1006
		@column_max = n
1007
		draw_grid
1008
		@itemWidth = 1
1009
		@itemHeight = 1
1010
		@movingItem = false
1011
		refresh
1012
	end
1013
	
1014
	def draw_grid
1015
		gridHeight = Grid_Variables::GRID_HEIGHT * 32
1016
		gridWidth = Grid_Variables::GRID_WIDTH * 32
1017
		# Creates the window bg
1018
		@window.contents.blt(0, 0, Grid_Variables::GRID_BG_LOCATION, Rect.new(0, 0, gridWidth, gridHeight))
1019
		i = 0
1020
		color = Color.new(150,150,150)
1021
		while i <= gridHeight
1022
			draw_line(-1, i, gridWidth + 1, i, color)
1023
			i += 32
1024
		end
1025
		i = 0
1026
		while i <= gridWidth
1027
			draw_line(i, 0, i, gridHeight, color)
1028
			i += 32
1029
		end
1030
	end
1031
	
1032
	def draw_line(sx, sy, ex, ey, color)
1033
		rad = Math.atan2(ey-sy, ex-sx)
1034
		dx = Math.cos(rad)
1035
		dy = Math.sin(rad)
1036
		while (sx - ex).abs > 1 || (sy - ey).abs > 1 
1037
			sx += dx
1038
			sy += dy
1039
			@window.contents.set_pixel(sx, sy, color)
1040
		end
1041
	end
1042
	
1043
	def refresh
1044
		@item_max = 0
1045
		item = $game_party.actors[@actor_index].item_grid
1046
		for i in 0..item.size - 1
1047
			for j in 0..item[i].size - 1
1048
				if item[i][j][0] == 0 and (item[i][j][1] == "i" or item[i][j][1] == "w" or item[i][j][1] == "a")
1049
					@item_max += 1
1050
				end
1051
			end
1052
		end
1053
		
1054
		for i in 0..item.size - 1
1055
			for j in 0..item[i].size - 1
1056
				draw_item(item[i][j][0], item[i][j][1], i , j)
1057
			end
1058
		end
1059
	end
1060
	
1061
	# Updates the @movingItem variable. Mostly used on remote access
1062
	def movingItemUpdate(moving_item)
1063
		@movingItem = moving_item
1064
	end
1065
	
1066
	# Returns true or false, depending on @movingItem. Mostly used on remote access
1067
	def movingItem?
1068
		movingItemUpdate(@movingItem)
1069
		return @movingItem
1070
	end
1071
	
1072
	
1073
	def update_cursor_rect
1074
		# @x is the cursor's x
1075
		if @x < 0
1076
			self.cursor_rect.empty
1077
			return
1078
		end
1079
		
1080
		# Assign the parameters in the item's name to the cursor
1081
		if item != nil
1082
			updateItemSize if !@movingItem
1083
			cursor_width = @itemWidth * 32
1084
			cursor_height = @itemHeight * 32
1085
		else
1086
			# Default values in case the item name has no parameters
1087
			case $game_party.actors[@actor_index].item_grid[@y][@x][1]
1088
			when "i" # Item, uses 1x1
1089
				cursor_width = 32
1090
				cursor_height = 32
1091
			when "w" # Weapon, uses 1x3
1092
				cursor_width = 32
1093
				cursor_height = 96
1094
			when "a" # Armor, uses 2x3
1095
				cursor_width = 64
1096
				cursor_height = 96
1097
			else
1098
				cursor_width = 32
1099
				cursor_height = 32
1100
			end
1101
		end
1102
		
1103
		
1104
		# Calculate cursor coordinates
1105
		x = @x * 32
1106
		y = @y * 32
1107
		
1108
		# Update cursor rectangle
1109
		self.cursor_rect.set(x, y, cursor_width, cursor_height)
1110
	end
1111
	
1112
	# Deletes the item from the grid. If removeData is true, also removes the item 
1113-
	# from inventory.
1113+
  # from inventory.
1114
	def delete_item(removeData = false)
1115
		type = $game_party.actors[@actor_index].item_grid[@y][@x][1]
1116
		item_id = $game_party.actors[@actor_index].item_grid[@y][@x][0]
1117
		if type != ""	|| type[0,1] != "["
1118
			iH, iW = 0, 0
1119
			@grid_color.bitmap.fill_rect(@x*32+1, @y*32+1, (@itemWidth * 32) - 1, (@itemHeight * 32) - 1, Color.new(0,0,0,0))
1120
			self.contents.fill_rect(@x*32, @y*32, @itemWidth*32, @itemHeight*32, Color.new(0,0,0,0))
1121
			
1122
			for iH in 0...@itemHeight.to_i 
1123
				for iW in 0...@itemWidth.to_i 
1124
					$game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][0] = 0
1125
					$game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][1] = ""
1126
					#iW = 0
1127
				end
1128
			end
1129
		end
1130
		
1131
		if removeData
1132
			$game_party.eraseData(type, item_id, 1)
1133
		end
1134
	end
1135
	
1136
	# This is a special delete_item, using the @item_saved array as parameters
1137
	def delete_item_replace
1138
		item_id = @item_saved2[0]
1139
		type = @item_saved2[1]
1140
		itemX = @item_saved2[2]
1141
		itemY = @item_saved2[3]
1142
		if type != ""					
1143
			updateItemSizeFirstDraw(item_id, type)
1144
			@grid_color.bitmap.fill_rect((itemX)*32+1, (itemY)*32+1, (@itemWidth * 32) - 1, (@itemHeight * 32) - 1, Color.new(0,0,0,0))
1145
			self.contents.fill_rect((itemX)*32, (itemY)*32, @itemWidth*32, @itemHeight*32, Color.new(0,0,0,0))
1146
			
1147
			for iH in 0...@itemHeight.to_i 
1148
				for iW in 0...@itemWidth.to_i 
1149
					$game_party.actors[@actor_index].item_grid[itemY + iH][itemX + iW][0] = 0
1150
					$game_party.actors[@actor_index].item_grid[itemY + iH][itemX + iW][1] = ""
1151
				end
1152
			end
1153
		end
1154
	end	
1155
	
1156
	# This iis a method for the grid equip feature. It "pretends" to delete the 
1157-
	# item to see if there is enough space to unequip the equipped item.
1157+
  # item to see if there is enough space to unequip the equipped item.
1158
	def checkWithoutDeleting(item_id, type, equip_id)
1159
		for iH in 0...@itemHeight.to_i 
1160
			for iW in 0...@itemWidth.to_i 
1161
				$game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][0] = 0
1162
				$game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][1] = ""
1163
			end
1164
		end
1165
		
1166
		flag = $game_party.isGridFull?(equip_id, type)
1167
		
1168
		for iH in 0...@itemHeight.to_i 
1169
			for iW in 0...@itemWidth.to_i 
1170
				if iH == 0 && iW == 0
1171
					$game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][0] = item_id
1172
					$game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][1] = type
1173
				else
1174
					$game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][0] = item_id
1175
					$game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][1] = "[#{iH}x#{iW}]"	
1176
				end
1177
			end
1178
		end
1179
		return flag
1180
	end
1181
	
1182
	# Updating the @itemWidth and @itemHeight variables
1183
	def updateItemSize
1184
		if item != nil && itemSize != nil
1185
			gridValues = itemSize.split('x')
1186
			@itemWidth = gridValues[0].to_i
1187
			@itemHeight = gridValues[1].to_i
1188
		else
1189
			@itemWidth = 0
1190
			@itemHeight = 0
1191
		end
1192
	end
1193
	
1194
	# Manually updating the @itemWidth and @itemHeight variables.
1195
	def updateItemSizeFirstDraw(item_id, type)
1196
		item = itemSize(item_id, type)
1197
		
1198
		if item != nil
1199
			gridValues = item.split('x')
1200
			@itemWidth = gridValues[0].to_i
1201
			@itemHeight = gridValues[1].to_i
1202
		end
1203
	end
1204
	
1205
	# Checking the item type and returning the correct $data
1206
	def item(type = nil, id = nil)
1207
		if type == nil && id == nil
1208
			id = $game_party.actors[@actor_index].item_grid[@y][@x][0]
1209
			type = $game_party.actors[@actor_index].item_grid[@y][@x][1]
1210
		end
1211
		
1212
		case type
1213
		when "i"
1214
			return $data_items[id]
1215
		when "w"
1216
			return $data_weapons[id]
1217
		when "a"
1218
			return $data_armors[id]
1219
		else 
1220
			return nil
1221
		end
1222
	end
1223
	
1224
	# Returns the item size from the $data_grid variables
1225
	def itemSize(id = nil, type = nil)
1226
		if type == nil && id == nil
1227
			id = $game_party.actors[@actor_index].item_grid[@y][@x][0]
1228
			type = $game_party.actors[@actor_index].item_grid[@y][@x][1]
1229
		end
1230
		
1231
		case type
1232
		when "i"
1233
			return $data_grid[0][id]
1234
		when "w"
1235
			return $data_grid[1][id]
1236
		when "a"
1237
			return $data_grid[2][id]
1238
		else return nil
1239
		end
1240
	end
1241
	
1242
	# Checking if the item is unusable or not, I guess. This was here on the 
1243-
	# original script
1243+
  # original script
1244
	def item_del?
1245
		if $game_party.actors[@actor_index].item_grid[@y][@x][0] == 0
1246
			# Unusable
1247
			return true
1248
		else
1249
			return false
1250
		end
1251
	end
1252
	
1253
	def dispose
1254
		super
1255
		@window.dispose
1256
		@dummy_window.dispose
1257
		@grid_color.dispose
1258
		@mini_help.dispose
1259
	end
1260
	
1261
	# Updating the help window (with item description) and the mini_help (with 
1262-
	# item name)
1262+
  # item name)
1263
	def update_help
1264
		@mini_help.contents.font.color = (($game_party.item_can_use?(item.id) || !item.is_a?(RPG::Item))? normal_color : disabled_color)
1265
		@help_window.set_text((item == nil || movingItem? == true) ? "" : item.description)
1266
		@mini_help.set_text(item == nil ? "" : item.name)
1267
		@mini_help.visible = false if item == nil || movingItem?
1268
		
1269
		@mini_help.x = self.x + (self.cursor_rect.x + 16) - (@mini_help.width / 2) + (self.cursor_rect.width / 2) 
1270
		@mini_help.y = self.y + (self.cursor_rect.y + 16) + (self.cursor_rect.height)
1271
		
1272
		if !Grid_Variables::MINIHELP_CAN_BE_OUTSIDE_GRID
1273
			@mini_help.x += (@mini_help.x - self.x - 16) * -1 if @mini_help.x < self.x + 16 # -16 to make it look good even if you hide the windowskin
1274
			@mini_help.x -= (@mini_help.x + @mini_help.width) - (self.x + self.width - 16) if @mini_help.x + @mini_help.width >= self.x + self.width - 16
1275
			@mini_help.y -= self.cursor_rect.height + @mini_help.height - 1 if @mini_help.y + @mini_help.height >= self.y + self.height - 16
1276
		end
1277
	end
1278
	
1279
	# Stores the item data on an array, and keeps them safe while moving the item.
1280
	def get_item
1281
		@item_saved = [$game_party.actors[@actor_index].item_grid[@y][@x][0], 
1282
			$game_party.actors[@actor_index].item_grid[@y][@x][1], @x, @y]
1283
	end
1284
	
1285
	# Same thing as above, but with some added precautions to make sure it gets 
1286-
	# the	right @x and @y. Used for the replace item method.
1286+
  # the	right @x and @y. Used for the replace item method.
1287
	def get_item2
1288
		updateItemSizeFirstDraw(@item_saved[0], @item_saved[1])
1289
		
1290
		iH, iW = 0, 0
1291
		if $game_party.actors[@actor_index].item_grid[@y][@x][0] == 0
1292
			for iW in 0...@itemWidth.to_i 
1293
				for iH in 0...@itemHeight.to_i 
1294
					if $game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][0] != 0
1295
						break
1296
					end
1297
				end
1298
				break if $game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][0] != 0
1299
			end
1300
		end
1301
		
1302
		if $game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][1][0,1] == "["
1303
			itemSplit = $game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][1].gsub(/[\[\]]/, "").split('x')
1304
			minusH = itemSplit[0].to_i
1305
			minusW = itemSplit[1].to_i
1306
		else
1307
			minusH = 0
1308
			minusW = 0
1309
		end
1310
		
1311
		item_id = $game_party.actors[@actor_index].item_grid[@y + iH - minusH][@x + iW - minusW][0]
1312
		type = $game_party.actors[@actor_index].item_grid[@y + iH - minusH][@x + iW - minusW][1]
1313
		@item_saved2 = [item_id, type, @x + iW - minusW, @y + iH - minusH]
1314
	end
1315
	
1316
	# Clears the @item_saved and transfers the data on @item_saved2 to it	
1317
	def transfer_get
1318
		@item_saved = []
1319
		@item_saved2.each{|i| @item_saved.push(i)}
1320
	end
1321
	
1322
	# Redrawing used for moving items. Using @item_saved parameters if moving was
1323
	# canceled (f = false)
1324
	def redraw_item(f = true)
1325
		if f
1326
			x = 4 + (@x * 32)
1327
			y = @y * 32
1328
		else # the moving has been canceled
1329
			x = 4 + (@item_saved[2] * 32)
1330
			y = @item_saved[3] * 32
1331
			tx = @x
1332
			ty = @y
1333
			@x = @item_saved[2]
1334
			@y = @item_saved[3]
1335
		end
1336
		
1337
		draw_item(@item_saved[0], @item_saved[1], @y, @x)
1338
		for iH in 0...@itemHeight.to_i 
1339
			for iW in 0...@itemWidth.to_i 
1340
				if iH == 0 && iW == 0
1341
					$game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][0] = @item_saved[0]
1342
					$game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][1] = @item_saved[1]
1343
				else
1344
					$game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][0] = @item_saved[0]
1345
					$game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][1] = "[#{iH}x#{iW}]"	
1346
				end
1347
			end
1348
		end
1349
		
1350
		# Making the cursor go to the replaced item
1351
		if f == "replace"
1352
			@x = @item_saved2[2]
1353
			@y = @item_saved2[3]
1354
		end
1355
		
1356
		# Uncomment these lines if you don't want the cursor to go back with the 
1357
		# item when the player cancels moving.
1358
		#@x = tx if @x != tx and tx != nil
1359
		#@y = ty if @y != ty and ty != nil
1360
	end
1361
	
1362
	# Checks if the cursor area is empty, and if there is more than one item on it
1363
	def empty?
1364
		n = 0
1365
		arr = []
1366
		for iH in 0...@itemHeight.to_i 
1367
			for iW in 0...@itemWidth.to_i 
1368
				type = $game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][1]
1369
				id = $game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][0]	
1370
				cond = (type == "")
1371
				replaceable = true if !cond
1372
				
1373
				if !cond && (type == "i" || type == "w" || type == "a") && arr[n-1] != "#{@y + iH},#{@x + iW}"
1374
					n += 1
1375
					arr.push("#{@y + iH},#{@x + iW}")
1376
				end
1377
				if type[0,1] == "["
1378
					itemSplit = type.gsub(/[\[\]]/, "").split('x')
1379
					minusH = itemSplit[0].to_i
1380
					minusW = itemSplit[1].to_i
1381
					
1382
					if arr[n-1] != "#{@y + iH - minusH},#{@x + iW - minusW}"
1383
						n += 1
1384
						arr.push("#{@y + iH - minusH},#{@x + iW - minusW}")
1385
					end
1386
				end
1387
				break if n >= 2
1388
			end
1389
			break if n >= 2
1390
		end
1391
		return "replace" if replaceable && n < 2
1392
		return (n < 2 && !replaceable)
1393
	end
1394
  
1395-
	def set=(set)
1395+
  def set=(set)
1396
		@x = set
1397
		@y = set
1398
		@mini_help.visible = (set == 0 ? true : false) 
1399
	end
1400
	
1401
	# Draws item graphics
1402
	def draw_item(item_id, type, i , j)
1403
		#~ if type == "i" and
1404
		#~ $game_party.item_can_use?($data_items[item_id].id)
1405
		opacity = 255
1406
		#~ else
1407
		#~ opacity = 128
1408
		#~ end
1409
		
1410
		if item_id != 0
1411
			x = 4 + (j * 32)
1412
			y = i * 32
1413
			itemWeaponArmor = item(type, item_id)
1414
			
1415
			case type
1416
			when "i"
1417
				color = Grid_Variables::COLOR_ITEMS
1418
			when "w"
1419
				color = Grid_Variables::COLOR_WEAPONS
1420
			when "a"
1421
				color = Grid_Variables::COLOR_ARMORS
1422
			end
1423
			
1424
			if type != "" && type[0,1] != "["
1425
				x = j * 32
1426
				y = i * 32
1427
				updateItemSizeFirstDraw(item_id, type)
1428
				bitmap = RPG::Cache.icon(Grid_Variables::BIG_ICONS_PREFIX + itemWeaponArmor.icon_name)
1429
				
1430
				if Grid_Variables::USE_BIG_ICONS && (bitmap.width != 24 && bitmap.height != 24)
1431
					self.contents.blt(x, y, bitmap, Rect.new(0, 0, @itemWidth * 32, @itemHeight * 32), opacity)
1432
				else
1433
					x += ((@itemWidth * 32) / 2) - 16
1434
					y += ((@itemHeight * 32) / 2) - 16
1435
					self.contents.blt(x + 4, y + 4, bitmap, Rect.new(0, 0, 48, 24), opacity)
1436
				end
1437
				
1438
				@grid_color.bitmap.fill_rect(j*32+1, i*32+1, (@itemWidth * 32) - 1, (@itemHeight * 32) - 1, color)
1439
			end
1440
		end
1441
	end
1442
end
1443
1444
#==============================================================================
1445
# This is Window_Target, edited to darken actors that can't equip the item.
1446
# Since there is no way to change the normal color on Window_Base, I had to
1447
# rewrite most draw functions here.
1448
#==============================================================================
1449
class Window_Target_Equip < Window_Selectable
1450
	
1451
	def initialize
1452
		super(0, 0, 336, 480)
1453
		self.contents = Bitmap.new(width - 32, height - 32)
1454
		self.contents.font.name = $fontface
1455
		self.contents.font.size = $fontsize
1456
		self.z += 10
1457
		@item_max = $game_party.actors.size
1458
		@disabled_actor = []
1459
		refresh
1460
	end
1461
	
1462
	def refresh
1463
		self.contents.clear
1464
		for i in 0...$game_party.actors.size
1465
			disabled = @disabled_actor[i]
1466
			if disabled
1467
				self.contents.font.color = disabled_color
1468
			else
1469
				self.contents.font.color = normal_color
1470
			end
1471
			
1472
			x = 4
1473
			y = i * 116
1474
			actor = $game_party.actors[i]
1475
			
1476
			# actor name
1477
			self.contents.draw_text(x, y, 120, 32, actor.name)
1478
			
1479
			# actor class
1480
			self.contents.draw_text(x + 144, y, 236, 32, actor.class_name)
1481
			
1482
			# actor level
1483
			self.contents.font.color = system_color if !disabled
1484
			self.contents.draw_text(x + 8, y + 32, 32, 32, "Lv")	
1485
			self.contents.font.color = normal_color if !disabled
1486
			self.contents.draw_text(x + 8 + 32, y + 32, 24, 32, actor.level.to_s, 2)
1487
			
1488
			# actor state
1489
			text = make_battler_state_text(actor, width, true)
1490
			self.contents.font.color = knockout_color if actor.hp == 0 && !disabled
1491
			self.contents.draw_text(x + 8, y + 64, width, 32, text)
1492
			self.contents.font.color = normal_color if actor.hp == 0 && !disabled
1493
			
1494
			# actor hp
1495
			self.contents.font.color = system_color if !disabled
1496
			self.contents.draw_text(x + 152, y + 32, 32, 32, $data_system.words.hp)
1497
			# Checking if there is enough space for max HP
1498
			if 144 - 32 >= 108
1499
				hp_x = x + 152 + 144 - 108
1500
				flag = true
1501
			elsif 144 - 32 >= 48
1502
				hp_x = x + 152 + 144 - 48
1503
				flag = false
1504
			end
1505
			# Draw HP
1506
			if !disabled 
1507
				if actor.hp == 0
1508
					self.contents.font.color = knockout_color
1509
				elsif actor.hp <= actor.maxhp / 4
1510
					self.contents.font.color = crisis_color
1511
				else
1512
					self.contents.font.color = normal_color
1513
				end
1514
			end
1515
			self.contents.draw_text(hp_x, y + 32, 48, 32, actor.hp.to_s, 2)
1516
			# Draw max HP
1517
			if flag
1518
				self.contents.font.color = normal_color if !disabled
1519
				self.contents.draw_text(hp_x + 48, y + 32, 12, 32, "/", 1)
1520
				self.contents.draw_text(hp_x + 60, y + 32, 48, 32, actor.maxhp.to_s)
1521
			end
1522
			
1523
			# actor sp
1524
			self.contents.font.color = system_color if !disabled
1525
			self.contents.draw_text(x + 152, y + 64, 32, 32, $data_system.words.sp)
1526
			# Check if there is enough space for max SP
1527
			if 144 - 32 >= 108
1528
				sp_x = x + 152+ 144 - 108
1529
				flag = true
1530
			elsif 144 - 32 >= 48
1531
				sp_x = x + 152+ 144 - 48
1532
				flag = false
1533
			end
1534
			# Draw SP
1535
			if !disabled 
1536
				if actor.sp == 0
1537
					self.contents.font.color = knockout_color
1538
				elsif actor.sp <= actor.maxsp / 4
1539
					self.contents.font.color = crisis_color
1540
				else
1541
					self.contents.font.color = normal_color
1542
				end
1543
			end
1544
			self.contents.draw_text(sp_x, y + 64, 48, 32, actor.sp.to_s, 2)
1545
			# Draw max SP
1546
			if flag
1547
				self.contents.font.color = normal_color if !disabled
1548
				self.contents.draw_text(sp_x + 48, y + 64, 12, 32, "/", 1)
1549
				self.contents.draw_text(sp_x + 60, y + 64, 48, 32, actor.maxsp.to_s)
1550
			end
1551
		end
1552
	end
1553
	
1554
	def update_cursor_rect
1555
		# Se define a posição atual -1
1556
		if @index < 0
1557
			self.cursor_rect.set(0, 0, self.width - 32, @item_max * 116 - 20)
1558
		else
1559
			self.cursor_rect.set(0, @index * 116, self.width - 32, 96)
1560
		end
1561
	end
1562
	
1563
	def disable_actor(actor_id)
1564
		@disabled_actor[actor_id] = true
1565
	end
1566
	
1567
	def enable_actor(actor_id)
1568
		@disabled_actor[actor_id] = false
1569
	end
1570
	
1571
	def disabled?(id)
1572
		return @disabled_actor[id]
1573
	end
1574
end
1575
1576
#==============================================================================
1577
# The mini help window shows the item name below the selection cursor
1578
#==============================================================================
1579
class Mini_Help < Window_Base
1580
	alias old_initialize initialize
1581
	def initialize
1582
		super(0, 0, 180, 43)
1583
		self.contents = Bitmap.new(width - 32, height - 32)
1584
		self.contents.font.size = 14
1585
		self.back_opacity = 170
1586
		self.z = 102
1587
		self.visible = false
1588
	end
1589
	
1590
	def set_text(text, align = 1)
1591
		# If at least one part of text and alignment differ from last time
1592
		if text != @text or align != @align
1593
			# Redraw text
1594
			self.contents.clear
1595
			#self.contents.font.color = normal_color
1596
			self.contents.draw_text(4, -12, self.width - 40, 32, text, align)
1597
			#self.width = self.contents.text_size(text).width
1598
			@text = text
1599
			@align = align
1600
			@actor = nil
1601
		end
1602
		self.visible = true
1603
	end
1604
end
1605
1606
#==============================================================================
1607
# Changes the way the game handles item creation 
1608
#==============================================================================
1609
class Game_Actor < Game_Battler
1610
	attr_accessor :item_grid
1611
	alias old_initialize initialize
1612
	def initialize(actor_id)
1613
		old_initialize(actor_id)
1614
		@item_grid = Array.new(Grid_Variables::GRID_HEIGHT)
1615
		for i in 0..@item_grid.size - 1
1616
			@item_grid[i] = Array.new(Grid_Variables::GRID_WIDTH)
1617
			for k in 0..@item_grid[i].size - 1
1618
				@item_grid[i][k] = Array.new(2)
1619
				@item_grid[i][k][0] = 0
1620
				@item_grid[i][k][1] = ""
1621
			end
1622
		end
1623
	end
1624
	
1625
	# This edit is to avoid losing the item if your inventory is already full.
1626
	def equip(equip_type, id)
1627
		case equip_type
1628
		when 0  # Weapons
1629
			if id == 0 or $game_party.weapon_number(id) > 0
1630
				$game_party.lose_weapon(id, 1)
1631
				if !$game_party.isGridFull?(@weapon_id, "w") || @weapon_id == 0
1632
					$game_party.gain_weapon(@weapon_id, 1)
1633
					@weapon_id = id
1634
				else
1635
					$game_party.gain_weapon(id, 1)
1636
					$game_system.se_play($data_system.buzzer_se)
1637
					return nil
1638
				end
1639
			end
1640
		when 1  # Shield
1641
			if id == 0 or $game_party.armor_number(id) > 0 
1642
				$game_party.lose_armor(id, 1)
1643
				if !$game_party.isGridFull?(@armor1_id, "a") || @armor1_id == 0
1644
					update_auto_state($data_armors[@armor1_id], $data_armors[id])
1645
					$game_party.gain_armor(@armor1_id, 1)
1646
					@armor1_id = id
1647
				else
1648
					$game_party.gain_armor(id, 1)
1649
					return nil
1650
				end
1651
			end
1652
		when 2  # Headgear
1653
			if id == 0 or $game_party.armor_number(id) > 0
1654
				$game_party.lose_armor(id, 1)
1655
				if !$game_party.isGridFull?(@armor2_id, "a") || @armor2_id == 0
1656
					update_auto_state($data_armors[@armor2_id], $data_armors[id])
1657
					$game_party.gain_armor(@armor2_id, 1)
1658
					@armor2_id = id
1659
				else
1660
					$game_party.gain_armor(id, 1)
1661
					return nil
1662
				end
1663
			end
1664
		when 3  # Armor
1665
			if id == 0 or $game_party.armor_number(id) > 0
1666
				$game_party.lose_armor(id, 1)
1667
				if !$game_party.isGridFull?(@armor3_id, "a") || @armor3_id == 0
1668
					update_auto_state($data_armors[@armor3_id], $data_armors[id])
1669
					$game_party.gain_armor(@armor3_id, 1)
1670
					@armor3_id = id
1671
				else
1672
					$game_party.gain_armor(id, 1)
1673
					return nil
1674
				end
1675
			end
1676
		when 4  # Accessory
1677
			if id == 0 or $game_party.armor_number(id) > 0
1678
				$game_party.lose_armor(id, 1)
1679
				if !$game_party.isGridFull?(@armor4_id, "a") || @armor4_id == 0
1680
					update_auto_state($data_armors[@armor4_id], $data_armors[id])
1681
					$game_party.gain_armor(@armor4_id, 1)
1682
					@armor4_id = id
1683
				else
1684
					$game_party.gain_armor(id, 1)
1685
					return nil
1686
				end
1687
			end
1688
		end
1689
	end
1690
	
1691
	# Same as above, but without deleting item. This one is used for the grid equip
1692
	def grid_equip(equip_type, id)
1693
		case equip_type
1694
		when 0  # Armas
1695
			if id == 0 or $game_party.weapon_number(id) > 0
1696
				$game_party.gain_weapon(@weapon_id, 1)
1697
				@weapon_id = id
1698
			end
1699
		when 1  # Escudo
1700
			if id == 0 or $game_party.armor_number(id) > 0
1701
				update_auto_state($data_armors[@armor1_id], $data_armors[id])
1702
				$game_party.gain_armor(@armor1_id, 1)
1703
				@armor1_id = id
1704
			end
1705
		when 2  # Elmo
1706
			if id == 0 or $game_party.armor_number(id) > 0
1707
				update_auto_state($data_armors[@armor2_id], $data_armors[id])
1708
				$game_party.gain_armor(@armor2_id, 1)
1709
				@armor2_id = id
1710
			end
1711
		when 3  # Armadura
1712
			if id == 0 or $game_party.armor_number(id) > 0
1713
				update_auto_state($data_armors[@armor3_id], $data_armors[id])
1714
				$game_party.gain_armor(@armor3_id, 1)
1715
				@armor3_id = id
1716
			end
1717
		when 4  # Acessório
1718
			if id == 0 or $game_party.armor_number(id) > 0
1719
				update_auto_state($data_armors[@armor4_id], $data_armors[id])
1720
				$game_party.gain_armor(@armor4_id, 1)
1721
				@armor4_id = id
1722
			end
1723
		end
1724
	end
1725
end
1726
1727
#==============================================================================
1728
# Handles most of the grid inventory functions
1729
#==============================================================================
1730
class Game_Party
1731
	# These have been edited for the Scene_Shop. If it returns something, that 
1732-
	# means the grid is full and it couldn't add more items, so we use that number
1732+
  # means the grid is full and it couldn't add more items, so we use that number
1733-
	# to charge for the items bought
1733+
  # to charge for the items bought
1734
	def gain_item(item_id, n)
1735
		if item_id > 0
1736
			if n.abs == n # if the number is a positive value, add the items
1737
				for k in 1..n
1738
					break if set_item(item_id, "i") == nil
1739
				end
1740
				return k unless k == n
1741
			else # if the number is a negative value, remove the items
1742
				lose_item(item_id, n.abs)
1743
			end
1744
		end
1745
	end
1746
	
1747
	def gain_weapon(weapon_id, n)
1748
		if weapon_id > 0
1749
			if n.abs == n # if the number is a positive value, add the items
1750
				for k in 1..n
1751
					break if set_item(weapon_id, "w") == nil
1752
				end
1753
				return k unless k == n
1754
			else # if the number is a negative value, remove the items
1755
				lose_weapon(weapon_id, n.abs)
1756
			end
1757
		end
1758
	end
1759
	
1760
	def gain_armor(armor_id, n)
1761
		if armor_id > 0
1762
			if n.abs == n # if the number is a positive value, add the items
1763
				for k in 1..n
1764
					break if set_item(armor_id, "a") == nil
1765
				end
1766
				return k unless k == n
1767
			else # if the number is a negative value, remove the items
1768
				lose_armor(armor_id, n.abs)
1769
			end
1770
		end
1771
	end
1772
	
1773
	def lose_item(item_id, n, random = true)
1774-
	def lose_item(item_id, n)
1774+
		if random == true
1775
			if item_id > 0
1776-
			for k in 1..n
1776+
1777-
				del_item(item_id, "i")
1777+
					del_item(item_id, "i")
1778
				end
1779
			end
1780
		end
1781
		@items[item_id] = [[item_number(item_id) + -n, 0].max, 99].min
1782
	end
1783-
	def lose_weapon(weapon_id, n)
1783+
1784
	def lose_weapon(weapon_id, n, random = true)
1785-
			for k in 1..n
1785+
		if random == true
1786-
				del_item(weapon_id, "w")
1786+
			if weapon_id > 0
1787
				for k in 1..n
1788
					del_item(weapon_id, "w")
1789
				end
1790
			end
1791
		end
1792-
	def lose_armor(armor_id, n)
1792+
1793
	end
1794-
			for k in 1..n
1794+
1795-
				del_item(armor_id, "a")
1795+
	def lose_armor(armor_id, n, random = true)
1796
		if random == true
1797
			if armor_id > 0
1798
				for k in 1..n
1799
					del_item(armor_id, "a")
1800
				end
1801
			end
1802
		end
1803
		@armors[armor_id] = [[armor_number(armor_id) + -n, 0].max, 99].min
1804
	end
1805
	
1806
	# Mostly used for the delete_item method. This removes the item from the inventory.
1807
	def eraseData(type, item_id, n)
1808
		case type
1809
		when "i"
1810
			@items[item_id] = [[item_number(item_id) + -n, 0].max, 99].min
1811
		when "w"
1812
			@weapons[item_id] = [[weapon_number(item_id) + -n, 0].max, 99].min
1813
		when "a"
1814
			@armors[item_id] = [[armor_number(item_id) + -n, 0].max, 99].min
1815
		end
1816
	end
1817
	
1818
	# Update item properties
1819
	def updateItemProp(type, item_id)
1820
		case type
1821
		when "i"
1822
			name = $data_grid[0][item_id]
1823
		when "w"
1824
			name = $data_grid[1][item_id]
1825
		when "a"
1826
			name = $data_grid[2][item_id]
1827
		else
1828
			name = nil
1829
		end
1830
		
1831
		if name != nil
1832
			gridValues = name.split('x')
1833
			@itemWidth = gridValues[0].to_i
1834
			@itemHeight = gridValues[1].to_i
1835
		end
1836
	end
1837
	
1838
	# Checks if x and y are empty
1839
	def isEmpty?(x, y)
1840
		for iH in 0...@itemHeight.to_i 
1841
			for iW in 0...@itemWidth.to_i 
1842
				cond = (self.actors[0].item_grid[x + iH][y + iW][0] == 0)
1843
				break if !cond
1844
			end
1845
			break if !cond
1846
		end
1847
		return cond
1848
	end	
1849
	
1850
	# Checking if there is enough space for the item on the grid
1851
	def isGridFull?(item_id, type, item = false)
1852
		if type == "" && item != false
1853
			case item
1854
			when RPG::Item
1855
				type = "i"
1856
			when RPG::Weapon
1857
				type = "w"
1858
			when RPG::Armor
1859
				type = "a"
1860
			end
1861
		end
1862
		
1863
		if item == false
1864
			updateItemProp(type, item_id)
1865
		else
1866
			case type
1867
			when "i"
1868
				name = $data_grid[0][item_id]
1869
			when "w"
1870
				name = $data_grid[1][item_id]
1871
			when "a"
1872
				name = $data_grid[2][item_id]
1873
			else
1874
				name = nil
1875
			end
1876
			
1877
			if name != nil
1878
				gridValues = name.split('x')
1879
				@itemWidth = gridValues[0].to_i
1880
				@itemHeight = gridValues[1].to_i
1881
			end
1882
		end
1883
		
1884
		
1885
		for a in 0..self.actors[0].item_grid.size - 1
1886
			for b in 0..self.actors[0].item_grid[a].size - 1
1887
				if b < self.actors[0].item_grid[a].size - (@itemWidth.to_i - 1) and a < self.actors[0].item_grid.size - (@itemHeight.to_i - 1)
1888
					cond = isEmpty?(a, b)
1889
					break if cond
1890
				end
1891
			end
1892-
	# Checking if the grid is full for multiple items
1892+
1893-
	def isGridFullMultipleItems?(arrayOfIds, types)
1893+
1894-
		# Just a little precaution, in case the user forgets the square brackets
1894+
1895-
		arrayOfIds = [arrayOfIds] if !arrayOfIds.kind_of?(Array)
1895+
1896
  
1897-
		for i in 0..arrayOfIds.length - 1
1897+
  # Checking if the grid is full for multiple items
1898-
			item_id = arrayOfIds[i]
1898+
  def isGridFullMultipleItems?(arrayOfIds, types)
1899-
			if types.length == 1
1899+
    # Just a little precaution, in case the user forgets the square brackets
1900-
				type = types
1900+
    arrayOfIds = [arrayOfIds] if !arrayOfIds.kind_of?(Array)
1901
    
1902-
				type = types[i]
1902+
    for i in 0..arrayOfIds.length - 1
1903
      item_id = arrayOfIds[i]
1904
      if types.length == 1
1905
        type = types
1906
      else
1907
        type = types[i]
1908
      end
1909
            
1910
      case type
1911
      when "i"
1912
        name = $data_grid[0][item_id]
1913
      when "w"
1914
        name = $data_grid[1][item_id]
1915
      when "a"
1916
        name = $data_grid[2][item_id]
1917
      else
1918
        name = nil
1919
      end
1920
        
1921
      if name != nil
1922-
			for a in 0..self.actors[0].item_grid.size - 1
1922+
        gridValues = name.split('x')
1923-
				for b in 0..self.actors[0].item_grid[a].size - 1
1923+
        @itemWidth = gridValues[0].to_i
1924-
					if b < self.actors[0].item_grid[a].size - (@itemWidth.to_i - 1) and a < self.actors[0].item_grid.size - (@itemHeight.to_i - 1)
1924+
        @itemHeight = gridValues[1].to_i
1925-
						cond = isEmpty?(a, b)
1925+
      end
1926-
						break if cond
1926+
            
1927
      for a in 0..self.actors[0].item_grid.size - 1
1928
        for b in 0..self.actors[0].item_grid[a].size - 1
1929-
				break if cond
1929+
          if b < self.actors[0].item_grid[a].size - (@itemWidth.to_i - 1) and a < self.actors[0].item_grid.size - (@itemHeight.to_i - 1)
1930
            cond = isEmpty?(a, b)
1931
            break if cond
1932
          end
1933-
		return !cond
1933+
        end
1934
        break if cond
1935
      end
1936
      break if !cond
1937
    end
1938
    return !cond
1939
  end
1940
  
1941
	# Adds the item values to the grid
1942
	def set_item(item_id, type, returnPos = false)
1943
		for a in 0..self.actors[0].item_grid.size - 1
1944
			for b in 0..self.actors[0].item_grid[a].size - 1
1945
				updateItemProp(type, item_id)			
1946
				iW = 0; iH = 0
1947
				if b < self.actors[0].item_grid[a].size - (@itemWidth.to_i - 1) and a < self.actors[0].item_grid.size - (@itemHeight.to_i - 1)
1948
					if isEmpty?(a, b)
1949
						for iH in 0...@itemHeight.to_i 
1950
							for iW in 0...@itemWidth.to_i 
1951
								if iH == 0 && iW == 0
1952
									self.actors[0].item_grid[a][b][0] = item_id
1953
									self.actors[0].item_grid[a][b][1] = type
1954
								else
1955
									self.actors[0].item_grid[a + iH][b + iW][0] = item_id
1956
									self.actors[0].item_grid[a + iH][b + iW][1] = "[#{iH}x#{iW}]"	
1957
								end
1958
							end
1959
						end
1960
						whatToReturn = ""
1961
						case type
1962
						when "i"
1963
							@items[item_id] = [[item_number(item_id) + 1, 0].max, 99].min
1964
						when "w"
1965
							@weapons[item_id] = [[weapon_number(item_id) + 1, 0].max, 99].min
1966
						when "a"
1967
							@armors[item_id] = [[armor_number(item_id) + 1, 0].max, 99].min
1968
						end
1969
						break
1970
					else
1971
						whatToReturn = nil
1972
					end
1973
				end
1974
			end
1975
			break if whatToReturn != nil
1976
		end
1977
		
1978
		return [a, b] if returnPos
1979
		return whatToReturn
1980
	end
1981
	
1982
	# Deletes the item values from the grid
1983
	def del_item(item_id, type)
1984
		updateItemProp(type, item_id)
1985
		for a in 0..self.actors[0].item_grid.size - 1
1986
			for b in 0..self.actors[0].item_grid[a].size - 1
1987
				if self.actors[0].item_grid[a][b][0] == item_id and self.actors[0].item_grid[a][b][1] == type
1988
					for iH in 0...@itemHeight.to_i 
1989
						for iW in 0...@itemWidth.to_i 
1990
							self.actors[0].item_grid[a + iH][b + iW][0] = 0
1991
							self.actors[0].item_grid[a + iH][b + iW][1] = ""
1992
						end
1993
					end
1994
					return
1995
				end
1996
			end
1997
		end
1998
	end
1999
end
2000
2001
#==============================================================================
2002
# This is the cursor used when moving the item.
2003
#==============================================================================
2004
class Cursor_Icon < RPG::Sprite
2005
	def initialize
2006
		super
2007
		@color = Color.new(255,255,0,50)
2008
		@rect = Rect.new(0, 0, 24, 24)
2009
	end
2010
	
2011
	def refresh(bitmap, iW, iH)
2012
		if Grid_Variables::USE_BIG_ICONS
2013
			x = 0
2014
			y = 0
2015
			@rect = Rect.new(0, 0, iW*32, iH*32)	
2016
		else
2017
			x = 4 + ((iW * 32) / 2) - 16
2018
			y = 4 + ((iH * 32) / 2) - 16 
2019
		end
2020
		
2021
		width = iW * 32
2022
		height = iH * 32
2023
		
2024
		if self.bitmap == nil or (self.bitmap.width != width or self.bitmap.height != height)
2025
			self.bitmap = Bitmap.new(width, height)
2026
		else
2027
			self.bitmap.clear
2028
		end
2029
		self.bitmap.fill_rect(0,0,width,height, @color)
2030
		self.bitmap.blt(x, y, bitmap, @rect)
2031
		self.z = 9999
2032
	end
2033
end