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

Project1

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

[已经解决] 【已解决】光标index满16个跳下一页已正常,16个头像重叠...

[复制链接]

Lv4.逐梦者

梦石
0
星屑
6291
在线时间
1103 小时
注册时间
2015-8-15
帖子
658
跳转到指定楼层
1
发表于 2023-4-14 10:27:52 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 金芒芒 于 2023-4-20 11:11 编辑

RUBY 代码复制
  1. #==============================================================================
  2. # ■ Window_Item
  3. #------------------------------------------------------------------------------
  4. #  显示可以装备的回路。
  5. #==============================================================================
  6. class Window_Troops_List< Window_Base
  7.   def blue_color
  8.     return Color.new(141,157,180)
  9.   end
  10.   #--------------------------------------------------------------------------
  11.   # ● 定义实例变量
  12.   #--------------------------------------------------------------------------
  13.   attr_reader   :index                    # 光标位置
  14.   attr_reader   :help_window              # 帮助窗口
  15.   attr_reader   :type                     # 种类
  16.   attr_reader   :able                     # 暗色
  17.  
  18.   def type=(type)
  19.     @type = type
  20.   end
  21.   def type
  22.     return @type
  23.   end
  24.   #--------------------------------------------------------------------------
  25.   # ● 设置光标的位置
  26.   #     index : 新的光标位置
  27.   #--------------------------------------------------------------------------
  28.   def index=(index)
  29.     @index = index
  30.     @column_max = 4
  31.     # 刷新帮助文本 (update_help 定义了继承目标)
  32.     if self.active and @help_window != nil
  33.       update_help
  34.     end
  35.     # 刷新光标矩形
  36.     update_cursor_rect
  37.   end
  38.   #--------------------------------------------------------------------------
  39.   # ● 获取行数
  40.   #--------------------------------------------------------------------------
  41.   def row_max
  42.     # 由项目数和列数计算出行数
  43.     return @item_max
  44.   end
  45.   #--------------------------------------------------------------------------
  46.   # ● 获取开头行
  47.   #--------------------------------------------------------------------------
  48.   def top_row
  49.     # 将窗口内容的传送源 Y 坐标、1 行的高 32 等分
  50.     return self.oy / 32
  51.   end
  52.   #--------------------------------------------------------------------------
  53.   # ● 设置开头行
  54.   #     row : 显示开头的行
  55.   #--------------------------------------------------------------------------
  56.   def top_row=(row)
  57.     # row 未满 0 的场合更正为 0
  58.     if row < 0
  59.       row = 0
  60.     end
  61.     # row 超过 row_max - 1 的情况下更正为 row_max - 1
  62.     if row > row_max - 1
  63.       row = row_max - 1
  64.     end
  65.     # row 1 行高的 32 倍、窗口内容的传送源 Y 坐标
  66.     self.oy = row * 32
  67.   end
  68.   #--------------------------------------------------------------------------
  69.   # ● 获取 1 页可以显示的行数
  70.   #--------------------------------------------------------------------------
  71.   def page_row_max
  72.     # 窗口的高度,设置画面的高度减去 32 ,除以 1 行的高度 32
  73.     return 14
  74.   end  
  75.   #--------------------------------------------------------------------------
  76.   # ● 初始化对像
  77.   #     actor : 角色
  78.   #--------------------------------------------------------------------------
  79.   def initialize(type = 0,player_or_enermy = 0)
  80.  
  81.     @all_fighters = Figter_data::ALL_SOLDIER   #所有士兵
  82.  
  83.     #右侧滚动条
  84.     @right_back = Bar_Right.new("right_back", origin_x+172, origin_y+12, 20*14)
  85.     @right_back.visible = false
  86.     @right = Bar_Right.new("right", origin_x+170, origin_y+12, 0)
  87.     @right.visible = false
  88.     #变量更新
  89.     @type = 0
  90.     @index = 0
  91.     #背景
  92.     @back = Sprite.new
  93.     @back.bitmap = RPG::Cache.menu("troopList-base")
  94.   #  @back.x = origin_x
  95.    # @back.y = origin_y
  96.     @help_window = Window_Troop_Info.new
  97.  
  98.  
  99.     @item_icon = []
  100.     @item_icon[0] = Sprite.new
  101.     #初始化
  102.     super(origin_x,origin_y,1200,600)
  103.    # super(origin_x,origin_y,287/2+32,14*20+32)
  104.     self.windowskin  = RPG::Cache.menu("Blue")
  105.     self.opacity = 0
  106.     self.active = false
  107.     #刷新
  108.     refresh(type)
  109.     refresh(type)
  110.     update_help
  111.   end
  112.   #--------------------------------------------------------------------------
  113.   # ● 活动窗口用原始x y坐标
  114.   #--------------------------------------------------------------------------  
  115.   def origin_x
  116.     return 28
  117.   end
  118.   def origin_y
  119.     return 108
  120.   end
  121.   #--------------------------------------------------------------------------
  122.   # ● 定义用选择状态决定窗口颜色
  123.   #--------------------------------------------------------------------------  
  124.   def able=(able)
  125.     @able=able
  126.     @right_back.able = able
  127.     @right.able = able
  128.     if active
  129.       @back.color = Color.new(255,255,255,0)
  130.     else
  131.       @back.color = Color.new(0,0,0,128)
  132.     end
  133.     refresh
  134.   end
  135.  
  136.  
  137.  
  138.       #--------------------------------------------------------------------------
  139.   # ● 更新光标矩形
  140.   #--------------------------------------------------------------------------
  141.   def update_cursor_rect
  142.     #@back.bitmap = RPG::Cache.menu("item_command"+type.to_s)
  143.     # 光标位置不满 0 的情况下
  144.     if @index < 0
  145.       self.cursor_rect.empty
  146.       return
  147.     end
  148.  
  149.     # 获取当前的行
  150.     row = @index / @column_max
  151.     # 当前行被显示开头行前面的情况下
  152.     if row < self.top_row
  153.       # 从当前行向开头行滚动
  154.       self.top_row = row
  155.     end
  156.     # 当前行被显示末尾行之后的情况下
  157.     if row > self.top_row + (self.page_row_max - 1)
  158.       # 从当前行向末尾滚动
  159.       self.top_row = row - (self.page_row_max - 1)
  160.     end
  161.     i = @index
  162.     #cursor_width = 240
  163.     self.cursor_rect.set(i%4*84,(i/4-self.oy/120)*120-1,84,120)
  164.   end
  165.   def top_row
  166.     return self.oy / 120
  167.   end
  168.   def page_row_max
  169.     return (self.height - 120) / 120
  170.   end
  171.  
  172.     # 计算光标的宽度
  173.  
  174.     # 计算光标坐标
  175.   #  x = 8
  176.   #  y = @index*20 - self.oy-1
  177.     # 更新光标矩形
  178.   #  self.cursor_rect.set(x, y, cursor_width, 22)
  179.   #end
  180.   #--------------------------------------------------------------------------
  181.   # ● 一些方法的重载
  182.   #--------------------------------------------------------------------------  
  183.   def active=(active)
  184.     if active
  185.       if @item_max <= 0
  186.         self.index = -1
  187.       else
  188.         self.index = 0
  189.       end
  190.     else
  191.       self.index = -1
  192.     end
  193.     @ajsdgfshfajklshfa = nil
  194.     @help_window.set_text( nil ) if @help_window != nil
  195.     super(active)
  196.   end
  197.   def dispose
  198.     @back.dispose
  199.     @right_back.dispose
  200.     @right.dispose
  201.     for i in 0...@item_icon.size
  202.       @item_icon[i].dispose
  203.     end
  204.     @help_window.dispose
  205.     super
  206.   end
  207.   def x=(x)
  208.     @back.x = x-origin_x #+ 15
  209.     @right_back.x = x+172 #+30
  210.     @right.x = x+170 #+30
  211.     for i in 0...@item_icon.size
  212.       @item_icon[i].x = 500+self.x+x - self.index%4 * (66 + 5)       #14
  213.     end
  214.     super(x-16)
  215.   end
  216.   def x
  217.     return super+16
  218.   end
  219.   def y=(y)
  220.     @back.y = y-origin_y# + 60
  221.     @right_back.y = y+12 #+ origin_y
  222.     @right.y = y+12 #+ origin_y
  223.     for i in 0...@item_icon.size
  224.       @item_icon[i].y= 110+ self.x+x - self.index/4 * (66 + 5)#16  # + origin_y #+ 25   #14
  225.     end
  226.     super(y)
  227.   end
  228.   def z=(z)
  229.     @back.z=z-5
  230.     @right_back.z=z+3
  231.     @right.z=z+4
  232.     for i in 0...@item_icon.size
  233.       @item_icon[i].z=z+2
  234.     end
  235.     super(z)
  236.   end
  237.   def visible=(visible)
  238.     @back.visible=visible
  239.     @right_back.visible=visible
  240.     @right.visible=visible
  241.   #  @help_window.visible=visible
  242.     super(visible)
  243.   end
  244.   def contents_opacity=(opacity)
  245.     @back.opacity=opacity
  246.     @right_back.opacity=opacity
  247.     @right.opacity=opacity
  248.    # @help_window.opacity=opacity
  249.     super(opacity)
  250.   end
  251.   def oy=(oy)
  252.     #缩放图标时只显示当前页的项目
  253.     for i in 0...@item_icon.size
  254.       @item_icon[i].y = 16+20*i+self.y-oy
  255.       if @item_icon[i].y < self.y or @item_icon[i].y > self.y+20*self.page_row_max
  256.         @item_icon[i].visible = false
  257.       else
  258.         @item_icon[i].visible = true
  259.       end
  260.     end
  261.     super(oy)
  262.   end
  263.  
  264.   #--------------------------------------------------------------------------
  265.   # ● 获取物品
  266.   #--------------------------------------------------------------------------  
  267.   def item
  268.     return @all_fighters[self.index]
  269.   end
  270.   #--------------------------------------------------------------------------
  271.   # ● 刷新
  272.   #--------------------------------------------------------------------------  
  273.   def refresh(type=@type)#all,1,2,3,4,5,6,7 RPPG::ARMOR_BEGIN
  274.     if self.contents != nil
  275.       self.contents.dispose
  276.       self.contents = nil
  277.     end
  278.  
  279.     for i in 0...@item_icon.size
  280.       @item_icon[i].dispose
  281.     end
  282.     @item_icon = []
  283.     @item_icon[0] = Sprite.new
  284.  
  285.  
  286.  
  287.     for i in 0...@all_fighters.size
  288.      @item_icon[i] = Sprite.new
  289.  
  290.      name = Figter_data::CHARACTER_NAME[@all_fighters[i]]
  291.      @item_icon[i].bitmap = RPG::Cache.icon(name) if name != nil
  292.  
  293.     end
  294.  
  295.     @item_max = @all_fighters.size
  296.     #下标超过范围的时候往回退一格
  297.     if self.top_row > @item_max-self.page_row_max
  298.       self.top_row = @item_max-self.page_row_max
  299.     end
  300.     if self.index >= @item_max
  301.       self.index = @item_max-1
  302.     end
  303.  
  304.     #右侧滚动条显示
  305.     if @item_max > self.page_row_max
  306.       @right_back.visible = true
  307.       @right.visible = true
  308.     else
  309.       @right_back.visible = false
  310.       @right.visible = false
  311.     end
  312.     #滚动条的更新
  313.     if @right.visible
  314.       @right.height = (14*20)*(14*20)/(@item_max.to_f*20)-24.0 > 0 ? (14*20)*(14*20)/(@item_max.to_f*20)-24.0 : 0
  315.     end
  316.  
  317.     # 如果项目数不是 0 就生成位图、描绘全部项目
  318.     if @item_max > 0
  319.       self.contents = Bitmap.new(width - 32, @item_max*20)
  320.       for i in 0...@item_max
  321.         draw_item(i, 12, i*20)
  322.       end
  323.     else
  324.       self.contents = Bitmap.new(width - 32, 20)
  325.     end
  326.     #缩放图标时只显示当前页的项目
  327.     for i in 0...@item_icon.size
  328.       @item_icon[i].y = 20*i+self.y-oy+16
  329.       if @item_icon[i].y < self.y or @item_icon[i].y > self.y+20*self.page_row_max
  330.         @item_icon[i].visible = false
  331.       else
  332.         @item_icon[i].visible = true
  333.       end
  334.     end
  335.    #update_help
  336.   end
  337.   #--------------------------------------------------------------------------
  338.   # ● 描绘物品
  339.   #--------------------------------------------------------------------------  
  340.   def draw_item(index, x, y)
  341.  
  342.     item = @all_fighters[index]
  343.  
  344.  
  345.  
  346.  
  347.     self.contents.font.size = 12
  348.   #  x = 4 + index % 4 * 37
  349.   #  y = index / 4 * 37
  350.  
  351.     #图标缩放显示专用
  352.     icon_size = 100#图片缩放大小
  353.    # row = @item_icon[index]/@column_max
  354.     @item_icon[index].x = 500+self.x+x - self.index%4 * (66 + 5)# self.x%4*84
  355.     @item_icon[index].y = 110+ self.x+x - self.index/4 * (66 + 5)
  356.     @item_icon[index].zoom_x = icon_size.to_f/@item_icon[index].bitmap.width
  357.     @item_icon[index].zoom_y = icon_size.to_f/@item_icon[index].bitmap.height
  358.     @item_icon[index].z = self.z+2
  359.     @item_icon[index].color = self.contents.font.color==normal_color ? Color.new(255,255,255,0):Color.new(0,0,0,128)
  360.     #self.contents.font.color = Color.new(128,193,125,0)
  361.     name = Figter_data::THE_NAME[item]
  362.     self.contents.draw_text(x + icon_size.to_f, y + 4, 184, self.contents.font.size, name)
  363.  
  364.  
  365.   end
  366.   #--------------------------------------------------------------------------
  367.   # ● 帮助窗口的设置
  368.   #     help_window : 新的帮助窗口
  369.   #--------------------------------------------------------------------------
  370.   def help_window=(help_window)
  371.     @help_window = help_window
  372.     # 刷新帮助文本 (update_help 定义了继承目标)
  373.     if self.active and @help_window != nil
  374.       update_help
  375.     end
  376.   end
  377.  
  378.  
  379.  
  380. #--------------------------------------------------------------------------
  381.   # ● 刷新画面
  382.   #--------------------------------------------------------------------------
  383.   def update
  384.     super
  385.  
  386.     # 可以移动光标的情况下
  387.     if self.active and @item_max >= 0 and @index >= 0
  388.       # 方向键下被按下的情况下
  389.       if Input.repeat?(Input::DOWN)
  390.         # 光标向下移动
  391.         $game_system.se_play($data_system.cursor_se)
  392.         @index = (@index+1+@item_max) % @item_max if @item_max != 0
  393.         update_help
  394.       end
  395.       # 方向键上被按下的情况下
  396.       if Input.repeat?(Input::UP)
  397.         # 光标向上移动
  398.         $game_system.se_play($data_system.cursor_se)
  399.         @index = (@index-1+@item_max) % @item_max if @item_max != 0
  400.         update_help
  401.       end
  402.  
  403.  
  404.     end
  405.  
  406.     # 刷新帮助文本 (update_help 定义了继承目标)
  407.     if @help_window != nil and @ajsdgfshfajklshfa == nil
  408.       update_help
  409.       update_help
  410.       @ajsdgfshfajklshfa = true
  411.     end
  412.  
  413.     # 刷新光标矩形
  414.     update_cursor_rect
  415.   end
  416.  
  417.  
  418.  
  419.   def now_selected_troop
  420.     return @all_fighters[@index]
  421.   end
  422.  
  423.   #--------------------------------------------------------------------------
  424.   # ● 刷新帮助文本
  425.   #--------------------------------------------------------------------------
  426.   def update_help
  427.     #鲜辣煎鱼
  428.     @help_window.set_text( @index>-1 ? self.item : nil )
  429.  
  430.   end
  431. end

重叠了.png (365.39 KB, 下载次数: 4)

重叠了

重叠了

1下一页.png (648.68 KB, 下载次数: 2)

以前的

以前的

Lv5.捕梦者

梦石
24
星屑
7017
在线时间
247 小时
注册时间
2020-12-4
帖子
306

极短24获奖极短23获奖极短22获奖

2
发表于 2023-4-19 13:32:51 | 只看该作者
建议放上上一个问题的链接,不然没有看过上文的人都不知所云【笑哭】

头像重叠,可能是翻页的时候的refresh 刷新的问题,即,生成了新的头像bitmap,但是没有把旧的 bitmap clear 掉
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
6291
在线时间
1103 小时
注册时间
2015-8-15
帖子
658
3
 楼主| 发表于 2023-4-19 17:04:36 | 只看该作者
纯属小虫 发表于 2023-4-19 13:32
建议放上上一个问题的链接,不然没有看过上文的人都不知所云【笑哭】

头像重叠,可能是翻页的时候的refres ...

这个已经解决了,  x%4   y/4 这个也是属于包裹问题
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-28 16:46

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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