Working on fixing minor bugs

This commit is contained in:
Vladislav Khorev committed 2026-03-05 23:58:35 +03:00
1 parent e84a094ad9
commit a8c76dee3c
32 files changed
+288 -110

No files matched your search

-24
View File
@@ -17,23 +17,10 @@
width: 100vw; height: 100vh; width: 100vw; height: 100vh;
border: none; border: none;
} }
/* Кнопка Fullscreen */
#fs-button {
position: absolute;
top: 10px; right: 10px;
padding: 10px;
z-index: 10;
background: rgba(255,255,255,0.3);
color: white; border: 1px solid white;
cursor: pointer;
font-family: sans-serif;
border-radius: 5px;
}
#status { color: white; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); } #status { color: white; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); }
</style> </style>
</head> </head>
<body> <body>
<button id="fs-button">Fullscreen</button>
<div id="status">Downloading...</div> <div id="status">Downloading...</div>
<canvas id="canvas" oncontextmenu="event.preventDefault()" tabindex="-1"></canvas> <canvas id="canvas" oncontextmenu="event.preventDefault()" tabindex="-1"></canvas>
@@ -49,17 +36,6 @@
} }
}; };
// Кнопка Fullscreen
document.getElementById('fs-button').addEventListener('click', function() {
if (!document.fullscreenElement) {
document.documentElement.requestFullscreen().catch(e => {
console.error(`Error attempting to enable full-screen mode: ${e.message}`);
});
} else {
document.exitFullscreen();
}
});
// Обработка ориентации // Обработка ориентации
window.addEventListener("orientationchange", function() { window.addEventListener("orientationchange", function() {
// Chrome на Android обновляет innerWidth/Height не мгновенно. // Chrome на Android обновляет innerWidth/Height не мгновенно.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+3 -3
View File
@@ -1,14 +1,14 @@
{ {
"emissionRate": 100.0, "emissionRate": 10.0,
"maxParticles": 200, "maxParticles": 200,
"particleSize": 0.3, "particleSize": 0.3,
"biasX": 0.3, "biasX": 0.3,
"emissionPoints": [ "emissionPoints": [
{ {
"position": [-1.3, 0, 0.0] "position": [-1.0, 1.4, -3.5]
}, },
{ {
"position": [1.3, 0.0, 0.0] "position": [1.0, 1.4, -3.5]
} }
], ],
"speedRange": [0.5, 2.0], "speedRange": [0.5, 2.0],
+20
View File
@@ -0,0 +1,20 @@
{
"emissionRate": 10.0,
"maxParticles": 200,
"particleSize": 0.3,
"biasX": 0.3,
"emissionPoints": [
{
"position": [0.0, 2.8, -3.5]
},
{
"position": [0.0, 1.5, -3.5]
}
],
"speedRange": [0.5, 2.0],
"zSpeedRange": [1.0, 3.0],
"scaleRange": [0.8, 1.2],
"lifeTimeRange": [600.0, 1400.0],
"texture": "resources/spark.png",
"shaderProgramName": "spark"
}
@@ -2,14 +2,14 @@
"emissionPoints": [ "emissionPoints": [
{ "position": [0.0, 0.0, 0.0] } { "position": [0.0, 0.0, 0.0] }
], ],
"texture": "resources/spark_white.png", "texture": "resources/spark2.png",
"speedRange": [10.0, 30.0], "speedRange": [5.0, 10.0],
"zSpeedRange": [-1.0, 1.0], "zSpeedRange": [-1.0, 1.0],
"scaleRange": [0.5, 1.0], "scaleRange": [0.5, 2.0],
"lifeTimeRange": [200.0, 800.0], "lifeTimeRange": [200.0, 800.0],
"emissionRate": 50.0, "emissionRate": 30.0,
"maxParticles": 10, "maxParticles": 150,
"particleSize": 0.5, "particleSize": 1.0,
"biasX": 0.1, "biasX": 0.1,
"shaderProgramName": "default" "shaderProgramName": "default"
} }
+44 -12
View File
@@ -6,6 +6,20 @@
"width": "match_parent", "width": "match_parent",
"height": "match_parent", "height": "match_parent",
"children": [ "children": [
{
"type": "TextView",
"name": "velocityText",
"x": 10,
"y": 10,
"width": 200,
"height": 40,
"horizontal_gravity": "left",
"vertical_gravity": "top",
"text": "Velocity: 0",
"fontSize": 24,
"color": [1.0, 1.0, 1.0, 1.0],
"centered": false
},
{ {
"type": "Button", "type": "Button",
"name": "shootButton", "name": "shootButton",
@@ -18,7 +32,8 @@
"textures": { "textures": {
"normal": "resources/fire.png", "normal": "resources/fire.png",
"hover": "resources/fire2.png", "hover": "resources/fire2.png",
"pressed": "resources/fire.png" "pressed": "resources/fire2.png",
"disabled": "resources/fire_disabled.png"
} }
}, },
{ {
@@ -33,23 +48,40 @@
"textures": { "textures": {
"normal": "resources/fire.png", "normal": "resources/fire.png",
"hover": "resources/fire2.png", "hover": "resources/fire2.png",
"pressed": "resources/fire.png" "pressed": "resources/fire2.png",
"disabled": "resources/fire_disabled.png"
} }
}, },
{ {
"type": "Slider", "type": "Button",
"name": "velocitySlider", "name": "minusButton",
"x": 10, "x": -20,
"y": 200, "y": 110,
"width": 80, "width": 150,
"height": 300, "height": 150,
"value": 0.0, "border" : 20,
"orientation": "vertical",
"horizontal_gravity": "right", "horizontal_gravity": "right",
"vertical_gravity": "bottom", "vertical_gravity": "bottom",
"textures": { "textures": {
"track": "resources/velocitySliderTexture.png", "normal": "resources/button_minus.png",
"knob": "resources/velocitySliderButton.png" "hover": "resources/button_minus_pressed.png",
"pressed": "resources/button_minus_pressed.png"
}
},
{
"type": "Button",
"name": "plusButton",
"x": -20,
"y": 220,
"width": 150,
"height": 150,
"border" : 20,
"horizontal_gravity": "right",
"vertical_gravity": "bottom",
"textures": {
"normal": "resources/button_plus.png",
"hover": "resources/button_plus_pressed.png",
"pressed": "resources/button_plus_pressed.png"
} }
} }
] ]
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+12
View File
@@ -150,6 +150,18 @@ namespace ZL
Environment::shipState.nickname = nickname; Environment::shipState.nickname = nickname;
Environment::shipState.shipType = shipType; Environment::shipState.shipType = shipType;
if (Environment::shipState.shipType == 1)
{
menuManager.uiManager.findButton("shootButton")->state = ButtonState::Disabled;
menuManager.uiManager.findButton("shootButton2")->state = ButtonState::Disabled;
}
else
{
menuManager.uiManager.findButton("shootButton")->state = ButtonState::Normal;
menuManager.uiManager.findButton("shootButton2")->state = ButtonState::Normal;
}
auto localClient = new LocalClient; auto localClient = new LocalClient;
ClientState st = Environment::shipState; ClientState st = Environment::shipState;
st.id = localClient->GetClientId(); st.id = localClient->GetClientId();
+16
View File
@@ -103,6 +103,22 @@ namespace ZL {
uiManager.setButtonCallback("shootButton2", [this](const std::string& name) { uiManager.setButtonCallback("shootButton2", [this](const std::string& name) {
onFirePressed(); onFirePressed();
}); });
uiManager.setButtonCallback("plusButton", [this](const std::string& name) {
int newVel = Environment::shipState.selectedVelocity+1;
if (newVel > 4)
{
newVel = 4;
}
onVelocityChanged(newVel);
});
uiManager.setButtonCallback("minusButton", [this](const std::string& name) {
int newVel = Environment::shipState.selectedVelocity-1;
if (newVel < 0)
{
newVel = 0;
}
onVelocityChanged(newVel);
});
uiManager.setSliderCallback("velocitySlider", [this](const std::string& name, float value) { uiManager.setSliderCallback("velocitySlider", [this](const std::string& name, float value) {
int newVel = roundf(value * 10); int newVel = roundf(value * 10);
+1 -1
View File
@@ -1,4 +1,4 @@
#include "Projectile.h" #include "Projectile.h"
namespace ZL { namespace ZL {
+1 -1
View File
@@ -1,4 +1,4 @@
#pragma once #pragma once
#include "render/Renderer.h" #include "render/Renderer.h"
#include "render/TextureManager.h" #include "render/TextureManager.h"
+64 -15
View File
@@ -282,6 +282,20 @@ namespace ZL
menuManager.onVelocityChanged = [this](float newVelocity) { menuManager.onVelocityChanged = [this](float newVelocity) {
newShipVelocity = newVelocity; newShipVelocity = newVelocity;
if (Environment::shipState.shipType == 0)
{
if (newVelocity > 2)
{
this->menuManager.uiManager.findButton("shootButton")->state = ButtonState::Disabled;
this->menuManager.uiManager.findButton("shootButton2")->state = ButtonState::Disabled;
}
else
{
this->menuManager.uiManager.findButton("shootButton")->state = ButtonState::Normal;
this->menuManager.uiManager.findButton("shootButton2")->state = ButtonState::Normal;
}
}
}; };
menuManager.onFirePressed = [this]() { menuManager.onFirePressed = [this]() {
@@ -289,10 +303,13 @@ namespace ZL
}; };
bool cfgLoaded = sparkEmitter.loadFromJsonFile("resources/config/spark_config.json", renderer, CONST_ZIP_FILE); bool cfgLoaded = sparkEmitter.loadFromJsonFile("resources/config/spark_config.json", renderer, CONST_ZIP_FILE);
bool cfgLoaded2 = sparkEmitterCargo.loadFromJsonFile("resources/config/spark_config_cargo.json", renderer, CONST_ZIP_FILE);
bool projCfgLoaded = projectileEmitter.loadFromJsonFile("resources/config/spark_projectile_config.json", renderer, CONST_ZIP_FILE); bool projCfgLoaded = projectileEmitter.loadFromJsonFile("resources/config/spark_projectile_config.json", renderer, CONST_ZIP_FILE);
bool explosionCfgLoaded = explosionEmitter.loadFromJsonFile("resources/config/explosion_config.json", renderer, CONST_ZIP_FILE); bool explosionCfgLoaded = explosionEmitter.loadFromJsonFile("resources/config/explosion_config.json", renderer, CONST_ZIP_FILE);
explosionEmitter.setEmissionPoints(std::vector<Vector3f>()); explosionEmitter.setEmissionPoints(std::vector<Vector3f>());
projectileEmitter.setEmissionPoints(std::vector<Vector3f>()); //projectileEmitter.setEmissionPoints({ Vector3f{0,0,45000} });
//projectileEmitter.setUseWorldSpace(true);
cubemapTexture = std::make_shared<Texture>( cubemapTexture = std::make_shared<Texture>(
std::array<TextureDataStruct, 6>{ std::array<TextureDataStruct, 6>{
@@ -315,7 +332,9 @@ namespace ZL
spaceshipBase = LoadFromTextFile02("resources/spaceshipnew001.txt", CONST_ZIP_FILE); spaceshipBase = LoadFromTextFile02("resources/spaceshipnew001.txt", CONST_ZIP_FILE);
spaceshipBase.RotateByMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(M_PI, Eigen::Vector3f::UnitY())).toRotationMatrix());// QuatFromRotateAroundY(M_PI / 2.0).toRotationMatrix()); spaceshipBase.RotateByMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(M_PI, Eigen::Vector3f::UnitY())).toRotationMatrix());// QuatFromRotateAroundY(M_PI / 2.0).toRotationMatrix());
spaceshipBase.Move(Vector3f{ 1.2, 0, -5 }); spaceshipBase.Move(Vector3f{ 1.2, 0, -5 });
spaceshipBase.Scale(0.4f);
spaceship.AssignFrom(spaceshipBase); spaceship.AssignFrom(spaceshipBase);
spaceship.RefreshVBO(); spaceship.RefreshVBO();
@@ -501,12 +520,18 @@ namespace ZL
renderer.EnableVertexAttribArray(vTexCoordName); renderer.EnableVertexAttribArray(vTexCoordName);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE); glBlendFunc(GL_SRC_ALPHA, GL_ONE);
renderer.PushMatrix();
renderer.LoadIdentity();
renderer.TranslateMatrix({ 0,0, -1.0f * Environment::zoom });
renderer.RotateMatrix(Environment::inverseShipMatrix);
renderer.TranslateMatrix(-Environment::shipState.position);
for (const auto& p : projectiles) { for (const auto& p : projectiles) {
if (p && p->isActive()) { if (p && p->isActive()) {
p->draw(renderer); //p->draw(renderer);
p->projectileEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height); p->projectileEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height);
} }
} }
renderer.PopMatrix();
glDisable(GL_BLEND); glDisable(GL_BLEND);
renderer.DisableVertexAttribArray(vPositionName); renderer.DisableVertexAttribArray(vPositionName);
@@ -519,12 +544,17 @@ namespace ZL
renderer.PushMatrix(); renderer.PushMatrix();
renderer.TranslateMatrix({ 0, 0, 16 }); renderer.TranslateMatrix({ 0, 0, 16 });
renderer.TranslateMatrix({ 0, -6.f, 0 }); renderer.TranslateMatrix({ 0, -6.f, 0 });
sparkEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height); if (Environment::shipState.shipType == 1) {
sparkEmitterCargo.draw(renderer, Environment::zoom, Environment::width, Environment::height, false);
}
else {
sparkEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height, false);
}
renderer.PopMatrix(); renderer.PopMatrix();
} }
if (showExplosion) { if (showExplosion) {
explosionEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height); explosionEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height, false);
} }
//glBindTexture(GL_TEXTURE_2D, basePlatformTexture->getTexID()); //glBindTexture(GL_TEXTURE_2D, basePlatformTexture->getTexID());
@@ -1450,7 +1480,17 @@ namespace ZL
auto now_ms = newTickCount; auto now_ms = newTickCount;
sparkEmitter.update(static_cast<float>(delta)); SparkEmitter* sparkEmitterPtr;
if (Environment::shipState.shipType == 1) {
sparkEmitterPtr = &sparkEmitterCargo;
}
else
{
sparkEmitterPtr = &sparkEmitter;
}
sparkEmitterPtr->update(static_cast<float>(delta));
planetObject.update(static_cast<float>(delta)); planetObject.update(static_cast<float>(delta));
if (firePressed) if (firePressed)
@@ -1594,9 +1634,9 @@ namespace ZL
for (const auto& p : projectiles) { for (const auto& p : projectiles) {
if (p && p->isActive()) { if (p && p->isActive()) {
Vector3f worldPos = p->getPosition(); Vector3f worldPos = p->getPosition();
Vector3f rel = worldPos - Environment::shipState.position; //Vector3f rel = worldPos - Environment::shipState.position;
Vector3f camPos = Environment::inverseShipMatrix * rel; //Vector3f camPos = Environment::inverseShipMatrix * rel;
p->projectileEmitter.setEmissionPoints({ camPos }); p->projectileEmitter.setEmissionPoints({ worldPos });
p->projectileEmitter.emit(); p->projectileEmitter.emit();
p->projectileEmitter.update(static_cast<float>(delta)); p->projectileEmitter.update(static_cast<float>(delta));
} }
@@ -1610,16 +1650,25 @@ namespace ZL
projectileEmitter.setEmissionPoints(std::vector<Vector3f>()); projectileEmitter.setEmissionPoints(std::vector<Vector3f>());
}*/ }*/
std::vector<Vector3f> shipCameraPoints; if (Environment::shipState.velocity > 0.1f) {
for (const auto& lp : shipLocalEmissionPoints) {
Vector3f adjusted = lp + Vector3f{ 0.0f, -Environment::zoom * 0.03f, 0.0f }; sparkEmitterPtr->setIsActive(true);
shipCameraPoints.push_back(adjusted);
std::vector<Vector3f> shipCameraPoints;
for (const auto& lp : shipLocalEmissionPoints) {
Vector3f adjusted = lp + Vector3f{ 0.0f, -Environment::zoom * 0.03f, 0.0f };
shipCameraPoints.push_back(adjusted);
}
if (!shipCameraPoints.empty()) {
sparkEmitterPtr->setEmissionPoints(shipCameraPoints);
}
} }
if (!shipCameraPoints.empty()) { else
sparkEmitter.setEmissionPoints(shipCameraPoints); {
sparkEmitterPtr->setIsActive(false);
} }
sparkEmitter.update(static_cast<float>(delta)); sparkEmitterPtr->update(static_cast<float>(delta));
//projectileEmitter.update(static_cast<float>(delta)); //projectileEmitter.update(static_cast<float>(delta));
explosionEmitter.update(static_cast<float>(delta)); explosionEmitter.update(static_cast<float>(delta));
+1
View File
@@ -88,6 +88,7 @@ namespace ZL {
VertexDataStruct boxBase; VertexDataStruct boxBase;
SparkEmitter sparkEmitter; SparkEmitter sparkEmitter;
SparkEmitter sparkEmitterCargo;
SparkEmitter projectileEmitter; SparkEmitter projectileEmitter;
SparkEmitter explosionEmitter; SparkEmitter explosionEmitter;
PlanetObject planetObject; PlanetObject planetObject;
+47 -17
View File
@@ -74,7 +74,7 @@ namespace ZL {
texture = tex; texture = tex;
} }
void SparkEmitter::prepareDrawData() { void SparkEmitter::prepareDrawData(bool withRotation) {
if (!drawDataDirty) return; if (!drawDataDirty) return;
drawPositions.clear(); drawPositions.clear();
@@ -91,10 +91,10 @@ namespace ZL {
for (const auto& particle : particles) { for (const auto& particle : particles) {
if (particle.active) { if (particle.active) {
Vector3f posCam; Vector3f posCam;
if (useWorldSpace) { if (withRotation) {
Vector3f rel = particle.position - Environment::shipState.position; Vector3f rel = particle.position - Environment::shipState.position;
posCam = Environment::inverseShipMatrix * rel; posCam = Environment::inverseShipMatrix * rel;
} }
else { else {
posCam = particle.position; posCam = particle.position;
} }
@@ -120,29 +120,59 @@ namespace ZL {
float size = particleSize * particle.scale; float size = particleSize * particle.scale;
drawPositions.push_back({ posCam(0) - size, posCam(1) - size, posCam(2) }); if (withRotation)
drawTexCoords.push_back({ 0.0f, 0.0f }); {
drawPositions.push_back({ posCam(0) - size, posCam(1) + size, posCam(2) }); drawPositions.push_back(Environment::shipState.rotation * Vector3f{ -size, -size, 0 } + posCam);
drawTexCoords.push_back({ 0.0f, 1.0f }); drawTexCoords.push_back({ 0.0f, 0.0f });
drawPositions.push_back({ posCam(0) + size, posCam(1) + size, posCam(2) }); drawPositions.push_back(Environment::shipState.rotation * Vector3f{ -size, size,0 } + posCam);
drawTexCoords.push_back({ 1.0f, 1.0f }); drawTexCoords.push_back({ 0.0f, 1.0f });
drawPositions.push_back({ posCam(0) - size, posCam(1) - size, posCam(2) }); drawPositions.push_back(Environment::shipState.rotation * Vector3f{ size,size, 0 } + posCam);
drawTexCoords.push_back({ 0.0f, 0.0f }); drawTexCoords.push_back({ 1.0f, 1.0f });
drawPositions.push_back({ posCam(0) + size, posCam(1) + size, posCam(2) }); drawPositions.push_back(Environment::shipState.rotation * Vector3f{ -size, -size, 0 } + posCam);
drawTexCoords.push_back({ 1.0f, 1.0f }); drawTexCoords.push_back({ 0.0f, 0.0f });
drawPositions.push_back({ posCam(0) + size, posCam(1) - size, posCam(2) }); drawPositions.push_back(Environment::shipState.rotation * Vector3f{ size, size,0 } + posCam);
drawTexCoords.push_back({ 1.0f, 0.0f }); drawTexCoords.push_back({ 1.0f, 1.0f });
drawPositions.push_back(Environment::shipState.rotation * Vector3f{ size, -size, 0 } + posCam);
drawTexCoords.push_back({ 1.0f, 0.0f });
}
else
{
drawPositions.push_back({ posCam(0) - size, posCam(1) - size, posCam(2) });
drawTexCoords.push_back({ 0.0f, 0.0f });
drawPositions.push_back({ posCam(0) - size, posCam(1) + size, posCam(2) });
drawTexCoords.push_back({ 0.0f, 1.0f });
drawPositions.push_back({ posCam(0) + size, posCam(1) + size, posCam(2) });
drawTexCoords.push_back({ 1.0f, 1.0f });
drawPositions.push_back({ posCam(0) - size, posCam(1) - size, posCam(2) });
drawTexCoords.push_back({ 0.0f, 0.0f });
drawPositions.push_back({ posCam(0) + size, posCam(1) + size, posCam(2) });
drawTexCoords.push_back({ 1.0f, 1.0f });
drawPositions.push_back({ posCam(0) + size, posCam(1) - size, posCam(2) });
drawTexCoords.push_back({ 1.0f, 0.0f });
}
} }
drawDataDirty = false; drawDataDirty = false;
} }
void SparkEmitter::draw(Renderer& renderer, float zoom, int screenWidth, int screenHeight) { void SparkEmitter::draw(Renderer& renderer, float zoom, int screenWidth, int screenHeight)
{
draw(renderer, zoom, screenWidth, screenHeight, true);
}
void SparkEmitter::draw(Renderer& renderer, float zoom, int screenWidth, int screenHeight, bool withRotation) {
if (!configured) { if (!configured) {
throw std::runtime_error("Failed to load spark emitter config file 1!"); throw std::runtime_error("Failed to load spark emitter config file 1!");
} }
@@ -155,7 +185,7 @@ namespace ZL {
throw std::runtime_error("Failed to load spark emitter config file 2!"); throw std::runtime_error("Failed to load spark emitter config file 2!");
} }
prepareDrawData(); prepareDrawData(withRotation);
if (drawPositions.empty()) { if (drawPositions.empty()) {
return; return;
+7 -1
View File
@@ -50,7 +50,7 @@ namespace ZL {
std::string shaderProgramName; std::string shaderProgramName;
bool configured; bool configured;
void prepareDrawData(); void prepareDrawData(bool withRotation);
bool useWorldSpace; bool useWorldSpace;
public: public:
@@ -76,11 +76,17 @@ namespace ZL {
void emit(); void emit();
void draw(Renderer& renderer, float zoom, int screenWidth, int screenHeight); void draw(Renderer& renderer, float zoom, int screenWidth, int screenHeight);
void draw(Renderer& renderer, float zoom, int screenWidth, int screenHeight, bool withRotation);
const std::vector<SparkParticle>& getParticles() const; const std::vector<SparkParticle>& getParticles() const;
size_t getActiveParticleCount() const; size_t getActiveParticleCount() const;
std::shared_ptr<Texture> getTexture() const { return texture; } std::shared_ptr<Texture> getTexture() const { return texture; }
void setIsActive(bool newActive)
{
isActive = newActive;
}
private: private:
void initParticle(SparkParticle& particle, int emitterIndex); void initParticle(SparkParticle& particle, int emitterIndex);
Vector3f getRandomVelocity(int emitterIndex); Vector3f getRandomVelocity(int emitterIndex);
+19 -8
View File
@@ -57,6 +57,7 @@ namespace ZL {
case ButtonState::Normal: tex = &texNormal; break; case ButtonState::Normal: tex = &texNormal; break;
case ButtonState::Hover: tex = &texHover; break; case ButtonState::Hover: tex = &texHover; break;
case ButtonState::Pressed: tex = &texPressed; break; case ButtonState::Pressed: tex = &texPressed; break;
case ButtonState::Disabled: tex = &texDisabled; break;
} }
if (!(*tex)) return; if (!(*tex)) return;
@@ -290,6 +291,9 @@ namespace ZL {
btn->texNormal = loadTex("normal"); btn->texNormal = loadTex("normal");
btn->texHover = loadTex("hover"); btn->texHover = loadTex("hover");
btn->texPressed = loadTex("pressed"); btn->texPressed = loadTex("pressed");
btn->texDisabled = loadTex("disabled");
btn->border = j.value("border", 0.0f);
node->button = btn; node->button = btn;
} }
@@ -1049,11 +1053,14 @@ namespace ZL {
void UiManager::onMouseMove(int x, int y) { void UiManager::onMouseMove(int x, int y) {
for (auto& b : buttons) { for (auto& b : buttons) {
if (b->rect.contains((float)x, (float)y)) { if (b->state != ButtonState::Disabled)
if (b->state != ButtonState::Pressed) b->state = ButtonState::Hover; {
} if (b->rect.containsConsideringBorder((float)x, (float)y, b->border)) {
else { if (b->state != ButtonState::Pressed) b->state = ButtonState::Hover;
if (b->state != ButtonState::Pressed) b->state = ButtonState::Normal; }
else {
if (b->state != ButtonState::Pressed) b->state = ButtonState::Normal;
}
} }
} }
@@ -1074,11 +1081,15 @@ namespace ZL {
} }
} }
void UiManager::onMouseDown(int x, int y) { void UiManager::onMouseDown(int x, int y) {
for (auto& b : buttons) { for (auto& b : buttons) {
if (b->rect.contains((float)x, (float)y)) { if (b->state != ButtonState::Disabled)
b->state = ButtonState::Pressed; {
pressedButton = b; if (b->rect.containsConsideringBorder((float)x, (float)y, b->border)) {
b->state = ButtonState::Pressed;
pressedButton = b;
}
} }
} }
+8 -1
View File
@@ -23,12 +23,17 @@ namespace ZL {
bool contains(float px, float py) const { bool contains(float px, float py) const {
return px >= x && px <= x + w && py >= y && py <= y + h; return px >= x && px <= x + w && py >= y && py <= y + h;
} }
bool containsConsideringBorder(float px, float py, float border) const {
return px >= x+border && px <= x + w-border && py >= y+border && py <= y + h-border;
}
}; };
enum class ButtonState { enum class ButtonState {
Normal, Normal,
Hover, Hover,
Pressed Pressed,
Disabled
}; };
enum class LayoutType { enum class LayoutType {
@@ -76,9 +81,11 @@ namespace ZL {
struct UiButton { struct UiButton {
std::string name; std::string name;
UiRect rect; UiRect rect;
float border = 0;
std::shared_ptr<Texture> texNormal; std::shared_ptr<Texture> texNormal;
std::shared_ptr<Texture> texHover; std::shared_ptr<Texture> texHover;
std::shared_ptr<Texture> texPressed; std::shared_ptr<Texture> texPressed;
std::shared_ptr<Texture> texDisabled;
ButtonState state = ButtonState::Normal; ButtonState state = ButtonState::Normal;
VertexRenderStruct mesh; VertexRenderStruct mesh;
+1 -1
View File
@@ -14,7 +14,7 @@ constexpr auto NET_SECRET = "880b3713b9ff3e7a94b2712d54679e1f";
#define ENABLE_NETWORK_CHECKSUM #define ENABLE_NETWORK_CHECKSUM
constexpr float ANGULAR_ACCEL = 0.005f * 1000.0f; constexpr float ANGULAR_ACCEL = 0.005f * 1000.0f;
constexpr float SHIP_ACCEL = 1.0f * 1000.0f; constexpr float SHIP_ACCEL = 1.0f * 200.0f;
constexpr float ROTATION_SENSITIVITY = 0.002f; constexpr float ROTATION_SENSITIVITY = 0.002f;
constexpr float PLANET_RADIUS = 20000.f; constexpr float PLANET_RADIUS = 20000.f;