Project1
标题:
尝试写个日记脚本,但是出现了一个简单但是奇怪的问题
[打印本页]
作者:
yangjunyin2002
时间:
2013-8-28 20:39
标题:
尝试写个日记脚本,但是出现了一个简单但是奇怪的问题
本帖最后由 yangjunyin2002 于 2013-9-15 20:31 编辑
@Password
@小小刀886
@丿梁丶小柒
@八宝粥先生
@protosssonny
本来呢,我看到了小柒的无尽之旅III-花落有时,然后里面有个“日志”,于是,我也想仿照这个写。
我已经有了思路了,先是借鉴叶子的任务系统,但是有些问题,现在借鉴了下VA的菜单显示任务脚本,虽然是VA的,但是给了我点启示吧。。。
日记这个场景我是仿照menu和end画面的。目前背景图已经OK了,窗口待我改下坐标和宽度、高度。
但是现在遇到了个问题,似乎很普通,但是为什么似乎解决不了?毕竟我是个脚本新手吧,再加上都是自己钻研的...求教下。。。
我把脚本贴上来。问题是:这个“日记”场景明明有个判定了的,可是按下esc无法返回。
注:此脚本还是半成品。。。“日记”内容的显示需要修改Window_Bsae,背景图我是仿照update_menu_background修改了Scene_Base等,然后File这儿是为了存档和读档时
能保存和读取这个信息。window_diary就是显示的那个窗口。主要还是找到Scene_diary部分,我前面写的应该也对啊,而且我也有:
def return_scene
$scene = Scene_Menu.new(5)
end
复制代码
和
def update_diary
if Input.trigger?(Input::B)
Sound.play_cancel
return_scene
end
end
复制代码
应该不会错啊。。。
脚本贴上(说过了是半成品):
class Scene_Base
def create_diary_background
@diaryback_sprite = Sprite.new
@diaryback_sprite.bitmap = Cache.system("日记背景")
@diaryback_sprite.color.set(16, 16, 16, 128)
update_diary_background
end
def dispose_diary_background
@diaryback_sprite.dispose
end
def update_diary_background
end
end
class Scene_Diary < Scene_Base
def start
super
create_diary_background
@diary_window = Window_Diary.new
end
def terminate
super
dispose_diary_background
@diary_window.dispose
end
def update
super
update_diary_background
@diary_window.update
end
def return_scene
$scene = Scene_Menu.new(5)
end
def update_diary
if Input.trigger?(Input::B)
Sound.play_cancel
return_scene
end
end
end
class Window_Diary < Window_Base
def initialize
addheight = 24
tb = Bitmap.new(544,416)
if $diary_information.is_a?(String) and $diary_information!=""
@temptext = $diary_information.gsub(/(\r\n)|\n/,"")
i = 1
p = 0
insert_list = []
while p+i<= @temptext.size
w = tb.text_size(@temptext[p,i]).width
if w > window_width
insert_list << p+i-2
p = p+i-2
i = 1
end
i+=1
end
insert_list.reverse!
insert_list.each{|k| @temptext.insert(k,"\n")}
tb.dispose
addheight = (insert_list.size+2) * 24
end
super(380,50, window_width, 48 + addheight)
refresh
end
def window_width
return 160
end
def refresh
contents.clear
if $diary.nil? or $diary==""
$diary="● "
$diary_information="● "
end
draw_text_ex(0,0,"")
draw_text_ex(0,24,"\\C[1]#{$diary}")
text_color(2)
draw_text_ex(0,48,@temptext)
end
def diary
$diary
end
def open
refresh
super
end
end
class Scene_File < Scene_Base
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)
Marshal.dump($diary, file)
end
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)
$diary = 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
class Window_Base < Window
def text_size(str)
contents.text_size(str)
end
def draw_text_ex(x, y, text)
reset_font_settings
text = convert_escape_characters(text)
pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
process_character(text.slice!(0, 1), text, pos) until text.empty?
end
def reset_font_settings
contents.font.size = Font.default_size
contents.font.bold = false
contents.font.italic = false
end
def draw_text(*args)
contents.draw_text(*args)
end
def text_size(str)
contents.text_size(str)
end
def make_font_bigger
contents.font.size += 8 if contents.font.size <= 64
end
def make_font_smaller
contents.font.size -= 8 if contents.font.size >= 16
end
def calc_line_height(text, restore_font_size = true)
result = [line_height, contents.font.size].max
last_font_size = contents.font.size
text.slice(/^.*$/).scan(/\e[\{\}]/).each do |esc|
make_font_bigger if esc == "\e{"
make_font_smaller if esc == "\e}"
result = [result, contents.font.size].max
end
contents.font.size = last_font_size if restore_font_size
result
end
def convert_escape_characters(text)
result = text.to_s.clone
result.gsub!(/\r\n/) { "\n" }
result.gsub!(/\\/) { "\e" }
result.gsub!(/\e\e/) { "\\" }
result.gsub!(/\eV\[(\d+)\]/i) { $game_variables[$1.to_i] }
result.gsub!(/\eV\[(\d+)\]/i) { $game_variables[$1.to_i] }
result.gsub!(/\eN\[(\d+)\]/i) { actor_name($1.to_i) }
result.gsub!(/\eP\[(\d+)\]/i) { party_member_name($1.to_i) }
result.gsub!(/\eG/i) { Vocab::currency_unit }
result
end
def line_height
return 24
end
def standard_padding
return 12
end
def process_character(c, text, pos)
case c
when "\n" # 换行
process_new_line(text, pos)
when "\f" # 翻页
process_new_page(text, pos)
when "\e" # 控制符
process_escape_character(obtain_escape_code(text), text, pos)
else # 普通文字
process_normal_character(c, pos)
end
end
def obtain_escape_code(text)
text.slice!(/^[\$\.\|\^!><\{\}\\]|^[A-Z]+/i)
end
def process_escape_character(code, text, pos)
case code.upcase
when 'I'
process_draw_icon(obtain_escape_param(text), pos)
when '{'
make_font_bigger
when '}'
make_font_smaller
end
end
def process_normal_character(c, pos)
text_width = text_size(c).width
draw_text(pos[:x], pos[:y], text_width * 2, pos[:height], c)
pos[:x] += text_width
end
def obtain_escape_param(text)
text.slice!(/^\[\d+\]/)[/\d+/].to_i rescue 0
end
end
复制代码
作者:
丿梁丶小柒
时间:
2013-8-28 21:07
最近一直在看VA,然后已经把VX忘记了。脚本表示看不懂
作者:
Password
时间:
2013-8-28 21:54
本帖最后由 Password 于 2013-8-28 21:57 编辑
也许是没有刷新?或者刷新的东西不对?两个定义是否写到一个Class里?
表示脚本好长好挤,看不懂
作者:
小小刀886
时间:
2013-8-29 11:50
脚本渣路过=-=
作者:
satgo1546
时间:
2013-8-29 12:21
你没有在update里调用update_diary。
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1