How to change the position of a command

Discussion in 'RGSSx Script Support' started by kamekache, Feb 12, 2017.

  1. kamekache

    kamekache Villager Member

    Messages:
    10
    Likes Received:
    3
    First Language:
    Spanish
    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.

    [​IMG]

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

    [​IMG]

    Anyone can help me? Thanks.
     
    #1
  2. Shaz

    Shaz Veteran Veteran

    Messages:
    37,586
    Likes Received:
    11,303
    Location:
    Australia
    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.
     
    #2
    kamekache likes this.
  3. Kes

    Kes Global Moderators Global Mod

    Messages:
    20,613
    Likes Received:
    10,514
    First Language:
    English
    Primarily Uses:
    RMVXA

    I've moved this thread to RGSSx Script Support. Please be sure to post your threads in the correct forum next time. Thank you.

     
    #3
  4. Sixth

    Sixth Veteran Veteran

    Messages:
    2,130
    Likes Received:
    798
    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.
     
    #4
    Shaz and kamekache like this.
  5. kamekache

    kamekache Villager Member

    Messages:
    10
    Likes Received:
    3
    First Language:
    Spanish
    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....
    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.
     
    #5
  6. Shaz

    Shaz Veteran Veteran

    Messages:
    37,586
    Likes Received:
    11,303
    Location:
    Australia
    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.
     
    #6
    kamekache likes this.
  7. Sixth

    Sixth Veteran Veteran

    Messages:
    2,130
    Likes Received:
    798
    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
     
    #7
    kamekache likes this.
  8. kamekache

    kamekache Villager Member

    Messages:
    10
    Likes Received:
    3
    First Language:
    Spanish
    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.


    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
     
    #8

Share This Page