设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1289|回复: 3
打印 上一主题 下一主题

[已经解决] 为什么自制的有光标的类却不显示光标?

[复制链接]

Lv1.梦旅人

矿工

梦石
0
星屑
134
在线时间
898 小时
注册时间
2012-10-5
帖子
1535
跳转到指定楼层
1
发表于 2013-10-4 16:35:02 | 只看该作者 回帖奖励 |正序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 876加几 于 2013-10-4 16:45 编辑

脚本:
  1. #==============================================================================
  2. # ■ Window_Task
  3. #------------------------------------------------------------------------------
  4. #  显示任务的选择行窗口。
  5. #==============================================================================

  6. class Window_Task < Window_Selectable
  7.   #--------------------------------------------------------------------------
  8.   # ● 初始化对像
  9.   #--------------------------------------------------------------------------
  10.   def initialize
  11.     super(0, 0, 640, 480 - 64)
  12.     @name = nil
  13.     @task_help = nil
  14.     [url=home.php?mod=space&uid=236945]@gold[/url] = nil
  15.     @items = nil
  16.     @weapons = nil
  17.     @armors = nil
  18.     @item = nil
  19.     [url=home.php?mod=space&uid=36793]@weapon[/url] = nil
  20.     @armor = nil
  21.     if @name == nil
  22.       @item_max = 1
  23.     else
  24.       @item_max = @name.size
  25.     end
  26.     difficulty = nil
  27.     self.contents = Bitmap.new(width - 32, height - 32)
  28.     refresh
  29.     self.index = -1
  30.   end
  31.   #--------------------------------------------------------------------------
  32.   # ● 刷新
  33.   #--------------------------------------------------------------------------
  34.   def refresh
  35.     self.contents.clear
  36.     if @name == nil
  37.       @item_max = 1
  38.     else
  39.       @item_max = @name.size
  40.     end
  41.   end
  42.   #--------------------------------------------------------------------------
  43.   # ● 报偿设置
  44.   #     item_id/weapon_id/armor_id : 报偿物品在数据库中的位置,nil等于没报偿
  45.   #--------------------------------------------------------------------------
  46.   def reward_items(item_id = nil)
  47.     @item[@item.size] = item_id
  48.   end
  49.   def reward_weapons(weapon_id = nil)
  50.     @weapon[@weapon.size] = weapon_id
  51.   end
  52.   def reward_armor(armor_id = nil)
  53.     @armor[@armor.size] = armor_id
  54.   end
  55.   #--------------------------------------------------------------------------
  56.   # ● 新建任务
  57.   #     new_name   :       新任务的名称
  58.   #     task_help  :       新任务的简介
  59.   #     difficulty :       新任务的难度
  60.   #     gold       :       金钱报偿,0等于没报偿
  61.   #--------------------------------------------------------------------------
  62.   def new_task(new_name, task_help, difficulty = 1, gold = 0)
  63.     @name_size = @name.size
  64.     @task_help_size = @task_help.size
  65.     difficulty_size = difficulty.size
  66.     @gold_size = @gold.size
  67.     @items_size = @items.size
  68.     @weapons_size = @weapons.size
  69.     @armors_size = @armors.size
  70.     @name[@name_size] = new_name
  71.     @name2[@name_size] = new_name
  72.     @task_help[@task_help_size] = task_help
  73.     @difficulty[difficulty_size] = difficulty
  74.     @gold[@gold_size] = gold
  75.     @items[@items_size] = @item
  76.     @weapons[@weapons_size] = @weapon
  77.     @armors[@armors_size] = @armor
  78.   end
  79.   #--------------------------------------------------------------------------
  80.   # ● 完成任务
  81.   #     bbb   : 任务ID
  82.   #--------------------------------------------------------------------------
  83.   def final_task(bbb)
  84.     [url=home.php?mod=space&uid=110690]@BBB[/url] = bbb - 1
  85.     unless @name[@bbb].include?("(已失败)")
  86.       @name[@bbb] = @name[@bbb] + "(已完成)"
  87.       @task_help[@bbb] = @task_help[@bbb] + "(已完成)"
  88.       $game_party.gain_gold(@gold[bbb])
  89.       for i in [email protected]
  90.         if @item != nil
  91.           $game_party.gain_item(@item[i], 1)
  92.         end
  93.       end
  94.       for i in [email protected]
  95.         if [url=home.php?mod=space&uid=36793]@weapon[/url] != nil
  96.           $game_party.gain_weapon(@weapon[i], 1)
  97.         end
  98.       end
  99.       for i in [email protected]
  100.         if @armor != nil
  101.           $game_party.gain_armor(@armor[i], 1)
  102.         end
  103.       end
  104.     end
  105.   end
  106.   #--------------------------------------------------------------------------
  107.   # ● 任务失败
  108.   #     ccc   : 任务ID
  109.   #--------------------------------------------------------------------------
  110.   def lose_task(ccc)
  111.     [url=home.php?mod=space&uid=9267]@CCC[/url] = ccc - 1
  112.     unless @name[@bbb].include?("(已完成)")
  113.       @name[@ccc] = @name[@ccc] + "(已失败)"
  114.       @task_help[@ccc] = @task_help[@ccc] + "(已失败)"
  115.     end
  116.   end
  117.   #--------------------------------------------------------------------------
  118.   # ● 描绘项目
  119.   #     index : 项目编号
  120.   #     color : 文字色
  121.   #--------------------------------------------------------------------------
  122.   def draw_item(index,color)
  123.     self.contents.font.color = color
  124.     rect = Rect.new(4, 32 * index, 640 / 2 - 8, 32)
  125.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  126.     self.contents.draw_text(rect, @name[index])
  127.   end
  128.   #--------------------------------------------------------------------------
  129.   # ● 项目无效化
  130.   #     index : 项目编号
  131.   #--------------------------------------------------------------------------
  132.   def disable_item(index)
  133.     draw_item(index, disabled_color)
  134.   end
  135.   #--------------------------------------------------------------------------
  136.   # ● 刷新光标矩形
  137.   #--------------------------------------------------------------------------
  138.   def update_cursor_rect
  139.     if [url=home.php?mod=space&uid=370741]@Index[/url] < 0
  140.       self.cursor_rect.empty
  141.     else
  142.       self.cursor_rect.set(0, @index * 56, 320 - 8, 32)
  143.     end
  144.   end
  145.   #--------------------------------------------------------------------------
  146.   # ● 拆分数组并显示内容
  147.   #--------------------------------------------------------------------------
  148.   def update
  149.     for i in 0...@item_max
  150.       x = 320 + 16
  151.       if self.index == i and $t == true
  152.         refresh
  153.         self.contents.font.color = system_color
  154.         self.contents.draw_text(x, 0, 100, 32, "任务名:")
  155.         self.contents.draw_text(x, 64, 100, 32, "难度:")
  156.         self.contents.draw_text(x, 112, 100, 32, "说明:")
  157.         if @gold[index] != 0
  158.           self.contents.draw_text(x, 176, 100, 32, "奖励金钱:")
  159.           y = 240
  160.         else
  161.           y = 208
  162.         end
  163.         if @items[index] != nil
  164.           self.contents.draw_text(x, y, 100, 32, "奖励物品:")
  165.         end
  166.         self.contents.font.color = normal_color
  167.         self.contents.draw_text(x, 32, 320 - 32, 32, @name2[index])
  168.         self.contents.draw_text(x, 144, 280, 32, @task_help[index])
  169.         if @gold[index] != 0
  170.           self.contents.draw_text(x, 208, 100, 32, @gold[index])
  171.         end
  172.         if @items[index] != nil and @item != nil
  173.           for j in [email protected]
  174.             @y = y + @item[j] * 32
  175.           end
  176.           for g in [email protected]
  177.             draw_item_name($data_items[@item[g]], x, @y)
  178.           end
  179.           for g in [email protected]
  180.             draw_item_name($data_weapons[@weapon[g]], x, @y + @item.size * 32)
  181.           end
  182.           for g in [email protected]
  183.             draw_item_name($data_armors[@armor[g]], x, @y + @item.size * 32 + @weapon.size * 32)
  184.           end
  185.         end
  186.         #Moon = difficulty[index] / DIFFICULTY::System
  187.         #Star = difficulty[index] % DIFFICULTY::System
  188.         #Sun = Moon / DIFFICULTY::System
  189.         #Moon %= DIFFICULTY::System
  190.         #Space = DIFFICULTY::Space
  191.         #rect = Rect.new(0, 0, DIFFICULTY::Size, DIFFICULTY::Size)
  192.         #while Sun>0
  193.         #  self.contents.blt(x + Space, 96, Sun, rect)
  194.         #  Space += DIFFICULTY::Size + DIFFICULTY::Space;Sun -= 1
  195.         #end
  196.         #while Moon>0
  197.         #  self.contents.blt(x + Space, 97, Moon, rect)
  198.         #  Space += DIFFICULTY::Size + DIFFICULTY::Space;Moon -= 1
  199.         #end
  200.         #while Star>0
  201.         #  self.contents.blt(x + Space, 98, Star, rect)
  202.         #  Space += DIFFICULTY::Size + DIFFICULTY::Space;Star -= 1
  203.         #end
  204.         text1 = "★" * difficulty[index]
  205.         text2 = "☆" * (5 - difficulty[index])
  206.         text = text1 + text2
  207.         self.contents.draw_text(x + 60, 64, 280, 32, text)
  208.       end
  209.     end
  210.   end
  211. end
