Window Selectables - Item/Rect Size

Discussion in 'Learning Ruby and RGSSx' started by Rikifive, May 4, 2016.

  1. Rikifive

    Rikifive Bringer of Happiness Veteran

    Messages:
    1,442
    Likes Received:
    676
    Location:
    Poland
    First Language:
    Polish
    Primarily Uses:
    Other
    I'm terrible when it comes to work with default scripts and I've run into a silly trouble that apparently I can't solve.


    Currently I'm working on the party window that allows to select a member when using an item/skill, nothing special.


    The window automatically divides its height into numbers of items that can be displayed, in my case it can display 6 items:


    #--------------------------------------------------------------------------
    # * Get Item Height
    #--------------------------------------------------------------------------
    def item_height
    (height - standard_padding * 2) / 6
    end



    And everything works perfectly:

    [​IMG]





    That's how the window was designed - divide its height into number of items and set the size of each item based on the result.


    BUT! Now the problem appears. What I want to do is to decrease the size to make them overlapping each other by 2 pixels, to make them look better and simply use less space:

    [​IMG]



    And yup, since the window has lower height, it automatically gives lower size for each item, which results in stuff being cut off even if there IS space available, which is kinda stupid.


    I was trying changing stuff around ~ item rects and such, but when it worked, then other things were breaking.


    I guess it just need some accurate adjustments in some places, but I can't get it to work, most likely I'm just overlooking something.


    ~ Aaaaand windows using a superclass, that use a superclass, that use a superclass, thus stuff being all over the place doesn't help me.


    Thank you! ~
     
    Last edited by a moderator: May 4, 2016
    #1
  2. chungsie

    chungsie Veteran Veteran

    Messages:
    644
    Likes Received:
    840
    First Language:
    English
    Primarily Uses:
    N/A
    you haven't scaled down the display pictures, and your formula automatically uses variables that don't adjust based on the window size. how is standard_padding defined?
     
    #2
  3. Rikifive

    Rikifive Bringer of Happiness Veteran

    Messages:
    1,442
    Likes Received:
    676
    Location:
    Poland
    First Language:
    Polish
    Primarily Uses:
    Other
    It is untouched: (left by default)


    #--------------------------------------------------------------------------
    # * Get Standard Padding Size
    #--------------------------------------------------------------------------
    def standard_padding
    return 12
    end


    these 12 pixels are the ones left for window skin, so I don't think it's an issue here. As I said, there is free space and it would absolutely fit there, but it's just cut off by the methods within the window selectable. So, even if I'll increase the window's height by 2 or 3, nothing will change - it'll just add more empty space until the extra free space will be dividable by 6, which will result in auto-increasing height of items drawn by 1. (move away from each other)


    It's so confusing. . .
     
    #3
  4. chungsie

    chungsie Veteran Veteran

    Messages:
    644
    Likes Received:
    840
    First Language:
    English
    Primarily Uses:
    N/A
    if you are using integers, it won't place the spacing using decimals. maybe try adding a decimal followed by a 0? that would turn it from an integer to a float, which would make 64-12) * 2)/6 return something other than a whole number?

    also, your formula does 64-12*2 which is 64-24)/6 which is 40/6 which is 6.something. so its saying your item height is only 6 by default.

    Why not replace height with Window.height?
     
    Last edited by a moderator: May 4, 2016
    #4
  5. Rikifive

    Rikifive Bringer of Happiness Veteran

    Messages:
    1,442
    Likes Received:
    676
    Location:
    Poland
    First Language:
    Polish
    Primarily Uses:
    Other
    I think float numbers will not help either.


    Let's take an example:


    In the first screenshot I've posted, the window height is 336.


    Now window borders that are reserved for window skin: 24 pixels :  336 - 24 = 312 #=> That's the height, where stuff can be drawn.


    Now the selectables automatically divide the size by amount of items. ~ In my case (as seen on screenshots) there are 6 party members displayed at once, so that height is divided by 6: ====>  312 / 6 = 52 #=> That's the height for each item and everything is right so far.


    [​IMG] <= This image has dimensions 52 x 52, that as seen in first screenshot ideally fits.


    Now because I don't want double black borders between profile pictures, I want to remove these extra lines. So I want to remove 2 pixels between images and I want to remove it from 5 places (images' connections), so let's decrease the height by 2x5 = 10.


    Now the free space's height is 302.


    Divided by 6 (items), it gives ~50.333 (50 height)


    Which is okay ~ Each item now has 50 height and as seen on the second screenshot, these extra black lines were covered.


    That remaining part ~0.333, which equals 2/6 is the two pixels that are remaining for the black line at the very bottom (that is cut off on the screenshot)


    BUT since the height of an item is 50, then it's outside the rect, so it's not drawn even if the window itself has the space for it.


    What I'd have to do, is to manually adjust the item size/rect, by adding 2 height, to allow it to be drawn, but I'm not sure what's happening, because it gives weird results.


    Holy balls it's difficult to explain and think about it. =P
     
    #5
  6. muramasa

    muramasa Abomination of life, or life itself. Veteran

    Messages:
    581
    Likes Received:
    291
    Location:
    CR
    First Language:
    Spanish
    First guessing. You'll need to manually add 2 extra pixels to the window's height. Right now the window height calculation probably looks akin to this:

    Code:
    visible_items * item_height




    Just add a "+ 2" at the end of window_height for that class. It should fix the thing. And add it to the contents_height too, since I'm pretty sure that's giving us a problem too.


    The other thing that could be causing the problem would be if item_rect is used for blitting the image. Check the draw_item method in that window class too.


    That's all I can think about right now, hope you solve it. Cheers!
     
    Last edited by a moderator: May 4, 2016
    #6
  7. Rikifive

    Rikifive Bringer of Happiness Veteran

    Messages:
    1,442
    Likes Received:
    676
    Location:
    Poland
    First Language:
    Polish
    Primarily Uses:
    Other
    Aw nothing works ~ it is coded really chaotic.


    Stuff is all over the place and one thing changes 10 other things, that change another 99 things... =/


    I'm struggling with such a silly thing for hours and it's getting ridiculous now. =/


    I'm soooooooo coooonfused by the way they coded stuff, I'll be trying things hoping I'll find the right things.


    Everything would be better if there wouldn't be that many superclasses all over the place. =P
     
    #7
  8. Rikifive

    Rikifive Bringer of Happiness Veteran

    Messages:
    1,442
    Likes Received:
    676
    Location:
    Poland
    First Language:
    Polish
    Primarily Uses:
    Other
    ❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤


    Okay, after hours and hours changing stuff around, I managed to make it work.


    First - I've merged all methods into one ~ I've moved methods from windows base and selectable to the window itself, to be able to see what's going on. (And don't worry! I've removed unused/unchanged methods after making it work! Don't yell at me ( ͡ᵔ ͜ʖ ͡ᵔ ))


    Then I took a look on stuff few times and started tweaking them.


    1) FORCE the item height - Replace the automatic maths by the size of one item


    #--------------------------------------------------------------------------
    # * Get Item Height
    #--------------------------------------------------------------------------
    def item_height
    50
    end


    2) Add the 'covered' size manually:


    #--------------------------------------------------------------------------
    # * Get Rectangle for Drawing Items
    #--------------------------------------------------------------------------
    def item_rect(index)
    rect = Rect.new
    rect.width = item_width
    rect.height = item_height + 2 # <<< HERE!
    rect.x = index % col_max * (item_width + spacing)
    rect.y = index / col_max * item_height
    rect
    end


    3) Since the items are overlapping, their size is smaller than the last item, that is displayed at the end, because is not covered by anything. So, to reserve the space, you need to add [full version] - [covered version] pixels to the general height.


    #--------------------------------------------------------------------------
    # * Calculate Height of Window Contents
    #--------------------------------------------------------------------------
    def contents_height
    [(height - standard_padding * 2) - (height - standard_padding * 2) % item_height, row_max * item_height].max + 2
    end

    # I've added 2 to the end


    4) Because the window tries to be smart, it automatically calculates the space for certain amount of items considering their size. Since their forced size equals 50 - it multiplies that by amount of items. The full version is bigger, and it will be cut off, so we'll have to manually add these extra pixels to the maths.


    #--------------------------------------------------------------------------
    # * Update Bottom Padding
    #--------------------------------------------------------------------------
    def update_padding_bottom
    surplus = (height - standard_padding * 2) % item_height
    self.padding_bottom = padding + surplus - 2 # <<< HERE!
    end

    # added 2 pixels


    5) FORCE amount of items displayed at once, because by default it will calculate how many items can be put taking available space and size of items into account. I want to have 6 items, and I don't care about anything else, so let's just put a number:


    #--------------------------------------------------------------------------
    # * Get Number of Rows Displayable on 1 Page
    #--------------------------------------------------------------------------
    def page_row_max
    6
    end






    And that worked for me perfectly:


    <no spoiler, because I'm sure it will mess up my post>


    [​IMG]


    It took me ages to figure it out! You can't even imagine how my mind was blowing when I was trying to focus and think logically on that. ~But finally I managed to make it work.


    YAY!! This thread can be closed.


    ❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤
     
    #8
    BrandonKaminari likes this.

Share This Page