じ☆ve冰风 发表于 2026-8-3 11:03:58

Select Key Item ACE

Select Key Item ACE

by Kyonides​

Introduction

This script has only one mission: to display the Select Key Item window with style!
Please read the embedded comments to learn how to use it properly.

                Ruby:       
# * Select Key Item ACE * #
#   Scripter : Kyonides Arkanthes
#   2024-03-22

# Display your Key Items on screen with style!
# Don't forget to add some key items to your party's bag before calling
# the Select Item event command or this script might laugh at you! :O
# You might only need to configure 5 CONSTANTS, yes in ALL_CAPS.
# Yet, this script can run just like any plug & play code available out there.

class Window_KeyItem
#
MAIN_COLOR =
EDGE_COLOR =
WINDOW_WIDTH = (Graphics.width - 40) / 2
POS_Y = Graphics.height / 2 - 24
NO_ITEM_FOUND = "No key items? Really?"
def initialize(message_window)
    @message_window = message_window
    @cw = WINDOW_WIDTH - 24
    super(WINDOW_WIDTH / 2, 0, WINDOW_WIDTH, 72)
    self.openness = 0
    create_back_bitmap
    create_back_sprite
    self.back_opacity = 0
    self.opacity = 0
    deactivate
    set_handler(:ok,   method(:on_ok))
    set_handler(:cancel, method(:on_cancel))
end

def create_back_bitmap
    @back_bitmap = Bitmap.new(@cw, 28)
    rect1 = Rect.new(0, 0, width, 12)
    rect2 = Rect.new(0, 12, width, height - 24)
    rect3 = Rect.new(0, height - 12, width, 12)
    @back_bitmap.gradient_fill_rect(rect1, back_color2, back_color1, true)
    @back_bitmap.fill_rect(rect2, back_color1)
    @back_bitmap.gradient_fill_rect(rect3, back_color1, back_color2, true)
end

def create_back_sprite
    @back_sprite = Sprite.new
    @back_sprite.bitmap = @back_bitmap
    @back_sprite.visible = false
    @back_sprite.x = self.x + 12
    @back_sprite.z = self.z - 1
end

def back_color1
    Color.new(*MAIN_COLOR)
end

def back_color2
    Color.new(*EDGE_COLOR)
end

def start
    self.category = :key_item
    update_placement
    select(0)
    open
    @back_sprite.visible = true
    activate
end

def make_item_list
    @data = $game_party.all_items.select {|item| include?(item) }
    @icon_ox = @cw / 2 - item_max * 14
end

def update_placement
    self.y = POS_Y
    @back_sprite.y = self.y + 34
end

def select(new_index)
    self.index = new_index
    draw_this_item
end

def item_max
    @data.size
end

def create_contents
    contents.dispose
    self.contents = Bitmap.new(@cw, 48)
end

def draw_this_item
    contents.clear_rect(0, 24, @cw, 24)
    item = @data[@index]
    item ? draw_item_found(item) : draw_no_item
end

def draw_item_found(item)
    rect = Rect.new(0, 24, @cw - 4, 24)
    draw_item_name(item)
    draw_item_number(rect, item)
end

def draw_item(n)
    icon_pos = @data.icon_index
    draw_icon(icon_pos, @icon_ox + n * 28, 0, true)
end

def draw_item_name(item)
    change_color(normal_color, true)
    draw_text(4, 24, @cw - 32, line_height, item.name)
end

def draw_item_number(rect, item)
    draw_text(rect, sprintf(":%2d", $game_party.item_number(item)), 2)
end

def draw_no_item
    draw_text(4, 24, @cw - 32, line_height, NO_ITEM_FOUND)
end

def hide_backdrop
    @back_sprite.visible = false
end

def this_rect
    Rect.new(@icon_ox + @index * 28, 0, 24, 24)
end

def update_cursor
    if @index < 0
      cursor_rect.empty
      return
    end
    cursor_rect.set(this_rect)
end

def process_ok
    if current_item_enabled?
      Sound.play_ok
      Input.update
      call_ok_handler
    else
      Sound.play_buzzer
      call_cancel_handler
    end
    deactivate
end

def dispose
    super
    @back_bitmap.dispose
    @back_sprite.dispose
end
end

class Window_Message
def input_item
    @item_window.start
    Fiber.yield while @item_window.active
    @item_window.hide_backdrop
end
end


Screenshots

Spoiler: 2 Snapshots






Terms & Conditions

Free for ANY game.
Due credit is mandatory.
Mention this forum in your game credits.
That's it!
data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7


本贴来自国际rpgmaker官方论坛作者:kyonides处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/select-key-item-ace.167060/
页: [1]
查看完整版本: Select Key Item ACE