From 69aa47e39b328300e513b902315c0075c894e0b2 Mon Sep 17 00:00:00 2001 From: nullifiedcat Date: Fri, 28 Apr 2017 19:16:58 +0300 Subject: [PATCH] upd gitignore, add snowflakes --- .gitignore | 2 +- res/bin/snowflake.o | Bin 0 -> 1460 bytes res/snowflake.png | Bin 0 -> 220 bytes src/common.h | 1 + src/gui/ncc/Background.cpp | 102 +++++++++++++++++++++++++++++++++++ src/gui/ncc/Background.hpp | 42 +++++++++++++++ src/gui/ncc/ItemVariable.cpp | 2 + src/gui/ncc/Menu.cpp | 6 +++ src/gui/ncc/Menu.hpp | 1 + src/gui/ncc/Root.cpp | 1 + 10 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 res/bin/snowflake.o create mode 100644 res/snowflake.png create mode 100644 src/gui/ncc/Background.cpp create mode 100644 src/gui/ncc/Background.hpp diff --git a/.gitignore b/.gitignore index 62ff2068..ab19ca77 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ *.d *.o -!res/ /bin/* +!res/bin/* /core diff --git a/res/bin/snowflake.o b/res/bin/snowflake.o new file mode 100644 index 0000000000000000000000000000000000000000..a61666dfdbf952b4ea5aa6b92c2829e2fb2ed3ac GIT binary patch literal 1460 zcmdT^u}%U(5S;@o=&&?YbXL&t3sPCwUUgZ*8Hsu(cbk~AvGMEt78<_bn0M@pV{+h1 z1)FT%%_Ax z$NI1*`Sh^)Uw5I0MH?Uc56iQ?WBYgMS))fxe{v6DjEC(@AJmR%d1keUV|CO6Pt{qE zOO7!;?EDyMc7q3nIf8ulE8jMfE!TxB>#Qo?-XCAwbDmY+mA<2%7psnHwf@LOrd9pw z-BQt)dwgQFa^A)N>R73GLqAB`*%$7Q65n@iIH-RsXM!Ls@_=?~&XxC|HCUn!9O)kF PW={>}OAi(Z!lK^}TUQHN literal 0 HcmV?d00001 diff --git a/res/snowflake.png b/res/snowflake.png new file mode 100644 index 0000000000000000000000000000000000000000..0fd73c18ec995df020569fcfe0fc0d2db46f38e8 GIT binary patch literal 220 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=I50S^h-E752+Bfr9KMp1!W^4_RdRxy2s+XFm=U%Jg(`46!(Ub&@0B0R;}0<-Ycs z{72Gnd1qd5QJoW|my{wF*?QhxbLrZ1>t)xhV&GkHt*V7(&1>ezpH>F2NB_9EjezWe@I?~wNFX&Lwq4~ci@7?`YStM0WD?l MboFyt=akR{0QcEUJOBUy literal 0 HcmV?d00001 diff --git a/src/common.h b/src/common.h index 8070e80f..fdd0772d 100644 --- a/src/common.h +++ b/src/common.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include diff --git a/src/gui/ncc/Background.cpp b/src/gui/ncc/Background.cpp new file mode 100644 index 00000000..7aad4120 --- /dev/null +++ b/src/gui/ncc/Background.cpp @@ -0,0 +1,102 @@ +/* + * Background.cpp + * + * Created on: Apr 28, 2017 + * Author: nullifiedcat + */ + +#include "Menu.hpp" + +namespace menu { namespace ncc { + +Background::Background() : CBaseWidget("nc_background"), snowflake_texture(&_binary_snowflake_start, 16, 16) { + SetSize(draw::width, draw::height); +} + +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); + +void Background::Update() { + Snowflake* current = list; + while (current) { + Snowflake* next = current->next; + current->Update(); + if (current->dead) { + KillSnowflake(current); + } + current = next; + } + if (!(rand() % (int)snowflake_chance)) { + for (int i = 0; i < rand() % (int)snowflake_pack_size; i++) MakeSnowflake(); + } +} + +Background::~Background() { + Snowflake* current = list; + while (current) { + Snowflake* next = current->next; + delete current; + current = next; + } +} + +void Background::Draw(int x, int y) { + if (!snowflake_texture.id) { + snowflake_texture.Load(); + } + Snowflake* current = list; + while (current) { + Snowflake* 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); + } + snowflake_texture.Draw((int)current->x, (int)current->y, 16, 16, color); + } + current = next; + } +} + +void Background::MakeSnowflake() { + Snowflake* flake = new Snowflake(); + flake->x = RandFloatRange(0, draw::width); + flake->y = 3 - (rand() % 6); + flake->dead = false; + flake->next = nullptr; + flake->show_in = rand() % 4; + if (list_tail) + list_tail->next = flake; + flake->prev = list_tail; + list_tail = flake; + if (!list) { + list = flake; + } +} + +void Background::KillSnowflake(Snowflake* flake) { + if (list_tail == flake) { + list_tail = flake->prev; + } + if (list == flake) { + list = flake->next; + } + if (flake->prev) flake->prev->next = flake->next; + if (flake->next) flake->next->prev = flake->prev; + delete flake; +} + +void Background::Snowflake::Update() { + if (show_in) show_in--; + if (!(rand() % (int)(snowflake_jittering_chance))) { + x += (rand() % 2) ? (int)snowflake_jittering : -(int)snowflake_jittering; + } + y += (float)snowflake_gravity; + if (y > (int)snowflake_safe + 255) dead = true; +} + +}} diff --git a/src/gui/ncc/Background.hpp b/src/gui/ncc/Background.hpp new file mode 100644 index 00000000..cf5ecfe3 --- /dev/null +++ b/src/gui/ncc/Background.hpp @@ -0,0 +1,42 @@ +/* + * Background.hpp + * + * Created on: Apr 28, 2017 + * Author: nullifiedcat + */ + +#ifndef BACKGROUND_HPP_ +#define BACKGROUND_HPP_ + +#include "Menu.hpp" + +extern unsigned char _binary_snowflake_start; + +namespace menu { namespace ncc { + +class Background : public CBaseWidget { +public: + struct Snowflake { + float x, y; + int show_in { 0 }; + bool dead { false }; + Snowflake* next { nullptr }; + Snowflake* prev { nullptr }; + void Update(); + }; +public: + Background(); + ~Background(); + virtual void Draw(int x, int y) override; + virtual void Update() override; + void MakeSnowflake(); + void KillSnowflake(Snowflake* flake); +public: + Texture snowflake_texture; + Snowflake* list { nullptr }; + Snowflake* list_tail { nullptr }; +}; + +}} + +#endif /* BACKGROUND_HPP_ */ diff --git a/src/gui/ncc/ItemVariable.cpp b/src/gui/ncc/ItemVariable.cpp index 66c99a58..e2931df5 100644 --- a/src/gui/ncc/ItemVariable.cpp +++ b/src/gui/ncc/ItemVariable.cpp @@ -81,6 +81,8 @@ void ItemVariable::OnKeyPress(ButtonCode_t key, bool repeat) { } } + if (change < 1.0f && catvar.type == CV_INT) change = 1.0f; + if ((catvar.type == CV_SWITCH && key == ButtonCode_t::MOUSE_FIRST) || key == ButtonCode_t::MOUSE_WHEEL_UP) { Change(change); } else if (key == ButtonCode_t::MOUSE_WHEEL_DOWN) { diff --git a/src/gui/ncc/Menu.cpp b/src/gui/ncc/Menu.cpp index ab844db8..e41c33ce 100644 --- a/src/gui/ncc/Menu.cpp +++ b/src/gui/ncc/Menu.cpp @@ -439,6 +439,12 @@ static const std::string list_tf2 = R"( "GUI" [ "GUI Settings" "logo" + "gui_snowflake_chance" + "gui_snowflake_pack_size" + "gui_snowflake_safe_zone" + "gui_snowflake_gravity" + "gui_snowflake_jittering" + "gui_snowflake_jittering_chance" "gui_color_b" "gui_color_g" "gui_color_r" diff --git a/src/gui/ncc/Menu.hpp b/src/gui/ncc/Menu.hpp index ac5df87e..7f4bbc39 100644 --- a/src/gui/ncc/Menu.hpp +++ b/src/gui/ncc/Menu.hpp @@ -23,6 +23,7 @@ #include "Radar.hpp" #include "Root.hpp" #include "Tooltip.hpp" +#include "Background.hpp" #include "Logo.hpp" namespace menu { namespace ncc { diff --git a/src/gui/ncc/Root.cpp b/src/gui/ncc/Root.cpp index 195cb274..6b7f593b 100644 --- a/src/gui/ncc/Root.cpp +++ b/src/gui/ncc/Root.cpp @@ -35,6 +35,7 @@ void Root::Setup() { tooltip = new Tooltip(); Logo* logo = new Logo(); logo->SetOffset(draw::width / 2 - 288, 25); + AddChild(new Background()); AddChild(logo); AddChild(tooltip); AddChild(&menu::ncc::MainList());