复制代码
先不说NoMethodError,居然连光标都不显示了,处于有光标活动的类连光标都不见了,这是怎么回事? 光标的声音也是在Scene类手动添加的。
Scene类代码:
  1. #===============================================================================
  2. # ● Scene_Task
  3. #-------------------------------------------------------------------------------
  4. #   处理任务画面的类。
  5. #===============================================================================
  6. class Scene_Task
  7.   #--------------------------------------------------------------------------
  8.   # ● 主处理
  9.   #--------------------------------------------------------------------------
  10.   def main
  11.     # 生成任务活动窗口
  12.     @task_window = Window_Task.new
  13.     @task_window.y = 64
  14.     if @task_window.active == false
  15.       @task_window.active = true
  16.     end
  17.     # 生成任务辅助窗口
  18.     @taskassist_window = Window_TaskAssist.new
  19.     # 执行过渡
  20.     Graphics.transition
  21.     # 主循环
  22.     loop do
  23.       # 刷新游戏画面
  24.       Graphics.update
  25.       # 刷新输入信息
  26.       Input.update
  27.       # 刷新画面
  28.       update
  29.       # 如果切换画面就中断循环
  30.       if $scene != self
  31.         break
  32.       end
  33.     end
  34.     # 准备过渡
  35.     Graphics.freeze
  36.     # 释放各个窗口
  37.     @task_window.dispose
  38.     @taskassist_window.dispose
  39.   end
  40.   #--------------------------------------------------------------------------
  41.   # ● 刷新画面
  42.   #--------------------------------------------------------------------------
  43.   def update
  44.     # 刷新各个窗口
  45.     @task_window.update
  46.     @taskassist_window.update
  47.     # 当按下 C 键后可查看任务信息
  48.     if Input.trigger?(Input::C)
  49.       $t = true #让T变为true
  50.       # 演奏确定 SE
  51.       $game_system.se_play($data_system.decision_se)
  52.     end
  53.     # 解除任务信息
  54.     if $t == true
  55.       # 按下 B 键的情况下
  56.       if Input.trigger?(Input::B)
  57.         $t = false
  58.         # 演奏取消 SE
  59.         $game_system.se_play($data_system.cancel_se)
  60.       end
  61.       if Input.trigger?(Input::UP)
  62.         $t = false
  63.         # 演奏光标 SE
  64.         $game_system.se_play($data_system.cursor_se)
  65.       end
  66.       if Input.trigger?(Input::DOWN)
  67.         # 演奏光标 SE
  68.         $game_system.se_play($data_system.cursor_se)
  69.       end
  70.     end
  71.     # 演奏光标 SE
  72.     if Input.trigger?(Input::UP)
  73.       # 演奏光标 SE
  74.       $game_system.se_play($data_system.cursor_se)
  75.     end
  76.     if Input.trigger?(Input::DOWN)
  77.       $t = false
  78.       # 演奏光标 SE
  79.       $game_system.se_play($data_system.cursor_se)
  80.     end
  81.     # 没显示任务时按下 B 键的情况下
  82.     if $t == false and Input.trigger?(Input::B)
  83.       # 切换到菜单界面
  84.       $scene = Scene_Menu.new(5)
  85.     end
  86.   end
  87. end
