Option Window - inventory not displayed correctly

In the option window, the last line of the inventory isn't blanked, and so as you drop items one by one, the last item gets repeated again and again. The blank part of the inventory window needs to be blanked when the inventory is re-displayed. Blanking the last line will be enough in 'most' cases, but by no means all.

The object descriptions need to be truncated properly for oddly-sized windows which display weights in the inventory, on order to prevent the final column of the window from getting a more or less random character from the object description. This works for 80 column windows, but smaller windows will display the bug.

There are several places in the game that manipulate the players inventory, but don't set the flag which will force the inventory window to update. this results in the inventory list in the option window becoming out of date rather quickly. These will obviously need to be quantified individually as time permits. It may be more effective to make the inventory manipulation routines (item_decrease, item_carry, etc) set these flags instead. This will naturally result in the windows being refreshed before they really need to be and maybe more times than they need to be, but it'd be easier. And we're apparently not that concered about speed in tome3 anyway.

JohnGilmore:Here is a patch that addresses all of the above, except for the redisplaying flag not getting set properly when the inventory is updated.

JohnGilmore:Modified and cleaned up patch. Is now against CVS. Rewrote some comments, too.

patch:

diff -ur tomec/game/engine/objects.lua tome3/game/engine/objects.lua
--- tomec/game/engine/objects.lua       2006-03-04 16:55:28.592373100 -0700
+++ tome3/game/engine/objects.lua       2006-03-04 19:04:34.512276662 -0700
@@ -349,11 +349,25 @@
        wid_scrollbar = wid_scrollbar or (wid - 1)
        y_start = y_start or 0
        x_start = x_start or 0
+       if mirror then 
+               -- Mirror window lists need to start at the top line, others start at the second line to allow
+               -- space for the messages or prompts on the top line.
+               -- Setting y_start to -1 accomplishes this in the only way possible, given that y_start is referanced in the
+               -- __core_objects.term_print to insure that nothing is printed above the region that is allowed when printing
+               -- scrolling inventory lists.
+               y_start=-1
+               -- Mirror windows need to be cleared before redisplay. We would just print a blank line
+               -- after the last inventory item, but that won't work if multiple items in the player's 
+               -- inventory are dropped or destroyed in one turn.
+               term.clear()
+       end
 
        y = y + y_start
 
        if not inventory then inventory = player.inventory end
 
+       -- loop over the sub-inventory. For equipment, this outer loop goes once per 
+       -- slot. For normal inventory, it loop exactly once.
        for inven_nb = start, stop do
                local inven = inventory[inven_nb]
                max_size = flag_max_key(inven)
@@ -377,12 +391,15 @@
                        if inven[INVEN_LIMIT_KEY] > 1 then nb = "("..inven[INVEN_LIMIT_KEY]..")" end
 
                        -- Anything at all to display ?
+                       -- Display the equipment slot name
                        if inven[INVEN_LIMIT_KEY] > 0 then
                                __core_objects.term_blank_print(y_start, hgt, "", y, 0 + x_start)
                                __core_objects.term_print(y_start, hgt, color,key.."> "..inventory_slot_names[inven_nb + 1].name..nb, y, 0 + x_start)
                                y = y + 1
                        end
                end
+
+               -- Loop over each item in the given sub-inventory
                for i = 1, max_size do
                        -- Find the first to display
                        if (scroll_start_item == -1) and (y > y_start) then scroll_start_item = i end
@@ -403,6 +420,9 @@
                                -- Blank the line
                                if (not dont_show_choices) and item_tester_okay(obj) then
                                        if max_size == 1 and not force_inven_color then
+                                               --For equipment slots, the item should be printed on the same line
+                                               --as the description of the slot. But empty slots still need to 
+                                               --take up a line. So...
                                                y = y - 1
 
                                                -- Display the item
@@ -417,7 +437,7 @@
                                                -- Display the item
                                                __core_objects.term_print(y_start, hgt, color, desc, y, 4 + x_start)
                                        end
-                                       __core_objects.term_print(y_start, hgt, format("%10s", ((obj.weight * obj.number) / 10).."."..imod(obj.weight * obj.number, 10).." lb"), y, wid - 12)
+                                       __core_objects.term_print(y_start, hgt, format("%10s", ((obj.weight * obj.number) / 10).."."..imod(obj.weight * obj.number, 10).." lb"), y, wid - 11)
                                        if extra_display_fct and y <= hgt and y > y_start then extra_display_fct(obj, color, y) end
 
                                        -- Update the last displayed index

BugReport587 (last edited 2006-03-05 02:11:29 by JohnGilmore)