How to change the position of a command

kamekache

Villager
Member
Joined
Jan 29, 2016
Messages
10
Reaction score
3
First Language
Spanish
Primarily Uses
Hi, I need to know if exist a posibility of change the position of commands. I creating a scene that have gems, and when you find the gem item in the game, this appear in the scene. But when I create the command window, this is create in the default way.


So I need to change the position of each command to make the selected command position be each gem, like this:


Anyone can help me? Thanks.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,141
Reaction score
12,416
First Language
English
Primarily Uses
RMMV
A command window can be created with one or more columns, but it's always in a grid pattern. To get them to follow a circular pattern, you'd need to modify the scripts.

However, it appears you're already modifying scripts to get as far as you have. Maybe if you show us what you've already done, we can help with position tweaking.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
21,852
Reaction score
11,062
First Language
English
Primarily Uses
RMVXA
[move]RGSSx Script Support[/move]
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,136
Reaction score
809
First Language
Hungarian
Primarily Uses
RMVXA
The default selectable windows got this method:
Code:
  def item_rect(index)
    rect = Rect.new
    rect.width = item_width
    rect.height = item_height
    rect.x = index % col_max * (item_width + spacing)
    rect.y = index / col_max * item_height
    rect
  end
This is what you will have to change to change the position of the commands in your window.
Either use a formula for your positions (using the index argument), or make a module and set up your positions there, and load those in the above method (again, using the index argument). You can also follow the methods called in that method to see from where it gets the width and height of the commands.

Just note that messing with the positions can (and will most probably) break the scrolling feature of the windows unless you modify those methods too.
But seeing your commands (gems), you don't really need scrolling, so you should be fine.
 

kamekache

Villager
Member
Joined
Jan 29, 2016
Messages
10
Reaction score
3
First Language
Spanish
Primarily Uses
A command window can be created with one or more columns, but it's always in a grid pattern. To get them to follow a circular pattern, you'd need to modify the scripts.

However, it appears you're already modifying scripts to get as far as you have. Maybe if you show us what you've already done, we can help with position tweaking.
The script that I create is the next following:
Code:
  #--------------------------------------------------------------------------
  # * Cache
  #--------------------------------------------------------------------------
module Cache
  def self.gems_files(filename)
    load_bitmap("Graphics/System/Zodiac_Gems/", filename)
  end
end

class Window_Gems < Window_Command
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(137, 128)
    self.windowskin = Cache.gems_files("System_Window")
    refresh
  end

  #--------------------------------------------------------------------------
  # * Get Width
  #--------------------------------------------------------------------------
  def window_width
    return 270
  end
  #--------------------------------------------------------------------------
  # * Get Width
  #--------------------------------------------------------------------------
  def window_height
    return 258
  end
  #--------------------------------------------------------------------------
  # * Get Number of Lines to Show
  #--------------------------------------------------------------------------
  def visible_line_number
    4
  end
  #--------------------------------------------------------------------------
  # * Get Item Height
  #--------------------------------------------------------------------------
  def item_width
    96
  end
  #--------------------------------------------------------------------------
  # * Create Command List
  #--------------------------------------------------------------------------
  def make_command_list
    add_option_commands
  end
 
  def add_option_commands
    add_command("",   :aries)
    add_command("",  :taurus)
  end
end
#==============================================================================
# ** Scene_ZodiacGems
#------------------------------------------------------------------------------
#  This class performs the Zodiac Gems Screen Prrocessing.
#==============================================================================

class Scene_ZodiacGems < Scene_MenuBase
  #--------------------------------------------------------------------------
  # * Start Processing
  #--------------------------------------------------------------------------
  def start
    super
    create_gem_window
    create_gem_mechanism
  end
 
  def create_gem_mechanism
    @gem_window = Window_Gems.new
    @gem_window.set_handler(:aries,      method(:command_aries))
    @gem_window.set_handler(:taurus,     method(:command_taurus))
  end
 
  def command_aries
  end
 
  def command_taurus
  end

  def create_gem_window
    @nogems = Sprite.new()
    @nogems.bitmap = Cache.gems_files("System_NoGems")
    @nogems.x = 137
    @nogems.y = 128
  end
  #--------------------------------------------------------------------------
  # * Create Black Background
  #--------------------------------------------------------------------------
  def create_gems_background
    @background_sprite = Sprite.new
    @background_sprite.bitmap = Cache.gems_files("System_Background")
  end
 
  def create_background
    create_gems_background
  end
end

I hope you can help me!

And....
The default selectable windows got this method:
Code:
  def item_rect(index)
    rect = Rect.new
    rect.width = item_width
    rect.height = item_height
    rect.x = index % col_max * (item_width + spacing)
    rect.y = index / col_max * item_height
    rect
  end
