[Hướng Dẫn] [XP] Hướng dẫn tạo Scene_Menu

in RPG Maker
Mình cũng gà mờ thôi nên mấy pro đừng vào chém kẻo tội :D
[size=large][align=center]Mở đầu[/align][/size]
Đầu tiên cần phác thảo sơ sơ về cấu trúc của menu mình muốn làm ra giấy hay đâu đó cũng được
ví dụ: mình muốn sắp xếp bố cục menu lại như thế này và hiển thị trang bị của nhân vật ra ngoài, thay các dòng lệnh = hình ảnh tượng trưng(dĩ nhiên là phác thảo ra paint chứ k có ra ngay thế này đc)

Vậy thì các bước cần làm là:
1/ Thay đổi các câu "Item","Skill",... bằng hình ảnh và tạo hiệu ứng cho các hình ảnh thay thế này
2/ Sắp xếp lại vị trí của Play time, Step count, Gold, trừa chỗ chính cho Menu_Status
3/ Thay đổi cấu trúc của Menu Status cho phù hợp
Kết quả sau khi làm:*các bạn chỉ cần điều chỉnh số lượng nhân vật, script sẽ tự động căn chỉnh lại menu*
Muốn demo?: cứ copy 2 script này vào là tự động có demo đó :Dtrong quá trình làm có chỉnh thêm chút chút nên có thể k đồng bộ hoặc có lỗi, ai thấy lỗi thì báo mình nha ^^!
[size=large][align=center]Mở đầu[/align][/size]
Đầu tiên cần phác thảo sơ sơ về cấu trúc của menu mình muốn làm ra giấy hay đâu đó cũng được
ví dụ: mình muốn sắp xếp bố cục menu lại như thế này và hiển thị trang bị của nhân vật ra ngoài, thay các dòng lệnh = hình ảnh tượng trưng(dĩ nhiên là phác thảo ra paint chứ k có ra ngay thế này đc)

Vậy thì các bước cần làm là:
1/ Thay đổi các câu "Item","Skill",... bằng hình ảnh và tạo hiệu ứng cho các hình ảnh thay thế này
2/ Sắp xếp lại vị trí của Play time, Step count, Gold, trừa chỗ chính cho Menu_Status
3/ Thay đổi cấu trúc của Menu Status cho phù hợp
Kết quả sau khi làm:*các bạn chỉ cần điều chỉnh số lượng nhân vật, script sẽ tự động căn chỉnh lại menu*
test với 3 người:

2 người:

[size=large][align=center]Bắt đầu nào[/align][/size]

2 người:

