查看: 3972|回复: 5

Vlue的「简单图标物品栏」兼容「右侧滚动条」

[复制链接]
梦石
0
星屑
29901
在线时间
5734 小时
注册时间
2016-3-8
回帖
1653
发表于 2020-9-10 21:04:25 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 alexncf125 于 2024-1-25 13:05 编辑

@cinderelmini
大大的右侧滚动条与下方的脚本合用会有瑕疵喔
问题好像与page_row_max有关?
未命名.png

[pre lang="ruby"]#简单图标物品栏 v1.0
#----------#
#特点: 看, 是图标! 而不是列表!
#
#使用方法:    即插即用.
#
#----------#
#-- Script by: V.M of D.T
#
#- Questions or comments can be:
#    given by email: sumptuaryspade@live.ca
#    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
#   All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
#
#--- Free to use in any project, commercial or non-commercial, with credit given
# - - Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)

class Window_ItemList < Window_Selectable
  def col_max
    (self.width - standard_padding) / 42
  end
  def page_row_max
    7
  end
  def item_height
    36
  end
  def item_width
    36
  end
  def contents_height
    [super - super % item_height, row_max * (item_height + spacing)].max
  end
  def spacing
    6
  end
  def top_row
    oy / (item_height + spacing)
  end
  def top_row=(row)
    row = 0 if row < 0
    row = row_max - 1 if row > row_max - 1
    self.oy = row * (item_height + spacing)
  end
  def item_rect(index)
    rect = Rect.new
    rect.width = item_width
    rect.height = item_height
    rect.x = index % col_max * (item_width + spacing) + spacing
    rect.y = index / col_max * (item_height + spacing) + spacing
    rect
  end
  def draw_item(index)
    item = @data[index]
    if item
      rect = item_rect(index)
      rect.width -= 4
      rect.x += 2
      big_rect = Rect.new(rect.x-1,rect.y-1,rect.width+2,rect.height+2)
      contents.fill_rect(big_rect, Color.new(0,0,0,255))
      contents.fill_rect(rect, Color.new(0,0,0,100))
      draw_icon(item.icon_index, rect.x+6, rect.y+6)
      contents.font.size = 12
      number = $game_party.item_number(item)
      if number > 1
        draw_text(rect.x + 20, rect.y + 28, 24, contents.font.size, "x" + number.to_s)
      end
    end
  end
end[/pre]

梦石
0
星屑
9716
在线时间
2775 小时
注册时间
2008-9-5
回帖
3458

开拓者短篇八RM组冠军短篇九导演组亚军白银编剧

发表于 2020-9-11 13:06:18 | 显示全部楼层
本帖最后由 cinderelmini 于 2020-9-11 14:33 编辑

啊……这还是有点年头的产物了……我看看先……


检查了一遍,大概找到问题是什么原因导致的了,
因为这个图标物品列表脚本里,给每一行都加上了原本作为横向排列的间距参数spacing,
但是这个方法过于暴力,改变了很多作为计算用的数值,而且原本很多是动态计算出来的数值都被设置为固定数字了,于是导致了滚动条的计算出现问题。

