stuff
This commit is contained in:
+443
-262
@@ -68,12 +68,14 @@
|
||||
#include "Sound.h"
|
||||
#include "Gui.h"
|
||||
#include "font.h"
|
||||
#include "TexturePainter.h"
|
||||
|
||||
// Character / animation
|
||||
#include "Rig.h"
|
||||
#include "Animator.h"
|
||||
#include "Character.h"
|
||||
#include "CharacterManager.h"
|
||||
#include "Ragdoll.h"
|
||||
#include "DefaultBodyComponents.h"
|
||||
#include "BodyComponentActions.h"
|
||||
|
||||
@@ -108,6 +110,12 @@ Engine::Engine()
|
||||
|
||||
rendersystem->RigShader = new Shader("shaders/rig.vert", "shaders/default.frag");
|
||||
rendersystem->MeshShader = new Shader("shaders/default.vert", "shaders/default.frag");
|
||||
rendersystem->GeometryShader = new Shader("shaders/geometry.vert", "shaders/geometry.frag");
|
||||
rendersystem->GeometryRigShader = new Shader("shaders/geometry_rig.vert", "shaders/geometry.frag");
|
||||
rendersystem->DeferredLightingShader = new Shader("shaders/deferred_lighting.vert", "shaders/deferred_lighting.frag");
|
||||
rendersystem->GBufferDebugShader = new Shader("shaders/gbuffer_debug.vert", "shaders/gbuffer_debug.frag");
|
||||
rendersystem->BloomExtractShader = new Shader("shaders/ScreenShader.vert", "shaders/bloom_extract.frag");
|
||||
rendersystem->BloomBlurShader = new Shader("shaders/ScreenShader.vert", "shaders/bloom_blur.frag");
|
||||
rendersystem->MeshShadowShader = new Shader("shaders/meshshadow.vert", "shaders/shadow.frag");
|
||||
rendersystem->RigShadowShader = new Shader("shaders/rigshadow.vert", "shaders/shadow.frag");
|
||||
rendersystem->SkyboxShader = new Shader("shaders/skybox.vert", "shaders/skybox.frag");
|
||||
@@ -124,14 +132,12 @@ Engine::Engine()
|
||||
// ============================================================================
|
||||
void Engine::Initiate()
|
||||
{
|
||||
Font* arial = new Font("assets/ft/arial.ttf");
|
||||
Texture* blanktex = new Texture("assets/blanktexture.png");
|
||||
Texture* snowflake = new Texture("assets/snowflake.png");
|
||||
Font* arial = resourcemanager->GetFont("assets/ft/arial.ttf");
|
||||
Texture* blanktex = resourcemanager->GetTexture("assets/blanktexture.png");
|
||||
|
||||
charactermanager = new CharacterManager();
|
||||
charactermanager->LoadRig("humanoid", "assets/rig.glb");
|
||||
charactermanager->LoadAnimation("walk", "assets/walkanim.glb", "humanoid");
|
||||
charactermanager->LoadAnimation("punch", "assets/punchanim.glb", "humanoid");
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Player character
|
||||
@@ -144,7 +150,6 @@ void Engine::Initiate()
|
||||
testcharacter.body->t.ScaleBy({ 0.7f, 2.5f, 0.7f });
|
||||
testcharacter.body->t.TranslateTo({ 0.0f, 1.5f, 0.0f });
|
||||
testcharacter.body->animator->loops = true;
|
||||
testcharacter.SetPunchAnimation(charactermanager->GetAnimation("punch"));
|
||||
testcharacter.BindToRenderSystem();
|
||||
|
||||
p* characterBody = new p(testcharacter.body);
|
||||
@@ -163,39 +168,11 @@ void Engine::Initiate()
|
||||
npc.roughness = 0.5f;
|
||||
npc.body->t.ScaleBy({ 0.7f, 2.5f, 0.7f });
|
||||
npc.body->t.TranslateTo({ 3.0f, 1.25f, 3.0f });
|
||||
npc.SetPunchAnimation(charactermanager->GetAnimation("punch"));
|
||||
npc.SetPunchLooping(true);
|
||||
npc.Punch();
|
||||
npc.BindToRenderSystem();
|
||||
|
||||
p* npcBody = new p(npc.body);
|
||||
npcBody->mass = 80.0f;
|
||||
npcBody->lockRotation = true;
|
||||
npcBody->friction = 0.0f;
|
||||
physicsengine->AddObject(npcBody);
|
||||
|
||||
testcharacter.SetWalking(false);
|
||||
npc.SetWalking(false);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Rain particles
|
||||
// ------------------------------------------------------------------------
|
||||
ParticleEmitter* rain = new ParticleEmitter();
|
||||
rain->name = "rain";
|
||||
rain->tex = snowflake;
|
||||
rain->opaque = false;
|
||||
rain->speed = 35.0f;
|
||||
rain->lifespan = 0.6f;
|
||||
rain->angularvelocity = { 0.0f, 0.0f, glm::radians(10.0f) };
|
||||
rain->size = { 0.04f, 0.4f, 0.0f };
|
||||
rain->emitangle = { glm::radians(60.0f), glm::radians(360.0f), glm::radians(60.0f) };
|
||||
rain->facecamera = false;
|
||||
rain->color = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
rain->emitdirection = ParticleEmitter::EmitDirection::Perpendicular;
|
||||
rain->t.TranslateTo({ 0.0f, 10.0f, 0.0f });
|
||||
rain->t.RotateToQuaternion(glm::quat(glm::vec3(glm::radians(85.0f), 0.0f, 0.0f)));
|
||||
rain->BindToRenderSystem();
|
||||
mainf->AddChild(rain);
|
||||
npc.EnableRagdoll(*physicsengine);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// 3D audio
|
||||
@@ -221,149 +198,272 @@ void Engine::Initiate()
|
||||
fpsCounter->t2d.size = { 0.1f, 0.1f, 0.0f, 0.0f };
|
||||
fpsCounter->BindToRenderSystem();
|
||||
|
||||
TextBox* healthText = new TextBox();
|
||||
healthText->font = arial;
|
||||
healthText->text = "";
|
||||
healthText->fontsize = 0.5f;
|
||||
healthText->Color = { 0.95f, 0.97f, 1.0f };
|
||||
healthText->t2d.position = { 0.02f, 0.02f, 0.0f, 0.0f };
|
||||
healthText->t2d.size = { 0.45f, 0.0f, 0.0f, 40.0f };
|
||||
healthText->textCenter = { 0.0f, 0.0f };
|
||||
healthText->BindToRenderSystem();
|
||||
|
||||
const float healthBarFillWidth = 314.0f;
|
||||
|
||||
Box* healthBarBack = new Box();
|
||||
healthBarBack->Color = { 0.03f, 0.04f, 0.06f };
|
||||
healthBarBack->Opacity = 0.85f;
|
||||
healthBarBack->t2d.position = { 0.02f, 1.0f, 0.0f, -30.0f };
|
||||
healthBarBack->t2d.center = { 0.0f, 1.0f };
|
||||
healthBarBack->t2d.size = { 0.0f, 0.0f, 320.0f, 26.0f };
|
||||
healthBarBack->BindToRenderSystem();
|
||||
|
||||
Box* healthBarFill = new Box();
|
||||
healthBarFill->Color = { 0.2f, 0.85f, 0.35f };
|
||||
healthBarFill->t2d.position = { 0.02f, 1.0f, 3.0f, -33.0f };
|
||||
healthBarFill->t2d.center = { 0.0f, 1.0f };
|
||||
healthBarFill->t2d.size = { 0.0f, 0.0f, healthBarFillWidth, 20.0f };
|
||||
healthBarFill->BindToRenderSystem();
|
||||
|
||||
struct MenuButton {
|
||||
Box* box;
|
||||
Box* accent;
|
||||
TextBox* label;
|
||||
glm::vec3 color;
|
||||
glm::vec3 hoverColor;
|
||||
float opacity;
|
||||
float labelX;
|
||||
float labelSlide; // how far the label moves right on hover
|
||||
bool hovered = false;
|
||||
float hover = 0.0f; // eased 0-1
|
||||
};
|
||||
|
||||
enum class MenuScreen { Main, Paused, Settings };
|
||||
enum class MenuScreen { Main, Paused, Settings, Graphics, Drawer };
|
||||
MenuScreen menuScreen = MenuScreen::Main;
|
||||
MenuScreen settingsReturn = MenuScreen::Main;
|
||||
bool menuActive = true;
|
||||
bool prevMouseDown = false;
|
||||
std::vector<Box*> menuItems;
|
||||
|
||||
// Everything hangs off a left side panel so the live scene stays visible.
|
||||
// Items are positioned in pixels from the left edge and the vertical center of the window.
|
||||
const float menuPanelWidth = 460.0f;
|
||||
const float menuMargin = 48.0f;
|
||||
const float menuContentWidth = 364.0f;
|
||||
const glm::vec3 menuAccent(0.96f, 0.58f, 0.16f);
|
||||
const glm::vec3 menuText(0.95f, 0.97f, 1.0f);
|
||||
const glm::vec3 menuMutedText(0.62f, 0.68f, 0.77f);
|
||||
const glm::vec3 menuButtonColor(0.11f, 0.14f, 0.19f);
|
||||
const glm::vec3 menuButtonHover(0.20f, 0.25f, 0.33f);
|
||||
|
||||
Box* menuVeil = new Box();
|
||||
menuVeil->Color = { 0.02f, 0.03f, 0.05f };
|
||||
menuVeil->Opacity = 0.55f;
|
||||
menuVeil->t2d.position = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
menuVeil->t2d.size = { 1.0f, 1.0f, 0.0f, 0.0f };
|
||||
menuVeil->BindToRenderSystem();
|
||||
menuItems.push_back(menuVeil);
|
||||
|
||||
TextBox* menuTitle = new TextBox();
|
||||
menuTitle->font = arial;
|
||||
menuTitle->text = "EIIFWHRN";
|
||||
menuTitle->fontsize = 3.0f;
|
||||
menuTitle->Color = { 0.95f, 0.97f, 1.0f };
|
||||
menuTitle->t2d.position = { 0.5f, 0.17f, 0.0f, 0.0f };
|
||||
menuTitle->t2d.center = { 0.5f, 0.5f };
|
||||
menuTitle->t2d.size = { 0.8f, 0.0f, 0.0f, 170.0f };
|
||||
menuTitle->textCenter = { 0.5f, 0.5f };
|
||||
menuTitle->BindToRenderSystem();
|
||||
menuItems.push_back(menuTitle);
|
||||
Box* menuPanel = new Box();
|
||||
menuPanel->Color = { 0.03f, 0.04f, 0.06f };
|
||||
menuPanel->t2d.position = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
menuPanel->t2d.size = { 0.0f, 1.0f, menuPanelWidth, 0.0f };
|
||||
menuPanel->BindToRenderSystem();
|
||||
menuItems.push_back(menuPanel);
|
||||
|
||||
TextBox* menuSubtitle = new TextBox();
|
||||
menuSubtitle->font = arial;
|
||||
menuSubtitle->text = "MAIN MENU";
|
||||
menuSubtitle->fontsize = 0.65f;
|
||||
menuSubtitle->Color = { 0.55f, 0.65f, 0.78f };
|
||||
menuSubtitle->t2d.position = { 0.5f, 0.285f, 0.0f, 0.0f };
|
||||
menuSubtitle->t2d.center = { 0.5f, 0.5f };
|
||||
menuSubtitle->t2d.size = { 0.4f, 0.0f, 0.0f, 50.0f };
|
||||
menuSubtitle->textCenter = { 0.5f, 0.5f };
|
||||
menuSubtitle->BindToRenderSystem();
|
||||
menuItems.push_back(menuSubtitle);
|
||||
|
||||
auto MakeMenuButton = [&](const char* text, float x, float y, glm::vec3 color,
|
||||
float width = 340.0f, float height = 62.0f,
|
||||
float fontsize = 0.85f) {
|
||||
Box* box = new Box();
|
||||
box->Color = color;
|
||||
box->Opacity = 0.92f;
|
||||
box->t2d.position = { x, y, 0.0f, 0.0f };
|
||||
box->t2d.center = { 0.5f, 0.5f };
|
||||
box->t2d.size = { 0.0f, 0.0f, width, height };
|
||||
box->BindToRenderSystem();
|
||||
menuItems.push_back(box);
|
||||
Box* menuPanelEdge = new Box();
|
||||
menuPanelEdge->Color = menuAccent;
|
||||
menuPanelEdge->t2d.position = { 0.0f, 0.0f, menuPanelWidth, 0.0f };
|
||||
menuPanelEdge->t2d.size = { 0.0f, 1.0f, 3.0f, 0.0f };
|
||||
menuPanelEdge->BindToRenderSystem();
|
||||
menuItems.push_back(menuPanelEdge);
|
||||
|
||||
auto MakeMenuText = [&](const char* text, float x, float y, float width, float height,
|
||||
float fontsize, glm::vec3 color, float alignX = 0.0f) {
|
||||
TextBox* label = new TextBox();
|
||||
label->font = arial;
|
||||
label->text = text;
|
||||
label->fontsize = fontsize;
|
||||
label->Color = { 0.95f, 0.97f, 1.0f };
|
||||
label->t2d.position = { x, y, 0.0f, 0.0f };
|
||||
label->t2d.center = { 0.5f, 0.5f };
|
||||
label->Color = color;
|
||||
label->t2d.position = { 0.0f, 0.5f, x, y };
|
||||
label->t2d.center = { 0.0f, 0.5f };
|
||||
label->t2d.size = { 0.0f, 0.0f, width, height };
|
||||
label->textCenter = { 0.5f, 0.5f };
|
||||
label->textCenter = { alignX, 0.5f };
|
||||
label->BindToRenderSystem();
|
||||
menuItems.push_back(label);
|
||||
|
||||
return MenuButton{ box, label, color };
|
||||
return label;
|
||||
};
|
||||
|
||||
MenuButton playButton = MakeMenuButton("PLAY", 0.5f, 0.46f, glm::vec3(0.12f, 0.30f, 0.22f));
|
||||
MenuButton settingsButton = MakeMenuButton("SETTINGS", 0.5f, 0.58f, glm::vec3(0.15f, 0.23f, 0.34f));
|
||||
MenuButton quitButton = MakeMenuButton("QUIT", 0.5f, 0.70f, glm::vec3(0.17f, 0.18f, 0.22f));
|
||||
TextBox* menuTitle = MakeMenuText("EIIFWHRN", menuMargin, -235.0f, 400.0f, 100.0f, 1.6f, menuText);
|
||||
TextBox* menuSubtitle = MakeMenuText("MAIN MENU", menuMargin, -165.0f, menuContentWidth, 36.0f, 0.5f, menuAccent);
|
||||
|
||||
MenuButton sensitivityDown = MakeMenuButton("- SENS", 0.40f, 0.47f,
|
||||
glm::vec3(0.15f, 0.23f, 0.34f), 170.0f, 50.0f, 0.65f);
|
||||
MenuButton sensitivityUp = MakeMenuButton("+ SENS", 0.60f, 0.47f,
|
||||
glm::vec3(0.15f, 0.23f, 0.34f), 170.0f, 50.0f, 0.65f);
|
||||
MenuButton fovDown = MakeMenuButton("- FOV", 0.40f, 0.58f,
|
||||
glm::vec3(0.15f, 0.23f, 0.34f), 170.0f, 50.0f, 0.65f);
|
||||
MenuButton fovUp = MakeMenuButton("+ FOV", 0.60f, 0.58f,
|
||||
glm::vec3(0.15f, 0.23f, 0.34f), 170.0f, 50.0f, 0.65f);
|
||||
MenuButton hitboxToggle = MakeMenuButton("HITBOXES: OFF", 0.5f, 0.68f,
|
||||
glm::vec3(0.20f, 0.22f, 0.28f), 340.0f, 50.0f, 0.65f);
|
||||
MenuButton resetButton = MakeMenuButton("RESET DEFAULTS", 0.5f, 0.77f,
|
||||
glm::vec3(0.20f, 0.22f, 0.28f), 340.0f, 52.0f, 0.65f);
|
||||
MenuButton backButton = MakeMenuButton("BACK", 0.5f, 0.86f,
|
||||
glm::vec3(0.12f, 0.30f, 0.22f), 340.0f, 52.0f, 0.85f);
|
||||
auto MakeMenuButton = [&](const char* text, float x, float y, float width, float height,
|
||||
float fontsize, glm::vec3 color, glm::vec3 hoverColor,
|
||||
float opacity = 0.6f, bool compact = false) {
|
||||
Box* box = new Box();
|
||||
box->Color = color;
|
||||
box->t2d.position = { 0.0f, 0.5f, x, y };
|
||||
box->t2d.center = { 0.0f, 0.5f };
|
||||
box->t2d.size = { 0.0f, 0.0f, width, height };
|
||||
box->rounding = 0.15f;
|
||||
box->BindToRenderSystem();
|
||||
menuItems.push_back(box);
|
||||
|
||||
TextBox* settingsInfo = new TextBox();
|
||||
settingsInfo->font = arial;
|
||||
settingsInfo->fontsize = 0.65f;
|
||||
settingsInfo->Color = { 0.85f, 0.90f, 0.97f };
|
||||
settingsInfo->t2d.position = { 0.5f, 0.37f, 0.0f, 0.0f };
|
||||
settingsInfo->t2d.center = { 0.5f, 0.5f };
|
||||
settingsInfo->t2d.size = { 0.8f, 0.0f, 0.0f, 90.0f };
|
||||
settingsInfo->textCenter = { 0.5f, 0.5f };
|
||||
settingsInfo->BindToRenderSystem();
|
||||
menuItems.push_back(settingsInfo);
|
||||
Box* accent = new Box();
|
||||
accent->Color = menuAccent;
|
||||
accent->t2d.position = { 0.0f, 0.5f, x, y };
|
||||
accent->t2d.center = { 0.0f, 0.5f };
|
||||
accent->t2d.size = { 0.0f, 0.0f, 0.0f, height };
|
||||
accent->BindToRenderSystem();
|
||||
menuItems.push_back(accent);
|
||||
|
||||
// Compact buttons hold a single centered symbol, the rest are left aligned and slide on hover
|
||||
const float padding = compact ? 0.0f : 20.0f;
|
||||
TextBox* label = MakeMenuText(text, x + padding, y, width - padding * 2.0f, height,
|
||||
fontsize, menuText, compact ? 0.5f : 0.0f);
|
||||
|
||||
return MenuButton{ box, accent, label, color, hoverColor, opacity,
|
||||
x + padding, compact ? 0.0f : 8.0f };
|
||||
};
|
||||
|
||||
const float mainButtonHeight = 60.0f;
|
||||
MenuButton playButton = MakeMenuButton("PLAY", menuMargin, -60.0f, menuContentWidth, mainButtonHeight, 0.75f,
|
||||
glm::vec3(0.82f, 0.45f, 0.10f), menuAccent, 0.95f);
|
||||
MenuButton drawerButton = MakeMenuButton("TEXTURE DRAWER", menuMargin, 12.0f, menuContentWidth, mainButtonHeight, 0.75f,
|
||||
menuButtonColor, menuButtonHover);
|
||||
MenuButton settingsButton = MakeMenuButton("SETTINGS", menuMargin, 84.0f, menuContentWidth, mainButtonHeight, 0.75f,
|
||||
menuButtonColor, menuButtonHover);
|
||||
MenuButton quitButton = MakeMenuButton("QUIT", menuMargin, 156.0f, menuContentWidth, mainButtonHeight, 0.75f,
|
||||
menuButtonColor, glm::vec3(0.42f, 0.14f, 0.16f));
|
||||
|
||||
// Settings rows: LABEL [-] VALUE [+]
|
||||
const float stepperDownX = menuMargin + 176.0f;
|
||||
const float stepperValueX = stepperDownX + 44.0f;
|
||||
const float stepperUpX = menuMargin + menuContentWidth - 44.0f;
|
||||
const float stepperValueWidth = stepperUpX - stepperValueX;
|
||||
const float sensRowY = -120.0f;
|
||||
const float fovRowY = -64.0f;
|
||||
|
||||
TextBox* sensLabel = MakeMenuText("SENSITIVITY", menuMargin, sensRowY, 172.0f, 44.0f, 0.5f, menuMutedText);
|
||||
TextBox* sensValue = MakeMenuText("", stepperValueX, sensRowY, stepperValueWidth, 44.0f, 0.5f, menuText, 0.5f);
|
||||
TextBox* fovLabel = MakeMenuText("FIELD OF VIEW", menuMargin, fovRowY, 172.0f, 44.0f, 0.5f, menuMutedText);
|
||||
TextBox* fovValue = MakeMenuText("", stepperValueX, fovRowY, stepperValueWidth, 44.0f, 0.5f, menuText, 0.5f);
|
||||
|
||||
MenuButton sensitivityDown = MakeMenuButton("-", stepperDownX, sensRowY, 44.0f, 44.0f, 0.7f,
|
||||
menuButtonColor, menuButtonHover, 0.6f, true);
|
||||
MenuButton sensitivityUp = MakeMenuButton("+", stepperUpX, sensRowY, 44.0f, 44.0f, 0.7f,
|
||||
menuButtonColor, menuButtonHover, 0.6f, true);
|
||||
MenuButton fovDown = MakeMenuButton("-", stepperDownX, fovRowY, 44.0f, 44.0f, 0.7f,
|
||||
menuButtonColor, menuButtonHover, 0.6f, true);
|
||||
MenuButton fovUp = MakeMenuButton("+", stepperUpX, fovRowY, 44.0f, 44.0f, 0.7f,
|
||||
menuButtonColor, menuButtonHover, 0.6f, true);
|
||||
MenuButton hitboxToggle = MakeMenuButton("HITBOXES: OFF", menuMargin, -18.0f, menuContentWidth, 40.0f, 0.6f,
|
||||
menuButtonColor, menuButtonHover);
|
||||
MenuButton graphicsButton = MakeMenuButton("GRAPHICS", menuMargin, 26.0f, menuContentWidth, 40.0f, 0.6f,
|
||||
menuButtonColor, menuButtonHover);
|
||||
MenuButton resetButton = MakeMenuButton("RESET DEFAULTS", menuMargin, 70.0f, menuContentWidth, 40.0f, 0.6f,
|
||||
menuButtonColor, menuButtonHover);
|
||||
|
||||
MenuButton bloomToggle = MakeMenuButton("", menuMargin, -128.0f, menuContentWidth, 44.0f, 0.6f,
|
||||
menuButtonColor, menuButtonHover);
|
||||
MenuButton shadowToggle = MakeMenuButton("", menuMargin, -78.0f, menuContentWidth, 44.0f, 0.6f,
|
||||
menuButtonColor, menuButtonHover);
|
||||
MenuButton lightShadowToggle = MakeMenuButton("", menuMargin, -28.0f, menuContentWidth, 44.0f, 0.6f,
|
||||
menuButtonColor, menuButtonHover);
|
||||
MenuButton vsyncToggle = MakeMenuButton("", menuMargin, 22.0f, menuContentWidth, 44.0f, 0.6f,
|
||||
menuButtonColor, menuButtonHover);
|
||||
MenuButton cullingToggle = MakeMenuButton("", menuMargin, 72.0f, menuContentWidth, 44.0f, 0.6f,
|
||||
menuButtonColor, menuButtonHover);
|
||||
MenuButton backButton = MakeMenuButton("BACK", menuMargin, 120.0f, menuContentWidth, 50.0f, 0.6f,
|
||||
glm::vec3(0.82f, 0.45f, 0.10f), menuAccent, 0.95f);
|
||||
|
||||
// Texture drawer. Filled in further down, once the things it paints on exist.
|
||||
struct DrawableSurface {
|
||||
const char* name;
|
||||
SurfaceTexture* surface;
|
||||
glm::vec4* colorOverride;
|
||||
bool hasCanvas = false;
|
||||
};
|
||||
std::vector<DrawableSurface> drawableSurfaces;
|
||||
int selectedSurface = 0;
|
||||
int selectedSwatch = 0;
|
||||
TexturePainter painter;
|
||||
bool painting = false;
|
||||
|
||||
// The first edit swaps in a private copy, so painting never touches the shared image file.
|
||||
// A colour override would hide the paint, so that goes too.
|
||||
auto EnsureCanvas = [&](DrawableSurface& drawable) {
|
||||
if (drawable.hasCanvas)
|
||||
return;
|
||||
|
||||
SurfaceTexture& surface = *drawable.surface;
|
||||
surface.texture = surface.texture ? resourcemanager->CopyTexture(*surface.texture)
|
||||
: resourcemanager->CreateTexture(256, 256);
|
||||
drawable.colorOverride->w = 0.0f;
|
||||
drawable.hasCanvas = true;
|
||||
};
|
||||
|
||||
const float surfaceRowY = -120.0f;
|
||||
const float swatchRowY = -64.0f;
|
||||
const float brushRowY = -8.0f;
|
||||
|
||||
MenuButton surfacePrevious = MakeMenuButton("<", menuMargin, surfaceRowY, 44.0f, 44.0f, 0.6f,
|
||||
menuButtonColor, menuButtonHover, 0.6f, true);
|
||||
MenuButton surfaceNext = MakeMenuButton(">", stepperUpX, surfaceRowY, 44.0f, 44.0f, 0.6f,
|
||||
menuButtonColor, menuButtonHover, 0.6f, true);
|
||||
TextBox* surfaceName = MakeMenuText("", menuMargin + 44.0f, surfaceRowY, menuContentWidth - 88.0f, 44.0f, 0.5f, menuText, 0.5f);
|
||||
|
||||
const glm::vec3 swatchColors[] = {
|
||||
{ 0.0f, 0.0f, 0.0f }, { 1.0f, 1.0f, 1.0f }, { 0.90f, 0.15f, 0.15f },
|
||||
{ 0.96f, 0.58f, 0.16f }, { 0.20f, 0.75f, 0.30f }, { 0.20f, 0.45f, 0.95f }
|
||||
};
|
||||
const float swatchSize = 52.0f;
|
||||
const float swatchSpacing = 60.0f;
|
||||
|
||||
std::vector<MenuButton> swatches;
|
||||
swatches.reserve(std::size(swatchColors));
|
||||
for (int i = 0; i < (int)std::size(swatchColors); i++) {
|
||||
swatches.push_back(MakeMenuButton("", menuMargin + swatchSpacing * i, swatchRowY, swatchSize, 44.0f, 0.5f,
|
||||
swatchColors[i], glm::mix(swatchColors[i], glm::vec3(1.0f), 0.2f), 1.0f, true));
|
||||
}
|
||||
|
||||
Box* swatchMarker = new Box();
|
||||
swatchMarker->Color = menuAccent;
|
||||
swatchMarker->t2d.center = { 0.0f, 0.5f };
|
||||
swatchMarker->t2d.size = { 0.0f, 0.0f, swatchSize, 4.0f };
|
||||
swatchMarker->BindToRenderSystem();
|
||||
menuItems.push_back(swatchMarker);
|
||||
|
||||
TextBox* brushLabel = MakeMenuText("BRUSH SIZE", menuMargin, brushRowY, 172.0f, 44.0f, 0.5f, menuMutedText);
|
||||
TextBox* brushValue = MakeMenuText("", stepperValueX, brushRowY, stepperValueWidth, 44.0f, 0.5f, menuText, 0.5f);
|
||||
MenuButton brushDown = MakeMenuButton("-", stepperDownX, brushRowY, 44.0f, 44.0f, 0.7f,
|
||||
menuButtonColor, menuButtonHover, 0.6f, true);
|
||||
MenuButton brushUp = MakeMenuButton("+", stepperUpX, brushRowY, 44.0f, 44.0f, 0.7f,
|
||||
menuButtonColor, menuButtonHover, 0.6f, true);
|
||||
MenuButton clearButton = MakeMenuButton("CLEAR", menuMargin, 52.0f, menuContentWidth, 50.0f, 0.6f,
|
||||
menuButtonColor, menuButtonHover);
|
||||
|
||||
// The canvas sits in the middle of the space right of the panel
|
||||
const float canvasSize = 640.0f;
|
||||
|
||||
Box* canvasBorder = new Box();
|
||||
canvasBorder->Color = menuAccent;
|
||||
canvasBorder->t2d.position = { 0.5f, 0.5f, menuPanelWidth * 0.5f, 0.0f };
|
||||
canvasBorder->t2d.center = { 0.5f, 0.5f };
|
||||
canvasBorder->t2d.size = { 0.0f, 0.0f, canvasSize + 8.0f, canvasSize + 8.0f };
|
||||
canvasBorder->BindToRenderSystem();
|
||||
menuItems.push_back(canvasBorder);
|
||||
|
||||
Box* canvasBlank = new Box(); // shows through until the surface has a texture
|
||||
canvasBlank->t2d.position = canvasBorder->t2d.position;
|
||||
canvasBlank->t2d.center = { 0.5f, 0.5f };
|
||||
canvasBlank->t2d.size = { 0.0f, 0.0f, canvasSize, canvasSize };
|
||||
canvasBlank->BindToRenderSystem();
|
||||
menuItems.push_back(canvasBlank);
|
||||
|
||||
ImageBox* canvasImage = new ImageBox();
|
||||
canvasImage->t2d.position = canvasBorder->t2d.position;
|
||||
canvasImage->t2d.center = { 0.5f, 0.5f };
|
||||
canvasImage->t2d.size = { 0.0f, 0.0f, canvasSize, canvasSize };
|
||||
canvasImage->BindToRenderSystem();
|
||||
menuItems.push_back(canvasImage);
|
||||
|
||||
std::vector<MenuButton*> menuButtons = {
|
||||
&playButton, &drawerButton, &settingsButton, &quitButton,
|
||||
&sensitivityDown, &sensitivityUp, &fovDown, &fovUp,
|
||||
&hitboxToggle, &graphicsButton, &resetButton, &backButton,
|
||||
&bloomToggle, &shadowToggle, &lightShadowToggle, &vsyncToggle, &cullingToggle,
|
||||
&surfacePrevious, &surfaceNext, &brushDown, &brushUp, &clearButton
|
||||
};
|
||||
for (MenuButton& swatch : swatches)
|
||||
menuButtons.push_back(&swatch);
|
||||
|
||||
TextBox* menuHint = new TextBox();
|
||||
menuHint->font = arial;
|
||||
menuHint->text = "WASD TO MOVE | LEFT CLICK TO PUNCH | ESC FOR MENU";
|
||||
menuHint->fontsize = 0.5f;
|
||||
menuHint->Color = { 0.55f, 0.61f, 0.70f };
|
||||
menuHint->t2d.position = { 0.5f, 0.92f, 0.0f, 0.0f };
|
||||
menuHint->t2d.center = { 0.5f, 0.5f };
|
||||
menuHint->t2d.size = { 0.9f, 0.0f, 0.0f, 40.0f };
|
||||
menuHint->textCenter = { 0.5f, 0.5f };
|
||||
menuHint->fontsize = 0.42f;
|
||||
menuHint->Color = menuMutedText;
|
||||
menuHint->t2d.position = { 0.0f, 1.0f, menuMargin, -28.0f };
|
||||
menuHint->t2d.center = { 0.0f, 1.0f };
|
||||
menuHint->t2d.size = { 0.0f, 0.0f, menuContentWidth, 110.0f };
|
||||
menuHint->textCenter = { 0.0f, 1.0f };
|
||||
menuHint->BindToRenderSystem();
|
||||
menuItems.push_back(menuHint);
|
||||
|
||||
auto SetButtonVisible = [](MenuButton& button, bool visible) {
|
||||
button.box->Opacity = visible ? 0.92f : 0.0f;
|
||||
button.box->Opacity = visible ? button.opacity : 0.0f;
|
||||
button.accent->Opacity = visible ? 1.0f : 0.0f;
|
||||
button.label->Opacity = visible ? 1.0f : 0.0f;
|
||||
};
|
||||
|
||||
@@ -371,38 +471,79 @@ void Engine::Initiate()
|
||||
const bool main = menuScreen == MenuScreen::Main;
|
||||
const bool paused = menuScreen == MenuScreen::Paused;
|
||||
const bool settings = menuScreen == MenuScreen::Settings;
|
||||
const bool graphics = menuScreen == MenuScreen::Graphics;
|
||||
const bool drawer = menuScreen == MenuScreen::Drawer;
|
||||
const bool mainButtons = main || paused;
|
||||
|
||||
menuVeil->Opacity = 0.55f;
|
||||
menuVeil->Opacity = 0.22f;
|
||||
menuPanel->Opacity = 0.82f;
|
||||
menuPanelEdge->Opacity = 1.0f;
|
||||
menuTitle->Opacity = 1.0f;
|
||||
menuSubtitle->Opacity = 1.0f;
|
||||
menuHint->Opacity = 1.0f;
|
||||
menuSubtitle->text = main ? "MAIN MENU" : (paused ? "PAUSED" : "SETTINGS");
|
||||
menuSubtitle->text = main ? "MAIN MENU" : (paused ? "PAUSED"
|
||||
: (drawer ? "TEXTURE DRAWER" : (graphics ? "GRAPHICS" : "SETTINGS")));
|
||||
playButton.label->text = paused ? "RESUME" : "PLAY";
|
||||
quitButton.label->text = paused ? "QUIT TO MENU" : "QUIT";
|
||||
menuHint->text = settings
|
||||
? "ESC TO GO BACK | ADJUST MOUSE, FOV, AND HITBOXES"
|
||||
: "WASD TO MOVE | LEFT CLICK TO PUNCH | ESC FOR MENU";
|
||||
menuHint->text = drawer
|
||||
? "DRAG ON THE CANVAS TO DRAW\nESC TO GO BACK"
|
||||
: (settings || graphics ? "ESC TO GO BACK" : "WASD TO MOVE\nESC FOR MENU");
|
||||
|
||||
SetButtonVisible(playButton, mainButtons);
|
||||
SetButtonVisible(drawerButton, mainButtons);
|
||||
SetButtonVisible(settingsButton, mainButtons);
|
||||
SetButtonVisible(quitButton, mainButtons);
|
||||
SetButtonVisible(surfacePrevious, drawer);
|
||||
SetButtonVisible(surfaceNext, drawer);
|
||||
SetButtonVisible(brushDown, drawer);
|
||||
SetButtonVisible(brushUp, drawer);
|
||||
SetButtonVisible(clearButton, drawer);
|
||||
for (MenuButton& swatch : swatches)
|
||||
SetButtonVisible(swatch, drawer);
|
||||
|
||||
Texture* canvasTexture = drawableSurfaces[selectedSurface].surface->texture;
|
||||
canvasImage->surface = SurfaceTexture::Stretched(canvasTexture);
|
||||
canvasImage->Opacity = drawer && canvasTexture ? 1.0f : 0.0f;
|
||||
canvasBlank->Opacity = drawer ? 1.0f : 0.0f;
|
||||
canvasBorder->Opacity = drawer ? 1.0f : 0.0f;
|
||||
surfaceName->Opacity = drawer ? 1.0f : 0.0f;
|
||||
surfaceName->text = drawableSurfaces[selectedSurface].name;
|
||||
brushLabel->Opacity = drawer ? 1.0f : 0.0f;
|
||||
brushValue->Opacity = drawer ? 1.0f : 0.0f;
|
||||
brushValue->text = std::to_string(painter.brushSize);
|
||||
swatchMarker->Opacity = drawer ? 1.0f : 0.0f;
|
||||
swatchMarker->t2d.position = { 0.0f, 0.5f, menuMargin + swatchSpacing * selectedSwatch, swatchRowY + 28.0f };
|
||||
|
||||
SetButtonVisible(playButton, !settings);
|
||||
SetButtonVisible(settingsButton, !settings);
|
||||
SetButtonVisible(quitButton, !settings);
|
||||
SetButtonVisible(sensitivityDown, settings);
|
||||
SetButtonVisible(sensitivityUp, settings);
|
||||
SetButtonVisible(fovDown, settings);
|
||||
SetButtonVisible(fovUp, settings);
|
||||
SetButtonVisible(hitboxToggle, settings);
|
||||
SetButtonVisible(graphicsButton, settings);
|
||||
SetButtonVisible(resetButton, settings);
|
||||
SetButtonVisible(backButton, settings);
|
||||
settingsInfo->Opacity = settings ? 1.0f : 0.0f;
|
||||
SetButtonVisible(backButton, settings || drawer || graphics);
|
||||
|
||||
auto ShowToggle = [&](MenuButton& button, const char* name, bool enabled) {
|
||||
SetButtonVisible(button, graphics);
|
||||
button.label->text = std::string(name) + (enabled ? ": ON" : ": OFF");
|
||||
button.color = enabled ? glm::vec3(0.82f, 0.45f, 0.10f) : menuButtonColor;
|
||||
};
|
||||
ShowToggle(bloomToggle, "BLOOM", rendersystem->graphics.bloom);
|
||||
ShowToggle(shadowToggle, "SUN SHADOWS", rendersystem->graphics.shadows);
|
||||
ShowToggle(lightShadowToggle, "LIGHT SHADOWS", rendersystem->graphics.lightShadows);
|
||||
ShowToggle(vsyncToggle, "VSYNC", rendersystem->graphics.vsync);
|
||||
ShowToggle(cullingToggle, "CULLING", rendersystem->graphics.culling);
|
||||
|
||||
sensLabel->Opacity = settings ? 1.0f : 0.0f;
|
||||
sensValue->Opacity = settings ? 1.0f : 0.0f;
|
||||
fovLabel->Opacity = settings ? 1.0f : 0.0f;
|
||||
fovValue->Opacity = settings ? 1.0f : 0.0f;
|
||||
|
||||
hitboxToggle.label->text = showHitboxes ? "HITBOXES: ON" : "HITBOXES: OFF";
|
||||
hitboxToggle.color = showHitboxes
|
||||
? glm::vec3(0.12f, 0.30f, 0.22f)
|
||||
: glm::vec3(0.20f, 0.22f, 0.28f);
|
||||
hitboxToggle.color = showHitboxes ? glm::vec3(0.82f, 0.45f, 0.10f) : menuButtonColor;
|
||||
|
||||
settingsInfo->text = "MOUSE SENSITIVITY: " +
|
||||
std::to_string((int)std::lround(StartupCmPer360)) +
|
||||
" CM / 360\nFIELD OF VIEW: " + std::to_string((int)std::lround(camera->FOV));
|
||||
sensValue->text = std::to_string((int)std::lround(StartupCmPer360)) + " CM";
|
||||
fovValue->text = std::to_string((int)std::lround(camera->FOV));
|
||||
};
|
||||
|
||||
auto OpenMenu = [&](MenuScreen screen) {
|
||||
@@ -412,9 +553,6 @@ void Engine::Initiate()
|
||||
testcharacter.SetWalking(false);
|
||||
npc.SetWalking(false);
|
||||
fpsCounter->Opacity = 0.0f;
|
||||
healthText->Opacity = 0.0f;
|
||||
healthBarBack->Opacity = 0.0f;
|
||||
healthBarFill->Opacity = 0.0f;
|
||||
camera->lockedcursor = false;
|
||||
glfwSetInputMode(window->handle, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
prevMouseDown = mouse->IsLeftDown();
|
||||
@@ -425,9 +563,6 @@ void Engine::Initiate()
|
||||
charactermanager->ClearInput();
|
||||
for (Box* item : menuItems) item->Opacity = 0.0f;
|
||||
fpsCounter->Opacity = 1.0f;
|
||||
healthText->Opacity = 1.0f;
|
||||
healthBarBack->Opacity = 0.85f;
|
||||
healthBarFill->Opacity = 1.0f;
|
||||
camera->lockedcursor = true;
|
||||
glfwSetInputMode(window->handle, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||
int ww, wh;
|
||||
@@ -436,9 +571,6 @@ void Engine::Initiate()
|
||||
};
|
||||
|
||||
fpsCounter->Opacity = 0.0f;
|
||||
healthText->Opacity = 0.0f;
|
||||
healthBarBack->Opacity = 0.0f;
|
||||
healthBarFill->Opacity = 0.0f;
|
||||
camera->lockedcursor = false;
|
||||
glfwSetInputMode(window->handle, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
|
||||
@@ -447,9 +579,9 @@ void Engine::Initiate()
|
||||
// ------------------------------------------------------------------------
|
||||
Mesh* floor = CreateCubeMesh();
|
||||
floor->name = "baseplate";
|
||||
floor->meshTexture = blanktex;
|
||||
floor->surface = SurfaceTexture::Tiled(blanktex, 8.0f);
|
||||
floor->roughness = 0.9f;
|
||||
floor->t.ScaleTo({ 32.0f, 2.0f, 32.0f });
|
||||
floor->t.ScaleTo({ 200.0f, 2.0f, 200.0f });
|
||||
floor->t.TranslateTo({ 0.0f, -1.0f, 0.0f });
|
||||
floor->BindToRenderSystem();
|
||||
mainf->AddChild(floor);
|
||||
@@ -459,30 +591,36 @@ void Engine::Initiate()
|
||||
physicsengine->AddObject(floorBody);
|
||||
const BoundingBox floorBounds = floor->t.GetRotationlessAABB();
|
||||
|
||||
const float wallHeight = 4.0f;
|
||||
const float wallThickness = 1.0f;
|
||||
const float wallOffset = 16.0f + wallThickness * 0.5f;
|
||||
const float wallSpan = 32.0f + wallThickness;
|
||||
|
||||
auto AddWall = [&](const char* name, const glm::vec3& position, const glm::vec3& scale) {
|
||||
Mesh* wall = CreateCubeMesh();
|
||||
wall->name = name;
|
||||
wall->meshTexture = blanktex;
|
||||
wall->roughness = 0.9f;
|
||||
wall->t.ScaleTo(scale);
|
||||
wall->t.TranslateTo(position);
|
||||
wall->BindToRenderSystem();
|
||||
mainf->AddChild(wall);
|
||||
|
||||
p* wallBody = new p(wall);
|
||||
wallBody->velocity = false;
|
||||
physicsengine->AddObject(wallBody);
|
||||
// ------------------------------------------------------------------------
|
||||
// Light cubes
|
||||
// ------------------------------------------------------------------------
|
||||
auto AddLightCube = [&](const char* name, const glm::vec3& position, float size, const glm::vec3& color) -> Mesh* {
|
||||
Mesh* cube = CreateCubeMesh();
|
||||
cube->name = name;
|
||||
cube->colorOverride = glm::vec4(color, 1.0f);
|
||||
cube->emissive = 1.0f;
|
||||
cube->t.ScaleTo(size);
|
||||
cube->t.TranslateTo(position);
|
||||
cube->BindToRenderSystem();
|
||||
mainf->AddChild(cube);
|
||||
return cube;
|
||||
};
|
||||
|
||||
AddWall("wall_north", { 0.0f, wallHeight * 0.5f, -wallOffset }, { wallSpan, wallHeight, wallThickness });
|
||||
AddWall("wall_south", { 0.0f, wallHeight * 0.5f, wallOffset }, { wallSpan, wallHeight, wallThickness });
|
||||
AddWall("wall_west", { -wallOffset, wallHeight * 0.5f, 0.0f }, { wallThickness, wallHeight, 32.0f });
|
||||
AddWall("wall_east", { wallOffset, wallHeight * 0.5f, 0.0f }, { wallThickness, wallHeight, 32.0f });
|
||||
const glm::vec3 skyLightColor(0.45f, 0.65f, 1.0f);
|
||||
const glm::vec3 skyLightPosition(-6.0f, 7.0f, -6.0f);
|
||||
Mesh* skyLightCube = AddLightCube("spot_light_cube", skyLightPosition, 1.5f, skyLightColor);
|
||||
rendersystem->lighting->AddSpotLight(skyLightPosition, { 0.0f, -1.0f, 0.0f }, skyLightColor, 1200.0f, 25.0f, 18.0f, 26.0f);
|
||||
|
||||
const glm::vec3 pointLightPosition(6.0f, 3.0f, -6.0f);
|
||||
const glm::vec3 pointLightColor(1.0f, 0.35f, 0.05f);
|
||||
Mesh* pointLightCube = AddLightCube("point_light_cube", pointLightPosition, 0.8f, pointLightColor);
|
||||
rendersystem->lighting->AddPointLight(pointLightPosition, pointLightColor, 300.0f, 30.0f);
|
||||
|
||||
drawableSurfaces.push_back({ "BASEPLATE", &floor->surface, &floor->colorOverride });
|
||||
drawableSurfaces.push_back({ "PLAYER", &testcharacter.surface, &testcharacter.colorOverride });
|
||||
drawableSurfaces.push_back({ "DUMMY", &npc.surface, &npc.colorOverride });
|
||||
drawableSurfaces.push_back({ "SKY LIGHT CUBE", &skyLightCube->surface, &skyLightCube->colorOverride });
|
||||
drawableSurfaces.push_back({ "POINT LIGHT CUBE", &pointLightCube->surface, &pointLightCube->colorOverride });
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Ground check + respawn
|
||||
@@ -515,10 +653,12 @@ void Engine::Initiate()
|
||||
if (showHitboxes) {
|
||||
for (Character* character : charactermanager->GetCharacters()) {
|
||||
if (!character->body) continue;
|
||||
if (character->ragdoll) {
|
||||
for (Ragdoll::Part* part : character->ragdoll->GetParts())
|
||||
lines.push_back({ part->transform.t.GetMatrix(), glm::vec3(0.2f, 0.9f, 0.35f) });
|
||||
continue;
|
||||
}
|
||||
lines.push_back({ character->body->t.GetMatrix(), glm::vec3(0.2f, 0.9f, 0.35f) });
|
||||
const Hitbox& punch = character->GetPunchHitbox();
|
||||
if (punch.active)
|
||||
lines.push_back({ punch.transform.GetMatrix(), glm::vec3(1.0f, 0.25f, 0.1f) });
|
||||
}
|
||||
}
|
||||
rendersystem->SetHitboxDebugLines(lines);
|
||||
@@ -545,8 +685,10 @@ void Engine::Initiate()
|
||||
if (escapePressed) {
|
||||
if (!menuActive)
|
||||
OpenMenu(MenuScreen::Paused);
|
||||
else if (menuScreen == MenuScreen::Settings)
|
||||
else if (menuScreen == MenuScreen::Settings || menuScreen == MenuScreen::Drawer)
|
||||
menuScreen = settingsReturn;
|
||||
else if (menuScreen == MenuScreen::Graphics)
|
||||
menuScreen = MenuScreen::Settings;
|
||||
else if (menuScreen == MenuScreen::Paused)
|
||||
ResumeGame();
|
||||
}
|
||||
@@ -561,9 +703,6 @@ void Engine::Initiate()
|
||||
float yoffset = mouse->GetLastY() - mouse->GetY();
|
||||
camera->ProcessMouseMovement(xoffset, yoffset);
|
||||
}
|
||||
else if (buffer.GetType() == Mouse::Event::Type::LPress) {
|
||||
testcharacter.Punch(camera->t.GetFrontVector());
|
||||
}
|
||||
else if (buffer.GetType() == Mouse::Event::Type::RPress) {
|
||||
camera->lockedcursor = !camera->lockedcursor;
|
||||
if (camera->lockedcursor) {
|
||||
@@ -582,7 +721,8 @@ void Engine::Initiate()
|
||||
ApplyMenuLayout();
|
||||
|
||||
const bool liveBackdrop = menuScreen == MenuScreen::Main ||
|
||||
(menuScreen == MenuScreen::Settings && settingsReturn == MenuScreen::Main);
|
||||
((menuScreen == MenuScreen::Settings || menuScreen == MenuScreen::Graphics || menuScreen == MenuScreen::Drawer)
|
||||
&& settingsReturn == MenuScreen::Main);
|
||||
if (liveBackdrop) {
|
||||
static float menuAngle = 0.6f;
|
||||
menuAngle += deltatime * 0.12f;
|
||||
@@ -593,11 +733,7 @@ void Engine::Initiate()
|
||||
camera->t.RotateToQuaternion(LookAt(menuTarget - menuCamera));
|
||||
camera->Step(deltatime);
|
||||
|
||||
npc.SetTurnDirection(testcharacter.body->t.GetTranslation() -
|
||||
npc.body->t.GetTranslation());
|
||||
charactermanager->Step(deltatime);
|
||||
rain->t.TranslateTo(camera->t.GetTranslation() + glm::vec3(0.0f, 20.0f, 0.0f));
|
||||
rain->Step(deltatime);
|
||||
}
|
||||
|
||||
soundsystem->SetListenerPosition(
|
||||
@@ -607,89 +743,146 @@ void Engine::Initiate()
|
||||
);
|
||||
soundsystem->Update();
|
||||
|
||||
MenuButton* buttons[] = {
|
||||
&playButton, &settingsButton, &quitButton,
|
||||
&sensitivityDown, &sensitivityUp, &fovDown, &fovUp,
|
||||
&hitboxToggle, &resetButton, &backButton
|
||||
};
|
||||
for (MenuButton* button : buttons)
|
||||
button->box->t2d.Recalculate();
|
||||
|
||||
const glm::vec2 mousePos((float)mouse->GetX(), (float)mouse->GetY());
|
||||
auto Hovered = [&](const MenuButton& button) {
|
||||
return mousePos.x > button.box->t2d.pixelposition.x &&
|
||||
mousePos.y > button.box->t2d.pixelposition.y &&
|
||||
mousePos.x < button.box->t2d.pixelposition.x + button.box->t2d.pixelsize.x &&
|
||||
mousePos.y < button.box->t2d.pixelposition.y + button.box->t2d.pixelsize.y;
|
||||
};
|
||||
const float hoverEase = 1.0f - std::exp(-12.0f * deltatime);
|
||||
|
||||
const bool playHovered = Hovered(playButton);
|
||||
const bool settingsHovered = Hovered(settingsButton);
|
||||
const bool quitHovered = Hovered(quitButton);
|
||||
const bool sensDownHovered = Hovered(sensitivityDown);
|
||||
const bool sensUpHovered = Hovered(sensitivityUp);
|
||||
const bool fovDownHovered = Hovered(fovDown);
|
||||
const bool fovUpHovered = Hovered(fovUp);
|
||||
const bool hitboxHovered = Hovered(hitboxToggle);
|
||||
const bool resetHovered = Hovered(resetButton);
|
||||
const bool backHovered = Hovered(backButton);
|
||||
for (MenuButton* button : menuButtons) {
|
||||
t2d_package& t2d = button->box->t2d;
|
||||
t2d.Recalculate();
|
||||
button->hovered = button->box->Opacity > 0.0f &&
|
||||
mousePos.x > t2d.pixelposition.x &&
|
||||
mousePos.y > t2d.pixelposition.y &&
|
||||
mousePos.x < t2d.pixelposition.x + t2d.pixelsize.x &&
|
||||
mousePos.y < t2d.pixelposition.y + t2d.pixelsize.y;
|
||||
|
||||
playButton.box->Color = playHovered ? glm::vec3(0.18f, 0.44f, 0.32f) : playButton.color;
|
||||
settingsButton.box->Color = settingsHovered ? glm::vec3(0.22f, 0.34f, 0.50f) : settingsButton.color;
|
||||
quitButton.box->Color = quitHovered ? glm::vec3(0.30f, 0.20f, 0.22f) : quitButton.color;
|
||||
sensitivityDown.box->Color = sensDownHovered ? glm::vec3(0.22f, 0.34f, 0.50f) : sensitivityDown.color;
|
||||
sensitivityUp.box->Color = sensUpHovered ? glm::vec3(0.22f, 0.34f, 0.50f) : sensitivityUp.color;
|
||||
fovDown.box->Color = fovDownHovered ? glm::vec3(0.22f, 0.34f, 0.50f) : fovDown.color;
|
||||
fovUp.box->Color = fovUpHovered ? glm::vec3(0.22f, 0.34f, 0.50f) : fovUp.color;
|
||||
hitboxToggle.box->Color = hitboxHovered ? glm::vec3(0.22f, 0.34f, 0.50f) : hitboxToggle.color;
|
||||
resetButton.box->Color = resetHovered ? glm::vec3(0.30f, 0.32f, 0.40f) : resetButton.color;
|
||||
backButton.box->Color = backHovered ? glm::vec3(0.18f, 0.44f, 0.32f) : backButton.color;
|
||||
button->hover += ((button->hovered ? 1.0f : 0.0f) - button->hover) * hoverEase;
|
||||
button->box->Color = glm::mix(button->color, button->hoverColor, button->hover);
|
||||
button->accent->t2d.size.z = 5.0f * button->hover;
|
||||
button->label->t2d.position.z = button->labelX + button->labelSlide * button->hover;
|
||||
}
|
||||
|
||||
const bool mouseDown = mouse->IsLeftDown();
|
||||
if (mouseDown && !prevMouseDown) {
|
||||
if (menuScreen == MenuScreen::Settings) {
|
||||
if (sensDownHovered) {
|
||||
if (sensitivityDown.hovered) {
|
||||
StartupCmPer360 = glm::clamp(StartupCmPer360 + 2.0f, 4.0f, 80.0f);
|
||||
camera->SetSensitivityCm(StartupCmPer360, StartupMouseDpi);
|
||||
}
|
||||
else if (sensUpHovered) {
|
||||
else if (sensitivityUp.hovered) {
|
||||
StartupCmPer360 = glm::clamp(StartupCmPer360 - 2.0f, 4.0f, 80.0f);
|
||||
camera->SetSensitivityCm(StartupCmPer360, StartupMouseDpi);
|
||||
}
|
||||
else if (fovDownHovered) {
|
||||
else if (fovDown.hovered) {
|
||||
camera->FOV = glm::clamp(camera->FOV - 5.0f, 60.0f, 130.0f);
|
||||
}
|
||||
else if (fovUpHovered) {
|
||||
else if (fovUp.hovered) {
|
||||
camera->FOV = glm::clamp(camera->FOV + 5.0f, 60.0f, 130.0f);
|
||||
}
|
||||
else if (hitboxHovered) {
|
||||
else if (hitboxToggle.hovered) {
|
||||
showHitboxes = !showHitboxes;
|
||||
}
|
||||
else if (resetHovered) {
|
||||
else if (graphicsButton.hovered) {
|
||||
menuScreen = MenuScreen::Graphics;
|
||||
}
|
||||
else if (resetButton.hovered) {
|
||||
StartupCmPer360 = 16.0f;
|
||||
StartupMouseDpi = 800.0f;
|
||||
camera->SetSensitivityCm(StartupCmPer360, StartupMouseDpi);
|
||||
camera->FOV = 110.0f;
|
||||
showHitboxes = false;
|
||||
}
|
||||
else if (backHovered) {
|
||||
else if (backButton.hovered) {
|
||||
menuScreen = settingsReturn;
|
||||
}
|
||||
}
|
||||
else if (playHovered) {
|
||||
else if (menuScreen == MenuScreen::Graphics) {
|
||||
GraphicsSettings& graphics = rendersystem->graphics;
|
||||
if (bloomToggle.hovered) {
|
||||
graphics.bloom = !graphics.bloom;
|
||||
}
|
||||
else if (shadowToggle.hovered) {
|
||||
graphics.shadows = !graphics.shadows;
|
||||
}
|
||||
else if (lightShadowToggle.hovered) {
|
||||
graphics.lightShadows = !graphics.lightShadows;
|
||||
}
|
||||
else if (vsyncToggle.hovered) {
|
||||
graphics.vsync = !graphics.vsync;
|
||||
glfwSwapInterval(graphics.vsync ? 1 : 0);
|
||||
}
|
||||
else if (cullingToggle.hovered) {
|
||||
graphics.culling = !graphics.culling;
|
||||
}
|
||||
else if (backButton.hovered) {
|
||||
menuScreen = MenuScreen::Settings;
|
||||
}
|
||||
}
|
||||
else if (menuScreen == MenuScreen::Drawer) {
|
||||
const int surfaceCount = (int)drawableSurfaces.size();
|
||||
if (surfacePrevious.hovered) {
|
||||
selectedSurface = (selectedSurface + surfaceCount - 1) % surfaceCount;
|
||||
}
|
||||
else if (surfaceNext.hovered) {
|
||||
selectedSurface = (selectedSurface + 1) % surfaceCount;
|
||||
}
|
||||
else if (brushDown.hovered) {
|
||||
painter.brushSize = glm::max(painter.brushSize - 2, 2);
|
||||
}
|
||||
else if (brushUp.hovered) {
|
||||
painter.brushSize = glm::min(painter.brushSize + 2, 64);
|
||||
}
|
||||
else if (clearButton.hovered) {
|
||||
DrawableSurface& drawable = drawableSurfaces[selectedSurface];
|
||||
EnsureCanvas(drawable);
|
||||
painter.Clear(*drawable.surface->texture);
|
||||
}
|
||||
else if (backButton.hovered) {
|
||||
menuScreen = settingsReturn;
|
||||
}
|
||||
for (int i = 0; i < (int)swatches.size(); i++) {
|
||||
if (swatches[i].hovered) {
|
||||
selectedSwatch = i;
|
||||
painter.color = swatchColors[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (playButton.hovered) {
|
||||
ResumeGame();
|
||||
}
|
||||
else if (settingsHovered) {
|
||||
else if (drawerButton.hovered) {
|
||||
settingsReturn = menuScreen;
|
||||
menuScreen = MenuScreen::Drawer;
|
||||
}
|
||||
else if (settingsButton.hovered) {
|
||||
settingsReturn = menuScreen;
|
||||
menuScreen = MenuScreen::Settings;
|
||||
}
|
||||
else if (quitHovered) {
|
||||
else if (quitButton.hovered) {
|
||||
if (menuScreen == MenuScreen::Main)
|
||||
glfwSetWindowShouldClose(window->handle, 1);
|
||||
else
|
||||
menuScreen = MenuScreen::Main;
|
||||
}
|
||||
}
|
||||
// A stroke has to start on the canvas, but carries on if the mouse wanders off it
|
||||
canvasImage->t2d.Recalculate();
|
||||
const glm::vec2 canvasUV = (mousePos - canvasImage->t2d.pixelposition) / canvasImage->t2d.pixelsize;
|
||||
if (!mouseDown || menuScreen != MenuScreen::Drawer) {
|
||||
painting = false;
|
||||
}
|
||||
else if (!prevMouseDown) {
|
||||
painting = canvasUV.x >= 0.0f && canvasUV.x <= 1.0f && canvasUV.y >= 0.0f && canvasUV.y <= 1.0f;
|
||||
}
|
||||
|
||||
if (painting) {
|
||||
DrawableSurface& drawable = drawableSurfaces[selectedSurface];
|
||||
EnsureCanvas(drawable);
|
||||
painter.Stroke(*drawable.surface->texture, glm::clamp(canvasUV, glm::vec2(0.0f), glm::vec2(1.0f)));
|
||||
}
|
||||
else {
|
||||
painter.EndStroke();
|
||||
}
|
||||
|
||||
prevMouseDown = mouseDown;
|
||||
|
||||
UpdateHitboxDebug();
|
||||
@@ -712,11 +905,6 @@ void Engine::Initiate()
|
||||
testcharacter.SetTurnDirection(inputDirection);
|
||||
testcharacter.SetWalking(hasMoveInput);
|
||||
|
||||
const glm::vec3 npcVelocity(npcBody->linearvelocity.x, 0.0f, npcBody->linearvelocity.z);
|
||||
npc.SetWalking(glm::length(npcVelocity) > 0.1f);
|
||||
npc.SetTurnDirection(testcharacter.body->t.GetTranslation() -
|
||||
npc.body->t.GetTranslation());
|
||||
|
||||
charactermanager->Step(deltatime);
|
||||
|
||||
const glm::vec3 inputVel = hasMoveInput
|
||||
@@ -746,13 +934,12 @@ void Engine::Initiate()
|
||||
characterBody->linearvelocity.z += wishDir.z * add;
|
||||
}
|
||||
|
||||
charactermanager->ResolveCombat(*physicsengine);
|
||||
|
||||
{
|
||||
const int substeps = std::max(1, (int)std::ceil(deltatime * 120.0f));
|
||||
const float subDt = deltatime / float(substeps);
|
||||
for (int i = 0; i < substeps; i++) physicsengine->Step(subDt);
|
||||
}
|
||||
npc.ragdoll->Update(deltatime);
|
||||
|
||||
if (testcharacter.body->t.GetTranslation().y < -20.0f) {
|
||||
testcharacter.body->t.TranslateTo(RandomSpawn());
|
||||
@@ -784,6 +971,8 @@ void Engine::Initiate()
|
||||
for (p* obj : physicsengine->GetObjects()) {
|
||||
if (obj->pointer == testcharacter.body || !obj->collision)
|
||||
continue;
|
||||
if (obj->collisionGroup != 0) // flailing ragdoll limbs would make the camera jump
|
||||
continue;
|
||||
if (obj == floorBody && ignoreFloorCollision)
|
||||
continue;
|
||||
auto hit = IsRayInT(cameraSweep, obj->pointer->t);
|
||||
@@ -800,9 +989,6 @@ void Engine::Initiate()
|
||||
}
|
||||
camera->Step(deltatime);
|
||||
|
||||
rain->t.TranslateTo(camera->t.GetTranslation() + glm::vec3(0.0f, 20.0f, 0.0f));
|
||||
rain->Step(deltatime);
|
||||
|
||||
Sound* music = static_cast<Sound*>(mainf->GetFirstChildOfName("music"));
|
||||
if (music) music->Update3DPosition(0.0f, 0.0f, 0.0f);
|
||||
|
||||
@@ -833,14 +1019,6 @@ void Engine::Initiate()
|
||||
fpsCounter->text = std::to_string(measuredFps) + " FPS";
|
||||
}
|
||||
|
||||
healthText->text = "PLAYER " + std::to_string((int)std::lround(testcharacter.body->Health)) +
|
||||
" HP DUMMY " + std::to_string((int)std::lround(npc.body->Health)) + " HP";
|
||||
|
||||
const float healthRatio = glm::clamp((float)testcharacter.body->Health / 100.0f, 0.0f, 1.0f);
|
||||
healthBarFill->t2d.size.z = healthBarFillWidth * healthRatio;
|
||||
healthBarFill->Color = glm::mix(glm::vec3(0.85f, 0.20f, 0.12f),
|
||||
glm::vec3(0.20f, 0.85f, 0.35f), healthRatio);
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Render
|
||||
// --------------------------------------------------------------------
|
||||
@@ -878,9 +1056,12 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod
|
||||
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
|
||||
glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate);
|
||||
}
|
||||
glfwSwapInterval(1);
|
||||
glfwSwapInterval(engine && engine->rendersystem && !engine->rendersystem->graphics.vsync ? 0 : 1);
|
||||
}
|
||||
|
||||
if (key == GLFW_KEY_H && action == GLFW_PRESS && engine && engine->rendersystem)
|
||||
engine->rendersystem->CycleDebugView();
|
||||
|
||||
if (action == GLFW_PRESS) keyboard->KeyDown(key);
|
||||
else if (action == GLFW_RELEASE) keyboard->KeyUp(key);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user