chore: format Minecraft.Client

This commit is contained in:
Tropical
2026-03-13 17:10:10 -05:00
parent 33d0737d1d
commit e8424f2000
531 changed files with 67709 additions and 62690 deletions

View File

@@ -2,23 +2,20 @@
#include "Button.h"
#include "../Textures/Textures.h"
Button::Button(int id, int x, int y, const std::wstring& msg)
{
init(id, x, y, 200, 20, msg);
Button::Button(int id, int x, int y, const std::wstring& msg) {
init(id, x, y, 200, 20, msg);
}
Button::Button(int id, int x, int y, int w, int h, const std::wstring& msg)
{
init(id, x, y, w, h, msg);
Button::Button(int id, int x, int y, int w, int h, const std::wstring& msg) {
init(id, x, y, w, h, msg);
}
// 4J - added
void Button::init(int id, int x, int y, int w, int h, const std::wstring& msg)
{
active = true;
visible = true;
void Button::init(int id, int x, int y, int w, int h, const std::wstring& msg) {
active = true;
visible = true;
// this bit of code from original ctor
// this bit of code from original ctor
this->id = id;
this->x = x;
this->y = y;
@@ -27,24 +24,24 @@ void Button::init(int id, int x, int y, int w, int h, const std::wstring& msg)
this->msg = msg;
}
int Button::getYImage(bool hovered)
{
int Button::getYImage(bool hovered) {
int res = 1;
if (!active) res = 0;
else if (hovered) res = 2;
if (!active)
res = 0;
else if (hovered)
res = 2;
return res;
}
void Button::render(Minecraft *minecraft, int xm, int ym)
{
void Button::render(Minecraft* minecraft, int xm, int ym) {
if (!visible) return;
Font *font = minecraft->font;
Font* font = minecraft->font;
glBindTexture(GL_TEXTURE_2D, minecraft->textures->loadTexture(TN_GUI_GUI)); // 4J was L"/gui/gui.png"
glBindTexture(GL_TEXTURE_2D, minecraft->textures->loadTexture(
TN_GUI_GUI)); // 4J was L"/gui/gui.png"
glColor4f(1, 1, 1, 1);
bool hovered = xm >= x && ym >= y && xm < x + w && ym < y + h;
int yImage = getYImage(hovered);
@@ -53,33 +50,21 @@ void Button::render(Minecraft *minecraft, int xm, int ym)
renderBg(minecraft, xm, ym);
if (!active)
{
if (!active) {
drawCenteredString(font, msg, x + w / 2, y + (h - 8) / 2, 0xffa0a0a0);
}
else
{
if (hovered)
{
} else {
if (hovered) {
drawCenteredString(font, msg, x + w / 2, y + (h - 8) / 2, 0xffffa0);
}
else
{
} else {
drawCenteredString(font, msg, x + w / 2, y + (h - 8) / 2, 0xe0e0e0);
}
}
}
void Button::renderBg(Minecraft *minecraft, int xm, int ym)
{
}
void Button::renderBg(Minecraft* minecraft, int xm, int ym) {}
void Button::released(int mx, int my)
{
}
void Button::released(int mx, int my) {}
bool Button::clicked(Minecraft *minecraft, int mx, int my)
{
return active && mx >= x && my >= y && mx < x + w && my < y + h;
bool Button::clicked(Minecraft* minecraft, int mx, int my) {
return active && mx >= x && my >= y && mx < x + w && my < y + h;
}

View File

@@ -1,14 +1,13 @@
#pragma once
#include "GuiComponent.h"
class Button : public GuiComponent
{
class Button : public GuiComponent {
protected:
int w;
int w;
int h;
public:
int x, y;
int x, y;
std::wstring msg;
int id;
bool active;
@@ -16,15 +15,18 @@ public:
Button(int id, int x, int y, const std::wstring& msg);
Button(int id, int x, int y, int w, int h, const std::wstring& msg);
void init(int id, int x, int y, int w, int h, const std::wstring& msg); // 4J - added
void init(int id, int x, int y, int w, int h,
const std::wstring& msg); // 4J - added
protected:
virtual int getYImage(bool hovered);
virtual int getYImage(bool hovered);
public:
virtual void render(Minecraft *minecraft, int xm, int ym);
virtual void render(Minecraft* minecraft, int xm, int ym);
protected:
virtual void renderBg(Minecraft *minecraft, int xm, int ym);
virtual void renderBg(Minecraft* minecraft, int xm, int ym);
public:
virtual void released(int mx, int my);
virtual bool clicked(Minecraft *minecraft, int mx, int my);
virtual void released(int mx, int my);
virtual bool clicked(Minecraft* minecraft, int mx, int my);
};

View File

@@ -2,109 +2,84 @@
#include "EditBox.h"
#include "../../Minecraft.World/Util/SharedConstants.h"
EditBox::EditBox(Screen *screen, Font *font, int x, int y, int width, int height, const std::wstring& value)
{
// 4J - added initialisers
maxLength = 0;
frame = 0;
EditBox::EditBox(Screen* screen, Font* font, int x, int y, int width,
int height, const std::wstring& value) {
// 4J - added initialisers
maxLength = 0;
frame = 0;
this->screen = screen;
this->font = font;
this->x = x;
this->y = y;
this->width = width;
this->height = height;
this->setValue(value);
this->screen = screen;
this->font = font;
this->x = x;
this->y = y;
this->width = width;
this->height = height;
this->setValue(value);
}
void EditBox::setValue(const std::wstring& value)
{
this->value = value;
}
void EditBox::setValue(const std::wstring& value) { this->value = value; }
std::wstring EditBox::getValue()
{
return value;
}
std::wstring EditBox::getValue() { return value; }
void EditBox::tick()
{
frame++;
}
void EditBox::tick() { frame++; }
void EditBox::keyPressed(wchar_t ch, int eventKey)
{
void EditBox::keyPressed(wchar_t ch, int eventKey) {
if (!active || !inFocus) {
return;
}
if (ch == 9)
{
if (ch == 9) {
screen->tabPressed();
}
/* 4J removed
if (ch == 22)
{
String msg = Screen.getClipboard();
if (msg == null) msg = "";
int toAdd = 32 - value.length();
if (toAdd > msg.length()) toAdd = msg.length();
if (toAdd > 0) {
value += msg.substring(0, toAdd);
/* 4J removed
if (ch == 22)
{
String msg = Screen.getClipboard();
if (msg == null) msg = "";
int toAdd = 32 - value.length();
if (toAdd > msg.length()) toAdd = msg.length();
if (toAdd > 0) {
value += msg.substring(0, toAdd);
}
}
}
*/
*/
if (eventKey == Keyboard::KEY_BACK && value.length() > 0)
{
if (eventKey == Keyboard::KEY_BACK && value.length() > 0) {
value = value.substr(0, value.length() - 1);
}
if (SharedConstants::acceptableLetters.find(ch) != std::wstring::npos && (value.length() < maxLength || maxLength == 0))
{
if (SharedConstants::acceptableLetters.find(ch) != std::wstring::npos &&
(value.length() < maxLength || maxLength == 0)) {
value += ch;
}
}
void EditBox::mouseClicked(int mouseX, int mouseY, int buttonNum)
{
bool newFocus = active && (mouseX >= x && mouseX < (x + width) && mouseY >= y && mouseY < (y + height));
void EditBox::mouseClicked(int mouseX, int mouseY, int buttonNum) {
bool newFocus = active && (mouseX >= x && mouseX < (x + width) &&
mouseY >= y && mouseY < (y + height));
focus(newFocus);
}
void EditBox::focus(bool newFocus)
{
if (newFocus && !inFocus)
{
void EditBox::focus(bool newFocus) {
if (newFocus && !inFocus) {
// reset the underscore counter to give quicker selection feedback
frame = 0;
}
inFocus = newFocus;
}
void EditBox::render()
{
void EditBox::render() {
fill(x - 1, y - 1, x + width + 1, y + height + 1, 0xffa0a0a0);
fill(x, y, x + width, y + height, 0xff000000);
if (active)
{
if (active) {
bool renderUnderscore = inFocus && (frame / 6 % 2 == 0);
drawString(font, value + (renderUnderscore ? L"_" : L""), x + 4, y + (height - 8) / 2, 0xe0e0e0);
}
else
{
drawString(font, value + (renderUnderscore ? L"_" : L""), x + 4,
y + (height - 8) / 2, 0xe0e0e0);
} else {
drawString(font, value, x + 4, y + (height - 8) / 2, 0x707070);
}
}
void EditBox::setMaxLength(int maxLength)
{
this->maxLength = maxLength;
}
void EditBox::setMaxLength(int maxLength) { this->maxLength = maxLength; }
int EditBox::getMaxLength()
{
return maxLength;
}
int EditBox::getMaxLength() { return maxLength; }

View File

@@ -4,10 +4,9 @@
class Font;
class Screen;
class EditBox : public GuiComponent
{
class EditBox : public GuiComponent {
private:
Font *font;
Font* font;
int x;
int y;
int width;
@@ -17,13 +16,15 @@ private:
int frame;
public:
bool inFocus;
bool inFocus;
bool active;
private:
Screen *screen;
Screen* screen;
public:
EditBox(Screen *screen, Font *font, int x, int y, int width, int height, const std::wstring& value);
EditBox(Screen* screen, Font* font, int x, int y, int width, int height,
const std::wstring& value);
void setValue(const std::wstring& value);
std::wstring getValue();
void tick();

View File

@@ -8,71 +8,69 @@
#include "../../Minecraft.World/Util/StringHelpers.h"
#include "../../Minecraft.World/Util/Random.h"
Font::Font(Options *options, const std::wstring& name, Textures* textures, bool enforceUnicode, TEXTURE_NAME textureName, int cols, int rows, int charWidth, int charHeight, unsigned short charMap[]/* = nullptr */) : textures(textures)
{
int charC = cols * rows; // Number of characters in the font
Font::Font(Options* options, const std::wstring& name, Textures* textures,
bool enforceUnicode, TEXTURE_NAME textureName, int cols, int rows,
int charWidth, int charHeight,
unsigned short charMap[] /* = nullptr */)
: textures(textures) {
int charC = cols * rows; // Number of characters in the font
charWidths = new int[charC];
charWidths = new int[charC];
// 4J - added initialisers
memset(charWidths, 0, charC);
// 4J - added initialisers
memset(charWidths, 0, charC);
enforceUnicodeSheet = false;
bidirectional = false;
xPos = yPos = 0.0f;
enforceUnicodeSheet = false;
bidirectional = false;
xPos = yPos = 0.0f;
// Set up member variables
m_cols = cols;
m_rows = rows;
m_charWidth = charWidth;
m_charHeight = charHeight;
m_textureName = textureName;
// Set up member variables
m_cols = cols;
m_rows = rows;
m_charWidth = charWidth;
m_charHeight = charHeight;
m_textureName = textureName;
// Build character map
if (charMap != NULL)
{
for(int i = 0; i < charC; i++)
{
m_charMap.insert(std::make_pair(charMap[i], i));
}
}
random = new Random();
// Load the image
BufferedImage *img = textures->readImage(m_textureName, name);
/* - 4J - TODO
try {
img = ImageIO.read(Textures.class.getResourceAsStream(name));
} catch (IOException e) {
throw new RuntimeException(e);
// Build character map
if (charMap != NULL) {
for (int i = 0; i < charC; i++) {
m_charMap.insert(std::make_pair(charMap[i], i));
}
}
*/
random = new Random();
// Load the image
BufferedImage* img = textures->readImage(m_textureName, name);
/* - 4J - TODO
try {
img = ImageIO.read(Textures.class.getResourceAsStream(name));
} catch (IOException e) {
throw new RuntimeException(e);
}
*/
int w = img->getWidth();
int h = img->getHeight();
intArray rawPixels(w * h);
img->getRGB(0, 0, w, h, rawPixels, 0, w);
for (int i = 0; i < charC; i++)
{
for (int i = 0; i < charC; i++) {
int xt = i % m_cols;
int yt = i / m_cols;
int x = 7;
for (; x >= 0; x--)
{
for (; x >= 0; x--) {
int xPixel = xt * 8 + x;
bool emptyColumn = true;
for (int y = 0; y < 8 && emptyColumn; y++)
{
for (int y = 0; y < 8 && emptyColumn; y++) {
int yPixel = (yt * 8 + y) * w;
bool emptyPixel = (rawPixels[xPixel + yPixel] >> 24) == 0; // Check the alpha value
if (!emptyPixel) emptyColumn = false;
bool emptyPixel = (rawPixels[xPixel + yPixel] >> 24) ==
0; // Check the alpha value
if (!emptyPixel) emptyColumn = false;
}
if (!emptyColumn)
{
if (!emptyColumn) {
break;
}
}
@@ -81,369 +79,326 @@ Font::Font(Options *options, const std::wstring& name, Textures* textures, bool
charWidths[i] = x + 2;
}
delete img;
delete img;
// calculate colors
for (int colorN = 0; colorN < 32; ++colorN)
{
int var10 = (colorN >> 3 & 1) * 85;
int red = (colorN >> 2 & 1) * 170 + var10;
int green = (colorN >> 1 & 1) * 170 + var10;
int blue = (colorN >> 0 & 1) * 170 + var10;
// calculate colors
for (int colorN = 0; colorN < 32; ++colorN) {
int var10 = (colorN >> 3 & 1) * 85;
int red = (colorN >> 2 & 1) * 170 + var10;
int green = (colorN >> 1 & 1) * 170 + var10;
int blue = (colorN >> 0 & 1) * 170 + var10;
if (colorN == 6)
{
red += 85;
}
if (colorN == 6) {
red += 85;
}
if (options->anaglyph3d)
{
int tmpRed = (red * 30 + green * 59 + blue * 11) / 100;
int tmpGreen = (red * 30 + green * 70) / 100;
int tmpBlue = (red * 30 + blue * 70) / 100;
red = tmpRed;
green = tmpGreen;
blue = tmpBlue;
}
if (options->anaglyph3d) {
int tmpRed = (red * 30 + green * 59 + blue * 11) / 100;
int tmpGreen = (red * 30 + green * 70) / 100;
int tmpBlue = (red * 30 + blue * 70) / 100;
red = tmpRed;
green = tmpGreen;
blue = tmpBlue;
}
if (colorN >= 16)
{
red /= 4;
green /= 4;
blue /= 4;
}
if (colorN >= 16) {
red /= 4;
green /= 4;
blue /= 4;
}
colors[colorN] = (red & 255) << 16 | (green & 255) << 8 | (blue & 255);
}
colors[colorN] = (red & 255) << 16 | (green & 255) << 8 | (blue & 255);
}
}
#ifndef _XBOX
// 4J Stu - This dtor clashes with one in xui! We never delete these anyway so take it out for now. Can go back when we have got rid of XUI
Font::~Font()
{
delete[] charWidths;
}
// 4J Stu - This dtor clashes with one in xui! We never delete these anyway so
// take it out for now. Can go back when we have got rid of XUI
Font::~Font() { delete[] charWidths; }
#endif
void Font::renderCharacter(wchar_t c)
{
float xOff = c % m_cols * m_charWidth;
float yOff = c / m_cols * m_charWidth;
void Font::renderCharacter(wchar_t c) {
float xOff = c % m_cols * m_charWidth;
float yOff = c / m_cols * m_charWidth;
float width = charWidths[c] - .01f;
float height = m_charHeight - .01f;
float fontWidth = m_cols * m_charWidth;
float fontHeight = m_rows * m_charHeight;
float width = charWidths[c] - .01f;
float height = m_charHeight - .01f;
Tesselator *t = Tesselator::getInstance();
// 4J Stu - Changed to a quad so that we can use within a command buffer
float fontWidth = m_cols * m_charWidth;
float fontHeight = m_rows * m_charHeight;
Tesselator* t = Tesselator::getInstance();
// 4J Stu - Changed to a quad so that we can use within a command buffer
#if 1
t->begin();
t->tex(xOff / fontWidth, (yOff + 7.99f) / fontHeight);
t->vertex(xPos, yPos + height, 0.0f);
t->begin();
t->tex(xOff / fontWidth, (yOff + 7.99f) / fontHeight);
t->vertex(xPos, yPos + height, 0.0f);
t->tex((xOff + width) / fontWidth, (yOff + 7.99f) / fontHeight);
t->vertex(xPos + width, yPos + height, 0.0f);
t->tex((xOff + width) / fontWidth, (yOff + 7.99f) / fontHeight);
t->vertex(xPos + width, yPos + height, 0.0f);
t->tex((xOff + width) / fontWidth, yOff / fontHeight);
t->vertex(xPos + width, yPos, 0.0f);
t->tex((xOff + width) / fontWidth, yOff / fontHeight);
t->vertex(xPos + width, yPos, 0.0f);
t->tex(xOff / fontWidth, yOff / fontHeight);
t->vertex(xPos, yPos, 0.0f);
t->tex(xOff / fontWidth, yOff / fontHeight);
t->vertex(xPos, yPos, 0.0f);
t->end();
t->end();
#else
t->begin(GL_TRIANGLE_STRIP);
t->tex(xOff / 128.0F, yOff / 128.0F);
t->vertex(xPos, yPos, 0.0f);
t->tex(xOff / 128.0F, (yOff + 7.99f) / 128.0F);
t->vertex(xPos, yPos + 7.99f, 0.0f);
t->tex((xOff + width) / 128.0F, yOff / 128.0F);
t->vertex(xPos + width, yPos, 0.0f);
t->tex((xOff + width) / 128.0F, (yOff + 7.99f) / 128.0F);
t->vertex(xPos + width, yPos + 7.99f, 0.0f);
t->end();
t->begin(GL_TRIANGLE_STRIP);
t->tex(xOff / 128.0F, yOff / 128.0F);
t->vertex(xPos, yPos, 0.0f);
t->tex(xOff / 128.0F, (yOff + 7.99f) / 128.0F);
t->vertex(xPos, yPos + 7.99f, 0.0f);
t->tex((xOff + width) / 128.0F, yOff / 128.0F);
t->vertex(xPos + width, yPos, 0.0f);
t->tex((xOff + width) / 128.0F, (yOff + 7.99f) / 128.0F);
t->vertex(xPos + width, yPos + 7.99f, 0.0f);
t->end();
#endif
xPos += (float) charWidths[c];
xPos += (float)charWidths[c];
}
void Font::drawShadow(const std::wstring& str, int x, int y, int color)
{
void Font::drawShadow(const std::wstring& str, int x, int y, int color) {
draw(str, x + 1, y + 1, color, true);
draw(str, x, y, color, false);
}
void Font::drawShadowWordWrap(const std::wstring &str, int x, int y, int w, int color, int h)
{
drawWordWrapInternal(str, x + 1, y + 1, w, color, true, h);
drawWordWrapInternal(str, x, y, w, color, h);
void Font::drawShadowWordWrap(const std::wstring& str, int x, int y, int w,
int color, int h) {
drawWordWrapInternal(str, x + 1, y + 1, w, color, true, h);
drawWordWrapInternal(str, x, y, w, color, h);
}
void Font::draw(const std::wstring& str, int x, int y, int color)
{
draw(str, x, y, color, false);
void Font::draw(const std::wstring& str, int x, int y, int color) {
draw(str, x, y, color, false);
}
std::wstring Font::reorderBidi(const std::wstring &str)
{
// 4J Not implemented
return str;
std::wstring Font::reorderBidi(const std::wstring& str) {
// 4J Not implemented
return str;
}
void Font::draw(const std::wstring &str, bool dropShadow)
{
// Bind the texture
textures->bindTexture(m_textureName);
void Font::draw(const std::wstring& str, bool dropShadow) {
// Bind the texture
textures->bindTexture(m_textureName);
bool noise = false;
std::wstring cleanStr = sanitize(str);
bool noise = false;
std::wstring cleanStr = sanitize(str);
for (int i = 0; i < (int)cleanStr.length(); ++i)
{
// Map character
wchar_t c = cleanStr.at(i);
for (int i = 0; i < (int)cleanStr.length(); ++i) {
// Map character
wchar_t c = cleanStr.at(i);
if (c == 167 && i + 1 < cleanStr.length())
{
// 4J - following block was:
// int colorN = L"0123456789abcdefk".indexOf(str.toLowerCase().charAt(i + 1));
wchar_t ca = cleanStr[i+1];
int colorN = 16;
if(( ca >= L'0' ) && (ca <= L'9')) colorN = ca - L'0';
else if(( ca >= L'a' ) && (ca <= L'f')) colorN = (ca - L'a') + 10;
else if(( ca >= L'A' ) && (ca <= L'F')) colorN = (ca - L'A') + 10;
if (c == 167 && i + 1 < cleanStr.length()) {
// 4J - following block was:
// int colorN =
// L"0123456789abcdefk".indexOf(str.toLowerCase().charAt(i + 1));
wchar_t ca = cleanStr[i + 1];
int colorN = 16;
if ((ca >= L'0') && (ca <= L'9'))
colorN = ca - L'0';
else if ((ca >= L'a') && (ca <= L'f'))
colorN = (ca - L'a') + 10;
else if ((ca >= L'A') && (ca <= L'F'))
colorN = (ca - L'A') + 10;
if (colorN == 16)
{
noise = true;
}
else
{
noise = false;
if (colorN < 0 || colorN > 15) colorN = 15;
if (colorN == 16) {
noise = true;
} else {
noise = false;
if (colorN < 0 || colorN > 15) colorN = 15;
if (dropShadow) colorN += 16;
if (dropShadow) colorN += 16;
int color = colors[colorN];
glColor3f((color >> 16) / 255.0F, ((color >> 8) & 255) / 255.0F, (color & 255) / 255.0F);
}
int color = colors[colorN];
glColor3f((color >> 16) / 255.0F, ((color >> 8) & 255) / 255.0F,
(color & 255) / 255.0F);
}
i += 1;
continue;
}
i += 1;
continue;
}
// "noise" for crazy splash screen message
if (noise)
{
int newc;
do
{
newc = random->nextInt(SharedConstants::acceptableLetters.length());
} while (charWidths[c + 32] != charWidths[newc + 32]);
c = newc;
}
// "noise" for crazy splash screen message
if (noise) {
int newc;
do {
newc = random->nextInt(
SharedConstants::acceptableLetters.length());
} while (charWidths[c + 32] != charWidths[newc + 32]);
c = newc;
}
renderCharacter(c);
}
renderCharacter(c);
}
}
void Font::draw(const std::wstring& str, int x, int y, int color, bool dropShadow)
{
if (!str.empty())
{
if ((color & 0xFC000000) == 0) color |= 0xFF000000; // force alpha
// if not set
void Font::draw(const std::wstring& str, int x, int y, int color,
bool dropShadow) {
if (!str.empty()) {
if ((color & 0xFC000000) == 0) color |= 0xFF000000; // force alpha
// if not set
if (dropShadow) // divide RGB by 4, preserve alpha
// 4jcraft changed -1 << 24 to the value of 1 (0xFF FF FF FF)
color = (color & 0xfcfcfc) >> 2 | (color & (0xFFFFFFFF << 24));
if (dropShadow) // divide RGB by 4, preserve alpha
// 4jcraft changed -1 << 24 to the value of 1 (0xFF FF
// FF FF)
color = (color & 0xfcfcfc) >> 2 | (color & (0xFFFFFFFF << 24));
glColor4f((color >> 16 & 255) / 255.0F, (color >> 8 & 255) / 255.0F, (color & 255) / 255.0F, (color >> 24 & 255) / 255.0F);
glColor4f((color >> 16 & 255) / 255.0F, (color >> 8 & 255) / 255.0F,
(color & 255) / 255.0F, (color >> 24 & 255) / 255.0F);
xPos = x;
yPos = y;
draw(str, dropShadow);
}
xPos = x;
yPos = y;
draw(str, dropShadow);
}
}
int Font::width(const std::wstring& str)
{
std::wstring cleanStr = sanitize(str);
int Font::width(const std::wstring& str) {
std::wstring cleanStr = sanitize(str);
if (cleanStr == L"") return 0; // 4J - was NULL comparison
int len = 0;
if (cleanStr == L"") return 0; // 4J - was NULL comparison
int len = 0;
for (int i = 0; i < cleanStr.length(); ++i)
{
wchar_t c = cleanStr.at(i);
for (int i = 0; i < cleanStr.length(); ++i) {
wchar_t c = cleanStr.at(i);
if(c == 167)
{
// Ignore the character used to define coloured text
++i;
}
else
{
len += charWidths[c];
}
}
if (c == 167) {
// Ignore the character used to define coloured text
++i;
} else {
len += charWidths[c];
}
}
return len;
return len;
}
std::wstring Font::sanitize(const std::wstring& str)
{
std::wstring sb = str;
std::wstring Font::sanitize(const std::wstring& str) {
std::wstring sb = str;
for (unsigned int i = 0; i < sb.length(); i++)
{
if (CharacterExists(sb[i]))
{
sb[i] = MapCharacter(sb[i]);
}
else
{
// If this character isn't supported, just show the first character (empty square box character)
sb[i] = 0;
}
for (unsigned int i = 0; i < sb.length(); i++) {
if (CharacterExists(sb[i])) {
sb[i] = MapCharacter(sb[i]);
} else {
// If this character isn't supported, just show the first character
// (empty square box character)
sb[i] = 0;
}
}
return sb;
}
int Font::MapCharacter(wchar_t c)
{
if (!m_charMap.empty())
{
// Don't map space character
return c == ' ' ? c : m_charMap[c];
}
else
{
return c;
}
int Font::MapCharacter(wchar_t c) {
if (!m_charMap.empty()) {
// Don't map space character
return c == ' ' ? c : m_charMap[c];
} else {
return c;
}
}
bool Font::CharacterExists(wchar_t c)
{
if (!m_charMap.empty())
{
return m_charMap.find(c) != m_charMap.end();
}
else
{
return c >= 0 && c <= m_rows*m_cols;
}
bool Font::CharacterExists(wchar_t c) {
if (!m_charMap.empty()) {
return m_charMap.find(c) != m_charMap.end();
} else {
return c >= 0 && c <= m_rows * m_cols;
}
}
void Font::drawWordWrap(const std::wstring &string, int x, int y, int w, int col, int h)
{
//if (bidirectional)
//{
// string = reorderBidi(string);
//}
drawWordWrapInternal(string, x, y, w, col, h);
void Font::drawWordWrap(const std::wstring& string, int x, int y, int w,
int col, int h) {
// if (bidirectional)
//{
// string = reorderBidi(string);
// }
drawWordWrapInternal(string, x, y, w, col, h);
}
void Font::drawWordWrapInternal(const std::wstring &string, int x, int y, int w, int col, int h)
{
drawWordWrapInternal(string, x, y, w, col, false, h);
void Font::drawWordWrapInternal(const std::wstring& string, int x, int y, int w,
int col, int h) {
drawWordWrapInternal(string, x, y, w, col, false, h);
}
void Font::drawWordWrap(const std::wstring &string, int x, int y, int w, int col, bool darken, int h)
{
//if (bidirectional)
//{
// string = reorderBidi(string);
//}
drawWordWrapInternal(string, x, y, w, col, darken, h);
void Font::drawWordWrap(const std::wstring& string, int x, int y, int w,
int col, bool darken, int h) {
// if (bidirectional)
//{
// string = reorderBidi(string);
// }
drawWordWrapInternal(string, x, y, w, col, darken, h);
}
void Font::drawWordWrapInternal(const std::wstring& string, int x, int y, int w, int col, bool darken, int h)
{
std::vector<std::wstring>lines = stringSplit(string,L'\n');
if (lines.size() > 1)
{
AUTO_VAR(itEnd, lines.end());
for (AUTO_VAR(it, lines.begin()); it != itEnd; it++)
{
// 4J Stu - Don't draw text that will be partially cutoff/overlap something it shouldn't
if( (y + this->wordWrapHeight(*it, w)) > h) break;
void Font::drawWordWrapInternal(const std::wstring& string, int x, int y, int w,
int col, bool darken, int h) {
std::vector<std::wstring> lines = stringSplit(string, L'\n');
if (lines.size() > 1) {
AUTO_VAR(itEnd, lines.end());
for (AUTO_VAR(it, lines.begin()); it != itEnd; it++) {
// 4J Stu - Don't draw text that will be partially cutoff/overlap
// something it shouldn't
if ((y + this->wordWrapHeight(*it, w)) > h) break;
drawWordWrapInternal(*it, x, y, w, col, h);
y += this->wordWrapHeight(*it, w);
}
return;
}
std::vector<std::wstring> words = stringSplit(string,L' ');
std::vector<std::wstring> words = stringSplit(string, L' ');
unsigned int pos = 0;
while (pos < words.size())
{
while (pos < words.size()) {
std::wstring line = words[pos++] + L" ";
while (pos < words.size() && width(line + words[pos]) < w)
{
while (pos < words.size() && width(line + words[pos]) < w) {
line += words[pos++] + L" ";
}
while (width(line) > w)
{
while (width(line) > w) {
int l = 0;
while (width(line.substr(0, l + 1)) <= w)
{
while (width(line.substr(0, l + 1)) <= w) {
l++;
}
if (trimString(line.substr(0, l)).length() > 0)
{
if (trimString(line.substr(0, l)).length() > 0) {
draw(line.substr(0, l), x, y, col);
y += 8;
}
line = line.substr(l);
// 4J Stu - Don't draw text that will be partially cutoff/overlap something it shouldn't
if( (y + 8) > h) break;
// 4J Stu - Don't draw text that will be partially cutoff/overlap
// something it shouldn't
if ((y + 8) > h) break;
}
// 4J Stu - Don't draw text that will be partially cutoff/overlap something it shouldn't
if (trimString(line).length() > 0 && !( (y + 8) > h) )
{
// 4J Stu - Don't draw text that will be partially cutoff/overlap
// something it shouldn't
if (trimString(line).length() > 0 && !((y + 8) > h)) {
draw(line, x, y, col);
y += 8;
}
}
}
int Font::wordWrapHeight(const std::wstring& string, int w)
{
std::vector<std::wstring> lines = stringSplit(string,L'\n');
if (lines.size() > 1)
{
int Font::wordWrapHeight(const std::wstring& string, int w) {
std::vector<std::wstring> lines = stringSplit(string, L'\n');
if (lines.size() > 1) {
int h = 0;
AUTO_VAR(itEnd, lines.end());
for (AUTO_VAR(it, lines.begin()); it != itEnd; it++)
{
AUTO_VAR(itEnd, lines.end());
for (AUTO_VAR(it, lines.begin()); it != itEnd; it++) {
h += this->wordWrapHeight(*it, w);
}
return h;
}
std::vector<std::wstring> words = stringSplit(string,L' ');
std::vector<std::wstring> words = stringSplit(string, L' ');
unsigned int pos = 0;
int y = 0;
while (pos < words.size())
{
while (pos < words.size()) {
std::wstring line = words[pos++] + L" ";
while (pos < words.size() && width(line + words[pos]) < w)
{
while (pos < words.size() && width(line + words[pos]) < w) {
line += words[pos++] + L" ";
}
while (width(line) > w)
{
while (width(line) > w) {
int l = 0;
while (width(line.substr(0, l + 1)) <= w)
{
while (width(line.substr(0, l + 1)) <= w) {
l++;
}
if (trimString(line.substr(0, l)).length() > 0)
{
if (trimString(line.substr(0, l)).length() > 0) {
y += 8;
}
line = line.substr(l);
@@ -454,164 +409,162 @@ int Font::wordWrapHeight(const std::wstring& string, int w)
}
if (y < 8) y += 8;
return y;
}
void Font::setEnforceUnicodeSheet(bool enforceUnicodeSheet)
{
this->enforceUnicodeSheet = enforceUnicodeSheet;
void Font::setEnforceUnicodeSheet(bool enforceUnicodeSheet) {
this->enforceUnicodeSheet = enforceUnicodeSheet;
}
void Font::setBidirectional(bool bidirectional)
{
this->bidirectional = bidirectional;
void Font::setBidirectional(bool bidirectional) {
this->bidirectional = bidirectional;
}
bool Font::AllCharactersValid(const std::wstring &str)
{
for (int i = 0; i < (int)str.length(); ++i)
{
wchar_t c = str.at(i);
bool Font::AllCharactersValid(const std::wstring& str) {
for (int i = 0; i < (int)str.length(); ++i) {
wchar_t c = str.at(i);
if (c == 167 && i + 1 < str.length())
{
// skip special color setting
i += 1;
continue;
}
if (c == 167 && i + 1 < str.length()) {
// skip special color setting
i += 1;
continue;
}
int index = SharedConstants::acceptableLetters.find(c);
int index = SharedConstants::acceptableLetters.find(c);
if ((c != ' ') && !(index > 0 && !enforceUnicodeSheet))
{
return false;
}
}
return true;
if ((c != ' ') && !(index > 0 && !enforceUnicodeSheet)) {
return false;
}
}
return true;
}
// Not in use
/*// 4J - this code is lifted from #if 0 section above, so that we can directly create what would have gone in each of our 256 + 32 command buffers
void Font::renderFakeCB(IntBuffer *ib)
/*// 4J - this code is lifted from #if 0 section above, so that we can directly
create what would have gone in each of our 256 + 32 command buffers void
Font::renderFakeCB(IntBuffer *ib)
{
Tesselator *t = Tesselator::getInstance();
int i;
int i;
for(unsigned int j = 0; j < ib->limit(); j++)
{
int cb = ib->get(j);
for(unsigned int j = 0; j < ib->limit(); j++)
{
int cb = ib->get(j);
if( cb < 256 )
{
i = cb;
t->begin();
int ix = i % 16 * 8;
int iy = i / 16 * 8;
// float s = 7.99f;
float s = 7.99f;
if( cb < 256 )
{
i = cb;
t->begin();
int ix = i % 16 * 8;
int iy = i / 16 * 8;
// float s = 7.99f;
float s = 7.99f;
float uo = (0.0f) / 128.0f;
float vo = (0.0f) / 128.0f;
float uo = (0.0f) / 128.0f;
float vo = (0.0f) / 128.0f;
t->vertexUV((float)(0), (float)( 0 + s), (float)( 0), (float)( ix / 128.0f + uo), (float)( (iy + s) / 128.0f + vo));
t->vertexUV((float)(0 + s), (float)( 0 + s), (float)( 0), (float)( (ix + s) / 128.0f + uo), (float)( (iy + s) / 128.0f + vo));
t->vertexUV((float)(0 + s), (float)( 0), (float)( 0), (float)( (ix + s) / 128.0f + uo), (float)( iy / 128.0f + vo));
t->vertexUV((float)(0), (float)( 0), (float)( 0), (float)( ix / 128.0f + uo), (float)( iy / 128.0f + vo));
// target.colorBlit(texture, x + xo, y, color, ix, iy,
// charWidths[chars[i]], 8);
t->end();
t->vertexUV((float)(0), (float)( 0 + s), (float)( 0),
(float)( ix / 128.0f + uo), (float)( (iy + s) / 128.0f + vo));
t->vertexUV((float)(0 + s), (float)( 0 + s), (float)(
0), (float)( (ix + s) / 128.0f + uo), (float)( (iy + s) / 128.0f + vo));
t->vertexUV((float)(0 + s), (float)( 0), (float)( 0),
(float)( (ix + s) / 128.0f + uo), (float)( iy / 128.0f + vo));
t->vertexUV((float)(0), (float)( 0), (float)( 0),
(float)( ix / 128.0f + uo), (float)( iy / 128.0f + vo));
// target.colorBlit(texture, x + xo, y, color, ix, iy,
// charWidths[chars[i]], 8);
t->end();
glTranslatef((float)charWidths[i], 0, 0);
}
else
{
i = cb - 256;
glTranslatef((float)charWidths[i], 0, 0);
}
else
{
i = cb - 256;
int br = ((i >> 3) & 1) * 0x55;
int r = ((i >> 2) & 1) * 0xaa + br;
int g = ((i >> 1) & 1) * 0xaa + br;
int b = ((i >> 0) & 1) * 0xaa + br;
if (i == 6)
{
r += 0x55;
}
bool darken = i >= 16;
int br = ((i >> 3) & 1) * 0x55;
int r = ((i >> 2) & 1) * 0xaa + br;
int g = ((i >> 1) & 1) * 0xaa + br;
int b = ((i >> 0) & 1) * 0xaa + br;
if (i == 6)
{
r += 0x55;
}
bool darken = i >= 16;
// color = r << 16 | g << 8 | b;
if (darken)
{
r /= 4;
g /= 4;
b /= 4;
}
glColor3f(r / 255.0f, g / 255.0f, b / 255.0f);
}
}
// color = r << 16 | g << 8 | b;
if (darken)
{
r /= 4;
g /= 4;
b /= 4;
}
glColor3f(r / 255.0f, g / 255.0f, b / 255.0f);
}
}
}
void Font::loadUnicodePage(int page)
{
wchar_t fileName[25];
//String fileName = String.format("/1_2_2/font/glyph_%02X.png", page);
swprintf(fileName,25,L"/1_2_2/font/glyph_%02X.png",page);
BufferedImage *image = new BufferedImage(fileName);
//try
//{
// image = ImageIO.read(Textures.class.getResourceAsStream(fileName.toString()));
//}
//catch (IOException e)
//{
// throw new RuntimeException(e);
//}
wchar_t fileName[25];
//String fileName = String.format("/1_2_2/font/glyph_%02X.png", page);
swprintf(fileName,25,L"/1_2_2/font/glyph_%02X.png",page);
BufferedImage *image = new BufferedImage(fileName);
//try
//{
// image =
ImageIO.read(Textures.class.getResourceAsStream(fileName.toString()));
//}
//catch (IOException e)
//{
// throw new RuntimeException(e);
//}
unicodeTexID[page] = textures->getTexture(image);
lastBoundTexture = unicodeTexID[page];
unicodeTexID[page] = textures->getTexture(image);
lastBoundTexture = unicodeTexID[page];
}
void Font::renderUnicodeCharacter(wchar_t c)
{
if (unicodeWidth[c] == 0)
{
// System.out.println("no-width char " + c);
return;
}
if (unicodeWidth[c] == 0)
{
// System.out.println("no-width char " + c);
return;
}
int page = c / 256;
int page = c / 256;
if (unicodeTexID[page] == 0) loadUnicodePage(page);
if (unicodeTexID[page] == 0) loadUnicodePage(page);
if (lastBoundTexture != unicodeTexID[page])
{
glBindTexture(GL_TEXTURE_2D, unicodeTexID[page]);
lastBoundTexture = unicodeTexID[page];
}
if (lastBoundTexture != unicodeTexID[page])
{
glBindTexture(GL_TEXTURE_2D, unicodeTexID[page]);
lastBoundTexture = unicodeTexID[page];
}
// first column with non-trans pixels
int firstLeft = unicodeWidth[c] >> 4;
// last column with non-trans pixels
int firstRight = unicodeWidth[c] & 0xF;
// first column with non-trans pixels
int firstLeft = unicodeWidth[c] >> 4;
// last column with non-trans pixels
int firstRight = unicodeWidth[c] & 0xF;
float left = firstLeft;
float right = firstRight + 1;
float left = firstLeft;
float right = firstRight + 1;
float xOff = c % 16 * 16 + left;
float yOff = (c & 0xFF) / 16 * 16;
float width = right - left - .02f;
float xOff = c % 16 * 16 + left;
float yOff = (c & 0xFF) / 16 * 16;
float width = right - left - .02f;
Tesselator *t = Tesselator::getInstance();
t->begin(GL_TRIANGLE_STRIP);
t->tex(xOff / 256.0F, yOff / 256.0F);
t->vertex(xPos, yPos, 0.0f);
t->tex(xOff / 256.0F, (yOff + 15.98f) / 256.0F);
t->vertex(xPos, yPos + 7.99f, 0.0f);
t->tex((xOff + width) / 256.0F, yOff / 256.0F);
t->vertex(xPos + width / 2, yPos, 0.0f);
t->tex((xOff + width) / 256.0F, (yOff + 15.98f) / 256.0F);
t->vertex(xPos + width / 2, yPos + 7.99f, 0.0f);
t->end();
t->begin(GL_TRIANGLE_STRIP);
t->tex(xOff / 256.0F, yOff / 256.0F);
t->vertex(xPos, yPos, 0.0f);
t->tex(xOff / 256.0F, (yOff + 15.98f) / 256.0F);
t->vertex(xPos, yPos + 7.99f, 0.0f);
t->tex((xOff + width) / 256.0F, yOff / 256.0F);
t->vertex(xPos + width / 2, yPos, 0.0f);
t->tex((xOff + width) / 256.0F, (yOff + 15.98f) / 256.0F);
t->vertex(xPos + width / 2, yPos + 7.99f, 0.0f);
t->end();
xPos += (right - left) / 2 + 1;
xPos += (right - left) / 2 + 1;
}
*/

View File

@@ -3,81 +3,90 @@ class IntBuffer;
class Options;
class Textures;
class Font
{
class Font {
private:
int *charWidths;
public:
int fontTexture;
Random *random;
private:
int colors[32]; // RGB colors for formatting
Textures *textures;
float xPos;
float yPos;
bool enforceUnicodeSheet; // use unicode sheet for ascii
bool bidirectional; // use bidi to flip strings
int m_cols; // Number of columns in font sheet
int m_rows; // Number of rows in font sheet
int m_charWidth; // Maximum character width
int m_charHeight; // Maximum character height
TEXTURE_NAME m_textureName; // Texture
std::map<int, int> m_charMap;
int* charWidths;
public:
Font(Options *options, const std::wstring& name, Textures* textures, bool enforceUnicode, TEXTURE_NAME textureName, int cols, int rows, int charWidth, int charHeight, unsigned short charMap[] = NULL);
int fontTexture;
Random* random;
private:
int colors[32]; // RGB colors for formatting
Textures* textures;
float xPos;
float yPos;
bool enforceUnicodeSheet; // use unicode sheet for ascii
bool bidirectional; // use bidi to flip strings
int m_cols; // Number of columns in font sheet
int m_rows; // Number of rows in font sheet
int m_charWidth; // Maximum character width
int m_charHeight; // Maximum character height
TEXTURE_NAME m_textureName; // Texture
std::map<int, int> m_charMap;
public:
Font(Options* options, const std::wstring& name, Textures* textures,
bool enforceUnicode, TEXTURE_NAME textureName, int cols, int rows,
int charWidth, int charHeight, unsigned short charMap[] = NULL);
#ifndef _XBOX
// 4J Stu - This dtor clashes with one in xui! We never delete these anyway so take it out for now. Can go back when we have got rid of XUI
~Font();
// 4J Stu - This dtor clashes with one in xui! We never delete these anyway
// so take it out for now. Can go back when we have got rid of XUI
~Font();
#endif
void renderFakeCB(IntBuffer *cb); // 4J added
void renderFakeCB(IntBuffer* cb); // 4J added
private:
void renderCharacter(wchar_t c); // 4J added
void renderCharacter(wchar_t c); // 4J added
public:
void drawShadow(const std::wstring& str, int x, int y, int color);
void drawShadowWordWrap(const std::wstring &str, int x, int y, int w, int color, int h); // 4J Added h param
void draw(const std::wstring &str, int x, int y, int color);
/**
* Reorders the string according to bidirectional levels. A bit expensive at
* the moment.
*
* @param str
* @return
*/
void drawShadowWordWrap(const std::wstring& str, int x, int y, int w,
int color, int h); // 4J Added h param
void draw(const std::wstring& str, int x, int y, int color);
/**
* Reorders the string according to bidirectional levels. A bit expensive at
* the moment.
*
* @param str
* @return
*/
private:
std::wstring reorderBidi(const std::wstring &str);
std::wstring reorderBidi(const std::wstring& str);
void draw(const std::wstring &str, bool dropShadow);
void draw(const std::wstring& str, int x, int y, int color, bool dropShadow);
int MapCharacter(wchar_t c); // 4J added
bool CharacterExists(wchar_t c); // 4J added
void draw(const std::wstring& str, bool dropShadow);
void draw(const std::wstring& str, int x, int y, int color,
bool dropShadow);
int MapCharacter(wchar_t c); // 4J added
bool CharacterExists(wchar_t c); // 4J added
public:
int width(const std::wstring& str);
std::wstring sanitize(const std::wstring& str);
void drawWordWrap(const std::wstring &string, int x, int y, int w, int col, int h); // 4J Added h param
void drawWordWrap(const std::wstring& string, int x, int y, int w, int col,
int h); // 4J Added h param
private:
void drawWordWrapInternal(const std::wstring &string, int x, int y, int w, int col, int h); // 4J Added h param
void drawWordWrapInternal(const std::wstring& string, int x, int y, int w,
int col, int h); // 4J Added h param
public:
void drawWordWrap(const std::wstring &string, int x, int y, int w, int col, bool darken, int h); // 4J Added h param
void drawWordWrap(const std::wstring& string, int x, int y, int w, int col,
bool darken, int h); // 4J Added h param
private:
void drawWordWrapInternal(const std::wstring& string, int x, int y, int w, int col, bool darken, int h); // 4J Added h param
void drawWordWrapInternal(const std::wstring& string, int x, int y, int w,
int col, bool darken, int h); // 4J Added h param
public:
int wordWrapHeight(const std::wstring& string, int w);
void setEnforceUnicodeSheet(bool enforceUnicodeSheet);
void setBidirectional(bool bidirectional);
void setEnforceUnicodeSheet(bool enforceUnicodeSheet);
void setBidirectional(bool bidirectional);
// 4J-PB - check for invalid player name - Japanese local name
bool AllCharactersValid(const std::wstring &str);
// 4J-PB - check for invalid player name - Japanese local name
bool AllCharactersValid(const std::wstring& str);
};

File diff suppressed because it is too large Load Diff

View File

@@ -6,64 +6,75 @@ class Random;
class Minecraft;
class ItemRenderer;
class Gui : public GuiComponent
{
class Gui : public GuiComponent {
private:
// 4J-PB - this doesn't account for the safe zone, and the indent applied to messages
//static const int MAX_MESSAGE_WIDTH = 320;
static const int m_iMaxMessageWidth = 280;
static ItemRenderer *itemRenderer;
// 4J-PB - this doesn't account for the safe zone, and the indent applied to
// messages
// static const int MAX_MESSAGE_WIDTH = 320;
static const int m_iMaxMessageWidth = 280;
static ItemRenderer* itemRenderer;
std::vector<GuiMessage> guiMessages[XUSER_MAX_COUNT];
Random *random;
Random* random;
Minecraft* minecraft;
Minecraft *minecraft;
public:
std::wstring selectedName;
std::wstring selectedName;
private:
int tickCount;
int tickCount;
std::wstring overlayMessageString;
int overlayMessageTime;
bool animateOverlayMessageColor;
// 4J Added
float lastTickA;
float fAlphaIncrementPerCent;
public:
static float currentGuiBlendFactor; // 4J added
static float currentGuiScaleFactor; // 4J added
float progress;
// private DecimalFormat df = new DecimalFormat("##.00");
// 4J Added
float lastTickA;
float fAlphaIncrementPerCent;
public:
Gui(Minecraft *minecraft);
static float currentGuiBlendFactor; // 4J added
static float currentGuiScaleFactor; // 4J added
void render(float a, bool mouseFree, int xMouse, int yMouse);
float progress;
// private DecimalFormat df = new DecimalFormat("##.00");
public:
Gui(Minecraft* minecraft);
void render(float a, bool mouseFree, int xMouse, int yMouse);
float tbr;
private:
//void renderBossHealth(void);
void renderPumpkin(int w, int h);
// void renderBossHealth(void);
void renderPumpkin(int w, int h);
void renderVignette(float br, int w, int h);
void renderTp(float br, int w, int h);
void renderSlot(int slot, int x, int y, float a);
public:
void tick();
void clearMessages(int iPad=-1);
void addMessage(const std::wstring& string, int iPad,bool bIsDeathMessage=false);
void tick();
void clearMessages(int iPad = -1);
void addMessage(const std::wstring& string, int iPad,
bool bIsDeathMessage = false);
void setNowPlaying(const std::wstring& string);
void displayClientMessage(int messageId, int iPad);
// 4J Added
std::size_t getMessagesCount(int iPad) { return guiMessages[iPad].size(); }
std::wstring getMessage(int iPad, std::size_t index) { return guiMessages[iPad].at(index).string; }
float getOpacity(int iPad, std::size_t index);
// 4J Added
std::size_t getMessagesCount(int iPad) { return guiMessages[iPad].size(); }
std::wstring getMessage(int iPad, std::size_t index) {
return guiMessages[iPad].at(index).string;
}
float getOpacity(int iPad, std::size_t index);
std::wstring getJukeboxMessage(int iPad) { return overlayMessageString; }
float getJukeboxOpacity(int iPad);
std::wstring getJukeboxMessage(int iPad) { return overlayMessageString; }
float getJukeboxOpacity(int iPad);
// 4J Added
void renderGraph(int dataLength, int dataPos, __int64 *dataA, float dataAScale, int dataAWarning, __int64 *dataB, float dataBScale, int dataBWarning);
void renderStackedGraph(int dataPos, int dataLength, int dataSources, __int64 (*func)(unsigned int dataPos, unsigned int dataSource) );
// 4J Added
void renderGraph(int dataLength, int dataPos, __int64* dataA,
float dataAScale, int dataAWarning, __int64* dataB,
float dataBScale, int dataBWarning);
void renderStackedGraph(int dataPos, int dataLength, int dataSources,
__int64 (*func)(unsigned int dataPos,
unsigned int dataSource));
};

View File

@@ -2,10 +2,8 @@
#include "GuiComponent.h"
#include "../Rendering/Tesselator.h"
void GuiComponent::hLine(int x0, int x1, int y, int col)
{
if (x1 < x0)
{
void GuiComponent::hLine(int x0, int x1, int y, int col) {
if (x1 < x0) {
int tmp = x0;
x0 = x1;
x1 = tmp;
@@ -13,10 +11,8 @@ void GuiComponent::hLine(int x0, int x1, int y, int col)
fill(x0, y, x1 + 1, y + 1, col);
}
void GuiComponent::vLine(int x, int y0, int y1, int col)
{
if (y1 < y0)
{
void GuiComponent::vLine(int x, int y0, int y1, int col) {
if (y1 < y0) {
int tmp = y0;
y0 = y1;
y1 = tmp;
@@ -24,16 +20,13 @@ void GuiComponent::vLine(int x, int y0, int y1, int col)
fill(x, y0 + 1, x + 1, y1, col);
}
void GuiComponent::fill(int x0, int y0, int x1, int y1, int col)
{
if (x0 < x1)
{
void GuiComponent::fill(int x0, int y0, int x1, int y1, int col) {
if (x0 < x1) {
int tmp = x0;
x0 = x1;
x1 = tmp;
}
if (y0 < y1)
{
if (y0 < y1) {
int tmp = y0;
y0 = y1;
y1 = tmp;
@@ -42,23 +35,23 @@ void GuiComponent::fill(int x0, int y0, int x1, int y1, int col)
float r = ((col >> 16) & 0xff) / 255.0f;
float g = ((col >> 8) & 0xff) / 255.0f;
float b = ((col) & 0xff) / 255.0f;
Tesselator *t = Tesselator::getInstance();
Tesselator* t = Tesselator::getInstance();
glEnable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(r, g, b, a);
t->begin();
t->vertex((float)(x0), (float)( y1), (float)( 0));
t->vertex((float)(x1), (float)( y1), (float)( 0));
t->vertex((float)(x1), (float)( y0), (float)( 0));
t->vertex((float)(x0), (float)( y0), (float)( 0));
t->vertex((float)(x0), (float)(y1), (float)(0));
t->vertex((float)(x1), (float)(y1), (float)(0));
t->vertex((float)(x1), (float)(y0), (float)(0));
t->vertex((float)(x0), (float)(y0), (float)(0));
t->end();
glEnable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
}
void GuiComponent::fillGradient(int x0, int y0, int x1, int y1, int col1, int col2)
{
void GuiComponent::fillGradient(int x0, int y0, int x1, int y1, int col1,
int col2) {
float a1 = ((col1 >> 24) & 0xff) / 255.0f;
float r1 = ((col1 >> 16) & 0xff) / 255.0f;
float g1 = ((col1 >> 8) & 0xff) / 255.0f;
@@ -74,14 +67,14 @@ void GuiComponent::fillGradient(int x0, int y0, int x1, int y1, int col1, int co
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glShadeModel(GL_SMOOTH);
Tesselator *t = Tesselator::getInstance();
Tesselator* t = Tesselator::getInstance();
t->begin();
t->color(r1, g1, b1, a1);
t->vertex((float)(x1), (float)( y0), blitOffset);
t->vertex((float)(x0), (float)( y0), blitOffset);
t->vertex((float)(x1), (float)(y0), blitOffset);
t->vertex((float)(x0), (float)(y0), blitOffset);
t->color(r2, g2, b2, a2);
t->vertex((float)(x0), (float)( y1), blitOffset);
t->vertex((float)(x1), (float)( y1), blitOffset);
t->vertex((float)(x0), (float)(y1), blitOffset);
t->vertex((float)(x1), (float)(y1), blitOffset);
t->end();
glShadeModel(GL_FLAT);
@@ -90,47 +83,62 @@ void GuiComponent::fillGradient(int x0, int y0, int x1, int y1, int col1, int co
glEnable(GL_TEXTURE_2D);
}
GuiComponent::GuiComponent()
{
blitOffset = 0;
GuiComponent::GuiComponent() { blitOffset = 0; }
void GuiComponent::drawCenteredString(Font* font, const std::wstring& str,
int x, int y, int color) {
font->drawShadow(str, x - (font->width(str)) / 2, y, color);
}
void GuiComponent::drawCenteredString(Font *font, const std::wstring& str, int x, int y, int color)
{
font->drawShadow(str, x - (font->width(str)) / 2, y, color);
void GuiComponent::drawString(Font* font, const std::wstring& str, int x, int y,
int color) {
font->drawShadow(str, x, y, color);
}
void GuiComponent::drawString(Font *font, const std::wstring& str, int x, int y, int color)
{
font->drawShadow(str, x, y, color);
}
void GuiComponent::blit(int x, int y, int sx, int sy, int w, int h)
{
void GuiComponent::blit(int x, int y, int sx, int sy, int w, int h) {
float us = 1 / 256.0f;
float vs = 1 / 256.0f;
Tesselator *t = Tesselator::getInstance();
Tesselator* t = Tesselator::getInstance();
t->begin();
// This is a bit of a mystery. In general this ought to be 0.5 to match the centre of texels & pixels in the DX9 version of things. However, when scaling the GUI by a factor of 1.5, I'm
// really not sure how exactly point sampled rasterisation works, but when shifting by 0.5 we get a discontinuity down the diagonal of quads. Setting this shift to 0.75 in all cases seems to work fine.
const float extraShift = 0.75f;
// This is a bit of a mystery. In general this ought to be 0.5 to match the
// centre of texels & pixels in the DX9 version of things. However, when
// scaling the GUI by a factor of 1.5, I'm really not sure how exactly point
// sampled rasterisation works, but when shifting by 0.5 we get a
// discontinuity down the diagonal of quads. Setting this shift to 0.75 in
// all cases seems to work fine.
const float extraShift = 0.75f;
// 4J - subtracting extraShift (actual screen pixels, so need to compensate for physical & game width) from each x & y coordinate to compensate for centre of pixels in directx vs openGL
float dx = ( extraShift * (float)Minecraft::GetInstance()->width ) / (float)Minecraft::GetInstance()->width_phys;
// 4J - Also factor in the scaling from gui coordinate space to the screen. This varies based on user-selected gui scale, and whether we are in a viewport mode or not
dx /= Gui::currentGuiScaleFactor;
float dy = extraShift / Gui::currentGuiScaleFactor;
// Ensure that the x/y, width and height are actually pixel aligned at our current scale factor - in particular, for split screen mode with the default (3X)
// scale, we have an overall scale factor of 3 * 0.5 = 1.5, and so any odd pixels won't align
float fx = (floorf((float)x * Gui::currentGuiScaleFactor)) / Gui::currentGuiScaleFactor;
float fy = (floorf((float)y * Gui::currentGuiScaleFactor)) / Gui::currentGuiScaleFactor;
float fw = (floorf((float)w * Gui::currentGuiScaleFactor)) / Gui::currentGuiScaleFactor;
float fh = (floorf((float)h * Gui::currentGuiScaleFactor)) / Gui::currentGuiScaleFactor;
// 4J - subtracting extraShift (actual screen pixels, so need to compensate
// for physical & game width) from each x & y coordinate to compensate for
// centre of pixels in directx vs openGL
float dx = (extraShift * (float)Minecraft::GetInstance()->width) /
(float)Minecraft::GetInstance()->width_phys;
// 4J - Also factor in the scaling from gui coordinate space to the screen.
// This varies based on user-selected gui scale, and whether we are in a
// viewport mode or not
dx /= Gui::currentGuiScaleFactor;
float dy = extraShift / Gui::currentGuiScaleFactor;
// Ensure that the x/y, width and height are actually pixel aligned at our
// current scale factor - in particular, for split screen mode with the
// default (3X) scale, we have an overall scale factor of 3 * 0.5 = 1.5, and
// so any odd pixels won't align
float fx = (floorf((float)x * Gui::currentGuiScaleFactor)) /
Gui::currentGuiScaleFactor;
float fy = (floorf((float)y * Gui::currentGuiScaleFactor)) /
Gui::currentGuiScaleFactor;
float fw = (floorf((float)w * Gui::currentGuiScaleFactor)) /
Gui::currentGuiScaleFactor;
float fh = (floorf((float)h * Gui::currentGuiScaleFactor)) /
Gui::currentGuiScaleFactor;
t->vertexUV(fx + 0 - dx, fy + fh - dy, (float)( blitOffset), (float)( (sx + 0) * us), (float)( (sy + h) * vs));
t->vertexUV(fx + fw - dx, fy + fh - dy, (float)( blitOffset), (float)( (sx + w) * us), (float)( (sy + h) * vs));
t->vertexUV(fx + fw - dx, fy + 0 - dy, (float)( blitOffset), (float)( (sx + w) * us), (float)( (sy + 0) * vs));
t->vertexUV(fx + 0 - dx, fy + 0 - dy, (float)( blitOffset), (float)( (sx + 0) * us), (float)( (sy + 0) * vs));
t->vertexUV(fx + 0 - dx, fy + fh - dy, (float)(blitOffset),
(float)((sx + 0) * us), (float)((sy + h) * vs));
t->vertexUV(fx + fw - dx, fy + fh - dy, (float)(blitOffset),
(float)((sx + w) * us), (float)((sy + h) * vs));
t->vertexUV(fx + fw - dx, fy + 0 - dy, (float)(blitOffset),
(float)((sx + w) * us), (float)((sy + 0) * vs));
t->vertexUV(fx + 0 - dx, fy + 0 - dy, (float)(blitOffset),
(float)((sx + 0) * us), (float)((sy + 0) * vs));
t->end();
}

View File

@@ -1,19 +1,21 @@
#pragma once
class Font;
class GuiComponent {
protected:
float blitOffset;
class GuiComponent
{
protected:
float blitOffset;
protected:
void hLine(int x0, int x1, int y, int col);
void hLine(int x0, int x1, int y, int col);
void vLine(int x, int y0, int y1, int col);
void fill(int x0, int y0, int x1, int y1, int col);
void fillGradient(int x0, int y0, int x1, int y1, int col1, int col2);
public:
GuiComponent(); // 4J added
void drawCenteredString(Font *font, const std::wstring& str, int x, int y, int color);
void drawString(Font *font, const std::wstring& str, int x, int y, int color);
GuiComponent(); // 4J added
void drawCenteredString(Font* font, const std::wstring& str, int x, int y,
int color);
void drawString(Font* font, const std::wstring& str, int x, int y,
int color);
void blit(int x, int y, int sx, int sy, int w, int h);
};

View File

@@ -1,8 +1,7 @@
#include "../Platform/stdafx.h"
#include "GuiMessage.h"
GuiMessage::GuiMessage(const std::wstring& string)
{
this->string = string;
ticks = 0;
GuiMessage::GuiMessage(const std::wstring& string) {
this->string = string;
ticks = 0;
}

View File

@@ -1,10 +1,8 @@
#pragma once
class GuiMessage
{
class GuiMessage {
public:
std::wstring string;
int ticks;
GuiMessage(const std::wstring& string);
std::wstring string;
int ticks;
GuiMessage(const std::wstring& string);
};

View File

@@ -1,76 +1,49 @@
#include "../Platform/stdafx.h"
#include "Rect2i.h"
Rect2i::Rect2i(int x, int y, int width, int height)
{
xPos = x;
yPos = y;
this->width = width;
this->height = height;
Rect2i::Rect2i(int x, int y, int width, int height) {
xPos = x;
yPos = y;
this->width = width;
this->height = height;
}
Rect2i *Rect2i::intersect(const Rect2i *other)
{
int x0 = xPos;
int y0 = yPos;
int x1 = xPos + width;
int y1 = yPos + height;
Rect2i* Rect2i::intersect(const Rect2i* other) {
int x0 = xPos;
int y0 = yPos;
int x1 = xPos + width;
int y1 = yPos + height;
int x2 = other->getX();
int y2 = other->getY();
int x3 = x2 + other->getWidth();
int y3 = y2 + other->getHeight();
int x2 = other->getX();
int y2 = other->getY();
int x3 = x2 + other->getWidth();
int y3 = y2 + other->getHeight();
xPos = std::max(x0, x2);
yPos = std::max(y0, y2);
width = std::max(0, std::min(x1, x3) - xPos);
height = std::max(0, std::min(y1, y3) - yPos);
xPos = std::max(x0, x2);
yPos = std::max(y0, y2);
width = std::max(0, std::min(x1, x3) - xPos);
height = std::max(0, std::min(y1, y3) - yPos);
return this;
return this;
}
int Rect2i::getX() const
{
return xPos;
}
int Rect2i::getX() const { return xPos; }
int Rect2i::getY() const
{
return yPos;
}
int Rect2i::getY() const { return yPos; }
void Rect2i::setX(int x)
{
xPos = x;
}
void Rect2i::setX(int x) { xPos = x; }
void Rect2i::setY(int y)
{
yPos = y;
}
void Rect2i::setY(int y) { yPos = y; }
int Rect2i::getWidth() const
{
return width;
}
int Rect2i::getWidth() const { return width; }
int Rect2i::getHeight() const
{
return height;
}
int Rect2i::getHeight() const { return height; }
void Rect2i::setWidth(int width)
{
this->width = width;
}
void Rect2i::setWidth(int width) { this->width = width; }
void Rect2i::setHeight(int height)
{
this->height = height;
}
void Rect2i::setHeight(int height) { this->height = height; }
void Rect2i::setPosition(int x, int y)
{
xPos = x;
yPos = y;
void Rect2i::setPosition(int x, int y) {
xPos = x;
yPos = y;
}

View File

@@ -1,24 +1,23 @@
#pragma once
class Rect2i
{
class Rect2i {
private:
int xPos;
int yPos;
int width;
int height;
int xPos;
int yPos;
int width;
int height;
public:
Rect2i(int x, int y, int width, int height);
Rect2i(int x, int y, int width, int height);
Rect2i *intersect(const Rect2i *other);
int getX() const;
int getY() const;
void setX(int x);
void setY(int y);
int getWidth() const;
int getHeight() const;
void setWidth(int width);
void setHeight(int height);
void setPosition(int x, int y);
Rect2i* intersect(const Rect2i* other);
int getX() const;
int getY() const;
void setX(int x);
void setY(int y);
int getWidth() const;
int getHeight() const;
void setWidth(int width);
void setHeight(int height);
void setPosition(int x, int y);
};

View File

@@ -6,59 +6,47 @@
#include "../Textures/Textures.h"
#include "../../Minecraft.World/Util/SoundTypes.h"
Screen::Screen() // 4J added
Screen::Screen() // 4J added
{
minecraft = NULL;
width = 0;
minecraft = NULL;
width = 0;
height = 0;
passEvents = false;
font = NULL;
particles = NULL;
clickedButton = NULL;
passEvents = false;
font = NULL;
particles = NULL;
clickedButton = NULL;
}
void Screen::render(int xm, int ym, float a)
{
AUTO_VAR(itEnd, buttons.end());
for (AUTO_VAR(it, buttons.begin()); it != itEnd; it++)
{
Button *button = *it; //buttons[i];
void Screen::render(int xm, int ym, float a) {
AUTO_VAR(itEnd, buttons.end());
for (AUTO_VAR(it, buttons.begin()); it != itEnd; it++) {
Button* button = *it; // buttons[i];
button->render(minecraft, xm, ym);
}
}
void Screen::keyPressed(wchar_t eventCharacter, int eventKey)
{
if (eventKey == Keyboard::KEY_ESCAPE)
{
minecraft->setScreen(NULL);
// minecraft->grabMouse(); // 4J - removed
}
void Screen::keyPressed(wchar_t eventCharacter, int eventKey) {
if (eventKey == Keyboard::KEY_ESCAPE) {
minecraft->setScreen(NULL);
// minecraft->grabMouse(); // 4J - removed
}
}
std::wstring Screen::getClipboard()
{
// 4J - removed
return NULL;
std::wstring Screen::getClipboard() {
// 4J - removed
return NULL;
}
void Screen::setClipboard(const std::wstring& str)
{
// 4J - removed
void Screen::setClipboard(const std::wstring& str) {
// 4J - removed
}
void Screen::mouseClicked(int x, int y, int buttonNum)
{
if (buttonNum == 0)
{
AUTO_VAR(itEnd, buttons.end());
for (AUTO_VAR(it, buttons.begin()); it != itEnd; it++)
{
Button *button = *it; //buttons[i];
if (button->clicked(minecraft, x, y))
{
void Screen::mouseClicked(int x, int y, int buttonNum) {
if (buttonNum == 0) {
AUTO_VAR(itEnd, buttons.end());
for (AUTO_VAR(it, buttons.begin()); it != itEnd; it++) {
Button* button = *it; // buttons[i];
if (button->clicked(minecraft, x, y)) {
clickedButton = button;
minecraft->soundEngine->playUI(eSoundType_RANDOM_CLICK, 1, 1);
buttonClicked(button);
@@ -67,21 +55,16 @@ void Screen::mouseClicked(int x, int y, int buttonNum)
}
}
void Screen::mouseReleased(int x, int y, int buttonNum)
{
if (clickedButton!=NULL && buttonNum==0)
{
void Screen::mouseReleased(int x, int y, int buttonNum) {
if (clickedButton != NULL && buttonNum == 0) {
clickedButton->released(x, y);
clickedButton = NULL;
}
}
void Screen::buttonClicked(Button *button)
{
}
void Screen::buttonClicked(Button* button) {}
void Screen::init(Minecraft *minecraft, int width, int height)
{
void Screen::init(Minecraft* minecraft, int width, int height) {
particles = new GuiParticles(minecraft);
this->minecraft = minecraft;
this->font = minecraft->font;
@@ -91,97 +74,71 @@ void Screen::init(Minecraft *minecraft, int width, int height)
init();
}
void Screen::setSize(int width, int height)
{
void Screen::setSize(int width, int height) {
this->width = width;
this->height = height;
}
void Screen::init()
{
void Screen::init() {}
void Screen::updateEvents() {
/* 4J - TODO
while (Mouse.next()) {
mouseEvent();
}
void Screen::updateEvents()
{
/* 4J - TODO
while (Mouse.next()) {
mouseEvent();
}
while (Keyboard.next()) {
keyboardEvent();
}
*/
while (Keyboard.next()) {
keyboardEvent();
}
*/
}
void Screen::mouseEvent()
{
/* 4J - TODO
if (Mouse.getEventButtonState()) {
int xm = Mouse.getEventX() * width / minecraft.width;
int ym = height - Mouse.getEventY() * height / minecraft.height - 1;
mouseClicked(xm, ym, Mouse.getEventButton());
void Screen::mouseEvent() {
/* 4J - TODO
if (Mouse.getEventButtonState()) {
int xm = Mouse.getEventX() * width / minecraft.width;
int ym = height - Mouse.getEventY() * height / minecraft.height - 1;
mouseClicked(xm, ym, Mouse.getEventButton());
} else {
int xm = Mouse.getEventX() * width / minecraft.width;
int ym = height - Mouse.getEventY() * height / minecraft.height - 1;
mouseReleased(xm, ym, Mouse.getEventButton());
}
*/
}
void Screen::keyboardEvent() {
/* 4J - TODO
if (Keyboard.getEventKeyState()) {
if (Keyboard.getEventKey() == Keyboard.KEY_F11) {
minecraft.toggleFullScreen();
return;
}
keyPressed(Keyboard.getEventCharacter(), Keyboard.getEventKey());
}
*/
}
void Screen::tick() {}
void Screen::removed() {}
void Screen::renderBackground() { renderBackground(0); }
void Screen::renderBackground(int vo) {
if (minecraft->level != NULL) {
fillGradient(0, 0, width, height, 0xc0101010, 0xd0101010);
} else {
int xm = Mouse.getEventX() * width / minecraft.width;
int ym = height - Mouse.getEventY() * height / minecraft.height - 1;
mouseReleased(xm, ym, Mouse.getEventButton());
renderDirtBackground(vo);
}
*/
}
void Screen::keyboardEvent()
{
/* 4J - TODO
if (Keyboard.getEventKeyState()) {
if (Keyboard.getEventKey() == Keyboard.KEY_F11) {
minecraft.toggleFullScreen();
return;
}
keyPressed(Keyboard.getEventCharacter(), Keyboard.getEventKey());
}
*/
}
void Screen::tick()
{
}
void Screen::removed()
{
}
void Screen::renderBackground()
{
renderBackground(0);
}
void Screen::renderBackground(int vo)
{
if (minecraft->level != NULL)
{
fillGradient(0, 0, width, height, 0xc0101010, 0xd0101010);
}
else
{
renderDirtBackground(vo);
}
}
void Screen::renderDirtBackground(int vo)
{
void Screen::renderDirtBackground(int vo) {
// 4J Unused - Iggy Flash UI renders the background on consoles
}
bool Screen::isPauseScreen()
{
return true;
}
bool Screen::isPauseScreen() { return true; }
void Screen::confirmResult(bool result, int id)
{
}
void Screen::confirmResult(bool result, int id) {}
void Screen::tabPressed()
{
}
void Screen::tabPressed() {}

View File

@@ -4,39 +4,46 @@ class Button;
class GuiParticles;
class Minecraft;
class Screen : public GuiComponent
{
class Screen : public GuiComponent {
protected:
Minecraft *minecraft;
Minecraft* minecraft;
public:
int width;
int width;
int height;
protected:
std::vector<Button *> buttons;
public:
bool passEvents;
protected:
Font *font;
public:
GuiParticles *particles;
Screen(); // 4J added
protected:
std::vector<Button*> buttons;
public:
bool passEvents;
protected:
Font* font;
public:
GuiParticles* particles;
Screen(); // 4J added
virtual void render(int xm, int ym, float a);
protected:
virtual void keyPressed(wchar_t eventCharacter, int eventKey);
public:
static std::wstring getClipboard();
static void setClipboard(const std::wstring& str);
private:
Button *clickedButton;
protected:
virtual void mouseClicked(int x, int y, int buttonNum);
virtual void mouseReleased(int x, int y, int buttonNum);
virtual void buttonClicked(Button *button);
virtual void keyPressed(wchar_t eventCharacter, int eventKey);
public:
virtual void init(Minecraft *minecraft, int width, int height);
static std::wstring getClipboard();
static void setClipboard(const std::wstring& str);
private:
Button* clickedButton;
protected:
virtual void mouseClicked(int x, int y, int buttonNum);
virtual void mouseReleased(int x, int y, int buttonNum);
virtual void buttonClicked(Button* button);
public:
virtual void init(Minecraft* minecraft, int width, int height);
virtual void setSize(int width, int height);
virtual void init();
virtual void updateEvents();
@@ -51,4 +58,3 @@ public:
virtual void confirmResult(bool result, int id);
virtual void tabPressed();
};

View File

@@ -3,37 +3,29 @@
#include "../GameState/Options.h"
// who the fuck thought this was a good idea
ScreenSizeCalculator::ScreenSizeCalculator(Options *options, int width, int height, int forceScale/*=-1*/)
{
ScreenSizeCalculator::ScreenSizeCalculator(Options* options, int width,
int height, int forceScale /*=-1*/) {
w = width;
h = height;
if( forceScale == -1 )
{
scale = 1;
if (forceScale == -1) {
scale = 1;
int maxScale = options->guiScale;
if (maxScale == 0) maxScale = 1000;
while (scale < maxScale && w / (scale + 1) >= 320 && h / (scale + 1) >= 240) // ughh
{
scale++;
}
}
else
{
scale = forceScale;
}
rawWidth = w / (double) scale;
rawHeight = h / (double) scale;
w = (int) ceil(rawWidth);
h = (int) ceil(rawHeight);
int maxScale = options->guiScale;
if (maxScale == 0) maxScale = 1000;
while (scale < maxScale && w / (scale + 1) >= 320 &&
h / (scale + 1) >= 240) // ughh
{
scale++;
}
} else {
scale = forceScale;
}
rawWidth = w / (double)scale;
rawHeight = h / (double)scale;
w = (int)ceil(rawWidth);
h = (int)ceil(rawHeight);
}
int ScreenSizeCalculator::getWidth()
{
return w;
}
int ScreenSizeCalculator::getWidth() { return w; }
int ScreenSizeCalculator::getHeight()
{
return h;
}
int ScreenSizeCalculator::getHeight() { return h; }

View File

@@ -1,15 +1,16 @@
#pragma once
class Options;
class ScreenSizeCalculator
{
class ScreenSizeCalculator {
private:
int w;
int w;
int h;
public:
double rawWidth, rawHeight;
double rawWidth, rawHeight;
int scale;
ScreenSizeCalculator(Options *options, int width, int height, int forceScale = -1); // 4J added forceScale parameter
ScreenSizeCalculator(Options* options, int width, int height,
int forceScale = -1); // 4J added forceScale parameter
int getWidth();
int getHeight();
};

View File

@@ -10,29 +10,25 @@
#include "../../../Minecraft.World/Headers/net.minecraft.locale.h"
#include "../../../Minecraft.World/Headers/net.minecraft.world.item.h"
ItemRenderer *AbstractContainerScreen::itemRenderer = new ItemRenderer();
ItemRenderer* AbstractContainerScreen::itemRenderer = new ItemRenderer();
AbstractContainerScreen::AbstractContainerScreen(AbstractContainerMenu *menu)
{
// 4J - added initialisers
imageWidth = 176;
imageHeight = 166;
AbstractContainerScreen::AbstractContainerScreen(AbstractContainerMenu* menu) {
// 4J - added initialisers
imageWidth = 176;
imageHeight = 166;
this->menu = menu;
this->menu = menu;
}
void AbstractContainerScreen::init()
{
void AbstractContainerScreen::init() {
Screen::init();
minecraft->player->containerMenu = menu;
// leftPos = (width - imageWidth) / 2;
// topPos = (height - imageHeight) / 2;
// leftPos = (width - imageWidth) / 2;
// topPos = (height - imageHeight) / 2;
}
void AbstractContainerScreen::render(int xm, int ym, float a)
{
// 4J Stu - Not used
void AbstractContainerScreen::render(int xm, int ym, float a) {
// 4J Stu - Not used
#if 0
renderBackground();
int xo = (width - imageWidth) / 2;
@@ -118,13 +114,10 @@ void AbstractContainerScreen::render(int xm, int ym, float a)
#endif
}
void AbstractContainerScreen::renderLabels()
{
}
void AbstractContainerScreen::renderLabels() {}
void AbstractContainerScreen::renderSlot(Slot *slot)
{
// 4J Unused
void AbstractContainerScreen::renderSlot(Slot* slot) {
// 4J Unused
#if 0
int x = slot->x;
int y = slot->y;
@@ -148,88 +141,76 @@ void AbstractContainerScreen::renderSlot(Slot *slot)
#endif
}
Slot *AbstractContainerScreen::findSlot(int x, int y)
{
AUTO_VAR(itEnd, menu->slots->end());
for (AUTO_VAR(it, menu->slots->begin()); it != itEnd; it++)
{
Slot *slot = *it; //menu->slots->at(i);
Slot* AbstractContainerScreen::findSlot(int x, int y) {
AUTO_VAR(itEnd, menu->slots->end());
for (AUTO_VAR(it, menu->slots->begin()); it != itEnd; it++) {
Slot* slot = *it; // menu->slots->at(i);
if (isHovering(slot, x, y)) return slot;
}
return NULL;
}
bool AbstractContainerScreen::isHovering(Slot *slot, int xm, int ym)
{
bool AbstractContainerScreen::isHovering(Slot* slot, int xm, int ym) {
int xo = (width - imageWidth) / 2;
int yo = (height - imageHeight) / 2;
xm -= xo;
ym -= yo;
return xm >= slot->x - 1 && xm < slot->x + 16 + 1 && ym >= slot->y - 1 && ym < slot->y + 16 + 1;
return xm >= slot->x - 1 && xm < slot->x + 16 + 1 && ym >= slot->y - 1 &&
ym < slot->y + 16 + 1;
}
void AbstractContainerScreen::mouseClicked(int x, int y, int buttonNum)
{
void AbstractContainerScreen::mouseClicked(int x, int y, int buttonNum) {
Screen::mouseClicked(x, y, buttonNum);
if (buttonNum == 0 || buttonNum == 1)
{
Slot *slot = findSlot(x, y);
if (buttonNum == 0 || buttonNum == 1) {
Slot* slot = findSlot(x, y);
int xo = (width - imageWidth) / 2;
int yo = (height - imageHeight) / 2;
bool clickedOutside = (x < xo || y < yo || x >= xo + imageWidth || y >= yo + imageHeight);
bool clickedOutside =
(x < xo || y < yo || x >= xo + imageWidth || y >= yo + imageHeight);
int slotId = -1;
if (slot != NULL) slotId = slot->index;
if (clickedOutside)
{
if (clickedOutside) {
slotId = AbstractContainerMenu::CLICKED_OUTSIDE;
}
if (slotId != -1)
{
bool quickKey = slotId != AbstractContainerMenu::CLICKED_OUTSIDE && (Keyboard::isKeyDown(Keyboard::KEY_LSHIFT) || Keyboard::isKeyDown(Keyboard::KEY_RSHIFT));
minecraft->gameMode->handleInventoryMouseClick(menu->containerId, slotId, buttonNum, quickKey, minecraft->player);
if (slotId != -1) {
bool quickKey = slotId != AbstractContainerMenu::CLICKED_OUTSIDE &&
(Keyboard::isKeyDown(Keyboard::KEY_LSHIFT) ||
Keyboard::isKeyDown(Keyboard::KEY_RSHIFT));
minecraft->gameMode->handleInventoryMouseClick(
menu->containerId, slotId, buttonNum, quickKey,
minecraft->player);
}
}
}
void AbstractContainerScreen::mouseReleased(int x, int y, int buttonNum)
{
if (buttonNum == 0)
{
void AbstractContainerScreen::mouseReleased(int x, int y, int buttonNum) {
if (buttonNum == 0) {
}
}
void AbstractContainerScreen::keyPressed(wchar_t eventCharacter, int eventKey)
{
if (eventKey == Keyboard::KEY_ESCAPE || eventKey == minecraft->options->keyBuild->key)
{
void AbstractContainerScreen::keyPressed(wchar_t eventCharacter, int eventKey) {
if (eventKey == Keyboard::KEY_ESCAPE ||
eventKey == minecraft->options->keyBuild->key) {
minecraft->player->closeContainer();
}
}
void AbstractContainerScreen::removed()
{
void AbstractContainerScreen::removed() {
if (minecraft->player == NULL) return;
}
void AbstractContainerScreen::slotsChanged(std::shared_ptr<Container> container)
{
}
void AbstractContainerScreen::slotsChanged(
std::shared_ptr<Container> container) {}
bool AbstractContainerScreen::isPauseScreen()
{
return false;
}
bool AbstractContainerScreen::isPauseScreen() { return false; }
void AbstractContainerScreen::tick()
{
void AbstractContainerScreen::tick() {
Screen::tick();
if (!minecraft->player->isAlive() || minecraft->player->removed) minecraft->player->closeContainer();
if (!minecraft->player->isAlive() || minecraft->player->removed)
minecraft->player->closeContainer();
}

View File

@@ -5,33 +5,37 @@ class AbstractContainerMenu;
class Slot;
class Container;
class AbstractContainerScreen : public Screen
{
class AbstractContainerScreen : public Screen {
private:
static ItemRenderer *itemRenderer;
protected:
int imageWidth;
int imageHeight;
//int leftPos, topPos;
public:
AbstractContainerMenu *menu;
static ItemRenderer* itemRenderer;
AbstractContainerScreen(AbstractContainerMenu *menu);
protected:
int imageWidth;
int imageHeight;
// int leftPos, topPos;
public:
AbstractContainerMenu* menu;
AbstractContainerScreen(AbstractContainerMenu* menu);
virtual void init();
virtual void render(int xm, int ym, float a);
protected:
virtual void renderLabels();
virtual void renderLabels();
virtual void renderBg(float a) = 0;
private:
virtual void renderSlot(Slot *slot);
virtual Slot *findSlot(int x, int y);
virtual bool isHovering(Slot *slot, int xm, int ym);
virtual void renderSlot(Slot* slot);
virtual Slot* findSlot(int x, int y);
virtual bool isHovering(Slot* slot, int xm, int ym);
protected:
virtual void mouseClicked(int x, int y, int buttonNum);
virtual void mouseClicked(int x, int y, int buttonNum);
virtual void mouseReleased(int x, int y, int buttonNum);
virtual void keyPressed(wchar_t eventCharacter, int eventKey);
public:
virtual void removed();
virtual void removed();
virtual void slotsChanged(std::shared_ptr<Container> container);
virtual bool isPauseScreen();
virtual void tick();

View File

@@ -9,21 +9,19 @@
#include "../../../Minecraft.World/Headers/net.minecraft.stats.h"
#include "../../../Minecraft.World/Util/SharedConstants.h"
AchievementPopup::AchievementPopup(Minecraft *mc)
{
// 4J - added initialisers
width = 0;
height = 0;
ach = NULL;
startTime = 0;
isHelper = false;
AchievementPopup::AchievementPopup(Minecraft* mc) {
// 4J - added initialisers
width = 0;
height = 0;
ach = NULL;
startTime = 0;
isHelper = false;
this->mc = mc;
ir = new ItemRenderer();
}
void AchievementPopup::popup(Achievement *ach)
{
void AchievementPopup::popup(Achievement* ach) {
title = I18n::get(L"achievement.get");
desc = ach->name;
startTime = System::currentTimeMillis();
@@ -31,8 +29,7 @@ void AchievementPopup::popup(Achievement *ach)
isHelper = false;
}
void AchievementPopup::permanent(Achievement *ach)
{
void AchievementPopup::permanent(Achievement* ach) {
title = ach->name;
desc = ach->getDescription();
@@ -41,13 +38,12 @@ void AchievementPopup::permanent(Achievement *ach)
isHelper = true;
}
void AchievementPopup::prepareWindow()
{
void AchievementPopup::prepareWindow() {
{
int fbw, fbh;
RenderManager.GetFramebufferSize(fbw, fbh);
glViewport(0, 0, fbw, fbh);
} // just future proofing
} // just future proofing
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
@@ -67,11 +63,9 @@ void AchievementPopup::prepareWindow()
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -2000);
}
void AchievementPopup::render()
{
void AchievementPopup::render() {
// 4J Unused
#if 0
if (Minecraft::warezTime > 0)

View File

@@ -3,26 +3,26 @@
class Achievement;
class ItemRenderer;
class AchievementPopup : public GuiComponent
{
class AchievementPopup : public GuiComponent {
private:
Minecraft *mc;
Minecraft* mc;
int width, height;
std::wstring title;
std::wstring desc;
Achievement *ach;
Achievement* ach;
__int64 startTime;
ItemRenderer *ir;
ItemRenderer* ir;
bool isHelper;
public:
AchievementPopup(Minecraft *mc);
void popup(Achievement *ach);
void permanent(Achievement *ach);
AchievementPopup(Minecraft* mc);
void popup(Achievement* ach);
void permanent(Achievement* ach);
private:
void prepareWindow();
void prepareWindow();
public:
void render();
};

View File

@@ -13,84 +13,71 @@
#include "../../../Minecraft.World/Headers/net.minecraft.world.level.tile.h"
#include "../../../Minecraft.World/Util/JavaMath.h"
AchievementScreen::AchievementScreen(StatsCounter *statsCounter)
{
// 4J - added initialisers
AchievementScreen::AchievementScreen(StatsCounter* statsCounter) {
// 4J - added initialisers
imageWidth = 256;
imageHeight = 202;
xLastScroll = 0;
yLastScroll = 0;
scrolling = 0;
scrolling = 0;
// 4J - TODO - investigate - these were static final ints before, but based on members of Achievements which
// aren't final Or actually initialised
xMin = Achievements::xMin * ACHIEVEMENT_COORD_SCALE - BIGMAP_WIDTH / 2;
yMin = Achievements::yMin * ACHIEVEMENT_COORD_SCALE - BIGMAP_WIDTH / 2;
xMax = Achievements::xMax * ACHIEVEMENT_COORD_SCALE - BIGMAP_HEIGHT / 2;
yMax = Achievements::yMax * ACHIEVEMENT_COORD_SCALE - BIGMAP_HEIGHT / 2;
// 4J - TODO - investigate - these were static final ints before, but based
// on members of Achievements which aren't final Or actually initialised
xMin = Achievements::xMin * ACHIEVEMENT_COORD_SCALE - BIGMAP_WIDTH / 2;
yMin = Achievements::yMin * ACHIEVEMENT_COORD_SCALE - BIGMAP_WIDTH / 2;
xMax = Achievements::xMax * ACHIEVEMENT_COORD_SCALE - BIGMAP_HEIGHT / 2;
yMax = Achievements::yMax * ACHIEVEMENT_COORD_SCALE - BIGMAP_HEIGHT / 2;
this->statsCounter = statsCounter;
int wBigMap = 141;
int hBigMap = 141;
xScrollO = xScrollP = xScrollTarget = Achievements::openInventory->x * ACHIEVEMENT_COORD_SCALE - wBigMap / 2 - 12;
yScrollO = yScrollP = yScrollTarget = Achievements::openInventory->y * ACHIEVEMENT_COORD_SCALE - hBigMap / 2;
xScrollO = xScrollP = xScrollTarget =
Achievements::openInventory->x * ACHIEVEMENT_COORD_SCALE - wBigMap / 2 -
12;
yScrollO = yScrollP = yScrollTarget =
Achievements::openInventory->y * ACHIEVEMENT_COORD_SCALE - hBigMap / 2;
}
void AchievementScreen::init()
{
void AchievementScreen::init() {
buttons.clear();
// buttons.add(new SmallButton(0, width / 2 - 80 - 24, height / 2 + 74, 110, 20, I18n.get("gui.achievements")));
buttons.push_back(new SmallButton(1, width / 2 + 24, height / 2 + 74, 80, 20, I18n::get(L"gui.done")));
// buttons.add(new SmallButton(0, width / 2 - 80 - 24, height / 2 +
// 74, 110, 20, I18n.get("gui.achievements")));
buttons.push_back(new SmallButton(1, width / 2 + 24, height / 2 + 74, 80,
20, I18n::get(L"gui.done")));
}
void AchievementScreen::buttonClicked(Button *button)
{
if (button->id == 1)
{
void AchievementScreen::buttonClicked(Button* button) {
if (button->id == 1) {
minecraft->setScreen(NULL);
// minecraft->grabMouse(); // 4J removed
// minecraft->grabMouse(); // 4J removed
}
Screen::buttonClicked(button);
}
void AchievementScreen::keyPressed(char eventCharacter, int eventKey)
{
if (eventKey == minecraft->options->keyBuild->key)
{
void AchievementScreen::keyPressed(char eventCharacter, int eventKey) {
if (eventKey == minecraft->options->keyBuild->key) {
minecraft->setScreen(NULL);
// minecraft->grabMouse(); // 4J removed
}
else
{
// minecraft->grabMouse(); // 4J removed
} else {
Screen::keyPressed(eventCharacter, eventKey);
}
}
void AchievementScreen::render(int mouseX, int mouseY, float a)
{
if (Mouse::isButtonDown(0))
{
void AchievementScreen::render(int mouseX, int mouseY, float a) {
if (Mouse::isButtonDown(0)) {
int xo = (width - imageWidth) / 2;
int yo = (height - imageHeight) / 2;
int xBigMap = xo + 8;
int yBigMap = yo + 17;
if (scrolling == 0 || scrolling == 1)
{
if (mouseX >= xBigMap && mouseX < xBigMap + BIGMAP_WIDTH && mouseY >= yBigMap && mouseY < yBigMap + BIGMAP_HEIGHT)
{
if (scrolling == 0)
{
if (scrolling == 0 || scrolling == 1) {
if (mouseX >= xBigMap && mouseX < xBigMap + BIGMAP_WIDTH &&
mouseY >= yBigMap && mouseY < yBigMap + BIGMAP_HEIGHT) {
if (scrolling == 0) {
scrolling = 1;
}
else
{
} else {
xScrollP -= mouseX - xLastScroll;
yScrollP -= mouseY - yLastScroll;
xScrollTarget = xScrollO = xScrollP;
@@ -105,9 +92,7 @@ void AchievementScreen::render(int mouseX, int mouseY, float a)
if (yScrollTarget < yMin) yScrollTarget = yMin;
if (xScrollTarget >= xMax) xScrollTarget = xMax - 1;
if (yScrollTarget >= yMax) yScrollTarget = yMax - 1;
}
else
{
} else {
scrolling = 0;
}
@@ -122,42 +107,36 @@ void AchievementScreen::render(int mouseX, int mouseY, float a)
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
}
void AchievementScreen::tick()
{
void AchievementScreen::tick() {
xScrollO = xScrollP;
yScrollO = yScrollP;
double xd = (xScrollTarget - xScrollP);
double yd = (yScrollTarget - yScrollP);
if (xd * xd + yd * yd < 4)
{
if (xd * xd + yd * yd < 4) {
xScrollP += xd;
yScrollP += yd;
}
else
{
} else {
xScrollP += xd * 0.85;
yScrollP += yd * 0.85;
}
}
void AchievementScreen::renderLabels()
{
void AchievementScreen::renderLabels() {
int xo = (width - imageWidth) / 2;
int yo = (height - imageHeight) / 2;
font->draw(L"Achievements", xo + 15, yo + 5, 0x404040);
// font.draw(xScrollP + ", " + yScrollP, xo + 5, yo + 5 + BIGMAP_HEIGHT + 18, 0x404040);
// font.drawWordWrap("Ride a pig off a cliff.", xo + 5, yo + 5 + BIGMAP_HEIGHT + 16, BIGMAP_WIDTH, 0x404040);
// font.draw(xScrollP + ", " + yScrollP, xo + 5, yo + 5 +
// BIGMAP_HEIGHT + 18, 0x404040); font.drawWordWrap("Ride a pig off a
// cliff.", xo + 5, yo + 5 + BIGMAP_HEIGHT + 16, BIGMAP_WIDTH,
// 0x404040);
}
void AchievementScreen::renderBg(int xm, int ym, float a)
{
// 4J Unused
void AchievementScreen::renderBg(int xm, int ym, float a) {
// 4J Unused
#if 0
int xScroll = Mth::floor(xScrollO + (xScrollP - xScrollO) * a);
int yScroll = Mth::floor(yScrollO + (yScrollP - yScrollO) * a);
@@ -420,7 +399,4 @@ void AchievementScreen::renderBg(int xm, int ym, float a)
#endif
}
bool AchievementScreen::isPauseScreen()
{
return true;
}
bool AchievementScreen::isPauseScreen() { return true; }

View File

@@ -3,18 +3,19 @@
#include "../../../Minecraft.World/Headers/net.minecraft.stats.h"
class StatsCounter;
class AchievementScreen : public Screen
{
class AchievementScreen : public Screen {
private:
static const int BIGMAP_X = 16;
static const int BIGMAP_X = 16;
static const int BIGMAP_Y = 17;
static const int BIGMAP_WIDTH = 224;
static const int BIGMAP_HEIGHT = 155;
// number of pixels per achievement
static const int ACHIEVEMENT_COORD_SCALE = 24;
static const int EDGE_VALUE_X = Achievements::ACHIEVEMENT_WIDTH_POSITION * ACHIEVEMENT_COORD_SCALE;
static const int EDGE_VALUE_Y = Achievements::ACHIEVEMENT_HEIGHT_POSITION * ACHIEVEMENT_COORD_SCALE;
static const int EDGE_VALUE_X =
Achievements::ACHIEVEMENT_WIDTH_POSITION * ACHIEVEMENT_COORD_SCALE;
static const int EDGE_VALUE_Y =
Achievements::ACHIEVEMENT_HEIGHT_POSITION * ACHIEVEMENT_COORD_SCALE;
int xMin;
int yMin;
@@ -24,34 +25,38 @@ private:
static const int MAX_BG_TILE_Y = (EDGE_VALUE_Y * 2 - 1) / 16;
protected:
int imageWidth;
int imageWidth;
int imageHeight;
int xLastScroll;
int yLastScroll;
protected:
double xScrollO, yScrollO;
double xScrollO, yScrollO;
double xScrollP, yScrollP;
double xScrollTarget, yScrollTarget;
private:
int scrolling;
StatsCounter *statsCounter;
int scrolling;
StatsCounter* statsCounter;
public:
using Screen::keyPressed;
using Screen::keyPressed;
AchievementScreen(StatsCounter *statsCounter);
AchievementScreen(StatsCounter* statsCounter);
virtual void init();
protected:
virtual void buttonClicked(Button *button);
virtual void buttonClicked(Button* button);
virtual void keyPressed(char eventCharacter, int eventKey);
public:
virtual void render(int mouseX, int mouseY, float a);
virtual void render(int mouseX, int mouseY, float a);
virtual void tick();
protected:
virtual void renderLabels();
virtual void renderLabels();
virtual void renderBg(int xm, int ym, float a);
public:
virtual bool isPauseScreen();
virtual bool isPauseScreen();
};

View File

@@ -4,86 +4,63 @@
#include "../../../Minecraft.World/Util/SharedConstants.h"
#include "../../../Minecraft.World/Util/StringHelpers.h"
const std::wstring ChatScreen::allowedChars = SharedConstants::readAcceptableChars();
const std::wstring ChatScreen::allowedChars =
SharedConstants::readAcceptableChars();
ChatScreen::ChatScreen()
{
frame = 0;
}
ChatScreen::ChatScreen() { frame = 0; }
void ChatScreen::init()
{
Keyboard::enableRepeatEvents(true);
}
void ChatScreen::init() { Keyboard::enableRepeatEvents(true); }
void ChatScreen::removed()
{
Keyboard::enableRepeatEvents(false);
}
void ChatScreen::removed() { Keyboard::enableRepeatEvents(false); }
void ChatScreen::tick()
{
frame++;
}
void ChatScreen::tick() { frame++; }
void ChatScreen::keyPressed(wchar_t ch, int eventKey)
{
if (eventKey == Keyboard::KEY_ESCAPE)
{
void ChatScreen::keyPressed(wchar_t ch, int eventKey) {
if (eventKey == Keyboard::KEY_ESCAPE) {
minecraft->setScreen(NULL);
return;
}
if (eventKey == Keyboard::KEY_RETURN)
{
if (eventKey == Keyboard::KEY_RETURN) {
std::wstring msg = trimString(message);
if (msg.length() > 0)
{
if (msg.length() > 0) {
std::wstring trim = trimString(message);
if (!minecraft->handleClientSideCommand(trim))
{
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)
{
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)
{
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);
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' ')
{
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)
{
if (message.length() > maxLength) {
message = message.substr(0, maxLength);
}
}
else
{
} else {
Screen::mouseClicked(x, y, buttonNum);
}
}
}

View File

@@ -1,25 +1,28 @@
#pragma once
#include "../Screen.h"
class ChatScreen : public Screen
{
class ChatScreen : public Screen {
protected:
std::wstring message;
std::wstring message;
private:
int frame;
int frame;
public:
ChatScreen(); //4J added
virtual void init();
ChatScreen(); // 4J added
virtual void init();
virtual void removed();
virtual void tick();
private:
static const std::wstring allowedChars;
static const std::wstring allowedChars;
protected:
void keyPressed(wchar_t ch, int eventKey);
void keyPressed(wchar_t ch, int eventKey);
public:
void render(int xm, int ym, float a);
void render(int xm, int ym, float a);
protected:
void mouseClicked(int x, int y, int buttonNum);
void mouseClicked(int x, int y, int buttonNum);
};

View File

@@ -3,20 +3,22 @@
#include "../SmallButton.h"
#include "../../../Minecraft.World/Headers/net.minecraft.locale.h"
ConfirmScreen::ConfirmScreen(Screen *parent, const std::wstring& title1, const std::wstring& title2, int id)
{
ConfirmScreen::ConfirmScreen(Screen* parent, const std::wstring& title1,
const std::wstring& title2, int id) {
this->parent = parent;
this->title1 = title1;
this->title2 = title2;
this->id = id;
Language *language = Language::getInstance();
Language* language = Language::getInstance();
yesButton = language->getElement(L"gui.yes");
noButton = language->getElement(L"gui.no");
}
ConfirmScreen::ConfirmScreen(Screen *parent, const std::wstring& title1, const std::wstring& title2, const std::wstring& yesButton, const std::wstring& noButton, int id)
{
ConfirmScreen::ConfirmScreen(Screen* parent, const std::wstring& title1,
const std::wstring& title2,
const std::wstring& yesButton,
const std::wstring& noButton, int id) {
this->parent = parent;
this->title1 = title1;
this->title2 = title2;
@@ -25,19 +27,18 @@ ConfirmScreen::ConfirmScreen(Screen *parent, const std::wstring& title1, const s
this->id = id;
}
void ConfirmScreen::init()
{
buttons.push_back(new SmallButton(0, width / 2 - 155 + 0 % 2 * 160, height / 6 + 24 * 4, yesButton));
buttons.push_back(new SmallButton(1, width / 2 - 155 + 1 % 2 * 160, height / 6 + 24 * 4, noButton));
void ConfirmScreen::init() {
buttons.push_back(new SmallButton(0, width / 2 - 155 + 0 % 2 * 160,
height / 6 + 24 * 4, yesButton));
buttons.push_back(new SmallButton(1, width / 2 - 155 + 1 % 2 * 160,
height / 6 + 24 * 4, noButton));
}
void ConfirmScreen::buttonClicked(Button *button)
{
parent->confirmResult(button->id == 0, id);
void ConfirmScreen::buttonClicked(Button* button) {
parent->confirmResult(button->id == 0, id);
}
void ConfirmScreen::render(int xm, int ym, float a)
{
void ConfirmScreen::render(int xm, int ym, float a) {
renderBackground();
drawCenteredString(font, title1, width / 2, 70, 0xffffff);
@@ -45,11 +46,10 @@ void ConfirmScreen::render(int xm, int ym, float a)
Screen::render(xm, ym, a);
// 4J - debug code - remove
static int count = 0;
if( count++ == 100 )
{
count = 0;
buttonClicked(buttons[0]);
}
// 4J - debug code - remove
static int count = 0;
if (count++ == 100) {
count = 0;
buttonClicked(buttons[0]);
}
}

View File

@@ -1,11 +1,9 @@
#pragma once
#include "../Screen.h"
class ConfirmScreen : public Screen
{
class ConfirmScreen : public Screen {
private:
Screen *parent;
Screen* parent;
std::wstring title1;
std::wstring title2;
std::wstring yesButton;
@@ -13,11 +11,16 @@ private:
int id;
public:
ConfirmScreen(Screen *parent, const std::wstring& title1, const std::wstring& title2, int id);
ConfirmScreen(Screen *parent, const std::wstring& title1, const std::wstring& title2, const std::wstring& yesButton, const std::wstring& noButton, int id);
ConfirmScreen(Screen* parent, const std::wstring& title1,
const std::wstring& title2, int id);
ConfirmScreen(Screen* parent, const std::wstring& title1,
const std::wstring& title2, const std::wstring& yesButton,
const std::wstring& noButton, int id);
virtual void init();
protected:
virtual void buttonClicked(Button *button);
virtual void buttonClicked(Button* button);
public:
virtual void render(int xm, int ym, float a);
virtual void render(int xm, int ym, float a);
};

View File

@@ -7,88 +7,87 @@
#include "../../Player/User.h"
#include "../../../Minecraft.World/Headers/net.minecraft.locale.h"
ConnectScreen::ConnectScreen(Minecraft *minecraft, const std::wstring& ip, int port)
{
aborted = false;
// System.out.println("Connecting to " + ip + ", " + port);
ConnectScreen::ConnectScreen(Minecraft* minecraft, const std::wstring& ip,
int port) {
aborted = false;
// System.out.println("Connecting to " + ip + ", " + port);
minecraft->setLevel(NULL);
#if 1
// 4J - removed from separate thread, but need to investigate what we actually need here
// 4J - removed from separate thread, but need to investigate what we
// actually need here
connection = new ClientConnection(minecraft, ip, port);
if (aborted) return;
connection->send( std::shared_ptr<PreLoginPacket>( new PreLoginPacket(minecraft->user->name) ) );
connection->send(std::shared_ptr<PreLoginPacket>(
new PreLoginPacket(minecraft->user->name)));
#else
new Thread() {
public void run() {
new Thread(){public void run(){
try {
connection = new ClientConnection(minecraft, ip, port);
if (aborted) return;
connection.send(new PreLoginPacket(minecraft.user.name));
} catch (UnknownHostException e) {
if (aborted) return;
minecraft.setScreen(new DisconnectedScreen("connect.failed", "disconnect.genericReason", "Unknown host '" + ip + "'"));
} catch (ConnectException e) {
if (aborted) return;
minecraft.setScreen(new DisconnectedScreen("connect.failed", "disconnect.genericReason", e.getMessage()));
} catch (Exception e) {
if (aborted) return;
e.printStackTrace();
minecraft.setScreen(new DisconnectedScreen("connect.failed", "disconnect.genericReason", e.toString()));
}
}
}.start();
try {connection = new ClientConnection(minecraft, ip, port);
if (aborted) return;
connection.send(new PreLoginPacket(minecraft.user.name));
}
catch (UnknownHostException e) {
if (aborted) return;
minecraft.setScreen(new DisconnectedScreen("connect.failed",
"disconnect.genericReason",
"Unknown host '" + ip + "'"));
}
catch (ConnectException e) {
if (aborted) return;
minecraft.setScreen(new DisconnectedScreen(
"connect.failed", "disconnect.genericReason", e.getMessage()));
}
catch (Exception e) {
if (aborted) return;
e.printStackTrace();
minecraft.setScreen(new DisconnectedScreen(
"connect.failed", "disconnect.genericReason", e.toString()));
}
}
}
.start();
#endif
}
void ConnectScreen::tick()
{
if (connection != NULL)
{
void ConnectScreen::tick() {
if (connection != NULL) {
connection->tick();
}
}
void ConnectScreen::keyPressed(char eventCharacter, int eventKey)
{
}
void ConnectScreen::keyPressed(char eventCharacter, int eventKey) {}
void ConnectScreen::init()
{
Language *language = Language::getInstance();
void ConnectScreen::init() {
Language* language = Language::getInstance();
buttons.clear();
buttons.push_back(new Button(0, width / 2 - 100, height / 4 + 24 * 5 + 12, language->getElement(L"gui.cancel")));
buttons.push_back(new Button(0, width / 2 - 100, height / 4 + 24 * 5 + 12,
language->getElement(L"gui.cancel")));
}
void ConnectScreen::buttonClicked(Button *button)
{
if (button->id == 0)
{
void ConnectScreen::buttonClicked(Button* button) {
if (button->id == 0) {
aborted = true;
if (connection != NULL) connection->close();
minecraft->setScreen(new TitleScreen());
}
}
void ConnectScreen::render(int xm, int ym, float a)
{
void ConnectScreen::render(int xm, int ym, float a) {
renderBackground();
Language *language = Language::getInstance();
Language* language = Language::getInstance();
if (connection == NULL)
{
drawCenteredString(font, language->getElement(L"connect.connecting"), width / 2, height / 2 - 50, 0xffffff);
if (connection == NULL) {
drawCenteredString(font, language->getElement(L"connect.connecting"),
width / 2, height / 2 - 50, 0xffffff);
drawCenteredString(font, L"", width / 2, height / 2 - 10, 0xffffff);
}
else
{
drawCenteredString(font, language->getElement(L"connect.authorizing"), width / 2, height / 2 - 50, 0xffffff);
drawCenteredString(font, connection->message, width / 2, height / 2 - 10, 0xffffff);
} else {
drawCenteredString(font, language->getElement(L"connect.authorizing"),
width / 2, height / 2 - 50, 0xffffff);
drawCenteredString(font, connection->message, width / 2,
height / 2 - 10, 0xffffff);
}
Screen::render(xm, ym, a);

View File

@@ -3,22 +3,24 @@
class ClientConnection;
class Minecraft;
class ConnectScreen : public Screen
{
class ConnectScreen : public Screen {
private:
ClientConnection *connection;
ClientConnection* connection;
bool aborted;
public:
ConnectScreen(Minecraft *minecraft, const std::wstring& ip, int port);
ConnectScreen(Minecraft* minecraft, const std::wstring& ip, int port);
virtual void tick();
protected:
virtual void keyPressed(char eventCharacter, int eventKey);
virtual void keyPressed(char eventCharacter, int eventKey);
public:
virtual void init();
virtual void init();
protected:
virtual void buttonClicked(Button *button);
virtual void buttonClicked(Button* button);
public:
virtual void render(int xm, int ym, float a);
virtual void render(int xm, int ym, float a);
};

View File

@@ -3,31 +3,29 @@
#include "../../Textures/Textures.h"
#include "../../../Minecraft.World/Headers/net.minecraft.world.inventory.h"
ContainerScreen::ContainerScreen(std::shared_ptr<Container> inventory, std::shared_ptr<Container> container) : AbstractContainerScreen(new ContainerMenu(inventory, container))
{
this->inventory = inventory;
this->container = container;
this->passEvents = false;
ContainerScreen::ContainerScreen(std::shared_ptr<Container> inventory,
std::shared_ptr<Container> container)
: AbstractContainerScreen(new ContainerMenu(inventory, container)) {
this->inventory = inventory;
this->container = container;
this->passEvents = false;
int defaultHeight = 222;
int noRowHeight = defaultHeight - 6 * 18;
containerRows = container->getContainerSize() / 9;
imageHeight = noRowHeight + containerRows * 18;
int defaultHeight = 222;
int noRowHeight = defaultHeight - 6 * 18;
containerRows = container->getContainerSize() / 9;
imageHeight = noRowHeight + containerRows * 18;
}
void ContainerScreen::renderLabels()
{
void ContainerScreen::renderLabels() {
#if 0
font->draw(container->getName(), 8, 2 + 2 + 2, 0x404040);
font->draw(inventory->getName(), 8, imageHeight - 96 + 2, 0x404040);
#endif
}
void ContainerScreen::renderBg(float a)
{
// 4J Unused
void ContainerScreen::renderBg(float a) {
// 4J Unused
#if 0
int tex = minecraft->textures->loadTexture(L"/gui/container.png");
glColor4f(1, 1, 1, 1);

View File

@@ -2,18 +2,18 @@
#include "AbstractContainerScreen.h"
class Container;
class ContainerScreen : public AbstractContainerScreen
{
class ContainerScreen : public AbstractContainerScreen {
private:
std::shared_ptr<Container> inventory;
std::shared_ptr<Container> container;
std::shared_ptr<Container> inventory;
std::shared_ptr<Container> container;
int containerRows;
int containerRows;
public:
ContainerScreen(std::shared_ptr<Container>inventory, std::shared_ptr<Container>container);
ContainerScreen(std::shared_ptr<Container> inventory,
std::shared_ptr<Container> container);
protected:
virtual void renderLabels();
virtual void renderBg(float a);
virtual void renderLabels();
virtual void renderBg(float a);
};

View File

@@ -4,76 +4,63 @@
#include "../SmallButton.h"
#include "../../../Minecraft.World/Headers/net.minecraft.locale.h"
ControlsScreen::ControlsScreen(Screen *lastScreen, Options *options)
{
// 4J - added initialisers
title = L"Controls";
selectedKey = -1;
ControlsScreen::ControlsScreen(Screen* lastScreen, Options* options) {
// 4J - added initialisers
title = L"Controls";
selectedKey = -1;
this->lastScreen = lastScreen;
this->lastScreen = lastScreen;
this->options = options;
}
int ControlsScreen::getLeftScreenPosition()
{
return width / 2 - 155;
}
int ControlsScreen::getLeftScreenPosition() { return width / 2 - 155; }
void ControlsScreen::init()
{
Language *language = Language::getInstance();
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)));
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")));
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++)
{
void ControlsScreen::buttonClicked(Button* button) {
for (int i = 0; i < Options::keyMappings_length; i++) {
buttons[i]->msg = options->getKeyMessage(i);
}
if (button->id == 200)
{
if (button->id == 200) {
minecraft->setScreen(lastScreen);
}
else
{
} else {
selectedKey = button->id;
button->msg = L"> " + options->getKeyMessage(button->id) + L" <";
}
}
void ControlsScreen::keyPressed(wchar_t eventCharacter, int eventKey)
{
if (selectedKey >= 0)
{
void ControlsScreen::keyPressed(wchar_t eventCharacter, int eventKey) {
if (selectedKey >= 0) {
options->setKey(selectedKey, eventKey);
buttons[selectedKey]->msg = options->getKeyMessage(selectedKey);
selectedKey = -1;
}
else
{
} else {
Screen::keyPressed(eventCharacter, eventKey);
}
}
void ControlsScreen::render(int xm, int ym, float a)
{
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);
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);

View File

@@ -3,29 +3,34 @@
class Options;
class ControlsScreen : public Screen
{
class ControlsScreen : public Screen {
private:
Screen *lastScreen;
Screen* lastScreen;
protected:
std::wstring title;
std::wstring title;
private:
Options *options;
int selectedKey;
Options* options;
int selectedKey;
static const int BUTTON_WIDTH = 70;
static const int ROW_WIDTH = 160;
public:
ControlsScreen(Screen *lastScreen, Options *options);
ControlsScreen(Screen* lastScreen, Options* options);
private:
int getLeftScreenPosition();
int getLeftScreenPosition();
public:
void init();
void init();
protected:
void buttonClicked(Button *button);
void buttonClicked(Button* button);
void keyPressed(wchar_t eventCharacter, int eventKey);
public:
void render(int xm, int ym, float a);
void render(int xm, int ym, float a);
};

View File

@@ -4,25 +4,22 @@
#include "../../Player/MultiPlayerLocalPlayer.h"
#include "../../../Minecraft.World/Headers/net.minecraft.world.inventory.h"
CraftingScreen::CraftingScreen(std::shared_ptr<Inventory> inventory, Level *level, int x, int y, int z) : AbstractContainerScreen(new CraftingMenu(inventory, level, x, y, z))
{
}
CraftingScreen::CraftingScreen(std::shared_ptr<Inventory> inventory,
Level* level, int x, int y, int z)
: AbstractContainerScreen(new CraftingMenu(inventory, level, x, y, z)) {}
void CraftingScreen::removed()
{
void CraftingScreen::removed() {
AbstractContainerScreen::removed();
menu->removed(std::dynamic_pointer_cast<Player>(minecraft->player));
}
void CraftingScreen::renderLabels()
{
void CraftingScreen::renderLabels() {
font->draw(L"Crafting", 8 + 16 + 4, 2 + 2 + 2, 0x404040);
font->draw(L"Inventory", 8, imageHeight - 96 + 2, 0x404040);
}
void CraftingScreen::renderBg(float a)
{
// 4J Unused
void CraftingScreen::renderBg(float a) {
// 4J Unused
#if 0
int tex = minecraft->textures->loadTexture(L"/gui/crafting.png");
glColor4f(1, 1, 1, 1);

View File

@@ -3,12 +3,13 @@
class Inventory;
class Level;
class CraftingScreen : public AbstractContainerScreen
{
class CraftingScreen : public AbstractContainerScreen {
public:
CraftingScreen(std::shared_ptr<Inventory> inventory, Level *level, int x, int y, int z);
virtual void removed();
CraftingScreen(std::shared_ptr<Inventory> inventory, Level* level, int x,
int y, int z);
virtual void removed();
protected:
virtual void renderLabels();
virtual void renderBg(float a);
virtual void renderLabels();
virtual void renderBg(float a);
};

View File

@@ -10,32 +10,34 @@
#include "../../../Minecraft.World/Util/SharedConstants.h"
#include "../../../Minecraft.World/Util/Random.h"
CreateWorldScreen::CreateWorldScreen(Screen *lastScreen)
{
done = false; // 4J added
this->lastScreen = lastScreen;
CreateWorldScreen::CreateWorldScreen(Screen* lastScreen) {
done = false; // 4J added
this->lastScreen = lastScreen;
}
void CreateWorldScreen::tick()
{
void CreateWorldScreen::tick() {
nameEdit->tick();
seedEdit->tick();
// 4J - debug code - to be removed
static int count = 0;
if(count++ == 100 ) buttonClicked(buttons[0]);
// 4J - debug code - to be removed
static int count = 0;
if (count++ == 100) buttonClicked(buttons[0]);
}
void CreateWorldScreen::init()
{
Language *language = Language::getInstance();
void CreateWorldScreen::init() {
Language* language = Language::getInstance();
Keyboard::enableRepeatEvents(true);
buttons.clear();
buttons.push_back(new Button(0, width / 2 - 100, height / 4 + 24 * 4 + 12, language->getElement(L"selectWorld.create")));
buttons.push_back(new Button(1, width / 2 - 100, height / 4 + 24 * 5 + 12, language->getElement(L"gui.cancel")));
buttons.push_back(new Button(0, width / 2 - 100, height / 4 + 24 * 4 + 12,
language->getElement(L"selectWorld.create")));
buttons.push_back(new Button(1, width / 2 - 100, height / 4 + 24 * 5 + 12,
language->getElement(L"gui.cancel")));
nameEdit = new EditBox(this, font, width / 2 - 100, 60, 200, 20, language->getElement(L"testWorld")); // 4J - test - should be L"selectWorld.newWorld"
nameEdit = new EditBox(
this, font, width / 2 - 100, 60, 200, 20,
language->getElement(
L"testWorld")); // 4J - test - should be L"selectWorld.newWorld"
nameEdit->inFocus = true;
nameEdit->setMaxLength(32);
@@ -44,30 +46,28 @@ void CreateWorldScreen::init()
updateResultFolder();
}
void CreateWorldScreen::updateResultFolder()
{
void CreateWorldScreen::updateResultFolder() {
resultFolder = trimString(nameEdit->getValue());
for( int i = 0; i < SharedConstants::ILLEGAL_FILE_CHARACTERS_LENGTH; i++ )
{
size_t pos;
while( (pos = resultFolder.find(SharedConstants::ILLEGAL_FILE_CHARACTERS[i])) != std::wstring::npos)
{
resultFolder[pos] = L'_';
}
}
for (int i = 0; i < SharedConstants::ILLEGAL_FILE_CHARACTERS_LENGTH; i++) {
size_t pos;
while ((pos = resultFolder.find(
SharedConstants::ILLEGAL_FILE_CHARACTERS[i])) !=
std::wstring::npos) {
resultFolder[pos] = L'_';
}
}
if (resultFolder.length()==0)
{
if (resultFolder.length() == 0) {
resultFolder = L"World";
}
resultFolder = CreateWorldScreen::findAvailableFolderName(minecraft->getLevelSource(), resultFolder);
resultFolder = CreateWorldScreen::findAvailableFolderName(
minecraft->getLevelSource(), resultFolder);
}
std::wstring CreateWorldScreen::findAvailableFolderName(LevelStorageSource *levelSource, const std::wstring& folder)
{
std::wstring folder2 = folder; // 4J - copy input as it is const
std::wstring CreateWorldScreen::findAvailableFolderName(
LevelStorageSource* levelSource, const std::wstring& folder) {
std::wstring folder2 = folder; // 4J - copy input as it is const
#if 0
while (levelSource->getDataTagFor(folder2) != NULL)
@@ -78,20 +78,13 @@ std::wstring CreateWorldScreen::findAvailableFolderName(LevelStorageSource *leve
return folder2;
}
void CreateWorldScreen::removed()
{
Keyboard::enableRepeatEvents(false);
}
void CreateWorldScreen::removed() { Keyboard::enableRepeatEvents(false); }
void CreateWorldScreen::buttonClicked(Button *button)
{
void CreateWorldScreen::buttonClicked(Button* button) {
if (!button->active) return;
if (button->id == 1)
{
if (button->id == 1) {
minecraft->setScreen(lastScreen);
}
else if (button->id == 0)
{
} else if (button->id == 0) {
// note: code copied from SelectWorldScreen
minecraft->setScreen(NULL);
if (done) return;
@@ -100,19 +93,17 @@ void CreateWorldScreen::buttonClicked(Button *button)
__int64 seedValue = (new Random())->nextLong();
std::wstring seedString = seedEdit->getValue();
if (seedString.length() != 0)
{
if (seedString.length() != 0) {
// try to convert it to a long first
// try { // 4J - removed try/catch
// try { // 4J - removed try/catch
__int64 value = _fromString<__int64>(seedString);
if (value != 0)
{
if (value != 0) {
seedValue = value;
}
// } catch (NumberFormatException e) {
// // not a number, fetch hash value
// seedValue = seedString.hashCode();
// }
// } catch (NumberFormatException e) {
// // not a number, fetch hash value
// seedValue = seedString.hashCode();
// }
}
// 4J Stu - This screen is not used, so removing this to stop the build failing
@@ -122,16 +113,15 @@ void CreateWorldScreen::buttonClicked(Button *button)
minecraft->setScreen(NULL);
#endif
}
}
void CreateWorldScreen::keyPressed(wchar_t ch, int eventKey)
{
if (nameEdit->inFocus) nameEdit->keyPressed(ch, eventKey);
else seedEdit->keyPressed(ch, eventKey);
void CreateWorldScreen::keyPressed(wchar_t ch, int eventKey) {
if (nameEdit->inFocus)
nameEdit->keyPressed(ch, eventKey);
else
seedEdit->keyPressed(ch, eventKey);
if (ch == 13)
{
if (ch == 13) {
buttonClicked(buttons[0]);
}
buttons[0]->active = nameEdit->getValue().length() > 0;
@@ -139,44 +129,44 @@ void CreateWorldScreen::keyPressed(wchar_t ch, int eventKey)
updateResultFolder();
}
void CreateWorldScreen::mouseClicked(int x, int y, int buttonNum)
{
void CreateWorldScreen::mouseClicked(int x, int y, int buttonNum) {
Screen::mouseClicked(x, y, buttonNum);
nameEdit->mouseClicked(x, y, buttonNum);
seedEdit->mouseClicked(x, y, buttonNum);
}
void CreateWorldScreen::render(int xm, int ym, float a)
{
Language *language = Language::getInstance();
void CreateWorldScreen::render(int xm, int ym, float a) {
Language* language = Language::getInstance();
// fill(0, 0, width, height, 0x40000000);
renderBackground();
// fill(0, 0, width, height, 0x40000000);
renderBackground();
drawCenteredString(font, language->getElement(L"selectWorld.create"), width / 2, height / 4 - 60 + 20, 0xffffff);
drawString(font, language->getElement(L"selectWorld.enterName"), width / 2 - 100, 47, 0xa0a0a0);
drawString(font, language->getElement(L"selectWorld.resultFolder") + L" " + resultFolder, width / 2 - 100, 85, 0xa0a0a0);
drawCenteredString(font, language->getElement(L"selectWorld.create"),
width / 2, height / 4 - 60 + 20, 0xffffff);
drawString(font, language->getElement(L"selectWorld.enterName"),
width / 2 - 100, 47, 0xa0a0a0);
drawString(
font,
language->getElement(L"selectWorld.resultFolder") + L" " + resultFolder,
width / 2 - 100, 85, 0xa0a0a0);
drawString(font, language->getElement(L"selectWorld.enterSeed"), width / 2 - 100, 104, 0xa0a0a0);
drawString(font, language->getElement(L"selectWorld.seedInfo"), width / 2 - 100, 140, 0xa0a0a0);
drawString(font, language->getElement(L"selectWorld.enterSeed"),
width / 2 - 100, 104, 0xa0a0a0);
drawString(font, language->getElement(L"selectWorld.seedInfo"),
width / 2 - 100, 140, 0xa0a0a0);
nameEdit->render();
seedEdit->render();
Screen::render(xm, ym, a);
nameEdit->render();
seedEdit->render();
Screen::render(xm, ym, a);
}
void CreateWorldScreen::tabPressed()
{
if (nameEdit->inFocus)
{
void CreateWorldScreen::tabPressed() {
if (nameEdit->inFocus) {
nameEdit->focus(false);
seedEdit->focus(true);
}
else
{
} else {
nameEdit->focus(true);
seedEdit->focus(false);
}

View File

@@ -3,30 +3,33 @@
class EditBox;
class LevelStorageSource;
class CreateWorldScreen : public Screen
{
class CreateWorldScreen : public Screen {
private:
Screen *lastScreen;
EditBox *nameEdit;
EditBox *seedEdit;
Screen* lastScreen;
EditBox* nameEdit;
EditBox* seedEdit;
std::wstring resultFolder;
bool done;
public:
CreateWorldScreen(Screen *lastScreen);
CreateWorldScreen(Screen* lastScreen);
virtual void tick();
virtual void init();
private:
void updateResultFolder();
void updateResultFolder();
public:
static std::wstring findAvailableFolderName(LevelStorageSource *levelSource, const std::wstring& folder);
static std::wstring findAvailableFolderName(LevelStorageSource* levelSource,
const std::wstring& folder);
virtual void removed();
protected:
virtual void buttonClicked(Button *button);
virtual void buttonClicked(Button* button);
virtual void keyPressed(wchar_t ch, int eventKey);
virtual void mouseClicked(int x, int y, int buttonNum);
public:
virtual void render(int xm, int ym, float a);
virtual void render(int xm, int ym, float a);
virtual void tabPressed();
};

View File

@@ -5,63 +5,55 @@
#include "../../Player/MultiPlayerLocalPlayer.h"
#include "TitleScreen.h"
void DeathScreen::init()
{
void DeathScreen::init() {
buttons.clear();
buttons.push_back(new Button(1, width / 2 - 100, height / 4 + 24 * 3, L"Respawn"));
buttons.push_back(new Button(2, width / 2 - 100, height / 4 + 24 * 4, L"Title menu"));
buttons.push_back(
new Button(1, width / 2 - 100, height / 4 + 24 * 3, L"Respawn"));
buttons.push_back(
new Button(2, width / 2 - 100, height / 4 + 24 * 4, L"Title menu"));
if (minecraft->user == NULL)
{
if (minecraft->user == NULL) {
buttons[1]->active = false;
}
}
void DeathScreen::keyPressed(char eventCharacter, int eventKey)
{
}
void DeathScreen::keyPressed(char eventCharacter, int eventKey) {}
void DeathScreen::buttonClicked(Button *button)
{
if (button->id == 0)
{
// minecraft.setScreen(new OptionsScreen(this, minecraft.options));
void DeathScreen::buttonClicked(Button* button) {
if (button->id == 0) {
// minecraft.setScreen(new OptionsScreen(this,
// minecraft.options));
}
if (button->id == 1)
{
if (button->id == 1) {
minecraft->player->respawn();
minecraft->setScreen(NULL);
// minecraft.setScreen(new NewLevelScreen(this));
}
if (button->id == 2)
{
if (button->id == 2) {
minecraft->setLevel(NULL);
minecraft->setScreen(new TitleScreen());
}
}
void DeathScreen::render(int xm, int ym, float a)
{
void DeathScreen::render(int xm, int ym, float a) {
fillGradient(0, 0, width, height, 0x60500000, 0xa0803030);
glPushMatrix();
glScalef(2, 2, 2);
drawCenteredString(font, L"Game over!", width / 2 / 2, 60 / 2, 0xffffff);
glPopMatrix();
drawCenteredString(font, L"Score: &e" + _toString( minecraft->player->getScore() ), width / 2, 100, 0xffffff);
drawCenteredString(font,
L"Score: &e" + _toString(minecraft->player->getScore()),
width / 2, 100, 0xffffff);
Screen::render(xm, ym, a);
// 4J - debug code - remove
static int count = 0;
if( count++ == 100 )
{
count = 0;
buttonClicked(buttons[0]);
}
// 4J - debug code - remove
static int count = 0;
if (count++ == 100) {
count = 0;
buttonClicked(buttons[0]);
}
}
bool DeathScreen::isPauseScreen()
{
return false;
}
bool DeathScreen::isPauseScreen() { return false; }

View File

@@ -1,14 +1,15 @@
#pragma once
#include "../Screen.h"
class DeathScreen : public Screen
{
class DeathScreen : public Screen {
public:
virtual void init();
virtual void init();
protected:
virtual void keyPressed(char eventCharacter, int eventKey);
virtual void buttonClicked(Button *button);
virtual void keyPressed(char eventCharacter, int eventKey);
virtual void buttonClicked(Button* button);
public:
virtual void render(int xm, int ym, float a);
virtual void render(int xm, int ym, float a);
virtual bool isPauseScreen();
};

View File

@@ -4,48 +4,38 @@
#include "../Button.h"
#include "../../../Minecraft.World/Headers/net.minecraft.locale.h"
DisconnectedScreen::DisconnectedScreen(const std::wstring& title, const std::wstring reason, void *reasonObjects, ...)
{
Language *language = Language::getInstance();
DisconnectedScreen::DisconnectedScreen(const std::wstring& title,
const std::wstring reason,
void* reasonObjects, ...) {
Language* language = Language::getInstance();
this->title = language->getElement(title);
if (reasonObjects != NULL)
{
if (reasonObjects != NULL) {
this->reason = language->getElement(reason, reasonObjects);
}
else
{
} else {
this->reason = language->getElement(reason);
}
}
void DisconnectedScreen::tick()
{
}
void DisconnectedScreen::tick() {}
void DisconnectedScreen::keyPressed(char eventCharacter, int eventKey)
{
}
void DisconnectedScreen::keyPressed(char eventCharacter, int eventKey) {}
void DisconnectedScreen::init()
{
Language *language = Language::getInstance();
void DisconnectedScreen::init() {
Language* language = Language::getInstance();
buttons.clear();
buttons.push_back(new Button(0, width / 2 - 100, height / 4 + 24 * 5 + 12, language->getElement(L"gui.toMenu")));
buttons.push_back(new Button(0, width / 2 - 100, height / 4 + 24 * 5 + 12,
language->getElement(L"gui.toMenu")));
}
void DisconnectedScreen::buttonClicked(Button *button)
{
if (button->id == 0)
{
void DisconnectedScreen::buttonClicked(Button* button) {
if (button->id == 0) {
minecraft->setScreen(new TitleScreen());
}
}
void DisconnectedScreen::render(int xm, int ym, float a)
{
void DisconnectedScreen::render(int xm, int ym, float a) {
renderBackground();
drawCenteredString(font, title, width / 2, height / 2 - 50, 0xffffff);

View File

@@ -1,23 +1,26 @@
#pragma once
#include "../Screen.h"
class DisconnectedScreen : public Screen
{
class DisconnectedScreen : public Screen {
private:
std::wstring title, reason;
std::wstring title, reason;
public:
DisconnectedScreen(const std::wstring& title, const std::wstring reason, void *reasonObjects, ...);
DisconnectedScreen(const std::wstring& title, const std::wstring reason,
void* reasonObjects, ...);
virtual void tick();
protected:
using Screen::keyPressed;
virtual void keyPressed(char eventCharacter, int eventKey);
public:
virtual void init();
protected:
virtual void buttonClicked(Button *button);
using Screen::keyPressed;
virtual void keyPressed(char eventCharacter, int eventKey);
public:
virtual void render(int xm, int ym, float a);
virtual void init();
protected:
virtual void buttonClicked(Button* button);
public:
virtual void render(int xm, int ym, float a);
};

View File

@@ -1,27 +1,22 @@
#include "../../Platform/stdafx.h"
#include "ErrorScreen.h"
ErrorScreen::ErrorScreen(const std::wstring& title, const std::wstring& message)
{
ErrorScreen::ErrorScreen(const std::wstring& title,
const std::wstring& message) {
this->title = title;
this->message = message;
}
void ErrorScreen::init()
{
}
void ErrorScreen::init() {}
void ErrorScreen::render(int xm, int ym, float a)
{
void ErrorScreen::render(int xm, int ym, float a) {
// fill(0, 0, width, height, 0x40000000);
fillGradient(0, 0, width, height, 0xff402020, 0xff501010);
drawCenteredString(font, title, width/2, 90, 0xffffff);
drawCenteredString(font, message, width/2, 110, 0xffffff);
drawCenteredString(font, title, width / 2, 90, 0xffffff);
drawCenteredString(font, message, width / 2, 110, 0xffffff);
Screen::render(xm, ym, a);
}
void ErrorScreen::keyPressed(wchar_t eventCharacter, int eventKey)
{
}
void ErrorScreen::keyPressed(wchar_t eventCharacter, int eventKey) {}

View File

@@ -1,14 +1,15 @@
#pragma once
#include "../Screen.h"
class ErrorScreen : public Screen
{
class ErrorScreen : public Screen {
private:
std::wstring title, message;
std::wstring title, message;
public:
ErrorScreen(const std::wstring& title, const std::wstring& message);
ErrorScreen(const std::wstring& title, const std::wstring& message);
virtual void init();
virtual void render(int xm, int ym, float a);
protected:
virtual void keyPressed(wchar_t eventCharacter, int eventKey);
virtual void keyPressed(wchar_t eventCharacter, int eventKey);
};

View File

@@ -6,20 +6,19 @@
#include "../../../Minecraft.World/Headers/net.minecraft.world.inventory.h"
#include "../../../Minecraft.World/Blocks/TileEntities/FurnaceTileEntity.h"
FurnaceScreen::FurnaceScreen(std::shared_ptr<Inventory> inventory, std::shared_ptr<FurnaceTileEntity> furnace) : AbstractContainerScreen(new FurnaceMenu(inventory, furnace))
{
this->furnace = furnace;
FurnaceScreen::FurnaceScreen(std::shared_ptr<Inventory> inventory,
std::shared_ptr<FurnaceTileEntity> furnace)
: AbstractContainerScreen(new FurnaceMenu(inventory, furnace)) {
this->furnace = furnace;
}
void FurnaceScreen::renderLabels()
{
font->draw(L"Furnace", 16 + 4 + 40, 2 + 2 + 2, 0x404040);
font->draw(L"Inventory", 8, imageHeight - 96 + 2, 0x404040);
void FurnaceScreen::renderLabels() {
font->draw(L"Furnace", 16 + 4 + 40, 2 + 2 + 2, 0x404040);
font->draw(L"Inventory", 8, imageHeight - 96 + 2, 0x404040);
}
void FurnaceScreen::renderBg(float a)
{
// 4J Unused
void FurnaceScreen::renderBg(float a) {
// 4J Unused
#if 0
int tex = minecraft->textures->loadTexture(L"/gui/furnace.png");
glColor4f(1, 1, 1, 1);

View File

@@ -4,14 +4,15 @@
class FurnaceTileEntity;
class Inventory;
class FurnaceScreen : public AbstractContainerScreen
{
class FurnaceScreen : public AbstractContainerScreen {
private:
std::shared_ptr<FurnaceTileEntity> furnace;
std::shared_ptr<FurnaceTileEntity> furnace;
public:
FurnaceScreen(std::shared_ptr<Inventory> inventory, std::shared_ptr<FurnaceTileEntity> furnace);
FurnaceScreen(std::shared_ptr<Inventory> inventory,
std::shared_ptr<FurnaceTileEntity> furnace);
protected:
virtual void renderLabels();
virtual void renderBg(float a);
virtual void renderLabels();
virtual void renderBg(float a);
};

View File

@@ -5,66 +5,51 @@
#include "../../../Minecraft.World/Headers/net.minecraft.locale.h"
#include "../../../Minecraft.World/Util/StringHelpers.h"
void InBedChatScreen::init()
{
void InBedChatScreen::init() {
Keyboard::enableRepeatEvents(true);
Language *language = Language::getInstance();
buttons.push_back(new Button(WAKE_UP_BUTTON, width / 2 - 100, height - 40, language->getElement(L"multiplayer.stopSleeping")));
Language* language = Language::getInstance();
buttons.push_back(
new Button(WAKE_UP_BUTTON, width / 2 - 100, height - 40,
language->getElement(L"multiplayer.stopSleeping")));
}
void InBedChatScreen::removed()
{
Keyboard::enableRepeatEvents(false);
}
void InBedChatScreen::removed() { Keyboard::enableRepeatEvents(false); }
void InBedChatScreen::keyPressed(wchar_t ch, int eventKey)
{
if (eventKey == Keyboard::KEY_ESCAPE)
{
void InBedChatScreen::keyPressed(wchar_t ch, int eventKey) {
if (eventKey == Keyboard::KEY_ESCAPE) {
sendWakeUp();
}
else if (eventKey == Keyboard::KEY_RETURN)
{
} else if (eventKey == Keyboard::KEY_RETURN) {
std::wstring msg = trimString(message);
if (msg.length() > 0)
{
if (msg.length() > 0) {
minecraft->player->chat(trimString(message));
}
message = L"";
}
else
{
} else {
ChatScreen::keyPressed(ch, eventKey);
}
}
void InBedChatScreen::render(int xm, int ym, float a)
{
ChatScreen::render(xm, ym, a);
void InBedChatScreen::render(int xm, int ym, float a) {
ChatScreen::render(xm, ym, a);
}
void InBedChatScreen::buttonClicked(Button *button)
{
if (button->id == WAKE_UP_BUTTON)
{
void InBedChatScreen::buttonClicked(Button* button) {
if (button->id == WAKE_UP_BUTTON) {
sendWakeUp();
}
else
{
} else {
ChatScreen::buttonClicked(button);
}
}
void InBedChatScreen::sendWakeUp()
{
/* 4J - TODO
if (minecraft.player instanceof MultiplayerLocalPlayer)
{
ClientConnection connection = ((MultiplayerLocalPlayer) minecraft.player).connection;
connection.send(new PlayerCommandPacket(minecraft.player, PlayerCommandPacket.STOP_SLEEPING));
}
*/
void InBedChatScreen::sendWakeUp() {
/* 4J - TODO
if (minecraft.player instanceof MultiplayerLocalPlayer)
{
ClientConnection connection = ((MultiplayerLocalPlayer)
minecraft.player).connection; connection.send(new
PlayerCommandPacket(minecraft.player, PlayerCommandPacket.STOP_SLEEPING));
}
*/
}

View File

@@ -2,19 +2,23 @@
#include "ChatScreen.h"
class InBedChatScreen : public ChatScreen
{
class InBedChatScreen : public ChatScreen {
private:
static const int WAKE_UP_BUTTON = 1;
static const int WAKE_UP_BUTTON = 1;
public:
virtual void init();
virtual void init();
virtual void removed();
protected:
virtual void keyPressed(wchar_t ch, int eventKey);
virtual void keyPressed(wchar_t ch, int eventKey);
public:
virtual void render(int xm, int ym, float a);
virtual void render(int xm, int ym, float a);
protected:
virtual void buttonClicked(Button *button);
virtual void buttonClicked(Button* button);
private:
void sendWakeUp();
void sendWakeUp();
};

View File

@@ -10,34 +10,29 @@
#include "StatsScreen.h"
#include "../../../Minecraft.World/Headers/net.minecraft.stats.h"
InventoryScreen::InventoryScreen(std::shared_ptr<Player> player) : AbstractContainerScreen(player->inventoryMenu)
{
xMouse = yMouse = 0.0f; // 4J added
InventoryScreen::InventoryScreen(std::shared_ptr<Player> player)
: AbstractContainerScreen(player->inventoryMenu) {
xMouse = yMouse = 0.0f; // 4J added
this->passEvents = true;
player->awardStat(GenericStats::openInventory(), GenericStats::param_noArgs());
player->awardStat(GenericStats::openInventory(),
GenericStats::param_noArgs());
}
void InventoryScreen::init()
{
buttons.clear();
void InventoryScreen::init() { buttons.clear(); }
void InventoryScreen::renderLabels() {
font->draw(L"Crafting", 84 + 2, 8 * 2, 0x404040);
}
void InventoryScreen::renderLabels()
{
font->draw(L"Crafting", 84 + 2, 8 * 2, 0x404040);
}
void InventoryScreen::render(int xm, int ym, float a)
{
void InventoryScreen::render(int xm, int ym, float a) {
AbstractContainerScreen::render(xm, ym, a);
this->xMouse = (float)xm;
this->yMouse = (float)ym;
}
void InventoryScreen::renderBg(float a)
{
// 4J Unused
void InventoryScreen::renderBg(float a) {
// 4J Unused
#if 0
int tex = minecraft->textures->loadTexture(L"/gui/inventory.png");
glColor4f(1, 1, 1, 1);
@@ -83,14 +78,13 @@ void InventoryScreen::renderBg(float a)
#endif
}
void InventoryScreen::buttonClicked(Button *button)
{
if (button->id == 0)
{
minecraft->setScreen(new AchievementScreen(minecraft->stats[minecraft->player->GetXboxPad()]));
void InventoryScreen::buttonClicked(Button* button) {
if (button->id == 0) {
minecraft->setScreen(new AchievementScreen(
minecraft->stats[minecraft->player->GetXboxPad()]));
}
if (button->id == 1)
{
minecraft->setScreen(new StatsScreen(this, minecraft->stats[minecraft->player->GetXboxPad()]));
if (button->id == 1) {
minecraft->setScreen(new StatsScreen(
this, minecraft->stats[minecraft->player->GetXboxPad()]));
}
}

View File

@@ -3,18 +3,21 @@
class Player;
class Button;
class InventoryScreen : public AbstractContainerScreen
{
class InventoryScreen : public AbstractContainerScreen {
public:
InventoryScreen(std::shared_ptr<Player> player);
InventoryScreen(std::shared_ptr<Player> player);
virtual void init();
protected:
virtual void renderLabels();
virtual void renderLabels();
private:
float xMouse, yMouse;
float xMouse, yMouse;
public:
virtual void render(int xm, int ym, float a);
virtual void render(int xm, int ym, float a);
protected:
virtual void renderBg(float a);
virtual void buttonClicked(Button *button);
virtual void renderBg(float a);
virtual void buttonClicked(Button* button);
};

View File

@@ -5,124 +5,106 @@
#include "../../GameState/Options.h"
#include "../../../Minecraft.World/Headers/net.minecraft.locale.h"
JoinMultiplayerScreen::JoinMultiplayerScreen(Screen *lastScreen)
{
ipEdit = NULL;
this->lastScreen = lastScreen;
JoinMultiplayerScreen::JoinMultiplayerScreen(Screen* lastScreen) {
ipEdit = NULL;
this->lastScreen = lastScreen;
}
void JoinMultiplayerScreen::tick()
{
ipEdit->tick();
}
void JoinMultiplayerScreen::tick() { ipEdit->tick(); }
void JoinMultiplayerScreen::init()
{
Language *language = Language::getInstance();
void JoinMultiplayerScreen::init() {
Language* language = Language::getInstance();
Keyboard::enableRepeatEvents(true);
buttons.clear();
buttons.push_back(new Button(0, width / 2 - 100, height / 4 + 24 * 4 + 12, language->getElement(L"multiplayer.connect")));
buttons.push_back(new Button(1, width / 2 - 100, height / 4 + 24 * 5 + 12, language->getElement(L"gui.cancel")));
std::wstring ip = replaceAll(minecraft->options->lastMpIp,L"_", L":");
buttons.push_back(new Button(0, width / 2 - 100, height / 4 + 24 * 4 + 12,
language->getElement(L"multiplayer.connect")));
buttons.push_back(new Button(1, width / 2 - 100, height / 4 + 24 * 5 + 12,
language->getElement(L"gui.cancel")));
std::wstring ip = replaceAll(minecraft->options->lastMpIp, L"_", L":");
buttons[0]->active = ip.length() > 0;
ipEdit = new EditBox(this, font, width / 2 - 100, height / 4 - 10 + 50 + 18, 200, 20, ip);
ipEdit = new EditBox(this, font, width / 2 - 100, height / 4 - 10 + 50 + 18,
200, 20, ip);
ipEdit->inFocus = true;
ipEdit->setMaxLength(128);
}
void JoinMultiplayerScreen::removed()
{
Keyboard::enableRepeatEvents(false);
}
void JoinMultiplayerScreen::removed() { Keyboard::enableRepeatEvents(false); }
void JoinMultiplayerScreen::buttonClicked(Button *button)
{
void JoinMultiplayerScreen::buttonClicked(Button* button) {
if (!button->active) return;
if (button->id == 1)
{
if (button->id == 1) {
minecraft->setScreen(lastScreen);
}
else if (button->id == 0)
{
} else if (button->id == 0) {
std::wstring ip = trimString(ipEdit->getValue());
minecraft->options->lastMpIp = replaceAll(ip,L":", L"_");
minecraft->options->lastMpIp = replaceAll(ip, L":", L"_");
minecraft->options->save();
std::vector<std::wstring> parts = stringSplit(ip,L'L');
if (ip[0]==L'[')
{
std::vector<std::wstring> parts = stringSplit(ip, L'L');
if (ip[0] == L'[') {
int pos = (int)ip.find(L"]");
if (pos != std::wstring::npos)
{
if (pos != std::wstring::npos) {
std::wstring path = ip.substr(1, pos);
std::wstring port = trimString(ip.substr(pos + 1));
if (port[0]==L':' && port.length() > 0)
{
if (port[0] == L':' && port.length() > 0) {
port = port.substr(1);
parts.clear();
parts.push_back(path);
parts.push_back(path);
parts.push_back(port);
}
else
{
parts.clear();
} else {
parts.clear();
parts.push_back(path);
}
}
}
if (parts.size() > 2)
{
parts.clear();
parts.push_back(ip);
if (parts.size() > 2) {
parts.clear();
parts.push_back(ip);
}
// 4J - TODO
// minecraft->setScreen(new ConnectScreen(minecraft, parts[0], parts.length > 1 ? parseInt(parts[1], 25565) : 25565));
// 4J - TODO
// minecraft->setScreen(new ConnectScreen(minecraft, parts[0],
// parts.length > 1 ? parseInt(parts[1], 25565) : 25565));
}
}
int JoinMultiplayerScreen::parseInt(const std::wstring& str, int def)
{
return _fromString<int>(str);
int JoinMultiplayerScreen::parseInt(const std::wstring& str, int def) {
return _fromString<int>(str);
}
void JoinMultiplayerScreen::keyPressed(wchar_t ch, int eventKey)
{
void JoinMultiplayerScreen::keyPressed(wchar_t ch, int eventKey) {
ipEdit->keyPressed(ch, eventKey);
if (ch == 13)
{
if (ch == 13) {
buttonClicked(buttons[0]);
}
buttons[0]->active = ipEdit->getValue().length() > 0;
}
void JoinMultiplayerScreen::mouseClicked(int x, int y, int buttonNum)
{
void JoinMultiplayerScreen::mouseClicked(int x, int y, int buttonNum) {
Screen::mouseClicked(x, y, buttonNum);
ipEdit->mouseClicked(x, y, buttonNum);
}
void JoinMultiplayerScreen::render(int xm, int ym, float a)
{
Language *language = Language::getInstance();
void JoinMultiplayerScreen::render(int xm, int ym, float a) {
Language* language = Language::getInstance();
// fill(0, 0, width, height, 0x40000000);
renderBackground();
drawCenteredString(font, language->getElement(L"multiplayer.title"), width / 2, height / 4 - 60 + 20, 0xffffff);
drawString(font, language->getElement(L"multiplayer.info1"), width / 2 - 140, height / 4 - 60 + 60 + 9 * 0, 0xa0a0a0);
drawString(font, language->getElement(L"multiplayer.info2"), width / 2 - 140, height / 4 - 60 + 60 + 9 * 1, 0xa0a0a0);
drawString(font, language->getElement(L"multiplayer.ipinfo"), width / 2 - 140, height / 4 - 60 + 60 + 9 * 4, 0xa0a0a0);
drawCenteredString(font, language->getElement(L"multiplayer.title"),
width / 2, height / 4 - 60 + 20, 0xffffff);
drawString(font, language->getElement(L"multiplayer.info1"),
width / 2 - 140, height / 4 - 60 + 60 + 9 * 0, 0xa0a0a0);
drawString(font, language->getElement(L"multiplayer.info2"),
width / 2 - 140, height / 4 - 60 + 60 + 9 * 1, 0xa0a0a0);
drawString(font, language->getElement(L"multiplayer.ipinfo"),
width / 2 - 140, height / 4 - 60 + 60 + 9 * 4, 0xa0a0a0);
ipEdit->render();
Screen::render(xm, ym, a);
}

View File

@@ -3,24 +3,27 @@
class EditBox;
class Button;
class JoinMultiplayerScreen : public Screen
{
class JoinMultiplayerScreen : public Screen {
private:
Screen *lastScreen;
EditBox *ipEdit;
Screen* lastScreen;
EditBox* ipEdit;
public:
JoinMultiplayerScreen(Screen *lastScreen);
JoinMultiplayerScreen(Screen* lastScreen);
virtual void tick();
virtual void init();
virtual void removed();
protected:
virtual void buttonClicked(Button *button);
virtual void buttonClicked(Button* button);
private:
virtual int parseInt(const std::wstring& str, int def);
virtual int parseInt(const std::wstring& str, int def);
protected:
virtual void keyPressed(wchar_t ch, int eventKey);
virtual void keyPressed(wchar_t ch, int eventKey);
virtual void mouseClicked(int x, int y, int buttonNum);
public:
virtual void render(int xm, int ym, float a);
virtual void render(int xm, int ym, float a);
};

View File

@@ -3,65 +3,57 @@
#include "../Button.h"
#include "../../../Minecraft.World/Util/StringHelpers.h"
const std::wstring NameEntryScreen::allowedChars = L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ,.:-_'*!\"#%/()=+?[]{}<>";
const std::wstring NameEntryScreen::allowedChars =
L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 "
L",.:-_'*!\"#%/()=+?[]{}<>";
NameEntryScreen::NameEntryScreen(Screen *lastScreen, const std::wstring& oldName, int slot)
{
frame = 0; // 4J added
NameEntryScreen::NameEntryScreen(Screen* lastScreen,
const std::wstring& oldName, int slot) {
frame = 0; // 4J added
this->lastScreen = lastScreen;
this->slot = slot;
this->name = oldName;
if (name==L"-") name = L"";
if (name == L"-") name = L"";
}
void NameEntryScreen::init()
{
void NameEntryScreen::init() {
buttons.clear();
Keyboard::enableRepeatEvents(true);
buttons.push_back(new Button(0, width / 2 - 100, height / 4 + 24 * 5, L"Save"));
buttons.push_back(new Button(1, width / 2 - 100, height / 4 + 24 * 6, L"Cancel"));
buttons.push_back(
new Button(0, width / 2 - 100, height / 4 + 24 * 5, L"Save"));
buttons.push_back(
new Button(1, width / 2 - 100, height / 4 + 24 * 6, L"Cancel"));
buttons[0]->active = trimString(name).length() > 1;
}
void NameEntryScreen::removed()
{
Keyboard::enableRepeatEvents(false);
}
void NameEntryScreen::removed() { Keyboard::enableRepeatEvents(false); }
void NameEntryScreen::tick()
{
frame++;
}
void NameEntryScreen::tick() { frame++; }
void NameEntryScreen::buttonClicked(Button button)
{
void NameEntryScreen::buttonClicked(Button button) {
if (!button.active) return;
if (button.id == 0 && trimString(name).length() > 1)
{
if (button.id == 0 && trimString(name).length() > 1) {
minecraft->saveSlot(slot, trimString(name));
minecraft->setScreen(NULL);
// minecraft->grabMouse(); // 4J - removed
// minecraft->grabMouse(); // 4J - removed
}
if (button.id == 1)
{
if (button.id == 1) {
minecraft->setScreen(lastScreen);
}
}
void NameEntryScreen::keyPressed(wchar_t ch, int eventKey)
{
if (eventKey == Keyboard::KEY_BACK && name.length() > 0) name = name.substr(0, name.length() - 1);
if (allowedChars.find(ch) != std::wstring::npos && name.length()<64)
{
void NameEntryScreen::keyPressed(wchar_t ch, int eventKey) {
if (eventKey == Keyboard::KEY_BACK && name.length() > 0)
name = name.substr(0, name.length() - 1);
if (allowedChars.find(ch) != std::wstring::npos && name.length() < 64) {
name += ch;
}
buttons[0]->active = trimString(name).length() > 1;
}
void NameEntryScreen::render(int xm, int ym, float a)
{
void NameEntryScreen::render(int xm, int ym, float a) {
renderBackground();
drawCenteredString(font, title, width / 2, 40, 0xffffff);
@@ -72,7 +64,8 @@ void NameEntryScreen::render(int xm, int ym, float a)
int bh = 20;
fill(bx - 1, by - 1, bx + bw + 1, by + bh + 1, 0xffa0a0a0);
fill(bx, by, bx + bw, by + bh, 0xff000000);
drawString(font, name + (frame / 6 % 2 == 0 ? L"_" : L""), bx + 4, by + (bh - 8) / 2, 0xe0e0e0);
drawString(font, name + (frame / 6 % 2 == 0 ? L"_" : L""), bx + 4,
by + (bh - 8) / 2, 0xe0e0e0);
Screen::render(xm, ym, a);
}

View File

@@ -1,27 +1,33 @@
#pragma once
#include "../Screen.h"
class NameEntryScreen : public Screen
{
class NameEntryScreen : public Screen {
private:
Screen *lastScreen;
Screen* lastScreen;
protected:
std::wstring title;
std::wstring title;
private:
int slot;
int slot;
std::wstring name;
int frame;
public:
NameEntryScreen(Screen *lastScreen, const std::wstring& oldName, int slot);
NameEntryScreen(Screen* lastScreen, const std::wstring& oldName, int slot);
virtual void init();
virtual void removed();
virtual void tick();
protected:
virtual void buttonClicked(Button button);
virtual void buttonClicked(Button button);
private:
static const std::wstring allowedChars;
static const std::wstring allowedChars;
protected:
virtual void keyPressed(wchar_t ch, int eventKey);
virtual void keyPressed(wchar_t ch, int eventKey);
public:
virtual void render(int xm, int ym, float a);
virtual void render(int xm, int ym, float a);
};

View File

@@ -7,70 +7,72 @@
#include "VideoSettingsScreen.h"
#include "../../../Minecraft.World/Headers/net.minecraft.locale.h"
OptionsScreen::OptionsScreen(Screen *lastScreen, Options *options)
{
title = L"Options"; // 4J added
OptionsScreen::OptionsScreen(Screen* lastScreen, Options* options) {
title = L"Options"; // 4J added
this->lastScreen = lastScreen;
this->options = options;
}
void OptionsScreen::init()
{
Language *language = Language::getInstance();
void OptionsScreen::init() {
Language* language = Language::getInstance();
this->title = language->getElement(L"options.title");
int position = 0;
// 4J - this was as static array but moving it into the function to remove any issues with static initialisation order
const Options::Option *items[5] = {Options::Option::MUSIC, Options::Option::SOUND, Options::Option::INVERT_MOUSE, Options::Option::SENSITIVITY, Options::Option::DIFFICULTY};
for (int i = 0; i < 5; i++)
{
const Options::Option *item = items[i];
if (!item->isProgress())
{
buttons.push_back(new SmallButton(item->getId(), width / 2 - 155 + position % 2 * 160, height / 6 + 24 * (position >> 1), item, options->getMessage(item)));
}
else
{
buttons.push_back(new SlideButton(item->getId(), width / 2 - 155 + position % 2 * 160, height / 6 + 24 * (position >> 1), item, options->getMessage(item), options->getProgressValue(item)));
// 4J - this was as static array but moving it into the function to remove
// any issues with static initialisation order
const Options::Option* items[5] = {
Options::Option::MUSIC, Options::Option::SOUND,
Options::Option::INVERT_MOUSE, Options::Option::SENSITIVITY,
Options::Option::DIFFICULTY};
for (int i = 0; i < 5; i++) {
const Options::Option* item = items[i];
if (!item->isProgress()) {
buttons.push_back(new SmallButton(
item->getId(), width / 2 - 155 + position % 2 * 160,
height / 6 + 24 * (position >> 1), item,
options->getMessage(item)));
} else {
buttons.push_back(new SlideButton(
item->getId(), width / 2 - 155 + position % 2 * 160,
height / 6 + 24 * (position >> 1), item,
options->getMessage(item), options->getProgressValue(item)));
}
position++;
}
buttons.push_back(new Button(VIDEO_BUTTON_ID, width / 2 - 100, height / 6 + 24 * 4 + 12, language->getElement(L"options.video")));
buttons.push_back(new Button(CONTROLS_BUTTON_ID, width / 2 - 100, height / 6 + 24 * 5 + 12, language->getElement(L"options.controls")));
buttons.push_back(new Button(200, width / 2 - 100, height / 6 + 24 * 7, language->getElement(L"gui.done")));
buttons.push_back(new Button(VIDEO_BUTTON_ID, width / 2 - 100,
height / 6 + 24 * 4 + 12,
language->getElement(L"options.video")));
buttons.push_back(new Button(CONTROLS_BUTTON_ID, width / 2 - 100,
height / 6 + 24 * 5 + 12,
language->getElement(L"options.controls")));
buttons.push_back(new Button(200, width / 2 - 100, height / 6 + 24 * 7,
language->getElement(L"gui.done")));
}
void OptionsScreen::buttonClicked(Button *button)
{
void OptionsScreen::buttonClicked(Button* button) {
if (!button->active) return;
if (button->id < 100 && (dynamic_cast<SmallButton *>(button) != NULL))
{
options->toggle(((SmallButton *) button)->getOption(), 1);
if (button->id < 100 && (dynamic_cast<SmallButton*>(button) != NULL)) {
options->toggle(((SmallButton*)button)->getOption(), 1);
button->msg = options->getMessage(Options::Option::getItem(button->id));
}
if (button->id == VIDEO_BUTTON_ID)
{
if (button->id == VIDEO_BUTTON_ID) {
minecraft->options->save();
minecraft->setScreen(new VideoSettingsScreen(this, options));
}
if (button->id == CONTROLS_BUTTON_ID)
{
if (button->id == CONTROLS_BUTTON_ID) {
minecraft->options->save();
minecraft->setScreen(new ControlsScreen(this, options));
}
if (button->id == 200)
{
if (button->id == 200) {
minecraft->options->save();
minecraft->setScreen(lastScreen);
}
}
void OptionsScreen::render(int xm, int ym, float a)
{
void OptionsScreen::render(int xm, int ym, float a) {
renderBackground();
drawCenteredString(font, title, width / 2, 20, 0xffffff);
Screen::render(xm, ym, a);

View File

@@ -2,22 +2,25 @@
#include "../Screen.h"
class Options;
class OptionsScreen : public Screen
{
class OptionsScreen : public Screen {
private:
static const int CONTROLS_BUTTON_ID = 100;
static const int CONTROLS_BUTTON_ID = 100;
static const int VIDEO_BUTTON_ID = 101;
Screen *lastScreen;
Screen* lastScreen;
protected:
std::wstring title;
std::wstring title;
private:
Options *options;
Options* options;
public:
OptionsScreen(Screen *lastScreen, Options *options);
OptionsScreen(Screen* lastScreen, Options* options);
virtual void init();
protected:
virtual void buttonClicked(Button *button);
virtual void buttonClicked(Button* button);
public:
virtual void render(int xm, int ym, float a);
virtual void render(int xm, int ym, float a);
};

View File

@@ -10,87 +10,80 @@
#include "../../../Minecraft.World/Headers/net.minecraft.stats.h"
#include "../../Player/LocalPlayer.h"
PauseScreen::PauseScreen()
{
saveStep = 0;
visibleTime = 0;
PauseScreen::PauseScreen() {
saveStep = 0;
visibleTime = 0;
}
void PauseScreen::init()
{
void PauseScreen::init() {
saveStep = 0;
buttons.clear();
int yo = -16;
buttons.push_back(new Button(1, width / 2 - 100, height / 4 + 24 * 5 + yo, L"Save and quit to title"));
if (minecraft->isClientSide())
{
buttons.push_back(new Button(1, width / 2 - 100, height / 4 + 24 * 5 + yo,
L"Save and quit to title"));
if (minecraft->isClientSide()) {
buttons[0]->msg = L"Disconnect";
}
buttons.push_back(new Button(4, width / 2 - 100, height / 4 + 24 * 1 + yo,
L"LBack to game"));
buttons.push_back(new Button(0, width / 2 - 100, height / 4 + 24 * 4 + yo,
L"LOptions..."));
buttons.push_back(new Button(4, width / 2 - 100, height / 4 + 24 * 1 + yo, L"LBack to game"));
buttons.push_back(new Button(0, width / 2 - 100, height / 4 + 24 * 4 + yo, L"LOptions..."));
buttons.push_back(new Button(5, width / 2 - 100, height / 4 + 24 * 2 + yo, 98, 20, I18n::get(L"gui.achievements")));
buttons.push_back(new Button(6, width / 2 + 2, height / 4 + 24 * 2 + yo, 98, 20, I18n::get(L"gui.stats")));
buttons.push_back(new Button(5, width / 2 - 100, height / 4 + 24 * 2 + yo,
98, 20, I18n::get(L"gui.achievements")));
buttons.push_back(new Button(6, width / 2 + 2, height / 4 + 24 * 2 + yo, 98,
20, I18n::get(L"gui.stats")));
/*
* if (minecraft->serverConnection!=null) { buttons.get(1).active =
* false; buttons.get(2).active = false; buttons.get(3).active = false;
* }
*/
* if (minecraft->serverConnection!=null) { buttons.get(1).active =
* false; buttons.get(2).active = false; buttons.get(3).active = false;
* }
*/
}
void PauseScreen::buttonClicked(Button button)
{
if (button.id == 0)
{
void PauseScreen::buttonClicked(Button button) {
if (button.id == 0) {
minecraft->setScreen(new OptionsScreen(this, minecraft->options));
}
if (button.id == 1)
{
if (minecraft->isClientSide())
{
if (button.id == 1) {
if (minecraft->isClientSide()) {
minecraft->level->disconnect();
}
minecraft->setLevel(NULL);
minecraft->setScreen(new TitleScreen());
}
if (button.id == 4)
{
if (button.id == 4) {
minecraft->setScreen(NULL);
// minecraft->grabMouse(); // 4J - removed
// minecraft->grabMouse(); // 4J - removed
}
if (button.id == 5)
{
// minecraft->setScreen(new AchievementScreen(minecraft->stats)); // 4J TODO - put back
if (button.id == 5) {
// minecraft->setScreen(new AchievementScreen(minecraft->stats));
// // 4J TODO - put back
}
if (button.id == 6)
{
// minecraft->setScreen(new StatsScreen(this, minecraft->stats)); // 4J TODO - put back
if (button.id == 6) {
// minecraft->setScreen(new StatsScreen(this, minecraft->stats));
// // 4J TODO - put back
}
}
void PauseScreen::tick()
{
void PauseScreen::tick() {
Screen::tick();
visibleTime++;
}
void PauseScreen::render(int xm, int ym, float a)
{
void PauseScreen::render(int xm, int ym, float a) {
renderBackground();
bool isSaving = false; //!minecraft->level->pauseSave(saveStep++);
if (isSaving || visibleTime < 20)
{
bool isSaving = false; //! minecraft->level->pauseSave(saveStep++);
if (isSaving || visibleTime < 20) {
float col = ((visibleTime % 10) + a) / 10.0f;
col = Mth::sin(col * PI * 2) * 0.2f + 0.8f;
int br = (int) (255 * col);
int br = (int)(255 * col);
drawString(font, L"Saving level..", 8, height - 16, br << 16 | br << 8 | br);
drawString(font, L"Saving level..", 8, height - 16,
br << 16 | br << 8 | br);
}
drawCenteredString(font, L"Game menu", width / 2, 40, 0xffffff);

View File

@@ -1,18 +1,21 @@
#pragma once
#include "../Screen.h"
class PauseScreen : public Screen
{
class PauseScreen : public Screen {
private:
int saveStep;
int saveStep;
int visibleTime;
public:
PauseScreen(); // 4J added
virtual void init();
protected:using Screen::buttonClicked;
virtual void buttonClicked(Button button);
public:
virtual void tick();
PauseScreen(); // 4J added
virtual void init();
protected:
using Screen::buttonClicked;
virtual void buttonClicked(Button button);
public:
virtual void tick();
virtual void render(int xm, int ym, float a);
};

View File

@@ -3,45 +3,36 @@
#include "../../Network/ClientConnection.h"
#include "../../../Minecraft.World/Headers/net.minecraft.locale.h"
ReceivingLevelScreen::ReceivingLevelScreen(ClientConnection *connection)
{
tickCount = 0;
this->connection = connection;
ReceivingLevelScreen::ReceivingLevelScreen(ClientConnection* connection) {
tickCount = 0;
this->connection = connection;
}
void ReceivingLevelScreen::keyPressed(char eventCharacter, int eventKey)
{
}
void ReceivingLevelScreen::keyPressed(char eventCharacter, int eventKey) {}
void ReceivingLevelScreen::init()
{
buttons.clear();
}
void ReceivingLevelScreen::init() { buttons.clear(); }
void ReceivingLevelScreen::tick()
{
void ReceivingLevelScreen::tick() {
tickCount++;
if (tickCount % 20 == 0)
{
connection->send( std::shared_ptr<KeepAlivePacket>( new KeepAlivePacket() ) );
if (tickCount % 20 == 0) {
connection->send(
std::shared_ptr<KeepAlivePacket>(new KeepAlivePacket()));
}
if (connection != NULL)
{
if (connection != NULL) {
connection->tick();
}
}
void ReceivingLevelScreen::buttonClicked(Button *button)
{
}
void ReceivingLevelScreen::buttonClicked(Button* button) {}
void ReceivingLevelScreen::render(int xm, int ym, float a)
{
void ReceivingLevelScreen::render(int xm, int ym, float a) {
renderDirtBackground(0);
Language *language = Language::getInstance();
Language* language = Language::getInstance();
drawCenteredString(font, language->getElement(L"multiplayer.downloadingTerrain"), width / 2, height / 2 - 50, 0xffffff);
drawCenteredString(font,
language->getElement(L"multiplayer.downloadingTerrain"),
width / 2, height / 2 - 50, 0xffffff);
Screen::render(xm, ym, a);
}

View File

@@ -2,23 +2,26 @@
#include "../Screen.h"
class ClientConnection;
class ReceivingLevelScreen : public Screen
{
class ReceivingLevelScreen : public Screen {
private:
ClientConnection *connection;
ClientConnection* connection;
int tickCount;
public:
ReceivingLevelScreen(ClientConnection *connection);
protected:
using Screen::keyPressed;
ReceivingLevelScreen(ClientConnection* connection);
virtual void keyPressed(char eventCharacter, int eventKey);
public:
virtual void init();
virtual void tick();
protected:
virtual void buttonClicked(Button *button);
using Screen::keyPressed;
virtual void keyPressed(char eventCharacter, int eventKey);
public:
virtual void render(int xm, int ym, float a);
virtual void init();
virtual void tick();
protected:
virtual void buttonClicked(Button* button);
public:
virtual void render(int xm, int ym, float a);
};

View File

@@ -6,21 +6,18 @@
#include "../../../Minecraft.World/Headers/net.minecraft.world.level.h"
#include "../../../Minecraft.World/Headers/net.minecraft.world.level.storage.h"
RenameWorldScreen::RenameWorldScreen(Screen *lastScreen, const std::wstring& levelId)
{
nameEdit = NULL;
RenameWorldScreen::RenameWorldScreen(Screen* lastScreen,
const std::wstring& levelId) {
nameEdit = NULL;
this->lastScreen = lastScreen;
this->levelId = levelId;
}
void RenameWorldScreen::tick()
{
nameEdit->tick();
}
void RenameWorldScreen::tick() { nameEdit->tick(); }
void RenameWorldScreen::init()
{
// 4J Stu - Removed this as we don't need the screen. Changed to how we pass save data around stopped this compiling
void RenameWorldScreen::init() {
// 4J Stu - Removed this as we don't need the screen. Changed to how we pass
// save data around stopped this compiling
#if 0
Language *language = Language::getInstance();
@@ -39,58 +36,47 @@ void RenameWorldScreen::init()
#endif
}
void RenameWorldScreen::removed()
{
Keyboard::enableRepeatEvents(false);
}
void RenameWorldScreen::removed() { Keyboard::enableRepeatEvents(false); }
void RenameWorldScreen::buttonClicked(Button *button)
{
void RenameWorldScreen::buttonClicked(Button* button) {
if (!button->active) return;
if (button->id == 1)
{
if (button->id == 1) {
minecraft->setScreen(lastScreen);
}
else if (button->id == 0)
{
LevelStorageSource *levelSource = minecraft->getLevelSource();
} else if (button->id == 0) {
LevelStorageSource* levelSource = minecraft->getLevelSource();
levelSource->renameLevel(levelId, trimString(nameEdit->getValue()));
minecraft->setScreen(lastScreen);
}
}
void RenameWorldScreen::keyPressed(wchar_t ch, int eventKey)
{
void RenameWorldScreen::keyPressed(wchar_t ch, int eventKey) {
nameEdit->keyPressed(ch, eventKey);
buttons[0]->active = trimString(nameEdit->getValue()).length() > 0;
if (ch == 13)
{
if (ch == 13) {
buttonClicked(buttons[0]);
}
}
void RenameWorldScreen::mouseClicked(int x, int y, int buttonNum)
{
void RenameWorldScreen::mouseClicked(int x, int y, int buttonNum) {
Screen::mouseClicked(x, y, buttonNum);
nameEdit->mouseClicked(x, y, buttonNum);
}
void RenameWorldScreen::render(int xm, int ym, float a)
{
Language *language = Language::getInstance();
void RenameWorldScreen::render(int xm, int ym, float a) {
Language* language = Language::getInstance();
// fill(0, 0, width, height, 0x40000000);
renderBackground();
drawCenteredString(font, language->getElement(L"selectWorld.renameTitle"), width / 2, height / 4 - 60 + 20, 0xffffff);
drawString(font, language->getElement(L"selectWorld.enterName"), width / 2 - 100, 47, 0xa0a0a0);
drawCenteredString(font, language->getElement(L"selectWorld.renameTitle"),
width / 2, height / 4 - 60 + 20, 0xffffff);
drawString(font, language->getElement(L"selectWorld.enterName"),
width / 2 - 100, 47, 0xa0a0a0);
nameEdit->render();
Screen::render(xm, ym, a);
}

View File

@@ -3,23 +3,23 @@
class Button;
class EditBox;
class RenameWorldScreen : public Screen
{
class RenameWorldScreen : public Screen {
private:
Screen *lastScreen;
EditBox *nameEdit;
Screen* lastScreen;
EditBox* nameEdit;
std::wstring levelId;
public:
RenameWorldScreen(Screen *lastScreen, const std::wstring& levelId);
RenameWorldScreen(Screen* lastScreen, const std::wstring& levelId);
virtual void tick();
virtual void init() ;
virtual void init();
virtual void removed();
protected:
virtual void buttonClicked(Button *button);
virtual void buttonClicked(Button* button);
virtual void keyPressed(wchar_t ch, int eventKey);
virtual void mouseClicked(int x, int y, int buttonNum);
public:
virtual void render(int xm, int ym, float a);
virtual void render(int xm, int ym, float a);
};

View File

@@ -9,25 +9,22 @@
#include "../../../Minecraft.World/Headers/net.minecraft.world.level.h"
#include "../../../Minecraft.World/Headers/net.minecraft.world.level.storage.h"
SelectWorldScreen::SelectWorldScreen(Screen *lastScreen)
{
// 4J - added initialisers
SelectWorldScreen::SelectWorldScreen(Screen* lastScreen) {
// 4J - added initialisers
title = L"Select world";
done = false;
selectedWorld = 0;
worldSelectionList = NULL;
isDeleting = false;
deleteButton = NULL;
selectedWorld = 0;
worldSelectionList = NULL;
isDeleting = false;
deleteButton = NULL;
selectButton = NULL;
renameButton = NULL;
this->lastScreen = lastScreen;
this->lastScreen = lastScreen;
}
void SelectWorldScreen::init()
{
Language *language = Language::getInstance();
void SelectWorldScreen::init() {
Language* language = Language::getInstance();
title = language->getElement(L"selectWorld.title");
worldLang = language->getElement(L"selectWorld.world");
@@ -40,80 +37,79 @@ void SelectWorldScreen::init()
postInit();
}
void SelectWorldScreen::loadLevelList()
{
LevelStorageSource *levelSource = minecraft->getLevelSource();
levelList = levelSource->getLevelList();
// Collections.sort(levelList); // 4J - TODO - get sort functor etc.
selectedWorld = -1;
void SelectWorldScreen::loadLevelList() {
LevelStorageSource* levelSource = minecraft->getLevelSource();
levelList = levelSource->getLevelList();
// Collections.sort(levelList); // 4J - TODO - get sort functor etc.
selectedWorld = -1;
}
std::wstring SelectWorldScreen::getWorldId(int id)
{
return levelList->at(id)->getLevelId();
std::wstring SelectWorldScreen::getWorldId(int id) {
return levelList->at(id)->getLevelId();
}
std::wstring SelectWorldScreen::getWorldName(int id)
{
std::wstring SelectWorldScreen::getWorldName(int id) {
std::wstring levelName = levelList->at(id)->getLevelName();
if ( levelName.length() == 0 )
{
Language *language = Language::getInstance();
levelName = language->getElement(L"selectWorld.world") + L" " + _toString<int>(id + 1);
if (levelName.length() == 0) {
Language* language = Language::getInstance();
levelName = language->getElement(L"selectWorld.world") + L" " +
_toString<int>(id + 1);
}
return levelName;
}
void SelectWorldScreen::postInit()
{
Language *language = Language::getInstance();
void SelectWorldScreen::postInit() {
Language* language = Language::getInstance();
buttons.push_back(selectButton = new Button(BUTTON_SELECT_ID, width / 2 - 154, height - 52, 150, 20, language->getElement(L"selectWorld.select")));
buttons.push_back(deleteButton = new Button(BUTTON_RENAME_ID, width / 2 - 154, height - 28, 70, 20, language->getElement(L"selectWorld.rename")));
buttons.push_back(renameButton = new Button(BUTTON_DELETE_ID, width / 2 - 74, height - 28, 70, 20, language->getElement(L"selectWorld.delete")));
buttons.push_back(new Button(BUTTON_CREATE_ID, width / 2 + 4, height - 52, 150, 20, language->getElement(L"selectWorld.create")));
buttons.push_back(new Button(BUTTON_CANCEL_ID, width / 2 + 4, height - 28, 150, 20, language->getElement(L"gui.cancel")));
buttons.push_back(selectButton = new Button(
BUTTON_SELECT_ID, width / 2 - 154, height - 52, 150,
20, language->getElement(L"selectWorld.select")));
buttons.push_back(deleteButton = new Button(
BUTTON_RENAME_ID, width / 2 - 154, height - 28, 70,
20, language->getElement(L"selectWorld.rename")));
buttons.push_back(renameButton = new Button(
BUTTON_DELETE_ID, width / 2 - 74, height - 28, 70, 20,
language->getElement(L"selectWorld.delete")));
buttons.push_back(new Button(BUTTON_CREATE_ID, width / 2 + 4, height - 52,
150, 20,
language->getElement(L"selectWorld.create")));
buttons.push_back(new Button(BUTTON_CANCEL_ID, width / 2 + 4, height - 28,
150, 20, language->getElement(L"gui.cancel")));
selectButton->active = false;
deleteButton->active = false;
renameButton->active = false;
}
void SelectWorldScreen::buttonClicked(Button *button)
{
void SelectWorldScreen::buttonClicked(Button* button) {
if (!button->active) return;
if (button->id == BUTTON_DELETE_ID)
{
if (button->id == BUTTON_DELETE_ID) {
std::wstring worldName = getWorldName(selectedWorld);
if (worldName != L"")
{
if (worldName != L"") {
isDeleting = true;
Language *language = Language::getInstance();
std::wstring title = language->getElement(L"selectWorld.deleteQuestion");
std::wstring warning = L"'" + worldName + L"' " + language->getElement(L"selectWorld.deleteWarning");
std::wstring yes = language->getElement(L"selectWorld.deleteButton");
Language* language = Language::getInstance();
std::wstring title =
language->getElement(L"selectWorld.deleteQuestion");
std::wstring warning =
L"'" + worldName + L"' " +
language->getElement(L"selectWorld.deleteWarning");
std::wstring yes =
language->getElement(L"selectWorld.deleteButton");
std::wstring no = language->getElement(L"gui.cancel");
ConfirmScreen *confirmScreen = new ConfirmScreen(this, title, warning, yes, no, selectedWorld);
ConfirmScreen* confirmScreen =
new ConfirmScreen(this, title, warning, yes, no, selectedWorld);
minecraft->setScreen(confirmScreen);
}
}
else if (button->id == BUTTON_SELECT_ID)
{
} else if (button->id == BUTTON_SELECT_ID) {
worldSelected(selectedWorld);
}
else if (button->id == BUTTON_CREATE_ID)
{
if (ProfileManager.IsFullVersion())
{
} else if (button->id == BUTTON_CREATE_ID) {
if (ProfileManager.IsFullVersion()) {
minecraft->setScreen(new CreateWorldScreen(this));
}
else
{
} else {
// create demo world
minecraft->setScreen(NULL);
if (done) return;
@@ -125,31 +121,25 @@ void SelectWorldScreen::buttonClicked(Button *button)
minecraft->setScreen(NULL);
#endif
}
}
else if (button->id == BUTTON_RENAME_ID)
{
minecraft->setScreen(new RenameWorldScreen(this, getWorldId(selectedWorld)));
}
else if (button->id == BUTTON_CANCEL_ID)
{
} else if (button->id == BUTTON_RENAME_ID) {
minecraft->setScreen(
new RenameWorldScreen(this, getWorldId(selectedWorld)));
} else if (button->id == BUTTON_CANCEL_ID) {
minecraft->setScreen(lastScreen);
}
else
{
} else {
worldSelectionList->buttonClicked(button);
}
}
void SelectWorldScreen::worldSelected(int id)
{
void SelectWorldScreen::worldSelected(int id) {
minecraft->setScreen(NULL);
if (done) return;
done = true;
minecraft->gameMode = NULL; //new SurvivalMode(minecraft);
minecraft->gameMode = NULL; // new SurvivalMode(minecraft);
std::wstring worldFolderName = getWorldId(id);
if (worldFolderName == L"") // 4J - was NULL comparison
{
if (worldFolderName == L"") // 4J - was NULL comparison
{
worldFolderName = L"World" + _toString<int>(id);
}
// 4J Stu - Not used, so commenting to stop the build failing
@@ -159,14 +149,11 @@ void SelectWorldScreen::worldSelected(int id)
#endif
}
void SelectWorldScreen::confirmResult(bool result, int id)
{
if (isDeleting)
{
void SelectWorldScreen::confirmResult(bool result, int id) {
if (isDeleting) {
isDeleting = false;
if (result)
{
LevelStorageSource *levelSource = minecraft->getLevelSource();
if (result) {
LevelStorageSource* levelSource = minecraft->getLevelSource();
levelSource->clearAll();
levelSource->deleteLevel(getWorldId(id));
@@ -176,8 +163,7 @@ void SelectWorldScreen::confirmResult(bool result, int id)
}
}
void SelectWorldScreen::render(int xm, int ym, float a)
{
void SelectWorldScreen::render(int xm, int ym, float a) {
// fill(0, 0, width, height, 0x40000000);
worldSelectionList->render(xm, ym, a);
@@ -185,126 +171,116 @@ void SelectWorldScreen::render(int xm, int ym, float a)
Screen::render(xm, ym, a);
// 4J - debug code - remove
static int count = 0;
static bool forceCreateLevel = false;
if( count++ >= 100 )
{
if( !forceCreateLevel && levelList->size() > 0 )
{
// 4J Stu - For some obscures reason the "delete" button is called "renameButton" and vice versa.
//if( levelList->size() > 2 && deleteButton->active )
//{
// this->selectedWorld = 2;
// count = 0;
// buttonClicked(deleteButton);
//}
//else
if( levelList->size() > 1 && renameButton->active )
{
this->selectedWorld = 1;
count = 0;
buttonClicked(renameButton);
}
else
if( selectButton->active == true )
{
this->selectedWorld = 0;
buttonClicked(selectButton);
//this->worldSelected( 0 );
}
else
{
selectButton->active = true;
deleteButton->active = true;
renameButton->active = true;
count = 0;
}
}
else
{
minecraft->setScreen(new CreateWorldScreen(this));
}
}
// 4J - debug code - remove
static int count = 0;
static bool forceCreateLevel = false;
if (count++ >= 100) {
if (!forceCreateLevel && levelList->size() > 0) {
// 4J Stu - For some obscures reason the "delete" button is called
// "renameButton" and vice versa.
// if( levelList->size() > 2 && deleteButton->active )
//{
// this->selectedWorld = 2;
// count = 0;
// buttonClicked(deleteButton);
//}
// else
if (levelList->size() > 1 && renameButton->active) {
this->selectedWorld = 1;
count = 0;
buttonClicked(renameButton);
} else if (selectButton->active == true) {
this->selectedWorld = 0;
buttonClicked(selectButton);
// this->worldSelected( 0 );
} else {
selectButton->active = true;
deleteButton->active = true;
renameButton->active = true;
count = 0;
}
} else {
minecraft->setScreen(new CreateWorldScreen(this));
}
}
}
SelectWorldScreen::WorldSelectionList::WorldSelectionList(SelectWorldScreen *sws) : ScrolledSelectionList(sws->minecraft, sws->width, sws->height, 32, sws->height - 64, 36)
{
parent = sws;
SelectWorldScreen::WorldSelectionList::WorldSelectionList(
SelectWorldScreen* sws)
: ScrolledSelectionList(sws->minecraft, sws->width, sws->height, 32,
sws->height - 64, 36) {
parent = sws;
}
int SelectWorldScreen::WorldSelectionList::getNumberOfItems()
{
return (int)this->parent->levelList->size();
int SelectWorldScreen::WorldSelectionList::getNumberOfItems() {
return (int)this->parent->levelList->size();
}
void SelectWorldScreen::WorldSelectionList::selectItem(int item, bool doubleClick)
{
void SelectWorldScreen::WorldSelectionList::selectItem(int item,
bool doubleClick) {
parent->selectedWorld = item;
bool active = (this->parent->selectedWorld >= 0 && this->parent->selectedWorld < getNumberOfItems());
bool active = (this->parent->selectedWorld >= 0 &&
this->parent->selectedWorld < getNumberOfItems());
parent->selectButton->active = active;
parent->deleteButton->active = active;
parent->renameButton->active = active;
if (doubleClick && active)
{
if (doubleClick && active) {
parent->worldSelected(item);
}
}
bool SelectWorldScreen::WorldSelectionList::isSelectedItem(int item)
{
return item == parent->selectedWorld;
bool SelectWorldScreen::WorldSelectionList::isSelectedItem(int item) {
return item == parent->selectedWorld;
}
int SelectWorldScreen::WorldSelectionList::getMaxPosition()
{
return (int)parent->levelList->size() * 36;
int SelectWorldScreen::WorldSelectionList::getMaxPosition() {
return (int)parent->levelList->size() * 36;
}
void SelectWorldScreen::WorldSelectionList::renderBackground()
{
parent->renderBackground(); // 4J - was SelectWorldScreen.this.renderBackground();
void SelectWorldScreen::WorldSelectionList::renderBackground() {
parent->renderBackground(); // 4J - was
// SelectWorldScreen.this.renderBackground();
}
void SelectWorldScreen::WorldSelectionList::renderItem(int i, int x, int y, int h, Tesselator *t)
{
LevelSummary *levelSummary = parent->levelList->at(i);
void SelectWorldScreen::WorldSelectionList::renderItem(int i, int x, int y,
int h, Tesselator* t) {
LevelSummary* levelSummary = parent->levelList->at(i);
std::wstring name = levelSummary->getLevelName();
if (name.length()==0)
{
if (name.length() == 0) {
name = parent->worldLang + L" " + _toString<int>(i + 1);
}
std::wstring id = levelSummary->getLevelId();
ULARGE_INTEGER rawtime;
rawtime.QuadPart = levelSummary->getLastPlayed() * 10000; // Convert it from milliseconds back to FileTime
ULARGE_INTEGER rawtime;
rawtime.QuadPart = levelSummary->getLastPlayed() *
10000; // Convert it from milliseconds back to FileTime
FILETIME timeasfiletime;
timeasfiletime.dwHighDateTime = rawtime.HighPart;
timeasfiletime.dwLowDateTime = rawtime.LowPart;
FILETIME timeasfiletime;
timeasfiletime.dwHighDateTime = rawtime.HighPart;
timeasfiletime.dwLowDateTime = rawtime.LowPart;
SYSTEMTIME time;
FileTimeToSystemTime( &timeasfiletime, &time );
SYSTEMTIME time;
FileTimeToSystemTime(&timeasfiletime, &time);
wchar_t buffer[20];
// 4J Stu - Currently shows years as 4 digits, where java only showed 2
swprintf(buffer,20,L"%d/%d/%d %d:%02d",time.wDay, time.wMonth, time.wYear, time.wHour, time.wMinute); // 4J - TODO Localise this
wchar_t buffer[20];
// 4J Stu - Currently shows years as 4 digits, where java only showed 2
swprintf(buffer, 20, L"%d/%d/%d %d:%02d", time.wDay, time.wMonth,
time.wYear, time.wHour, time.wMinute); // 4J - TODO Localise this
id = id + L" (" + buffer;
__int64 size = levelSummary->getSizeOnDisk();
id = id + L", " + _toString<float>(size / 1024 * 100 / 1024 / 100.0f) + L" MB)";
id = id + L", " + _toString<float>(size / 1024 * 100 / 1024 / 100.0f) +
L" MB)";
std::wstring info;
if (levelSummary->isRequiresConversion())
{
if (levelSummary->isRequiresConversion()) {
info = parent->conversionLang + L" " + info;
}
parent->drawString(parent->font, name, x + 2, y + 1, 0xffffff);
parent->drawString(parent->font, id, x + 2, y + 12, 0x808080);
parent->drawString(parent->font, info, x + 2, y + 12 + 10, 0x808080);
}

View File

@@ -5,14 +5,12 @@ class LevelSummary;
class Button;
class Tesselator;
class SelectWorldScreen : public Screen
{
class SelectWorldScreen : public Screen {
public:
class WorldSelectionList;
class WorldSelectionList;
protected:
static const int BUTTON_CANCEL_ID = 0;
static const int BUTTON_CANCEL_ID = 0;
static const int BUTTON_SELECT_ID = 1;
static const int BUTTON_DELETE_ID = 2;
static const int BUTTON_CREATE_ID = 3;
@@ -21,54 +19,61 @@ protected:
static const int BUTTON_RENAME_ID = 6;
private:
// final DateFormat DATE_FORMAT = new SimpleDateFormat(); // 4J - removed
// final DateFormat DATE_FORMAT = new SimpleDateFormat(); // 4J -
//removed
protected:
Screen *lastScreen;
Screen* lastScreen;
std::wstring title;
private:
bool done;
bool done;
int selectedWorld;
std::vector<LevelSummary *> *levelList;
WorldSelectionList *worldSelectionList;
std::vector<LevelSummary*>* levelList;
WorldSelectionList* worldSelectionList;
std::wstring worldLang;
std::wstring conversionLang;
bool isDeleting;
Button *deleteButton;
Button *selectButton;
Button *renameButton;
Button* deleteButton;
Button* selectButton;
Button* renameButton;
public:
SelectWorldScreen(Screen *lastScreen);
SelectWorldScreen(Screen* lastScreen);
virtual void init();
private:
void loadLevelList();
protected:
std::wstring getWorldId(int id);
std::wstring getWorldName(int id);
public:
virtual void postInit();
void loadLevelList();
protected:
virtual void buttonClicked(Button *button);
std::wstring getWorldId(int id);
std::wstring getWorldName(int id);
public:
void worldSelected(int id);
virtual void postInit();
protected:
virtual void buttonClicked(Button* button);
public:
void worldSelected(int id);
void confirmResult(bool result, int id);
virtual void render(int xm, int ym, float a);
class WorldSelectionList : public ScrolledSelectionList
{
public:
SelectWorldScreen *parent;
// 4J - had to add input parameters to ctor, original is a java subclass of the screen and can access its members
WorldSelectionList(SelectWorldScreen *sws);
protected:
virtual int getNumberOfItems();
class WorldSelectionList : public ScrolledSelectionList {
public:
SelectWorldScreen* parent;
// 4J - had to add input parameters to ctor, original is a java subclass
// of the screen and can access its members
WorldSelectionList(SelectWorldScreen* sws);
protected:
virtual int getNumberOfItems();
virtual void selectItem(int item, bool doubleClick);
virtual bool isSelectedItem(int item);
virtual int getMaxPosition();
virtual void renderBackground();
virtual void renderItem(int i, int x, int y, int h, Tesselator *t);
virtual void renderItem(int i, int x, int y, int h, Tesselator* t);
};
};

View File

@@ -10,21 +10,19 @@
#include "../../../Minecraft.World/Headers/net.minecraft.world.item.h"
const float StatsScreen::SLOT_TEX_SIZE = 128.0f;
ItemRenderer *StatsScreen::itemRenderer = NULL;
ItemRenderer* StatsScreen::itemRenderer = NULL;
StatsScreen::StatsScreen(Screen *lastScreen, StatsCounter *stats)
{
// 4J - added initialisers
itemRenderer = new ItemRenderer();
statsList = NULL;
itemStatsList = NULL;
blockStatsList = NULL;
StatsScreen::StatsScreen(Screen* lastScreen, StatsCounter* stats) {
// 4J - added initialisers
itemRenderer = new ItemRenderer();
statsList = NULL;
itemStatsList = NULL;
blockStatsList = NULL;
this->lastScreen = lastScreen;
this->stats = stats;
}
void StatsScreen::init()
{
void StatsScreen::init() {
title = I18n::get(L"gui.stats");
statsList = new GeneralStatisticsList(this);
@@ -41,104 +39,93 @@ void StatsScreen::init()
postInit();
}
void StatsScreen::postInit()
{
Language *language = Language::getInstance();
buttons.push_back(new Button(BUTTON_CANCEL_ID, width / 2 + 4, height - 28, 150, 20, language->getElement(L"gui.done")));
void StatsScreen::postInit() {
Language* language = Language::getInstance();
buttons.push_back(new Button(BUTTON_CANCEL_ID, width / 2 + 4, height - 28,
150, 20, language->getElement(L"gui.done")));
Button *blockButton, *itemButton;
buttons.push_back(new Button(BUTTON_STATS_ID, width / 2 - 154, height - 52, 100, 20, language->getElement(L"stat.generalButton")));
buttons.push_back(blockButton = new Button(BUTTON_BLOCKITEMSTATS_ID, width / 2 - 46, height - 52, 100, 20, language->getElement(L"stat.blocksButton")));
buttons.push_back(itemButton = new Button(BUTTON_ITEMSTATS_ID, width / 2 + 62, height - 52, 100, 20, language->getElement(L"stat.itemsButton")));
buttons.push_back(new Button(BUTTON_STATS_ID, width / 2 - 154, height - 52,
100, 20,
language->getElement(L"stat.generalButton")));
buttons.push_back(blockButton = new Button(
BUTTON_BLOCKITEMSTATS_ID, width / 2 - 46, height - 52,
100, 20, language->getElement(L"stat.blocksButton")));
buttons.push_back(itemButton = new Button(
BUTTON_ITEMSTATS_ID, width / 2 + 62, height - 52, 100,
20, language->getElement(L"stat.itemsButton")));
if (blockStatsList->getNumberOfItems() == 0)
{
if (blockStatsList->getNumberOfItems() == 0) {
blockButton->active = false;
}
if (itemStatsList->getNumberOfItems() == 0)
{
if (itemStatsList->getNumberOfItems() == 0) {
itemButton->active = false;
}
}
void StatsScreen::buttonClicked(Button *button)
{
void StatsScreen::buttonClicked(Button* button) {
if (!button->active) return;
if (button->id == BUTTON_CANCEL_ID)
{
if (button->id == BUTTON_CANCEL_ID) {
minecraft->setScreen(lastScreen);
}
else if (button->id == BUTTON_STATS_ID)
{
} else if (button->id == BUTTON_STATS_ID) {
activeList = statsList;
}
else if (button->id == BUTTON_ITEMSTATS_ID)
{
} else if (button->id == BUTTON_ITEMSTATS_ID) {
activeList = itemStatsList;
}
else if (button->id == BUTTON_BLOCKITEMSTATS_ID)
{
} else if (button->id == BUTTON_BLOCKITEMSTATS_ID) {
activeList = blockStatsList;
}
else
{
} else {
activeList->buttonClicked(button);
}
}
void StatsScreen::render(int xm, int ym, float a)
{
void StatsScreen::render(int xm, int ym, float a) {
activeList->render(xm, ym, a);
drawCenteredString(font, title, width / 2, 20, 0xffffff);
Screen::render(xm, ym, a);
}
StatsScreen::GeneralStatisticsList::GeneralStatisticsList(StatsScreen *ss) : ScrolledSelectionList(ss->minecraft, ss->width, ss->height, 32, ss->height - 64, 10)
{
parent = ss;
setRenderSelection(false);
StatsScreen::GeneralStatisticsList::GeneralStatisticsList(StatsScreen* ss)
: ScrolledSelectionList(ss->minecraft, ss->width, ss->height, 32,
ss->height - 64, 10) {
parent = ss;
setRenderSelection(false);
}
int StatsScreen::GeneralStatisticsList::getNumberOfItems()
{
return (int)Stats::generalStats->size();
int StatsScreen::GeneralStatisticsList::getNumberOfItems() {
return (int)Stats::generalStats->size();
}
void StatsScreen::GeneralStatisticsList::selectItem(int item, bool doubleClick)
{
void StatsScreen::GeneralStatisticsList::selectItem(int item,
bool doubleClick) {}
bool StatsScreen::GeneralStatisticsList::isSelectedItem(int item) {
return false;
}
bool StatsScreen::GeneralStatisticsList::isSelectedItem(int item)
{
return false;
int StatsScreen::GeneralStatisticsList::getMaxPosition() {
return getNumberOfItems() * 10;
}
int StatsScreen::GeneralStatisticsList::getMaxPosition()
{
return getNumberOfItems() * 10;
void StatsScreen::GeneralStatisticsList::renderBackground() {
parent
->renderBackground(); // 4J - was StatsScreen.this.renderBackground();
}
void StatsScreen::GeneralStatisticsList::renderBackground()
{
parent->renderBackground(); // 4J - was StatsScreen.this.renderBackground();
}
void StatsScreen::GeneralStatisticsList::renderItem(int i, int x, int y, int h, Tesselator *t)
{
Stat *stat = Stats::generalStats->at(i);
parent->drawString(parent->font, stat->name, x + 2, y + 1, i % 2 == 0 ? 0xffffff : 0x909090);
void StatsScreen::GeneralStatisticsList::renderItem(int i, int x, int y, int h,
Tesselator* t) {
Stat* stat = Stats::generalStats->at(i);
parent->drawString(parent->font, stat->name, x + 2, y + 1,
i % 2 == 0 ? 0xffffff : 0x909090);
std::wstring msg = stat->format(parent->stats->getTotalValue(stat));
parent->drawString(parent->font, msg, x + 2 + 213 - parent->font->width(msg), y + 1, i % 2 == 0 ? 0xffffff : 0x909090);
parent->drawString(parent->font, msg,
x + 2 + 213 - parent->font->width(msg), y + 1,
i % 2 == 0 ? 0xffffff : 0x909090);
}
void StatsScreen::blitSlot(int x, int y, int item)
{
void StatsScreen::blitSlot(int x, int y, int item) {
// 4J Unused
#if 0
blitSlotBg(x + SLOT_BG_X, y + SLOT_BG_Y);
@@ -157,14 +144,10 @@ void StatsScreen::blitSlot(int x, int y, int item)
#endif
}
void StatsScreen::blitSlotBg(int x, int y)
{
blitSlotIcon(x, y, 0, 0);
}
void StatsScreen::blitSlotBg(int x, int y) { blitSlotIcon(x, y, 0, 0); }
void StatsScreen::blitSlotIcon(int x, int y, int sx, int sy)
{
// 4J Unused
void StatsScreen::blitSlotIcon(int x, int y, int sx, int sy) {
// 4J Unused
#if 0
int tex = minecraft->textures->loadTexture(L"/gui/slot.png");
glColor4f(1, 1, 1, 1);
@@ -185,193 +168,164 @@ void StatsScreen::blitSlotIcon(int x, int y, int sx, int sy)
}
// 4J - added parameter so we can access parent
StatsScreen::StatisticsList::StatisticsList(StatsScreen *ss) : ScrolledSelectionList(ss->minecraft, ss->width, ss->height, 32, ss->height - 64, SLOT_STAT_HEIGHT)
{
// 4J - added initialisers
parent = ss;
headerPressed = -1;
sortColumn = -1;
sortOrder = SORT_NONE;
StatsScreen::StatisticsList::StatisticsList(StatsScreen* ss)
: ScrolledSelectionList(ss->minecraft, ss->width, ss->height, 32,
ss->height - 64, SLOT_STAT_HEIGHT) {
// 4J - added initialisers
parent = ss;
headerPressed = -1;
sortColumn = -1;
sortOrder = SORT_NONE;
setRenderSelection(false);
setRenderHeader(true, SLOT_STAT_HEIGHT);
}
void StatsScreen::StatisticsList::selectItem(int item, bool doubleClick)
{
void StatsScreen::StatisticsList::selectItem(int item, bool doubleClick) {}
bool StatsScreen::StatisticsList::isSelectedItem(int item) { return false; }
void StatsScreen::StatisticsList::renderBackground() {
parent->renderBackground(); // 4J - was
// StatsScreen.this.renderBackground();
}
bool StatsScreen::StatisticsList::isSelectedItem(int item)
{
return false;
void StatsScreen::StatisticsList::renderHeader(int x, int y, Tesselator* t) {
if (!Mouse::isButtonDown(0)) {
headerPressed = -1;
}
if (headerPressed == 0) {
parent->blitSlotIcon(x + ROW_COL_1 - SLOT_BG_SIZE, y + SLOT_BG_Y,
SLOT_BG_SIZE * 0, SLOT_BG_SIZE * 0);
} else {
parent->blitSlotIcon(x + ROW_COL_1 - SLOT_BG_SIZE, y + SLOT_BG_Y,
SLOT_BG_SIZE * 0, SLOT_BG_SIZE * 1);
}
if (headerPressed == 1) {
parent->blitSlotIcon(x + ROW_COL_2 - SLOT_BG_SIZE, y + SLOT_BG_Y,
SLOT_BG_SIZE * 0, SLOT_BG_SIZE * 0);
} else {
parent->blitSlotIcon(x + ROW_COL_2 - SLOT_BG_SIZE, y + SLOT_BG_Y,
SLOT_BG_SIZE * 0, SLOT_BG_SIZE * 1);
}
if (headerPressed == 2) {
parent->blitSlotIcon(x + ROW_COL_3 - SLOT_BG_SIZE, y + SLOT_BG_Y,
SLOT_BG_SIZE * 0, SLOT_BG_SIZE * 0);
} else {
parent->blitSlotIcon(x + ROW_COL_3 - SLOT_BG_SIZE, y + SLOT_BG_Y,
SLOT_BG_SIZE * 0, SLOT_BG_SIZE * 1);
}
if (sortColumn != -1) {
int offset = ROW_COL_1 - SLOT_BG_SIZE * 2;
int image = SLOT_BG_SIZE;
if (sortColumn == 1) {
offset = ROW_COL_2 - SLOT_BG_SIZE * 2;
} else if (sortColumn == 2) {
offset = ROW_COL_3 - SLOT_BG_SIZE * 2;
}
if (sortOrder == SORT_UP) {
image = SLOT_BG_SIZE * 2;
}
parent->blitSlotIcon(x + offset, y + SLOT_BG_Y, image,
SLOT_BG_SIZE * 0);
}
}
void StatsScreen::StatisticsList::renderBackground()
{
parent->renderBackground(); // 4J - was StatsScreen.this.renderBackground();
}
void StatsScreen::StatisticsList::renderHeader(int x, int y, Tesselator *t)
{
if (!Mouse::isButtonDown(0))
{
headerPressed = -1;
}
if (headerPressed == 0)
{
parent->blitSlotIcon(x + ROW_COL_1 - SLOT_BG_SIZE, y + SLOT_BG_Y, SLOT_BG_SIZE * 0, SLOT_BG_SIZE * 0);
}
else
{
parent->blitSlotIcon(x + ROW_COL_1 - SLOT_BG_SIZE, y + SLOT_BG_Y, SLOT_BG_SIZE * 0, SLOT_BG_SIZE * 1);
}
if (headerPressed == 1)
{
parent->blitSlotIcon(x + ROW_COL_2 - SLOT_BG_SIZE, y + SLOT_BG_Y, SLOT_BG_SIZE * 0, SLOT_BG_SIZE * 0);
}
else
{
parent->blitSlotIcon(x + ROW_COL_2 - SLOT_BG_SIZE, y + SLOT_BG_Y, SLOT_BG_SIZE * 0, SLOT_BG_SIZE * 1);
}
if (headerPressed == 2)
{
parent->blitSlotIcon(x + ROW_COL_3 - SLOT_BG_SIZE, y + SLOT_BG_Y, SLOT_BG_SIZE * 0, SLOT_BG_SIZE * 0);
}
else
{
parent->blitSlotIcon(x + ROW_COL_3 - SLOT_BG_SIZE, y + SLOT_BG_Y, SLOT_BG_SIZE * 0, SLOT_BG_SIZE * 1);
}
if (sortColumn != -1)
{
int offset = ROW_COL_1 - SLOT_BG_SIZE * 2;
int image = SLOT_BG_SIZE;
if (sortColumn == 1)
{
offset = ROW_COL_2 - SLOT_BG_SIZE * 2;
}
else if (sortColumn == 2)
{
offset = ROW_COL_3 - SLOT_BG_SIZE * 2;
}
if (sortOrder == SORT_UP)
{
image = SLOT_BG_SIZE * 2;
}
parent->blitSlotIcon(x + offset, y + SLOT_BG_Y, image, SLOT_BG_SIZE * 0);
}
}
void StatsScreen::StatisticsList::clickedHeader(int headerMouseX, int headerMouseY)
{
void StatsScreen::StatisticsList::clickedHeader(int headerMouseX,
int headerMouseY) {
headerPressed = -1;
if (headerMouseX >= (ROW_COL_1 - SLOT_BG_SIZE * 2) && headerMouseX < ROW_COL_1)
{
if (headerMouseX >= (ROW_COL_1 - SLOT_BG_SIZE * 2) &&
headerMouseX < ROW_COL_1) {
headerPressed = 0;
}
else if (headerMouseX >= (ROW_COL_2 - SLOT_BG_SIZE * 2) && headerMouseX < ROW_COL_2)
{
} else if (headerMouseX >= (ROW_COL_2 - SLOT_BG_SIZE * 2) &&
headerMouseX < ROW_COL_2) {
headerPressed = 1;
}
else if (headerMouseX >= (ROW_COL_3 - SLOT_BG_SIZE * 2) && headerMouseX < ROW_COL_3)
{
} else if (headerMouseX >= (ROW_COL_3 - SLOT_BG_SIZE * 2) &&
headerMouseX < ROW_COL_3) {
headerPressed = 2;
}
if (headerPressed >= 0)
{
if (headerPressed >= 0) {
sortByColumn(headerPressed);
parent->minecraft->soundEngine->playUI(eSoundType_RANDOM_CLICK, 1, 1);
}
}
int StatsScreen::StatisticsList::getNumberOfItems()
{
return (int)statItemList.size();
int StatsScreen::StatisticsList::getNumberOfItems() {
return (int)statItemList.size();
}
ItemStat *StatsScreen::StatisticsList::getSlotStat(int slot)
{
return statItemList.at(slot);
ItemStat* StatsScreen::StatisticsList::getSlotStat(int slot) {
return statItemList.at(slot);
}
void StatsScreen::StatisticsList::renderStat(ItemStat *stat, int x, int y, bool shaded)
{
if (stat != NULL)
{
void StatsScreen::StatisticsList::renderStat(ItemStat* stat, int x, int y,
bool shaded) {
if (stat != NULL) {
std::wstring msg = stat->format(parent->stats->getTotalValue(stat));
parent->drawString(parent->font, msg, x - parent->font->width(msg), y + SLOT_TEXT_OFFSET, shaded ? 0xffffff : 0x909090);
}
else
{
parent->drawString(parent->font, msg, x - parent->font->width(msg),
y + SLOT_TEXT_OFFSET, shaded ? 0xffffff : 0x909090);
} else {
std::wstring msg = L"-";
parent->drawString(parent->font, msg, x - parent->font->width(msg), y + SLOT_TEXT_OFFSET, shaded ? 0xffffff : 0x909090);
parent->drawString(parent->font, msg, x - parent->font->width(msg),
y + SLOT_TEXT_OFFSET, shaded ? 0xffffff : 0x909090);
}
}
void StatsScreen::StatisticsList::renderDecorations(int mouseX, int mouseY)
{
if (mouseY < y0 || mouseY > y1 )
{
void StatsScreen::StatisticsList::renderDecorations(int mouseX, int mouseY) {
if (mouseY < y0 || mouseY > y1) {
return;
}
int slot = getItemAtPosition(mouseX, mouseY);
int rowX = parent->width / 2 - 92 - 16;
if (slot >= 0)
{
if (mouseX < (rowX + SLOT_LEFT_INSERT) || mouseX > (rowX + SLOT_LEFT_INSERT + 20))
{
if (slot >= 0) {
if (mouseX < (rowX + SLOT_LEFT_INSERT) ||
mouseX > (rowX + SLOT_LEFT_INSERT + 20)) {
return;
}
ItemStat *stat = getSlotStat(slot);
ItemStat* stat = getSlotStat(slot);
renderMousehoverTooltip(stat, mouseX, mouseY);
}
else
{
} else {
std::wstring elementName;
if (mouseX >= (rowX + ROW_COL_1 - SLOT_BG_SIZE) && mouseX <= (rowX + ROW_COL_1))
{
if (mouseX >= (rowX + ROW_COL_1 - SLOT_BG_SIZE) &&
mouseX <= (rowX + ROW_COL_1)) {
elementName = getHeaderDescriptionId(0);
}
else if (mouseX >= (rowX + ROW_COL_2 - SLOT_BG_SIZE) && mouseX <= (rowX + ROW_COL_2))
{
} else if (mouseX >= (rowX + ROW_COL_2 - SLOT_BG_SIZE) &&
mouseX <= (rowX + ROW_COL_2)) {
elementName = getHeaderDescriptionId(1);
}
else if (mouseX >= (rowX + ROW_COL_3 - SLOT_BG_SIZE) && mouseX <= (rowX + ROW_COL_3))
{
} else if (mouseX >= (rowX + ROW_COL_3 - SLOT_BG_SIZE) &&
mouseX <= (rowX + ROW_COL_3)) {
elementName = getHeaderDescriptionId(2);
}
else
{
} else {
return;
}
elementName = trimString(L"" + Language::getInstance()->getElement(elementName));
elementName =
trimString(L"" + Language::getInstance()->getElement(elementName));
if (elementName.length() > 0)
{
if (elementName.length() > 0) {
int rx = mouseX + 12;
int ry = mouseY - 12;
int width = parent->font->width(elementName);
parent->fillGradient(rx - 3, ry - 3, rx + width + 3, ry + 8 + 3, 0xc0000000, 0xc0000000);
parent->fillGradient(rx - 3, ry - 3, rx + width + 3, ry + 8 + 3,
0xc0000000, 0xc0000000);
parent->font->drawShadow(elementName, rx, ry, 0xffffffff);
}
}
}
void StatsScreen::StatisticsList::renderMousehoverTooltip(ItemStat *stat, int x, int y)
{
// 4J Stu - Unused
void StatsScreen::StatisticsList::renderMousehoverTooltip(ItemStat* stat, int x,
int y) {
// 4J Stu - Unused
#if 0
if (stat == NULL)
{
@@ -394,277 +348,265 @@ void StatsScreen::StatisticsList::renderMousehoverTooltip(ItemStat *stat, int x,
#endif
}
void StatsScreen::StatisticsList::sortByColumn(int column)
{
if (column != sortColumn)
{
void StatsScreen::StatisticsList::sortByColumn(int column) {
if (column != sortColumn) {
sortColumn = column;
sortOrder = SORT_DOWN;
}
else if (sortOrder == SORT_DOWN)
{
} else if (sortOrder == SORT_DOWN) {
sortOrder = SORT_UP;
}
else
{
} else {
sortColumn = -1;
sortOrder = SORT_NONE;
}
// Collections.sort(statItemList, itemStatSorter); // 4J - TODO
// Collections.sort(statItemList, itemStatSorter); // 4J -
// TODO
}
StatsScreen::ItemStatisticsList::ItemStatisticsList(StatsScreen* ss)
: StatsScreen::StatisticsList(ss) {
// 4J Gordon: Removed, not used anyway
/*for(std::vector<ItemStat *>::iterator it = Stats::itemStats->begin(); it
!= Stats::itemStats->end(); it++ )
{
ItemStat *stat = *it;
StatsScreen::ItemStatisticsList::ItemStatisticsList(StatsScreen *ss) : StatsScreen::StatisticsList(ss)
{
//4J Gordon: Removed, not used anyway
/*for(std::vector<ItemStat *>::iterator it = Stats::itemStats->begin(); it != Stats::itemStats->end(); it++ )
{
ItemStat *stat = *it;
bool addToList = false;
int id = stat->getItemId();
bool addToList = false;
int id = stat->getItemId();
if (parent->stats->getTotalValue(stat) > 0)
{
addToList = true;
}
else if (Stats::itemBroke[id] != NULL &&
parent->stats->getTotalValue(Stats::itemBroke[id]) > 0)
{
addToList = true;
}
else if (Stats::itemCrafted[id] != NULL &&
parent->stats->getTotalValue(Stats::itemCrafted[id]) > 0)
{
addToList = true;
}
if (addToList)
{
statItemList.push_back(stat);
}
}*/
if (parent->stats->getTotalValue(stat) > 0)
{
addToList = true;
/* 4J - TODO
itemStatSorter = new Comparator<ItemStat>() {
public int compare(ItemStat o1, ItemStat o2) {
int id1 = o1.getItemId();
int id2 = o2.getItemId();
Stat stat1 = null;
Stat stat2 = null;
if (sortColumn == COLUMN_DEPLETED) {
stat1 = Stats.itemBroke[id1];
stat2 = Stats.itemBroke[id2];
} else if (sortColumn == COLUMN_CRAFTED) {
stat1 = Stats.itemCrafted[id1];
stat2 = Stats.itemCrafted[id2];
} else if (sortColumn == COLUMN_USED) {
stat1 = Stats.itemUsed[id1];
stat2 = Stats.itemUsed[id2];
}
else if (Stats::itemBroke[id] != NULL && parent->stats->getTotalValue(Stats::itemBroke[id]) > 0)
{
addToList = true;
}
else if (Stats::itemCrafted[id] != NULL && parent->stats->getTotalValue(Stats::itemCrafted[id]) > 0)
{
addToList = true;
}
if (addToList)
{
statItemList.push_back(stat);
}
}*/
/* 4J - TODO
itemStatSorter = new Comparator<ItemStat>() {
public int compare(ItemStat o1, ItemStat o2) {
int id1 = o1.getItemId();
int id2 = o2.getItemId();
Stat stat1 = null;
Stat stat2 = null;
if (sortColumn == COLUMN_DEPLETED) {
stat1 = Stats.itemBroke[id1];
stat2 = Stats.itemBroke[id2];
} else if (sortColumn == COLUMN_CRAFTED) {
stat1 = Stats.itemCrafted[id1];
stat2 = Stats.itemCrafted[id2];
} else if (sortColumn == COLUMN_USED) {
stat1 = Stats.itemUsed[id1];
stat2 = Stats.itemUsed[id2];
}
if (stat1 != null || stat2 != null) {
if (stat1 == null) {
return 1;
} else if (stat2 == null) {
return -1;
} else {
int value1 = stats.getValue(stat1);
int value2 = stats.getValue(stat2);
if (value1 != value2) {
return (value1 - value2) * sortOrder;
}
if (stat1 != null || stat2 != null) {
if (stat1 == null) {
return 1;
} else if (stat2 == null) {
return -1;
} else {
int value1 = stats.getValue(stat1);
int value2 = stats.getValue(stat2);
if (value1 != value2) {
return (value1 - value2) * sortOrder;
}
}
return id1 - id2;
}
};
*/
return id1 - id2;
}
};
*/
}
void StatsScreen::ItemStatisticsList::renderHeader(int x, int y, Tesselator *t)
{
void StatsScreen::ItemStatisticsList::renderHeader(int x, int y,
Tesselator* t) {
StatsScreen::StatisticsList::renderHeader(x, y, t);
if (headerPressed == 0)
{
parent->blitSlotIcon(x + ROW_COL_1 - SLOT_BG_SIZE + 1, y + SLOT_BG_Y + 1, SLOT_BG_SIZE * 4, SLOT_BG_SIZE * 1);
if (headerPressed == 0) {
parent->blitSlotIcon(x + ROW_COL_1 - SLOT_BG_SIZE + 1,
y + SLOT_BG_Y + 1, SLOT_BG_SIZE * 4,
SLOT_BG_SIZE * 1);
} else {
parent->blitSlotIcon(x + ROW_COL_1 - SLOT_BG_SIZE, y + SLOT_BG_Y,
SLOT_BG_SIZE * 4, SLOT_BG_SIZE * 1);
}
else
{
parent->blitSlotIcon(x + ROW_COL_1 - SLOT_BG_SIZE, y + SLOT_BG_Y, SLOT_BG_SIZE * 4, SLOT_BG_SIZE * 1);
if (headerPressed == 1) {
parent->blitSlotIcon(x + ROW_COL_2 - SLOT_BG_SIZE + 1,
y + SLOT_BG_Y + 1, SLOT_BG_SIZE * 1,
SLOT_BG_SIZE * 1);
} else {
parent->blitSlotIcon(x + ROW_COL_2 - SLOT_BG_SIZE, y + SLOT_BG_Y,
SLOT_BG_SIZE * 1, SLOT_BG_SIZE * 1);
}
if (headerPressed == 1)
{
parent->blitSlotIcon(x + ROW_COL_2 - SLOT_BG_SIZE + 1, y + SLOT_BG_Y + 1, SLOT_BG_SIZE * 1, SLOT_BG_SIZE * 1);
if (headerPressed == 2) {
parent->blitSlotIcon(x + ROW_COL_3 - SLOT_BG_SIZE + 1,
y + SLOT_BG_Y + 1, SLOT_BG_SIZE * 2,
SLOT_BG_SIZE * 1);
} else {
parent->blitSlotIcon(x + ROW_COL_3 - SLOT_BG_SIZE, y + SLOT_BG_Y,
SLOT_BG_SIZE * 2, SLOT_BG_SIZE * 1);
}
else
{
parent->blitSlotIcon(x + ROW_COL_2 - SLOT_BG_SIZE, y + SLOT_BG_Y, SLOT_BG_SIZE * 1, SLOT_BG_SIZE * 1);
}
if (headerPressed == 2)
{
parent->blitSlotIcon(x + ROW_COL_3 - SLOT_BG_SIZE + 1, y + SLOT_BG_Y + 1, SLOT_BG_SIZE * 2, SLOT_BG_SIZE * 1);
}
else
{
parent->blitSlotIcon(x + ROW_COL_3 - SLOT_BG_SIZE, y + SLOT_BG_Y, SLOT_BG_SIZE * 2, SLOT_BG_SIZE * 1);
}
}
void StatsScreen::ItemStatisticsList::renderItem(int i, int x, int y, int h, Tesselator *t)
{
//4J Gordon: Removed, not used anyway
void StatsScreen::ItemStatisticsList::renderItem(int i, int x, int y, int h,
Tesselator* t) {
// 4J Gordon: Removed, not used anyway
/*ItemStat *stat = getSlotStat(i);
int id = stat->getItemId();
parent->blitSlot(x + SLOT_LEFT_INSERT, y, id);
renderStat((ItemStat *) Stats::itemBroke[id], x + ROW_COL_1, y, i % 2 == 0);
renderStat((ItemStat *) Stats::itemCrafted[id], x + ROW_COL_2, y, i % 2 == 0);
renderStat((ItemStat *) stat, x + ROW_COL_3, y, i % 2 == 0);*/
renderStat((ItemStat *) Stats::itemCrafted[id], x + ROW_COL_2, y, i % 2 ==
0); renderStat((ItemStat *) stat, x + ROW_COL_3, y, i % 2 == 0);*/
}
std::wstring StatsScreen::ItemStatisticsList::getHeaderDescriptionId(int column)
{
if (column == COLUMN_CRAFTED)
{
return L"stat.crafted";
}
else if (column == COLUMN_USED)
{
return L"stat.used";
}
else
{
return L"stat.depleted";
}
std::wstring StatsScreen::ItemStatisticsList::getHeaderDescriptionId(
int column) {
if (column == COLUMN_CRAFTED) {
return L"stat.crafted";
} else if (column == COLUMN_USED) {
return L"stat.used";
} else {
return L"stat.depleted";
}
}
StatsScreen::BlockStatisticsList::BlockStatisticsList(StatsScreen *ss) : StatisticsList(ss)
{
//4J Gordon: Removed, not used anyway
/*for(std::vector<ItemStat *>::iterator it = Stats::blockStats->begin(); it != Stats::blockStats->end(); it++ )
{
ItemStat *stat = *it;
StatsScreen::BlockStatisticsList::BlockStatisticsList(StatsScreen* ss)
: StatisticsList(ss) {
// 4J Gordon: Removed, not used anyway
/*for(std::vector<ItemStat *>::iterator it = Stats::blockStats->begin(); it
!= Stats::blockStats->end(); it++ )
{
ItemStat *stat = *it;
bool addToList = false;
int id = stat->getItemId();
bool addToList = false;
int id = stat->getItemId();
if (parent->stats->getTotalValue(stat) > 0)
{
addToList = true;
}
else if (Stats::itemUsed[id] != NULL && parent->stats->getTotalValue(Stats::itemUsed[id]) > 0)
{
addToList = true;
}
else if (Stats::itemCrafted[id] != NULL && parent->stats->getTotalValue(Stats::itemCrafted[id]) > 0)
{
addToList = true;
}
if (addToList)
{
statItemList.push_back(stat);
}
}*/
if (parent->stats->getTotalValue(stat) > 0)
{
addToList = true;
}
else if (Stats::itemUsed[id] != NULL &&
parent->stats->getTotalValue(Stats::itemUsed[id]) > 0)
{
addToList = true;
}
else if (Stats::itemCrafted[id] != NULL &&
parent->stats->getTotalValue(Stats::itemCrafted[id]) > 0)
{
addToList = true;
}
if (addToList)
{
statItemList.push_back(stat);
}
}*/
/* 4J - TODO
itemStatSorter = new Comparator<ItemStat>() {
public int compare(ItemStat o1, ItemStat o2) {
int id1 = o1.getItemId();
int id2 = o2.getItemId();
/* 4J - TODO
itemStatSorter = new Comparator<ItemStat>() {
public int compare(ItemStat o1, ItemStat o2) {
int id1 = o1.getItemId();
int id2 = o2.getItemId();
Stat stat1 = null;
Stat stat2 = null;
if (sortColumn == COLUMN_MINED) {
stat1 = Stats.blockMined[id1];
stat2 = Stats.blockMined[id2];
} else if (sortColumn == COLUMN_CRAFTED) {
stat1 = Stats.itemCrafted[id1];
stat2 = Stats.itemCrafted[id2];
} else if (sortColumn == COLUMN_USED) {
stat1 = Stats.itemUsed[id1];
stat2 = Stats.itemUsed[id2];
}
Stat stat1 = null;
Stat stat2 = null;
if (sortColumn == COLUMN_MINED) {
stat1 = Stats.blockMined[id1];
stat2 = Stats.blockMined[id2];
} else if (sortColumn == COLUMN_CRAFTED) {
stat1 = Stats.itemCrafted[id1];
stat2 = Stats.itemCrafted[id2];
} else if (sortColumn == COLUMN_USED) {
stat1 = Stats.itemUsed[id1];
stat2 = Stats.itemUsed[id2];
}
if (stat1 != null || stat2 != null) {
if (stat1 == null) {
return 1;
} else if (stat2 == null) {
return -1;
} else {
int value1 = stats.getValue(stat1);
int value2 = stats.getValue(stat2);
if (value1 != value2) {
return (value1 - value2) * sortOrder;
}
if (stat1 != null || stat2 != null) {
if (stat1 == null) {
return 1;
} else if (stat2 == null) {
return -1;
} else {
int value1 = stats.getValue(stat1);
int value2 = stats.getValue(stat2);
if (value1 != value2) {
return (value1 - value2) * sortOrder;
}
}
return id1 - id2;
}
};
*/
return id1 - id2;
}
};
*/
}
void StatsScreen::BlockStatisticsList::renderHeader(int x, int y, Tesselator *t)
{
void StatsScreen::BlockStatisticsList::renderHeader(int x, int y,
Tesselator* t) {
StatisticsList::renderHeader(x, y, t);
if (headerPressed == 0)
{
parent->blitSlotIcon(x + ROW_COL_1 - SLOT_BG_SIZE + 1, y + SLOT_BG_Y + 1, SLOT_BG_SIZE * 1, SLOT_BG_SIZE * 1);
if (headerPressed == 0) {
parent->blitSlotIcon(x + ROW_COL_1 - SLOT_BG_SIZE + 1,
y + SLOT_BG_Y + 1, SLOT_BG_SIZE * 1,
SLOT_BG_SIZE * 1);
} else {
parent->blitSlotIcon(x + ROW_COL_1 - SLOT_BG_SIZE, y + SLOT_BG_Y,
SLOT_BG_SIZE * 1, SLOT_BG_SIZE * 1);
}
else
{
parent->blitSlotIcon(x + ROW_COL_1 - SLOT_BG_SIZE, y + SLOT_BG_Y, SLOT_BG_SIZE * 1, SLOT_BG_SIZE * 1);
if (headerPressed == 1) {
parent->blitSlotIcon(x + ROW_COL_2 - SLOT_BG_SIZE + 1,
y + SLOT_BG_Y + 1, SLOT_BG_SIZE * 2,
SLOT_BG_SIZE * 1);
} else {
parent->blitSlotIcon(x + ROW_COL_2 - SLOT_BG_SIZE, y + SLOT_BG_Y,
SLOT_BG_SIZE * 2, SLOT_BG_SIZE * 1);
}
if (headerPressed == 1)
{
parent->blitSlotIcon(x + ROW_COL_2 - SLOT_BG_SIZE + 1, y + SLOT_BG_Y + 1, SLOT_BG_SIZE * 2, SLOT_BG_SIZE * 1);
if (headerPressed == 2) {
parent->blitSlotIcon(x + ROW_COL_3 - SLOT_BG_SIZE + 1,
y + SLOT_BG_Y + 1, SLOT_BG_SIZE * 3,
SLOT_BG_SIZE * 1);
} else {
parent->blitSlotIcon(x + ROW_COL_3 - SLOT_BG_SIZE, y + SLOT_BG_Y,
SLOT_BG_SIZE * 3, SLOT_BG_SIZE * 1);
}
else
{
parent->blitSlotIcon(x + ROW_COL_2 - SLOT_BG_SIZE, y + SLOT_BG_Y, SLOT_BG_SIZE * 2, SLOT_BG_SIZE * 1);
}
if (headerPressed == 2)
{
parent->blitSlotIcon(x + ROW_COL_3 - SLOT_BG_SIZE + 1, y + SLOT_BG_Y + 1, SLOT_BG_SIZE * 3, SLOT_BG_SIZE * 1);
}
else
{
parent->blitSlotIcon(x + ROW_COL_3 - SLOT_BG_SIZE, y + SLOT_BG_Y, SLOT_BG_SIZE * 3, SLOT_BG_SIZE * 1);
}
}
void StatsScreen::BlockStatisticsList::renderItem(int i, int x, int y, int h, Tesselator *t)
{
//4J Gordon: Removed, not used anyway
void StatsScreen::BlockStatisticsList::renderItem(int i, int x, int y, int h,
Tesselator* t) {
// 4J Gordon: Removed, not used anyway
/*ItemStat *mineCount = getSlotStat(i);
int id = mineCount->getItemId();
parent->blitSlot(x + SLOT_LEFT_INSERT, y, id);
renderStat((ItemStat *) Stats::itemCrafted[id], x + ROW_COL_1, y, i % 2 == 0);
renderStat((ItemStat *) Stats::itemUsed[id], x + ROW_COL_2, y, i % 2 == 0);
renderStat((ItemStat *) mineCount, x + ROW_COL_3, y, i % 2 == 0);*/
renderStat((ItemStat *) Stats::itemCrafted[id], x + ROW_COL_1, y, i % 2 ==
0); renderStat((ItemStat *) Stats::itemUsed[id], x + ROW_COL_2, y, i % 2 ==
0); renderStat((ItemStat *) mineCount, x + ROW_COL_3, y, i % 2 == 0);*/
}
std::wstring StatsScreen::BlockStatisticsList::getHeaderDescriptionId(int column)
{
if (column == COLUMN_CRAFTED)
{
return L"stat.crafted";
}
else if (column == COLUMN_USED)
{
return L"stat.used";
}
else
{
return L"stat.mined";
}
std::wstring StatsScreen::BlockStatisticsList::getHeaderDescriptionId(
int column) {
if (column == COLUMN_CRAFTED) {
return L"stat.crafted";
} else if (column == COLUMN_USED) {
return L"stat.used";
} else {
return L"stat.mined";
}
}

View File

@@ -3,55 +3,59 @@
#include "../ScrolledSelectionList.h"
class ItemStat;
class StatsScreen : public Screen
{
class StatsScreen : public Screen {
private:
static ItemRenderer *itemRenderer;
static ItemRenderer* itemRenderer;
protected:
static const int BUTTON_CANCEL_ID = 0;
static const int BUTTON_CANCEL_ID = 0;
static const int BUTTON_STATS_ID = 1;
static const int BUTTON_BLOCKITEMSTATS_ID = 2;
static const int BUTTON_ITEMSTATS_ID = 3;
Screen *lastScreen;
Screen* lastScreen;
std::wstring title;
public:
class GeneralStatisticsList;
class ItemStatisticsList;
class BlockStatisticsList;
class GeneralStatisticsList;
class ItemStatisticsList;
class BlockStatisticsList;
private:
GeneralStatisticsList *statsList;
ItemStatisticsList *itemStatsList;
BlockStatisticsList *blockStatsList;
StatsCounter *stats;
GeneralStatisticsList* statsList;
ItemStatisticsList* itemStatsList;
BlockStatisticsList* blockStatsList;
StatsCounter* stats;
ScrolledSelectionList *activeList;
ScrolledSelectionList* activeList;
public:
StatsScreen(Screen *lastScreen, StatsCounter *stats);
StatsScreen(Screen* lastScreen, StatsCounter* stats);
virtual void init();
virtual void postInit();
protected:
virtual void buttonClicked(Button *button);
public:
virtual void render(int xm, int ym, float a);
class GeneralStatisticsList : public ScrolledSelectionList
{
protected:
StatsScreen *parent;
public:
GeneralStatisticsList(StatsScreen *ss); // 4J - added parameter so we can access parent
virtual int getNumberOfItems();
protected:
virtual void buttonClicked(Button* button);
public:
virtual void render(int xm, int ym, float a);
class GeneralStatisticsList : public ScrolledSelectionList {
protected:
StatsScreen* parent;
public:
GeneralStatisticsList(
StatsScreen* ss); // 4J - added parameter so we can access parent
virtual int getNumberOfItems();
virtual void selectItem(int item, bool doubleClick);
virtual bool isSelectedItem(int item);
virtual int getMaxPosition();
virtual void renderBackground();
virtual void renderItem(int i, int x, int y, int h, Tesselator *t);
virtual void renderItem(int i, int x, int y, int h, Tesselator* t);
};
private:
private:
static const float SLOT_TEX_SIZE;
static const int SLOT_BG_SIZE = 18;
static const int SLOT_STAT_HEIGHT = SLOT_BG_SIZE + 2;
@@ -72,62 +76,61 @@ private:
void blitSlotBg(int x, int y);
void blitSlotIcon(int x, int y, int sx, int sy);
class StatisticsList : public ScrolledSelectionList
{
public:
StatsScreen *parent;
protected:
int headerPressed;
std::vector<ItemStat *> statItemList;
// Comparator<ItemStat> itemStatSorter;
class StatisticsList : public ScrolledSelectionList {
public:
StatsScreen* parent;
protected:
int headerPressed;
std::vector<ItemStat*> statItemList;
// Comparator<ItemStat> itemStatSorter;
int sortColumn;
int sortOrder;
public:
StatisticsList(StatsScreen *ss); // 4J - added parameter so we can access parent
public:
StatisticsList(
StatsScreen* ss); // 4J - added parameter so we can access parent
virtual void selectItem(int item, bool doubleClick);
virtual bool isSelectedItem(int item);
virtual void renderBackground();
virtual void renderHeader(int x, int y, Tesselator *t);
virtual void renderHeader(int x, int y, Tesselator* t);
virtual void clickedHeader(int headerMouseX, int headerMouseY);
virtual int getNumberOfItems();
ItemStat *getSlotStat(int slot);
ItemStat* getSlotStat(int slot);
virtual std::wstring getHeaderDescriptionId(int column) = 0;
virtual void renderStat(ItemStat *stat, int x, int y, bool shaded);
virtual void renderStat(ItemStat* stat, int x, int y, bool shaded);
virtual void renderDecorations(int mouseX, int mouseY);
virtual void renderMousehoverTooltip(ItemStat *stat, int x, int y);
virtual void renderMousehoverTooltip(ItemStat* stat, int x, int y);
virtual void sortByColumn(int column);
};
public:
class ItemStatisticsList : public StatisticsList
{
private:
static const int COLUMN_DEPLETED = 0;
class ItemStatisticsList : public StatisticsList {
private:
static const int COLUMN_DEPLETED = 0;
static const int COLUMN_CRAFTED = 1;
static const int COLUMN_USED = 2;
public:
ItemStatisticsList(StatsScreen *ss); // 4J - added parameter so we can access parent
virtual void renderHeader(int x, int y, Tesselator *t);
virtual void renderItem(int i, int x, int y, int h, Tesselator *t);
public:
ItemStatisticsList(
StatsScreen* ss); // 4J - added parameter so we can access parent
virtual void renderHeader(int x, int y, Tesselator* t);
virtual void renderItem(int i, int x, int y, int h, Tesselator* t);
virtual std::wstring getHeaderDescriptionId(int column);
};
};
class BlockStatisticsList : public StatisticsList
{
private:
static const int COLUMN_CRAFTED = 0;
class BlockStatisticsList : public StatisticsList {
private:
static const int COLUMN_CRAFTED = 0;
static const int COLUMN_USED = 1;
static const int COLUMN_MINED = 2;
public:
BlockStatisticsList(StatsScreen *ss); // 4J - added parameter so we can access parent
virtual void renderHeader(int x, int y, Tesselator *t);
virtual void renderItem(int i, int x, int y, int h, Tesselator *t);
public:
BlockStatisticsList(
StatsScreen* ss); // 4J - added parameter so we can access parent
virtual void renderHeader(int x, int y, Tesselator* t);
virtual void renderItem(int i, int x, int y, int h, Tesselator* t);
virtual std::wstring getHeaderDescriptionId(int column);
};
};
};

View File

@@ -1,5 +1,5 @@
#include "../../Platform/stdafx.h"
#include "TextEditScreen.h"
#include "TextEditScreen.h"
#include "../Button.h"
#include "../../Rendering/EntityRenderers/TileEntityRenderDispatcher.h"
#include "../../Network/ClientConnection.h"
@@ -10,73 +10,62 @@
#include "../../../Minecraft.World/Headers/net.minecraft.world.level.h"
#include "../../../Minecraft.World/Headers/net.minecraft.world.level.tile.h"
const std::wstring TextEditScreen::allowedChars =
SharedConstants::readAcceptableChars();
const std::wstring TextEditScreen::allowedChars = SharedConstants::readAcceptableChars();
TextEditScreen::TextEditScreen(std::shared_ptr<SignTileEntity> sign) {
// 4J - added initialisers
line = 0;
frame = 0;
title = L"Edit sign message:";
TextEditScreen::TextEditScreen(std::shared_ptr<SignTileEntity> sign)
{
// 4J - added initialisers
line = 0;
frame = 0;
title = L"Edit sign message:";
this->sign = sign;
this->sign = sign;
}
void TextEditScreen::init()
{
void TextEditScreen::init() {
buttons.clear();
Keyboard::enableRepeatEvents(true);
buttons.push_back(new Button(0, width / 2 - 100, height / 4 + 24 * 5, L"Done"));
buttons.push_back(
new Button(0, width / 2 - 100, height / 4 + 24 * 5, L"Done"));
}
void TextEditScreen::removed()
{
void TextEditScreen::removed() {
Keyboard::enableRepeatEvents(false);
if (minecraft->level->isClientSide)
{
minecraft->getConnection(0)->send( std::shared_ptr<SignUpdatePacket>( new SignUpdatePacket(sign->x, sign->y, sign->z, sign->IsVerified(), sign->IsCensored(), sign->GetMessages()) ) );
if (minecraft->level->isClientSide) {
minecraft->getConnection(0)->send(std::shared_ptr<SignUpdatePacket>(
new SignUpdatePacket(sign->x, sign->y, sign->z, sign->IsVerified(),
sign->IsCensored(), sign->GetMessages())));
}
}
void TextEditScreen::tick()
{
frame++;
}
void TextEditScreen::tick() { frame++; }
void TextEditScreen::buttonClicked(Button *button)
{
void TextEditScreen::buttonClicked(Button* button) {
if (!button->active) return;
if (button->id == 0)
{
if (button->id == 0) {
sign->setChanged();
minecraft->setScreen(NULL);
}
}
void TextEditScreen::keyPressed(wchar_t ch, int eventKey)
{
void TextEditScreen::keyPressed(wchar_t ch, int eventKey) {
if (eventKey == Keyboard::KEY_UP) line = (line - 1) & 3;
if (eventKey == Keyboard::KEY_DOWN || eventKey == Keyboard::KEY_RETURN) line = (line + 1) & 3;
if (eventKey == Keyboard::KEY_DOWN || eventKey == Keyboard::KEY_RETURN)
line = (line + 1) & 3;
std::wstring temp=sign->GetMessage(line);
if (eventKey == Keyboard::KEY_BACK && temp.length() > 0)
{
std::wstring temp = sign->GetMessage(line);
if (eventKey == Keyboard::KEY_BACK && temp.length() > 0) {
temp = temp.substr(0, temp.length() - 1);
}
if (allowedChars.find(ch) != std::wstring::npos && temp.length() < 15)
{
if (allowedChars.find(ch) != std::wstring::npos && temp.length() < 15) {
temp += ch;
}
sign->SetMessage(line,temp);
sign->SetMessage(line, temp);
}
void TextEditScreen::render(int xm, int ym, float a)
{
void TextEditScreen::render(int xm, int ym, float a) {
renderBackground();
drawCenteredString(font, title, width / 2, 40, 0xffffff);
@@ -87,16 +76,13 @@ void TextEditScreen::render(int xm, int ym, float a)
glScalef(-ss, -ss, -ss);
glRotatef(180, 0, 1, 0);
Tile *tile = sign->getTile();
Tile* tile = sign->getTile();
if (tile == Tile::sign)
{
if (tile == Tile::sign) {
float rot = sign->getData() * 360 / 16.0f;
glRotatef(rot, 0, 1, 0);
glTranslatef(0, 5 / 16.0f, 0);
}
else
{
} else {
int face = sign->getData();
float rot = 0;
@@ -109,11 +95,11 @@ void TextEditScreen::render(int xm, int ym, float a)
if (frame / 6 % 2 == 0) sign->SetSelectedLine(line);
TileEntityRenderDispatcher::instance->render(sign, 0 - 0.5f, -0.75f, 0 - 0.5f, 0);
TileEntityRenderDispatcher::instance->render(sign, 0 - 0.5f, -0.75f,
0 - 0.5f, 0);
sign->SetSelectedLine(-1);
glPopMatrix();
Screen::render(xm, ym, a);
}

View File

@@ -2,27 +2,30 @@
#include "../Screen.h"
class SignTileEntity;
class TextEditScreen : public Screen
{
class TextEditScreen : public Screen {
protected:
std::wstring title;
std::wstring title;
private:
std::shared_ptr<SignTileEntity> sign;
std::shared_ptr<SignTileEntity> sign;
int frame;
int line;
public:
TextEditScreen(std::shared_ptr<SignTileEntity> sign);
TextEditScreen(std::shared_ptr<SignTileEntity> sign);
virtual void init();
virtual void removed();
virtual void tick();
protected:
virtual void buttonClicked(Button *button);
virtual void buttonClicked(Button* button);
private:
static const std::wstring allowedChars;
static const std::wstring allowedChars;
protected:
virtual void keyPressed(wchar_t ch, int eventKey);
virtual void keyPressed(wchar_t ch, int eventKey);
public:
virtual void render(int xm, int ym, float a);
virtual void render(int xm, int ym, float a);
};

View File

@@ -12,119 +12,114 @@
#include "../../../Minecraft.World/Util/Random.h"
#include "TitleScreen.h"
Random *TitleScreen::random = new Random();
Random* TitleScreen::random = new Random();
TitleScreen::TitleScreen()
{
// 4J - added initialisers
vo = 0;
multiplayerButton = NULL;
TitleScreen::TitleScreen() {
// 4J - added initialisers
vo = 0;
multiplayerButton = NULL;
splash = L"missingno";
// try { // 4J - removed try/catch
// try { // 4J - removed try/catch
std::vector<std::wstring> splashes;
/*
BufferedReader *br = new BufferedReader(new InputStreamReader(InputStream::getResourceAsStream(L"res\\title\\splashes.txt"))); //, Charset.forName("UTF-8")
std::wstring line = L"";
while ( !(line = br->readLine()).empty() )
{
line = trimString( line );
if (line.length() > 0)
{
splashes.push_back(line);
}
/*
BufferedReader *br = new BufferedReader(new
InputStreamReader(InputStream::getResourceAsStream(L"res\\title\\splashes.txt")));
//, Charset.forName("UTF-8")
std::wstring line = L"";
while ( !(line = br->readLine()).empty() )
{
line = trimString( line );
if (line.length() > 0)
{
splashes.push_back(line);
}
br->close();
delete br;
*/
splash = L""; //splashes.at(random->nextInt(splashes.size()));
// } catch (Exception e) {
// }
}
void TitleScreen::tick()
{
//vo += 1.0f;
//if( vo > 100.0f ) minecraft->setScreen(new SelectWorldScreen(this)); // 4J - temp testing
br->close();
delete br;
*/
splash = L""; // splashes.at(random->nextInt(splashes.size()));
// } catch (Exception e) {
// }
}
void TitleScreen::keyPressed(wchar_t eventCharacter, int eventKey)
{
void TitleScreen::tick() {
// vo += 1.0f;
// if( vo > 100.0f ) minecraft->setScreen(new SelectWorldScreen(this));
// // 4J - temp testing
}
void TitleScreen::init()
{
/* 4J - removed
Calendar c = Calendar.getInstance();
c.setTime(new Date());
void TitleScreen::keyPressed(wchar_t eventCharacter, int eventKey) {}
if (c.get(Calendar.MONTH) + 1 == 11 && c.get(Calendar.DAY_OF_MONTH) == 9) {
splash = "Happy birthday, ez!";
} else if (c.get(Calendar.MONTH) + 1 == 6 && c.get(Calendar.DAY_OF_MONTH) == 1) {
splash = "Happy birthday, Notch!";
} else if (c.get(Calendar.MONTH) + 1 == 12 && c.get(Calendar.DAY_OF_MONTH) == 24) {
splash = "Merry X-mas!";
} else if (c.get(Calendar.MONTH) + 1 == 1 && c.get(Calendar.DAY_OF_MONTH) == 1) {
splash = "Happy new year!";
}
*/
void TitleScreen::init() {
/* 4J - removed
Calendar c = Calendar.getInstance();
c.setTime(new Date());
Language *language = Language::getInstance();
if (c.get(Calendar.MONTH) + 1 == 11 && c.get(Calendar.DAY_OF_MONTH) == 9) {
splash = "Happy birthday, ez!";
} else if (c.get(Calendar.MONTH) + 1 == 6 && c.get(Calendar.DAY_OF_MONTH) == 1)
{ splash = "Happy birthday, Notch!"; } else if (c.get(Calendar.MONTH) + 1 == 12
&& c.get(Calendar.DAY_OF_MONTH) == 24) { splash = "Merry X-mas!"; } else if
(c.get(Calendar.MONTH) + 1 == 1 && c.get(Calendar.DAY_OF_MONTH) == 1) { splash =
"Happy new year!";
}
*/
Language* language = Language::getInstance();
const int spacing = 24;
const int topPos = height / 4 + spacing * 2;
buttons.push_back(new Button(1, width / 2 - 100, topPos, language->getElement(L"menu.singleplayer")));
buttons.push_back(multiplayerButton = new Button(2, width / 2 - 100, topPos + spacing * 1, language->getElement(L"menu.multiplayer")));
buttons.push_back(new Button(3, width / 2 - 100, topPos + spacing * 2, language->getElement(L"menu.mods")));
buttons.push_back(new Button(1, width / 2 - 100, topPos,
language->getElement(L"menu.singleplayer")));
buttons.push_back(multiplayerButton = new Button(
2, width / 2 - 100, topPos + spacing * 1,
language->getElement(L"menu.multiplayer")));
buttons.push_back(new Button(3, width / 2 - 100, topPos + spacing * 2,
language->getElement(L"menu.mods")));
if (minecraft->appletMode)
{
buttons.push_back(new Button(0, width / 2 - 100, topPos + spacing * 3, language->getElement(L"menu.options")));
}
else
{
buttons.push_back(new Button(0, width / 2 - 100, topPos + spacing * 3 + 12, 98, 20, language->getElement(L"menu.options")));
buttons.push_back(new Button(4, width / 2 + 2, topPos + spacing * 3 + 12, 98, 20, language->getElement(L"menu.quit")));
if (minecraft->appletMode) {
buttons.push_back(new Button(0, width / 2 - 100, topPos + spacing * 3,
language->getElement(L"menu.options")));
} else {
buttons.push_back(new Button(0, width / 2 - 100,
topPos + spacing * 3 + 12, 98, 20,
language->getElement(L"menu.options")));
buttons.push_back(new Button(4, width / 2 + 2,
topPos + spacing * 3 + 12, 98, 20,
language->getElement(L"menu.quit")));
}
if (minecraft->user == NULL)
{
if (minecraft->user == NULL) {
multiplayerButton->active = false;
}
}
void TitleScreen::buttonClicked(Button *button)
{
if (button->id == 0)
{
void TitleScreen::buttonClicked(Button* button) {
if (button->id == 0) {
minecraft->setScreen(new OptionsScreen(this, minecraft->options));
}
if (button->id == 1)
{
if (button->id == 1) {
minecraft->setScreen(new SelectWorldScreen(this));
}
if (button->id == 2)
{
if (button->id == 2) {
minecraft->setScreen(new JoinMultiplayerScreen(this));
}
if (button->id == 3)
{
// minecraft->setScreen(new TexturePackSelectScreen(this)); // 4J - TODO put back in
if (button->id == 3) {
// minecraft->setScreen(new TexturePackSelectScreen(this));
// // 4J - TODO put back in
}
if (button->id == 4)
{
if (button->id == 4) {
minecraft->stop();
}
}
void TitleScreen::render(int xm, int ym, float a)
{
void TitleScreen::render(int xm, int ym, float a) {
// 4J Unused - Iggy Flash UI renders the title screen on consoles
}

View File

@@ -3,26 +3,28 @@
class Random;
class Button;
class TitleScreen : public Screen
{
class TitleScreen : public Screen {
private:
static Random *random;
static Random* random;
float vo;
std::wstring splash;
Button *multiplayerButton;
Button* multiplayerButton;
public:
TitleScreen();
TitleScreen();
virtual void tick();
protected:
virtual void keyPressed(wchar_t eventCharacter, int eventKey);
virtual void keyPressed(wchar_t eventCharacter, int eventKey);
public:
virtual void init();
virtual void init();
protected:
virtual void buttonClicked(Button *button);
virtual void buttonClicked(Button* button);
public:
virtual void render(int xm, int ym, float a);
virtual void render(int xm, int ym, float a);
};

View File

@@ -6,20 +6,17 @@
#include "../../../Minecraft.World/Blocks/TileEntities/DispenserTileEntity.h"
#include "../../../Minecraft.World/Headers/net.minecraft.world.h"
TrapScreen::TrapScreen(std::shared_ptr<Inventory> inventory, std::shared_ptr<DispenserTileEntity> trap) : AbstractContainerScreen(new TrapMenu(inventory, trap))
{
TrapScreen::TrapScreen(std::shared_ptr<Inventory> inventory,
std::shared_ptr<DispenserTileEntity> trap)
: AbstractContainerScreen(new TrapMenu(inventory, trap)) {}
}
void TrapScreen::renderLabels()
{
void TrapScreen::renderLabels() {
font->draw(L"Dispenser", 16 + 4 + 40, 2 + 2 + 2, 0x404040);
font->draw(L"Inventory", 8, imageHeight - 96 + 2, 0x404040);
}
void TrapScreen::renderBg(float a)
{
// 4J Unused
void TrapScreen::renderBg(float a) {
// 4J Unused
#if 0
int tex = minecraft->textures->loadTexture(L"/gui/trap.png");
glColor4f(1, 1, 1, 1);

View File

@@ -3,11 +3,12 @@
class DispenserTileEntity;
class Inventory;
class TrapScreen : public AbstractContainerScreen
{
class TrapScreen : public AbstractContainerScreen {
public:
TrapScreen(std::shared_ptr<Inventory> inventory, std::shared_ptr<DispenserTileEntity> trap);
TrapScreen(std::shared_ptr<Inventory> inventory,
std::shared_ptr<DispenserTileEntity> trap);
protected:
virtual void renderLabels();
virtual void renderLabels();
virtual void renderBg(float a);
};

View File

@@ -6,65 +6,66 @@
#include "ControlsScreen.h"
#include "../../../Minecraft.World/Headers/net.minecraft.locale.h"
VideoSettingsScreen::VideoSettingsScreen(Screen *lastScreen, Options *options)
{
this->title = L"Video Settings"; // 4J - added
VideoSettingsScreen::VideoSettingsScreen(Screen* lastScreen, Options* options) {
this->title = L"Video Settings"; // 4J - added
this->lastScreen = lastScreen;
this->options = options;
}
void VideoSettingsScreen::init()
{
Language *language = Language::getInstance();
void VideoSettingsScreen::init() {
Language* language = Language::getInstance();
this->title = language->getElement(L"options.videoTitle");
// 4J - this was as static array but moving it into the function to remove any issues with static initialisation order
const Options::Option *items[8] = {
Options::Option::GRAPHICS, Options::Option::RENDER_DISTANCE, Options::Option::AMBIENT_OCCLUSION, Options::Option::FRAMERATE_LIMIT, Options::Option::ANAGLYPH, Options::Option::VIEW_BOBBING,
Options::Option::GUI_SCALE, Options::Option::ADVANCED_OPENGL
};
// 4J - this was as static array but moving it into the function to remove
// any issues with static initialisation order
const Options::Option* items[8] = {
Options::Option::GRAPHICS, Options::Option::RENDER_DISTANCE,
Options::Option::AMBIENT_OCCLUSION, Options::Option::FRAMERATE_LIMIT,
Options::Option::ANAGLYPH, Options::Option::VIEW_BOBBING,
Options::Option::GUI_SCALE, Options::Option::ADVANCED_OPENGL};
for (int position = 0; position < 8; position++)
{
const Options::Option *item = items[position];
if (!item->isProgress())
{
buttons.push_back(new SmallButton(item->getId(), width / 2 - 155 + position % 2 * 160, height / 6 + 24 * (position >> 1), item, options->getMessage(item)));
}
else
{
buttons.push_back(new SlideButton(item->getId(), width / 2 - 155 + position % 2 * 160, height / 6 + 24 * (position >> 1), item, options->getMessage(item), options->getProgressValue(item)));
for (int position = 0; position < 8; position++) {
const Options::Option* item = items[position];
if (!item->isProgress()) {
buttons.push_back(new SmallButton(
item->getId(), width / 2 - 155 + position % 2 * 160,
height / 6 + 24 * (position >> 1), item,
options->getMessage(item)));
} else {
buttons.push_back(new SlideButton(
item->getId(), width / 2 - 155 + position % 2 * 160,
height / 6 + 24 * (position >> 1), item,
options->getMessage(item), options->getProgressValue(item)));
}
}
// buttons.add(new Button(VIDEO_BUTTON_ID, width / 2 - 100, height / 6 + 24 * 4 + 12, language.getElement("options.video")));
// buttons.add(new Button(CONTROLS_BUTTON_ID, width / 2 - 100, height / 6 + 24 * 5 + 12, language.getElement("options.controls")));
buttons.push_back(new Button(200, width / 2 - 100, height / 6 + 24 * 7, language->getElement(L"gui.done")));
// buttons.add(new Button(VIDEO_BUTTON_ID, width / 2 - 100, height /
// 6 + 24 * 4 + 12, language.getElement("options.video")));
// buttons.add(new Button(CONTROLS_BUTTON_ID, width / 2 - 100, height
// / 6 + 24 * 5 + 12, language.getElement("options.controls")));
buttons.push_back(new Button(200, width / 2 - 100, height / 6 + 24 * 7,
language->getElement(L"gui.done")));
}
void VideoSettingsScreen::buttonClicked(Button *button)
{
void VideoSettingsScreen::buttonClicked(Button* button) {
if (!button->active) return;
if (button->id < 100 && (dynamic_cast<SmallButton *>(button) != NULL))
{
options->toggle(((SmallButton *) button)->getOption(), 1);
if (button->id < 100 && (dynamic_cast<SmallButton*>(button) != NULL)) {
options->toggle(((SmallButton*)button)->getOption(), 1);
button->msg = options->getMessage(Options::Option::getItem(button->id));
}
if (button->id == 200)
{
if (button->id == 200) {
minecraft->options->save();
minecraft->setScreen(lastScreen);
}
ScreenSizeCalculator ssc(minecraft->options, minecraft->width, minecraft->height);
ScreenSizeCalculator ssc(minecraft->options, minecraft->width,
minecraft->height);
int screenWidth = ssc.getWidth();
int screenHeight = ssc.getHeight();
Screen::init(minecraft, screenWidth, screenHeight); // 4J - was this.init
Screen::init(minecraft, screenWidth, screenHeight); // 4J - was this.init
}
void VideoSettingsScreen::render(int xm, int ym, float a)
{
void VideoSettingsScreen::render(int xm, int ym, float a) {
renderBackground();
drawCenteredString(font, title, width / 2, 20, 0xffffff);
Screen::render(xm, ym, a);

View File

@@ -2,21 +2,23 @@
#include "../Screen.h"
class Options;
class VideoSettingsScreen : public Screen {
private:
Screen* lastScreen;
class VideoSettingsScreen : public Screen
{
private:
Screen *lastScreen;
protected:
std::wstring title;
std::wstring title;
private:
Options *options;
Options* options;
public:
VideoSettingsScreen(Screen *lastScreen, Options *options);
VideoSettingsScreen(Screen* lastScreen, Options* options);
virtual void init();
protected:
virtual void buttonClicked(Button *button);
virtual void buttonClicked(Button* button);
public:
virtual void render(int xm, int ym, float a);
virtual void render(int xm, int ym, float a);
};

View File

@@ -5,20 +5,20 @@
#include "../Textures/Textures.h"
#include "../../Minecraft.World/Platform/System.h"
ScrolledSelectionList::ScrolledSelectionList(Minecraft *minecraft, int width, int height, int y0, int y1, int itemHeight)
{
this->minecraft = minecraft;
this->width = width;
this->height = height;
this->y0 = y0;
this->y1 = y1;
this->itemHeight = itemHeight;
this->x0 = 0;
this->x1 = width;
ScrolledSelectionList::ScrolledSelectionList(Minecraft* minecraft, int width,
int height, int y0, int y1,
int itemHeight) {
this->minecraft = minecraft;
this->width = width;
this->height = height;
this->y0 = y0;
this->y1 = y1;
this->itemHeight = itemHeight;
this->x0 = 0;
this->x1 = width;
// 4J Stu - Smoe default initialisers
upId = 0;
// 4J Stu - Smoe default initialisers
upId = 0;
downId = 0;
yDrag = 0.0f;
@@ -31,90 +31,75 @@ ScrolledSelectionList::ScrolledSelectionList(Minecraft *minecraft, int width, in
renderSelection = false;
_renderHeader = false;
headerHeight = 0;
//End
// End
}
void ScrolledSelectionList::setRenderSelection(bool renderSelection)
{
this->renderSelection = renderSelection;
void ScrolledSelectionList::setRenderSelection(bool renderSelection) {
this->renderSelection = renderSelection;
}
void ScrolledSelectionList::setRenderHeader(bool renderHeader, int headerHeight)
{
void ScrolledSelectionList::setRenderHeader(bool renderHeader,
int headerHeight) {
this->_renderHeader = renderHeader;
this->headerHeight = headerHeight;
if (!_renderHeader)
{
if (!_renderHeader) {
this->headerHeight = 0;
}
}
int ScrolledSelectionList::getMaxPosition()
{
return getNumberOfItems() * itemHeight + headerHeight;
int ScrolledSelectionList::getMaxPosition() {
return getNumberOfItems() * itemHeight + headerHeight;
}
void ScrolledSelectionList::renderHeader(int x, int y, Tesselator *t)
{
}
void ScrolledSelectionList::renderHeader(int x, int y, Tesselator* t) {}
void ScrolledSelectionList::clickedHeader(int headerMouseX, int headerMouseY)
{
}
void ScrolledSelectionList::clickedHeader(int headerMouseX, int headerMouseY) {}
void ScrolledSelectionList::renderDecorations(int mouseX, int mouseY)
{
}
void ScrolledSelectionList::renderDecorations(int mouseX, int mouseY) {}
int ScrolledSelectionList::getItemAtPosition(int x, int y)
{
int ScrolledSelectionList::getItemAtPosition(int x, int y) {
int x0 = width / 2 - (92 + 16 + 2);
int x1 = width / 2 + (92 + 16 + 2);
int clickSlotPos = (y - y0 - headerHeight + (int) yo - 4);
int clickSlotPos = (y - y0 - headerHeight + (int)yo - 4);
int slot = clickSlotPos / itemHeight;
if (x >= x0 && x <= x1 && slot >= 0 && clickSlotPos >= 0 && slot < getNumberOfItems())
{
if (x >= x0 && x <= x1 && slot >= 0 && clickSlotPos >= 0 &&
slot < getNumberOfItems()) {
return slot;
}
return -1;
}
void ScrolledSelectionList::init(std::vector<Button *> *buttons, int upButtonId, int downButtonId)
{
void ScrolledSelectionList::init(std::vector<Button*>* buttons, int upButtonId,
int downButtonId) {
this->upId = upButtonId;
this->downId = downButtonId;
}
void ScrolledSelectionList::capYPosition()
{
void ScrolledSelectionList::capYPosition() {
int max = getMaxPosition() - (y1 - y0 - 4);
if (max < 0) max /= 2;
if (yo < 0) yo = 0;
if (yo > max) yo = (float)max;
}
void ScrolledSelectionList::buttonClicked(Button *button)
{
void ScrolledSelectionList::buttonClicked(Button* button) {
if (!button->active) return;
if (button->id == upId)
{
if (button->id == upId) {
yo -= (itemHeight * 2) / 3;
yDrag = DRAG_OUTSIDE;
capYPosition();
} else if (button->id == downId)
{
} else if (button->id == downId) {
yo += (itemHeight * 2) / 3;
yDrag = DRAG_OUTSIDE;
capYPosition();
}
}
void ScrolledSelectionList::render(int xm, int ym, float a)
{
// 4J Unused
void ScrolledSelectionList::render(int xm, int ym, float a) {
// 4J Unused
#if 0
renderBackground();
@@ -338,9 +323,9 @@ void ScrolledSelectionList::render(int xm, int ym, float a)
#endif
}
void ScrolledSelectionList::renderHoleBackground(int y0, int y1, int a0, int a1)
{
// 4J Unused
void ScrolledSelectionList::renderHoleBackground(int y0, int y1, int a0,
int a1) {
// 4J Unused
#if 0
Tesselator *t = Tesselator::getInstance();
glBindTexture(GL_TEXTURE_2D, minecraft->textures->loadTexture(L"/gui/background.png"));

View File

@@ -2,25 +2,28 @@
class Button;
class Tesselator;
class ScrolledSelectionList
{
class ScrolledSelectionList {
private:
static const int NO_DRAG = -1;
static const int NO_DRAG = -1;
static const int DRAG_OUTSIDE = -2;
Minecraft *minecraft;
Minecraft* minecraft;
int width;
int height;
protected:
int y0;
int y0;
int y1;
private:
int x1;
int x1;
int x0;
protected:
int itemHeight;
int itemHeight;
private:
int upId;
int upId;
int downId;
float yDrag;
@@ -28,35 +31,40 @@ private:
float yo;
int lastSelection;
__int64 lastSelectionTime ;
__int64 lastSelectionTime;
bool renderSelection;
bool _renderHeader;
int headerHeight;
public:
ScrolledSelectionList(Minecraft *minecraft, int width, int height, int y0, int y1, int itemHeight);
ScrolledSelectionList(Minecraft* minecraft, int width, int height, int y0,
int y1, int itemHeight);
void setRenderSelection(bool renderSelection);
protected:
void setRenderHeader(bool renderHeader, int headerHeight);
virtual int getNumberOfItems() = 0;
void setRenderHeader(bool renderHeader, int headerHeight);
virtual int getNumberOfItems() = 0;
virtual void selectItem(int item, bool doubleClick) = 0;
virtual bool isSelectedItem(int item) = 0;
virtual int getMaxPosition();
virtual void renderBackground() = 0;
virtual void renderItem(int i, int x, int y, int h, Tesselator *t) = 0;
void renderHeader(int x, int y, Tesselator *t);
virtual void renderItem(int i, int x, int y, int h, Tesselator* t) = 0;
void renderHeader(int x, int y, Tesselator* t);
void clickedHeader(int headerMouseX, int headerMouseY);
void renderDecorations(int mouseX, int mouseY);
public:
int getItemAtPosition(int x, int y);
void init(std::vector<Button *> *buttons, int upButtonId, int downButtonId);
int getItemAtPosition(int x, int y);
void init(std::vector<Button*>* buttons, int upButtonId, int downButtonId);
private:
void capYPosition();
void capYPosition();
public:
void buttonClicked(Button *button);
void buttonClicked(Button* button);
void render(int xm, int ym, float a);
private:
void renderHoleBackground(int y0, int y1, int a0, int a1);
void renderHoleBackground(int y0, int y1, int a0, int a1);
};

View File

@@ -1,10 +1,11 @@
#include "../Platform/stdafx.h"
#include "SimpleIcon.h"
SimpleIcon::SimpleIcon(const std::wstring &name, float U0, float V0, float U1, float V1) : StitchedTexture(name)
{
u0 = U0;
u1 = U1;
v0 = V0;
v1 = V1;
SimpleIcon::SimpleIcon(const std::wstring& name, float U0, float V0, float U1,
float V1)
: StitchedTexture(name) {
u0 = U0;
u1 = U1;
v0 = V0;
v1 = V1;
}

View File

@@ -1,11 +1,11 @@
#pragma once
#include "../Textures/Stitching/StitchedTexture.h"
// 4J Added this class to store the uv data that we have pre-calculated and loaded from a file
class SimpleIcon : public StitchedTexture
{
// 4J Added this class to store the uv data that we have pre-calculated and
// loaded from a file
class SimpleIcon : public StitchedTexture {
public:
SimpleIcon(const std::wstring &name, float u0, float v0, float u1, float v1);
SimpleIcon(const std::wstring& name, float u0, float v0, float u1,
float v1);
};

View File

@@ -1,39 +1,33 @@
#include "../Platform/stdafx.h"
#include "SlideButton.h"
SlideButton::SlideButton(int id, int x, int y, const Options::Option *option, const std::wstring& msg, float value) : Button(id, x, y, 150, 20, msg)
{
this->sliding = false; //4J added
this->option = option;
this->value = value;
SlideButton::SlideButton(int id, int x, int y, const Options::Option* option,
const std::wstring& msg, float value)
: Button(id, x, y, 150, 20, msg) {
this->sliding = false; // 4J added
this->option = option;
this->value = value;
}
int SlideButton::getYImage(bool hovered)
{
return 0;
}
int SlideButton::getYImage(bool hovered) { return 0; }
void SlideButton::renderBg(Minecraft *minecraft, int xm, int ym)
{
void SlideButton::renderBg(Minecraft* minecraft, int xm, int ym) {
if (!visible) return;
if (sliding)
{
value = (xm - (x + 4)) / (float) (w - 8);
if (sliding) {
value = (xm - (x + 4)) / (float)(w - 8);
if (value < 0) value = 0;
if (value > 1) value = 1;
minecraft->options->set(option, value);
msg = minecraft->options->getMessage(option);
}
glColor4f(1, 1, 1, 1);
blit(x + (int) (value * (w - 8)), y, 0, 46 + 1 * 20, 4, 20);
blit(x + (int) (value * (w - 8)) + 4, y, 196, 46 + 1 * 20, 4, 20);
blit(x + (int)(value * (w - 8)), y, 0, 46 + 1 * 20, 4, 20);
blit(x + (int)(value * (w - 8)) + 4, y, 196, 46 + 1 * 20, 4, 20);
}
bool SlideButton::clicked(Minecraft *minecraft, int mx, int my)
{
if (Button::clicked(minecraft, mx, my))
{
value = (mx - (x + 4)) / (float) (w - 8);
bool SlideButton::clicked(Minecraft* minecraft, int mx, int my) {
if (Button::clicked(minecraft, mx, my)) {
value = (mx - (x + 4)) / (float)(w - 8);
if (value < 0) value = 0;
if (value > 1) value = 1;
minecraft->options->set(option, value);
@@ -45,7 +39,4 @@ bool SlideButton::clicked(Minecraft *minecraft, int mx, int my)
return false;
}
void SlideButton::released(int mx, int my)
{
sliding = false;
}
void SlideButton::released(int mx, int my) { sliding = false; }

View File

@@ -3,20 +3,23 @@
#include "../GameState/Options.h"
class Minecraft;
class SlideButton : public Button
{
class SlideButton : public Button {
public:
float value;
float value;
bool sliding;
private:
const Options::Option *option;
const Options::Option* option;
public:
SlideButton(int id, int x, int y, const Options::Option *option, const std::wstring& msg, float value);
SlideButton(int id, int x, int y, const Options::Option* option,
const std::wstring& msg, float value);
protected:
virtual int getYImage(bool hovered);
virtual void renderBg(Minecraft *minecraft, int xm, int ym);
virtual int getYImage(bool hovered);
virtual void renderBg(Minecraft* minecraft, int xm, int ym);
public:
virtual bool clicked(Minecraft *minecraft, int mx, int my);
virtual bool clicked(Minecraft* minecraft, int mx, int my);
virtual void released(int mx, int my);
};

View File

@@ -1,22 +1,21 @@
#include "../Platform/stdafx.h"
#include "SmallButton.h"
SmallButton::SmallButton(int id, int x, int y, const std::wstring& msg) : Button(id, x, y, 150, 20, msg)
{
this->option = NULL;
SmallButton::SmallButton(int id, int x, int y, const std::wstring& msg)
: Button(id, x, y, 150, 20, msg) {
this->option = NULL;
}
SmallButton::SmallButton(int id, int x, int y, int width, int height, const std::wstring& msg) : Button(id, x, y, width, height, msg)
{
this->option = NULL;
SmallButton::SmallButton(int id, int x, int y, int width, int height,
const std::wstring& msg)
: Button(id, x, y, width, height, msg) {
this->option = NULL;
}
SmallButton::SmallButton(int id, int x, int y, const Options::Option *item, const std::wstring& msg) : Button(id, x, y, 150, 20, msg)
{
this->option = item;
SmallButton::SmallButton(int id, int x, int y, const Options::Option* item,
const std::wstring& msg)
: Button(id, x, y, 150, 20, msg) {
this->option = item;
}
const Options::Option *SmallButton::getOption()
{
return option;
}
const Options::Option* SmallButton::getOption() { return option; }

View File

@@ -2,14 +2,15 @@
#include "Button.h"
#include "../GameState/Options.h"
class SmallButton : public Button
{
class SmallButton : public Button {
private:
const Options::Option *option;
const Options::Option* option;
public:
SmallButton(int id, int x, int y, const std::wstring& msg);
SmallButton(int id, int x, int y, int width, int height, const std::wstring& msg);
SmallButton(int id, int x, int y, const Options::Option *item, const std::wstring& msg);
const Options::Option *getOption();
SmallButton(int id, int x, int y, const std::wstring& msg);
SmallButton(int id, int x, int y, int width, int height,
const std::wstring& msg);
SmallButton(int id, int x, int y, const Options::Option* item,
const std::wstring& msg);
const Options::Option* getOption();
};