aboutsummaryrefslogtreecommitdiff
path: root/CastleManager.cpp
blob: 6b85e3679fd8cbf18c915740d8c1cd9aab665399 (plain)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "CastleManager.h"

#include "ThreadsafeQueue.h"


#include "Engine.h"
#include "SDK.h"
#include "Renderer.h"
#include "Config.h"

bool warningEnabled = true;
int notification = 0;

ThreadSafeQueue<std::string> localMessages;
ThreadSafeQueue<std::string> teamMessages;
ThreadSafeQueue<std::string> allMessages;

void CastleManager::LoadConfig()
{
	Config* config = Config::Get();
	notification = config->ReadInt("CastleManager", "notification");
	warningEnabled = config->ReadInt("CastleManager", "warningEnabled");
}

void CastleManager::SaveConfig()
{
	Config* config = Config::Get();
	config->Write<int>("CastleManager", "warningEnabled", warningEnabled);
	config->Write<int>("CastleManager", "notification", notification);
}

void CastleManager::OnUnitIteration(Unit* unit, Player* player, int playerIndex)
{
	
}

void CastleManager::OnUnitCreated(Unit* unit)
{
	if (!warningEnabled)
	{
		return;
	}
	Player* owningPlayer = unit->GetOwner();
	if (!owningPlayer /*|| owningPlayer == Engine::Get()->GetLocalPlayer()*/)
	{
		return;
	}
	
	if (strcmp("CSTL", unit->GetUnitData()->GetName()) == 0)
	{
		std::string message = std::string(owningPlayer->name) + " is building a castle!";
		const char* charMessage = message.c_str();

		switch (notification)
		{
		case 0:
			localMessages.push(message);
			break;
		case 1:
			teamMessages.push(message);
			break;
		case 2:
			allMessages.push(message);
			break;
		default:
			break;
		}
	}
}

void CastleManager::OnMenuMainWindow()
{
	if (!localMessages.isEmpty())
	{
		std::string message;
		localMessages.pop(message);
		Engine::Get()->PrintNotification(message.c_str());
	}

	if (!teamMessages.isEmpty())
	{
		std::string message;
		teamMessages.pop(message);
		Engine::Get()->SendChat(message.c_str(), true);
	}

	if (!allMessages.isEmpty())
	{
		std::string message;
		allMessages.pop(message);
		Engine::Get()->SendChat(message.c_str(), false);
	}
	
	ImGui::Separator();
	ImGui::Text("Castle Manager");
	ImGui::Checkbox("Warning", &warningEnabled);
	ImGui::Text("Notification");
	ImGui::SameLine();
	ImGui::RadioButton("Local", &notification, 0);
	ImGui::SameLine();
	ImGui::RadioButton("Team", &notification, 1);
	ImGui::SameLine();
	ImGui::RadioButton("All", &notification, 2);
	ImGui::Separator();
}

void CastleManager::OnDraw()
{
	/*if (strcmp("CSTL", unit->pUnitData->name) == 0)
	{
		Vector2 screenPos = Engine::Get()->worldToScreen(unit->position);
		int screenResX = Engine::Get()->GetMainScreen()->pGameScreen->ScreenResX;
		int screenResY = Engine::Get()->GetMainScreen()->pGameScreen->ScreenResY;
		Renderer::Get()->RenderLine(ImVec2(screenResX / 2, screenResY / 2), ImVec2(screenPos.x, screenPos.y), 0xffffffff, 2);
	}*/
}

void CastleManager::OnPlayerIteration(Player* player, int playerIndex)
{
	
}