Mở script editor lên vào Scene_Menu
kiếm
các bạn có thể cho bức hình di chuyển, hay làm bất cứ hoạt động nào, dưới đây là 1 ví dụ(các bạn tự add vào để thấy kết quả): thêm dòng lệnh này dưới def update_command(update_command này thuộc def update cho nên thay đổi ở đây cũng là thay đổi ở def update)
kiếm
@command_window.index = @menu_index
thêm vào ngay dưới
@command_window.visible = false # làm ẩn command_window
# các bước dưới đây để gọi ra 6 bức ảnh thay thế cho command_window
# cách khai báo biến các bạn có thể tham khảo ở bài khác
@cmd = []
for i in 0...6
@cmd[i] = Sprite.new
end
@cmd[0].bitmap = RPG::Cache.icon("032-Item01") # các bạn có thể thay các icon này bằng hình khác
@cmd[1].bitmap = RPG::Cache.icon("044-Skill01")
@cmd[2].bitmap = RPG::Cache.icon("001-Weapon01")
@cmd[3].bitmap = RPG::Cache.icon("050-Skill07")
@cmd[4].bitmap = RPG::Cache.icon("038-Item07")
@cmd[5].bitmap = RPG::Cache.icon("049-Skill06")
for i in 0...6
@cmd[i].x = 156 + i * 56
@cmd[i].y = 16
@cmd[i].ox = @cmd[i].bitmap.width/2
@cmd[i].oy = @cmd[i].bitmap.height/2
end
xuống dưới tìm
@command_window.dispose
thêm vào
for i in 0...6
@cmd[i].dispose
end
dưới
def update
thêm vào
for i in 0...6
@cmd[i].update
end
2 bước này chỉ là thủ tục, .dispose có chức năng làm biến mất(khác với ẩn) và .update để cập nhập hoạt động của các biến. Các hiệu ứng cho Menu đều được thực hiện tại def update nàycác bạn có thể cho bức hình di chuyển, hay làm bất cứ hoạt động nào, dưới đây là 1 ví dụ(các bạn tự add vào để thấy kết quả): thêm dòng lệnh này dưới def update_command(update_command này thuộc def update cho nên thay đổi ở đây cũng là thay đổi ở def update)
if @a == true #hiệu ứng này có 2 pha, biến @a có tác dụng như công tắc chuyển giữa 2 pha
@cmd[@command_window.index].zoom_x *= 1.2
@cmd[@command_window.index].zoom_y *= 1.2
if @cmd[@command_window.index].zoom_x >= 1.5
@a = false
end
else
@cmd[@command_window.index].zoom_x /= 1.2
@cmd[@command_window.index].zoom_y /= 1.2
if @cmd[@command_window.index].zoom_x <= 0.5
@a = true
end
end
for i in 0...6
@cmd[i].zoom_x = @cmd[i].zoom_y = 1 if i != @command_window.index
end
cái này thì đơn giản rồi, các bạn tìm các dòng dưới đây, rồi thay thế tọa độ x,y sao cho phù hợp(đơn giản nhưng mà phải làm lui làm tới để căn chỉnh tọa độ)
@playtime_window.x =
@playtime_window.y =
@steps_window.x =
@steps_window.y =
@gold_window.x =
@gold_window.y =
@status_window.x =
@status_window.y =
Ở đây các bước sẽ rất lộn xộn, mình sắp xếp thứ tự theo kiểu "làm đến đâu chỉnh đến đó" khi làm script chứ k phải nghĩ được 1 loạt từ trên xuống dưới rồi cứ làm đâu :D
Bước này làm việc chủ yếu với Window_MenuStatus
*lưu ý: các bạn nên copy riêng các script sau đây ra đặt ngay trên script Scene_Menu để dễ làm việc, đó là Window_Selectable,Window_Command và Window_MenuStatus

thay
Bước này làm việc chủ yếu với Window_MenuStatus
*lưu ý: các bạn nên copy riêng các script sau đây ra đặt ngay trên script Scene_Menu để dễ làm việc, đó là Window_Selectable,Window_Command và Window_MenuStatus