This is what you will have to change to change the position of the commands in your window.
Either use a formula for your positions (using the index argument), or make a module and set up your positions there, and load those in the above method (again, using the index argument). You can also follow the methods called in that method to see from where it gets the width and height of the commands.

Just note that messing with the positions can (and will most probably) break the scrolling feature of the windows unless you modify those methods too.
But seeing your commands (gems), you don't really need scrolling, so you should be fine.
I tried to add this code in the Window_Command class, but I have a trouble when I try to assign the position to the index, I can't move of one command to another.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,141
Reaction score
12,416
First Language
English
Primarily Uses
RMMV
Don't do it in the Window_Command class - that will cause ALL menus to change. Just do it in your Window_Gems class.

What you want to do is redefine that item_rect method to change the rect.x and rect.y values according to where you want it to be drawn. There are two options here - you can either do some fancy calculations with trigonometry and radians and stuff to get your x and y values, or you could pull a screenshot into an image editing program, add a sprite that represents your command, and move it around to where you want each one to appear, making a note of the x and y values of the upper left corner, then put those values into two arrays and use them.

I would go with the second option, because that's a weak area of maths for me. But if you can handle the maths, or find someone who can do the calculations for you, go with that by all means.

So you're going to end up with something like this:
Code:
class Window_Gems < Window_Command
  def item_rect(index)
    rect = super
    rect.x = (do calculation here)
    rect.y = (do calculation here)
    rect
  end
end
or this:
Code:
class Window_Gems < Window_Command
  rect_x = [array of all x values here, for commands 0-11]
  rect_y = [array of all y values here, for commands 0-11]

  def item_rect(index)
    rect = super
    rect.x = rect_x[index]
    rect.y = rect_y[index]  
    rect
  end
end
You don't need to add the class name again - just put what's inside it into that class in your script.
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,136
Reaction score
809
First Language
Hungarian
Primarily Uses
RMVXA
The Window_Command class already got this method from it's parent class (Window_Selectable).
The method I copied here is the default method of the engine for all selectable windows.
You will have to modify that method in your own class (Window_Gems in your script), or else you will break every other selectable window in the game.

You can make something like this:
Code:
module GemWin

  Commands = {
    0 => { # Index number here - 1st command
      :rect => [10,10,30,40], # [x,y,width,height]
      :u => 0,  # Command selected when the UP button is pressed
      :d => 0,  # Command selected when the DOWN button is pressed
      :l => 11, # Command selected when the LEFT button is pressed
      :r => 1,  # Command selected when the RIGHT button is pressed
    },
    1 => { # Index number here - 2nd command
      :rect => [40,30,30,40], # [x,y,width,height]
      :u => 0,  # Command selected when the UP button is pressed
      :d => 2,  # Command selected when the DOWN button is pressed
      :l => 0,  # Command selected when the LEFT button is pressed
      :r => 2,  # Command selected when the RIGHT button is pressed
    },
    2 => { # Index number here - 3rd command
      :rect => [70,50,30,40], # [x,y,width,height]
      :u => 1,  # Command selected when the UP button is pressed
      :d => 3,  # Command selected when the DOWN button is pressed
      :l => 1,  # Command selected when the LEFT button is pressed
      :r => 3,  # Command selected when the RIGHT button is pressed
    },
    # And so on... Add more settings below if needed.
  }
 
end

class Window_Gems < Window_Command
 
  # This loads the values from the module setting based on the
  # command's index.
  def item_rect(index)
    return Rect.new(*GemWin::Commands[index][:rect])
  end
 
  def cursor_up(wrap = false)
    select(GemWin::Commands[index][:u])
  end
 
  def cursor_down(wrap = false)
    select(GemWin::Commands[index][:d])
  end
 
  def cursor_left(wrap = false)
    select(GemWin::Commands[index][:l])
  end
 
  def cursor_right(wrap = false)
    select(GemWin::Commands[index][:r])
  end
 
end

This will read the position and size of your commands from the module settings.
Also, because your commands will be aligned into a circular shape, the default cursor movement during selection is not something you should keep.
For that reason, you can also set up where the cursor will go when the specific directional button is pressed based on your module settings.

Adjust the settings how you want. Make sure to include a setting for all of your commands or else the game will crash!

Shaz's method also works, but I like to organize my settings in a clean way with names, all at one place, outside of the real code.
Putting all the settings into one giant array would make my head spin if I would I need to edit it later. :p
 

kamekache

Villager
Member
Joined
Jan 29, 2016
Messages
10
Reaction score
3
First Language
Spanish
Primarily Uses
Don't do it in the Window_Command class - that will cause ALL menus to change. Just do it in your Window_Gems class.

