From 5aeccd7fbee973fecd9470878d31936eac1c668c Mon Sep 17 00:00:00 2001 From: nullifiedcat Date: Sat, 29 Apr 2017 00:08:19 +0300 Subject: [PATCH] particle stuff --- res/bin/flame.o | Bin 0 -> 1448 bytes res/bin/raindrop.o | Bin 0 -> 1456 bytes res/convert.sh | 5 ++ res/flame | Bin 0 -> 1024 bytes res/flame.png | Bin 0 -> 487 bytes res/raindrop | Bin 0 -> 1024 bytes res/raindrop.png | Bin 0 -> 258 bytes src/gui/CBaseContainer.cpp | 6 ++- src/gui/CBaseWidget.cpp | 12 +++++ src/gui/CBaseWidget.h | 9 ++-- src/gui/GUI.cpp | 18 ++++++- src/gui/GUI.h | 1 + src/gui/IWidget.h | 2 + src/gui/ncc/Background.cpp | 100 +++++++++++++++++++++++++------------ src/gui/ncc/Background.hpp | 26 +++++++--- src/gui/ncc/Logo.cpp | 7 ++- src/gui/ncc/Logo.hpp | 1 + src/gui/ncc/Menu.cpp | 18 ++++--- 18 files changed, 147 insertions(+), 58 deletions(-) create mode 100644 res/bin/flame.o create mode 100644 res/bin/raindrop.o create mode 100755 res/convert.sh create mode 100644 res/flame create mode 100644 res/flame.png create mode 100644 res/raindrop create mode 100644 res/raindrop.png diff --git a/res/bin/flame.o b/res/bin/flame.o new file mode 100644 index 0000000000000000000000000000000000000000..4b4593cd60d7b1c3dc0876a671df5b92162b9442 GIT binary patch literal 1448 zcmbVMOKVd>6h1LZu~n&pZroU0R2M2jd{hK+QD4*$gdi46ym=HONz~*bR7734bK~D| z(PeR`&_b6r=neI@MI##fz<5ouQV8kiIg>j!DM?Kn7|zU@^L^(#XP9}?KXAe0@sJ)K z^3wW_D8IFO;#1}jZKEwZw4t@{9Y({07M*sCFm;9go5KndX09{GrS>_jTZC!GJ8?pe zHMGNFMLLi(2+Q{gr4(W58sYur);T1%bC;)!pARrcknoo4_?HgB78xtK9nSrodstxn zJZlh+&G3R;JO1Z#iXgcQH_bHMCrSAl};KPGm`10mF zzFB^Jo;Z&DXfNJHI@^AS@_W?&AKkp$D=R1yi|yvQou|&pOM1o!XJp|H&G!d^gl%^K literal 0 HcmV?d00001 diff --git a/res/bin/raindrop.o b/res/bin/raindrop.o new file mode 100644 index 0000000000000000000000000000000000000000..c224bbef75c010a6cace2ae85d9f0583f334bcd5 GIT binary patch literal 1456 zcmb<-^>JflWMqH=Mh0dE1doB?1q(#R1Wai#ure^gl;Wgork!R0VRAv&;;a9G`u~%o zAEbB9k#As3jv18bN7f5+1F7~?q90u^srFN%AEx)r%`g8!7#9A-x&c`~vR)XQP&iUc zKg>RKnvngVbP96=IeKB~9Ni3J?1kxt(I7oA3=^X#4Jtj5%MSq{PXgosXgLDn>!R>K z{%43!%FIhFs*Ep6%*;zE$}fm7E=epZ!4yu-OTiQ@&a6shV9+bB%q>Yw0@5W#5IO_K zN=Yn9BsvJBfhs}nXNKwkmwQmRgM?sy6GT!25I6%EN{KyXbUyC;zG3ZxeV?q-|UU~hGY{xYAik%nF1hURFL zgIR@G_EyRJjXI1IpP&q^QIBUf?J2Q}o3bC8@Ojds@f8h;x(L+hli7%?>`SbAU0u~X(NnH6sv5VZn|9gs(n@|dbL^my)zbAO)?16d~uNh=ES2#NtSk{gEK z9`tzj*SyswKy{#yvLPQbQx*&ImxGAUmpatrWt#u%xEshhH69-hjpqz_wBX&{u63uk z1MVPp)b+>H4EgA|HUsnF?T)(p literal 0 HcmV?d00001 diff --git a/res/flame.png b/res/flame.png new file mode 100644 index 0000000000000000000000000000000000000000..aed66d7b88bd6d65b471d3264fd9c0ba4c26509f GIT binary patch literal 487 zcmV$#2wAV>&jmoQaQ(8C3Go z6f2ryV;Ou%FO1?;Gck*vE10iKnbjJU3)rB8C8V@Iiyrj`{{sym8gFSj8l?nlEh_6W zvNi(-wC)4AYeA|y0z*y|dg(~r7@TUF)MS?1m&o!DV15e~7W; dwY_*Vz$coadd1`eLLmSE002ovPDHLkV1hmuyYK)2 literal 0 HcmV?d00001 diff --git a/res/raindrop b/res/raindrop new file mode 100644 index 0000000000000000000000000000000000000000..6dfa7bbc65ba7c863cced4af7db018badfd246f2 GIT binary patch literal 1024 zcmZQzzz=Gson`=GazWSPtN(%e|C6I1q<77cZ(vN08I3w#~|1{{OPN)WuwNP1Q$TtT~AX rJaU{4O`Rgi`NXB7A@Q=0C<8+Tui3te%#Nu*r!jcC`njxgN@xNAFicQs literal 0 HcmV?d00001 diff --git a/src/gui/CBaseContainer.cpp b/src/gui/CBaseContainer.cpp index 15307434..709f863a 100644 --- a/src/gui/CBaseContainer.cpp +++ b/src/gui/CBaseContainer.cpp @@ -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(); } diff --git a/src/gui/CBaseWidget.cpp b/src/gui/CBaseWidget.cpp index d1a6d31e..652052ba 100644 --- a/src/gui/CBaseWidget.cpp +++ b/src/gui/CBaseWidget.cpp @@ -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()); diff --git a/src/gui/CBaseWidget.h b/src/gui/CBaseWidget.h index 7e5a290d..285b11ff 100644 --- a/src/gui/CBaseWidget.h +++ b/src/gui/CBaseWidget.h @@ -9,7 +9,6 @@ #define CBASEWIDGET_H_ #include "IWidget.h" - #include "../beforecheaders.h" #include #include @@ -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; } diff --git a/src/gui/GUI.cpp b/src/gui/GUI.cpp index bd8d34fd..5865fa7a 100644 --- a/src/gui/GUI.cpp +++ b/src/gui/GUI.cpp @@ -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()); } diff --git a/src/gui/GUI.h b/src/gui/GUI.h index 6f1bee95..7a811386 100644 --- a/src/gui/GUI.h +++ b/src/gui/GUI.h @@ -40,6 +40,7 @@ public: CatGUI(); ~CatGUI(); + bool Visible(); void Update(); void Setup(); RootWindow* GetRootWindow(); diff --git a/src/gui/IWidget.h b/src/gui/IWidget.h index 85f2c14e..3a959542 100644 --- a/src/gui/IWidget.h +++ b/src/gui/IWidget.h @@ -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; diff --git a/src/gui/ncc/Background.cpp b/src/gui/ncc/Background.cpp index 7215bf09..a5ac962d 100644 --- a/src/gui/ncc/Background.cpp +++ b/src/gui/ncc/Background.cpp @@ -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; } }} diff --git a/src/gui/ncc/Background.hpp b/src/gui/ncc/Background.hpp index cf5ecfe3..c15043d6 100644 --- a/src/gui/ncc/Background.hpp +++ b/src/gui/ncc/Background.hpp @@ -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 }; }; }} diff --git a/src/gui/ncc/Logo.cpp b/src/gui/ncc/Logo.cpp index 1379395c..1053528c 100644 --- a/src/gui/ncc/Logo.cpp +++ b/src/gui/ncc/Logo.cpp @@ -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(); diff --git a/src/gui/ncc/Logo.hpp b/src/gui/ncc/Logo.hpp index 8f9dba38..c4e6c9a3 100644 --- a/src/gui/ncc/Logo.hpp +++ b/src/gui/ncc/Logo.hpp @@ -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; diff --git a/src/gui/ncc/Menu.cpp b/src/gui/ncc/Menu.cpp index c37ae6ca..e4d9ce28 100644 --- a/src/gui/ncc/Menu.cpp +++ b/src/gui/ncc/Menu.cpp @@ -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"