117 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			117 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
| inventory_drawer_height=0
 | |
| inventory_drawer_height_max=106
 | |
|  
 | |
| inventory_cursor = {
 | |
|     x=0, y=0,
 | |
| }
 | |
| 
 | |
| function inventory_slide(x1, x2)
 | |
|     return {
 | |
|         timer = 0,
 | |
|         active=true,
 | |
| 
 | |
|         before=function(s) 
 | |
|             inventory_drawer_height = x1
 | |
|         end,
 | |
| 
 | |
|         update=function(s) 
 | |
|             inventory_drawer_height = x1 + (s.timer/0.2)*(x2-x1)
 | |
|             if s.timer > 0.2 then 
 | |
|                 inventory_drawer_height = x2
 | |
|                 s.active=false 
 | |
|             end
 | |
|         end,
 | |
|         draw=function(s)
 | |
|             draw_drawer()
 | |
|             draw_item_sheet()
 | |
|         end,
 | |
|     }
 | |
| end
 | |
| 
 | |
| function inventory_before()
 | |
| end
 | |
| 
 | |
| function inventory_update()
 | |
|     cx, cy = inventory_cursor.x, inventory_cursor.y
 | |
|     if btnp(0) then cx -= 1 end
 | |
|     if btnp(1) then cx += 1 end
 | |
|     if btnp(2) then cy -= 1 end
 | |
|     if btnp(3) then cy += 1 end
 | |
|     if cy >= 0 and cy < flr(#inventory/5) then
 | |
|         if cx >= 0 and cx < 5 then
 | |
|             inventory_cursor.x = cx
 | |
|             inventory_cursor.y = cy
 | |
|         end
 | |
|     elseif cy == flr(#inventory / 5) then
 | |
|         if cx >= 0 and cx < #inventory % 5  then
 | |
|             inventory_cursor.x = cx
 | |
|             inventory_cursor.y = cy
 | |
|         end
 | |
|     end
 | |
| 
 | |
|     if btnp(5) then
 | |
|         animate(inventory_slide(inventory_drawer_height_max,0))
 | |
|         change_screen(screen_workbench)
 | |
|     end
 | |
| end
 | |
| 
 | |
| function inventory_draw()
 | |
|     bench_draw()
 | |
|     draw_drawer()
 | |
|     draw_item_sheet()
 | |
| end
 | |
| 
 | |
| function draw_drawer()
 | |
|     rectfill(14, 0, 114, inventory_drawer_height, 4)
 | |
|     for y=0,(inventory_drawer_height_max / 8) do
 | |
|         yval = y*8 + inventory_drawer_height - inventory_drawer_height_max
 | |
|         line(10, yval, 110, yval, 5)
 | |
|         for x=1,(4 - (y%2)) do
 | |
|             xval = x*32 + (y%2)*16
 | |
|             line(xval, yval, xval, yval+8, 5)
 | |
|         end
 | |
|         spr(20, 10,  yval)
 | |
|         spr(20, 110, yval)
 | |
|     end
 | |
|     rectfill(6, inventory_drawer_height, 120, inventory_drawer_height+7, 4)
 | |
|     line(6, inventory_drawer_height, 120, inventory_drawer_height, 9)
 | |
|     line(6, inventory_drawer_height+7, 120, inventory_drawer_height+7, 9)
 | |
|     spr(21, 2, inventory_drawer_height)
 | |
|     spr(21, 118, inventory_drawer_height, 1, 1, true, false)
 | |
|     spr(22, 60, inventory_drawer_height+8)
 | |
|     draw_drawer_contents()
 | |
| 
 | |
| end
 | |
| 
 | |
| function draw_drawer_contents()
 | |
|     for i, val in ipairs(inventory) do
 | |
|         x, y = 20+20*((i-1)%5), 10+20*flr((i-1)/5) + inventory_drawer_height - inventory_drawer_height_max
 | |
|         if inventory_cursor.x + 5*inventory_cursor.y == i-1 then
 | |
|             rect(x-2,y-2,x+9,y+9, 10)
 | |
|         end
 | |
|         sprite = val.sprite
 | |
|         if sprite == nil then sprite = 36 end
 | |
|         if val.sprite_recolor ~= nil then
 | |
|             pal(val.sprite_recolor)
 | |
|         end
 | |
|         spr(sprite, x, y)
 | |
|         pal()
 | |
|     end
 | |
| end
 | |
| 
 | |
| function draw_item_sheet()
 | |
|     if #inventory ~= 0 then
 | |
|         draw_paper(35,94, 128-2*35,28)
 | |
|         draw_ingredient_listing(inventory[1 + 5*inventory_cursor.y + inventory_cursor.x], 35, 94)
 | |
|     end
 | |
| end
 | |
| 
 | |
| 
 | |
| screen_inventory_raw = {before=inventory_before, draw=inventory_draw, update=inventory_update}
 | |
| screen_inventory = screen_conversation({
 | |
|     {phoebe_portrait, [[oh right, this is the drawer where i keep my stuff!]]},}, 
 | |
|     function() 
 | |
|         screen_inventory = screen_inventory_raw
 | |
|         change_screen(screen_inventory)
 | |
|     end,
 | |
|     screen_inventory_raw) |