我不是很建议让这两个脚本放在一起使用,可以换用另一个来自外网“atelier-rgss”的滚动条脚本:
MOG - Scroll Bar (V1.2)
  1. #==============================================================================
  2. # +++ MOG - Scroll Bar (V1.2) +++
  3. #==============================================================================
  4. # By Moghunter
  5. # http://www.atelier-rgss.com
  6. #==============================================================================
  7. # Adiciona uma barra de rolamento nas janelas quando a lista de itens é maior
  8. # que a altura da janela.
  9. #==============================================================================
  10. # Histórico.
  11. #==============================================================================
  12. # 1.2 - Melhoria de compatibilidade.
  13. #==============================================================================
  14. module MOG_SCROLL_BAR
  15.    #Definição da posição da barra de deslize.
  16.    SCROLL_BAR_POSITION = [-6,8]
  17.    #Definição da posição Z.
  18.    SCROLL_BAR_Z = 100
  19.    #Definição da cor na imagem baseado no Windowskin.
  20.    SCROLL_BAR_COLOR = [72,96]
  21.    SCROLL_BACKGROUND_COLOR = [64,96]   
  22. end

  23. $imported = {} if $imported.nil?
  24. $imported[:mog_scroll_bar] = true

  25. #==============================================================================
  26. # ■ Window Selectable
  27. #==============================================================================
  28. class Window_Selectable < Window_Base
  29.   
  30.   include MOG_SCROLL_BAR
  31.   
  32.   #--------------------------------------------------------------------------
  33.   # * Create Scroll Bar
  34.   #--------------------------------------------------------------------------
  35.   def create_scroll_bar
  36.       @scroll_bitmap = true
  37.       return if row_max < 1
  38.       @sc_active = self.active ; @sb_sprite = []; @sb_sprite_px = 0
  39.       2.times do |i| @sb_sprite[i] = Sprite.new; @sb_sprite[i].opacity = 0
  40.       @sb_sprite[i].bitmap = Bitmap.new(4,self.height - 16) end
  41.       refresh_scroll_bar ; update_scroll_bar
  42.   end
  43.   
  44.   #--------------------------------------------------------------------------
  45.   # * Refresh Scroll Bar
  46.   #--------------------------------------------------------------------------
  47.   def refresh_scroll_bar
  48.       return if @sb_sprite == nil
  49.       @sc_active = self.active
  50.       refresh_scroll_point ; refresh_scroll_background
  51.   end
  52.   
  53.   #--------------------------------------------------------------------------
  54.   # * Refresh Scroll Point
  55.   #--------------------------------------------------------------------------
  56.   def refresh_scroll_point
  57.       @sb_sprite[1].bitmap.clear
  58.       row_max_sc = row_max  > 20 ? 20 : row_max
  59.       @sb_row_zize = @sb_sprite[1].bitmap.height / row_max_sc + 1
  60.       @row_range_y = @sb_sprite[1].bitmap.height.to_f / row_max
  61.       @sb_row_max = self.y + self.height + 8  - (@sb_row_zize + 16)      
  62.       sc_rect = Rect.new(SCROLL_BAR_COLOR[0],SCROLL_BAR_COLOR[1],4,8)
  63.       sc_rect2 = Rect.new(0,0,6,@sb_row_zize)
  64.       @sb_sprite[1].bitmap.stretch_blt(sc_rect2, self.windowskin, sc_rect)   
  65.       @sb_sprite[1].z = self.z + SCROLL_BAR_Z + 1; @sb_sprite[1].opacity = 0
  66.       @sb_sprite[1].visible = can_scroll_bar_visible?
  67.   end
  68.   
  69.   #--------------------------------------------------------------------------
  70.   # * Refresh Scroll Background
  71.   #--------------------------------------------------------------------------
  72.   def refresh_scroll_background
  73.       @sb_sprite[0].bitmap.clear
  74.       @sb_sprite_px = self.width - (-SCROLL_BAR_POSITION[0] + @sb_sprite[0].bitmap.width)      
  75.       sc_rect = Rect.new(SCROLL_BACKGROUND_COLOR[0],SCROLL_BACKGROUND_COLOR[1],6,8)
  76.       sc_rect2 = Rect.new(0,0,6,@sb_sprite[0].bitmap.height)
  77.       @sb_sprite[0].bitmap.stretch_blt(sc_rect2, self.windowskin, sc_rect)   
  78.       @sb_sprite[0].z = self.z + SCROLL_BAR_Z; @sb_sprite[0].opacity = 0
  79.       @sb_sprite[0].visible = can_scroll_bar_visible?
  80.   end
  81.   
  82.   #--------------------------------------------------------------------------
  83.   # * Can Scroll Bar Visible
  84.   #--------------------------------------------------------------------------
  85.   def can_scroll_bar_visible?
  86.       return false if row_max <= page_row_max
  87.       return true
  88.   end  
  89.   
  90.   #--------------------------------------------------------------------------
  91.   # * Dispose
  92.   #--------------------------------------------------------------------------
  93.   alias mog_sc_dispose dispose
  94.   def dispose
  95.       mog_sc_dispose
  96.       dispose_scroll_bar
  97.   end
  98.   
  99.   #--------------------------------------------------------------------------
  100.   # * Dispose Scroll Bar
  101.   #--------------------------------------------------------------------------
  102.   def dispose_scroll_bar
  103.       return if @sb_sprite == nil
  104.       @sb_sprite.each {|sprite| sprite.bitmap.dispose ; sprite.dispose }
  105.   end
  106.   
  107.   #--------------------------------------------------------------------------
  108.   # * Update
  109.   #--------------------------------------------------------------------------
  110.   alias mog_sc_update update
  111.   def update
  112.       mog_sc_update
  113.       update_scroll_bar
  114.   end
  115.   
  116.   #--------------------------------------------------------------------------
  117.   # * Update Scroll Bar
  118.   #--------------------------------------------------------------------------
  119.   def update_scroll_bar
  120.       create_scroll_bar if @scroll_bitmap == nil
  121.       return if @sb_sprite == nil            
  122.       refresh_scroll_bar if @sc_active != self.active
  123.       @sb_sprite[0].y = self.y + 8; @sb_sprite[1].y = scroll_bar_y
  124.       @sb_sprite[1].y = @sb_row_max if @sb_sprite[1].y  > @sb_row_max
  125.       @sb_sprite.each {|sprite| sprite.x = self.x + @sb_sprite_px; update_sc_visible(sprite)}
  126.   end

  127.   #--------------------------------------------------------------------------
  128.   # * Update SC Visible
  129.   #--------------------------------------------------------------------------
  130.   def update_sc_visible(sprite)
  131.       if self.active
  132.          sprite.opacity += 15 ; sprite.opacity = 0 if !self.visible
  133.       else
  134.          sprite.opacity -= 30
  135.       end
  136.   end
  137.   
  138.   #--------------------------------------------------------------------------
  139.   # * Scroll Bar Y
  140.   #--------------------------------------------------------------------------
  141.   def scroll_bar_y
  142.       self.y + SCROLL_BAR_POSITION[1] + (@row_range_y * row)
  143.   end
  144.   
  145. end