复制代码

点评

@myownroc Scene类写好的,每个窗口都有.new(生成)、.dispose(释放)、.update(刷新)  发表于 2013-10-4 16:43
你给个window 类的代码有什么用?谁知道是不是你Scene 类的代码没写好(比如没刷新)。。。  发表于 2013-10-4 16:41
呃,发糖贴好冷清呀!

Lv1.梦旅人

薄凉看客

梦石
0
星屑
50
在线时间
1269 小时
注册时间
2010-6-20
帖子
1316
来自 2楼
发表于 2013-10-4 16:54:28 | 只看该作者
本帖最后由 恋′挂机 于 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"

等等

点评

看我的回答。他把父类的update方法重新定义了。。。index=-1 也是一个原因  发表于 2013-10-4 17:16
我看是因为index = -1的缘故  发表于 2013-10-4 16:54

评分

参与人数 1星屑 +100 收起 理由
myownroc + 100 认可答案

查看全部评分

回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
3846
在线时间
1966 小时
注册时间
2013-1-3
帖子
9536
4
发表于 2013-10-4 17:45:07 | 只看该作者
index的事,顺便我说说星星
这是谁改的,比之前方便多了。我之前想根据完成程度描绘星星,并且由项目数得到坐标,看来我想麻烦了…

点评

