satoshinm / NetCraft

Web-based fork of fogleman/Craft ⛺
https://satoshinm.github.io/NetCraft/
MIT License
56 stars 13 forks source link

Inventory. GH-18 #175

Closed satoshinm closed 7 years ago

satoshinm commented 7 years ago

https://github.com/satoshinm/NetCraft/issues/18

satoshinm commented 7 years ago

CraftNG https://github.com/satoshinm/NetCraft/issues/25#issuecomment-299733356 has a good start of an inventory system:

screen shot 2017-06-03 at 7 54 20 pm

specifically these commits at least: https://github.com/twetzel59/CraftNG/commit/a604e73fe977ef15e47c5cbd6f96ef4eb6942174 https://github.com/twetzel59/CraftNG/commit/3b44099b65ece05d7bf91a7ad017147c8f1eb842 and https://github.com/twetzel59/CraftNG/commit/7e7c624f74f8f0eed83ed2c4d46fbd1dd986b113. Cherry-picked them and got the beginning of an inventory:

screenshot-netcraft-2017-06-04t02 55 18z

The next/previous E/R keys and 0-9 cycle the available blocks, so the bottommost block is active for placement, the others above serve as previews.

satoshinm commented 7 years ago

The item counts are rendered rightmost but the items, from render_item to set_matrix_item, shift in the wrong place when the window is resized, if wider then not far enough left (and vice versa if narrower then too far left):

screen shot 2017-06-03 at 8 22 44 pm
satoshinm commented 7 years ago

I think the offset is caused discrepancy is caused by using direct manipulation of the matrix instead of stacked matrix transformations, e.g. in set_matrix_item:

-    mat_translate(b, -xoffset, -yoffset, 0);
+    mat_translate(b, -xoffset + 1.75f, -yoffset, 0);

and render_item:

        if (!i) {
            set_matrix_item(matrix, g->width, g->height, g->scale);
            matrix[12] += 0.08f;
            matrix[13] += 0.1f;
        }

        matrix[13] += 0.25f;

matrix[12] += 0.08f; is meant to offset the non-active item slightly to the right, and matrix[13] += 0.1f; to move the active item down an offset. But +='ing matrix[12] doesn't take into account the window width, or rather, it mistakingly takes it into account when it shouldn't. Update: actually it is the -xoffset + 1.75f, it should instead be factored into float xoffset = 1 - size / width * 2;?

satoshinm commented 7 years ago

Having the sidebar flush wouldn't be too bad, if the text overlaid it, but even though it is drawn later it is partly clobbered:

screen shot 2017-06-03 at 8 51 39 pm
satoshinm commented 7 years ago

Native ok no longer item clobbering text:

screen shot 2017-06-03 at 8 54 38 pm

but web build, partially visible only:

screenshot-netcraft-2017-06-04t03_58_56 460z

satoshinm commented 7 years ago
    mat_translate(b, xoffset, -yoffset, 0.6f);

screenshot-netcraft-2017-06-04t04_01_29 058z

At 1.0f, text is fully visible but then the item is clipped (since zfar=-1, znear=1 in mat_ortho call in set_matrix_2d)... maybe there is a better way:

screenshot-netcraft-2017-06-04t04_01_48 399z

satoshinm commented 7 years ago

Better:

screenshot-netcraft-2017-06-04t04_07_29 644z

screen shot 2017-06-03 at 9 10 08 pm

satoshinm commented 7 years ago

Reducing scope of this pull request: https://github.com/satoshinm/NetCraft/pull/177