Closed satoshinm closed 7 years ago
CraftNG https://github.com/satoshinm/NetCraft/issues/25#issuecomment-299733356 has a good start of an inventory system:
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:
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.
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):
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;
?
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:
Native ok no longer item clobbering text:
but web build, partially visible only:
mat_translate(b, xoffset, -yoffset, 0.6f);
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:
Better:
Reducing scope of this pull request: https://github.com/satoshinm/NetCraft/pull/177
https://github.com/satoshinm/NetCraft/issues/18