复制代码

他这个计算机制和动态方式都不一样,但是兼容性非常好。


另外,我这提供一个与自己那个脚本兼容的解决方法思路:
如果要在行之间增加间距,不建议直接暴力在各项参数里加spacing,那样会改动非常多地方。
item_height方法本来就是使用line_height,那么不要动它,直接改line_height,
把spacing加到line_height上,但是这样一来可能draw_item和update_cursor等地方里使用到的item_rect的高度会比预期的高出一段spacing,
那么只需要仿照item_rect_for_text另外设置一个rect方法,读取item_rect并将高度减去spacing用到对应的地方去就可以了
(注:不是替换所有的item_rect,仅作为增加行距的话,仅需要替换draw_item和update_cursor两处)
附上粗略修改的版本
  1. #简单图标物品栏 v1.0
  2. #----------#
  3. #特点: 看, 是图标! 而不是列表!
  4. #
  5. #使用方法:    即插即用.
  6. #
  7. #----------#
  8. #-- Script by: V.M of D.T
  9. #
  10. #- Questions or comments can be:
  11. #    given by email: sumptuaryspade@live.ca
  12. #    provided on facebook: [url]http://www.facebook.com/DaimoniousTailsGames[/url]
  13. #   All my other scripts and projects can be found here: [url]http://daimonioustails.weebly.com/[/url]
  14. #
  15. #--- Free to use in any project, commercial or non-commercial, with credit given
  16. # - - Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)

  17. class Window_ItemList < Window_Selectable
  18.   def col_max
  19. #~     (self.width - standard_padding) / 42
  20.     (self.width - standard_padding) / line_height
  21.   end
  22. #~   def page_row_max
  23. #~     7
  24. #~   end
  25.   def line_height
  26.     return 36 + spacing
  27.   end
  28. #~   def item_height
  29. #~     36
  30. #~   end
  31.   def item_width
  32.     36
  33.   end
  34. #~   def contents_height
  35. #~     [super - super % item_height, row_max * (item_height + spacing)].max
  36. #~   end
  37.   def spacing
  38.     6
  39.   end
  40. #~   def top_row
  41. #~     oy / (item_height + spacing)
  42. #~   end
  43. #~   def top_row=(row)
  44. #~     row = 0 if row < 0
  45. #~     row = row_max - 1 if row > row_max - 1
  46. #~     self.oy = row * (item_height + spacing)
  47. #~   end
  48. #~   def item_rect(index)
  49. #~     rect = Rect.new
  50. #~     rect.width = item_width
  51. #~     rect.height = item_height
  52. #~     rect.x = index % col_max * (item_width + spacing) + spacing
  53. #~     rect.y = index / col_max * (item_height + spacing) + spacing
  54. #~     rect
  55. #~   end
  56.   def item_rect_for_grid(index)
  57.     rect = item_rect(index)
  58.     rect.height -= spacing
  59.     return rect
  60.   end
  61.   def draw_item(index)
  62.     item = @data[index]
  63.     if item
  64. #~       rect = item_rect(index)
  65.       rect = item_rect_for_grid(index)
  66.       rect.width -= 4
  67.       rect.x += 2
  68.       big_rect = Rect.new(rect.x-1,rect.y-1,rect.width+2,rect.height+2)
  69.       contents.fill_rect(big_rect, Color.new(0,0,0,255))
  70.       contents.fill_rect(rect, Color.new(0,0,0,100))
  71.       draw_icon(item.icon_index, rect.x+6, rect.y+6)
  72.       contents.font.size = 12
  73.       number = $game_party.item_number(item)
  74.       if number > 1
  75.         draw_text(rect.x + 20, rect.y + 28, 24, contents.font.size, "x" + number.to_s)
  76.       end
  77.     end
  78.   end
  79.   
  80.   def update_cursor
  81.     if @cursor_all
  82.       cursor_rect.set(0, 0, contents.width, row_max * item_height)
  83.       self.top_row = 0
  84.     elsif @index < 0
  85.       cursor_rect.empty
  86.     else
  87.       ensure_cursor_visible
  88. #~       cursor_rect.set(item_rect(@index))
  89.       cursor_rect.set(item_rect_for_grid(@index))
  90.     end
  91.   end

  92. end
复制代码

PS:这样粗略修改之后其实还有一点点高度上的误差,可能我还有什么地方没计算好吧(X

点评

已更新~请查收~  发表于 2020-9-11 13:49
忘了说,那个物品列表当时有999(测试效果)种不同的物品  发表于 2020-9-11 13:20

评分

参与人数 1赞 +1 收起 理由
alexncf125 + 1 麻烦您了

查看全部评分

回复

使用道具 举报

梦石
0
星屑
29901
在线时间
5734 小时
注册时间
2016-3-8
回帖
1653
 楼主| 发表于 2020-9-11 15:03:42 | 显示全部楼层
cinderelmini 发表于 2020-9-11 13:06
啊……这还是有点年头的产物了……我看看先……


检查了一遍,大概找到问题是什么原 ...

按大大的脚本改了后, 很多東西的位置和宽高都不同了
我想我转用MOG好了, 不过还是大大的滚动条最美观

点评

呃,可能你是把line_height和item_leight分开使用了吧,单纯这个脚本的话我这边这样改之后没什么排版问题。如果改动太多的话用mog确实会比较方便233  发表于 2020-9-11 16:32
回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部