particle stuff
This commit is contained in:
parent
f0e77bc485
commit
5aeccd7fbe
BIN
res/bin/flame.o
Normal file
BIN
res/bin/flame.o
Normal file
Binary file not shown.
BIN
res/bin/raindrop.o
Normal file
BIN
res/bin/raindrop.o
Normal file
Binary file not shown.
5
res/convert.sh
Executable file
5
res/convert.sh
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
convert $1.png -depth 8 -format rgba $1.rgba
|
||||
mv $1.rgba $1
|
||||
objcopy --input binary --output elf32-i386 --binary-architecture i386 $1 $1.o
|
||||
mv $1.o bin/$1.o
|
BIN
res/flame.png
Normal file
BIN
res/flame.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 487 B |
BIN
res/raindrop
Normal file
BIN
res/raindrop
Normal file
Binary file not shown.
BIN
res/raindrop.png
Normal file
BIN
res/raindrop.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 258 B |
@ -62,7 +62,8 @@ void CBaseContainer::Draw(int x, int y) {
|
||||
for (auto child : m_children) {
|
||||
if (child->IsVisible()) {
|
||||
auto off = child->GetOffset();
|
||||
child->Draw(x + off.first, y + off.second);
|
||||
if (AlwaysVisible() || g_pGUI->Visible() || child->AlwaysVisible())
|
||||
child->Draw(x + off.first, y + off.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -182,7 +183,8 @@ void CBaseContainer::Update() {
|
||||
MoveChildren();
|
||||
UpdateHovers();
|
||||
for (auto child : m_children) {
|
||||
child->Update();
|
||||
if (AlwaysVisible() || g_pGUI->Visible() || child->AlwaysVisible())
|
||||
child->Update();
|
||||
}
|
||||
CBaseWidget::Update();
|
||||
}
|
||||
|
@ -17,6 +17,18 @@ void CBaseWidget::DrawBounds(int x, int y) {
|
||||
draw::OutlineRect(x, y, size.first, size.second, m_KeyValues->GetInt("bounds_color"));
|
||||
}
|
||||
|
||||
bool CBaseWidget::IsHovered() {
|
||||
return g_pGUI->Visible() && m_KeyValues->GetBool("hover");
|
||||
}
|
||||
|
||||
bool CBaseWidget::IsFocused() {
|
||||
return g_pGUI->Visible() && m_KeyValues->GetBool("focus");
|
||||
}
|
||||
|
||||
bool CBaseWidget::IsPressed() {
|
||||
return g_pGUI->Visible() && m_KeyValues->GetBool("press");
|
||||
}
|
||||
|
||||
CBaseWidget::CBaseWidget(std::string name, IWidget* parent) : m_KeyValues(new KeyValues(std::string(name + "_kv").c_str())) {
|
||||
m_pParent = parent;
|
||||
Props()->SetString("name", name.c_str());
|
||||
|
@ -9,7 +9,6 @@
|
||||
#define CBASEWIDGET_H_
|
||||
|
||||
#include "IWidget.h"
|
||||
|
||||
#include "../beforecheaders.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
@ -45,6 +44,8 @@ public:
|
||||
|
||||
inline virtual bool ConsumesKey(ButtonCode_t key) { return false; }
|
||||
|
||||
inline virtual bool AlwaysVisible() { return m_KeyValues->GetBool("always_visible"); }
|
||||
|
||||
inline virtual void Show() { m_KeyValues->SetBool("visible", true); }
|
||||
inline virtual void Hide() { m_KeyValues->SetBool("visible", false); }
|
||||
inline virtual bool IsVisible() {
|
||||
@ -52,9 +53,9 @@ public:
|
||||
return m_KeyValues->GetBool("visible");
|
||||
}
|
||||
|
||||
inline virtual bool IsHovered() { return m_KeyValues->GetBool("hover"); }
|
||||
inline virtual bool IsFocused() { return m_KeyValues->GetBool("focus"); }
|
||||
inline virtual bool IsPressed() { return m_KeyValues->GetBool("press"); }
|
||||
virtual bool IsHovered();
|
||||
virtual bool IsFocused();
|
||||
virtual bool IsPressed();
|
||||
|
||||
inline virtual bool DoesStealFocus() { return true; }
|
||||
|
||||
|
@ -43,6 +43,10 @@ CatGUI::~CatGUI() {
|
||||
delete m_pRootWindow;
|
||||
}
|
||||
|
||||
bool CatGUI::Visible() {
|
||||
return gui_visible;
|
||||
}
|
||||
|
||||
CatVar gui_color_r(CV_INT, "gui_color_r", "255", "Main GUI color (red)", "Defines red component of main gui color", 0, 255);
|
||||
CatVar gui_color_g(CV_INT, "gui_color_g", "105", "Main GUI color (green)", "Defines green component of main gui color", 0, 255);
|
||||
CatVar gui_color_b(CV_INT, "gui_color_b", "180", "Main GUI color (blue)", "Defines blue component of main gui color", 0, 255);
|
||||
@ -146,7 +150,17 @@ void CatGUI::Update() {
|
||||
m_iMouseY = ny;
|
||||
|
||||
if (!m_bKeysInit) m_bKeysInit = 1;
|
||||
if (gui_visible) {
|
||||
if (!root->IsVisible())
|
||||
root->Show();
|
||||
root->Update();
|
||||
if (!m_bShowTooltip && m_pTooltip->IsVisible()) m_pTooltip->Hide();
|
||||
root->Draw(0, 0);
|
||||
//draw::DrawRect(m_iMouseX - 5, m_iMouseY - 5, 10, 10, colors::Transparent(colors::white));
|
||||
//draw::OutlineRect(m_iMouseX - 5, m_iMouseY - 5, 10, 10, GUIColor());
|
||||
if (gui_draw_bounds) {
|
||||
root->DrawBounds(0, 0);
|
||||
}
|
||||
/*if (gui_visible) {
|
||||
if (!root->IsVisible())
|
||||
root->Show();
|
||||
root->Update();
|
||||
@ -160,7 +174,7 @@ void CatGUI::Update() {
|
||||
} else {
|
||||
if (root->IsVisible())
|
||||
root->Hide();
|
||||
}
|
||||
}*/
|
||||
} catch (std::exception& ex) {
|
||||
logging::Info("ERROR: %s", ex.what());
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ public:
|
||||
CatGUI();
|
||||
~CatGUI();
|
||||
|
||||
bool Visible();
|
||||
void Update();
|
||||
void Setup();
|
||||
RootWindow* GetRootWindow();
|
||||
|
@ -45,6 +45,8 @@ public:
|
||||
|
||||
virtual bool ConsumesKey(ButtonCode_t key) = 0;
|
||||
|
||||
// Widget will be visible even when gui is turned off
|
||||
virtual bool AlwaysVisible() = 0;
|
||||
virtual void Show() = 0;
|
||||
virtual void Hide() = 0;
|
||||
virtual bool IsVisible() = 0;
|
||||
|
@ -9,69 +9,98 @@
|
||||
|
||||
namespace menu { namespace ncc {
|
||||
|
||||
Background::Background() : CBaseWidget("nc_background"), snowflake_texture(&_binary_snowflake_start, 16, 16) {
|
||||
Background::Background() : CBaseWidget("nc_background"),
|
||||
tx_snowflake(&_binary_snowflake_start, 16, 16),
|
||||
tx_raindrop(&_binary_raindrop_start, 16, 16),
|
||||
tx_flame(&_binary_flame_start, 16, 16){
|
||||
SetSize(draw::width, draw::height);
|
||||
}
|
||||
|
||||
static CatVar snowflakes(CV_SWITCH, "gui_snowflakes", "0", "Snowflakes");
|
||||
static CatVar snowflake_chance(CV_INT, "gui_snowflake_chance", "10", "Snowflake Spawn Rate", "Defines snowflake spawn rate (HAS TO BE NONZERO!)", 1.0f, 100.0f);
|
||||
static CatVar snowflake_pack_size(CV_INT, "gui_snowflake_pack_size", "10", "Snowflake Max Pack", "Defines max snowflake spawn pack size (HAS TO BE NONZERO!)", 1.0f, 100.0f);
|
||||
static CatVar snowflake_safe(CV_INT, "gui_snowflake_safe_zone", "100", "Snowflake Safe Zone", "Defines snowflake safe zone (they will decay after reaching that point)", 0.0f, 400.0f);
|
||||
static CatVar snowflake_gravity(CV_FLOAT, "gui_snowflake_gravity", "0.9", "Snowflake Gravity", "Defines snowflake gravity (HAS TO BE NONZERO!)", 0.01f, 5.0f);
|
||||
static CatVar snowflake_jittering(CV_INT, "gui_snowflake_jittering", "2", "Snowflake Jittering", "Defines snowflake jittering amount", 0.0f, 10.0f);
|
||||
static CatVar snowflake_jittering_chance(CV_INT, "gui_snowflake_jittering_chance", "60", "Snowflake Jittering Rate", "Defines snowflake jittering rate (HAS TO BE NONZERO!)", 1.0f, 20.0f);
|
||||
static CatVar particles(CV_SWITCH, "gui_bg_particles", "0", "Particles");
|
||||
static CatEnum particle_type_enum({"Snowflake", "Raindrop", "Flame"});
|
||||
static CatVar particle_type(particle_type_enum, "gui_bg_particles_type", "0", "Particles Type", "Defines particle type");
|
||||
static CatVar particle_chance(CV_INT, "gui_bg_particles_chance", "10", "Particles Spawn Rate", "Defines snowflake spawn rate (HAS TO BE NONZERO!)", 1.0f, 100.0f);
|
||||
static CatVar particle_pack_size(CV_INT, "gui_bg_particles_pack_size", "10", "Particles Max Pack", "Defines max snowflake spawn pack size (HAS TO BE NONZERO!)", 1.0f, 100.0f);
|
||||
static CatVar particle_safe(CV_INT, "gui_bg_particles_safe_zone", "100", "Particles Safe Zone", "Defines snowflake safe zone (they will decay after reaching that point)", 0.0f, 400.0f);
|
||||
static CatVar particle_gravity(CV_FLOAT, "gui_bg_particles_gravity", "0.9", "Particles Gravity", "Defines snowflake gravity (HAS TO BE NONZERO!)", 0.01f, 5.0f);
|
||||
static CatVar particle_jittering(CV_INT, "gui_bg_particles_jittering", "2", "Particles Jittering", "Defines snowflake jittering amount", 0.0f, 10.0f);
|
||||
static CatVar particle_wind(CV_INT, "gui_bg_particles_wind", "0", "Particles Wind", "Wind strength and direction", -50.0f, 50.0f);
|
||||
static CatVar particle_jittering_chance(CV_INT, "gui_bg_particles_jittering_chance", "60", "Snowflake Jittering Rate", "Defines snowflake jittering rate (HAS TO BE NONZERO!)", 1.0f, 20.0f);
|
||||
static CatEnum background_visible_enum({"NEVER", "MENU", "ALWAYS"});
|
||||
static CatVar background_visible(background_visible_enum, "gui_bg_visible", "1", "Render background", "Render background when");
|
||||
|
||||
bool Background::AlwaysVisible() {
|
||||
return (int)background_visible == 2;
|
||||
}
|
||||
|
||||
void Background::Update() {
|
||||
if (!snowflakes) return;
|
||||
Snowflake* current = list;
|
||||
if (!particles) return;
|
||||
Particle* current = list;
|
||||
while (current) {
|
||||
Snowflake* next = current->next;
|
||||
Particle* next = current->next;
|
||||
current->Update();
|
||||
if (current->dead) {
|
||||
KillSnowflake(current);
|
||||
KillParticle(current);
|
||||
}
|
||||
current = next;
|
||||
}
|
||||
if (!(rand() % (int)snowflake_chance)) {
|
||||
for (int i = 0; i < rand() % (int)snowflake_pack_size; i++) MakeSnowflake();
|
||||
if (!(rand() % (int)particle_chance)) {
|
||||
for (int i = 0; i < rand() % (int)particle_pack_size; i++) MakeParticle();
|
||||
}
|
||||
}
|
||||
|
||||
Background::~Background() {
|
||||
Snowflake* current = list;
|
||||
Particle* current = list;
|
||||
while (current) {
|
||||
Snowflake* next = current->next;
|
||||
Particle* next = current->next;
|
||||
delete current;
|
||||
current = next;
|
||||
}
|
||||
}
|
||||
|
||||
void Background::LoadTextures() {
|
||||
tx_flame.Load();
|
||||
tx_raindrop.Load();
|
||||
tx_snowflake.Load();
|
||||
textures_loaded = true;
|
||||
}
|
||||
|
||||
void Background::Draw(int x, int y) {
|
||||
if (!snowflakes) return;
|
||||
if (!snowflake_texture.id) {
|
||||
snowflake_texture.Load();
|
||||
}
|
||||
Snowflake* current = list;
|
||||
if (!particles) return;
|
||||
if (!textures_loaded) LoadTextures();
|
||||
Particle* current = list;
|
||||
while (current) {
|
||||
Snowflake* next = current->next;
|
||||
Particle* next = current->next;
|
||||
if (!current->show_in) {
|
||||
int color = colors::white;
|
||||
if (current->y > (int)snowflake_safe) {
|
||||
color = colors::Create(255, 255, 255, ((int)snowflake_safe + 255) - current->y);
|
||||
if (current->y > (int)particle_safe) {
|
||||
color = colors::Create(255, 255, 255, ((int)particle_safe + 255) - current->y);
|
||||
}
|
||||
snowflake_texture.Draw((int)current->x, (int)current->y, 16, 16, color);
|
||||
current->texture->Draw((int)current->x, (int)current->y, 16, 16, color);
|
||||
}
|
||||
current = next;
|
||||
}
|
||||
}
|
||||
|
||||
void Background::MakeSnowflake() {
|
||||
Snowflake* flake = new Snowflake();
|
||||
void Background::MakeParticle() {
|
||||
Particle* flake = new Particle();
|
||||
flake->x = RandFloatRange(0, draw::width);
|
||||
flake->y = 3 - (rand() % 6);
|
||||
flake->vx = 0;
|
||||
flake->vy = 0;
|
||||
flake->dead = false;
|
||||
flake->next = nullptr;
|
||||
flake->show_in = rand() % 4;
|
||||
switch ((int)particle_type) {
|
||||
case 1:
|
||||
flake->texture = &tx_raindrop;
|
||||
break;
|
||||
case 2:
|
||||
flake->texture = &tx_flame;
|
||||
break;
|
||||
default:
|
||||
flake->texture = &tx_snowflake;
|
||||
}
|
||||
if (list_tail)
|
||||
list_tail->next = flake;
|
||||
flake->prev = list_tail;
|
||||
@ -81,7 +110,7 @@ void Background::MakeSnowflake() {
|
||||
}
|
||||
}
|
||||
|
||||
void Background::KillSnowflake(Snowflake* flake) {
|
||||
void Background::KillParticle(Particle* flake) {
|
||||
if (list_tail == flake) {
|
||||
list_tail = flake->prev;
|
||||
}
|
||||
@ -93,13 +122,18 @@ void Background::KillSnowflake(Snowflake* flake) {
|
||||
delete flake;
|
||||
}
|
||||
|
||||
void Background::Snowflake::Update() {
|
||||
void Background::Particle::Update() {
|
||||
if (show_in) show_in--;
|
||||
if (!(rand() % (int)(snowflake_jittering_chance))) {
|
||||
x += (rand() % 2) ? (int)snowflake_jittering : -(int)snowflake_jittering;
|
||||
if (particle_wind) {
|
||||
vx += (float)particle_wind * 0.005f;
|
||||
}
|
||||
y += (float)snowflake_gravity;
|
||||
if (y > (int)snowflake_safe + 255) dead = true;
|
||||
if (!(rand() % (int)(particle_jittering_chance))) {
|
||||
x += (rand() % 2) ? (int)particle_jittering : -(int)particle_jittering;
|
||||
}
|
||||
vy += (float)particle_gravity / 60.0f;
|
||||
x += vx;
|
||||
y += vy;
|
||||
if (y > (int)particle_safe + 255) dead = true;
|
||||
}
|
||||
|
||||
}}
|
||||
|
@ -11,30 +11,40 @@
|
||||
#include "Menu.hpp"
|
||||
|
||||
extern unsigned char _binary_snowflake_start;
|
||||
extern unsigned char _binary_flame_start;
|
||||
extern unsigned char _binary_raindrop_start;
|
||||
|
||||
namespace menu { namespace ncc {
|
||||
|
||||
class Background : public CBaseWidget {
|
||||
public:
|
||||
struct Snowflake {
|
||||
struct Particle {
|
||||
float x, y;
|
||||
float vx, vy;
|
||||
int show_in { 0 };
|
||||
bool dead { false };
|
||||
Snowflake* next { nullptr };
|
||||
Snowflake* prev { nullptr };
|
||||
Texture* texture { nullptr };
|
||||
Particle* next { nullptr };
|
||||
Particle* prev { nullptr };
|
||||
void Update();
|
||||
};
|
||||
public:
|
||||
Background();
|
||||
~Background();
|
||||
virtual bool AlwaysVisible() override;
|
||||
virtual void Draw(int x, int y) override;
|
||||
virtual void Update() override;
|
||||
void MakeSnowflake();
|
||||
void KillSnowflake(Snowflake* flake);
|
||||
void LoadTextures();
|
||||
void MakeParticle();
|
||||
void KillParticle(Particle* flake);
|
||||
public:
|
||||
Texture snowflake_texture;
|
||||
Snowflake* list { nullptr };
|
||||
Snowflake* list_tail { nullptr };
|
||||
// FIXME array or something
|
||||
bool textures_loaded { false };
|
||||
Texture tx_snowflake;
|
||||
Texture tx_raindrop;
|
||||
Texture tx_flame;
|
||||
Particle* list { nullptr };
|
||||
Particle* list_tail { nullptr };
|
||||
};
|
||||
|
||||
}}
|
||||
|
@ -9,12 +9,17 @@
|
||||
|
||||
namespace menu { namespace ncc {
|
||||
|
||||
CatVar logo(CV_SWITCH, "logo", "1", "Show logo", "Show cathook logo when GUI is open");
|
||||
static CatEnum logo_enum({"NEVER", "MENU", "ALWAYS"});
|
||||
CatVar logo(logo_enum, "logo", "1", "Show logo", "Show cathook logo when");
|
||||
|
||||
Logo::Logo() : CBaseWidget("nc_logo"), texture(&_binary_logo_start, 576, 288) {
|
||||
SetSize(576, 288);
|
||||
}
|
||||
|
||||
bool Logo::AlwaysVisible() {
|
||||
return (int)logo == 2;
|
||||
}
|
||||
|
||||
void Logo::Draw(int x, int y) {
|
||||
if (logo) {
|
||||
if (!texture.id) texture.Load();
|
||||
|
@ -17,6 +17,7 @@ namespace menu { namespace ncc {
|
||||
class Logo : public CBaseWidget {
|
||||
public:
|
||||
Logo();
|
||||
virtual bool AlwaysVisible() override;
|
||||
virtual void Draw(int x, int y) override;
|
||||
virtual void Update() override;
|
||||
Texture texture;
|
||||
|
@ -210,7 +210,6 @@ static const std::string list_hl2dm = R"(
|
||||
|
||||
"GUI" [
|
||||
"GUI Settings"
|
||||
"logo"
|
||||
"gui_color_b"
|
||||
"gui_color_g"
|
||||
"gui_color_r"
|
||||
@ -439,13 +438,16 @@ static const std::string list_tf2 = R"(
|
||||
"GUI" [
|
||||
"GUI Settings"
|
||||
"logo"
|
||||
"gui_snowflakes"
|
||||
"gui_snowflake_chance"
|
||||
"gui_snowflake_pack_size"
|
||||
"gui_snowflake_safe_zone"
|
||||
"gui_snowflake_gravity"
|
||||
"gui_snowflake_jittering"
|
||||
"gui_snowflake_jittering_chance"
|
||||
"gui_bg_particles"
|
||||
"gui_bg_particles_type"
|
||||
"gui_bg_particles_chance"
|
||||
"gui_bg_particles_pack_size"
|
||||
"gui_bg_particles_safe_zone"
|
||||
"gui_bg_particles_gravity"
|
||||
"gui_bg_particles_jittering"
|
||||
"gui_bg_particles_jittering_chance"
|
||||
"gui_bg_particles_wind"
|
||||
"gui_bg_visible"
|
||||
"gui_color_b"
|
||||
"gui_color_g"
|
||||
"gui_color_r"
|
||||
|
Reference in New Issue
Block a user