不只是index,楼主重新定义了update方法。。。  发表于 2013-10-4 17:48
《宿愿·寻剑篇》正式版已经发布!快去看看!点击进入论坛发布贴
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
2744
在线时间
2630 小时
注册时间
2013-1-16
帖子
5657

贵宾

3
发表于 2013-10-4 17:12:27 | 只看该作者
@Index 无视这个@

Window_Task类里的
def update 是什么情况?
Window_Task是Window_Selectable的子类,继承了父类Window_Selectable的方法update
所以你在Window_Task类里重新定义了update方法
而父类的update方法定义了光标移动和刷新
解决办法是 把父类的update方法的内容复制到你新定义的方法的最后
像这样
  1.   #--------------------------------------------------------------------------
  2.   # ● 拆分数组并显示内容
  3.   #--------------------------------------------------------------------------
  4.   def update
  5.     for i in 0...@item_max
  6.       x = 320 + 16
  7.       if self.index == i and $t == true
  8.         refresh
  9.         self.contents.font.color = system_color
  10.         self.contents.draw_text(x, 0, 100, 32, "任务名:")
  11.         self.contents.draw_text(x, 64, 100, 32, "难度:")
  12.         self.contents.draw_text(x, 112, 100, 32, "说明:")
  13.         if @gold[index] != 0
  14.           self.contents.draw_text(x, 176, 100, 32, "奖励金钱:")
  15.           y = 240
  16.         else
  17.           y = 208
  18.         end
  19.         if @items[index] != nil
  20.           self.contents.draw_text(x, y, 100, 32, "奖励物品:")
  21.         end
  22.         self.contents.font.color = normal_color
  23.         self.contents.draw_text(x, 32, 320 - 32, 32, @name2[index])
  24.         self.contents.draw_text(x, 144, 280, 32, @task_help[index])
  25.         if @gold[index] != 0
  26.           self.contents.draw_text(x, 208, 100, 32, @gold[index])
  27.         end
  28.         if @items[index] != nil and @item != nil
  29.           for j in [email protected]
  30.             @y = y + @item[j] * 32
  31.           end
  32.           for g in [email protected]
  33.             draw_item_name($data_items[@item[g]], x, @y)
  34.           end
  35.           for g in [email protected]
  36.             draw_item_name($data_weapons[@weapon[g]], x, @y + @item.size * 32)
  37.           end
  38.           for g in [email protected]
  39.             draw_item_name($data_armors[@armor[g]], x, @y + @item.size * 32 + @weapon.size * 32)
  40.           end
  41.         end
  42.         #Moon = difficulty[index] / DIFFICULTY::System
  43.         #Star = difficulty[index] % DIFFICULTY::System
  44.         #Sun = Moon / DIFFICULTY::System
  45.         #Moon %= DIFFICULTY::System
  46.         #Space = DIFFICULTY::Space
  47.         #rect = Rect.new(0, 0, DIFFICULTY::Size, DIFFICULTY::Size)
  48.         #while Sun>0
  49.         #  self.contents.blt(x + Space, 96, Sun, rect)
  50.         #  Space += DIFFICULTY::Size + DIFFICULTY::Space;Sun -= 1
  51.         #end
  52.         #while Moon>0
  53.         #  self.contents.blt(x + Space, 97, Moon, rect)
  54.         #  Space += DIFFICULTY::Size + DIFFICULTY::Space;Moon -= 1
  55.         #end
  56.         #while Star>0
  57.         #  self.contents.blt(x + Space, 98, Star, rect)
  58.         #  Space += DIFFICULTY::Size + DIFFICULTY::Space;Star -= 1
  59.         #end
  60.         text1 = "★" * difficulty[index]
  61.         text2 = "☆" * (5 - difficulty[index])
  62.         text = text1 + text2
  63.         self.contents.draw_text(x + 60, 64, 280, 32, text)
  64.       end
  65.     end
  66. #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||   
  67.     super
  68.     # 可以移动光标的情况下
  69.     if self.active and @item_max > 0 and @index >= 0
  70.       # 方向键下被按下的情况下
  71.       if Input.repeat?(Input::DOWN)
  72.         # 列数不是 1 并且不与方向键下的按下状态重复的情况、
  73.         # 或光标位置在(项目数-列数)之前的情况下
  74.         if (@column_max == 1 and Input.trigger?(Input::DOWN)) or
  75.            @index < @item_max - @column_max
  76.           # 光标向下移动
  77.           $game_system.se_play($data_system.cursor_se)
  78.           @index = (@index + @column_max) % @item_max
  79.         end
  80.       end
  81.       # 方向键上被按下的情况下
  82.       if Input.repeat?(Input::UP)
  83.         # 列数不是 1 并且不与方向键下的按下状态重复的情况、
  84.         # 或光标位置在列之后的情况下
  85.         if (@column_max == 1 and Input.trigger?(Input::UP)) or
  86.            @index >= @column_max
  87.           # 光标向上移动
  88.           $game_system.se_play($data_system.cursor_se)
  89.           @index = (@index - @column_max + @item_max) % @item_max
  90.         end
  91.       end
  92.       # 方向键右被按下的情况下
  93.       if Input.repeat?(Input::RIGHT)
  94.         # 列数为 2 以上并且、光标位置在(项目数 - 1)之前的情况下
  95.         if @column_max >= 2 and @index < @item_max - 1
  96.           # 光标向右移动
  97.           $game_system.se_play($data_system.cursor_se)
  98.           @index += 1
  99.         end
  100.       end
  101.       # 方向键左被按下的情况下
  102.       if Input.repeat?(Input::LEFT)
  103.         # 列数为 2 以上并且、光标位置在 0 之后的情况下
  104.         if @column_max >= 2 and @index > 0
  105.           # 光标向左移动
  106.           $game_system.se_play($data_system.cursor_se)
  107.           @index -= 1
  108.         end
  109.       end
  110.       # R 键被按下的情况下
  111.       if Input.repeat?(Input::R)
  112.         # 显示的最后行在数据中最后行上方的情况下
  113.         if self.top_row + (self.page_row_max - 1) < (self.row_max - 1)
  114.           # 光标向后移动一页
  115.           $game_system.se_play($data_system.cursor_se)
  116.           @index = [@index + self.page_item_max, @item_max - 1].min
  117.           self.top_row += self.page_row_max
  118.         end
  119.       end
  120.       # L 键被按下的情况下
  121.       if Input.repeat?(Input::L)
  122.         # 显示的开头行在位置 0 之后的情况下
  123.         if self.top_row > 0
  124.           # 光标向前移动一页
  125.           $game_system.se_play($data_system.cursor_se)
  126.           @index = [@index - self.page_item_max, 0].max
  127.           self.top_row -= self.page_row_max
  128.         end
  129.       end
  130.     end
  131.     # 刷新帮助文本 (update_help 定义了继承目标)
  132.     if self.active and @help_window != nil
  133.       update_help
  134.     end
  135.     # 刷新光标矩形
  136.     update_cursor_rect
  137.   end
复制代码
另外,140行的Index应该为index。。。

评分

参与人数 1星屑 +6 收起 理由
恐惧剑刃 + 6 我很赞同

查看全部评分

(Created by @喵kano)


施工现场:hotege.github.io
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-9-30 04:18

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表