赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 2 |
经验 | 5380 |
最后登录 | 2024-1-30 |
在线时间 | 35 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 192
- 在线时间
- 35 小时
- 注册时间
- 2008-5-26
- 帖子
- 15
|
最近学脚本,粗糙做了个,不嫌弃将就用下好了{/gg}
- #===========================================================================
- #1、调用方法:$Scene = Scene_System.new(上级菜单索引编号,从菜单进入?
- # 从事件进入(false)?从标题进入(false)?)
- #
- #2、from_event和from_title可以无视,还没弄--|||
- # 要去掉的话改下return_Scene好了
- #3、想不出啥了,改了下Window_Help的initialize方法:
- # def initialize(x = 0, y = 0, width = 544, heigh = WLH + 32)
- # super(x, y, width, heigh)
- # end
- #===========================================================================
- #==============================================================================
- # ■ Scene_System
- #------------------------------------------------------------------------------
- # 处理游戏系统的画面,包括存档,读档,退出游戏。
- #==============================================================================
- class Scene_System < Scene_Base
- #--------------------------------------------------------------------------
- # ● 初始化对象
- # saving : 存档标志 (false 为载入画面)
- # from_menu : 从菜单进入
- # from_title : 调用标题画面的 "继续" 标志
- # from_event : 事件的 "调用存档画面" 的调用标志
- # main_menu_index :主菜单索引号
- #--------------------------------------------------------------------------
- def initialize(main_menu_index,from_menu, from_event = false, from_title=false)
- @from_menu = from_menu
- @from_title = from_title
- @from_event = from_event
- @main_menu_index = main_menu_index
- end
- #--------------------------------------------------------------------------
- # ● 开始处理
- #--------------------------------------------------------------------------
- def start
- super
- create_menu_background
- create_command_window
- create_savefile_windows
- create_help_window
- create_determine_command_window
- end
- #--------------------------------------------------------------------------
- # ● 结束处理
- #--------------------------------------------------------------------------
- def terminate
- super
- dispose_menu_background
- dispose_item_windows
- @command_window.dispose
- @help_window.dispose
- @determine_command_window.dispose
- end
- #--------------------------------------------------------------------------
- # ● 还原至原先的画面
- #--------------------------------------------------------------------------
- def return_scene
- if @from_title
- $scene = Scene_Title.new
- elsif @from_event
- $scene = Scene_Map.new
- else
- $scene = Scene_Menu.new(@main_menu_index)
- end
- end
- #--------------------------------------------------------------------------
- # ● 更新画面
- #--------------------------------------------------------------------------
- def update
- super
- update_menu_background
- @help_window.update
- @command_window.update
- @determine_command_window.update
- update_savefile_windows
- if @command_window.active
- update_command_selection
- elsif @savefile_windows[@index].active
- update_savefile_selection
- elsif @determine_command_window.active
- update_determine_command_selection
- end
- end
- #--------------------------------------------------------------------------
- # ● 创建指令窗口
- #--------------------------------------------------------------------------
- def create_command_window
- s1 ="存 档"
- s2 ="读 档"
- s3 ="返回标题"
- @command_window = Window_Command.new(544, [s1, s2, s3], 3, 1, 112)
- @command_window.index = 0
- if $game_system.save_disabled
- @command_window.draw_item(0, false)
- end
-
- end
- #--------------------------------------------------------------------------
- # ● 更新指令选择
- #--------------------------------------------------------------------------
- def update_command_selection
- # @determine_command_window.index = 0
- if Input.trigger?(Input::B)
- Sound.play_cancel
- return_scene
- elsif Input.trigger?(Input::C)
- if $game_system.save_disabled and @command_window.index == 0
- Sound.play_buzzer
- return
- end
- Sound.play_decision
- case @command_window.index
- when 0 #存档
- save_window(true)
- when 1 #读档
- save_window(false)
- when 2 #返回标题画面
- @command_window.active = false
- help_determine_visible(true,true,"确定要返回标题画面吗?")
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 是否可视化help和确定窗口,align :对齐方式 0,1,2
- #--------------------------------------------------------------------------
- def help_determine_visible(active = false,visible = false, text = "", align = 1)
- @determine_command_window.active = active
- @determine_command_window.visible = visible
- @help_window.set_text(text,align)
- @help_window.visible = visible
- end
-
- #--------------------------------------------------------------------------
- # ● 存取档窗口,初始化存档文件索引编号
- #--------------------------------------------------------------------------
- def save_window(save)
- @saving = save
- savefile_windows_visible_active(true,true)
- @command_window.active = false
- if @saving
- @index = $game_temp.last_file_index
- else
- @index = self.latest_file_index
- end
- @savefile_windows[@index].selected = true
- end
- #--------------------------------------------------------------------------
- # ● 创建帮助窗口
- #--------------------------------------------------------------------------
- def create_help_window
- @help_window = Window_Help.new(0, 0, 272, 56)
- @help_window.x = (544 - @help_window.width) / 2
- @help_window.y = (416 - @help_window.height) / 2
- @help_window.visible = false
- end
- #--------------------------------------------------------------------------
- # ● 创建确认指令窗口
- #--------------------------------------------------------------------------
- def create_determine_command_window
- @determine_command_window = Window_Command.new(112,["否","是"],2,1,32)
- @determine_command_window.x = (544 - @determine_command_window.width) / 2
- @determine_command_window.y = @help_window.y + 56
- @determine_command_window.active = false
- @determine_command_window.visible = false
- end
- #--------------------------------------------------------------------------
- # ● 更新确认窗口选择
- #--------------------------------------------------------------------------
- def update_determine_command_selection
- case @command_window.index
- when 0 #确认覆盖存档
- @command_window.visible = false
- help_determine_visible(true,true,"确定要覆盖原档案吗?")
- if Input.trigger?(Input::C) and @determine_command_window.index == 0 or Input.trigger?(Input::B)
- Sound.play_cancel
- help_determine_visible
- savefile_windows_visible_active(true,true)
- @command_window.visible = true
- elsif Input.trigger?(Input::C) and @determine_command_window.index == 1
- Sound.play_save
- do_save
- help_determine_visible
- savefile_windows_visible_active(true,true)
- @command_window.visible = true
- end
-
- when 2 #确认返回标题画面
- if Input.trigger?(Input::C) and @determine_command_window.index == 0 or Input.trigger?(Input::B)
- Sound.play_cancel
- help_determine_visible
- @determine_command_window.active =false
- @command_window.active = true
- elsif Input.trigger?(Input::C) and @determine_command_window.index == 1
- Sound.play_decision
- $scene = Scene_Title.new
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 生成存档文件窗口
- #--------------------------------------------------------------------------
- def create_savefile_windows
- @savefile_windows = []
- for i in 0..3
- @savefile_windows.push(Window_SaveFile.new(i, make_filename(i)))
- end
- @item_max = 4
- @index = $game_temp.last_file_index
- savefile_windows_visible_active(false,false)
- end
-
- #--------------------------------------------------------------------------
- # ● 存档文件可见,活化
- #--------------------------------------------------------------------------
- def savefile_windows_visible_active(visible = true, active = true)
- for i in 0...@item_max
- @savefile_windows[i].visible = visible
- @savefile_windows[i].active = active
- end
- end
-
- #--------------------------------------------------------------------------
- # ● 释放存档文件
- #--------------------------------------------------------------------------
- def dispose_item_windows
- for window in @savefile_windows
- window.dispose
- end
- end
- #--------------------------------------------------------------------------
- # ● 更新存档文件窗口
- #--------------------------------------------------------------------------
- def update_savefile_windows
- for window in @savefile_windows
- window.update
- end
- end
- #--------------------------------------------------------------------------
- # ● 更新存档文件选择
- #--------------------------------------------------------------------------
- def update_savefile_selection
- if Input.trigger?(Input::C)
- determine_savefile
- elsif Input.trigger?(Input::B)
- Sound.play_cancel
- savefile_windows_visible_active(false,false)
- @command_window.active = true
- @savefile_windows[@index].selected = false
- else
- last_index = @index
- if Input.repeat?(Input::DOWN)
- cursor_down(Input.trigger?(Input::DOWN))
- end
- if Input.repeat?(Input::UP)
- cursor_up(Input.trigger?(Input::UP))
- end
- if @index != last_index
- Sound.play_cursor
- @savefile_windows[last_index].selected = false
- @savefile_windows[@index].selected = true
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 确定存档文件
- #--------------------------------------------------------------------------
- def determine_savefile
- if @saving
- if @savefile_windows[@index].file_exist
- @determine_command_window.index = 0
- @determine_command_window.active = true
- savefile_windows_visible_active(false,false)
- else
- Sound.play_save
- do_save
- end
-
- else
- if @savefile_windows[@index].file_exist
- Sound.play_load
- do_load
- else
- Sound.play_buzzer
- return
- end
- end
- $game_temp.last_file_index = @index
- end
- #--------------------------------------------------------------------------
- # ● 光标向下移动
- # wrap : 允许跳过
- #--------------------------------------------------------------------------
- def cursor_down(wrap)
- if @index < @item_max - 1 or wrap
- @index = (@index + 1) % @item_max
- end
- end
- #--------------------------------------------------------------------------
- # ● 光标向上移动
- # wrap : 允许跳过
- #--------------------------------------------------------------------------
- def cursor_up(wrap)
- if @index > 0 or wrap
- @index = (@index - 1 + @item_max) % @item_max
- end
- end
- #--------------------------------------------------------------------------
- # ● 生成文件名
- # file_index : 存档文件索引 (0~3)
- #--------------------------------------------------------------------------
- def make_filename(file_index)
- return "Save#{file_index + 1}.rvdata"
- end
- #--------------------------------------------------------------------------
- # ● 按时间戳选择最新的文件
- #--------------------------------------------------------------------------
- def latest_file_index
- index = 0
- latest_time = Time.at(0)
- for i in 0...@savefile_windows.size
- if @savefile_windows[i].time_stamp > latest_time
- latest_time = @savefile_windows[i].time_stamp
- index = i
- end
- end
- return index
- end
- #--------------------------------------------------------------------------
- # ● 执行存档
- #--------------------------------------------------------------------------
- def do_save
- file = File.open(@savefile_windows[@index].filename, "wb")
- write_save_data(file)
- file.close
- dispose_item_windows
- create_savefile_windows
- @savefile_windows[@index].selected = true
- savefile_windows_visible_active(true,true)
- end
- #--------------------------------------------------------------------------
- # ● 执行载入
- #--------------------------------------------------------------------------
- def do_load
- file = File.open(@savefile_windows[@index].filename, "rb")
- read_save_data(file)
- file.close
- $scene = Scene_Map.new
- RPG::BGM.fade(1500)
- Graphics.fadeout(60)
- Graphics.wait(40)
- @last_bgm.play
- @last_bgs.play
- end
- #--------------------------------------------------------------------------
- # ● 写入存档数据
- # file : 写入文件用对象 (已经打开)
- #--------------------------------------------------------------------------
- def write_save_data(file)
- characters = []
- for actor in $game_party.members
- characters.push([actor.character_name, actor.character_index])
- end
- $game_system.save_count += 1
- $game_system.version_id = $data_system.version_id
- @last_bgm = RPG::BGM::last
- @last_bgs = RPG::BGS::last
- Marshal.dump(characters, file)
- Marshal.dump(Graphics.frame_count, file)
- Marshal.dump(@last_bgm, file)
- Marshal.dump(@last_bgs, file)
- Marshal.dump($game_system, file)
- Marshal.dump($game_message, file)
- Marshal.dump($game_switches, file)
- Marshal.dump($game_variables, file)
- Marshal.dump($game_self_switches, file)
- Marshal.dump($game_actors, file)
- Marshal.dump($game_party, file)
- Marshal.dump($game_troop, file)
- Marshal.dump($game_map, file)
- Marshal.dump($game_player, file)
- end
- #--------------------------------------------------------------------------
- # ● 读取存档数据
- # file : 读取文件用对象 (已经打开)
- #--------------------------------------------------------------------------
- def read_save_data(file)
- characters = Marshal.load(file)
- Graphics.frame_count = Marshal.load(file)
- @last_bgm = Marshal.load(file)
- @last_bgs = Marshal.load(file)
- $game_system = Marshal.load(file)
- $game_message = Marshal.load(file)
- $game_switches = Marshal.load(file)
- $game_variables = Marshal.load(file)
- $game_self_switches = Marshal.load(file)
- $game_actors = Marshal.load(file)
- $game_party = Marshal.load(file)
- $game_troop = Marshal.load(file)
- $game_map = Marshal.load(file)
- $game_player = Marshal.load(file)
- if $game_system.version_id != $data_system.version_id
- $game_map.setup($game_map.map_id)
- $game_player.center($game_player.x, $game_player.y)
- end
- end
- end
- #==============================================================================
- # ■ Window_Help
- #------------------------------------------------------------------------------
- # 特技及物品的说明、角色的状态显示的窗口。
- #==============================================================================
- class Window_Help < Window_Base
- #--------------------------------------------------------------------------
- # ● 初始化对象
- #--------------------------------------------------------------------------
- def initialize(x = 0, y = 0, width = 544, heigh = WLH + 32)
- super(x, y, width, heigh)
- end
- #--------------------------------------------------------------------------
- # ● 文本设置
- # text : 窗口显示的字符串
- # align : 对齐方式 (0..左对齐、1..中间对齐、2..右对齐)
- #--------------------------------------------------------------------------
- def set_text(text, align = 0)
- if text != @text or align != @align
- self.contents.clear
- self.contents.font.color = normal_color
- self.contents.draw_text(4, 0, self.width - 40, WLH, text, align)
- @text = text
- @align = align
- end
- end
- end
复制代码
版主对此帖的认可:『辛苦了,鼓勵一下』,积分『+40』。 |
|