Project1
标题:
为什么自制的有光标的类却不显示光标?
[打印本页]
作者:
876加几
时间:
2013-10-4 16:35
标题:
为什么自制的有光标的类却不显示光标?
本帖最后由 876加几 于 2013-10-4 16:45 编辑
脚本:
#==============================================================================
# ■ Window_Task
#------------------------------------------------------------------------------
# 显示任务的选择行窗口。
#==============================================================================
class Window_Task < Window_Selectable
#--------------------------------------------------------------------------
# ● 初始化对像
#--------------------------------------------------------------------------
def initialize
super(0, 0, 640, 480 - 64)
@name = nil
@task_help = nil
[url=home.php?mod=space&uid=236945]@gold[/url] = nil
@items = nil
@weapons = nil
@armors = nil
@item = nil
[url=home.php?mod=space&uid=36793]@weapon[/url] = nil
@armor = nil
if @name == nil
@item_max = 1
else
@item_max = @name.size
end
difficulty = nil
self.contents = Bitmap.new(width - 32, height - 32)
refresh
self.index = -1
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
self.contents.clear
if @name == nil
@item_max = 1
else
@item_max = @name.size
end
end
#--------------------------------------------------------------------------
# ● 报偿设置
# item_id/weapon_id/armor_id : 报偿物品在数据库中的位置,nil等于没报偿
#--------------------------------------------------------------------------
def reward_items(item_id = nil)
@item[@item.size] = item_id
end
def reward_weapons(weapon_id = nil)
@weapon[@weapon.size] = weapon_id
end
def reward_armor(armor_id = nil)
@armor[@armor.size] = armor_id
end
#--------------------------------------------------------------------------
# ● 新建任务
# new_name : 新任务的名称
# task_help : 新任务的简介
# difficulty : 新任务的难度
# gold : 金钱报偿,0等于没报偿
#--------------------------------------------------------------------------
def new_task(new_name, task_help, difficulty = 1, gold = 0)
@name_size = @name.size
@task_help_size = @task_help.size
difficulty_size = difficulty.size
@gold_size = @gold.size
@items_size = @items.size
@weapons_size = @weapons.size
@armors_size = @armors.size
@name[@name_size] = new_name
@name2[@name_size] = new_name
@task_help[@task_help_size] = task_help
@difficulty[difficulty_size] = difficulty
@gold[@gold_size] = gold
@items[@items_size] = @item
@weapons[@weapons_size] = @weapon
@armors[@armors_size] = @armor
end
#--------------------------------------------------------------------------
# ● 完成任务
# bbb : 任务ID
#--------------------------------------------------------------------------
def final_task(bbb)
[url=home.php?mod=space&uid=110690]@BBB[/url] = bbb - 1
unless @name[@bbb].include?("(已失败)")
@name[@bbb] = @name[@bbb] + "(已完成)"
@task_help[@bbb] = @task_help[@bbb] + "(已完成)"
$game_party.gain_gold(@gold[bbb])
for i in
[email protected]
if @item != nil
$game_party.gain_item(@item[i], 1)
end
end
for i in
[email protected]
if [url=home.php?mod=space&uid=36793]@weapon[/url] != nil
$game_party.gain_weapon(@weapon[i], 1)
end
end
for i in
[email protected]
if @armor != nil
$game_party.gain_armor(@armor[i], 1)
end
end
end
end
#--------------------------------------------------------------------------
# ● 任务失败
# ccc : 任务ID
#--------------------------------------------------------------------------
def lose_task(ccc)
[url=home.php?mod=space&uid=9267]@CCC[/url] = ccc - 1
unless @name[@bbb].include?("(已完成)")
@name[@ccc] = @name[@ccc] + "(已失败)"
@task_help[@ccc] = @task_help[@ccc] + "(已失败)"
end
end
#--------------------------------------------------------------------------
# ● 描绘项目
# index : 项目编号
# color : 文字色
#--------------------------------------------------------------------------
def draw_item(index,color)
self.contents.font.color = color
rect = Rect.new(4, 32 * index, 640 / 2 - 8, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, @name[index])
end
#--------------------------------------------------------------------------
# ● 项目无效化
# index : 项目编号
#--------------------------------------------------------------------------
def disable_item(index)
draw_item(index, disabled_color)
end
#--------------------------------------------------------------------------
# ● 刷新光标矩形
#--------------------------------------------------------------------------
def update_cursor_rect
if [url=home.php?mod=space&uid=370741]@Index[/url] < 0
self.cursor_rect.empty
else
self.cursor_rect.set(0, @index * 56, 320 - 8, 32)
end
end
#--------------------------------------------------------------------------
# ● 拆分数组并显示内容
#--------------------------------------------------------------------------
def update
for i in 0...@item_max
x = 320 + 16
if self.index == i and $t == true
refresh
self.contents.font.color = system_color
self.contents.draw_text(x, 0, 100, 32, "任务名:")
self.contents.draw_text(x, 64, 100, 32, "难度:")
self.contents.draw_text(x, 112, 100, 32, "说明:")
if @gold[index] != 0
self.contents.draw_text(x, 176, 100, 32, "奖励金钱:")
y = 240
else
y = 208
end
if @items[index] != nil
self.contents.draw_text(x, y, 100, 32, "奖励物品:")
end
self.contents.font.color = normal_color
self.contents.draw_text(x, 32, 320 - 32, 32, @name2[index])
self.contents.draw_text(x, 144, 280, 32, @task_help[index])
if @gold[index] != 0
self.contents.draw_text(x, 208, 100, 32, @gold[index])
end
if @items[index] != nil and @item != nil
for j in
[email protected]
@y = y + @item[j] * 32
end
for g in
[email protected]
draw_item_name($data_items[@item[g]], x, @y)
end
for g in
[email protected]
draw_item_name($data_weapons[@weapon[g]], x, @y + @item.size * 32)
end
for g in
[email protected]
draw_item_name($data_armors[@armor[g]], x, @y + @item.size * 32 + @weapon.size * 32)
end
end
#Moon = difficulty[index] / DIFFICULTY::System
#Star = difficulty[index] % DIFFICULTY::System
#Sun = Moon / DIFFICULTY::System
#Moon %= DIFFICULTY::System
#Space = DIFFICULTY::Space
#rect = Rect.new(0, 0, DIFFICULTY::Size, DIFFICULTY::Size)
#while Sun>0
# self.contents.blt(x + Space, 96, Sun, rect)
# Space += DIFFICULTY::Size + DIFFICULTY::Space;Sun -= 1
#end
#while Moon>0
# self.contents.blt(x + Space, 97, Moon, rect)
# Space += DIFFICULTY::Size + DIFFICULTY::Space;Moon -= 1
#end
#while Star>0
# self.contents.blt(x + Space, 98, Star, rect)
# Space += DIFFICULTY::Size + DIFFICULTY::Space;Star -= 1
#end
text1 = "★" * difficulty[index]
text2 = "☆" * (5 - difficulty[index])
text = text1 + text2
self.contents.draw_text(x + 60, 64, 280, 32, text)
end
end
end
end
复制代码
先不说NoMethodError,居然连光标都不显示了,处于有光标活动的类连光标都不见了,这是怎么回事? 光标的声音也是在Scene类手动添加的。
Scene类代码:
#===============================================================================
# ● Scene_Task
#-------------------------------------------------------------------------------
# 处理任务画面的类。
#===============================================================================
class Scene_Task
#--------------------------------------------------------------------------
# ● 主处理
#--------------------------------------------------------------------------
def main
# 生成任务活动窗口
@task_window = Window_Task.new
@task_window.y = 64
if @task_window.active == false
@task_window.active = true
end
# 生成任务辅助窗口
@taskassist_window = Window_TaskAssist.new
# 执行过渡
Graphics.transition
# 主循环
loop do
# 刷新游戏画面
Graphics.update
# 刷新输入信息
Input.update
# 刷新画面
update
# 如果切换画面就中断循环
if $scene != self
break
end
end
# 准备过渡
Graphics.freeze
# 释放各个窗口
@task_window.dispose
@taskassist_window.dispose
end
#--------------------------------------------------------------------------
# ● 刷新画面
#--------------------------------------------------------------------------
def update
# 刷新各个窗口
@task_window.update
@taskassist_window.update
# 当按下 C 键后可查看任务信息
if Input.trigger?(Input::C)
$t = true #让T变为true
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
end
# 解除任务信息
if $t == true
# 按下 B 键的情况下
if Input.trigger?(Input::B)
$t = false
# 演奏取消 SE
$game_system.se_play($data_system.cancel_se)
end
if Input.trigger?(Input::UP)
$t = false
# 演奏光标 SE
$game_system.se_play($data_system.cursor_se)
end
if Input.trigger?(Input::DOWN)
# 演奏光标 SE
$game_system.se_play($data_system.cursor_se)
end
end
# 演奏光标 SE
if Input.trigger?(Input::UP)
# 演奏光标 SE
$game_system.se_play($data_system.cursor_se)
end
if Input.trigger?(Input::DOWN)
$t = false
# 演奏光标 SE
$game_system.se_play($data_system.cursor_se)
end
# 没显示任务时按下 B 键的情况下
if $t == false and Input.trigger?(Input::B)
# 切换到菜单界面
$scene = Scene_Menu.new(5)
end
end
end
复制代码
作者:
恐惧剑刃
时间:
2013-10-4 16:54
本帖最后由 恋′挂机 于 2013-10-4 17:14 编辑
你的脚本“永远”都那么莫名奇妙。。
光标不显示原因:
1.self.index = -1 or @xx.index = -1
2.self.cursor_rect.empty
另一个思路,
生成一个命令窗体,只不过命令窗体的选项文字是任务名而已。
class Game_Temp
attr_accessor :rw
alias initialize_old initialize
def initialize
@rw = {}
initialize_old
end
end
s1 = $game_temp.rw[1]
s2 = $game_temp.rw[2]
…………………………
@command = Window_Command.new(160, [s1, s2, s3, ..., sn])
添加任务方法:
$game_temp.rw = {1=>"送信", 2=>"打怪"}等等
可以通过不断重新给$game_temp.rw赋值的方式添加或者删除任务
@help = Window_Help_2.new
@command.help_window = @help
class Window_Command < Window_Selectable
def update_help
#就在这里下点功夫就可以了
end
end
当然只是一个思路,很多地方可能没有想到仅供参考
另外哈希表可以添加$game_temp.rw[3] = "任务3"
等等
作者:
myownroc
时间:
2013-10-4 17:12
@Index
无视这个@
Window_Task类里的
def update 是什么情况?
Window_Task是Window_Selectable的子类,继承了父类Window_Selectable的方法update
所以你在Window_Task类里重新定义了update方法
而父类的update方法定义了光标移动和刷新
解决办法是 把父类的update方法的内容复制到你新定义的方法的最后
像这样
#--------------------------------------------------------------------------
# ● 拆分数组并显示内容
#--------------------------------------------------------------------------
def update
for i in 0...@item_max
x = 320 + 16
if self.index == i and $t == true
refresh
self.contents.font.color = system_color
self.contents.draw_text(x, 0, 100, 32, "任务名:")
self.contents.draw_text(x, 64, 100, 32, "难度:")
self.contents.draw_text(x, 112, 100, 32, "说明:")
if @gold[index] != 0
self.contents.draw_text(x, 176, 100, 32, "奖励金钱:")
y = 240
else
y = 208
end
if @items[index] != nil
self.contents.draw_text(x, y, 100, 32, "奖励物品:")
end
self.contents.font.color = normal_color
self.contents.draw_text(x, 32, 320 - 32, 32, @name2[index])
self.contents.draw_text(x, 144, 280, 32, @task_help[index])
if @gold[index] != 0
self.contents.draw_text(x, 208, 100, 32, @gold[index])
end
if @items[index] != nil and @item != nil
for j in
[email protected]
@y = y + @item[j] * 32
end
for g in
[email protected]
draw_item_name($data_items[@item[g]], x, @y)
end
for g in
[email protected]
draw_item_name($data_weapons[@weapon[g]], x, @y + @item.size * 32)
end
for g in
[email protected]
draw_item_name($data_armors[@armor[g]], x, @y + @item.size * 32 + @weapon.size * 32)
end
end
#Moon = difficulty[index] / DIFFICULTY::System
#Star = difficulty[index] % DIFFICULTY::System
#Sun = Moon / DIFFICULTY::System
#Moon %= DIFFICULTY::System
#Space = DIFFICULTY::Space
#rect = Rect.new(0, 0, DIFFICULTY::Size, DIFFICULTY::Size)
#while Sun>0
# self.contents.blt(x + Space, 96, Sun, rect)
# Space += DIFFICULTY::Size + DIFFICULTY::Space;Sun -= 1
#end
#while Moon>0
# self.contents.blt(x + Space, 97, Moon, rect)
# Space += DIFFICULTY::Size + DIFFICULTY::Space;Moon -= 1
#end
#while Star>0
# self.contents.blt(x + Space, 98, Star, rect)
# Space += DIFFICULTY::Size + DIFFICULTY::Space;Star -= 1
#end
text1 = "★" * difficulty[index]
text2 = "☆" * (5 - difficulty[index])
text = text1 + text2
self.contents.draw_text(x + 60, 64, 280, 32, text)
end
end
#||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
super
# 可以移动光标的情况下
if self.active and @item_max > 0 and @index >= 0
# 方向键下被按下的情况下
if Input.repeat?(Input::DOWN)
# 列数不是 1 并且不与方向键下的按下状态重复的情况、
# 或光标位置在(项目数-列数)之前的情况下
if (@column_max == 1 and Input.trigger?(Input::DOWN)) or
@index < @item_max - @column_max
# 光标向下移动
$game_system.se_play($data_system.cursor_se)
@index = (@index + @column_max) % @item_max
end
end
# 方向键上被按下的情况下
if Input.repeat?(Input::UP)
# 列数不是 1 并且不与方向键下的按下状态重复的情况、
# 或光标位置在列之后的情况下
if (@column_max == 1 and Input.trigger?(Input::UP)) or
@index >= @column_max
# 光标向上移动
$game_system.se_play($data_system.cursor_se)
@index = (@index - @column_max + @item_max) % @item_max
end
end
# 方向键右被按下的情况下
if Input.repeat?(Input::RIGHT)
# 列数为 2 以上并且、光标位置在(项目数 - 1)之前的情况下
if @column_max >= 2 and @index < @item_max - 1
# 光标向右移动
$game_system.se_play($data_system.cursor_se)
@index += 1
end
end
# 方向键左被按下的情况下
if Input.repeat?(Input::LEFT)
# 列数为 2 以上并且、光标位置在 0 之后的情况下
if @column_max >= 2 and @index > 0
# 光标向左移动
$game_system.se_play($data_system.cursor_se)
@index -= 1
end
end
# R 键被按下的情况下
if Input.repeat?(Input::R)
# 显示的最后行在数据中最后行上方的情况下
if self.top_row + (self.page_row_max - 1) < (self.row_max - 1)
# 光标向后移动一页
$game_system.se_play($data_system.cursor_se)
@index = [@index + self.page_item_max, @item_max - 1].min
self.top_row += self.page_row_max
end
end
# L 键被按下的情况下
if Input.repeat?(Input::L)
# 显示的开头行在位置 0 之后的情况下
if self.top_row > 0
# 光标向前移动一页
$game_system.se_play($data_system.cursor_se)
@index = [@index - self.page_item_max, 0].max
self.top_row -= self.page_row_max
end
end
end
# 刷新帮助文本 (update_help 定义了继承目标)
if self.active and @help_window != nil
update_help
end
# 刷新光标矩形
update_cursor_rect
end
复制代码
另外,140行的Index应该为index。。。
作者:
紫英晓狼1130
时间:
2013-10-4 17:45
index的事,顺便我说说星星
这是谁改的,比之前方便多了。我之前想根据完成程度描绘星星,并且由项目数得到坐标,看来我想麻烦了…
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1