Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

WIP Custom Graphical Command Window!

Alright I am working on a custom graphical command window, I am new to RGSS so I was hoping people could check the syntax for me to see that everything is correct. I will update the code as I go.
Code:
 

class Window_Graphical < Window_Selectable

 

  def initialize(width, commands, bmpheight, bmpwidth, hspacing, vspacing)

    #If vertical spacing is not provided, derive from horizontal spacing

    if vspacing == nil 

      vspacing = hspacing

    end

    

    #Calculate total commands width.

    @commands_width = (commands.size * (bmpwidth + hspacing))

    

    # Check that the bitmaps provided are not wider than the window width

    if @commands_width + 32 > width #If bitmaps are wider

      @lines = @commands_width / width #create lines

      @commands_height = (commands.size / @lines) * (bmpheight + vspacing) # Find window height

      super(0, 0, @commands_width / @lines, @commands_height)

    else    

      super(0, 0, @commands_width, @commands_height)

    end

 

    @item_max = commands.size

    @commands = commands

  end

...

 

  def draw_item(index)

    rect = Rect.new( @commands_width / @lines , @commands_height * @lines, bmpwidth, bmpheight)

    bitmap = RPG::Cache.picture(commands[index])

    self.contents.blt(index * @commands_width , index * @commands_height, bitmap, rect) 

  end

end

 

It is missing quite a bit but it is a WIP. I really need help with blitting bitmaps, it may just be lack of sleep but atm I am drawing a total blank. I am gonna head to sleep and pick this up tomorrow night.
 
Quick glance.... looks ok so far. I assume "commands" in the initialize argument is an array of bitmaps??

Line 29: missing a @

You must be tired... what is "blitting"?

I think this line: self.contents.blt(index * @commands_width , index * @commands_height, bitmap, rect)
will give you something like:
Code:
 

Command 1

                Command 2

                                 Command 3...
 
too true, I will have to put an if statement in, and some sort of math for that lol

Blit = BLock Image Transfer "To copy a large array of bits from one part of a computer's memory to another part, particularly when the memory is being used to determine what is shown on a display screen."
 
Gotcha... it's like you read "blt", pronounced it in your head, then transliterated the colloquialism back into writing. I missed the verbal pronunciation...

Anyways, use the modulus operator to determine the x position

x = index % (# of items in a row) * item.width #item being a menu item
y = index / (# of items in a row) * row.height
 
EDIT: Updated again

Code:
 

class Window_Graphical < Window_Selectable

 

  def initialize(width, commands, bmpheight, bmpwidth, hspacing, vspacing)

    #If vertical spacing is not provided, derive from horizontal spacing

    if vspacing == nil

      @vspacing = hspacing

    else

      @vspacing = vspacing

    end

    

    #Calculate total commands width.

    @commands_width = (commands.size * (bmpwidth + hspacing))

    @bmpheight = bmpheight

    @bmpwidth = bmpwidth

    @hspacing = hspacing

    # Check that the bitmaps provided are not wider than the window width

    if @commands_width + 32 > width #If bitmaps are wider

      @lines = @commands_width / width #create lines

      @commands_height = (commands.size / @lines) * (bmpheight + vspacing) # Find window height

      super(0, 0, @commands_width / @lines, @commands_height)

    else    

      super(0, 0, @commands_width, bmpheight+vspacing)

    end

 

    @item_max = commands.size

    @commands = commands

    refresh

    self.index = 0

  end

  

  def refresh

    for i in 0...@item_max

      draw_item(i)

  end

  end

 

  def draw_item(index)

    x = index % 3 * (@bmpwidth + @hspacing) #item being a menu item

    y = index / 3 * (@bmpheight + @vspacing)

    rect = Rect.new( x, y, @bmpwidth, @bmpheight )

    bitmap = RPG::Cache.picture(@commands[index])

    self.contents.blt( x, y, bitmap, rect )

  end

end

 
calling it using
$window=Window_Graphical.new(300, ["male01","male01"], 65, 45, 6, 6)
 
New Error
---------------------------
Digimon Complete
---------------------------
Script 'Window_graphical' line 42: NoMethodError occurred.

undefined method `blt' for nil:NilClass
---------------------------
OK
---------------------------

I am totally retarded with this stuff, I wish there was a good tutorial on resizing selectable menus and removing text lol.
 
thanks Brewmeister, math I am good at... graphical stuff I have never even really understood in any language lol.

Now it manages to show me an image, but the window is not active, nor is it the right size. I think I should give up on this for a while, I could already have one of my other more important systems complete by now =/

Last version of the code....for now
Code:
 

class Window_Graphical < Window_Selectable

 

  def initialize(width, commands, bmpheight, bmpwidth, hspacing, vspacing, columns)

    #If vertical spacing is not provided, derive from horizontal spacing

    if vspacing == nil

      @vspacing = hspacing

    else

      @vspacing = vspacing

    end

    

    #Calculate total commands width.

    @commands = commands

    @commands_width = (commands.size * (bmpwidth + hspacing))

    @bmpheight = bmpheight

    @bmpwidth = bmpwidth

    @hspacing = hspacing

    @lines=1

    # Check that the bitmaps provided are not wider than the window width

    if @commands_width + 32 > width #If bitmaps are wider

      @lines = @commands_width / width #create lines

      @commands_height = (commands.size / @lines) * (bmpheight + vspacing) # Find window height

      super(0, 0, @commands_width / @lines, @commands_height)

      @column_max = @commands.size / @lines

    else    

      super(0, 0, @commands_width, bmpheight+vspacing)

    end

    self.contents = Bitmap.new( width - 32, height - 32)

    @column_max = columns

    @item_max = commands.size

    @commands = commands

    refresh

    self.index = 0

  end

  

  def refresh

    for i in 0...@item_max

      draw_item(i)

  end

  end

 

  def draw_item(index)

    x = index % (@commands.size / @lines) * (@bmpwidth + @hspacing) #item being a menu item

    y = index / @lines * (@bmpheight + @vspacing)

    rect = Rect.new( x, y, @bmpwidth, @bmpheight )

    bitmap = RPG::Cache.picture(@commands[index])

    self.contents.blt( x, y, bitmap, rect )

  end

end

 
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top