.h -> .hpp everything
This commit is contained in:
@@ -1,372 +1,372 @@
|
||||
#include "Font.h"
|
||||
|
||||
//#include "SharedConstants.h"
|
||||
#include "../Options.h"
|
||||
#include "../renderer/Textures.h"
|
||||
#include "../renderer/Tesselator.h"
|
||||
#include "../../util/Mth.h"
|
||||
#include <cstring>
|
||||
|
||||
Font::Font( Options* options, const std::string& name, Textures* textures )
|
||||
: options(options),
|
||||
fontTexture(0),
|
||||
fontName(name),
|
||||
index(0),
|
||||
count(0),
|
||||
_textures(textures),
|
||||
_x(0), _y(0),
|
||||
_cols(16), _rows(16),
|
||||
_charOffset(0),
|
||||
lineHeight(DefaultLineHeight)
|
||||
{
|
||||
init(options);
|
||||
}
|
||||
|
||||
|
||||
//Font::Font( Options* options, const std::string& name, Textures* textures, int imgW, int imgH, int x, int y, int cols, int rows, unsigned char charOffset )
|
||||
//: options(options),
|
||||
// fontTexture(0),
|
||||
// fontName(name),
|
||||
// index(0),
|
||||
// count(0),
|
||||
// _textures(textures),
|
||||
// _x(x), _y(y),
|
||||
// _cols(cols), _rows(rows),
|
||||
// _charOffset(charOffset)
|
||||
//{
|
||||
// init(options);
|
||||
//}
|
||||
|
||||
void Font::onGraphicsReset()
|
||||
{
|
||||
init(options);
|
||||
}
|
||||
|
||||
void Font::init( Options* options )
|
||||
{
|
||||
TextureId fontTexture = _textures->loadTexture(fontName);
|
||||
const TextureData* tex = _textures->getTemporaryTextureData(fontTexture);
|
||||
|
||||
if (!tex)
|
||||
return;
|
||||
|
||||
unsigned char* rawPixels = tex->data;
|
||||
|
||||
const int numChars = _rows * _cols;
|
||||
for (int i = 0; i < numChars; i++) {
|
||||
int xt = i % _cols;
|
||||
int yt = i / _cols;
|
||||
|
||||
int x = 7;
|
||||
for (; x >= 0; x--) {
|
||||
int xPixel = _x + xt * 8 + x;
|
||||
bool emptyColumn = true;
|
||||
for (int y = 0; y < 8 && emptyColumn; y++) {
|
||||
int yPixel = _y + (yt * 8 + y) * tex->w;
|
||||
unsigned char pixelalpha = rawPixels[(xPixel + yPixel) << 2];
|
||||
if (pixelalpha > 0) emptyColumn = false;
|
||||
}
|
||||
if (!emptyColumn) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == ' ') x = 4 - 2;
|
||||
charWidths[i] = x + 2;
|
||||
fcharWidths[i] = (float) charWidths[i];
|
||||
}
|
||||
|
||||
#ifdef USE_VBO
|
||||
return; // this <1
|
||||
#endif
|
||||
|
||||
#ifndef USE_VBO
|
||||
listPos = glGenLists(256 + 32);
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
for (int i = 0; i < 256; i++) {
|
||||
glNewList(listPos + i, GL_COMPILE);
|
||||
// @attn @huge @note: This is some dangerous code right here / Aron, added ^1
|
||||
t.begin();
|
||||
buildChar(i);
|
||||
t.end(false, -1);
|
||||
|
||||
glTranslatef2((GLfloat)charWidths[i], 0.0f, 0.0f);
|
||||
glEndList();
|
||||
}
|
||||
|
||||
for (int i = 0; i < 32; i++) {
|
||||
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;
|
||||
|
||||
if (options->anaglyph3d) {
|
||||
int cr = (r * 30 + g * 59 + b * 11) / 100;
|
||||
int cg = (r * 30 + g * 70) / (100);
|
||||
int cb = (r * 30 + b * 70) / (100);
|
||||
|
||||
r = cr;
|
||||
g = cg;
|
||||
b = cb;
|
||||
}
|
||||
|
||||
// color = r << 16 | g << 8 | b;
|
||||
if (darken) {
|
||||
r /= 4;
|
||||
g /= 4;
|
||||
b /= 4;
|
||||
}
|
||||
|
||||
glNewList(listPos + 256 + i, GL_COMPILE);
|
||||
glColor3f(r / 255.0f, g / 255.0f, b / 255.0f);
|
||||
glEndList();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Font::drawShadow( const std::string& str, float x, float y, int color )
|
||||
{
|
||||
draw(str, x + 1, y + 1, color, true);
|
||||
draw(str, x, y, color);
|
||||
}
|
||||
void Font::drawShadow( const char* str, float x, float y, int color )
|
||||
{
|
||||
draw(str, x + 1, y + 1, color, true);
|
||||
draw(str, x, y, color);
|
||||
}
|
||||
|
||||
void Font::draw( const std::string& str, float x, float y, int color )
|
||||
{
|
||||
draw(str, x, y, color, false);
|
||||
}
|
||||
|
||||
void Font::draw( const char* str, float x, float y, int color )
|
||||
{
|
||||
draw(str, x, y, color, false);
|
||||
}
|
||||
|
||||
void Font::draw( const char* str, float x, float y, int color, bool darken )
|
||||
{
|
||||
#ifdef USE_VBO
|
||||
drawSlow(str, x, y, color, darken);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Font::draw( const std::string& str, float x, float y, int color, bool darken )
|
||||
{
|
||||
#ifdef USE_VBO
|
||||
drawSlow(str, x, y, color, darken);
|
||||
return;
|
||||
#endif
|
||||
|
||||
if (str.empty()) return;
|
||||
|
||||
if (darken) {
|
||||
int oldAlpha = color & 0xff000000;
|
||||
color = (color & 0xfcfcfc) >> 2;
|
||||
color += oldAlpha;
|
||||
}
|
||||
|
||||
_textures->loadAndBindTexture(fontName);
|
||||
float r = ((color >> 16) & 0xff) / 255.0f;
|
||||
float g = ((color >> 8) & 0xff) / 255.0f;
|
||||
float b = ((color) & 0xff) / 255.0f;
|
||||
float a = ((color >> 24) & 0xff) / 255.0f;
|
||||
if (a == 0) a = 1;
|
||||
glColor4f2(r, g, b, a);
|
||||
|
||||
static const std::string hex("0123456789abcdef");
|
||||
|
||||
index = 0;
|
||||
glPushMatrix2();
|
||||
glTranslatef2((GLfloat)x, (GLfloat)y, 0.0f);
|
||||
for (unsigned int i = 0; i < str.length(); i++) {
|
||||
while (str.length() > i + 1 && str[i] == '\xa7') {
|
||||
int cc = hex.find((char)tolower(str[i + 1]));
|
||||
if (cc < 0 || cc > 15) cc = 15;
|
||||
lists[index++] = listPos + 256 + cc + (darken ? 16 : 0);
|
||||
|
||||
if (index == 1024) {
|
||||
count = index;
|
||||
index = 0;
|
||||
#ifndef USE_VBO
|
||||
glCallLists(count, GL_UNSIGNED_INT, lists);
|
||||
#endif
|
||||
count = 1024;
|
||||
}
|
||||
|
||||
i += 2;
|
||||
}
|
||||
|
||||
if (i < str.length()) {
|
||||
//int ch = SharedConstants.acceptableLetters.indexOf(str.charAt(i));
|
||||
char ch = str[i];
|
||||
if (ch >= 0) {
|
||||
//ib.put(listPos + ch + 32);
|
||||
lists[index++] = listPos + ch;
|
||||
}
|
||||
}
|
||||
|
||||
if (index == 1024) {
|
||||
count = index;
|
||||
index = 0;
|
||||
#ifndef USE_VBO
|
||||
glCallLists(count, GL_UNSIGNED_INT, lists);
|
||||
#endif
|
||||
count = 1024;
|
||||
}
|
||||
}
|
||||
count = index;
|
||||
index = 0;
|
||||
#ifndef USE_VBO
|
||||
glCallLists(count, GL_UNSIGNED_INT, lists);
|
||||
#endif
|
||||
glPopMatrix2();
|
||||
}
|
||||
|
||||
int Font::width( const std::string& str )
|
||||
{
|
||||
int maxLen = 0;
|
||||
int len = 0;
|
||||
|
||||
for (unsigned int i = 0; i < str.length(); i++) {
|
||||
if (str[i] == '\xa7') {
|
||||
i++;
|
||||
} else {
|
||||
//int ch = SharedConstants.acceptableLetters.indexOf(str.charAt(i));
|
||||
//if (ch >= 0) {
|
||||
// len += charWidths[ch + 32];
|
||||
//}
|
||||
if (str[i] == '\n') {
|
||||
if (len > maxLen) maxLen = len;
|
||||
len = 0;
|
||||
}
|
||||
else {
|
||||
int charWidth = charWidths[ (unsigned char) str[i] ];
|
||||
len += charWidth;
|
||||
}
|
||||
}
|
||||
}
|
||||
return maxLen>len? maxLen : len;
|
||||
}
|
||||
|
||||
int Font::height( const std::string& str ) {
|
||||
int h = 0;
|
||||
bool hasLine = false;
|
||||
for (unsigned int i = 0; i < str.length(); ++i) {
|
||||
if (str[i] == '\n') hasLine = true;
|
||||
else {
|
||||
if (hasLine) h += lineHeight;
|
||||
hasLine = false;
|
||||
}
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
std::string Font::sanitize( const std::string& str )
|
||||
{
|
||||
std::string sanitized(str.length() + 1, 0);
|
||||
int j = 0;
|
||||
|
||||
for (unsigned int i = 0; i < str.length(); i++) {
|
||||
if (str[i] == '\xa7') {
|
||||
i++;
|
||||
//} else if (SharedConstants.acceptableLetters.indexOf(str.charAt(i)) >= 0) {
|
||||
} else {
|
||||
sanitized[j++] = str[i];
|
||||
}
|
||||
}
|
||||
return sanitized.erase(j);
|
||||
}
|
||||
|
||||
void Font::drawWordWrap( const std::string& str, float x, float y, float w, int col )
|
||||
{
|
||||
char* cstr = new char[str.length() + 1];
|
||||
strncpy(cstr, str.c_str(), str.length());
|
||||
cstr[str.length()] = 0;
|
||||
|
||||
const char* lims = " \n\t\r";
|
||||
char* ptok = strtok(cstr, lims);
|
||||
|
||||
std::vector<std::string> words;
|
||||
while (ptok != NULL) {
|
||||
words.push_back( ptok );
|
||||
ptok = strtok(NULL, lims);
|
||||
}
|
||||
|
||||
delete[] cstr;
|
||||
|
||||
int pos = 0;
|
||||
while (pos < (int)words.size()) {
|
||||
std::string line = words[pos++] + " ";
|
||||
while (pos < (int)words.size() && width(line + words[pos]) < w) {
|
||||
line += words[pos++] + " ";
|
||||
}
|
||||
drawShadow(line, x, y, col);
|
||||
y += lineHeight;
|
||||
}
|
||||
}
|
||||
|
||||
void Font::drawSlow( const std::string& str, float x, float y, int color, bool darken /*= false*/ ) {
|
||||
drawSlow(str.c_str(), x, y, color, darken);
|
||||
}
|
||||
void Font::drawSlow( const char* str, float x, float y, int color, bool darken /*= false*/ )
|
||||
{
|
||||
if (!str) return;
|
||||
|
||||
if (darken) {
|
||||
int oldAlpha = color & 0xff000000;
|
||||
color = (color & 0xfcfcfc) >> 2;
|
||||
color += oldAlpha;
|
||||
}
|
||||
|
||||
_textures->loadAndBindTexture(fontName);
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
t.begin();
|
||||
int alpha = (0xff000000 & color) >> 24;
|
||||
if (!alpha) alpha = 0xff;
|
||||
t.color((color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff, alpha);
|
||||
|
||||
t.addOffset((float)x, (float)y, 0);
|
||||
float xOffset = 0;
|
||||
float yOffset = 0;
|
||||
|
||||
while (unsigned char ch = *(str++)) {
|
||||
if (ch == '\n') {
|
||||
xOffset = 0;
|
||||
yOffset += lineHeight;
|
||||
} else {
|
||||
buildChar(ch, xOffset, yOffset);
|
||||
xOffset += fcharWidths[ch];
|
||||
}
|
||||
}
|
||||
t.draw();
|
||||
t.addOffset(-(float)x, -(float)y, 0);
|
||||
}
|
||||
|
||||
void Font::buildChar( unsigned char i, float x /*= 0*/, float y /*=0*/ )
|
||||
{
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
//i -= _charOffset;
|
||||
//int ix = (i % _cols) * 8 + _x;
|
||||
//int iy = (i / _cols) * 8 + _y;
|
||||
float ix = (float)((i & 15) * 8);
|
||||
float iy = (float)((i >> 4) * 8);
|
||||
float s = 7.99f;
|
||||
|
||||
float uo = (0.0f) / 128.0f;
|
||||
float vo = (0.0f) / 128.0f;
|
||||
|
||||
t.vertexUV(x, y + s, 0, ix / 128.0f + uo, (iy + s) / 128.0f + vo);
|
||||
t.vertexUV(x + s, y + s, 0, (ix + s) / 128.0f + uo, (iy + s) / 128.0f + vo);
|
||||
t.vertexUV(x + s, y, 0, (ix + s) / 128.0f + uo, iy / 128.0f + vo);
|
||||
t.vertexUV(x, y, 0, ix / 128.0f + uo, iy / 128.0f + vo);
|
||||
}
|
||||
|
||||
#include "Font.hpp"
|
||||
|
||||
//#include "SharedConstants.hpp"
|
||||
#include "client/Options.hpp"
|
||||
#include "client/renderer/Textures.hpp"
|
||||
#include "client/renderer/Tesselator.hpp"
|
||||
#include "util/Mth.hpp"
|
||||
#include <cstring>
|
||||
|
||||
Font::Font( Options* options, const std::string& name, Textures* textures )
|
||||
: options(options),
|
||||
fontTexture(0),
|
||||
fontName(name),
|
||||
index(0),
|
||||
count(0),
|
||||
_textures(textures),
|
||||
_x(0), _y(0),
|
||||
_cols(16), _rows(16),
|
||||
_charOffset(0),
|
||||
lineHeight(DefaultLineHeight)
|
||||
{
|
||||
init(options);
|
||||
}
|
||||
|
||||
|
||||
//Font::Font( Options* options, const std::string& name, Textures* textures, int imgW, int imgH, int x, int y, int cols, int rows, unsigned char charOffset )
|
||||
//: options(options),
|
||||
// fontTexture(0),
|
||||
// fontName(name),
|
||||
// index(0),
|
||||
// count(0),
|
||||
// _textures(textures),
|
||||
// _x(x), _y(y),
|
||||
// _cols(cols), _rows(rows),
|
||||
// _charOffset(charOffset)
|
||||
//{
|
||||
// init(options);
|
||||
//}
|
||||
|
||||
void Font::onGraphicsReset()
|
||||
{
|
||||
init(options);
|
||||
}
|
||||
|
||||
void Font::init( Options* options )
|
||||
{
|
||||
TextureId fontTexture = _textures->loadTexture(fontName);
|
||||
const TextureData* tex = _textures->getTemporaryTextureData(fontTexture);
|
||||
|
||||
if (!tex)
|
||||
return;
|
||||
|
||||
unsigned char* rawPixels = tex->data;
|
||||
|
||||
const int numChars = _rows * _cols;
|
||||
for (int i = 0; i < numChars; i++) {
|
||||
int xt = i % _cols;
|
||||
int yt = i / _cols;
|
||||
|
||||
int x = 7;
|
||||
for (; x >= 0; x--) {
|
||||
int xPixel = _x + xt * 8 + x;
|
||||
bool emptyColumn = true;
|
||||
for (int y = 0; y < 8 && emptyColumn; y++) {
|
||||
int yPixel = _y + (yt * 8 + y) * tex->w;
|
||||
unsigned char pixelalpha = rawPixels[(xPixel + yPixel) << 2];
|
||||
if (pixelalpha > 0) emptyColumn = false;
|
||||
}
|
||||
if (!emptyColumn) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == ' ') x = 4 - 2;
|
||||
charWidths[i] = x + 2;
|
||||
fcharWidths[i] = (float) charWidths[i];
|
||||
}
|
||||
|
||||
#ifdef USE_VBO
|
||||
return; // this <1
|
||||
#endif
|
||||
|
||||
#ifndef USE_VBO
|
||||
listPos = glGenLists(256 + 32);
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
for (int i = 0; i < 256; i++) {
|
||||
glNewList(listPos + i, GL_COMPILE);
|
||||
// @attn @huge @note: This is some dangerous code right here / Aron, added ^1
|
||||
t.begin();
|
||||
buildChar(i);
|
||||
t.end(false, -1);
|
||||
|
||||
glTranslatef2((GLfloat)charWidths[i], 0.0f, 0.0f);
|
||||
glEndList();
|
||||
}
|
||||
|
||||
for (int i = 0; i < 32; i++) {
|
||||
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;
|
||||
|
||||
if (options->anaglyph3d) {
|
||||
int cr = (r * 30 + g * 59 + b * 11) / 100;
|
||||
int cg = (r * 30 + g * 70) / (100);
|
||||
int cb = (r * 30 + b * 70) / (100);
|
||||
|
||||
r = cr;
|
||||
g = cg;
|
||||
b = cb;
|
||||
}
|
||||
|
||||
// color = r << 16 | g << 8 | b;
|
||||
if (darken) {
|
||||
r /= 4;
|
||||
g /= 4;
|
||||
b /= 4;
|
||||
}
|
||||
|
||||
glNewList(listPos + 256 + i, GL_COMPILE);
|
||||
glColor3f(r / 255.0f, g / 255.0f, b / 255.0f);
|
||||
glEndList();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Font::drawShadow( const std::string& str, float x, float y, int color )
|
||||
{
|
||||
draw(str, x + 1, y + 1, color, true);
|
||||
draw(str, x, y, color);
|
||||
}
|
||||
void Font::drawShadow( const char* str, float x, float y, int color )
|
||||
{
|
||||
draw(str, x + 1, y + 1, color, true);
|
||||
draw(str, x, y, color);
|
||||
}
|
||||
|
||||
void Font::draw( const std::string& str, float x, float y, int color )
|
||||
{
|
||||
draw(str, x, y, color, false);
|
||||
}
|
||||
|
||||
void Font::draw( const char* str, float x, float y, int color )
|
||||
{
|
||||
draw(str, x, y, color, false);
|
||||
}
|
||||
|
||||
void Font::draw( const char* str, float x, float y, int color, bool darken )
|
||||
{
|
||||
#ifdef USE_VBO
|
||||
drawSlow(str, x, y, color, darken);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Font::draw( const std::string& str, float x, float y, int color, bool darken )
|
||||
{
|
||||
#ifdef USE_VBO
|
||||
drawSlow(str, x, y, color, darken);
|
||||
return;
|
||||
#endif
|
||||
|
||||
if (str.empty()) return;
|
||||
|
||||
if (darken) {
|
||||
int oldAlpha = color & 0xff000000;
|
||||
color = (color & 0xfcfcfc) >> 2;
|
||||
color += oldAlpha;
|
||||
}
|
||||
|
||||
_textures->loadAndBindTexture(fontName);
|
||||
float r = ((color >> 16) & 0xff) / 255.0f;
|
||||
float g = ((color >> 8) & 0xff) / 255.0f;
|
||||
float b = ((color) & 0xff) / 255.0f;
|
||||
float a = ((color >> 24) & 0xff) / 255.0f;
|
||||
if (a == 0) a = 1;
|
||||
glColor4f2(r, g, b, a);
|
||||
|
||||
static const std::string hex("0123456789abcdef");
|
||||
|
||||
index = 0;
|
||||
glPushMatrix2();
|
||||
glTranslatef2((GLfloat)x, (GLfloat)y, 0.0f);
|
||||
for (unsigned int i = 0; i < str.length(); i++) {
|
||||
while (str.length() > i + 1 && str[i] == '\xa7') {
|
||||
int cc = hex.find((char)tolower(str[i + 1]));
|
||||
if (cc < 0 || cc > 15) cc = 15;
|
||||
lists[index++] = listPos + 256 + cc + (darken ? 16 : 0);
|
||||
|
||||
if (index == 1024) {
|
||||
count = index;
|
||||
index = 0;
|
||||
#ifndef USE_VBO
|
||||
glCallLists(count, GL_UNSIGNED_INT, lists);
|
||||
#endif
|
||||
count = 1024;
|
||||
}
|
||||
|
||||
i += 2;
|
||||
}
|
||||
|
||||
if (i < str.length()) {
|
||||
//int ch = SharedConstants.acceptableLetters.indexOf(str.charAt(i));
|
||||
char ch = str[i];
|
||||
if (ch >= 0) {
|
||||
//ib.put(listPos + ch + 32);
|
||||
lists[index++] = listPos + ch;
|
||||
}
|
||||
}
|
||||
|
||||
if (index == 1024) {
|
||||
count = index;
|
||||
index = 0;
|
||||
#ifndef USE_VBO
|
||||
glCallLists(count, GL_UNSIGNED_INT, lists);
|
||||
#endif
|
||||
count = 1024;
|
||||
}
|
||||
}
|
||||
count = index;
|
||||
index = 0;
|
||||
#ifndef USE_VBO
|
||||
glCallLists(count, GL_UNSIGNED_INT, lists);
|
||||
#endif
|
||||
glPopMatrix2();
|
||||
}
|
||||
|
||||
int Font::width( const std::string& str )
|
||||
{
|
||||
int maxLen = 0;
|
||||
int len = 0;
|
||||
|
||||
for (unsigned int i = 0; i < str.length(); i++) {
|
||||
if (str[i] == '\xa7') {
|
||||
i++;
|
||||
} else {
|
||||
//int ch = SharedConstants.acceptableLetters.indexOf(str.charAt(i));
|
||||
//if (ch >= 0) {
|
||||
// len += charWidths[ch + 32];
|
||||
//}
|
||||
if (str[i] == '\n') {
|
||||
if (len > maxLen) maxLen = len;
|
||||
len = 0;
|
||||
}
|
||||
else {
|
||||
int charWidth = charWidths[ (unsigned char) str[i] ];
|
||||
len += charWidth;
|
||||
}
|
||||
}
|
||||
}
|
||||
return maxLen>len? maxLen : len;
|
||||
}
|
||||
|
||||
int Font::height( const std::string& str ) {
|
||||
int h = 0;
|
||||
bool hasLine = false;
|
||||
for (unsigned int i = 0; i < str.length(); ++i) {
|
||||
if (str[i] == '\n') hasLine = true;
|
||||
else {
|
||||
if (hasLine) h += lineHeight;
|
||||
hasLine = false;
|
||||
}
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
std::string Font::sanitize( const std::string& str )
|
||||
{
|
||||
std::string sanitized(str.length() + 1, 0);
|
||||
int j = 0;
|
||||
|
||||
for (unsigned int i = 0; i < str.length(); i++) {
|
||||
if (str[i] == '\xa7') {
|
||||
i++;
|
||||
//} else if (SharedConstants.acceptableLetters.indexOf(str.charAt(i)) >= 0) {
|
||||
} else {
|
||||
sanitized[j++] = str[i];
|
||||
}
|
||||
}
|
||||
return sanitized.erase(j);
|
||||
}
|
||||
|
||||
void Font::drawWordWrap( const std::string& str, float x, float y, float w, int col )
|
||||
{
|
||||
char* cstr = new char[str.length() + 1];
|
||||
strncpy(cstr, str.c_str(), str.length());
|
||||
cstr[str.length()] = 0;
|
||||
|
||||
const char* lims = " \n\t\r";
|
||||
char* ptok = strtok(cstr, lims);
|
||||
|
||||
std::vector<std::string> words;
|
||||
while (ptok != NULL) {
|
||||
words.push_back( ptok );
|
||||
ptok = strtok(NULL, lims);
|
||||
}
|
||||
|
||||
delete[] cstr;
|
||||
|
||||
int pos = 0;
|
||||
while (pos < (int)words.size()) {
|
||||
std::string line = words[pos++] + " ";
|
||||
while (pos < (int)words.size() && width(line + words[pos]) < w) {
|
||||
line += words[pos++] + " ";
|
||||
}
|
||||
drawShadow(line, x, y, col);
|
||||
y += lineHeight;
|
||||
}
|
||||
}
|
||||
|
||||
void Font::drawSlow( const std::string& str, float x, float y, int color, bool darken /*= false*/ ) {
|
||||
drawSlow(str.c_str(), x, y, color, darken);
|
||||
}
|
||||
void Font::drawSlow( const char* str, float x, float y, int color, bool darken /*= false*/ )
|
||||
{
|
||||
if (!str) return;
|
||||
|
||||
if (darken) {
|
||||
int oldAlpha = color & 0xff000000;
|
||||
color = (color & 0xfcfcfc) >> 2;
|
||||
color += oldAlpha;
|
||||
}
|
||||
|
||||
_textures->loadAndBindTexture(fontName);
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
t.begin();
|
||||
int alpha = (0xff000000 & color) >> 24;
|
||||
if (!alpha) alpha = 0xff;
|
||||
t.color((color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff, alpha);
|
||||
|
||||
t.addOffset((float)x, (float)y, 0);
|
||||
float xOffset = 0;
|
||||
float yOffset = 0;
|
||||
|
||||
while (unsigned char ch = *(str++)) {
|
||||
if (ch == '\n') {
|
||||
xOffset = 0;
|
||||
yOffset += lineHeight;
|
||||
} else {
|
||||
buildChar(ch, xOffset, yOffset);
|
||||
xOffset += fcharWidths[ch];
|
||||
}
|
||||
}
|
||||
t.draw();
|
||||
t.addOffset(-(float)x, -(float)y, 0);
|
||||
}
|
||||
|
||||
void Font::buildChar( unsigned char i, float x /*= 0*/, float y /*=0*/ )
|
||||
{
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
//i -= _charOffset;
|
||||
//int ix = (i % _cols) * 8 + _x;
|
||||
//int iy = (i / _cols) * 8 + _y;
|
||||
float ix = (float)((i & 15) * 8);
|
||||
float iy = (float)((i >> 4) * 8);
|
||||
float s = 7.99f;
|
||||
|
||||
float uo = (0.0f) / 128.0f;
|
||||
float vo = (0.0f) / 128.0f;
|
||||
|
||||
t.vertexUV(x, y + s, 0, ix / 128.0f + uo, (iy + s) / 128.0f + vo);
|
||||
t.vertexUV(x + s, y + s, 0, (ix + s) / 128.0f + uo, (iy + s) / 128.0f + vo);
|
||||
t.vertexUV(x + s, y, 0, (ix + s) / 128.0f + uo, iy / 128.0f + vo);
|
||||
t.vertexUV(x, y, 0, ix / 128.0f + uo, iy / 128.0f + vo);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <string>
|
||||
#include <cctype>
|
||||
|
||||
#include "../renderer/gles.h"
|
||||
#include "client/renderer/gles.hpp"
|
||||
|
||||
class Textures;
|
||||
class Options;
|
||||
@@ -1,31 +1,31 @@
|
||||
#include "Gui.h"
|
||||
#include "Font.h"
|
||||
#include "MinecraftClient.h"
|
||||
#include "client/Options.h"
|
||||
#include "platform/input/Keyboard.h"
|
||||
#include "screens/IngameBlockSelectionScreen.h"
|
||||
#include "screens/ChatScreen.h"
|
||||
#include "screens/ConsoleScreen.h"
|
||||
#include <Minecraft.h>
|
||||
#include "../player/LocalPlayer.h"
|
||||
#include "../renderer/Tesselator.h"
|
||||
#include "../renderer/TileRenderer.h"
|
||||
#include "../renderer/LevelRenderer.h"
|
||||
#include "../renderer/GameRenderer.h"
|
||||
#include "../renderer/entity/ItemRenderer.h"
|
||||
#include "../player/input/IInputHolder.h"
|
||||
#include "../gamemode/GameMode.h"
|
||||
#include "../gamemode/CreativeMode.h"
|
||||
#include "../renderer/Textures.h"
|
||||
#include "../../AppConstants.h"
|
||||
#include "../../world/entity/player/Inventory.h"
|
||||
#include "../../world/level/material/Material.h"
|
||||
#include "../../world/item/Item.h"
|
||||
#include "../../world/item/ItemInstance.h"
|
||||
#include "../../platform/input/Mouse.h"
|
||||
#include "../../world/level/Level.h"
|
||||
#include "../../world/PosTranslator.h"
|
||||
#include "../../platform/time.h"
|
||||
#include "Gui.hpp"
|
||||
#include "Font.hpp"
|
||||
#include "MinecraftClient.hpp"
|
||||
#include "client/Options.hpp"
|
||||
#include "platform/input/Keyboard.hpp"
|
||||
#include "screens/IngameBlockSelectionScreen.hpp"
|
||||
#include "screens/ChatScreen.hpp"
|
||||
#include "screens/ConsoleScreen.hpp"
|
||||
#include <Minecraft.hpp>
|
||||
#include "client/player/LocalPlayer.hpp"
|
||||
#include "client/renderer/Tesselator.hpp"
|
||||
#include "client/renderer/TileRenderer.hpp"
|
||||
#include "client/renderer/LevelRenderer.hpp"
|
||||
#include "client/renderer/GameRenderer.hpp"
|
||||
#include "client/renderer/entity/ItemRenderer.hpp"
|
||||
#include "client/player/input/IInputHolder.hpp"
|
||||
#include "client/gamemode/GameMode.hpp"
|
||||
#include "client/gamemode/CreativeMode.hpp"
|
||||
#include "client/renderer/Textures.hpp"
|
||||
#include "AppConstants.hpp"
|
||||
#include "world/entity/player/Inventory.hpp"
|
||||
#include "world/level/material/Material.hpp"
|
||||
#include "world/item/Item.hpp"
|
||||
#include "world/item/ItemInstance.hpp"
|
||||
#include "platform/input/Mouse.hpp"
|
||||
#include "world/level/Level.hpp"
|
||||
#include "world/PosTranslator.hpp"
|
||||
#include "platform/time.hpp"
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
//package net.minecraft.client.gui;
|
||||
|
||||
#include "GuiComponent.h"
|
||||
#include "Font.h"
|
||||
#include "../player/input/touchscreen/TouchAreaModel.h"
|
||||
#include "../renderer/RenderChunk.h"
|
||||
#include "../../util/Random.h"
|
||||
#include "../IConfigListener.h"
|
||||
#include "GuiComponent.hpp"
|
||||
#include "Font.hpp"
|
||||
#include "client/player/input/touchscreen/TouchAreaModel.hpp"
|
||||
#include "client/renderer/RenderChunk.hpp"
|
||||
#include "util/Random.hpp"
|
||||
#include "client/IConfigListener.hpp"
|
||||
|
||||
class MinecraftClient;
|
||||
class ItemInstance;
|
||||
@@ -1,156 +1,156 @@
|
||||
#include "GuiComponent.h"
|
||||
|
||||
#include "../renderer/Tesselator.h"
|
||||
#include "../renderer/gles.h"
|
||||
#include "Font.h"
|
||||
|
||||
|
||||
GuiComponent::GuiComponent()
|
||||
: blitOffset(0)
|
||||
{
|
||||
}
|
||||
|
||||
GuiComponent::~GuiComponent()
|
||||
{
|
||||
}
|
||||
|
||||
void GuiComponent::drawCenteredString( Font* font, const std::string& str, int x, int y, int color )
|
||||
{
|
||||
font->drawShadow(str, (float)(x - font->width(str) / 2), (float)(y - font->height(str) / 2), color);
|
||||
}
|
||||
|
||||
void GuiComponent::drawString( Font* font, const std::string& str, int x, int y, int color )
|
||||
{
|
||||
font->drawShadow(str, (float)x, (float)y /*- font->height(str)/2*/, color);
|
||||
}
|
||||
|
||||
void GuiComponent::blit( int x, int y, int sx, int sy, int w, int h, int sw/*=0*/, int sh/*=0*/ )
|
||||
{
|
||||
if (!sw) sw = w;
|
||||
if (!sh) sh = h;
|
||||
float us = 1 / 256.0f;
|
||||
float vs = 1 / 256.0f;
|
||||
Tesselator& t = Tesselator::instance;
|
||||
t.begin();
|
||||
t.vertexUV((float)(x) , (float)(y + h), blitOffset, (float)(sx ) * us, (float)(sy + sh) * vs);
|
||||
t.vertexUV((float)(x + w), (float)(y + h), blitOffset, (float)(sx + sw) * us, (float)(sy + sh) * vs);
|
||||
t.vertexUV((float)(x + w), (float)(y) , blitOffset, (float)(sx + sw) * us, (float)(sy ) * vs);
|
||||
t.vertexUV((float)(x) , (float)(y) , blitOffset, (float)(sx ) * us, (float)(sy ) * vs);
|
||||
t.draw();
|
||||
}
|
||||
void GuiComponent::blit( float x, float y, int sx, int sy, float w, float h, int sw/*=0*/, int sh/*=0*/ )
|
||||
{
|
||||
if (!sw) sw = (int)w;
|
||||
if (!sh) sh = (int)h;
|
||||
float us = 1 / 256.0f;
|
||||
float vs = 1 / 256.0f;
|
||||
Tesselator& t = Tesselator::instance;
|
||||
t.begin();
|
||||
t.vertexUV(x , y + h, blitOffset, (float)(sx ) * us, (float)(sy + sh) * vs);
|
||||
t.vertexUV(x + w, y + h, blitOffset, (float)(sx + sw) * us, (float)(sy + sh) * vs);
|
||||
t.vertexUV(x + w, y , blitOffset, (float)(sx + sw) * us, (float)(sy ) * vs);
|
||||
t.vertexUV(x , y , blitOffset, (float)(sx ) * us, (float)(sy ) * vs);
|
||||
t.draw();
|
||||
}
|
||||
|
||||
void GuiComponent::fill( int x0, int y0, int x1, int y1, int col ) {
|
||||
fill((float)x0, (float)y0, (float)x1, (float)y1, col);
|
||||
}
|
||||
void GuiComponent::fill( float x0, float y0, float x1, float y1, int col )
|
||||
{
|
||||
//float a = ((col >> 24) & 0xff) / 255.0f;
|
||||
//float r = ((col >> 16) & 0xff) / 255.0f;
|
||||
//float g = ((col >> 8) & 0xff) / 255.0f;
|
||||
//float b = ((col) & 0xff) / 255.0f;
|
||||
//glColor4f2(r, g, b, a);
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
glEnable2(GL_BLEND);
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
//LOGI("col: %f, %f, %f, %f\n", r, g, b, a);
|
||||
t.begin();
|
||||
const int color = (col&0xff00ff00) | ((col&0xff0000) >> 16) | ((col&0xff) << 16);
|
||||
t.colorABGR(color);
|
||||
t.vertex(x0, y1, 0);
|
||||
t.vertex(x1, y1, 0);
|
||||
t.vertex(x1, y0, 0);
|
||||
t.vertex(x0, y0, 0);
|
||||
t.draw();
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
glDisable2(GL_BLEND);
|
||||
}
|
||||
|
||||
void GuiComponent::fillGradient( int x0, int y0, int x1, int y1, int col1, int col2 ) {
|
||||
fillGradient((float)x0, (float)y0, (float)x1, (float)y1, col1, col2);
|
||||
}
|
||||
void GuiComponent::fillGradient( float x0, float y0, float x1, float 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;
|
||||
float b1 = ((col1) & 0xff) / 255.0f;
|
||||
|
||||
float a2 = ((col2 >> 24) & 0xff) / 255.0f;
|
||||
float r2 = ((col2 >> 16) & 0xff) / 255.0f;
|
||||
float g2 = ((col2 >> 8) & 0xff) / 255.0f;
|
||||
float b2 = ((col2) & 0xff) / 255.0f;
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
glEnable2(GL_BLEND);
|
||||
glDisable2(GL_ALPHA_TEST);
|
||||
glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glShadeModel2(GL_SMOOTH);
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
t.begin();
|
||||
t.color(r1, g1, b1, a1);
|
||||
t.vertex(x1, y0, 0);
|
||||
t.vertex(x0, y0, 0);
|
||||
t.color(r2, g2, b2, a2);
|
||||
t.vertex(x0, y1, 0);
|
||||
t.vertex(x1, y1, 0);
|
||||
t.draw();
|
||||
|
||||
glShadeModel2(GL_FLAT);
|
||||
glDisable2(GL_BLEND);
|
||||
glEnable2(GL_ALPHA_TEST);
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
}
|
||||
void GuiComponent::fillHorizontalGradient( int x0, int y0, int x1, int y1, int col1, int col2 ) {
|
||||
fillHorizontalGradient((float)x0, (float)y0, (float)x1, (float)y1, col1, col2);
|
||||
}
|
||||
void GuiComponent::fillHorizontalGradient( float x0, float y0, float x1, float 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;
|
||||
float b1 = ((col1) & 0xff) / 255.0f;
|
||||
|
||||
float a2 = ((col2 >> 24) & 0xff) / 255.0f;
|
||||
float r2 = ((col2 >> 16) & 0xff) / 255.0f;
|
||||
float g2 = ((col2 >> 8) & 0xff) / 255.0f;
|
||||
float b2 = ((col2) & 0xff) / 255.0f;
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
glEnable2(GL_BLEND);
|
||||
glDisable2(GL_ALPHA_TEST);
|
||||
glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glShadeModel2(GL_SMOOTH);
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
t.begin();
|
||||
t.color(r2, g2, b2, a2);
|
||||
t.vertex(x1, y0, 0);
|
||||
t.color(r1, g1, b1, a1);
|
||||
t.vertex(x0, y0, 0);
|
||||
t.color(r1, g1, b1, a1);
|
||||
t.vertex(x0, y1, 0);
|
||||
t.color(r2, g2, b2, a2);
|
||||
t.vertex(x1, y1, 0);
|
||||
t.draw();
|
||||
|
||||
glShadeModel2(GL_FLAT);
|
||||
glDisable2(GL_BLEND);
|
||||
glEnable2(GL_ALPHA_TEST);
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
}
|
||||
#include "GuiComponent.hpp"
|
||||
|
||||
#include "client/renderer/Tesselator.hpp"
|
||||
#include "client/renderer/gles.hpp"
|
||||
#include "Font.hpp"
|
||||
|
||||
|
||||
GuiComponent::GuiComponent()
|
||||
: blitOffset(0)
|
||||
{
|
||||
}
|
||||
|
||||
GuiComponent::~GuiComponent()
|
||||
{
|
||||
}
|
||||
|
||||
void GuiComponent::drawCenteredString( Font* font, const std::string& str, int x, int y, int color )
|
||||
{
|
||||
font->drawShadow(str, (float)(x - font->width(str) / 2), (float)(y - font->height(str) / 2), color);
|
||||
}
|
||||
|
||||
void GuiComponent::drawString( Font* font, const std::string& str, int x, int y, int color )
|
||||
{
|
||||
font->drawShadow(str, (float)x, (float)y /*- font->height(str)/2*/, color);
|
||||
}
|
||||
|
||||
void GuiComponent::blit( int x, int y, int sx, int sy, int w, int h, int sw/*=0*/, int sh/*=0*/ )
|
||||
{
|
||||
if (!sw) sw = w;
|
||||
if (!sh) sh = h;
|
||||
float us = 1 / 256.0f;
|
||||
float vs = 1 / 256.0f;
|
||||
Tesselator& t = Tesselator::instance;
|
||||
t.begin();
|
||||
t.vertexUV((float)(x) , (float)(y + h), blitOffset, (float)(sx ) * us, (float)(sy + sh) * vs);
|
||||
t.vertexUV((float)(x + w), (float)(y + h), blitOffset, (float)(sx + sw) * us, (float)(sy + sh) * vs);
|
||||
t.vertexUV((float)(x + w), (float)(y) , blitOffset, (float)(sx + sw) * us, (float)(sy ) * vs);
|
||||
t.vertexUV((float)(x) , (float)(y) , blitOffset, (float)(sx ) * us, (float)(sy ) * vs);
|
||||
t.draw();
|
||||
}
|
||||
void GuiComponent::blit( float x, float y, int sx, int sy, float w, float h, int sw/*=0*/, int sh/*=0*/ )
|
||||
{
|
||||
if (!sw) sw = (int)w;
|
||||
if (!sh) sh = (int)h;
|
||||
float us = 1 / 256.0f;
|
||||
float vs = 1 / 256.0f;
|
||||
Tesselator& t = Tesselator::instance;
|
||||
t.begin();
|
||||
t.vertexUV(x , y + h, blitOffset, (float)(sx ) * us, (float)(sy + sh) * vs);
|
||||
t.vertexUV(x + w, y + h, blitOffset, (float)(sx + sw) * us, (float)(sy + sh) * vs);
|
||||
t.vertexUV(x + w, y , blitOffset, (float)(sx + sw) * us, (float)(sy ) * vs);
|
||||
t.vertexUV(x , y , blitOffset, (float)(sx ) * us, (float)(sy ) * vs);
|
||||
t.draw();
|
||||
}
|
||||
|
||||
void GuiComponent::fill( int x0, int y0, int x1, int y1, int col ) {
|
||||
fill((float)x0, (float)y0, (float)x1, (float)y1, col);
|
||||
}
|
||||
void GuiComponent::fill( float x0, float y0, float x1, float y1, int col )
|
||||
{
|
||||
//float a = ((col >> 24) & 0xff) / 255.0f;
|
||||
//float r = ((col >> 16) & 0xff) / 255.0f;
|
||||
//float g = ((col >> 8) & 0xff) / 255.0f;
|
||||
//float b = ((col) & 0xff) / 255.0f;
|
||||
//glColor4f2(r, g, b, a);
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
glEnable2(GL_BLEND);
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
//LOGI("col: %f, %f, %f, %f\n", r, g, b, a);
|
||||
t.begin();
|
||||
const int color = (col&0xff00ff00) | ((col&0xff0000) >> 16) | ((col&0xff) << 16);
|
||||
t.colorABGR(color);
|
||||
t.vertex(x0, y1, 0);
|
||||
t.vertex(x1, y1, 0);
|
||||
t.vertex(x1, y0, 0);
|
||||
t.vertex(x0, y0, 0);
|
||||
t.draw();
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
glDisable2(GL_BLEND);
|
||||
}
|
||||
|
||||
void GuiComponent::fillGradient( int x0, int y0, int x1, int y1, int col1, int col2 ) {
|
||||
fillGradient((float)x0, (float)y0, (float)x1, (float)y1, col1, col2);
|
||||
}
|
||||
void GuiComponent::fillGradient( float x0, float y0, float x1, float 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;
|
||||
float b1 = ((col1) & 0xff) / 255.0f;
|
||||
|
||||
float a2 = ((col2 >> 24) & 0xff) / 255.0f;
|
||||
float r2 = ((col2 >> 16) & 0xff) / 255.0f;
|
||||
float g2 = ((col2 >> 8) & 0xff) / 255.0f;
|
||||
float b2 = ((col2) & 0xff) / 255.0f;
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
glEnable2(GL_BLEND);
|
||||
glDisable2(GL_ALPHA_TEST);
|
||||
glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glShadeModel2(GL_SMOOTH);
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
t.begin();
|
||||
t.color(r1, g1, b1, a1);
|
||||
t.vertex(x1, y0, 0);
|
||||
t.vertex(x0, y0, 0);
|
||||
t.color(r2, g2, b2, a2);
|
||||
t.vertex(x0, y1, 0);
|
||||
t.vertex(x1, y1, 0);
|
||||
t.draw();
|
||||
|
||||
glShadeModel2(GL_FLAT);
|
||||
glDisable2(GL_BLEND);
|
||||
glEnable2(GL_ALPHA_TEST);
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
}
|
||||
void GuiComponent::fillHorizontalGradient( int x0, int y0, int x1, int y1, int col1, int col2 ) {
|
||||
fillHorizontalGradient((float)x0, (float)y0, (float)x1, (float)y1, col1, col2);
|
||||
}
|
||||
void GuiComponent::fillHorizontalGradient( float x0, float y0, float x1, float 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;
|
||||
float b1 = ((col1) & 0xff) / 255.0f;
|
||||
|
||||
float a2 = ((col2 >> 24) & 0xff) / 255.0f;
|
||||
float r2 = ((col2 >> 16) & 0xff) / 255.0f;
|
||||
float g2 = ((col2 >> 8) & 0xff) / 255.0f;
|
||||
float b2 = ((col2) & 0xff) / 255.0f;
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
glEnable2(GL_BLEND);
|
||||
glDisable2(GL_ALPHA_TEST);
|
||||
glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glShadeModel2(GL_SMOOTH);
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
t.begin();
|
||||
t.color(r2, g2, b2, a2);
|
||||
t.vertex(x1, y0, 0);
|
||||
t.color(r1, g1, b1, a1);
|
||||
t.vertex(x0, y0, 0);
|
||||
t.color(r1, g1, b1, a1);
|
||||
t.vertex(x0, y1, 0);
|
||||
t.color(r2, g2, b2, a2);
|
||||
t.vertex(x1, y1, 0);
|
||||
t.draw();
|
||||
|
||||
glShadeModel2(GL_FLAT);
|
||||
glDisable2(GL_BLEND);
|
||||
glEnable2(GL_ALPHA_TEST);
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
@@ -1,291 +1,291 @@
|
||||
#include "Screen.h"
|
||||
#include "components/Button.h"
|
||||
#include "components/TextBox.h"
|
||||
#include <Minecraft.h>
|
||||
#include "../renderer/Tesselator.h"
|
||||
#include "../sound/SoundEngine.h"
|
||||
#include "../../platform/input/Keyboard.h"
|
||||
#include "../../platform/input/Mouse.h"
|
||||
#include "../renderer/Textures.h"
|
||||
|
||||
Screen::Screen()
|
||||
: passEvents(false),
|
||||
clickedButton(NULL),
|
||||
tabButtonIndex(0),
|
||||
width(1),
|
||||
height(1),
|
||||
minecraft(NULL),
|
||||
font(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
void Screen::render( int xm, int ym, float a )
|
||||
{
|
||||
for (unsigned int i = 0; i < buttons.size(); i++) {
|
||||
Button* button = buttons[i];
|
||||
button->render(minecraft, xm, ym);
|
||||
}
|
||||
|
||||
// render any text boxes after buttons
|
||||
for (unsigned int i = 0; i < textBoxes.size(); i++) {
|
||||
TextBox* textbox = textBoxes[i];
|
||||
textbox->render(minecraft, xm, ym);
|
||||
}
|
||||
}
|
||||
|
||||
void Screen::init( Minecraft* minecraft, int width, int height )
|
||||
{
|
||||
//particles = /*new*/ GuiParticles(minecraft);
|
||||
this->minecraft = minecraft;
|
||||
this->font = minecraft->font;
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
init();
|
||||
setupPositions();
|
||||
updateTabButtonSelection();
|
||||
}
|
||||
|
||||
void Screen::init()
|
||||
{
|
||||
}
|
||||
|
||||
void Screen::setSize( int width, int height )
|
||||
{
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
setupPositions();
|
||||
}
|
||||
|
||||
bool Screen::handleBackEvent( bool isDown )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void Screen::updateEvents()
|
||||
{
|
||||
if (passEvents)
|
||||
return;
|
||||
|
||||
while (Mouse::next())
|
||||
mouseEvent();
|
||||
|
||||
while (Keyboard::next())
|
||||
keyboardEvent();
|
||||
while (Keyboard::nextTextChar())
|
||||
keyboardTextEvent();
|
||||
}
|
||||
|
||||
void Screen::mouseEvent()
|
||||
{
|
||||
const MouseAction& e = Mouse::getEvent();
|
||||
// forward wheel events to subclasses
|
||||
if (e.action == MouseAction::ACTION_WHEEL) {
|
||||
int xm = e.x * width / minecraft->width;
|
||||
int ym = e.y * height / minecraft->height - 1;
|
||||
mouseWheel(e.dx, e.dy, xm, ym);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!e.isButton())
|
||||
return;
|
||||
|
||||
if (Mouse::getEventButtonState()) {
|
||||
int xm = e.x * width / minecraft->width;
|
||||
int ym = e.y * height / minecraft->height - 1;
|
||||
mouseClicked(xm, ym, Mouse::getEventButton());
|
||||
} else {
|
||||
int xm = e.x * width / minecraft->width;
|
||||
int ym = e.y * height / minecraft->height - 1;
|
||||
mouseReleased(xm, ym, Mouse::getEventButton());
|
||||
}
|
||||
}
|
||||
|
||||
void Screen::keyboardEvent()
|
||||
{
|
||||
if (Keyboard::getEventKeyState()) {
|
||||
//if (Keyboard.getEventKey() == Keyboard.KEY_F11) {
|
||||
// minecraft->toggleFullScreen();
|
||||
// return;
|
||||
//}
|
||||
keyPressed(Keyboard::getEventKey());
|
||||
}
|
||||
}
|
||||
void Screen::keyboardTextEvent()
|
||||
{
|
||||
charPressed(Keyboard::getChar());
|
||||
}
|
||||
void Screen::renderBackground()
|
||||
{
|
||||
renderBackground(0);
|
||||
}
|
||||
|
||||
void Screen::renderBackground( int vo )
|
||||
{
|
||||
if (minecraft->isLevelGenerated()) {
|
||||
fillGradient(0, 0, width, height, 0xc0101010, 0xd0101010);
|
||||
} else {
|
||||
renderDirtBackground(vo);
|
||||
}
|
||||
}
|
||||
|
||||
void Screen::renderDirtBackground( int vo )
|
||||
{
|
||||
//glDisable2(GL_LIGHTING);
|
||||
glDisable2(GL_FOG);
|
||||
Tesselator& t = Tesselator::instance;
|
||||
minecraft->textures->loadAndBindTexture("gui/background.png");
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
float s = 32;
|
||||
float fvo = (float) vo;
|
||||
t.begin();
|
||||
t.color(0x404040);
|
||||
t.vertexUV(0, (float)height, 0, 0, height / s + fvo);
|
||||
t.vertexUV((float)width, (float)height, 0, width / s, (float)height / s + fvo);
|
||||
t.vertexUV((float)width, 0, 0, (float)width / s, 0 + fvo);
|
||||
t.vertexUV(0, 0, 0, 0, 0 + fvo);
|
||||
t.draw();
|
||||
}
|
||||
|
||||
bool Screen::isPauseScreen()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Screen::isErrorScreen()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Screen::isInGameScreen()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Screen::closeOnPlayerHurt() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void Screen::keyPressed( int eventKey )
|
||||
{
|
||||
if (eventKey == Keyboard::KEY_ESCAPE) {
|
||||
minecraft->setScreen(NULL);
|
||||
//minecraft->grabMouse();
|
||||
}
|
||||
|
||||
// pass key events to any text boxes first
|
||||
for (auto& textbox : textBoxes) {
|
||||
textbox->keyPressed(minecraft, eventKey);
|
||||
}
|
||||
|
||||
#ifdef TABBING
|
||||
if (minecraft->useTouchscreen())
|
||||
return;
|
||||
|
||||
|
||||
// "Tabbing" the buttons (walking with keys)
|
||||
const int tabButtonCount = tabButtons.size();
|
||||
if (!tabButtonCount)
|
||||
return;
|
||||
|
||||
Options& o = minecraft->options;
|
||||
if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_NEXT))
|
||||
if (++tabButtonIndex == tabButtonCount) tabButtonIndex = 0;
|
||||
if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_PREV))
|
||||
if (--tabButtonIndex == -1) tabButtonIndex = tabButtonCount-1;
|
||||
if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_OK)) {
|
||||
Button* button = tabButtons[tabButtonIndex];
|
||||
if (button->active) {
|
||||
minecraft->soundEngine->playUI("random.click", 1, 1);
|
||||
buttonClicked(button);
|
||||
}
|
||||
}
|
||||
|
||||
updateTabButtonSelection();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Screen::charPressed(char inputChar) {
|
||||
for (auto& textbox : textBoxes) {
|
||||
textbox->charPressed(minecraft, inputChar);
|
||||
}
|
||||
}
|
||||
|
||||
void Screen::updateTabButtonSelection()
|
||||
{
|
||||
#ifdef TABBING
|
||||
if (minecraft->useTouchscreen())
|
||||
return;
|
||||
|
||||
for (unsigned int i = 0; i < tabButtons.size(); ++i)
|
||||
tabButtons[i]->selected = (i == tabButtonIndex);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Screen::mouseClicked( int x, int y, int buttonNum )
|
||||
{
|
||||
if (buttonNum == MouseAction::ACTION_LEFT) {
|
||||
for (unsigned int i = 0; i < buttons.size(); ++i) {
|
||||
Button* button = buttons[i];
|
||||
//LOGI("Hit-testing button: %p\n", button);
|
||||
if (button->clicked(minecraft, x, y)) {
|
||||
button->setPressed();
|
||||
|
||||
//LOGI("Hit-test successful: %p\n", button);
|
||||
clickedButton = button;
|
||||
/*
|
||||
#if !defined(ANDROID) && !defined(__APPLE__) //if (!minecraft->isTouchscreen()) {
|
||||
minecraft->soundEngine->playUI("random.click", 1, 1);
|
||||
buttonClicked(button);
|
||||
#endif }
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// let textboxes see the click regardless
|
||||
for (auto& textbox : textBoxes) {
|
||||
textbox->mouseClicked(minecraft, x, y, buttonNum);
|
||||
}
|
||||
}
|
||||
|
||||
void Screen::mouseReleased( int x, int y, int buttonNum )
|
||||
{
|
||||
//LOGI("b_id: %d, (%p), text: %s\n", buttonNum, clickedButton, clickedButton?clickedButton->msg.c_str():"<null>");
|
||||
if (!clickedButton || buttonNum != MouseAction::ACTION_LEFT) return;
|
||||
|
||||
#if 1
|
||||
//#if defined(ANDROID) || defined(__APPLE__) //if (minecraft->isTouchscreen()) {
|
||||
for (unsigned int i = 0; i < buttons.size(); ++i) {
|
||||
Button* button = buttons[i];
|
||||
if (clickedButton == button && button->clicked(minecraft, x, y)) {
|
||||
buttonClicked(button);
|
||||
minecraft->soundEngine->playUI("random.click", 1, 1);
|
||||
clickedButton->released(x, y);
|
||||
}
|
||||
}
|
||||
# else // } else {
|
||||
clickedButton->released(x, y);
|
||||
#endif // }
|
||||
clickedButton = NULL;
|
||||
}
|
||||
|
||||
bool Screen::renderGameBehind() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Screen::hasClippingArea( IntRectangle& out )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void Screen::lostFocus() {
|
||||
for(std::vector<TextBox*>::iterator it = textBoxes.begin(); it != textBoxes.end(); ++it) {
|
||||
TextBox* tb = *it;
|
||||
tb->loseFocus(minecraft);
|
||||
}
|
||||
}
|
||||
|
||||
void Screen::toGUICoordinate( int& x, int& y ) {
|
||||
x = x * width / minecraft->width;
|
||||
y = y * height / minecraft->height - 1;
|
||||
}
|
||||
#include "Screen.hpp"
|
||||
#include "components/Button.hpp"
|
||||
#include "components/TextBox.hpp"
|
||||
#include <Minecraft.hpp>
|
||||
#include "client/renderer/Tesselator.hpp"
|
||||
#include "client/sound/SoundEngine.hpp"
|
||||
#include "platform/input/Keyboard.hpp"
|
||||
#include "platform/input/Mouse.hpp"
|
||||
#include "client/renderer/Textures.hpp"
|
||||
|
||||
Screen::Screen()
|
||||
: passEvents(false),
|
||||
clickedButton(NULL),
|
||||
tabButtonIndex(0),
|
||||
width(1),
|
||||
height(1),
|
||||
minecraft(NULL),
|
||||
font(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
void Screen::render( int xm, int ym, float a )
|
||||
{
|
||||
for (unsigned int i = 0; i < buttons.size(); i++) {
|
||||
Button* button = buttons[i];
|
||||
button->render(minecraft, xm, ym);
|
||||
}
|
||||
|
||||
// render any text boxes after buttons
|
||||
for (unsigned int i = 0; i < textBoxes.size(); i++) {
|
||||
TextBox* textbox = textBoxes[i];
|
||||
textbox->render(minecraft, xm, ym);
|
||||
}
|
||||
}
|
||||
|
||||
void Screen::init( Minecraft* minecraft, int width, int height )
|
||||
{
|
||||
//particles = /*new*/ GuiParticles(minecraft);
|
||||
this->minecraft = minecraft;
|
||||
this->font = minecraft->font;
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
init();
|
||||
setupPositions();
|
||||
updateTabButtonSelection();
|
||||
}
|
||||
|
||||
void Screen::init()
|
||||
{
|
||||
}
|
||||
|
||||
void Screen::setSize( int width, int height )
|
||||
{
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
setupPositions();
|
||||
}
|
||||
|
||||
bool Screen::handleBackEvent( bool isDown )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void Screen::updateEvents()
|
||||
{
|
||||
if (passEvents)
|
||||
return;
|
||||
|
||||
while (Mouse::next())
|
||||
mouseEvent();
|
||||
|
||||
while (Keyboard::next())
|
||||
keyboardEvent();
|
||||
while (Keyboard::nextTextChar())
|
||||
keyboardTextEvent();
|
||||
}
|
||||
|
||||
void Screen::mouseEvent()
|
||||
{
|
||||
const MouseAction& e = Mouse::getEvent();
|
||||
// forward wheel events to subclasses
|
||||
if (e.action == MouseAction::ACTION_WHEEL) {
|
||||
int xm = e.x * width / minecraft->width;
|
||||
int ym = e.y * height / minecraft->height - 1;
|
||||
mouseWheel(e.dx, e.dy, xm, ym);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!e.isButton())
|
||||
return;
|
||||
|
||||
if (Mouse::getEventButtonState()) {
|
||||
int xm = e.x * width / minecraft->width;
|
||||
int ym = e.y * height / minecraft->height - 1;
|
||||
mouseClicked(xm, ym, Mouse::getEventButton());
|
||||
} else {
|
||||
int xm = e.x * width / minecraft->width;
|
||||
int ym = e.y * height / minecraft->height - 1;
|
||||
mouseReleased(xm, ym, Mouse::getEventButton());
|
||||
}
|
||||
}
|
||||
|
||||
void Screen::keyboardEvent()
|
||||
{
|
||||
if (Keyboard::getEventKeyState()) {
|
||||
//if (Keyboard.getEventKey() == Keyboard.KEY_F11) {
|
||||
// minecraft->toggleFullScreen();
|
||||
// return;
|
||||
//}
|
||||
keyPressed(Keyboard::getEventKey());
|
||||
}
|
||||
}
|
||||
void Screen::keyboardTextEvent()
|
||||
{
|
||||
charPressed(Keyboard::getChar());
|
||||
}
|
||||
void Screen::renderBackground()
|
||||
{
|
||||
renderBackground(0);
|
||||
}
|
||||
|
||||
void Screen::renderBackground( int vo )
|
||||
{
|
||||
if (minecraft->isLevelGenerated()) {
|
||||
fillGradient(0, 0, width, height, 0xc0101010, 0xd0101010);
|
||||
} else {
|
||||
renderDirtBackground(vo);
|
||||
}
|
||||
}
|
||||
|
||||
void Screen::renderDirtBackground( int vo )
|
||||
{
|
||||
//glDisable2(GL_LIGHTING);
|
||||
glDisable2(GL_FOG);
|
||||
Tesselator& t = Tesselator::instance;
|
||||
minecraft->textures->loadAndBindTexture("gui/background.png");
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
float s = 32;
|
||||
float fvo = (float) vo;
|
||||
t.begin();
|
||||
t.color(0x404040);
|
||||
t.vertexUV(0, (float)height, 0, 0, height / s + fvo);
|
||||
t.vertexUV((float)width, (float)height, 0, width / s, (float)height / s + fvo);
|
||||
t.vertexUV((float)width, 0, 0, (float)width / s, 0 + fvo);
|
||||
t.vertexUV(0, 0, 0, 0, 0 + fvo);
|
||||
t.draw();
|
||||
}
|
||||
|
||||
bool Screen::isPauseScreen()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Screen::isErrorScreen()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Screen::isInGameScreen()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Screen::closeOnPlayerHurt() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void Screen::keyPressed( int eventKey )
|
||||
{
|
||||
if (eventKey == Keyboard::KEY_ESCAPE) {
|
||||
minecraft->setScreen(NULL);
|
||||
//minecraft->grabMouse();
|
||||
}
|
||||
|
||||
// pass key events to any text boxes first
|
||||
for (auto& textbox : textBoxes) {
|
||||
textbox->keyPressed(minecraft, eventKey);
|
||||
}
|
||||
|
||||
#ifdef TABBING
|
||||
if (minecraft->useTouchscreen())
|
||||
return;
|
||||
|
||||
|
||||
// "Tabbing" the buttons (walking with keys)
|
||||
const int tabButtonCount = tabButtons.size();
|
||||
if (!tabButtonCount)
|
||||
return;
|
||||
|
||||
Options& o = minecraft->options;
|
||||
if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_NEXT))
|
||||
if (++tabButtonIndex == tabButtonCount) tabButtonIndex = 0;
|
||||
if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_PREV))
|
||||
if (--tabButtonIndex == -1) tabButtonIndex = tabButtonCount-1;
|
||||
if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_OK)) {
|
||||
Button* button = tabButtons[tabButtonIndex];
|
||||
if (button->active) {
|
||||
minecraft->soundEngine->playUI("random.click", 1, 1);
|
||||
buttonClicked(button);
|
||||
}
|
||||
}
|
||||
|
||||
updateTabButtonSelection();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Screen::charPressed(char inputChar) {
|
||||
for (auto& textbox : textBoxes) {
|
||||
textbox->charPressed(minecraft, inputChar);
|
||||
}
|
||||
}
|
||||
|
||||
void Screen::updateTabButtonSelection()
|
||||
{
|
||||
#ifdef TABBING
|
||||
if (minecraft->useTouchscreen())
|
||||
return;
|
||||
|
||||
for (unsigned int i = 0; i < tabButtons.size(); ++i)
|
||||
tabButtons[i]->selected = (i == tabButtonIndex);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Screen::mouseClicked( int x, int y, int buttonNum )
|
||||
{
|
||||
if (buttonNum == MouseAction::ACTION_LEFT) {
|
||||
for (unsigned int i = 0; i < buttons.size(); ++i) {
|
||||
Button* button = buttons[i];
|
||||
//LOGI("Hit-testing button: %p\n", button);
|
||||
if (button->clicked(minecraft, x, y)) {
|
||||
button->setPressed();
|
||||
|
||||
//LOGI("Hit-test successful: %p\n", button);
|
||||
clickedButton = button;
|
||||
/*
|
||||
#if !defined(ANDROID) && !defined(__APPLE__) //if (!minecraft->isTouchscreen()) {
|
||||
minecraft->soundEngine->playUI("random.click", 1, 1);
|
||||
buttonClicked(button);
|
||||
#endif }
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// let textboxes see the click regardless
|
||||
for (auto& textbox : textBoxes) {
|
||||
textbox->mouseClicked(minecraft, x, y, buttonNum);
|
||||
}
|
||||
}
|
||||
|
||||
void Screen::mouseReleased( int x, int y, int buttonNum )
|
||||
{
|
||||
//LOGI("b_id: %d, (%p), text: %s\n", buttonNum, clickedButton, clickedButton?clickedButton->msg.c_str():"<null>");
|
||||
if (!clickedButton || buttonNum != MouseAction::ACTION_LEFT) return;
|
||||
|
||||
#if 1
|
||||
//#if defined(ANDROID) || defined(__APPLE__) //if (minecraft->isTouchscreen()) {
|
||||
for (unsigned int i = 0; i < buttons.size(); ++i) {
|
||||
Button* button = buttons[i];
|
||||
if (clickedButton == button && button->clicked(minecraft, x, y)) {
|
||||
buttonClicked(button);
|
||||
minecraft->soundEngine->playUI("random.click", 1, 1);
|
||||
clickedButton->released(x, y);
|
||||
}
|
||||
}
|
||||
# else // } else {
|
||||
clickedButton->released(x, y);
|
||||
#endif // }
|
||||
clickedButton = NULL;
|
||||
}
|
||||
|
||||
bool Screen::renderGameBehind() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Screen::hasClippingArea( IntRectangle& out )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void Screen::lostFocus() {
|
||||
for(std::vector<TextBox*>::iterator it = textBoxes.begin(); it != textBoxes.end(); ++it) {
|
||||
TextBox* tb = *it;
|
||||
tb->loseFocus(minecraft);
|
||||
}
|
||||
}
|
||||
|
||||
void Screen::toGUICoordinate( int& x, int& y ) {
|
||||
x = x * width / minecraft->width;
|
||||
y = y * height / minecraft->height - 1;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
//package net.minecraft.client.gui;
|
||||
|
||||
#include <vector>
|
||||
#include "GuiComponent.h"
|
||||
#include "GuiComponent.hpp"
|
||||
|
||||
class Font;
|
||||
class Minecraft;
|
||||
@@ -1,219 +1,219 @@
|
||||
#include "Button.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../renderer/Textures.h"
|
||||
|
||||
Button::Button(int id, const std::string& msg)
|
||||
: GuiElement(true, true, 0, 0, 200, 24),
|
||||
id(id),
|
||||
msg(msg),
|
||||
selected(false),
|
||||
_currentlyDown(false)
|
||||
{
|
||||
}
|
||||
|
||||
Button::Button( int id, int x, int y, const std::string& msg )
|
||||
: GuiElement(true, true, x, y, 200, 24),
|
||||
id(id),
|
||||
msg(msg),
|
||||
selected(false),
|
||||
_currentlyDown(false)
|
||||
{
|
||||
}
|
||||
|
||||
Button::Button( int id, int x, int y, int w, int h, const std::string& msg )
|
||||
: GuiElement(true, true, x, y, w, h),
|
||||
id(id),
|
||||
msg(msg),
|
||||
selected(false),
|
||||
_currentlyDown(false)
|
||||
{
|
||||
}
|
||||
|
||||
void Button::render( Minecraft* minecraft, int xm, int ym )
|
||||
{
|
||||
if (!visible) return;
|
||||
|
||||
/*
|
||||
minecraft->textures->loadAndBindTexture("gui/gui.png");
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
|
||||
//printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym);
|
||||
int yImage = getYImage(hovered || selected);
|
||||
|
||||
blit(x, y, 0, 46 + yImage * 20, w / 2, h, 0, 20);
|
||||
blit(x + w / 2, y, 200 - w / 2, 46 + yImage * 20, w / 2, h, 0, 20);
|
||||
*/
|
||||
|
||||
renderBg(minecraft, xm, ym);
|
||||
renderFace(minecraft, xm , ym);
|
||||
}
|
||||
|
||||
void Button::released( int mx, int my ) {
|
||||
_currentlyDown = false;
|
||||
}
|
||||
|
||||
bool Button::clicked( Minecraft* minecraft, int mx, int my )
|
||||
{
|
||||
return active && mx >= x && my >= y && mx < x + width && my < y + height;
|
||||
}
|
||||
|
||||
void Button::setPressed() {
|
||||
_currentlyDown = true;
|
||||
}
|
||||
|
||||
int Button::getYImage( bool hovered )
|
||||
{
|
||||
int res = 1;
|
||||
if (!active) res = 0;
|
||||
else if (hovered) res = 2;
|
||||
return res;
|
||||
}
|
||||
|
||||
void Button::renderFace(Minecraft* mc, int xm, int ym) {
|
||||
Font* font = mc->font;
|
||||
if (!active) {
|
||||
drawCenteredString(font, msg, x + width / 2, y + (height - 8) / 2, 0xffa0a0a0);
|
||||
} else {
|
||||
if (hovered(mc, xm, ym) || selected) {
|
||||
drawCenteredString(font, msg, x + width / 2, y + (height - 8) / 2, 0xffffa0);
|
||||
} else {
|
||||
drawCenteredString(font, msg, x + width / 2, y + (height - 8) / 2, 0xe0e0e0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Button::renderBg( Minecraft* minecraft, int xm, int ym )
|
||||
{
|
||||
minecraft->textures->loadAndBindTexture("gui/gui.png");
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
|
||||
//printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym);
|
||||
int yImage = getYImage(selected || hovered(minecraft, xm, ym));;
|
||||
|
||||
blit(x, y, 0, 46 + yImage * 20, width / 2, height, 0, 20);
|
||||
blit(x + width / 2, y, 200 - width / 2, 46 + yImage * 20, width / 2, height, 0, 20);
|
||||
}
|
||||
|
||||
bool Button::hovered(Minecraft* minecraft, int xm , int ym) {
|
||||
return minecraft->useTouchscreen()? (_currentlyDown && isInside(xm, ym)) : isInside(xm, ym);
|
||||
}
|
||||
|
||||
bool Button::isInside( int xm, int ym ) {
|
||||
return xm >= x && ym >= y && xm < x + width && ym < y + height;
|
||||
}
|
||||
|
||||
//
|
||||
// BlankButton
|
||||
//
|
||||
BlankButton::BlankButton(int id)
|
||||
: super(id, "")
|
||||
{
|
||||
visible = false;
|
||||
}
|
||||
|
||||
BlankButton::BlankButton(int id, int x, int y, int w, int h)
|
||||
: super(id, x, y, w, h, "")
|
||||
{
|
||||
visible = false;
|
||||
}
|
||||
|
||||
//
|
||||
// The Touch-interface button
|
||||
//
|
||||
namespace Touch {
|
||||
|
||||
TButton::TButton(int id, const std::string& msg)
|
||||
: super(id, msg)
|
||||
{
|
||||
width = 66;
|
||||
height = 26;
|
||||
}
|
||||
|
||||
TButton::TButton( int id, int x, int y, const std::string& msg )
|
||||
: super(id, x, y, msg)
|
||||
{
|
||||
width = 66;
|
||||
height = 26;
|
||||
}
|
||||
|
||||
TButton::TButton( int id, int x, int y, int w, int h, const std::string& msg )
|
||||
: super(id, x, y, w, h, msg)
|
||||
{
|
||||
}
|
||||
|
||||
void TButton::renderBg( Minecraft* minecraft, int xm, int ym )
|
||||
{
|
||||
bool hovered = active && (minecraft->useTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : isInside(xm, ym));
|
||||
// bool hovered = active && (_currentlyDown && isInside(xm, ym));
|
||||
|
||||
minecraft->textures->loadAndBindTexture("gui/touchgui.png");
|
||||
|
||||
//printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym);
|
||||
if (active)
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
else
|
||||
glColor4f2(0.5f, 0.5f, 0.5f, 1);
|
||||
|
||||
blit(x, y, hovered?66:0, 0, width, height, 66, 26);
|
||||
//blit(x + w / 2, y, 200 - w / 2, 46 + yImage * 20, w / 2, h, 0, 20);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Header spacing in Touchscreen mode
|
||||
//
|
||||
THeader::THeader(int id, const std::string& msg)
|
||||
: super(id, msg),
|
||||
xText(-99999)
|
||||
{
|
||||
active = false;
|
||||
width = 66;
|
||||
height = 26;
|
||||
}
|
||||
|
||||
THeader::THeader( int id, int x, int y, const std::string& msg )
|
||||
: super(id, x, y, msg),
|
||||
xText(-99999)
|
||||
{
|
||||
active = false;
|
||||
width = 66;
|
||||
height = 26;
|
||||
}
|
||||
|
||||
THeader::THeader( int id, int x, int y, int w, int h, const std::string& msg )
|
||||
: super(id, x, y, w, h, msg),
|
||||
xText(-99999)
|
||||
{
|
||||
active = false;
|
||||
}
|
||||
|
||||
void THeader::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
Font* font = minecraft->font;
|
||||
renderBg(minecraft, xm, ym);
|
||||
|
||||
int xx = x + width/2;
|
||||
if (xText != -99999)
|
||||
xx = xText;
|
||||
drawCenteredString(font, msg, xx, y + (height - 8) / 2, 0xe0e0e0);
|
||||
}
|
||||
|
||||
void THeader::renderBg( Minecraft* minecraft, int xm, int ym )
|
||||
{
|
||||
minecraft->textures->loadAndBindTexture("gui/touchgui.png");
|
||||
|
||||
//printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym);
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
|
||||
// Left cap
|
||||
blit(x, y, 150, 26, 2, height-1, 2, 25);
|
||||
// Middle
|
||||
blit(x+2, y, 153, 26, width-3, height-1, 8, 25);
|
||||
// Right cap
|
||||
blit(x+width-2, y, 162, 26, 2, height-1, 2, 25);
|
||||
// Shadow
|
||||
glEnable2(GL_BLEND);
|
||||
glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
blit(x, y+height-1, 153, 52, width, 3, 8, 3);
|
||||
}
|
||||
|
||||
};
|
||||
#include "Button.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "client/renderer/Textures.hpp"
|
||||
|
||||
Button::Button(int id, const std::string& msg)
|
||||
: GuiElement(true, true, 0, 0, 200, 24),
|
||||
id(id),
|
||||
msg(msg),
|
||||
selected(false),
|
||||
_currentlyDown(false)
|
||||
{
|
||||
}
|
||||
|
||||
Button::Button( int id, int x, int y, const std::string& msg )
|
||||
: GuiElement(true, true, x, y, 200, 24),
|
||||
id(id),
|
||||
msg(msg),
|
||||
selected(false),
|
||||
_currentlyDown(false)
|
||||
{
|
||||
}
|
||||
|
||||
Button::Button( int id, int x, int y, int w, int h, const std::string& msg )
|
||||
: GuiElement(true, true, x, y, w, h),
|
||||
id(id),
|
||||
msg(msg),
|
||||
selected(false),
|
||||
_currentlyDown(false)
|
||||
{
|
||||
}
|
||||
|
||||
void Button::render( Minecraft* minecraft, int xm, int ym )
|
||||
{
|
||||
if (!visible) return;
|
||||
|
||||
/*
|
||||
minecraft->textures->loadAndBindTexture("gui/gui.png");
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
|
||||
//printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym);
|
||||
int yImage = getYImage(hovered || selected);
|
||||
|
||||
blit(x, y, 0, 46 + yImage * 20, w / 2, h, 0, 20);
|
||||
blit(x + w / 2, y, 200 - w / 2, 46 + yImage * 20, w / 2, h, 0, 20);
|
||||
*/
|
||||
|
||||
renderBg(minecraft, xm, ym);
|
||||
renderFace(minecraft, xm , ym);
|
||||
}
|
||||
|
||||
void Button::released( int mx, int my ) {
|
||||
_currentlyDown = false;
|
||||
}
|
||||
|
||||
bool Button::clicked( Minecraft* minecraft, int mx, int my )
|
||||
{
|
||||
return active && mx >= x && my >= y && mx < x + width && my < y + height;
|
||||
}
|
||||
|
||||
void Button::setPressed() {
|
||||
_currentlyDown = true;
|
||||
}
|
||||
|
||||
int Button::getYImage( bool hovered )
|
||||
{
|
||||
int res = 1;
|
||||
if (!active) res = 0;
|
||||
else if (hovered) res = 2;
|
||||
return res;
|
||||
}
|
||||
|
||||
void Button::renderFace(Minecraft* mc, int xm, int ym) {
|
||||
Font* font = mc->font;
|
||||
if (!active) {
|
||||
drawCenteredString(font, msg, x + width / 2, y + (height - 8) / 2, 0xffa0a0a0);
|
||||
} else {
|
||||
if (hovered(mc, xm, ym) || selected) {
|
||||
drawCenteredString(font, msg, x + width / 2, y + (height - 8) / 2, 0xffffa0);
|
||||
} else {
|
||||
drawCenteredString(font, msg, x + width / 2, y + (height - 8) / 2, 0xe0e0e0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Button::renderBg( Minecraft* minecraft, int xm, int ym )
|
||||
{
|
||||
minecraft->textures->loadAndBindTexture("gui/gui.png");
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
|
||||
//printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym);
|
||||
int yImage = getYImage(selected || hovered(minecraft, xm, ym));;
|
||||
|
||||
blit(x, y, 0, 46 + yImage * 20, width / 2, height, 0, 20);
|
||||
blit(x + width / 2, y, 200 - width / 2, 46 + yImage * 20, width / 2, height, 0, 20);
|
||||
}
|
||||
|
||||
bool Button::hovered(Minecraft* minecraft, int xm , int ym) {
|
||||
return minecraft->useTouchscreen()? (_currentlyDown && isInside(xm, ym)) : isInside(xm, ym);
|
||||
}
|
||||
|
||||
bool Button::isInside( int xm, int ym ) {
|
||||
return xm >= x && ym >= y && xm < x + width && ym < y + height;
|
||||
}
|
||||
|
||||
//
|
||||
// BlankButton
|
||||
//
|
||||
BlankButton::BlankButton(int id)
|
||||
: super(id, "")
|
||||
{
|
||||
visible = false;
|
||||
}
|
||||
|
||||
BlankButton::BlankButton(int id, int x, int y, int w, int h)
|
||||
: super(id, x, y, w, h, "")
|
||||
{
|
||||
visible = false;
|
||||
}
|
||||
|
||||
//
|
||||
// The Touch-interface button
|
||||
//
|
||||
namespace Touch {
|
||||
|
||||
TButton::TButton(int id, const std::string& msg)
|
||||
: super(id, msg)
|
||||
{
|
||||
width = 66;
|
||||
height = 26;
|
||||
}
|
||||
|
||||
TButton::TButton( int id, int x, int y, const std::string& msg )
|
||||
: super(id, x, y, msg)
|
||||
{
|
||||
width = 66;
|
||||
height = 26;
|
||||
}
|
||||
|
||||
TButton::TButton( int id, int x, int y, int w, int h, const std::string& msg )
|
||||
: super(id, x, y, w, h, msg)
|
||||
{
|
||||
}
|
||||
|
||||
void TButton::renderBg( Minecraft* minecraft, int xm, int ym )
|
||||
{
|
||||
bool hovered = active && (minecraft->useTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : isInside(xm, ym));
|
||||
// bool hovered = active && (_currentlyDown && isInside(xm, ym));
|
||||
|
||||
minecraft->textures->loadAndBindTexture("gui/touchgui.png");
|
||||
|
||||
//printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym);
|
||||
if (active)
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
else
|
||||
glColor4f2(0.5f, 0.5f, 0.5f, 1);
|
||||
|
||||
blit(x, y, hovered?66:0, 0, width, height, 66, 26);
|
||||
//blit(x + w / 2, y, 200 - w / 2, 46 + yImage * 20, w / 2, h, 0, 20);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Header spacing in Touchscreen mode
|
||||
//
|
||||
THeader::THeader(int id, const std::string& msg)
|
||||
: super(id, msg),
|
||||
xText(-99999)
|
||||
{
|
||||
active = false;
|
||||
width = 66;
|
||||
height = 26;
|
||||
}
|
||||
|
||||
THeader::THeader( int id, int x, int y, const std::string& msg )
|
||||
: super(id, x, y, msg),
|
||||
xText(-99999)
|
||||
{
|
||||
active = false;
|
||||
width = 66;
|
||||
height = 26;
|
||||
}
|
||||
|
||||
THeader::THeader( int id, int x, int y, int w, int h, const std::string& msg )
|
||||
: super(id, x, y, w, h, msg),
|
||||
xText(-99999)
|
||||
{
|
||||
active = false;
|
||||
}
|
||||
|
||||
void THeader::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
Font* font = minecraft->font;
|
||||
renderBg(minecraft, xm, ym);
|
||||
|
||||
int xx = x + width/2;
|
||||
if (xText != -99999)
|
||||
xx = xText;
|
||||
drawCenteredString(font, msg, xx, y + (height - 8) / 2, 0xe0e0e0);
|
||||
}
|
||||
|
||||
void THeader::renderBg( Minecraft* minecraft, int xm, int ym )
|
||||
{
|
||||
minecraft->textures->loadAndBindTexture("gui/touchgui.png");
|
||||
|
||||
//printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym);
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
|
||||
// Left cap
|
||||
blit(x, y, 150, 26, 2, height-1, 2, 25);
|
||||
// Middle
|
||||
blit(x+2, y, 153, 26, width-3, height-1, 8, 25);
|
||||
// Right cap
|
||||
blit(x+width-2, y, 162, 26, 2, height-1, 2, 25);
|
||||
// Shadow
|
||||
glEnable2(GL_BLEND);
|
||||
glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
blit(x, y+height-1, 153, 52, width, 3, 8, 3);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
//package net.minecraft.client.gui;
|
||||
|
||||
#include <string>
|
||||
#include "GuiElement.h"
|
||||
#include "../../Options.h"
|
||||
#include "GuiElement.hpp"
|
||||
#include "client/Options.hpp"
|
||||
|
||||
class Font;
|
||||
class Minecraft;
|
||||
@@ -1 +1 @@
|
||||
#include "GuiElement.h"
|
||||
#include "GuiElement.hpp"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "Button.h"
|
||||
#include "Button.hpp"
|
||||
|
||||
class GButton: public Button {
|
||||
typedef Button super;
|
||||
@@ -1,20 +1,20 @@
|
||||
#include "GuiElement.h"
|
||||
|
||||
GuiElement::GuiElement( bool active/*=false*/, bool visible/*=true*/, int x /*= 0*/, int y /*= 0*/, int width/*=24*/, int height/*=24*/ )
|
||||
: active(active),
|
||||
visible(visible),
|
||||
x(x),
|
||||
y(y),
|
||||
width(width),
|
||||
height(height) {
|
||||
|
||||
}
|
||||
|
||||
bool GuiElement::pointInside( int x, int y ) {
|
||||
if(x >= this->x && x < this->x + this->width) {
|
||||
if(y >= this->y && y < this->y + this->height) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#include "GuiElement.hpp"
|
||||
|
||||
GuiElement::GuiElement( bool active/*=false*/, bool visible/*=true*/, int x /*= 0*/, int y /*= 0*/, int width/*=24*/, int height/*=24*/ )
|
||||
: active(active),
|
||||
visible(visible),
|
||||
x(x),
|
||||
y(y),
|
||||
width(width),
|
||||
height(height) {
|
||||
|
||||
}
|
||||
|
||||
bool GuiElement::pointInside( int x, int y ) {
|
||||
if(x >= this->x && x < this->x + this->width) {
|
||||
if(y >= this->y && y < this->y + this->height) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "../GuiComponent.h"
|
||||
#include "client/gui/GuiComponent.hpp"
|
||||
|
||||
class Tesselator;
|
||||
class Minecraft;
|
||||
@@ -1,66 +1,66 @@
|
||||
#include "GuiElementContainer.h"
|
||||
#include <algorithm>
|
||||
GuiElementContainer::GuiElementContainer( bool active/*=false*/, bool visible/*=true*/, int x /*= 0*/, int y /*= 0*/, int width/*=24*/, int height/*=24*/ )
|
||||
: GuiElement(active, visible, x, y, width, height) {
|
||||
|
||||
}
|
||||
|
||||
GuiElementContainer::~GuiElementContainer() {
|
||||
while(!children.empty()) {
|
||||
GuiElement* element = children.back();
|
||||
children.pop_back();
|
||||
delete element;
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElementContainer::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->render(minecraft, xm, ym);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElementContainer::setupPositions() {
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->setupPositions();
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElementContainer::addChild( GuiElement* element ) {
|
||||
children.push_back(element);
|
||||
}
|
||||
|
||||
void GuiElementContainer::removeChild( GuiElement* element ) {
|
||||
std::vector<GuiElement*>::iterator it = std::find(children.begin(), children.end(), element);
|
||||
if(it != children.end())
|
||||
children.erase(it);
|
||||
}
|
||||
|
||||
void GuiElementContainer::tick( Minecraft* minecraft ) {
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->tick(minecraft);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElementContainer::mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->mouseClicked(minecraft, x, y, buttonNum);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElementContainer::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->mouseReleased(minecraft, x, y, buttonNum);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElementContainer::keyPressed(Minecraft* minecraft, int key) {
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->keyPressed(minecraft, key);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElementContainer::charPressed(Minecraft* minecraft, char key) {
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->charPressed(minecraft, key);
|
||||
}
|
||||
#include "GuiElementContainer.hpp"
|
||||
#include <algorithm>
|
||||
GuiElementContainer::GuiElementContainer( bool active/*=false*/, bool visible/*=true*/, int x /*= 0*/, int y /*= 0*/, int width/*=24*/, int height/*=24*/ )
|
||||
: GuiElement(active, visible, x, y, width, height) {
|
||||
|
||||
}
|
||||
|
||||
GuiElementContainer::~GuiElementContainer() {
|
||||
while(!children.empty()) {
|
||||
GuiElement* element = children.back();
|
||||
children.pop_back();
|
||||
delete element;
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElementContainer::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->render(minecraft, xm, ym);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElementContainer::setupPositions() {
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->setupPositions();
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElementContainer::addChild( GuiElement* element ) {
|
||||
children.push_back(element);
|
||||
}
|
||||
|
||||
void GuiElementContainer::removeChild( GuiElement* element ) {
|
||||
std::vector<GuiElement*>::iterator it = std::find(children.begin(), children.end(), element);
|
||||
if(it != children.end())
|
||||
children.erase(it);
|
||||
}
|
||||
|
||||
void GuiElementContainer::tick( Minecraft* minecraft ) {
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->tick(minecraft);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElementContainer::mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->mouseClicked(minecraft, x, y, buttonNum);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElementContainer::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->mouseReleased(minecraft, x, y, buttonNum);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElementContainer::keyPressed(Minecraft* minecraft, int key) {
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->keyPressed(minecraft, key);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElementContainer::charPressed(Minecraft* minecraft, char key) {
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->charPressed(minecraft, key);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "GuiElement.h"
|
||||
#include "GuiElement.hpp"
|
||||
#include <vector>
|
||||
class Tesselator;
|
||||
class Minecraft;
|
||||
@@ -1,135 +1,135 @@
|
||||
#include "ImageButton.h"
|
||||
#include "../../renderer/Tesselator.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../../platform/log.h"
|
||||
#include "../../../util/Mth.h"
|
||||
#include "../../renderer/Textures.h"
|
||||
#include <client/Option.h>
|
||||
|
||||
|
||||
ImageButton::ImageButton(int id, const std::string& msg)
|
||||
: super(id, msg)
|
||||
{
|
||||
setupDefault();
|
||||
}
|
||||
|
||||
ImageButton::ImageButton(int id, const std::string& msg, const ImageDef& imagedef)
|
||||
: super(id, msg),
|
||||
_imageDef(imagedef)
|
||||
{
|
||||
setupDefault();
|
||||
}
|
||||
|
||||
void ImageButton::setupDefault() {
|
||||
width = 48;
|
||||
height = 48;
|
||||
scaleWhenPressed = true;
|
||||
}
|
||||
|
||||
void ImageButton::setImageDef(const ImageDef& imageDef, bool setButtonSize) {
|
||||
_imageDef = imageDef;
|
||||
if (setButtonSize) {
|
||||
width = (int)_imageDef.width;
|
||||
height = (int)_imageDef.height;
|
||||
}
|
||||
}
|
||||
|
||||
void ImageButton::render(Minecraft* minecraft, int xm, int ym) {
|
||||
if (!visible) return;
|
||||
|
||||
Font* font = minecraft->font;
|
||||
|
||||
//minecraft->textures->loadAndBindTexture("gui/gui.png");
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
|
||||
bool hovered = active && (minecraft->useTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : isInside(xm, ym));
|
||||
bool IsSecondImage = isSecondImage(hovered);
|
||||
|
||||
//printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym);
|
||||
//int yImage = getYImage(hovered || selected);
|
||||
|
||||
//blit(x, y, 0, 46 + yImage * 20, w / 2, h, 0, 20);
|
||||
//blit(x + w / 2, y, 200 - w / 2, 46 + yImage * 20, w / 2, h, 0, 20);
|
||||
|
||||
renderBg(minecraft, xm, ym);
|
||||
|
||||
TextureId texId = (_imageDef.name.length() > 0)? minecraft->textures->loadAndBindTexture(_imageDef.name) : Textures::InvalidId;
|
||||
if ( Textures::isTextureIdValid(texId) ) {
|
||||
const ImageDef& d = _imageDef;
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
t.begin();
|
||||
if (!active) t.color(0xff808080);
|
||||
//else if (hovered||selected) t.color(0xffffffff);
|
||||
//else t.color(0xffe0e0e0);
|
||||
else t.color(0xffffffff);
|
||||
|
||||
float hx = ((float) d.width) * 0.5f;
|
||||
float hy = ((float) d.height) * 0.5f;
|
||||
const float cx = ((float)x+d.x) + hx;
|
||||
const float cy = ((float)y+d.y) + hy;
|
||||
if (scaleWhenPressed && hovered) {
|
||||
hx *= 0.95f;
|
||||
hy *= 0.95f;
|
||||
}
|
||||
|
||||
const IntRectangle* src = _imageDef.getSrc();
|
||||
if (src) {
|
||||
const TextureData* d = minecraft->textures->getTemporaryTextureData(texId);
|
||||
if (d != NULL) {
|
||||
float u0 = (src->x+(IsSecondImage?src->w:0)) / (float)d->w;
|
||||
float u1 = (src->x+(IsSecondImage?2*src->w:src->w)) / (float)d->w;
|
||||
float v0 = src->y / (float)d->h;
|
||||
float v1 = (src->y+src->h) / (float)d->h;
|
||||
t.vertexUV(cx-hx, cy-hy, blitOffset, u0, v0);
|
||||
t.vertexUV(cx-hx, cy+hy, blitOffset, u0, v1);
|
||||
t.vertexUV(cx+hx, cy+hy, blitOffset, u1, v1);
|
||||
t.vertexUV(cx+hx, cy-hy, blitOffset, u1, v0);
|
||||
}
|
||||
} else {
|
||||
t.vertexUV(cx-hx, cy-hy, blitOffset, 0, 0);
|
||||
t.vertexUV(cx-hx, cy+hy, blitOffset, 0, 1);
|
||||
t.vertexUV(cx+hx, cy+hy, blitOffset, 1, 1);
|
||||
t.vertexUV(cx+hx, cy-hy, blitOffset, 1, 0);
|
||||
}
|
||||
t.draw();
|
||||
}
|
||||
//blit(0, 0, 0, 0, 64, 64, 256, 256);
|
||||
|
||||
//LOGI("%d %d\n", x+d.x, x+d.x+d.w);
|
||||
|
||||
if (!active) {
|
||||
drawCenteredString(font, msg, x + width / 2, y + 16/*(h - 16)*/, 0xffa0a0a0);
|
||||
} else {
|
||||
if (hovered || selected) {
|
||||
drawCenteredString(font, msg, x + width / 2, y + 17/*(h - 16)*/, 0xffffa0);
|
||||
} else {
|
||||
drawCenteredString(font, msg, x + width / 2, y + 16/*(h - 48)*/, 0xe0e0e0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// A toggleable Button
|
||||
//
|
||||
OptionButton::OptionButton(OptionId option) : m_optId(option), super(ButtonId, "") {}
|
||||
|
||||
void OptionButton::toggle(Options* options) {
|
||||
options->toggle(m_optId);
|
||||
|
||||
// Update graphics here
|
||||
updateImage(options);
|
||||
}
|
||||
|
||||
void OptionButton::updateImage(Options* options) {
|
||||
_secondImage = options->getBooleanValue(m_optId);
|
||||
}
|
||||
|
||||
void OptionButton::mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
if(buttonNum == MouseAction::ACTION_LEFT) {
|
||||
if(clicked(minecraft, x, y)) {
|
||||
toggle(&minecraft->options);
|
||||
}
|
||||
}
|
||||
}
|
||||
#include "ImageButton.hpp"
|
||||
#include "client/renderer/Tesselator.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "platform/log.hpp"
|
||||
#include "util/Mth.hpp"
|
||||
#include "client/renderer/Textures.hpp"
|
||||
#include <client/Option.hpp>
|
||||
|
||||
|
||||
ImageButton::ImageButton(int id, const std::string& msg)
|
||||
: super(id, msg)
|
||||
{
|
||||
setupDefault();
|
||||
}
|
||||
|
||||
ImageButton::ImageButton(int id, const std::string& msg, const ImageDef& imagedef)
|
||||
: super(id, msg),
|
||||
_imageDef(imagedef)
|
||||
{
|
||||
setupDefault();
|
||||
}
|
||||
|
||||
void ImageButton::setupDefault() {
|
||||
width = 48;
|
||||
height = 48;
|
||||
scaleWhenPressed = true;
|
||||
}
|
||||
|
||||
void ImageButton::setImageDef(const ImageDef& imageDef, bool setButtonSize) {
|
||||
_imageDef = imageDef;
|
||||
if (setButtonSize) {
|
||||
width = (int)_imageDef.width;
|
||||
height = (int)_imageDef.height;
|
||||
}
|
||||
}
|
||||
|
||||
void ImageButton::render(Minecraft* minecraft, int xm, int ym) {
|
||||
if (!visible) return;
|
||||
|
||||
Font* font = minecraft->font;
|
||||
|
||||
//minecraft->textures->loadAndBindTexture("gui/gui.png");
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
|
||||
bool hovered = active && (minecraft->useTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : isInside(xm, ym));
|
||||
bool IsSecondImage = isSecondImage(hovered);
|
||||
|
||||
//printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym);
|
||||
//int yImage = getYImage(hovered || selected);
|
||||
|
||||
//blit(x, y, 0, 46 + yImage * 20, w / 2, h, 0, 20);
|
||||
//blit(x + w / 2, y, 200 - w / 2, 46 + yImage * 20, w / 2, h, 0, 20);
|
||||
|
||||
renderBg(minecraft, xm, ym);
|
||||
|
||||
TextureId texId = (_imageDef.name.length() > 0)? minecraft->textures->loadAndBindTexture(_imageDef.name) : Textures::InvalidId;
|
||||
if ( Textures::isTextureIdValid(texId) ) {
|
||||
const ImageDef& d = _imageDef;
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
t.begin();
|
||||
if (!active) t.color(0xff808080);
|
||||
//else if (hovered||selected) t.color(0xffffffff);
|
||||
//else t.color(0xffe0e0e0);
|
||||
else t.color(0xffffffff);
|
||||
|
||||
float hx = ((float) d.width) * 0.5f;
|
||||
float hy = ((float) d.height) * 0.5f;
|
||||
const float cx = ((float)x+d.x) + hx;
|
||||
const float cy = ((float)y+d.y) + hy;
|
||||
if (scaleWhenPressed && hovered) {
|
||||
hx *= 0.95f;
|
||||
hy *= 0.95f;
|
||||
}
|
||||
|
||||
const IntRectangle* src = _imageDef.getSrc();
|
||||
if (src) {
|
||||
const TextureData* d = minecraft->textures->getTemporaryTextureData(texId);
|
||||
if (d != NULL) {
|
||||
float u0 = (src->x+(IsSecondImage?src->w:0)) / (float)d->w;
|
||||
float u1 = (src->x+(IsSecondImage?2*src->w:src->w)) / (float)d->w;
|
||||
float v0 = src->y / (float)d->h;
|
||||
float v1 = (src->y+src->h) / (float)d->h;
|
||||
t.vertexUV(cx-hx, cy-hy, blitOffset, u0, v0);
|
||||
t.vertexUV(cx-hx, cy+hy, blitOffset, u0, v1);
|
||||
t.vertexUV(cx+hx, cy+hy, blitOffset, u1, v1);
|
||||
t.vertexUV(cx+hx, cy-hy, blitOffset, u1, v0);
|
||||
}
|
||||
} else {
|
||||
t.vertexUV(cx-hx, cy-hy, blitOffset, 0, 0);
|
||||
t.vertexUV(cx-hx, cy+hy, blitOffset, 0, 1);
|
||||
t.vertexUV(cx+hx, cy+hy, blitOffset, 1, 1);
|
||||
t.vertexUV(cx+hx, cy-hy, blitOffset, 1, 0);
|
||||
}
|
||||
t.draw();
|
||||
}
|
||||
//blit(0, 0, 0, 0, 64, 64, 256, 256);
|
||||
|
||||
//LOGI("%d %d\n", x+d.x, x+d.x+d.w);
|
||||
|
||||
if (!active) {
|
||||
drawCenteredString(font, msg, x + width / 2, y + 16/*(h - 16)*/, 0xffa0a0a0);
|
||||
} else {
|
||||
if (hovered || selected) {
|
||||
drawCenteredString(font, msg, x + width / 2, y + 17/*(h - 16)*/, 0xffffa0);
|
||||
} else {
|
||||
drawCenteredString(font, msg, x + width / 2, y + 16/*(h - 48)*/, 0xe0e0e0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// A toggleable Button
|
||||
//
|
||||
OptionButton::OptionButton(OptionId option) : m_optId(option), super(ButtonId, "") {}
|
||||
|
||||
void OptionButton::toggle(Options* options) {
|
||||
options->toggle(m_optId);
|
||||
|
||||
// Update graphics here
|
||||
updateImage(options);
|
||||
}
|
||||
|
||||
void OptionButton::updateImage(Options* options) {
|
||||
_secondImage = options->getBooleanValue(m_optId);
|
||||
}
|
||||
|
||||
void OptionButton::mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
if(buttonNum == MouseAction::ACTION_LEFT) {
|
||||
if(clicked(minecraft, x, y)) {
|
||||
toggle(&minecraft->options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "Button.h"
|
||||
#include "Button.hpp"
|
||||
|
||||
typedef struct IntRectangle {
|
||||
IntRectangle()
|
||||
@@ -1,206 +1,206 @@
|
||||
#include "InventoryPane.h"
|
||||
#include "../Gui.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../player/input/touchscreen/TouchAreaModel.h"
|
||||
#include "../../renderer/entity/ItemRenderer.h"
|
||||
#include "../../renderer/Tesselator.h"
|
||||
#include "../../renderer/Textures.h"
|
||||
#include "../../../world/item/ItemInstance.h"
|
||||
#include "../../../world/entity/player/Inventory.h"
|
||||
|
||||
namespace Touch {
|
||||
|
||||
static const int By = 6; // Border Frame height
|
||||
|
||||
InventoryPane::InventoryPane( IInventoryPaneCallback* screen, Minecraft* mc, const IntRectangle& rect, int paneWidth, float clickMarginH, int numItems, int itemSize, int itemBorderSize)
|
||||
: screen(screen),
|
||||
mc(mc),
|
||||
paneWidth(paneWidth),
|
||||
rect(rect),
|
||||
super(
|
||||
SF_LockX|/*SF_Scissor|*/SF_ShowScrollbar|SF_NoHoldSelect,
|
||||
rect, // Pane rect
|
||||
IntRectangle(0, 0, itemSize, itemSize), // Item rect
|
||||
0, numItems, Gui::GuiScale),
|
||||
BorderPixels(itemBorderSize),
|
||||
lastItemIndex(-1),
|
||||
lastItemTicks(-1),
|
||||
fillMarginX(2),
|
||||
fillMarginY(4),
|
||||
markerType(1),
|
||||
markerIndex(-1),
|
||||
markerShare(0),
|
||||
renderDecorations(true)
|
||||
{
|
||||
_clickArea = new RectangleArea(0, 0, 0, 0);
|
||||
area._x0 = rect.x - clickMarginH;
|
||||
area._x1 = rect.x + rect.w + clickMarginH;
|
||||
area._y0 -= By;
|
||||
area._y1 += By;
|
||||
|
||||
/*
|
||||
const int left = bbox.x + (bbox.w - paneWidth) / 2;
|
||||
bg.x = left;
|
||||
bg.w = left + paneWidth; // @note: read as x1, not width
|
||||
bg.y = bbox.y - fillMarginY;
|
||||
bg.h = bbox.y + bbox.h + fillMarginY; // @note: read as y1, not width
|
||||
*/
|
||||
}
|
||||
|
||||
InventoryPane::~InventoryPane() {
|
||||
delete _clickArea;
|
||||
}
|
||||
|
||||
void InventoryPane::renderBatch( std::vector<GridItem>& items, float alpha )
|
||||
{
|
||||
//fill(bg.x, bg.y, bg.w, bg.h, 0xff333333);
|
||||
fill((float)(bbox.x-fillMarginX-1), (float)(bbox.y-fillMarginY), (float)(bbox.x + bbox.w + fillMarginX+1), (float)(bbox.y + bbox.h + fillMarginY), 0xff333333);
|
||||
//fill(0.0f, (float)(bbox.y-fillMarginY), 400.0f, (float)(bbox.y + bbox.h + fillMarginY), 0xff333333);//(float)(bbox.x-fillMarginX), (float)(bbox.y-fillMarginY), (float)(bbox.x + bbox.w + fillMarginX), (float)(bbox.y + bbox.h + fillMarginY), 0xff333333);
|
||||
glEnable2(GL_BLEND);
|
||||
glDisable2(GL_ALPHA_TEST);
|
||||
std::vector<const ItemInstance*> inventoryItems = screen->getItems(this);
|
||||
|
||||
glEnable2(GL_SCISSOR_TEST);
|
||||
GLuint x = (GLuint)(screenScale * bbox.x);
|
||||
GLuint y = mc->height - (GLuint)(screenScale * (bbox.y + bbox.h));
|
||||
GLuint w = (GLuint)(screenScale * bbox.w);
|
||||
GLuint h = (GLuint)(screenScale * bbox.h);
|
||||
glScissor(x, y, w, h);
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
t.beginOverride();
|
||||
t.colorABGR(0xffffffff);
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
GridItem& item = items[i];
|
||||
blit(item.xf, item.yf, 200, 46, (float)itemBbox.w, (float)itemBbox.h, 16, 16);
|
||||
}
|
||||
mc->textures->loadAndBindTexture("gui/gui.png");
|
||||
t.endOverrideAndDraw();
|
||||
|
||||
GridItem* marked = NULL;
|
||||
float mxx, myy;
|
||||
|
||||
t.beginOverride();
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
GridItem& item = items[i];
|
||||
int j = item.id;
|
||||
const ItemInstance* citem = inventoryItems[j];
|
||||
if (!citem) continue;
|
||||
|
||||
bool allowed = true;
|
||||
|
||||
t.enableColor();
|
||||
//#ifdef DEMO_MODE //@huge @attn
|
||||
if (!screen->isAllowed(j)) { allowed = false; t.color( 64, 64, 64); }
|
||||
else
|
||||
//#endif
|
||||
if (lastItemTicks > 0 && lastItemIndex == j) {
|
||||
int gv = 255 - lastItemTicks * 15;
|
||||
t.color(gv, gv, gv, (allowed && citem->count <= 0)?0x60:0xff);
|
||||
} else {
|
||||
t.color(255, 255, 255, (allowed && citem->count <= 0)?0x60:0xff);
|
||||
}
|
||||
t.noColor();
|
||||
float xx = Gui::floorAlignToScreenPixel(item.xf + BorderPixels + 4);
|
||||
float yy = Gui::floorAlignToScreenPixel(item.yf + BorderPixels + 4);
|
||||
ItemRenderer::renderGuiItem(NULL, mc->textures, citem, xx, yy, 16, 16, false);
|
||||
|
||||
if (j == markerIndex && markerShare >= 0)
|
||||
marked = &item, mxx = xx, myy = yy;
|
||||
|
||||
}
|
||||
t.endOverrideAndDraw();
|
||||
|
||||
if (marked) {
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
const float yy0 = myy - 5.0f;
|
||||
const float yy1 = yy0 + 2;
|
||||
fill(mxx, yy0, mxx + 16.0f, yy1, 0xff606060);
|
||||
fill(mxx, yy0, mxx + markerShare * 16.0f, yy1, markerType==1?0xff00ff00:0xff476543);
|
||||
glEnable2(GL_BLEND);
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
|
||||
if (!mc->isCreativeMode()) {
|
||||
const float ikText = Gui::InvGuiScale + Gui::InvGuiScale;
|
||||
const float kText = 0.5f * Gui::GuiScale;
|
||||
t.beginOverride();
|
||||
t.scale2d(ikText, ikText);
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
GridItem& item = items[i];
|
||||
const ItemInstance* citem = inventoryItems[item.id];
|
||||
if (!citem) continue;
|
||||
|
||||
char buf[64] = {0};
|
||||
/*int c = */ Gui::itemCountItoa(buf, citem->count);
|
||||
|
||||
float tx = Gui::floorAlignToScreenPixel(kText * (item.xf + BorderPixels + 3));
|
||||
float ty = Gui::floorAlignToScreenPixel(kText * (item.yf + BorderPixels + 3));
|
||||
mc->gui.renderSlotText(citem, tx, ty, true, true);
|
||||
}
|
||||
t.resetScale();
|
||||
glEnable2(GL_BLEND);
|
||||
t.endOverrideAndDraw();
|
||||
}
|
||||
|
||||
if (renderDecorations) {
|
||||
t.beginOverride();
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
GridItem& item = items[i];
|
||||
const ItemInstance* citem = inventoryItems[item.id];
|
||||
if (!citem || citem->isNull()) continue;
|
||||
|
||||
if (citem->isDamaged()) {
|
||||
ItemRenderer::renderGuiItemDecorations(citem, item.xf + 8, item.yf + 12);
|
||||
}
|
||||
}
|
||||
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
t.endOverrideAndDraw();
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
}
|
||||
glDisable2(GL_SCISSOR_TEST);
|
||||
|
||||
//fillGradient(bbox.x - 1, bbox.y, bbox.x + bbox.w + 1, bbox.y + 20, 0x99000000, 0x00000000);
|
||||
//fillGradient(bbox.x - 1, bbox.y + bbox.h - 20, bbox.x + bbox.w + 1, bbox.y + bbox.h, 0x00000000, 0x99000000);
|
||||
fillGradient(bg.x - fillMarginX, bbox.y, bg.w + fillMarginX, bbox.y + 20, 0x99000000, 0x00000000);
|
||||
fillGradient(bg.x - fillMarginX, bbox.y + bbox.h - 20, bg.w + fillMarginX, bbox.y + bbox.h, 0x00000000, 0x99000000);
|
||||
|
||||
drawScrollBar(hScroll);
|
||||
drawScrollBar(vScroll);
|
||||
}
|
||||
|
||||
bool InventoryPane::onSelect( int gridId, bool selected )
|
||||
{
|
||||
//screen->onItemSelected(gridId);
|
||||
if (screen->isAllowed(gridId))
|
||||
if (screen->addItem(this, gridId)) {
|
||||
lastItemIndex = gridId;
|
||||
lastItemTicks = 7;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void InventoryPane::drawScrollBar( ScrollBar& sb ) {
|
||||
if (sb.alpha <= 0)
|
||||
return;
|
||||
|
||||
const int color = ((int)(255.0f * sb.alpha) << 24) | 0xaaaaaa;
|
||||
const float xx = (float)(bbox.x + bbox.w);
|
||||
fill(xx - sb.w, sb.y, xx, sb.y + sb.h, color);
|
||||
}
|
||||
|
||||
void InventoryPane::tick()
|
||||
{
|
||||
--lastItemTicks;
|
||||
super::tick();
|
||||
}
|
||||
|
||||
void InventoryPane::setRenderDecorations( bool value ) {
|
||||
renderDecorations = value;
|
||||
}
|
||||
|
||||
}
|
||||
#include "InventoryPane.hpp"
|
||||
#include "client/gui/Gui.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "client/player/input/touchscreen/TouchAreaModel.hpp"
|
||||
#include "client/renderer/entity/ItemRenderer.hpp"
|
||||
#include "client/renderer/Tesselator.hpp"
|
||||
#include "client/renderer/Textures.hpp"
|
||||
#include "world/item/ItemInstance.hpp"
|
||||
#include "world/entity/player/Inventory.hpp"
|
||||
|
||||
namespace Touch {
|
||||
|
||||
static const int By = 6; // Border Frame height
|
||||
|
||||
InventoryPane::InventoryPane( IInventoryPaneCallback* screen, Minecraft* mc, const IntRectangle& rect, int paneWidth, float clickMarginH, int numItems, int itemSize, int itemBorderSize)
|
||||
: screen(screen),
|
||||
mc(mc),
|
||||
paneWidth(paneWidth),
|
||||
rect(rect),
|
||||
super(
|
||||
SF_LockX|/*SF_Scissor|*/SF_ShowScrollbar|SF_NoHoldSelect,
|
||||
rect, // Pane rect
|
||||
IntRectangle(0, 0, itemSize, itemSize), // Item rect
|
||||
0, numItems, Gui::GuiScale),
|
||||
BorderPixels(itemBorderSize),
|
||||
lastItemIndex(-1),
|
||||
lastItemTicks(-1),
|
||||
fillMarginX(2),
|
||||
fillMarginY(4),
|
||||
markerType(1),
|
||||
markerIndex(-1),
|
||||
markerShare(0),
|
||||
renderDecorations(true)
|
||||
{
|
||||
_clickArea = new RectangleArea(0, 0, 0, 0);
|
||||
area._x0 = rect.x - clickMarginH;
|
||||
area._x1 = rect.x + rect.w + clickMarginH;
|
||||
area._y0 -= By;
|
||||
area._y1 += By;
|
||||
|
||||
/*
|
||||
const int left = bbox.x + (bbox.w - paneWidth) / 2;
|
||||
bg.x = left;
|
||||
bg.w = left + paneWidth; // @note: read as x1, not width
|
||||
bg.y = bbox.y - fillMarginY;
|
||||
bg.h = bbox.y + bbox.h + fillMarginY; // @note: read as y1, not width
|
||||
*/
|
||||
}
|
||||
|
||||
InventoryPane::~InventoryPane() {
|
||||
delete _clickArea;
|
||||
}
|
||||
|
||||
void InventoryPane::renderBatch( std::vector<GridItem>& items, float alpha )
|
||||
{
|
||||
//fill(bg.x, bg.y, bg.w, bg.h, 0xff333333);
|
||||
fill((float)(bbox.x-fillMarginX-1), (float)(bbox.y-fillMarginY), (float)(bbox.x + bbox.w + fillMarginX+1), (float)(bbox.y + bbox.h + fillMarginY), 0xff333333);
|
||||
//fill(0.0f, (float)(bbox.y-fillMarginY), 400.0f, (float)(bbox.y + bbox.h + fillMarginY), 0xff333333);//(float)(bbox.x-fillMarginX), (float)(bbox.y-fillMarginY), (float)(bbox.x + bbox.w + fillMarginX), (float)(bbox.y + bbox.h + fillMarginY), 0xff333333);
|
||||
glEnable2(GL_BLEND);
|
||||
glDisable2(GL_ALPHA_TEST);
|
||||
std::vector<const ItemInstance*> inventoryItems = screen->getItems(this);
|
||||
|
||||
glEnable2(GL_SCISSOR_TEST);
|
||||
GLuint x = (GLuint)(screenScale * bbox.x);
|
||||
GLuint y = mc->height - (GLuint)(screenScale * (bbox.y + bbox.h));
|
||||
GLuint w = (GLuint)(screenScale * bbox.w);
|
||||
GLuint h = (GLuint)(screenScale * bbox.h);
|
||||
glScissor(x, y, w, h);
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
t.beginOverride();
|
||||
t.colorABGR(0xffffffff);
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
GridItem& item = items[i];
|
||||
blit(item.xf, item.yf, 200, 46, (float)itemBbox.w, (float)itemBbox.h, 16, 16);
|
||||
}
|
||||
mc->textures->loadAndBindTexture("gui/gui.png");
|
||||
t.endOverrideAndDraw();
|
||||
|
||||
GridItem* marked = NULL;
|
||||
float mxx, myy;
|
||||
|
||||
t.beginOverride();
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
GridItem& item = items[i];
|
||||
int j = item.id;
|
||||
const ItemInstance* citem = inventoryItems[j];
|
||||
if (!citem) continue;
|
||||
|
||||
bool allowed = true;
|
||||
|
||||
t.enableColor();
|
||||
//#ifdef DEMO_MODE //@huge @attn
|
||||
if (!screen->isAllowed(j)) { allowed = false; t.color( 64, 64, 64); }
|
||||
else
|
||||
//#endif
|
||||
if (lastItemTicks > 0 && lastItemIndex == j) {
|
||||
int gv = 255 - lastItemTicks * 15;
|
||||
t.color(gv, gv, gv, (allowed && citem->count <= 0)?0x60:0xff);
|
||||
} else {
|
||||
t.color(255, 255, 255, (allowed && citem->count <= 0)?0x60:0xff);
|
||||
}
|
||||
t.noColor();
|
||||
float xx = Gui::floorAlignToScreenPixel(item.xf + BorderPixels + 4);
|
||||
float yy = Gui::floorAlignToScreenPixel(item.yf + BorderPixels + 4);
|
||||
ItemRenderer::renderGuiItem(NULL, mc->textures, citem, xx, yy, 16, 16, false);
|
||||
|
||||
if (j == markerIndex && markerShare >= 0)
|
||||
marked = &item, mxx = xx, myy = yy;
|
||||
|
||||
}
|
||||
t.endOverrideAndDraw();
|
||||
|
||||
if (marked) {
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
const float yy0 = myy - 5.0f;
|
||||
const float yy1 = yy0 + 2;
|
||||
fill(mxx, yy0, mxx + 16.0f, yy1, 0xff606060);
|
||||
fill(mxx, yy0, mxx + markerShare * 16.0f, yy1, markerType==1?0xff00ff00:0xff476543);
|
||||
glEnable2(GL_BLEND);
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
|
||||
if (!mc->isCreativeMode()) {
|
||||
const float ikText = Gui::InvGuiScale + Gui::InvGuiScale;
|
||||
const float kText = 0.5f * Gui::GuiScale;
|
||||
t.beginOverride();
|
||||
t.scale2d(ikText, ikText);
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
GridItem& item = items[i];
|
||||
const ItemInstance* citem = inventoryItems[item.id];
|
||||
if (!citem) continue;
|
||||
|
||||
char buf[64] = {0};
|
||||
/*int c = */ Gui::itemCountItoa(buf, citem->count);
|
||||
|
||||
float tx = Gui::floorAlignToScreenPixel(kText * (item.xf + BorderPixels + 3));
|
||||
float ty = Gui::floorAlignToScreenPixel(kText * (item.yf + BorderPixels + 3));
|
||||
mc->gui.renderSlotText(citem, tx, ty, true, true);
|
||||
}
|
||||
t.resetScale();
|
||||
glEnable2(GL_BLEND);
|
||||
t.endOverrideAndDraw();
|
||||
}
|
||||
|
||||
if (renderDecorations) {
|
||||
t.beginOverride();
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
GridItem& item = items[i];
|
||||
const ItemInstance* citem = inventoryItems[item.id];
|
||||
if (!citem || citem->isNull()) continue;
|
||||
|
||||
if (citem->isDamaged()) {
|
||||
ItemRenderer::renderGuiItemDecorations(citem, item.xf + 8, item.yf + 12);
|
||||
}
|
||||
}
|
||||
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
t.endOverrideAndDraw();
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
}
|
||||
glDisable2(GL_SCISSOR_TEST);
|
||||
|
||||
//fillGradient(bbox.x - 1, bbox.y, bbox.x + bbox.w + 1, bbox.y + 20, 0x99000000, 0x00000000);
|
||||
//fillGradient(bbox.x - 1, bbox.y + bbox.h - 20, bbox.x + bbox.w + 1, bbox.y + bbox.h, 0x00000000, 0x99000000);
|
||||
fillGradient(bg.x - fillMarginX, bbox.y, bg.w + fillMarginX, bbox.y + 20, 0x99000000, 0x00000000);
|
||||
fillGradient(bg.x - fillMarginX, bbox.y + bbox.h - 20, bg.w + fillMarginX, bbox.y + bbox.h, 0x00000000, 0x99000000);
|
||||
|
||||
drawScrollBar(hScroll);
|
||||
drawScrollBar(vScroll);
|
||||
}
|
||||
|
||||
bool InventoryPane::onSelect( int gridId, bool selected )
|
||||
{
|
||||
//screen->onItemSelected(gridId);
|
||||
if (screen->isAllowed(gridId))
|
||||
if (screen->addItem(this, gridId)) {
|
||||
lastItemIndex = gridId;
|
||||
lastItemTicks = 7;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void InventoryPane::drawScrollBar( ScrollBar& sb ) {
|
||||
if (sb.alpha <= 0)
|
||||
return;
|
||||
|
||||
const int color = ((int)(255.0f * sb.alpha) << 24) | 0xaaaaaa;
|
||||
const float xx = (float)(bbox.x + bbox.w);
|
||||
fill(xx - sb.w, sb.y, xx, sb.y + sb.h, color);
|
||||
}
|
||||
|
||||
void InventoryPane::tick()
|
||||
{
|
||||
--lastItemTicks;
|
||||
super::tick();
|
||||
}
|
||||
|
||||
void InventoryPane::setRenderDecorations( bool value ) {
|
||||
renderDecorations = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "ScrollingPane.h"
|
||||
#include "ImageButton.h"
|
||||
#include "ScrollingPane.hpp"
|
||||
#include "ImageButton.hpp"
|
||||
|
||||
class Minecraft;
|
||||
class ItemInstance;
|
||||
@@ -1,148 +1,148 @@
|
||||
#include "ItemPane.h"
|
||||
#include "../Gui.h"
|
||||
#include "../../renderer/gles.h"
|
||||
#include "../../renderer/Tesselator.h"
|
||||
#include "NinePatch.h"
|
||||
#include "../../renderer/entity/ItemRenderer.h"
|
||||
|
||||
const int rgbActive = 0xfff0f0f0;
|
||||
const int rgbInactive = 0xc0635558;
|
||||
const int rgbInactiveShadow = 0xc0aaaaaa;
|
||||
|
||||
ItemPane::ItemPane( IItemPaneCallback* screen,
|
||||
Textures* textures,
|
||||
const IntRectangle& rect,
|
||||
int numItems,
|
||||
int guiHeight,
|
||||
int physicalScreenHeight,
|
||||
bool isVertical /*= true*/)
|
||||
: super(
|
||||
(isVertical?SF_LockX:SF_LockY)/*|SF_Scissor*/|SF_ShowScrollbar,
|
||||
rect, // Pane rect
|
||||
isVertical?IntRectangle(0, 0, rect.w, 22) // Item rect if vertical
|
||||
:IntRectangle(0, 0, 32, rect.h), // Item rect if horizontal
|
||||
isVertical?1:numItems, numItems, Gui::GuiScale),
|
||||
screen(screen),
|
||||
textures(textures),
|
||||
physicalScreenHeight(physicalScreenHeight),
|
||||
guiSlotItem(NULL),
|
||||
guiSlotItemSelected(NULL),
|
||||
isVertical(isVertical)
|
||||
{
|
||||
// Expand the area to make it easier to scroll
|
||||
area._x0 -= 4;
|
||||
area._x1 += 4;
|
||||
area._y0 = 0;
|
||||
area._y1 = (float)guiHeight;
|
||||
|
||||
// GUI
|
||||
NinePatchFactory builder(textures, "gui/spritesheet.png");
|
||||
guiSlotItem = builder.createSymmetrical(IntRectangle(20, 32, 8, 8), 2, 2);
|
||||
guiSlotItemSelected = builder.createSymmetrical(IntRectangle(28, 32, 8, 8), 2, 2);
|
||||
guiSlotItem->setSize((float)rect.w + 4, 22);
|
||||
guiSlotItemSelected->setSize((float)rect.w + 4, 22);
|
||||
}
|
||||
|
||||
ItemPane::~ItemPane() {
|
||||
delete guiSlotItem;
|
||||
delete guiSlotItemSelected;
|
||||
}
|
||||
|
||||
void ItemPane::renderBatch( std::vector<GridItem>& items, float alpha )
|
||||
{
|
||||
//fill(bbox.x, bbox.y, bbox.x + bbox.w, bbox.y + bbox.h, 0xff666666);
|
||||
const std::vector<CItem*>& cat = screen->getItems(this);
|
||||
if (cat.empty()) return;
|
||||
|
||||
glEnable2(GL_SCISSOR_TEST);
|
||||
GLuint x = (GLuint)(screenScale * bbox.x);
|
||||
GLuint y = physicalScreenHeight - (GLuint)(screenScale * (bbox.y + bbox.h));
|
||||
GLuint w = (GLuint)(screenScale * bbox.w);
|
||||
GLuint h = (GLuint)(screenScale * bbox.h);
|
||||
glScissor(x, y, w, h);
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
t.beginOverride();
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
GridItem& item = items[i];
|
||||
(item.selected? guiSlotItemSelected : guiSlotItem)->draw(t, Gui::floorAlignToScreenPixel(item.xf-1), Gui::floorAlignToScreenPixel(item.yf));
|
||||
}
|
||||
t.endOverrideAndDraw();
|
||||
|
||||
t.beginOverride();
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
GridItem& item = items[i];
|
||||
CItem* citem = cat[item.id];
|
||||
|
||||
ItemRenderer::renderGuiItem(NULL, textures, &citem->item,
|
||||
Gui::floorAlignToScreenPixel(item.xf + itemBbox.w - 16),
|
||||
Gui::floorAlignToScreenPixel(2 + item.yf), 16, 16, false);
|
||||
}
|
||||
t.endOverrideAndDraw();
|
||||
|
||||
t.beginOverride();
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
GridItem& item = items[i];
|
||||
CItem* citem = cat[item.id];
|
||||
|
||||
char buf[64] = {0};
|
||||
int c = Gui::itemCountItoa(buf, citem->inventoryCount);
|
||||
|
||||
float xf = item.xf - 1;
|
||||
if (citem->canCraft()) {
|
||||
f->drawShadow(citem->text,
|
||||
Gui::floorAlignToScreenPixel(xf + 2),
|
||||
Gui::floorAlignToScreenPixel(item.yf + 6), rgbActive);
|
||||
t.scale2d(0.6667f, 0.6667f);
|
||||
f->drawShadow(buf,
|
||||
Gui::floorAlignToScreenPixel(1.5f * (xf + itemBbox.w - c*4)),
|
||||
Gui::floorAlignToScreenPixel(1.5f * (item.yf + itemBbox.h - 8)), rgbActive);
|
||||
t.resetScale();
|
||||
} else {
|
||||
f->draw(citem->text,
|
||||
Gui::floorAlignToScreenPixel(xf + 3),
|
||||
Gui::floorAlignToScreenPixel(item.yf + 7), rgbInactiveShadow);
|
||||
f->draw(citem->text,
|
||||
Gui::floorAlignToScreenPixel(xf + 2),
|
||||
Gui::floorAlignToScreenPixel(item.yf + 6), rgbInactive);
|
||||
t.scale2d(0.6667f, 0.6667f);
|
||||
f->draw(buf,
|
||||
Gui::floorAlignToScreenPixel(1.5f * (xf + itemBbox.w - c*4)),
|
||||
Gui::floorAlignToScreenPixel(1.5f * (item.yf + itemBbox.h - 8)), rgbInactive);
|
||||
t.resetScale();
|
||||
}
|
||||
}
|
||||
t.endOverrideAndDraw();
|
||||
|
||||
//fillGradient(bbox.x, bbox.y, bbox.x + bbox.w, 20, 0x00000000, 0x80ff0000)
|
||||
if (isVertical) {
|
||||
fillGradient(bbox.x, bbox.y, bbox.x + bbox.w, bbox.y + 28, 0xbb000000, 0x00000000);
|
||||
fillGradient(bbox.x, bbox.y + bbox.h - 28, bbox.x + bbox.w, bbox.y + bbox.h, 0x00000000, 0xbb000000);//0xbb2A272B);
|
||||
} else {
|
||||
fillHorizontalGradient(bbox.x, bbox.y, bbox.x + 28, bbox.y + bbox.h, 0xbb000000, 0x00000000);
|
||||
fillHorizontalGradient(bbox.x + bbox.w - 28, bbox.y, bbox.x + bbox.w, bbox.y + bbox.h, 0x00000000, 0xbb000000);//0xbb2A272B);
|
||||
}
|
||||
|
||||
//LOGI("scroll: %f - %f, %f :: %f, %f\n", hScroll.alpha, hScroll.x, hScroll.y, hScroll.w, hScroll.h);
|
||||
glDisable2(GL_SCISSOR_TEST);
|
||||
|
||||
drawScrollBar(hScroll);
|
||||
drawScrollBar(vScroll);
|
||||
}
|
||||
|
||||
bool ItemPane::onSelect( int gridId, bool selected )
|
||||
{
|
||||
if (selected)
|
||||
screen->onItemSelected(this, gridId);
|
||||
|
||||
return selected;
|
||||
}
|
||||
|
||||
void ItemPane::drawScrollBar( ScrollBar& sb ) {
|
||||
if (sb.alpha <= 0)
|
||||
return;
|
||||
|
||||
int color = ((int)(255.0f * sb.alpha) << 24) | 0xffffff;
|
||||
fill(2 + sb.x, sb.y, 2 + sb.x + sb.w, sb.y + sb.h, color);
|
||||
}
|
||||
#include "ItemPane.hpp"
|
||||
#include "client/gui/Gui.hpp"
|
||||
#include "client/renderer/gles.hpp"
|
||||
#include "client/renderer/Tesselator.hpp"
|
||||
#include "NinePatch.hpp"
|
||||
#include "client/renderer/entity/ItemRenderer.hpp"
|
||||
|
||||
const int rgbActive = 0xfff0f0f0;
|
||||
const int rgbInactive = 0xc0635558;
|
||||
const int rgbInactiveShadow = 0xc0aaaaaa;
|
||||
|
||||
ItemPane::ItemPane( IItemPaneCallback* screen,
|
||||
Textures* textures,
|
||||
const IntRectangle& rect,
|
||||
int numItems,
|
||||
int guiHeight,
|
||||
int physicalScreenHeight,
|
||||
bool isVertical /*= true*/)
|
||||
: super(
|
||||
(isVertical?SF_LockX:SF_LockY)/*|SF_Scissor*/|SF_ShowScrollbar,
|
||||
rect, // Pane rect
|
||||
isVertical?IntRectangle(0, 0, rect.w, 22) // Item rect if vertical
|
||||
:IntRectangle(0, 0, 32, rect.h), // Item rect if horizontal
|
||||
isVertical?1:numItems, numItems, Gui::GuiScale),
|
||||
screen(screen),
|
||||
textures(textures),
|
||||
physicalScreenHeight(physicalScreenHeight),
|
||||
guiSlotItem(NULL),
|
||||
guiSlotItemSelected(NULL),
|
||||
isVertical(isVertical)
|
||||
{
|
||||
// Expand the area to make it easier to scroll
|
||||
area._x0 -= 4;
|
||||
area._x1 += 4;
|
||||
area._y0 = 0;
|
||||
area._y1 = (float)guiHeight;
|
||||
|
||||
// GUI
|
||||
NinePatchFactory builder(textures, "gui/spritesheet.png");
|
||||
guiSlotItem = builder.createSymmetrical(IntRectangle(20, 32, 8, 8), 2, 2);
|
||||
guiSlotItemSelected = builder.createSymmetrical(IntRectangle(28, 32, 8, 8), 2, 2);
|
||||
guiSlotItem->setSize((float)rect.w + 4, 22);
|
||||
guiSlotItemSelected->setSize((float)rect.w + 4, 22);
|
||||
}
|
||||
|
||||
ItemPane::~ItemPane() {
|
||||
delete guiSlotItem;
|
||||
delete guiSlotItemSelected;
|
||||
}
|
||||
|
||||
void ItemPane::renderBatch( std::vector<GridItem>& items, float alpha )
|
||||
{
|
||||
//fill(bbox.x, bbox.y, bbox.x + bbox.w, bbox.y + bbox.h, 0xff666666);
|
||||
const std::vector<CItem*>& cat = screen->getItems(this);
|
||||
if (cat.empty()) return;
|
||||
|
||||
glEnable2(GL_SCISSOR_TEST);
|
||||
GLuint x = (GLuint)(screenScale * bbox.x);
|
||||
GLuint y = physicalScreenHeight - (GLuint)(screenScale * (bbox.y + bbox.h));
|
||||
GLuint w = (GLuint)(screenScale * bbox.w);
|
||||
GLuint h = (GLuint)(screenScale * bbox.h);
|
||||
glScissor(x, y, w, h);
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
t.beginOverride();
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
GridItem& item = items[i];
|
||||
(item.selected? guiSlotItemSelected : guiSlotItem)->draw(t, Gui::floorAlignToScreenPixel(item.xf-1), Gui::floorAlignToScreenPixel(item.yf));
|
||||
}
|
||||
t.endOverrideAndDraw();
|
||||
|
||||
t.beginOverride();
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
GridItem& item = items[i];
|
||||
CItem* citem = cat[item.id];
|
||||
|
||||
ItemRenderer::renderGuiItem(NULL, textures, &citem->item,
|
||||
Gui::floorAlignToScreenPixel(item.xf + itemBbox.w - 16),
|
||||
Gui::floorAlignToScreenPixel(2 + item.yf), 16, 16, false);
|
||||
}
|
||||
t.endOverrideAndDraw();
|
||||
|
||||
t.beginOverride();
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
GridItem& item = items[i];
|
||||
CItem* citem = cat[item.id];
|
||||
|
||||
char buf[64] = {0};
|
||||
int c = Gui::itemCountItoa(buf, citem->inventoryCount);
|
||||
|
||||
float xf = item.xf - 1;
|
||||
if (citem->canCraft()) {
|
||||
f->drawShadow(citem->text,
|
||||
Gui::floorAlignToScreenPixel(xf + 2),
|
||||
Gui::floorAlignToScreenPixel(item.yf + 6), rgbActive);
|
||||
t.scale2d(0.6667f, 0.6667f);
|
||||
f->drawShadow(buf,
|
||||
Gui::floorAlignToScreenPixel(1.5f * (xf + itemBbox.w - c*4)),
|
||||
Gui::floorAlignToScreenPixel(1.5f * (item.yf + itemBbox.h - 8)), rgbActive);
|
||||
t.resetScale();
|
||||
} else {
|
||||
f->draw(citem->text,
|
||||
Gui::floorAlignToScreenPixel(xf + 3),
|
||||
Gui::floorAlignToScreenPixel(item.yf + 7), rgbInactiveShadow);
|
||||
f->draw(citem->text,
|
||||
Gui::floorAlignToScreenPixel(xf + 2),
|
||||
Gui::floorAlignToScreenPixel(item.yf + 6), rgbInactive);
|
||||
t.scale2d(0.6667f, 0.6667f);
|
||||
f->draw(buf,
|
||||
Gui::floorAlignToScreenPixel(1.5f * (xf + itemBbox.w - c*4)),
|
||||
Gui::floorAlignToScreenPixel(1.5f * (item.yf + itemBbox.h - 8)), rgbInactive);
|
||||
t.resetScale();
|
||||
}
|
||||
}
|
||||
t.endOverrideAndDraw();
|
||||
|
||||
//fillGradient(bbox.x, bbox.y, bbox.x + bbox.w, 20, 0x00000000, 0x80ff0000)
|
||||
if (isVertical) {
|
||||
fillGradient(bbox.x, bbox.y, bbox.x + bbox.w, bbox.y + 28, 0xbb000000, 0x00000000);
|
||||
fillGradient(bbox.x, bbox.y + bbox.h - 28, bbox.x + bbox.w, bbox.y + bbox.h, 0x00000000, 0xbb000000);//0xbb2A272B);
|
||||
} else {
|
||||
fillHorizontalGradient(bbox.x, bbox.y, bbox.x + 28, bbox.y + bbox.h, 0xbb000000, 0x00000000);
|
||||
fillHorizontalGradient(bbox.x + bbox.w - 28, bbox.y, bbox.x + bbox.w, bbox.y + bbox.h, 0x00000000, 0xbb000000);//0xbb2A272B);
|
||||
}
|
||||
|
||||
//LOGI("scroll: %f - %f, %f :: %f, %f\n", hScroll.alpha, hScroll.x, hScroll.y, hScroll.w, hScroll.h);
|
||||
glDisable2(GL_SCISSOR_TEST);
|
||||
|
||||
drawScrollBar(hScroll);
|
||||
drawScrollBar(vScroll);
|
||||
}
|
||||
|
||||
bool ItemPane::onSelect( int gridId, bool selected )
|
||||
{
|
||||
if (selected)
|
||||
screen->onItemSelected(this, gridId);
|
||||
|
||||
return selected;
|
||||
}
|
||||
|
||||
void ItemPane::drawScrollBar( ScrollBar& sb ) {
|
||||
if (sb.alpha <= 0)
|
||||
return;
|
||||
|
||||
int color = ((int)(255.0f * sb.alpha) << 24) | 0xffffff;
|
||||
fill(2 + sb.x, sb.y, 2 + sb.x + sb.w, sb.y + sb.h, color);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "ScrollingPane.h"
|
||||
#include "../../../world/item/ItemInstance.h"
|
||||
#include "ScrollingPane.hpp"
|
||||
#include "world/item/ItemInstance.hpp"
|
||||
|
||||
class Font;
|
||||
class Textures;
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "KeyOption.h"
|
||||
#include <client/Minecraft.h>
|
||||
#include "KeyOption.hpp"
|
||||
#include <client/Minecraft.hpp>
|
||||
|
||||
KeyOption::KeyOption(Minecraft* minecraft, OptionId optId)
|
||||
: Touch::TButton((int)optId, Keyboard::getKeyName(minecraft->options.getIntValue(optId))) {}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include "Button.h"
|
||||
#include <client/Options.h>
|
||||
#include "Button.hpp"
|
||||
#include <client/Options.hpp>
|
||||
|
||||
class KeyOption : public Touch::TButton {
|
||||
public:
|
||||
@@ -1,104 +1,104 @@
|
||||
#include "LargeImageButton.h"
|
||||
#include "../../renderer/Tesselator.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../../util/Mth.h"
|
||||
#include "../../../platform/log.h"
|
||||
#include "../../../util/Mth.h"
|
||||
#include "../../renderer/Textures.h"
|
||||
|
||||
|
||||
LargeImageButton::LargeImageButton(int id, const std::string& msg)
|
||||
: super(id, msg)
|
||||
{
|
||||
setupDefault();
|
||||
}
|
||||
|
||||
LargeImageButton::LargeImageButton(int id, const std::string& msg, ImageDef& imagedef)
|
||||
: super(id, msg)
|
||||
{
|
||||
_imageDef = imagedef;
|
||||
setupDefault();
|
||||
}
|
||||
|
||||
void LargeImageButton::setupDefault() {
|
||||
_buttonScale = 1;
|
||||
width = 72;
|
||||
height = 72;
|
||||
}
|
||||
|
||||
void LargeImageButton::render(Minecraft* minecraft, int xm, int ym) {
|
||||
if (!visible) return;
|
||||
|
||||
Font* font = minecraft->font;
|
||||
|
||||
//minecraft->textures->loadAndBindTexture("gui/gui.png");
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
bool hovered = active && (minecraft->useTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : isInside(xm, ym));
|
||||
|
||||
//printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym);
|
||||
//int yImage = getYImage(hovered || selected);
|
||||
|
||||
//blit(x, y, 0, 46 + yImage * 20, w / 2, h, 0, 20);
|
||||
//blit(x + w / 2, y, 200 - w / 2, 46 + yImage * 20, w / 2, h, 0, 20);
|
||||
|
||||
renderBg(minecraft, xm, ym);
|
||||
|
||||
TextureId texId = (_imageDef.name.length() > 0)? minecraft->textures->loadAndBindTexture(_imageDef.name) : Textures::InvalidId;
|
||||
if ( Textures::isTextureIdValid(texId) ) {
|
||||
const ImageDef& d = _imageDef;
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
t.begin();
|
||||
if (!active) t.color(0xff808080);
|
||||
//else if (hovered||selected) t.color(0xffffffff);
|
||||
//else t.color(0xffe0e0e0);
|
||||
else t.color(0xffffffff);
|
||||
|
||||
float hx = ((float) d.width) * 0.5f;
|
||||
float hy = ((float) d.height) * 0.5f;
|
||||
const float cx = ((float)x+d.x) + hx;
|
||||
const float cy = ((float)y+d.y) + hy;
|
||||
|
||||
if (hovered)
|
||||
_buttonScale = Mth::Max(0.95f, _buttonScale-0.025f);
|
||||
else
|
||||
_buttonScale = Mth::Min(1.00f, _buttonScale+0.025f);
|
||||
|
||||
hx *= _buttonScale;
|
||||
hy *= _buttonScale;
|
||||
|
||||
const IntRectangle* src = _imageDef.getSrc();
|
||||
if (src) {
|
||||
const TextureData* d = minecraft->textures->getTemporaryTextureData(texId);
|
||||
if (d != NULL) {
|
||||
float u0 = (src->x+(hovered?src->w:0)) / (float)d->w;
|
||||
float u1 = (src->x+(hovered?2*src->w:src->w)) / (float)d->w;
|
||||
float v0 = src->y / (float)d->h;
|
||||
float v1 = (src->y+src->h) / (float)d->h;
|
||||
t.vertexUV(cx-hx, cy-hy, blitOffset, u0, v0);
|
||||
t.vertexUV(cx-hx, cy+hy, blitOffset, u0, v1);
|
||||
t.vertexUV(cx+hx, cy+hy, blitOffset, u1, v1);
|
||||
t.vertexUV(cx+hx, cy-hy, blitOffset, u1, v0);
|
||||
}
|
||||
} else {
|
||||
t.vertexUV(cx-hx, cy-hy, blitOffset, 0, 0);
|
||||
t.vertexUV(cx-hx, cy+hy, blitOffset, 0, 1);
|
||||
t.vertexUV(cx+hx, cy+hy, blitOffset, 1, 1);
|
||||
t.vertexUV(cx+hx, cy-hy, blitOffset, 1, 0);
|
||||
}
|
||||
t.draw();
|
||||
}
|
||||
//blit(0, 0, 0, 0, 64, 64, 256, 256);
|
||||
|
||||
//LOGI("%d %d\n", x+d.x, x+d.x+d.w);
|
||||
|
||||
if (!active) {
|
||||
drawCenteredString(font, msg, x + width / 2, y + 11/*(h - 16)*/, 0xffa0a0a0);
|
||||
} else {
|
||||
if (hovered || selected) {
|
||||
drawCenteredString(font, msg, x + width / 2, y + 11/*(h - 16)*/, 0xffffa0);
|
||||
} else {
|
||||
drawCenteredString(font, msg, x + width / 2, y + 11/*(h - 48)*/, 0xe0e0e0);
|
||||
}
|
||||
}
|
||||
}
|
||||
#include "LargeImageButton.hpp"
|
||||
#include "client/renderer/Tesselator.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "util/Mth.hpp"
|
||||
#include "platform/log.hpp"
|
||||
#include "util/Mth.hpp"
|
||||
#include "client/renderer/Textures.hpp"
|
||||
|
||||
|
||||
LargeImageButton::LargeImageButton(int id, const std::string& msg)
|
||||
: super(id, msg)
|
||||
{
|
||||
setupDefault();
|
||||
}
|
||||
|
||||
LargeImageButton::LargeImageButton(int id, const std::string& msg, ImageDef& imagedef)
|
||||
: super(id, msg)
|
||||
{
|
||||
_imageDef = imagedef;
|
||||
setupDefault();
|
||||
}
|
||||
|
||||
void LargeImageButton::setupDefault() {
|
||||
_buttonScale = 1;
|
||||
width = 72;
|
||||
height = 72;
|
||||
}
|
||||
|
||||
void LargeImageButton::render(Minecraft* minecraft, int xm, int ym) {
|
||||
if (!visible) return;
|
||||
|
||||
Font* font = minecraft->font;
|
||||
|
||||
//minecraft->textures->loadAndBindTexture("gui/gui.png");
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
bool hovered = active && (minecraft->useTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : isInside(xm, ym));
|
||||
|
||||
//printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym);
|
||||
//int yImage = getYImage(hovered || selected);
|
||||
|
||||
//blit(x, y, 0, 46 + yImage * 20, w / 2, h, 0, 20);
|
||||
//blit(x + w / 2, y, 200 - w / 2, 46 + yImage * 20, w / 2, h, 0, 20);
|
||||
|
||||
renderBg(minecraft, xm, ym);
|
||||
|
||||
TextureId texId = (_imageDef.name.length() > 0)? minecraft->textures->loadAndBindTexture(_imageDef.name) : Textures::InvalidId;
|
||||
if ( Textures::isTextureIdValid(texId) ) {
|
||||
const ImageDef& d = _imageDef;
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
t.begin();
|
||||
if (!active) t.color(0xff808080);
|
||||
//else if (hovered||selected) t.color(0xffffffff);
|
||||
//else t.color(0xffe0e0e0);
|
||||
else t.color(0xffffffff);
|
||||
|
||||
float hx = ((float) d.width) * 0.5f;
|
||||
float hy = ((float) d.height) * 0.5f;
|
||||
const float cx = ((float)x+d.x) + hx;
|
||||
const float cy = ((float)y+d.y) + hy;
|
||||
|
||||
if (hovered)
|
||||
_buttonScale = Mth::Max(0.95f, _buttonScale-0.025f);
|
||||
else
|
||||
_buttonScale = Mth::Min(1.00f, _buttonScale+0.025f);
|
||||
|
||||
hx *= _buttonScale;
|
||||
hy *= _buttonScale;
|
||||
|
||||
const IntRectangle* src = _imageDef.getSrc();
|
||||
if (src) {
|
||||
const TextureData* d = minecraft->textures->getTemporaryTextureData(texId);
|
||||
if (d != NULL) {
|
||||
float u0 = (src->x+(hovered?src->w:0)) / (float)d->w;
|
||||
float u1 = (src->x+(hovered?2*src->w:src->w)) / (float)d->w;
|
||||
float v0 = src->y / (float)d->h;
|
||||
float v1 = (src->y+src->h) / (float)d->h;
|
||||
t.vertexUV(cx-hx, cy-hy, blitOffset, u0, v0);
|
||||
t.vertexUV(cx-hx, cy+hy, blitOffset, u0, v1);
|
||||
t.vertexUV(cx+hx, cy+hy, blitOffset, u1, v1);
|
||||
t.vertexUV(cx+hx, cy-hy, blitOffset, u1, v0);
|
||||
}
|
||||
} else {
|
||||
t.vertexUV(cx-hx, cy-hy, blitOffset, 0, 0);
|
||||
t.vertexUV(cx-hx, cy+hy, blitOffset, 0, 1);
|
||||
t.vertexUV(cx+hx, cy+hy, blitOffset, 1, 1);
|
||||
t.vertexUV(cx+hx, cy-hy, blitOffset, 1, 0);
|
||||
}
|
||||
t.draw();
|
||||
}
|
||||
//blit(0, 0, 0, 0, 64, 64, 256, 256);
|
||||
|
||||
//LOGI("%d %d\n", x+d.x, x+d.x+d.w);
|
||||
|
||||
if (!active) {
|
||||
drawCenteredString(font, msg, x + width / 2, y + 11/*(h - 16)*/, 0xffa0a0a0);
|
||||
} else {
|
||||
if (hovered || selected) {
|
||||
drawCenteredString(font, msg, x + width / 2, y + 11/*(h - 16)*/, 0xffffa0);
|
||||
} else {
|
||||
drawCenteredString(font, msg, x + width / 2, y + 11/*(h - 48)*/, 0xe0e0e0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "ImageButton.h"
|
||||
#include "ImageButton.hpp"
|
||||
|
||||
class LargeImageButton: public ImageButton
|
||||
{
|
||||
@@ -1,141 +1,141 @@
|
||||
#include "NinePatch.h"
|
||||
|
||||
NinePatchDescription::NinePatchDescription( float x, float y, float x1, float x2, float x3, float y1, float y2, float y3, float w, float e, float n, float s ) : u0(x), u1(x + x1), u2(x + x2), u3(x + x3),
|
||||
v0(y), v1(y + y1), v2(y + y2), v3(y + y3),
|
||||
w(w), e(e), n(n), s(s),
|
||||
imgW(-1),
|
||||
imgH(-1) {
|
||||
|
||||
}
|
||||
|
||||
NinePatchDescription& NinePatchDescription::transformUVForImage( const TextureData& d ) {
|
||||
return transformUVForImageSize(d.w, d.h);
|
||||
}
|
||||
|
||||
NinePatchDescription& NinePatchDescription::transformUVForImageSize( int w, int h ) {
|
||||
if (imgW < 0)
|
||||
imgW = imgH = 1;
|
||||
|
||||
const float us = (float) imgW / w; // @todo: prepare for normal blit? (e.g. mult by 256)
|
||||
const float vs = (float) imgH / h;
|
||||
u0 *= us; u1 *= us; u2 *= us; u3 *= us;
|
||||
v0 *= vs; v1 *= vs; v2 *= vs; v3 *= vs;
|
||||
|
||||
imgW = w;
|
||||
imgH = h;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
NinePatchDescription NinePatchDescription::createSymmetrical( int texWidth, int texHeight, const IntRectangle& src, int xCutAt, int yCutAt ) {
|
||||
NinePatchDescription patch((float)src.x, (float)src.y,// width and height of src
|
||||
(float)xCutAt, (float)(src.w-xCutAt), (float)src.w, // u tex coordinates
|
||||
(float)yCutAt, (float)(src.h-yCutAt), (float)src.h, // v tex coordinates
|
||||
(float)xCutAt, (float)xCutAt, (float)yCutAt, (float)yCutAt); // border width and heights
|
||||
if (texWidth > 0) patch.transformUVForImageSize(texWidth, texHeight);
|
||||
return patch;
|
||||
}
|
||||
|
||||
NinePatchLayer::NinePatchLayer(const NinePatchDescription& desc, const std::string& imageName, Textures* textures, float w, float h)
|
||||
: desc(desc),
|
||||
imageName(imageName),
|
||||
textures(textures),
|
||||
w(-1), h(-1),
|
||||
excluded(0)
|
||||
{
|
||||
setSize(w, h);
|
||||
}
|
||||
|
||||
void NinePatchLayer::setSize( float w, float h ) {
|
||||
if (w == this->w && h == this->h)
|
||||
return;
|
||||
|
||||
this->w = w;
|
||||
this->h = h;
|
||||
|
||||
for (int i = 0; i < 9; ++i)
|
||||
buildQuad(i);
|
||||
}
|
||||
|
||||
void NinePatchLayer::draw( Tesselator& t, float x, float y ) {
|
||||
textures->loadAndBindTexture(imageName);
|
||||
t.begin();
|
||||
t.addOffset(x, y, 0);
|
||||
for (int i = 0, b = 1; i < 9; ++i, b += b)
|
||||
if ((b & excluded) == 0)
|
||||
d(t, quads[i]);
|
||||
t.addOffset(-x, -y, 0);
|
||||
t.draw();
|
||||
}
|
||||
|
||||
NinePatchLayer* NinePatchLayer::exclude( int excludeId ) {
|
||||
return setExcluded(excluded | (1 << excludeId));
|
||||
}
|
||||
|
||||
NinePatchLayer* NinePatchLayer::setExcluded( int exludeBits ) {
|
||||
excluded = exludeBits;
|
||||
return this;
|
||||
}
|
||||
|
||||
void NinePatchLayer::buildQuad( int qid ) {
|
||||
//@attn; fix
|
||||
CachedQuad& q = quads[qid];
|
||||
const int yid = qid / 3;
|
||||
const int xid = qid - 3 * yid;
|
||||
q.u0 = (&desc.u0)[xid];
|
||||
q.u1 = (&desc.u0)[xid + 1];
|
||||
q.v0 = (&desc.v0)[yid];
|
||||
q.v1 = (&desc.v0)[yid + 1];
|
||||
q.z = 0;
|
||||
getPatchInfo(xid, yid, q.x0, q.x1, q.y0, q.y1);
|
||||
/* q.x0 = w * (q.u0 - desc.u0);
|
||||
q.y0 = h * (q.v0 - desc.v0);
|
||||
q.x1 = w * (q.u1 - desc.u0);
|
||||
q.y1 = h * (q.v1 - desc.v0);
|
||||
*/
|
||||
}
|
||||
|
||||
void NinePatchLayer::getPatchInfo( int xc, int yc, float& x0, float& x1, float& y0, float& y1 ) {
|
||||
if (xc == 0) { x0 = 0; x1 = desc.w; }
|
||||
else if (xc == 1) { x0 = desc.w; x1 = w - desc.e; }
|
||||
else if (xc == 2) { x0 = w-desc.e; x1 = w; }
|
||||
if (yc == 0) { y0 = 0; y1 = desc.n; }
|
||||
else if (yc == 1) { y0 = desc.n; y1 = h - desc.s; }
|
||||
else if (yc == 2) { y0 = h-desc.s; y1 = h; }
|
||||
}
|
||||
|
||||
void NinePatchLayer::d( Tesselator& t, const CachedQuad& q ) {
|
||||
/*
|
||||
t.vertexUV(x , y + h, blitOffset, (float)(sx ), (float)(sy + sh));
|
||||
t.vertexUV(x + w, y + h, blitOffset, (float)(sx + sw), (float)(sy + sh));
|
||||
t.vertexUV(x + w, y , blitOffset, (float)(sx + sw), (float)(sy ));
|
||||
t.vertexUV(x , y , blitOffset, (float)(sx ), (float)(sy ));
|
||||
*/
|
||||
|
||||
t.vertexUV(q.x0, q.y1, q.z, q.u0, q.v1);
|
||||
t.vertexUV(q.x1, q.y1, q.z, q.u1, q.v1);
|
||||
t.vertexUV(q.x1, q.y0, q.z, q.u1, q.v0);
|
||||
t.vertexUV(q.x0, q.y0, q.z, q.u0, q.v0);
|
||||
}
|
||||
|
||||
NinePatchFactory::NinePatchFactory( Textures* textures, const std::string& imageName ) : textures(textures),
|
||||
imageName(imageName),
|
||||
width(1),
|
||||
height(1) {
|
||||
TextureId id = textures->loadTexture(imageName);
|
||||
if (id != Textures::InvalidId) {
|
||||
const TextureData* data = textures->getTemporaryTextureData(id);
|
||||
if (data) { // This should never be false
|
||||
width = data->w;
|
||||
height = data->h;
|
||||
}
|
||||
} else {
|
||||
LOGE("Error @ NinePatchFactory::ctor - Couldn't find texture: %s\n", imageName.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
NinePatchLayer* NinePatchFactory::createSymmetrical( const IntRectangle& src, int xCutAt, int yCutAt, float w /*= 32.0f*/, float h /*= 32.0f*/ ) {
|
||||
return new NinePatchLayer(
|
||||
NinePatchDescription::createSymmetrical(width, height, src, xCutAt, yCutAt),
|
||||
imageName, textures, w, h);
|
||||
}
|
||||
#include "NinePatch.hpp"
|
||||
|
||||
NinePatchDescription::NinePatchDescription( float x, float y, float x1, float x2, float x3, float y1, float y2, float y3, float w, float e, float n, float s ) : u0(x), u1(x + x1), u2(x + x2), u3(x + x3),
|
||||
v0(y), v1(y + y1), v2(y + y2), v3(y + y3),
|
||||
w(w), e(e), n(n), s(s),
|
||||
imgW(-1),
|
||||
imgH(-1) {
|
||||
|
||||
}
|
||||
|
||||
NinePatchDescription& NinePatchDescription::transformUVForImage( const TextureData& d ) {
|
||||
return transformUVForImageSize(d.w, d.h);
|
||||
}
|
||||
|
||||
NinePatchDescription& NinePatchDescription::transformUVForImageSize( int w, int h ) {
|
||||
if (imgW < 0)
|
||||
imgW = imgH = 1;
|
||||
|
||||
const float us = (float) imgW / w; // @todo: prepare for normal blit? (e.g. mult by 256)
|
||||
const float vs = (float) imgH / h;
|
||||
u0 *= us; u1 *= us; u2 *= us; u3 *= us;
|
||||
v0 *= vs; v1 *= vs; v2 *= vs; v3 *= vs;
|
||||
|
||||
imgW = w;
|
||||
imgH = h;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
NinePatchDescription NinePatchDescription::createSymmetrical( int texWidth, int texHeight, const IntRectangle& src, int xCutAt, int yCutAt ) {
|
||||
NinePatchDescription patch((float)src.x, (float)src.y,// width and height of src
|
||||
(float)xCutAt, (float)(src.w-xCutAt), (float)src.w, // u tex coordinates
|
||||
(float)yCutAt, (float)(src.h-yCutAt), (float)src.h, // v tex coordinates
|
||||
(float)xCutAt, (float)xCutAt, (float)yCutAt, (float)yCutAt); // border width and heights
|
||||
if (texWidth > 0) patch.transformUVForImageSize(texWidth, texHeight);
|
||||
return patch;
|
||||
}
|
||||
|
||||
NinePatchLayer::NinePatchLayer(const NinePatchDescription& desc, const std::string& imageName, Textures* textures, float w, float h)
|
||||
: desc(desc),
|
||||
imageName(imageName),
|
||||
textures(textures),
|
||||
w(-1), h(-1),
|
||||
excluded(0)
|
||||
{
|
||||
setSize(w, h);
|
||||
}
|
||||
|
||||
void NinePatchLayer::setSize( float w, float h ) {
|
||||
if (w == this->w && h == this->h)
|
||||
return;
|
||||
|
||||
this->w = w;
|
||||
this->h = h;
|
||||
|
||||
for (int i = 0; i < 9; ++i)
|
||||
buildQuad(i);
|
||||
}
|
||||
|
||||
void NinePatchLayer::draw( Tesselator& t, float x, float y ) {
|
||||
textures->loadAndBindTexture(imageName);
|
||||
t.begin();
|
||||
t.addOffset(x, y, 0);
|
||||
for (int i = 0, b = 1; i < 9; ++i, b += b)
|
||||
if ((b & excluded) == 0)
|
||||
d(t, quads[i]);
|
||||
t.addOffset(-x, -y, 0);
|
||||
t.draw();
|
||||
}
|
||||
|
||||
NinePatchLayer* NinePatchLayer::exclude( int excludeId ) {
|
||||
return setExcluded(excluded | (1 << excludeId));
|
||||
}
|
||||
|
||||
NinePatchLayer* NinePatchLayer::setExcluded( int exludeBits ) {
|
||||
excluded = exludeBits;
|
||||
return this;
|
||||
}
|
||||
|
||||
void NinePatchLayer::buildQuad( int qid ) {
|
||||
//@attn; fix
|
||||
CachedQuad& q = quads[qid];
|
||||
const int yid = qid / 3;
|
||||
const int xid = qid - 3 * yid;
|
||||
q.u0 = (&desc.u0)[xid];
|
||||
q.u1 = (&desc.u0)[xid + 1];
|
||||
q.v0 = (&desc.v0)[yid];
|
||||
q.v1 = (&desc.v0)[yid + 1];
|
||||
q.z = 0;
|
||||
getPatchInfo(xid, yid, q.x0, q.x1, q.y0, q.y1);
|
||||
/* q.x0 = w * (q.u0 - desc.u0);
|
||||
q.y0 = h * (q.v0 - desc.v0);
|
||||
q.x1 = w * (q.u1 - desc.u0);
|
||||
q.y1 = h * (q.v1 - desc.v0);
|
||||
*/
|
||||
}
|
||||
|
||||
void NinePatchLayer::getPatchInfo( int xc, int yc, float& x0, float& x1, float& y0, float& y1 ) {
|
||||
if (xc == 0) { x0 = 0; x1 = desc.w; }
|
||||
else if (xc == 1) { x0 = desc.w; x1 = w - desc.e; }
|
||||
else if (xc == 2) { x0 = w-desc.e; x1 = w; }
|
||||
if (yc == 0) { y0 = 0; y1 = desc.n; }
|
||||
else if (yc == 1) { y0 = desc.n; y1 = h - desc.s; }
|
||||
else if (yc == 2) { y0 = h-desc.s; y1 = h; }
|
||||
}
|
||||
|
||||
void NinePatchLayer::d( Tesselator& t, const CachedQuad& q ) {
|
||||
/*
|
||||
t.vertexUV(x , y + h, blitOffset, (float)(sx ), (float)(sy + sh));
|
||||
t.vertexUV(x + w, y + h, blitOffset, (float)(sx + sw), (float)(sy + sh));
|
||||
t.vertexUV(x + w, y , blitOffset, (float)(sx + sw), (float)(sy ));
|
||||
t.vertexUV(x , y , blitOffset, (float)(sx ), (float)(sy ));
|
||||
*/
|
||||
|
||||
t.vertexUV(q.x0, q.y1, q.z, q.u0, q.v1);
|
||||
t.vertexUV(q.x1, q.y1, q.z, q.u1, q.v1);
|
||||
t.vertexUV(q.x1, q.y0, q.z, q.u1, q.v0);
|
||||
t.vertexUV(q.x0, q.y0, q.z, q.u0, q.v0);
|
||||
}
|
||||
|
||||
NinePatchFactory::NinePatchFactory( Textures* textures, const std::string& imageName ) : textures(textures),
|
||||
imageName(imageName),
|
||||
width(1),
|
||||
height(1) {
|
||||
TextureId id = textures->loadTexture(imageName);
|
||||
if (id != Textures::InvalidId) {
|
||||
const TextureData* data = textures->getTemporaryTextureData(id);
|
||||
if (data) { // This should never be false
|
||||
width = data->w;
|
||||
height = data->h;
|
||||
}
|
||||
} else {
|
||||
LOGE("Error @ NinePatchFactory::ctor - Couldn't find texture: %s\n", imageName.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
NinePatchLayer* NinePatchFactory::createSymmetrical( const IntRectangle& src, int xCutAt, int yCutAt, float w /*= 32.0f*/, float h /*= 32.0f*/ ) {
|
||||
return new NinePatchLayer(
|
||||
NinePatchDescription::createSymmetrical(width, height, src, xCutAt, yCutAt),
|
||||
imageName, textures, w, h);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "ImageButton.h"
|
||||
#include "../../renderer/TextureData.h"
|
||||
#include "../../renderer/Textures.h"
|
||||
#include "../../renderer/Tesselator.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "ImageButton.hpp"
|
||||
#include "client/renderer/TextureData.hpp"
|
||||
#include "client/renderer/Textures.hpp"
|
||||
#include "client/renderer/Tesselator.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
|
||||
class Tesselator;
|
||||
|
||||
@@ -1,115 +1,115 @@
|
||||
#include "OptionsGroup.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "ImageButton.h"
|
||||
#include "OptionsItem.h"
|
||||
#include "Slider.h"
|
||||
#include "../../../locale/I18n.h"
|
||||
#include "TextOption.h"
|
||||
#include "KeyOption.h"
|
||||
|
||||
OptionsGroup::OptionsGroup( std::string labelID ) {
|
||||
label = I18n::get(labelID);
|
||||
}
|
||||
|
||||
void OptionsGroup::setupPositions() {
|
||||
// First we write the header and then we add the items
|
||||
int curY = y + 18;
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->width = width - 5;
|
||||
|
||||
(*it)->y = curY;
|
||||
(*it)->x = x + 10;
|
||||
(*it)->setupPositions();
|
||||
curY += (*it)->height + 3;
|
||||
}
|
||||
height = curY;
|
||||
}
|
||||
|
||||
void OptionsGroup::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
float padX = 10.0f;
|
||||
float padY = 5.0f;
|
||||
|
||||
minecraft->font->draw(label, (float)x + padX, (float)y + padY, 0xffffffff, false);
|
||||
|
||||
super::render(minecraft, xm, ym);
|
||||
}
|
||||
|
||||
OptionsGroup& OptionsGroup::addOptionItem(OptionId optId, Minecraft* minecraft ) {
|
||||
auto option = minecraft->options.getOpt(optId);
|
||||
|
||||
if (option == nullptr) return *this;
|
||||
|
||||
// TODO: do a options key class to check it faster via dynamic_cast
|
||||
if (option->getStringId().find("options.key") != std::string::npos) createKey(optId, minecraft);
|
||||
else if (dynamic_cast<OptionBool*>(option)) createToggle(optId, minecraft);
|
||||
else if (dynamic_cast<OptionFloat*>(option)) createProgressSlider(optId, minecraft);
|
||||
else if (dynamic_cast<OptionInt*>(option)) createStepSlider(optId, minecraft);
|
||||
else if (dynamic_cast<OptionString*>(option)) createTextbox(optId, minecraft);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// TODO: wrap this copypaste shit into templates
|
||||
|
||||
void OptionsGroup::createToggle(OptionId optId, Minecraft* minecraft ) {
|
||||
ImageDef def;
|
||||
|
||||
def.setSrc(IntRectangle(160, 206, 39, 20));
|
||||
def.name = "gui/touchgui.png";
|
||||
def.width = 39 * 0.7f;
|
||||
def.height = 20 * 0.7f;
|
||||
|
||||
OptionButton* element = new OptionButton(optId);
|
||||
element->setImageDef(def, true);
|
||||
element->updateImage(&minecraft->options);
|
||||
|
||||
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
|
||||
|
||||
OptionsItem* item = new OptionsItem(optId, itemLabel, element);
|
||||
|
||||
addChild(item);
|
||||
setupPositions();
|
||||
}
|
||||
|
||||
void OptionsGroup::createProgressSlider(OptionId optId, Minecraft* minecraft ) {
|
||||
Slider* element = new SliderFloat(minecraft, optId);
|
||||
element->width = 100;
|
||||
element->height = 20;
|
||||
|
||||
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
|
||||
OptionsItem* item = new OptionsItem(optId, itemLabel, element);
|
||||
addChild(item);
|
||||
setupPositions();
|
||||
}
|
||||
|
||||
void OptionsGroup::createStepSlider(OptionId optId, Minecraft* minecraft ) {
|
||||
Slider* element = new SliderInt(minecraft, optId);
|
||||
element->width = 100;
|
||||
element->height = 20;
|
||||
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
|
||||
OptionsItem* item = new OptionsItem(optId, itemLabel, element);
|
||||
addChild(item);
|
||||
setupPositions();
|
||||
}
|
||||
|
||||
void OptionsGroup::createTextbox(OptionId optId, Minecraft* minecraft) {
|
||||
TextBox* element = new TextOption(minecraft, optId);
|
||||
element->width = 100;
|
||||
element->height = 20;
|
||||
|
||||
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
|
||||
OptionsItem* item = new OptionsItem(optId, itemLabel, element);
|
||||
addChild(item);
|
||||
setupPositions();
|
||||
}
|
||||
|
||||
void OptionsGroup::createKey(OptionId optId, Minecraft* minecraft) {
|
||||
KeyOption* element = new KeyOption(minecraft, optId);
|
||||
element->width = 50;
|
||||
element->height = 20;
|
||||
|
||||
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
|
||||
OptionsItem* item = new OptionsItem(optId, itemLabel, element);
|
||||
addChild(item);
|
||||
setupPositions();
|
||||
#include "OptionsGroup.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "ImageButton.hpp"
|
||||
#include "OptionsItem.hpp"
|
||||
#include "Slider.hpp"
|
||||
#include "locale/I18n.hpp"
|
||||
#include "TextOption.hpp"
|
||||
#include "KeyOption.hpp"
|
||||
|
||||
OptionsGroup::OptionsGroup( std::string labelID ) {
|
||||
label = I18n::get(labelID);
|
||||
}
|
||||
|
||||
void OptionsGroup::setupPositions() {
|
||||
// First we write the header and then we add the items
|
||||
int curY = y + 18;
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->width = width - 5;
|
||||
|
||||
(*it)->y = curY;
|
||||
(*it)->x = x + 10;
|
||||
(*it)->setupPositions();
|
||||
curY += (*it)->height + 3;
|
||||
}
|
||||
height = curY;
|
||||
}
|
||||
|
||||
void OptionsGroup::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
float padX = 10.0f;
|
||||
float padY = 5.0f;
|
||||
|
||||
minecraft->font->draw(label, (float)x + padX, (float)y + padY, 0xffffffff, false);
|
||||
|
||||
super::render(minecraft, xm, ym);
|
||||
}
|
||||
|
||||
OptionsGroup& OptionsGroup::addOptionItem(OptionId optId, Minecraft* minecraft ) {
|
||||
auto option = minecraft->options.getOpt(optId);
|
||||
|
||||
if (option == nullptr) return *this;
|
||||
|
||||
// TODO: do a options key class to check it faster via dynamic_cast
|
||||
if (option->getStringId().find("options.key") != std::string::npos) createKey(optId, minecraft);
|
||||
else if (dynamic_cast<OptionBool*>(option)) createToggle(optId, minecraft);
|
||||
else if (dynamic_cast<OptionFloat*>(option)) createProgressSlider(optId, minecraft);
|
||||
else if (dynamic_cast<OptionInt*>(option)) createStepSlider(optId, minecraft);
|
||||
else if (dynamic_cast<OptionString*>(option)) createTextbox(optId, minecraft);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// TODO: wrap this copypaste shit into templates
|
||||
|
||||
void OptionsGroup::createToggle(OptionId optId, Minecraft* minecraft ) {
|
||||
ImageDef def;
|
||||
|
||||
def.setSrc(IntRectangle(160, 206, 39, 20));
|
||||
def.name = "gui/touchgui.png";
|
||||
def.width = 39 * 0.7f;
|
||||
def.height = 20 * 0.7f;
|
||||
|
||||
OptionButton* element = new OptionButton(optId);
|
||||
element->setImageDef(def, true);
|
||||
element->updateImage(&minecraft->options);
|
||||
|
||||
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
|
||||
|
||||
OptionsItem* item = new OptionsItem(optId, itemLabel, element);
|
||||
|
||||
addChild(item);
|
||||
setupPositions();
|
||||
}
|
||||
|
||||
void OptionsGroup::createProgressSlider(OptionId optId, Minecraft* minecraft ) {
|
||||
Slider* element = new SliderFloat(minecraft, optId);
|
||||
element->width = 100;
|
||||
element->height = 20;
|
||||
|
||||
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
|
||||
OptionsItem* item = new OptionsItem(optId, itemLabel, element);
|
||||
addChild(item);
|
||||
setupPositions();
|
||||
}
|
||||
|
||||
void OptionsGroup::createStepSlider(OptionId optId, Minecraft* minecraft ) {
|
||||
Slider* element = new SliderInt(minecraft, optId);
|
||||
element->width = 100;
|
||||
element->height = 20;
|
||||
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
|
||||
OptionsItem* item = new OptionsItem(optId, itemLabel, element);
|
||||
addChild(item);
|
||||
setupPositions();
|
||||
}
|
||||
|
||||
void OptionsGroup::createTextbox(OptionId optId, Minecraft* minecraft) {
|
||||
TextBox* element = new TextOption(minecraft, optId);
|
||||
element->width = 100;
|
||||
element->height = 20;
|
||||
|
||||
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
|
||||
OptionsItem* item = new OptionsItem(optId, itemLabel, element);
|
||||
addChild(item);
|
||||
setupPositions();
|
||||
}
|
||||
|
||||
void OptionsGroup::createKey(OptionId optId, Minecraft* minecraft) {
|
||||
KeyOption* element = new KeyOption(minecraft, optId);
|
||||
element->width = 50;
|
||||
element->height = 20;
|
||||
|
||||
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
|
||||
OptionsItem* item = new OptionsItem(optId, itemLabel, element);
|
||||
addChild(item);
|
||||
setupPositions();
|
||||
}
|
||||
@@ -3,9 +3,9 @@
|
||||
//package net.minecraft.client.gui;
|
||||
|
||||
#include <string>
|
||||
#include "GuiElementContainer.h"
|
||||
#include "ScrollingPane.h"
|
||||
#include "../../Options.h"
|
||||
#include "GuiElementContainer.hpp"
|
||||
#include "ScrollingPane.hpp"
|
||||
#include "client/Options.hpp"
|
||||
|
||||
class Font;
|
||||
class Minecraft;
|
||||
@@ -1,42 +1,42 @@
|
||||
#include "OptionsItem.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../../locale/I18n.h"
|
||||
#include "../../../util/Mth.h"
|
||||
OptionsItem::OptionsItem( OptionId optionId, std::string label, GuiElement* element )
|
||||
: GuiElementContainer(false, true, 0, 0, 24, 12),
|
||||
m_optionId(optionId),
|
||||
m_label(label) {
|
||||
addChild(element);
|
||||
}
|
||||
|
||||
void OptionsItem::setupPositions() {
|
||||
int currentHeight = 0;
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->x = x + width - (*it)->width - 15;
|
||||
(*it)->y = y + currentHeight;
|
||||
currentHeight += (*it)->height;
|
||||
}
|
||||
height = currentHeight;
|
||||
}
|
||||
|
||||
void OptionsItem::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
int yOffset = (height - 8) / 2;
|
||||
std::string text = m_label;
|
||||
if (m_optionId == OPTIONS_GUI_SCALE) {
|
||||
int value = minecraft->options.getIntValue(OPTIONS_GUI_SCALE);
|
||||
std::string scaleText;
|
||||
switch (value) {
|
||||
case 0: scaleText = I18n::get("options.guiScale.auto"); break;
|
||||
case 1: scaleText = I18n::get("options.guiScale.small"); break;
|
||||
case 2: scaleText = I18n::get("options.guiScale.medium"); break;
|
||||
case 3: scaleText = I18n::get("options.guiScale.large"); break;
|
||||
case 4: scaleText = I18n::get("options.guiScale.larger"); break;
|
||||
case 5: scaleText = I18n::get("options.guiScale.largest"); break;
|
||||
default: scaleText = I18n::get("options.guiScale.auto"); break;
|
||||
}
|
||||
text += ": " + scaleText;
|
||||
}
|
||||
|
||||
minecraft->font->draw(text, (float)x, (float)y + yOffset, 0x909090, false);
|
||||
super::render(minecraft, xm, ym);
|
||||
#include "OptionsItem.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "locale/I18n.hpp"
|
||||
#include "util/Mth.hpp"
|
||||
OptionsItem::OptionsItem( OptionId optionId, std::string label, GuiElement* element )
|
||||
: GuiElementContainer(false, true, 0, 0, 24, 12),
|
||||
m_optionId(optionId),
|
||||
m_label(label) {
|
||||
addChild(element);
|
||||
}
|
||||
|
||||
void OptionsItem::setupPositions() {
|
||||
int currentHeight = 0;
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->x = x + width - (*it)->width - 15;
|
||||
(*it)->y = y + currentHeight;
|
||||
currentHeight += (*it)->height;
|
||||
}
|
||||
height = currentHeight;
|
||||
}
|
||||
|
||||
void OptionsItem::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
int yOffset = (height - 8) / 2;
|
||||
std::string text = m_label;
|
||||
if (m_optionId == OPTIONS_GUI_SCALE) {
|
||||
int value = minecraft->options.getIntValue(OPTIONS_GUI_SCALE);
|
||||
std::string scaleText;
|
||||
switch (value) {
|
||||
case 0: scaleText = I18n::get("options.guiScale.auto"); break;
|
||||
case 1: scaleText = I18n::get("options.guiScale.small"); break;
|
||||
case 2: scaleText = I18n::get("options.guiScale.medium"); break;
|
||||
case 3: scaleText = I18n::get("options.guiScale.large"); break;
|
||||
case 4: scaleText = I18n::get("options.guiScale.larger"); break;
|
||||
case 5: scaleText = I18n::get("options.guiScale.largest"); break;
|
||||
default: scaleText = I18n::get("options.guiScale.auto"); break;
|
||||
}
|
||||
text += ": " + scaleText;
|
||||
}
|
||||
|
||||
minecraft->font->draw(text, (float)x, (float)y + yOffset, 0x909090, false);
|
||||
super::render(minecraft, xm, ym);
|
||||
}
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "GuiElementContainer.h"
|
||||
#include "../../../world/item/ItemInstance.h"
|
||||
#include "../../../client/Options.h"
|
||||
#include "GuiElementContainer.hpp"
|
||||
#include "world/item/ItemInstance.hpp"
|
||||
#include "client/Options.hpp"
|
||||
class Font;
|
||||
class Textures;
|
||||
class NinePatchLayer;
|
||||
@@ -1,299 +1,299 @@
|
||||
#include "RolledSelectionListH.h"
|
||||
#include "../../renderer/Tesselator.h"
|
||||
#include "../../renderer/gles.h"
|
||||
#include "../../../platform/input/Mouse.h"
|
||||
#include "../../../platform/input/Multitouch.h"
|
||||
#include "../../../util/Mth.h"
|
||||
#include "../../renderer/Textures.h"
|
||||
#include "MinecraftClient.h"
|
||||
|
||||
|
||||
RolledSelectionListH::RolledSelectionListH( MinecraftClient& minecraft, int width, int height, int x0, int x1, int y0, int y1, int itemWidth )
|
||||
: minecraft(minecraft),
|
||||
width(width),
|
||||
height(height),
|
||||
x0((float)x0),
|
||||
x1((float)x1),
|
||||
y0((float)y0),
|
||||
y1((float)y1),
|
||||
itemWidth(itemWidth),
|
||||
selectionX(-1),
|
||||
lastSelectionTime(0),
|
||||
lastSelection(-1),
|
||||
renderSelection(true),
|
||||
doRenderHeader(false),
|
||||
headerWidth(0),
|
||||
dragState(DRAG_OUTSIDE),
|
||||
xDrag(0.0f),
|
||||
xo(0.0f),
|
||||
xoo(0.0f),
|
||||
xInertia(0.0f),
|
||||
_componentSelected(false),
|
||||
_renderTopBorder(true),
|
||||
_renderBottomBorder(true),
|
||||
_lastxoo(0),
|
||||
_xinertia(0)
|
||||
{
|
||||
xo = xoo = (float)(itemWidth-width) * 0.5f;
|
||||
_lastxoo = xoo;
|
||||
}
|
||||
|
||||
void RolledSelectionListH::setRenderSelection( bool _renderSelection )
|
||||
{
|
||||
renderSelection = _renderSelection;
|
||||
}
|
||||
|
||||
void RolledSelectionListH::setComponentSelected(bool selected) {
|
||||
_componentSelected = selected;
|
||||
}
|
||||
|
||||
void RolledSelectionListH::setRenderHeader( bool _renderHeader, int _headerHeight )
|
||||
{
|
||||
doRenderHeader = _renderHeader;
|
||||
headerWidth = _headerHeight;
|
||||
|
||||
if (!doRenderHeader) {
|
||||
headerWidth = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int RolledSelectionListH::getMaxPosition()
|
||||
{
|
||||
return getNumberOfItems() * itemWidth + headerWidth;
|
||||
}
|
||||
|
||||
int RolledSelectionListH::getItemAtPosition( int x, int y )
|
||||
{
|
||||
int clickSlotPos = (int)(x - x0 - headerWidth + (int) xo - 4);
|
||||
int isInsideY = y >= y0 && y <= y1;
|
||||
return isInsideY? getItemAtXPositionRaw(clickSlotPos) : -1;
|
||||
}
|
||||
|
||||
int RolledSelectionListH::getItemAtXPositionRaw(int x) {
|
||||
int slot = x / itemWidth;
|
||||
bool isInsideX = slot >= 0 && x >= 0 && slot < getNumberOfItems();
|
||||
return isInsideX? slot : -1;
|
||||
}
|
||||
|
||||
bool RolledSelectionListH::capXPosition()
|
||||
{
|
||||
const float MinX = (float)(itemWidth-width)/2;
|
||||
const float MaxX = MinX + (getNumberOfItems()-1) * itemWidth;
|
||||
if (xo < MinX) { xo = MinX; xInertia = 0; return true; }
|
||||
if (xo > MaxX) { xo = MaxX; xInertia = 0; return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
void RolledSelectionListH::tick() {
|
||||
|
||||
//if (Mouse::isButtonDown(MouseAction::ACTION_LEFT))
|
||||
{
|
||||
_xinertia = _lastxoo - xoo;
|
||||
}
|
||||
_lastxoo = xoo;
|
||||
xoo = xo - xInertia;
|
||||
}
|
||||
|
||||
float RolledSelectionListH::getPos(float alpha) {
|
||||
return xoo - xInertia * alpha;
|
||||
}
|
||||
|
||||
void RolledSelectionListH::render( int xm, int ym, float a )
|
||||
{
|
||||
renderBackground();
|
||||
|
||||
int itemCount = getNumberOfItems();
|
||||
|
||||
//float yy0 = height / 2.0f + 124;
|
||||
//float yy1 = yy0 + 6;
|
||||
|
||||
if (Mouse::isButtonDown(MouseAction::ACTION_LEFT)) {
|
||||
touched();
|
||||
//LOGI("DOWN ym: %d\n", ym);
|
||||
if (ym >= y0 && ym <= y1) {
|
||||
if (dragState == NO_DRAG) {
|
||||
lastSelectionTime = getTimeMs();
|
||||
lastSelection = getItemAtPosition(xm, height/2);
|
||||
//float localX = (float)(xm*Gui::InvGuiScale - x0 - xo + lastSelection * itemWidth + headerWidth);
|
||||
selectStart(lastSelection, 0, 0);//localX, ym-y0);
|
||||
selectionX = xm;
|
||||
}
|
||||
else if (dragState >= 0) {
|
||||
xo -= (xm - xDrag);
|
||||
xoo = xo;
|
||||
}
|
||||
dragState = DRAG_NORMAL;
|
||||
//const int* ids;
|
||||
//LOGI("mtouch: %d\n", Multitouch::getActivePointerIds(&ids));
|
||||
}
|
||||
} else {
|
||||
if (dragState >= 0) {
|
||||
if (dragState >= 0) {
|
||||
xInertia = _xinertia < 0? Mth::Max(-20.0f, _xinertia) : Mth::Min(20.0f, _xinertia);
|
||||
}
|
||||
//LOGI("Inertia: %f. Time: %d, delta-x: %d, (xm, sel: %d, %d)\n", xInertia, getTimeMs() - lastSelectionTime, std::abs(selectionX - xm), xm, selectionX);
|
||||
// kill small inertia values when releasing scrollist
|
||||
if (std::abs(xInertia) <= 2.0001f) {
|
||||
xInertia = 0.0f;
|
||||
}
|
||||
|
||||
if (std::abs(xInertia) <= 10 && getTimeMs() - lastSelectionTime < 300)
|
||||
{
|
||||
int slot = getItemAtPosition(xm, height/2);
|
||||
//LOGI("slot: %d, lt: %d. diff: %d - %d\n", slot, lastSelection, selectionX, xm);
|
||||
if (slot >= 0 && slot == lastSelection && std::abs(selectionX - xm) < 10)
|
||||
selectItem(slot, false);
|
||||
else
|
||||
selectCancel();
|
||||
} else {
|
||||
selectCancel();
|
||||
}
|
||||
}
|
||||
|
||||
// if (slot >= 0 && std::abs(selectionX - xm) < itemWidth)
|
||||
// {
|
||||
// bool doubleClick = false;
|
||||
// selectItem(slot, doubleClick);
|
||||
// //xInertia = 0.0f;
|
||||
// }
|
||||
//}
|
||||
dragState = NO_DRAG;
|
||||
|
||||
xo = getPos(a);
|
||||
}
|
||||
xDrag = (float)xm;
|
||||
|
||||
capXPosition();
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
float by0 = _renderTopBorder? y0 : 0;
|
||||
float by1 = _renderBottomBorder? y1 : height;
|
||||
|
||||
//LOGI("x: %f\n", xo);
|
||||
|
||||
minecraft.textures().loadAndBindTexture("gui/background.png");
|
||||
glColor4f2(1.0f, 1, 1, 1);
|
||||
float s = 32;
|
||||
t.begin();
|
||||
t.color(0x202020);
|
||||
t.vertexUV(x0, by1, 0, (x0 + (int) xo) / s, by1 / s);
|
||||
t.vertexUV(x1, by1, 0, (x1 + (int) xo) / s, by1 / s);
|
||||
t.vertexUV(x1, by0, 0, (x1 + (int) xo) / s, by0 / s);
|
||||
t.vertexUV(x0, by0, 0, (x0 + (int) xo) / s, by0 / s);
|
||||
t.draw();
|
||||
|
||||
const int HalfHeight = 48;
|
||||
|
||||
if (getNumberOfItems() == 0) xo = 0;
|
||||
|
||||
int rowY = (int)(height / 2 - HalfHeight + 8);
|
||||
int rowBaseX = (int)(x0 /*+ 4*/ - (int) xo);
|
||||
|
||||
if (doRenderHeader) {
|
||||
renderHeader(rowBaseX, rowY, t);
|
||||
}
|
||||
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
|
||||
float x = (float)(rowBaseX + (i) * itemWidth + headerWidth);
|
||||
float h = (float)itemWidth;
|
||||
|
||||
if (x > x1 || (x + h) < x0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (renderSelection && isSelectedItem(i)) {
|
||||
float y0 = height / 2.0f - HalfHeight - 4; //@kindle-res:+2
|
||||
float y1 = height / 2.0f + HalfHeight - 4; //@kindle-res:-6
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
|
||||
int ew = 0;
|
||||
int color = 0x808080;
|
||||
if (_componentSelected) {
|
||||
ew = 0;
|
||||
color = 0x7F89BF;
|
||||
}
|
||||
t.begin();
|
||||
t.color(color);
|
||||
t.vertex(x - 1 - ew, y0 - ew, 0);
|
||||
t.vertex(x - 1 - ew, y1 + ew, 0);
|
||||
t.vertex(x + h + 1 + ew, y1 + ew, 0);
|
||||
t.vertex(x + h + 1 + ew, y0 - ew, 0);
|
||||
|
||||
t.color(0x000000);
|
||||
t.vertex(x, y0 + 1, 0);
|
||||
t.vertex(x, y1 - 1, 0);
|
||||
t.vertex(x + h, y1 - 1, 0);
|
||||
t.vertex(x + h, y0 + 1, 0);
|
||||
|
||||
t.draw();
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
}
|
||||
renderItem(i, (int)x, rowY, (int)h, t);
|
||||
}
|
||||
|
||||
glDisable2(GL_DEPTH_TEST);
|
||||
|
||||
if (_renderTopBorder)
|
||||
renderHoleBackground(0, y0, 255, 255);
|
||||
if (_renderBottomBorder)
|
||||
renderHoleBackground(y1, (float)height, 255, 255);
|
||||
|
||||
//glEnable2(GL_BLEND);
|
||||
//glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
//glDisable2(GL_ALPHA_TEST);
|
||||
//glShadeModel2(GL_SMOOTH);
|
||||
|
||||
//glDisable2(GL_TEXTURE_2D);
|
||||
|
||||
//const int d = 4;
|
||||
//t.begin();
|
||||
//t.color(0x000000, 0);
|
||||
//t.vertexUV(y0, x0 + d, 0, 0, 1);
|
||||
//t.vertexUV(y1, x0 + d, 0, 1, 1);
|
||||
//t.color(0x000000, 255);
|
||||
//t.vertexUV(y1, x0, 0, 1, 0);
|
||||
//t.vertexUV(y0, x0, 0, 0, 0);
|
||||
//t.draw();
|
||||
|
||||
//t.begin();
|
||||
//t.color(0x000000, 255);
|
||||
//t.vertexUV(y0, x1, 0, 0, 1);
|
||||
//t.vertexUV(y1, x1, 0, 1, 1);
|
||||
//t.color(0x000000, 0);
|
||||
//t.vertexUV(y1, x1 - d, 0, 1, 0);
|
||||
//t.vertexUV(y0, x1 - d, 0, 0, 0);
|
||||
//t.draw();
|
||||
|
||||
//renderDecorations(xm, ym);
|
||||
|
||||
//glEnable2(GL_TEXTURE_2D);
|
||||
glEnable2(GL_DEPTH_TEST);
|
||||
|
||||
//glShadeModel2(GL_FLAT);
|
||||
//glEnable2(GL_ALPHA_TEST);
|
||||
//glDisable2(GL_BLEND);
|
||||
}
|
||||
|
||||
void RolledSelectionListH::renderHoleBackground( /*float x0, float x1,*/ float y0, float y1, int a0, int a1 )
|
||||
{
|
||||
Tesselator& t = Tesselator::instance;
|
||||
minecraft.textures().loadAndBindTexture("gui/background.png");
|
||||
glColor4f2(1.0f, 1, 1, 1);
|
||||
float s = 32;
|
||||
t.begin();
|
||||
t.color(0x505050, a1);
|
||||
t.vertexUV(0, y1, 0, 0, y1 / s);
|
||||
t.vertexUV((float)width, y1, 0, width / s, y1 / s);
|
||||
t.color(0x505050, a0);
|
||||
t.vertexUV((float)width, y0, 0, width / s, y0 / s);
|
||||
t.vertexUV(0, y0, 0, 0, y0 / s);
|
||||
t.draw();
|
||||
//printf("x, y, x1, y1: %d, %d, %d, %d\n", 0, (int)y0, width, (int)y1);
|
||||
}
|
||||
|
||||
void RolledSelectionListH::touched()
|
||||
{
|
||||
}
|
||||
#include "RolledSelectionListH.hpp"
|
||||
#include "client/renderer/Tesselator.hpp"
|
||||
#include "client/renderer/gles.hpp"
|
||||
#include "platform/input/Mouse.hpp"
|
||||
#include "platform/input/Multitouch.hpp"
|
||||
#include "util/Mth.hpp"
|
||||
#include "client/renderer/Textures.hpp"
|
||||
#include "MinecraftClient.hpp"
|
||||
|
||||
|
||||
RolledSelectionListH::RolledSelectionListH( MinecraftClient& minecraft, int width, int height, int x0, int x1, int y0, int y1, int itemWidth )
|
||||
: minecraft(minecraft),
|
||||
width(width),
|
||||
height(height),
|
||||
x0((float)x0),
|
||||
x1((float)x1),
|
||||
y0((float)y0),
|
||||
y1((float)y1),
|
||||
itemWidth(itemWidth),
|
||||
selectionX(-1),
|
||||
lastSelectionTime(0),
|
||||
lastSelection(-1),
|
||||
renderSelection(true),
|
||||
doRenderHeader(false),
|
||||
headerWidth(0),
|
||||
dragState(DRAG_OUTSIDE),
|
||||
xDrag(0.0f),
|
||||
xo(0.0f),
|
||||
xoo(0.0f),
|
||||
xInertia(0.0f),
|
||||
_componentSelected(false),
|
||||
_renderTopBorder(true),
|
||||
_renderBottomBorder(true),
|
||||
_lastxoo(0),
|
||||
_xinertia(0)
|
||||
{
|
||||
xo = xoo = (float)(itemWidth-width) * 0.5f;
|
||||
_lastxoo = xoo;
|
||||
}
|
||||
|
||||
void RolledSelectionListH::setRenderSelection( bool _renderSelection )
|
||||
{
|
||||
renderSelection = _renderSelection;
|
||||
}
|
||||
|
||||
void RolledSelectionListH::setComponentSelected(bool selected) {
|
||||
_componentSelected = selected;
|
||||
}
|
||||
|
||||
void RolledSelectionListH::setRenderHeader( bool _renderHeader, int _headerHeight )
|
||||
{
|
||||
doRenderHeader = _renderHeader;
|
||||
headerWidth = _headerHeight;
|
||||
|
||||
if (!doRenderHeader) {
|
||||
headerWidth = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int RolledSelectionListH::getMaxPosition()
|
||||
{
|
||||
return getNumberOfItems() * itemWidth + headerWidth;
|
||||
}
|
||||
|
||||
int RolledSelectionListH::getItemAtPosition( int x, int y )
|
||||
{
|
||||
int clickSlotPos = (int)(x - x0 - headerWidth + (int) xo - 4);
|
||||
int isInsideY = y >= y0 && y <= y1;
|
||||
return isInsideY? getItemAtXPositionRaw(clickSlotPos) : -1;
|
||||
}
|
||||
|
||||
int RolledSelectionListH::getItemAtXPositionRaw(int x) {
|
||||
int slot = x / itemWidth;
|
||||
bool isInsideX = slot >= 0 && x >= 0 && slot < getNumberOfItems();
|
||||
return isInsideX? slot : -1;
|
||||
}
|
||||
|
||||
bool RolledSelectionListH::capXPosition()
|
||||
{
|
||||
const float MinX = (float)(itemWidth-width)/2;
|
||||
const float MaxX = MinX + (getNumberOfItems()-1) * itemWidth;
|
||||
if (xo < MinX) { xo = MinX; xInertia = 0; return true; }
|
||||
if (xo > MaxX) { xo = MaxX; xInertia = 0; return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
void RolledSelectionListH::tick() {
|
||||
|
||||
//if (Mouse::isButtonDown(MouseAction::ACTION_LEFT))
|
||||
{
|
||||
_xinertia = _lastxoo - xoo;
|
||||
}
|
||||
_lastxoo = xoo;
|
||||
xoo = xo - xInertia;
|
||||
}
|
||||
|
||||
float RolledSelectionListH::getPos(float alpha) {
|
||||
return xoo - xInertia * alpha;
|
||||
}
|
||||
|
||||
void RolledSelectionListH::render( int xm, int ym, float a )
|
||||
{
|
||||
renderBackground();
|
||||
|
||||
int itemCount = getNumberOfItems();
|
||||
|
||||
//float yy0 = height / 2.0f + 124;
|
||||
//float yy1 = yy0 + 6;
|
||||
|
||||
if (Mouse::isButtonDown(MouseAction::ACTION_LEFT)) {
|
||||
touched();
|
||||
//LOGI("DOWN ym: %d\n", ym);
|
||||
if (ym >= y0 && ym <= y1) {
|
||||
if (dragState == NO_DRAG) {
|
||||
lastSelectionTime = getTimeMs();
|
||||
lastSelection = getItemAtPosition(xm, height/2);
|
||||
//float localX = (float)(xm*Gui::InvGuiScale - x0 - xo + lastSelection * itemWidth + headerWidth);
|
||||
selectStart(lastSelection, 0, 0);//localX, ym-y0);
|
||||
selectionX = xm;
|
||||
}
|
||||
else if (dragState >= 0) {
|
||||
xo -= (xm - xDrag);
|
||||
xoo = xo;
|
||||
}
|
||||
dragState = DRAG_NORMAL;
|
||||
//const int* ids;
|
||||
//LOGI("mtouch: %d\n", Multitouch::getActivePointerIds(&ids));
|
||||
}
|
||||
} else {
|
||||
if (dragState >= 0) {
|
||||
if (dragState >= 0) {
|
||||
xInertia = _xinertia < 0? Mth::Max(-20.0f, _xinertia) : Mth::Min(20.0f, _xinertia);
|
||||
}
|
||||
//LOGI("Inertia: %f. Time: %d, delta-x: %d, (xm, sel: %d, %d)\n", xInertia, getTimeMs() - lastSelectionTime, std::abs(selectionX - xm), xm, selectionX);
|
||||
// kill small inertia values when releasing scrollist
|
||||
if (std::abs(xInertia) <= 2.0001f) {
|
||||
xInertia = 0.0f;
|
||||
}
|
||||
|
||||
if (std::abs(xInertia) <= 10 && getTimeMs() - lastSelectionTime < 300)
|
||||
{
|
||||
int slot = getItemAtPosition(xm, height/2);
|
||||
//LOGI("slot: %d, lt: %d. diff: %d - %d\n", slot, lastSelection, selectionX, xm);
|
||||
if (slot >= 0 && slot == lastSelection && std::abs(selectionX - xm) < 10)
|
||||
selectItem(slot, false);
|
||||
else
|
||||
selectCancel();
|
||||
} else {
|
||||
selectCancel();
|
||||
}
|
||||
}
|
||||
|
||||
// if (slot >= 0 && std::abs(selectionX - xm) < itemWidth)
|
||||
// {
|
||||
// bool doubleClick = false;
|
||||
// selectItem(slot, doubleClick);
|
||||
// //xInertia = 0.0f;
|
||||
// }
|
||||
//}
|
||||
dragState = NO_DRAG;
|
||||
|
||||
xo = getPos(a);
|
||||
}
|
||||
xDrag = (float)xm;
|
||||
|
||||
capXPosition();
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
float by0 = _renderTopBorder? y0 : 0;
|
||||
float by1 = _renderBottomBorder? y1 : height;
|
||||
|
||||
//LOGI("x: %f\n", xo);
|
||||
|
||||
minecraft.textures().loadAndBindTexture("gui/background.png");
|
||||
glColor4f2(1.0f, 1, 1, 1);
|
||||
float s = 32;
|
||||
t.begin();
|
||||
t.color(0x202020);
|
||||
t.vertexUV(x0, by1, 0, (x0 + (int) xo) / s, by1 / s);
|
||||
t.vertexUV(x1, by1, 0, (x1 + (int) xo) / s, by1 / s);
|
||||
t.vertexUV(x1, by0, 0, (x1 + (int) xo) / s, by0 / s);
|
||||
t.vertexUV(x0, by0, 0, (x0 + (int) xo) / s, by0 / s);
|
||||
t.draw();
|
||||
|
||||
const int HalfHeight = 48;
|
||||
|
||||
if (getNumberOfItems() == 0) xo = 0;
|
||||
|
||||
int rowY = (int)(height / 2 - HalfHeight + 8);
|
||||
int rowBaseX = (int)(x0 /*+ 4*/ - (int) xo);
|
||||
|
||||
if (doRenderHeader) {
|
||||
renderHeader(rowBaseX, rowY, t);
|
||||
}
|
||||
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
|
||||
float x = (float)(rowBaseX + (i) * itemWidth + headerWidth);
|
||||
float h = (float)itemWidth;
|
||||
|
||||
if (x > x1 || (x + h) < x0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (renderSelection && isSelectedItem(i)) {
|
||||
float y0 = height / 2.0f - HalfHeight - 4; //@kindle-res:+2
|
||||
float y1 = height / 2.0f + HalfHeight - 4; //@kindle-res:-6
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
|
||||
int ew = 0;
|
||||
int color = 0x808080;
|
||||
if (_componentSelected) {
|
||||
ew = 0;
|
||||
color = 0x7F89BF;
|
||||
}
|
||||
t.begin();
|
||||
t.color(color);
|
||||
t.vertex(x - 1 - ew, y0 - ew, 0);
|
||||
t.vertex(x - 1 - ew, y1 + ew, 0);
|
||||
t.vertex(x + h + 1 + ew, y1 + ew, 0);
|
||||
t.vertex(x + h + 1 + ew, y0 - ew, 0);
|
||||
|
||||
t.color(0x000000);
|
||||
t.vertex(x, y0 + 1, 0);
|
||||
t.vertex(x, y1 - 1, 0);
|
||||
t.vertex(x + h, y1 - 1, 0);
|
||||
t.vertex(x + h, y0 + 1, 0);
|
||||
|
||||
t.draw();
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
}
|
||||
renderItem(i, (int)x, rowY, (int)h, t);
|
||||
}
|
||||
|
||||
glDisable2(GL_DEPTH_TEST);
|
||||
|
||||
if (_renderTopBorder)
|
||||
renderHoleBackground(0, y0, 255, 255);
|
||||
if (_renderBottomBorder)
|
||||
renderHoleBackground(y1, (float)height, 255, 255);
|
||||
|
||||
//glEnable2(GL_BLEND);
|
||||
//glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
//glDisable2(GL_ALPHA_TEST);
|
||||
//glShadeModel2(GL_SMOOTH);
|
||||
|
||||
//glDisable2(GL_TEXTURE_2D);
|
||||
|
||||
//const int d = 4;
|
||||
//t.begin();
|
||||
//t.color(0x000000, 0);
|
||||
//t.vertexUV(y0, x0 + d, 0, 0, 1);
|
||||
//t.vertexUV(y1, x0 + d, 0, 1, 1);
|
||||
//t.color(0x000000, 255);
|
||||
//t.vertexUV(y1, x0, 0, 1, 0);
|
||||
//t.vertexUV(y0, x0, 0, 0, 0);
|
||||
//t.draw();
|
||||
|
||||
//t.begin();
|
||||
//t.color(0x000000, 255);
|
||||
//t.vertexUV(y0, x1, 0, 0, 1);
|
||||
//t.vertexUV(y1, x1, 0, 1, 1);
|
||||
//t.color(0x000000, 0);
|
||||
//t.vertexUV(y1, x1 - d, 0, 1, 0);
|
||||
//t.vertexUV(y0, x1 - d, 0, 0, 0);
|
||||
//t.draw();
|
||||
|
||||
//renderDecorations(xm, ym);
|
||||
|
||||
//glEnable2(GL_TEXTURE_2D);
|
||||
glEnable2(GL_DEPTH_TEST);
|
||||
|
||||
//glShadeModel2(GL_FLAT);
|
||||
//glEnable2(GL_ALPHA_TEST);
|
||||
//glDisable2(GL_BLEND);
|
||||
}
|
||||
|
||||
void RolledSelectionListH::renderHoleBackground( /*float x0, float x1,*/ float y0, float y1, int a0, int a1 )
|
||||
{
|
||||
Tesselator& t = Tesselator::instance;
|
||||
minecraft.textures().loadAndBindTexture("gui/background.png");
|
||||
glColor4f2(1.0f, 1, 1, 1);
|
||||
float s = 32;
|
||||
t.begin();
|
||||
t.color(0x505050, a1);
|
||||
t.vertexUV(0, y1, 0, 0, y1 / s);
|
||||
t.vertexUV((float)width, y1, 0, width / s, y1 / s);
|
||||
t.color(0x505050, a0);
|
||||
t.vertexUV((float)width, y0, 0, width / s, y0 / s);
|
||||
t.vertexUV(0, y0, 0, 0, y0 / s);
|
||||
t.draw();
|
||||
//printf("x, y, x1, y1: %d, %d, %d, %d\n", 0, (int)y0, width, (int)y1);
|
||||
}
|
||||
|
||||
void RolledSelectionListH::touched()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "../GuiComponent.h"
|
||||
#include "client/gui/GuiComponent.hpp"
|
||||
class MinecraftClient;
|
||||
class Tesselator;
|
||||
|
||||
@@ -1,352 +1,352 @@
|
||||
#include "RolledSelectionListV.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../renderer/Tesselator.h"
|
||||
#include "../../renderer/gles.h"
|
||||
#include "../../../platform/input/Mouse.h"
|
||||
#include "../../../util/Mth.h"
|
||||
#include "../../renderer/Textures.h"
|
||||
|
||||
|
||||
RolledSelectionListV::RolledSelectionListV( Minecraft* minecraft_, int width_, int height_, int x0_, int x1_, int y0_, int y1_, int itemHeight_ )
|
||||
: minecraft(minecraft_),
|
||||
width(width_),
|
||||
height(height_),
|
||||
x0((float)x0_),
|
||||
x1((float)x1_),
|
||||
y0((float)y0_),
|
||||
y1((float)y1_),
|
||||
itemHeight(itemHeight_),
|
||||
selectionY(-1),
|
||||
lastSelectionTime(0),
|
||||
lastSelection(-1),
|
||||
renderSelection(true),
|
||||
doRenderHeader(false),
|
||||
headerHeight(0),
|
||||
dragState(DRAG_OUTSIDE),
|
||||
yDrag(0.0f),
|
||||
yo(0.0f),
|
||||
yoo(0.0f),
|
||||
yInertia(0.0f),
|
||||
_componentSelected(false),
|
||||
_renderDirtBackground(true),
|
||||
_renderTopBorder(true),
|
||||
_renderBottomBorder(true),
|
||||
_lastyoo(0),
|
||||
_yinertia(0),
|
||||
_stickPixels(0),
|
||||
_lastxm(0),
|
||||
_lastym(0)
|
||||
{
|
||||
yo = yoo = 0;//(float)(-itemHeight) * 0.5f;
|
||||
_lastyoo = yoo;
|
||||
}
|
||||
|
||||
void RolledSelectionListV::setRenderSelection( bool _renderSelection )
|
||||
{
|
||||
renderSelection = _renderSelection;
|
||||
}
|
||||
|
||||
void RolledSelectionListV::setComponentSelected(bool selected) {
|
||||
_componentSelected = selected;
|
||||
}
|
||||
|
||||
void RolledSelectionListV::setRenderHeader( bool _renderHeader, int _headerHeight )
|
||||
{
|
||||
doRenderHeader = _renderHeader;
|
||||
headerHeight = _headerHeight;
|
||||
|
||||
if (!doRenderHeader) {
|
||||
headerHeight = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int RolledSelectionListV::getMaxPosition()
|
||||
{
|
||||
return getNumberOfItems() * itemHeight + headerHeight;
|
||||
}
|
||||
|
||||
int RolledSelectionListV::getItemAtPosition( int x, int y )
|
||||
{
|
||||
int clickSlotPos = (int)(y - y0 - headerHeight + (int) yo - 4);
|
||||
int isInsideX = x >= x0 && x <= x1;
|
||||
return isInsideX? getItemAtYPositionRaw(clickSlotPos) : -1;
|
||||
}
|
||||
|
||||
int RolledSelectionListV::getItemAtYPositionRaw(int y) {
|
||||
int slot = y / itemHeight;
|
||||
bool isInsideX = slot >= 0 && y >= 0 && slot < getNumberOfItems();
|
||||
return isInsideX? slot : -1;
|
||||
}
|
||||
|
||||
bool RolledSelectionListV::capYPosition()
|
||||
{
|
||||
float max = getMaxPosition() - (y1 - y0 - 4);
|
||||
if (max < 0) max /= 2;
|
||||
if (yo < 0) yo = 0;
|
||||
if (yo > max) yo = max;
|
||||
return false;
|
||||
/*
|
||||
const float MinY = -itemHeight/2;//(float)(itemHeight-height)/2;
|
||||
const float MaxY = MinY + (getNumberOfItems()-1) * itemHeight;
|
||||
if (yo < MinY) { yo = MinY; yInertia = 0; return true; }
|
||||
if (yo > MaxY) { yo = MaxY; yInertia = 0; return true; }
|
||||
return false;
|
||||
*/
|
||||
}
|
||||
|
||||
void RolledSelectionListV::tick() {
|
||||
|
||||
if (Mouse::isButtonDown(MouseAction::ACTION_LEFT))
|
||||
{
|
||||
_yinertia = _lastyoo - yoo;
|
||||
}
|
||||
_lastyoo = yoo;
|
||||
|
||||
//yInertia = Mth::absDecrease(yInertia, 1.0f, 0);
|
||||
|
||||
yoo = yo - yInertia;
|
||||
|
||||
//LOGI("tick: %f, %f, %f\n", yo, yInertia, _yinertia);
|
||||
}
|
||||
|
||||
float RolledSelectionListV::getPos(float alpha) {
|
||||
return yoo - yInertia * alpha;
|
||||
}
|
||||
|
||||
void RolledSelectionListV::render( int xm, int ym, float a )
|
||||
{
|
||||
_lastxm = xm;
|
||||
_lastym = ym;
|
||||
renderBackground();
|
||||
|
||||
int itemCount = getNumberOfItems();
|
||||
|
||||
//float yy0 = height / 2.0f + 124;
|
||||
//float yy1 = yy0 + 6;
|
||||
|
||||
if (Mouse::isButtonDown(MouseAction::ACTION_LEFT)) {
|
||||
touched();
|
||||
//LOGI("DOWN ym: %d\n", ym);
|
||||
if (ym >= y0 && ym <= y1) {
|
||||
if (dragState == NO_DRAG) {
|
||||
lastSelectionTime = getTimeMs();
|
||||
lastSelection = convertSelection( getItemAtPosition(width/2, ym), xm, ym );
|
||||
selectStart(lastSelection);
|
||||
//LOGI("Sel : %d\n", lastSelection);
|
||||
selectionY = ym;
|
||||
_stickPixels = 10;
|
||||
}
|
||||
else if (dragState >= 0) {
|
||||
float delta = (ym - yDrag);
|
||||
float absDelta = Mth::abs(delta);
|
||||
if (absDelta > _stickPixels) {
|
||||
_stickPixels = 0;
|
||||
delta -= delta>0? _stickPixels : -_stickPixels;
|
||||
} else {
|
||||
delta = 0;
|
||||
_stickPixels -= absDelta;
|
||||
}
|
||||
yo -= delta;
|
||||
yoo = yo;
|
||||
}
|
||||
dragState = DRAG_NORMAL;
|
||||
}
|
||||
} else {
|
||||
if (dragState >= 0) {
|
||||
if (dragState >= 0) {
|
||||
yInertia = _yinertia < 0? Mth::Max(-10.0f, _yinertia) : Mth::Min(10.0f, _yinertia);
|
||||
}
|
||||
// kill small inertia values when releasing scrollist
|
||||
if (std::abs(yInertia) <= 2.0001f) {
|
||||
yInertia = 0.0f;
|
||||
}
|
||||
|
||||
if (std::abs(yInertia) <= 10 /*&& getTimeMs() - lastSelectionTime < 300 */)
|
||||
{
|
||||
//float clickSlotPos = (ym - x0 - headerHeight + (int) yo - 4);
|
||||
int slot = convertSelection( getItemAtPosition(width/2, ym), xm, ym);
|
||||
//LOGI("slot: %d, lt: %d. diff: %d - %d\n", slot, lastSelection, selectionX, xm);
|
||||
if (xm >= x0 && xm <= x1 && slot >= 0 && slot == lastSelection && std::abs(selectionY - ym) < 10)
|
||||
selectItem(slot, false);
|
||||
} else {
|
||||
selectCancel();
|
||||
}
|
||||
}
|
||||
|
||||
// if (slot >= 0 && std::abs(selectionX - xm) < itemWidth)
|
||||
// {
|
||||
// bool doubleClick = false;
|
||||
// selectItem(slot, doubleClick);
|
||||
// //xInertia = 0.0f;
|
||||
// }
|
||||
//}
|
||||
dragState = NO_DRAG;
|
||||
|
||||
yo = getPos(a);
|
||||
}
|
||||
yDrag = (float)ym;
|
||||
|
||||
evaluate(xm, ym);
|
||||
capYPosition();
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
const int HalfWidth = 48;
|
||||
int rowX = (int)(width / 2 - HalfWidth + 8);
|
||||
int rowBaseY = (int)(y0 + 4 - (int) yo);
|
||||
|
||||
if (_renderDirtBackground)
|
||||
renderDirtBackground();
|
||||
|
||||
if (getNumberOfItems() == 0) yo = 0;
|
||||
|
||||
//int rowY = (int)(height / 2 - HalfHeight + 8);
|
||||
if (doRenderHeader) {
|
||||
const int HalfWidth = 48;
|
||||
int rowX = (int)(width / 2 - HalfWidth + 8);
|
||||
int rowBaseY = (int)(y0 + 4 - (int) yo);
|
||||
renderHeader(rowX, rowBaseY, t);
|
||||
}
|
||||
|
||||
onPreRender();
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
|
||||
float y = (float)(rowBaseY + (i) * itemHeight + headerHeight);
|
||||
float h = itemHeight - 4.0f;
|
||||
|
||||
if (y > y1 || (y + h) < y0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (renderSelection && isSelectedItem(i)) {
|
||||
//float y0 = height / 2.0f - HalfHeight - 4;
|
||||
//float y1 = height / 2.0f + HalfHeight - 4;
|
||||
//glColor4f2(1, 1, 1, 1);
|
||||
//glDisable2(GL_TEXTURE_2D);
|
||||
|
||||
//int ew = 0;
|
||||
//int color = 0x808080;
|
||||
//if (_componentSelected) {
|
||||
// ew = 0;
|
||||
// color = 0x7F89BF;
|
||||
//}
|
||||
//t.begin();
|
||||
//t.color(color);
|
||||
//t.vertex(x - 2 - ew, y0 - ew, 0);
|
||||
//t.vertex(x - 2 - ew, y1 + ew, 0);
|
||||
//t.vertex(x + h + 2 + ew, y1 + ew, 0);
|
||||
//t.vertex(x + h + 2 + ew, y0 - ew, 0);
|
||||
|
||||
//t.color(0x000000);
|
||||
//t.vertex(x - 1, y0 + 1, 0);
|
||||
//t.vertex(x - 1, y1 - 1, 0);
|
||||
//t.vertex(x + h + 1, y1 - 1, 0);
|
||||
//t.vertex(x + h + 1, y0 + 1, 0);
|
||||
|
||||
//t.draw();
|
||||
//glEnable2(GL_TEXTURE_2D);
|
||||
}
|
||||
renderItem(i, rowX, (int)y, (int)h, t);
|
||||
}
|
||||
onPostRender();
|
||||
|
||||
glDisable2(GL_DEPTH_TEST);
|
||||
|
||||
if (_renderTopBorder)
|
||||
renderHoleBackground(0, y0, 255, 255);
|
||||
if (_renderBottomBorder)
|
||||
renderHoleBackground(y1, (float)height, 255, 255);
|
||||
renderForeground();
|
||||
|
||||
//glEnable2(GL_BLEND);
|
||||
//glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
//glDisable2(GL_ALPHA_TEST);
|
||||
//glShadeModel2(GL_SMOOTH);
|
||||
|
||||
//glDisable2(GL_TEXTURE_2D);
|
||||
|
||||
//const int d = 4;
|
||||
//t.begin();
|
||||
//t.color(0x000000, 0);
|
||||
//t.vertexUV(y0, x0 + d, 0, 0, 1);
|
||||
//t.vertexUV(y1, x0 + d, 0, 1, 1);
|
||||
//t.color(0x000000, 255);
|
||||
//t.vertexUV(y1, x0, 0, 1, 0);
|
||||
//t.vertexUV(y0, x0, 0, 0, 0);
|
||||
//t.draw();
|
||||
|
||||
//t.begin();
|
||||
//t.color(0x000000, 255);
|
||||
//t.vertexUV(y0, x1, 0, 0, 1);
|
||||
//t.vertexUV(y1, x1, 0, 1, 1);
|
||||
//t.color(0x000000, 0);
|
||||
//t.vertexUV(y1, x1 - d, 0, 1, 0);
|
||||
//t.vertexUV(y0, x1 - d, 0, 0, 0);
|
||||
//t.draw();
|
||||
|
||||
//renderDecorations(xm, ym);
|
||||
|
||||
//glEnable2(GL_TEXTURE_2D);
|
||||
//glEnable2(GL_DEPTH_TEST);
|
||||
|
||||
//glShadeModel2(GL_FLAT);
|
||||
//glEnable2(GL_ALPHA_TEST);
|
||||
//glDisable2(GL_BLEND);
|
||||
}
|
||||
|
||||
void RolledSelectionListV::renderHoleBackground( /*float x0, float x1,*/ float y0, float y1, int a0, int a1 )
|
||||
{
|
||||
Tesselator& t = Tesselator::instance;
|
||||
minecraft->textures->loadAndBindTexture("gui/background.png");
|
||||
glColor4f2(1.0f, 1, 1, 1);
|
||||
float s = 32;
|
||||
t.begin();
|
||||
t.color(0x505050, a1);
|
||||
t.vertexUV(0, y1, 0, 0, y1 / s);
|
||||
t.vertexUV((float)width, y1, 0, width / s, y1 / s);
|
||||
t.color(0x505050, a0);
|
||||
t.vertexUV((float)width, y0, 0, width / s, y0 / s);
|
||||
t.vertexUV(0, y0, 0, 0, y0 / s);
|
||||
t.draw();
|
||||
//printf("x, y, x1, y1: %d, %d, %d, %d\n", 0, (int)y0, width, (int)y1);
|
||||
}
|
||||
|
||||
void RolledSelectionListV::touched()
|
||||
{
|
||||
}
|
||||
|
||||
void RolledSelectionListV::evaluate(int xm, int ym)
|
||||
{
|
||||
if (std::abs(selectionY - ym) >= 10) {
|
||||
lastSelection = -1;
|
||||
selectCancel();
|
||||
}
|
||||
}
|
||||
|
||||
void RolledSelectionListV::onPreRender()
|
||||
{
|
||||
}
|
||||
|
||||
void RolledSelectionListV::onPostRender()
|
||||
{
|
||||
}
|
||||
|
||||
void RolledSelectionListV::renderDirtBackground()
|
||||
{
|
||||
float by0 = _renderTopBorder? y0 : 0;
|
||||
float by1 = _renderBottomBorder? y1 : height;
|
||||
|
||||
minecraft->textures->loadAndBindTexture("gui/background.png");
|
||||
glColor4f2(1.0f, 1, 1, 1);
|
||||
float s = 32;
|
||||
const float uvy = (float)((int) yo);
|
||||
Tesselator& t = Tesselator::instance;
|
||||
t.begin();
|
||||
t.color(0x202020);
|
||||
t.vertexUV(x0, by1, 0, x0 / s, (by1+uvy) / s);
|
||||
t.vertexUV(x1, by1, 0, x1 / s, (by1+uvy) / s);
|
||||
t.vertexUV(x1, by0, 0, x1 / s, (by0+uvy) / s);
|
||||
t.vertexUV(x0, by0, 0, x0 / s, (by0+uvy) / s);
|
||||
t.draw();
|
||||
//LOGI("%f, %f - %f, %f\n", x0, by0, x1, by1);
|
||||
}
|
||||
#include "RolledSelectionListV.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "client/renderer/Tesselator.hpp"
|
||||
#include "client/renderer/gles.hpp"
|
||||
#include "platform/input/Mouse.hpp"
|
||||
#include "util/Mth.hpp"
|
||||
#include "client/renderer/Textures.hpp"
|
||||
|
||||
|
||||
RolledSelectionListV::RolledSelectionListV( Minecraft* minecraft_, int width_, int height_, int x0_, int x1_, int y0_, int y1_, int itemHeight_ )
|
||||
: minecraft(minecraft_),
|
||||
width(width_),
|
||||
height(height_),
|
||||
x0((float)x0_),
|
||||
x1((float)x1_),
|
||||
y0((float)y0_),
|
||||
y1((float)y1_),
|
||||
itemHeight(itemHeight_),
|
||||
selectionY(-1),
|
||||
lastSelectionTime(0),
|
||||
lastSelection(-1),
|
||||
renderSelection(true),
|
||||
doRenderHeader(false),
|
||||
headerHeight(0),
|
||||
dragState(DRAG_OUTSIDE),
|
||||
yDrag(0.0f),
|
||||
yo(0.0f),
|
||||
yoo(0.0f),
|
||||
yInertia(0.0f),
|
||||
_componentSelected(false),
|
||||
_renderDirtBackground(true),
|
||||
_renderTopBorder(true),
|
||||
_renderBottomBorder(true),
|
||||
_lastyoo(0),
|
||||
_yinertia(0),
|
||||
_stickPixels(0),
|
||||
_lastxm(0),
|
||||
_lastym(0)
|
||||
{
|
||||
yo = yoo = 0;//(float)(-itemHeight) * 0.5f;
|
||||
_lastyoo = yoo;
|
||||
}
|
||||
|
||||
void RolledSelectionListV::setRenderSelection( bool _renderSelection )
|
||||
{
|
||||
renderSelection = _renderSelection;
|
||||
}
|
||||
|
||||
void RolledSelectionListV::setComponentSelected(bool selected) {
|
||||
_componentSelected = selected;
|
||||
}
|
||||
|
||||
void RolledSelectionListV::setRenderHeader( bool _renderHeader, int _headerHeight )
|
||||
{
|
||||
doRenderHeader = _renderHeader;
|
||||
headerHeight = _headerHeight;
|
||||
|
||||
if (!doRenderHeader) {
|
||||
headerHeight = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int RolledSelectionListV::getMaxPosition()
|
||||
{
|
||||
return getNumberOfItems() * itemHeight + headerHeight;
|
||||
}
|
||||
|
||||
int RolledSelectionListV::getItemAtPosition( int x, int y )
|
||||
{
|
||||
int clickSlotPos = (int)(y - y0 - headerHeight + (int) yo - 4);
|
||||
int isInsideX = x >= x0 && x <= x1;
|
||||
return isInsideX? getItemAtYPositionRaw(clickSlotPos) : -1;
|
||||
}
|
||||
|
||||
int RolledSelectionListV::getItemAtYPositionRaw(int y) {
|
||||
int slot = y / itemHeight;
|
||||
bool isInsideX = slot >= 0 && y >= 0 && slot < getNumberOfItems();
|
||||
return isInsideX? slot : -1;
|
||||
}
|
||||
|
||||
bool RolledSelectionListV::capYPosition()
|
||||
{
|
||||
float max = getMaxPosition() - (y1 - y0 - 4);
|
||||
if (max < 0) max /= 2;
|
||||
if (yo < 0) yo = 0;
|
||||
if (yo > max) yo = max;
|
||||
return false;
|
||||
/*
|
||||
const float MinY = -itemHeight/2;//(float)(itemHeight-height)/2;
|
||||
const float MaxY = MinY + (getNumberOfItems()-1) * itemHeight;
|
||||
if (yo < MinY) { yo = MinY; yInertia = 0; return true; }
|
||||
if (yo > MaxY) { yo = MaxY; yInertia = 0; return true; }
|
||||
return false;
|
||||
*/
|
||||
}
|
||||
|
||||
void RolledSelectionListV::tick() {
|
||||
|
||||
if (Mouse::isButtonDown(MouseAction::ACTION_LEFT))
|
||||
{
|
||||
_yinertia = _lastyoo - yoo;
|
||||
}
|
||||
_lastyoo = yoo;
|
||||
|
||||
//yInertia = Mth::absDecrease(yInertia, 1.0f, 0);
|
||||
|
||||
yoo = yo - yInertia;
|
||||
|
||||
//LOGI("tick: %f, %f, %f\n", yo, yInertia, _yinertia);
|
||||
}
|
||||
|
||||
float RolledSelectionListV::getPos(float alpha) {
|
||||
return yoo - yInertia * alpha;
|
||||
}
|
||||
|
||||
void RolledSelectionListV::render( int xm, int ym, float a )
|
||||
{
|
||||
_lastxm = xm;
|
||||
_lastym = ym;
|
||||
renderBackground();
|
||||
|
||||
int itemCount = getNumberOfItems();
|
||||
|
||||
//float yy0 = height / 2.0f + 124;
|
||||
//float yy1 = yy0 + 6;
|
||||
|
||||
if (Mouse::isButtonDown(MouseAction::ACTION_LEFT)) {
|
||||
touched();
|
||||
//LOGI("DOWN ym: %d\n", ym);
|
||||
if (ym >= y0 && ym <= y1) {
|
||||
if (dragState == NO_DRAG) {
|
||||
lastSelectionTime = getTimeMs();
|
||||
lastSelection = convertSelection( getItemAtPosition(width/2, ym), xm, ym );
|
||||
selectStart(lastSelection);
|
||||
//LOGI("Sel : %d\n", lastSelection);
|
||||
selectionY = ym;
|
||||
_stickPixels = 10;
|
||||
}
|
||||
else if (dragState >= 0) {
|
||||
float delta = (ym - yDrag);
|
||||
float absDelta = Mth::abs(delta);
|
||||
if (absDelta > _stickPixels) {
|
||||
_stickPixels = 0;
|
||||
delta -= delta>0? _stickPixels : -_stickPixels;
|
||||
} else {
|
||||
delta = 0;
|
||||
_stickPixels -= absDelta;
|
||||
}
|
||||
yo -= delta;
|
||||
yoo = yo;
|
||||
}
|
||||
dragState = DRAG_NORMAL;
|
||||
}
|
||||
} else {
|
||||
if (dragState >= 0) {
|
||||
if (dragState >= 0) {
|
||||
yInertia = _yinertia < 0? Mth::Max(-10.0f, _yinertia) : Mth::Min(10.0f, _yinertia);
|
||||
}
|
||||
// kill small inertia values when releasing scrollist
|
||||
if (std::abs(yInertia) <= 2.0001f) {
|
||||
yInertia = 0.0f;
|
||||
}
|
||||
|
||||
if (std::abs(yInertia) <= 10 /*&& getTimeMs() - lastSelectionTime < 300 */)
|
||||
{
|
||||
//float clickSlotPos = (ym - x0 - headerHeight + (int) yo - 4);
|
||||
int slot = convertSelection( getItemAtPosition(width/2, ym), xm, ym);
|
||||
//LOGI("slot: %d, lt: %d. diff: %d - %d\n", slot, lastSelection, selectionX, xm);
|
||||
if (xm >= x0 && xm <= x1 && slot >= 0 && slot == lastSelection && std::abs(selectionY - ym) < 10)
|
||||
selectItem(slot, false);
|
||||
} else {
|
||||
selectCancel();
|
||||
}
|
||||
}
|
||||
|
||||
// if (slot >= 0 && std::abs(selectionX - xm) < itemWidth)
|
||||
// {
|
||||
// bool doubleClick = false;
|
||||
// selectItem(slot, doubleClick);
|
||||
// //xInertia = 0.0f;
|
||||
// }
|
||||
//}
|
||||
dragState = NO_DRAG;
|
||||
|
||||
yo = getPos(a);
|
||||
}
|
||||
yDrag = (float)ym;
|
||||
|
||||
evaluate(xm, ym);
|
||||
capYPosition();
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
const int HalfWidth = 48;
|
||||
int rowX = (int)(width / 2 - HalfWidth + 8);
|
||||
int rowBaseY = (int)(y0 + 4 - (int) yo);
|
||||
|
||||
if (_renderDirtBackground)
|
||||
renderDirtBackground();
|
||||
|
||||
if (getNumberOfItems() == 0) yo = 0;
|
||||
|
||||
//int rowY = (int)(height / 2 - HalfHeight + 8);
|
||||
if (doRenderHeader) {
|
||||
const int HalfWidth = 48;
|
||||
int rowX = (int)(width / 2 - HalfWidth + 8);
|
||||
int rowBaseY = (int)(y0 + 4 - (int) yo);
|
||||
renderHeader(rowX, rowBaseY, t);
|
||||
}
|
||||
|
||||
onPreRender();
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
|
||||
float y = (float)(rowBaseY + (i) * itemHeight + headerHeight);
|
||||
float h = itemHeight - 4.0f;
|
||||
|
||||
if (y > y1 || (y + h) < y0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (renderSelection && isSelectedItem(i)) {
|
||||
//float y0 = height / 2.0f - HalfHeight - 4;
|
||||
//float y1 = height / 2.0f + HalfHeight - 4;
|
||||
//glColor4f2(1, 1, 1, 1);
|
||||
//glDisable2(GL_TEXTURE_2D);
|
||||
|
||||
//int ew = 0;
|
||||
//int color = 0x808080;
|
||||
//if (_componentSelected) {
|
||||
// ew = 0;
|
||||
// color = 0x7F89BF;
|
||||
//}
|
||||
//t.begin();
|
||||
//t.color(color);
|
||||
//t.vertex(x - 2 - ew, y0 - ew, 0);
|
||||
//t.vertex(x - 2 - ew, y1 + ew, 0);
|
||||
//t.vertex(x + h + 2 + ew, y1 + ew, 0);
|
||||
//t.vertex(x + h + 2 + ew, y0 - ew, 0);
|
||||
|
||||
//t.color(0x000000);
|
||||
//t.vertex(x - 1, y0 + 1, 0);
|
||||
//t.vertex(x - 1, y1 - 1, 0);
|
||||
//t.vertex(x + h + 1, y1 - 1, 0);
|
||||
//t.vertex(x + h + 1, y0 + 1, 0);
|
||||
|
||||
//t.draw();
|
||||
//glEnable2(GL_TEXTURE_2D);
|
||||
}
|
||||
renderItem(i, rowX, (int)y, (int)h, t);
|
||||
}
|
||||
onPostRender();
|
||||
|
||||
glDisable2(GL_DEPTH_TEST);
|
||||
|
||||
if (_renderTopBorder)
|
||||
renderHoleBackground(0, y0, 255, 255);
|
||||
if (_renderBottomBorder)
|
||||
renderHoleBackground(y1, (float)height, 255, 255);
|
||||
renderForeground();
|
||||
|
||||
//glEnable2(GL_BLEND);
|
||||
//glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
//glDisable2(GL_ALPHA_TEST);
|
||||
//glShadeModel2(GL_SMOOTH);
|
||||
|
||||
//glDisable2(GL_TEXTURE_2D);
|
||||
|
||||
//const int d = 4;
|
||||
//t.begin();
|
||||
//t.color(0x000000, 0);
|
||||
//t.vertexUV(y0, x0 + d, 0, 0, 1);
|
||||
//t.vertexUV(y1, x0 + d, 0, 1, 1);
|
||||
//t.color(0x000000, 255);
|
||||
//t.vertexUV(y1, x0, 0, 1, 0);
|
||||
//t.vertexUV(y0, x0, 0, 0, 0);
|
||||
//t.draw();
|
||||
|
||||
//t.begin();
|
||||
//t.color(0x000000, 255);
|
||||
//t.vertexUV(y0, x1, 0, 0, 1);
|
||||
//t.vertexUV(y1, x1, 0, 1, 1);
|
||||
//t.color(0x000000, 0);
|
||||
//t.vertexUV(y1, x1 - d, 0, 1, 0);
|
||||
//t.vertexUV(y0, x1 - d, 0, 0, 0);
|
||||
//t.draw();
|
||||
|
||||
//renderDecorations(xm, ym);
|
||||
|
||||
//glEnable2(GL_TEXTURE_2D);
|
||||
//glEnable2(GL_DEPTH_TEST);
|
||||
|
||||
//glShadeModel2(GL_FLAT);
|
||||
//glEnable2(GL_ALPHA_TEST);
|
||||
//glDisable2(GL_BLEND);
|
||||
}
|
||||
|
||||
void RolledSelectionListV::renderHoleBackground( /*float x0, float x1,*/ float y0, float y1, int a0, int a1 )
|
||||
{
|
||||
Tesselator& t = Tesselator::instance;
|
||||
minecraft->textures->loadAndBindTexture("gui/background.png");
|
||||
glColor4f2(1.0f, 1, 1, 1);
|
||||
float s = 32;
|
||||
t.begin();
|
||||
t.color(0x505050, a1);
|
||||
t.vertexUV(0, y1, 0, 0, y1 / s);
|
||||
t.vertexUV((float)width, y1, 0, width / s, y1 / s);
|
||||
t.color(0x505050, a0);
|
||||
t.vertexUV((float)width, y0, 0, width / s, y0 / s);
|
||||
t.vertexUV(0, y0, 0, 0, y0 / s);
|
||||
t.draw();
|
||||
//printf("x, y, x1, y1: %d, %d, %d, %d\n", 0, (int)y0, width, (int)y1);
|
||||
}
|
||||
|
||||
void RolledSelectionListV::touched()
|
||||
{
|
||||
}
|
||||
|
||||
void RolledSelectionListV::evaluate(int xm, int ym)
|
||||
{
|
||||
if (std::abs(selectionY - ym) >= 10) {
|
||||
lastSelection = -1;
|
||||
selectCancel();
|
||||
}
|
||||
}
|
||||
|
||||
void RolledSelectionListV::onPreRender()
|
||||
{
|
||||
}
|
||||
|
||||
void RolledSelectionListV::onPostRender()
|
||||
{
|
||||
}
|
||||
|
||||
void RolledSelectionListV::renderDirtBackground()
|
||||
{
|
||||
float by0 = _renderTopBorder? y0 : 0;
|
||||
float by1 = _renderBottomBorder? y1 : height;
|
||||
|
||||
minecraft->textures->loadAndBindTexture("gui/background.png");
|
||||
glColor4f2(1.0f, 1, 1, 1);
|
||||
float s = 32;
|
||||
const float uvy = (float)((int) yo);
|
||||
Tesselator& t = Tesselator::instance;
|
||||
t.begin();
|
||||
t.color(0x202020);
|
||||
t.vertexUV(x0, by1, 0, x0 / s, (by1+uvy) / s);
|
||||
t.vertexUV(x1, by1, 0, x1 / s, (by1+uvy) / s);
|
||||
t.vertexUV(x1, by0, 0, x1 / s, (by0+uvy) / s);
|
||||
t.vertexUV(x0, by0, 0, x0 / s, (by0+uvy) / s);
|
||||
t.draw();
|
||||
//LOGI("%f, %f - %f, %f\n", x0, by0, x1, by1);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "../GuiComponent.h"
|
||||
#include "client/gui/GuiComponent.hpp"
|
||||
class Minecraft;
|
||||
class Tesselator;
|
||||
|
||||
@@ -1,296 +1,296 @@
|
||||
#include "ScrolledSelectionList.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../renderer/Tesselator.h"
|
||||
#include "../../renderer/gles.h"
|
||||
#include "../../../platform/input/Mouse.h"
|
||||
#include "../../renderer/Textures.h"
|
||||
|
||||
static int Abs(int d) {
|
||||
return d >= 0? d : -d;
|
||||
}
|
||||
|
||||
ScrolledSelectionList::ScrolledSelectionList( Minecraft* _minecraft, int _width, int _height, int _y0, int _y1, int _itemHeight )
|
||||
: minecraft(_minecraft),
|
||||
width(_width),
|
||||
height(_height),
|
||||
y0((float)_y0),
|
||||
y1((float)_y1),
|
||||
itemHeight(_itemHeight),
|
||||
x0(0.0f),
|
||||
x1((float)_width),
|
||||
selectionY(-1),
|
||||
lastSelectionTime(0),
|
||||
renderSelection(true),
|
||||
doRenderHeader(false),
|
||||
headerHeight(0),
|
||||
dragState(DRAG_OUTSIDE),
|
||||
yDrag(0.0f),
|
||||
yo(0.0f),
|
||||
yInertia(0.0f)
|
||||
{
|
||||
}
|
||||
|
||||
void ScrolledSelectionList::setRenderSelection( bool _renderSelection )
|
||||
{
|
||||
renderSelection = _renderSelection;
|
||||
}
|
||||
|
||||
void ScrolledSelectionList::setRenderHeader( bool _renderHeader, int _headerHeight )
|
||||
{
|
||||
doRenderHeader = _renderHeader;
|
||||
headerHeight = _headerHeight;
|
||||
|
||||
if (!doRenderHeader) {
|
||||
headerHeight = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ScrolledSelectionList::getMaxPosition()
|
||||
{
|
||||
return getNumberOfItems() * itemHeight + headerHeight;
|
||||
}
|
||||
|
||||
int ScrolledSelectionList::getItemAtPosition( int x, int y )
|
||||
{
|
||||
int x0 = width / 2 - (92 + 16 + 2);
|
||||
int x1 = width / 2 + (92 + 16 + 2);
|
||||
|
||||
int clickSlotPos = (int)(y - y0 - headerHeight + (int) yo - 4);
|
||||
int slot = clickSlotPos / itemHeight;
|
||||
if (x >= x0 && x <= x1 && slot >= 0 && clickSlotPos >= 0 && slot < getNumberOfItems()) {
|
||||
return slot;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void ScrolledSelectionList::capYPosition()
|
||||
{
|
||||
float max = getMaxPosition() - (y1 - y0 - 4);
|
||||
if (max < 0) max /= 2;
|
||||
if (yo < 0) yo = 0;
|
||||
if (yo > max) yo = max;
|
||||
}
|
||||
|
||||
void ScrolledSelectionList::render( int xm, int ym, float a )
|
||||
{
|
||||
renderBackground();
|
||||
|
||||
int itemCount = getNumberOfItems();
|
||||
|
||||
//float xx0 = width / 2.0f + 124;
|
||||
//float xx1 = xx0 + 6;
|
||||
|
||||
|
||||
if (Mouse::isButtonDown(MouseAction::ACTION_LEFT)) {
|
||||
//LOGI("DOWN ym: %d\n", ym);
|
||||
if (ym >= y0 && ym <= y1 && ym != ignoreY) {
|
||||
if (dragState == NO_DRAG) {
|
||||
dragState = DRAG_SKIP;
|
||||
}
|
||||
else if (dragState >= 0)
|
||||
{
|
||||
if (dragState == DRAG_SKIP)
|
||||
{
|
||||
lastSelectionTime = getTimeMs();
|
||||
selectionY = ym;
|
||||
}
|
||||
else if (dragState == DRAG_NORMAL)
|
||||
{
|
||||
yo -= (ym - yDrag);
|
||||
yInertia += (float)(ym - yDrag);
|
||||
}
|
||||
dragState = DRAG_NORMAL;
|
||||
}
|
||||
ignoreY = -1;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (dragState != NO_DRAG)
|
||||
{
|
||||
//LOGI("UP ym: %d\n", ym);
|
||||
}
|
||||
//ignoreY = ym;
|
||||
|
||||
// kill small inertia values when releasing scrollist
|
||||
if (dragState >= 0 && std::abs(yInertia) < 2)
|
||||
{
|
||||
yInertia = 0.0f;
|
||||
}
|
||||
|
||||
if (dragState >= 0 && getTimeMs() - lastSelectionTime < 300)
|
||||
{
|
||||
float clickSlotPos = (ym - y0 - headerHeight + (int) yo - 4);
|
||||
int slot = (int)clickSlotPos / itemHeight;
|
||||
|
||||
if (slot >= 0 && Abs(selectionY - ym) < itemHeight)
|
||||
{
|
||||
bool doubleClick = false;
|
||||
selectItem(slot, doubleClick);
|
||||
yInertia = 0.0f;
|
||||
}
|
||||
}
|
||||
dragState = NO_DRAG;
|
||||
|
||||
yo -= yInertia;
|
||||
}
|
||||
yInertia = yInertia * .75f;
|
||||
yDrag = (float)ym;
|
||||
|
||||
capYPosition();
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
renderDirtBackground();
|
||||
|
||||
int rowX = (int)(width / 2 - 92 - 16);
|
||||
int rowBaseY = (int)(y0 + 4 - (int) yo);
|
||||
|
||||
if (doRenderHeader) {
|
||||
renderHeader(rowX, rowBaseY, t);
|
||||
}
|
||||
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
|
||||
float y = (float)(rowBaseY + (i) * itemHeight + headerHeight);
|
||||
float h = itemHeight - 4.0f;
|
||||
|
||||
if (y > y1 || (y + h) < y0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (renderSelection && isSelectedItem(i)) {
|
||||
float x0 = width / 2.0f - (92 + 16 + 2);
|
||||
float x1 = width / 2.0f + (92 + 16 + 2);
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
t.begin();
|
||||
t.color(0x808080);
|
||||
t.vertexUV(x0, y + h + 2, 0, 0, 1);
|
||||
t.vertexUV(x1, y + h + 2, 0, 1, 1);
|
||||
t.vertexUV(x1, y - 2, 0, 1, 0);
|
||||
t.vertexUV(x0, y - 2, 0, 0, 0);
|
||||
|
||||
t.color(0x000000);
|
||||
t.vertexUV(x0 + 1, y + h + 1, 0, 0, 1);
|
||||
t.vertexUV(x1 - 1, y + h + 1, 0, 1, 1);
|
||||
t.vertexUV(x1 - 1, y - 1, 0, 1, 0);
|
||||
t.vertexUV(x0 + 1, y - 1, 0, 0, 0);
|
||||
|
||||
t.draw();
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
renderItem(i, rowX, (int)y, (int)h, t);
|
||||
|
||||
}
|
||||
|
||||
glDisable2(GL_DEPTH_TEST);
|
||||
|
||||
|
||||
int d = 4;
|
||||
|
||||
renderHoleBackground(0, y0, 255, 255);
|
||||
renderHoleBackground(y1, (float)height, 255, 255);
|
||||
|
||||
glEnable2(GL_BLEND);
|
||||
glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDisable2(GL_ALPHA_TEST);
|
||||
glShadeModel2(GL_SMOOTH);
|
||||
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
|
||||
t.begin();
|
||||
t.color(0x000000, 0);
|
||||
t.vertexUV(x0, y0 + d, 0, 0, 1);
|
||||
t.vertexUV(x1, y0 + d, 0, 1, 1);
|
||||
t.color(0x000000, 255);
|
||||
t.vertexUV(x1, y0, 0, 1, 0);
|
||||
t.vertexUV(x0, y0, 0, 0, 0);
|
||||
t.draw();
|
||||
|
||||
t.begin();
|
||||
t.color(0x000000, 255);
|
||||
t.vertexUV(x0, y1, 0, 0, 1);
|
||||
t.vertexUV(x1, y1, 0, 1, 1);
|
||||
t.color(0x000000, 0);
|
||||
t.vertexUV(x1, y1 - d, 0, 1, 0);
|
||||
t.vertexUV(x0, y1 - d, 0, 0, 0);
|
||||
t.draw();
|
||||
|
||||
// {
|
||||
// float max = getMaxPosition() - (y1 - y0 - 4);
|
||||
// if (max > 0) {
|
||||
// float barHeight = (y1 - y0) * (y1 - y0) / (getMaxPosition());
|
||||
// if (barHeight < 32) barHeight = 32;
|
||||
// if (barHeight > (y1 - y0 - 8)) barHeight = (y1 - y0 - 8);
|
||||
//
|
||||
// float yp = (int) yo * (y1 - y0 - barHeight) / max + y0;
|
||||
// if (yp < y0) yp = y0;
|
||||
//
|
||||
// t.begin();
|
||||
// t.color(0x000000, 255);
|
||||
// t.vertexUV(xx0, y1, 0.0f, 0.0f, 1.0f);
|
||||
// t.vertexUV(xx1, y1, 0.0f, 1.0f, 1.0f);
|
||||
// t.vertexUV(xx1, y0, 0.0f, 1.0f, 0.0f);
|
||||
// t.vertexUV(xx0, y0, 0.0f, 0.0f, 0.0f);
|
||||
// t.draw();
|
||||
//
|
||||
// t.begin();
|
||||
// t.color(0x808080, 255);
|
||||
// t.vertexUV(xx0, yp + barHeight, 0, 0, 1);
|
||||
// t.vertexUV(xx1, yp + barHeight, 0, 1, 1);
|
||||
// t.vertexUV(xx1, yp, 0, 1, 0);
|
||||
// t.vertexUV(xx0, yp, 0, 0, 0);
|
||||
// t.draw();
|
||||
//
|
||||
// t.begin();
|
||||
// t.color(0xc0c0c0, 255);
|
||||
// t.vertexUV(xx0, yp + barHeight - 1, 0, 0, 1);
|
||||
// t.vertexUV(xx1 - 1, yp + barHeight - 1, 0, 1, 1);
|
||||
// t.vertexUV(xx1 - 1, yp, 0, 1, 0);
|
||||
// t.vertexUV(xx0, yp, 0, 0, 0);
|
||||
// t.draw();
|
||||
// }
|
||||
// }
|
||||
|
||||
renderDecorations(xm, ym);
|
||||
|
||||
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
glEnable2(GL_DEPTH_TEST);
|
||||
|
||||
glShadeModel2(GL_FLAT);
|
||||
glEnable2(GL_ALPHA_TEST);
|
||||
glDisable2(GL_BLEND);
|
||||
}
|
||||
|
||||
void ScrolledSelectionList::renderHoleBackground( float y0, float y1, int a0, int a1 )
|
||||
{
|
||||
Tesselator& t = Tesselator::instance;
|
||||
minecraft->textures->loadAndBindTexture("gui/background.png");
|
||||
glColor4f2(1.0f, 1, 1, 1);
|
||||
float s = 32;
|
||||
t.begin();
|
||||
t.color(0x505050, a1);
|
||||
t.vertexUV(0, y1, 0, 0, y1 / s);
|
||||
t.vertexUV((float)width, y1, 0, width / s, y1 / s);
|
||||
t.color(0x505050, a0);
|
||||
t.vertexUV((float)width, y0, 0, width / s, y0 / s);
|
||||
t.vertexUV(0, y0, 0, 0, y0 / s);
|
||||
t.draw();
|
||||
}
|
||||
|
||||
void ScrolledSelectionList::renderDirtBackground()
|
||||
{
|
||||
Tesselator& t = Tesselator::instance;
|
||||
minecraft->textures->loadAndBindTexture("gui/background.png");
|
||||
glColor4f2(1.0f, 1, 1, 1);
|
||||
float s = 32;
|
||||
t.begin();
|
||||
t.color(0x202020);
|
||||
t.vertexUV(x0, y1, 0, x0 / s, (y1 + (int) yo) / s);
|
||||
t.vertexUV(x1, y1, 0, x1 / s, (y1 + (int) yo) / s);
|
||||
t.vertexUV(x1, y0, 0, x1 / s, (y0 + (int) yo) / s);
|
||||
t.vertexUV(x0, y0, 0, x0 / s, (y0 + (int) yo) / s);
|
||||
t.draw();
|
||||
}
|
||||
#include "ScrolledSelectionList.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "client/renderer/Tesselator.hpp"
|
||||
#include "client/renderer/gles.hpp"
|
||||
#include "platform/input/Mouse.hpp"
|
||||
#include "client/renderer/Textures.hpp"
|
||||
|
||||
static int Abs(int d) {
|
||||
return d >= 0? d : -d;
|
||||
}
|
||||
|
||||
ScrolledSelectionList::ScrolledSelectionList( Minecraft* _minecraft, int _width, int _height, int _y0, int _y1, int _itemHeight )
|
||||
: minecraft(_minecraft),
|
||||
width(_width),
|
||||
height(_height),
|
||||
y0((float)_y0),
|
||||
y1((float)_y1),
|
||||
itemHeight(_itemHeight),
|
||||
x0(0.0f),
|
||||
x1((float)_width),
|
||||
selectionY(-1),
|
||||
lastSelectionTime(0),
|
||||
renderSelection(true),
|
||||
doRenderHeader(false),
|
||||
headerHeight(0),
|
||||
dragState(DRAG_OUTSIDE),
|
||||
yDrag(0.0f),
|
||||
yo(0.0f),
|
||||
yInertia(0.0f)
|
||||
{
|
||||
}
|
||||
|
||||
void ScrolledSelectionList::setRenderSelection( bool _renderSelection )
|
||||
{
|
||||
renderSelection = _renderSelection;
|
||||
}
|
||||
|
||||
void ScrolledSelectionList::setRenderHeader( bool _renderHeader, int _headerHeight )
|
||||
{
|
||||
doRenderHeader = _renderHeader;
|
||||
headerHeight = _headerHeight;
|
||||
|
||||
if (!doRenderHeader) {
|
||||
headerHeight = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ScrolledSelectionList::getMaxPosition()
|
||||
{
|
||||
return getNumberOfItems() * itemHeight + headerHeight;
|
||||
}
|
||||
|
||||
int ScrolledSelectionList::getItemAtPosition( int x, int y )
|
||||
{
|
||||
int x0 = width / 2 - (92 + 16 + 2);
|
||||
int x1 = width / 2 + (92 + 16 + 2);
|
||||
|
||||
int clickSlotPos = (int)(y - y0 - headerHeight + (int) yo - 4);
|
||||
int slot = clickSlotPos / itemHeight;
|
||||
if (x >= x0 && x <= x1 && slot >= 0 && clickSlotPos >= 0 && slot < getNumberOfItems()) {
|
||||
return slot;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void ScrolledSelectionList::capYPosition()
|
||||
{
|
||||
float max = getMaxPosition() - (y1 - y0 - 4);
|
||||
if (max < 0) max /= 2;
|
||||
if (yo < 0) yo = 0;
|
||||
if (yo > max) yo = max;
|
||||
}
|
||||
|
||||
void ScrolledSelectionList::render( int xm, int ym, float a )
|
||||
{
|
||||
renderBackground();
|
||||
|
||||
int itemCount = getNumberOfItems();
|
||||
|
||||
//float xx0 = width / 2.0f + 124;
|
||||
//float xx1 = xx0 + 6;
|
||||
|
||||
|
||||
if (Mouse::isButtonDown(MouseAction::ACTION_LEFT)) {
|
||||
//LOGI("DOWN ym: %d\n", ym);
|
||||
if (ym >= y0 && ym <= y1 && ym != ignoreY) {
|
||||
if (dragState == NO_DRAG) {
|
||||
dragState = DRAG_SKIP;
|
||||
}
|
||||
else if (dragState >= 0)
|
||||
{
|
||||
if (dragState == DRAG_SKIP)
|
||||
{
|
||||
lastSelectionTime = getTimeMs();
|
||||
selectionY = ym;
|
||||
}
|
||||
else if (dragState == DRAG_NORMAL)
|
||||
{
|
||||
yo -= (ym - yDrag);
|
||||
yInertia += (float)(ym - yDrag);
|
||||
}
|
||||
dragState = DRAG_NORMAL;
|
||||
}
|
||||
ignoreY = -1;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (dragState != NO_DRAG)
|
||||
{
|
||||
//LOGI("UP ym: %d\n", ym);
|
||||
}
|
||||
//ignoreY = ym;
|
||||
|
||||
// kill small inertia values when releasing scrollist
|
||||
if (dragState >= 0 && std::abs(yInertia) < 2)
|
||||
{
|
||||
yInertia = 0.0f;
|
||||
}
|
||||
|
||||
if (dragState >= 0 && getTimeMs() - lastSelectionTime < 300)
|
||||
{
|
||||
float clickSlotPos = (ym - y0 - headerHeight + (int) yo - 4);
|
||||
int slot = (int)clickSlotPos / itemHeight;
|
||||
|
||||
if (slot >= 0 && Abs(selectionY - ym) < itemHeight)
|
||||
{
|
||||
bool doubleClick = false;
|
||||
selectItem(slot, doubleClick);
|
||||
yInertia = 0.0f;
|
||||
}
|
||||
}
|
||||
dragState = NO_DRAG;
|
||||
|
||||
yo -= yInertia;
|
||||
}
|
||||
yInertia = yInertia * .75f;
|
||||
yDrag = (float)ym;
|
||||
|
||||
capYPosition();
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
renderDirtBackground();
|
||||
|
||||
int rowX = (int)(width / 2 - 92 - 16);
|
||||
int rowBaseY = (int)(y0 + 4 - (int) yo);
|
||||
|
||||
if (doRenderHeader) {
|
||||
renderHeader(rowX, rowBaseY, t);
|
||||
}
|
||||
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
|
||||
float y = (float)(rowBaseY + (i) * itemHeight + headerHeight);
|
||||
float h = itemHeight - 4.0f;
|
||||
|
||||
if (y > y1 || (y + h) < y0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (renderSelection && isSelectedItem(i)) {
|
||||
float x0 = width / 2.0f - (92 + 16 + 2);
|
||||
float x1 = width / 2.0f + (92 + 16 + 2);
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
t.begin();
|
||||
t.color(0x808080);
|
||||
t.vertexUV(x0, y + h + 2, 0, 0, 1);
|
||||
t.vertexUV(x1, y + h + 2, 0, 1, 1);
|
||||
t.vertexUV(x1, y - 2, 0, 1, 0);
|
||||
t.vertexUV(x0, y - 2, 0, 0, 0);
|
||||
|
||||
t.color(0x000000);
|
||||
t.vertexUV(x0 + 1, y + h + 1, 0, 0, 1);
|
||||
t.vertexUV(x1 - 1, y + h + 1, 0, 1, 1);
|
||||
t.vertexUV(x1 - 1, y - 1, 0, 1, 0);
|
||||
t.vertexUV(x0 + 1, y - 1, 0, 0, 0);
|
||||
|
||||
t.draw();
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
renderItem(i, rowX, (int)y, (int)h, t);
|
||||
|
||||
}
|
||||
|
||||
glDisable2(GL_DEPTH_TEST);
|
||||
|
||||
|
||||
int d = 4;
|
||||
|
||||
renderHoleBackground(0, y0, 255, 255);
|
||||
renderHoleBackground(y1, (float)height, 255, 255);
|
||||
|
||||
glEnable2(GL_BLEND);
|
||||
glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDisable2(GL_ALPHA_TEST);
|
||||
glShadeModel2(GL_SMOOTH);
|
||||
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
|
||||
t.begin();
|
||||
t.color(0x000000, 0);
|
||||
t.vertexUV(x0, y0 + d, 0, 0, 1);
|
||||
t.vertexUV(x1, y0 + d, 0, 1, 1);
|
||||
t.color(0x000000, 255);
|
||||
t.vertexUV(x1, y0, 0, 1, 0);
|
||||
t.vertexUV(x0, y0, 0, 0, 0);
|
||||
t.draw();
|
||||
|
||||
t.begin();
|
||||
t.color(0x000000, 255);
|
||||
t.vertexUV(x0, y1, 0, 0, 1);
|
||||
t.vertexUV(x1, y1, 0, 1, 1);
|
||||
t.color(0x000000, 0);
|
||||
t.vertexUV(x1, y1 - d, 0, 1, 0);
|
||||
t.vertexUV(x0, y1 - d, 0, 0, 0);
|
||||
t.draw();
|
||||
|
||||
// {
|
||||
// float max = getMaxPosition() - (y1 - y0 - 4);
|
||||
// if (max > 0) {
|
||||
// float barHeight = (y1 - y0) * (y1 - y0) / (getMaxPosition());
|
||||
// if (barHeight < 32) barHeight = 32;
|
||||
// if (barHeight > (y1 - y0 - 8)) barHeight = (y1 - y0 - 8);
|
||||
//
|
||||
// float yp = (int) yo * (y1 - y0 - barHeight) / max + y0;
|
||||
// if (yp < y0) yp = y0;
|
||||
//
|
||||
// t.begin();
|
||||
// t.color(0x000000, 255);
|
||||
// t.vertexUV(xx0, y1, 0.0f, 0.0f, 1.0f);
|
||||
// t.vertexUV(xx1, y1, 0.0f, 1.0f, 1.0f);
|
||||
// t.vertexUV(xx1, y0, 0.0f, 1.0f, 0.0f);
|
||||
// t.vertexUV(xx0, y0, 0.0f, 0.0f, 0.0f);
|
||||
// t.draw();
|
||||
//
|
||||
// t.begin();
|
||||
// t.color(0x808080, 255);
|
||||
// t.vertexUV(xx0, yp + barHeight, 0, 0, 1);
|
||||
// t.vertexUV(xx1, yp + barHeight, 0, 1, 1);
|
||||
// t.vertexUV(xx1, yp, 0, 1, 0);
|
||||
// t.vertexUV(xx0, yp, 0, 0, 0);
|
||||
// t.draw();
|
||||
//
|
||||
// t.begin();
|
||||
// t.color(0xc0c0c0, 255);
|
||||
// t.vertexUV(xx0, yp + barHeight - 1, 0, 0, 1);
|
||||
// t.vertexUV(xx1 - 1, yp + barHeight - 1, 0, 1, 1);
|
||||
// t.vertexUV(xx1 - 1, yp, 0, 1, 0);
|
||||
// t.vertexUV(xx0, yp, 0, 0, 0);
|
||||
// t.draw();
|
||||
// }
|
||||
// }
|
||||
|
||||
renderDecorations(xm, ym);
|
||||
|
||||
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
glEnable2(GL_DEPTH_TEST);
|
||||
|
||||
glShadeModel2(GL_FLAT);
|
||||
glEnable2(GL_ALPHA_TEST);
|
||||
glDisable2(GL_BLEND);
|
||||
}
|
||||
|
||||
void ScrolledSelectionList::renderHoleBackground( float y0, float y1, int a0, int a1 )
|
||||
{
|
||||
Tesselator& t = Tesselator::instance;
|
||||
minecraft->textures->loadAndBindTexture("gui/background.png");
|
||||
glColor4f2(1.0f, 1, 1, 1);
|
||||
float s = 32;
|
||||
t.begin();
|
||||
t.color(0x505050, a1);
|
||||
t.vertexUV(0, y1, 0, 0, y1 / s);
|
||||
t.vertexUV((float)width, y1, 0, width / s, y1 / s);
|
||||
t.color(0x505050, a0);
|
||||
t.vertexUV((float)width, y0, 0, width / s, y0 / s);
|
||||
t.vertexUV(0, y0, 0, 0, y0 / s);
|
||||
t.draw();
|
||||
}
|
||||
|
||||
void ScrolledSelectionList::renderDirtBackground()
|
||||
{
|
||||
Tesselator& t = Tesselator::instance;
|
||||
minecraft->textures->loadAndBindTexture("gui/background.png");
|
||||
glColor4f2(1.0f, 1, 1, 1);
|
||||
float s = 32;
|
||||
t.begin();
|
||||
t.color(0x202020);
|
||||
t.vertexUV(x0, y1, 0, x0 / s, (y1 + (int) yo) / s);
|
||||
t.vertexUV(x1, y1, 0, x1 / s, (y1 + (int) yo) / s);
|
||||
t.vertexUV(x1, y0, 0, x1 / s, (y0 + (int) yo) / s);
|
||||
t.vertexUV(x0, y0, 0, x0 / s, (y0 + (int) yo) / s);
|
||||
t.draw();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "../GuiComponent.h"
|
||||
#include "client/gui/GuiComponent.hpp"
|
||||
class Minecraft;
|
||||
class Tesselator;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "../GuiComponent.h"
|
||||
#include "ImageButton.h"
|
||||
#include "../../player/input/touchscreen/TouchAreaModel.h"
|
||||
#include "../../../world/phys/Vec3.h"
|
||||
#include "../../Timer.h"
|
||||
#include "client/gui/GuiComponent.hpp"
|
||||
#include "ImageButton.hpp"
|
||||
#include "client/player/input/touchscreen/TouchAreaModel.hpp"
|
||||
#include "world/phys/Vec3.hpp"
|
||||
#include "client/Timer.hpp"
|
||||
|
||||
enum ScrollingPaneFlags {
|
||||
SF_LockX = 1 << 0,
|
||||
@@ -1,94 +1,94 @@
|
||||
#include "Slider.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../renderer/Textures.h"
|
||||
#include "../Screen.h"
|
||||
#include "../../../locale/I18n.h"
|
||||
#include "../../../util/Mth.h"
|
||||
#include <algorithm>
|
||||
#include <assert.h>
|
||||
|
||||
Slider::Slider(OptionId optId) : m_mouseDownOnElement(false), m_optId(optId), m_numSteps(0) {}
|
||||
|
||||
void Slider::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
int xSliderStart = x + 5;
|
||||
int xSliderEnd = x + width - 5;
|
||||
int ySliderStart = y + 6;
|
||||
int ySliderEnd = y + 9;
|
||||
int handleSizeX = 9;
|
||||
int handleSizeY = 15;
|
||||
int barWidth = xSliderEnd - xSliderStart;
|
||||
//fill(x, y + 8, x + (int)(width * percentage), y + height, 0xffff00ff);
|
||||
fill(xSliderStart, ySliderStart, xSliderEnd, ySliderEnd, 0xff606060);
|
||||
|
||||
if (m_numSteps > 2) {
|
||||
int stepDistance = barWidth / (m_numSteps-1);
|
||||
for(int a = 0; a < m_numSteps; ++a) {
|
||||
int renderSliderStepPosX = xSliderStart + a * stepDistance + 1;
|
||||
fill(renderSliderStepPosX - 1, ySliderStart - 2, renderSliderStepPosX + 1, ySliderEnd + 2, 0xff606060);
|
||||
}
|
||||
}
|
||||
|
||||
minecraft->textures->loadAndBindTexture("gui/touchgui.png");
|
||||
blit(xSliderStart + (int)(m_percentage * barWidth) - handleSizeX / 2, y, 226, 126, handleSizeX, handleSizeY, handleSizeX, handleSizeY);
|
||||
}
|
||||
|
||||
void Slider::mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
if(pointInside(x, y)) {
|
||||
m_mouseDownOnElement = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Slider::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
m_mouseDownOnElement = false;
|
||||
}
|
||||
|
||||
void Slider::tick(Minecraft* minecraft) {
|
||||
if(minecraft->screen != NULL) {
|
||||
int xm = Mouse::getX();
|
||||
int ym = Mouse::getY();
|
||||
|
||||
minecraft->screen->toGUICoordinate(xm, ym);
|
||||
|
||||
if(m_mouseDownOnElement) {
|
||||
m_percentage = float(xm - x) / float(width);
|
||||
m_percentage = Mth::clamp(m_percentage, 0.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SliderFloat::SliderFloat(Minecraft* minecraft, OptionId option)
|
||||
: Slider(option), m_option(dynamic_cast<OptionFloat*>(minecraft->options.getOpt(option)))
|
||||
{
|
||||
m_percentage = Mth::clamp((m_option->get() - m_option->getMin()) / (m_option->getMax() - m_option->getMin()), 0.f, 1.f);
|
||||
}
|
||||
|
||||
SliderInt::SliderInt(Minecraft* minecraft, OptionId option)
|
||||
: Slider(option), m_option(dynamic_cast<OptionInt*>(minecraft->options.getOpt(option)))
|
||||
{
|
||||
m_numSteps = m_option->getMax() - m_option->getMin() + 1;
|
||||
m_percentage = float(m_option->get() - m_option->getMin()) / (m_numSteps-1);
|
||||
}
|
||||
|
||||
void SliderInt::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
Slider::render(minecraft, xm, ym);
|
||||
}
|
||||
|
||||
void SliderInt::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
Slider::mouseReleased(minecraft, x, y, buttonNum);
|
||||
|
||||
if (pointInside(x, y)) {
|
||||
int curStep = int(m_percentage * (m_numSteps-1) + 0.5f);
|
||||
curStep = Mth::clamp(curStep + m_option->getMin(), m_option->getMin(), m_option->getMax());
|
||||
m_percentage = float(curStep - m_option->getMin()) / (m_numSteps-1);
|
||||
|
||||
minecraft->options.set(m_optId, curStep);
|
||||
}
|
||||
}
|
||||
|
||||
void SliderFloat::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
Slider::mouseReleased(minecraft, x, y, buttonNum);
|
||||
|
||||
if (pointInside(x, y)) {
|
||||
minecraft->options.set(m_optId, m_percentage * (m_option->getMax() - m_option->getMin()) + m_option->getMin());
|
||||
}
|
||||
#include "Slider.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "client/renderer/Textures.hpp"
|
||||
#include "client/gui/Screen.hpp"
|
||||
#include "locale/I18n.hpp"
|
||||
#include "util/Mth.hpp"
|
||||
#include <algorithm>
|
||||
#include <assert.h>
|
||||
|
||||
Slider::Slider(OptionId optId) : m_mouseDownOnElement(false), m_optId(optId), m_numSteps(0) {}
|
||||
|
||||
void Slider::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
int xSliderStart = x + 5;
|
||||
int xSliderEnd = x + width - 5;
|
||||
int ySliderStart = y + 6;
|
||||
int ySliderEnd = y + 9;
|
||||
int handleSizeX = 9;
|
||||
int handleSizeY = 15;
|
||||
int barWidth = xSliderEnd - xSliderStart;
|
||||
//fill(x, y + 8, x + (int)(width * percentage), y + height, 0xffff00ff);
|
||||
fill(xSliderStart, ySliderStart, xSliderEnd, ySliderEnd, 0xff606060);
|
||||
|
||||
if (m_numSteps > 2) {
|
||||
int stepDistance = barWidth / (m_numSteps-1);
|
||||
for(int a = 0; a < m_numSteps; ++a) {
|
||||
int renderSliderStepPosX = xSliderStart + a * stepDistance + 1;
|
||||
fill(renderSliderStepPosX - 1, ySliderStart - 2, renderSliderStepPosX + 1, ySliderEnd + 2, 0xff606060);
|
||||
}
|
||||
}
|
||||
|
||||
minecraft->textures->loadAndBindTexture("gui/touchgui.png");
|
||||
blit(xSliderStart + (int)(m_percentage * barWidth) - handleSizeX / 2, y, 226, 126, handleSizeX, handleSizeY, handleSizeX, handleSizeY);
|
||||
}
|
||||
|
||||
void Slider::mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
if(pointInside(x, y)) {
|
||||
m_mouseDownOnElement = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Slider::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
m_mouseDownOnElement = false;
|
||||
}
|
||||
|
||||
void Slider::tick(Minecraft* minecraft) {
|
||||
if(minecraft->screen != NULL) {
|
||||
int xm = Mouse::getX();
|
||||
int ym = Mouse::getY();
|
||||
|
||||
minecraft->screen->toGUICoordinate(xm, ym);
|
||||
|
||||
if(m_mouseDownOnElement) {
|
||||
m_percentage = float(xm - x) / float(width);
|
||||
m_percentage = Mth::clamp(m_percentage, 0.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SliderFloat::SliderFloat(Minecraft* minecraft, OptionId option)
|
||||
: Slider(option), m_option(dynamic_cast<OptionFloat*>(minecraft->options.getOpt(option)))
|
||||
{
|
||||
m_percentage = Mth::clamp((m_option->get() - m_option->getMin()) / (m_option->getMax() - m_option->getMin()), 0.f, 1.f);
|
||||
}
|
||||
|
||||
SliderInt::SliderInt(Minecraft* minecraft, OptionId option)
|
||||
: Slider(option), m_option(dynamic_cast<OptionInt*>(minecraft->options.getOpt(option)))
|
||||
{
|
||||
m_numSteps = m_option->getMax() - m_option->getMin() + 1;
|
||||
m_percentage = float(m_option->get() - m_option->getMin()) / (m_numSteps-1);
|
||||
}
|
||||
|
||||
void SliderInt::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
Slider::render(minecraft, xm, ym);
|
||||
}
|
||||
|
||||
void SliderInt::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
Slider::mouseReleased(minecraft, x, y, buttonNum);
|
||||
|
||||
if (pointInside(x, y)) {
|
||||
int curStep = int(m_percentage * (m_numSteps-1) + 0.5f);
|
||||
curStep = Mth::clamp(curStep + m_option->getMin(), m_option->getMin(), m_option->getMax());
|
||||
m_percentage = float(curStep - m_option->getMin()) / (m_numSteps-1);
|
||||
|
||||
minecraft->options.set(m_optId, curStep);
|
||||
}
|
||||
}
|
||||
|
||||
void SliderFloat::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
||||
Slider::mouseReleased(minecraft, x, y, buttonNum);
|
||||
|
||||
if (pointInside(x, y)) {
|
||||
minecraft->options.set(m_optId, m_percentage * (m_option->getMax() - m_option->getMin()) + m_option->getMin());
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "GuiElement.h"
|
||||
#include "../../../client/Options.h"
|
||||
#include <client/Option.h>
|
||||
#include "GuiElement.hpp"
|
||||
#include "client/Options.hpp"
|
||||
#include <client/Option.hpp>
|
||||
|
||||
class Slider : public GuiElement {
|
||||
typedef GuiElement super;
|
||||
@@ -1,102 +1,102 @@
|
||||
#include "TextBox.h"
|
||||
#include "../Gui.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../../AppPlatform.h"
|
||||
#include "../../../platform/input/Mouse.h"
|
||||
|
||||
// delegate constructors
|
||||
TextBox::TextBox(int id, const std::string& msg)
|
||||
: TextBox(id, 0, 0, msg)
|
||||
{
|
||||
}
|
||||
|
||||
TextBox::TextBox(int id, int x, int y, const std::string& msg)
|
||||
: TextBox(id, x, y, 24, Font::DefaultLineHeight + 4, msg)
|
||||
{
|
||||
}
|
||||
|
||||
TextBox::TextBox(int id, int x, int y, int w, int h, const std::string& msg)
|
||||
: GuiElement(true, true, x, y, w, h),
|
||||
id(id), hint(msg), focused(false), blink(false), blinkTicks(0)
|
||||
{
|
||||
}
|
||||
|
||||
void TextBox::setFocus(Minecraft* minecraft) {
|
||||
if (!focused) {
|
||||
minecraft->platform()->showKeyboard();
|
||||
focused = true;
|
||||
blinkTicks = 0;
|
||||
blink = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool TextBox::loseFocus(Minecraft* minecraft) {
|
||||
if (focused) {
|
||||
minecraft->platform()->hideKeyboard();
|
||||
focused = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void TextBox::mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum) {
|
||||
if (buttonNum == MouseAction::ACTION_LEFT) {
|
||||
if (pointInside(x, y)) {
|
||||
setFocus(minecraft);
|
||||
} else {
|
||||
loseFocus(minecraft);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TextBox::charPressed(Minecraft* minecraft, char c) {
|
||||
if (focused && c >= 32 && c < 127 && (int)text.size() < 256) {
|
||||
text.push_back(c);
|
||||
}
|
||||
}
|
||||
|
||||
void TextBox::keyPressed(Minecraft* minecraft, int key) {
|
||||
if (focused && key == Keyboard::KEY_BACKSPACE && !text.empty()) {
|
||||
text.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void TextBox::tick(Minecraft* minecraft) {
|
||||
blinkTicks++;
|
||||
if (blinkTicks >= 5) {
|
||||
blink = !blink;
|
||||
blinkTicks = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void TextBox::render(Minecraft* minecraft, int xm, int ym) {
|
||||
// textbox like in beta 1.7.3
|
||||
// change appearance when focused so the user can tell it's active
|
||||
// active background darker gray with a subtle border
|
||||
uint32_t bgColor = focused ? 0xffa0a0a0 : 0xffa0a0a0;
|
||||
uint32_t borderColor = focused ? 0xff000000 : 0xff000000;
|
||||
fill(x, y, x + width, y + height, bgColor);
|
||||
fill(x + 1, y + 1, x + width - 1, y + height - 1, borderColor);
|
||||
|
||||
glEnable2(GL_SCISSOR_TEST);
|
||||
glScissor(
|
||||
Gui::GuiScale * (x + 2),
|
||||
minecraft->height - Gui::GuiScale * (y + height - 2),
|
||||
Gui::GuiScale * (width - 2),
|
||||
Gui::GuiScale * (height - 2)
|
||||
);
|
||||
|
||||
int _y = y + (height - Font::DefaultLineHeight) / 2;
|
||||
|
||||
if (text.empty() && !focused) {
|
||||
drawString(minecraft->font, hint, x + 2, _y, 0xff5e5e5e);
|
||||
}
|
||||
|
||||
if (focused && blink) text.push_back('_');
|
||||
|
||||
drawString(minecraft->font, text, x + 2, _y, 0xffffffff);
|
||||
|
||||
if (focused && blink) text.pop_back();
|
||||
|
||||
glDisable2(GL_SCISSOR_TEST);
|
||||
}
|
||||
#include "TextBox.hpp"
|
||||
#include "client/gui/Gui.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "AppPlatform.hpp"
|
||||
#include "platform/input/Mouse.hpp"
|
||||
|
||||
// delegate constructors
|
||||
TextBox::TextBox(int id, const std::string& msg)
|
||||
: TextBox(id, 0, 0, msg)
|
||||
{
|
||||
}
|
||||
|
||||
TextBox::TextBox(int id, int x, int y, const std::string& msg)
|
||||
: TextBox(id, x, y, 24, Font::DefaultLineHeight + 4, msg)
|
||||
{
|
||||
}
|
||||
|
||||
TextBox::TextBox(int id, int x, int y, int w, int h, const std::string& msg)
|
||||
: GuiElement(true, true, x, y, w, h),
|
||||
id(id), hint(msg), focused(false), blink(false), blinkTicks(0)
|
||||
{
|
||||
}
|
||||
|
||||
void TextBox::setFocus(Minecraft* minecraft) {
|
||||
if (!focused) {
|
||||
minecraft->platform()->showKeyboard();
|
||||
focused = true;
|
||||
blinkTicks = 0;
|
||||
blink = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool TextBox::loseFocus(Minecraft* minecraft) {
|
||||
if (focused) {
|
||||
minecraft->platform()->hideKeyboard();
|
||||
focused = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void TextBox::mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum) {
|
||||
if (buttonNum == MouseAction::ACTION_LEFT) {
|
||||
if (pointInside(x, y)) {
|
||||
setFocus(minecraft);
|
||||
} else {
|
||||
loseFocus(minecraft);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TextBox::charPressed(Minecraft* minecraft, char c) {
|
||||
if (focused && c >= 32 && c < 127 && (int)text.size() < 256) {
|
||||
text.push_back(c);
|
||||
}
|
||||
}
|
||||
|
||||
void TextBox::keyPressed(Minecraft* minecraft, int key) {
|
||||
if (focused && key == Keyboard::KEY_BACKSPACE && !text.empty()) {
|
||||
text.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void TextBox::tick(Minecraft* minecraft) {
|
||||
blinkTicks++;
|
||||
if (blinkTicks >= 5) {
|
||||
blink = !blink;
|
||||
blinkTicks = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void TextBox::render(Minecraft* minecraft, int xm, int ym) {
|
||||
// textbox like in beta 1.7.3
|
||||
// change appearance when focused so the user can tell it's active
|
||||
// active background darker gray with a subtle border
|
||||
uint32_t bgColor = focused ? 0xffa0a0a0 : 0xffa0a0a0;
|
||||
uint32_t borderColor = focused ? 0xff000000 : 0xff000000;
|
||||
fill(x, y, x + width, y + height, bgColor);
|
||||
fill(x + 1, y + 1, x + width - 1, y + height - 1, borderColor);
|
||||
|
||||
glEnable2(GL_SCISSOR_TEST);
|
||||
glScissor(
|
||||
Gui::GuiScale * (x + 2),
|
||||
minecraft->height - Gui::GuiScale * (y + height - 2),
|
||||
Gui::GuiScale * (width - 2),
|
||||
Gui::GuiScale * (height - 2)
|
||||
);
|
||||
|
||||
int _y = y + (height - Font::DefaultLineHeight) / 2;
|
||||
|
||||
if (text.empty() && !focused) {
|
||||
drawString(minecraft->font, hint, x + 2, _y, 0xff5e5e5e);
|
||||
}
|
||||
|
||||
if (focused && blink) text.push_back('_');
|
||||
|
||||
drawString(minecraft->font, text, x + 2, _y, 0xffffffff);
|
||||
|
||||
if (focused && blink) text.pop_back();
|
||||
|
||||
glDisable2(GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
//package net.minecraft.client.gui;
|
||||
|
||||
#include <string>
|
||||
#include "GuiElement.h"
|
||||
#include "../../Options.h"
|
||||
#include "../../../platform/input/Mouse.h"
|
||||
#include "../../../platform/input/Keyboard.h"
|
||||
#include "GuiElement.hpp"
|
||||
#include "client/Options.hpp"
|
||||
#include "platform/input/Mouse.hpp"
|
||||
#include "platform/input/Keyboard.hpp"
|
||||
|
||||
class Font;
|
||||
class Minecraft;
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "TextOption.h"
|
||||
#include <client/Minecraft.h>
|
||||
#include "TextOption.hpp"
|
||||
#include <client/Minecraft.hpp>
|
||||
|
||||
TextOption::TextOption(Minecraft* minecraft, OptionId optId)
|
||||
: TextBox((int)optId, minecraft->options.getOpt(optId)->getStringId())
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include "TextBox.h"
|
||||
#include <client/Options.h>
|
||||
#include "TextBox.hpp"
|
||||
#include <client/Options.hpp>
|
||||
|
||||
class TextOption : public TextBox {
|
||||
public:
|
||||
@@ -1,370 +1,370 @@
|
||||
#include "ArmorScreen.h"
|
||||
#include "../Screen.h"
|
||||
#include "../components/NinePatch.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../player/LocalPlayer.h"
|
||||
#include "../../renderer/Tesselator.h"
|
||||
#include "../../renderer/entity/ItemRenderer.h"
|
||||
#include "../../../world/item/Item.h"
|
||||
#include "../../../world/item/ItemCategory.h"
|
||||
#include "../../../world/entity/player/Inventory.h"
|
||||
#include "../../../world/entity/item/ItemEntity.h"
|
||||
#include "../../../world/level/Level.h"
|
||||
#include "../../../network/RakNetInstance.h"
|
||||
#include "../../renderer/entity/EntityRenderDispatcher.h"
|
||||
#include "../../../world/item/ArmorItem.h"
|
||||
|
||||
static void setIfNotSet(bool& ref, bool condition) {
|
||||
ref = (ref || condition);
|
||||
}
|
||||
|
||||
const int descFrameWidth = 100;
|
||||
|
||||
const int rgbActive = 0xfff0f0f0;
|
||||
const int rgbInactive = 0xc0635558;
|
||||
const int rgbInactiveShadow = 0xc0aaaaaa;
|
||||
|
||||
#ifdef __APPLE__
|
||||
static const float BorderPixels = 4;
|
||||
#ifdef DEMO_MODE
|
||||
static const float BlockPixels = 22;
|
||||
#else
|
||||
static const float BlockPixels = 22;
|
||||
#endif
|
||||
#else
|
||||
static const float BorderPixels = 4;
|
||||
static const float BlockPixels = 24;
|
||||
#endif
|
||||
static const int ItemSize = (int)(BlockPixels + 2*BorderPixels);
|
||||
|
||||
static const int Bx = 10; // Border Frame width
|
||||
static const int By = 6; // Border Frame height
|
||||
|
||||
|
||||
ArmorScreen::ArmorScreen():
|
||||
inventoryPane(NULL),
|
||||
btnArmor0(0),
|
||||
btnArmor1(1),
|
||||
btnArmor2(2),
|
||||
btnArmor3(3),
|
||||
btnClose(4, ""),
|
||||
bHeader (5, "Armor"),
|
||||
guiBackground(NULL),
|
||||
guiSlot(NULL),
|
||||
guiPaneFrame(NULL),
|
||||
guiPlayerBg(NULL),
|
||||
doRecreatePane(false),
|
||||
descWidth(90)
|
||||
//guiSlotItem(NULL),
|
||||
//guiSlotItemSelected(NULL)
|
||||
{
|
||||
//LOGI("Creating ArmorScreen with %p, %d\n", furnace, furnace->runningId);
|
||||
}
|
||||
|
||||
ArmorScreen::~ArmorScreen() {
|
||||
delete inventoryPane;
|
||||
|
||||
delete guiBackground;
|
||||
delete guiSlot;
|
||||
delete guiPaneFrame;
|
||||
delete guiPlayerBg;
|
||||
}
|
||||
|
||||
void ArmorScreen::init() {
|
||||
super::init();
|
||||
|
||||
player = minecraft->player;
|
||||
|
||||
ImageDef def;
|
||||
def.name = "gui/spritesheet.png";
|
||||
def.x = 0;
|
||||
def.y = 1;
|
||||
def.width = def.height = 18;
|
||||
def.setSrc(IntRectangle(60, 0, 18, 18));
|
||||
btnClose.setImageDef(def, true);
|
||||
btnClose.scaleWhenPressed = false;
|
||||
|
||||
buttons.push_back(&bHeader);
|
||||
buttons.push_back(&btnClose);
|
||||
|
||||
armorButtons[0] = &btnArmor0;
|
||||
armorButtons[1] = &btnArmor1;
|
||||
armorButtons[2] = &btnArmor2;
|
||||
armorButtons[3] = &btnArmor3;
|
||||
for (int i = 0; i < NUM_ARMORBUTTONS; ++i)
|
||||
buttons.push_back(armorButtons[i]);
|
||||
|
||||
// GUI - nine patches
|
||||
NinePatchFactory builder(minecraft->textures, "gui/spritesheet.png");
|
||||
|
||||
guiBackground = builder.createSymmetrical(IntRectangle(0, 0, 16, 16), 4, 4);
|
||||
guiSlot = builder.createSymmetrical(IntRectangle(0, 32, 8, 8), 3, 3, 20, 20);
|
||||
guiPaneFrame = builder.createSymmetrical(IntRectangle(28, 42, 4, 4), 1, 1)->setExcluded(1 << 4);
|
||||
guiPlayerBg = builder.createSymmetrical(IntRectangle(0, 20, 8, 8), 3, 3);
|
||||
|
||||
updateItems();
|
||||
}
|
||||
|
||||
void ArmorScreen::setupPositions() {
|
||||
// Left - Categories
|
||||
bHeader.x = bHeader.y = 0;
|
||||
bHeader.width = width;// - bDone.w;
|
||||
|
||||
btnClose.width = btnClose.height = 19;
|
||||
btnClose.x = width - btnClose.width;
|
||||
btnClose.y = 0;
|
||||
|
||||
// Inventory pane
|
||||
const int maxWidth = (int)(width/1.8f) - Bx - Bx;
|
||||
const int InventoryColumns = maxWidth / ItemSize;
|
||||
const int realWidth = InventoryColumns * ItemSize;
|
||||
const int paneWidth = realWidth + Bx + Bx;
|
||||
const int realBx = (paneWidth - realWidth) / 2;
|
||||
|
||||
inventoryPaneRect = IntRectangle(realBx,
|
||||
#ifdef __APPLE__
|
||||
26 + By - ((width==240)?1:0), realWidth, ((width==240)?1:0) + height-By-By-28);
|
||||
#else
|
||||
26 + By, realWidth, height-By-By-28);
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < NUM_ARMORBUTTONS; ++i) {
|
||||
Button& b = *armorButtons[i];
|
||||
b.x = paneWidth;
|
||||
b.y = inventoryPaneRect.y + 24 * i;
|
||||
b.width = 20;
|
||||
b.height = 20;
|
||||
}
|
||||
|
||||
guiPlayerBgRect.y = inventoryPaneRect.y;
|
||||
int xx = armorButtons[0]->x + armorButtons[0]->width;
|
||||
int xw = width - xx;
|
||||
guiPlayerBgRect.x = xx + xw / 10;
|
||||
guiPlayerBgRect.w = xw - (xw / 10) * 2;
|
||||
guiPlayerBgRect.h = inventoryPaneRect.h;
|
||||
|
||||
guiPaneFrame->setSize((float)inventoryPaneRect.w + 2, (float)inventoryPaneRect.h + 2);
|
||||
guiPlayerBg->setSize((float)guiPlayerBgRect.w, (float)guiPlayerBgRect.h);
|
||||
guiBackground->setSize((float)width, (float)height);
|
||||
|
||||
updateItems();
|
||||
setupInventoryPane();
|
||||
}
|
||||
|
||||
void ArmorScreen::tick() {
|
||||
if (inventoryPane)
|
||||
inventoryPane->tick();
|
||||
|
||||
if (doRecreatePane) {
|
||||
updateItems();
|
||||
setupInventoryPane();
|
||||
doRecreatePane = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ArmorScreen::handleRenderPane(Touch::InventoryPane* pane, Tesselator& t, int xm, int ym, float a) {
|
||||
if (pane) {
|
||||
pane->render(xm, ym, a);
|
||||
guiPaneFrame->draw(t, (float)(pane->rect.x - 1), (float)(pane->rect.y - 1));
|
||||
}
|
||||
}
|
||||
|
||||
void ArmorScreen::render(int xm, int ym, float a) {
|
||||
//renderBackground();
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
t.addOffset(0, 0, -500);
|
||||
guiBackground->draw(t, 0, 0);
|
||||
t.addOffset(0, 0, 500);
|
||||
glEnable2(GL_ALPHA_TEST);
|
||||
|
||||
// Buttons (Left side + crafting)
|
||||
super::render(xm, ym, a);
|
||||
|
||||
handleRenderPane(inventoryPane, t, xm, ym, a);
|
||||
|
||||
t.colorABGR(0xffffffff);
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
|
||||
t.addOffset(0, 0, -490);
|
||||
guiPlayerBg->draw(t, (float)guiPlayerBgRect.x, (float)guiPlayerBgRect.y);
|
||||
t.addOffset(0, 0, 490);
|
||||
renderPlayer((float)(guiPlayerBgRect.x + guiPlayerBgRect.w / 2), 0.85f * height);
|
||||
|
||||
for (int i = 0; i < NUM_ARMORBUTTONS; ++i) {
|
||||
drawSlotItemAt(t, i, player->getArmor(i), armorButtons[i]->x, armorButtons[i]->y);
|
||||
}
|
||||
glDisable2(GL_ALPHA_TEST);
|
||||
}
|
||||
|
||||
void ArmorScreen::buttonClicked(Button* button) {
|
||||
if (button == &btnClose) {
|
||||
minecraft->setScreen(NULL);
|
||||
}
|
||||
|
||||
if (button->id >= 0 && button->id <= 3) {
|
||||
takeAndClearSlot(button->id);
|
||||
}
|
||||
}
|
||||
|
||||
bool ArmorScreen::addItem(const Touch::InventoryPane* forPane, int itemIndex) {
|
||||
const ItemInstance* instance = armorItems[itemIndex];
|
||||
if (!ItemInstance::isArmorItem(instance))
|
||||
return false;
|
||||
|
||||
ArmorItem* item = (ArmorItem*) instance->getItem();
|
||||
ItemInstance* old = player->getArmor(item->slot);
|
||||
ItemInstance oldArmor;
|
||||
|
||||
if (ItemInstance::isArmorItem(old)) {
|
||||
oldArmor = *old;
|
||||
}
|
||||
|
||||
player->setArmor(item->slot, instance);
|
||||
|
||||
player->inventory->removeItem(instance);
|
||||
//@attn: this is hugely important
|
||||
armorItems[itemIndex] = NULL;
|
||||
|
||||
if (!oldArmor.isNull()) {
|
||||
if (!player->inventory->add(&oldArmor)) {
|
||||
player->drop(new ItemInstance(oldArmor), false);
|
||||
}
|
||||
}
|
||||
|
||||
doRecreatePane = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ArmorScreen::isAllowed( int slot ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ArmorScreen::renderGameBehind() {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<const ItemInstance*> ArmorScreen::getItems( const Touch::InventoryPane* forPane ) {
|
||||
return armorItems;
|
||||
}
|
||||
|
||||
void ArmorScreen::updateItems() {
|
||||
armorItems.clear();
|
||||
|
||||
for (int i = Inventory::MAX_SELECTION_SIZE; i < minecraft->player->inventory->getContainerSize(); ++i) {
|
||||
ItemInstance* item = minecraft->player->inventory->getItem(i);
|
||||
if (ItemInstance::isArmorItem(item))
|
||||
armorItems.push_back(item);
|
||||
}
|
||||
}
|
||||
|
||||
bool ArmorScreen::canMoveToSlot(int slot, const ItemInstance* item) {
|
||||
return ItemInstance::isArmorItem(item)
|
||||
&& ((ArmorItem*)item)->slot == slot;
|
||||
}
|
||||
|
||||
void ArmorScreen::setupInventoryPane() {
|
||||
// IntRectangle(0, 0, 100, 100)
|
||||
if (inventoryPane) delete inventoryPane;
|
||||
inventoryPane = new Touch::InventoryPane(this, minecraft, inventoryPaneRect, inventoryPaneRect.w, BorderPixels, armorItems.size(), ItemSize, (int)BorderPixels);
|
||||
inventoryPane->fillMarginX = 0;
|
||||
inventoryPane->fillMarginY = 0;
|
||||
//LOGI("Creating new pane: %d %p\n", inventoryItems.size(), inventoryPane);
|
||||
}
|
||||
|
||||
void ArmorScreen::drawSlotItemAt( Tesselator& t, int slot, const ItemInstance* item, int x, int y)
|
||||
{
|
||||
float xx = (float)x;
|
||||
float yy = (float)y;
|
||||
|
||||
guiSlot->draw(t, xx, yy);
|
||||
|
||||
if (item && !item->isNull()) {
|
||||
ItemRenderer::renderGuiItem(minecraft->font, minecraft->textures, item, xx + 2, yy, true);
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
ItemRenderer::renderGuiItemDecorations(item, xx + 2, yy + 3);
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
//minecraft->gui.renderSlotText(item, xx + 3, yy + 3, true, true);
|
||||
} else {
|
||||
minecraft->textures->loadAndBindTexture("gui/items.png");
|
||||
blit(x + 2, y, 15 * 16, slot * 16, 16, 16, 16, 16);
|
||||
}
|
||||
}
|
||||
|
||||
void ArmorScreen::takeAndClearSlot( int slot ) {
|
||||
ItemInstance* item = player->getArmor(slot);
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
int oldSize = minecraft->player->inventory->getNumEmptySlots();
|
||||
|
||||
if (!minecraft->player->inventory->add(item))
|
||||
minecraft->player->drop(new ItemInstance(*item), false);
|
||||
|
||||
player->setArmor(slot, NULL);
|
||||
|
||||
int newSize = minecraft->player->inventory->getNumEmptySlots();
|
||||
setIfNotSet(doRecreatePane, newSize != oldSize);
|
||||
}
|
||||
|
||||
void ArmorScreen::renderPlayer(float xo, float yo) {
|
||||
// Push GL and player state
|
||||
glPushMatrix();
|
||||
|
||||
glTranslatef(xo, yo, -200);
|
||||
float ss = 45;
|
||||
glScalef(-ss, ss, ss);
|
||||
|
||||
glRotatef(180, 0, 0, 1);
|
||||
//glDisable(GL_DEPTH_TEST);
|
||||
|
||||
Player* player = (Player*) minecraft->player;
|
||||
float oybr = player->yBodyRot;
|
||||
float oyr = player->yRot;
|
||||
float oxr = player->xRot;
|
||||
|
||||
float t = getTimeS();
|
||||
|
||||
float xd = 10 * Mth::sin(t);//(xo + 51) - xm;
|
||||
float yd = 10 * Mth::cos(t * 0.05f);//(yo + 75 - 50) - ym;
|
||||
|
||||
glRotatef(45 + 90, 0, 1, 0);
|
||||
glRotatef(-45 - 90, 0, 1, 0);
|
||||
|
||||
const float xtan = Mth::atan(xd / 40.0f) * +20;
|
||||
const float ytan = Mth::atan(yd / 40.0f) * -20;
|
||||
|
||||
glRotatef(ytan, 1, 0, 0);
|
||||
|
||||
player->yBodyRot = xtan;
|
||||
player->yRot = xtan + xtan;
|
||||
player->xRot = ytan;
|
||||
glTranslatef(0, player->heightOffset, 0);
|
||||
|
||||
// Push walking anim
|
||||
float oldWAP = player->walkAnimPos;
|
||||
float oldWAS = player->walkAnimSpeed;
|
||||
float oldWASO = player->walkAnimSpeedO;
|
||||
|
||||
// Set new walking anim
|
||||
player->walkAnimSpeedO = player->walkAnimSpeed = 0.25f;
|
||||
player->walkAnimPos = getTimeS() * player->walkAnimSpeed * SharedConstants::TicksPerSecond;
|
||||
|
||||
EntityRenderDispatcher* rd = EntityRenderDispatcher::getInstance();
|
||||
rd->playerRotY = 180;
|
||||
rd->render(player, 0, 0, 0, 0, 1);
|
||||
|
||||
// Pop walking anim
|
||||
player->walkAnimPos = oldWAP;
|
||||
player->walkAnimSpeed = oldWAS;
|
||||
player->walkAnimSpeedO = oldWASO;
|
||||
|
||||
//glEnable(GL_DEPTH_TEST);
|
||||
// Pop GL and player state
|
||||
player->yBodyRot = oybr;
|
||||
player->yRot = oyr;
|
||||
player->xRot = oxr;
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
#include "ArmorScreen.hpp"
|
||||
#include "client/gui/Screen.hpp"
|
||||
#include "client/gui/components/NinePatch.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "client/player/LocalPlayer.hpp"
|
||||
#include "client/renderer/Tesselator.hpp"
|
||||
#include "client/renderer/entity/ItemRenderer.hpp"
|
||||
#include "world/item/Item.hpp"
|
||||
#include "world/item/ItemCategory.hpp"
|
||||
#include "world/entity/player/Inventory.hpp"
|
||||
#include "world/entity/item/ItemEntity.hpp"
|
||||
#include "world/level/Level.hpp"
|
||||
#include "network/RakNetInstance.hpp"
|
||||
#include "client/renderer/entity/EntityRenderDispatcher.hpp"
|
||||
#include "world/item/ArmorItem.hpp"
|
||||
|
||||
static void setIfNotSet(bool& ref, bool condition) {
|
||||
ref = (ref || condition);
|
||||
}
|
||||
|
||||
const int descFrameWidth = 100;
|
||||
|
||||
const int rgbActive = 0xfff0f0f0;
|
||||
const int rgbInactive = 0xc0635558;
|
||||
const int rgbInactiveShadow = 0xc0aaaaaa;
|
||||
|
||||
#ifdef __APPLE__
|
||||
static const float BorderPixels = 4;
|
||||
#ifdef DEMO_MODE
|
||||
static const float BlockPixels = 22;
|
||||
#else
|
||||
static const float BlockPixels = 22;
|
||||
#endif
|
||||
#else
|
||||
static const float BorderPixels = 4;
|
||||
static const float BlockPixels = 24;
|
||||
#endif
|
||||
static const int ItemSize = (int)(BlockPixels + 2*BorderPixels);
|
||||
|
||||
static const int Bx = 10; // Border Frame width
|
||||
static const int By = 6; // Border Frame height
|
||||
|
||||
|
||||
ArmorScreen::ArmorScreen():
|
||||
inventoryPane(NULL),
|
||||
btnArmor0(0),
|
||||
btnArmor1(1),
|
||||
btnArmor2(2),
|
||||
btnArmor3(3),
|
||||
btnClose(4, ""),
|
||||
bHeader (5, "Armor"),
|
||||
guiBackground(NULL),
|
||||
guiSlot(NULL),
|
||||
guiPaneFrame(NULL),
|
||||
guiPlayerBg(NULL),
|
||||
doRecreatePane(false),
|
||||
descWidth(90)
|
||||
//guiSlotItem(NULL),
|
||||
//guiSlotItemSelected(NULL)
|
||||
{
|
||||
//LOGI("Creating ArmorScreen with %p, %d\n", furnace, furnace->runningId);
|
||||
}
|
||||
|
||||
ArmorScreen::~ArmorScreen() {
|
||||
delete inventoryPane;
|
||||
|
||||
delete guiBackground;
|
||||
delete guiSlot;
|
||||
delete guiPaneFrame;
|
||||
delete guiPlayerBg;
|
||||
}
|
||||
|
||||
void ArmorScreen::init() {
|
||||
super::init();
|
||||
|
||||
player = minecraft->player;
|
||||
|
||||
ImageDef def;
|
||||
def.name = "gui/spritesheet.png";
|
||||
def.x = 0;
|
||||
def.y = 1;
|
||||
def.width = def.height = 18;
|
||||
def.setSrc(IntRectangle(60, 0, 18, 18));
|
||||
btnClose.setImageDef(def, true);
|
||||
btnClose.scaleWhenPressed = false;
|
||||
|
||||
buttons.push_back(&bHeader);
|
||||
buttons.push_back(&btnClose);
|
||||
|
||||
armorButtons[0] = &btnArmor0;
|
||||
armorButtons[1] = &btnArmor1;
|
||||
armorButtons[2] = &btnArmor2;
|
||||
armorButtons[3] = &btnArmor3;
|
||||
for (int i = 0; i < NUM_ARMORBUTTONS; ++i)
|
||||
buttons.push_back(armorButtons[i]);
|
||||
|
||||
// GUI - nine patches
|
||||
NinePatchFactory builder(minecraft->textures, "gui/spritesheet.png");
|
||||
|
||||
guiBackground = builder.createSymmetrical(IntRectangle(0, 0, 16, 16), 4, 4);
|
||||
guiSlot = builder.createSymmetrical(IntRectangle(0, 32, 8, 8), 3, 3, 20, 20);
|
||||
guiPaneFrame = builder.createSymmetrical(IntRectangle(28, 42, 4, 4), 1, 1)->setExcluded(1 << 4);
|
||||
guiPlayerBg = builder.createSymmetrical(IntRectangle(0, 20, 8, 8), 3, 3);
|
||||
|
||||
updateItems();
|
||||
}
|
||||
|
||||
void ArmorScreen::setupPositions() {
|
||||
// Left - Categories
|
||||
bHeader.x = bHeader.y = 0;
|
||||
bHeader.width = width;// - bDone.w;
|
||||
|
||||
btnClose.width = btnClose.height = 19;
|
||||
btnClose.x = width - btnClose.width;
|
||||
btnClose.y = 0;
|
||||
|
||||
// Inventory pane
|
||||
const int maxWidth = (int)(width/1.8f) - Bx - Bx;
|
||||
const int InventoryColumns = maxWidth / ItemSize;
|
||||
const int realWidth = InventoryColumns * ItemSize;
|
||||
const int paneWidth = realWidth + Bx + Bx;
|
||||
const int realBx = (paneWidth - realWidth) / 2;
|
||||
|
||||
inventoryPaneRect = IntRectangle(realBx,
|
||||
#ifdef __APPLE__
|
||||
26 + By - ((width==240)?1:0), realWidth, ((width==240)?1:0) + height-By-By-28);
|
||||
#else
|
||||
26 + By, realWidth, height-By-By-28);
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < NUM_ARMORBUTTONS; ++i) {
|
||||
Button& b = *armorButtons[i];
|
||||
b.x = paneWidth;
|
||||
b.y = inventoryPaneRect.y + 24 * i;
|
||||
b.width = 20;
|
||||
b.height = 20;
|
||||
}
|
||||
|
||||
guiPlayerBgRect.y = inventoryPaneRect.y;
|
||||
int xx = armorButtons[0]->x + armorButtons[0]->width;
|
||||
int xw = width - xx;
|
||||
guiPlayerBgRect.x = xx + xw / 10;
|
||||
guiPlayerBgRect.w = xw - (xw / 10) * 2;
|
||||
guiPlayerBgRect.h = inventoryPaneRect.h;
|
||||
|
||||
guiPaneFrame->setSize((float)inventoryPaneRect.w + 2, (float)inventoryPaneRect.h + 2);
|
||||
guiPlayerBg->setSize((float)guiPlayerBgRect.w, (float)guiPlayerBgRect.h);
|
||||
guiBackground->setSize((float)width, (float)height);
|
||||
|
||||
updateItems();
|
||||
setupInventoryPane();
|
||||
}
|
||||
|
||||
void ArmorScreen::tick() {
|
||||
if (inventoryPane)
|
||||
inventoryPane->tick();
|
||||
|
||||
if (doRecreatePane) {
|
||||
updateItems();
|
||||
setupInventoryPane();
|
||||
doRecreatePane = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ArmorScreen::handleRenderPane(Touch::InventoryPane* pane, Tesselator& t, int xm, int ym, float a) {
|
||||
if (pane) {
|
||||
pane->render(xm, ym, a);
|
||||
guiPaneFrame->draw(t, (float)(pane->rect.x - 1), (float)(pane->rect.y - 1));
|
||||
}
|
||||
}
|
||||
|
||||
void ArmorScreen::render(int xm, int ym, float a) {
|
||||
//renderBackground();
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
t.addOffset(0, 0, -500);
|
||||
guiBackground->draw(t, 0, 0);
|
||||
t.addOffset(0, 0, 500);
|
||||
glEnable2(GL_ALPHA_TEST);
|
||||
|
||||
// Buttons (Left side + crafting)
|
||||
super::render(xm, ym, a);
|
||||
|
||||
handleRenderPane(inventoryPane, t, xm, ym, a);
|
||||
|
||||
t.colorABGR(0xffffffff);
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
|
||||
t.addOffset(0, 0, -490);
|
||||
guiPlayerBg->draw(t, (float)guiPlayerBgRect.x, (float)guiPlayerBgRect.y);
|
||||
t.addOffset(0, 0, 490);
|
||||
renderPlayer((float)(guiPlayerBgRect.x + guiPlayerBgRect.w / 2), 0.85f * height);
|
||||
|
||||
for (int i = 0; i < NUM_ARMORBUTTONS; ++i) {
|
||||
drawSlotItemAt(t, i, player->getArmor(i), armorButtons[i]->x, armorButtons[i]->y);
|
||||
}
|
||||
glDisable2(GL_ALPHA_TEST);
|
||||
}
|
||||
|
||||
void ArmorScreen::buttonClicked(Button* button) {
|
||||
if (button == &btnClose) {
|
||||
minecraft->setScreen(NULL);
|
||||
}
|
||||
|
||||
if (button->id >= 0 && button->id <= 3) {
|
||||
takeAndClearSlot(button->id);
|
||||
}
|
||||
}
|
||||
|
||||
bool ArmorScreen::addItem(const Touch::InventoryPane* forPane, int itemIndex) {
|
||||
const ItemInstance* instance = armorItems[itemIndex];
|
||||
if (!ItemInstance::isArmorItem(instance))
|
||||
return false;
|
||||
|
||||
ArmorItem* item = (ArmorItem*) instance->getItem();
|
||||
ItemInstance* old = player->getArmor(item->slot);
|
||||
ItemInstance oldArmor;
|
||||
|
||||
if (ItemInstance::isArmorItem(old)) {
|
||||
oldArmor = *old;
|
||||
}
|
||||
|
||||
player->setArmor(item->slot, instance);
|
||||
|
||||
player->inventory->removeItem(instance);
|
||||
//@attn: this is hugely important
|
||||
armorItems[itemIndex] = NULL;
|
||||
|
||||
if (!oldArmor.isNull()) {
|
||||
if (!player->inventory->add(&oldArmor)) {
|
||||
player->drop(new ItemInstance(oldArmor), false);
|
||||
}
|
||||
}
|
||||
|
||||
doRecreatePane = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ArmorScreen::isAllowed( int slot ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ArmorScreen::renderGameBehind() {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<const ItemInstance*> ArmorScreen::getItems( const Touch::InventoryPane* forPane ) {
|
||||
return armorItems;
|
||||
}
|
||||
|
||||
void ArmorScreen::updateItems() {
|
||||
armorItems.clear();
|
||||
|
||||
for (int i = Inventory::MAX_SELECTION_SIZE; i < minecraft->player->inventory->getContainerSize(); ++i) {
|
||||
ItemInstance* item = minecraft->player->inventory->getItem(i);
|
||||
if (ItemInstance::isArmorItem(item))
|
||||
armorItems.push_back(item);
|
||||
}
|
||||
}
|
||||
|
||||
bool ArmorScreen::canMoveToSlot(int slot, const ItemInstance* item) {
|
||||
return ItemInstance::isArmorItem(item)
|
||||
&& ((ArmorItem*)item)->slot == slot;
|
||||
}
|
||||
|
||||
void ArmorScreen::setupInventoryPane() {
|
||||
// IntRectangle(0, 0, 100, 100)
|
||||
if (inventoryPane) delete inventoryPane;
|
||||
inventoryPane = new Touch::InventoryPane(this, minecraft, inventoryPaneRect, inventoryPaneRect.w, BorderPixels, armorItems.size(), ItemSize, (int)BorderPixels);
|
||||
inventoryPane->fillMarginX = 0;
|
||||
inventoryPane->fillMarginY = 0;
|
||||
//LOGI("Creating new pane: %d %p\n", inventoryItems.size(), inventoryPane);
|
||||
}
|
||||
|
||||
void ArmorScreen::drawSlotItemAt( Tesselator& t, int slot, const ItemInstance* item, int x, int y)
|
||||
{
|
||||
float xx = (float)x;
|
||||
float yy = (float)y;
|
||||
|
||||
guiSlot->draw(t, xx, yy);
|
||||
|
||||
if (item && !item->isNull()) {
|
||||
ItemRenderer::renderGuiItem(minecraft->font, minecraft->textures, item, xx + 2, yy, true);
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
ItemRenderer::renderGuiItemDecorations(item, xx + 2, yy + 3);
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
//minecraft->gui.renderSlotText(item, xx + 3, yy + 3, true, true);
|
||||
} else {
|
||||
minecraft->textures->loadAndBindTexture("gui/items.png");
|
||||
blit(x + 2, y, 15 * 16, slot * 16, 16, 16, 16, 16);
|
||||
}
|
||||
}
|
||||
|
||||
void ArmorScreen::takeAndClearSlot( int slot ) {
|
||||
ItemInstance* item = player->getArmor(slot);
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
int oldSize = minecraft->player->inventory->getNumEmptySlots();
|
||||
|
||||
if (!minecraft->player->inventory->add(item))
|
||||
minecraft->player->drop(new ItemInstance(*item), false);
|
||||
|
||||
player->setArmor(slot, NULL);
|
||||
|
||||
int newSize = minecraft->player->inventory->getNumEmptySlots();
|
||||
setIfNotSet(doRecreatePane, newSize != oldSize);
|
||||
}
|
||||
|
||||
void ArmorScreen::renderPlayer(float xo, float yo) {
|
||||
// Push GL and player state
|
||||
glPushMatrix();
|
||||
|
||||
glTranslatef(xo, yo, -200);
|
||||
float ss = 45;
|
||||
glScalef(-ss, ss, ss);
|
||||
|
||||
glRotatef(180, 0, 0, 1);
|
||||
//glDisable(GL_DEPTH_TEST);
|
||||
|
||||
Player* player = (Player*) minecraft->player;
|
||||
float oybr = player->yBodyRot;
|
||||
float oyr = player->yRot;
|
||||
float oxr = player->xRot;
|
||||
|
||||
float t = getTimeS();
|
||||
|
||||
float xd = 10 * Mth::sin(t);//(xo + 51) - xm;
|
||||
float yd = 10 * Mth::cos(t * 0.05f);//(yo + 75 - 50) - ym;
|
||||
|
||||
glRotatef(45 + 90, 0, 1, 0);
|
||||
glRotatef(-45 - 90, 0, 1, 0);
|
||||
|
||||
const float xtan = Mth::atan(xd / 40.0f) * +20;
|
||||
const float ytan = Mth::atan(yd / 40.0f) * -20;
|
||||
|
||||
glRotatef(ytan, 1, 0, 0);
|
||||
|
||||
player->yBodyRot = xtan;
|
||||
player->yRot = xtan + xtan;
|
||||
player->xRot = ytan;
|
||||
glTranslatef(0, player->heightOffset, 0);
|
||||
|
||||
// Push walking anim
|
||||
float oldWAP = player->walkAnimPos;
|
||||
float oldWAS = player->walkAnimSpeed;
|
||||
float oldWASO = player->walkAnimSpeedO;
|
||||
|
||||
// Set new walking anim
|
||||
player->walkAnimSpeedO = player->walkAnimSpeed = 0.25f;
|
||||
player->walkAnimPos = getTimeS() * player->walkAnimSpeed * SharedConstants::TicksPerSecond;
|
||||
|
||||
EntityRenderDispatcher* rd = EntityRenderDispatcher::getInstance();
|
||||
rd->playerRotY = 180;
|
||||
rd->render(player, 0, 0, 0, 0, 1);
|
||||
|
||||
// Pop walking anim
|
||||
player->walkAnimPos = oldWAP;
|
||||
player->walkAnimSpeed = oldWAS;
|
||||
player->walkAnimSpeedO = oldWASO;
|
||||
|
||||
//glEnable(GL_DEPTH_TEST);
|
||||
// Pop GL and player state
|
||||
player->yBodyRot = oybr;
|
||||
player->yRot = oyr;
|
||||
player->xRot = oxr;
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "BaseContainerScreen.h"
|
||||
#include "BaseContainerScreen.hpp"
|
||||
|
||||
#include "../components/InventoryPane.h"
|
||||
#include "../components/Button.h"
|
||||
#include "client/gui/components/InventoryPane.hpp"
|
||||
#include "client/gui/components/Button.hpp"
|
||||
|
||||
class Font;
|
||||
class CItem;
|
||||
@@ -3,9 +3,9 @@
|
||||
//package net.minecraft.client.gui.screens;
|
||||
|
||||
#include <vector>
|
||||
#include "../Screen.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../player/LocalPlayer.h"
|
||||
#include "client/gui/Screen.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "client/player/LocalPlayer.hpp"
|
||||
|
||||
class BaseContainerMenu;
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
#include "ChatScreen.h"
|
||||
#include "DialogDefinitions.h"
|
||||
#include "../Gui.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../../AppPlatform.h"
|
||||
#include "../../../platform/log.h"
|
||||
|
||||
void ChatScreen::init() {
|
||||
minecraft->platform()->createUserInput(DialogDefinitions::DIALOG_NEW_CHAT_MESSAGE);
|
||||
}
|
||||
|
||||
void ChatScreen::render(int xm, int ym, float a)
|
||||
{
|
||||
int status = minecraft->platform()->getUserInputStatus();
|
||||
if (status > -1) {
|
||||
if (status == 1) {
|
||||
std::vector<std::string> v = minecraft->platform()->getUserInput();
|
||||
if (v.size() && v[0].length() > 0)
|
||||
minecraft->gui.addMessage(v[0]);
|
||||
}
|
||||
|
||||
minecraft->setScreen(NULL);
|
||||
}
|
||||
}
|
||||
#include "ChatScreen.hpp"
|
||||
#include "DialogDefinitions.hpp"
|
||||
#include "client/gui/Gui.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "AppPlatform.hpp"
|
||||
#include "platform/log.hpp"
|
||||
|
||||
void ChatScreen::init() {
|
||||
minecraft->platform()->createUserInput(DialogDefinitions::DIALOG_NEW_CHAT_MESSAGE);
|
||||
}
|
||||
|
||||
void ChatScreen::render(int xm, int ym, float a)
|
||||
{
|
||||
int status = minecraft->platform()->getUserInputStatus();
|
||||
if (status > -1) {
|
||||
if (status == 1) {
|
||||
std::vector<std::string> v = minecraft->platform()->getUserInput();
|
||||
if (v.size() && v[0].length() > 0)
|
||||
minecraft->gui.addMessage(v[0]);
|
||||
}
|
||||
|
||||
minecraft->setScreen(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Screen.h"
|
||||
#include "client/gui/Screen.hpp"
|
||||
|
||||
class ChatScreen: public Screen
|
||||
{
|
||||
@@ -1,474 +1,474 @@
|
||||
#include "ChestScreen.h"
|
||||
#include "touch/TouchStartMenuScreen.h"
|
||||
#include "../Screen.h"
|
||||
#include "../components/NinePatch.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../player/LocalPlayer.h"
|
||||
#include "../../renderer/Tesselator.h"
|
||||
#include "../../renderer/entity/ItemRenderer.h"
|
||||
#include "../../../world/item/Item.h"
|
||||
#include "../../../world/item/ItemCategory.h"
|
||||
#include "../../../world/entity/player/Inventory.h"
|
||||
#include "../../../world/entity/item/ItemEntity.h"
|
||||
#include "../../../world/level/Level.h"
|
||||
#include "../../../locale/I18n.h"
|
||||
#include "../../../util/StringUtils.h"
|
||||
#include "../../../network/packet/ContainerSetSlotPacket.h"
|
||||
#include "../../../network/RakNetInstance.h"
|
||||
#include "../../../world/level/tile/entity/TileEntity.h"
|
||||
#include "../../../world/level/tile/entity/ChestTileEntity.h"
|
||||
#include "../../../world/inventory/ContainerMenu.h"
|
||||
#include "../../../util/Mth.h"
|
||||
|
||||
//static NinePatchLayer* guiPaneFrame = NULL;
|
||||
|
||||
static inline void setIfNotSet(bool& ref, bool condition) {
|
||||
ref = (ref || condition);
|
||||
}
|
||||
|
||||
template<typename T,typename V>
|
||||
T* upcast(V* x) { return x; }
|
||||
|
||||
static int heldMs = -1;
|
||||
static int percent = -1;
|
||||
static const float MaxHoldMs = 500.0f;
|
||||
static const int MinChargeMs = 200;
|
||||
|
||||
class ItemDiffer {
|
||||
public:
|
||||
ItemDiffer(int size)
|
||||
: size(size),
|
||||
count(0)
|
||||
{
|
||||
base = new ItemInstance[size];
|
||||
}
|
||||
ItemDiffer(const std::vector<const ItemInstance*>& v)
|
||||
: size(v.size()),
|
||||
count(0)
|
||||
{
|
||||
base = new ItemInstance[size];
|
||||
init(v);
|
||||
}
|
||||
|
||||
~ItemDiffer() {
|
||||
delete[] base;
|
||||
}
|
||||
|
||||
void init(const std::vector<const ItemInstance*>& v) {
|
||||
for (int i = 0; i < size; ++i) {
|
||||
if (v[i]) base[i] = *v[i];
|
||||
else base[i].setNull();
|
||||
}
|
||||
}
|
||||
|
||||
int getDiff(const std::vector<const ItemInstance*>& v, std::vector<int>& outIndices) {
|
||||
int diffLen = v.size() - size;
|
||||
int minLen = Mth::Max((int)v.size(), size);
|
||||
for (int i = 0; i < minLen; ++i) {
|
||||
//LOGI("%s, %s\n", base[i].toString().c_str(), v[i]?v[i]->toString().c_str() : "null");
|
||||
if (!ItemInstance::matchesNulls(&base[i], v[i]))
|
||||
outIndices.push_back(i);
|
||||
}
|
||||
return diffLen;
|
||||
}
|
||||
|
||||
private:
|
||||
int size;
|
||||
int count;
|
||||
ItemInstance* base;
|
||||
};
|
||||
|
||||
const int descFrameWidth = 100;
|
||||
|
||||
const int rgbActive = 0xfff0f0f0;
|
||||
const int rgbInactive = 0xc0635558;
|
||||
const int rgbInactiveShadow = 0xc0aaaaaa;
|
||||
|
||||
#ifdef __APPLE__
|
||||
static const float BorderPixels = 3;
|
||||
#ifdef DEMO_MODE
|
||||
static const float BlockPixels = 22;
|
||||
#else
|
||||
static const float BlockPixels = 22;
|
||||
#endif
|
||||
#else
|
||||
static const float BorderPixels = 4;
|
||||
static const float BlockPixels = 24;
|
||||
#endif
|
||||
static const int ItemSize = (int)(BlockPixels + 2*BorderPixels);
|
||||
|
||||
static const int Bx = 10; // Border Frame width
|
||||
static const int By = 6; // Border Frame height
|
||||
|
||||
typedef struct FlyingItem {
|
||||
ItemInstance item;
|
||||
float startTime;
|
||||
float sx, sy;
|
||||
float dx, dy;
|
||||
} FlyingItem ;
|
||||
|
||||
static std::vector<FlyingItem> flyingItems;
|
||||
|
||||
ChestScreen::ChestScreen(Player* player, ChestTileEntity* chest)
|
||||
: super(new ContainerMenu(chest, chest->runningId)), //@huge @attn
|
||||
inventoryPane(NULL),
|
||||
chestPane(NULL),
|
||||
btnClose(4, ""),
|
||||
bHeader (5, "Inventory"),
|
||||
bHeaderChest (6, "Chest"),
|
||||
guiBackground(NULL),
|
||||
guiSlot(NULL),
|
||||
guiSlotMarked(NULL),
|
||||
guiSlotMarker(NULL),
|
||||
player(player),
|
||||
chest(chest),
|
||||
selectedSlot(-1),
|
||||
doRecreatePane(false)
|
||||
//guiSlotItem(NULL),
|
||||
//guiSlotItemSelected(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
ChestScreen::~ChestScreen() {
|
||||
delete inventoryPane;
|
||||
delete chestPane;
|
||||
|
||||
delete guiBackground;
|
||||
delete guiSlot;
|
||||
delete guiSlotMarked;
|
||||
delete guiSlotMarker;
|
||||
delete guiPaneFrame;
|
||||
|
||||
delete menu;
|
||||
|
||||
if (chest->clientSideOnly)
|
||||
delete chest;
|
||||
}
|
||||
|
||||
void ChestScreen::init() {
|
||||
super::init();
|
||||
//printf("-> %d\n", width/2);
|
||||
|
||||
ImageDef def;
|
||||
def.name = "gui/spritesheet.png";
|
||||
def.x = 0;
|
||||
def.y = 1;
|
||||
def.width = def.height = 18;
|
||||
def.setSrc(IntRectangle(60, 0, 18, 18));
|
||||
btnClose.setImageDef(def, true);
|
||||
btnClose.scaleWhenPressed = false;
|
||||
|
||||
buttons.push_back(&bHeader);
|
||||
buttons.push_back(&bHeaderChest);
|
||||
buttons.push_back(&btnClose);
|
||||
|
||||
// GUI - nine patches
|
||||
NinePatchFactory builder(minecraft->textures, "gui/spritesheet.png");
|
||||
|
||||
guiBackground = builder.createSymmetrical(IntRectangle(0, 0, 16, 16), 4, 4);
|
||||
guiSlot = builder.createSymmetrical(IntRectangle(0, 32, 8, 8), 3, 3);
|
||||
guiSlotMarked = builder.createSymmetrical(IntRectangle(0, 44, 8, 8), 3, 3);
|
||||
guiSlotMarker = builder.createSymmetrical(IntRectangle(10, 42, 16, 16), 5, 5);
|
||||
guiPaneFrame = builder.createSymmetrical(IntRectangle(28, 42, 4, 4), 1, 1)->exclude(4);
|
||||
}
|
||||
|
||||
void ChestScreen::setupPositions() {
|
||||
// Left - Categories
|
||||
bHeader.x = 0;
|
||||
bHeader.y = bHeaderChest.y = 0;
|
||||
bHeader.width = bHeaderChest.width = width / 2;// - bDone.w;
|
||||
bHeaderChest.x = bHeader.x + bHeader.width;
|
||||
|
||||
// Right - Description
|
||||
btnClose.width = btnClose.height = 19;
|
||||
btnClose.x = width - btnClose.width;
|
||||
btnClose.y = 0;
|
||||
|
||||
//guiPaneFrame->setSize((float)paneFuelRect.w + 2, (float)paneFuelRect.h + 4);
|
||||
guiBackground->setSize((float)width, (float)height);
|
||||
//guiSlotItem->setSize((float)width, 22); //@todo
|
||||
//guiSlotItemSelected->setSize((float)width, 22);
|
||||
|
||||
setupPane();
|
||||
}
|
||||
|
||||
void ChestScreen::tick() {
|
||||
if (inventoryPane)
|
||||
inventoryPane->tick();
|
||||
|
||||
if (chestPane)
|
||||
chestPane->tick();
|
||||
|
||||
if (doRecreatePane) {
|
||||
setupPane();
|
||||
doRecreatePane = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ChestScreen::handleRenderPane(Touch::InventoryPane* pane, Tesselator& t, int xm, int ym, float a) {
|
||||
if (pane) {
|
||||
int ms, id;
|
||||
pane->markerIndex = -1;
|
||||
if (pane->queryHoldTime(&id, &ms)) {
|
||||
heldMs = ms;
|
||||
|
||||
FillingContainer* c = (pane == inventoryPane)?
|
||||
upcast<FillingContainer>(minecraft->player->inventory)
|
||||
: upcast<FillingContainer>(chest);
|
||||
|
||||
const int slotIndex = id + c->getNumLinkedSlots();
|
||||
ItemInstance* item = c->getItem(slotIndex);
|
||||
int count = (item && !item->isNull())? item->count : 0;
|
||||
float maxHoldMs = item? 700 + 10 * item->count: MaxHoldMs;
|
||||
|
||||
if (count > 1) {
|
||||
float share = (heldMs-MinChargeMs) / maxHoldMs;
|
||||
pane->markerType = 1;//(heldMs >= MinChargeMs)? 1 : 0;
|
||||
pane->markerIndex = id;
|
||||
pane->markerShare = Mth::Max(share, 0.0f);
|
||||
|
||||
percent = (int)Mth::clamp(100.0f * share, 0.0f, 100.0f);
|
||||
if (percent >= 100) {
|
||||
addItem(pane, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pane->render(xm, ym, a);
|
||||
guiPaneFrame->draw(t, (float)(pane->rect.x - 1), (float)(pane->rect.y - 1));
|
||||
//LOGI("query-iv: %d, %d\n", gridId, heldMs);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void ChestScreen::render(int xm, int ym, float a) {
|
||||
const int N = 5;
|
||||
static StopwatchNLast r(N);
|
||||
//renderBackground();
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
guiBackground->draw(t, 0, 0);
|
||||
glEnable2(GL_ALPHA_TEST);
|
||||
|
||||
// Buttons (Left side + crafting)
|
||||
super::render(xm, ym, a);
|
||||
|
||||
heldMs = -1;
|
||||
|
||||
handleRenderPane(inventoryPane, t, xm, ym, a);
|
||||
handleRenderPane(chestPane, t, xm, ym, a);
|
||||
|
||||
float now = getTimeS();
|
||||
float MaxTime = 0.3f;
|
||||
std::vector<FlyingItem> flyingToSave;
|
||||
|
||||
glEnable2(GL_BLEND);
|
||||
glColor4f(1, 1, 1, 0.2f);
|
||||
t.beginOverride();
|
||||
//t.color(1.0f, 0.0f, 0.0f, 0.2f);
|
||||
//t.noColor();
|
||||
|
||||
glEnable2(GL_SCISSOR_TEST);
|
||||
//LOGI("panesBox: %d, %d - %d, %d\n", panesBbox.x, panesBbox.y, panesBbox.w, panesBbox.h);
|
||||
minecraft->gui.setScissorRect(panesBbox);
|
||||
for (unsigned int i = 0; i < flyingItems.size(); ++i) {
|
||||
FlyingItem& fi = flyingItems[i];
|
||||
float since = (now - fi.startTime);
|
||||
if (since > MaxTime) continue;
|
||||
float t = since / MaxTime;
|
||||
t *= t;
|
||||
//float xx = fi.sx + t * 100.0f;
|
||||
|
||||
float xx = Mth::lerp(fi.sx, fi.dx, t);
|
||||
float yy = Mth::lerp(fi.sy, fi.dy, t);
|
||||
ItemRenderer::renderGuiItem(minecraft->font, minecraft->textures, &fi.item, xx + 7, yy + 8, true);
|
||||
//minecraft->gui.renderSlotText(&fi.item, xx + 3, yy + 3, true, true);
|
||||
|
||||
flyingToSave.push_back(fi);
|
||||
}
|
||||
t.enableColor();
|
||||
t.endOverrideAndDraw();
|
||||
glDisable2(GL_SCISSOR_TEST);
|
||||
|
||||
flyingItems = flyingToSave;
|
||||
|
||||
t.colorABGR(0xffffffff);
|
||||
glDisable2(GL_BLEND);
|
||||
|
||||
minecraft->textures->loadAndBindTexture("gui/spritesheet.png");
|
||||
}
|
||||
|
||||
void ChestScreen::buttonClicked(Button* button) {
|
||||
if (button == &btnClose) {
|
||||
minecraft->player->closeContainer();
|
||||
}
|
||||
}
|
||||
|
||||
bool ChestScreen::handleAddItem(FillingContainer* from, FillingContainer* to, int itemIndex) {
|
||||
const int itemOffset = from->getNumLinkedSlots();
|
||||
const int slotIndex = itemIndex + itemOffset;
|
||||
ItemInstance* item = from->getItem(slotIndex);
|
||||
|
||||
bool added = false;
|
||||
bool fromChest = (from == chest);
|
||||
Touch::InventoryPane* pane = fromChest? chestPane : inventoryPane;
|
||||
Touch::InventoryPane* toPane = fromChest? inventoryPane : chestPane;
|
||||
|
||||
int wantedCount = (item && !item->isNull())? item->count * percent / 100 : 0;
|
||||
if ((item && !item->isNull()) && (!wantedCount || heldMs < MinChargeMs)) {
|
||||
wantedCount = 1;
|
||||
}
|
||||
|
||||
if (wantedCount > 0) {
|
||||
ItemInstance takenItem(*item);
|
||||
takenItem.count = wantedCount;
|
||||
|
||||
ItemDiffer differ(getItems(toPane));
|
||||
to->add(&takenItem);
|
||||
|
||||
added = (takenItem.count != wantedCount);
|
||||
|
||||
if (added) {
|
||||
item->count -= (wantedCount - takenItem.count);
|
||||
std::vector<int> changed;
|
||||
std::vector<const ItemInstance*> items = getItems(toPane);
|
||||
differ.getDiff(items, changed);
|
||||
|
||||
ScrollingPane::GridItem g, gTo;
|
||||
pane->getGridItemFor_slow(itemIndex, g);
|
||||
|
||||
//LOGI("Changed: %d\n", changed.size());
|
||||
for (unsigned int i = 0; i < changed.size(); ++i) {
|
||||
FlyingItem fi;
|
||||
fi.startTime = getTimeS();
|
||||
fi.item = *item;
|
||||
|
||||
fi.sx = g.xf;
|
||||
fi.sy = g.yf;
|
||||
|
||||
int toIndex = changed[i];
|
||||
toPane->getGridItemFor_slow(toIndex, gTo);
|
||||
|
||||
fi.dx = gTo.xf;
|
||||
fi.dy = gTo.yf;
|
||||
flyingItems.push_back(fi);
|
||||
|
||||
if (!fromChest && minecraft->level->isClientSide) {
|
||||
int j = toIndex;
|
||||
ItemInstance item = items[j]? *items[j] : ItemInstance();
|
||||
ContainerSetSlotPacket p(menu->containerId, j, item);
|
||||
minecraft->raknetInstance->send(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Send to server, needs a bit special handling
|
||||
if (fromChest) {
|
||||
ItemInstance ins(item->count <= 0? ItemInstance() : *item);
|
||||
ContainerSetSlotPacket p(menu->containerId, slotIndex, ins);
|
||||
minecraft->raknetInstance->send(p);
|
||||
}
|
||||
if (item->count <= 0)
|
||||
from->clearSlot(slotIndex);
|
||||
}
|
||||
// Clear the marker indices
|
||||
pane->markerIndex = toPane->markerIndex = -1;
|
||||
|
||||
return added;
|
||||
}
|
||||
|
||||
bool ChestScreen::addItem(const Touch::InventoryPane* forPane, int itemIndex) {
|
||||
//LOGI("items.size, index: %d, %d\n", inventoryItems.size(), itemIndex);
|
||||
bool l2r = (forPane == inventoryPane);
|
||||
return handleAddItem( l2r? upcast<FillingContainer>(minecraft->player->inventory) : upcast<FillingContainer>(chest),
|
||||
l2r? upcast<FillingContainer>(chest) : upcast<FillingContainer>(minecraft->player->inventory),
|
||||
itemIndex);
|
||||
}
|
||||
|
||||
bool ChestScreen::isAllowed( int slot )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ChestScreen::renderGameBehind()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<const ItemInstance*> ChestScreen::getItems( const Touch::InventoryPane* forPane )
|
||||
{
|
||||
if (forPane == inventoryPane) {
|
||||
for (int i = Inventory::MAX_SELECTION_SIZE, j = 0; i < minecraft->player->inventory->getContainerSize(); ++i, ++j)
|
||||
inventoryItems[j] = minecraft->player->inventory->getItem(i);
|
||||
return inventoryItems;
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < chest->getContainerSize(); ++i)
|
||||
chestItems[i] = chest->getItem(i);
|
||||
return chestItems;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ChestScreen::setupPane()
|
||||
{
|
||||
inventoryItems.clear();
|
||||
for (int i = Inventory::MAX_SELECTION_SIZE; i < minecraft->player->inventory->getContainerSize(); ++i) {
|
||||
ItemInstance* item = minecraft->player->inventory->getItem(i);
|
||||
/*if (!item || item->isNull()) continue;*/
|
||||
inventoryItems.push_back(item);
|
||||
}
|
||||
chestItems.clear();
|
||||
for (int i = 0; i < chest->getContainerSize(); ++i) {
|
||||
ItemInstance* item = chest->getItem(i);
|
||||
/*if (!item || item->isNull()) continue;*/
|
||||
chestItems.push_back(item);
|
||||
}
|
||||
|
||||
int maxWidth = width/2 - Bx/2;//- Bx - Bx/*- Bx*/;
|
||||
int InventoryColumns = maxWidth / ItemSize;
|
||||
const int realWidth = InventoryColumns * ItemSize;
|
||||
int paneWidth = realWidth;// + Bx + Bx;
|
||||
const int realBx = (width/2 - realWidth) / 2;
|
||||
|
||||
IntRectangle rect(realBx,
|
||||
#ifdef __APPLE__
|
||||
24 + By - ((width==240)?1:0), realWidth, ((width==240)?1:0) + height-By-By-24);
|
||||
#else
|
||||
24 + By, realWidth, height-By-By-24);
|
||||
#endif
|
||||
// IntRectangle(0, 0, 100, 100)
|
||||
if (inventoryPane) delete inventoryPane;
|
||||
inventoryPane = new Touch::InventoryPane(this, minecraft, rect, paneWidth, BorderPixels, minecraft->player->inventory->getContainerSize() - Inventory::MAX_SELECTION_SIZE, ItemSize, (int)BorderPixels);
|
||||
inventoryPane->fillMarginX = 0;
|
||||
inventoryPane->fillMarginY = 0;
|
||||
guiPaneFrame->setSize((float)rect.w + 2, (float)rect.h + 2);
|
||||
|
||||
panesBbox = rect;
|
||||
rect.x += width/2;// - rect.w - Bx;
|
||||
panesBbox.w += (rect.x - panesBbox.x);
|
||||
|
||||
if (chestPane) delete chestPane;
|
||||
chestPane = new Touch::InventoryPane(this, minecraft, rect, paneWidth, BorderPixels, chest->getContainerSize(), ItemSize, (int)BorderPixels);
|
||||
chestPane->fillMarginX = 0;
|
||||
chestPane->fillMarginY = 0;
|
||||
LOGI("Creating new panes\n:"
|
||||
" Inventory %d %p\n"
|
||||
" Chest %d %p\n", (int)inventoryItems.size(), inventoryPane, (int)chestItems.size(), chestPane);
|
||||
}
|
||||
|
||||
void ChestScreen::drawSlotItemAt( Tesselator& t, const ItemInstance* item, int x, int y, bool selected)
|
||||
{
|
||||
float xx = (float)x;
|
||||
float yy = (float)y;
|
||||
|
||||
(selected? guiSlot/*Marked*/ : guiSlot)->draw(t, xx, yy);
|
||||
|
||||
if (selected)
|
||||
guiSlotMarker->draw(t, xx - 2, yy - 2);
|
||||
|
||||
if (item && !item->isNull()) {
|
||||
ItemRenderer::renderGuiItem(minecraft->font, minecraft->textures, item, xx + 7, yy + 8, true);
|
||||
minecraft->gui.renderSlotText(item, xx + 3, yy + 3, true, true);
|
||||
}
|
||||
}
|
||||
#include "ChestScreen.hpp"
|
||||
#include "touch/TouchStartMenuScreen.hpp"
|
||||
#include "client/gui/Screen.hpp"
|
||||
#include "client/gui/components/NinePatch.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "client/player/LocalPlayer.hpp"
|
||||
#include "client/renderer/Tesselator.hpp"
|
||||
#include "client/renderer/entity/ItemRenderer.hpp"
|
||||
#include "world/item/Item.hpp"
|
||||
#include "world/item/ItemCategory.hpp"
|
||||
#include "world/entity/player/Inventory.hpp"
|
||||
#include "world/entity/item/ItemEntity.hpp"
|
||||
#include "world/level/Level.hpp"
|
||||
#include "locale/I18n.hpp"
|
||||
#include "util/StringUtils.hpp"
|
||||
#include "network/packet/ContainerSetSlotPacket.hpp"
|
||||
#include "network/RakNetInstance.hpp"
|
||||
#include "world/level/tile/entity/TileEntity.hpp"
|
||||
#include "world/level/tile/entity/ChestTileEntity.hpp"
|
||||
#include "world/inventory/ContainerMenu.hpp"
|
||||
#include "util/Mth.hpp"
|
||||
|
||||
//static NinePatchLayer* guiPaneFrame = NULL;
|
||||
|
||||
static inline void setIfNotSet(bool& ref, bool condition) {
|
||||
ref = (ref || condition);
|
||||
}
|
||||
|
||||
template<typename T,typename V>
|
||||
T* upcast(V* x) { return x; }
|
||||
|
||||
static int heldMs = -1;
|
||||
static int percent = -1;
|
||||
static const float MaxHoldMs = 500.0f;
|
||||
static const int MinChargeMs = 200;
|
||||
|
||||
class ItemDiffer {
|
||||
public:
|
||||
ItemDiffer(int size)
|
||||
: size(size),
|
||||
count(0)
|
||||
{
|
||||
base = new ItemInstance[size];
|
||||
}
|
||||
ItemDiffer(const std::vector<const ItemInstance*>& v)
|
||||
: size(v.size()),
|
||||
count(0)
|
||||
{
|
||||
base = new ItemInstance[size];
|
||||
init(v);
|
||||
}
|
||||
|
||||
~ItemDiffer() {
|
||||
delete[] base;
|
||||
}
|
||||
|
||||
void init(const std::vector<const ItemInstance*>& v) {
|
||||
for (int i = 0; i < size; ++i) {
|
||||
if (v[i]) base[i] = *v[i];
|
||||
else base[i].setNull();
|
||||
}
|
||||
}
|
||||
|
||||
int getDiff(const std::vector<const ItemInstance*>& v, std::vector<int>& outIndices) {
|
||||
int diffLen = v.size() - size;
|
||||
int minLen = Mth::Max((int)v.size(), size);
|
||||
for (int i = 0; i < minLen; ++i) {
|
||||
//LOGI("%s, %s\n", base[i].toString().c_str(), v[i]?v[i]->toString().c_str() : "null");
|
||||
if (!ItemInstance::matchesNulls(&base[i], v[i]))
|
||||
outIndices.push_back(i);
|
||||
}
|
||||
return diffLen;
|
||||
}
|
||||
|
||||
private:
|
||||
int size;
|
||||
int count;
|
||||
ItemInstance* base;
|
||||
};
|
||||
|
||||
const int descFrameWidth = 100;
|
||||
|
||||
const int rgbActive = 0xfff0f0f0;
|
||||
const int rgbInactive = 0xc0635558;
|
||||
const int rgbInactiveShadow = 0xc0aaaaaa;
|
||||
|
||||
#ifdef __APPLE__
|
||||
static const float BorderPixels = 3;
|
||||
#ifdef DEMO_MODE
|
||||
static const float BlockPixels = 22;
|
||||
#else
|
||||
static const float BlockPixels = 22;
|
||||
#endif
|
||||
#else
|
||||
static const float BorderPixels = 4;
|
||||
static const float BlockPixels = 24;
|
||||
#endif
|
||||
static const int ItemSize = (int)(BlockPixels + 2*BorderPixels);
|
||||
|
||||
static const int Bx = 10; // Border Frame width
|
||||
static const int By = 6; // Border Frame height
|
||||
|
||||
typedef struct FlyingItem {
|
||||
ItemInstance item;
|
||||
float startTime;
|
||||
float sx, sy;
|
||||
float dx, dy;
|
||||
} FlyingItem ;
|
||||
|
||||
static std::vector<FlyingItem> flyingItems;
|
||||
|
||||
ChestScreen::ChestScreen(Player* player, ChestTileEntity* chest)
|
||||
: super(new ContainerMenu(chest, chest->runningId)), //@huge @attn
|
||||
inventoryPane(NULL),
|
||||
chestPane(NULL),
|
||||
btnClose(4, ""),
|
||||
bHeader (5, "Inventory"),
|
||||
bHeaderChest (6, "Chest"),
|
||||
guiBackground(NULL),
|
||||
guiSlot(NULL),
|
||||
guiSlotMarked(NULL),
|
||||
guiSlotMarker(NULL),
|
||||
player(player),
|
||||
chest(chest),
|
||||
selectedSlot(-1),
|
||||
doRecreatePane(false)
|
||||
//guiSlotItem(NULL),
|
||||
//guiSlotItemSelected(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
ChestScreen::~ChestScreen() {
|
||||
delete inventoryPane;
|
||||
delete chestPane;
|
||||
|
||||
delete guiBackground;
|
||||
delete guiSlot;
|
||||
delete guiSlotMarked;
|
||||
delete guiSlotMarker;
|
||||
delete guiPaneFrame;
|
||||
|
||||
delete menu;
|
||||
|
||||
if (chest->clientSideOnly)
|
||||
delete chest;
|
||||
}
|
||||
|
||||
void ChestScreen::init() {
|
||||
super::init();
|
||||
//printf("-> %d\n", width/2);
|
||||
|
||||
ImageDef def;
|
||||
def.name = "gui/spritesheet.png";
|
||||
def.x = 0;
|
||||
def.y = 1;
|
||||
def.width = def.height = 18;
|
||||
def.setSrc(IntRectangle(60, 0, 18, 18));
|
||||
btnClose.setImageDef(def, true);
|
||||
btnClose.scaleWhenPressed = false;
|
||||
|
||||
buttons.push_back(&bHeader);
|
||||
buttons.push_back(&bHeaderChest);
|
||||
buttons.push_back(&btnClose);
|
||||
|
||||
// GUI - nine patches
|
||||
NinePatchFactory builder(minecraft->textures, "gui/spritesheet.png");
|
||||
|
||||
guiBackground = builder.createSymmetrical(IntRectangle(0, 0, 16, 16), 4, 4);
|
||||
guiSlot = builder.createSymmetrical(IntRectangle(0, 32, 8, 8), 3, 3);
|
||||
guiSlotMarked = builder.createSymmetrical(IntRectangle(0, 44, 8, 8), 3, 3);
|
||||
guiSlotMarker = builder.createSymmetrical(IntRectangle(10, 42, 16, 16), 5, 5);
|
||||
guiPaneFrame = builder.createSymmetrical(IntRectangle(28, 42, 4, 4), 1, 1)->exclude(4);
|
||||
}
|
||||
|
||||
void ChestScreen::setupPositions() {
|
||||
// Left - Categories
|
||||
bHeader.x = 0;
|
||||
bHeader.y = bHeaderChest.y = 0;
|
||||
bHeader.width = bHeaderChest.width = width / 2;// - bDone.w;
|
||||
bHeaderChest.x = bHeader.x + bHeader.width;
|
||||
|
||||
// Right - Description
|
||||
btnClose.width = btnClose.height = 19;
|
||||
btnClose.x = width - btnClose.width;
|
||||
btnClose.y = 0;
|
||||
|
||||
//guiPaneFrame->setSize((float)paneFuelRect.w + 2, (float)paneFuelRect.h + 4);
|
||||
guiBackground->setSize((float)width, (float)height);
|
||||
//guiSlotItem->setSize((float)width, 22); //@todo
|
||||
//guiSlotItemSelected->setSize((float)width, 22);
|
||||
|
||||
setupPane();
|
||||
}
|
||||
|
||||
void ChestScreen::tick() {
|
||||
if (inventoryPane)
|
||||
inventoryPane->tick();
|
||||
|
||||
if (chestPane)
|
||||
chestPane->tick();
|
||||
|
||||
if (doRecreatePane) {
|
||||
setupPane();
|
||||
doRecreatePane = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ChestScreen::handleRenderPane(Touch::InventoryPane* pane, Tesselator& t, int xm, int ym, float a) {
|
||||
if (pane) {
|
||||
int ms, id;
|
||||
pane->markerIndex = -1;
|
||||
if (pane->queryHoldTime(&id, &ms)) {
|
||||
heldMs = ms;
|
||||
|
||||
FillingContainer* c = (pane == inventoryPane)?
|
||||
upcast<FillingContainer>(minecraft->player->inventory)
|
||||
: upcast<FillingContainer>(chest);
|
||||
|
||||
const int slotIndex = id + c->getNumLinkedSlots();
|
||||
ItemInstance* item = c->getItem(slotIndex);
|
||||
int count = (item && !item->isNull())? item->count : 0;
|
||||
float maxHoldMs = item? 700 + 10 * item->count: MaxHoldMs;
|
||||
|
||||
if (count > 1) {
|
||||
float share = (heldMs-MinChargeMs) / maxHoldMs;
|
||||
pane->markerType = 1;//(heldMs >= MinChargeMs)? 1 : 0;
|
||||
pane->markerIndex = id;
|
||||
pane->markerShare = Mth::Max(share, 0.0f);
|
||||
|
||||
percent = (int)Mth::clamp(100.0f * share, 0.0f, 100.0f);
|
||||
if (percent >= 100) {
|
||||
addItem(pane, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pane->render(xm, ym, a);
|
||||
guiPaneFrame->draw(t, (float)(pane->rect.x - 1), (float)(pane->rect.y - 1));
|
||||
//LOGI("query-iv: %d, %d\n", gridId, heldMs);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void ChestScreen::render(int xm, int ym, float a) {
|
||||
const int N = 5;
|
||||
static StopwatchNLast r(N);
|
||||
//renderBackground();
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
guiBackground->draw(t, 0, 0);
|
||||
glEnable2(GL_ALPHA_TEST);
|
||||
|
||||
// Buttons (Left side + crafting)
|
||||
super::render(xm, ym, a);
|
||||
|
||||
heldMs = -1;
|
||||
|
||||
handleRenderPane(inventoryPane, t, xm, ym, a);
|
||||
handleRenderPane(chestPane, t, xm, ym, a);
|
||||
|
||||
float now = getTimeS();
|
||||
float MaxTime = 0.3f;
|
||||
std::vector<FlyingItem> flyingToSave;
|
||||
|
||||
glEnable2(GL_BLEND);
|
||||
glColor4f(1, 1, 1, 0.2f);
|
||||
t.beginOverride();
|
||||
//t.color(1.0f, 0.0f, 0.0f, 0.2f);
|
||||
//t.noColor();
|
||||
|
||||
glEnable2(GL_SCISSOR_TEST);
|
||||
//LOGI("panesBox: %d, %d - %d, %d\n", panesBbox.x, panesBbox.y, panesBbox.w, panesBbox.h);
|
||||
minecraft->gui.setScissorRect(panesBbox);
|
||||
for (unsigned int i = 0; i < flyingItems.size(); ++i) {
|
||||
FlyingItem& fi = flyingItems[i];
|
||||
float since = (now - fi.startTime);
|
||||
if (since > MaxTime) continue;
|
||||
float t = since / MaxTime;
|
||||
t *= t;
|
||||
//float xx = fi.sx + t * 100.0f;
|
||||
|
||||
float xx = Mth::lerp(fi.sx, fi.dx, t);
|
||||
float yy = Mth::lerp(fi.sy, fi.dy, t);
|
||||
ItemRenderer::renderGuiItem(minecraft->font, minecraft->textures, &fi.item, xx + 7, yy + 8, true);
|
||||
//minecraft->gui.renderSlotText(&fi.item, xx + 3, yy + 3, true, true);
|
||||
|
||||
flyingToSave.push_back(fi);
|
||||
}
|
||||
t.enableColor();
|
||||
t.endOverrideAndDraw();
|
||||
glDisable2(GL_SCISSOR_TEST);
|
||||
|
||||
flyingItems = flyingToSave;
|
||||
|
||||
t.colorABGR(0xffffffff);
|
||||
glDisable2(GL_BLEND);
|
||||
|
||||
minecraft->textures->loadAndBindTexture("gui/spritesheet.png");
|
||||
}
|
||||
|
||||
void ChestScreen::buttonClicked(Button* button) {
|
||||
if (button == &btnClose) {
|
||||
minecraft->player->closeContainer();
|
||||
}
|
||||
}
|
||||
|
||||
bool ChestScreen::handleAddItem(FillingContainer* from, FillingContainer* to, int itemIndex) {
|
||||
const int itemOffset = from->getNumLinkedSlots();
|
||||
const int slotIndex = itemIndex + itemOffset;
|
||||
ItemInstance* item = from->getItem(slotIndex);
|
||||
|
||||
bool added = false;
|
||||
bool fromChest = (from == chest);
|
||||
Touch::InventoryPane* pane = fromChest? chestPane : inventoryPane;
|
||||
Touch::InventoryPane* toPane = fromChest? inventoryPane : chestPane;
|
||||
|
||||
int wantedCount = (item && !item->isNull())? item->count * percent / 100 : 0;
|
||||
if ((item && !item->isNull()) && (!wantedCount || heldMs < MinChargeMs)) {
|
||||
wantedCount = 1;
|
||||
}
|
||||
|
||||
if (wantedCount > 0) {
|
||||
ItemInstance takenItem(*item);
|
||||
takenItem.count = wantedCount;
|
||||
|
||||
ItemDiffer differ(getItems(toPane));
|
||||
to->add(&takenItem);
|
||||
|
||||
added = (takenItem.count != wantedCount);
|
||||
|
||||
if (added) {
|
||||
item->count -= (wantedCount - takenItem.count);
|
||||
std::vector<int> changed;
|
||||
std::vector<const ItemInstance*> items = getItems(toPane);
|
||||
differ.getDiff(items, changed);
|
||||
|
||||
ScrollingPane::GridItem g, gTo;
|
||||
pane->getGridItemFor_slow(itemIndex, g);
|
||||
|
||||
//LOGI("Changed: %d\n", changed.size());
|
||||
for (unsigned int i = 0; i < changed.size(); ++i) {
|
||||
FlyingItem fi;
|
||||
fi.startTime = getTimeS();
|
||||
fi.item = *item;
|
||||
|
||||
fi.sx = g.xf;
|
||||
fi.sy = g.yf;
|
||||
|
||||
int toIndex = changed[i];
|
||||
toPane->getGridItemFor_slow(toIndex, gTo);
|
||||
|
||||
fi.dx = gTo.xf;
|
||||
fi.dy = gTo.yf;
|
||||
flyingItems.push_back(fi);
|
||||
|
||||
if (!fromChest && minecraft->level->isClientSide) {
|
||||
int j = toIndex;
|
||||
ItemInstance item = items[j]? *items[j] : ItemInstance();
|
||||
ContainerSetSlotPacket p(menu->containerId, j, item);
|
||||
minecraft->raknetInstance->send(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Send to server, needs a bit special handling
|
||||
if (fromChest) {
|
||||
ItemInstance ins(item->count <= 0? ItemInstance() : *item);
|
||||
ContainerSetSlotPacket p(menu->containerId, slotIndex, ins);
|
||||
minecraft->raknetInstance->send(p);
|
||||
}
|
||||
if (item->count <= 0)
|
||||
from->clearSlot(slotIndex);
|
||||
}
|
||||
// Clear the marker indices
|
||||
pane->markerIndex = toPane->markerIndex = -1;
|
||||
|
||||
return added;
|
||||
}
|
||||
|
||||
bool ChestScreen::addItem(const Touch::InventoryPane* forPane, int itemIndex) {
|
||||
//LOGI("items.size, index: %d, %d\n", inventoryItems.size(), itemIndex);
|
||||
bool l2r = (forPane == inventoryPane);
|
||||
return handleAddItem( l2r? upcast<FillingContainer>(minecraft->player->inventory) : upcast<FillingContainer>(chest),
|
||||
l2r? upcast<FillingContainer>(chest) : upcast<FillingContainer>(minecraft->player->inventory),
|
||||
itemIndex);
|
||||
}
|
||||
|
||||
bool ChestScreen::isAllowed( int slot )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ChestScreen::renderGameBehind()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<const ItemInstance*> ChestScreen::getItems( const Touch::InventoryPane* forPane )
|
||||
{
|
||||
if (forPane == inventoryPane) {
|
||||
for (int i = Inventory::MAX_SELECTION_SIZE, j = 0; i < minecraft->player->inventory->getContainerSize(); ++i, ++j)
|
||||
inventoryItems[j] = minecraft->player->inventory->getItem(i);
|
||||
return inventoryItems;
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < chest->getContainerSize(); ++i)
|
||||
chestItems[i] = chest->getItem(i);
|
||||
return chestItems;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ChestScreen::setupPane()
|
||||
{
|
||||
inventoryItems.clear();
|
||||
for (int i = Inventory::MAX_SELECTION_SIZE; i < minecraft->player->inventory->getContainerSize(); ++i) {
|
||||
ItemInstance* item = minecraft->player->inventory->getItem(i);
|
||||
/*if (!item || item->isNull()) continue;*/
|
||||
inventoryItems.push_back(item);
|
||||
}
|
||||
chestItems.clear();
|
||||
for (int i = 0; i < chest->getContainerSize(); ++i) {
|
||||
ItemInstance* item = chest->getItem(i);
|
||||
/*if (!item || item->isNull()) continue;*/
|
||||
chestItems.push_back(item);
|
||||
}
|
||||
|
||||
int maxWidth = width/2 - Bx/2;//- Bx - Bx/*- Bx*/;
|
||||
int InventoryColumns = maxWidth / ItemSize;
|
||||
const int realWidth = InventoryColumns * ItemSize;
|
||||
int paneWidth = realWidth;// + Bx + Bx;
|
||||
const int realBx = (width/2 - realWidth) / 2;
|
||||
|
||||
IntRectangle rect(realBx,
|
||||
#ifdef __APPLE__
|
||||
24 + By - ((width==240)?1:0), realWidth, ((width==240)?1:0) + height-By-By-24);
|
||||
#else
|
||||
24 + By, realWidth, height-By-By-24);
|
||||
#endif
|
||||
// IntRectangle(0, 0, 100, 100)
|
||||
if (inventoryPane) delete inventoryPane;
|
||||
inventoryPane = new Touch::InventoryPane(this, minecraft, rect, paneWidth, BorderPixels, minecraft->player->inventory->getContainerSize() - Inventory::MAX_SELECTION_SIZE, ItemSize, (int)BorderPixels);
|
||||
inventoryPane->fillMarginX = 0;
|
||||
inventoryPane->fillMarginY = 0;
|
||||
guiPaneFrame->setSize((float)rect.w + 2, (float)rect.h + 2);
|
||||
|
||||
panesBbox = rect;
|
||||
rect.x += width/2;// - rect.w - Bx;
|
||||
panesBbox.w += (rect.x - panesBbox.x);
|
||||
|
||||
if (chestPane) delete chestPane;
|
||||
chestPane = new Touch::InventoryPane(this, minecraft, rect, paneWidth, BorderPixels, chest->getContainerSize(), ItemSize, (int)BorderPixels);
|
||||
chestPane->fillMarginX = 0;
|
||||
chestPane->fillMarginY = 0;
|
||||
LOGI("Creating new panes\n:"
|
||||
" Inventory %d %p\n"
|
||||
" Chest %d %p\n", (int)inventoryItems.size(), inventoryPane, (int)chestItems.size(), chestPane);
|
||||
}
|
||||
|
||||
void ChestScreen::drawSlotItemAt( Tesselator& t, const ItemInstance* item, int x, int y, bool selected)
|
||||
{
|
||||
float xx = (float)x;
|
||||
float yy = (float)y;
|
||||
|
||||
(selected? guiSlot/*Marked*/ : guiSlot)->draw(t, xx, yy);
|
||||
|
||||
if (selected)
|
||||
guiSlotMarker->draw(t, xx - 2, yy - 2);
|
||||
|
||||
if (item && !item->isNull()) {
|
||||
ItemRenderer::renderGuiItem(minecraft->font, minecraft->textures, item, xx + 7, yy + 8, true);
|
||||
minecraft->gui.renderSlotText(item, xx + 3, yy + 3, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "BaseContainerScreen.h"
|
||||
#include "BaseContainerScreen.hpp"
|
||||
|
||||
#include "../components/InventoryPane.h"
|
||||
#include "../components/Button.h"
|
||||
#include "client/gui/components/InventoryPane.hpp"
|
||||
#include "client/gui/components/Button.hpp"
|
||||
|
||||
class Font;
|
||||
class CItem;
|
||||
@@ -1,26 +1,26 @@
|
||||
#include "ChooseLevelScreen.h"
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
#include "../../Minecraft.h"
|
||||
|
||||
void ChooseLevelScreen::init() {
|
||||
loadLevelSource();
|
||||
}
|
||||
|
||||
void ChooseLevelScreen::loadLevelSource()
|
||||
{
|
||||
LevelStorageSource* levelSource = minecraft->getLevelSource();
|
||||
levelSource->getLevelList(levels);
|
||||
std::sort(levels.begin(), levels.end());
|
||||
}
|
||||
|
||||
std::string ChooseLevelScreen::getUniqueLevelName( const std::string& level ) {
|
||||
std::set<std::string> Set;
|
||||
for (unsigned int i = 0; i < levels.size(); ++i)
|
||||
Set.insert(levels[i].id);
|
||||
|
||||
std::string s = level;
|
||||
while ( Set.find(s) != Set.end() )
|
||||
s += "-";
|
||||
return s;
|
||||
}
|
||||
#include "ChooseLevelScreen.hpp"
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
#include "client/Minecraft.hpp"
|
||||
|
||||
void ChooseLevelScreen::init() {
|
||||
loadLevelSource();
|
||||
}
|
||||
|
||||
void ChooseLevelScreen::loadLevelSource()
|
||||
{
|
||||
LevelStorageSource* levelSource = minecraft->getLevelSource();
|
||||
levelSource->getLevelList(levels);
|
||||
std::sort(levels.begin(), levels.end());
|
||||
}
|
||||
|
||||
std::string ChooseLevelScreen::getUniqueLevelName( const std::string& level ) {
|
||||
std::set<std::string> Set;
|
||||
for (unsigned int i = 0; i < levels.size(); ++i)
|
||||
Set.insert(levels[i].id);
|
||||
|
||||
std::string s = level;
|
||||
while ( Set.find(s) != Set.end() )
|
||||
s += "-";
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Screen.h"
|
||||
#include "../../../world/level/storage/LevelStorageSource.h"
|
||||
#include "client/gui/Screen.hpp"
|
||||
#include "world/level/storage/LevelStorageSource.hpp"
|
||||
|
||||
class ChooseLevelScreen: public Screen
|
||||
{
|
||||
@@ -1,84 +1,84 @@
|
||||
#include "ConfirmScreen.h"
|
||||
#include "../components/Button.h"
|
||||
#include "../../Minecraft.h"
|
||||
|
||||
ConfirmScreen::ConfirmScreen(Screen* parent_, const std::string& title1_, const std::string& title2_, int id_)
|
||||
: parent(parent_),
|
||||
title1(title1_),
|
||||
title2(title2_),
|
||||
id(id_),
|
||||
yesButtonText("Ok"),
|
||||
noButtonText("Cancel"),
|
||||
yesButton(0),
|
||||
noButton(0)
|
||||
{
|
||||
}
|
||||
|
||||
ConfirmScreen::ConfirmScreen(Screen* parent_, const std::string& title1_, const std::string& title2_, const std::string& yesButton_, const std::string& noButton_, int id_ )
|
||||
: parent(parent_),
|
||||
title1(title1_),
|
||||
title2(title2_),
|
||||
id(id_),
|
||||
yesButtonText(yesButton_),
|
||||
noButtonText(noButton_)
|
||||
{
|
||||
}
|
||||
|
||||
ConfirmScreen::~ConfirmScreen() {
|
||||
delete yesButton;
|
||||
delete noButton;
|
||||
}
|
||||
|
||||
void ConfirmScreen::init()
|
||||
{
|
||||
if (/* minecraft->useTouchscreen() */ true) {
|
||||
yesButton = new Touch::TButton(0, 0, 0, yesButtonText),
|
||||
noButton = new Touch::TButton(1, 0, 0, noButtonText);
|
||||
} else {
|
||||
yesButton = new Button(0, 0, 0, yesButtonText),
|
||||
noButton = new Button(1, 0, 0, noButtonText);
|
||||
}
|
||||
|
||||
buttons.push_back(yesButton);
|
||||
buttons.push_back(noButton);
|
||||
|
||||
tabButtons.push_back(yesButton);
|
||||
tabButtons.push_back(noButton);
|
||||
}
|
||||
|
||||
void ConfirmScreen::setupPositions() {
|
||||
const int ButtonWidth = 120;
|
||||
const int ButtonHeight = 24;
|
||||
yesButton->x = width / 2 - ButtonWidth - 4;
|
||||
yesButton->y = height / 6 + 72;
|
||||
noButton->x = width / 2 + 4;
|
||||
noButton->y = height / 6 + 72;
|
||||
yesButton->width = noButton->width = ButtonWidth;
|
||||
yesButton->height = noButton->height = ButtonHeight;
|
||||
}
|
||||
|
||||
bool ConfirmScreen::handleBackEvent(bool isDown) {
|
||||
if (!isDown)
|
||||
postResult(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ConfirmScreen::render( int xm, int ym, float a )
|
||||
{
|
||||
renderBackground();
|
||||
|
||||
drawCenteredString(font, title1, width / 2, 50, 0xffffff);
|
||||
drawCenteredString(font, title2, width / 2, 70, 0xffffff);
|
||||
|
||||
super::render(xm, ym, a);
|
||||
}
|
||||
|
||||
void ConfirmScreen::buttonClicked( Button* button )
|
||||
{
|
||||
postResult(button->id == 0);
|
||||
}
|
||||
|
||||
void ConfirmScreen::postResult(bool isOk)
|
||||
{
|
||||
parent->confirmResult(isOk, id);
|
||||
}
|
||||
#include "ConfirmScreen.hpp"
|
||||
#include "client/gui/components/Button.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
|
||||
ConfirmScreen::ConfirmScreen(Screen* parent_, const std::string& title1_, const std::string& title2_, int id_)
|
||||
: parent(parent_),
|
||||
title1(title1_),
|
||||
title2(title2_),
|
||||
id(id_),
|
||||
yesButtonText("Ok"),
|
||||
noButtonText("Cancel"),
|
||||
yesButton(0),
|
||||
noButton(0)
|
||||
{
|
||||
}
|
||||
|
||||
ConfirmScreen::ConfirmScreen(Screen* parent_, const std::string& title1_, const std::string& title2_, const std::string& yesButton_, const std::string& noButton_, int id_ )
|
||||
: parent(parent_),
|
||||
title1(title1_),
|
||||
title2(title2_),
|
||||
id(id_),
|
||||
yesButtonText(yesButton_),
|
||||
noButtonText(noButton_)
|
||||
{
|
||||
}
|
||||
|
||||
ConfirmScreen::~ConfirmScreen() {
|
||||
delete yesButton;
|
||||
delete noButton;
|
||||
}
|
||||
|
||||
void ConfirmScreen::init()
|
||||
{
|
||||
if (/* minecraft->useTouchscreen() */ true) {
|
||||
yesButton = new Touch::TButton(0, 0, 0, yesButtonText),
|
||||
noButton = new Touch::TButton(1, 0, 0, noButtonText);
|
||||
} else {
|
||||
yesButton = new Button(0, 0, 0, yesButtonText),
|
||||
noButton = new Button(1, 0, 0, noButtonText);
|
||||
}
|
||||
|
||||
buttons.push_back(yesButton);
|
||||
buttons.push_back(noButton);
|
||||
|
||||
tabButtons.push_back(yesButton);
|
||||
tabButtons.push_back(noButton);
|
||||
}
|
||||
|
||||
void ConfirmScreen::setupPositions() {
|
||||
const int ButtonWidth = 120;
|
||||
const int ButtonHeight = 24;
|
||||
yesButton->x = width / 2 - ButtonWidth - 4;
|
||||
yesButton->y = height / 6 + 72;
|
||||
noButton->x = width / 2 + 4;
|
||||
noButton->y = height / 6 + 72;
|
||||
yesButton->width = noButton->width = ButtonWidth;
|
||||
yesButton->height = noButton->height = ButtonHeight;
|
||||
}
|
||||
|
||||
bool ConfirmScreen::handleBackEvent(bool isDown) {
|
||||
if (!isDown)
|
||||
postResult(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ConfirmScreen::render( int xm, int ym, float a )
|
||||
{
|
||||
renderBackground();
|
||||
|
||||
drawCenteredString(font, title1, width / 2, 50, 0xffffff);
|
||||
drawCenteredString(font, title2, width / 2, 70, 0xffffff);
|
||||
|
||||
super::render(xm, ym, a);
|
||||
}
|
||||
|
||||
void ConfirmScreen::buttonClicked( Button* button )
|
||||
{
|
||||
postResult(button->id == 0);
|
||||
}
|
||||
|
||||
void ConfirmScreen::postResult(bool isOk)
|
||||
{
|
||||
parent->confirmResult(isOk, id);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
//package net.minecraft.client.gui;
|
||||
|
||||
#include "../Screen.h"
|
||||
#include "client/gui/Screen.hpp"
|
||||
#include <string>
|
||||
|
||||
class ConfirmScreen: public Screen
|
||||
@@ -1,13 +1,13 @@
|
||||
#include "ConsoleScreen.h"
|
||||
#include "../Gui.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../player/LocalPlayer.h"
|
||||
#include "../../../platform/input/Keyboard.h"
|
||||
#include "../../../world/level/Level.h"
|
||||
#include "../../../network/RakNetInstance.h"
|
||||
#include "../../../network/ServerSideNetworkHandler.h"
|
||||
#include "../../../network/packet/ChatPacket.h"
|
||||
#include "../../../platform/log.h"
|
||||
#include "ConsoleScreen.hpp"
|
||||
#include "client/gui/Gui.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "client/player/LocalPlayer.hpp"
|
||||
#include "platform/input/Keyboard.hpp"
|
||||
#include "world/level/Level.hpp"
|
||||
#include "network/RakNetInstance.hpp"
|
||||
#include "network/ServerSideNetworkHandler.hpp"
|
||||
#include "network/packet/ChatPacket.hpp"
|
||||
#include "platform/log.hpp"
|
||||
|
||||
#include <sstream>
|
||||
#include <cstdlib>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Screen.h"
|
||||
#include "client/gui/Screen.hpp"
|
||||
#include <string>
|
||||
|
||||
class ConsoleScreen: public Screen
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "CreditsScreen.h"
|
||||
#include "StartMenuScreen.h"
|
||||
#include "OptionsScreen.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../components/Button.h"
|
||||
#include "../components/ImageButton.h"
|
||||
#include "platform/input/Mouse.h"
|
||||
#include "CreditsScreen.hpp"
|
||||
#include "StartMenuScreen.hpp"
|
||||
#include "OptionsScreen.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "client/gui/components/Button.hpp"
|
||||
#include "client/gui/components/ImageButton.hpp"
|
||||
#include "platform/input/Mouse.hpp"
|
||||
|
||||
CreditsScreen::CreditsScreen()
|
||||
: bHeader(NULL), btnBack(NULL)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Screen.h"
|
||||
#include "../components/Button.h"
|
||||
#include "client/gui/Screen.hpp"
|
||||
#include "client/gui/components/Button.hpp"
|
||||
|
||||
class ImageButton;
|
||||
|
||||
@@ -1,83 +1,83 @@
|
||||
#include "DeathScreen.h"
|
||||
#include "ScreenChooser.h"
|
||||
#include "../components/Button.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../player/LocalPlayer.h"
|
||||
#include "../../../platform/time.h"
|
||||
|
||||
static const int WAIT_TICKS = 30;
|
||||
|
||||
DeathScreen::DeathScreen()
|
||||
: bRespawn(0),
|
||||
bTitle(0),
|
||||
_hasChosen(false),
|
||||
_tick(0)
|
||||
{
|
||||
}
|
||||
|
||||
DeathScreen::~DeathScreen()
|
||||
{
|
||||
delete bRespawn;
|
||||
delete bTitle;
|
||||
}
|
||||
|
||||
void DeathScreen::init()
|
||||
{
|
||||
if (/* minecraft->useTouchscreen() */ true) {
|
||||
bRespawn = new Touch::TButton(1, "Respawn!");
|
||||
bTitle = new Touch::TButton(2, "Main menu");
|
||||
} else {
|
||||
bRespawn = new Button(1, "Respawn!");
|
||||
bTitle = new Button(2, "Main menu");
|
||||
}
|
||||
buttons.push_back(bRespawn);
|
||||
buttons.push_back(bTitle);
|
||||
|
||||
tabButtons.push_back(bRespawn);
|
||||
tabButtons.push_back(bTitle);
|
||||
}
|
||||
|
||||
void DeathScreen::setupPositions()
|
||||
{
|
||||
bRespawn->width = bTitle->width = width / 4;
|
||||
|
||||
bRespawn->y = bTitle->y = height / 2;
|
||||
bRespawn->x = width/2 - bRespawn->width - 10;
|
||||
bTitle->x = width/2 + 10;
|
||||
|
||||
LOGI("xyz: %d, %d (%d, %d)\n", bTitle->x, bTitle->y, width, height);
|
||||
}
|
||||
|
||||
void DeathScreen::tick() {
|
||||
++_tick;
|
||||
}
|
||||
|
||||
void DeathScreen::render( int xm, int ym, float a )
|
||||
{
|
||||
fillGradient(0, 0, width, height, 0x60500000, 0xa0803030);
|
||||
|
||||
glPushMatrix2();
|
||||
glScalef2(2, 2, 2);
|
||||
drawCenteredString(font, "You died!", width / 2 / 2, height / 8, 0xffffff);
|
||||
glPopMatrix2();
|
||||
|
||||
if (_tick >= WAIT_TICKS)
|
||||
Screen::render(xm, ym, a);
|
||||
}
|
||||
|
||||
void DeathScreen::buttonClicked( Button* button )
|
||||
{
|
||||
if (_tick < WAIT_TICKS) return;
|
||||
|
||||
if (button == bRespawn) {
|
||||
//RespawnPacket packet();
|
||||
//minecraft->raknetInstance->send(packet);
|
||||
|
||||
minecraft->player->respawn();
|
||||
//minecraft->raknetInstance->send();
|
||||
minecraft->setScreen(NULL);
|
||||
}
|
||||
|
||||
if (button == bTitle)
|
||||
minecraft->leaveGame();
|
||||
}
|
||||
#include "DeathScreen.hpp"
|
||||
#include "ScreenChooser.hpp"
|
||||
#include "client/gui/components/Button.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "client/player/LocalPlayer.hpp"
|
||||
#include "platform/time.hpp"
|
||||
|
||||
static const int WAIT_TICKS = 30;
|
||||
|
||||
DeathScreen::DeathScreen()
|
||||
: bRespawn(0),
|
||||
bTitle(0),
|
||||
_hasChosen(false),
|
||||
_tick(0)
|
||||
{
|
||||
}
|
||||
|
||||
DeathScreen::~DeathScreen()
|
||||
{
|
||||
delete bRespawn;
|
||||
delete bTitle;
|
||||
}
|
||||
|
||||
void DeathScreen::init()
|
||||
{
|
||||
if (/* minecraft->useTouchscreen() */ true) {
|
||||
bRespawn = new Touch::TButton(1, "Respawn!");
|
||||
bTitle = new Touch::TButton(2, "Main menu");
|
||||
} else {
|
||||
bRespawn = new Button(1, "Respawn!");
|
||||
bTitle = new Button(2, "Main menu");
|
||||
}
|
||||
buttons.push_back(bRespawn);
|
||||
buttons.push_back(bTitle);
|
||||
|
||||
tabButtons.push_back(bRespawn);
|
||||
tabButtons.push_back(bTitle);
|
||||
}
|
||||
|
||||
void DeathScreen::setupPositions()
|
||||
{
|
||||
bRespawn->width = bTitle->width = width / 4;
|
||||
|
||||
bRespawn->y = bTitle->y = height / 2;
|
||||
bRespawn->x = width/2 - bRespawn->width - 10;
|
||||
bTitle->x = width/2 + 10;
|
||||
|
||||
LOGI("xyz: %d, %d (%d, %d)\n", bTitle->x, bTitle->y, width, height);
|
||||
}
|
||||
|
||||
void DeathScreen::tick() {
|
||||
++_tick;
|
||||
}
|
||||
|
||||
void DeathScreen::render( int xm, int ym, float a )
|
||||
{
|
||||
fillGradient(0, 0, width, height, 0x60500000, 0xa0803030);
|
||||
|
||||
glPushMatrix2();
|
||||
glScalef2(2, 2, 2);
|
||||
drawCenteredString(font, "You died!", width / 2 / 2, height / 8, 0xffffff);
|
||||
glPopMatrix2();
|
||||
|
||||
if (_tick >= WAIT_TICKS)
|
||||
Screen::render(xm, ym, a);
|
||||
}
|
||||
|
||||
void DeathScreen::buttonClicked( Button* button )
|
||||
{
|
||||
if (_tick < WAIT_TICKS) return;
|
||||
|
||||
if (button == bRespawn) {
|
||||
//RespawnPacket packet();
|
||||
//minecraft->raknetInstance->send(packet);
|
||||
|
||||
minecraft->player->respawn();
|
||||
//minecraft->raknetInstance->send();
|
||||
minecraft->setScreen(NULL);
|
||||
}
|
||||
|
||||
if (button == bTitle)
|
||||
minecraft->leaveGame();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Screen.h"
|
||||
#include "client/gui/Screen.hpp"
|
||||
class Button;
|
||||
|
||||
class DeathScreen: public Screen
|
||||
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Screen.h"
|
||||
#include "../Font.h"
|
||||
#include "../components/Button.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "client/gui/Screen.hpp"
|
||||
#include "client/gui/Font.hpp"
|
||||
#include "client/gui/components/Button.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include <string>
|
||||
|
||||
class DisconnectionScreen: public Screen
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "BaseContainerScreen.h"
|
||||
#include "BaseContainerScreen.hpp"
|
||||
|
||||
#include "../components/InventoryPane.h"
|
||||
#include "../components/Button.h"
|
||||
#include "client/gui/components/InventoryPane.hpp"
|
||||
#include "client/gui/components/Button.hpp"
|
||||
|
||||
class Font;
|
||||
class CItem;
|
||||
@@ -1,49 +1,49 @@
|
||||
#include "InBedScreen.h"
|
||||
#include "ScreenChooser.h"
|
||||
#include "../components/Button.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../player/LocalPlayer.h"
|
||||
#include "../../../platform/time.h"
|
||||
|
||||
static const int WAIT_TICKS = 30;
|
||||
|
||||
InBedScreen::InBedScreen()
|
||||
: bWakeUp(0)
|
||||
{
|
||||
}
|
||||
|
||||
InBedScreen::~InBedScreen() {
|
||||
delete bWakeUp;
|
||||
}
|
||||
|
||||
void InBedScreen::init() {
|
||||
if (/* minecraft->useTouchscreen() */ true) {
|
||||
bWakeUp = new Touch::TButton(1, "Leave Bed");
|
||||
} else {
|
||||
bWakeUp = new Button(1, "Leave Bed");
|
||||
}
|
||||
buttons.push_back(bWakeUp);
|
||||
|
||||
tabButtons.push_back(bWakeUp);
|
||||
}
|
||||
|
||||
void InBedScreen::setupPositions() {
|
||||
bWakeUp->width = width / 2;
|
||||
bWakeUp->height = int(height * 0.2f);
|
||||
bWakeUp->y = height - int(bWakeUp->height * 1.5);
|
||||
bWakeUp->x = width/2 - bWakeUp->width/2;
|
||||
}
|
||||
|
||||
void InBedScreen::render( int xm, int ym, float a ) {
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
Screen::render(xm, ym, a);
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
void InBedScreen::buttonClicked( Button* button ) {
|
||||
if (button == bWakeUp) {
|
||||
minecraft->player->stopSleepInBed(true, true, true);
|
||||
minecraft->setScreen(NULL);
|
||||
}
|
||||
}
|
||||
#include "InBedScreen.hpp"
|
||||
#include "ScreenChooser.hpp"
|
||||
#include "client/gui/components/Button.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "client/player/LocalPlayer.hpp"
|
||||
#include "platform/time.hpp"
|
||||
|
||||
static const int WAIT_TICKS = 30;
|
||||
|
||||
InBedScreen::InBedScreen()
|
||||
: bWakeUp(0)
|
||||
{
|
||||
}
|
||||
|
||||
InBedScreen::~InBedScreen() {
|
||||
delete bWakeUp;
|
||||
}
|
||||
|
||||
void InBedScreen::init() {
|
||||
if (/* minecraft->useTouchscreen() */ true) {
|
||||
bWakeUp = new Touch::TButton(1, "Leave Bed");
|
||||
} else {
|
||||
bWakeUp = new Button(1, "Leave Bed");
|
||||
}
|
||||
buttons.push_back(bWakeUp);
|
||||
|
||||
tabButtons.push_back(bWakeUp);
|
||||
}
|
||||
|
||||
void InBedScreen::setupPositions() {
|
||||
bWakeUp->width = width / 2;
|
||||
bWakeUp->height = int(height * 0.2f);
|
||||
bWakeUp->y = height - int(bWakeUp->height * 1.5);
|
||||
bWakeUp->x = width/2 - bWakeUp->width/2;
|
||||
}
|
||||
|
||||
void InBedScreen::render( int xm, int ym, float a ) {
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
Screen::render(xm, ym, a);
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
void InBedScreen::buttonClicked( Button* button ) {
|
||||
if (button == bWakeUp) {
|
||||
minecraft->player->stopSleepInBed(true, true, true);
|
||||
minecraft->setScreen(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Screen.h"
|
||||
#include "client/gui/Screen.hpp"
|
||||
class Button;
|
||||
|
||||
class InBedScreen: public Screen
|
||||
@@ -1,341 +1,341 @@
|
||||
#include "IngameBlockSelectionScreen.h"
|
||||
#include "../../renderer/TileRenderer.h"
|
||||
#include "../../player/LocalPlayer.h"
|
||||
#include "../../renderer/gles.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../sound/SoundEngine.h"
|
||||
#include "../../../world/entity/player/Inventory.h"
|
||||
#include "../../../platform/input/Mouse.h"
|
||||
|
||||
#include "../Gui.h"
|
||||
#include "../../renderer/Textures.h"
|
||||
#include <gamemode/GameMode.h>
|
||||
#include "ArmorScreen.h"
|
||||
#include "../components/Button.h"
|
||||
|
||||
#if defined(__APPLE__)
|
||||
static const std::string demoVersionString("Not available in the Lite version");
|
||||
#else
|
||||
static const std::string demoVersionString("Not available in the demo version");
|
||||
#endif
|
||||
|
||||
IngameBlockSelectionScreen::IngameBlockSelectionScreen()
|
||||
: selectedItem(0),
|
||||
_area(0,0,0,0),
|
||||
_pendingQuit(false),
|
||||
InventoryRows(1),
|
||||
InventoryCols(1),
|
||||
InventorySize(1),
|
||||
bArmor(1, "Armor")
|
||||
{
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::init()
|
||||
{
|
||||
Inventory* inventory = minecraft->player->inventory;
|
||||
InventoryCols = minecraft->isCreativeMode()? 13 : 9;
|
||||
InventorySize = inventory->getContainerSize() - Inventory::MAX_SELECTION_SIZE;
|
||||
InventoryRows = 1 + (InventorySize - 1) / InventoryCols;
|
||||
|
||||
_area = RectangleArea( (float)getSlotPosX(0) - 4,
|
||||
(float)getSlotPosY(0) - 4,
|
||||
(float)getSlotPosX(InventoryCols) + 4,
|
||||
(float)getSlotPosY(InventoryRows) + 4);
|
||||
|
||||
ItemInstance* selected = inventory->getSelected();
|
||||
if (!selected || selected->isNull()) {
|
||||
selectedItem = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = Inventory::MAX_SELECTION_SIZE; i < InventorySize; i++) {
|
||||
if (selected == minecraft->player->inventory->getItem(i))
|
||||
{
|
||||
selectedItem = i - Inventory::MAX_SELECTION_SIZE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isAllowed(selectedItem))
|
||||
selectedItem = 0;
|
||||
|
||||
if (!minecraft->isCreativeMode()) {
|
||||
bArmor.width = 42;
|
||||
bArmor.x = 0;
|
||||
bArmor.y = height - bArmor.height;
|
||||
buttons.push_back(&bArmor);
|
||||
}
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::removed()
|
||||
{
|
||||
minecraft->gui.inventoryUpdated();
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::renderSlots()
|
||||
{
|
||||
//static Stopwatch w;
|
||||
//w.start();
|
||||
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
|
||||
blitOffset = -90;
|
||||
|
||||
//glEnable2(GL_RESCALE_NORMAL);
|
||||
//glPushMatrix2();
|
||||
//glRotatef2(180, 1, 0, 0);
|
||||
//Lighting::turnOn();
|
||||
//glPopMatrix2();
|
||||
|
||||
minecraft->textures->loadAndBindTexture("gui/gui.png");
|
||||
for (int r = 0; r < InventoryRows; r++)
|
||||
{
|
||||
int x = getSlotPosX(0) - 3;
|
||||
int y = getSlotPosY(r) - 3;
|
||||
|
||||
if (InventoryCols == 9) {
|
||||
blit(x, y, 0, 0, 182, 22);
|
||||
} else {
|
||||
// first 8 slots
|
||||
blit(x, y, 0, 0, 182-20, 22);
|
||||
// last k slots
|
||||
const int k = 5;
|
||||
const int w = k * 20;
|
||||
blit(x + 162, y, 182-w, 0, w, 22);
|
||||
}
|
||||
}
|
||||
if (selectedItem >= 0)
|
||||
{
|
||||
int x = getSlotPosX(selectedItem % InventoryCols) - 4;// width / 2 - 182 / 2 - 1 + () * 20;
|
||||
int y = getSlotPosY(selectedItem / InventoryCols) - 4;// height - 22 * 3 - 1 - (selectedItem / InventoryCols) * 22;
|
||||
blit(x, y, 0, 22, 24, 22);
|
||||
}
|
||||
|
||||
for (int r = 0; r < InventoryRows; r++)
|
||||
{
|
||||
int y = getSlotPosY(r);
|
||||
for (int i = 0; i < InventoryCols; i++) {
|
||||
int x = getSlotPosX(i);
|
||||
renderSlot(r * InventoryCols + i + Inventory::MAX_SELECTION_SIZE, x, y, 0);
|
||||
}
|
||||
}
|
||||
|
||||
//w.stop();
|
||||
//w.printEvery(1000, "render-blocksel");
|
||||
|
||||
//glDisable2(GL_RESCALE_NORMAL);
|
||||
//Lighting::turnOn();
|
||||
}
|
||||
|
||||
int IngameBlockSelectionScreen::getSlotPosX(int slotX) {
|
||||
return width / 2 - InventoryCols * 10 + slotX * 20 + 2;
|
||||
}
|
||||
|
||||
int IngameBlockSelectionScreen::getSlotPosY(int slotY) {
|
||||
//return height - 63 - 22 * (3 - slotY);
|
||||
int yy = InventoryCols==9? 8 : 3;
|
||||
return yy + slotY * getSlotHeight();
|
||||
}
|
||||
|
||||
//int IngameBlockSelectionScreen::getLinearSlotId(int x, int y) {
|
||||
// return
|
||||
//}
|
||||
|
||||
|
||||
#include "../../../world/item/ItemInstance.h"
|
||||
#include "../../renderer/entity/ItemRenderer.h"
|
||||
|
||||
void IngameBlockSelectionScreen::renderSlot(int slot, int x, int y, float a)
|
||||
{
|
||||
ItemInstance* item = minecraft->player->inventory->getItem(slot);
|
||||
if (!item) return;
|
||||
|
||||
ItemRenderer::renderGuiItem(minecraft->font, minecraft->textures, item, (float)x, (float)y, true);
|
||||
|
||||
if (minecraft->gameMode->isCreativeType()) return;
|
||||
if (!isAllowed(slot - Inventory::MAX_SELECTION_SIZE)) return;
|
||||
|
||||
glPushMatrix2();
|
||||
glScalef2(Gui::InvGuiScale + Gui::InvGuiScale, Gui::InvGuiScale + Gui::InvGuiScale, 1);
|
||||
const float k = 0.5f * Gui::GuiScale;
|
||||
minecraft->gui.renderSlotText(item, k*x, k*y, true, true);
|
||||
glPopMatrix2();
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::keyPressed(int eventKey)
|
||||
{
|
||||
int selX = selectedItem % InventoryCols;
|
||||
int selY = selectedItem / InventoryCols;
|
||||
|
||||
int tmpSelectedSlot = selectedItem;
|
||||
|
||||
Options& o = minecraft->options;
|
||||
if (eventKey == o.getIntValue(OPTIONS_KEY_LEFT) && selX > 0)
|
||||
{
|
||||
tmpSelectedSlot -= 1;
|
||||
}
|
||||
else if (eventKey == o.getIntValue(OPTIONS_KEY_RIGHT) && selX < (InventoryCols - 1))
|
||||
{
|
||||
tmpSelectedSlot += 1;
|
||||
}
|
||||
else if (eventKey == o.getIntValue(OPTIONS_KEY_BACK) && selY < (InventoryRows - 1))
|
||||
{
|
||||
tmpSelectedSlot += InventoryCols;
|
||||
}
|
||||
else if (eventKey == o.getIntValue(OPTIONS_KEY_FORWARD) && selY > 0)
|
||||
{
|
||||
tmpSelectedSlot -= InventoryCols;
|
||||
}
|
||||
|
||||
if (isAllowed(tmpSelectedSlot))
|
||||
selectedItem = tmpSelectedSlot;
|
||||
|
||||
if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_OK))
|
||||
selectSlotAndClose();
|
||||
|
||||
#ifdef RPI
|
||||
if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_CANCEL)
|
||||
|| eventKey == Keyboard::KEY_ESCAPE)
|
||||
minecraft->setScreen(NULL);
|
||||
#else
|
||||
if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_CANCEL))
|
||||
minecraft->setScreen(NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// wheel support for creative inventory; scroll moves selection vertically
|
||||
void IngameBlockSelectionScreen::mouseWheel(int dx, int dy, int xm, int ym)
|
||||
{
|
||||
if (dy == 0) return;
|
||||
// just move selection up/down one row; desktop UI doesn't have a pane
|
||||
int cols = InventoryCols;
|
||||
int maxIndex = InventorySize - 1;
|
||||
int idx = selectedItem;
|
||||
if (dy > 0) {
|
||||
// wheel up -> previous row
|
||||
if (idx >= cols) idx -= cols;
|
||||
} else {
|
||||
// wheel down -> next row
|
||||
if (idx + cols <= maxIndex) idx += cols;
|
||||
}
|
||||
selectedItem = idx;
|
||||
}
|
||||
|
||||
int IngameBlockSelectionScreen::getSelectedSlot(int x, int y)
|
||||
{
|
||||
int left = width / 2 - InventoryCols * 10;
|
||||
int top = -4 + getSlotPosY(0);
|
||||
|
||||
if (x >= left && y >= top)
|
||||
{
|
||||
int xSlot = (x - left) / 20;
|
||||
if (xSlot < InventoryCols) {
|
||||
int row = ((y-top) / getSlotHeight());
|
||||
return row * InventoryCols + xSlot;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::mouseClicked(int x, int y, int buttonNum)
|
||||
{
|
||||
if (buttonNum == MouseAction::ACTION_LEFT) {
|
||||
|
||||
int slot = getSelectedSlot(x, y);
|
||||
if (isAllowed(slot))
|
||||
{
|
||||
selectedItem = slot;
|
||||
//minecraft->soundEngine->playUI("random.click", 1, 1);
|
||||
} else {
|
||||
_pendingQuit = !_area.isInside((float)x, (float)y)
|
||||
&& !bArmor.isInside(x, y);
|
||||
}
|
||||
}
|
||||
if (!_pendingQuit)
|
||||
super::mouseClicked(x, y, buttonNum);
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::mouseReleased(int x, int y, int buttonNum)
|
||||
{
|
||||
if (buttonNum == MouseAction::ACTION_LEFT) {
|
||||
|
||||
int slot = getSelectedSlot(x, y);
|
||||
if (isAllowed(slot) && slot == selectedItem)
|
||||
{
|
||||
selectSlotAndClose();
|
||||
} else {
|
||||
if (_pendingQuit && !_area.isInside((float)x, (float)y))
|
||||
minecraft->setScreen(NULL);
|
||||
}
|
||||
}
|
||||
if (!_pendingQuit)
|
||||
super::mouseReleased(x, y, buttonNum);
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::selectSlotAndClose()
|
||||
{
|
||||
Inventory* inventory = minecraft->player->inventory;
|
||||
// Flash the selected gui item
|
||||
//inventory->moveToSelectedSlot(selectedItem + Inventory::MAX_SELECTION_SIZE, true);
|
||||
inventory->moveToSelectionSlot(0, selectedItem + Inventory::MAX_SELECTION_SIZE, true);
|
||||
inventory->selectSlot(0);
|
||||
minecraft->gui.flashSlot(inventory->selected);
|
||||
|
||||
minecraft->soundEngine->playUI("random.click", 1, 1);
|
||||
minecraft->setScreen(NULL);
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::render( int xm, int ym, float a )
|
||||
{
|
||||
glDisable2(GL_DEPTH_TEST);
|
||||
fill(0, 0, width, height, (0x80) << 24);
|
||||
glEnable2(GL_BLEND);
|
||||
|
||||
glDisable2(GL_ALPHA_TEST);
|
||||
glEnable2(GL_BLEND);
|
||||
glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
renderSlots();
|
||||
renderDemoOverlay();
|
||||
|
||||
glEnable2(GL_ALPHA_TEST);
|
||||
glDisable2(GL_BLEND);
|
||||
|
||||
glEnable2(GL_DEPTH_TEST);
|
||||
|
||||
Screen::render(xm, ym, a);
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::renderDemoOverlay() {
|
||||
#ifdef DEMO_MODE
|
||||
fill( getSlotPosX(0) - 3, getSlotPosY(3) - 3,
|
||||
getSlotPosX(InventoryCols) - 3, getSlotPosY(InventoryRows) - 3, 0xa0 << 24);
|
||||
|
||||
const int centerX = (getSlotPosX(4) + getSlotPosX(5)) / 2;
|
||||
const int centerY = (getSlotPosY(3) + getSlotPosY(InventoryRows-1)) / 2 + 5;
|
||||
drawCenteredString(minecraft->font, demoVersionString, centerX, centerY, 0xffffffff);
|
||||
#endif /*DEMO_MODE*/
|
||||
}
|
||||
|
||||
bool IngameBlockSelectionScreen::isAllowed(int slot) {
|
||||
if (slot < 0 || slot >= InventorySize)
|
||||
return false;
|
||||
|
||||
#ifdef DEMO_MODE
|
||||
return slot < (minecraft->isCreativeMode()? 28 : 27);
|
||||
#endif /*DEMO_MODE*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int IngameBlockSelectionScreen::getSlotHeight() {
|
||||
return InventoryCols==9? 22 : 20;
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::buttonClicked( Button* button )
|
||||
{
|
||||
if (button == &bArmor) {
|
||||
minecraft->setScreen(new ArmorScreen());
|
||||
}
|
||||
super::buttonClicked(button);
|
||||
}
|
||||
#include "IngameBlockSelectionScreen.hpp"
|
||||
#include "client/renderer/TileRenderer.hpp"
|
||||
#include "client/player/LocalPlayer.hpp"
|
||||
#include "client/renderer/gles.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "client/sound/SoundEngine.hpp"
|
||||
#include "world/entity/player/Inventory.hpp"
|
||||
#include "platform/input/Mouse.hpp"
|
||||
|
||||
#include "client/gui/Gui.hpp"
|
||||
#include "client/renderer/Textures.hpp"
|
||||
#include <gamemode/GameMode.hpp>
|
||||
#include "ArmorScreen.hpp"
|
||||
#include "client/gui/components/Button.hpp"
|
||||
|
||||
#if defined(__APPLE__)
|
||||
static const std::string demoVersionString("Not available in the Lite version");
|
||||
#else
|
||||
static const std::string demoVersionString("Not available in the demo version");
|
||||
#endif
|
||||
|
||||
IngameBlockSelectionScreen::IngameBlockSelectionScreen()
|
||||
: selectedItem(0),
|
||||
_area(0,0,0,0),
|
||||
_pendingQuit(false),
|
||||
InventoryRows(1),
|
||||
InventoryCols(1),
|
||||
InventorySize(1),
|
||||
bArmor(1, "Armor")
|
||||
{
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::init()
|
||||
{
|
||||
Inventory* inventory = minecraft->player->inventory;
|
||||
InventoryCols = minecraft->isCreativeMode()? 13 : 9;
|
||||
InventorySize = inventory->getContainerSize() - Inventory::MAX_SELECTION_SIZE;
|
||||
InventoryRows = 1 + (InventorySize - 1) / InventoryCols;
|
||||
|
||||
_area = RectangleArea( (float)getSlotPosX(0) - 4,
|
||||
(float)getSlotPosY(0) - 4,
|
||||
(float)getSlotPosX(InventoryCols) + 4,
|
||||
(float)getSlotPosY(InventoryRows) + 4);
|
||||
|
||||
ItemInstance* selected = inventory->getSelected();
|
||||
if (!selected || selected->isNull()) {
|
||||
selectedItem = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = Inventory::MAX_SELECTION_SIZE; i < InventorySize; i++) {
|
||||
if (selected == minecraft->player->inventory->getItem(i))
|
||||
{
|
||||
selectedItem = i - Inventory::MAX_SELECTION_SIZE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isAllowed(selectedItem))
|
||||
selectedItem = 0;
|
||||
|
||||
if (!minecraft->isCreativeMode()) {
|
||||
bArmor.width = 42;
|
||||
bArmor.x = 0;
|
||||
bArmor.y = height - bArmor.height;
|
||||
buttons.push_back(&bArmor);
|
||||
}
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::removed()
|
||||
{
|
||||
minecraft->gui.inventoryUpdated();
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::renderSlots()
|
||||
{
|
||||
//static Stopwatch w;
|
||||
//w.start();
|
||||
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
|
||||
blitOffset = -90;
|
||||
|
||||
//glEnable2(GL_RESCALE_NORMAL);
|
||||
//glPushMatrix2();
|
||||
//glRotatef2(180, 1, 0, 0);
|
||||
//Lighting::turnOn();
|
||||
//glPopMatrix2();
|
||||
|
||||
minecraft->textures->loadAndBindTexture("gui/gui.png");
|
||||
for (int r = 0; r < InventoryRows; r++)
|
||||
{
|
||||
int x = getSlotPosX(0) - 3;
|
||||
int y = getSlotPosY(r) - 3;
|
||||
|
||||
if (InventoryCols == 9) {
|
||||
blit(x, y, 0, 0, 182, 22);
|
||||
} else {
|
||||
// first 8 slots
|
||||
blit(x, y, 0, 0, 182-20, 22);
|
||||
// last k slots
|
||||
const int k = 5;
|
||||
const int w = k * 20;
|
||||
blit(x + 162, y, 182-w, 0, w, 22);
|
||||
}
|
||||
}
|
||||
if (selectedItem >= 0)
|
||||
{
|
||||
int x = getSlotPosX(selectedItem % InventoryCols) - 4;// width / 2 - 182 / 2 - 1 + () * 20;
|
||||
int y = getSlotPosY(selectedItem / InventoryCols) - 4;// height - 22 * 3 - 1 - (selectedItem / InventoryCols) * 22;
|
||||
blit(x, y, 0, 22, 24, 22);
|
||||
}
|
||||
|
||||
for (int r = 0; r < InventoryRows; r++)
|
||||
{
|
||||
int y = getSlotPosY(r);
|
||||
for (int i = 0; i < InventoryCols; i++) {
|
||||
int x = getSlotPosX(i);
|
||||
renderSlot(r * InventoryCols + i + Inventory::MAX_SELECTION_SIZE, x, y, 0);
|
||||
}
|
||||
}
|
||||
|
||||
//w.stop();
|
||||
//w.printEvery(1000, "render-blocksel");
|
||||
|
||||
//glDisable2(GL_RESCALE_NORMAL);
|
||||
//Lighting::turnOn();
|
||||
}
|
||||
|
||||
int IngameBlockSelectionScreen::getSlotPosX(int slotX) {
|
||||
return width / 2 - InventoryCols * 10 + slotX * 20 + 2;
|
||||
}
|
||||
|
||||
int IngameBlockSelectionScreen::getSlotPosY(int slotY) {
|
||||
//return height - 63 - 22 * (3 - slotY);
|
||||
int yy = InventoryCols==9? 8 : 3;
|
||||
return yy + slotY * getSlotHeight();
|
||||
}
|
||||
|
||||
//int IngameBlockSelectionScreen::getLinearSlotId(int x, int y) {
|
||||
// return
|
||||
//}
|
||||
|
||||
|
||||
#include "world/item/ItemInstance.hpp"
|
||||
#include "client/renderer/entity/ItemRenderer.hpp"
|
||||
|
||||
void IngameBlockSelectionScreen::renderSlot(int slot, int x, int y, float a)
|
||||
{
|
||||
ItemInstance* item = minecraft->player->inventory->getItem(slot);
|
||||
if (!item) return;
|
||||
|
||||
ItemRenderer::renderGuiItem(minecraft->font, minecraft->textures, item, (float)x, (float)y, true);
|
||||
|
||||
if (minecraft->gameMode->isCreativeType()) return;
|
||||
if (!isAllowed(slot - Inventory::MAX_SELECTION_SIZE)) return;
|
||||
|
||||
glPushMatrix2();
|
||||
glScalef2(Gui::InvGuiScale + Gui::InvGuiScale, Gui::InvGuiScale + Gui::InvGuiScale, 1);
|
||||
const float k = 0.5f * Gui::GuiScale;
|
||||
minecraft->gui.renderSlotText(item, k*x, k*y, true, true);
|
||||
glPopMatrix2();
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::keyPressed(int eventKey)
|
||||
{
|
||||
int selX = selectedItem % InventoryCols;
|
||||
int selY = selectedItem / InventoryCols;
|
||||
|
||||
int tmpSelectedSlot = selectedItem;
|
||||
|
||||
Options& o = minecraft->options;
|
||||
if (eventKey == o.getIntValue(OPTIONS_KEY_LEFT) && selX > 0)
|
||||
{
|
||||
tmpSelectedSlot -= 1;
|
||||
}
|
||||
else if (eventKey == o.getIntValue(OPTIONS_KEY_RIGHT) && selX < (InventoryCols - 1))
|
||||
{
|
||||
tmpSelectedSlot += 1;
|
||||
}
|
||||
else if (eventKey == o.getIntValue(OPTIONS_KEY_BACK) && selY < (InventoryRows - 1))
|
||||
{
|
||||
tmpSelectedSlot += InventoryCols;
|
||||
}
|
||||
else if (eventKey == o.getIntValue(OPTIONS_KEY_FORWARD) && selY > 0)
|
||||
{
|
||||
tmpSelectedSlot -= InventoryCols;
|
||||
}
|
||||
|
||||
if (isAllowed(tmpSelectedSlot))
|
||||
selectedItem = tmpSelectedSlot;
|
||||
|
||||
if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_OK))
|
||||
selectSlotAndClose();
|
||||
|
||||
#ifdef RPI
|
||||
if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_CANCEL)
|
||||
|| eventKey == Keyboard::KEY_ESCAPE)
|
||||
minecraft->setScreen(NULL);
|
||||
#else
|
||||
if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_CANCEL))
|
||||
minecraft->setScreen(NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// wheel support for creative inventory; scroll moves selection vertically
|
||||
void IngameBlockSelectionScreen::mouseWheel(int dx, int dy, int xm, int ym)
|
||||
{
|
||||
if (dy == 0) return;
|
||||
// just move selection up/down one row; desktop UI doesn't have a pane
|
||||
int cols = InventoryCols;
|
||||
int maxIndex = InventorySize - 1;
|
||||
int idx = selectedItem;
|
||||
if (dy > 0) {
|
||||
// wheel up -> previous row
|
||||
if (idx >= cols) idx -= cols;
|
||||
} else {
|
||||
// wheel down -> next row
|
||||
if (idx + cols <= maxIndex) idx += cols;
|
||||
}
|
||||
selectedItem = idx;
|
||||
}
|
||||
|
||||
int IngameBlockSelectionScreen::getSelectedSlot(int x, int y)
|
||||
{
|
||||
int left = width / 2 - InventoryCols * 10;
|
||||
int top = -4 + getSlotPosY(0);
|
||||
|
||||
if (x >= left && y >= top)
|
||||
{
|
||||
int xSlot = (x - left) / 20;
|
||||
if (xSlot < InventoryCols) {
|
||||
int row = ((y-top) / getSlotHeight());
|
||||
return row * InventoryCols + xSlot;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::mouseClicked(int x, int y, int buttonNum)
|
||||
{
|
||||
if (buttonNum == MouseAction::ACTION_LEFT) {
|
||||
|
||||
int slot = getSelectedSlot(x, y);
|
||||
if (isAllowed(slot))
|
||||
{
|
||||
selectedItem = slot;
|
||||
//minecraft->soundEngine->playUI("random.click", 1, 1);
|
||||
} else {
|
||||
_pendingQuit = !_area.isInside((float)x, (float)y)
|
||||
&& !bArmor.isInside(x, y);
|
||||
}
|
||||
}
|
||||
if (!_pendingQuit)
|
||||
super::mouseClicked(x, y, buttonNum);
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::mouseReleased(int x, int y, int buttonNum)
|
||||
{
|
||||
if (buttonNum == MouseAction::ACTION_LEFT) {
|
||||
|
||||
int slot = getSelectedSlot(x, y);
|
||||
if (isAllowed(slot) && slot == selectedItem)
|
||||
{
|
||||
selectSlotAndClose();
|
||||
} else {
|
||||
if (_pendingQuit && !_area.isInside((float)x, (float)y))
|
||||
minecraft->setScreen(NULL);
|
||||
}
|
||||
}
|
||||
if (!_pendingQuit)
|
||||
super::mouseReleased(x, y, buttonNum);
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::selectSlotAndClose()
|
||||
{
|
||||
Inventory* inventory = minecraft->player->inventory;
|
||||
// Flash the selected gui item
|
||||
//inventory->moveToSelectedSlot(selectedItem + Inventory::MAX_SELECTION_SIZE, true);
|
||||
inventory->moveToSelectionSlot(0, selectedItem + Inventory::MAX_SELECTION_SIZE, true);
|
||||
inventory->selectSlot(0);
|
||||
minecraft->gui.flashSlot(inventory->selected);
|
||||
|
||||
minecraft->soundEngine->playUI("random.click", 1, 1);
|
||||
minecraft->setScreen(NULL);
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::render( int xm, int ym, float a )
|
||||
{
|
||||
glDisable2(GL_DEPTH_TEST);
|
||||
fill(0, 0, width, height, (0x80) << 24);
|
||||
glEnable2(GL_BLEND);
|
||||
|
||||
glDisable2(GL_ALPHA_TEST);
|
||||
glEnable2(GL_BLEND);
|
||||
glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
renderSlots();
|
||||
renderDemoOverlay();
|
||||
|
||||
glEnable2(GL_ALPHA_TEST);
|
||||
glDisable2(GL_BLEND);
|
||||
|
||||
glEnable2(GL_DEPTH_TEST);
|
||||
|
||||
Screen::render(xm, ym, a);
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::renderDemoOverlay() {
|
||||
#ifdef DEMO_MODE
|
||||
fill( getSlotPosX(0) - 3, getSlotPosY(3) - 3,
|
||||
getSlotPosX(InventoryCols) - 3, getSlotPosY(InventoryRows) - 3, 0xa0 << 24);
|
||||
|
||||
const int centerX = (getSlotPosX(4) + getSlotPosX(5)) / 2;
|
||||
const int centerY = (getSlotPosY(3) + getSlotPosY(InventoryRows-1)) / 2 + 5;
|
||||
drawCenteredString(minecraft->font, demoVersionString, centerX, centerY, 0xffffffff);
|
||||
#endif /*DEMO_MODE*/
|
||||
}
|
||||
|
||||
bool IngameBlockSelectionScreen::isAllowed(int slot) {
|
||||
if (slot < 0 || slot >= InventorySize)
|
||||
return false;
|
||||
|
||||
#ifdef DEMO_MODE
|
||||
return slot < (minecraft->isCreativeMode()? 28 : 27);
|
||||
#endif /*DEMO_MODE*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int IngameBlockSelectionScreen::getSlotHeight() {
|
||||
return InventoryCols==9? 22 : 20;
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::buttonClicked( Button* button )
|
||||
{
|
||||
if (button == &bArmor) {
|
||||
minecraft->setScreen(new ArmorScreen());
|
||||
}
|
||||
super::buttonClicked(button);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Screen.h"
|
||||
#include "../../player/input/touchscreen/TouchAreaModel.h"
|
||||
#include "../components/Button.h"
|
||||
#include "client/gui/Screen.hpp"
|
||||
#include "client/player/input/touchscreen/TouchAreaModel.hpp"
|
||||
#include "client/gui/components/Button.hpp"
|
||||
|
||||
class IngameBlockSelectionScreen : public Screen
|
||||
{
|
||||
@@ -1,14 +1,14 @@
|
||||
#include "JoinByIPScreen.h"
|
||||
#include "JoinByIPScreen.hpp"
|
||||
|
||||
#include "JoinGameScreen.h"
|
||||
#include "StartMenuScreen.h"
|
||||
#include "ProgressScreen.h"
|
||||
#include "../Font.h"
|
||||
#include "../../../network/RakNetInstance.h"
|
||||
#include "client/Options.h"
|
||||
#include "client/gui/Screen.h"
|
||||
#include "client/gui/components/TextBox.h"
|
||||
#include "network/ClientSideNetworkHandler.h"
|
||||
#include "JoinGameScreen.hpp"
|
||||
#include "StartMenuScreen.hpp"
|
||||
#include "ProgressScreen.hpp"
|
||||
#include "client/gui/Font.hpp"
|
||||
#include "network/RakNetInstance.hpp"
|
||||
#include "client/Options.hpp"
|
||||
#include "client/gui/Screen.hpp"
|
||||
#include "client/gui/components/TextBox.hpp"
|
||||
#include "network/ClientSideNetworkHandler.hpp"
|
||||
|
||||
JoinByIPScreen::JoinByIPScreen() :
|
||||
tIP(0, "Server IP"),
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
|
||||
#include "../Screen.h"
|
||||
#include "../components/Button.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "client/gui/components/ImageButton.h"
|
||||
#include "client/gui/components/TextBox.h"
|
||||
#include "client/gui/Screen.hpp"
|
||||
#include "client/gui/components/Button.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "client/gui/components/ImageButton.hpp"
|
||||
#include "client/gui/components/TextBox.hpp"
|
||||
|
||||
class JoinByIPScreen: public Screen
|
||||
{
|
||||
@@ -1,167 +1,167 @@
|
||||
#include "JoinGameScreen.h"
|
||||
#include "StartMenuScreen.h"
|
||||
#include "ProgressScreen.h"
|
||||
#include "../Font.h"
|
||||
#include "../../../network/RakNetInstance.h"
|
||||
|
||||
JoinGameScreen::JoinGameScreen()
|
||||
: bJoin( 2, "Join Game"),
|
||||
bBack( 3, "Back"),
|
||||
gamesList(NULL)
|
||||
{
|
||||
bJoin.active = false;
|
||||
//gamesList->yInertia = 0.5f;
|
||||
}
|
||||
|
||||
JoinGameScreen::~JoinGameScreen()
|
||||
{
|
||||
delete gamesList;
|
||||
}
|
||||
|
||||
void JoinGameScreen::buttonClicked(Button* button)
|
||||
{
|
||||
if (button->id == bJoin.id)
|
||||
{
|
||||
if (isIndexValid(gamesList->selectedItem))
|
||||
{
|
||||
PingedCompatibleServer selectedServer = gamesList->copiedServerList[gamesList->selectedItem];
|
||||
minecraft->joinMultiplayer(selectedServer);
|
||||
{
|
||||
bJoin.active = false;
|
||||
bBack.active = false;
|
||||
minecraft->setScreen(new ProgressScreen());
|
||||
}
|
||||
}
|
||||
//minecraft->locateMultiplayer();
|
||||
//minecraft->setScreen(new JoinGameScreen());
|
||||
}
|
||||
if (button->id == bBack.id)
|
||||
{
|
||||
minecraft->cancelLocateMultiplayer();
|
||||
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||
}
|
||||
}
|
||||
|
||||
bool JoinGameScreen::handleBackEvent(bool isDown)
|
||||
{
|
||||
if (!isDown)
|
||||
{
|
||||
minecraft->cancelLocateMultiplayer();
|
||||
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool JoinGameScreen::isIndexValid( int index )
|
||||
{
|
||||
return gamesList && index >= 0 && index < gamesList->getNumberOfItems();
|
||||
}
|
||||
|
||||
void JoinGameScreen::tick()
|
||||
{
|
||||
const ServerList& orgServerList = minecraft->raknetInstance->getServerList();
|
||||
ServerList serverList;
|
||||
for (unsigned int i = 0; i < orgServerList.size(); ++i)
|
||||
if (orgServerList[i].name.GetLength() > 0)
|
||||
serverList.push_back(orgServerList[i]);
|
||||
|
||||
if (serverList.size() != gamesList->copiedServerList.size())
|
||||
{
|
||||
// copy the currently selected item
|
||||
PingedCompatibleServer selectedServer;
|
||||
bool hasSelection = false;
|
||||
if (isIndexValid(gamesList->selectedItem))
|
||||
{
|
||||
selectedServer = gamesList->copiedServerList[gamesList->selectedItem];
|
||||
hasSelection = true;
|
||||
}
|
||||
|
||||
gamesList->copiedServerList = serverList;
|
||||
gamesList->selectItem(-1, false);
|
||||
|
||||
// re-select previous item if it still exists
|
||||
if (hasSelection)
|
||||
{
|
||||
for (unsigned int i = 0; i < gamesList->copiedServerList.size(); i++)
|
||||
{
|
||||
if (gamesList->copiedServerList[i].address == selectedServer.address)
|
||||
{
|
||||
gamesList->selectItem(i, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = (int)gamesList->copiedServerList.size()-1; i >= 0 ; --i) {
|
||||
for (int j = 0; j < (int) serverList.size(); ++j)
|
||||
if (serverList[j].address == gamesList->copiedServerList[i].address)
|
||||
gamesList->copiedServerList[i].name = serverList[j].name;
|
||||
}
|
||||
}
|
||||
|
||||
bJoin.active = isIndexValid(gamesList->selectedItem);
|
||||
}
|
||||
|
||||
void JoinGameScreen::init()
|
||||
{
|
||||
buttons.push_back(&bJoin);
|
||||
buttons.push_back(&bBack);
|
||||
|
||||
minecraft->raknetInstance->clearServerList();
|
||||
gamesList = new AvailableGamesList(minecraft, width, height);
|
||||
|
||||
#ifdef ANDROID
|
||||
tabButtons.push_back(&bJoin);
|
||||
tabButtons.push_back(&bBack);
|
||||
#endif
|
||||
}
|
||||
|
||||
void JoinGameScreen::setupPositions() {
|
||||
int yBase = height - 26;
|
||||
|
||||
//#ifdef ANDROID
|
||||
bJoin.y = yBase;
|
||||
bBack.y = yBase;
|
||||
|
||||
bBack.width = bJoin.width = 120;
|
||||
//#endif
|
||||
|
||||
// Center buttons
|
||||
bJoin.x = width / 2 - 4 - bJoin.width;
|
||||
bBack.x = width / 2 + 4;
|
||||
}
|
||||
|
||||
void JoinGameScreen::render( int xm, int ym, float a )
|
||||
{
|
||||
bool hasNetwork = minecraft->platform()->isNetworkEnabled(true);
|
||||
#ifdef WIN32
|
||||
hasNetwork = hasNetwork && !GetAsyncKeyState(VK_TAB);
|
||||
#endif
|
||||
|
||||
renderBackground();
|
||||
if (hasNetwork) gamesList->render(xm, ym, a);
|
||||
Screen::render(xm, ym, a);
|
||||
|
||||
if (hasNetwork) {
|
||||
#ifdef RPI
|
||||
std::string s = "Scanning for Local Network Games...";
|
||||
#else
|
||||
std::string s = "Scanning for WiFi Games...";
|
||||
#endif
|
||||
drawCenteredString(minecraft->font, s, width / 2, 8, 0xffffffff);
|
||||
|
||||
const int textWidth = minecraft->font->width(s);
|
||||
const int spinnerX = width/2 + textWidth / 2 + 6;
|
||||
|
||||
static const char* spinnerTexts[] = {"-", "\\", "|", "/"};
|
||||
int n = ((int)(5.5f * getTimeS()) % 4);
|
||||
drawCenteredString(minecraft->font, spinnerTexts[n], spinnerX, 8, 0xffffffff);
|
||||
} else {
|
||||
std::string s = "WiFi is disabled";
|
||||
const int yy = height / 2 - 8;
|
||||
drawCenteredString(minecraft->font, s, width / 2, yy, 0xffffffff);
|
||||
}
|
||||
}
|
||||
|
||||
bool JoinGameScreen::isInGameScreen() { return false; }
|
||||
#include "JoinGameScreen.hpp"
|
||||
#include "StartMenuScreen.hpp"
|
||||
#include "ProgressScreen.hpp"
|
||||
#include "client/gui/Font.hpp"
|
||||
#include "network/RakNetInstance.hpp"
|
||||
|
||||
JoinGameScreen::JoinGameScreen()
|
||||
: bJoin( 2, "Join Game"),
|
||||
bBack( 3, "Back"),
|
||||
gamesList(NULL)
|
||||
{
|
||||
bJoin.active = false;
|
||||
//gamesList->yInertia = 0.5f;
|
||||
}
|
||||
|
||||
JoinGameScreen::~JoinGameScreen()
|
||||
{
|
||||
delete gamesList;
|
||||
}
|
||||
|
||||
void JoinGameScreen::buttonClicked(Button* button)
|
||||
{
|
||||
if (button->id == bJoin.id)
|
||||
{
|
||||
if (isIndexValid(gamesList->selectedItem))
|
||||
{
|
||||
PingedCompatibleServer selectedServer = gamesList->copiedServerList[gamesList->selectedItem];
|
||||
minecraft->joinMultiplayer(selectedServer);
|
||||
{
|
||||
bJoin.active = false;
|
||||
bBack.active = false;
|
||||
minecraft->setScreen(new ProgressScreen());
|
||||
}
|
||||
}
|
||||
//minecraft->locateMultiplayer();
|
||||
//minecraft->setScreen(new JoinGameScreen());
|
||||
}
|
||||
if (button->id == bBack.id)
|
||||
{
|
||||
minecraft->cancelLocateMultiplayer();
|
||||
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||
}
|
||||
}
|
||||
|
||||
bool JoinGameScreen::handleBackEvent(bool isDown)
|
||||
{
|
||||
if (!isDown)
|
||||
{
|
||||
minecraft->cancelLocateMultiplayer();
|
||||
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool JoinGameScreen::isIndexValid( int index )
|
||||
{
|
||||
return gamesList && index >= 0 && index < gamesList->getNumberOfItems();
|
||||
}
|
||||
|
||||
void JoinGameScreen::tick()
|
||||
{
|
||||
const ServerList& orgServerList = minecraft->raknetInstance->getServerList();
|
||||
ServerList serverList;
|
||||
for (unsigned int i = 0; i < orgServerList.size(); ++i)
|
||||
if (orgServerList[i].name.GetLength() > 0)
|
||||
serverList.push_back(orgServerList[i]);
|
||||
|
||||
if (serverList.size() != gamesList->copiedServerList.size())
|
||||
{
|
||||
// copy the currently selected item
|
||||
PingedCompatibleServer selectedServer;
|
||||
bool hasSelection = false;
|
||||
if (isIndexValid(gamesList->selectedItem))
|
||||
{
|
||||
selectedServer = gamesList->copiedServerList[gamesList->selectedItem];
|
||||
hasSelection = true;
|
||||
}
|
||||
|
||||
gamesList->copiedServerList = serverList;
|
||||
gamesList->selectItem(-1, false);
|
||||
|
||||
// re-select previous item if it still exists
|
||||
if (hasSelection)
|
||||
{
|
||||
for (unsigned int i = 0; i < gamesList->copiedServerList.size(); i++)
|
||||
{
|
||||
if (gamesList->copiedServerList[i].address == selectedServer.address)
|
||||
{
|
||||
gamesList->selectItem(i, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = (int)gamesList->copiedServerList.size()-1; i >= 0 ; --i) {
|
||||
for (int j = 0; j < (int) serverList.size(); ++j)
|
||||
if (serverList[j].address == gamesList->copiedServerList[i].address)
|
||||
gamesList->copiedServerList[i].name = serverList[j].name;
|
||||
}
|
||||
}
|
||||
|
||||
bJoin.active = isIndexValid(gamesList->selectedItem);
|
||||
}
|
||||
|
||||
void JoinGameScreen::init()
|
||||
{
|
||||
buttons.push_back(&bJoin);
|
||||
buttons.push_back(&bBack);
|
||||
|
||||
minecraft->raknetInstance->clearServerList();
|
||||
gamesList = new AvailableGamesList(minecraft, width, height);
|
||||
|
||||
#ifdef ANDROID
|
||||
tabButtons.push_back(&bJoin);
|
||||
tabButtons.push_back(&bBack);
|
||||
#endif
|
||||
}
|
||||
|
||||
void JoinGameScreen::setupPositions() {
|
||||
int yBase = height - 26;
|
||||
|
||||
//#ifdef ANDROID
|
||||
bJoin.y = yBase;
|
||||
bBack.y = yBase;
|
||||
|
||||
bBack.width = bJoin.width = 120;
|
||||
//#endif
|
||||
|
||||
// Center buttons
|
||||
bJoin.x = width / 2 - 4 - bJoin.width;
|
||||
bBack.x = width / 2 + 4;
|
||||
}
|
||||
|
||||
void JoinGameScreen::render( int xm, int ym, float a )
|
||||
{
|
||||
bool hasNetwork = minecraft->platform()->isNetworkEnabled(true);
|
||||
#ifdef WIN32
|
||||
hasNetwork = hasNetwork && !GetAsyncKeyState(VK_TAB);
|
||||
#endif
|
||||
|
||||
renderBackground();
|
||||
if (hasNetwork) gamesList->render(xm, ym, a);
|
||||
Screen::render(xm, ym, a);
|
||||
|
||||
if (hasNetwork) {
|
||||
#ifdef RPI
|
||||
std::string s = "Scanning for Local Network Games...";
|
||||
#else
|
||||
std::string s = "Scanning for WiFi Games...";
|
||||
#endif
|
||||
drawCenteredString(minecraft->font, s, width / 2, 8, 0xffffffff);
|
||||
|
||||
const int textWidth = minecraft->font->width(s);
|
||||
const int spinnerX = width/2 + textWidth / 2 + 6;
|
||||
|
||||
static const char* spinnerTexts[] = {"-", "\\", "|", "/"};
|
||||
int n = ((int)(5.5f * getTimeS()) % 4);
|
||||
drawCenteredString(minecraft->font, spinnerTexts[n], spinnerX, 8, 0xffffffff);
|
||||
} else {
|
||||
std::string s = "WiFi is disabled";
|
||||
const int yy = height / 2 - 8;
|
||||
drawCenteredString(minecraft->font, s, width / 2, yy, 0xffffffff);
|
||||
}
|
||||
}
|
||||
|
||||
bool JoinGameScreen::isInGameScreen() { return false; }
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Screen.h"
|
||||
#include "../components/Button.h"
|
||||
#include "../components/ScrolledSelectionList.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../../network/RakNetInstance.h"
|
||||
#include "client/gui/Screen.hpp"
|
||||
#include "client/gui/components/Button.hpp"
|
||||
#include "client/gui/components/ScrolledSelectionList.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "network/RakNetInstance.hpp"
|
||||
|
||||
|
||||
class JoinGameScreen;
|
||||
@@ -1,267 +1,267 @@
|
||||
#include "OptionsScreen.h"
|
||||
|
||||
#include "StartMenuScreen.h"
|
||||
#include "UsernameScreen.h"
|
||||
#include "DialogDefinitions.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../../AppPlatform.h"
|
||||
#include "CreditsScreen.h"
|
||||
|
||||
#include "../components/ImageButton.h"
|
||||
#include "../components/OptionsGroup.h"
|
||||
#include "platform/input/Keyboard.h"
|
||||
|
||||
OptionsScreen::OptionsScreen()
|
||||
: btnClose(NULL),
|
||||
bHeader(NULL),
|
||||
btnCredits(NULL),
|
||||
selectedCategory(0) {
|
||||
}
|
||||
|
||||
OptionsScreen::~OptionsScreen() {
|
||||
if (btnClose != NULL) {
|
||||
delete btnClose;
|
||||
btnClose = NULL;
|
||||
}
|
||||
|
||||
if (bHeader != NULL) {
|
||||
delete bHeader;
|
||||
bHeader = NULL;
|
||||
}
|
||||
|
||||
if (btnCredits != NULL) {
|
||||
delete btnCredits;
|
||||
btnCredits = NULL;
|
||||
}
|
||||
|
||||
for (std::vector<Touch::TButton*>::iterator it = categoryButtons.begin(); it != categoryButtons.end(); ++it) {
|
||||
if (*it != NULL) {
|
||||
delete* it;
|
||||
*it = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
for (std::vector<OptionsGroup*>::iterator it = optionPanes.begin(); it != optionPanes.end(); ++it) {
|
||||
if (*it != NULL) {
|
||||
delete* it;
|
||||
*it = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
categoryButtons.clear();
|
||||
}
|
||||
|
||||
void OptionsScreen::init() {
|
||||
bHeader = new Touch::THeader(0, "Options");
|
||||
|
||||
btnClose = new ImageButton(1, "");
|
||||
|
||||
ImageDef def;
|
||||
def.name = "gui/touchgui.png";
|
||||
def.width = 34;
|
||||
def.height = 26;
|
||||
|
||||
def.setSrc(IntRectangle(150, 0, (int)def.width, (int)def.height));
|
||||
btnClose->setImageDef(def, true);
|
||||
|
||||
categoryButtons.push_back(new Touch::TButton(2, "General"));
|
||||
categoryButtons.push_back(new Touch::TButton(3, "Game"));
|
||||
categoryButtons.push_back(new Touch::TButton(4, "Controls"));
|
||||
categoryButtons.push_back(new Touch::TButton(5, "Graphics"));
|
||||
categoryButtons.push_back(new Touch::TButton(6, "Tweaks"));
|
||||
|
||||
btnCredits = new Touch::TButton(11, "Credits");
|
||||
|
||||
buttons.push_back(bHeader);
|
||||
buttons.push_back(btnClose);
|
||||
buttons.push_back(btnCredits);
|
||||
|
||||
for (std::vector<Touch::TButton*>::iterator it = categoryButtons.begin(); it != categoryButtons.end(); ++it) {
|
||||
buttons.push_back(*it);
|
||||
tabButtons.push_back(*it);
|
||||
}
|
||||
|
||||
generateOptionScreens();
|
||||
// start with first category selected
|
||||
selectCategory(0);
|
||||
}
|
||||
|
||||
void OptionsScreen::setupPositions() {
|
||||
int buttonHeight = btnClose->height;
|
||||
|
||||
btnClose->x = width - btnClose->width;
|
||||
btnClose->y = 0;
|
||||
|
||||
int offsetNum = 1;
|
||||
|
||||
for (std::vector<Touch::TButton*>::iterator it = categoryButtons.begin(); it != categoryButtons.end(); ++it) {
|
||||
|
||||
(*it)->x = 0;
|
||||
(*it)->y = offsetNum * buttonHeight;
|
||||
(*it)->selected = false;
|
||||
|
||||
offsetNum++;
|
||||
}
|
||||
|
||||
bHeader->x = 0;
|
||||
bHeader->y = 0;
|
||||
bHeader->width = width - btnClose->width;
|
||||
bHeader->height = btnClose->height;
|
||||
|
||||
// Credits button (bottom-right)
|
||||
if (btnCredits != NULL) {
|
||||
btnCredits->x = width - btnCredits->width;
|
||||
btnCredits->y = height - btnCredits->height;
|
||||
}
|
||||
|
||||
for (std::vector<OptionsGroup*>::iterator it = optionPanes.begin(); it != optionPanes.end(); ++it) {
|
||||
|
||||
if (categoryButtons.size() > 0 && categoryButtons[0] != NULL) {
|
||||
|
||||
(*it)->x = categoryButtons[0]->width;
|
||||
(*it)->y = bHeader->height;
|
||||
(*it)->width = width - categoryButtons[0]->width;
|
||||
|
||||
(*it)->setupPositions();
|
||||
}
|
||||
}
|
||||
|
||||
// don't override user selection on resize
|
||||
}
|
||||
|
||||
|
||||
void OptionsScreen::render(int xm, int ym, float a) {
|
||||
renderBackground();
|
||||
|
||||
int xmm = xm * width / minecraft->width;
|
||||
int ymm = ym * height / minecraft->height - 1;
|
||||
|
||||
if (currentOptionsGroup != NULL)
|
||||
currentOptionsGroup->render(minecraft, xmm, ymm);
|
||||
|
||||
super::render(xm, ym, a);
|
||||
}
|
||||
|
||||
void OptionsScreen::removed() {
|
||||
}
|
||||
|
||||
void OptionsScreen::buttonClicked(Button* button) {
|
||||
if (button == btnClose) {
|
||||
minecraft->options.save();
|
||||
if (minecraft->screen != NULL) {
|
||||
minecraft->setScreen(NULL);
|
||||
} else {
|
||||
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||
}
|
||||
}
|
||||
else if (button->id > 1 && button->id < 7) {
|
||||
int categoryButton = button->id - categoryButtons[0]->id;
|
||||
selectCategory(categoryButton);
|
||||
}
|
||||
else if (button == btnCredits) {
|
||||
minecraft->setScreen(new CreditsScreen());
|
||||
}
|
||||
}
|
||||
|
||||
void OptionsScreen::selectCategory(int index) {
|
||||
int currentIndex = 0;
|
||||
|
||||
for (std::vector<Touch::TButton*>::iterator it = categoryButtons.begin(); it != categoryButtons.end(); ++it) {
|
||||
|
||||
if (index == currentIndex)
|
||||
(*it)->selected = true;
|
||||
else
|
||||
(*it)->selected = false;
|
||||
|
||||
currentIndex++;
|
||||
}
|
||||
|
||||
if (index < (int)optionPanes.size())
|
||||
currentOptionsGroup = optionPanes[index];
|
||||
}
|
||||
|
||||
void OptionsScreen::generateOptionScreens() {
|
||||
// how the fuck it works
|
||||
|
||||
optionPanes.push_back(new OptionsGroup("options.group.general"));
|
||||
optionPanes.push_back(new OptionsGroup("options.group.game"));
|
||||
optionPanes.push_back(new OptionsGroup("options.group.controls"));
|
||||
optionPanes.push_back(new OptionsGroup("options.group.graphics"));
|
||||
optionPanes.push_back(new OptionsGroup("options.group.tweaks"));
|
||||
|
||||
// General Pane
|
||||
optionPanes[0]->addOptionItem(OPTIONS_USERNAME, minecraft)
|
||||
.addOptionItem(OPTIONS_SENSITIVITY, minecraft);
|
||||
|
||||
// Game Pane
|
||||
optionPanes[1]->addOptionItem(OPTIONS_DIFFICULTY, minecraft)
|
||||
.addOptionItem(OPTIONS_SERVER_VISIBLE, minecraft)
|
||||
.addOptionItem(OPTIONS_THIRD_PERSON_VIEW, minecraft)
|
||||
.addOptionItem(OPTIONS_GUI_SCALE, minecraft)
|
||||
.addOptionItem(OPTIONS_SENSITIVITY, minecraft)
|
||||
.addOptionItem(OPTIONS_MUSIC_VOLUME, minecraft)
|
||||
.addOptionItem(OPTIONS_SOUND_VOLUME, minecraft)
|
||||
.addOptionItem(OPTIONS_SMOOTH_CAMERA, minecraft)
|
||||
.addOptionItem(OPTIONS_DESTROY_VIBRATION, minecraft)
|
||||
.addOptionItem(OPTIONS_IS_LEFT_HANDED, minecraft);
|
||||
|
||||
// // Controls Pane
|
||||
optionPanes[2]->addOptionItem(OPTIONS_INVERT_Y_MOUSE, minecraft)
|
||||
.addOptionItem(OPTIONS_USE_TOUCHSCREEN, minecraft)
|
||||
.addOptionItem(OPTIONS_AUTOJUMP, minecraft);
|
||||
|
||||
for (int i = OPTIONS_KEY_FORWARD; i <= OPTIONS_KEY_USE; i++) {
|
||||
optionPanes[2]->addOptionItem((OptionId)i, minecraft);
|
||||
}
|
||||
|
||||
// // Graphics Pane
|
||||
optionPanes[3]->addOptionItem(OPTIONS_FANCY_GRAPHICS, minecraft)
|
||||
.addOptionItem(OPTIONS_LIMIT_FRAMERATE, minecraft)
|
||||
.addOptionItem(OPTIONS_VSYNC, minecraft)
|
||||
.addOptionItem(OPTIONS_RENDER_DEBUG, minecraft)
|
||||
.addOptionItem(OPTIONS_ANAGLYPH_3D, minecraft)
|
||||
.addOptionItem(OPTIONS_VIEW_BOBBING, minecraft)
|
||||
.addOptionItem(OPTIONS_AMBIENT_OCCLUSION, minecraft);
|
||||
|
||||
optionPanes[4]->addOptionItem(OPTIONS_ALLOW_SPRINT, minecraft)
|
||||
.addOptionItem(OPTIONS_BAR_ON_TOP, minecraft)
|
||||
.addOptionItem(OPTIONS_RPI_CURSOR, minecraft);
|
||||
}
|
||||
|
||||
void OptionsScreen::mouseClicked(int x, int y, int buttonNum) {
|
||||
if (currentOptionsGroup != NULL)
|
||||
currentOptionsGroup->mouseClicked(minecraft, x, y, buttonNum);
|
||||
|
||||
super::mouseClicked(x, y, buttonNum);
|
||||
}
|
||||
|
||||
void OptionsScreen::mouseReleased(int x, int y, int buttonNum) {
|
||||
if (currentOptionsGroup != NULL)
|
||||
currentOptionsGroup->mouseReleased(minecraft, x, y, buttonNum);
|
||||
|
||||
super::mouseReleased(x, y, buttonNum);
|
||||
}
|
||||
|
||||
void OptionsScreen::keyPressed(int eventKey) {
|
||||
if (currentOptionsGroup != NULL)
|
||||
currentOptionsGroup->keyPressed(minecraft, eventKey);
|
||||
if (eventKey == Keyboard::KEY_ESCAPE)
|
||||
minecraft->options.save();
|
||||
|
||||
super::keyPressed(eventKey);
|
||||
}
|
||||
|
||||
void OptionsScreen::charPressed(char inputChar) {
|
||||
if (currentOptionsGroup != NULL)
|
||||
currentOptionsGroup->charPressed(minecraft, inputChar);
|
||||
|
||||
super::keyPressed(inputChar);
|
||||
}
|
||||
|
||||
void OptionsScreen::tick() {
|
||||
|
||||
if (currentOptionsGroup != NULL)
|
||||
currentOptionsGroup->tick(minecraft);
|
||||
|
||||
super::tick();
|
||||
#include "OptionsScreen.hpp"
|
||||
|
||||
#include "StartMenuScreen.hpp"
|
||||
#include "UsernameScreen.hpp"
|
||||
#include "DialogDefinitions.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "AppPlatform.hpp"
|
||||
#include "CreditsScreen.hpp"
|
||||
|
||||
#include "client/gui/components/ImageButton.hpp"
|
||||
#include "client/gui/components/OptionsGroup.hpp"
|
||||
#include "platform/input/Keyboard.hpp"
|
||||
|
||||
OptionsScreen::OptionsScreen()
|
||||
: btnClose(NULL),
|
||||
bHeader(NULL),
|
||||
btnCredits(NULL),
|
||||
selectedCategory(0) {
|
||||
}
|
||||
|
||||
OptionsScreen::~OptionsScreen() {
|
||||
if (btnClose != NULL) {
|
||||
delete btnClose;
|
||||
btnClose = NULL;
|
||||
}
|
||||
|
||||
if (bHeader != NULL) {
|
||||
delete bHeader;
|
||||
bHeader = NULL;
|
||||
}
|
||||
|
||||
if (btnCredits != NULL) {
|
||||
delete btnCredits;
|
||||
btnCredits = NULL;
|
||||
}
|
||||
|
||||
for (std::vector<Touch::TButton*>::iterator it = categoryButtons.begin(); it != categoryButtons.end(); ++it) {
|
||||
if (*it != NULL) {
|
||||
delete* it;
|
||||
*it = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
for (std::vector<OptionsGroup*>::iterator it = optionPanes.begin(); it != optionPanes.end(); ++it) {
|
||||
if (*it != NULL) {
|
||||
delete* it;
|
||||
*it = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
categoryButtons.clear();
|
||||
}
|
||||
|
||||
void OptionsScreen::init() {
|
||||
bHeader = new Touch::THeader(0, "Options");
|
||||
|
||||
btnClose = new ImageButton(1, "");
|
||||
|
||||
ImageDef def;
|
||||
def.name = "gui/touchgui.png";
|
||||
def.width = 34;
|
||||
def.height = 26;
|
||||
|
||||
def.setSrc(IntRectangle(150, 0, (int)def.width, (int)def.height));
|
||||
btnClose->setImageDef(def, true);
|
||||
|
||||
categoryButtons.push_back(new Touch::TButton(2, "General"));
|
||||
categoryButtons.push_back(new Touch::TButton(3, "Game"));
|
||||
categoryButtons.push_back(new Touch::TButton(4, "Controls"));
|
||||
categoryButtons.push_back(new Touch::TButton(5, "Graphics"));
|
||||
categoryButtons.push_back(new Touch::TButton(6, "Tweaks"));
|
||||
|
||||
btnCredits = new Touch::TButton(11, "Credits");
|
||||
|
||||
buttons.push_back(bHeader);
|
||||
buttons.push_back(btnClose);
|
||||
buttons.push_back(btnCredits);
|
||||
|
||||
for (std::vector<Touch::TButton*>::iterator it = categoryButtons.begin(); it != categoryButtons.end(); ++it) {
|
||||
buttons.push_back(*it);
|
||||
tabButtons.push_back(*it);
|
||||
}
|
||||
|
||||
generateOptionScreens();
|
||||
// start with first category selected
|
||||
selectCategory(0);
|
||||
}
|
||||
|
||||
void OptionsScreen::setupPositions() {
|
||||
int buttonHeight = btnClose->height;
|
||||
|
||||
btnClose->x = width - btnClose->width;
|
||||
btnClose->y = 0;
|
||||
|
||||
int offsetNum = 1;
|
||||
|
||||
for (std::vector<Touch::TButton*>::iterator it = categoryButtons.begin(); it != categoryButtons.end(); ++it) {
|
||||
|
||||
(*it)->x = 0;
|
||||
(*it)->y = offsetNum * buttonHeight;
|
||||
(*it)->selected = false;
|
||||
|
||||
offsetNum++;
|
||||
}
|
||||
|
||||
bHeader->x = 0;
|
||||
bHeader->y = 0;
|
||||
bHeader->width = width - btnClose->width;
|
||||
bHeader->height = btnClose->height;
|
||||
|
||||
// Credits button (bottom-right)
|
||||
if (btnCredits != NULL) {
|
||||
btnCredits->x = width - btnCredits->width;
|
||||
btnCredits->y = height - btnCredits->height;
|
||||
}
|
||||
|
||||
for (std::vector<OptionsGroup*>::iterator it = optionPanes.begin(); it != optionPanes.end(); ++it) {
|
||||
|
||||
if (categoryButtons.size() > 0 && categoryButtons[0] != NULL) {
|
||||
|
||||
(*it)->x = categoryButtons[0]->width;
|
||||
(*it)->y = bHeader->height;
|
||||
(*it)->width = width - categoryButtons[0]->width;
|
||||
|
||||
(*it)->setupPositions();
|
||||
}
|
||||
}
|
||||
|
||||
// don't override user selection on resize
|
||||
}
|
||||
|
||||
|
||||
void OptionsScreen::render(int xm, int ym, float a) {
|
||||
renderBackground();
|
||||
|
||||
int xmm = xm * width / minecraft->width;
|
||||
int ymm = ym * height / minecraft->height - 1;
|
||||
|
||||
if (currentOptionsGroup != NULL)
|
||||
currentOptionsGroup->render(minecraft, xmm, ymm);
|
||||
|
||||
super::render(xm, ym, a);
|
||||
}
|
||||
|
||||
void OptionsScreen::removed() {
|
||||
}
|
||||
|
||||
void OptionsScreen::buttonClicked(Button* button) {
|
||||
if (button == btnClose) {
|
||||
minecraft->options.save();
|
||||
if (minecraft->screen != NULL) {
|
||||
minecraft->setScreen(NULL);
|
||||
} else {
|
||||
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||
}
|
||||
}
|
||||
else if (button->id > 1 && button->id < 7) {
|
||||
int categoryButton = button->id - categoryButtons[0]->id;
|
||||
selectCategory(categoryButton);
|
||||
}
|
||||
else if (button == btnCredits) {
|
||||
minecraft->setScreen(new CreditsScreen());
|
||||
}
|
||||
}
|
||||
|
||||
void OptionsScreen::selectCategory(int index) {
|
||||
int currentIndex = 0;
|
||||
|
||||
for (std::vector<Touch::TButton*>::iterator it = categoryButtons.begin(); it != categoryButtons.end(); ++it) {
|
||||
|
||||
if (index == currentIndex)
|
||||
(*it)->selected = true;
|
||||
else
|
||||
(*it)->selected = false;
|
||||
|
||||
currentIndex++;
|
||||
}
|
||||
|
||||
if (index < (int)optionPanes.size())
|
||||
currentOptionsGroup = optionPanes[index];
|
||||
}
|
||||
|
||||
void OptionsScreen::generateOptionScreens() {
|
||||
// how the fuck it works
|
||||
|
||||
optionPanes.push_back(new OptionsGroup("options.group.general"));
|
||||
optionPanes.push_back(new OptionsGroup("options.group.game"));
|
||||
optionPanes.push_back(new OptionsGroup("options.group.controls"));
|
||||
optionPanes.push_back(new OptionsGroup("options.group.graphics"));
|
||||
optionPanes.push_back(new OptionsGroup("options.group.tweaks"));
|
||||
|
||||
// General Pane
|
||||
optionPanes[0]->addOptionItem(OPTIONS_USERNAME, minecraft)
|
||||
.addOptionItem(OPTIONS_SENSITIVITY, minecraft);
|
||||
|
||||
// Game Pane
|
||||
optionPanes[1]->addOptionItem(OPTIONS_DIFFICULTY, minecraft)
|
||||
.addOptionItem(OPTIONS_SERVER_VISIBLE, minecraft)
|
||||
.addOptionItem(OPTIONS_THIRD_PERSON_VIEW, minecraft)
|
||||
.addOptionItem(OPTIONS_GUI_SCALE, minecraft)
|
||||
.addOptionItem(OPTIONS_SENSITIVITY, minecraft)
|
||||
.addOptionItem(OPTIONS_MUSIC_VOLUME, minecraft)
|
||||
.addOptionItem(OPTIONS_SOUND_VOLUME, minecraft)
|
||||
.addOptionItem(OPTIONS_SMOOTH_CAMERA, minecraft)
|
||||
.addOptionItem(OPTIONS_DESTROY_VIBRATION, minecraft)
|
||||
.addOptionItem(OPTIONS_IS_LEFT_HANDED, minecraft);
|
||||
|
||||
// // Controls Pane
|
||||
optionPanes[2]->addOptionItem(OPTIONS_INVERT_Y_MOUSE, minecraft)
|
||||
.addOptionItem(OPTIONS_USE_TOUCHSCREEN, minecraft)
|
||||
.addOptionItem(OPTIONS_AUTOJUMP, minecraft);
|
||||
|
||||
for (int i = OPTIONS_KEY_FORWARD; i <= OPTIONS_KEY_USE; i++) {
|
||||
optionPanes[2]->addOptionItem((OptionId)i, minecraft);
|
||||
}
|
||||
|
||||
// // Graphics Pane
|
||||
optionPanes[3]->addOptionItem(OPTIONS_FANCY_GRAPHICS, minecraft)
|
||||
.addOptionItem(OPTIONS_LIMIT_FRAMERATE, minecraft)
|
||||
.addOptionItem(OPTIONS_VSYNC, minecraft)
|
||||
.addOptionItem(OPTIONS_RENDER_DEBUG, minecraft)
|
||||
.addOptionItem(OPTIONS_ANAGLYPH_3D, minecraft)
|
||||
.addOptionItem(OPTIONS_VIEW_BOBBING, minecraft)
|
||||
.addOptionItem(OPTIONS_AMBIENT_OCCLUSION, minecraft);
|
||||
|
||||
optionPanes[4]->addOptionItem(OPTIONS_ALLOW_SPRINT, minecraft)
|
||||
.addOptionItem(OPTIONS_BAR_ON_TOP, minecraft)
|
||||
.addOptionItem(OPTIONS_RPI_CURSOR, minecraft);
|
||||
}
|
||||
|
||||
void OptionsScreen::mouseClicked(int x, int y, int buttonNum) {
|
||||
if (currentOptionsGroup != NULL)
|
||||
currentOptionsGroup->mouseClicked(minecraft, x, y, buttonNum);
|
||||
|
||||
super::mouseClicked(x, y, buttonNum);
|
||||
}
|
||||
|
||||
void OptionsScreen::mouseReleased(int x, int y, int buttonNum) {
|
||||
if (currentOptionsGroup != NULL)
|
||||
currentOptionsGroup->mouseReleased(minecraft, x, y, buttonNum);
|
||||
|
||||
super::mouseReleased(x, y, buttonNum);
|
||||
}
|
||||
|
||||
void OptionsScreen::keyPressed(int eventKey) {
|
||||
if (currentOptionsGroup != NULL)
|
||||
currentOptionsGroup->keyPressed(minecraft, eventKey);
|
||||
if (eventKey == Keyboard::KEY_ESCAPE)
|
||||
minecraft->options.save();
|
||||
|
||||
super::keyPressed(eventKey);
|
||||
}
|
||||
|
||||
void OptionsScreen::charPressed(char inputChar) {
|
||||
if (currentOptionsGroup != NULL)
|
||||
currentOptionsGroup->charPressed(minecraft, inputChar);
|
||||
|
||||
super::keyPressed(inputChar);
|
||||
}
|
||||
|
||||
void OptionsScreen::tick() {
|
||||
|
||||
if (currentOptionsGroup != NULL)
|
||||
currentOptionsGroup->tick(minecraft);
|
||||
|
||||
super::tick();
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Screen.h"
|
||||
#include "../components/Button.h"
|
||||
#include "../components/OptionsGroup.h"
|
||||
#include "client/gui/Screen.hpp"
|
||||
#include "client/gui/components/Button.hpp"
|
||||
#include "client/gui/components/OptionsGroup.hpp"
|
||||
|
||||
class ImageButton;
|
||||
class OptionsPane;
|
||||
@@ -1,201 +1,201 @@
|
||||
#include "PauseScreen.h"
|
||||
#include "StartMenuScreen.h"
|
||||
#include "../components/ImageButton.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../../util/Mth.h"
|
||||
#include "../../../network/RakNetInstance.h"
|
||||
#include "../../../network/ServerSideNetworkHandler.h"
|
||||
#include "client/Options.h"
|
||||
#include "client/gui/components/Button.h"
|
||||
#include "client/gui/screens/OptionsScreen.h"
|
||||
|
||||
PauseScreen::PauseScreen(bool wasBackPaused)
|
||||
: saveStep(0),
|
||||
visibleTime(0),
|
||||
bContinue(0),
|
||||
bQuit(0),
|
||||
bOptions(0),
|
||||
bQuitAndSaveLocally(0),
|
||||
bServerVisibility(0),
|
||||
// bThirdPerson(0),
|
||||
wasBackPaused(wasBackPaused),
|
||||
// bSound(OPTIONS_SOUND_VOLUME, 1, 0),
|
||||
bThirdPerson(OPTIONS_THIRD_PERSON_VIEW),
|
||||
bHideGui(OPTIONS_HIDEGUI)
|
||||
{
|
||||
ImageDef def;
|
||||
def.setSrc(IntRectangle(160, 144, 39, 31));
|
||||
def.name = "gui/touchgui.png";
|
||||
IntRectangle& defSrc = *def.getSrc();
|
||||
|
||||
def.width = defSrc.w * 0.666667f;
|
||||
def.height = defSrc.h * 0.666667f;
|
||||
|
||||
// bSound.setImageDef(def, true);
|
||||
defSrc.y += defSrc.h;
|
||||
bThirdPerson.setImageDef(def, true);
|
||||
bHideGui.setImageDef(def, true);
|
||||
//void setImageDef(ImageDef& imageDef, bool setButtonSize);
|
||||
}
|
||||
|
||||
PauseScreen::~PauseScreen() {
|
||||
delete bContinue;
|
||||
delete bQuit;
|
||||
delete bQuitAndSaveLocally;
|
||||
delete bServerVisibility;
|
||||
delete bOptions;
|
||||
// delete bThirdPerson;
|
||||
}
|
||||
|
||||
void PauseScreen::init() {
|
||||
if (/* minecraft->useTouchscreen() */ true) {
|
||||
bContinue = new Touch::TButton(1, "Back to game");
|
||||
bOptions = new Touch::TButton(5, "Options");
|
||||
bQuit = new Touch::TButton(2, "Quit to title");
|
||||
bQuitAndSaveLocally = new Touch::TButton(3, "Quit and copy map");
|
||||
bServerVisibility = new Touch::TButton(4, "");
|
||||
// bThirdPerson = new Touch::TButton(5, "Toggle 3:rd person view");
|
||||
} else {
|
||||
bContinue = new Button(1, "Back to game");
|
||||
bOptions = new Button(5, "Options");
|
||||
bQuit = new Button(2, "Quit to title");
|
||||
bQuitAndSaveLocally = new Button(3, "Quit and copy map");
|
||||
bServerVisibility = new Button(4, "");
|
||||
// bThirdPerson = new Button(5, "Toggle 3:rd person view");
|
||||
}
|
||||
|
||||
buttons.push_back(bContinue);
|
||||
buttons.push_back(bQuit);
|
||||
buttons.push_back(bOptions);
|
||||
// bSound.updateImage(&minecraft->options);
|
||||
bThirdPerson.updateImage(&minecraft->options);
|
||||
bHideGui.updateImage(&minecraft->options);
|
||||
// buttons.push_back(&bSound);
|
||||
buttons.push_back(&bThirdPerson);
|
||||
//buttons.push_back(&bHideGui);
|
||||
|
||||
// If Back wasn't pressed, set up additional items (more than Quit to menu
|
||||
// and Back to game) here
|
||||
|
||||
#if !defined(APPLE_DEMO_PROMOTION) && !defined(RPI)
|
||||
if (true || !wasBackPaused) {
|
||||
if (minecraft->raknetInstance) {
|
||||
if (minecraft->raknetInstance->isServer()) {
|
||||
updateServerVisibilityText();
|
||||
buttons.push_back(bServerVisibility);
|
||||
}
|
||||
else {
|
||||
#if !defined(DEMO_MODE)
|
||||
buttons.push_back(bQuitAndSaveLocally);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// buttons.push_back(bThirdPerson);
|
||||
|
||||
for (unsigned int i = 0; i < buttons.size(); ++i) {
|
||||
// if (buttons[i] == &bSound) continue;
|
||||
if (buttons[i] == &bThirdPerson) continue;
|
||||
if (buttons[i] == &bHideGui) continue;
|
||||
tabButtons.push_back(buttons[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void PauseScreen::setupPositions() {
|
||||
saveStep = 0;
|
||||
int yBase = 16;
|
||||
|
||||
bContinue->width = bOptions->width = bQuit->width = /*bThirdPerson->w =*/ 160;
|
||||
bQuitAndSaveLocally->width = bServerVisibility->width = 160;
|
||||
|
||||
bContinue->x = (width - bContinue->width) / 2;
|
||||
bContinue->y = yBase + 32 * 1;
|
||||
|
||||
bOptions->x = (width - bOptions->width) / 2;
|
||||
bOptions->y = yBase + 32 * 2;
|
||||
|
||||
bQuit->x = (width - bQuit->width) / 2;
|
||||
bQuit->y = yBase + 32 * 3;
|
||||
|
||||
#if APPLE_DEMO_PROMOTION
|
||||
bQuit->y += 16;
|
||||
#endif
|
||||
|
||||
bQuitAndSaveLocally->x = bServerVisibility->x = (width - bQuitAndSaveLocally->width) / 2;
|
||||
bQuitAndSaveLocally->y = bServerVisibility->y = yBase + 32 * 4;
|
||||
|
||||
// bSound.y = bThirdPerson.y = 8;
|
||||
// bSound.x = 4;
|
||||
// bThirdPerson.x = bSound.x + 4 + bSound.width;
|
||||
// bHideGui.x = bThirdPerson.x + 4 + bThirdPerson.width;
|
||||
|
||||
//bThirdPerson->x = (width - bThirdPerson->w) / 2;
|
||||
//bThirdPerson->y = yBase + 32 * 4;
|
||||
}
|
||||
|
||||
void PauseScreen::tick() {
|
||||
super::tick();
|
||||
visibleTime++;
|
||||
}
|
||||
|
||||
void PauseScreen::render(int xm, int ym, float a) {
|
||||
renderBackground();
|
||||
|
||||
//bool isSaving = !minecraft->level.pauseSave(saveStep++);
|
||||
//if (isSaving || visibleTime < 20) {
|
||||
// float col = ((visibleTime % 10) + a) / 10.0f;
|
||||
// col = Mth::sin(col * Mth::PI * 2) * 0.2f + 0.8f;
|
||||
// int br = (int) (255 * col);
|
||||
|
||||
// drawString(font, "Saving level..", 8, height - 16, br << 16 | br << 8 | br);
|
||||
//}
|
||||
|
||||
drawCenteredString(font, "Game menu", width / 2, 24, 0xffffff);
|
||||
|
||||
super::render(xm, ym, a);
|
||||
}
|
||||
|
||||
void PauseScreen::buttonClicked(Button* button) {
|
||||
if (button->id == bContinue->id) {
|
||||
minecraft->setScreen(NULL);
|
||||
//minecraft->grabMouse();
|
||||
}
|
||||
if (button->id == bQuit->id) {
|
||||
minecraft->leaveGame();
|
||||
}
|
||||
if (button->id == bQuitAndSaveLocally->id) {
|
||||
minecraft->leaveGame(true);
|
||||
}
|
||||
if (button->id == bOptions->id) {
|
||||
minecraft->setScreen(new OptionsScreen());
|
||||
}
|
||||
if (button->id == bServerVisibility->id) {
|
||||
if (minecraft->raknetInstance && minecraft->netCallback && minecraft->raknetInstance->isServer()) {
|
||||
ServerSideNetworkHandler* ss = (ServerSideNetworkHandler*) minecraft->netCallback;
|
||||
bool allows = !ss->allowsIncomingConnections();
|
||||
ss->allowIncomingConnections(allows);
|
||||
|
||||
updateServerVisibilityText();
|
||||
}
|
||||
}
|
||||
|
||||
if (button->id == OptionButton::ButtonId) {
|
||||
((OptionButton*)button)->toggle(&minecraft->options);
|
||||
}
|
||||
|
||||
//if (button->id == bThirdPerson->id) {
|
||||
// minecraft->options.thirdPersonView = !minecraft->options.thirdPersonView;
|
||||
//}
|
||||
}
|
||||
|
||||
void PauseScreen::updateServerVisibilityText()
|
||||
{
|
||||
if (!minecraft->raknetInstance || !minecraft->raknetInstance->isServer())
|
||||
return;
|
||||
|
||||
ServerSideNetworkHandler* ss = (ServerSideNetworkHandler*) minecraft->netCallback;
|
||||
bServerVisibility->msg = ss->allowsIncomingConnections()?
|
||||
"Server is visible"
|
||||
: "Server is invisible";
|
||||
}
|
||||
#include "PauseScreen.hpp"
|
||||
#include "StartMenuScreen.hpp"
|
||||
#include "client/gui/components/ImageButton.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "util/Mth.hpp"
|
||||
#include "network/RakNetInstance.hpp"
|
||||
#include "network/ServerSideNetworkHandler.hpp"
|
||||
#include "client/Options.hpp"
|
||||
#include "client/gui/components/Button.hpp"
|
||||
#include "client/gui/screens/OptionsScreen.hpp"
|
||||
|
||||
PauseScreen::PauseScreen(bool wasBackPaused)
|
||||
: saveStep(0),
|
||||
visibleTime(0),
|
||||
bContinue(0),
|
||||
bQuit(0),
|
||||
bOptions(0),
|
||||
bQuitAndSaveLocally(0),
|
||||
bServerVisibility(0),
|
||||
// bThirdPerson(0),
|
||||
wasBackPaused(wasBackPaused),
|
||||
// bSound(OPTIONS_SOUND_VOLUME, 1, 0),
|
||||
bThirdPerson(OPTIONS_THIRD_PERSON_VIEW),
|
||||
bHideGui(OPTIONS_HIDEGUI)
|
||||
{
|
||||
ImageDef def;
|
||||
def.setSrc(IntRectangle(160, 144, 39, 31));
|
||||
def.name = "gui/touchgui.png";
|
||||
IntRectangle& defSrc = *def.getSrc();
|
||||
|
||||
def.width = defSrc.w * 0.666667f;
|
||||
def.height = defSrc.h * 0.666667f;
|
||||
|
||||
// bSound.setImageDef(def, true);
|
||||
defSrc.y += defSrc.h;
|
||||
bThirdPerson.setImageDef(def, true);
|
||||
bHideGui.setImageDef(def, true);
|
||||
//void setImageDef(ImageDef& imageDef, bool setButtonSize);
|
||||
}
|
||||
|
||||
PauseScreen::~PauseScreen() {
|
||||
delete bContinue;
|
||||
delete bQuit;
|
||||
delete bQuitAndSaveLocally;
|
||||
delete bServerVisibility;
|
||||
delete bOptions;
|
||||
// delete bThirdPerson;
|
||||
}
|
||||
|
||||
void PauseScreen::init() {
|
||||
if (/* minecraft->useTouchscreen() */ true) {
|
||||
bContinue = new Touch::TButton(1, "Back to game");
|
||||
bOptions = new Touch::TButton(5, "Options");
|
||||
bQuit = new Touch::TButton(2, "Quit to title");
|
||||
bQuitAndSaveLocally = new Touch::TButton(3, "Quit and copy map");
|
||||
bServerVisibility = new Touch::TButton(4, "");
|
||||
// bThirdPerson = new Touch::TButton(5, "Toggle 3:rd person view");
|
||||
} else {
|
||||
bContinue = new Button(1, "Back to game");
|
||||
bOptions = new Button(5, "Options");
|
||||
bQuit = new Button(2, "Quit to title");
|
||||
bQuitAndSaveLocally = new Button(3, "Quit and copy map");
|
||||
bServerVisibility = new Button(4, "");
|
||||
// bThirdPerson = new Button(5, "Toggle 3:rd person view");
|
||||
}
|
||||
|
||||
buttons.push_back(bContinue);
|
||||
buttons.push_back(bQuit);
|
||||
buttons.push_back(bOptions);
|
||||
// bSound.updateImage(&minecraft->options);
|
||||
bThirdPerson.updateImage(&minecraft->options);
|
||||
bHideGui.updateImage(&minecraft->options);
|
||||
// buttons.push_back(&bSound);
|
||||
buttons.push_back(&bThirdPerson);
|
||||
//buttons.push_back(&bHideGui);
|
||||
|
||||
// If Back wasn't pressed, set up additional items (more than Quit to menu
|
||||
// and Back to game) here
|
||||
|
||||
#if !defined(APPLE_DEMO_PROMOTION) && !defined(RPI)
|
||||
if (true || !wasBackPaused) {
|
||||
if (minecraft->raknetInstance) {
|
||||
if (minecraft->raknetInstance->isServer()) {
|
||||
updateServerVisibilityText();
|
||||
buttons.push_back(bServerVisibility);
|
||||
}
|
||||
else {
|
||||
#if !defined(DEMO_MODE)
|
||||
buttons.push_back(bQuitAndSaveLocally);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// buttons.push_back(bThirdPerson);
|
||||
|
||||
for (unsigned int i = 0; i < buttons.size(); ++i) {
|
||||
// if (buttons[i] == &bSound) continue;
|
||||
if (buttons[i] == &bThirdPerson) continue;
|
||||
if (buttons[i] == &bHideGui) continue;
|
||||
tabButtons.push_back(buttons[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void PauseScreen::setupPositions() {
|
||||
saveStep = 0;
|
||||
int yBase = 16;
|
||||
|
||||
bContinue->width = bOptions->width = bQuit->width = /*bThirdPerson->w =*/ 160;
|
||||
bQuitAndSaveLocally->width = bServerVisibility->width = 160;
|
||||
|
||||
bContinue->x = (width - bContinue->width) / 2;
|
||||
bContinue->y = yBase + 32 * 1;
|
||||
|
||||
bOptions->x = (width - bOptions->width) / 2;
|
||||
bOptions->y = yBase + 32 * 2;
|
||||
|
||||
bQuit->x = (width - bQuit->width) / 2;
|
||||
bQuit->y = yBase + 32 * 3;
|
||||
|
||||
#if APPLE_DEMO_PROMOTION
|
||||
bQuit->y += 16;
|
||||
#endif
|
||||
|
||||
bQuitAndSaveLocally->x = bServerVisibility->x = (width - bQuitAndSaveLocally->width) / 2;
|
||||
bQuitAndSaveLocally->y = bServerVisibility->y = yBase + 32 * 4;
|
||||
|
||||
// bSound.y = bThirdPerson.y = 8;
|
||||
// bSound.x = 4;
|
||||
// bThirdPerson.x = bSound.x + 4 + bSound.width;
|
||||
// bHideGui.x = bThirdPerson.x + 4 + bThirdPerson.width;
|
||||
|
||||
//bThirdPerson->x = (width - bThirdPerson->w) / 2;
|
||||
//bThirdPerson->y = yBase + 32 * 4;
|
||||
}
|
||||
|
||||
void PauseScreen::tick() {
|
||||
super::tick();
|
||||
visibleTime++;
|
||||
}
|
||||
|
||||
void PauseScreen::render(int xm, int ym, float a) {
|
||||
renderBackground();
|
||||
|
||||
//bool isSaving = !minecraft->level.pauseSave(saveStep++);
|
||||
//if (isSaving || visibleTime < 20) {
|
||||
// float col = ((visibleTime % 10) + a) / 10.0f;
|
||||
// col = Mth::sin(col * Mth::PI * 2) * 0.2f + 0.8f;
|
||||
// int br = (int) (255 * col);
|
||||
|
||||
// drawString(font, "Saving level..", 8, height - 16, br << 16 | br << 8 | br);
|
||||
//}
|
||||
|
||||
drawCenteredString(font, "Game menu", width / 2, 24, 0xffffff);
|
||||
|
||||
super::render(xm, ym, a);
|
||||
}
|
||||
|
||||
void PauseScreen::buttonClicked(Button* button) {
|
||||
if (button->id == bContinue->id) {
|
||||
minecraft->setScreen(NULL);
|
||||
//minecraft->grabMouse();
|
||||
}
|
||||
if (button->id == bQuit->id) {
|
||||
minecraft->leaveGame();
|
||||
}
|
||||
if (button->id == bQuitAndSaveLocally->id) {
|
||||
minecraft->leaveGame(true);
|
||||
}
|
||||
if (button->id == bOptions->id) {
|
||||
minecraft->setScreen(new OptionsScreen());
|
||||
}
|
||||
if (button->id == bServerVisibility->id) {
|
||||
if (minecraft->raknetInstance && minecraft->netCallback && minecraft->raknetInstance->isServer()) {
|
||||
ServerSideNetworkHandler* ss = (ServerSideNetworkHandler*) minecraft->netCallback;
|
||||
bool allows = !ss->allowsIncomingConnections();
|
||||
ss->allowIncomingConnections(allows);
|
||||
|
||||
updateServerVisibilityText();
|
||||
}
|
||||
}
|
||||
|
||||
if (button->id == OptionButton::ButtonId) {
|
||||
((OptionButton*)button)->toggle(&minecraft->options);
|
||||
}
|
||||
|
||||
//if (button->id == bThirdPerson->id) {
|
||||
// minecraft->options.thirdPersonView = !minecraft->options.thirdPersonView;
|
||||
//}
|
||||
}
|
||||
|
||||
void PauseScreen::updateServerVisibilityText()
|
||||
{
|
||||
if (!minecraft->raknetInstance || !minecraft->raknetInstance->isServer())
|
||||
return;
|
||||
|
||||
ServerSideNetworkHandler* ss = (ServerSideNetworkHandler*) minecraft->netCallback;
|
||||
bServerVisibility->msg = ss->allowsIncomingConnections()?
|
||||
"Server is visible"
|
||||
: "Server is invisible";
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
//package net.minecraft.client.gui;
|
||||
|
||||
#include "../Screen.h"
|
||||
#include "../components/ImageButton.h"
|
||||
#include "client/gui/Screen.hpp"
|
||||
#include "client/gui/components/ImageButton.hpp"
|
||||
|
||||
class Button;
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Screen.h"
|
||||
#include "client/gui/Screen.hpp"
|
||||
|
||||
#include "../../renderer/GameRenderer.h"
|
||||
#include "../../renderer/entity/ItemRenderer.h"
|
||||
#include "../../../world/item/ItemInstance.h"
|
||||
#include "../../../world/level/tile/Tile.h"
|
||||
#include "client/renderer/GameRenderer.hpp"
|
||||
#include "client/renderer/entity/ItemRenderer.hpp"
|
||||
#include "world/item/ItemInstance.hpp"
|
||||
#include "world/level/tile/Tile.hpp"
|
||||
|
||||
#include "../../../world/entity/player/Inventory.h"
|
||||
#include "../../renderer/Tesselator.h"
|
||||
#include "../../../world/item/crafting/Recipes.h"
|
||||
#include "../../../world/item/crafting/FurnaceRecipes.h"
|
||||
#include "../../../world/level/tile/LeafTile.h"
|
||||
#include "../../renderer/TileRenderer.h"
|
||||
#include "world/entity/player/Inventory.hpp"
|
||||
#include "client/renderer/Tesselator.hpp"
|
||||
#include "world/item/crafting/Recipes.hpp"
|
||||
#include "world/item/crafting/FurnaceRecipes.hpp"
|
||||
#include "world/level/tile/LeafTile.hpp"
|
||||
#include "client/renderer/TileRenderer.hpp"
|
||||
|
||||
class PrerenderTilesScreen: public Screen
|
||||
{
|
||||
@@ -1,99 +1,99 @@
|
||||
#include "ProgressScreen.h"
|
||||
#include "DisconnectionScreen.h"
|
||||
#include "../Gui.h"
|
||||
#include "../Font.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../renderer/Tesselator.h"
|
||||
#include "../../../SharedConstants.h"
|
||||
#include "../../renderer/Textures.h"
|
||||
|
||||
ProgressScreen::ProgressScreen()
|
||||
: ticks(0)
|
||||
{
|
||||
}
|
||||
|
||||
void ProgressScreen::render( int xm, int ym, float a )
|
||||
{
|
||||
if (minecraft->isLevelGenerated()) {
|
||||
minecraft->setScreen(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
renderBackground();
|
||||
|
||||
minecraft->textures->loadAndBindTexture("gui/background.png");
|
||||
|
||||
const float s = 32;
|
||||
t.begin();
|
||||
t.color(0x404040);
|
||||
t.vertexUV(0, (float)height, 0, 0, height / s);
|
||||
t.vertexUV((float)width, (float)height, 0, width / s, height / s);
|
||||
t.vertexUV((float)width, 0, 0, width / s, 0);
|
||||
t.vertexUV(0, 0, 0, 0, 0);
|
||||
t.draw();
|
||||
|
||||
int i = minecraft->progressStagePercentage;
|
||||
|
||||
if (i >= 0) {
|
||||
int w = 100;
|
||||
int h = 2;
|
||||
int x = width / 2 - w / 2;
|
||||
int y = height / 2 + 16;
|
||||
|
||||
//printf("%d, %d - %d, %d\n", x, y, x + w, y + h);
|
||||
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
t.begin();
|
||||
t.color(0x808080);
|
||||
t.vertex((float)x, (float)y, 0);
|
||||
t.vertex((float)x, (float)(y + h), 0);
|
||||
t.vertex((float)(x + w), (float)(y + h), 0);
|
||||
t.vertex((float)(x + w), (float)y, 0);
|
||||
|
||||
t.color(0x80ff80);
|
||||
t.vertex((float)x, (float)y, 0);
|
||||
t.vertex((float)x, (float)(y + h), 0);
|
||||
t.vertex((float)(x + i), (float)(y + h), 0);
|
||||
t.vertex((float)(x + i), (float)y, 0);
|
||||
t.draw();
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
glEnable2(GL_BLEND);
|
||||
|
||||
const char* title = "Generating world";
|
||||
minecraft->font->drawShadow(title, (float)((width - minecraft->font->width(title)) / 2), (float)(height / 2 - 4 - 16), 0xffffff);
|
||||
|
||||
const char* status = minecraft->getProgressMessage();
|
||||
const int progressWidth = minecraft->font->width(status);
|
||||
const int progressLeft = (width - progressWidth) / 2;
|
||||
const int progressY = height / 2 - 4 + 8;
|
||||
minecraft->font->drawShadow(status, (float)progressLeft, (float)progressY, 0xffffff);
|
||||
|
||||
#if APPLE_DEMO_PROMOTION
|
||||
drawCenteredString(minecraft->font, "This demonstration version", width/2, progressY + 36, 0xffffff);
|
||||
drawCenteredString(minecraft->font, "does not allow saving games", width/2, progressY + 46, 0xffffff);
|
||||
#endif
|
||||
|
||||
// If we're locating the server, show our famous spinner!
|
||||
bool isLocating = (minecraft->getProgressStatusId() == 0);
|
||||
if (isLocating) {
|
||||
const int spinnerX = progressLeft + progressWidth + 6;
|
||||
static const char* spinnerTexts[] = {"-", "\\", "|", "/"};
|
||||
int n = ((int)(5.5f * getTimeS()) % 4);
|
||||
drawCenteredString(minecraft->font, spinnerTexts[n], spinnerX, progressY, 0xffffffff);
|
||||
}
|
||||
|
||||
glDisable2(GL_BLEND);
|
||||
sleepMs(50);
|
||||
}
|
||||
|
||||
bool ProgressScreen::isInGameScreen() { return false; }
|
||||
|
||||
void ProgressScreen::tick() {
|
||||
// After 10 seconds of not connecting -> write an error message and go back
|
||||
if (++ticks == 10 * SharedConstants::TicksPerSecond && minecraft->getProgressStatusId() == 0) {
|
||||
minecraft->setScreen( new DisconnectionScreen("Could not connect to server. Try again.") );
|
||||
}
|
||||
}
|
||||
#include "ProgressScreen.hpp"
|
||||
#include "DisconnectionScreen.hpp"
|
||||
#include "client/gui/Gui.hpp"
|
||||
#include "client/gui/Font.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "client/renderer/Tesselator.hpp"
|
||||
#include "SharedConstants.hpp"
|
||||
#include "client/renderer/Textures.hpp"
|
||||
|
||||
ProgressScreen::ProgressScreen()
|
||||
: ticks(0)
|
||||
{
|
||||
}
|
||||
|
||||
void ProgressScreen::render( int xm, int ym, float a )
|
||||
{
|
||||
if (minecraft->isLevelGenerated()) {
|
||||
minecraft->setScreen(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
renderBackground();
|
||||
|
||||
minecraft->textures->loadAndBindTexture("gui/background.png");
|
||||
|
||||
const float s = 32;
|
||||
t.begin();
|
||||
t.color(0x404040);
|
||||
t.vertexUV(0, (float)height, 0, 0, height / s);
|
||||
t.vertexUV((float)width, (float)height, 0, width / s, height / s);
|
||||
t.vertexUV((float)width, 0, 0, width / s, 0);
|
||||
t.vertexUV(0, 0, 0, 0, 0);
|
||||
t.draw();
|
||||
|
||||
int i = minecraft->progressStagePercentage;
|
||||
|
||||
if (i >= 0) {
|
||||
int w = 100;
|
||||
int h = 2;
|
||||
int x = width / 2 - w / 2;
|
||||
int y = height / 2 + 16;
|
||||
|
||||
//printf("%d, %d - %d, %d\n", x, y, x + w, y + h);
|
||||
|
||||
glDisable2(GL_TEXTURE_2D);
|
||||
t.begin();
|
||||
t.color(0x808080);
|
||||
t.vertex((float)x, (float)y, 0);
|
||||
t.vertex((float)x, (float)(y + h), 0);
|
||||
t.vertex((float)(x + w), (float)(y + h), 0);
|
||||
t.vertex((float)(x + w), (float)y, 0);
|
||||
|
||||
t.color(0x80ff80);
|
||||
t.vertex((float)x, (float)y, 0);
|
||||
t.vertex((float)x, (float)(y + h), 0);
|
||||
t.vertex((float)(x + i), (float)(y + h), 0);
|
||||
t.vertex((float)(x + i), (float)y, 0);
|
||||
t.draw();
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
glEnable2(GL_BLEND);
|
||||
|
||||
const char* title = "Generating world";
|
||||
minecraft->font->drawShadow(title, (float)((width - minecraft->font->width(title)) / 2), (float)(height / 2 - 4 - 16), 0xffffff);
|
||||
|
||||
const char* status = minecraft->getProgressMessage();
|
||||
const int progressWidth = minecraft->font->width(status);
|
||||
const int progressLeft = (width - progressWidth) / 2;
|
||||
const int progressY = height / 2 - 4 + 8;
|
||||
minecraft->font->drawShadow(status, (float)progressLeft, (float)progressY, 0xffffff);
|
||||
|
||||
#if APPLE_DEMO_PROMOTION
|
||||
drawCenteredString(minecraft->font, "This demonstration version", width/2, progressY + 36, 0xffffff);
|
||||
drawCenteredString(minecraft->font, "does not allow saving games", width/2, progressY + 46, 0xffffff);
|
||||
#endif
|
||||
|
||||
// If we're locating the server, show our famous spinner!
|
||||
bool isLocating = (minecraft->getProgressStatusId() == 0);
|
||||
if (isLocating) {
|
||||
const int spinnerX = progressLeft + progressWidth + 6;
|
||||
static const char* spinnerTexts[] = {"-", "\\", "|", "/"};
|
||||
int n = ((int)(5.5f * getTimeS()) % 4);
|
||||
drawCenteredString(minecraft->font, spinnerTexts[n], spinnerX, progressY, 0xffffffff);
|
||||
}
|
||||
|
||||
glDisable2(GL_BLEND);
|
||||
sleepMs(50);
|
||||
}
|
||||
|
||||
bool ProgressScreen::isInGameScreen() { return false; }
|
||||
|
||||
void ProgressScreen::tick() {
|
||||
// After 10 seconds of not connecting -> write an error message and go back
|
||||
if (++ticks == 10 * SharedConstants::TicksPerSecond && minecraft->getProgressStatusId() == 0) {
|
||||
minecraft->setScreen( new DisconnectionScreen("Could not connect to server. Try again.") );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Screen.h"
|
||||
#include "client/gui/Screen.hpp"
|
||||
|
||||
class ProgressScreen: public Screen
|
||||
{
|
||||
@@ -1,64 +1,64 @@
|
||||
#include "ScreenChooser.h"
|
||||
#include "StartMenuScreen.h"
|
||||
#include "MinecraftClient.h"
|
||||
#include "SelectWorldScreen.h"
|
||||
#include "JoinGameScreen.h"
|
||||
#include "PauseScreen.h"
|
||||
#include "RenameMPLevelScreen.h"
|
||||
#include "ConsoleScreen.h"
|
||||
#include "IngameBlockSelectionScreen.h"
|
||||
#include "JoinByIPScreen.h"
|
||||
#include "touch/TouchStartMenuScreen.h"
|
||||
#include "touch/TouchSelectWorldScreen.h"
|
||||
#include "touch/TouchJoinGameScreen.h"
|
||||
#include "touch/TouchIngameBlockSelectionScreen.h"
|
||||
|
||||
#include "../../Minecraft.h"
|
||||
|
||||
#include <client/gui/screens/UsernameScreen.h>
|
||||
|
||||
Screen* ScreenChooser::createScreen( ScreenId id )
|
||||
{
|
||||
Screen* screen = NULL;
|
||||
|
||||
// :sob:
|
||||
if (/* _mc->useTouchscreen() */ true) {
|
||||
switch (id) {
|
||||
case SCREEN_STARTMENU: screen = new Touch::StartMenuScreen(); break;
|
||||
case SCREEN_SELECTWORLD: screen = new Touch::SelectWorldScreen();break;
|
||||
case SCREEN_JOINGAME: screen = new Touch::JoinGameScreen(); break;
|
||||
case SCREEN_PAUSE: screen = new PauseScreen(false); break;
|
||||
case SCREEN_PAUSEPREV: screen = new PauseScreen(true); break;
|
||||
case SCREEN_BLOCKSELECTION: screen = new Touch::IngameBlockSelectionScreen(); break;
|
||||
case SCREEN_JOINBYIP: screen = new JoinByIPScreen(); break;
|
||||
case SCREEN_CONSOLE: screen = new ConsoleScreen(); break;
|
||||
case SCREEN_NONE:
|
||||
default:
|
||||
// Do nothing
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (id) {
|
||||
case SCREEN_STARTMENU: screen = new StartMenuScreen(); break;
|
||||
case SCREEN_SELECTWORLD: screen = new SelectWorldScreen();break;
|
||||
case SCREEN_JOINGAME: screen = new JoinGameScreen(); break;
|
||||
case SCREEN_PAUSE: screen = new PauseScreen(false); break;
|
||||
case SCREEN_PAUSEPREV: screen = new PauseScreen(true); break;
|
||||
case SCREEN_BLOCKSELECTION: screen = new IngameBlockSelectionScreen(); break;
|
||||
case SCREEN_JOINBYIP: screen = new JoinByIPScreen(); break;
|
||||
case SCREEN_CONSOLE: screen = new ConsoleScreen(); break;
|
||||
case SCREEN_NONE:
|
||||
default:
|
||||
// Do nothing
|
||||
break;
|
||||
}
|
||||
}
|
||||
return screen;
|
||||
}
|
||||
|
||||
Screen* ScreenChooser::setScreen(ScreenId id)
|
||||
{
|
||||
Screen* screen = createScreen(id);
|
||||
_mc.setScreen(screen);
|
||||
return screen;
|
||||
}
|
||||
#include "ScreenChooser.hpp"
|
||||
#include "StartMenuScreen.hpp"
|
||||
#include "MinecraftClient.hpp"
|
||||
#include "SelectWorldScreen.hpp"
|
||||
#include "JoinGameScreen.hpp"
|
||||
#include "PauseScreen.hpp"
|
||||
#include "RenameMPLevelScreen.hpp"
|
||||
#include "ConsoleScreen.hpp"
|
||||
#include "IngameBlockSelectionScreen.hpp"
|
||||
#include "JoinByIPScreen.hpp"
|
||||
#include "touch/TouchStartMenuScreen.hpp"
|
||||
#include "touch/TouchSelectWorldScreen.hpp"
|
||||
#include "touch/TouchJoinGameScreen.hpp"
|
||||
#include "touch/TouchIngameBlockSelectionScreen.hpp"
|
||||
|
||||
#include "client/Minecraft.hpp"
|
||||
|
||||
#include <client/gui/screens/UsernameScreen.hpp>
|
||||
|
||||
Screen* ScreenChooser::createScreen( ScreenId id )
|
||||
{
|
||||
Screen* screen = NULL;
|
||||
|
||||
// :sob:
|
||||
if (/* _mc->useTouchscreen() */ true) {
|
||||
switch (id) {
|
||||
case SCREEN_STARTMENU: screen = new Touch::StartMenuScreen(); break;
|
||||
case SCREEN_SELECTWORLD: screen = new Touch::SelectWorldScreen();break;
|
||||
case SCREEN_JOINGAME: screen = new Touch::JoinGameScreen(); break;
|
||||
case SCREEN_PAUSE: screen = new PauseScreen(false); break;
|
||||
case SCREEN_PAUSEPREV: screen = new PauseScreen(true); break;
|
||||
case SCREEN_BLOCKSELECTION: screen = new Touch::IngameBlockSelectionScreen(); break;
|
||||
case SCREEN_JOINBYIP: screen = new JoinByIPScreen(); break;
|
||||
case SCREEN_CONSOLE: screen = new ConsoleScreen(); break;
|
||||
case SCREEN_NONE:
|
||||
default:
|
||||
// Do nothing
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (id) {
|
||||
case SCREEN_STARTMENU: screen = new StartMenuScreen(); break;
|
||||
case SCREEN_SELECTWORLD: screen = new SelectWorldScreen();break;
|
||||
case SCREEN_JOINGAME: screen = new JoinGameScreen(); break;
|
||||
case SCREEN_PAUSE: screen = new PauseScreen(false); break;
|
||||
case SCREEN_PAUSEPREV: screen = new PauseScreen(true); break;
|
||||
case SCREEN_BLOCKSELECTION: screen = new IngameBlockSelectionScreen(); break;
|
||||
case SCREEN_JOINBYIP: screen = new JoinByIPScreen(); break;
|
||||
case SCREEN_CONSOLE: screen = new ConsoleScreen(); break;
|
||||
case SCREEN_NONE:
|
||||
default:
|
||||
// Do nothing
|
||||
break;
|
||||
}
|
||||
}
|
||||
return screen;
|
||||
}
|
||||
|
||||
Screen* ScreenChooser::setScreen(ScreenId id)
|
||||
{
|
||||
Screen* screen = createScreen(id);
|
||||
_mc.setScreen(screen);
|
||||
return screen;
|
||||
}
|
||||
|
||||
@@ -1,469 +1,469 @@
|
||||
#include "SelectWorldScreen.h"
|
||||
#include "MinecraftClient.h"
|
||||
#include "StartMenuScreen.h"
|
||||
#include "ProgressScreen.h"
|
||||
#include "DialogDefinitions.h"
|
||||
#include "../../renderer/Tesselator.h"
|
||||
#include "../../../AppPlatform.h"
|
||||
#include "../../../util/StringUtils.h"
|
||||
#include "../../../util/Mth.h"
|
||||
#include "../../../platform/input/Mouse.h"
|
||||
#include "../../../Performance.h"
|
||||
#include "../../../world/level/LevelSettings.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
#include "../../renderer/Textures.h"
|
||||
#include "SimpleChooseLevelScreen.h"
|
||||
|
||||
static float Max(float a, float b) {
|
||||
return a>b? a : b;
|
||||
}
|
||||
|
||||
//
|
||||
// World Selection List
|
||||
//
|
||||
WorldSelectionList::WorldSelectionList( MinecraftClient& minecraft, int width, int height )
|
||||
: _height(height),
|
||||
hasPickedLevel(false),
|
||||
currentTick(0),
|
||||
stoppedTick(-1),
|
||||
mode(0),
|
||||
RolledSelectionListH(minecraft, width, height, 0, width, 26, height-32, 120)
|
||||
{
|
||||
}
|
||||
|
||||
int WorldSelectionList::getNumberOfItems() {
|
||||
return (int)levels.size();
|
||||
}
|
||||
|
||||
void WorldSelectionList::selectItem( int item, bool doubleClick ) {
|
||||
//LOGI("sel: %d, item %d\n", selectedItem, item);
|
||||
if (selectedItem < 0 || (selectedItem != item))
|
||||
return;
|
||||
|
||||
if (!hasPickedLevel) {
|
||||
hasPickedLevel = true;
|
||||
pickedLevel = levels[item];
|
||||
}
|
||||
}
|
||||
|
||||
bool WorldSelectionList::isSelectedItem( int item ) {
|
||||
return item == selectedItem;
|
||||
}
|
||||
|
||||
void WorldSelectionList::renderItem( int i, int x, int y, int h, Tesselator& t ) {
|
||||
|
||||
int centerx = x + itemWidth/2;
|
||||
|
||||
float a0 = Max(1.1f - std::abs( width / 2 - centerx ) * 0.0055f, 0.2f);
|
||||
if (a0 > 1) a0 = 1;
|
||||
int textColor = (int)(255.0f * a0) * 0x010101;
|
||||
int textColor2 = (int)(140.0f * a0) * 0x010101;
|
||||
|
||||
const int TY = y + 42;
|
||||
const int TX = centerx - itemWidth / 2 + 5;
|
||||
|
||||
StringVector v = _descriptions[i];
|
||||
drawString(minecraft->font, v[0].c_str(), TX, TY + 0, textColor);
|
||||
drawString(minecraft->font, v[1].c_str(), TX, TY + 10, textColor2);
|
||||
drawString(minecraft->font, v[2].c_str(), TX, TY + 20, textColor2);
|
||||
drawString(minecraft->font, v[3].c_str(), TX, TY + 30, textColor2);
|
||||
|
||||
minecraft->textures->loadAndBindTexture(_imageNames[i]);
|
||||
t.color(0.3f, 1.0f, 0.2f);
|
||||
|
||||
//float x0 = (float)x;
|
||||
//float x1 = (float)x + (float)itemWidth;
|
||||
|
||||
const float IY = (float)y - 8;
|
||||
t.begin();
|
||||
t.color(textColor);
|
||||
t.vertexUV((float)(centerx-32), IY, blitOffset, 0, 0);
|
||||
t.vertexUV((float)(centerx-32), IY + 48, blitOffset, 0, 1);
|
||||
t.vertexUV((float)(centerx+32), IY + 48, blitOffset, 1, 1);
|
||||
t.vertexUV((float)(centerx+32), IY, blitOffset, 1, 0);
|
||||
t.draw();
|
||||
}
|
||||
|
||||
void WorldSelectionList::stepLeft() {
|
||||
if (selectedItem > 0) {
|
||||
td.start = xo;
|
||||
td.stop = xo - itemWidth;
|
||||
td.cur = 0;
|
||||
td.dur = 8;
|
||||
mode = 1;
|
||||
tweenInited();
|
||||
}
|
||||
}
|
||||
|
||||
void WorldSelectionList::stepRight() {
|
||||
if (selectedItem >= 0 && selectedItem < getNumberOfItems()-1) {
|
||||
td.start = xo;
|
||||
td.stop = xo + itemWidth;
|
||||
td.cur = 0;
|
||||
td.dur = 8;
|
||||
mode = 1;
|
||||
tweenInited();
|
||||
}
|
||||
}
|
||||
|
||||
void WorldSelectionList::commit() {
|
||||
for (unsigned int i = 0; i < levels.size(); ++i) {
|
||||
LevelSummary& level = levels[i];
|
||||
|
||||
std::stringstream ss;
|
||||
ss << level.name << "/preview.png";
|
||||
TextureId id = Textures::InvalidId;//minecraft->textures->loadTexture(ss.str(), false);
|
||||
|
||||
if (id != Textures::InvalidId) {
|
||||
_imageNames.push_back( ss.str() );
|
||||
} else {
|
||||
_imageNames.push_back("gui/default_world.png");
|
||||
}
|
||||
|
||||
StringVector lines;
|
||||
lines.push_back(level.name);
|
||||
lines.push_back(minecraft->platform()->getDateString(level.lastPlayed));
|
||||
lines.push_back(level.id);
|
||||
lines.push_back(LevelSettings::gameTypeToString(level.gameType));
|
||||
_descriptions.push_back(lines);
|
||||
|
||||
selectedItem = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static float quadraticInOut(float t, float dur, float start, float stop) {
|
||||
const float delta = stop - start;
|
||||
const float T = (t / dur) * 2.0f;
|
||||
if (T < 1) return 0.5f*delta*T*T + start;
|
||||
return -0.5f*delta * ((T-1)*(T-3) - 1) + start;
|
||||
}
|
||||
|
||||
void WorldSelectionList::tick()
|
||||
{
|
||||
RolledSelectionListH::tick();
|
||||
|
||||
++currentTick;
|
||||
|
||||
if (Mouse::isButtonDown(MouseAction::ACTION_LEFT) || dragState == 0)
|
||||
return;
|
||||
|
||||
// Handle the tween (when in "mode 1")
|
||||
selectedItem = -1;
|
||||
if (mode == 1) {
|
||||
if (++td.cur == td.dur) {
|
||||
mode = 0;
|
||||
xInertia = 0;
|
||||
xoo = xo = td.stop;
|
||||
selectedItem = getItemAtPosition(width/2, height/2);
|
||||
} else {
|
||||
tweenInited();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// It's still going fast, let it run
|
||||
float speed = Mth::abs(xInertia);
|
||||
bool slowEnoughToBeBothered = speed < 5.0f;
|
||||
if (!slowEnoughToBeBothered) {
|
||||
xInertia = xInertia * .9f;
|
||||
return;
|
||||
}
|
||||
|
||||
xInertia *= 0.8f;
|
||||
|
||||
if (speed < 1 && dragState < 0) {
|
||||
const int offsetx = (width-itemWidth) / 2;
|
||||
const float pxo = xo + offsetx;
|
||||
int index = getItemAtXPositionRaw((int)(pxo - 10*xInertia));
|
||||
int indexPos = index*itemWidth;
|
||||
|
||||
// Pick closest
|
||||
float diff = (float)indexPos - pxo;
|
||||
if (diff < -itemWidth/2) {
|
||||
diff += itemWidth;
|
||||
index++;
|
||||
//indexPos += itemWidth;
|
||||
}
|
||||
if (Mth::abs(diff) < 1 && speed < 0.1f) {
|
||||
selectedItem = getItemAtPosition(width/2, height/2);
|
||||
return;
|
||||
}
|
||||
|
||||
td.start = xo;
|
||||
td.stop = xo + diff;
|
||||
td.cur = 0;
|
||||
td.dur = (float) Mth::Min(7, 1 + (int)(Mth::abs(diff) * 0.25f));
|
||||
mode = 1;
|
||||
//LOGI("inited-t %d\n", dragState);
|
||||
tweenInited();
|
||||
}
|
||||
}
|
||||
|
||||
float WorldSelectionList::getPos( float alpha )
|
||||
{
|
||||
if (mode != 1) return RolledSelectionListH::getPos(alpha);
|
||||
|
||||
float x0 = quadraticInOut(td.cur, td.dur, td.start, td.stop);
|
||||
float x1 = quadraticInOut(td.cur+1, td.dur, td.start, td.stop);
|
||||
return x0 + (x1-x0)*alpha;
|
||||
}
|
||||
|
||||
bool WorldSelectionList::capXPosition() {
|
||||
bool capped = RolledSelectionListH::capXPosition();
|
||||
if (capped) mode = 0;
|
||||
return capped;
|
||||
}
|
||||
|
||||
void WorldSelectionList::tweenInited() {
|
||||
float x0 = quadraticInOut(td.cur, td.dur, td.start, td.stop);
|
||||
float x1 = quadraticInOut(td.cur+1, td.dur, td.start, td.stop);
|
||||
xInertia = x0-x1; // yes, it's all backwards and messed up..
|
||||
}
|
||||
|
||||
//
|
||||
// Select World Screen
|
||||
//
|
||||
SelectWorldScreen::SelectWorldScreen()
|
||||
: bDelete (1, "Delete"),
|
||||
bCreate (2, "Create new"),
|
||||
bBack (3, "Back"),
|
||||
bWorldView(4, ""),
|
||||
worldsList(NULL),
|
||||
_hasStartedLevel(false)
|
||||
{
|
||||
bDelete.active = false;
|
||||
}
|
||||
|
||||
SelectWorldScreen::~SelectWorldScreen()
|
||||
{
|
||||
delete worldsList;
|
||||
}
|
||||
|
||||
void SelectWorldScreen::buttonClicked(Button* button)
|
||||
{
|
||||
if (button->id == bCreate.id) {
|
||||
// open in-game world-creation screen instead of using platform dialog
|
||||
if (!_hasStartedLevel) {
|
||||
std::string name = getUniqueLevelName("world");
|
||||
minecraft->setScreen(new SimpleChooseLevelScreen(name));
|
||||
}
|
||||
}
|
||||
if (button->id == bDelete.id) {
|
||||
if (isIndexValid(worldsList->selectedItem)) {
|
||||
LevelSummary level = worldsList->levels[worldsList->selectedItem];
|
||||
LOGI("level: %s, %s\n", level.id.c_str(), level.name.c_str());
|
||||
minecraft->setScreen( new DeleteWorldScreen(level) );
|
||||
}
|
||||
}
|
||||
if (button->id == bBack.id) {
|
||||
minecraft->cancelLocateMultiplayer();
|
||||
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||
}
|
||||
if (button->id == bWorldView.id) {
|
||||
// Try to "click" the item in the middle
|
||||
worldsList->selectItem( worldsList->getItemAtPosition(width/2, height/2), false );
|
||||
}
|
||||
}
|
||||
|
||||
bool SelectWorldScreen::handleBackEvent(bool isDown)
|
||||
{
|
||||
if (!isDown)
|
||||
{
|
||||
minecraft->cancelLocateMultiplayer();
|
||||
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SelectWorldScreen::isIndexValid( int index )
|
||||
{
|
||||
return worldsList && index >= 0 && index < worldsList->getNumberOfItems();
|
||||
}
|
||||
|
||||
static char ILLEGAL_FILE_CHARACTERS[] = {
|
||||
'/', '\n', '\r', '\t', '\0', '\f', '`', '?', '*', '\\', '<', '>', '|', '\"', ':'
|
||||
};
|
||||
|
||||
void SelectWorldScreen::tick()
|
||||
{
|
||||
worldsList->tick();
|
||||
|
||||
if (worldsList->hasPickedLevel) {
|
||||
minecraft->selectLevel(worldsList->pickedLevel.id, worldsList->pickedLevel.name, LevelSettings::None());
|
||||
minecraft->hostMultiplayer();
|
||||
minecraft->setScreen(new ProgressScreen());
|
||||
_hasStartedLevel = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// copy the currently selected item
|
||||
LevelSummary selectedWorld;
|
||||
//bool hasSelection = false;
|
||||
if (isIndexValid(worldsList->selectedItem))
|
||||
{
|
||||
selectedWorld = worldsList->levels[worldsList->selectedItem];
|
||||
//hasSelection = true;
|
||||
}
|
||||
|
||||
bDelete.active = isIndexValid(worldsList->selectedItem);
|
||||
}
|
||||
|
||||
void SelectWorldScreen::init()
|
||||
{
|
||||
worldsList = new WorldSelectionList(minecraft, width, height);
|
||||
loadLevelSource();
|
||||
worldsList->commit();
|
||||
|
||||
buttons.push_back(&bDelete);
|
||||
buttons.push_back(&bCreate);
|
||||
buttons.push_back(&bBack);
|
||||
|
||||
_mouseHasBeenUp = !Mouse::getButtonState(MouseAction::ACTION_LEFT);
|
||||
|
||||
tabButtons.push_back(&bWorldView);
|
||||
tabButtons.push_back(&bDelete);
|
||||
tabButtons.push_back(&bCreate);
|
||||
tabButtons.push_back(&bBack);
|
||||
}
|
||||
|
||||
void SelectWorldScreen::setupPositions() {
|
||||
int yBase = height - 28;
|
||||
|
||||
//#ifdef ANDROID
|
||||
bCreate.y = yBase;
|
||||
bBack.y = yBase;
|
||||
bDelete.y = yBase;
|
||||
|
||||
bBack.width = bDelete.width = bCreate.width = 84;
|
||||
//bDelete.h = bCreate.h = bBack.h = 24;
|
||||
//#endif
|
||||
|
||||
// Center buttons
|
||||
bDelete.x = width / 2 - 4 - bDelete.width - bDelete.width / 2;
|
||||
bCreate.x = width / 2 - bCreate.width / 2;
|
||||
bBack.x = width / 2 + 4 + bCreate.width - bBack.width / 2;
|
||||
}
|
||||
|
||||
void SelectWorldScreen::render( int xm, int ym, float a )
|
||||
{
|
||||
//Performance::watches.get("sws-full").start();
|
||||
//Performance::watches.get("sws-renderbg").start();
|
||||
renderBackground();
|
||||
//Performance::watches.get("sws-renderbg").stop();
|
||||
//Performance::watches.get("sws-worlds").start();
|
||||
|
||||
worldsList->setComponentSelected(bWorldView.selected);
|
||||
// #ifdef PLATFORM_DESKTOP
|
||||
|
||||
// desktop: render the list normally (mouse wheel handled separately below)
|
||||
if (_mouseHasBeenUp)
|
||||
worldsList->render(xm, ym, a);
|
||||
else {
|
||||
worldsList->render(0, 0, a);
|
||||
_mouseHasBeenUp = !Mouse::getButtonState(MouseAction::ACTION_LEFT);
|
||||
}
|
||||
// #else
|
||||
// if (_mouseHasBeenUp)
|
||||
// worldsList->render(xm, ym, a);
|
||||
// else {
|
||||
// worldsList->render(0, 0, a);
|
||||
// _mouseHasBeenUp = !Mouse::getButtonState(MouseAction::ACTION_LEFT);
|
||||
// }
|
||||
// #endif
|
||||
|
||||
//Performance::watches.get("sws-worlds").stop();
|
||||
//Performance::watches.get("sws-screen").start();
|
||||
Screen::render(xm, ym, a);
|
||||
//Performance::watches.get("sws-screen").stop();
|
||||
|
||||
//Performance::watches.get("sws-string").start();
|
||||
drawCenteredString(minecraft->font, "Select world", width / 2, 8, 0xffffffff);
|
||||
//Performance::watches.get("sws-string").stop();
|
||||
|
||||
//Performance::watches.get("sws-full").stop();
|
||||
//Performance::watches.printEvery(128);
|
||||
}
|
||||
|
||||
void SelectWorldScreen::loadLevelSource()
|
||||
{
|
||||
LevelStorageSource* levelSource = minecraft->getLevelSource();
|
||||
levelSource->getLevelList(levels);
|
||||
std::sort(levels.begin(), levels.end());
|
||||
|
||||
for (unsigned int i = 0; i < levels.size(); ++i) {
|
||||
if (levels[i].id != LevelStorageSource::TempLevelId)
|
||||
worldsList->levels.push_back( levels[i] );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string SelectWorldScreen::getUniqueLevelName( const std::string& level )
|
||||
{
|
||||
std::set<std::string> Set;
|
||||
for (unsigned int i = 0; i < levels.size(); ++i)
|
||||
Set.insert(levels[i].id);
|
||||
|
||||
std::string s = level;
|
||||
while ( Set.find(s) != Set.end() )
|
||||
s += "-";
|
||||
return s;
|
||||
}
|
||||
|
||||
bool SelectWorldScreen::isInGameScreen() { return true; }
|
||||
|
||||
void SelectWorldScreen::mouseWheel(int dx, int dy, int xm, int ym)
|
||||
{
|
||||
if (!worldsList)
|
||||
return;
|
||||
if (dy == 0)
|
||||
return;
|
||||
int num = worldsList->getNumberOfItems();
|
||||
int idx = worldsList->selectedItem;
|
||||
if (dy > 0) {
|
||||
if (idx > 0) {
|
||||
idx--;
|
||||
worldsList->stepLeft();
|
||||
}
|
||||
} else {
|
||||
if (idx < num - 1) {
|
||||
idx++;
|
||||
worldsList->stepRight();
|
||||
}
|
||||
}
|
||||
worldsList->selectedItem = idx;
|
||||
}
|
||||
|
||||
void SelectWorldScreen::keyPressed( int eventKey )
|
||||
{
|
||||
if (bWorldView.selected) {
|
||||
if (eventKey == minecraft->options.getIntValue(OPTIONS_KEY_RIGHT))
|
||||
worldsList->stepLeft();
|
||||
if (eventKey == minecraft->options.getIntValue(OPTIONS_KEY_LEFT))
|
||||
worldsList->stepRight();
|
||||
}
|
||||
|
||||
Screen::keyPressed(eventKey);
|
||||
}
|
||||
|
||||
//
|
||||
// Delete World Screen
|
||||
//
|
||||
DeleteWorldScreen::DeleteWorldScreen(const LevelSummary& level)
|
||||
: ConfirmScreen(NULL, "Are you sure you want to delete this world?",
|
||||
"'" + level.name + "' will be lost forever!",
|
||||
"Delete", "Cancel", 0),
|
||||
_level(level)
|
||||
{
|
||||
tabButtonIndex = 1;
|
||||
}
|
||||
|
||||
void DeleteWorldScreen::postResult( bool isOk )
|
||||
{
|
||||
if (isOk) {
|
||||
LevelStorageSource* storageSource = minecraft->getLevelSource();
|
||||
storageSource->deleteLevel(_level.id);
|
||||
}
|
||||
minecraft->screenChooser.setScreen(SCREEN_SELECTWORLD);
|
||||
}
|
||||
#include "SelectWorldScreen.hpp"
|
||||
#include "MinecraftClient.hpp"
|
||||
#include "StartMenuScreen.hpp"
|
||||
#include "ProgressScreen.hpp"
|
||||
#include "DialogDefinitions.hpp"
|
||||
#include "client/renderer/Tesselator.hpp"
|
||||
#include "AppPlatform.hpp"
|
||||
#include "util/StringUtils.hpp"
|
||||
#include "util/Mth.hpp"
|
||||
#include "platform/input/Mouse.hpp"
|
||||
#include "Performance.hpp"
|
||||
#include "world/level/LevelSettings.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
#include "client/renderer/Textures.hpp"
|
||||
#include "SimpleChooseLevelScreen.hpp"
|
||||
|
||||
static float Max(float a, float b) {
|
||||
return a>b? a : b;
|
||||
}
|
||||
|
||||
//
|
||||
// World Selection List
|
||||
//
|
||||
WorldSelectionList::WorldSelectionList( MinecraftClient& minecraft, int width, int height )
|
||||
: _height(height),
|
||||
hasPickedLevel(false),
|
||||
currentTick(0),
|
||||
stoppedTick(-1),
|
||||
mode(0),
|
||||
RolledSelectionListH(minecraft, width, height, 0, width, 26, height-32, 120)
|
||||
{
|
||||
}
|
||||
|
||||
int WorldSelectionList::getNumberOfItems() {
|
||||
return (int)levels.size();
|
||||
}
|
||||
|
||||
void WorldSelectionList::selectItem( int item, bool doubleClick ) {
|
||||
//LOGI("sel: %d, item %d\n", selectedItem, item);
|
||||
if (selectedItem < 0 || (selectedItem != item))
|
||||
return;
|
||||
|
||||
if (!hasPickedLevel) {
|
||||
hasPickedLevel = true;
|
||||
pickedLevel = levels[item];
|
||||
}
|
||||
}
|
||||
|
||||
bool WorldSelectionList::isSelectedItem( int item ) {
|
||||
return item == selectedItem;
|
||||
}
|
||||
|
||||
void WorldSelectionList::renderItem( int i, int x, int y, int h, Tesselator& t ) {
|
||||
|
||||
int centerx = x + itemWidth/2;
|
||||
|
||||
float a0 = Max(1.1f - std::abs( width / 2 - centerx ) * 0.0055f, 0.2f);
|
||||
if (a0 > 1) a0 = 1;
|
||||
int textColor = (int)(255.0f * a0) * 0x010101;
|
||||
int textColor2 = (int)(140.0f * a0) * 0x010101;
|
||||
|
||||
const int TY = y + 42;
|
||||
const int TX = centerx - itemWidth / 2 + 5;
|
||||
|
||||
StringVector v = _descriptions[i];
|
||||
drawString(minecraft->font, v[0].c_str(), TX, TY + 0, textColor);
|
||||
drawString(minecraft->font, v[1].c_str(), TX, TY + 10, textColor2);
|
||||
drawString(minecraft->font, v[2].c_str(), TX, TY + 20, textColor2);
|
||||
drawString(minecraft->font, v[3].c_str(), TX, TY + 30, textColor2);
|
||||
|
||||
minecraft->textures->loadAndBindTexture(_imageNames[i]);
|
||||
t.color(0.3f, 1.0f, 0.2f);
|
||||
|
||||
//float x0 = (float)x;
|
||||
//float x1 = (float)x + (float)itemWidth;
|
||||
|
||||
const float IY = (float)y - 8;
|
||||
t.begin();
|
||||
t.color(textColor);
|
||||
t.vertexUV((float)(centerx-32), IY, blitOffset, 0, 0);
|
||||
t.vertexUV((float)(centerx-32), IY + 48, blitOffset, 0, 1);
|
||||
t.vertexUV((float)(centerx+32), IY + 48, blitOffset, 1, 1);
|
||||
t.vertexUV((float)(centerx+32), IY, blitOffset, 1, 0);
|
||||
t.draw();
|
||||
}
|
||||
|
||||
void WorldSelectionList::stepLeft() {
|
||||
if (selectedItem > 0) {
|
||||
td.start = xo;
|
||||
td.stop = xo - itemWidth;
|
||||
td.cur = 0;
|
||||
td.dur = 8;
|
||||
mode = 1;
|
||||
tweenInited();
|
||||
}
|
||||
}
|
||||
|
||||
void WorldSelectionList::stepRight() {
|
||||
if (selectedItem >= 0 && selectedItem < getNumberOfItems()-1) {
|
||||
td.start = xo;
|
||||
td.stop = xo + itemWidth;
|
||||
td.cur = 0;
|
||||
td.dur = 8;
|
||||
mode = 1;
|
||||
tweenInited();
|
||||
}
|
||||
}
|
||||
|
||||
void WorldSelectionList::commit() {
|
||||
for (unsigned int i = 0; i < levels.size(); ++i) {
|
||||
LevelSummary& level = levels[i];
|
||||
|
||||
std::stringstream ss;
|
||||
ss << level.name << "/preview.png";
|
||||
TextureId id = Textures::InvalidId;//minecraft->textures->loadTexture(ss.str(), false);
|
||||
|
||||
if (id != Textures::InvalidId) {
|
||||
_imageNames.push_back( ss.str() );
|
||||
} else {
|
||||
_imageNames.push_back("gui/default_world.png");
|
||||
}
|
||||
|
||||
StringVector lines;
|
||||
lines.push_back(level.name);
|
||||
lines.push_back(minecraft->platform()->getDateString(level.lastPlayed));
|
||||
lines.push_back(level.id);
|
||||
lines.push_back(LevelSettings::gameTypeToString(level.gameType));
|
||||
_descriptions.push_back(lines);
|
||||
|
||||
selectedItem = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static float quadraticInOut(float t, float dur, float start, float stop) {
|
||||
const float delta = stop - start;
|
||||
const float T = (t / dur) * 2.0f;
|
||||
if (T < 1) return 0.5f*delta*T*T + start;
|
||||
return -0.5f*delta * ((T-1)*(T-3) - 1) + start;
|
||||
}
|
||||
|
||||
void WorldSelectionList::tick()
|
||||
{
|
||||
RolledSelectionListH::tick();
|
||||
|
||||
++currentTick;
|
||||
|
||||
if (Mouse::isButtonDown(MouseAction::ACTION_LEFT) || dragState == 0)
|
||||
return;
|
||||
|
||||
// Handle the tween (when in "mode 1")
|
||||
selectedItem = -1;
|
||||
if (mode == 1) {
|
||||
if (++td.cur == td.dur) {
|
||||
mode = 0;
|
||||
xInertia = 0;
|
||||
xoo = xo = td.stop;
|
||||
selectedItem = getItemAtPosition(width/2, height/2);
|
||||
} else {
|
||||
tweenInited();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// It's still going fast, let it run
|
||||
float speed = Mth::abs(xInertia);
|
||||
bool slowEnoughToBeBothered = speed < 5.0f;
|
||||
if (!slowEnoughToBeBothered) {
|
||||
xInertia = xInertia * .9f;
|
||||
return;
|
||||
}
|
||||
|
||||
xInertia *= 0.8f;
|
||||
|
||||
if (speed < 1 && dragState < 0) {
|
||||
const int offsetx = (width-itemWidth) / 2;
|
||||
const float pxo = xo + offsetx;
|
||||
int index = getItemAtXPositionRaw((int)(pxo - 10*xInertia));
|
||||
int indexPos = index*itemWidth;
|
||||
|
||||
// Pick closest
|
||||
float diff = (float)indexPos - pxo;
|
||||
if (diff < -itemWidth/2) {
|
||||
diff += itemWidth;
|
||||
index++;
|
||||
//indexPos += itemWidth;
|
||||
}
|
||||
if (Mth::abs(diff) < 1 && speed < 0.1f) {
|
||||
selectedItem = getItemAtPosition(width/2, height/2);
|
||||
return;
|
||||
}
|
||||
|
||||
td.start = xo;
|
||||
td.stop = xo + diff;
|
||||
td.cur = 0;
|
||||
td.dur = (float) Mth::Min(7, 1 + (int)(Mth::abs(diff) * 0.25f));
|
||||
mode = 1;
|
||||
//LOGI("inited-t %d\n", dragState);
|
||||
tweenInited();
|
||||
}
|
||||
}
|
||||
|
||||
float WorldSelectionList::getPos( float alpha )
|
||||
{
|
||||
if (mode != 1) return RolledSelectionListH::getPos(alpha);
|
||||
|
||||
float x0 = quadraticInOut(td.cur, td.dur, td.start, td.stop);
|
||||
float x1 = quadraticInOut(td.cur+1, td.dur, td.start, td.stop);
|
||||
return x0 + (x1-x0)*alpha;
|
||||
}
|
||||
|
||||
bool WorldSelectionList::capXPosition() {
|
||||
bool capped = RolledSelectionListH::capXPosition();
|
||||
if (capped) mode = 0;
|
||||
return capped;
|
||||
}
|
||||
|
||||
void WorldSelectionList::tweenInited() {
|
||||
float x0 = quadraticInOut(td.cur, td.dur, td.start, td.stop);
|
||||
float x1 = quadraticInOut(td.cur+1, td.dur, td.start, td.stop);
|
||||
xInertia = x0-x1; // yes, it's all backwards and messed up..
|
||||
}
|
||||
|
||||
//
|
||||
// Select World Screen
|
||||
//
|
||||
SelectWorldScreen::SelectWorldScreen()
|
||||
: bDelete (1, "Delete"),
|
||||
bCreate (2, "Create new"),
|
||||
bBack (3, "Back"),
|
||||
bWorldView(4, ""),
|
||||
worldsList(NULL),
|
||||
_hasStartedLevel(false)
|
||||
{
|
||||
bDelete.active = false;
|
||||
}
|
||||
|
||||
SelectWorldScreen::~SelectWorldScreen()
|
||||
{
|
||||
delete worldsList;
|
||||
}
|
||||
|
||||
void SelectWorldScreen::buttonClicked(Button* button)
|
||||
{
|
||||
if (button->id == bCreate.id) {
|
||||
// open in-game world-creation screen instead of using platform dialog
|
||||
if (!_hasStartedLevel) {
|
||||
std::string name = getUniqueLevelName("world");
|
||||
minecraft->setScreen(new SimpleChooseLevelScreen(name));
|
||||
}
|
||||
}
|
||||
if (button->id == bDelete.id) {
|
||||
if (isIndexValid(worldsList->selectedItem)) {
|
||||
LevelSummary level = worldsList->levels[worldsList->selectedItem];
|
||||
LOGI("level: %s, %s\n", level.id.c_str(), level.name.c_str());
|
||||
minecraft->setScreen( new DeleteWorldScreen(level) );
|
||||
}
|
||||
}
|
||||
if (button->id == bBack.id) {
|
||||
minecraft->cancelLocateMultiplayer();
|
||||
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||
}
|
||||
if (button->id == bWorldView.id) {
|
||||
// Try to "click" the item in the middle
|
||||
worldsList->selectItem( worldsList->getItemAtPosition(width/2, height/2), false );
|
||||
}
|
||||
}
|
||||
|
||||
bool SelectWorldScreen::handleBackEvent(bool isDown)
|
||||
{
|
||||
if (!isDown)
|
||||
{
|
||||
minecraft->cancelLocateMultiplayer();
|
||||
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SelectWorldScreen::isIndexValid( int index )
|
||||
{
|
||||
return worldsList && index >= 0 && index < worldsList->getNumberOfItems();
|
||||
}
|
||||
|
||||
static char ILLEGAL_FILE_CHARACTERS[] = {
|
||||
'/', '\n', '\r', '\t', '\0', '\f', '`', '?', '*', '\\', '<', '>', '|', '\"', ':'
|
||||
};
|
||||
|
||||
void SelectWorldScreen::tick()
|
||||
{
|
||||
worldsList->tick();
|
||||
|
||||
if (worldsList->hasPickedLevel) {
|
||||
minecraft->selectLevel(worldsList->pickedLevel.id, worldsList->pickedLevel.name, LevelSettings::None());
|
||||
minecraft->hostMultiplayer();
|
||||
minecraft->setScreen(new ProgressScreen());
|
||||
_hasStartedLevel = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// copy the currently selected item
|
||||
LevelSummary selectedWorld;
|
||||
//bool hasSelection = false;
|
||||
if (isIndexValid(worldsList->selectedItem))
|
||||
{
|
||||
selectedWorld = worldsList->levels[worldsList->selectedItem];
|
||||
//hasSelection = true;
|
||||
}
|
||||
|
||||
bDelete.active = isIndexValid(worldsList->selectedItem);
|
||||
}
|
||||
|
||||
void SelectWorldScreen::init()
|
||||
{
|
||||
worldsList = new WorldSelectionList(minecraft, width, height);
|
||||
loadLevelSource();
|
||||
worldsList->commit();
|
||||
|
||||
buttons.push_back(&bDelete);
|
||||
buttons.push_back(&bCreate);
|
||||
buttons.push_back(&bBack);
|
||||
|
||||
_mouseHasBeenUp = !Mouse::getButtonState(MouseAction::ACTION_LEFT);
|
||||
|
||||
tabButtons.push_back(&bWorldView);
|
||||
tabButtons.push_back(&bDelete);
|
||||
tabButtons.push_back(&bCreate);
|
||||
tabButtons.push_back(&bBack);
|
||||
}
|
||||
|
||||
void SelectWorldScreen::setupPositions() {
|
||||
int yBase = height - 28;
|
||||
|
||||
//#ifdef ANDROID
|
||||
bCreate.y = yBase;
|
||||
bBack.y = yBase;
|
||||
bDelete.y = yBase;
|
||||
|
||||
bBack.width = bDelete.width = bCreate.width = 84;
|
||||
//bDelete.h = bCreate.h = bBack.h = 24;
|
||||
//#endif
|
||||
|
||||
// Center buttons
|
||||
bDelete.x = width / 2 - 4 - bDelete.width - bDelete.width / 2;
|
||||
bCreate.x = width / 2 - bCreate.width / 2;
|
||||
bBack.x = width / 2 + 4 + bCreate.width - bBack.width / 2;
|
||||
}
|
||||
|
||||
void SelectWorldScreen::render( int xm, int ym, float a )
|
||||
{
|
||||
//Performance::watches.get("sws-full").start();
|
||||
//Performance::watches.get("sws-renderbg").start();
|
||||
renderBackground();
|
||||
//Performance::watches.get("sws-renderbg").stop();
|
||||
//Performance::watches.get("sws-worlds").start();
|
||||
|
||||
worldsList->setComponentSelected(bWorldView.selected);
|
||||
// #ifdef PLATFORM_DESKTOP
|
||||
|
||||
// desktop: render the list normally (mouse wheel handled separately below)
|
||||
if (_mouseHasBeenUp)
|
||||
worldsList->render(xm, ym, a);
|
||||
else {
|
||||
worldsList->render(0, 0, a);
|
||||
_mouseHasBeenUp = !Mouse::getButtonState(MouseAction::ACTION_LEFT);
|
||||
}
|
||||
// #else
|
||||
// if (_mouseHasBeenUp)
|
||||
// worldsList->render(xm, ym, a);
|
||||
// else {
|
||||
// worldsList->render(0, 0, a);
|
||||
// _mouseHasBeenUp = !Mouse::getButtonState(MouseAction::ACTION_LEFT);
|
||||
// }
|
||||
// #endif
|
||||
|
||||
//Performance::watches.get("sws-worlds").stop();
|
||||
//Performance::watches.get("sws-screen").start();
|
||||
Screen::render(xm, ym, a);
|
||||
//Performance::watches.get("sws-screen").stop();
|
||||
|
||||
//Performance::watches.get("sws-string").start();
|
||||
drawCenteredString(minecraft->font, "Select world", width / 2, 8, 0xffffffff);
|
||||
//Performance::watches.get("sws-string").stop();
|
||||
|
||||
//Performance::watches.get("sws-full").stop();
|
||||
//Performance::watches.printEvery(128);
|
||||
}
|
||||
|
||||
void SelectWorldScreen::loadLevelSource()
|
||||
{
|
||||
LevelStorageSource* levelSource = minecraft->getLevelSource();
|
||||
levelSource->getLevelList(levels);
|
||||
std::sort(levels.begin(), levels.end());
|
||||
|
||||
for (unsigned int i = 0; i < levels.size(); ++i) {
|
||||
if (levels[i].id != LevelStorageSource::TempLevelId)
|
||||
worldsList->levels.push_back( levels[i] );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string SelectWorldScreen::getUniqueLevelName( const std::string& level )
|
||||
{
|
||||
std::set<std::string> Set;
|
||||
for (unsigned int i = 0; i < levels.size(); ++i)
|
||||
Set.insert(levels[i].id);
|
||||
|
||||
std::string s = level;
|
||||
while ( Set.find(s) != Set.end() )
|
||||
s += "-";
|
||||
return s;
|
||||
}
|
||||
|
||||
bool SelectWorldScreen::isInGameScreen() { return true; }
|
||||
|
||||
void SelectWorldScreen::mouseWheel(int dx, int dy, int xm, int ym)
|
||||
{
|
||||
if (!worldsList)
|
||||
return;
|
||||
if (dy == 0)
|
||||
return;
|
||||
int num = worldsList->getNumberOfItems();
|
||||
int idx = worldsList->selectedItem;
|
||||
if (dy > 0) {
|
||||
if (idx > 0) {
|
||||
idx--;
|
||||
worldsList->stepLeft();
|
||||
}
|
||||
} else {
|
||||
if (idx < num - 1) {
|
||||
idx++;
|
||||
worldsList->stepRight();
|
||||
}
|
||||
}
|
||||
worldsList->selectedItem = idx;
|
||||
}
|
||||
|
||||
void SelectWorldScreen::keyPressed( int eventKey )
|
||||
{
|
||||
if (bWorldView.selected) {
|
||||
if (eventKey == minecraft->options.getIntValue(OPTIONS_KEY_RIGHT))
|
||||
worldsList->stepLeft();
|
||||
if (eventKey == minecraft->options.getIntValue(OPTIONS_KEY_LEFT))
|
||||
worldsList->stepRight();
|
||||
}
|
||||
|
||||
Screen::keyPressed(eventKey);
|
||||
}
|
||||
|
||||
//
|
||||
// Delete World Screen
|
||||
//
|
||||
DeleteWorldScreen::DeleteWorldScreen(const LevelSummary& level)
|
||||
: ConfirmScreen(NULL, "Are you sure you want to delete this world?",
|
||||
"'" + level.name + "' will be lost forever!",
|
||||
"Delete", "Cancel", 0),
|
||||
_level(level)
|
||||
{
|
||||
tabButtonIndex = 1;
|
||||
}
|
||||
|
||||
void DeleteWorldScreen::postResult( bool isOk )
|
||||
{
|
||||
if (isOk) {
|
||||
LevelStorageSource* storageSource = minecraft->getLevelSource();
|
||||
storageSource->deleteLevel(_level.id);
|
||||
}
|
||||
minecraft->screenChooser.setScreen(SCREEN_SELECTWORLD);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Screen.h"
|
||||
#include "../TweenData.h"
|
||||
#include "../components/Button.h"
|
||||
#include "../components/RolledSelectionListH.h"
|
||||
#include "../../../world/level/storage/LevelStorageSource.h"
|
||||
#include "client/gui/Screen.hpp"
|
||||
#include "client/gui/TweenData.hpp"
|
||||
#include "client/gui/components/Button.hpp"
|
||||
#include "client/gui/components/RolledSelectionListH.hpp"
|
||||
#include "world/level/storage/LevelStorageSource.hpp"
|
||||
|
||||
|
||||
class SelectWorldScreen;
|
||||
@@ -56,7 +56,7 @@ private:
|
||||
//
|
||||
// Delete World screen
|
||||
//
|
||||
#include "ConfirmScreen.h"
|
||||
#include "ConfirmScreen.hpp"
|
||||
class DeleteWorldScreen: public ConfirmScreen
|
||||
{
|
||||
public:
|
||||
@@ -1,260 +1,260 @@
|
||||
#include "SimpleChooseLevelScreen.h"
|
||||
#include "ProgressScreen.h"
|
||||
#include "ScreenChooser.h"
|
||||
#include "../components/Button.h"
|
||||
#include "../components/ImageButton.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../../world/level/LevelSettings.h"
|
||||
#include "../../../platform/time.h"
|
||||
#include "../../../platform/input/Keyboard.h"
|
||||
#include "../../../platform/log.h"
|
||||
|
||||
SimpleChooseLevelScreen::SimpleChooseLevelScreen(const std::string& levelName)
|
||||
: bHeader(0),
|
||||
bGamemode(0),
|
||||
bCheats(0),
|
||||
bBack(0),
|
||||
bCreate(0),
|
||||
levelName(levelName),
|
||||
hasChosen(false),
|
||||
gamemode(GameType::Survival),
|
||||
cheatsEnabled(false),
|
||||
tLevelName(0, "World name"),
|
||||
tSeed(1, "World seed")
|
||||
{
|
||||
}
|
||||
|
||||
SimpleChooseLevelScreen::~SimpleChooseLevelScreen()
|
||||
{
|
||||
if (bHeader) delete bHeader;
|
||||
delete bGamemode;
|
||||
delete bCheats;
|
||||
delete bBack;
|
||||
delete bCreate;
|
||||
}
|
||||
|
||||
void SimpleChooseLevelScreen::init()
|
||||
{
|
||||
// make sure the base class loads the existing level list; the
|
||||
// derived screen uses ChooseLevelScreen::getUniqueLevelName(), which
|
||||
// depends on `levels` being populated. omitting this used to result
|
||||
// in duplicate IDs ("creating the second world would load the
|
||||
// first") when the name already existed.
|
||||
ChooseLevelScreen::init();
|
||||
|
||||
tLevelName.text = "New world";
|
||||
|
||||
// header + close button
|
||||
bHeader = new Touch::THeader(0, "Create World");
|
||||
// create the back/X button as ImageButton like CreditsScreen
|
||||
bBack = new ImageButton(2, "");
|
||||
{
|
||||
ImageDef def;
|
||||
def.name = "gui/touchgui.png";
|
||||
def.width = 34;
|
||||
def.height = 26;
|
||||
def.setSrc(IntRectangle(150, 0, (int)def.width, (int)def.height));
|
||||
bBack->setImageDef(def, true);
|
||||
}
|
||||
if (/* minecraft->useTouchscreen() */ true) {
|
||||
bGamemode = new Touch::TButton(1, "Survival mode");
|
||||
bCheats = new Touch::TButton(4, "Cheats: Off");
|
||||
bCreate = new Touch::TButton(3, "Create");
|
||||
} else {
|
||||
bGamemode = new Button(1, "Survival mode");
|
||||
bCheats = new Button(4, "Cheats: Off");
|
||||
bCreate = new Button(3, "Create");
|
||||
}
|
||||
|
||||
buttons.push_back(bHeader);
|
||||
buttons.push_back(bBack);
|
||||
buttons.push_back(bGamemode);
|
||||
buttons.push_back(bCheats);
|
||||
buttons.push_back(bCreate);
|
||||
|
||||
tabButtons.push_back(bGamemode);
|
||||
tabButtons.push_back(bCheats);
|
||||
tabButtons.push_back(bBack);
|
||||
tabButtons.push_back(bCreate);
|
||||
|
||||
textBoxes.push_back(&tLevelName);
|
||||
textBoxes.push_back(&tSeed);
|
||||
}
|
||||
|
||||
void SimpleChooseLevelScreen::setupPositions()
|
||||
{
|
||||
int buttonHeight = bBack->height;
|
||||
|
||||
// position back button in upper-right
|
||||
bBack->x = width - bBack->width;
|
||||
bBack->y = 0;
|
||||
|
||||
// header occupies remaining top bar
|
||||
if (bHeader) {
|
||||
bHeader->x = 0;
|
||||
bHeader->y = 0;
|
||||
bHeader->width = width - bBack->width;
|
||||
bHeader->height = buttonHeight;
|
||||
}
|
||||
|
||||
// layout the form elements below the header
|
||||
int centerX = width / 2;
|
||||
const int padding = 5;
|
||||
|
||||
tLevelName.width = tSeed.width = 200;
|
||||
tLevelName.x = centerX - tLevelName.width / 2;
|
||||
tLevelName.y = buttonHeight + 20;
|
||||
|
||||
tSeed.x = tLevelName.x;
|
||||
tSeed.y = tLevelName.y + 30;
|
||||
|
||||
const int buttonWidth = 120;
|
||||
const int buttonSpacing = 10;
|
||||
const int totalButtonWidth = buttonWidth * 2 + buttonSpacing;
|
||||
|
||||
bGamemode->width = buttonWidth;
|
||||
bCheats->width = buttonWidth;
|
||||
|
||||
bGamemode->x = centerX - totalButtonWidth / 2;
|
||||
bCheats->x = bGamemode->x + buttonWidth + buttonSpacing;
|
||||
|
||||
// compute vertical centre for buttons in remaining space
|
||||
{
|
||||
int bottomPad = 20;
|
||||
int availTop = buttonHeight + 20 + 30 + 10; // just below seed
|
||||
int availBottom = height - bottomPad - bCreate->height - 10; // leave some gap before create
|
||||
int availHeight = availBottom - availTop;
|
||||
if (availHeight < 0) availHeight = 0;
|
||||
int y = availTop + (availHeight - bGamemode->height) / 2;
|
||||
bGamemode->y = y;
|
||||
bCheats->y = y;
|
||||
}
|
||||
|
||||
bCreate->width = 100;
|
||||
bCreate->x = centerX - bCreate->width / 2;
|
||||
int bottomPadding = 20;
|
||||
bCreate->y = height - bottomPadding - bCreate->height;
|
||||
}
|
||||
|
||||
void SimpleChooseLevelScreen::tick()
|
||||
{
|
||||
// let any textboxes handle their own blinking/input
|
||||
for (auto* tb : textBoxes)
|
||||
tb->tick(minecraft);
|
||||
}
|
||||
|
||||
void SimpleChooseLevelScreen::render( int xm, int ym, float a )
|
||||
{
|
||||
renderDirtBackground(0);
|
||||
glEnable2(GL_BLEND);
|
||||
|
||||
const char* modeDesc = NULL;
|
||||
if (gamemode == GameType::Survival) {
|
||||
modeDesc = "Mobs, health and gather resources";
|
||||
} else if (gamemode == GameType::Creative) {
|
||||
modeDesc = "Unlimited resources and flying";
|
||||
}
|
||||
if (modeDesc) {
|
||||
drawCenteredString(minecraft->font, modeDesc, width / 2, bGamemode->y + bGamemode->height + 4, 0xffcccccc);
|
||||
}
|
||||
|
||||
drawString(minecraft->font, "World name:", tLevelName.x, tLevelName.y - Font::DefaultLineHeight - 2, 0xffcccccc);
|
||||
drawString(minecraft->font, "World seed:", tSeed.x, tSeed.y - Font::DefaultLineHeight - 2, 0xffcccccc);
|
||||
|
||||
Screen::render(xm, ym, a);
|
||||
glDisable2(GL_BLEND);
|
||||
}
|
||||
|
||||
// mouse clicks should also manage textbox focus explicitly
|
||||
void SimpleChooseLevelScreen::mouseClicked(int x, int y, int buttonNum)
|
||||
{
|
||||
if (buttonNum == MouseAction::ACTION_LEFT) {
|
||||
// determine if the click landed on either textbox or its label above
|
||||
int lvlTop = tLevelName.y - (Font::DefaultLineHeight + 4);
|
||||
int lvlBottom = tLevelName.y + tLevelName.height;
|
||||
int lvlLeft = tLevelName.x;
|
||||
int lvlRight = tLevelName.x + tLevelName.width;
|
||||
bool clickedLevel = x >= lvlLeft && x < lvlRight && y >= lvlTop && y < lvlBottom;
|
||||
|
||||
int seedTop = tSeed.y - (Font::DefaultLineHeight + 4);
|
||||
int seedBottom = tSeed.y + tSeed.height;
|
||||
int seedLeft = tSeed.x;
|
||||
int seedRight = tSeed.x + tSeed.width;
|
||||
bool clickedSeed = x >= seedLeft && x < seedRight && y >= seedTop && y < seedBottom;
|
||||
|
||||
if (clickedLevel) {
|
||||
LOGI("SimpleChooseLevelScreen: level textbox clicked (%d,%d)\n", x, y);
|
||||
tLevelName.setFocus(minecraft);
|
||||
tSeed.loseFocus(minecraft);
|
||||
} else if (clickedSeed) {
|
||||
LOGI("SimpleChooseLevelScreen: seed textbox clicked (%d,%d)\n", x, y);
|
||||
tSeed.setFocus(minecraft);
|
||||
tLevelName.loseFocus(minecraft);
|
||||
} else {
|
||||
// click outside both fields -> blur both
|
||||
tLevelName.loseFocus(minecraft);
|
||||
tSeed.loseFocus(minecraft);
|
||||
}
|
||||
}
|
||||
|
||||
// allow normal button and textbox handling too
|
||||
Screen::mouseClicked(x, y, buttonNum);
|
||||
}
|
||||
|
||||
void SimpleChooseLevelScreen::buttonClicked( Button* button )
|
||||
{
|
||||
if (hasChosen)
|
||||
return;
|
||||
|
||||
if (button == bGamemode) {
|
||||
gamemode ^= 1;
|
||||
bGamemode->msg = (gamemode == GameType::Survival) ? "Survival mode" : "Creative mode";
|
||||
return;
|
||||
}
|
||||
|
||||
if (button == bCheats) {
|
||||
cheatsEnabled = !cheatsEnabled;
|
||||
bCheats->msg = cheatsEnabled ? "Cheats: On" : "Cheats: Off";
|
||||
return;
|
||||
}
|
||||
|
||||
if (button == bCreate && !tLevelName.text.empty()) {
|
||||
int seed = getEpochTimeS();
|
||||
if (!tSeed.text.empty()) {
|
||||
std::string seedString = Util::stringTrim(tSeed.text);
|
||||
int tmpSeed;
|
||||
if (sscanf(seedString.c_str(), "%d", &tmpSeed) > 0) {
|
||||
seed = tmpSeed;
|
||||
} else {
|
||||
seed = Util::hashCode(seedString);
|
||||
}
|
||||
}
|
||||
std::string levelId = getUniqueLevelName(tLevelName.text);
|
||||
LevelSettings settings(seed, gamemode, cheatsEnabled);
|
||||
minecraft->selectLevel(levelId, levelId, settings);
|
||||
minecraft->hostMultiplayer();
|
||||
minecraft->setScreen(new ProgressScreen());
|
||||
hasChosen = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (button == bBack) {
|
||||
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleChooseLevelScreen::keyPressed(int eventKey)
|
||||
{
|
||||
if (eventKey == Keyboard::KEY_ESCAPE) {
|
||||
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||
return;
|
||||
}
|
||||
// let base class handle navigation and text box keys
|
||||
Screen::keyPressed(eventKey);
|
||||
}
|
||||
|
||||
bool SimpleChooseLevelScreen::handleBackEvent(bool isDown) {
|
||||
if (!isDown)
|
||||
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||
return true;
|
||||
}
|
||||
#include "SimpleChooseLevelScreen.hpp"
|
||||
#include "ProgressScreen.hpp"
|
||||
#include "ScreenChooser.hpp"
|
||||
#include "client/gui/components/Button.hpp"
|
||||
#include "client/gui/components/ImageButton.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "world/level/LevelSettings.hpp"
|
||||
#include "platform/time.hpp"
|
||||
#include "platform/input/Keyboard.hpp"
|
||||
#include "platform/log.hpp"
|
||||
|
||||
SimpleChooseLevelScreen::SimpleChooseLevelScreen(const std::string& levelName)
|
||||
: bHeader(0),
|
||||
bGamemode(0),
|
||||
bCheats(0),
|
||||
bBack(0),
|
||||
bCreate(0),
|
||||
levelName(levelName),
|
||||
hasChosen(false),
|
||||
gamemode(GameType::Survival),
|
||||
cheatsEnabled(false),
|
||||
tLevelName(0, "World name"),
|
||||
tSeed(1, "World seed")
|
||||
{
|
||||
}
|
||||
|
||||
SimpleChooseLevelScreen::~SimpleChooseLevelScreen()
|
||||
{
|
||||
if (bHeader) delete bHeader;
|
||||
delete bGamemode;
|
||||
delete bCheats;
|
||||
delete bBack;
|
||||
delete bCreate;
|
||||
}
|
||||
|
||||
void SimpleChooseLevelScreen::init()
|
||||
{
|
||||
// make sure the base class loads the existing level list; the
|
||||
// derived screen uses ChooseLevelScreen::getUniqueLevelName(), which
|
||||
// depends on `levels` being populated. omitting this used to result
|
||||
// in duplicate IDs ("creating the second world would load the
|
||||
// first") when the name already existed.
|
||||
ChooseLevelScreen::init();
|
||||
|
||||
tLevelName.text = "New world";
|
||||
|
||||
// header + close button
|
||||
bHeader = new Touch::THeader(0, "Create World");
|
||||
// create the back/X button as ImageButton like CreditsScreen
|
||||
bBack = new ImageButton(2, "");
|
||||
{
|
||||
ImageDef def;
|
||||
def.name = "gui/touchgui.png";
|
||||
def.width = 34;
|
||||
def.height = 26;
|
||||
def.setSrc(IntRectangle(150, 0, (int)def.width, (int)def.height));
|
||||
bBack->setImageDef(def, true);
|
||||
}
|
||||
if (/* minecraft->useTouchscreen() */ true) {
|
||||
bGamemode = new Touch::TButton(1, "Survival mode");
|
||||
bCheats = new Touch::TButton(4, "Cheats: Off");
|
||||
bCreate = new Touch::TButton(3, "Create");
|
||||
} else {
|
||||
bGamemode = new Button(1, "Survival mode");
|
||||
bCheats = new Button(4, "Cheats: Off");
|
||||
bCreate = new Button(3, "Create");
|
||||
}
|
||||
|
||||
buttons.push_back(bHeader);
|
||||
buttons.push_back(bBack);
|
||||
buttons.push_back(bGamemode);
|
||||
buttons.push_back(bCheats);
|
||||
buttons.push_back(bCreate);
|
||||
|
||||
tabButtons.push_back(bGamemode);
|
||||
tabButtons.push_back(bCheats);
|
||||
tabButtons.push_back(bBack);
|
||||
tabButtons.push_back(bCreate);
|
||||
|
||||
textBoxes.push_back(&tLevelName);
|
||||
textBoxes.push_back(&tSeed);
|
||||
}
|
||||
|
||||
void SimpleChooseLevelScreen::setupPositions()
|
||||
{
|
||||
int buttonHeight = bBack->height;
|
||||
|
||||
// position back button in upper-right
|
||||
bBack->x = width - bBack->width;
|
||||
bBack->y = 0;
|
||||
|
||||
// header occupies remaining top bar
|
||||
if (bHeader) {
|
||||
bHeader->x = 0;
|
||||
bHeader->y = 0;
|
||||
bHeader->width = width - bBack->width;
|
||||
bHeader->height = buttonHeight;
|
||||
}
|
||||
|
||||
// layout the form elements below the header
|
||||
int centerX = width / 2;
|
||||
const int padding = 5;
|
||||
|
||||
tLevelName.width = tSeed.width = 200;
|
||||
tLevelName.x = centerX - tLevelName.width / 2;
|
||||
tLevelName.y = buttonHeight + 20;
|
||||
|
||||
tSeed.x = tLevelName.x;
|
||||
tSeed.y = tLevelName.y + 30;
|
||||
|
||||
const int buttonWidth = 120;
|
||||
const int buttonSpacing = 10;
|
||||
const int totalButtonWidth = buttonWidth * 2 + buttonSpacing;
|
||||
|
||||
bGamemode->width = buttonWidth;
|
||||
bCheats->width = buttonWidth;
|
||||
|
||||
bGamemode->x = centerX - totalButtonWidth / 2;
|
||||
bCheats->x = bGamemode->x + buttonWidth + buttonSpacing;
|
||||
|
||||
// compute vertical centre for buttons in remaining space
|
||||
{
|
||||
int bottomPad = 20;
|
||||
int availTop = buttonHeight + 20 + 30 + 10; // just below seed
|
||||
int availBottom = height - bottomPad - bCreate->height - 10; // leave some gap before create
|
||||
int availHeight = availBottom - availTop;
|
||||
if (availHeight < 0) availHeight = 0;
|
||||
int y = availTop + (availHeight - bGamemode->height) / 2;
|
||||
bGamemode->y = y;
|
||||
bCheats->y = y;
|
||||
}
|
||||
|
||||
bCreate->width = 100;
|
||||
bCreate->x = centerX - bCreate->width / 2;
|
||||
int bottomPadding = 20;
|
||||
bCreate->y = height - bottomPadding - bCreate->height;
|
||||
}
|
||||
|
||||
void SimpleChooseLevelScreen::tick()
|
||||
{
|
||||
// let any textboxes handle their own blinking/input
|
||||
for (auto* tb : textBoxes)
|
||||
tb->tick(minecraft);
|
||||
}
|
||||
|
||||
void SimpleChooseLevelScreen::render( int xm, int ym, float a )
|
||||
{
|
||||
renderDirtBackground(0);
|
||||
glEnable2(GL_BLEND);
|
||||
|
||||
const char* modeDesc = NULL;
|
||||
if (gamemode == GameType::Survival) {
|
||||
modeDesc = "Mobs, health and gather resources";
|
||||
} else if (gamemode == GameType::Creative) {
|
||||
modeDesc = "Unlimited resources and flying";
|
||||
}
|
||||
if (modeDesc) {
|
||||
drawCenteredString(minecraft->font, modeDesc, width / 2, bGamemode->y + bGamemode->height + 4, 0xffcccccc);
|
||||
}
|
||||
|
||||
drawString(minecraft->font, "World name:", tLevelName.x, tLevelName.y - Font::DefaultLineHeight - 2, 0xffcccccc);
|
||||
drawString(minecraft->font, "World seed:", tSeed.x, tSeed.y - Font::DefaultLineHeight - 2, 0xffcccccc);
|
||||
|
||||
Screen::render(xm, ym, a);
|
||||
glDisable2(GL_BLEND);
|
||||
}
|
||||
|
||||
// mouse clicks should also manage textbox focus explicitly
|
||||
void SimpleChooseLevelScreen::mouseClicked(int x, int y, int buttonNum)
|
||||
{
|
||||
if (buttonNum == MouseAction::ACTION_LEFT) {
|
||||
// determine if the click landed on either textbox or its label above
|
||||
int lvlTop = tLevelName.y - (Font::DefaultLineHeight + 4);
|
||||
int lvlBottom = tLevelName.y + tLevelName.height;
|
||||
int lvlLeft = tLevelName.x;
|
||||
int lvlRight = tLevelName.x + tLevelName.width;
|
||||
bool clickedLevel = x >= lvlLeft && x < lvlRight && y >= lvlTop && y < lvlBottom;
|
||||
|
||||
int seedTop = tSeed.y - (Font::DefaultLineHeight + 4);
|
||||
int seedBottom = tSeed.y + tSeed.height;
|
||||
int seedLeft = tSeed.x;
|
||||
int seedRight = tSeed.x + tSeed.width;
|
||||
bool clickedSeed = x >= seedLeft && x < seedRight && y >= seedTop && y < seedBottom;
|
||||
|
||||
if (clickedLevel) {
|
||||
LOGI("SimpleChooseLevelScreen: level textbox clicked (%d,%d)\n", x, y);
|
||||
tLevelName.setFocus(minecraft);
|
||||
tSeed.loseFocus(minecraft);
|
||||
} else if (clickedSeed) {
|
||||
LOGI("SimpleChooseLevelScreen: seed textbox clicked (%d,%d)\n", x, y);
|
||||
tSeed.setFocus(minecraft);
|
||||
tLevelName.loseFocus(minecraft);
|
||||
} else {
|
||||
// click outside both fields -> blur both
|
||||
tLevelName.loseFocus(minecraft);
|
||||
tSeed.loseFocus(minecraft);
|
||||
}
|
||||
}
|
||||
|
||||
// allow normal button and textbox handling too
|
||||
Screen::mouseClicked(x, y, buttonNum);
|
||||
}
|
||||
|
||||
void SimpleChooseLevelScreen::buttonClicked( Button* button )
|
||||
{
|
||||
if (hasChosen)
|
||||
return;
|
||||
|
||||
if (button == bGamemode) {
|
||||
gamemode ^= 1;
|
||||
bGamemode->msg = (gamemode == GameType::Survival) ? "Survival mode" : "Creative mode";
|
||||
return;
|
||||
}
|
||||
|
||||
if (button == bCheats) {
|
||||
cheatsEnabled = !cheatsEnabled;
|
||||
bCheats->msg = cheatsEnabled ? "Cheats: On" : "Cheats: Off";
|
||||
return;
|
||||
}
|
||||
|
||||
if (button == bCreate && !tLevelName.text.empty()) {
|
||||
int seed = getEpochTimeS();
|
||||
if (!tSeed.text.empty()) {
|
||||
std::string seedString = Util::stringTrim(tSeed.text);
|
||||
int tmpSeed;
|
||||
if (sscanf(seedString.c_str(), "%d", &tmpSeed) > 0) {
|
||||
seed = tmpSeed;
|
||||
} else {
|
||||
seed = Util::hashCode(seedString);
|
||||
}
|
||||
}
|
||||
std::string levelId = getUniqueLevelName(tLevelName.text);
|
||||
LevelSettings settings(seed, gamemode, cheatsEnabled);
|
||||
minecraft->selectLevel(levelId, levelId, settings);
|
||||
minecraft->hostMultiplayer();
|
||||
minecraft->setScreen(new ProgressScreen());
|
||||
hasChosen = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (button == bBack) {
|
||||
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleChooseLevelScreen::keyPressed(int eventKey)
|
||||
{
|
||||
if (eventKey == Keyboard::KEY_ESCAPE) {
|
||||
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||
return;
|
||||
}
|
||||
// let base class handle navigation and text box keys
|
||||
Screen::keyPressed(eventKey);
|
||||
}
|
||||
|
||||
bool SimpleChooseLevelScreen::handleBackEvent(bool isDown) {
|
||||
if (!isDown)
|
||||
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "ChooseLevelScreen.h"
|
||||
#include "../components/TextBox.h"
|
||||
#include "../components/Button.h" // for Touch::THeader
|
||||
#include "ChooseLevelScreen.hpp"
|
||||
#include "client/gui/components/TextBox.hpp"
|
||||
#include "client/gui/components/Button.hpp" // for Touch::THeader
|
||||
class Button;
|
||||
class ImageButton;
|
||||
|
||||
@@ -1,216 +1,216 @@
|
||||
#include "StartMenuScreen.h"
|
||||
#include "UsernameScreen.h"
|
||||
#include "SelectWorldScreen.h"
|
||||
#include "ProgressScreen.h"
|
||||
#include "JoinGameScreen.h"
|
||||
#include "OptionsScreen.h"
|
||||
#include "PauseScreen.h"
|
||||
#include "PrerenderTilesScreen.h" // test button
|
||||
#include "../components/ImageButton.h"
|
||||
|
||||
#include "../../../util/Mth.h"
|
||||
|
||||
#include "../Font.h"
|
||||
#include "../components/ScrolledSelectionList.h"
|
||||
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../renderer/Tesselator.h"
|
||||
#include "../../../AppPlatform.h"
|
||||
#include "../../../LicenseCodes.h"
|
||||
#include "SimpleChooseLevelScreen.h"
|
||||
#include "../../renderer/Textures.h"
|
||||
#include "../../../SharedConstants.h"
|
||||
|
||||
// Some kind of default settings, might be overridden in ::init
|
||||
StartMenuScreen::StartMenuScreen()
|
||||
: bHost( 2, 0, 0, 160, 24, "Start Game"),
|
||||
bJoin( 3, 0, 0, 160, 24, "Join Game"),
|
||||
bOptions( 4, 0, 0, 160, 24, "Options"),
|
||||
bQuit( 5, "")
|
||||
{
|
||||
}
|
||||
|
||||
StartMenuScreen::~StartMenuScreen()
|
||||
{
|
||||
}
|
||||
|
||||
void StartMenuScreen::init()
|
||||
{
|
||||
bJoin.active = bHost.active = bOptions.active = true;
|
||||
|
||||
if (minecraft->options.getStringValue(OPTIONS_USERNAME).empty()) {
|
||||
return; // tick() will redirect to UsernameScreen
|
||||
}
|
||||
|
||||
buttons.push_back(&bHost);
|
||||
buttons.push_back(&bJoin);
|
||||
//buttons.push_back(&bTest);
|
||||
|
||||
tabButtons.push_back(&bHost);
|
||||
tabButtons.push_back(&bJoin);
|
||||
|
||||
#ifndef RPI
|
||||
buttons.push_back(&bOptions);
|
||||
tabButtons.push_back(&bOptions);
|
||||
#endif
|
||||
|
||||
// add quit button (top right X icon) – match OptionsScreen style
|
||||
{
|
||||
ImageDef def;
|
||||
def.name = "gui/touchgui.png";
|
||||
def.width = 34;
|
||||
def.height = 26;
|
||||
def.setSrc(IntRectangle(150, 0, (int)def.width, (int)def.height));
|
||||
bQuit.setImageDef(def, true);
|
||||
bQuit.scaleWhenPressed = false;
|
||||
buttons.push_back(&bQuit);
|
||||
// don't include in tab navigation
|
||||
}
|
||||
|
||||
copyright = "\xffMojang AB";//. Do not distribute!";
|
||||
|
||||
// always show base version string, suffix was previously added for Android builds
|
||||
std::string versionString = Common::getGameVersionString();
|
||||
|
||||
std::string _username = minecraft->options.getStringValue(OPTIONS_USERNAME);
|
||||
if (_username.empty()) _username = "unknown";
|
||||
|
||||
username = "Username: " + _username;
|
||||
|
||||
#ifdef DEMO_MODE
|
||||
#ifdef __APPLE__
|
||||
version = versionString + " (Lite)";
|
||||
#else
|
||||
version = versionString + " (Demo)";
|
||||
#endif
|
||||
#else
|
||||
#ifdef RPI
|
||||
version = "v0.1.1 alpha";//(MCPE " + versionString + " compatible)";
|
||||
#else
|
||||
version = versionString;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void StartMenuScreen::setupPositions() {
|
||||
int yBase = height / 2;
|
||||
|
||||
bHost.y = yBase;
|
||||
bJoin.y = bHost.y + 24 + 4;
|
||||
bOptions.y = bJoin.y + 24 + 4;
|
||||
|
||||
// Center buttons
|
||||
bHost.x = (width - bHost.width) / 2;
|
||||
bJoin.x = (width - bJoin.width) / 2;
|
||||
bOptions.x = (width - bOptions.width) / 2;
|
||||
|
||||
// position quit icon at top-right (use image-defined size)
|
||||
bQuit.x = width - bQuit.width;
|
||||
bQuit.y = 0;
|
||||
}
|
||||
|
||||
void StartMenuScreen::tick() {
|
||||
}
|
||||
|
||||
void StartMenuScreen::buttonClicked(Button* button) {
|
||||
|
||||
if (button->id == bHost.id)
|
||||
{
|
||||
#if defined(DEMO_MODE) || defined(APPLE_DEMO_PROMOTION)
|
||||
minecraft->setScreen( new SimpleChooseLevelScreen("_DemoLevel") );
|
||||
#else
|
||||
minecraft->screenChooser.setScreen(SCREEN_SELECTWORLD);
|
||||
#endif
|
||||
}
|
||||
if (button->id == bJoin.id)
|
||||
{
|
||||
minecraft->locateMultiplayer();
|
||||
minecraft->screenChooser.setScreen(SCREEN_JOINGAME);
|
||||
}
|
||||
if (button->id == bOptions.id)
|
||||
{
|
||||
minecraft->setScreen(new OptionsScreen());
|
||||
}
|
||||
if (button == &bQuit)
|
||||
{
|
||||
minecraft->quit();
|
||||
}
|
||||
}
|
||||
|
||||
bool StartMenuScreen::isInGameScreen() { return false; }
|
||||
|
||||
void StartMenuScreen::render( int xm, int ym, float a )
|
||||
{
|
||||
renderBackground();
|
||||
|
||||
// Show current username in the top-left corner
|
||||
drawString(font, username, 2, 2, 0xffffffff);
|
||||
|
||||
#if defined(RPI)
|
||||
TextureId id = minecraft->textures->loadTexture("gui/pi_title.png");
|
||||
#else
|
||||
TextureId id = minecraft->textures->loadTexture("gui/title.png");
|
||||
#endif
|
||||
const TextureData* data = minecraft->textures->getTemporaryTextureData(id);
|
||||
|
||||
if (data) {
|
||||
minecraft->textures->bind(id);
|
||||
|
||||
const float x = (float)width / 2;
|
||||
const float y = height/16;
|
||||
//const float scale = Mth::Min(
|
||||
const float wh = Mth::Min((float)width/2.0f, (float)data->w / 2);
|
||||
const float scale = 2.0f * wh / (float)data->w;
|
||||
const float h = scale * (float)data->h;
|
||||
|
||||
// Render title text
|
||||
Tesselator& t = Tesselator::instance;
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
t.begin();
|
||||
t.vertexUV(x-wh, y+h, blitOffset, 0, 1);
|
||||
t.vertexUV(x+wh, y+h, blitOffset, 1, 1);
|
||||
t.vertexUV(x+wh, y+0, blitOffset, 1, 0);
|
||||
t.vertexUV(x-wh, y+0, blitOffset, 0, 0);
|
||||
t.draw();
|
||||
}
|
||||
|
||||
#if defined(RPI)
|
||||
if (Textures::isTextureIdValid(minecraft->textures->loadAndBindTexture("gui/logo/raknet_high_72.png")))
|
||||
blit(0, height - 12, 0, 0, 43, 12, 256, 72+72);
|
||||
#endif
|
||||
|
||||
drawString(font, version, width - font->width(version) - 2, height - 10, 0xffcccccc);//0x666666);
|
||||
drawString(font, copyright, 2, height - 20, 0xffffff);
|
||||
glEnable2(GL_BLEND);
|
||||
glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
if (Textures::isTextureIdValid(minecraft->textures->loadAndBindTexture("gui/logo/github.png")))
|
||||
blit(2, height - 10, 0, 0, 8, 8, 256, 256);
|
||||
{
|
||||
std::string txt = "Kolyah35/minecraft-pe-0.6.1";
|
||||
float wtxt = font->width(txt);
|
||||
Gui::drawColoredString(font, txt, 12, height - 10, 255);
|
||||
// underline link
|
||||
float y0 = height - 10 + font->lineHeight - 1;
|
||||
this->fill(12, (int)y0, 12 + (int)wtxt, (int)(y0 + 1), 0xffffffff);
|
||||
}
|
||||
|
||||
|
||||
Screen::render(xm, ym, a);
|
||||
}
|
||||
|
||||
void StartMenuScreen::mouseClicked(int x, int y, int buttonNum) {
|
||||
const int logoX = 2;
|
||||
const int logoW = 8 + 2 + font->width("Kolyah35/minecraft-pe-0.6.1");
|
||||
const int logoY = height - 10;
|
||||
const int logoH = 10;
|
||||
if (x >= logoX && x <= logoX + logoW && y >= logoY && y <= logoY + logoH)
|
||||
minecraft->platform()->openURL("https://gitea.sffempire.ru/Kolyah35/minecraft-pe-0.6.1");
|
||||
else
|
||||
Screen::mouseClicked(x, y, buttonNum);
|
||||
}
|
||||
|
||||
bool StartMenuScreen::handleBackEvent( bool isDown ) {
|
||||
minecraft->quit();
|
||||
return true;
|
||||
}
|
||||
#include "StartMenuScreen.hpp"
|
||||
#include "UsernameScreen.hpp"
|
||||
#include "SelectWorldScreen.hpp"
|
||||
#include "ProgressScreen.hpp"
|
||||
#include "JoinGameScreen.hpp"
|
||||
#include "OptionsScreen.hpp"
|
||||
#include "PauseScreen.hpp"
|
||||
#include "PrerenderTilesScreen.hpp" // test button
|
||||
#include "client/gui/components/ImageButton.hpp"
|
||||
|
||||
#include "util/Mth.hpp"
|
||||
|
||||
#include "client/gui/Font.hpp"
|
||||
#include "client/gui/components/ScrolledSelectionList.hpp"
|
||||
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "client/renderer/Tesselator.hpp"
|
||||
#include "AppPlatform.hpp"
|
||||
#include "LicenseCodes.hpp"
|
||||
#include "SimpleChooseLevelScreen.hpp"
|
||||
#include "client/renderer/Textures.hpp"
|
||||
#include "SharedConstants.hpp"
|
||||
|
||||
// Some kind of default settings, might be overridden in ::init
|
||||
StartMenuScreen::StartMenuScreen()
|
||||
: bHost( 2, 0, 0, 160, 24, "Start Game"),
|
||||
bJoin( 3, 0, 0, 160, 24, "Join Game"),
|
||||
bOptions( 4, 0, 0, 160, 24, "Options"),
|
||||
bQuit( 5, "")
|
||||
{
|
||||
}
|
||||
|
||||
StartMenuScreen::~StartMenuScreen()
|
||||
{
|
||||
}
|
||||
|
||||
void StartMenuScreen::init()
|
||||
{
|
||||
bJoin.active = bHost.active = bOptions.active = true;
|
||||
|
||||
if (minecraft->options.getStringValue(OPTIONS_USERNAME).empty()) {
|
||||
return; // tick() will redirect to UsernameScreen
|
||||
}
|
||||
|
||||
buttons.push_back(&bHost);
|
||||
buttons.push_back(&bJoin);
|
||||
//buttons.push_back(&bTest);
|
||||
|
||||
tabButtons.push_back(&bHost);
|
||||
tabButtons.push_back(&bJoin);
|
||||
|
||||
#ifndef RPI
|
||||
buttons.push_back(&bOptions);
|
||||
tabButtons.push_back(&bOptions);
|
||||
#endif
|
||||
|
||||
// add quit button (top right X icon) – match OptionsScreen style
|
||||
{
|
||||
ImageDef def;
|
||||
def.name = "gui/touchgui.png";
|
||||
def.width = 34;
|
||||
def.height = 26;
|
||||
def.setSrc(IntRectangle(150, 0, (int)def.width, (int)def.height));
|
||||
bQuit.setImageDef(def, true);
|
||||
bQuit.scaleWhenPressed = false;
|
||||
buttons.push_back(&bQuit);
|
||||
// don't include in tab navigation
|
||||
}
|
||||
|
||||
copyright = "\xffMojang AB";//. Do not distribute!";
|
||||
|
||||
// always show base version string, suffix was previously added for Android builds
|
||||
std::string versionString = Common::getGameVersionString();
|
||||
|
||||
std::string _username = minecraft->options.getStringValue(OPTIONS_USERNAME);
|
||||
if (_username.empty()) _username = "unknown";
|
||||
|
||||
username = "Username: " + _username;
|
||||
|
||||
#ifdef DEMO_MODE
|
||||
#ifdef __APPLE__
|
||||
version = versionString + " (Lite)";
|
||||
#else
|
||||
version = versionString + " (Demo)";
|
||||
#endif
|
||||
#else
|
||||
#ifdef RPI
|
||||
version = "v0.1.1 alpha";//(MCPE " + versionString + " compatible)";
|
||||
#else
|
||||
version = versionString;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void StartMenuScreen::setupPositions() {
|
||||
int yBase = height / 2;
|
||||
|
||||
bHost.y = yBase;
|
||||
bJoin.y = bHost.y + 24 + 4;
|
||||
bOptions.y = bJoin.y + 24 + 4;
|
||||
|
||||
// Center buttons
|
||||
bHost.x = (width - bHost.width) / 2;
|
||||
bJoin.x = (width - bJoin.width) / 2;
|
||||
bOptions.x = (width - bOptions.width) / 2;
|
||||
|
||||
// position quit icon at top-right (use image-defined size)
|
||||
bQuit.x = width - bQuit.width;
|
||||
bQuit.y = 0;
|
||||
}
|
||||
|
||||
void StartMenuScreen::tick() {
|
||||
}
|
||||
|
||||
void StartMenuScreen::buttonClicked(Button* button) {
|
||||
|
||||
if (button->id == bHost.id)
|
||||
{
|
||||
#if defined(DEMO_MODE) || defined(APPLE_DEMO_PROMOTION)
|
||||
minecraft->setScreen( new SimpleChooseLevelScreen("_DemoLevel") );
|
||||
#else
|
||||
minecraft->screenChooser.setScreen(SCREEN_SELECTWORLD);
|
||||
#endif
|
||||
}
|
||||
if (button->id == bJoin.id)
|
||||
{
|
||||
minecraft->locateMultiplayer();
|
||||
minecraft->screenChooser.setScreen(SCREEN_JOINGAME);
|
||||
}
|
||||
if (button->id == bOptions.id)
|
||||
{
|
||||
minecraft->setScreen(new OptionsScreen());
|
||||
}
|
||||
if (button == &bQuit)
|
||||
{
|
||||
minecraft->quit();
|
||||
}
|
||||
}
|
||||
|
||||
bool StartMenuScreen::isInGameScreen() { return false; }
|
||||
|
||||
void StartMenuScreen::render( int xm, int ym, float a )
|
||||
{
|
||||
renderBackground();
|
||||
|
||||
// Show current username in the top-left corner
|
||||
drawString(font, username, 2, 2, 0xffffffff);
|
||||
|
||||
#if defined(RPI)
|
||||
TextureId id = minecraft->textures->loadTexture("gui/pi_title.png");
|
||||
#else
|
||||
TextureId id = minecraft->textures->loadTexture("gui/title.png");
|
||||
#endif
|
||||
const TextureData* data = minecraft->textures->getTemporaryTextureData(id);
|
||||
|
||||
if (data) {
|
||||
minecraft->textures->bind(id);
|
||||
|
||||
const float x = (float)width / 2;
|
||||
const float y = height/16;
|
||||
//const float scale = Mth::Min(
|
||||
const float wh = Mth::Min((float)width/2.0f, (float)data->w / 2);
|
||||
const float scale = 2.0f * wh / (float)data->w;
|
||||
const float h = scale * (float)data->h;
|
||||
|
||||
// Render title text
|
||||
Tesselator& t = Tesselator::instance;
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
t.begin();
|
||||
t.vertexUV(x-wh, y+h, blitOffset, 0, 1);
|
||||
t.vertexUV(x+wh, y+h, blitOffset, 1, 1);
|
||||
t.vertexUV(x+wh, y+0, blitOffset, 1, 0);
|
||||
t.vertexUV(x-wh, y+0, blitOffset, 0, 0);
|
||||
t.draw();
|
||||
}
|
||||
|
||||
#if defined(RPI)
|
||||
if (Textures::isTextureIdValid(minecraft->textures->loadAndBindTexture("gui/logo/raknet_high_72.png")))
|
||||
blit(0, height - 12, 0, 0, 43, 12, 256, 72+72);
|
||||
#endif
|
||||
|
||||
drawString(font, version, width - font->width(version) - 2, height - 10, 0xffcccccc);//0x666666);
|
||||
drawString(font, copyright, 2, height - 20, 0xffffff);
|
||||
glEnable2(GL_BLEND);
|
||||
glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
if (Textures::isTextureIdValid(minecraft->textures->loadAndBindTexture("gui/logo/github.png")))
|
||||
blit(2, height - 10, 0, 0, 8, 8, 256, 256);
|
||||
{
|
||||
std::string txt = "Kolyah35/minecraft-pe-0.6.1";
|
||||
float wtxt = font->width(txt);
|
||||
Gui::drawColoredString(font, txt, 12, height - 10, 255);
|
||||
// underline link
|
||||
float y0 = height - 10 + font->lineHeight - 1;
|
||||
this->fill(12, (int)y0, 12 + (int)wtxt, (int)(y0 + 1), 0xffffffff);
|
||||
}
|
||||
|
||||
|
||||
Screen::render(xm, ym, a);
|
||||
}
|
||||
|
||||
void StartMenuScreen::mouseClicked(int x, int y, int buttonNum) {
|
||||
const int logoX = 2;
|
||||
const int logoW = 8 + 2 + font->width("Kolyah35/minecraft-pe-0.6.1");
|
||||
const int logoY = height - 10;
|
||||
const int logoH = 10;
|
||||
if (x >= logoX && x <= logoX + logoW && y >= logoY && y <= logoY + logoH)
|
||||
minecraft->platform()->openURL("https://gitea.sffempire.ru/Kolyah35/minecraft-pe-0.6.1");
|
||||
else
|
||||
Screen::mouseClicked(x, y, buttonNum);
|
||||
}
|
||||
|
||||
bool StartMenuScreen::handleBackEvent( bool isDown ) {
|
||||
minecraft->quit();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Screen.h"
|
||||
#include "../components/Button.h"
|
||||
#include "../components/ImageButton.h"
|
||||
#include "client/gui/Screen.hpp"
|
||||
#include "client/gui/components/Button.hpp"
|
||||
#include "client/gui/components/ImageButton.hpp"
|
||||
|
||||
class StartMenuScreen: public Screen
|
||||
{
|
||||
@@ -1,146 +1,146 @@
|
||||
#include "TextEditScreen.h"
|
||||
#include "../../../world/level/tile/entity/SignTileEntity.h"
|
||||
#include "../../../AppPlatform.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../renderer/tileentity/TileEntityRenderDispatcher.h"
|
||||
#include "../../renderer/Tesselator.h"
|
||||
#include "../../renderer/Textures.h"
|
||||
#include "../../renderer/GameRenderer.h"
|
||||
#include "../components/Button.h"
|
||||
#include "../../../network/Packet.h"
|
||||
#include "../../../network/RakNetInstance.h"
|
||||
TextEditScreen::TextEditScreen( SignTileEntity* signEntity )
|
||||
: sign(signEntity), isShowingKeyboard(false), frame(0), line(0), btnClose(1, "") {
|
||||
|
||||
}
|
||||
TextEditScreen::~TextEditScreen() {
|
||||
|
||||
}
|
||||
void TextEditScreen::init() {
|
||||
super::init();
|
||||
minecraft->platform()->showKeyboard();
|
||||
isShowingKeyboard = true;
|
||||
ImageDef def;
|
||||
def.name = "gui/spritesheet.png";
|
||||
def.x = 0;
|
||||
def.y = 1;
|
||||
def.width = def.height = 18;
|
||||
def.setSrc(IntRectangle(60, 0, 18, 18));
|
||||
btnClose.setImageDef(def, true);
|
||||
btnClose.scaleWhenPressed = false;
|
||||
buttons.push_back(&btnClose);
|
||||
}
|
||||
|
||||
void TextEditScreen::setupPositions() {
|
||||
btnClose.width = btnClose.height = 19;
|
||||
btnClose.x = width - btnClose.width;
|
||||
btnClose.y = 0;
|
||||
}
|
||||
|
||||
|
||||
bool TextEditScreen::handleBackEvent( bool isDown ) {
|
||||
sign->setChanged();
|
||||
Packet* signUpdatePacket = sign->getUpdatePacket();
|
||||
minecraft->raknetInstance->send(signUpdatePacket);
|
||||
minecraft->platform()->hideKeyboard();
|
||||
minecraft->setScreen(NULL);
|
||||
return true;
|
||||
}
|
||||
|
||||
void TextEditScreen::render( int xm, int ym, float a ) {
|
||||
glDepthMask(GL_FALSE);
|
||||
renderBackground();
|
||||
glPushMatrix();
|
||||
glDepthMask(GL_TRUE);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glLoadIdentity();
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glOrthof(0.0f, (float)minecraft->width, (float)minecraft->height, 0, -1, 1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
minecraft->textures->loadAndBindTexture("item/sign.png");
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
|
||||
static float minUV[] = {0.03126f, 0.06249f};
|
||||
static float maxUV[] = {0.39063f, 0.4374f};
|
||||
float scale = ((minecraft->height / 2) / 32) * 0.9f;
|
||||
|
||||
glTranslatef(minecraft->width / 2.0f, 5.0f, 0.0f);
|
||||
glScalef2(scale,scale,1);
|
||||
t.begin(GL_QUADS);
|
||||
t.vertexUV(-32, 0, 0.0f,minUV[0],minUV[1]);
|
||||
t.vertexUV(32, 0, 0.0f, maxUV[0], minUV[1]);
|
||||
t.vertexUV(32, 0 + 32, 0.0f, maxUV[0], maxUV[1]);
|
||||
t.vertexUV(-32, 0 + 32, 0.0f, minUV[0], maxUV[1]);
|
||||
t.draw();
|
||||
|
||||
sign->selectedLine = line;
|
||||
float textScale = 8.0f / 11.0f;
|
||||
|
||||
glTranslatef(0, 2 ,0);
|
||||
glScalef2(textScale, textScale, 1);
|
||||
for(int i = 0; i < 4; ++i) {
|
||||
//drawCenteredString(font, sign->messages[a], 32.0f, 10 * a, 0xFF000000);
|
||||
std::string msg = sign->messages[i];
|
||||
if (i == sign->selectedLine && msg.length() < 14) {
|
||||
std::string s = "> " + msg + " <";
|
||||
font->draw(s, -(float)font->width(s) / 2.0f, 10.0f * i, 0xFF000000, false);
|
||||
} else {
|
||||
font->draw(msg, -(float)font->width(msg) / 2.0f, 10.0f * i, 0xFF000000, false);
|
||||
}
|
||||
}
|
||||
sign->selectedLine = -1;
|
||||
//font->draw("Hej", minecraft->width / 2, 100, 0xFFFFFFFF, false);
|
||||
|
||||
glPopMatrix();
|
||||
glEnable(GL_CULL_FACE);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
//glEnable(GL_DEPTH_TEST);
|
||||
super::render(xm, ym, a);
|
||||
}
|
||||
|
||||
void TextEditScreen::lostFocus() {
|
||||
|
||||
}
|
||||
|
||||
void TextEditScreen::tick() {
|
||||
frame++;
|
||||
}
|
||||
|
||||
void TextEditScreen::keyPressed( int eventKey ) {
|
||||
LOGW("Key pressed! [%d]", eventKey);
|
||||
if(eventKey == Keyboard::KEY_BACKSPACE) {
|
||||
if(sign->messages[line].length() > 0) {
|
||||
sign->messages[line].erase(sign->messages[line].size() - 1, 1);
|
||||
} else {
|
||||
line--;
|
||||
if(line < 0) {
|
||||
line = 3;
|
||||
}
|
||||
}
|
||||
} else if(eventKey == Keyboard::KEY_RETURN) {
|
||||
line = (line + 1) % 4;
|
||||
} else {
|
||||
super::keyPressed(eventKey);
|
||||
}
|
||||
}
|
||||
|
||||
void TextEditScreen::charPressed( char inputChar ) {
|
||||
std::string fullstring = sign->messages[line] + inputChar;
|
||||
if(fullstring.length() < 16) {
|
||||
sign->messages[line] = fullstring;
|
||||
//LOGW("Line text updated: %s\n", fullstring.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void TextEditScreen::buttonClicked( Button* button ) {
|
||||
if(button == &btnClose)
|
||||
handleBackEvent(true);
|
||||
}
|
||||
#include "TextEditScreen.hpp"
|
||||
#include "world/level/tile/entity/SignTileEntity.hpp"
|
||||
#include "AppPlatform.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "client/renderer/tileentity/TileEntityRenderDispatcher.hpp"
|
||||
#include "client/renderer/Tesselator.hpp"
|
||||
#include "client/renderer/Textures.hpp"
|
||||
#include "client/renderer/GameRenderer.hpp"
|
||||
#include "client/gui/components/Button.hpp"
|
||||
#include "network/Packet.hpp"
|
||||
#include "network/RakNetInstance.hpp"
|
||||
TextEditScreen::TextEditScreen( SignTileEntity* signEntity )
|
||||
: sign(signEntity), isShowingKeyboard(false), frame(0), line(0), btnClose(1, "") {
|
||||
|
||||
}
|
||||
TextEditScreen::~TextEditScreen() {
|
||||
|
||||
}
|
||||
void TextEditScreen::init() {
|
||||
super::init();
|
||||
minecraft->platform()->showKeyboard();
|
||||
isShowingKeyboard = true;
|
||||
ImageDef def;
|
||||
def.name = "gui/spritesheet.png";
|
||||
def.x = 0;
|
||||
def.y = 1;
|
||||
def.width = def.height = 18;
|
||||
def.setSrc(IntRectangle(60, 0, 18, 18));
|
||||
btnClose.setImageDef(def, true);
|
||||
btnClose.scaleWhenPressed = false;
|
||||
buttons.push_back(&btnClose);
|
||||
}
|
||||
|
||||
void TextEditScreen::setupPositions() {
|
||||
btnClose.width = btnClose.height = 19;
|
||||
btnClose.x = width - btnClose.width;
|
||||
btnClose.y = 0;
|
||||
}
|
||||
|
||||
|
||||
bool TextEditScreen::handleBackEvent( bool isDown ) {
|
||||
sign->setChanged();
|
||||
Packet* signUpdatePacket = sign->getUpdatePacket();
|
||||
minecraft->raknetInstance->send(signUpdatePacket);
|
||||
minecraft->platform()->hideKeyboard();
|
||||
minecraft->setScreen(NULL);
|
||||
return true;
|
||||
}
|
||||
|
||||
void TextEditScreen::render( int xm, int ym, float a ) {
|
||||
glDepthMask(GL_FALSE);
|
||||
renderBackground();
|
||||
glPushMatrix();
|
||||
glDepthMask(GL_TRUE);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glLoadIdentity();
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glOrthof(0.0f, (float)minecraft->width, (float)minecraft->height, 0, -1, 1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
minecraft->textures->loadAndBindTexture("item/sign.png");
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
|
||||
static float minUV[] = {0.03126f, 0.06249f};
|
||||
static float maxUV[] = {0.39063f, 0.4374f};
|
||||
float scale = ((minecraft->height / 2) / 32) * 0.9f;
|
||||
|
||||
glTranslatef(minecraft->width / 2.0f, 5.0f, 0.0f);
|
||||
glScalef2(scale,scale,1);
|
||||
t.begin(GL_QUADS);
|
||||
t.vertexUV(-32, 0, 0.0f,minUV[0],minUV[1]);
|
||||
t.vertexUV(32, 0, 0.0f, maxUV[0], minUV[1]);
|
||||
t.vertexUV(32, 0 + 32, 0.0f, maxUV[0], maxUV[1]);
|
||||
t.vertexUV(-32, 0 + 32, 0.0f, minUV[0], maxUV[1]);
|
||||
t.draw();
|
||||
|
||||
sign->selectedLine = line;
|
||||
float textScale = 8.0f / 11.0f;
|
||||
|
||||
glTranslatef(0, 2 ,0);
|
||||
glScalef2(textScale, textScale, 1);
|
||||
for(int i = 0; i < 4; ++i) {
|
||||
//drawCenteredString(font, sign->messages[a], 32.0f, 10 * a, 0xFF000000);
|
||||
std::string msg = sign->messages[i];
|
||||
if (i == sign->selectedLine && msg.length() < 14) {
|
||||
std::string s = "> " + msg + " <";
|
||||
font->draw(s, -(float)font->width(s) / 2.0f, 10.0f * i, 0xFF000000, false);
|
||||
} else {
|
||||
font->draw(msg, -(float)font->width(msg) / 2.0f, 10.0f * i, 0xFF000000, false);
|
||||
}
|
||||
}
|
||||
sign->selectedLine = -1;
|
||||
//font->draw("Hej", minecraft->width / 2, 100, 0xFFFFFFFF, false);
|
||||
|
||||
glPopMatrix();
|
||||
glEnable(GL_CULL_FACE);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
//glEnable(GL_DEPTH_TEST);
|
||||
super::render(xm, ym, a);
|
||||
}
|
||||
|
||||
void TextEditScreen::lostFocus() {
|
||||
|
||||
}
|
||||
|
||||
void TextEditScreen::tick() {
|
||||
frame++;
|
||||
}
|
||||
|
||||
void TextEditScreen::keyPressed( int eventKey ) {
|
||||
LOGW("Key pressed! [%d]", eventKey);
|
||||
if(eventKey == Keyboard::KEY_BACKSPACE) {
|
||||
if(sign->messages[line].length() > 0) {
|
||||
sign->messages[line].erase(sign->messages[line].size() - 1, 1);
|
||||
} else {
|
||||
line--;
|
||||
if(line < 0) {
|
||||
line = 3;
|
||||
}
|
||||
}
|
||||
} else if(eventKey == Keyboard::KEY_RETURN) {
|
||||
line = (line + 1) % 4;
|
||||
} else {
|
||||
super::keyPressed(eventKey);
|
||||
}
|
||||
}
|
||||
|
||||
void TextEditScreen::charPressed( char inputChar ) {
|
||||
std::string fullstring = sign->messages[line] + inputChar;
|
||||
if(fullstring.length() < 16) {
|
||||
sign->messages[line] = fullstring;
|
||||
//LOGW("Line text updated: %s\n", fullstring.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void TextEditScreen::buttonClicked( Button* button ) {
|
||||
if(button == &btnClose)
|
||||
handleBackEvent(true);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
//package net.minecraft.client.gui;
|
||||
|
||||
#include "../Screen.h"
|
||||
#include "client/gui/Screen.hpp"
|
||||
#include <string>
|
||||
#include "../components/ImageButton.h"
|
||||
#include "client/gui/components/ImageButton.hpp"
|
||||
class SignTileEntity;
|
||||
class Button;
|
||||
class TextEditScreen: public Screen
|
||||
@@ -1,177 +1,177 @@
|
||||
#if 0
|
||||
|
||||
#include "UploadPhotoScreen.h"
|
||||
#include "../renderer/TileRenderer.h"
|
||||
#include "../player/LocalPlayer.h"
|
||||
#include "../../world/entity/player/Inventory.h"
|
||||
|
||||
UploadPhotoScreen::UploadPhotoScreen()
|
||||
:
|
||||
selectedItem(0)
|
||||
{
|
||||
}
|
||||
|
||||
void UploadPhotoScreen::init()
|
||||
{
|
||||
int currentSelection = minecraft->player->inventory->getSelectedItemId();
|
||||
for (int i = 0; i < Inventory::INVENTORY_SIZE; i++)
|
||||
{
|
||||
if (currentSelection == minecraft->player->inventory->getSelectionSlotItemId(i + Inventory::SELECTION_SIZE))
|
||||
{
|
||||
selectedItem = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void UploadPhotoScreen::renderSlots()
|
||||
{
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
|
||||
blitOffset = -90;
|
||||
|
||||
minecraft->textures->loadAndBindTexture("gui/gui.png");
|
||||
for (int r = 0; r < Inventory::INVENTORY_ROWS; r++)
|
||||
{
|
||||
blit(width / 2 - 182 / 2, height - 22 * 3 - 22 * r, 0, 0, 182, 22);
|
||||
}
|
||||
if (selectedItem >= 0)
|
||||
{
|
||||
int x = width / 2 - 182 / 2 - 1 + (selectedItem % Inventory::SELECTION_SIZE) * 20;
|
||||
int y = height - 22 * 3 - 1 - (selectedItem / Inventory::SELECTION_SIZE) * 22;
|
||||
blit(x, y, 0, 22, 24, 22);
|
||||
}
|
||||
|
||||
for (int r = 0; r < Inventory::INVENTORY_ROWS; r++)
|
||||
{
|
||||
for (int i = 0; i < 9; i++) {
|
||||
int x = width / 2 - 9 * 10 + i * 20 + 2;
|
||||
int y = height - 16 - 3 - 22 * 2 - 22 * r;
|
||||
renderSlot(r * 9 + i + Inventory::SELECTION_SIZE, x, y, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void UploadPhotoScreen::renderSlot(int slot, int x, int y, float a)
|
||||
{
|
||||
int itemId = minecraft->player->inventory->getSelectionSlotItemId(slot);
|
||||
if (itemId < 0) return;
|
||||
|
||||
const bool fancy = false;
|
||||
|
||||
if (fancy && itemId < 256 && TileRenderer::canRender(Tile::tiles[itemId]->getRenderShape())) {
|
||||
|
||||
} else {
|
||||
if (itemId < 256) {
|
||||
Tile* tile = Tile::tiles[itemId];
|
||||
if (tile == NULL) return;
|
||||
|
||||
minecraft->textures->loadAndBindTexture("terrain.png");
|
||||
|
||||
int textureId = tile->getTexture(2, 0);
|
||||
blit(x, y, textureId % 16 * 16, textureId / 16 * 16, 16, 16);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void UploadPhotoScreen::keyPressed(int eventKey)
|
||||
{
|
||||
int selX = selectedItem % Inventory::SELECTION_SIZE;
|
||||
int selY = selectedItem / Inventory::SELECTION_SIZE;
|
||||
|
||||
Options& o = minecraft->options;
|
||||
if (eventKey == o.keyLeft.key && selX > 0)
|
||||
{
|
||||
selectedItem -= 1;
|
||||
}
|
||||
else if (eventKey == o.keyRight.key && selX < (Inventory::SELECTION_SIZE - 1))
|
||||
{
|
||||
selectedItem += 1;
|
||||
}
|
||||
else if (eventKey == o.keyDown.key && selY > 0)
|
||||
{
|
||||
selectedItem -= Inventory::SELECTION_SIZE;
|
||||
}
|
||||
else if (eventKey == o.keyUp.key && selY < (Inventory::INVENTORY_ROWS - 1))
|
||||
{
|
||||
selectedItem += Inventory::SELECTION_SIZE;
|
||||
}
|
||||
|
||||
if (eventKey == o.keyMenuOk.key)
|
||||
{
|
||||
selectSlotAndClose();
|
||||
}
|
||||
}
|
||||
|
||||
int UploadPhotoScreen::getSelectedSlot(int x, int y)
|
||||
{
|
||||
int left = 3 + width / 2 - Inventory::SELECTION_SIZE * 10;
|
||||
int top = height - 16 - 3 - 22 * 2 - 22 * Inventory::INVENTORY_ROWS;
|
||||
|
||||
if (x >= left && y >= top)
|
||||
{
|
||||
int xSlot = (x - left) / 20;
|
||||
if (xSlot < Inventory::SELECTION_SIZE)
|
||||
{
|
||||
// rows are rendered upsidedown
|
||||
return xSlot + Inventory::INVENTORY_SIZE - ((y - top) / 22) * Inventory::SELECTION_SIZE;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void UploadPhotoScreen::mouseClicked(int x, int y, int buttonNum) {
|
||||
if (buttonNum == MouseAction::ACTION_LEFT) {
|
||||
|
||||
int slot = getSelectedSlot(x, y);
|
||||
if (slot >= 0 && slot < Inventory::INVENTORY_SIZE)
|
||||
{
|
||||
selectedItem = slot;
|
||||
//minecraft->soundEngine->playUI("random.click", 1, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UploadPhotoScreen::mouseReleased(int x, int y, int buttonNum)
|
||||
{
|
||||
if (buttonNum == MouseAction::ACTION_LEFT) {
|
||||
|
||||
int slot = getSelectedSlot(x, y);
|
||||
if (slot >= 0 && slot < Inventory::INVENTORY_SIZE && slot == selectedItem)
|
||||
{
|
||||
selectSlotAndClose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UploadPhotoScreen::selectSlotAndClose()
|
||||
{
|
||||
Inventory* inventory = minecraft->player->inventory;
|
||||
|
||||
int itemId = inventory->getSelectionSlotItemId(selectedItem + Inventory::SELECTION_SIZE);
|
||||
int i = 0;
|
||||
|
||||
for (; i < Inventory::SELECTION_SIZE - 2; i++)
|
||||
{
|
||||
if (itemId == inventory->getSelectionSlotItemId(i))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// update selection list
|
||||
for (; i >= 1; i--)
|
||||
{
|
||||
inventory->setSelectionSlotItemId(i, inventory->getSelectionSlotItemId(i - 1));
|
||||
}
|
||||
inventory->setSelectionSlotItemId(0, itemId);
|
||||
inventory->selectSlot(0);
|
||||
|
||||
minecraft->soundEngine->playUI("random.click", 1, 1);
|
||||
minecraft->setScreen(NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
#if 0
|
||||
|
||||
#include "UploadPhotoScreen.hpp"
|
||||
#include "client/gui/renderer/TileRenderer.hpp"
|
||||
#include "client/gui/player/LocalPlayer.hpp"
|
||||
#include "client/world/entity/player/Inventory.hpp"
|
||||
|
||||
UploadPhotoScreen::UploadPhotoScreen()
|
||||
:
|
||||
selectedItem(0)
|
||||
{
|
||||
}
|
||||
|
||||
void UploadPhotoScreen::init()
|
||||
{
|
||||
int currentSelection = minecraft->player->inventory->getSelectedItemId();
|
||||
for (int i = 0; i < Inventory::INVENTORY_SIZE; i++)
|
||||
{
|
||||
if (currentSelection == minecraft->player->inventory->getSelectionSlotItemId(i + Inventory::SELECTION_SIZE))
|
||||
{
|
||||
selectedItem = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void UploadPhotoScreen::renderSlots()
|
||||
{
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
|
||||
blitOffset = -90;
|
||||
|
||||
minecraft->textures->loadAndBindTexture("gui/gui.png");
|
||||
for (int r = 0; r < Inventory::INVENTORY_ROWS; r++)
|
||||
{
|
||||
blit(width / 2 - 182 / 2, height - 22 * 3 - 22 * r, 0, 0, 182, 22);
|
||||
}
|
||||
if (selectedItem >= 0)
|
||||
{
|
||||
int x = width / 2 - 182 / 2 - 1 + (selectedItem % Inventory::SELECTION_SIZE) * 20;
|
||||
int y = height - 22 * 3 - 1 - (selectedItem / Inventory::SELECTION_SIZE) * 22;
|
||||
blit(x, y, 0, 22, 24, 22);
|
||||
}
|
||||
|
||||
for (int r = 0; r < Inventory::INVENTORY_ROWS; r++)
|
||||
{
|
||||
for (int i = 0; i < 9; i++) {
|
||||
int x = width / 2 - 9 * 10 + i * 20 + 2;
|
||||
int y = height - 16 - 3 - 22 * 2 - 22 * r;
|
||||
renderSlot(r * 9 + i + Inventory::SELECTION_SIZE, x, y, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void UploadPhotoScreen::renderSlot(int slot, int x, int y, float a)
|
||||
{
|
||||
int itemId = minecraft->player->inventory->getSelectionSlotItemId(slot);
|
||||
if (itemId < 0) return;
|
||||
|
||||
const bool fancy = false;
|
||||
|
||||
if (fancy && itemId < 256 && TileRenderer::canRender(Tile::tiles[itemId]->getRenderShape())) {
|
||||
|
||||
} else {
|
||||
if (itemId < 256) {
|
||||
Tile* tile = Tile::tiles[itemId];
|
||||
if (tile == NULL) return;
|
||||
|
||||
minecraft->textures->loadAndBindTexture("terrain.png");
|
||||
|
||||
int textureId = tile->getTexture(2, 0);
|
||||
blit(x, y, textureId % 16 * 16, textureId / 16 * 16, 16, 16);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void UploadPhotoScreen::keyPressed(int eventKey)
|
||||
{
|
||||
int selX = selectedItem % Inventory::SELECTION_SIZE;
|
||||
int selY = selectedItem / Inventory::SELECTION_SIZE;
|
||||
|
||||
Options& o = minecraft->options;
|
||||
if (eventKey == o.keyLeft.key && selX > 0)
|
||||
{
|
||||
selectedItem -= 1;
|
||||
}
|
||||
else if (eventKey == o.keyRight.key && selX < (Inventory::SELECTION_SIZE - 1))
|
||||
{
|
||||
selectedItem += 1;
|
||||
}
|
||||
else if (eventKey == o.keyDown.key && selY > 0)
|
||||
{
|
||||
selectedItem -= Inventory::SELECTION_SIZE;
|
||||
}
|
||||
else if (eventKey == o.keyUp.key && selY < (Inventory::INVENTORY_ROWS - 1))
|
||||
{
|
||||
selectedItem += Inventory::SELECTION_SIZE;
|
||||
}
|
||||
|
||||
if (eventKey == o.keyMenuOk.key)
|
||||
{
|
||||
selectSlotAndClose();
|
||||
}
|
||||
}
|
||||
|
||||
int UploadPhotoScreen::getSelectedSlot(int x, int y)
|
||||
{
|
||||
int left = 3 + width / 2 - Inventory::SELECTION_SIZE * 10;
|
||||
int top = height - 16 - 3 - 22 * 2 - 22 * Inventory::INVENTORY_ROWS;
|
||||
|
||||
if (x >= left && y >= top)
|
||||
{
|
||||
int xSlot = (x - left) / 20;
|
||||
if (xSlot < Inventory::SELECTION_SIZE)
|
||||
{
|
||||
// rows are rendered upsidedown
|
||||
return xSlot + Inventory::INVENTORY_SIZE - ((y - top) / 22) * Inventory::SELECTION_SIZE;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void UploadPhotoScreen::mouseClicked(int x, int y, int buttonNum) {
|
||||
if (buttonNum == MouseAction::ACTION_LEFT) {
|
||||
|
||||
int slot = getSelectedSlot(x, y);
|
||||
if (slot >= 0 && slot < Inventory::INVENTORY_SIZE)
|
||||
{
|
||||
selectedItem = slot;
|
||||
//minecraft->soundEngine->playUI("random.click", 1, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UploadPhotoScreen::mouseReleased(int x, int y, int buttonNum)
|
||||
{
|
||||
if (buttonNum == MouseAction::ACTION_LEFT) {
|
||||
|
||||
int slot = getSelectedSlot(x, y);
|
||||
if (slot >= 0 && slot < Inventory::INVENTORY_SIZE && slot == selectedItem)
|
||||
{
|
||||
selectSlotAndClose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UploadPhotoScreen::selectSlotAndClose()
|
||||
{
|
||||
Inventory* inventory = minecraft->player->inventory;
|
||||
|
||||
int itemId = inventory->getSelectionSlotItemId(selectedItem + Inventory::SELECTION_SIZE);
|
||||
int i = 0;
|
||||
|
||||
for (; i < Inventory::SELECTION_SIZE - 2; i++)
|
||||
{
|
||||
if (itemId == inventory->getSelectionSlotItemId(i))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// update selection list
|
||||
for (; i >= 1; i--)
|
||||
{
|
||||
inventory->setSelectionSlotItemId(i, inventory->getSelectionSlotItemId(i - 1));
|
||||
}
|
||||
inventory->setSelectionSlotItemId(0, itemId);
|
||||
inventory->selectSlot(0);
|
||||
|
||||
minecraft->soundEngine->playUI("random.click", 1, 1);
|
||||
minecraft->setScreen(NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "Screen.h"
|
||||
#include "Screen.hpp"
|
||||
|
||||
class UploadPhotoScreen : public Screen
|
||||
{
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "UsernameScreen.h"
|
||||
#include "StartMenuScreen.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../Font.h"
|
||||
#include "../components/Button.h"
|
||||
#include "../../../platform/input/Keyboard.h"
|
||||
#include "../../../AppPlatform.h"
|
||||
#include "UsernameScreen.hpp"
|
||||
#include "StartMenuScreen.hpp"
|
||||
#include "client/Minecraft.hpp"
|
||||
#include "client/gui/Font.hpp"
|
||||
#include "client/gui/components/Button.hpp"
|
||||
#include "platform/input/Keyboard.hpp"
|
||||
#include "AppPlatform.hpp"
|
||||
|
||||
UsernameScreen::UsernameScreen()
|
||||
: _btnDone(0, "Done"),
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Screen.h"
|
||||
#include "../components/Button.h"
|
||||
#include "client/gui/components/TextBox.h"
|
||||
#include "client/gui/Screen.hpp"
|
||||
#include "client/gui/components/Button.hpp"
|
||||
#include "client/gui/components/TextBox.hpp"
|
||||
#include <string>
|
||||
|
||||
class UsernameScreen : public Screen
|
||||
@@ -1,32 +1,32 @@
|
||||
#include "CraftingFilters.h"
|
||||
#include "../../../../world/item/ItemInstance.h"
|
||||
#include "../../../../world/item/Item.h"
|
||||
#include "../../../../world/level/tile/Tile.h"
|
||||
#include "../../../../world/level/material/Material.h"
|
||||
#include "../../../../world/level/tile/StoneSlabTile.h"
|
||||
|
||||
namespace CraftingFilters {
|
||||
|
||||
bool isStonecutterItem(const ItemInstance& ins) {
|
||||
Item* const item = ins.getItem();
|
||||
if (item->id < 0 || item->id >= 256)
|
||||
return false;
|
||||
|
||||
Tile* const tile = Tile::tiles[item->id];
|
||||
if (!tile)
|
||||
return false;
|
||||
|
||||
// Special stone/sand cases
|
||||
if ( tile == Tile::lapisBlock
|
||||
|| tile == Tile::furnace
|
||||
|| tile == Tile::stonecutterBench)
|
||||
return false;
|
||||
|
||||
if (tile == Tile::stoneSlabHalf && ins.getAuxValue() == StoneSlabTile::WOOD_SLAB)
|
||||
return false;
|
||||
|
||||
// Return everything stone or sand
|
||||
return (tile->material == Material::stone || tile->material == Material::sand);
|
||||
}
|
||||
|
||||
#include "CraftingFilters.hpp"
|
||||
#include "world/item/ItemInstance.hpp"
|
||||
#include "world/item/Item.hpp"
|
||||
#include "world/level/tile/Tile.hpp"
|
||||
#include "world/level/material/Material.hpp"
|
||||
#include "world/level/tile/StoneSlabTile.hpp"
|
||||
|
||||
namespace CraftingFilters {
|
||||
|
||||
bool isStonecutterItem(const ItemInstance& ins) {
|
||||
Item* const item = ins.getItem();
|
||||
if (item->id < 0 || item->id >= 256)
|
||||
return false;
|
||||
|
||||
Tile* const tile = Tile::tiles[item->id];
|
||||
if (!tile)
|
||||
return false;
|
||||
|
||||
// Special stone/sand cases
|
||||
if ( tile == Tile::lapisBlock
|
||||
|| tile == Tile::furnace
|
||||
|| tile == Tile::stonecutterBench)
|
||||
return false;
|
||||
|
||||
if (tile == Tile::stoneSlabHalf && ins.getAuxValue() == StoneSlabTile::WOOD_SLAB)
|
||||
return false;
|
||||
|
||||
// Return everything stone or sand
|
||||
return (tile->material == Material::stone || tile->material == Material::sand);
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user