thay
class Window_MenuStatus < Window_Selectable
class Window_Command < Window_Selectable2
class Window_Selectable < Window_Base
thành
class Window_MenuStatus2 < Window_Selectable2
class Window_Command2 < Window_Selectable2
class Window_Selectable2 < Window_Base
Đầu tiên là Window_MenuStatus2 đã được copy ra riêng
ở def initialize các bạn sẽ thấy dòng super(0,0, độ rộng, độ cao) độ rộng vào cao của Window này tùy ý các bạn, ở đây mình lấy là 640 và 360
ở def refresh sẽ thấy các lệnh kiểu như draw_actor_..., đây chính là những thứ bạn sẽ chỉnh sửa lại về tọa độ theo ý mình muốn, việc chỉnh tọa độ này đơn giản nhưng khá tốn thời gian ngồi căn chỉnh.
Các bạn để ý Menu gốc được chia theo chiều dọc, do đó tọa độ x là hằng số còn y thay đổi tùy vào i, với i có thể hiểu là số thứ tự của của các nhân vật có trong team được hiển thị lên menu, với i = 0 thì là nhân vật thứ 1,tương tự i = 3 là nhân vật thứ 4,...
vào Window_Base thêm vào ở dưới cùng(hoặc ở đâu đó cũng được) lệnh sau(thực chất là copy của def draw_item_name
tiếp đến là Window_Selectable2
ở def refresh sẽ thấy các lệnh kiểu như draw_actor_..., đây chính là những thứ bạn sẽ chỉnh sửa lại về tọa độ theo ý mình muốn, việc chỉnh tọa độ này đơn giản nhưng khá tốn thời gian ngồi căn chỉnh.
Các bạn để ý Menu gốc được chia theo chiều dọc, do đó tọa độ x là hằng số còn y thay đổi tùy vào i, với i có thể hiểu là số thứ tự của của các nhân vật có trong team được hiển thị lên menu, với i = 0 thì là nhân vật thứ 1,tương tự i = 3 là nhân vật thứ 4,...
y = i * 116
bây giờ Menu mới của mình sẽ sắp xếp theo chiều ngang do đó x sẽ thay đổi theo i còn y là hằng số, dưới đây là phần mình đã sắp xếp lại và giải thích
def refresh
self.contents.clear
@item_max = $game_party.actors.size
for i in 0...$game_party.actors.size
x = i*(640/$game_party.actors.size) # 640/$game_party... chính là kích thước của mỗi khung, như vậy kích thước ngang của window sẽ chia đều cho số lượng nhân vật
y = 16 # như đã nói, y = hằng
actor = $game_party.actors[i]
draw_actor_graphic(actor, x+64+(4-$game_party.actors.size)*32, y+160) # phần ở trong ngoặc là việc tăng thêm tọa độ x của [b]actor_graphic[/b] ứng với số nhân vật hiện có trong party, còn lại chỉ là việc căn chỉnh tọa độ
#dưới đây là phần hiển thị trang bị của từng nhân vật, cái này thực chất là copy từ script Equip mà ra cả :D
@data = []
@data.push($data_weapons[actor.weapon_id])
@data.push($data_armors[actor.armor1_id])
@data.push($data_armors[actor.armor2_id])
@data.push($data_armors[actor.armor3_id])
@data.push($data_armors[actor.armor4_id])
# điều chỉnh tọa độ cho các icon trang bị
draw_weaponmenu(@data[0], x,y+136)
draw_weaponmenu(@data[1], x+100+(4-$game_party.actors.size)*64,y+136)
draw_weaponmenu(@data[2], x,y+96)
draw_weaponmenu(@data[3], x+100+(4-$game_party.actors.size)*64,y+96)
draw_weaponmenu(@data[4], x,y+172)
draw_actor_name(actor, x, y-16)
draw_actor_state(actor, x+(4-$game_party.actors.size)*64, y+8)
draw_actor_level(actor,x+72+(4-$game_party.actors.size)*64, y + 64)
draw_actor_class(actor, x, y+32)
draw_actor_hp(actor, x, y + 212)
draw_actor_sp(actor, x, y + 248)
draw_actor_exp(actor, x, y + 280)
end
end
def update_cursor_rect
if @index < 0
self.cursor_rect.empty
else
self.cursor_rect.set(@index*(640/$game_party.actors.size)-16, -16, 640/$game_party.actors.size,360) # chỉnh lại kích thước cho ô lựa chọn
end
end
đến đây sẽ bị báo lỗi liên quan tới draw_weaponmenu do bạn chưa khai báo nóvào Window_Base thêm vào ở dưới cùng(hoặc ở đâu đó cũng được) lệnh sau(thực chất là copy của def draw_item_name
def draw_weaponmenu(item, x, y)
if item == nil
return
end
bitmap = RPG::Cache.icon(item.icon_name)
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
end
thực sự có thể xóa rất nhiều lệnh k cần thiết trong script này, nhưng mà cứ để đó đi, bao h bạn hiểu đc thì có thể tự xóa mà k lo lỗi
Bây giờ xuống def update tìm tất cả
còn Window_Command2 thì chỉ đổi tên rồi thôiBây giờ xuống def update tìm tất cả
(Input::DOWN)
(Input::UP)
và thay nó thành
(Input::RIGHT)
(Input::LEFT)
class Window_Base < Window
def draw_weaponmenu(item, x, y)
if item == nil
return
end
bitmap = RPG::Cache.icon(item.icon_name)
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
end
end
class Window_Selectable2 < Window_Base
attr_reader :index # cursor position
def initialize(x, y, width, height)
super(x, y, width, height)
@item_max = 1
@column_max = 1
@index = -1
end
def index=(index)
@index = index
end
def update_cursor_rect
if @index < 0
self.cursor_rect.empty
return
else
self.cursor_rect.set(x, y, 32, 32)
end
end
def update
super
if self.active and @item_max > 0 and @index >= 0
if Input.repeat?(Input::DOWN) or Input.repeat?(Input::RIGHT)
if (@column_max == 1 and (Input.trigger?(Input::DOWN) or Input.trigger?(Input::RIGHT))) or
@index < @item_max - @column_max
$game_system.se_play($data_system.cursor_se)
@index = (@index + @column_max) % @item_max
else
$game_system.se_play($data_system.cursor_se)
@index = 0
end
end
if Input.repeat?(Input::UP) or Input.repeat?(Input::LEFT)
if (@column_max == 1 and Input.trigger?(Input::UP) or Input.trigger?(Input::LEFT)) or
@index >= @column_max
$game_system.se_play($data_system.cursor_se)
@index = (@index - @column_max + @item_max) % @item_max
else
$game_system.se_play($data_system.cursor_se)
@index = @item_max-1
end
end
end
update_cursor_rect
end
end
class Window_Command2 < Window_Selectable2
def initialize(width, commands)
super(0, 0, width, commands.size * 32 + 32)
@item_max = commands.size
@commands = commands
self.contents = Bitmap.new(width - 32, @item_max * 32)
refresh
self.index = 0
end
def refresh
self.contents.clear
for i in 0...@item_max
draw_item(i, normal_color)
end
end
def draw_item(index, color)
self.contents.font.color = color
rect = Rect.new(4, 32 * index, self.contents.width - 8, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, @commands[index])
end
def disable_item(index)
draw_item(index, disabled_color)
end
end
class Window_MenuStatus2 < Window_Selectable2
def initialize
super(0, 0, 640, 360)
self.contents = Bitmap.new(width-32, height-32)
refresh
self.active = false
self.index = -1
end
def refresh
self.contents.clear
@item_max = $game_party.actors.size
for i in 0...$game_party.actors.size
x = i*(640/$game_party.actors.size)
y = 16
rong = self.width / $game_party.actors.size
actor = $game_party.actors
draw_actor_graphic(actor, x+64+(4-$game_party.actors.size)*32, y+160)
@data = []
@data.push($data_weapons[actor.weapon_id])
@data.push($data_armors[actor.armor1_id])
@data.push($data_armors[actor.armor2_id])
@data.push($data_armors[actor.armor3_id])
@data.push($data_armors[actor.armor4_id])
draw_weaponmenu(@data[0], x,y+136)
draw_weaponmenu(@data[1], x+100+(4-$game_party.actors.size)*64,y+136)
draw_weaponmenu(@data[2], x,y+96)
draw_weaponmenu(@data[3], x+100+(4-$game_party.actors.size)*64,y+96)
draw_weaponmenu(@data[4], x,y+172)
draw_actor_name(actor, x, y-16)
draw_actor_state(actor, x+(4-$game_party.actors.size)*64, y+8)
draw_actor_level(actor,x+72+(4-$game_party.actors.size)*64, y + 64)
draw_actor_class(actor, x, y+32)
draw_actor_hp(actor, x, y + 212)
draw_actor_sp(actor, x, y + 248)
draw_actor_exp(actor, x, y + 280)
end
end
def update_cursor_rect
if @index < 0
self.cursor_rect.empty
else
self.cursor_rect.set(@index*(640/$game_party.actors.size)-16, -16, 640/$game_party.actors.size,360)
end
end
end
def draw_weaponmenu(item, x, y)
if item == nil
return
end
bitmap = RPG::Cache.icon(item.icon_name)
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
end
end
class Window_Selectable2 < Window_Base
attr_reader :index # cursor position
def initialize(x, y, width, height)
super(x, y, width, height)
@item_max = 1
@column_max = 1
@index = -1
end
def index=(index)
@index = index
end
def update_cursor_rect
if @index < 0
self.cursor_rect.empty
return
else
self.cursor_rect.set(x, y, 32, 32)
end
end
def update
super
if self.active and @item_max > 0 and @index >= 0
if Input.repeat?(Input::DOWN) or Input.repeat?(Input::RIGHT)
if (@column_max == 1 and (Input.trigger?(Input::DOWN) or Input.trigger?(Input::RIGHT))) or
@index < @item_max - @column_max
$game_system.se_play($data_system.cursor_se)
@index = (@index + @column_max) % @item_max
else
$game_system.se_play($data_system.cursor_se)
@index = 0
end
end
if Input.repeat?(Input::UP) or Input.repeat?(Input::LEFT)
if (@column_max == 1 and Input.trigger?(Input::UP) or Input.trigger?(Input::LEFT)) or
@index >= @column_max
$game_system.se_play($data_system.cursor_se)
@index = (@index - @column_max + @item_max) % @item_max
else
$game_system.se_play($data_system.cursor_se)
@index = @item_max-1
end
end
end
update_cursor_rect
end
end
class Window_Command2 < Window_Selectable2
def initialize(width, commands)
super(0, 0, width, commands.size * 32 + 32)
@item_max = commands.size
@commands = commands
self.contents = Bitmap.new(width - 32, @item_max * 32)
refresh
self.index = 0
end
def refresh
self.contents.clear
for i in 0...@item_max
draw_item(i, normal_color)
end
end
def draw_item(index, color)
self.contents.font.color = color
rect = Rect.new(4, 32 * index, self.contents.width - 8, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, @commands[index])
end
def disable_item(index)
draw_item(index, disabled_color)
end
end
class Window_MenuStatus2 < Window_Selectable2
def initialize
super(0, 0, 640, 360)
self.contents = Bitmap.new(width-32, height-32)
refresh
self.active = false
self.index = -1
end
def refresh
self.contents.clear
@item_max = $game_party.actors.size
for i in 0...$game_party.actors.size
x = i*(640/$game_party.actors.size)
y = 16
rong = self.width / $game_party.actors.size
actor = $game_party.actors
draw_actor_graphic(actor, x+64+(4-$game_party.actors.size)*32, y+160)
@data = []
@data.push($data_weapons[actor.weapon_id])
@data.push($data_armors[actor.armor1_id])
@data.push($data_armors[actor.armor2_id])
@data.push($data_armors[actor.armor3_id])
@data.push($data_armors[actor.armor4_id])
draw_weaponmenu(@data[0], x,y+136)
draw_weaponmenu(@data[1], x+100+(4-$game_party.actors.size)*64,y+136)
draw_weaponmenu(@data[2], x,y+96)
draw_weaponmenu(@data[3], x+100+(4-$game_party.actors.size)*64,y+96)
draw_weaponmenu(@data[4], x,y+172)
draw_actor_name(actor, x, y-16)
draw_actor_state(actor, x+(4-$game_party.actors.size)*64, y+8)
draw_actor_level(actor,x+72+(4-$game_party.actors.size)*64, y + 64)
draw_actor_class(actor, x, y+32)
draw_actor_hp(actor, x, y + 212)
draw_actor_sp(actor, x, y + 248)
draw_actor_exp(actor, x, y + 280)
end
end
def update_cursor_rect
if @index < 0
self.cursor_rect.empty
else
self.cursor_rect.set(@index*(640/$game_party.actors.size)-16, -16, 640/$game_party.actors.size,360)
end
end
end
module Test
X = 156
Y = 16
Khoang_cach = 56
end
#==============================================================================
# ** Scene_Menu
#
# This class performs menu screen processing.
#==============================================================================
class Scene_Menu
#
# * Object Initialization
# menu_index : command cursor's initial position
#
def initialize(menu_index = 0)
@menu_index = menu_index
end
#
# * Main Processing
#
def main
# Make command window
s1 = $data_system.words.item
s2 = $data_system.words.skill
s3 = $data_system.words.equip
s4 = "Status"
s5 = "Save"
s6 = "End Game"
@command_window = Window_Command2.new(160, [s1, s2, s3, s4, s5, s6])
@command_window.index = @menu_index
@command_window.visible = false
@cmd = []
for i in 0...6
@cmd = Sprite.new
end
@cmd[0].bitmap = RPG::Cache.picture("Item") rescue RPG::Cache.icon("032-Item01")
@cmd[1].bitmap = RPG::Cache.picture("Skill") rescue RPG::Cache.icon("044-Skill01")
@cmd[2].bitmap = RPG::Cache.picture("Equip") rescue RPG::Cache.icon("001-Weapon01")
@cmd[3].bitmap = RPG::Cache.picture("Status") rescue RPG::Cache.icon("050-Skill07")
@cmd[4].bitmap = RPG::Cache.picture("Save") rescue RPG::Cache.icon("038-Item07")
@cmd[5].bitmap = RPG::Cache.picture("End Game") rescue RPG::Cache.icon("049-Skill06")
for i in 0...6
@cmd.x = Test::X + i * Test::Khoang_cach
@cmd.y = Test::Y
@cmd.ox = @cmd.bitmap.width/2
@cmd.oy = @cmd.bitmap.height/2
end
# If number of party members is 0
if $game_party.actors.size == 0
# Disable items, skills, equipment, and status
@command_window.disable_item(0)
@command_window.disable_item(1)
@command_window.disable_item(2)
@command_window.disable_item(3)
end
# If save is forbidden
if $game_system.save_disabled
# Disable save
@command_window.disable_item(4)
end
# Make play time window
@playtime_window = Window_PlayTime.new
@playtime_window.x = 0
@playtime_window.y = 392
@playtime_window.opacity = 0
# Make steps window
@steps_window = Window_Steps.new
@steps_window.x = 240
@steps_window.y = 392
@steps_window.opacity = 0
# Make gold window
@gold_window = Window_Gold.new
@gold_window.x = 480
@gold_window.y = 416
@gold_window.opacity = 0
# Make status window
@status_window = Window_MenuStatus2.new
@status_window.x = 0
@status_window.y = 48
@status_window.opacity = 20
# Execute transition
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
# Abort loop if screen is changed
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
# Dispose of windows
for i in 0...6
@cmd.dispose
end
@command_window.dispose
@playtime_window.dispose
@steps_window.dispose
@gold_window.dispose
@status_window.dispose
end
#
# * Frame Update
#
def update
# Update windows
for i in 0...6
@cmd.update
end
@command_window.update
@playtime_window.update
@steps_window.update
@gold_window.update
@status_window.update
# If command window is active: call update_command
if @command_window.active
update_command
return
end
# If status window is active: call update_status
if @status_window.active
update_status
return
end
end
#
# * Frame Update (when command window is active)
#
def update_command
#
if @a == true
@cmd[@command_window.index].zoom_x *= 1.2
@cmd[@command_window.index].zoom_y *= 1.2
if @cmd[@command_window.index].zoom_x >= 1.5
@a = false
end
else
@cmd[@command_window.index].zoom_x /= 1.2
@cmd[@command_window.index].zoom_y /= 1.2
if @cmd[@command_window.index].zoom_x <= 0.5
@a = true
end
end
for i in 0...6
@cmd.zoom_x = @cmd.zoom_y = 1 if i != @command_window.index
end
#
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Switch to map screen
$scene = Scene_Map.new
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# If command other than save or end game, and party members = 0
if $game_party.actors.size == 0 and @command_window.index < 4
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Branch by command window cursor position
case @command_window.index
when 0 # item
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to item screen
$scene = Scene_Item.new
when 1 # skill
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Make status window active
@command_window.active = false
@status_window.active = true
@status_window.index = 0
when 2 # equipment
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Make status window active
@command_window.active = false
@status_window.active = true
@status_window.index = 0
when 3 # status
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Make status window active
@command_window.active = false
@status_window.active = true
@status_window.index = 0
when 4 # save
# If saving is forbidden
if $game_system.save_disabled
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to save screen
$scene = Scene_Save.new
when 5 # end game
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to end game screen
$scene = Scene_End.new
end
return
end
end
#
# * Frame Update (when status window is active)
#
def update_status
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Make command window active
@command_window.active = true
@status_window.active = false
@status_window.index = -1
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# Branch by command window cursor position
case @command_window.index
when 1 # skill
# If this actor's action limit is 2 or more
if $game_party.actors[@status_window.index].restriction >= 2
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to skill screen
$scene = Scene_Skill.new(@status_window.index)
when 2 # equipment
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to equipment screen
$scene = Scene_Equip.new(@status_window.index)
when 3 # status
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to status screen
$scene = Scene_Status.new(@status_window.index)
end
return
end
end
end
X = 156
Y = 16
Khoang_cach = 56
end
#==============================================================================
# ** Scene_Menu
#
# This class performs menu screen processing.
#==============================================================================
class Scene_Menu
#
# * Object Initialization
# menu_index : command cursor's initial position
#
def initialize(menu_index = 0)
@menu_index = menu_index
end
#
# * Main Processing
#
def main
# Make command window
s1 = $data_system.words.item
s2 = $data_system.words.skill
s3 = $data_system.words.equip
s4 = "Status"
s5 = "Save"
s6 = "End Game"
@command_window = Window_Command2.new(160, [s1, s2, s3, s4, s5, s6])
@command_window.index = @menu_index
@command_window.visible = false
@cmd = []
for i in 0...6
@cmd = Sprite.new
end
@cmd[0].bitmap = RPG::Cache.picture("Item") rescue RPG::Cache.icon("032-Item01")
@cmd[1].bitmap = RPG::Cache.picture("Skill") rescue RPG::Cache.icon("044-Skill01")
@cmd[2].bitmap = RPG::Cache.picture("Equip") rescue RPG::Cache.icon("001-Weapon01")
@cmd[3].bitmap = RPG::Cache.picture("Status") rescue RPG::Cache.icon("050-Skill07")
@cmd[4].bitmap = RPG::Cache.picture("Save") rescue RPG::Cache.icon("038-Item07")
@cmd[5].bitmap = RPG::Cache.picture("End Game") rescue RPG::Cache.icon("049-Skill06")
for i in 0...6
@cmd.x = Test::X + i * Test::Khoang_cach
@cmd.y = Test::Y
@cmd.ox = @cmd.bitmap.width/2
@cmd.oy = @cmd.bitmap.height/2
end
# If number of party members is 0
if $game_party.actors.size == 0
# Disable items, skills, equipment, and status
@command_window.disable_item(0)
@command_window.disable_item(1)
@command_window.disable_item(2)
@command_window.disable_item(3)
end
# If save is forbidden
if $game_system.save_disabled
# Disable save
@command_window.disable_item(4)
end
# Make play time window
@playtime_window = Window_PlayTime.new
@playtime_window.x = 0
@playtime_window.y = 392
@playtime_window.opacity = 0
# Make steps window
@steps_window = Window_Steps.new
@steps_window.x = 240
@steps_window.y = 392
@steps_window.opacity = 0
# Make gold window
@gold_window = Window_Gold.new
@gold_window.x = 480
@gold_window.y = 416
@gold_window.opacity = 0
# Make status window
@status_window = Window_MenuStatus2.new
@status_window.x = 0
@status_window.y = 48
@status_window.opacity = 20
# Execute transition
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
# Abort loop if screen is changed
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
# Dispose of windows
for i in 0...6
@cmd.dispose
end
@command_window.dispose
@playtime_window.dispose
@steps_window.dispose
@gold_window.dispose
@status_window.dispose
end
#
# * Frame Update
#
def update
# Update windows
for i in 0...6
@cmd.update
end
@command_window.update
@playtime_window.update
@steps_window.update
@gold_window.update
@status_window.update
# If command window is active: call update_command
if @command_window.active
update_command
return
end
# If status window is active: call update_status
if @status_window.active
update_status
return
end
end
#
# * Frame Update (when command window is active)
#
def update_command
#
if @a == true
@cmd[@command_window.index].zoom_x *= 1.2
@cmd[@command_window.index].zoom_y *= 1.2
if @cmd[@command_window.index].zoom_x >= 1.5
@a = false
end
else
@cmd[@command_window.index].zoom_x /= 1.2
@cmd[@command_window.index].zoom_y /= 1.2
if @cmd[@command_window.index].zoom_x <= 0.5
@a = true
end
end
for i in 0...6
@cmd.zoom_x = @cmd.zoom_y = 1 if i != @command_window.index
end
#
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Switch to map screen
$scene = Scene_Map.new
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# If command other than save or end game, and party members = 0
if $game_party.actors.size == 0 and @command_window.index < 4
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Branch by command window cursor position
case @command_window.index
when 0 # item
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to item screen
$scene = Scene_Item.new
when 1 # skill
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Make status window active
@command_window.active = false
@status_window.active = true
@status_window.index = 0
when 2 # equipment
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Make status window active
@command_window.active = false
@status_window.active = true
@status_window.index = 0
when 3 # status
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Make status window active
@command_window.active = false
@status_window.active = true
@status_window.index = 0
when 4 # save
# If saving is forbidden
if $game_system.save_disabled
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to save screen
$scene = Scene_Save.new
when 5 # end game
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to end game screen
$scene = Scene_End.new
end
return
end
end
#
# * Frame Update (when status window is active)
#
def update_status
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Make command window active
@command_window.active = true
@status_window.active = false
@status_window.index = -1
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# Branch by command window cursor position
case @command_window.index
when 1 # skill
# If this actor's action limit is 2 or more
if $game_party.actors[@status_window.index].restriction >= 2
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to skill screen
$scene = Scene_Skill.new(@status_window.index)
when 2 # equipment
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to equipment screen
$scene = Scene_Equip.new(@status_window.index)
when 3 # status
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to status screen
$scene = Scene_Status.new(@status_window.index)
end
return
end
end
end
Muốn demo?: cứ copy 2 script này vào là tự động có demo đó :Dtrong quá trình làm có chỉnh thêm chút chút nên có thể k đồng bộ hoặc có lỗi, ai thấy lỗi thì báo mình nha ^^!
Comments
Khen thật đấy :D
mỗi tội bài viết khô khan quá *tự thấy vậy
Lần sau để script vào mã CODE ấy :D