赞 | 2 |
VIP | 143 |
好人卡 | 1 |
积分 | 1 |
经验 | 216792 |
最后登录 | 2019-10-10 |
在线时间 | 24 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 61
- 在线时间
- 24 小时
- 注册时间
- 2008-8-5
- 帖子
- 1924
|
自动排序,现在加了按 ID、名称和价格三种排序方式
进入物品列表按 F5 就能看到效果了~
下面是脚本,插到物品分类系统的下面
- #==============================================================================
- # 本脚本来自www.66RPG.com,使用和转载请保留此信息
- #==============================================================================
- # 复杂物品分类作者:柳柳
- #
- # 修改 by 紫苏
- # 新增内容:
- # 自动排序物品(按ID、名称或价格)
- #==============================================================================
- #==============================================================================
- # ■ 排序算法
- #==============================================================================
- def insertionSortA(arr, offset = 0, len = arr.length)
- for i in offset + 1...len
- j, temp = i - 1, arr[i]
- while j >= offset && (arr[j] <=> temp) > 0
- arr[j + 1] = arr[j]
- j -= 1
- end
- arr[j + 1] = temp
- end
- end
- def insertionSortD(arr, offset = 0, len = arr.length)
- for i in offset + 1...len
- j, temp = i - 1, arr[i]
- while j >= offset && (arr[j] <=> temp) < 0
- arr[j + 1] = arr[j]
- j -= 1
- end
- arr[j + 1] = temp
- end
- end
- def quickSortA(arr, left = 0, right = arr.length - 1)
- return if left >= right
- if right - left < 10
- insertionSortA(arr, left, right + 1)
- return
- end
-
- pivot, i, j = arr[left], left, right
- while i < j
- while i < j && (arr[j] <=> pivot) >= 0
- j -= 1
- end
- if i < j
- arr[i] = arr[j]
- i += 1
- end
- while i < j && (arr[i] <=> pivot) <= 0
- i += 1
- end
- if i < j
- arr[j] = arr[i]
- j -= 1
- end
- end
- arr[i] = pivot
- quickSortA(arr, left, i - 1)
- quickSortA(arr, i + 1, right)
- end
- def quickSortD(arr, left = 0, right = arr.length - 1)
- return if left >= right
- if right - left < 10
- insertionSortD(arr, left, right + 1)
- return
- end
-
- pivot, i, j = arr[left], left, right
- while i < j
- while i < j && (arr[j] <=> pivot) <= 0
- j -= 1
- end
- if i < j
- arr[i] = arr[j]
- i += 1
- end
- while i < j && (arr[i] <=> pivot) >= 0
- i += 1
- end
- if i < j
- arr[j] = arr[i]
- j -= 1
- end
- end
- arr[i] = pivot
- quickSortD(arr, left, i - 1)
- quickSortD(arr, i + 1, right)
- end
- #==============================================================================
- # ■ module RPG
- #------------------------------------------------------------------------------
- # 追加物品之间的比较方式。
- # sort_mode : 排序方式(0 = ID, 1 = 名称, 2 = 价格)
- #==============================================================================
- $sort_mode = 0 if $sort_mode == nil
- $descending = 0 if $descending == nil
- module RPG
- class Item
- def <=>(item)
- return case $sort_mode
- when 0
- self.id <=> item.id
- when 1
- self.name <=> item.name
- when 2
- self.price <=> item.price
- end
- end
- end
- class Weapon
- def <=>(wep)
- return case $sort_mode
- when 0
- self.id <=> wep.id
- when 1
- self.name <=> wep.name
- when 2
- self.price <=> wep.price
- end
- end
- end
- class Armor
- def <=>(armor)
- return case $sort_mode
- when 0
- self.id <=> armor.id
- when 1
- self.name <=> armor.name
- when 2
- self.price <=> armor.price
- end
- end
- end
- end
- #==============================================================================
- # ■ Harts_Window_ItemTitle
- #------------------------------------------------------------------------------
- # 显示排序选项的窗口。
- # 基于原脚本的修改:让左手边分类选项栏文字居中。
- #==============================================================================
- class Harts_Window_ItemCommand < Window_Selectable
- def draw_item(index, color)
- self.contents.font.color = color
- y = index * 32
- self.contents.draw_text(4, y, self.contents.width - 8, 32,
- @commands[index], 1)
- end
- end
- #==============================================================================
- # ■ Harts_Window_ItemTitle
- #------------------------------------------------------------------------------
- # 显示分类物品列表的窗口。
- # 基于原脚本的修改:排序。
- #==============================================================================
- class Harts_Window_ItemList < Window_Selectable
- @ascending = 0
- def set_item(command, sort_mode = -1)
- refresh
- for i in 1...$data_items.size
- if $game_party.item_number(i) > 0 and $data_items[i].desc == command
- @data.push($data_items[i])
- end
- end
- for i in 1...$data_weapons.size
- if $game_party.weapon_number(i) > 0 and $data_weapons[i].desc == command
- @data.push($data_weapons[i])
- end
- end
- for i in 1...$data_armors.size
- if $game_party.armor_number(i) > 0 and $data_armors[i].desc == command
- @data.push($data_armors[i])
- end
- end
- if sort_mode >= 0
- if $sort_mode == sort_mode
- $descending ^= 1
- else
- $sort_mode = sort_mode
- end
- end
- $descending == 0 ? quickSortA(@data) : quickSortD(@data)
- @item_max = @data.size
- if @item_max > 0
- self.contents = Bitmap.new(width - 32, row_max * 32)
- self.contents.clear
- for i in 0...@item_max
- draw_item(i)
- end
- end
- end
- end
- #==============================================================================
- # ■ Window_SortCommand
- #------------------------------------------------------------------------------
- # 显示排序选项的窗口。
- #==============================================================================
- class Window_SortCommand < Window_Command
- def draw_item(index, color)
- self.contents.font.color = color
- rect = Rect.new(4, 32 * index, self.contents.width - 8, 32)
- self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
- self.contents.draw_text(rect, @commands[index], 1)
- end
- end
- class Scene_Item
- alias :main_original :main unless method_defined? :main_original
- def main
- @sort_window = Window_SortCommand.new(224, ["按物品 ID 排序", "按名称排序",
- "按价格排序"])
- @sort_window.visible = false
- @sort_window.active = false
- @sort_window.x = (640 - @sort_window.width) >> 1
- @sort_window.y = (480 - @sort_window.height) >> 1
- @sort_window.z = 1000
- main_original
- @sort_window.dispose
- end
- alias :update_original :update unless method_defined? :update_original
- def update
- @sort_window.update
- if @sort_window.active
- update_sort
- return
- end
- update_original
- end
-
- alias :update_itemlist_original :update_itemlist unless
- method_defined? :update_itemlist_original
- def update_itemlist
- if Input.trigger?(Input::F5)
- @itemlist_window.active = false
- @sort_window.visible = true
- @sort_window.active = true
- $game_system.se_play($data_system.decision_se)
- return
- end
- update_itemlist_original
- end
- def update_sort
- if Input.trigger?(Input::B)
- $game_system.se_play($data_system.cancel_se)
- @itemlist_window.active = true
- @sort_window.active = false
- @sort_window.visible = false
- return
- end
- if Input.trigger?(Input::C)
- @itemlist_window.set_item(@itemcommand_window.commands[@command_index],
- @sort_window.index)
- $game_system.se_play($data_system.decision_se)
- @itemlist_window.active = true
- @sort_window.active = false
- @sort_window.visible = false
- return
- end
- end
- end
复制代码
效果图:
系统信息:本贴由本区版主认可为正确答案,66RPG感谢您的热情解答~ |
|