[RESOLVED] [XP] How do I align center Scene_End command text?

Discussion in 'RGSSx Script Support' started by callmedan, Feb 21, 2019.

Thread Status:
Not open for further replies.
  1. callmedan

    callmedan Friendly Stranger Veteran

    Messages:
    562
    Likes Received:
    875
    Location:
    i'm behind you . . .
    First Language:
    Vietnamese
    Primarily Uses:
    RMXP
    As the title said, how do I align the text? I prefer it like in image below than the default.
    rmxp-align-command-text.png

    Thanks in advance
     
    #1
  2. gstv87

    gstv87 Veteran Veteran

    Messages:
    1,769
    Likes Received:
    798
    First Language:
    Spanish
    Primarily Uses:
    RMVXA
    find the draw text instruction that drives those labels.
    add a 1 at the end. 0 is left, 1 is center, 2 is right.
    draw_text(rect, string, align), or draw_text(x,y,w,h, string, align)
    That's the format. Default is 0, so you might not find a number.
     
    #2
  3. callmedan

    callmedan Friendly Stranger Veteran

    Messages:
    562
    Likes Received:
    875
    Location:
    i'm behind you . . .
    First Language:
    Vietnamese
    Primarily Uses:
    RMXP
    Oh, there's no draw_text.
    Here's the code:
    Code:
    def main
        # Make command window
        s1 = "To Title"
        s2 = "Shutdown"
        s3 = "Cancel"
        @command_window = Window_Command.new(192, [s1, s2, s3])
        @command_window.x = 320 - @command_window.width / 2
        @command_window.y = 240 - @command_window.height / 2
        # Execute transition
        Graphics.transition
        # Main loop
        loop do
          # Update game screen
          Graphics.update
          # Update input information
          Input.update
          # Frame Update
          update
          # Abort loop if screen is changed
          if $scene != self
            break
          end
        end
        # Prepare for transition
        Graphics.freeze
        # Dispose of window
        @command_window.dispose
        # If switching to title screen
        if $scene.is_a?(Scene_Title)
          # Fade out screen
          Graphics.transition
          Graphics.freeze
        end
      end
    I tried to put 1 into
    Code:
    @command_window = Window_Command.new(192, [s1, s2, s3])
    , and it'll give a wrong number of argument (3 for 2) error.

    Edit: Okay. I just figured out how to do that. We'll have to write a script inheriting Window_Selectable and call it in Scene_End.
    Also, I'd like to leave this thread open in a few days. Maybe someone could have a better solution.
    Code:
    #==============================================================================
    # ** Window_Quit
    #==============================================================================
    class Window_Quit < Window_Selectable
    # ------------------------
      def initialize()
        super(0, 32, 250, 128)
        @column_max = 1
        refresh
        self.index = 0
      end
    
    #--------------------------------------------------------------------------
    # * Draw the contents of the item window
    #--------------------------------------------------------------------------
      def refresh
        if self.contents != nil
          self.contents.dispose
          self.contents = nil
        end
    
       # draw the bitmap. the text will appear on this bitmap
        self.contents = Bitmap.new(width - 32, height - 32)
        self.contents.font.name = "Arial"
        self.contents.font.size = 24
        #self.contents.font.bold = true
    
       # n represents the y coordinate where the entry will be displayed
        @y_cord = 0
        @item_max = 3
    
       # show the items in the menu
        for i in 0..3
          draw_item(i)
        end
     
      end
    
    #--------------------------------------------------------------------------
    # * Draw info about a character in the window
    #--------------------------------------------------------------------------
      def draw_item(index)
        case index
          when 0
            item = "To Title"
          when 1
            item = "Shutdown"
          when 2
            item = "Cancel"
          when 3
            item = ""
        end
    
        # draw the option
        self.contents.draw_text(0, @y_cord, width-30, 32, item, 1)
    
        # move the next info block down so that characters don't overlap
        @y_cord += 32
    
      end
    end
    Code:
    #==============================================================================
    # ** Scene_End
    #------------------------------------------------------------------------------
    #  This class performs game end screen processing.
    #==============================================================================
    
    class Scene_End
    
      def initialize(index)
        @location = index
      end
     
      def main
    
        if @location != 1
          @spriteset = Spriteset_Map.new
        end
     
        # Set up options window
        @quit_window = Window_Quit.new
        @quit_window.x = 320 - @quit_window.width / 2
        @quit_window.y = 240 - @quit_window.height / 2
     
        if @location != 1
          @quit_window.back_opacity = $game_temp.menu_transparency
        end
     
        # Update graphics and input
        Graphics.transition
    
        loop do
          Graphics.update
          Input.update
          update
          if $scene != self
            break
          end
        end
    
        # Freeze graphics for transition
        Graphics.freeze
    
        # Erase
        @quit_window.dispose
    
        if @location != 1
          @spriteset.dispose
        end
    
      end
      #--------------------------------------------------------------------------
      # * Frame Update
      #--------------------------------------------------------------------------
      def update
        # Update command window
        #@command_window.update
        @quit_window.update
     
        # If B button was pressed
        if Input.trigger?(Input::B)
          # Play cancel SE
          $game_system.se_play($data_system.cancel_se)
          # Switch to menu screen
          $scene = Scene_Menu.new(5)
          return
        end
        # If C button was pressed
        if Input.trigger?(Input::C)
          # Branch by command window cursor position
          case @quit_window.index
          when 0  # to title
            command_to_title
          when 1  # shutdown
            command_shutdown
          when 2  # quit
            command_cancel
          end
          return
        end
      end
      #--------------------------------------------------------------------------
      # * Process When Choosing [To Title] Command
      #--------------------------------------------------------------------------
      def command_to_title
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Fade out BGM, BGS, and ME
        Audio.bgm_fade(800)
        Audio.bgs_fade(800)
        Audio.me_fade(800)
        # Switch to title screen
        $scene = Scene_Title.new
      end
      #--------------------------------------------------------------------------
      # * Process When Choosing [Shutdown] Command
      #--------------------------------------------------------------------------
      def command_shutdown
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Fade out BGM, BGS, and ME
        Audio.bgm_fade(800)
        Audio.bgs_fade(800)
        Audio.me_fade(800)
        # Shutdown
        $scene = nil
      end
      #--------------------------------------------------------------------------
      # *  Process When Choosing [Cancel] Command
      #--------------------------------------------------------------------------
      def command_cancel
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch to menu screen
        $scene = Scene_Menu.new(5)
      end
    end
     
    Last edited: Feb 22, 2019
    #3
  4. MobiusXVI

    MobiusXVI Game Maker Veteran

    Messages:
    359
    Likes Received:
    84
    First Language:
    English
    That's a reasonable solution. A slight improvement on it would be to inherit from Window_Command since that's what it currently used and will save you a lot of re-writes. Then you just have to change Scene_End to use (instantiate) the new subclass and everything else works as intended. If RMXP had a better format for its 'main' method you could get the change down to a single line. But since it doesn't, you have to copy-paste the whole method and then make the one line change.
    Code:
    class Window_CommandCentered < Window_Command
    
      #--------------------------------------------------------------------------
      # * Draw Item - NEW draws text centered
      #     index : item number
      #     color : text color
      #--------------------------------------------------------------------------
      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) #ONLY line changed from Window_Command
      end
     
    end
    
    class Scene_End
      #--------------------------------------------------------------------------
      # * Main Processing
      #--------------------------------------------------------------------------
      def main
        # Make command window
        s1 = "To Title"
        s2 = "Shutdown"
        s3 = "Cancel"
        @command_window = Window_CommandCentered.new(192, [s1, s2, s3]) # ONLY LINE CHANGED!
        @command_window.x = 320 - @command_window.width / 2
        @command_window.y = 240 - @command_window.height / 2
        # Execute transition
        Graphics.transition
        # Main loop
        loop do
          # Update game screen
          Graphics.update
          # Update input information
          Input.update
          # Frame Update
          update
          # Abort loop if screen is changed
          if $scene != self
            break
          end
        end
        # Prepare for transition
        Graphics.freeze
        # Dispose of window
        @command_window.dispose
        # If switching to title screen
        if $scene.is_a?(Scene_Title)
          # Fade out screen
          Graphics.transition
          Graphics.freeze
        end
      end
    end
    
     
    #4
    callmedan likes this.
  5. mlogan

    mlogan Global Moderators Global Mod

    Messages:
    13,797
    Likes Received:
    7,616
    Location:
    Texas
    First Language:
    English
    Primarily Uses:
    RMMV

    This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

     
    #5
Thread Status:
Not open for further replies.

Share This Page