aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/ControlsScreen.cpp
blob: 487dbb160658be966d11dc4ade696d9771d4b77a (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
#include "stdafx.h"
#include "ControlsScreen.h"
#include "Options.h"
#include "SmallButton.h"
#include "..\Minecraft.World\net.minecraft.locale.h"

ControlsScreen::ControlsScreen(Screen *lastScreen, Options *options)
{
	// 4J - added initialisers
	title == L"Controls";
	selectedKey = -1;

	this->lastScreen = lastScreen;
    this->options = options;
}

int ControlsScreen::getLeftScreenPosition()
{
	return width / 2 - 155;
}

void ControlsScreen::init()
{
    Language *language = Language::getInstance();

    int leftPos = getLeftScreenPosition();
    for (int i = 0; i < Options::keyMappings_length; i++)
	{
        buttons.push_back(new SmallButton(i, leftPos + i % 2 * ROW_WIDTH, height / 6 + 24 * (i >> 1), BUTTON_WIDTH, 20, options->getKeyMessage(i)));
    }

    buttons.push_back(new Button(200, width / 2 - 100, height / 6 + 24 * 7, language->getElement(L"gui.done")));
    title = language->getElement(L"controls.title");

}

void ControlsScreen::buttonClicked(Button *button)
{
    for (int i = 0; i < Options::keyMappings_length; i++)
	{
        buttons[i]->msg = options->getKeyMessage(i);
    }
    if (button->id == 200)
	{
        minecraft->setScreen(lastScreen);
    }
	else
	{
        selectedKey = button->id;
        button->msg = L"> " + options->getKeyMessage(button->id) + L" <";
    }
}

void ControlsScreen::keyPressed(wchar_t eventCharacter, int eventKey)
{
    if (selectedKey >= 0)
	{
        options->setKey(selectedKey, eventKey);
        buttons[selectedKey]->msg = options->getKeyMessage(selectedKey);
        selectedKey = -1;
    }
	else
	{
        Screen::keyPressed(eventCharacter, eventKey);
    }
}

void ControlsScreen::render(int xm, int ym, float a)
{
    renderBackground();
    drawCenteredString(font, title, width / 2, 20, 0xffffff);

    int leftPos = getLeftScreenPosition();
    for (int i = 0; i < Options::keyMappings_length; i++)
	{
        drawString(font, options->getKeyDescription(i), leftPos + i % 2 * ROW_WIDTH + BUTTON_WIDTH + 6, height / 6 + 24 * (i >> 1) + 7, 0xffffffff);
    }

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