File: MpInGameCanvasLayer.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 (67 lines) | stat: -rw-r--r-- 1,985 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
#include "MpInGameCanvasLayer.h"

#if defined(WITH_MULTIPLAYER)

#include "../../ContentResolver.h"
#include "../../LevelHandler.h"
#include "../../Actors/Multiplayer/MpPlayer.h"

#include "../../../nCine/Graphics/RenderQueue.h"

using namespace Jazz2::Multiplayer;

namespace Jazz2::UI::Multiplayer
{
	MpInGameCanvasLayer::MpInGameCanvasLayer(MpLevelHandler* levelHandler)
		: _levelHandler(levelHandler)
	{
		auto& resolver = ContentResolver::Get();

		_smallFont = resolver.GetFont(FontType::Small);
	}

	bool MpInGameCanvasLayer::OnDraw(RenderQueue& renderQueue)
	{
		Canvas::OnDraw(renderQueue);

		if (_levelHandler->_isServer) {
			for (auto& [peer, peerDesc] : *_levelHandler->_networkManager->GetPeers()) {
				if (peerDesc->RemotePeer && peerDesc->Player && peerDesc->Player->_renderer.isEnabled()) {
					auto pos = peerDesc->Player->GetPos();
					DrawStringShadow(peerDesc->PlayerName, pos.X, pos.Y - 42.0f);
				}
			}
		} else {
			for (auto& [actorId, playerName] : _levelHandler->_playerNames) {
				auto it = _levelHandler->_remoteActors.find(actorId);
				if (it != _levelHandler->_remoteActors.end() && it->second->_renderer.isEnabled()) {
					auto pos = it->second->GetPos();
					DrawStringShadow(playerName, pos.X, pos.Y - 42.0f);
				}
			}
		}

		return true;
	}

	void MpInGameCanvasLayer::DrawStringShadow(StringView text, float x, float y)
	{
		x = std::round(x);
		y = std::round(y);

		float textScale = 0.7f;
		if (text == "\xF0\x9D\x94\x87\xF0\x9D\x94\xA2\xF0\x9D\x94\x9E\xF0\x9D\x94\xB1\xF0\x9D\x94\xA5"_s) {
			textScale = 0.8f;
		}

		std::int32_t charOffsetShadow = 0;
		_smallFont->DrawString(this, text, charOffsetShadow, x, y + 1.0f, FontShadowLayer, Alignment::Center,
			Colorf(0.0f, 0.0f, 0.0f, 0.36f), textScale, 0.0f, 0.0f, 0.0f, 0.0f, 0.8f);

		std::int32_t charOffset = 0;
		_smallFont->DrawString(this, text, charOffset, x, y, FontLayer, Alignment::Center,
			Font::DefaultColor, textScale, 0.0f, 0.0f, 0.0f, 0.0f, 0.8f);
	}
}

#endif