aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/ChatScreen.cpp
blob: b68e6cac04c4a5f7473a8526904251e9d6388857 (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
#include "stdafx.h"
#include "ChatScreen.h"
#include "MultiplayerLocalPlayer.h"
#include "..\Minecraft.World\SharedConstants.h"
#include "..\Minecraft.World\StringHelpers.h"

const wstring ChatScreen::allowedChars = SharedConstants::acceptableLetters;

ChatScreen::ChatScreen()
{
	frame = 0;
}

void ChatScreen::init()
{
	Keyboard::enableRepeatEvents(true);
}

void ChatScreen::removed()
{
	Keyboard::enableRepeatEvents(false);
}

void ChatScreen::tick()
{
	frame++;
}

void ChatScreen::keyPressed(wchar_t ch, int eventKey)
{
    if (eventKey == Keyboard::KEY_ESCAPE)
	{
        minecraft->setScreen(NULL);
        return;
    }
    if (eventKey == Keyboard::KEY_RETURN)
	{
        wstring msg = trimString(message);
        if (msg.length() > 0)
		{
            wstring trim = trimString(message);
            if (!minecraft->handleClientSideCommand(trim))
			{
                minecraft->player->chat(trim);
            }
        }
        minecraft->setScreen(NULL);
        return;
    }
    if (eventKey == Keyboard::KEY_BACK && message.length() > 0) message = message.substr(0, message.length() - 1);
    if (allowedChars.find(ch) >= 0 && message.length() < SharedConstants::maxChatLength)
	{
        message += ch;
    }

}

void ChatScreen::render(int xm, int ym, float a)
{
    fill(2, height - 14, width - 2, height - 2, 0x80000000);
    drawString(font, L"> " + message + (frame / 6 % 2 == 0 ? L"_" : L""), 4, height - 12, 0xe0e0e0);

    Screen::render(xm, ym, a);
}

void ChatScreen::mouseClicked(int x, int y, int buttonNum)
{
    if (buttonNum == 0)
	{
        if (minecraft->gui->selectedName != L"")	// 4J - was NULL comparison
		{
			if (message.length() > 0 && message[message.length()-1]!=L' ')
			{
                message += L" ";
            }
            message += minecraft->gui->selectedName;
            unsigned int maxLength = SharedConstants::maxChatLength;
            if (message.length() > maxLength)
			{
                message = message.substr(0, maxLength);
            }
        }
		else
		{
            Screen::mouseClicked(x, y, buttonNum);
        }
    }

}