inventory

This commit is contained in:
lllzebralll
2022-11-19 02:21:15 +03:00
parent b1e5a3c6fb
commit d2416946d9
9 changed files with 213 additions and 100 deletions
+90 -24
View File
@@ -56,8 +56,8 @@ void HudRenderer::drawDebug(Level* level, Assets* assets, int fps, bool occlusio
batch->begin();
font->draw(batch, L"chunks: "+std::to_wstring(chunks->chunksCount), 16, 16, STYLE_OUTLINE);
font->draw(batch, std::to_wstring((int)player->camera->position.x), 10, 30, STYLE_OUTLINE);
font->draw(batch, std::to_wstring((int)player->camera->position.y), 50, 30, STYLE_OUTLINE);
font->draw(batch, std::to_wstring((int)player->camera->position.z), 90, 30, STYLE_OUTLINE);
font->draw(batch, std::to_wstring((int)player->camera->position.y), 90, 30, STYLE_OUTLINE);
font->draw(batch, std::to_wstring((int)player->camera->position.z), 170, 30, STYLE_OUTLINE);
font->draw(batch, L"fps:", 16, 42, STYLE_OUTLINE);
font->draw(batch, std::to_wstring(fps), 44, 42, STYLE_OUTLINE);
font->draw(batch, L"occlusion: "+std::to_wstring(occlusion), 16, 54, STYLE_OUTLINE);
@@ -80,51 +80,115 @@ void HudRenderer::draw(Level* level, Assets* assets){
Texture* sprite = assets->getTexture("slot");
if (!Events::_cursor_locked) {
batch->texture(nullptr);
batch->color = vec4(0.0f, 0.0f, 0.0f, 0.5f);
batch->rect(0, 0, Window::width, Window::height);
}
batch->color = vec4(1.0f);
batch->texture(sprite);
batch->sprite(16, uicamera->fov - 80, 64, 64, 16, 0, vec4(1.0f));
// batch->texture(sprite);
batch->texture(nullptr);
// batch->sprite(Window::width/2-32, uicamera->fov - 80, 64, 64, 16, 0, vec4(1.0f));
// batch->rect(Window::width/2-128-4, Window::height-80-4, 256+8, 64+8,
// 0.85f, 0.85f, 0.85f, 0.95f, 0.95f, 0.95f,
// 0.55f, 0.55f, 0.55f,
// 0.45f, 0.45f, 0.45f, 0.7f, 0.7f, 0.7f, 2);
batch->rect(Window::width/2-128-4, Window::height-80-4, 256+8, 64+8,
0.95f, 0.95f, 0.95f, 0.85f, 0.85f, 0.85f,
0.7f, 0.7f, 0.7f,
0.55f, 0.55f, 0.55f, 0.45f, 0.45f, 0.45f, 4);
batch->rect(Window::width/2-128, Window::height - 80, 256, 64,
0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 0.75f,
0.75f, 0.75f, 0.75f,
0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 4);
batch->rect(Window::width/2-32+2, Window::height - 80+2, 60, 60,
0.45f, 0.45f, 0.45f, 0.55f, 0.55f, 0.55f,
0.7f, 0.7f, 0.7f,
0.85f, 0.85f, 0.85f, 0.95f, 0.95f, 0.95f, 2);
batch->rect(Window::width/2-32+4, Window::height - 80+4, 56, 56,
0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 0.75f,
0.75f, 0.75f, 0.75f,
0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 2);
batch->texture(blocks);
Player* player = level->player;
{
Block* cblock = Block::blocks[player->choosenBlock];
if (cblock->model == BLOCK_MODEL_CUBE){
batch->blockSprite(24, uicamera->fov - 72, 48, 48, 16, cblock->textureFaces, vec4(1.0f));
batch->blockSprite(Window::width/2-24, uicamera->fov - 72, 48, 48, 16, cblock->textureFaces, vec4(1.0f));
} else if (cblock->model == BLOCK_MODEL_X_SPRITE){
batch->sprite(24, uicamera->fov - 72, 48, 48, 16, cblock->textureFaces[3], vec4(1.0f));
batch->sprite(Window::width/2-24, uicamera->fov - 72, 48, 48, 16, cblock->textureFaces[3], vec4(1.0f));
}
}
if (!Events::_cursor_locked) {
if (!Events::_cursor_locked) { //inventory
int size = 48;
int step = 70;
int y = uicamera->fov - 72 - 70;
int step = 64;
int inv_wm = step*10;
int inv_hm = step*8;
int inv_w = inv_wm - (step - size);
int inv_h = inv_hm - (step - size);
int xs = (Window::width - inv_w + step)/2;
int x = 0;
int ys = (Window::height - inv_h + step)/2;
int y = 0;
vec4 tint = vec4(1.0f);
int mx = Events::x;
int my = Events::y;
int count = (inv_w / step) * (inv_h / step) + 1;
for (unsigned i = 1; i < 256; i++) {
//back
batch->texture(nullptr);
batch->color = vec4(0.0f, 0.0f, 0.0f, 0.3f);
batch->rect(0, 0, Window::width, Window::height);
batch->rect((Window::width - (inv_w)) / 2 - 4, (Window::height - (inv_h)) / 2 - 4, inv_w+8, inv_h+8,
0.95f, 0.95f, 0.95f, 0.85f, 0.85f, 0.85f,
0.7f, 0.7f, 0.7f,
0.55f, 0.55f, 0.55f, 0.45f, 0.45f, 0.45f, 4);
batch->rect((Window::width - (inv_w)) / 2, (Window::height - (inv_h)) / 2, inv_w, inv_h,
0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 0.75f,
0.75f, 0.75f, 0.75f,
0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 4);
batch->color = vec4(0.35f, 0.35f, 0.35f, 1.0f);
for (unsigned i = 1; i < count; i++) {
x = xs + step * ((i-1) % (inv_w / step));
y = ys + step * ((i-1) / (inv_w / step));
// batch->rect(x-2, y-2, size+4, size+4);
batch->rect(x-2, y-2, size+4, size+4,
0.45f, 0.45f, 0.45f, 0.55f, 0.55f, 0.55f,
0.7f, 0.7f, 0.7f,
0.85f, 0.85f, 0.85f, 0.95f, 0.95f, 0.95f, 2);
batch->rect(x, y, size, size,
0.65f, 0.65f, 0.65f, 0.65f, 0.65f, 0.65f,
0.65f, 0.65f, 0.65f,
0.65f, 0.65f, 0.65f, 0.65f, 0.65f, 0.65f, 2);
}
// batch->color = vec4(0.5f, 0.5f, 0.5f, 1.0f);
// for (unsigned i = 1; i < count; i++) {
// x = xs + step * ((i-1) % (inv_w / step));
// y = ys + step * ((i-1) / (inv_w / step));
// batch->rect(x, y, size, size);
// }
//front
batch->texture(blocks);
for (unsigned i = 1; i < count; i++) {
Block* cblock = Block::blocks[i];
if (cblock == nullptr)
break;
x = 24 + (i-1) * step;
y -= 72 * (x / (Window::width - step));
x %= (Window::width - step);
x = xs + step * ((i-1) % (inv_w / step));
y = ys + step * ((i-1) / (inv_w / step));
if (mx > x && mx < x + size && my > y && my < y + size) {
tint.r *= 1.3f;
tint.g *= 1.3f;
tint.b *= 1.3f;
tint.r *= 1.2f;
tint.g *= 1.2f;
tint.b *= 1.2f;
if (Events::jclicked(GLFW_MOUSE_BUTTON_LEFT)) {
player->choosenBlock = i;
}
// size = 50;
} else
{
// size = 48;
tint = vec4(1.0f);
}
@@ -138,9 +202,11 @@ void HudRenderer::draw(Level* level, Assets* assets){
batch->render();
Shader* crosshairShader = assets->getShader("crosshair");
crosshairShader->use();
crosshairShader->uniform1f("u_ar", (float)Window::height / (float)Window::width);
crosshairShader->uniform1f("u_scale", 1.0f / ((float)Window::height / 1000.0f));
crosshair->draw(GL_LINES);
if (Events::_cursor_locked){
Shader* crosshairShader = assets->getShader("crosshair");
crosshairShader->use();
crosshairShader->uniform1f("u_ar", (float)Window::height / (float)Window::width);
crosshairShader->uniform1f("u_scale", 1.0f / ((float)Window::height / 1000.0f));
crosshair->draw(GL_LINES);
}
}