Project1
标题:
物品自动排列系统
[打印本页]
作者:
tommay
时间:
2009-4-12 08:05
-屏蔽-
作者:
destinyNX
时间:
2009-4-12 08:17
提示:
作者被禁止或删除 内容自动屏蔽
作者:
紫苏
时间:
2009-4-12 13:36
能做出 #2 的话就肯定能做出 #1 了~
我想问下你具体想要如何排序呢?按价钱?拼音首字母?还是不同的标准针对不同的物品类型(比如物品按可使用、不可使用排,武器按攻击力排)?
#3 很简单,直接在 draw_text 的时候居中就行了,等你答复了我一起发上来吧
作者:
destinyNX
时间:
2009-4-12 20:13
提示:
作者被禁止或删除 内容自动屏蔽
作者:
紫苏
时间:
2009-4-13 13:20
自动排序,现在加了按 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
复制代码
效果图:
[LINE]1,#dddddd[/LINE]
系统信息:本贴由本区版主认可为正确答案,66RPG感谢您的热情解答~
作者:
hitlerson
时间:
2009-4-13 16:39
Window_Item的第57行加
@data.sort!{|a,b| a.name < b.name ? 1 : -1}
这样是按照名字排序,要ID排序就a.id,b.id,别的都自己改了
貌似这个问题我刚提过
作者:
destinyNX
时间:
2009-6-12 08:00
提示:
作者被禁止或删除 内容自动屏蔽
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1