What you want to do is redefine that item_rect method to change the rect.x and rect.y values according to where you want it to be drawn. There are two options here - you can either do some fancy calculations with trigonometry and radians and stuff to get your x and y values, or you could pull a screenshot into an image editing program, add a sprite that represents your command, and move it around to where you want each one to appear, making a note of the x and y values of the upper left corner, then put those values into two arrays and use them.

I would go with the second option, because that's a weak area of maths for me. But if you can handle the maths, or find someone who can do the calculations for you, go with that by all means.

So you're going to end up with something like this:
Code:
class Window_Gems < Window_Command
  def item_rect(index)
    rect = super
    rect.x = (do calculation here)
    rect.y = (do calculation here)
    rect
  end
end
or this:
Code:
class Window_Gems < Window_Command
  rect_x = [array of all x values here, for commands 0-11]
  rect_y = [array of all y values here, for commands 0-11]

  def item_rect(index)
    rect = super
    rect.x = rect_x[index]
    rect.y = rect_y[index]
    rect
  end
end
You don't need to add the class name again - just put what's inside it into that class in your script.
No, I'm doing the item_rect in the Window_Gems class, not in the Window_Command class, I expressed wrong haha. Ok, I got it, but I don't understand how can I put the array of the values for each command.


The Window_Command class already got this method from it's parent class (Window_Selectable).
The method I copied here is the default method of the engine for all selectable windows.
You will have to modify that method in your own class (Window_Gems in your script), or else you will break every other selectable window in the game.

You can make something like this:
Code:
module GemWin

  Commands = {
    0 => { # Index number here - 1st command
      :rect => [10,10,30,40], # [x,y,width,height]
      :u => 0,  # Command selected when the UP button is pressed
      :d => 0,  # Command selected when the DOWN button is pressed
      :l => 11, # Command selected when the LEFT button is pressed
      :r => 1,  # Command selected when the RIGHT button is pressed
    },
    1 => { # Index number here - 2nd command
      :rect => [40,30,30,40], # [x,y,width,height]
      :u => 0,  # Command selected when the UP button is pressed
      :d => 2,  # Command selected when the DOWN button is pressed
      :l => 0,  # Command selected when the LEFT button is pressed
      :r => 2,  # Command selected when the RIGHT button is pressed
    },
    2 => { # Index number here - 3rd command
      :rect => [70,50,30,40], # [x,y,width,height]
      :u => 1,  # Command selected when the UP button is pressed
      :d => 3,  # Command selected when the DOWN button is pressed
      :l => 1,  # Command selected when the LEFT button is pressed
      :r => 3,  # Command selected when the RIGHT button is pressed
    },
    # And so on... Add more settings below if needed.
  }
 
end

class Window_Gems < Window_Command
 
  # This loads the values from the module setting based on the
  # command's index.
  def item_rect(index)
    return Rect.new(*GemWin::Commands[index][:rect])
  end
 
  def cursor_up(wrap = false)
    select(GemWin::Commands[index][:u])
  end
 
  def cursor_down(wrap = false)
    select(GemWin::Commands[index][:d])
  end
 
  def cursor_left(wrap = false)
    select(GemWin::Commands[index][:l])
  end
 
  def cursor_right(wrap = false)
    select(GemWin::Commands[index][:r])
  end
 
end

This will read the position and size of your commands from the module settings.
Also, because your commands will be aligned into a circular shape, the default cursor movement during selection is not something you should keep.
For that reason, you can also set up where the cursor will go when the specific directional button is pressed based on your module settings.

Adjust the settings how you want. Make sure to include a setting for all of your commands or else the game will crash!

Shaz's method also works, but I like to organize my settings in a clean way with names, all at one place, outside of the real code.
Putting all the settings into one giant array would make my head spin if I would I need to edit it later. :p
I really love you!! hahaha You saved me, this way works like a charm, I ever have this trouble with the different command position, and now, you clarified me a easy way to do it
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

My first game is going to have the main character more or less create monsters as his party members.

Thanks to the plugin creators still producing content for MV, I might be able to give each of the monster members a personalized range of tactics during combat. I liked how the devs made it like that in FF6.
Stream will be live shortly! Tonight will be the PREMIERE of Killer 7 for the first half of the stream, and at half-stream, we will switch to a session of the Interactive Text Adventure! Feel free to drop by!
Watching the launch, I felt a sort of detached excitement. Usually I'd think something like this would be extremely exciting. I'm fascinated by space exploration and am a big Sci-Fi fan. I guess it's just current events.
What did everyone else think about it?
Doing ep 1 of my RPG!
For those still craving more Konosuba madness
I'm new here, any tips welcome

Hope you fun! :LZSgrin: :LZSkiss:
I set my goal to be finished with Knight Bewitched 2 by sometime in July. Based on my current work schedule and progress, I'm not sure that's going to happen, but by golly I'm gonna try!

Forum statistics

Threads
97,968
Messages
948,189
Members
129,217
Latest member
41728280
Top