File: RefreshCacheSection.cpp

package info (click to toggle)
jazz2-native 3.5.0-1
  • links: PTS, VCS
  • area: contrib
  • in suites:
  • size: 16,836 kB
  • sloc: cpp: 172,557; xml: 113; python: 36; makefile: 5; sh: 2
file content (92 lines) | stat: -rw-r--r-- 3,202 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "RefreshCacheSection.h"

#if !defined(DEATH_TARGET_EMSCRIPTEN)

#include "MenuResources.h"
#include "MainMenu.h"

#include "../../../nCine/I18n.h"
#include "../../../nCine/Graphics/BinaryShaderCache.h"
#include "../../../nCine/Graphics/RenderResources.h"

using namespace Jazz2::UI::Menu::Resources;
using namespace nCine;

namespace Jazz2::UI::Menu
{
	RefreshCacheSection::RefreshCacheSection()
		: _animation(0.0f), _done(false)
	{
	}

	void RefreshCacheSection::OnShow(IMenuContainer* root)
	{
		MenuSection::OnShow(root);

#if defined(WITH_THREADS)
		_thread = Thread([](void* arg) {
			auto _this = static_cast<RefreshCacheSection*>(arg);
			if (auto mainMenu = runtime_cast<MainMenu>(_this->_root)) {
				mainMenu->_root->RefreshCacheLevels(true);
			}

			std::uint32_t filesRemoved = RenderResources::GetBinaryShaderCache().Prune();
			LOGI("Pruning binary shader cache (removed {} directories)...", filesRemoved);

			_this->_done = true;
		}, this);
#else
		if (auto mainMenu = runtime_cast<MainMenu*>(_root)) {
			mainMenu->_root->RefreshCacheLevels(true);
		}

		std::uint32_t filesRemoved = RenderResources::binaryShaderCache().Prune();
		LOGI("Pruning binary shader cache (removed {} directories)...", filesRemoved);

		_done = true;
#endif
	}

	void RefreshCacheSection::OnUpdate(float timeMult)
	{
		if (_animation < 1.0f) {
			_animation = std::min(_animation + timeMult * 0.016f, 1.0f);
		}
		if (_done) {
			_root->PlaySfx("MenuSelect"_s, 0.5f);
			_root->LeaveSection();
		}
	}

	void RefreshCacheSection::OnDraw(Canvas* canvas)
	{
		Recti contentBounds = _root->GetContentBounds();
		Vector2f center = Vector2f(contentBounds.X + contentBounds.W * 0.5f, contentBounds.Y + contentBounds.H * 0.5f);
		float topLine = contentBounds.Y + 31.0f;
		float bottomLine = contentBounds.Y + contentBounds.H - 42.0f;

		_root->DrawElement(MenuDim, center.X, (topLine + bottomLine) * 0.5f, IMenuContainer::BackgroundLayer,
			Alignment::Center, Colorf::Black, Vector2f(680.0f, bottomLine - topLine + 2), Vector4f(1.0f, 0.0f, 0.4f, 0.3f));
		_root->DrawElement(MenuLine, 0, center.X, topLine, IMenuContainer::MainLayer, Alignment::Center, Colorf::White, 1.6f);
		_root->DrawElement(MenuLine, 1, center.X, bottomLine, IMenuContainer::MainLayer, Alignment::Center, Colorf::White, 1.6f);

		center.Y = topLine + (bottomLine - topLine) * 0.4f;
		std::int32_t charOffset = 0;

		_root->DrawStringShadow(_("Refresh Cache"), charOffset, center.X, topLine - 21.0f, IMenuContainer::FontLayer,
			Alignment::Center, Colorf(0.46f, 0.46f, 0.46f, 0.5f), 0.9f, 0.7f, 1.1f, 1.1f, 0.4f, 0.9f);

		_root->DrawStringShadow(_("Processing of files in \f[c:#9e7056]\"Source\"\f[/c] directory..."), charOffset, center.X, center.Y, IMenuContainer::FontLayer,
			Alignment::Center, Font::DefaultColor, 0.9f, 0.7f, 1.1f, 1.1f, 0.4f, 0.9f);

		_root->DrawStringShadow(_("Newly added levels and episodes will be available soon."), charOffset, center.X, center.Y + 24.0f, IMenuContainer::FontLayer,
			Alignment::Top, Font::DefaultColor, 0.8f, 0.7f, 1.1f, 1.1f, 0.4f, 0.9f);
	}

	void RefreshCacheSection::OnTouchEvent(const nCine::TouchEvent& event, Vector2i viewSize)
	{
		// No actions are allowed
	}
}

#endif