RMRK is retiring.
Server is paid up for the rest of 2026, but the forum may go after that. See here for more information. Please archive or save anything you would like to keep before 2027.
Main Menu
  • Welcome to The RPG Maker Resource Kit.

[VX]Moving zifee's Spin Command to Actor's sprite

Started by EmperorAlan, April 28, 2013, 08:37:48 AM

0 Members and 1 Guest are viewing this topic.

EmperorAlan

So, after messing up a little with the spin command, I managed to make a compabilty with my HUD script. Problem is, the position is kinda off so can somebody please edit it so instead appering at lower-right of screen, it will be circling around the selected actor?

PS: If possible I also wanted to skip the Fight and Escape command, and goes to the fighting command first. Here's the script if someone have trouble to find it.


=begin ========================================================================
* ziifee's Spin Command for RPG Tankentai Sideview Battle System
  By ziifee ( http://neomemo.web.fc2.com/ )
   <SBS Only>
   ?-This script is only for the Tankentai SBS WITHOUT the ATB installed.
   <Image Required>
     Spin40 : Spin40.png is required in the Graphics/System folder.
=end # ========================================================================

#==============================================================================
# ? Ziifee
#==============================================================================

module Zii 
  # ? Spin Command/Icon Index Number
  FIGHT = 132                               # Fight
  ESCAPE = 143                              # Escape
  ATTACK = 1                                # Attack (Default)
  GUARD = 3040                                # Guard
  SKILL = 159                               # Skill
  ITEM = 144                                # Item

  # ? Spin Command/Direction of Rotation ( "normal" or "reverse" )
  #   Determines how Spin Command rotates according to left/right key press.
  TURN = "reverse"
 
  # ? Face Graphics (true: Use battle face graphic / false: don't use faces)
  STATUS_FACE = true
 
  # ? Actor Names (true: Show actor names / false: Don't show )
  STATUS_LINE = true
 
  # ? Actor Name Text Size ( VX default size: 20 )
  LINE_SIZE = 14
 
  #--------------------------------------------------------------------------
  # ? ???? ???
  #--------------------------------------------------------------------------
  def self.turn_normal?
    return false if TURN == "reverse"
    return true  if TURN == "normal"
    return true
  end
# ? ???????

  #--------------------------------------------------------------------------
  # ? ???????
  #--------------------------------------------------------------------------
  def update_cursor
    if @index < 0                   # ??????? 0 ?????
      self.cursor_rect.empty        # ??????????
    else                            # ??????? 0 ?????
      rect = Rect.new(index * 96, 0, 96, 96)
      self.cursor_rect = rect       # ??????????
    end
  end
end

# ? ??????
#==============================================================================
# ? Window_SpinCommand
#------------------------------------------------------------------------------
# ?????????????????????
#==============================================================================

class Window_SpinCommand < Window_Base
  #--------------------------------------------------------------------------
  # ? ??????????
  #--------------------------------------------------------------------------
  attr_reader   :index                    # ??????
  attr_reader   :help_window              # ????????
  #--------------------------------------------------------------------------
  # ? ?????????
  #     cx / cy  : ??? X?? / Y??
  #     commands : ?????? (?? ? [name, kind, pull, enabled?])
  #     setting  : ?????? ("R"=>?? "S"=>?? "G"=>?? "L"=>??)
  #--------------------------------------------------------------------------
  def initialize(cx, cy, commands, setting = {})
    @radius    = setting.has_key?("R") ? setting["R"] : 40  # ????
    @speed     = setting.has_key?("S") ? setting["S"] : 36  # ????
    @spin_back = setting.has_key?("G") ? setting["G"] : ""  # ????
    @spin_line = setting.has_key?("L") ? setting["L"] : nil # ????
    x, y = cx - @radius - 28, cy - @radius - 28
    width = height = @radius * 2 + 56
    super(x, y, width, height)
    self.opacity = 0
    @index = 0
    @commands = commands                                    # ????
    @spin_right = true
    @spin_count = 0
    update_cursor
  end
  #--------------------------------------------------------------------------
  # ? ?????????? (???? ???)
  #     i  : ??????
  #     cx : ?? ???? X??
  #     cy : ?? ???? Y??
  #--------------------------------------------------------------------------
  def draw_spin_graphic(i, cx, cy)
    case command_kind(i)
    when "icon"
      draw_icon(command_pull(i), cx - 12, cy - 12, command_enabled?(i))
    end
  end
  #--------------------------------------------------------------------------
  # ? ?????? ?????
  #--------------------------------------------------------------------------
  def refresh
    set_spin
  end
  #--------------------------------------------------------------------------
  # ? ????? ?????
  #--------------------------------------------------------------------------
  def draw_item(index, enabled = true)
    @commands[index][3] = enabled
    set_spin
  end
  #--------------------------------------------------------------------------
  # ? ?????????????
  #--------------------------------------------------------------------------
  def command_name(index = @index)
    return "" if index < 0
    name = @commands[index][0]
    return name != nil ? name : ""
  end
  #--------------------------------------------------------------------------
  # ? ??????????
  #--------------------------------------------------------------------------
  def command_kind(index)
    result = @commands[index][1]
    return result != nil ? result : ""
  end
  #--------------------------------------------------------------------------
  # ? ??????? ???
  #--------------------------------------------------------------------------
  def command_pull(index)
    result = @commands[index][2]
    return result != nil ? result : ""
  end
  #--------------------------------------------------------------------------
  # ? ?????????????
  #--------------------------------------------------------------------------
  def command_enabled?(index)
    result = @commands[index][3]
    return result != nil ? result : true
  end
  #--------------------------------------------------------------------------
  # ? ?????? index ?????
  #--------------------------------------------------------------------------
  def set_index(name)
    n = -1
    for i in 0...@commands.size
      n = i if @commands[i][0] == name
    end
    @index = n if n >= 0
    update_cursor
    call_update_help
    set_spin
  end
  #--------------------------------------------------------------------------
  # ? ?????????
  #     index : ?????????
  #--------------------------------------------------------------------------
  def index=(index)
    @index = index
    update_cursor
    call_update_help
    set_spin
  end
  #--------------------------------------------------------------------------
  # ? ???X?????
  #--------------------------------------------------------------------------
  def center_x
    return contents.width / 2
  end
  #--------------------------------------------------------------------------
  # ? ???Y?????
  #--------------------------------------------------------------------------
  def center_y
    return contents.height / 2
  end
  #--------------------------------------------------------------------------
  # ? ??????
  #--------------------------------------------------------------------------
  def item_max
    return @commands.size
  end
  #--------------------------------------------------------------------------
  # ? ????? (??? ??)
  #--------------------------------------------------------------------------
  def set_background
    return if @spin_back == ""
    bitmap = Cache.system(@spin_back)
    rect = Rect.new(0, 0, bitmap.width, bitmap.height)
    self.contents.blt(12, 12, bitmap, rect)
  end
  #--------------------------------------------------------------------------
  # ? ????? (??? ??)
  #--------------------------------------------------------------------------
  def set_text
    return if @spin_line == nil
    y = center_y - WLH / 2 + @spin_line
    self.contents.draw_text(center_x - 48, y, 96, WLH, command_name, 1)
  end
  #--------------------------------------------------------------------------
  # ? ?????????????????
  #--------------------------------------------------------------------------
  def angle_size
    return (Math::PI * 2 / item_max)
  end
  #--------------------------------------------------------------------------
  # ? ??????????????? ?????
  #--------------------------------------------------------------------------
  def set_spin_count
    @spin_count = angle_size * 360 / @speed
    set_spin(true)
  end
  #--------------------------------------------------------------------------
  # ? ????? ???
  #     spin : ????? (true ?????)
  #--------------------------------------------------------------------------
  def set_spin(spin = false)
    self.contents.clear
    set_background
    angle = spin ? @speed * @spin_count / 360 : 0
    angle = @spin_right ? angle : -angle
    for i in 0...item_max
      n = (i - @index) * angle_size + angle
      cx = @radius * Math.sin(n) + center_x
      cy = - @radius * Math.cos(n) + center_y
      draw_spin_graphic(i, cx, cy)
    end
    set_text
  end
  #--------------------------------------------------------------------------
  # ? ??????
  #--------------------------------------------------------------------------
  def update
    super
    update_cursor
    if @spin_count > 0
      @spin_count -= 1
      set_spin(@spin_count >= 1)
      return
    end
    update_command
  end
  #--------------------------------------------------------------------------
  # ? ???????????
  #--------------------------------------------------------------------------
  def command_movable?
    return false if @spin_count > 0
    return false if (not visible or not active)
    return false if (index < 0 or index > item_max or item_max == 0)
    return false if (@opening or @closing)
    return true
  end
  #--------------------------------------------------------------------------
  # ? ?????????
  #--------------------------------------------------------------------------
  def command_right
    @index = (@index + 1) % item_max
    @spin_right = true
    set_spin_count
  end
  #--------------------------------------------------------------------------
  # ? ?????????
  #--------------------------------------------------------------------------
  def command_left
    @index = (@index - 1 + item_max) % item_max
    @spin_right = false
    set_spin_count
  end
  #--------------------------------------------------------------------------
  # ? ?????????
  #--------------------------------------------------------------------------
  def update_command
    if command_movable?
      if Input.press?(Input::RIGHT)
        Sound.play_cursor
        Zii.turn_normal? ? command_right : command_left
      end
      if Input.press?(Input::LEFT)
        Sound.play_cursor
        Zii.turn_normal? ? command_left : command_right
      end
    end
    call_update_help
  end
  #--------------------------------------------------------------------------
  # ? ???????
  #--------------------------------------------------------------------------
  def update_cursor
    if @index < 0
      self.cursor_rect.empty
    else
      rect = Rect.new(0, 0, 24, 24)
      rect.x = center_x - rect.width / 2
      rect.y = center_y - rect.height / 2 - @radius
      self.cursor_rect = rect
    end
  end
  #--------------------------------------------------------------------------
  # ? ???????????
  #     help_window : ???????????
  #--------------------------------------------------------------------------
  def help_window=(help_window)
    @help_window = help_window
    call_update_help
  end
  #--------------------------------------------------------------------------
  # ? ???????????????????
  #--------------------------------------------------------------------------
  def call_update_help
    if self.active and @help_window != nil
       update_help
    end
  end
  #--------------------------------------------------------------------------
  # ? ??????????? (???????????)
  #--------------------------------------------------------------------------
  def update_help
  end
end

#==============================================================================
# ? Window_PartyCommand
#==============================================================================

class Window_PartyCommand < Window_SpinCommand
  #--------------------------------------------------------------------------
  # ? ?????????
  #--------------------------------------------------------------------------
  def initialize
    s1 = [Vocab::fight,  "icon", Zii::FIGHT,  true]
    s2 = [Vocab::escape, "icon", Zii::ESCAPE, $game_troop.can_escape]
    setting = {"R"=>40, "S"=>52, "G"=>"Spin40", "L"=>-12}
    super(56, 64, [s1, s2], setting)
    self.active = false
    set_spin
  end
end

#==============================================================================
# ? Window_ActorCommand
#==============================================================================

class Window_ActorCommand < Window_SpinCommand
  #--------------------------------------------------------------------------
  # ? ?????????
  #--------------------------------------------------------------------------
  def initialize
    s1 = [Vocab::attack, "icon", Zii::ATTACK, true]
    s2 = [Vocab::skill,  "icon", Zii::SKILL,  true]
    s3 = [Vocab::guard,  "icon", Zii::GUARD,  true]
    s4 = [Vocab::item,   "icon", Zii::ITEM,   true]
    setting = {"R"=>40, "S"=>52, "G"=>"Spin40", "L"=>-12}
    super(0, 64, [s1, s2, s3, s4], setting)
    self.active = false
    set_spin
  end
  #--------------------------------------------------------------------------
  # ? ??????
  #     actor : ????
  #--------------------------------------------------------------------------
  def setup(actor)
    @commands[0][2] = Zii::ATTACK
    @commands[1][0] = Vocab::skill
    if actor.weapons[0] != nil
      n = actor.weapons[0].icon_index
      @commands[0][2] = n if n > 0
    end
    @commands[1][0] = actor.class.skill_name if actor.class.skill_name_valid
    self.index = 0
    set_spin
  end
end


Thank you.