3 Commits

Author SHA1 Message Date
Kolyah35
7418263193 .h -> .hpp everything 2026-03-28 01:08:50 +03:00
Kolyah35
7d3257669a pragma once everywhere 2026-03-28 00:00:19 +03:00
Kolyah35
a45c01d013 server compilable 2026-03-26 03:55:28 +03:00
943 changed files with 91306 additions and 97978 deletions

View File

@@ -39,6 +39,8 @@ if (${PLATFORM} STREQUAL "Desktop")
set(EXTRA_LIBS pthread m) set(EXTRA_LIBS pthread m)
endif() endif()
include_directories("glad/include")
elseif (${PLATFORM} STREQUAL "Web") elseif (${PLATFORM} STREQUAL "Web")
set(PLATFORM_CPP "PLATFORM_WEB") set(PLATFORM_CPP "PLATFORM_WEB")
set(EXTRA_LIBS "idbfs.js") set(EXTRA_LIBS "idbfs.js")
@@ -111,36 +113,41 @@ CPMAddPackage(
"ALSOFT_STATIC_LIBGCC ON" "ALSOFT_STATIC_LIBGCC ON"
) )
# TODO: Clear this paths with *
file(GLOB SERVER_SOURCES file(GLOB SERVER_SOURCES
"project/lib_projects/raknet/jni/RaknetSources/*.cpp" "project/lib_projects/raknet/jni/RaknetSources/*.cpp"
"src/NinecraftApp.cpp"
"src/Performance.cpp" "src/Performance.cpp"
"src/SharedConstants.cpp" "src/SharedConstants.cpp"
"src/Minecraft.cpp"
"src/MinecraftServer.cpp"
"src/App.cpp"
"src/IPlatform.cpp"
"src/client/IConfigListener.cpp"
"src/client/Minecraft.cpp"
"src/client/OptionStrings.cpp"
"src/client/Option.cpp"
"src/client/Options.cpp"
"src/client/OptionsFile.cpp"
"src/client/ServerProfiler.cpp"
"src/client/gamemode/CreativeMode.cpp" # "src/client/IConfigListener.cpp"
"src/client/gamemode/GameMode.cpp" # "src/client/Minecraft.cpp"
"src/client/gamemode/SurvivalMode.cpp" # "src/client/OptionStrings.cpp"
# "src/client/Option.cpp"
# "src/client/Options.cpp"
# "src/client/OptionsFile.cpp"
# "src/client/ServerProfiler.cpp"
"src/client/player/LocalPlayer.cpp" # "src/client/gamemode/CreativeMode.cpp"
"src/client/player/RemotePlayer.cpp" # "src/client/gamemode/GameMode.cpp"
"src/client/player/input/KeyboardInput.cpp" # "src/client/gamemode/SurvivalMode.cpp"
# "src/client/player/LocalPlayer.cpp"
# "src/client/player/RemotePlayer.cpp"
# "src/client/player/input/KeyboardInput.cpp"
"src/gamemode/*.cpp"
"src/locale/I18n.cpp" "src/locale/I18n.cpp"
"src/main.cpp"
"src/main_dedicated.cpp" "src/main_dedicated.cpp"
"src/nbt/Tag.cpp" "src/nbt/Tag.cpp"
"src/network/ClientSideNetworkHandler.cpp"
"src/network/NetEventCallback.cpp" "src/network/NetEventCallback.cpp"
"src/network/Packet.cpp" "src/network/Packet.cpp"
"src/network/RakNetInstance.cpp" "src/network/RakNetInstance.cpp"
@@ -151,11 +158,7 @@ file(GLOB SERVER_SOURCES
"src/platform/HttpClient.cpp" "src/platform/HttpClient.cpp"
"src/platform/PngLoader.cpp" "src/platform/PngLoader.cpp"
"src/platform/time.cpp" "src/platform/time.cpp"
"src/platform/server/PlatformServer.cpp"
"src/platform/input/Controller.cpp"
"src/platform/input/Keyboard.cpp"
"src/platform/input/Mouse.cpp"
"src/platform/input/Multitouch.cpp"
"src/server/ArgumentsSettings.cpp" "src/server/ArgumentsSettings.cpp"
"src/server/ServerLevel.cpp" "src/server/ServerLevel.cpp"
@@ -211,7 +214,6 @@ file(GLOB SERVER_SOURCES
"src/world/level/tile/entity/*.cpp" "src/world/level/tile/entity/*.cpp"
"src/world/phys/HitResult.cpp" "src/world/phys/HitResult.cpp"
"src/commands/*.cpp"
) )
file(GLOB CLIENT_SOURCES file(GLOB CLIENT_SOURCES
@@ -293,8 +295,6 @@ file(GLOB CLIENT_SOURCES
"src/AppPlatform_glfw.cpp" "src/AppPlatform_glfw.cpp"
"src/main.cpp" "src/main.cpp"
"src/commands/*.cpp"
) )
if (${PLATFORM} STREQUAL "Desktop") if (${PLATFORM} STREQUAL "Desktop")
@@ -371,7 +371,7 @@ if(${PLATFORM} MATCHES "Web")
endif() endif()
# Client # Client
target_compile_definitions(${PROJECT_NAME} PUBLIC "OPENGL_ES" "NO_EGL" ${PLATFORM}) target_compile_definitions(${PROJECT_NAME} PUBLIC "OPENGL_ES" "NO_EGL" "${PLATFORM_CPP}")
target_link_libraries(${PROJECT_NAME} zlib ${PNG_LIB} OpenAL::OpenAL glfw ${EXTRA_LIBS}) target_link_libraries(${PROJECT_NAME} zlib ${PNG_LIB} OpenAL::OpenAL glfw ${EXTRA_LIBS})
if (OpenSSL_FOUND) if (OpenSSL_FOUND)

26
src/App.cpp Normal file
View File

@@ -0,0 +1,26 @@
#include "App.hpp"
#include "IPlatform.hpp"
#include "platform/server/PlatformServer.hpp"
#include "platform/glfw/PlatformGlfw.hpp"
std::unique_ptr<IPlatform> App::CreatePlatform() {
#if defined(STANDALONE_SERVER)
return std::make_unique<PlatformServer>();
#elif defined(PLATFORM_DESKTOP)
return std::make_unique<PlatformGlfw>();
#else
static_assert(false, "Unsupported platform!");
#endif
}
void App::run() {
init();
m_platform->runMainLoop(*this);
}
void App::swapBuffers() {
m_platform->swapBuffers();
}

View File

@@ -1,87 +0,0 @@
#ifndef APP_H__
#define APP_H__
#ifdef __APPLE__
#define NO_EGL
#endif
#ifdef STANDALONE_SERVER
#define NO_EGL
#endif
#include "AppPlatform.h"
#ifndef NO_EGL
#include <EGL/egl.h>
#endif
#include "platform/log.h"
typedef struct AppContext {
#ifndef NO_EGL
EGLDisplay display;
EGLContext context;
EGLSurface surface;
#endif
AppPlatform* platform;
bool doRender;
} AppContext;
class App
{
public:
App()
: _finished(false),
_inited(false)
{
_context.platform = 0;
}
virtual ~App() {}
void init(AppContext& c) {
_context = c;
init();
_inited = true;
}
bool isInited() { return _inited; }
virtual AppPlatform* platform() { return _context.platform; }
void onGraphicsReset(AppContext& c) {
_context = c;
onGraphicsReset();
}
virtual void audioEngineOn () {}
virtual void audioEngineOff() {}
virtual void destroy() {}
virtual void loadState(void* state, int stateSize) {}
virtual bool saveState(void** state, int* stateSize) { return false; }
void swapBuffers() {
#ifndef NO_EGL
if (_context.doRender)
eglSwapBuffers(_context.display, _context.surface);
#endif
}
virtual void draw() {}
virtual void update() {};// = 0;
virtual void setSize(int width, int height) {}
virtual void quit() { _finished = true; }
virtual bool wantToQuit() { return _finished; }
virtual bool handleBack(bool isDown) { return false; }
protected:
virtual void init() {}
//virtual void onGraphicsLost() = 0;
virtual void onGraphicsReset() = 0;
private:
bool _inited;
bool _finished;
AppContext _context;
};
#endif//APP_H__

71
src/App.hpp Executable file
View File

@@ -0,0 +1,71 @@
#pragma once
#include <memory>
#ifdef __APPLE__
#define NO_EGL
#endif
#ifdef STANDALONE_SERVER
#define NO_EGL
#endif
#include <IPlatform.hpp>
#ifndef NO_EGL
#include <EGL/egl.h>
#endif
// typedef struct AppContext {
// #ifndef NO_EGL
// EGLDisplay display;
// EGLContext context;
// EGLSurface surface;
// #endif
// AppPlatform* platform;
// bool doRender;
// } AppContext;
class App {
protected:
std::unique_ptr<IPlatform> m_platform;
public:
static std::unique_ptr<IPlatform> CreatePlatform();
App(std::unique_ptr<IPlatform> platform) : m_platform(std::move(platform)), m_finished(false), m_inited(false) {}
App() = delete;
virtual ~App() {}
void run();
bool isInited() { return m_inited; }
virtual void audioEngineOn () {}
virtual void audioEngineOff() {}
virtual void destroy() {}
virtual void loadState(void* state, int stateSize) {}
virtual bool saveState(void** state, int* stateSize) { return false; }
void swapBuffers();
// {
// #ifndef NO_EGL
// if (_context.doRender)
// eglSwapBuffers(_context.display, _context.surface);
// #endif
// m_platform->swapBuffers();
// }
virtual void update() = 0;
virtual void quit() { m_finished = true; }
virtual bool wantToQuit() { return m_finished; }
virtual bool handleBack(bool isDown) { return false; }
protected:
virtual void init() { m_inited = true;}
private:
bool m_inited = false;
bool m_finished = false;
};

View File

@@ -1,10 +0,0 @@
#ifndef _MINECRAFT_APPCONSTANTS_H_
#define _MINECRAFT_APPCONSTANTS_H_
#define APP_VERSION_STRING "Demo"
#define APP_NAME "Minecraft - Pocket Edition " APP_VERSION_STRING
#endif

View File

@@ -1,143 +0,0 @@
#ifndef APPPLATFORM_H__
#define APPPLATFORM_H__
#include <vector>
#include <string>
#include <cstring>
#include "client/renderer/TextureData.h"
typedef std::vector<std::string> StringVector;
/*
typedef struct UserInput
{
static const int STATUS_INVALID = -1;
static const int STATUS_NOTINITED = -2;
static const int STATUS_OK = 1;
static const int STATUS_CANCEL = 0;
UserInput(int id)
: _id(id),
status(STATUS_NOTINITED)
{}
UserInput(int id, int status)
: _id(id),
status(status)
{}
int getId() { return _id; }
int status;
private:
int _id;
} UserInput;
class UserInputStatus {
int _status;
public:
UserInputStatus(int status)
: _status(status)
{}
bool isAnswered() { return _status >= 0; }
bool isOk() { return _status == UserInput::STATUS_OK; }
bool isCancel() { return _status == UserInput::STATUS_CANCEL; }
};
*/
class BinaryBlob {
public:
BinaryBlob()
: data(NULL),
size(-1) {}
BinaryBlob(unsigned char* data, unsigned int size)
: data(data),
size(size) {}
unsigned char* data;
int size;
};
class PlatformStringVars {
public:
static const int DEVICE_BUILD_MODEL = 0;
};
class AppPlatform
{
public:
AppPlatform() : keyboardVisible(false) {}
virtual ~AppPlatform() {}
virtual void saveScreenshot(const std::string& filename, int glWidth, int glHeight) {}
virtual TextureData loadTexture(const std::string& filename_, bool textureFolder) { return TextureData(); }
virtual TextureData loadTextureFromMemory(const unsigned char* data, size_t size) { return TextureData(); }
virtual void playSound(const std::string& fn, float volume, float pitch) {}
virtual void hideCursor(bool hide) {}
virtual void showDialog(int dialogId) {}
virtual void createUserInput() {}
bool is_big_endian(void) {
union {
unsigned int i;
char c[4];
} bint = {0x01020304};
return bint.c[0] == 1;
}
void createUserInput(int dialogId)
{
showDialog(dialogId);
createUserInput();
}
virtual int getUserInputStatus() { return 0; }
virtual StringVector getUserInput() { return StringVector(); }
virtual std::string getDateString(int s) { return ""; }
//virtual void createUserInputScreen(const char* types) {}
virtual void uploadPlatformDependentData(int id, void* data) {}
virtual BinaryBlob readAssetFile(const std::string& filename) { return BinaryBlob(); }
virtual void _tick() {}
virtual int getScreenWidth() { return 854; }
virtual int getScreenHeight() { return 480; }
virtual float getPixelsPerMillimeter() { return 10; }
virtual bool isNetworkEnabled(bool onlyWifiAllowed) { return true; }
virtual bool isPowerVR() {
return false;
}
virtual int getKeyFromKeyCode(int keyCode, int metaState, int deviceId) {return 0;}
#ifdef __APPLE__
virtual bool isSuperFast() = 0;
#endif
virtual void openURL(const std::string& url) {}
virtual void finish() {}
virtual bool supportsTouchscreen() { return false; }
virtual void vibrate(int milliSeconds) {}
virtual std::string getPlatformStringVar(int stringId) {
return "<getPlatformStringVar NotImplemented>";
}
virtual void showKeyboard() {
keyboardVisible = true;
}
virtual void hideKeyboard() {
keyboardVisible = false;
}
virtual bool isKeyboardVisible() {return keyboardVisible;}
protected:
bool keyboardVisible;
};
#endif /*APPPLATFORM_H__*/

View File

@@ -1,12 +0,0 @@
#include "AppPlatform_glfw.h"
float AppPlatform_glfw::getPixelsPerMillimeter() {
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
int width_mm, height_mm;
glfwGetMonitorPhysicalSize(monitor, &width_mm, &height_mm);
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
return (float)mode->width / (float)width_mm;
}

View File

@@ -1,155 +0,0 @@
#ifndef APPPLATFORM_GLFW_H__
#define APPPLATFORM_GLFW_H__
#include "AppPlatform.h"
#include "platform/log.h"
#include "platform/HttpClient.h"
#include "platform/PngLoader.h"
#include "client/renderer/gles.h"
#include "world/level/storage/FolderMethods.h"
#include <png.h>
#include <cmath>
#include <fstream>
#include <sstream>
#include <GLFW/glfw3.h>
#include <ctime>
#include "util/StringUtils.h"
#ifdef _WIN32
#include <windows.h>
#include <shellapi.h>
#endif
#ifdef __EMSCRIPTEN__
#include <emscripten/html5.h>
#endif
static void png_funcReadFile(png_structp pngPtr, png_bytep data, png_size_t length) {
((std::istream*)png_get_io_ptr(pngPtr))->read((char*)data, length);
}
class AppPlatform_glfw: public AppPlatform
{
public:
AppPlatform_glfw()
{
}
BinaryBlob readAssetFile(const std::string& filename) override {
FILE* fp = fopen(("data/" + filename).c_str(), "r");
if (!fp)
return BinaryBlob();
int size = getRemainingFileSize(fp);
BinaryBlob blob;
blob.size = size;
blob.data = new unsigned char[size];
fread(blob.data, 1, size, fp);
fclose(fp);
return blob;
}
void saveScreenshot(const std::string& filename, int glWidth, int glHeight) override {
//@todo
}
__inline unsigned int rgbToBgr(unsigned int p) {
return (p & 0xff00ff00) | ((p >> 16) & 0xff) | ((p << 16) & 0xff0000);
}
TextureData loadTexture(const std::string& filename_, bool textureFolder) override
{
// Support fetching PNG textures via HTTP/HTTPS (for skins, etc)
if (Util::startsWith(filename_, "http://") || Util::startsWith(filename_, "https://")) {
std::vector<unsigned char> body;
if (HttpClient::download(filename_, body) && !body.empty()) {
return loadTextureFromMemory(body.data(), body.size());
}
return TextureData();
}
TextureData out;
std::string filename = textureFolder? "data/images/" + filename_
: filename_;
std::ifstream source(filename.c_str(), std::ios::binary);
if (!source) {
LOGI("Couldn't find file: %s\n", filename.c_str());
return out;
}
std::vector<unsigned char> fileData((std::istreambuf_iterator<char>(source)), std::istreambuf_iterator<char>());
source.close();
if (fileData.empty()) {
LOGI("Couldn't read file: %s\n", filename.c_str());
return out;
}
return loadTextureFromMemory(fileData.data(), fileData.size());
}
TextureData loadTextureFromMemory(const unsigned char* data, size_t size) override {
return loadPngFromMemory(data, size);
}
virtual std::string getDateString(int s) override {
time_t tm = s;
char mbstr[100];
std::strftime(mbstr, sizeof(mbstr), "%F %T", std::localtime(&tm));
return std::string(mbstr);
}
virtual int getScreenWidth() override {
#ifdef __EMSCRIPTEN__
int w, h;
emscripten_get_canvas_element_size("canvas", &w, &h);
return w;
#endif
return 854;
};
virtual int getScreenHeight() override {
#ifdef __EMSCRIPTEN__
int w, h;
emscripten_get_canvas_element_size("canvas", &w, &h);
return h;
#endif
return 480;
};
virtual float getPixelsPerMillimeter() override;
virtual bool supportsTouchscreen() override { return false; /* glfw supports only mouse and keyboard */ }
virtual void hideCursor(bool hide) override {
int isHide = hide ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_HIDDEN;
glfwSetInputMode(window, GLFW_CURSOR, isHide);
}
virtual void openURL(const std::string& url) override {
#ifdef _WIN32
ShellExecuteA(NULL, "open", url.c_str(), NULL, NULL, SW_SHOWNORMAL);
#elif __linux__
std::string command = "xdg-open " + url;
system(command.c_str());
#elif __EMSCRIPTEN__
emscripten_run_script(std::string("window.open('" + url + "', '_blank')").c_str());
#endif
}
GLFWwindow* window;
private:
};
#endif /*APPPLATFORM_GLFW_H__*/

View File

@@ -1,5 +1,4 @@
#ifndef EGLCONFIGPRINTER_H__ #pragma once
#define EGLCONFIGPRINTER_H__
#include <cstdio> #include <cstdio>
#include <string> #include <string>
@@ -122,4 +121,3 @@ public:
} }
}; };
#endif /*EGLCONFIGPRINTER_H__*/

View File

@@ -1,13 +0,0 @@
#ifndef ERRORCODES_H__
#define ERRORCODES_H__
namespace ErrorCodes {
enum Enum {
Unknown,
ContainerRefStillExistsAfterDestruction
};
}
#endif /*ERRORCODES_H__*/

14
src/IPlatform.cpp Normal file
View File

@@ -0,0 +1,14 @@
#include <IPlatform.hpp>
#include <App.hpp>
#include <fstream>
void IPlatform::runMainLoop(App& app) {
while(!app.wantToQuit()) app.update();
}
ByteVector IPlatform::readAssetFile(const std::string& path) {
std::ifstream instream(path, std::ios::in | std::ios::binary);
std::vector<uint8_t> data((std::istreambuf_iterator<char>(instream)), std::istreambuf_iterator<char>());
return data;
}

81
src/IPlatform.hpp Executable file
View File

@@ -0,0 +1,81 @@
#pragma once
#include <vector>
#include <string>
#include "client/renderer/TextureData.hpp"
#include <cstdint>
typedef std::vector<std::string> StringVector;
typedef std::vector<uint8_t> ByteVector;
class App;
class IPlatform {
public:
IPlatform() : keyboardVisible(false), windowSizeChanged(false), m_targetFrametime(0.f) {}
virtual ~IPlatform() {}
virtual bool init() { return true; }
virtual void swapBuffers() {}
virtual void runMainLoop(App& app);
virtual ByteVector readAssetFile(const std::string& path);
// Mojang functions here
virtual TextureData loadTexture(const std::string& filename_, bool textureFolder) { return TextureData(); }
virtual TextureData loadTextureFromMemory(const unsigned char* data, size_t size) { return TextureData(); }
virtual void playSound(const std::string& fn, float volume, float pitch) {}
virtual void hideCursor(bool hide) {}
virtual std::string getDateString(int s) = 0;
virtual void uploadPlatformDependentData(int id, void* data) {}
// virtual BinaryBlob readAssetFile(const std::string& filename) { return BinaryBlob(); }
virtual void _tick() {}
virtual int getScreenWidth() { return 854; }
virtual int getScreenHeight() { return 480; }
virtual float getPixelsPerMillimeter() { return 10; }
virtual bool isNetworkEnabled(bool onlyWifiAllowed) { return true; }
virtual bool isPowerVR() {
return false;
}
virtual int getKeyFromKeyCode(int keyCode, int metaState, int deviceId) {return 0;}
#ifdef __APPLE__
virtual bool isSuperFast() = 0;
#endif
virtual void openURL(const std::string& url) {}
virtual void finish() {}
virtual bool supportsTouchscreen() { return false; }
virtual void vibrate(int milliSeconds) {}
virtual std::string getPlatformStringVar(int stringId) = 0;
virtual void showKeyboard() { keyboardVisible = true; }
virtual void hideKeyboard() { keyboardVisible = false; }
virtual bool isKeyboardVisible() { return keyboardVisible; }
virtual void setTargetFPS(int fps) { m_targetFrametime = 1.0 / fps; }
bool isWindowSizeChanged() { return windowSizeChanged; }
virtual void setVSync(bool on) { vsync = on; }
protected:
bool keyboardVisible;
bool windowSizeChanged;
bool vsync;
double m_targetFrametime;
};

View File

@@ -1,40 +1,39 @@
#ifndef LICENSECODES_H__ #pragma once
#define LICENSECODES_H__
class LicenseCodes
class LicenseCodes {
{ public:
public: // Something's not ready, call again later
// Something's not ready, call again later static const int WAIT_PLATFORM_NOT_READY = -2;
static const int WAIT_PLATFORM_NOT_READY = -2; static const int WAIT_SERVER_NOT_READY = -1;
static const int WAIT_SERVER_NOT_READY = -1;
// License is ok
// License is ok static const int LICENSE_OK = 0;
static const int LICENSE_OK = 0; static const int LICENSE_TRIAL_OK = 1;
static const int LICENSE_TRIAL_OK = 1;
// License is not working in one way or another
// License is not working in one way or another static const int LICENSE_VALIDATION_FAILED = 50;
static const int LICENSE_VALIDATION_FAILED = 50; static const int ITEM_NOT_FOUND = 51;
static const int ITEM_NOT_FOUND = 51; static const int LICENSE_NOT_FOUND = 52;
static const int LICENSE_NOT_FOUND = 52; static const int ERROR_CONTENT_HANDLER = 100;
static const int ERROR_CONTENT_HANDLER = 100; static const int ERROR_ILLEGAL_ARGUMENT = 101;
static const int ERROR_ILLEGAL_ARGUMENT = 101; static const int ERROR_SECURITY = 102;
static const int ERROR_SECURITY = 102; static const int ERROR_INPUT_OUTPUT = 103;
static const int ERROR_INPUT_OUTPUT = 103; static const int ERROR_ILLEGAL_STATE = 104;
static const int ERROR_ILLEGAL_STATE = 104; static const int ERROR_NULL_POINTER = 105;
static const int ERROR_NULL_POINTER = 105; static const int ERROR_GENERAL = 106;
static const int ERROR_GENERAL = 106; static const int ERROR_UNABLE_TO_CONNECT_TO_CDS = 107;
static const int ERROR_UNABLE_TO_CONNECT_TO_CDS = 107;
// The call went wrong so we didn't get a license value at all
// The call went wrong so we didn't get a license value at all static const int ERROR_EXCEPTION = 200;
static const int ERROR_EXCEPTION = 200;
static bool isOk(int i) {
static bool isOk(int i) { return (i == 0) || (i == 1);
return (i == 0) || (i == 1); }
} static bool isReady(int i) {
static bool isReady(int i) { return (i >= 0);
return (i >= 0); }
} };
};
#endif /*LICENSECODES_H__ */
#endif /*LICENSECODES_H__ */

502
src/Minecraft.cpp Executable file
View File

@@ -0,0 +1,502 @@
#include <Minecraft.hpp>
#include "gamemode/CreativeMode.hpp"
#include "gamemode/SurvivalMode.hpp"
#include "gamemode/CreatorMode.hpp"
#include "world/entity/player/Player.hpp"
#include "world/item/Item.hpp"
#include "world/item/ItemInstance.hpp"
#include "world/item/crafting/Recipes.hpp"
#include "world/level/Level.hpp"
#include "world/level/tile/entity/TileEntity.hpp"
#include <string>
#include <cstdlib>
#include "client/gui/Screen.hpp"
#include "world/level/storage/ExternalFileLevelStorageSource.hpp"
#if defined(APPLE_DEMO_PROMOTION)
#define NO_NETWORK
#endif
#if defined(RPI)
#define CREATORMODE
#endif
#include "network/RakNetInstance.hpp"
#include "network/ClientSideNetworkHandler.hpp"
#include "network/ServerSideNetworkHandler.hpp"
//#include "network/Packet.hpp"
#include "world/entity/player/Inventory.hpp"
#include "world/level/tile/Tile.hpp"
#include "world/level/storage/LevelStorageSource.hpp"
#include "world/level/storage/LevelStorage.hpp"
#include "world/level/chunk/ChunkSource.hpp"
#include "platform/CThread.hpp"
#include <IPlatform.hpp>
#include "util/PerfTimer.hpp"
#include "util/PerfRenderer.hpp"
#include "world/entity/MobFactory.hpp"
#include "world/level/MobSpawner.hpp"
#include "util/Mth.hpp"
#include "world/entity/MobCategory.hpp"
#include "server/ServerLevel.hpp"
#ifdef CREATORMODE
#include "server/CreatorLevel.hpp"
#endif
#include "network/command/CommandServer.hpp"
/*static*/
const char* Minecraft::progressMessages[] = {
"Locating server",
"Building terrain",
"Preparing",
"Saving chunks"
};
// int Minecraft::customDebugId = Minecraft::CDI_NONE;
bool Minecraft::_hasInitedStatics = false;
#if defined(_MSC_VER)
#pragma warning( disable : 4355 ) // 'this' pointer in initialization list which is perfectly legal
#endif
// Minecraft::Minecraft() :
// #ifdef __APPLE__
// _isSuperFast(false),
// #endif
// #if defined(NO_NETWORK)
// raknetInstance = new IRakNetInstance();
// #else
// raknetInstance = new RakNetInstance();
// #endif
// #ifndef STANDALONE_SERVER
// soundEngine = new SoundEngine(20.0f);
// soundEngine->init(this, &options);
// #endif
// //setupPieces();
// #if defined(ANDROID) || defined(__APPLE__) || defined(RPI)
// signal(SIGPIPE, SIG_IGN);
// #endif
// externalCacheStoragePath = '.';
// externalCacheStoragePath = '.';
// }
Minecraft::~Minecraft() {
delete netCallback;
delete raknetInstance;
delete gameMode;
if (level != NULL) {
level->saveGame();
if (level->getChunkSource())
level->getChunkSource()->saveAll(true);
delete level->getLevelStorage();
delete level;
level = NULL;
}
//delete player;
delete storageSource;
delete _commandServer;
MobFactory::clearStaticTestMobs();
// Note: Don't tear down statics if we run on Android
// (we might change this in the future)
#ifndef ANDROID
Biome::teardownBiomes();
Item ::teardownItems();
Tile ::teardownTiles();
Material::teardownMaterials();
Recipes ::teardownRecipes();
TileEntity::teardownTileEntities();
#endif
}
// Only called by server
void Minecraft::selectLevel( const std::string& levelId, const std::string& levelName, const LevelSettings& settings ) {
level = (Level*)new ServerLevel(
storageSource->selectLevel(levelId, false),
levelName,
settings,
SharedConstants::GeneratorVersion
);
// note: settings is useless beyond this point, since it's
// either copied to LevelData (or LevelData read from file)
setLevel(level, "Generating level");
setIsCreativeMode(level->getLevelData()->getGameType() == GameType::Creative);
_running = true;
}
void Minecraft::setLevel(Level* level, const std::string& message, Player* forceInsertPlayer) {
LOGI("Seed is %ld\n", level->getSeed());
if (level != NULL) {
level->raknetInstance = raknetInstance;
gameMode->initLevel(level);
this->level = level;
_hasSignaledGeneratingLevelFinished = false;
#ifdef STANDALONE_SERVER
const bool threadedLevelCreation = false;
#else
const bool threadedLevelCreation = true;
#endif
if (threadedLevelCreation) {
// Threaded
// "Lock"
isGeneratingLevel = true;
generateLevelThread = new CThread(Minecraft::prepareLevel_tspawn, this);
} else {
// Non-threaded
generateLevel("Currently not used", level);
}
}
this->lastTickTime = 0;
this->_running = true;
}
void Minecraft::prepareLevel(const std::string& title) {
LOGI("status: 1\n");
progressStageStatusId = 1;
Stopwatch A, B, C, D;
A.start();
Stopwatch L;
// Dont update lights if we load the level (ok, actually just with leveldata version=1.+(?))
if (!level->isNew())
level->setUpdateLights(false);
int Max = CHUNK_CACHE_WIDTH * CHUNK_CACHE_WIDTH;
int pp = 0;
for (int x = 8; x < (CHUNK_CACHE_WIDTH * CHUNK_WIDTH); x += CHUNK_WIDTH) {
for (int z = 8; z < (CHUNK_CACHE_WIDTH * CHUNK_WIDTH); z += CHUNK_WIDTH) {
progressStagePercentage = 100 * pp++ / Max;
//printf("level generation progress %d\n", progressStagePercentage);
B.start();
level->getTile(x, 64, z);
B.stop();
L.start();
if (level->isNew())
while (level->updateLights())
;
L.stop();
}
}
A.stop();
level->setUpdateLights(true);
C.start();
for (int x = 0; x < CHUNK_CACHE_WIDTH; x++)
{
for (int z = 0; z < CHUNK_CACHE_WIDTH; z++)
{
LevelChunk* chunk = level->getChunk(x, z);
if (chunk && !chunk->createdFromSave)
{
chunk->unsaved = false;
chunk->clearUpdateMap();
}
}
}
C.stop();
LOGI("status: 3\n");
progressStageStatusId = 3;
if (level->isNew()) {
level->setInitialSpawn(); // @note: should obviously be called from Level itself
level->saveLevelData();
level->getChunkSource()->saveAll(false);
level->saveGame();
} else {
level->saveLevelData();
level->loadEntities();
}
progressStagePercentage = -1;
progressStageStatusId = 2;
LOGI("status: 2\n");
D.start();
level->prepare();
D.stop();
A.print("Generate level: ");
L.print(" - light: ");
B.print(" - getTl: ");
C.print(" - clear: ");
D.print(" - prepr: ");
progressStageStatusId = 0;
}
void Minecraft::update() {
timer.advanceTime();
raknetInstance->runEvents(netCallback);
TIMER_PUSH("tick");
int toTick = timer.ticks;
timer.ticks = 0;
for (int i = 0; i < toTick; ++i, ++ticks) tick(i, toTick-1);
TIMER_POP_PUSH("updatelights");
{
if (level && !isGeneratingLevel) {
level->updateLights();
}
}
TIMER_POP();
// Restart the server if (our modded) RakNet reports an error
if (level && raknetInstance->isProbablyBroken() && raknetInstance->isServer()) {
restartServer();
}
}
void Minecraft::restartServer() {
if (!level) return;
raknetInstance->resetIsBroken();
hostMultiplayer();
if (netCallback) netCallback->levelGenerated(level);
}
void Minecraft::tick(int nTick, int maxTick) {
if (missTime > 0) missTime--;
TIMER_PUSH("gameMode");
if (level) {
gameMode->tick();
}
TIMER_POP_PUSH("commandServer");
if (level && _commandServer) {
_commandServer->tick();
}
//
// Ongoing level generation in a (perhaps) different thread. When it's
// ready, _levelGenerated() is called once and any threads are deleted.
//
if (isGeneratingLevel) {
return;
} else if (!_hasSignaledGeneratingLevelFinished) {
if (generateLevelThread) {
delete generateLevelThread;
generateLevelThread = NULL;
}
_levelGenerated();
}
//
// Normal game loop, run before or efter level generation
//
if (level != NULL) {
TIMER_POP_PUSH("level");
level->tickEntities();
level->tick();
}
TIMER_POP();
}
bool Minecraft::isOnlineClient() {
return false;
}
bool Minecraft::isOnline() {
return netCallback != NULL;
}
void Minecraft::init()
{
// WHY DO WE NEED THIS ON MODERN PLATFORMS :sob:
// Global initialization goes here
Mth::initMth();
if (raknetInstance != nullptr) {
delete raknetInstance;
}
raknetInstance = new RakNetInstance();
// If we're running Android, only initialize
// the first time class is instanced
#ifdef ANDROID
if (!_hasInitedStatics) {
_hasInitedStatics = true;
#endif
Material::initMaterials();
MobCategory::initMobCategories();
Tile::initTiles();
Item::initItems();
Biome::initBiomes();
TileEntity::initTileEntities();
#ifdef ANDROID
}
#endif
setIsCreativeMode(false); // false means it's Survival Mode
#if !defined(NO_STORAGE)
storageSource = new ExternalFileLevelStorageSource(externalStoragePath, externalCacheStoragePath);
#else
storageSource = new MemoryLevelStorageSource();
#endif
// Server-only featire @todo server class app
hostMultiplayer();
}
//
// Multiplayer
//
void Minecraft::hostMultiplayer(int port) {
// Tear down last instance
raknetInstance->disconnect();
delete netCallback;
netCallback = nullptr;
#if !defined(NO_NETWORK)
netCallback = new ServerSideNetworkHandler(this, raknetInstance);
#endif
}
//
// Level generation
//
/*static*/
void* Minecraft::prepareLevel_tspawn(void *p_param) {
Minecraft* mc = (Minecraft*) p_param;
mc->generateLevel("Currently not used", mc->level);
return 0;
}
void Minecraft::generateLevel( const std::string& message, Level* level ) {
Stopwatch s;
s.start();
prepareLevel(message);
s.stop();
s.print("Level generated: ");
// "Unlock"
isGeneratingLevel = false;
}
void Minecraft::_levelGenerated() {
level->validateSpawn();
if (raknetInstance->isServer())
raknetInstance->announceServer(getServerName());
if (netCallback) {
netCallback->levelGenerated(level);
}
_hasSignaledGeneratingLevelFinished = true;
}
Player* Minecraft::respawnPlayer(int playerId) {
for (unsigned int i = 0; i < level->players.size(); ++i) {
if (level->players[i]->entityId == playerId) {
resetPlayer(level->players[i]);
return level->players[i];
}
}
return NULL;
}
void Minecraft::resetPlayer(Player* player) {
level->validateSpawn();
player->reset();
Pos p;
if(player->hasRespawnPosition()) {
p = player->getRespawnPosition();
}
else {
p = level->getSharedSpawnPos();
}
player->setPos((float)p.x + 0.5f, (float)p.y + 1.0f, (float)p.z + 0.5f);
player->resetPos(true);
if (isCreativeMode())
player->inventory->clearInventoryWithDefault();
}
int Minecraft::getProgressStatusId() {
return progressStageStatusId;
}
const char* Minecraft::getProgressMessage()
{
return progressMessages[progressStageStatusId];
}
bool Minecraft::isLevelGenerated()
{
return level != NULL && !isGeneratingLevel;
}
LevelStorageSource* Minecraft::getLevelSource()
{
return storageSource;
}
void Minecraft::setIsCreativeMode(bool isCreative)
{
#ifdef CREATORMODE
delete gameMode;
gameMode = new CreatorMode(this);
_isCreativeMode = true;
#else
if (!gameMode || isCreative != _isCreativeMode)
{
delete gameMode;
if (isCreative) gameMode = new CreativeMode(*this);
else gameMode = new SurvivalMode(*this);
_isCreativeMode = isCreative;
}
#endif
}
bool Minecraft::isCreativeMode() {
return _isCreativeMode;
}
ICreator* Minecraft::getCreator()
{
#ifdef CREATORMODE
return ((CreatorMode*)gameMode)->getCreator();
#else
return NULL;
#endif
}
void Minecraft::optionUpdated(OptionId option, bool value ) {
if(netCallback != NULL && option == OPTIONS_SERVER_VISIBLE) {
ServerSideNetworkHandler* ss = (ServerSideNetworkHandler*) netCallback;
ss->allowIncomingConnections(value);
}
}
void Minecraft::optionUpdated(OptionId option, float value ) {}
void Minecraft::optionUpdated(OptionId option, int value ) {}

138
src/Minecraft.hpp Executable file
View File

@@ -0,0 +1,138 @@
#pragma once
#include "client/Options.hpp"
#include "client/Timer.hpp"
//#include "../network/RakNetInstance.hpp"
#include "world/phys/HitResult.hpp"
#include "App.hpp"
#include <cstddef>
class Level;
class LocalPlayer;
class IInputHolder;
class Mob;
class Player;
class Entity;
class ICreator;
class GameMode;
class CThread;
class LevelStorageSource;
class BuildActionIntention;
class PerfRenderer;
class LevelSettings;
class IRakNetInstance;
class NetEventCallback;
class CommandServer;
struct PingedCompatibleServer;
class Minecraft: public App {
public:
using App::App;
virtual ~Minecraft();
virtual void init();
virtual void update();
virtual void restartServer();
virtual void tick(int nTick, int maxTick);
virtual bool isOnlineClient();
virtual bool isOnline();
virtual void setIsCreativeMode(bool isCreative);
virtual void optionUpdated(OptionId option, bool value);
virtual void optionUpdated(OptionId option, float value);
virtual void optionUpdated(OptionId option, int value);
/**
* @brief Get public name that will be listed in JoinGame menu
*/
virtual std::string getServerName() { return "Unknown"; }
void toggleDimension() {}
bool isCreativeMode();
virtual void selectLevel(const std::string& levelId, const std::string& levelName, const LevelSettings& settings);
virtual void setLevel(Level* level, const std::string& message = "", Player* forceInsertPlayer = NULL);
virtual void onBlockDestroyed(Player* player, int x, int y, int z, int face) {}
void generateLevel( const std::string& message, Level* level );
LevelStorageSource* getLevelSource();
virtual void hostMultiplayer(int port=19132);
Player* respawnPlayer(int playerId);
void respawnPlayer();
void resetPlayer(Player* player);
void doActuallyRespawnPlayer();
void prepareLevel(const std::string& message);
int getProgressStatusId();
const char* getProgressMessage();
ICreator* getCreator();
bool isLevelGenerated();
#ifdef __APPLE__
bool _isSuperFast = false;
bool isSuperFast() { return _isSuperFast; }
#endif
protected:
virtual void _levelGenerated();
private:
static void* prepareLevel_tspawn(void *p_param);
public:
Level* level = nullptr;
CommandServer* _commandServer = nullptr;
GameMode* gameMode = nullptr;
IRakNetInstance* raknetInstance = nullptr;
NetEventCallback* netCallback = nullptr;
int commandPort = 4711;
int lastTime = 0;
int lastTickTime = -1;
int missTime = 0;
int ticks = 0;
CThread* generateLevelThread = nullptr;
// static int customDebugId;
HitResult hitResult;
volatile int progressStagePercentage = 0;
// This field is initialized in main()
// It sets the base path to where worlds can be written (sdcard on android)
std::string externalStoragePath;
std::string externalCacheStoragePath;
protected:
Timer timer{20};
// @note @attn @warn: this is dangerous as fuck!
volatile bool isGeneratingLevel = false;
bool _hasSignaledGeneratingLevelFinished = true;
LevelStorageSource* storageSource;
bool _running;
protected:
volatile int progressStageStatusId = 0;
static const char* progressMessages[];
int _licenseId;
bool _isCreativeMode;
Player* _pendingRemovePlayer; // @attn @todo @fix: remove this shait and fix the respawn behaviour
// from NinecraftApp
bool _verbose = true;
int _lastTickMs = 0;
static bool _hasInitedStatics;
};

2865
src/client/Minecraft.cpp → src/MinecraftClient.cpp Executable file → Normal file

File diff suppressed because it is too large Load Diff

142
src/MinecraftClient.hpp Normal file
View File

@@ -0,0 +1,142 @@
#pragma once
#include "client/gui/Font.hpp"
#include "client/gui/Screen.hpp"
#include "client/particle/ParticleEngine.hpp"
#include "client/player/LocalPlayer.hpp"
#include "client/renderer/GameRenderer.hpp"
#include "client/renderer/Textures.hpp"
#include "client/sound/SoundEngine.hpp"
#include <Minecraft.hpp>
#include <client/MouseHandler.hpp>
#include <client/gui/Gui.hpp>
#include <client/gui/screens/ScreenChooser.hpp>
#include <client/PixelCalc.hpp>
#include <client/renderer/LevelRenderer.hpp>
class MinecraftClient : public Minecraft {
public:
using Minecraft::Minecraft;
~MinecraftClient();
void init() override;
void update() override;
void setSize(int width, int height);
void reloadOptions();
bool supportNonTouchScreen();
bool useTouchscreen();
void grabMouse();
void releaseMouse();
void setScreen(Screen*);
void leaveGame(bool renameLevel = false);
void setLevel(Level* level, const std::string& message = "", Player* forceInsertPlayer = NULL) override;
void updateStats();
void restartServer() override;
bool handleBack(bool isDown) override;
void onGraphicsReset();
void initGLStates();
void tick(int nTick, int maxTick) override;
void tickInput();
void handleBuildAction(BuildActionIntention* action);
bool isOnlineClient() override;
void pauseGame(bool isBackPaused);
void gameLostFocus();
void respawnPlayer();
void audioEngineOn() override;
void audioEngineOff() override;
void setIsCreativeMode(bool isCreative) override;
void optionUpdated(OptionId option, bool value) override;
void optionUpdated(OptionId option, float value) override;
void optionUpdated(OptionId option, int value) override;
LocalPlayer* getPlayer() { return player; }
Font* getFont() { return font; }
Textures& textures() { return m_textures; }
Options& options() { return m_options;}
Screen* getScreen() { return m_screen; }
Gui& gui() { return m_gui; }
ParticleEngine* getParticleEngine() {return particleEngine; }
int getScreenWidth() { return width; }
int getScreenHeigth() { return height; }
virtual void hostMultiplayer(int port) override;
bool isPowerVR() { return _powerVr; }
bool isKindleFire(int kindleVersion);
bool transformResolution(int* w, int* h);
virtual std::string getServerName() override;
void locateMultiplayer();
void cancelLocateMultiplayer();
bool joinMultiplayer(const PingedCompatibleServer& server);
bool joinMultiplayerFromString(const std::string& server);
void onBlockDestroyed(Player* player, int x, int y, int z, int face) override;
protected:
void _reloadInput();
void _levelGenerated() override;
int width = 1, height = 1;
Font* font = nullptr;
// @warn This is unsafe cuz Gui may call some MinecraftClient method while MinecraftClient is not ready
MouseHandler mouseHandler;
LevelRenderer* levelRenderer = nullptr;
GameRenderer* gameRenderer = nullptr;
ParticleEngine* particleEngine = nullptr;
SoundEngine* soundEngine = nullptr;
PerfRenderer* _perfRenderer = nullptr;
bool mouseGrabbed = false;
PixelCalc pixelCalc;
PixelCalc pixelCalcUi;
Screen* m_screen = nullptr;
bool screenMutex = false;
bool hasScheduledScreen = false;
Screen* scheduledScreen = nullptr;
int m_frames = 0;
volatile bool pause = false;
// @todo make static
LocalPlayer* player = nullptr;
IInputHolder* inputHolder = nullptr;
Mob* cameraTargetPlayer = nullptr;
bool _supportsNonTouchscreen = false;
bool isLookingForMultiplayer = false;
bool _powerVr = false;
Options m_options{*this};
Textures m_textures{m_options, *m_platform};
ScreenChooser screenChooser{*this};
Gui m_gui{*this};
};

15
src/MinecraftServer.cpp Normal file
View File

@@ -0,0 +1,15 @@
#include "MinecraftServer.hpp"
#include <Minecraft.hpp>
#include <network/RakNetInstance.hpp>
void MinecraftServer::hostMultiplayer(int port) {
Minecraft::hostMultiplayer(port);
raknetInstance->host("Server", port, 16);
}
std::string MinecraftServer::getServerName() {
// @todo read server name from config
return "Dedicated server 0.6.1";
}

10
src/MinecraftServer.hpp Normal file
View File

@@ -0,0 +1,10 @@
#pragma once
#include <Minecraft.hpp>
class MinecraftServer : public Minecraft {
public:
using Minecraft::Minecraft;
void hostMultiplayer(int port) override;
std::string getServerName() override;
};

View File

@@ -1,428 +0,0 @@
#include "NinecraftApp.h"
//#include <EGL/egl.h>
#ifdef RPI
//#define NO_STORAGE
#endif
#include <errno.h>
#include "platform/input/Mouse.h"
#include "platform/input/Multitouch.h"
#include "world/item/Item.h"
#include "world/level/Level.h"
#include "world/level/biome/Biome.h"
#include "world/level/material/Material.h"
#include "world/entity/MobCategory.h"
//#include "world/level/storage/FolderMethods.h"
#ifndef STANDALONE_SERVER
#include "client/gui/screens/StartMenuScreen.h"
#include "client/gui/screens/UsernameScreen.h"
#endif
#include "client/player/LocalPlayer.h"
#ifndef STANDALONE_SERVER
#include "client/renderer/gles.h"
#include "client/renderer/Chunk.h"
#include "client/renderer/LevelRenderer.h"
#include "client/renderer/Tesselator.h"
#endif
// sorry for raknet dependency, but I'm too lazy to find another getTime method
#include "raknet/GetTime.h"
#include "network/RakNetInstance.h"
#include "network/ClientSideNetworkHandler.h"
#include "client/gui/screens/ProgressScreen.h"
//#include "world/entity/player/Inventory2.h"
#if !defined(DEMO_MODE) && !defined(APPLE_DEMO_PROMOTION) && !defined(NO_STORAGE)
#include "world/level/storage/ExternalFileLevelStorageSource.h"
#else
#include "world/level/storage/MemoryLevelStorageSource.h"
#endif
#ifndef STANDALONE_SERVER
#include "client/renderer/Textures.h"
#include "client/renderer/entity/ItemRenderer.h"
#endif
#include "world/item/crafting/Recipes.h"
#include "world/level/tile/entity/TileEntity.h"
#ifndef STANDALONE_SERVER
#include "client/renderer/EntityTileRenderer.h"
#endif
bool NinecraftApp::_hasInitedStatics = false;
NinecraftApp::NinecraftApp()
: _verbose(true),
_lastTickMs(0),
_frames(0)
{
#if defined(ANDROID) || defined(__APPLE__) || defined(RPI)
signal(SIGPIPE, SIG_IGN);
#endif
}
NinecraftApp::~NinecraftApp()
{
teardown();
}
void NinecraftApp::init()
{
// Global initialization goes here
Mth::initMth();
//#ifdef DEMO_MODE
//writeDemoFile();
//#endif
// If we're running Android, only initialize
// the first time class is instanced
#ifdef ANDROID
if (!_hasInitedStatics) {
_hasInitedStatics = true;
#endif
Material::initMaterials();
MobCategory::initMobCategories();
Tile::initTiles();
Item::initItems();
Biome::initBiomes();
TileEntity::initTileEntities();
#ifdef ANDROID
}
#endif
#ifndef STANDALONE_SERVER
initGLStates();
Tesselator::instance.init();
I18n::loadLanguage(platform(), "en_US");
#endif
if (!externalStoragePath.empty()) {
options.setOptionsFilePath(externalStoragePath);
}
Minecraft::init();
#if !defined(DEMO_MODE) && !defined(APPLE_DEMO_PROMOTION) && !defined(NO_STORAGE)
storageSource = new ExternalFileLevelStorageSource(externalStoragePath, externalCacheStoragePath);
#else
storageSource = new MemoryLevelStorageSource();
#endif
_running = false;
#ifndef STANDALONE_SERVER
LOGI("This: %p\n", this);
screenChooser.setScreen(SCREEN_STARTMENU);
if (options.getBooleanValue(OPTIONS_FIRST_LAUNCH)) {
options.toggle(OPTIONS_FIRST_LAUNCH);
setScreen(new UsernameScreen());
}
#else
hostMultiplayer();
#endif
}
void NinecraftApp::teardown()
{
// Note: Don't tear down statics if we run on Android
// (we might change this in the future)
#ifndef ANDROID
Biome::teardownBiomes();
Item ::teardownItems();
Tile ::teardownTiles();
Material::teardownMaterials();
Recipes ::teardownRecipes();
TileEntity::teardownTileEntities();
#endif
#ifdef WIN32
ItemRenderer::teardown_static();
if (EntityTileRenderer::instance != NULL) {
delete EntityTileRenderer::instance;
EntityTileRenderer::instance = NULL;
}
TileEntityRenderDispatcher::destroy();
#endif
}
void NinecraftApp::update()
{
++_frames;
// Generate Multitouch active pointer list
Multitouch::commit();
#ifndef ANDROID_PUBLISH
//testCreationAndDestruction();
//testJoiningAndDestruction();
#endif /*ANDROID_PUBLISH*/
Minecraft::update();
swapBuffers();
Mouse::reset2();
// Restart the server if (our modded) RakNet reports an error
if (level && raknetInstance->isProbablyBroken() && raknetInstance->isServer()) {
restartServer();
}
#ifndef WIN32
updateStats();
#endif
}
void NinecraftApp::updateStats()
{
#ifndef STANDALONE_SERVER
if (Options::debugGl)
LOGI("--------------------------------------------\n");
//*
int now = getTimeMs();
//int since = now - _lastTickMs;
if (now >= lastTime + 1000)
{
if (player) {
LOGI("%d fps \t%3d chunk updates. (%.2f, %.2f, %.2f)\n",
_frames, Chunk::updates, player->x, player->y, player->z);
Chunk::resetUpdates();
//static int _n = 0;
//if (++_n % 5 == -1) { // @note: -1
// static char filename[256];
// sprintf(filename, "%s/games/com.mojang/img_%.4d.jpg", externalStoragePath.c_str(), _n/5);
// _context.platform->saveScreenshot(filename, width, height);
//}
LOGI("%s", levelRenderer->gatherStats1().c_str());
//printf("Texture swaps (this frame): %d\n", Textures::textureChanges);
} else {
LOGI("%d fps\n", _frames);
}
//const int* pointerIds;
//int pointerCount = Multitouch::getActivePointerIds(&pointerIds);
//if (pointerCount) {
// std::string s = "Pointers (";
// s += (char)(48 + pointerCount);
// s += ": ";
// for (int i = 0; i < pointerCount; ++i) {
// s += (char)(48 + pointerIds[i]);
// s += ", ";
// }
// LOGI("%s\n", s.c_str());
//}
lastTime = now;
_frames = 0;
#ifdef GLDEBUG
while (1) {
int error = glGetError();
if (error == GL_NO_ERROR) break;
LOGI("#################### GL-ERROR: %d\t#####################\n", error);
LOGI("#################### GL-ERROR: %d\t#####################\n", error);
LOGI("#################### GL-ERROR: %d\t#####################\n", error);
}
#endif
}
Textures::textureChanges = 0;
/**/
#endif /* STANDALONE_SERVER */
}
void NinecraftApp::initGLStates()
{
#ifndef STANDALONE_SERVER
//glShadeModel2(GL_SMOOTH);
//glClearDepthf(1.0f);
glEnable2(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glDepthRangef(0, 1);
glEnable2(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.1f);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glEnable2(GL_TEXTURE_2D);
#ifndef _EMSCRIPTEN_
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
#endif
// Both updates isPowerVR flag in java and returns if the graphics chip is PowerVR SGX or not
_powerVr = platform()->isPowerVR();
#ifdef __APPLE__
_isSuperFast = platform()->isSuperFast();
#endif
//glLineWidth(4);
#endif /* STANDALONE_SERVER */
}
void NinecraftApp::restartServer() {
if (!level) return;
for (int i = level->players.size()-1; i >= 0; --i) {
Player* p = level->players[i];
if (p != player)
level->removeEntity(p);
}
raknetInstance->resetIsBroken();
#ifndef STANDALONE_SERVER
gui.addMessage("This server has restarted!");
#endif
hostMultiplayer();
if (netCallback) netCallback->levelGenerated(level);
}
bool NinecraftApp::handleBack(bool isDown)
{
if (isGeneratingLevel)
{
return true;
}
if (level)
{
if (!isDown)
{
if (screen)
{
if (!screen->handleBackEvent(isDown))
{
if (player->containerMenu) player->closeContainer();
setScreen(NULL);
}
return true;
} else {
pauseGame(true);
}
//leaveGame();
return false;
}
return true;
}
else if (screen)
{
return screen->handleBackEvent(isDown);
}
return false;
}
void NinecraftApp::onGraphicsReset()
{
#ifndef STANDALONE_SERVER
initGLStates();
Tesselator::instance.init();
Minecraft::onGraphicsReset();
#endif
}
#ifndef ANDROID_PUBLISH
static int _state = -1;
static int _stateTicksLeft = 0;
void NinecraftApp::testCreationAndDestruction()
{
if (_state == -1) {
_stateTicksLeft = 100;
_state = 0;
}
if (_state == 0) {
if (--_stateTicksLeft <= 0)
_state = 1;
}
else if (_state == 1) {
getLevelSource()->deleteLevel("perf");
int seed = getEpochTimeS();
LOGI(">seed %d\n", seed);
selectLevel("perf", "perf", LevelSettings(seed, GameType::Creative));
hostMultiplayer();
#ifndef STANDALONE_SERVER
setScreen(new ProgressScreen());
#endif
_state = 2;
_stateTicksLeft = 1000;//25000;//00;
}
else if (_state == 2) {
if (isLevelGenerated()) {
if (--_stateTicksLeft <= 0) {
_state = 3;
}
}
} else if (_state == 3) {
leaveGame();
_state = 1;
}
}
void NinecraftApp::testJoiningAndDestruction()
{
if (_state == -1) {
//LightUpdate sz[2] = { LightUpdate(LightLayer::Block, 0, 0, 0, 1, 1, 1),
// LightUpdate(LightLayer::Sky, 0, 0, 0, 1, 1, 1) };
//LOGI("size of lightupdate: %lu == %d\n", sizeof(LightUpdate), (const char*)&sz[1] - (const char*)&sz[0]);
_stateTicksLeft = 100;
_state = 0;
}
if (_state == 0) {
if (--_stateTicksLeft <= 0) {
raknetInstance->clearServerList();
locateMultiplayer();
_state = 1;
}
}
else if (_state == 1) {
if (!raknetInstance->getServerList().empty()) {
PingedCompatibleServer s = raknetInstance->getServerList().at(0);
if (s.name.GetLength() > 0) {
joinMultiplayer(s);
#ifndef STANDALONE_SERVER
setScreen(new ProgressScreen());
#endif
_state = 2;
_stateTicksLeft = 80;//1000;
}
}
}
else if (_state == 2) {
if (isLevelGenerated()) {
if (--_stateTicksLeft <= 0) {
_state = 3;
}
}
} else if (_state == 3) {
leaveGame();
_stateTicksLeft = 50;
_state = 0;
}
}
#endif /*ANDROID_PUBLISH*/
/*
void NinecraftApp::writeDemoFile() {
std::string path = externalStoragePath + "/games";
if (createFolderIfNotExists(path.c_str())) {
path += "/com.mojang";
if (createFolderIfNotExists(path.c_str())) {
path += "/minecraftpe";
if (createFolderIfNotExists(path.c_str())) {
path += "/played_demo";
FILE* fp = fopen(path.c_str(), "w");
if (fp) fclose(fp);
}}}
}
bool NinecraftApp::hasPlayedDemo() {
std::string filename = externalStoragePath + "/games/com.mojang/minecraftpe/played_demo";
FILE* fp = fopen(filename.c_str(), "r");
if (!fp) return false;
fclose(fp);
return true;
}
*/

View File

@@ -1,52 +0,0 @@
#ifndef NINECRAFTAPP_H__
#define NINECRAFTAPP_H__
#include "world/Pos.h"
#include "App.h"
#include "client/Minecraft.h"
#include "world/level/storage/MemoryLevelStorage.h"
#include <string>
class Level;
class LocalPlayer;
class ExternalFileLevelStorageSource;
class NinecraftApp: public Minecraft
{
public:
NinecraftApp();
~NinecraftApp();
void init();
void teardown();
void update();
virtual bool handleBack(bool isDown);
protected:
void onGraphicsReset();
private:
void initGLStates();
void restartServer();
void updateStats();
//void writeDemoFile();
//bool hasPlayedDemo();
#ifndef ANDROID_PUBLISH
void testCreationAndDestruction();
void testJoiningAndDestruction();
#endif /*ANDROID_PUBLISH*/
bool _verbose;
int _frames;
int _lastTickMs;
static bool _hasInitedStatics;
};
#endif//NINECRAFTAPP_H__

View File

@@ -1,4 +1,4 @@
#include "Performance.h" #include "Performance.hpp"
/*static*/ /*static*/
StopwatchHandler Performance::watches; StopwatchHandler Performance::watches;

View File

@@ -1,12 +0,0 @@
#ifndef PERFORMANCE_H__
#define PERFORMANCE_H__
#include "platform/time.h"
class Performance
{
public:
static StopwatchHandler watches;
};
#endif /*PERFORMANCE_H__*/

10
src/Performance.hpp Executable file
View File

@@ -0,0 +1,10 @@
#pragma once
#include "platform/time.hpp"
class Performance
{
public:
static StopwatchHandler watches;
};

View File

@@ -1,16 +1,16 @@
#include "SharedConstants.h" #include "SharedConstants.hpp"
namespace Common { namespace Common {
std::string getGameVersionString(const std::string& versionSuffix /* = "" */) std::string getGameVersionString(const std::string& versionSuffix /* = "" */)
{ {
std::string result = std::string("v0.6.1") + versionSuffix; std::string result = std::string("v0.6.1") + versionSuffix;
// append 64-bit port marker only on Android 64bit targets // append 64-bit port marker only on Android 64bit targets
#if defined(ANDROID) && (defined(__aarch64__) || defined(__x86_64__)) #if defined(ANDROID) && (defined(__aarch64__) || defined(__x86_64__))
result += " (64-bit port)"; result += " (64-bit port)";
#endif #endif
result += " alpha"; result += " alpha";
return result; return result;
} }
}; };

View File

@@ -1,34 +1,32 @@
#ifndef NET_MINECRAFT_SharedConstants_H__ #pragma once
#define NET_MINECRAFT_SharedConstants_H__
#include <string>
#include <string>
enum LevelGeneratorVersion
enum LevelGeneratorVersion {
{ LGV_ORIGINAL = 0,
LGV_ORIGINAL = 0, };
};
namespace Common {
namespace Common { std::string getGameVersionString(const std::string& versionSuffix = "");
std::string getGameVersionString(const std::string& versionSuffix = ""); }
}
namespace SharedConstants
namespace SharedConstants {
{ // 0.5.0 uses NPv8
// 0.5.0 uses NPv8 // 0.6.0 uses NPv9
// 0.6.0 uses NPv9 const int NetworkProtocolVersion = 9;
const int NetworkProtocolVersion = 9; const int NetworkProtocolLowestSupportedVersion = 9;
const int NetworkProtocolLowestSupportedVersion = 9; const int GameProtocolVersion = 1;
const int GameProtocolVersion = 1; const int GameProtocolLowestSupportedVersion = 1;
const int GameProtocolLowestSupportedVersion = 1;
const int StorageVersion = 3;
const int StorageVersion = 3;
const int MaxChatLength = 100;
const int MaxChatLength = 100;
const int TicksPerSecond = 20;
const int TicksPerSecond = 20;
const int GeneratorVersion = (int)LGV_ORIGINAL;
const int GeneratorVersion = (int)LGV_ORIGINAL; //int FULLBRIGHT_LIGHTVALUE = 15 << 20 | 15 << 4;
//int FULLBRIGHT_LIGHTVALUE = 15 << 20 | 15 << 4; }
}
#endif /*NET_MINECRAFT_SharedConstants_H__*/

View File

@@ -1,16 +1,16 @@
#include "IConfigListener.h" #include "IConfigListener.hpp"
#include "Minecraft.h" #include "Minecraft.hpp"
#ifndef STANDALONE_SERVER #ifndef STANDALONE_SERVER
#include "gui/Gui.h" #include "gui/Gui.hpp"
#endif /* STANDALONE_SERVER */ #endif /* STANDALONE_SERVER */
Config createConfig(Minecraft* mc) { Config createConfig(Minecraft* mc) {
Config c; Config c;
#ifndef STANDALONE_SERVER #ifndef STANDALONE_SERVER
c.setScreenSize(mc->width, mc->height, Gui::GuiScale); c.setScreenSize(mc->width, mc->height, Gui::GuiScale);
#endif #endif
c.pixelCalc = mc->pixelCalc; c.pixelCalc = mc->pixelCalc;
c.pixelCalcUi = mc->pixelCalcUi; c.pixelCalcUi = mc->pixelCalcUi;
c.minecraft = mc; c.minecraft = mc;
c.options = &mc->options; c.options = &mc->options;
return c; return c;
} }

View File

@@ -1,48 +1,46 @@
#ifndef CONFIGLISTENER_H__ #pragma once
#define CONFIGLISTENER_H__
#include "PixelCalc.hpp"
#include "PixelCalc.h" class Minecraft;
class Minecraft; class Options;
class Options;
class Config {
class Config { public:
public: // Screen dimensions and world-to-screen conversion
// Screen dimensions and world-to-screen conversion void setScreenSize(int width, int height, float scale) {
void setScreenSize(int width, int height, float scale) { this->width = width;
this->width = width; this->height = height;
this->height = height; this->guiScale = scale;
this->guiScale = scale; this->invGuiScale = 1.0f / scale;
this->invGuiScale = 1.0f / scale; this->guiWidth = (int)(width * invGuiScale);
this->guiWidth = (int)(width * invGuiScale); this->guiHeight = (int)(height * invGuiScale);
this->guiHeight = (int)(height * invGuiScale); }
}
int width;
int width; int height;
int height;
float guiScale;
float guiScale; float invGuiScale;
float invGuiScale; int guiWidth;
int guiWidth; int guiHeight;
int guiHeight;
PixelCalc pixelCalc;
PixelCalc pixelCalc; PixelCalc pixelCalcUi;
PixelCalc pixelCalcUi;
Minecraft* minecraft;
Minecraft* minecraft; Options* options;
Options* options; };
};
Config createConfig(Minecraft* mc);
Config createConfig(Minecraft* mc);
// Interface for Configuration-Changed listener
// Interface for Configuration-Changed listener // This can mean (for instance);
// This can mean (for instance); // - Screen has changed dimensions, or rotation if rotations are enabled
// - Screen has changed dimensions, or rotation if rotations are enabled // - New input device or control mechanism
// - New input device or control mechanism class IConfigListener
class IConfigListener {
{ public:
public: virtual ~IConfigListener() {}
virtual ~IConfigListener() {} virtual void onConfigChanged(const Config& config) = 0;
virtual void onConfigChanged(const Config& config) = 0; };
};
#endif /*CONFIGLISTENER_H__*/

View File

@@ -1,239 +0,0 @@
#ifndef NET_MINECRAFT_CLIENT__Minecraft_H__
#define NET_MINECRAFT_CLIENT__Minecraft_H__
#include "Options.h"
#include "commands/CommandManager.hpp"
#ifndef STANDALONE_SERVER
#include "MouseHandler.h"
#include "gui/Gui.h"
#include "gui/screens/ScreenChooser.h"
#endif
#include "Timer.h"
//#include "../network/RakNetInstance.h"
#include "../world/phys/HitResult.h"
class Level;
class LocalPlayer;
class IInputHolder;
class Mob;
class Player;
class LevelRenderer;
class GameRenderer;
class ParticleEngine;
class Entity;
class ICreator;
class GameMode;
class Textures;
class CThread;
class SoundEngine;
class Screen;
class Font;
class LevelStorageSource;
class BuildActionIntention;
class PerfRenderer;
class LevelSettings;
class IRakNetInstance;
class NetEventCallback;
class CommandServer;
struct PingedCompatibleServer;
//class ExternalFileLevelStorageSource;
#include "../App.h"
#include "PixelCalc.h"
class AppPlatform;
class AppPlatform_android;
class Minecraft: public App
{
protected:
Minecraft();
public:
virtual ~Minecraft();
void init();
void setSize(int width, int height);
void reloadOptions();
bool supportNonTouchScreen();
bool useTouchscreen();
void grabMouse();
void releaseMouse();
void handleBuildAction(BuildActionIntention*);
void toggleDimension(){}
bool isCreativeMode();
void setIsCreativeMode(bool isCreative);
void setScreen(Screen*);
virtual void selectLevel(const std::string& levelId, const std::string& levelName, const LevelSettings& settings);
virtual void setLevel(Level* level, const std::string& message = "", LocalPlayer* forceInsertPlayer = NULL);
void generateLevel( const std::string& message, Level* level );
LevelStorageSource* getLevelSource();
bool isLookingForMultiplayer;
void locateMultiplayer();
void cancelLocateMultiplayer();
bool joinMultiplayer(const PingedCompatibleServer& server);
bool joinMultiplayerFromString(const std::string& server);
void hostMultiplayer(int port=19132);
Player* respawnPlayer(int playerId);
void respawnPlayer();
void resetPlayer(Player* player);
void doActuallyRespawnPlayer();
void update();
void tick(int nTick, int maxTick);
void tickInput();
bool isOnlineClient();
bool isOnline();
void pauseGame(bool isBackPaused);
void gameLostFocus();
void prepareLevel(const std::string& message);
void leaveGame(bool renameLevel = false);
int getProgressStatusId();
const char* getProgressMessage();
ICreator* getCreator();
// void onGraphicsLost() {}
void onGraphicsReset();
bool isLevelGenerated();
void handleMouseDown(int button, bool down);
void audioEngineOn();
void audioEngineOff();
bool isPowerVR() { return _powerVr; }
bool isKindleFire(int kindleVersion);
bool transformResolution(int* w, int* h);
void optionUpdated(OptionId option, bool value);
void optionUpdated(OptionId option, float value);
void optionUpdated(OptionId option, int value);
int getTicks() { return ticks; }
void addMessage(const std::string& msg);
#ifdef __APPLE__
bool _isSuperFast;
bool isSuperFast() { return _isSuperFast; }
#endif
CommandManager& commandManager() { return m_commandManager; }
protected:
void _levelGenerated();
private:
static void* prepareLevel_tspawn(void *p_param);
void _reloadInput();
public:
int width;
int height;
// Vars that the platform is allowed to use in the future
int commandPort;
int reserved_d1, reserved_d2;
float reserved_f1, reserved_f2;
Options options;
static bool useAmbientOcclusion;
//static bool threadInterrupt;
volatile bool pause;
LevelRenderer* levelRenderer;
GameRenderer* gameRenderer;
ParticleEngine* particleEngine;
SoundEngine* soundEngine;
GameMode* gameMode;
#ifndef STANDALONE_SERVER
Textures* textures;
ScreenChooser screenChooser;
Font* font;
#endif
IRakNetInstance* raknetInstance;
NetEventCallback* netCallback;
int lastTime;
int lastTickTime;
float ticksSinceLastUpdate;
Level* level;
LocalPlayer* player;
IInputHolder* inputHolder;
Mob* cameraTargetPlayer;
#ifndef STANDALONE_SERVER
Gui gui;
#endif
CThread* generateLevelThread;
Screen* screen;
static int customDebugId;
static const int CDI_NONE = 0;
static const int CDI_GRAPHICS = 1;
#ifndef STANDALONE_SERVER
MouseHandler mouseHandler;
#endif
bool mouseGrabbed;
PixelCalc pixelCalc;
PixelCalc pixelCalcUi;
HitResult hitResult;
volatile int progressStagePercentage;
// This field is initialized in main()
// It sets the base path to where worlds can be written (sdcard on android)
std::string externalStoragePath;
std::string externalCacheStoragePath;
protected:
Timer timer;
// @note @attn @warn: this is dangerous as fuck!
volatile bool isGeneratingLevel;
bool _hasSignaledGeneratingLevelFinished;
LevelStorageSource* storageSource;
bool _running;
bool _powerVr;
private:
volatile int progressStageStatusId;
static const char* progressMessages[];
int missTime;
int ticks;
bool screenMutex;
bool hasScheduledScreen;
Screen* scheduledScreen;
int _licenseId;
bool _supportsNonTouchscreen;
bool _isCreativeMode;
//int _respawnPlayerTicks;
Player* _pendingRemovePlayer; // @attn @todo @fix: remove this shait and fix the respawn behaviour
PerfRenderer* _perfRenderer;
CommandServer* _commandServer;
CommandManager m_commandManager;
};
#endif /*NET_MINECRAFT_CLIENT__Minecraft_H__*/

View File

@@ -1,60 +1,60 @@
#include "MouseHandler.h" #include "MouseHandler.hpp"
#include "player/input/ITurnInput.h" #include "player/input/ITurnInput.hpp"
#ifdef RPI #ifdef RPI
#include <SDL/SDL.h> #include <SDL/SDL.h>
#endif #endif
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#endif #endif
MouseHandler::MouseHandler( ITurnInput* turnInput ) MouseHandler::MouseHandler( ITurnInput* turnInput )
: _turnInput(turnInput) : _turnInput(turnInput)
{} {}
MouseHandler::MouseHandler() MouseHandler::MouseHandler()
: _turnInput(0) : _turnInput(0)
{} {}
MouseHandler::~MouseHandler() { MouseHandler::~MouseHandler() {
} }
void MouseHandler::setTurnInput( ITurnInput* turnInput ) { void MouseHandler::setTurnInput( ITurnInput* turnInput ) {
_turnInput = turnInput; _turnInput = turnInput;
} }
void MouseHandler::grab() { void MouseHandler::grab() {
xd = 0; xd = 0;
yd = 0; yd = 0;
#if defined(RPI) #if defined(RPI)
//LOGI("Grabbing input!\n"); //LOGI("Grabbing input!\n");
SDL_WM_GrabInput(SDL_GRAB_ON); SDL_WM_GrabInput(SDL_GRAB_ON);
SDL_ShowCursor(0); SDL_ShowCursor(0);
#endif #endif
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
glfwSetInputMode(glfwGetCurrentContext(), GLFW_CURSOR, GLFW_CURSOR_DISABLED); glfwSetInputMode(glfwGetCurrentContext(), GLFW_CURSOR, GLFW_CURSOR_DISABLED);
#endif #endif
} }
void MouseHandler::release() { void MouseHandler::release() {
#if defined(RPI) #if defined(RPI)
//LOGI("Releasing input!\n"); //LOGI("Releasing input!\n");
SDL_WM_GrabInput(SDL_GRAB_OFF); SDL_WM_GrabInput(SDL_GRAB_OFF);
SDL_ShowCursor(1); SDL_ShowCursor(1);
#endif #endif
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
glfwSetInputMode(glfwGetCurrentContext(), GLFW_CURSOR, GLFW_CURSOR_NORMAL); glfwSetInputMode(glfwGetCurrentContext(), GLFW_CURSOR, GLFW_CURSOR_NORMAL);
#endif #endif
} }
void MouseHandler::poll() { void MouseHandler::poll() {
if (_turnInput != 0) { if (_turnInput != 0) {
TurnDelta td = _turnInput->getTurnDelta(); TurnDelta td = _turnInput->getTurnDelta();
xd = td.x; xd = td.x;
yd = td.y; yd = td.y;
} }
} }

View File

@@ -1,28 +1,26 @@
#ifndef NET_MINECRAFT_CLIENT__MouseHandler_H__ #pragma once
#define NET_MINECRAFT_CLIENT__MouseHandler_H__
//package net.minecraft.client;
//package net.minecraft.client;
class ITurnInput;
class ITurnInput;
class MouseHandler
class MouseHandler {
{ public:
public: MouseHandler(ITurnInput* turnInput);
MouseHandler(ITurnInput* turnInput); MouseHandler();
MouseHandler(); ~MouseHandler();
~MouseHandler();
void setTurnInput(ITurnInput* turnInput);
void setTurnInput(ITurnInput* turnInput);
void grab();
void grab(); void release();
void release();
void poll();
void poll();
float xd, yd;
float xd, yd; private:
private: int toSkip;
int toSkip; ITurnInput* _turnInput;
ITurnInput* _turnInput; };
};
#endif /*NET_MINECRAFT_CLIENT__MouseHandler_H__*/

View File

@@ -1,4 +1,4 @@
#include "Option.h" #include "Option.hpp"
#include <sstream> #include <sstream>
#include <cstdio> #include <cstdio>

View File

@@ -1,7 +1,7 @@
#pragma once #pragma once
#include <sstream> #include <sstream>
#include <type_traits> #include <type_traits>
#include <util/Mth.h> #include <util/Mth.hpp>
/* /*
template<typename T> template<typename T>
struct is_option_type : std::false_type {}; struct is_option_type : std::false_type {};

View File

@@ -1,4 +1,4 @@
#include "OptionStrings.h" #include "OptionStrings.hpp"
const char* OptionStrings::Multiplayer_Username = "mp_username"; const char* OptionStrings::Multiplayer_Username = "mp_username";
const char* OptionStrings::Multiplayer_ServerVisible = "mp_server_visible_default"; const char* OptionStrings::Multiplayer_ServerVisible = "mp_server_visible_default";

View File

@@ -1,5 +1,4 @@
#ifndef NET_MINECRAFT_CLIENT__OptionStrings_H__ #pragma once
#define NET_MINECRAFT_CLIENT__OptionStrings_H__
class OptionStrings { class OptionStrings {
public: public:
@@ -33,4 +32,3 @@ public:
}; };
#endif /*NET_MINECRAFT_CLIENT__OptionsStrings_H__*/

View File

@@ -1,302 +1,297 @@
#include "Options.h" #include "Options.hpp"
#include "OptionStrings.h" #include "world/Difficulty.hpp"
#include "Minecraft.h" #include <MinecraftClient.hpp>
#include "../platform/log.h"
#include "../world/Difficulty.h" bool Options::debugGl = false;
#include <cmath>
// OPTIONS TABLE
#include <memory>
OptionInt difficulty("difficulty", Difficulty::NORMAL, 0, Difficulty::COUNT);
bool Options::debugGl = false; OptionBool hidegui("hidegui", false);
OptionBool thirdPersonView("thirdperson", false);
// OPTIONS TABLE OptionBool renderDebug("renderDebug", false);
OptionBool smoothCamera("smoothCamera", false);
OptionInt difficulty("difficulty", Difficulty::NORMAL, 0, Difficulty::COUNT); OptionBool fixedCamera("fixedCamera", false);
OptionBool hidegui("hidegui", false); OptionBool isFlying("isflying", false);
OptionBool thirdPersonView("thirdperson", false); OptionBool barOnTop("barOnTop", false);
OptionBool renderDebug("renderDebug", false); OptionBool allowSprint("allowSprint", true);
OptionBool smoothCamera("smoothCamera", false); OptionBool rpiCursor("rpiCursor", false);
OptionBool fixedCamera("fixedCamera", false); OptionBool autoJump("autoJump", true);
OptionBool isFlying("isflying", false);
OptionBool barOnTop("barOnTop", false);
OptionBool allowSprint("allowSprint", true); OptionFloat flySpeed("flySpeed", 1.f);
OptionBool rpiCursor("rpiCursor", false); OptionFloat cameraSpeed("cameraSpeed", 1.f);
OptionBool autoJump("autoJump", true);
OptionInt guiScale("guiScale", 0, 0, 5);
OptionFloat flySpeed("flySpeed", 1.f); OptionString skin("skin", "Default");
OptionFloat cameraSpeed("cameraSpeed", 1.f);
#ifdef RPI
OptionInt guiScale("guiScale", 0, 0, 5); OptionString username("username", "StevePi");
#else
OptionString skin("skin", "Default"); OptionString username("username", "Steve");
#endif
#ifdef RPI
OptionString username("username", "StevePi"); OptionBool destroyVibration("destroyVibration", true);
#else OptionBool isLeftHanded("isLeftHanded", false);
OptionString username("username", "Steve"); OptionBool isJoyTouchArea("isJoyTouchArea", false);
#endif
OptionFloat musicVolume("music", 1.f, MUSIC_MIN_VALUE, MUSIC_MAX_VALUE);
OptionBool destroyVibration("destroyVibration", true); OptionFloat soundVolume("sound", 1.f, SOUND_MIN_VALUE, SOUND_MAX_VALUE);
OptionBool isLeftHanded("isLeftHanded", false);
OptionBool isJoyTouchArea("isJoyTouchArea", false); OptionFloat sensitivityOpt("sensitivity", 0.5f, SENSITIVITY_MIN_VALUE, SENSITIVITY_MAX_VALUE);
OptionFloat musicVolume("music", 1.f, MUSIC_MIN_VALUE, MUSIC_MAX_VALUE); OptionBool invertYMouse("invertMouse", false);
OptionFloat soundVolume("sound", 1.f, SOUND_MIN_VALUE, SOUND_MAX_VALUE); OptionInt viewDistance("renderDistance", 2, 0, 4);
OptionFloat sensitivityOpt("sensitivity", 0.5f, SENSITIVITY_MIN_VALUE, SENSITIVITY_MAX_VALUE); OptionBool anaglyph3d("anaglyph3d", false);
OptionBool limitFramerate("limitFramerate", false);
OptionBool invertYMouse("invertMouse", false); OptionBool vsync("vsync", true);
OptionInt viewDistance("renderDistance", 2, 0, 4); OptionBool fancyGraphics("fancyGraphics", true);
OptionBool viewBobbing("viewBobbing", true);
OptionBool anaglyph3d("anaglyph3d", false); OptionBool ambientOcclusion("ao", false);
OptionBool limitFramerate("limitFramerate", false);
OptionBool vsync("vsync", true); OptionBool useTouchscreen("useTouchscreen", true);
OptionBool fancyGraphics("fancyGraphics", true);
OptionBool viewBobbing("viewBobbing", true); OptionBool serverVisible("servervisible", true);
OptionBool ambientOcclusion("ao", false);
OptionInt keyForward("key.forward", Keyboard::KEY_W);
OptionBool useTouchscreen("useTouchscreen", true); OptionInt keyLeft("key.left", Keyboard::KEY_A);
OptionInt keyBack("key.back", Keyboard::KEY_S);
OptionBool serverVisible("servervisible", true); OptionInt keyRight("key.right", Keyboard::KEY_D);
OptionInt keyJump("key.jump", Keyboard::KEY_SPACE);
OptionInt keyForward("key.forward", Keyboard::KEY_W); OptionInt keyInventory("key.inventory", Keyboard::KEY_E);
OptionInt keyLeft("key.left", Keyboard::KEY_A); OptionInt keySneak("key.sneak", Keyboard::KEY_LSHIFT);
OptionInt keyBack("key.back", Keyboard::KEY_S); OptionInt keyDrop("key.drop", Keyboard::KEY_Q);
OptionInt keyRight("key.right", Keyboard::KEY_D); OptionInt keyChat("key.chat", Keyboard::KEY_T);
OptionInt keyJump("key.jump", Keyboard::KEY_SPACE); OptionInt keyFog("key.fog", Keyboard::KEY_F);
OptionInt keyInventory("key.inventory", Keyboard::KEY_E); OptionInt keyUse("key.use", Keyboard::KEY_U);
OptionInt keySneak("key.sneak", Keyboard::KEY_LSHIFT);
OptionInt keyDrop("key.drop", Keyboard::KEY_Q); // TODO: make human readable keycodes here
OptionInt keyChat("key.chat", Keyboard::KEY_T); OptionInt keyMenuNext("key.menu.next", 40);
OptionInt keyFog("key.fog", Keyboard::KEY_F); OptionInt keyMenuPrev("key.menu.previous", 38);
OptionInt keyUse("key.use", Keyboard::KEY_U); OptionInt keyMenuOk("key.menu.ok", 13);
OptionInt keyMenuCancel("key.menu.cancel", 8);
// TODO: make human readable keycodes here
OptionInt keyMenuNext("key.menu.next", 40); OptionBool firstLaunch("firstLaunch", true);
OptionInt keyMenuPrev("key.menu.previous", 38);
OptionInt keyMenuOk("key.menu.ok", 13); OptionString lastIp("lastip");
OptionInt keyMenuCancel("key.menu.cancel", 8);
void Options::initTable() {
OptionBool firstLaunch("firstLaunch", true); m_options[OPTIONS_DIFFICULTY] = &difficulty;
m_options[OPTIONS_HIDEGUI] = &hidegui;
OptionString lastIp("lastip"); m_options[OPTIONS_THIRD_PERSON_VIEW] = &thirdPersonView;
m_options[OPTIONS_RENDER_DEBUG] = &renderDebug;
void Options::initTable() { m_options[OPTIONS_SMOOTH_CAMERA] = &smoothCamera;
m_options[OPTIONS_DIFFICULTY] = &difficulty; m_options[OPTIONS_FIXED_CAMERA] = &fixedCamera;
m_options[OPTIONS_HIDEGUI] = &hidegui; m_options[OPTIONS_IS_FLYING] = &isFlying;
m_options[OPTIONS_THIRD_PERSON_VIEW] = &thirdPersonView;
m_options[OPTIONS_RENDER_DEBUG] = &renderDebug; m_options[OPTIONS_FLY_SPEED] = &flySpeed;
m_options[OPTIONS_SMOOTH_CAMERA] = &smoothCamera; m_options[OPTIONS_CAMERA_SPEED] = &cameraSpeed;
m_options[OPTIONS_FIXED_CAMERA] = &fixedCamera;
m_options[OPTIONS_IS_FLYING] = &isFlying; m_options[OPTIONS_GUI_SCALE] = &guiScale;
m_options[OPTIONS_FLY_SPEED] = &flySpeed; m_options[OPTIONS_DESTROY_VIBRATION] = &destroyVibration;
m_options[OPTIONS_CAMERA_SPEED] = &cameraSpeed;
m_options[OPTIONS_IS_LEFT_HANDED] = &isLeftHanded;
m_options[OPTIONS_GUI_SCALE] = &guiScale; m_options[OPTIONS_IS_JOY_TOUCH_AREA] = &isJoyTouchArea;
m_options[OPTIONS_DESTROY_VIBRATION] = &destroyVibration; m_options[OPTIONS_MUSIC_VOLUME] = &musicVolume;
m_options[OPTIONS_SOUND_VOLUME] = &soundVolume;
m_options[OPTIONS_IS_LEFT_HANDED] = &isLeftHanded;
m_options[OPTIONS_IS_JOY_TOUCH_AREA] = &isJoyTouchArea; #if defined(PLATFORM_DESKTOP) || defined(RPI)
float sensitivity = sensitivityOpt.get();
m_options[OPTIONS_MUSIC_VOLUME] = &musicVolume; sensitivity *= 0.4f;
m_options[OPTIONS_SOUND_VOLUME] = &soundVolume; sensitivityOpt.set(sensitivity);
#endif
#if defined(PLATFORM_DESKTOP) || defined(RPI)
float sensitivity = sensitivityOpt.get();
sensitivity *= 0.4f; m_options[OPTIONS_GUI_SCALE] = &guiScale;
sensitivityOpt.set(sensitivity);
#endif m_options[OPTIONS_SKIN] = &skin;
m_options[OPTIONS_USERNAME] = &username;
m_options[OPTIONS_GUI_SCALE] = &guiScale; m_options[OPTIONS_DESTROY_VIBRATION] = &destroyVibration;
m_options[OPTIONS_IS_LEFT_HANDED] = &isLeftHanded;
m_options[OPTIONS_SKIN] = &skin;
m_options[OPTIONS_USERNAME] = &username; m_options[OPTIONS_MUSIC_VOLUME] = &musicVolume;
m_options[OPTIONS_SOUND_VOLUME] = &soundVolume;
m_options[OPTIONS_DESTROY_VIBRATION] = &destroyVibration;
m_options[OPTIONS_IS_LEFT_HANDED] = &isLeftHanded; m_options[OPTIONS_SENSITIVITY] = &sensitivityOpt;
m_options[OPTIONS_MUSIC_VOLUME] = &musicVolume; m_options[OPTIONS_INVERT_Y_MOUSE] = &invertYMouse;
m_options[OPTIONS_SOUND_VOLUME] = &soundVolume; m_options[OPTIONS_VIEW_DISTANCE] = &viewDistance;
m_options[OPTIONS_SENSITIVITY] = &sensitivityOpt; m_options[OPTIONS_ANAGLYPH_3D] = &anaglyph3d;
m_options[OPTIONS_LIMIT_FRAMERATE] = &limitFramerate;
m_options[OPTIONS_INVERT_Y_MOUSE] = &invertYMouse; m_options[OPTIONS_VSYNC] = &vsync;
m_options[OPTIONS_VIEW_DISTANCE] = &viewDistance; m_options[OPTIONS_FANCY_GRAPHICS] = &fancyGraphics;
m_options[OPTIONS_VIEW_BOBBING] = &viewBobbing;
m_options[OPTIONS_ANAGLYPH_3D] = &anaglyph3d; m_options[OPTIONS_AMBIENT_OCCLUSION] = &ambientOcclusion;
m_options[OPTIONS_LIMIT_FRAMERATE] = &limitFramerate;
m_options[OPTIONS_VSYNC] = &vsync; m_options[OPTIONS_USE_TOUCHSCREEN] = &useTouchscreen;
m_options[OPTIONS_FANCY_GRAPHICS] = &fancyGraphics;
m_options[OPTIONS_VIEW_BOBBING] = &viewBobbing; m_options[OPTIONS_SERVER_VISIBLE] = &serverVisible;
m_options[OPTIONS_AMBIENT_OCCLUSION] = &ambientOcclusion;
m_options[OPTIONS_KEY_FORWARD] = &keyForward;
m_options[OPTIONS_USE_TOUCHSCREEN] = &useTouchscreen; m_options[OPTIONS_KEY_LEFT] = &keyLeft;
m_options[OPTIONS_KEY_BACK] = &keyBack;
m_options[OPTIONS_SERVER_VISIBLE] = &serverVisible; m_options[OPTIONS_KEY_RIGHT] = &keyRight;
m_options[OPTIONS_KEY_JUMP] = &keyJump;
m_options[OPTIONS_KEY_FORWARD] = &keyForward; m_options[OPTIONS_KEY_INVENTORY] = &keyInventory;
m_options[OPTIONS_KEY_LEFT] = &keyLeft; m_options[OPTIONS_KEY_SNEAK] = &keySneak;
m_options[OPTIONS_KEY_BACK] = &keyBack; m_options[OPTIONS_KEY_DROP] = &keyDrop;
m_options[OPTIONS_KEY_RIGHT] = &keyRight; m_options[OPTIONS_KEY_CHAT] = &keyChat;
m_options[OPTIONS_KEY_JUMP] = &keyJump; m_options[OPTIONS_KEY_FOG] = &keyFog;
m_options[OPTIONS_KEY_INVENTORY] = &keyInventory; m_options[OPTIONS_KEY_USE] = &keyUse;
m_options[OPTIONS_KEY_SNEAK] = &keySneak;
m_options[OPTIONS_KEY_DROP] = &keyDrop; m_options[OPTIONS_KEY_MENU_NEXT] = &keyMenuNext;
m_options[OPTIONS_KEY_CHAT] = &keyChat; m_options[OPTIONS_KEY_MENU_PREV] = &keyMenuPrev;
m_options[OPTIONS_KEY_FOG] = &keyFog; m_options[OPTIONS_KEY_MENU_OK] = &keyMenuOk;
m_options[OPTIONS_KEY_USE] = &keyUse; m_options[OPTIONS_KEY_MENU_CANCEL] = &keyMenuCancel;
m_options[OPTIONS_KEY_MENU_NEXT] = &keyMenuNext; m_options[OPTIONS_FIRST_LAUNCH] = &firstLaunch;
m_options[OPTIONS_KEY_MENU_PREV] = &keyMenuPrev;
m_options[OPTIONS_KEY_MENU_OK] = &keyMenuOk; m_options[OPTIONS_BAR_ON_TOP] = &barOnTop;
m_options[OPTIONS_KEY_MENU_CANCEL] = &keyMenuCancel; m_options[OPTIONS_ALLOW_SPRINT] = &allowSprint;
m_options[OPTIONS_RPI_CURSOR] = &rpiCursor;
m_options[OPTIONS_FIRST_LAUNCH] = &firstLaunch;
m_options[OPTIONS_AUTOJUMP] = &autoJump;
m_options[OPTIONS_BAR_ON_TOP] = &barOnTop; m_options[OPTIONS_LAST_IP] = &lastIp;
m_options[OPTIONS_ALLOW_SPRINT] = &allowSprint; }
m_options[OPTIONS_RPI_CURSOR] = &rpiCursor;
void Options::set(OptionId key, const std::string& value) {
m_options[OPTIONS_AUTOJUMP] = &autoJump; auto option = opt<OptionString>(key);
m_options[OPTIONS_LAST_IP] = &lastIp;
} if (option) {
option->set(value);
void Options::set(OptionId key, const std::string& value) { notifyOptionUpdate(key, value);
auto option = opt<OptionString>(key); }
}
if (option) {
option->set(value); void Options::set(OptionId key, float value) {
notifyOptionUpdate(key, value); auto option = opt<OptionFloat>(key);
}
} if (option) {
option->set(value);
void Options::set(OptionId key, float value) { notifyOptionUpdate(key, value);
auto option = opt<OptionFloat>(key); }
}
if (option) {
option->set(value); void Options::set(OptionId key, int value) {
notifyOptionUpdate(key, value); auto option = opt<OptionInt>(key);
}
} if (option) {
option->set(value);
void Options::set(OptionId key, int value) { notifyOptionUpdate(key, value);
auto option = opt<OptionInt>(key); }
}
if (option) {
option->set(value); void Options::toggle(OptionId key) {
notifyOptionUpdate(key, value); auto option = opt<OptionBool>(key);
}
} if (option) {
option->toggle();
void Options::toggle(OptionId key) { notifyOptionUpdate(key, option->get());
auto option = opt<OptionBool>(key); }
}
if (option) {
option->toggle(); void Options::load() {
notifyOptionUpdate(key, option->get()); StringVector optionStrings = optionsFile.getOptionStrings();
}
} for (auto i = 0; i < optionStrings.size(); i += 2) {
const std::string& key = optionStrings[i];
void Options::load() { const std::string& value = optionStrings[i+1];
StringVector optionStrings = optionsFile.getOptionStrings();
// FIXME: woah this is so slow
for (auto i = 0; i < optionStrings.size(); i += 2) { auto opt = std::find_if(m_options.begin(), m_options.end(), [&](auto& it) {
const std::string& key = optionStrings[i]; return it != nullptr && it->getStringId() == key;
const std::string& value = optionStrings[i+1]; });
// FIXME: woah this is so slow if (opt == m_options.end()) continue;
auto opt = std::find_if(m_options.begin(), m_options.end(), [&](auto& it) {
return it != nullptr && it->getStringId() == key; (*opt)->parse(value);
}); /*
// //LOGI("reading key: %s (%s)\n", key.c_str(), value.c_str());
if (opt == m_options.end()) continue;
// // Multiplayer
(*opt)->parse(value); // // if (key == OptionStrings::Multiplayer_Username) username = value;
/* // if (key == OptionStrings::Multiplayer_ServerVisible) {
// //LOGI("reading key: %s (%s)\n", key.c_str(), value.c_str()); // m_options[OPTIONS_SERVER_VISIBLE] = readBool(value);
// }
// // Multiplayer
// // if (key == OptionStrings::Multiplayer_Username) username = value; // // Controls
// if (key == OptionStrings::Multiplayer_ServerVisible) { // if (key == OptionStrings::Controls_Sensitivity) {
// m_options[OPTIONS_SERVER_VISIBLE] = readBool(value); // float sens = readFloat(value);
// }
// // sens is in range [0,1] with default/center at 0.5 (for aesthetics)
// // Controls // // We wanna map it to something like [0.3, 0.9] BUT keep 0.5 @ ~0.5...
// if (key == OptionStrings::Controls_Sensitivity) { // m_options[OPTIONS_SENSITIVITY] = 0.3f + std::pow(1.1f * sens, 1.3f) * 0.42f;
// float sens = readFloat(value); // }
// // sens is in range [0,1] with default/center at 0.5 (for aesthetics) // if (key == OptionStrings::Controls_InvertMouse) {
// // We wanna map it to something like [0.3, 0.9] BUT keep 0.5 @ ~0.5... // m_options[OPTIONS_INVERT_Y_MOUSE] = readBool(value);
// m_options[OPTIONS_SENSITIVITY] = 0.3f + std::pow(1.1f * sens, 1.3f) * 0.42f; // }
// }
// if (key == OptionStrings::Controls_IsLefthanded) {
// if (key == OptionStrings::Controls_InvertMouse) { // m_options[OPTIONS_IS_LEFT_HANDED] = readBool(value);
// m_options[OPTIONS_INVERT_Y_MOUSE] = readBool(value); // }
// }
// if (key == OptionStrings::Controls_UseTouchJoypad) {
// if (key == OptionStrings::Controls_IsLefthanded) { // m_options[OPTIONS_IS_JOY_TOUCH_AREA] = readBool(value) && minecraft->useTouchscreen();
// m_options[OPTIONS_IS_LEFT_HANDED] = readBool(value); // }
// }
// // Feedback
// if (key == OptionStrings::Controls_UseTouchJoypad) { // if (key == OptionStrings::Controls_FeedbackVibration) {
// m_options[OPTIONS_IS_JOY_TOUCH_AREA] = readBool(value) && minecraft->useTouchscreen(); // m_options[OPTIONS_DESTROY_VIBRATION] = readBool(value);
// } // }
// // Feedback // // Graphics
// if (key == OptionStrings::Controls_FeedbackVibration) { // if (key == OptionStrings::Graphics_Fancy) {
// m_options[OPTIONS_DESTROY_VIBRATION] = readBool(value); // m_options[OPTIONS_FANCY_GRAPHICS] = readBool(value);
// } // }
// // Graphics // // Graphics extras
// if (key == OptionStrings::Graphics_Fancy) { // if (key == OptionStrings::Graphics_Vsync) {
// m_options[OPTIONS_FANCY_GRAPHICS] = readBool(value); // m_options[OPTIONS_VSYNC] = readBool(value);
// } // }
// // Graphics extras // if (key == OptionStrings::Graphics_GUIScale) {
// if (key == OptionStrings::Graphics_Vsync) { // m_options[OPTIONS_GUI_SCALE] = readInt(value) % 5;
// m_options[OPTIONS_VSYNC] = readBool(value); // }
// }
// // Game
// if (key == OptionStrings::Graphics_GUIScale) { // if (key == OptionStrings::Game_DifficultyLevel) {
// m_options[OPTIONS_GUI_SCALE] = readInt(value) % 5; // readInt(value, difficulty);
// } // // Only support peaceful and normal right now
// if (difficulty != Difficulty::PEACEFUL && difficulty != Difficulty::NORMAL)
// // Game // difficulty = Difficulty::NORMAL;
// if (key == OptionStrings::Game_DifficultyLevel) { // }*/
// readInt(value, difficulty); }
// // Only support peaceful and normal right now }
// if (difficulty != Difficulty::PEACEFUL && difficulty != Difficulty::NORMAL)
// difficulty = Difficulty::NORMAL; void Options::save() {
// }*/ StringVector stringVec;
}
} for (auto& it : m_options) {
if (it) stringVec.push_back(it->serialize());
void Options::save() { }
StringVector stringVec;
optionsFile.save(stringVec);
for (auto& it : m_options) { }
if (it) stringVec.push_back(it->serialize());
} void Options::setOptionsFilePath(const std::string& path) {
optionsFile.setOptionsPath(path + "/options.txt");
optionsFile.save(stringVec); }
}
void Options::notifyOptionUpdate(OptionId key, bool value) {
void Options::setOptionsFilePath(const std::string& path) { minecraft.optionUpdated(key, value);
optionsFile.setOptionsPath(path + "/options.txt"); }
}
void Options::notifyOptionUpdate(OptionId key, float value) {
void Options::notifyOptionUpdate(OptionId key, bool value) { minecraft.optionUpdated(key, value);
minecraft->optionUpdated(key, value); }
}
void Options::notifyOptionUpdate(OptionId key, int value) {
void Options::notifyOptionUpdate(OptionId key, float value) { minecraft.optionUpdated(key, value);
minecraft->optionUpdated(key, value); }
}
void Options::notifyOptionUpdate(OptionId key, int value) {
minecraft->optionUpdated(key, value);
}

View File

@@ -1,167 +1,164 @@
#ifndef NET_MINECRAFT_CLIENT__Options_H__ #pragma once
#define NET_MINECRAFT_CLIENT__Options_H__
#define SOUND_MIN_VALUE 0.0f
#define SOUND_MIN_VALUE 0.0f #define SOUND_MAX_VALUE 1.0f
#define SOUND_MAX_VALUE 1.0f #define MUSIC_MIN_VALUE 0.0f
#define MUSIC_MIN_VALUE 0.0f #define MUSIC_MAX_VALUE 1.0f
#define MUSIC_MAX_VALUE 1.0f #define SENSITIVITY_MIN_VALUE 0.0f
#define SENSITIVITY_MIN_VALUE 0.0f #define SENSITIVITY_MAX_VALUE 1.0f
#define SENSITIVITY_MAX_VALUE 1.0f #define PIXELS_PER_MILLIMETER_MIN_VALUE 3.0f
#define PIXELS_PER_MILLIMETER_MIN_VALUE 3.0f #define PIXELS_PER_MILLIMETER_MAX_VALUE 4.0f
#define PIXELS_PER_MILLIMETER_MAX_VALUE 4.0f
//package net.minecraft.client;
//package net.minecraft.client;
//#include "locale/Language.hpp"
//#include "locale/Language.h"
#include <string>
#include <string> #include <platform/input/Keyboard.hpp>
#include <cstdio> #include <util/StringUtils.hpp>
#include "../platform/input/Keyboard.h" #include "OptionsFile.hpp"
#include "../util/StringUtils.h" #include "Option.hpp"
#include "OptionsFile.h" #include <array>
#include "Option.h"
#include <array> enum OptionId {
// General
enum OptionId { OPTIONS_DIFFICULTY,
// General OPTIONS_HIDEGUI,
OPTIONS_DIFFICULTY, OPTIONS_THIRD_PERSON_VIEW,
OPTIONS_HIDEGUI, OPTIONS_GUI_SCALE,
OPTIONS_THIRD_PERSON_VIEW, OPTIONS_DESTROY_VIBRATION,
OPTIONS_GUI_SCALE, OPTIONS_MUSIC_VOLUME,
OPTIONS_DESTROY_VIBRATION, OPTIONS_SOUND_VOLUME,
OPTIONS_MUSIC_VOLUME, OPTIONS_SKIN,
OPTIONS_SOUND_VOLUME, OPTIONS_USERNAME,
OPTIONS_SKIN, OPTIONS_SERVER_VISIBLE,
OPTIONS_USERNAME, OPTIONS_BAR_ON_TOP,
OPTIONS_SERVER_VISIBLE, OPTIONS_ALLOW_SPRINT,
OPTIONS_BAR_ON_TOP, OPTIONS_AUTOJUMP,
OPTIONS_ALLOW_SPRINT,
OPTIONS_AUTOJUMP, // Graphics
OPTIONS_RENDER_DEBUG,
// Graphics OPTIONS_SMOOTH_CAMERA,
OPTIONS_RENDER_DEBUG, OPTIONS_FIXED_CAMERA,
OPTIONS_SMOOTH_CAMERA, OPTIONS_VIEW_DISTANCE,
OPTIONS_FIXED_CAMERA, OPTIONS_VIEW_BOBBING,
OPTIONS_VIEW_DISTANCE, OPTIONS_AMBIENT_OCCLUSION,
OPTIONS_VIEW_BOBBING, OPTIONS_ANAGLYPH_3D,
OPTIONS_AMBIENT_OCCLUSION, OPTIONS_LIMIT_FRAMERATE,
OPTIONS_ANAGLYPH_3D, OPTIONS_VSYNC,
OPTIONS_LIMIT_FRAMERATE, OPTIONS_FANCY_GRAPHICS,
OPTIONS_VSYNC,
OPTIONS_FANCY_GRAPHICS, // Cheats / debug
OPTIONS_FLY_SPEED,
// Cheats / debug OPTIONS_CAMERA_SPEED,
OPTIONS_FLY_SPEED, OPTIONS_IS_FLYING,
OPTIONS_CAMERA_SPEED,
OPTIONS_IS_FLYING, // Control
OPTIONS_USE_MOUSE_FOR_DIGGING,
// Control OPTIONS_IS_LEFT_HANDED,
OPTIONS_USE_MOUSE_FOR_DIGGING, OPTIONS_IS_JOY_TOUCH_AREA,
OPTIONS_IS_LEFT_HANDED, OPTIONS_SENSITIVITY,
OPTIONS_IS_JOY_TOUCH_AREA, OPTIONS_INVERT_Y_MOUSE,
OPTIONS_SENSITIVITY, OPTIONS_USE_TOUCHSCREEN,
OPTIONS_INVERT_Y_MOUSE,
OPTIONS_USE_TOUCHSCREEN, OPTIONS_KEY_FORWARD,
OPTIONS_KEY_LEFT,
OPTIONS_KEY_FORWARD, OPTIONS_KEY_BACK,
OPTIONS_KEY_LEFT, OPTIONS_KEY_RIGHT,
OPTIONS_KEY_BACK, OPTIONS_KEY_JUMP,
OPTIONS_KEY_RIGHT, OPTIONS_KEY_INVENTORY,
OPTIONS_KEY_JUMP, OPTIONS_KEY_SNEAK,
OPTIONS_KEY_INVENTORY, OPTIONS_KEY_DROP,
OPTIONS_KEY_SNEAK, OPTIONS_KEY_CHAT,
OPTIONS_KEY_DROP, OPTIONS_KEY_FOG,
OPTIONS_KEY_CHAT, OPTIONS_KEY_USE,
OPTIONS_KEY_FOG,
OPTIONS_KEY_USE, OPTIONS_KEY_MENU_NEXT,
OPTIONS_KEY_MENU_PREV,
OPTIONS_KEY_MENU_NEXT, OPTIONS_KEY_MENU_OK,
OPTIONS_KEY_MENU_PREV, OPTIONS_KEY_MENU_CANCEL,
OPTIONS_KEY_MENU_OK,
OPTIONS_KEY_MENU_CANCEL, OPTIONS_FIRST_LAUNCH,
OPTIONS_LAST_IP,
OPTIONS_FIRST_LAUNCH,
OPTIONS_LAST_IP, OPTIONS_RPI_CURSOR,
// Should be last!
OPTIONS_RPI_CURSOR, OPTIONS_COUNT
// Should be last! };
OPTIONS_COUNT
}; class MinecraftClient;
typedef std::vector<std::string> StringVector;
class Minecraft;
typedef std::vector<std::string> StringVector; class Options
{
class Options public:
{ static bool debugGl;
public:
static bool debugGl; Options(MinecraftClient& minecraft, const std::string& workingDirectory = "")
: minecraft(minecraft) {
Options(Minecraft* minecraft, const std::string& workingDirectory = "") // elements werent initialized so i was getting a garbage pointer and a crash
: minecraft(minecraft) { m_options.fill(nullptr);
// elements werent initialized so i was getting a garbage pointer and a crash initTable();
m_options.fill(nullptr); // load() is deferred to init() where path is configured correctly
initTable(); }
// load() is deferred to init() where path is configured correctly
} void initTable();
void initTable(); int getIntValue(OptionId key) {
auto option = opt<OptionInt>(key);
int getIntValue(OptionId key) { return (option)? option->get() : 0;
auto option = opt<OptionInt>(key); }
return (option)? option->get() : 0;
} std::string getStringValue(OptionId key) {
auto option = opt<OptionString>(key);
std::string getStringValue(OptionId key) { return (option)? option->get() : "";
auto option = opt<OptionString>(key); }
return (option)? option->get() : "";
} float getProgressValue(OptionId key) {
auto option = opt<OptionFloat>(key);
float getProgressValue(OptionId key) { return (option)? option->get() : 0.f;
auto option = opt<OptionFloat>(key); }
return (option)? option->get() : 0.f;
} bool getBooleanValue(OptionId key) {
auto option = opt<OptionBool>(key);
bool getBooleanValue(OptionId key) { return (option)? option->get() : false;
auto option = opt<OptionBool>(key); }
return (option)? option->get() : false;
} float getProgrssMin(OptionId key) {
auto option = opt<OptionFloat>(key);
float getProgrssMin(OptionId key) { return (option)? option->getMin() : 0.f;
auto option = opt<OptionFloat>(key); }
return (option)? option->getMin() : 0.f;
} float getProgrssMax(OptionId key) {
auto option = opt<OptionFloat>(key);
float getProgrssMax(OptionId key) { return (option)? option->getMax() : 0.f;
auto option = opt<OptionFloat>(key); }
return (option)? option->getMax() : 0.f;
} Option* getOpt(OptionId id) { return m_options[id]; }
Option* getOpt(OptionId id) { return m_options[id]; } void load();
void save();
void load(); void set(OptionId key, int value);
void save(); void set(OptionId key, float value);
void set(OptionId key, int value); void set(OptionId key, const std::string& value);
void set(OptionId key, float value); void setOptionsFilePath(const std::string& path);
void set(OptionId key, const std::string& value); void toggle(OptionId key);
void setOptionsFilePath(const std::string& path);
void toggle(OptionId key); void notifyOptionUpdate(OptionId key, bool value);
void notifyOptionUpdate(OptionId key, float value);
void notifyOptionUpdate(OptionId key, bool value); void notifyOptionUpdate(OptionId key, int value);
void notifyOptionUpdate(OptionId key, float value); void notifyOptionUpdate(OptionId key, const std::string& value) {}
void notifyOptionUpdate(OptionId key, int value);
void notifyOptionUpdate(OptionId key, const std::string& value) {} private:
template<typename T>
private: T* opt(OptionId key) {
template<typename T> if (m_options[key] == nullptr) return nullptr;
T* opt(OptionId key) { return dynamic_cast<T*>(m_options[key]);
if (m_options[key] == nullptr) return nullptr; }
return dynamic_cast<T*>(m_options[key]);
} std::array<Option*, OPTIONS_COUNT> m_options;
OptionsFile optionsFile;
std::array<Option*, OPTIONS_COUNT> m_options;
OptionsFile optionsFile; MinecraftClient& minecraft;
};
Minecraft* minecraft;
};
#endif /*NET_MINECRAFT_CLIENT__Options_H__*/

View File

@@ -1,98 +1,98 @@
#include "OptionsFile.h" #include "OptionsFile.hpp"
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <platform/log.h> #include <platform/log.hpp>
#if defined(_WIN32) #if defined(_WIN32)
#include <direct.h> #include <direct.h>
#else #else
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#endif #endif
OptionsFile::OptionsFile() { OptionsFile::OptionsFile() {
#ifdef __APPLE__ #ifdef __APPLE__
settingsPath = "./Documents/options.txt"; settingsPath = "./Documents/options.txt";
#elif defined(ANDROID) #elif defined(ANDROID)
settingsPath = "options.txt"; settingsPath = "options.txt";
#elif defined(__EMSCRIPTEN__) #elif defined(__EMSCRIPTEN__)
settingsPath = "/games/com.mojang/options.txt"; settingsPath = "/games/com.mojang/options.txt";
#else #else
settingsPath = "options.txt"; settingsPath = "options.txt";
#endif #endif
} }
void OptionsFile::setOptionsPath(const std::string& path) { void OptionsFile::setOptionsPath(const std::string& path) {
settingsPath = path; settingsPath = path;
} }
std::string OptionsFile::getOptionsPath() const { std::string OptionsFile::getOptionsPath() const {
return settingsPath; return settingsPath;
} }
void OptionsFile::save(const StringVector& settings) { void OptionsFile::save(const StringVector& settings) {
FILE* pFile = fopen(settingsPath.c_str(), "w"); FILE* pFile = fopen(settingsPath.c_str(), "w");
if (!pFile && errno == ENOENT) { if (!pFile && errno == ENOENT) {
std::string dir = settingsPath; std::string dir = settingsPath;
size_t fpos = dir.find_last_of("/\\"); size_t fpos = dir.find_last_of("/\\");
if (fpos != std::string::npos) { if (fpos != std::string::npos) {
dir.resize(fpos); dir.resize(fpos);
std::string toCreate; std::string toCreate;
for (size_t i = 0; i <= dir.size(); ++i) { for (size_t i = 0; i <= dir.size(); ++i) {
if (i == dir.size() || dir[i] == '/' || dir[i] == '\\') { if (i == dir.size() || dir[i] == '/' || dir[i] == '\\') {
if (!toCreate.empty()) { if (!toCreate.empty()) {
#if defined(_WIN32) #if defined(_WIN32)
_mkdir(toCreate.c_str()); _mkdir(toCreate.c_str());
#else #else
mkdir(toCreate.c_str(), 0755); mkdir(toCreate.c_str(), 0755);
#endif #endif
} }
} }
if (i < dir.size()) if (i < dir.size())
toCreate.push_back(dir[i]); toCreate.push_back(dir[i]);
} }
} }
pFile = fopen(settingsPath.c_str(), "w"); pFile = fopen(settingsPath.c_str(), "w");
} }
if (!pFile) { if (!pFile) {
LOGI("OptionsFile::save failed: %s", strerror(errno)); LOGI("OptionsFile::save failed: %s", strerror(errno));
return; return;
} }
for (const auto& s : settings) { for (const auto& s : settings) {
fprintf(pFile, "%s\n", s.c_str()); fprintf(pFile, "%s\n", s.c_str());
} }
fclose(pFile); fclose(pFile);
} }
StringVector OptionsFile::getOptionStrings() { StringVector OptionsFile::getOptionStrings() {
StringVector returnVector; StringVector returnVector;
FILE* pFile = fopen(settingsPath.c_str(), "r"); FILE* pFile = fopen(settingsPath.c_str(), "r");
if(pFile != NULL) { if(pFile != NULL) {
char lineBuff[128]; char lineBuff[128];
while(fgets(lineBuff, sizeof lineBuff, pFile)) { while(fgets(lineBuff, sizeof lineBuff, pFile)) {
// Strip trailing newline // Strip trailing newline
size_t len = strlen(lineBuff); size_t len = strlen(lineBuff);
while(len > 0 && (lineBuff[len-1] == '\n' || lineBuff[len-1] == '\r')) while(len > 0 && (lineBuff[len-1] == '\n' || lineBuff[len-1] == '\r'))
lineBuff[--len] = '\0'; lineBuff[--len] = '\0';
if(len < 3) continue; if(len < 3) continue;
// Split "key:value" into two separate entries to match update() pairing // Split "key:value" into two separate entries to match update() pairing
char* colon = strchr(lineBuff, ':'); char* colon = strchr(lineBuff, ':');
if(colon) { if(colon) {
returnVector.push_back(std::string(lineBuff, colon - lineBuff)); returnVector.push_back(std::string(lineBuff, colon - lineBuff));
returnVector.push_back(std::string(colon + 1)); returnVector.push_back(std::string(colon + 1));
} }
} }
fclose(pFile); fclose(pFile);
} else { } else {
if (errno != ENOENT) if (errno != ENOENT)
LOGI("OptionsFile::getOptionStrings failed to open '%s' for reading: %s", settingsPath.c_str(), strerror(errno)); LOGI("OptionsFile::getOptionStrings failed to open '%s' for reading: %s", settingsPath.c_str(), strerror(errno));
} }
return returnVector; return returnVector;
} }

View File

@@ -1,21 +1,19 @@
#ifndef NET_MINECRAFT_CLIENT__OptionsFile_H__ #pragma once
#define NET_MINECRAFT_CLIENT__OptionsFile_H__
//package net.minecraft.client;
//package net.minecraft.client; #include <string>
#include <string> #include <vector>
#include <vector> typedef std::vector<std::string> StringVector;
typedef std::vector<std::string> StringVector; class OptionsFile
class OptionsFile {
{ public:
public: OptionsFile();
OptionsFile(); void save(const StringVector& settings);
void save(const StringVector& settings); StringVector getOptionStrings();
StringVector getOptionStrings(); void setOptionsPath(const std::string& path);
void setOptionsPath(const std::string& path); std::string getOptionsPath() const;
std::string getOptionsPath() const;
private:
private: std::string settingsPath;
std::string settingsPath; };
};
#endif /* NET_MINECRAFT_CLIENT__OptionsFile_H__ */

View File

@@ -1,124 +1,122 @@
#ifndef NET_MINECRAFT_CLIENT__Timer_H__ #pragma once
#define NET_MINECRAFT_CLIENT__Timer_H__
//package net.minecraft.client;
//package net.minecraft.client; #include "platform/time.hpp"
#include "../platform/time.h"
class Timer
class Timer {
{ public:
public: Timer(float ticksPerSecond)
Timer(float ticksPerSecond) : ticksPerSecond(ticksPerSecond),
: ticksPerSecond(ticksPerSecond), adjustTime(1.0f),
adjustTime(1.0f), timeScale(1.0f),
timeScale(1.0f), passedTime(0)
passedTime(0) {
{ lastMs = getTimeMs();
lastMs = getTimeMs(); lastMsSysTime = lastMs;
lastMsSysTime = lastMs; lastTime = lastMs / 1000.0f;
lastTime = lastMs / 1000.0f; }
}
void advanceTime() {
void advanceTime() { long nowMs = getTimeMs();
long nowMs = getTimeMs(); long passedMs = nowMs - lastMs;
long passedMs = nowMs - lastMs; long msSysTime = nowMs;//System.nanoTime() / 1000000;
long msSysTime = nowMs;//System.nanoTime() / 1000000;
if (passedMs > 1000) {
if (passedMs > 1000) { long passedMsSysTime = msSysTime - lastMsSysTime;
long passedMsSysTime = msSysTime - lastMsSysTime; if (passedMsSysTime == 0)
if (passedMsSysTime == 0) passedMs = passedMsSysTime = 1;
passedMs = passedMsSysTime = 1;
float adjustTimeT = passedMs / (float) passedMsSysTime;
float adjustTimeT = passedMs / (float) passedMsSysTime; adjustTime += (adjustTimeT - adjustTime) * 0.2f;
adjustTime += (adjustTimeT - adjustTime) * 0.2f;
lastMs = nowMs;
lastMs = nowMs; lastMsSysTime = msSysTime;
lastMsSysTime = msSysTime; }
} if (passedMs < 0) {
if (passedMs < 0) { lastMs = nowMs;
lastMs = nowMs; lastMsSysTime = msSysTime;
lastMsSysTime = msSysTime; }
}
float now = msSysTime / 1000.0f;
float now = msSysTime / 1000.0f; float passedSeconds = (now - lastTime) * adjustTime;
float passedSeconds = (now - lastTime) * adjustTime; lastTime = now;
lastTime = now;
if (passedSeconds < 0) passedSeconds = 0;
if (passedSeconds < 0) passedSeconds = 0; if (passedSeconds > 1) passedSeconds = 1;
if (passedSeconds > 1) passedSeconds = 1; //LOGI("passed s: %f\n", passedSeconds);
//LOGI("passed s: %f\n", passedSeconds);
passedTime += passedSeconds * timeScale * ticksPerSecond;
passedTime += passedSeconds * timeScale * ticksPerSecond;
ticks = (int) passedTime;
ticks = (int) passedTime; passedTime -= ticks;
passedTime -= ticks; if (ticks > MAX_TICKS_PER_UPDATE) ticks = MAX_TICKS_PER_UPDATE;
if (ticks > MAX_TICKS_PER_UPDATE) ticks = MAX_TICKS_PER_UPDATE; a = passedTime;
a = passedTime; }
}
/**
/** * Advances time the max number of ticks per second.
* Advances time the max number of ticks per second. */
*/ void advanceTimeQuickly() {
void advanceTimeQuickly() {
float passedSeconds = (float) MAX_TICKS_PER_UPDATE / (float) ticksPerSecond;
float passedSeconds = (float) MAX_TICKS_PER_UPDATE / (float) ticksPerSecond;
passedTime += passedSeconds * timeScale * ticksPerSecond;
passedTime += passedSeconds * timeScale * ticksPerSecond; ticks = (int) passedTime;
ticks = (int) passedTime; passedTime -= ticks;
passedTime -= ticks; a = passedTime;
a = passedTime;
lastMs = getTimeMs();//System.currentTimeMillis();
lastMs = getTimeMs();//System.currentTimeMillis(); lastMsSysTime = lastMs;
lastMsSysTime = lastMs; }
}
void skipTime() {
void skipTime() { long nowMs = getTimeMs();//System.currentTimeMillis();
long nowMs = getTimeMs();//System.currentTimeMillis(); long passedMs = nowMs - lastMs;
long passedMs = nowMs - lastMs; long msSysTime = nowMs;//System.nanoTime() / 1000000;
long msSysTime = nowMs;//System.nanoTime() / 1000000;
if (passedMs > 1000) {
if (passedMs > 1000) { long passedMsSysTime = msSysTime - lastMsSysTime;
long passedMsSysTime = msSysTime - lastMsSysTime; if (passedMsSysTime == 0)
if (passedMsSysTime == 0) passedMs = passedMsSysTime = 1;
passedMs = passedMsSysTime = 1;
float adjustTimeT = passedMs / (float) passedMsSysTime;
float adjustTimeT = passedMs / (float) passedMsSysTime; adjustTime += (adjustTimeT - adjustTime) * 0.2f;
adjustTime += (adjustTimeT - adjustTime) * 0.2f;
lastMs = nowMs;
lastMs = nowMs; lastMsSysTime = msSysTime;
lastMsSysTime = msSysTime; }
} if (passedMs < 0) {
if (passedMs < 0) { lastMs = nowMs;
lastMs = nowMs; lastMsSysTime = msSysTime;
lastMsSysTime = msSysTime; }
}
float now = msSysTime / 1000.0f;
float now = msSysTime / 1000.0f; float passedSeconds = (now - lastTime) * adjustTime;
float passedSeconds = (now - lastTime) * adjustTime; lastTime = now;
lastTime = now;
if (passedSeconds < 0) passedSeconds = 0;
if (passedSeconds < 0) passedSeconds = 0; if (passedSeconds > 1) passedSeconds = 1;
if (passedSeconds > 1) passedSeconds = 1;
passedTime += passedSeconds * timeScale * ticksPerSecond;
passedTime += passedSeconds * timeScale * ticksPerSecond;
ticks = (int) 0;
ticks = (int) 0; if (ticks > MAX_TICKS_PER_UPDATE) ticks = MAX_TICKS_PER_UPDATE;
if (ticks > MAX_TICKS_PER_UPDATE) ticks = MAX_TICKS_PER_UPDATE; passedTime -= ticks;
passedTime -= ticks; }
}
public:
public: float ticksPerSecond;
float ticksPerSecond; int ticks;
int ticks; float a;
float a; float timeScale;
float timeScale; float passedTime;
float passedTime; private:
private: static const int MAX_TICKS_PER_UPDATE = 10;
static const int MAX_TICKS_PER_UPDATE = 10;
float lastTime;
float lastTime; long lastMs;
long lastMs; long lastMsSysTime;
long lastMsSysTime; float adjustTime;
float adjustTime; };
};
#endif /*NET_MINECRAFT_CLIENT__Timer_H__*/

View File

@@ -1,56 +0,0 @@
#include "CreativeMode.h"
#include "../Minecraft.h"
#ifndef STANDALONE_SERVER
#include "../particle/ParticleEngine.h"
#endif
#include "../player/LocalPlayer.h"
#ifndef STANDALONE_SERVER
#include "../renderer/LevelRenderer.h"
#include "../sound/SoundEngine.h"
#endif
#include "../../world/level/Level.h"
//#include "../../network/Packet.h"
#include "../../network/packet/RemoveBlockPacket.h"
#include "../../world/entity/player/Abilities.h"
static const int DestructionTickDelay = 5;
CreativeMode::CreativeMode(Minecraft* minecraft)
: super(minecraft)
{
}
void CreativeMode::startDestroyBlock(int x, int y, int z, int face) {
if(minecraft->player->getCarriedItem() != NULL && minecraft->player->getCarriedItem()->id == Item::bow->id)
return;
creativeDestroyBlock(x, y, z, face);
destroyDelay = DestructionTickDelay;
}
void CreativeMode::creativeDestroyBlock(int x, int y, int z, int face) {
minecraft->level->extinguishFire(x, y, z, face);
destroyBlock(x, y, z, face);
}
void CreativeMode::continueDestroyBlock(int x, int y, int z, int face) {
destroyDelay--;
if (destroyDelay <= 0) {
destroyDelay = DestructionTickDelay;
creativeDestroyBlock(x, y, z, face);
}
}
void CreativeMode::stopDestroyBlock() {
destroyDelay = 0;
}
void CreativeMode::initAbilities( Abilities& abilities ) {
abilities.mayfly = true;
abilities.instabuild = true;
abilities.invulnerable = true;
}
bool CreativeMode::isCreativeType() {
return true;
}

View File

@@ -1,26 +0,0 @@
#ifndef NET_MINECRAFT_CLIENT_GAMEMODE__CreativeMode_H__
#define NET_MINECRAFT_CLIENT_GAMEMODE__CreativeMode_H__
//package net.minecraft.client.gamemode;
#include "GameMode.h"
class CreativeMode: public GameMode
{
typedef GameMode super;
public:
CreativeMode(Minecraft* minecraft);
void startDestroyBlock(int x, int y, int z, int face);
void continueDestroyBlock(int x, int y, int z, int face);
void stopDestroyBlock();
bool isCreativeType();
void initAbilities(Abilities& abilities);
private:
void creativeDestroyBlock(int x, int y, int z, int face);
};
#endif /*NET_MINECRAFT_CLIENT_GAMEMODE__CreativeMode_H__*/

View File

@@ -1,102 +0,0 @@
#include "CreatorMode.h"
#include "../Minecraft.h"
#include "../particle/ParticleEngine.h"
#include "../player/LocalPlayer.h"
#include "../renderer/LevelRenderer.h"
#include "../sound/SoundEngine.h"
#include "../../world/level/Level.h"
//#include "../../network/Packet.h"
#include "../../network/packet/RemoveBlockPacket.h"
#include "../../world/entity/player/Abilities.h"
static const int DestructionTickDelay = 5;
class Creator: public ICreator {
//virtual void getEvents();
public:
Creator(/*int eventLifeTime*/)
: _tileEvents(32),
_tickId(0)
{
}
void setTick(int tick) {
_tickId = tick;
}
EventList<TileEvent>& getTileEvents() { return _tileEvents; }
void addevent_blockUse(int entityId, int x, int y, int z, int face) {
TileEvent t = {
entityId,
x,y,z,
face
};
_tileEvents.add(t, _tickId);
}
private:
EventList<TileEvent> _tileEvents;
int _tickId;
};
CreatorMode::CreatorMode(Minecraft* minecraft)
: super(minecraft)
{
_creator = new Creator();
}
CreatorMode::~CreatorMode() {
delete _creator;
}
void CreatorMode::startDestroyBlock(int x, int y, int z, int face) {
if(minecraft->player->getCarriedItem() != NULL && minecraft->player->getCarriedItem()->id == Item::bow->id)
return;
CreatorDestroyBlock(x, y, z, face);
destroyDelay = DestructionTickDelay;
}
void CreatorMode::CreatorDestroyBlock(int x, int y, int z, int face) {
minecraft->level->extinguishFire(x, y, z, face);
destroyBlock(x, y, z, face);
}
void CreatorMode::continueDestroyBlock(int x, int y, int z, int face) {
destroyDelay--;
if (destroyDelay <= 0) {
destroyDelay = DestructionTickDelay;
CreatorDestroyBlock(x, y, z, face);
}
}
bool CreatorMode::useItemOn( Player* player, Level* level, ItemInstance* item, int x, int y, int z, int face, const Vec3& hit ) {
if (item && item->id == ((Item*)Item::sword_iron)->id)
_creator->addevent_blockUse(player->entityId, x, y, z, face);
return super::useItemOn(player, level, item, x, y, z, face, hit);
}
void CreatorMode::stopDestroyBlock() {
destroyDelay = 0;
}
void CreatorMode::initAbilities( Abilities& abilities ) {
abilities.mayfly = true;
abilities.instabuild = true;
abilities.invulnerable = true;
}
bool CreatorMode::isCreativeType() {
return true;
}
ICreator* CreatorMode::getCreator() {
return _creator;
}
void CreatorMode::tick() {
_creator->setTick(minecraft->level->getTime());
super::tick();
}

View File

@@ -1,99 +0,0 @@
#include "SurvivalMode.h"
#include "../Minecraft.h"
#include "../player/LocalPlayer.h"
#ifndef STANDALONE_SERVER
#include "../particle/ParticleEngine.h"
#include "../sound/SoundEngine.h"
#endif
#include "../../world/level/Level.h"
#include "../../world/entity/player/Abilities.h"
SurvivalMode::SurvivalMode( Minecraft* minecraft )
: super(minecraft),
xDestroyBlock(-1),
yDestroyBlock(-1),
zDestroyBlock(-1)
{
}
void SurvivalMode::continueDestroyBlock( int x, int y, int z, int face ) {
if (destroyDelay > 0) {
destroyDelay--;
return;
}
if (x == xDestroyBlock && y == yDestroyBlock && z == zDestroyBlock) {
int t = minecraft->level->getTile(x, y, z);
if (t == 0) return;
Tile* tile = Tile::tiles[t];
destroyProgress += tile->getDestroyProgress(minecraft->player);
if ((++destroyTicks & 3) == 1) {
#ifndef STANDALONE_SERVER
if (tile != NULL) {
minecraft->soundEngine->play(tile->soundType->getStepSound(), x + 0.5f, y + 0.5f, z + 0.5f, (tile->soundType->getVolume() + 1) / 8, tile->soundType->getPitch() * 0.5f);
}
#endif
}
if (destroyProgress >= 1) {
destroyBlock(x, y, z, face);
destroyProgress = 0;
oDestroyProgress = 0;
destroyTicks = 0;
destroyDelay = 5;
}
} else {
destroyProgress = 0;
oDestroyProgress = 0;
destroyTicks = 0;
xDestroyBlock = x;
yDestroyBlock = y;
zDestroyBlock = z;
}
}
bool SurvivalMode::destroyBlock( int x, int y, int z, int face ) {
int t = minecraft->level->getTile(x, y, z);
int data = minecraft->level->getData(x, y, z);
bool changed = GameMode::destroyBlock(x, y, z, face);
bool couldDestroy = minecraft->player->canDestroy(Tile::tiles[t]);
ItemInstance* item = minecraft->player->inventory->getSelected();
if (item != NULL) {
item->mineBlock(t, x, y, z);
if (item->count == 0) {
//item->snap(minecraft->player);
minecraft->player->inventory->clearSlot(minecraft->player->inventory->selected);
}
}
if (changed && couldDestroy) {
ItemInstance instance(t, 1, data);
Tile::tiles[t]->playerDestroy(minecraft->level, minecraft->player, x, y, z, data);
}
return changed;
}
void SurvivalMode::stopDestroyBlock() {
destroyProgress = 0;
destroyDelay = 0;
}
void SurvivalMode::initAbilities( Abilities& abilities ) {
abilities.flying = false;
abilities.mayfly = false;
abilities.instabuild = false;
abilities.invulnerable = false;
}
void SurvivalMode::startDestroyBlock( int x, int y, int z, int face ) {
if(minecraft->player->getCarriedItem() != NULL && minecraft->player->getCarriedItem()->id == Item::bow->id)
return;
int t = minecraft->level->getTile(x, y, z);
if (t > 0 && destroyProgress == 0) Tile::tiles[t]->attack(minecraft->level, x, y, z, minecraft->player);
if (t > 0 && Tile::tiles[t]->getDestroyProgress(minecraft->player) >= 1)
destroyBlock(x, y, z, face);
}

View File

@@ -1,31 +0,0 @@
#ifndef NET_MINECRAFT_CLIENT_GAMEMODE__SurvivalMode_H__
#define NET_MINECRAFT_CLIENT_GAMEMODE__SurvivalMode_H__
#include "GameMode.h"
class Abilities;
class Minecraft;
class SurvivalMode: public GameMode
{
typedef GameMode super;
public:
SurvivalMode(Minecraft* minecraft);
bool destroyBlock(int x, int y, int z, int face);
void startDestroyBlock(int x, int y, int z, int face);
void continueDestroyBlock(int x, int y, int z, int face);
void stopDestroyBlock();
bool canHurtPlayer() { return true; }
bool isSurvivalType() { return true; }
void initAbilities( Abilities& abilities );
private:
int xDestroyBlock;
int yDestroyBlock;
int zDestroyBlock;
};
#endif /*NET_MINECRAFT_CLIENT_GAMEMODE__SurvivalMode_H__*/

View File

@@ -1,372 +1,372 @@
#include "Font.h" #include "Font.hpp"
//#include "SharedConstants.h" //#include "SharedConstants.hpp"
#include "../Options.h" #include "client/Options.hpp"
#include "../renderer/Textures.h" #include "client/renderer/Textures.hpp"
#include "../renderer/Tesselator.h" #include "client/renderer/Tesselator.hpp"
#include "../../util/Mth.h" #include "util/Mth.hpp"
#include <cstring> #include <cstring>
Font::Font( Options* options, const std::string& name, Textures* textures ) Font::Font( Options* options, const std::string& name, Textures* textures )
: options(options), : options(options),
fontTexture(0), fontTexture(0),
fontName(name), fontName(name),
index(0), index(0),
count(0), count(0),
_textures(textures), _textures(textures),
_x(0), _y(0), _x(0), _y(0),
_cols(16), _rows(16), _cols(16), _rows(16),
_charOffset(0), _charOffset(0),
lineHeight(DefaultLineHeight) lineHeight(DefaultLineHeight)
{ {
init(options); 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 ) //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), //: options(options),
// fontTexture(0), // fontTexture(0),
// fontName(name), // fontName(name),
// index(0), // index(0),
// count(0), // count(0),
// _textures(textures), // _textures(textures),
// _x(x), _y(y), // _x(x), _y(y),
// _cols(cols), _rows(rows), // _cols(cols), _rows(rows),
// _charOffset(charOffset) // _charOffset(charOffset)
//{ //{
// init(options); // init(options);
//} //}
void Font::onGraphicsReset() void Font::onGraphicsReset()
{ {
init(options); init(options);
} }
void Font::init( Options* options ) void Font::init( Options* options )
{ {
TextureId fontTexture = _textures->loadTexture(fontName); TextureId fontTexture = _textures->loadTexture(fontName);
const TextureData* tex = _textures->getTemporaryTextureData(fontTexture); const TextureData* tex = _textures->getTemporaryTextureData(fontTexture);
if (!tex) if (!tex)
return; return;
unsigned char* rawPixels = tex->data; unsigned char* rawPixels = tex->data;
const int numChars = _rows * _cols; const int numChars = _rows * _cols;
for (int i = 0; i < numChars; i++) { for (int i = 0; i < numChars; i++) {
int xt = i % _cols; int xt = i % _cols;
int yt = i / _cols; int yt = i / _cols;
int x = 7; int x = 7;
for (; x >= 0; x--) { for (; x >= 0; x--) {
int xPixel = _x + xt * 8 + x; int xPixel = _x + xt * 8 + x;
bool emptyColumn = true; bool emptyColumn = true;
for (int y = 0; y < 8 && emptyColumn; y++) { for (int y = 0; y < 8 && emptyColumn; y++) {
int yPixel = _y + (yt * 8 + y) * tex->w; int yPixel = _y + (yt * 8 + y) * tex->w;
unsigned char pixelalpha = rawPixels[(xPixel + yPixel) << 2]; unsigned char pixelalpha = rawPixels[(xPixel + yPixel) << 2];
if (pixelalpha > 0) emptyColumn = false; if (pixelalpha > 0) emptyColumn = false;
} }
if (!emptyColumn) { if (!emptyColumn) {
break; break;
} }
} }
if (i == ' ') x = 4 - 2; if (i == ' ') x = 4 - 2;
charWidths[i] = x + 2; charWidths[i] = x + 2;
fcharWidths[i] = (float) charWidths[i]; fcharWidths[i] = (float) charWidths[i];
} }
#ifdef USE_VBO #ifdef USE_VBO
return; // this <1 return; // this <1
#endif #endif
#ifndef USE_VBO #ifndef USE_VBO
listPos = glGenLists(256 + 32); listPos = glGenLists(256 + 32);
Tesselator& t = Tesselator::instance; Tesselator& t = Tesselator::instance;
for (int i = 0; i < 256; i++) { for (int i = 0; i < 256; i++) {
glNewList(listPos + i, GL_COMPILE); glNewList(listPos + i, GL_COMPILE);
// @attn @huge @note: This is some dangerous code right here / Aron, added ^1 // @attn @huge @note: This is some dangerous code right here / Aron, added ^1
t.begin(); t.begin();
buildChar(i); buildChar(i);
t.end(false, -1); t.end(false, -1);
glTranslatef2((GLfloat)charWidths[i], 0.0f, 0.0f); glTranslatef2((GLfloat)charWidths[i], 0.0f, 0.0f);
glEndList(); glEndList();
} }
for (int i = 0; i < 32; i++) { for (int i = 0; i < 32; i++) {
int br = ((i >> 3) & 1) * 0x55; int br = ((i >> 3) & 1) * 0x55;
int r = ((i >> 2) & 1) * 0xaa + br; int r = ((i >> 2) & 1) * 0xaa + br;
int g = ((i >> 1) & 1) * 0xaa + br; int g = ((i >> 1) & 1) * 0xaa + br;
int b = ((i >> 0) & 1) * 0xaa + br; int b = ((i >> 0) & 1) * 0xaa + br;
if (i == 6) { if (i == 6) {
r += 0x55; r += 0x55;
} }
bool darken = i >= 16; bool darken = i >= 16;
if (options->anaglyph3d) { if (options->anaglyph3d) {
int cr = (r * 30 + g * 59 + b * 11) / 100; int cr = (r * 30 + g * 59 + b * 11) / 100;
int cg = (r * 30 + g * 70) / (100); int cg = (r * 30 + g * 70) / (100);
int cb = (r * 30 + b * 70) / (100); int cb = (r * 30 + b * 70) / (100);
r = cr; r = cr;
g = cg; g = cg;
b = cb; b = cb;
} }
// color = r << 16 | g << 8 | b; // color = r << 16 | g << 8 | b;
if (darken) { if (darken) {
r /= 4; r /= 4;
g /= 4; g /= 4;
b /= 4; b /= 4;
} }
glNewList(listPos + 256 + i, GL_COMPILE); glNewList(listPos + 256 + i, GL_COMPILE);
glColor3f(r / 255.0f, g / 255.0f, b / 255.0f); glColor3f(r / 255.0f, g / 255.0f, b / 255.0f);
glEndList(); glEndList();
} }
#endif #endif
} }
void Font::drawShadow( const std::string& str, float x, float y, int color ) void Font::drawShadow( const std::string& str, float x, float y, int color )
{ {
draw(str, x + 1, y + 1, color, true); draw(str, x + 1, y + 1, color, true);
draw(str, x, y, color); draw(str, x, y, color);
} }
void Font::drawShadow( const char* str, float x, float y, int color ) void Font::drawShadow( const char* str, float x, float y, int color )
{ {
draw(str, x + 1, y + 1, color, true); draw(str, x + 1, y + 1, color, true);
draw(str, x, y, color); draw(str, x, y, color);
} }
void Font::draw( const std::string& str, float x, float y, int color ) void Font::draw( const std::string& str, float x, float y, int color )
{ {
draw(str, x, y, color, false); draw(str, x, y, color, false);
} }
void Font::draw( const char* str, float x, float y, int color ) void Font::draw( const char* str, float x, float y, int color )
{ {
draw(str, x, y, color, false); draw(str, x, y, color, false);
} }
void Font::draw( const char* str, float x, float y, int color, bool darken ) void Font::draw( const char* str, float x, float y, int color, bool darken )
{ {
#ifdef USE_VBO #ifdef USE_VBO
drawSlow(str, x, y, color, darken); drawSlow(str, x, y, color, darken);
#endif #endif
} }
void Font::draw( const std::string& str, float x, float y, int color, bool darken ) void Font::draw( const std::string& str, float x, float y, int color, bool darken )
{ {
#ifdef USE_VBO #ifdef USE_VBO
drawSlow(str, x, y, color, darken); drawSlow(str, x, y, color, darken);
return; return;
#endif #endif
if (str.empty()) return; if (str.empty()) return;
if (darken) { if (darken) {
int oldAlpha = color & 0xff000000; int oldAlpha = color & 0xff000000;
color = (color & 0xfcfcfc) >> 2; color = (color & 0xfcfcfc) >> 2;
color += oldAlpha; color += oldAlpha;
} }
_textures->loadAndBindTexture(fontName); _textures->loadAndBindTexture(fontName);
float r = ((color >> 16) & 0xff) / 255.0f; float r = ((color >> 16) & 0xff) / 255.0f;
float g = ((color >> 8) & 0xff) / 255.0f; float g = ((color >> 8) & 0xff) / 255.0f;
float b = ((color) & 0xff) / 255.0f; float b = ((color) & 0xff) / 255.0f;
float a = ((color >> 24) & 0xff) / 255.0f; float a = ((color >> 24) & 0xff) / 255.0f;
if (a == 0) a = 1; if (a == 0) a = 1;
glColor4f2(r, g, b, a); glColor4f2(r, g, b, a);
static const std::string hex("0123456789abcdef"); static const std::string hex("0123456789abcdef");
index = 0; index = 0;
glPushMatrix2(); glPushMatrix2();
glTranslatef2((GLfloat)x, (GLfloat)y, 0.0f); glTranslatef2((GLfloat)x, (GLfloat)y, 0.0f);
for (unsigned int i = 0; i < str.length(); i++) { for (unsigned int i = 0; i < str.length(); i++) {
while (str.length() > i + 1 && str[i] == '\xa7') { while (str.length() > i + 1 && str[i] == '\xa7') {
int cc = hex.find((char)tolower(str[i + 1])); int cc = hex.find((char)tolower(str[i + 1]));
if (cc < 0 || cc > 15) cc = 15; if (cc < 0 || cc > 15) cc = 15;
lists[index++] = listPos + 256 + cc + (darken ? 16 : 0); lists[index++] = listPos + 256 + cc + (darken ? 16 : 0);
if (index == 1024) { if (index == 1024) {
count = index; count = index;
index = 0; index = 0;
#ifndef USE_VBO #ifndef USE_VBO
glCallLists(count, GL_UNSIGNED_INT, lists); glCallLists(count, GL_UNSIGNED_INT, lists);
#endif #endif
count = 1024; count = 1024;
} }
i += 2; i += 2;
} }
if (i < str.length()) { if (i < str.length()) {
//int ch = SharedConstants.acceptableLetters.indexOf(str.charAt(i)); //int ch = SharedConstants.acceptableLetters.indexOf(str.charAt(i));
char ch = str[i]; char ch = str[i];
if (ch >= 0) { if (ch >= 0) {
//ib.put(listPos + ch + 32); //ib.put(listPos + ch + 32);
lists[index++] = listPos + ch; lists[index++] = listPos + ch;
} }
} }
if (index == 1024) { if (index == 1024) {
count = index; count = index;
index = 0; index = 0;
#ifndef USE_VBO #ifndef USE_VBO
glCallLists(count, GL_UNSIGNED_INT, lists); glCallLists(count, GL_UNSIGNED_INT, lists);
#endif #endif
count = 1024; count = 1024;
} }
} }
count = index; count = index;
index = 0; index = 0;
#ifndef USE_VBO #ifndef USE_VBO
glCallLists(count, GL_UNSIGNED_INT, lists); glCallLists(count, GL_UNSIGNED_INT, lists);
#endif #endif
glPopMatrix2(); glPopMatrix2();
} }
int Font::width( const std::string& str ) int Font::width( const std::string& str )
{ {
int maxLen = 0; int maxLen = 0;
int len = 0; int len = 0;
for (unsigned int i = 0; i < str.length(); i++) { for (unsigned int i = 0; i < str.length(); i++) {
if (str[i] == '\xa7') { if (str[i] == '\xa7') {
i++; i++;
} else { } else {
//int ch = SharedConstants.acceptableLetters.indexOf(str.charAt(i)); //int ch = SharedConstants.acceptableLetters.indexOf(str.charAt(i));
//if (ch >= 0) { //if (ch >= 0) {
// len += charWidths[ch + 32]; // len += charWidths[ch + 32];
//} //}
if (str[i] == '\n') { if (str[i] == '\n') {
if (len > maxLen) maxLen = len; if (len > maxLen) maxLen = len;
len = 0; len = 0;
} }
else { else {
int charWidth = charWidths[ (unsigned char) str[i] ]; int charWidth = charWidths[ (unsigned char) str[i] ];
len += charWidth; len += charWidth;
} }
} }
} }
return maxLen>len? maxLen : len; return maxLen>len? maxLen : len;
} }
int Font::height( const std::string& str ) { int Font::height( const std::string& str ) {
int h = 0; int h = 0;
bool hasLine = false; bool hasLine = false;
for (unsigned int i = 0; i < str.length(); ++i) { for (unsigned int i = 0; i < str.length(); ++i) {
if (str[i] == '\n') hasLine = true; if (str[i] == '\n') hasLine = true;
else { else {
if (hasLine) h += lineHeight; if (hasLine) h += lineHeight;
hasLine = false; hasLine = false;
} }
} }
return h; return h;
} }
std::string Font::sanitize( const std::string& str ) std::string Font::sanitize( const std::string& str )
{ {
std::string sanitized(str.length() + 1, 0); std::string sanitized(str.length() + 1, 0);
int j = 0; int j = 0;
for (unsigned int i = 0; i < str.length(); i++) { for (unsigned int i = 0; i < str.length(); i++) {
if (str[i] == '\xa7') { if (str[i] == '\xa7') {
i++; i++;
//} else if (SharedConstants.acceptableLetters.indexOf(str.charAt(i)) >= 0) { //} else if (SharedConstants.acceptableLetters.indexOf(str.charAt(i)) >= 0) {
} else { } else {
sanitized[j++] = str[i]; sanitized[j++] = str[i];
} }
} }
return sanitized.erase(j); return sanitized.erase(j);
} }
void Font::drawWordWrap( const std::string& str, float x, float y, float w, int col ) void Font::drawWordWrap( const std::string& str, float x, float y, float w, int col )
{ {
char* cstr = new char[str.length() + 1]; char* cstr = new char[str.length() + 1];
strncpy(cstr, str.c_str(), str.length()); strncpy(cstr, str.c_str(), str.length());
cstr[str.length()] = 0; cstr[str.length()] = 0;
const char* lims = " \n\t\r"; const char* lims = " \n\t\r";
char* ptok = strtok(cstr, lims); char* ptok = strtok(cstr, lims);
std::vector<std::string> words; std::vector<std::string> words;
while (ptok != NULL) { while (ptok != NULL) {
words.push_back( ptok ); words.push_back( ptok );
ptok = strtok(NULL, lims); ptok = strtok(NULL, lims);
} }
delete[] cstr; delete[] cstr;
int pos = 0; int pos = 0;
while (pos < (int)words.size()) { while (pos < (int)words.size()) {
std::string line = words[pos++] + " "; std::string line = words[pos++] + " ";
while (pos < (int)words.size() && width(line + words[pos]) < w) { while (pos < (int)words.size() && width(line + words[pos]) < w) {
line += words[pos++] + " "; line += words[pos++] + " ";
} }
drawShadow(line, x, y, col); drawShadow(line, x, y, col);
y += lineHeight; y += lineHeight;
} }
} }
void Font::drawSlow( const std::string& str, float x, float y, int color, bool darken /*= false*/ ) { void Font::drawSlow( const std::string& str, float x, float y, int color, bool darken /*= false*/ ) {
drawSlow(str.c_str(), x, y, color, darken); drawSlow(str.c_str(), x, y, color, darken);
} }
void Font::drawSlow( const char* str, float x, float y, int color, bool darken /*= false*/ ) void Font::drawSlow( const char* str, float x, float y, int color, bool darken /*= false*/ )
{ {
if (!str) return; if (!str) return;
if (darken) { if (darken) {
int oldAlpha = color & 0xff000000; int oldAlpha = color & 0xff000000;
color = (color & 0xfcfcfc) >> 2; color = (color & 0xfcfcfc) >> 2;
color += oldAlpha; color += oldAlpha;
} }
_textures->loadAndBindTexture(fontName); _textures->loadAndBindTexture(fontName);
Tesselator& t = Tesselator::instance; Tesselator& t = Tesselator::instance;
t.begin(); t.begin();
int alpha = (0xff000000 & color) >> 24; int alpha = (0xff000000 & color) >> 24;
if (!alpha) alpha = 0xff; if (!alpha) alpha = 0xff;
t.color((color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff, alpha); t.color((color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff, alpha);
t.addOffset((float)x, (float)y, 0); t.addOffset((float)x, (float)y, 0);
float xOffset = 0; float xOffset = 0;
float yOffset = 0; float yOffset = 0;
while (unsigned char ch = *(str++)) { while (unsigned char ch = *(str++)) {
if (ch == '\n') { if (ch == '\n') {
xOffset = 0; xOffset = 0;
yOffset += lineHeight; yOffset += lineHeight;
} else { } else {
buildChar(ch, xOffset, yOffset); buildChar(ch, xOffset, yOffset);
xOffset += fcharWidths[ch]; xOffset += fcharWidths[ch];
} }
} }
t.draw(); t.draw();
t.addOffset(-(float)x, -(float)y, 0); t.addOffset(-(float)x, -(float)y, 0);
} }
void Font::buildChar( unsigned char i, float x /*= 0*/, float y /*=0*/ ) void Font::buildChar( unsigned char i, float x /*= 0*/, float y /*=0*/ )
{ {
Tesselator& t = Tesselator::instance; Tesselator& t = Tesselator::instance;
//i -= _charOffset; //i -= _charOffset;
//int ix = (i % _cols) * 8 + _x; //int ix = (i % _cols) * 8 + _x;
//int iy = (i / _cols) * 8 + _y; //int iy = (i / _cols) * 8 + _y;
float ix = (float)((i & 15) * 8); float ix = (float)((i & 15) * 8);
float iy = (float)((i >> 4) * 8); float iy = (float)((i >> 4) * 8);
float s = 7.99f; float s = 7.99f;
float uo = (0.0f) / 128.0f; float uo = (0.0f) / 128.0f;
float vo = (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, 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 + 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 + 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); t.vertexUV(x, y, 0, ix / 128.0f + uo, iy / 128.0f + vo);
} }

View File

@@ -1,63 +1,61 @@
#ifndef NET_MINECRAFT_CLIENT_GUI__Font_H__ #pragma once
#define NET_MINECRAFT_CLIENT_GUI__Font_H__
//package net.minecraft.client.gui;
//package net.minecraft.client.gui;
#include <string>
#include <string> #include <cctype>
#include <cctype>
#include "client/renderer/gles.hpp"
#include "../renderer/gles.h"
class Textures;
class Textures; class Options;
class Options;
class Font
class Font {
{ public:
public: Font(Options* options, const std::string& name, Textures* textures);
Font(Options* options, const std::string& name, Textures* textures); //Font(Options* options, const std::string& name, Textures* textures, int imgW, int imgH, int x, int y, int cols, int rows, unsigned char charOffset);
//Font(Options* options, const std::string& name, Textures* textures, int imgW, int imgH, int x, int y, int cols, int rows, unsigned char charOffset);
void init(Options* options);
void init(Options* options); void onGraphicsReset();
void onGraphicsReset();
void draw(const char* str, float x, float y, int color);
void draw(const char* str, float x, float y, int color); void draw(const std::string& str, float x, float y, int color);
void draw(const std::string& str, float x, float y, int color); void draw(const char* str, float x, float y, int color, bool darken);
void draw(const char* str, float x, float y, int color, bool darken); void draw(const std::string& str, float x, float y, int color, bool darken);
void draw(const std::string& str, float x, float y, int color, bool darken); void drawShadow(const std::string& str, float x, float y, int color);
void drawShadow(const std::string& str, float x, float y, int color); void drawShadow(const char* str, float x, float y, int color);
void drawShadow(const char* str, float x, float y, int color); void drawWordWrap(const std::string& str, float x, float y, float w, int col);
void drawWordWrap(const std::string& str, float x, float y, float w, int col);
int width(const std::string& str);
int width(const std::string& str); int height(const std::string& str);
int height(const std::string& str);
static std::string sanitize(const std::string& str);
static std::string sanitize(const std::string& str); private:
private: void buildChar(unsigned char i, float x = 0, float y = 0);
void buildChar(unsigned char i, float x = 0, float y = 0); void drawSlow(const std::string& str, float x, float y, int color, bool darken = false);
void drawSlow(const std::string& str, float x, float y, int color, bool darken = false); void drawSlow(const char* str, float x, float y, int color, bool darken = false);
void drawSlow(const char* str, float x, float y, int color, bool darken = false); public:
public: int fontTexture;
int fontTexture; int lineHeight;
int lineHeight; static const int DefaultLineHeight = 10;
static const int DefaultLineHeight = 10; private:
private: int charWidths[256];
int charWidths[256]; float fcharWidths[256];
float fcharWidths[256]; int listPos;
int listPos;
int index;
int index; int count;
int count; GLuint lists[1024];
GLuint lists[1024];
std::string fontName;
std::string fontName; Textures* _textures;
Textures* _textures;
Options* options;
Options* options;
int _x, _y;
int _x, _y; int _cols;
int _cols; int _rows;
int _rows; unsigned char _charOffset;
unsigned char _charOffset; };
};
#endif /*NET_MINECRAFT_CLIENT_GUI__Font_H__*/

View File

@@ -1,67 +1,52 @@
#include "Gui.h" #include "Gui.hpp"
#include "Font.h" #include "Font.hpp"
#include "client/Options.h" #include "MinecraftClient.hpp"
#include "platform/input/Keyboard.h" #include "client/Options.hpp"
#include "screens/IngameBlockSelectionScreen.h" #include "platform/input/Keyboard.hpp"
#include "screens/ChatScreen.h" #include "screens/IngameBlockSelectionScreen.hpp"
#include "screens/ConsoleScreen.h" #include "screens/ChatScreen.hpp"
#include "../Minecraft.h" #include "screens/ConsoleScreen.hpp"
#include "../player/LocalPlayer.h" #include <Minecraft.hpp>
#include "../renderer/Tesselator.h" #include "client/player/LocalPlayer.hpp"
#include "../renderer/TileRenderer.h" #include "client/renderer/Tesselator.hpp"
#include "../renderer/LevelRenderer.h" #include "client/renderer/TileRenderer.hpp"
#include "../renderer/GameRenderer.h" #include "client/renderer/LevelRenderer.hpp"
#include "../renderer/entity/ItemRenderer.h" #include "client/renderer/GameRenderer.hpp"
#include "../player/input/IInputHolder.h" #include "client/renderer/entity/ItemRenderer.hpp"
#include "../gamemode/GameMode.h" #include "client/player/input/IInputHolder.hpp"
#include "../gamemode/CreativeMode.h" #include "client/gamemode/GameMode.hpp"
#include "../renderer/Textures.h" #include "client/gamemode/CreativeMode.hpp"
#include "../../AppConstants.h" #include "client/renderer/Textures.hpp"
#include "../../world/entity/player/Inventory.h" #include "AppConstants.hpp"
#include "../../world/level/material/Material.h" #include "world/entity/player/Inventory.hpp"
#include "../../world/item/Item.h" #include "world/level/material/Material.hpp"
#include "../../world/item/ItemInstance.h" #include "world/item/Item.hpp"
#include "../../platform/input/Mouse.h" #include "world/item/ItemInstance.hpp"
#include "../../world/level/Level.h" #include "platform/input/Mouse.hpp"
#include "../../world/PosTranslator.h" #include "world/level/Level.hpp"
#include "../../platform/time.h" #include "world/PosTranslator.hpp"
#include "platform/time.hpp"
#include <cmath> #include <cmath>
#include <algorithm> #include <algorithm>
#include <sstream> #include <sstream>
#define MAX_MESSAGE_WIDTH 240
float Gui::InvGuiScale = 1.0f / 3.0f; float Gui::InvGuiScale = 1.0f / 3.0f;
float Gui::GuiScale = 1.0f / Gui::InvGuiScale; float Gui::GuiScale = 1.0f / Gui::InvGuiScale;
const float Gui::DropTicks = 40.0f; const float Gui::DropTicks = 40.0f;
//#include <android/log.h> //#include <android/log.h>
Gui::Gui(Minecraft* minecraft) // @todo virtual controlConfigurationChanged() when player switches from keyboard to touch for example
: minecraft(minecraft), Gui::Gui(MinecraftClient& minecraft) : minecraft(minecraft), _openInventorySlot(minecraft.useTouchscreen()) {
tickCount(0),
progress(0),
overlayMessageTime(0),
animateOverlayMessageColor(false),
chatScrollOffset(0),
tbr(1),
_inventoryNeedsUpdate(true),
_flashSlotId(-1),
_flashSlotStartTime(-1),
_slotFont(NULL),
_numSlots(4),
_currentDropTicks(-1),
_currentDropSlot(-1),
MAX_MESSAGE_WIDTH(240),
itemNameOverlayTime(2),
_openInventorySlot(minecraft->useTouchscreen())
{
glGenBuffers2(1, &_inventoryRc.vboId); glGenBuffers2(1, &_inventoryRc.vboId);
glGenBuffers2(1, &rcFeedbackInner.vboId); glGenBuffers2(1, &rcFeedbackInner.vboId);
glGenBuffers2(1, &rcFeedbackOuter.vboId); glGenBuffers2(1, &rcFeedbackOuter.vboId);
//Gui::InvGuiScale = 1.0f / (int) (3 * Minecraft::width / 854); //Gui::InvGuiScale = 1.0f / (int) (3 * Minecraft::width / 854);
} }
Gui::~Gui() Gui::~Gui() {
{
if (_slotFont) if (_slotFont)
delete _slotFont; delete _slotFont;
@@ -69,17 +54,16 @@ Gui::~Gui()
} }
void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) { void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
if (!minecraft.level || !minecraft.getPlayer())
if (!minecraft->level || !minecraft->player)
return; return;
//minecraft->gameRenderer->setupGuiScreen(); //minecraft->gameRenderer->setupGuiScreen();
Font* font = minecraft->font; Font* font = minecraft.getFont();
const bool isTouchInterface = minecraft->useTouchscreen(); const bool isTouchInterface = minecraft.useTouchscreen();
const int screenWidth = (int)(minecraft->width * InvGuiScale); const int screenWidth = (int)(minecraft.getScreenWidth() * InvGuiScale);
const int screenHeight = (int)(minecraft->height * InvGuiScale); const int screenHeight = (int)(minecraft.getScreenHeigth() * InvGuiScale);
blitOffset = -90; blitOffset = -90;
renderProgressIndicator(isTouchInterface, screenWidth, screenHeight, a); renderProgressIndicator(isTouchInterface, screenWidth, screenHeight, a);
@@ -91,9 +75,9 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
// F: 3 // F: 3
int ySlot = screenHeight - 16 - 3; int ySlot = screenHeight - 16 - 3;
if (!minecraft->options.getBooleanValue(OPTIONS_HIDEGUI)) { if (!minecraft.options.getBooleanValue(OPTIONS_HIDEGUI)) {
if (minecraft->gameMode->canHurtPlayer()) { if (minecraft.gameMode->canHurtPlayer()) {
minecraft->textures->loadAndBindTexture("gui/icons.png"); minecraft.getTextures()->loadAndBindTexture("gui/icons.png");
Tesselator& t = Tesselator::instance; Tesselator& t = Tesselator::instance;
t.beginOverride(); t.beginOverride();
t.colorABGR(0xffffffff); t.colorABGR(0xffffffff);
@@ -103,7 +87,7 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
} }
} }
if(minecraft->player->getSleepTimer() > 0) { if(minecraft.getPlayer()->getSleepTimer() > 0) {
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST); glDisable(GL_ALPHA_TEST);
@@ -112,7 +96,7 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
glEnable(GL_ALPHA_TEST); glEnable(GL_ALPHA_TEST);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
} }
if (!minecraft->options.getBooleanValue(OPTIONS_HIDEGUI)) { if (!minecraft.options.getBooleanValue(OPTIONS_HIDEGUI)) {
renderToolBar(a, ySlot, screenWidth); renderToolBar(a, ySlot, screenWidth);
glEnable(GL_BLEND); glEnable(GL_BLEND);
@@ -730,6 +714,7 @@ void Gui::renderDebugInfo() {
// Position // Position
float px = p->x, py = p->y - p->heightOffset, pz = p->z; float px = p->x, py = p->y - p->heightOffset, pz = p->z;
posTranslator.to(px, py, pz);
int bx = (int)floorf(px), by = (int)floorf(py), bz = (int)floorf(pz); int bx = (int)floorf(px), by = (int)floorf(py), bz = (int)floorf(pz);
int cx = bx >> 4, cz = bz >> 4; int cx = bx >> 4, cz = bz >> 4;

View File

@@ -1,134 +1,131 @@
#ifndef NET_MINECRAFT_CLIENT_GUI__Gui_H__ #pragma once
#define NET_MINECRAFT_CLIENT_GUI__Gui_H__
//package net.minecraft.client.gui;
//package net.minecraft.client.gui;
#include "GuiComponent.hpp"
#include "GuiComponent.h" #include "Font.hpp"
#include "Font.h" #include "client/player/input/touchscreen/TouchAreaModel.hpp"
#include "../player/input/touchscreen/TouchAreaModel.h" #include "client/renderer/RenderChunk.hpp"
#include "../renderer/RenderChunk.h" #include "util/Random.hpp"
#include "../../util/Random.h" #include "client/IConfigListener.hpp"
#include "../IConfigListener.h"
class MinecraftClient;
class Minecraft; class ItemInstance;
class ItemInstance; class Textures;
class Textures; class Tesselator;
class Tesselator; struct IntRectangle;
struct IntRectangle;
struct GuiMessage
struct GuiMessage {
{ std::string message;
std::string message; int ticks;
int ticks; };
};
typedef std::vector<GuiMessage> GuiMessageList;
typedef std::vector<GuiMessage> GuiMessageList;
class Gui: public GuiComponent, IConfigListener
class Gui: public GuiComponent, IConfigListener {
{ public:
public: Gui(MinecraftClient& minecraft);
Gui(Minecraft* minecraft); ~Gui();
~Gui();
int getSlotIdAt(int x, int y);
int getSlotIdAt(int x, int y); void flashSlot(int slotId);
void flashSlot(int slotId); bool isInside(int x, int y);
bool isInside(int x, int y); RectangleArea getRectangleArea(int extendSide);
RectangleArea getRectangleArea(int extendSide); void getSlotPos(int slot, int& posX, int& posY);
void getSlotPos(int slot, int& posX, int& posY); int getNumSlots();
int getNumSlots();
void handleClick(int button, int x, int y);
void handleClick(int button, int x, int y); void handleKeyPressed( int key );
void handleKeyPressed( int key ); void scrollChat(int delta);
void scrollChat(int delta);
void tick();
void tick(); void render(float a, bool mouseFree, int xMouse, int yMouse);
void render(float a, bool mouseFree, int xMouse, int yMouse);
void renderToolBar( float a, int ySlot, const int screenWidth );
void renderToolBar( float a, int ySlot, const int screenWidth );
void renderChatMessages( const int screenHeight, unsigned int max, bool isChatting, Font* font );
void renderChatMessages( const int screenHeight, unsigned int max, bool isChatting, Font* font );
// draw a string containing simple [color]...[/color] tags; color names are matched
// draw a string containing simple [color]...[/color] tags; color names are matched // case-insensitively and default to white. alpha is applied to each segment.
// case-insensitively and default to white. alpha is applied to each segment. // draw tagged string (ignores simple [color]…[/color] tags)
// draw tagged string (ignores simple [color]…[/color] tags) static void drawColoredString(Font* font, const std::string& text, float x, float y, int alpha);
static void drawColoredString(Font* font, const std::string& text, float x, float y, int alpha); static float getColoredWidth(Font* font, const std::string& text);
static float getColoredWidth(Font* font, const std::string& text);
void renderOnSelectItemNameText( const int screenWidth, Font* font, int ySlot );
void renderOnSelectItemNameText( const int screenWidth, Font* font, int ySlot );
void renderSleepAnimation( const int screenWidth, const int screenHeight );
void renderSleepAnimation( const int screenWidth, const int screenHeight );
void renderBubbles();
void renderBubbles(); void renderHearts();
void renderHearts(); void renderDebugInfo();
void renderDebugInfo(); void renderPlayerList(Font* font, int screenWidth, int screenHeight);
void renderPlayerList(Font* font, int screenWidth, int screenHeight);
void renderProgressIndicator( const bool isTouchInterface, const int screenWidth, const int screenHeight, float a );
void renderProgressIndicator( const bool isTouchInterface, const int screenWidth, const int screenHeight, float a );
void addMessage(const std::string& string);
void addMessage(const std::string& string); void clearMessages();
void clearMessages(); void postError(int errCode);
void postError(int errCode);
void onGraphicsReset();
void onGraphicsReset(); void inventoryUpdated();
void inventoryUpdated();
void setNowPlaying(const std::string& string);
void setNowPlaying(const std::string& string); void displayClientMessage(const std::string& messageId);
void displayClientMessage(const std::string& messageId); void renderSlotText(const ItemInstance* item, float x, float y, bool hasFinite, bool shadow);
void renderSlotText(const ItemInstance* item, float x, float y, bool hasFinite, bool shadow); void texturesLoaded( Textures* textures );
void texturesLoaded( Textures* textures );
void onConfigChanged(const Config& config);
void onConfigChanged(const Config& config); void onLevelGenerated();
void onLevelGenerated();
void setScissorRect(const IntRectangle& rect);
void setScissorRect(const IntRectangle& rect);
static float floorAlignToScreenPixel(float);
static float floorAlignToScreenPixel(float); static int itemCountItoa(char* buf, int count);
static int itemCountItoa(char* buf, int count); private:
private: void renderVignette(float br, int w, int h);
void renderVignette(float br, int w, int h); void renderSlot(int slot, int x, int y, float a);
void renderSlot(int slot, int x, int y, float a); void tickItemDrop();
void tickItemDrop(); float cubeSmoothStep(float percentage, float min, float max);
float cubeSmoothStep(float percentage, float min, float max); public:
public: float progress = 0.f;
float progress; std::string selectedName;
std::string selectedName; static float InvGuiScale;
static float InvGuiScale; static float GuiScale;
static float GuiScale;
private:
private: //ItemRenderer itemRenderer;
int MAX_MESSAGE_WIDTH; GuiMessageList guiMessages;
//ItemRenderer itemRenderer; int chatScrollOffset = 0;
GuiMessageList guiMessages; Random random;
int chatScrollOffset;
Random random; MinecraftClient& minecraft;
int tickCount = 0;
Minecraft* minecraft; float itemNameOverlayTime = 2;
int tickCount; std::string overlayMessageString;
float itemNameOverlayTime; int overlayMessageTime = 0;
std::string overlayMessageString; bool animateOverlayMessageColor = false;
int overlayMessageTime;
bool animateOverlayMessageColor; float tbr = 1.f;
float tbr; RenderChunk _inventoryRc;
bool _inventoryNeedsUpdate = true;
RenderChunk _inventoryRc;
bool _inventoryNeedsUpdate; int _flashSlotId = -1;
float _flashSlotStartTime = -1;
int _flashSlotId;
float _flashSlotStartTime; Font* _slotFont = nullptr;
int _numSlots = 4;
Font* _slotFont;
int _numSlots; RenderChunk rcFeedbackOuter;
RenderChunk rcFeedbackInner;
RenderChunk rcFeedbackOuter;
RenderChunk rcFeedbackInner; // For dropping
static const float DropTicks;
// For dropping float _currentDropTicks = -1;
static const float DropTicks; int _currentDropSlot = -1;
float _currentDropTicks;
int _currentDropSlot; bool _openInventorySlot;
};
bool _openInventorySlot;
};
#endif /*NET_MINECRAFT_CLIENT_GUI__Gui_H__*/

View File

@@ -1,156 +1,156 @@
#include "GuiComponent.h" #include "GuiComponent.hpp"
#include "../renderer/Tesselator.h" #include "client/renderer/Tesselator.hpp"
#include "../renderer/gles.h" #include "client/renderer/gles.hpp"
#include "Font.h" #include "Font.hpp"
GuiComponent::GuiComponent() GuiComponent::GuiComponent()
: blitOffset(0) : blitOffset(0)
{ {
} }
GuiComponent::~GuiComponent() GuiComponent::~GuiComponent()
{ {
} }
void GuiComponent::drawCenteredString( Font* font, const std::string& str, int x, int y, int color ) 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); 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 ) 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); 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*/ ) 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 (!sw) sw = w;
if (!sh) sh = h; if (!sh) sh = h;
float us = 1 / 256.0f; float us = 1 / 256.0f;
float vs = 1 / 256.0f; float vs = 1 / 256.0f;
Tesselator& t = Tesselator::instance; Tesselator& t = Tesselator::instance;
t.begin(); t.begin();
t.vertexUV((float)(x) , (float)(y + h), blitOffset, (float)(sx ) * us, (float)(sy + sh) * vs); 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 + 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 + 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.vertexUV((float)(x) , (float)(y) , blitOffset, (float)(sx ) * us, (float)(sy ) * vs);
t.draw(); t.draw();
} }
void GuiComponent::blit( float x, float y, int sx, int sy, float w, float h, int sw/*=0*/, int sh/*=0*/ ) 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 (!sw) sw = (int)w;
if (!sh) sh = (int)h; if (!sh) sh = (int)h;
float us = 1 / 256.0f; float us = 1 / 256.0f;
float vs = 1 / 256.0f; float vs = 1 / 256.0f;
Tesselator& t = Tesselator::instance; Tesselator& t = Tesselator::instance;
t.begin(); t.begin();
t.vertexUV(x , y + h, blitOffset, (float)(sx ) * us, (float)(sy + sh) * vs); 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 + 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 + w, y , blitOffset, (float)(sx + sw) * us, (float)(sy ) * vs);
t.vertexUV(x , y , blitOffset, (float)(sx ) * us, (float)(sy ) * vs); t.vertexUV(x , y , blitOffset, (float)(sx ) * us, (float)(sy ) * vs);
t.draw(); t.draw();
} }
void GuiComponent::fill( int x0, int y0, int x1, int y1, int col ) { void GuiComponent::fill( int x0, int y0, int x1, int y1, int col ) {
fill((float)x0, (float)y0, (float)x1, (float)y1, col); fill((float)x0, (float)y0, (float)x1, (float)y1, col);
} }
void GuiComponent::fill( float x0, float y0, float x1, float y1, int col ) void GuiComponent::fill( float x0, float y0, float x1, float y1, int col )
{ {
//float a = ((col >> 24) & 0xff) / 255.0f; //float a = ((col >> 24) & 0xff) / 255.0f;
//float r = ((col >> 16) & 0xff) / 255.0f; //float r = ((col >> 16) & 0xff) / 255.0f;
//float g = ((col >> 8) & 0xff) / 255.0f; //float g = ((col >> 8) & 0xff) / 255.0f;
//float b = ((col) & 0xff) / 255.0f; //float b = ((col) & 0xff) / 255.0f;
//glColor4f2(r, g, b, a); //glColor4f2(r, g, b, a);
Tesselator& t = Tesselator::instance; Tesselator& t = Tesselator::instance;
glEnable2(GL_BLEND); glEnable2(GL_BLEND);
glDisable2(GL_TEXTURE_2D); glDisable2(GL_TEXTURE_2D);
glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//LOGI("col: %f, %f, %f, %f\n", r, g, b, a); //LOGI("col: %f, %f, %f, %f\n", r, g, b, a);
t.begin(); t.begin();
const int color = (col&0xff00ff00) | ((col&0xff0000) >> 16) | ((col&0xff) << 16); const int color = (col&0xff00ff00) | ((col&0xff0000) >> 16) | ((col&0xff) << 16);
t.colorABGR(color); t.colorABGR(color);
t.vertex(x0, y1, 0); t.vertex(x0, y1, 0);
t.vertex(x1, y1, 0); t.vertex(x1, y1, 0);
t.vertex(x1, y0, 0); t.vertex(x1, y0, 0);
t.vertex(x0, y0, 0); t.vertex(x0, y0, 0);
t.draw(); t.draw();
glEnable2(GL_TEXTURE_2D); glEnable2(GL_TEXTURE_2D);
glDisable2(GL_BLEND); glDisable2(GL_BLEND);
} }
void GuiComponent::fillGradient( int x0, int y0, int x1, int y1, int col1, int col2 ) { void GuiComponent::fillGradient( int x0, int y0, int x1, int y1, int col1, int col2 ) {
fillGradient((float)x0, (float)y0, (float)x1, (float)y1, col1, 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 ) void GuiComponent::fillGradient( float x0, float y0, float x1, float y1, int col1, int col2 )
{ {
float a1 = ((col1 >> 24) & 0xff) / 255.0f; float a1 = ((col1 >> 24) & 0xff) / 255.0f;
float r1 = ((col1 >> 16) & 0xff) / 255.0f; float r1 = ((col1 >> 16) & 0xff) / 255.0f;
float g1 = ((col1 >> 8) & 0xff) / 255.0f; float g1 = ((col1 >> 8) & 0xff) / 255.0f;
float b1 = ((col1) & 0xff) / 255.0f; float b1 = ((col1) & 0xff) / 255.0f;
float a2 = ((col2 >> 24) & 0xff) / 255.0f; float a2 = ((col2 >> 24) & 0xff) / 255.0f;
float r2 = ((col2 >> 16) & 0xff) / 255.0f; float r2 = ((col2 >> 16) & 0xff) / 255.0f;
float g2 = ((col2 >> 8) & 0xff) / 255.0f; float g2 = ((col2 >> 8) & 0xff) / 255.0f;
float b2 = ((col2) & 0xff) / 255.0f; float b2 = ((col2) & 0xff) / 255.0f;
glDisable2(GL_TEXTURE_2D); glDisable2(GL_TEXTURE_2D);
glEnable2(GL_BLEND); glEnable2(GL_BLEND);
glDisable2(GL_ALPHA_TEST); glDisable2(GL_ALPHA_TEST);
glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glShadeModel2(GL_SMOOTH); glShadeModel2(GL_SMOOTH);
Tesselator& t = Tesselator::instance; Tesselator& t = Tesselator::instance;
t.begin(); t.begin();
t.color(r1, g1, b1, a1); t.color(r1, g1, b1, a1);
t.vertex(x1, y0, 0); t.vertex(x1, y0, 0);
t.vertex(x0, y0, 0); t.vertex(x0, y0, 0);
t.color(r2, g2, b2, a2); t.color(r2, g2, b2, a2);
t.vertex(x0, y1, 0); t.vertex(x0, y1, 0);
t.vertex(x1, y1, 0); t.vertex(x1, y1, 0);
t.draw(); t.draw();
glShadeModel2(GL_FLAT); glShadeModel2(GL_FLAT);
glDisable2(GL_BLEND); glDisable2(GL_BLEND);
glEnable2(GL_ALPHA_TEST); glEnable2(GL_ALPHA_TEST);
glEnable2(GL_TEXTURE_2D); glEnable2(GL_TEXTURE_2D);
} }
void GuiComponent::fillHorizontalGradient( int x0, int y0, int x1, int y1, int col1, int col2 ) { 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); 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 ) void GuiComponent::fillHorizontalGradient( float x0, float y0, float x1, float y1, int col1, int col2 )
{ {
float a1 = ((col1 >> 24) & 0xff) / 255.0f; float a1 = ((col1 >> 24) & 0xff) / 255.0f;
float r1 = ((col1 >> 16) & 0xff) / 255.0f; float r1 = ((col1 >> 16) & 0xff) / 255.0f;
float g1 = ((col1 >> 8) & 0xff) / 255.0f; float g1 = ((col1 >> 8) & 0xff) / 255.0f;
float b1 = ((col1) & 0xff) / 255.0f; float b1 = ((col1) & 0xff) / 255.0f;
float a2 = ((col2 >> 24) & 0xff) / 255.0f; float a2 = ((col2 >> 24) & 0xff) / 255.0f;
float r2 = ((col2 >> 16) & 0xff) / 255.0f; float r2 = ((col2 >> 16) & 0xff) / 255.0f;
float g2 = ((col2 >> 8) & 0xff) / 255.0f; float g2 = ((col2 >> 8) & 0xff) / 255.0f;
float b2 = ((col2) & 0xff) / 255.0f; float b2 = ((col2) & 0xff) / 255.0f;
glDisable2(GL_TEXTURE_2D); glDisable2(GL_TEXTURE_2D);
glEnable2(GL_BLEND); glEnable2(GL_BLEND);
glDisable2(GL_ALPHA_TEST); glDisable2(GL_ALPHA_TEST);
glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glShadeModel2(GL_SMOOTH); glShadeModel2(GL_SMOOTH);
Tesselator& t = Tesselator::instance; Tesselator& t = Tesselator::instance;
t.begin(); t.begin();
t.color(r2, g2, b2, a2); t.color(r2, g2, b2, a2);
t.vertex(x1, y0, 0); t.vertex(x1, y0, 0);
t.color(r1, g1, b1, a1); t.color(r1, g1, b1, a1);
t.vertex(x0, y0, 0); t.vertex(x0, y0, 0);
t.color(r1, g1, b1, a1); t.color(r1, g1, b1, a1);
t.vertex(x0, y1, 0); t.vertex(x0, y1, 0);
t.color(r2, g2, b2, a2); t.color(r2, g2, b2, a2);
t.vertex(x1, y1, 0); t.vertex(x1, y1, 0);
t.draw(); t.draw();
glShadeModel2(GL_FLAT); glShadeModel2(GL_FLAT);
glDisable2(GL_BLEND); glDisable2(GL_BLEND);
glEnable2(GL_ALPHA_TEST); glEnable2(GL_ALPHA_TEST);
glEnable2(GL_TEXTURE_2D); glEnable2(GL_TEXTURE_2D);
} }

View File

@@ -1,34 +1,32 @@
#ifndef NET_MINECRAFT_CLIENT_GUI__GuiComponent_H__ #pragma once
#define NET_MINECRAFT_CLIENT_GUI__GuiComponent_H__
//package net.minecraft.client.gui;
//package net.minecraft.client.gui;
#include <string>
#include <string> class Font;
class Font; class Minecraft;
class Minecraft;
class GuiComponent
class GuiComponent {
{ public:
public: GuiComponent();
GuiComponent(); virtual ~GuiComponent();
virtual ~GuiComponent();
void drawString(Font* font, const std::string& str, int x, int y, int color);
void drawString(Font* font, const std::string& str, int x, int y, int color); void drawCenteredString(Font* font, const std::string& str, int x, int y, int color);
void drawCenteredString(Font* font, const std::string& str, int x, int y, int color);
void blit(int x, int y, int sx, int sy, int w, int h, int sw=0, int sh=0);
void blit(int x, int y, int sx, int sy, int w, int h, int sw=0, int sh=0); void blit(float x, float y, int sx, int sy, float w, float h, int sw=0, int sh=0);
void blit(float x, float y, int sx, int sy, float w, float h, int sw=0, int sh=0);
protected:
protected: void fill(int x0, int y0, int x1, int y1, int col);
void fill(int x0, int y0, int x1, int y1, int col); void fill(float x0, float y0, float x1, float y1, int col);
void fill(float x0, float y0, float x1, float y1, int col); void fillGradient(int x0, int y0, int x1, int y1, int col1, int col2);
void fillGradient(int x0, int y0, int x1, int y1, int col1, int col2); void fillGradient(float x0, float y0, float x1, float y1, int col1, int col2);
void fillGradient(float x0, float y0, float x1, float y1, int col1, int col2); void fillHorizontalGradient(int x0, int y0, int x1, int y1, int col1, int col2);
void fillHorizontalGradient(int x0, int y0, int x1, int y1, int col1, int col2); void fillHorizontalGradient(float x0, float y0, float x1, float y1, int col1, int col2);
void fillHorizontalGradient(float x0, float y0, float x1, float y1, int col1, int col2);
float blitOffset;
float blitOffset;
};
};
#endif /*NET_MINECRAFT_CLIENT_GUI__GuiComponent_H__*/

View File

@@ -1,291 +1,291 @@
#include "Screen.h" #include "Screen.hpp"
#include "components/Button.h" #include "components/Button.hpp"
#include "components/TextBox.h" #include "components/TextBox.hpp"
#include "../Minecraft.h" #include <Minecraft.hpp>
#include "../renderer/Tesselator.h" #include "client/renderer/Tesselator.hpp"
#include "../sound/SoundEngine.h" #include "client/sound/SoundEngine.hpp"
#include "../../platform/input/Keyboard.h" #include "platform/input/Keyboard.hpp"
#include "../../platform/input/Mouse.h" #include "platform/input/Mouse.hpp"
#include "../renderer/Textures.h" #include "client/renderer/Textures.hpp"
Screen::Screen() Screen::Screen()
: passEvents(false), : passEvents(false),
clickedButton(NULL), clickedButton(NULL),
tabButtonIndex(0), tabButtonIndex(0),
width(1), width(1),
height(1), height(1),
minecraft(NULL), minecraft(NULL),
font(NULL) font(NULL)
{ {
} }
void Screen::render( int xm, int ym, float a ) void Screen::render( int xm, int ym, float a )
{ {
for (unsigned int i = 0; i < buttons.size(); i++) { for (unsigned int i = 0; i < buttons.size(); i++) {
Button* button = buttons[i]; Button* button = buttons[i];
button->render(minecraft, xm, ym); button->render(minecraft, xm, ym);
} }
// render any text boxes after buttons // render any text boxes after buttons
for (unsigned int i = 0; i < textBoxes.size(); i++) { for (unsigned int i = 0; i < textBoxes.size(); i++) {
TextBox* textbox = textBoxes[i]; TextBox* textbox = textBoxes[i];
textbox->render(minecraft, xm, ym); textbox->render(minecraft, xm, ym);
} }
} }
void Screen::init( Minecraft* minecraft, int width, int height ) void Screen::init( Minecraft* minecraft, int width, int height )
{ {
//particles = /*new*/ GuiParticles(minecraft); //particles = /*new*/ GuiParticles(minecraft);
this->minecraft = minecraft; this->minecraft = minecraft;
this->font = minecraft->font; this->font = minecraft->font;
this->width = width; this->width = width;
this->height = height; this->height = height;
init(); init();
setupPositions(); setupPositions();
updateTabButtonSelection(); updateTabButtonSelection();
} }
void Screen::init() void Screen::init()
{ {
} }
void Screen::setSize( int width, int height ) void Screen::setSize( int width, int height )
{ {
this->width = width; this->width = width;
this->height = height; this->height = height;
setupPositions(); setupPositions();
} }
bool Screen::handleBackEvent( bool isDown ) bool Screen::handleBackEvent( bool isDown )
{ {
return false; return false;
} }
void Screen::updateEvents() void Screen::updateEvents()
{ {
if (passEvents) if (passEvents)
return; return;
while (Mouse::next()) while (Mouse::next())
mouseEvent(); mouseEvent();
while (Keyboard::next()) while (Keyboard::next())
keyboardEvent(); keyboardEvent();
while (Keyboard::nextTextChar()) while (Keyboard::nextTextChar())
keyboardTextEvent(); keyboardTextEvent();
} }
void Screen::mouseEvent() void Screen::mouseEvent()
{ {
const MouseAction& e = Mouse::getEvent(); const MouseAction& e = Mouse::getEvent();
// forward wheel events to subclasses // forward wheel events to subclasses
if (e.action == MouseAction::ACTION_WHEEL) { if (e.action == MouseAction::ACTION_WHEEL) {
int xm = e.x * width / minecraft->width; int xm = e.x * width / minecraft->width;
int ym = e.y * height / minecraft->height - 1; int ym = e.y * height / minecraft->height - 1;
mouseWheel(e.dx, e.dy, xm, ym); mouseWheel(e.dx, e.dy, xm, ym);
return; return;
} }
if (!e.isButton()) if (!e.isButton())
return; return;
if (Mouse::getEventButtonState()) { if (Mouse::getEventButtonState()) {
int xm = e.x * width / minecraft->width; int xm = e.x * width / minecraft->width;
int ym = e.y * height / minecraft->height - 1; int ym = e.y * height / minecraft->height - 1;
mouseClicked(xm, ym, Mouse::getEventButton()); mouseClicked(xm, ym, Mouse::getEventButton());
} else { } else {
int xm = e.x * width / minecraft->width; int xm = e.x * width / minecraft->width;
int ym = e.y * height / minecraft->height - 1; int ym = e.y * height / minecraft->height - 1;
mouseReleased(xm, ym, Mouse::getEventButton()); mouseReleased(xm, ym, Mouse::getEventButton());
} }
} }
void Screen::keyboardEvent() void Screen::keyboardEvent()
{ {
if (Keyboard::getEventKeyState()) { if (Keyboard::getEventKeyState()) {
//if (Keyboard.getEventKey() == Keyboard.KEY_F11) { //if (Keyboard.getEventKey() == Keyboard.KEY_F11) {
// minecraft->toggleFullScreen(); // minecraft->toggleFullScreen();
// return; // return;
//} //}
keyPressed(Keyboard::getEventKey()); keyPressed(Keyboard::getEventKey());
} }
} }
void Screen::keyboardTextEvent() void Screen::keyboardTextEvent()
{ {
charPressed(Keyboard::getChar()); charPressed(Keyboard::getChar());
} }
void Screen::renderBackground() void Screen::renderBackground()
{ {
renderBackground(0); renderBackground(0);
} }
void Screen::renderBackground( int vo ) void Screen::renderBackground( int vo )
{ {
if (minecraft->isLevelGenerated()) { if (minecraft->isLevelGenerated()) {
fillGradient(0, 0, width, height, 0xc0101010, 0xd0101010); fillGradient(0, 0, width, height, 0xc0101010, 0xd0101010);
} else { } else {
renderDirtBackground(vo); renderDirtBackground(vo);
} }
} }
void Screen::renderDirtBackground( int vo ) void Screen::renderDirtBackground( int vo )
{ {
//glDisable2(GL_LIGHTING); //glDisable2(GL_LIGHTING);
glDisable2(GL_FOG); glDisable2(GL_FOG);
Tesselator& t = Tesselator::instance; Tesselator& t = Tesselator::instance;
minecraft->textures->loadAndBindTexture("gui/background.png"); minecraft->textures->loadAndBindTexture("gui/background.png");
glColor4f2(1, 1, 1, 1); glColor4f2(1, 1, 1, 1);
float s = 32; float s = 32;
float fvo = (float) vo; float fvo = (float) vo;
t.begin(); t.begin();
t.color(0x404040); t.color(0x404040);
t.vertexUV(0, (float)height, 0, 0, height / s + fvo); 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, (float)height, 0, width / s, (float)height / s + fvo);
t.vertexUV((float)width, 0, 0, (float)width / s, 0 + fvo); t.vertexUV((float)width, 0, 0, (float)width / s, 0 + fvo);
t.vertexUV(0, 0, 0, 0, 0 + fvo); t.vertexUV(0, 0, 0, 0, 0 + fvo);
t.draw(); t.draw();
} }
bool Screen::isPauseScreen() bool Screen::isPauseScreen()
{ {
return true; return true;
} }
bool Screen::isErrorScreen() bool Screen::isErrorScreen()
{ {
return false; return false;
} }
bool Screen::isInGameScreen() bool Screen::isInGameScreen()
{ {
return true; return true;
} }
bool Screen::closeOnPlayerHurt() { bool Screen::closeOnPlayerHurt() {
return false; return false;
} }
void Screen::keyPressed( int eventKey ) void Screen::keyPressed( int eventKey )
{ {
if (eventKey == Keyboard::KEY_ESCAPE) { if (eventKey == Keyboard::KEY_ESCAPE) {
minecraft->setScreen(NULL); minecraft->setScreen(NULL);
//minecraft->grabMouse(); //minecraft->grabMouse();
} }
// pass key events to any text boxes first // pass key events to any text boxes first
for (auto& textbox : textBoxes) { for (auto& textbox : textBoxes) {
textbox->keyPressed(minecraft, eventKey); textbox->keyPressed(minecraft, eventKey);
} }
#ifdef TABBING #ifdef TABBING
if (minecraft->useTouchscreen()) if (minecraft->useTouchscreen())
return; return;
// "Tabbing" the buttons (walking with keys) // "Tabbing" the buttons (walking with keys)
const int tabButtonCount = tabButtons.size(); const int tabButtonCount = tabButtons.size();
if (!tabButtonCount) if (!tabButtonCount)
return; return;
Options& o = minecraft->options; Options& o = minecraft->options;
if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_NEXT)) if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_NEXT))
if (++tabButtonIndex == tabButtonCount) tabButtonIndex = 0; if (++tabButtonIndex == tabButtonCount) tabButtonIndex = 0;
if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_PREV)) if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_PREV))
if (--tabButtonIndex == -1) tabButtonIndex = tabButtonCount-1; if (--tabButtonIndex == -1) tabButtonIndex = tabButtonCount-1;
if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_OK)) { if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_OK)) {
Button* button = tabButtons[tabButtonIndex]; Button* button = tabButtons[tabButtonIndex];
if (button->active) { if (button->active) {
minecraft->soundEngine->playUI("random.click", 1, 1); minecraft->soundEngine->playUI("random.click", 1, 1);
buttonClicked(button); buttonClicked(button);
} }
} }
updateTabButtonSelection(); updateTabButtonSelection();
#endif #endif
} }
void Screen::charPressed(char inputChar) { void Screen::charPressed(char inputChar) {
for (auto& textbox : textBoxes) { for (auto& textbox : textBoxes) {
textbox->charPressed(minecraft, inputChar); textbox->charPressed(minecraft, inputChar);
} }
} }
void Screen::updateTabButtonSelection() void Screen::updateTabButtonSelection()
{ {
#ifdef TABBING #ifdef TABBING
if (minecraft->useTouchscreen()) if (minecraft->useTouchscreen())
return; return;
for (unsigned int i = 0; i < tabButtons.size(); ++i) for (unsigned int i = 0; i < tabButtons.size(); ++i)
tabButtons[i]->selected = (i == tabButtonIndex); tabButtons[i]->selected = (i == tabButtonIndex);
#endif #endif
} }
void Screen::mouseClicked( int x, int y, int buttonNum ) void Screen::mouseClicked( int x, int y, int buttonNum )
{ {
if (buttonNum == MouseAction::ACTION_LEFT) { if (buttonNum == MouseAction::ACTION_LEFT) {
for (unsigned int i = 0; i < buttons.size(); ++i) { for (unsigned int i = 0; i < buttons.size(); ++i) {
Button* button = buttons[i]; Button* button = buttons[i];
//LOGI("Hit-testing button: %p\n", button); //LOGI("Hit-testing button: %p\n", button);
if (button->clicked(minecraft, x, y)) { if (button->clicked(minecraft, x, y)) {
button->setPressed(); button->setPressed();
//LOGI("Hit-test successful: %p\n", button); //LOGI("Hit-test successful: %p\n", button);
clickedButton = button; clickedButton = button;
/* /*
#if !defined(ANDROID) && !defined(__APPLE__) //if (!minecraft->isTouchscreen()) { #if !defined(ANDROID) && !defined(__APPLE__) //if (!minecraft->isTouchscreen()) {
minecraft->soundEngine->playUI("random.click", 1, 1); minecraft->soundEngine->playUI("random.click", 1, 1);
buttonClicked(button); buttonClicked(button);
#endif } #endif }
*/ */
} }
} }
} }
// let textboxes see the click regardless // let textboxes see the click regardless
for (auto& textbox : textBoxes) { for (auto& textbox : textBoxes) {
textbox->mouseClicked(minecraft, x, y, buttonNum); textbox->mouseClicked(minecraft, x, y, buttonNum);
} }
} }
void Screen::mouseReleased( int x, int y, int 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>"); //LOGI("b_id: %d, (%p), text: %s\n", buttonNum, clickedButton, clickedButton?clickedButton->msg.c_str():"<null>");
if (!clickedButton || buttonNum != MouseAction::ACTION_LEFT) return; if (!clickedButton || buttonNum != MouseAction::ACTION_LEFT) return;
#if 1 #if 1
//#if defined(ANDROID) || defined(__APPLE__) //if (minecraft->isTouchscreen()) { //#if defined(ANDROID) || defined(__APPLE__) //if (minecraft->isTouchscreen()) {
for (unsigned int i = 0; i < buttons.size(); ++i) { for (unsigned int i = 0; i < buttons.size(); ++i) {
Button* button = buttons[i]; Button* button = buttons[i];
if (clickedButton == button && button->clicked(minecraft, x, y)) { if (clickedButton == button && button->clicked(minecraft, x, y)) {
buttonClicked(button); buttonClicked(button);
minecraft->soundEngine->playUI("random.click", 1, 1); minecraft->soundEngine->playUI("random.click", 1, 1);
clickedButton->released(x, y); clickedButton->released(x, y);
} }
} }
# else // } else { # else // } else {
clickedButton->released(x, y); clickedButton->released(x, y);
#endif // } #endif // }
clickedButton = NULL; clickedButton = NULL;
} }
bool Screen::renderGameBehind() { bool Screen::renderGameBehind() {
return true; return true;
} }
bool Screen::hasClippingArea( IntRectangle& out ) bool Screen::hasClippingArea( IntRectangle& out )
{ {
return false; return false;
} }
void Screen::lostFocus() { void Screen::lostFocus() {
for(std::vector<TextBox*>::iterator it = textBoxes.begin(); it != textBoxes.end(); ++it) { for(std::vector<TextBox*>::iterator it = textBoxes.begin(); it != textBoxes.end(); ++it) {
TextBox* tb = *it; TextBox* tb = *it;
tb->loseFocus(minecraft); tb->loseFocus(minecraft);
} }
} }
void Screen::toGUICoordinate( int& x, int& y ) { void Screen::toGUICoordinate( int& x, int& y ) {
x = x * width / minecraft->width; x = x * width / minecraft->width;
y = y * height / minecraft->height - 1; y = y * height / minecraft->height - 1;
} }

View File

@@ -1,83 +1,81 @@
#ifndef NET_MINECRAFT_CLIENT_GUI__Screen_H__ #pragma once
#define NET_MINECRAFT_CLIENT_GUI__Screen_H__
//package net.minecraft.client.gui;
//package net.minecraft.client.gui;
#include <vector>
#include <vector> #include "GuiComponent.hpp"
#include "GuiComponent.h"
class Font;
class Font; class Minecraft;
class Minecraft; class Button;
class Button; class TextBox;
class TextBox; struct IntRectangle;
struct IntRectangle;
class Screen: public GuiComponent
class Screen: public GuiComponent {
{ public:
public: Screen();
Screen();
virtual void render(int xm, int ym, float a);
virtual void render(int xm, int ym, float a);
void init(Minecraft* minecraft, int width, int height);
void init(Minecraft* minecraft, int width, int height); virtual void init();
virtual void init();
void setSize(int width, int height);
void setSize(int width, int height); virtual void setupPositions() {};
virtual void setupPositions() {};
virtual void updateEvents();
virtual void updateEvents(); virtual void mouseEvent();
virtual void mouseEvent(); virtual void keyboardEvent();
virtual void keyboardEvent(); virtual void keyboardTextEvent();
virtual void keyboardTextEvent(); virtual bool handleBackEvent(bool isDown);
virtual bool handleBackEvent(bool isDown);
virtual void tick() {}
virtual void tick() {}
virtual void removed() {}
virtual void removed() {}
virtual void renderBackground();
virtual void renderBackground(); virtual void renderBackground(int vo);
virtual void renderBackground(int vo); virtual void renderDirtBackground(int vo);
virtual void renderDirtBackground(int vo); // query
// query virtual bool renderGameBehind();
virtual bool renderGameBehind(); virtual bool hasClippingArea(IntRectangle& out);
virtual bool hasClippingArea(IntRectangle& out);
virtual bool isPauseScreen();
virtual bool isPauseScreen(); virtual bool isErrorScreen();
virtual bool isErrorScreen(); virtual bool isInGameScreen();
virtual bool isInGameScreen(); virtual bool closeOnPlayerHurt();
virtual bool closeOnPlayerHurt();
virtual void confirmResult(bool result, int id) {}
virtual void confirmResult(bool result, int id) {} virtual void lostFocus();
virtual void lostFocus(); virtual void toGUICoordinate(int& x, int& y);
virtual void toGUICoordinate(int& x, int& y); protected:
protected: void updateTabButtonSelection();
void updateTabButtonSelection();
virtual void buttonClicked(Button* button) {}
virtual void buttonClicked(Button* button) {} virtual void mouseClicked(int x, int y, int buttonNum);
virtual void mouseClicked(int x, int y, int buttonNum); virtual void mouseReleased(int x, int y, int buttonNum);
virtual void mouseReleased(int x, int y, int buttonNum);
// mouse wheel movement (dx/dy are wheel deltas, xm/ym are GUI coords)
// mouse wheel movement (dx/dy are wheel deltas, xm/ym are GUI coords) virtual void mouseWheel(int dx, int dy, int xm, int ym) {}
virtual void mouseWheel(int dx, int dy, int xm, int ym) {}
virtual void keyPressed(int eventKey);
virtual void keyPressed(int eventKey); virtual void charPressed(char inputChar);
virtual void charPressed(char inputChar); public:
public: int width;
int width; int height;
int height; bool passEvents;
bool passEvents; //GuiParticles* particles;
//GuiParticles* particles; protected:
protected: Minecraft* minecraft;
Minecraft* minecraft; std::vector<Button*> buttons;
std::vector<Button*> buttons; std::vector<TextBox*> textBoxes;
std::vector<TextBox*> textBoxes;
std::vector<Button*> tabButtons;
std::vector<Button*> tabButtons; int tabButtonIndex;
int tabButtonIndex;
Font* font;
Font* font; private:
private: Button* clickedButton;
Button* clickedButton; };
};
#endif /*NET_MINECRAFT_CLIENT_GUI__Screen_H__*/

View File

@@ -1,11 +0,0 @@
#ifndef NET_MINECRAFT_CLIENT_GUI__TweenData_H__
#define NET_MINECRAFT_CLIENT_GUI__TweenData_H__
typedef struct TweenData {
float cur;
float dur;
float start;
float stop;
} TweenData;
#endif /*NET_MINECRAFT_CLIENT_GUI__TweenData_H__*/

9
src/client/gui/TweenData.hpp Executable file
View File

@@ -0,0 +1,9 @@
#pragma once
typedef struct TweenData {
float cur;
float dur;
float start;
float stop;
} TweenData;

View File

@@ -1,219 +1,219 @@
#include "Button.h" #include "Button.hpp"
#include "../../Minecraft.h" #include "client/Minecraft.hpp"
#include "../../renderer/Textures.h" #include "client/renderer/Textures.hpp"
Button::Button(int id, const std::string& msg) Button::Button(int id, const std::string& msg)
: GuiElement(true, true, 0, 0, 200, 24), : GuiElement(true, true, 0, 0, 200, 24),
id(id), id(id),
msg(msg), msg(msg),
selected(false), selected(false),
_currentlyDown(false) _currentlyDown(false)
{ {
} }
Button::Button( int id, int x, int y, const std::string& msg ) Button::Button( int id, int x, int y, const std::string& msg )
: GuiElement(true, true, x, y, 200, 24), : GuiElement(true, true, x, y, 200, 24),
id(id), id(id),
msg(msg), msg(msg),
selected(false), selected(false),
_currentlyDown(false) _currentlyDown(false)
{ {
} }
Button::Button( int id, int x, int y, int w, int h, const std::string& msg ) Button::Button( int id, int x, int y, int w, int h, const std::string& msg )
: GuiElement(true, true, x, y, w, h), : GuiElement(true, true, x, y, w, h),
id(id), id(id),
msg(msg), msg(msg),
selected(false), selected(false),
_currentlyDown(false) _currentlyDown(false)
{ {
} }
void Button::render( Minecraft* minecraft, int xm, int ym ) void Button::render( Minecraft* minecraft, int xm, int ym )
{ {
if (!visible) return; if (!visible) return;
/* /*
minecraft->textures->loadAndBindTexture("gui/gui.png"); minecraft->textures->loadAndBindTexture("gui/gui.png");
glColor4f2(1, 1, 1, 1); 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); //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); int yImage = getYImage(hovered || selected);
blit(x, y, 0, 46 + yImage * 20, w / 2, h, 0, 20); 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); blit(x + w / 2, y, 200 - w / 2, 46 + yImage * 20, w / 2, h, 0, 20);
*/ */
renderBg(minecraft, xm, ym); renderBg(minecraft, xm, ym);
renderFace(minecraft, xm , ym); renderFace(minecraft, xm , ym);
} }
void Button::released( int mx, int my ) { void Button::released( int mx, int my ) {
_currentlyDown = false; _currentlyDown = false;
} }
bool Button::clicked( Minecraft* minecraft, int mx, int my ) bool Button::clicked( Minecraft* minecraft, int mx, int my )
{ {
return active && mx >= x && my >= y && mx < x + width && my < y + height; return active && mx >= x && my >= y && mx < x + width && my < y + height;
} }
void Button::setPressed() { void Button::setPressed() {
_currentlyDown = true; _currentlyDown = true;
} }
int Button::getYImage( bool hovered ) int Button::getYImage( bool hovered )
{ {
int res = 1; int res = 1;
if (!active) res = 0; if (!active) res = 0;
else if (hovered) res = 2; else if (hovered) res = 2;
return res; return res;
} }
void Button::renderFace(Minecraft* mc, int xm, int ym) { void Button::renderFace(Minecraft* mc, int xm, int ym) {
Font* font = mc->font; Font* font = mc->font;
if (!active) { if (!active) {
drawCenteredString(font, msg, x + width / 2, y + (height - 8) / 2, 0xffa0a0a0); drawCenteredString(font, msg, x + width / 2, y + (height - 8) / 2, 0xffa0a0a0);
} else { } else {
if (hovered(mc, xm, ym) || selected) { if (hovered(mc, xm, ym) || selected) {
drawCenteredString(font, msg, x + width / 2, y + (height - 8) / 2, 0xffffa0); drawCenteredString(font, msg, x + width / 2, y + (height - 8) / 2, 0xffffa0);
} else { } else {
drawCenteredString(font, msg, x + width / 2, y + (height - 8) / 2, 0xe0e0e0); drawCenteredString(font, msg, x + width / 2, y + (height - 8) / 2, 0xe0e0e0);
} }
} }
} }
void Button::renderBg( Minecraft* minecraft, int xm, int ym ) void Button::renderBg( Minecraft* minecraft, int xm, int ym )
{ {
minecraft->textures->loadAndBindTexture("gui/gui.png"); minecraft->textures->loadAndBindTexture("gui/gui.png");
glColor4f2(1, 1, 1, 1); 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); //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));; int yImage = getYImage(selected || hovered(minecraft, xm, ym));;
blit(x, y, 0, 46 + yImage * 20, width / 2, height, 0, 20); 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); 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) { bool Button::hovered(Minecraft* minecraft, int xm , int ym) {
return minecraft->useTouchscreen()? (_currentlyDown && isInside(xm, ym)) : isInside(xm, ym); return minecraft->useTouchscreen()? (_currentlyDown && isInside(xm, ym)) : isInside(xm, ym);
} }
bool Button::isInside( int xm, int ym ) { bool Button::isInside( int xm, int ym ) {
return xm >= x && ym >= y && xm < x + width && ym < y + height; return xm >= x && ym >= y && xm < x + width && ym < y + height;
} }
// //
// BlankButton // BlankButton
// //
BlankButton::BlankButton(int id) BlankButton::BlankButton(int id)
: super(id, "") : super(id, "")
{ {
visible = false; visible = false;
} }
BlankButton::BlankButton(int id, int x, int y, int w, int h) BlankButton::BlankButton(int id, int x, int y, int w, int h)
: super(id, x, y, w, h, "") : super(id, x, y, w, h, "")
{ {
visible = false; visible = false;
} }
// //
// The Touch-interface button // The Touch-interface button
// //
namespace Touch { namespace Touch {
TButton::TButton(int id, const std::string& msg) TButton::TButton(int id, const std::string& msg)
: super(id, msg) : super(id, msg)
{ {
width = 66; width = 66;
height = 26; height = 26;
} }
TButton::TButton( int id, int x, int y, const std::string& msg ) TButton::TButton( int id, int x, int y, const std::string& msg )
: super(id, x, y, msg) : super(id, x, y, msg)
{ {
width = 66; width = 66;
height = 26; height = 26;
} }
TButton::TButton( int id, int x, int y, int w, int h, const std::string& msg ) TButton::TButton( int id, int x, int y, int w, int h, const std::string& msg )
: super(id, x, y, w, h, msg) : super(id, x, y, w, h, msg)
{ {
} }
void TButton::renderBg( Minecraft* minecraft, int xm, int ym ) 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 && (minecraft->useTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : isInside(xm, ym));
// bool hovered = active && (_currentlyDown && isInside(xm, ym)); // bool hovered = active && (_currentlyDown && isInside(xm, ym));
minecraft->textures->loadAndBindTexture("gui/touchgui.png"); 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); //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) if (active)
glColor4f2(1, 1, 1, 1); glColor4f2(1, 1, 1, 1);
else else
glColor4f2(0.5f, 0.5f, 0.5f, 1); glColor4f2(0.5f, 0.5f, 0.5f, 1);
blit(x, y, hovered?66:0, 0, width, height, 66, 26); 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); //blit(x + w / 2, y, 200 - w / 2, 46 + yImage * 20, w / 2, h, 0, 20);
} }
// //
// Header spacing in Touchscreen mode // Header spacing in Touchscreen mode
// //
THeader::THeader(int id, const std::string& msg) THeader::THeader(int id, const std::string& msg)
: super(id, msg), : super(id, msg),
xText(-99999) xText(-99999)
{ {
active = false; active = false;
width = 66; width = 66;
height = 26; height = 26;
} }
THeader::THeader( int id, int x, int y, const std::string& msg ) THeader::THeader( int id, int x, int y, const std::string& msg )
: super(id, x, y, msg), : super(id, x, y, msg),
xText(-99999) xText(-99999)
{ {
active = false; active = false;
width = 66; width = 66;
height = 26; height = 26;
} }
THeader::THeader( int id, int x, int y, int w, int h, const std::string& msg ) THeader::THeader( int id, int x, int y, int w, int h, const std::string& msg )
: super(id, x, y, w, h, msg), : super(id, x, y, w, h, msg),
xText(-99999) xText(-99999)
{ {
active = false; active = false;
} }
void THeader::render( Minecraft* minecraft, int xm, int ym ) { void THeader::render( Minecraft* minecraft, int xm, int ym ) {
Font* font = minecraft->font; Font* font = minecraft->font;
renderBg(minecraft, xm, ym); renderBg(minecraft, xm, ym);
int xx = x + width/2; int xx = x + width/2;
if (xText != -99999) if (xText != -99999)
xx = xText; xx = xText;
drawCenteredString(font, msg, xx, y + (height - 8) / 2, 0xe0e0e0); drawCenteredString(font, msg, xx, y + (height - 8) / 2, 0xe0e0e0);
} }
void THeader::renderBg( Minecraft* minecraft, int xm, int ym ) void THeader::renderBg( Minecraft* minecraft, int xm, int ym )
{ {
minecraft->textures->loadAndBindTexture("gui/touchgui.png"); 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); //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); glColor4f2(1, 1, 1, 1);
// Left cap // Left cap
blit(x, y, 150, 26, 2, height-1, 2, 25); blit(x, y, 150, 26, 2, height-1, 2, 25);
// Middle // Middle
blit(x+2, y, 153, 26, width-3, height-1, 8, 25); blit(x+2, y, 153, 26, width-3, height-1, 8, 25);
// Right cap // Right cap
blit(x+width-2, y, 162, 26, 2, height-1, 2, 25); blit(x+width-2, y, 162, 26, 2, height-1, 2, 25);
// Shadow // Shadow
glEnable2(GL_BLEND); glEnable2(GL_BLEND);
glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
blit(x, y+height-1, 153, 52, width, 3, 8, 3); blit(x, y+height-1, 153, 52, width, 3, 8, 3);
} }
}; };

View File

@@ -1,80 +1,78 @@
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__Button_H__ #pragma once
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__Button_H__
//package net.minecraft.client.gui;
//package net.minecraft.client.gui;
#include <string>
#include <string> #include "GuiElement.hpp"
#include "GuiElement.h" #include "client/Options.hpp"
#include "../../Options.h"
class Font;
class Font; class Minecraft;
class Minecraft;
class Button: public GuiElement
class Button: public GuiElement {
{ public:
public: Button(int id, const std::string& msg);
Button(int id, const std::string& msg); Button(int id, int x, int y, const std::string& msg);
Button(int id, int x, int y, const std::string& msg); Button(int id, int x, int y, int w, int h, const std::string& msg);
Button(int id, int x, int y, int w, int h, const std::string& msg); virtual ~Button() {}
virtual ~Button() {} virtual void render(Minecraft* minecraft, int xm, int ym);
virtual void render(Minecraft* minecraft, int xm, int ym);
virtual bool clicked(Minecraft* minecraft, int mx, int my);
virtual bool clicked(Minecraft* minecraft, int mx, int my); virtual void released(int mx, int my);
virtual void released(int mx, int my); virtual void setPressed();
virtual void setPressed();
bool isInside(int xm, int ym);
bool isInside(int xm, int ym); protected:
protected: virtual int getYImage(bool hovered);
virtual int getYImage(bool hovered); virtual void renderBg(Minecraft* minecraft, int xm, int ym);
virtual void renderBg(Minecraft* minecraft, int xm, int ym);
virtual void renderFace(Minecraft* minecraft, int xm, int ym);
virtual void renderFace(Minecraft* minecraft, int xm, int ym); bool hovered(Minecraft* minecraft, int xm, int ym);
bool hovered(Minecraft* minecraft, int xm, int ym); public:
public: std::string msg;
std::string msg; int id;
int id;
bool selected;
bool selected; protected:
protected: bool _currentlyDown;
bool _currentlyDown; };
};
// @note: A bit backwards, but this is a button that
// @note: A bit backwards, but this is a button that // only reacts to clicks, but isn't rendered.
// only reacts to clicks, but isn't rendered. class BlankButton: public Button
class BlankButton: public Button {
{ typedef Button super;
typedef Button super; public:
public: BlankButton(int id);
BlankButton(int id); BlankButton(int id, int x, int y, int w, int h);
BlankButton(int id, int x, int y, int w, int h); };
};
namespace Touch {
namespace Touch { class TButton: public Button
class TButton: public Button {
{ typedef Button super;
typedef Button super; public:
public: TButton(int id, const std::string& msg);
TButton(int id, const std::string& msg); TButton(int id, int x, int y, const std::string& msg);
TButton(int id, int x, int y, const std::string& msg); TButton(int id, int x, int y, int w, int h, const std::string& msg);
TButton(int id, int x, int y, int w, int h, const std::string& msg); protected:
protected: virtual void renderBg(Minecraft* minecraft, int xm, int ym);
virtual void renderBg(Minecraft* minecraft, int xm, int ym); };
};
// "Header" in Touchscreen mode
// "Header" in Touchscreen mode class THeader: public Button {
class THeader: public Button { typedef Button super;
typedef Button super; public:
public: THeader(int id, const std::string& msg);
THeader(int id, const std::string& msg); THeader(int id, int x, int y, const std::string& msg);
THeader(int id, int x, int y, const std::string& msg); THeader(int id, int x, int y, int w, int h, const std::string& msg);
THeader(int id, int x, int y, int w, int h, const std::string& msg); protected:
protected: virtual void renderBg(Minecraft* minecraft, int xm, int ym);
virtual void renderBg(Minecraft* minecraft, int xm, int ym); void render( Minecraft* minecraft, int xm, int ym );
void render( Minecraft* minecraft, int xm, int ym ); public:
public: int xText;
int xText; };
}; }
}
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__Button_H__*/

View File

@@ -1 +1 @@
#include "GuiElement.h" #include "GuiElement.hpp"

View File

@@ -1,55 +1,53 @@
#ifndef NET_MINECRAFT_CLIENT_GUI__GButton_H__ #pragma once
#define NET_MINECRAFT_CLIENT_GUI__GButton_H__ #include "Button.hpp"
#include "Button.h"
class GButton: public Button {
class GButton: public Button { typedef Button super;
typedef Button super; public:
public: static const int LayerDefault = 1;
static const int LayerDefault = 1; static const int LayerSelected = 2;
static const int LayerSelected = 2; static const int LayerMax = 4;
static const int LayerMax = 4;
GButton(int id)
GButton(int id) : super(id, "")
: super(id, "") {}
{} ~GButton() {
~GButton() { for (unsigned int i = 0; i < layers.size(); ++i) {
for (unsigned int i = 0; i < layers.size(); ++i) { delete layers[i].first;
delete layers[i].first; }
} }
}
void addElement(int layerId, GuiElement* e) {
void addElement(int layerId, GuiElement* e) { if (!e || layerId < 0 || layerId >= LayerMax) {
if (!e || layerId < 0 || layerId >= LayerMax) { LOGE("Error @ GButton::element : Trying to add element %p at layer: %d\n", e, layerId);
LOGE("Error @ GButton::element : Trying to add element %p at layer: %d\n", e, layerId); return;
return; }
} layers.push_back(std::make_pair(e, layerId));
layers.push_back(std::make_pair(e, layerId)); }
}
void render( Minecraft* minecraft, int xm, int ym )
void render( Minecraft* minecraft, int xm, int ym ) {
{ if (!visible) return;
if (!visible) return;
bool isHovered = minecraft->isTouchscreen()?
bool isHovered = minecraft->isTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height): false;
(_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height): false;
int layer = isHovered? LayerSelected : LayerDefault;
int layer = isHovered? LayerSelected : LayerDefault; if (layer < 0) return;
if (layer < 0) return;
Tesselator& t = Tesselator::instance;
Tesselator& t = Tesselator::instance; t.addOffset((float)x, (float)y, 0);
t.addOffset((float)x, (float)y, 0);
for (unsigned int i = 0; i < layers.size(); ++i) {
for (unsigned int i = 0; i < layers.size(); ++i) { if ((layers[i].second & layer) != 0)
if ((layers[i].second & layer) != 0) layers[i].first->render(minecraft, 0, 0);
layers[i].first->render(minecraft, 0, 0); }
}
t.addOffset((float)-x, (float)-y, 0);
t.addOffset((float)-x, (float)-y, 0); }
}
private:
private: std::vector<std::pair<GuiElement*, int> > layers;
std::vector<std::pair<GuiElement*, int> > layers; };
};
#endif /*NET_MINECRAFT_CLIENT_GUI__GButton_H__*/

View File

@@ -1,20 +1,20 @@
#include "GuiElement.h" #include "GuiElement.hpp"
GuiElement::GuiElement( bool active/*=false*/, bool visible/*=true*/, int x /*= 0*/, int y /*= 0*/, int width/*=24*/, int height/*=24*/ ) GuiElement::GuiElement( bool active/*=false*/, bool visible/*=true*/, int x /*= 0*/, int y /*= 0*/, int width/*=24*/, int height/*=24*/ )
: active(active), : active(active),
visible(visible), visible(visible),
x(x), x(x),
y(y), y(y),
width(width), width(width),
height(height) { height(height) {
} }
bool GuiElement::pointInside( int x, int y ) { bool GuiElement::pointInside( int x, int y ) {
if(x >= this->x && x < this->x + this->width) { if(x >= this->x && x < this->x + this->width) {
if(y >= this->y && y < this->y + this->height) { if(y >= this->y && y < this->y + this->height) {
return true; return true;
} }
} }
return false; return false;
} }

View File

@@ -1,34 +1,32 @@
#ifndef NET_MINECRAFT_CLIENT_GUI__GuiElement_H__ #pragma once
#define NET_MINECRAFT_CLIENT_GUI__GuiElement_H__ #include "client/gui/GuiComponent.hpp"
#include "../GuiComponent.h"
class Tesselator;
class Tesselator; class Minecraft;
class Minecraft;
class GuiElement : public GuiComponent {
class GuiElement : public GuiComponent { public:
public: GuiElement(bool active=false, bool visible=true, int x = 0, int y = 0, int width=24, int height=24);
GuiElement(bool active=false, bool visible=true, int x = 0, int y = 0, int width=24, int height=24); virtual ~GuiElement() {}
virtual ~GuiElement() {}
virtual void tick(Minecraft* minecraft) {}
virtual void tick(Minecraft* minecraft) {} virtual void render(Minecraft* minecraft, int xm, int ym) { }
virtual void render(Minecraft* minecraft, int xm, int ym) { } virtual void setupPositions() {}
virtual void setupPositions() {}
virtual void mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum) {}
virtual void mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum) {} virtual void mouseReleased(Minecraft* minecraft, int x, int y, int buttonNum) {}
virtual void mouseReleased(Minecraft* minecraft, int x, int y, int buttonNum) {} virtual void keyPressed(Minecraft* minecraft, int key) {}
virtual void keyPressed(Minecraft* minecraft, int key) {} virtual void charPressed(Minecraft* minecraft, char key) {}
virtual void charPressed(Minecraft* minecraft, char key) {}
virtual bool pointInside(int x, int y);
virtual bool pointInside(int x, int y);
void setVisible(bool visible);
void setVisible(bool visible);
bool active;
bool active; bool visible;
bool visible; int x;
int x; int y;
int y; int width;
int width; int height;
int height; };
};
#endif /*NET_MINECRAFT_CLIENT_GUI__GuiElement_H__*/

View File

@@ -1,66 +1,66 @@
#include "GuiElementContainer.h" #include "GuiElementContainer.hpp"
#include <algorithm> #include <algorithm>
GuiElementContainer::GuiElementContainer( bool active/*=false*/, bool visible/*=true*/, int x /*= 0*/, int y /*= 0*/, int width/*=24*/, int height/*=24*/ ) 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) { : GuiElement(active, visible, x, y, width, height) {
} }
GuiElementContainer::~GuiElementContainer() { GuiElementContainer::~GuiElementContainer() {
while(!children.empty()) { while(!children.empty()) {
GuiElement* element = children.back(); GuiElement* element = children.back();
children.pop_back(); children.pop_back();
delete element; delete element;
} }
} }
void GuiElementContainer::render( Minecraft* minecraft, int xm, int ym ) { void GuiElementContainer::render( Minecraft* minecraft, int xm, int ym ) {
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) { for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
(*it)->render(minecraft, xm, ym); (*it)->render(minecraft, xm, ym);
} }
} }
void GuiElementContainer::setupPositions() { void GuiElementContainer::setupPositions() {
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) { for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
(*it)->setupPositions(); (*it)->setupPositions();
} }
} }
void GuiElementContainer::addChild( GuiElement* element ) { void GuiElementContainer::addChild( GuiElement* element ) {
children.push_back(element); children.push_back(element);
} }
void GuiElementContainer::removeChild( GuiElement* element ) { void GuiElementContainer::removeChild( GuiElement* element ) {
std::vector<GuiElement*>::iterator it = std::find(children.begin(), children.end(), element); std::vector<GuiElement*>::iterator it = std::find(children.begin(), children.end(), element);
if(it != children.end()) if(it != children.end())
children.erase(it); children.erase(it);
} }
void GuiElementContainer::tick( Minecraft* minecraft ) { void GuiElementContainer::tick( Minecraft* minecraft ) {
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) { for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
(*it)->tick(minecraft); (*it)->tick(minecraft);
} }
} }
void GuiElementContainer::mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ) { void GuiElementContainer::mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ) {
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) { for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
(*it)->mouseClicked(minecraft, x, y, buttonNum); (*it)->mouseClicked(minecraft, x, y, buttonNum);
} }
} }
void GuiElementContainer::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) { void GuiElementContainer::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) {
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) { for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
(*it)->mouseReleased(minecraft, x, y, buttonNum); (*it)->mouseReleased(minecraft, x, y, buttonNum);
} }
} }
void GuiElementContainer::keyPressed(Minecraft* minecraft, int key) { void GuiElementContainer::keyPressed(Minecraft* minecraft, int key) {
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) { for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
(*it)->keyPressed(minecraft, key); (*it)->keyPressed(minecraft, key);
} }
} }
void GuiElementContainer::charPressed(Minecraft* minecraft, char key) { void GuiElementContainer::charPressed(Minecraft* minecraft, char key) {
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) { for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
(*it)->charPressed(minecraft, key); (*it)->charPressed(minecraft, key);
} }
} }

View File

@@ -1,28 +1,26 @@
#ifndef NET_MINECRAFT_CLIENT_GUI__GuiElementContainer_H__ #pragma once
#define NET_MINECRAFT_CLIENT_GUI__GuiElementContainer_H__ #include "GuiElement.hpp"
#include "GuiElement.h" #include <vector>
#include <vector> class Tesselator;
class Tesselator; class Minecraft;
class Minecraft;
class GuiElementContainer : public GuiElement {
class GuiElementContainer : public GuiElement { public:
public: GuiElementContainer(bool active=false, bool visible=true, int x = 0, int y = 0, int width=24, int height=24);
GuiElementContainer(bool active=false, bool visible=true, int x = 0, int y = 0, int width=24, int height=24); virtual ~GuiElementContainer();
virtual ~GuiElementContainer(); virtual void render(Minecraft* minecraft, int xm, int ym);
virtual void render(Minecraft* minecraft, int xm, int ym); virtual void setupPositions();
virtual void setupPositions(); virtual void addChild(GuiElement* element);
virtual void addChild(GuiElement* element); virtual void removeChild(GuiElement* element);
virtual void removeChild(GuiElement* element);
virtual void tick( Minecraft* minecraft );
virtual void tick( Minecraft* minecraft );
virtual void mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum );
virtual void mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ); virtual void mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum );
virtual void mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ); virtual void keyPressed(Minecraft* minecraft, int key);
virtual void keyPressed(Minecraft* minecraft, int key); virtual void charPressed(Minecraft* minecraft, char key);
virtual void charPressed(Minecraft* minecraft, char key);
protected:
protected: std::vector<GuiElement*> children;
std::vector<GuiElement*> children; };
};
#endif /*NET_MINECRAFT_CLIENT_GUI__GuiElementContainer_H__*/

View File

@@ -1,135 +1,135 @@
#include "ImageButton.h" #include "ImageButton.hpp"
#include "../../renderer/Tesselator.h" #include "client/renderer/Tesselator.hpp"
#include "../../Minecraft.h" #include "client/Minecraft.hpp"
#include "../../../platform/log.h" #include "platform/log.hpp"
#include "../../../util/Mth.h" #include "util/Mth.hpp"
#include "../../renderer/Textures.h" #include "client/renderer/Textures.hpp"
#include <client/Option.h> #include <client/Option.hpp>
ImageButton::ImageButton(int id, const std::string& msg) ImageButton::ImageButton(int id, const std::string& msg)
: super(id, msg) : super(id, msg)
{ {
setupDefault(); setupDefault();
} }
ImageButton::ImageButton(int id, const std::string& msg, const ImageDef& imagedef) ImageButton::ImageButton(int id, const std::string& msg, const ImageDef& imagedef)
: super(id, msg), : super(id, msg),
_imageDef(imagedef) _imageDef(imagedef)
{ {
setupDefault(); setupDefault();
} }
void ImageButton::setupDefault() { void ImageButton::setupDefault() {
width = 48; width = 48;
height = 48; height = 48;
scaleWhenPressed = true; scaleWhenPressed = true;
} }
void ImageButton::setImageDef(const ImageDef& imageDef, bool setButtonSize) { void ImageButton::setImageDef(const ImageDef& imageDef, bool setButtonSize) {
_imageDef = imageDef; _imageDef = imageDef;
if (setButtonSize) { if (setButtonSize) {
width = (int)_imageDef.width; width = (int)_imageDef.width;
height = (int)_imageDef.height; height = (int)_imageDef.height;
} }
} }
void ImageButton::render(Minecraft* minecraft, int xm, int ym) { void ImageButton::render(Minecraft* minecraft, int xm, int ym) {
if (!visible) return; if (!visible) return;
Font* font = minecraft->font; Font* font = minecraft->font;
//minecraft->textures->loadAndBindTexture("gui/gui.png"); //minecraft->textures->loadAndBindTexture("gui/gui.png");
glColor4f2(1, 1, 1, 1); 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 hovered = active && (minecraft->useTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : isInside(xm, ym));
bool IsSecondImage = isSecondImage(hovered); 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); //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); //int yImage = getYImage(hovered || selected);
//blit(x, y, 0, 46 + yImage * 20, w / 2, h, 0, 20); //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); //blit(x + w / 2, y, 200 - w / 2, 46 + yImage * 20, w / 2, h, 0, 20);
renderBg(minecraft, xm, ym); renderBg(minecraft, xm, ym);
TextureId texId = (_imageDef.name.length() > 0)? minecraft->textures->loadAndBindTexture(_imageDef.name) : Textures::InvalidId; TextureId texId = (_imageDef.name.length() > 0)? minecraft->textures->loadAndBindTexture(_imageDef.name) : Textures::InvalidId;
if ( Textures::isTextureIdValid(texId) ) { if ( Textures::isTextureIdValid(texId) ) {
const ImageDef& d = _imageDef; const ImageDef& d = _imageDef;
Tesselator& t = Tesselator::instance; Tesselator& t = Tesselator::instance;
t.begin(); t.begin();
if (!active) t.color(0xff808080); if (!active) t.color(0xff808080);
//else if (hovered||selected) t.color(0xffffffff); //else if (hovered||selected) t.color(0xffffffff);
//else t.color(0xffe0e0e0); //else t.color(0xffe0e0e0);
else t.color(0xffffffff); else t.color(0xffffffff);
float hx = ((float) d.width) * 0.5f; float hx = ((float) d.width) * 0.5f;
float hy = ((float) d.height) * 0.5f; float hy = ((float) d.height) * 0.5f;
const float cx = ((float)x+d.x) + hx; const float cx = ((float)x+d.x) + hx;
const float cy = ((float)y+d.y) + hy; const float cy = ((float)y+d.y) + hy;
if (scaleWhenPressed && hovered) { if (scaleWhenPressed && hovered) {
hx *= 0.95f; hx *= 0.95f;
hy *= 0.95f; hy *= 0.95f;
} }
const IntRectangle* src = _imageDef.getSrc(); const IntRectangle* src = _imageDef.getSrc();
if (src) { if (src) {
const TextureData* d = minecraft->textures->getTemporaryTextureData(texId); const TextureData* d = minecraft->textures->getTemporaryTextureData(texId);
if (d != NULL) { if (d != NULL) {
float u0 = (src->x+(IsSecondImage?src->w:0)) / (float)d->w; 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 u1 = (src->x+(IsSecondImage?2*src->w:src->w)) / (float)d->w;
float v0 = src->y / (float)d->h; float v0 = src->y / (float)d->h;
float v1 = (src->y+src->h) / (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, v0);
t.vertexUV(cx-hx, cy+hy, blitOffset, u0, v1); 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, v1);
t.vertexUV(cx+hx, cy-hy, blitOffset, u1, v0); t.vertexUV(cx+hx, cy-hy, blitOffset, u1, v0);
} }
} else { } else {
t.vertexUV(cx-hx, cy-hy, blitOffset, 0, 0); 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, 0, 1);
t.vertexUV(cx+hx, cy+hy, blitOffset, 1, 1); t.vertexUV(cx+hx, cy+hy, blitOffset, 1, 1);
t.vertexUV(cx+hx, cy-hy, blitOffset, 1, 0); t.vertexUV(cx+hx, cy-hy, blitOffset, 1, 0);
} }
t.draw(); t.draw();
} }
//blit(0, 0, 0, 0, 64, 64, 256, 256); //blit(0, 0, 0, 0, 64, 64, 256, 256);
//LOGI("%d %d\n", x+d.x, x+d.x+d.w); //LOGI("%d %d\n", x+d.x, x+d.x+d.w);
if (!active) { if (!active) {
drawCenteredString(font, msg, x + width / 2, y + 16/*(h - 16)*/, 0xffa0a0a0); drawCenteredString(font, msg, x + width / 2, y + 16/*(h - 16)*/, 0xffa0a0a0);
} else { } else {
if (hovered || selected) { if (hovered || selected) {
drawCenteredString(font, msg, x + width / 2, y + 17/*(h - 16)*/, 0xffffa0); drawCenteredString(font, msg, x + width / 2, y + 17/*(h - 16)*/, 0xffffa0);
} else { } else {
drawCenteredString(font, msg, x + width / 2, y + 16/*(h - 48)*/, 0xe0e0e0); drawCenteredString(font, msg, x + width / 2, y + 16/*(h - 48)*/, 0xe0e0e0);
} }
} }
} }
// //
// A toggleable Button // A toggleable Button
// //
OptionButton::OptionButton(OptionId option) : m_optId(option), super(ButtonId, "") {} OptionButton::OptionButton(OptionId option) : m_optId(option), super(ButtonId, "") {}
void OptionButton::toggle(Options* options) { void OptionButton::toggle(Options* options) {
options->toggle(m_optId); options->toggle(m_optId);
// Update graphics here // Update graphics here
updateImage(options); updateImage(options);
} }
void OptionButton::updateImage(Options* options) { void OptionButton::updateImage(Options* options) {
_secondImage = options->getBooleanValue(m_optId); _secondImage = options->getBooleanValue(m_optId);
} }
void OptionButton::mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ) { void OptionButton::mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ) {
if(buttonNum == MouseAction::ACTION_LEFT) { if(buttonNum == MouseAction::ACTION_LEFT) {
if(clicked(minecraft, x, y)) { if(clicked(minecraft, x, y)) {
toggle(&minecraft->options); toggle(&minecraft->options);
} }
} }
} }

View File

@@ -1,97 +1,95 @@
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__ImageButton_H__ #pragma once
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__ImageButton_H__
#include "Button.hpp"
#include "Button.h"
typedef struct IntRectangle {
typedef struct IntRectangle { IntRectangle()
IntRectangle() : x(0),
: x(0), y(0),
y(0), w(1),
w(1), h(1)
h(1) {}
{} IntRectangle(int x, int y, int w, int h)
IntRectangle(int x, int y, int w, int h) : x(x),
: x(x), y(y),
y(y), w(w),
w(w), h(h)
h(h) {}
{}
int x, y;
int x, y; int w, h;
int w, h; } IntRectangle;
} IntRectangle;
typedef struct ImageDef {
typedef struct ImageDef { ImageDef()
ImageDef() : hasSrc(false),
: hasSrc(false), x(0),
x(0), y(0),
y(0), width(16),
width(16), height(16)
height(16) {}
{}
std::string name;
std::string name; int x;
int x; int y;
int y; float width;
float width; float height;
float height;
ImageDef& setSrc(const IntRectangle& srcRect) {
ImageDef& setSrc(const IntRectangle& srcRect) { hasSrc = true;
hasSrc = true; src = srcRect;
src = srcRect; return *this;
return *this; }
} IntRectangle* getSrc() {
IntRectangle* getSrc() { return hasSrc? &src : NULL;
return hasSrc? &src : NULL; }
} protected:
protected: IntRectangle src;
IntRectangle src; bool hasSrc;
bool hasSrc; } ImageDef;
} ImageDef;
class ImageButton: public Button
class ImageButton: public Button {
{ typedef Button super;
typedef Button super; public:
public: ImageButton(int id, const std::string& msg);
ImageButton(int id, const std::string& msg); ImageButton(int id, const std::string& msg, const ImageDef& imageDef);
ImageButton(int id, const std::string& msg, const ImageDef& imageDef); void setImageDef(const ImageDef& imageDef, bool setButtonSize);
void setImageDef(const ImageDef& imageDef, bool setButtonSize);
void render(Minecraft* minecraft, int xm, int ym);
void render(Minecraft* minecraft, int xm, int ym); void renderBg(Minecraft* minecraft, int xm, int ym) {}
void renderBg(Minecraft* minecraft, int xm, int ym) {}
protected:
protected: virtual void setupDefault();
virtual void setupDefault(); virtual bool isSecondImage(bool hovered) { return hovered; }
virtual bool isSecondImage(bool hovered) { return hovered; }
ImageDef _imageDef;
ImageDef _imageDef; public:
public: bool scaleWhenPressed;
bool scaleWhenPressed; };
};
//
// // A toggleable Button
// A toggleable Button //
// class OptionButton: public ImageButton
class OptionButton: public ImageButton {
{ typedef ImageButton super;
typedef ImageButton super; public:
public: OptionButton(OptionId optId);
OptionButton(OptionId optId);
void toggle(Options* options);
void toggle(Options* options); void updateImage(Options* options);
void updateImage(Options* options);
static const int ButtonId = 9999999;
static const int ButtonId = 9999999; protected:
protected: bool isSecondImage(bool hovered) { return _secondImage; }
bool isSecondImage(bool hovered) { return _secondImage; }
virtual void mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum );
virtual void mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum );
private:
private: OptionId m_optId;
OptionId m_optId; bool _secondImage;
bool _secondImage; };
};
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__ImageButton_H__*/

View File

@@ -1,206 +1,206 @@
#include "InventoryPane.h" #include "InventoryPane.hpp"
#include "../Gui.h" #include "client/gui/Gui.hpp"
#include "../../Minecraft.h" #include "client/Minecraft.hpp"
#include "../../player/input/touchscreen/TouchAreaModel.h" #include "client/player/input/touchscreen/TouchAreaModel.hpp"
#include "../../renderer/entity/ItemRenderer.h" #include "client/renderer/entity/ItemRenderer.hpp"
#include "../../renderer/Tesselator.h" #include "client/renderer/Tesselator.hpp"
#include "../../renderer/Textures.h" #include "client/renderer/Textures.hpp"
#include "../../../world/item/ItemInstance.h" #include "world/item/ItemInstance.hpp"
#include "../../../world/entity/player/Inventory.h" #include "world/entity/player/Inventory.hpp"
namespace Touch { namespace Touch {
static const int By = 6; // Border Frame height 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) InventoryPane::InventoryPane( IInventoryPaneCallback* screen, Minecraft* mc, const IntRectangle& rect, int paneWidth, float clickMarginH, int numItems, int itemSize, int itemBorderSize)
: screen(screen), : screen(screen),
mc(mc), mc(mc),
paneWidth(paneWidth), paneWidth(paneWidth),
rect(rect), rect(rect),
super( super(
SF_LockX|/*SF_Scissor|*/SF_ShowScrollbar|SF_NoHoldSelect, SF_LockX|/*SF_Scissor|*/SF_ShowScrollbar|SF_NoHoldSelect,
rect, // Pane rect rect, // Pane rect
IntRectangle(0, 0, itemSize, itemSize), // Item rect IntRectangle(0, 0, itemSize, itemSize), // Item rect
0, numItems, Gui::GuiScale), 0, numItems, Gui::GuiScale),
BorderPixels(itemBorderSize), BorderPixels(itemBorderSize),
lastItemIndex(-1), lastItemIndex(-1),
lastItemTicks(-1), lastItemTicks(-1),
fillMarginX(2), fillMarginX(2),
fillMarginY(4), fillMarginY(4),
markerType(1), markerType(1),
markerIndex(-1), markerIndex(-1),
markerShare(0), markerShare(0),
renderDecorations(true) renderDecorations(true)
{ {
_clickArea = new RectangleArea(0, 0, 0, 0); _clickArea = new RectangleArea(0, 0, 0, 0);
area._x0 = rect.x - clickMarginH; area._x0 = rect.x - clickMarginH;
area._x1 = rect.x + rect.w + clickMarginH; area._x1 = rect.x + rect.w + clickMarginH;
area._y0 -= By; area._y0 -= By;
area._y1 += By; area._y1 += By;
/* /*
const int left = bbox.x + (bbox.w - paneWidth) / 2; const int left = bbox.x + (bbox.w - paneWidth) / 2;
bg.x = left; bg.x = left;
bg.w = left + paneWidth; // @note: read as x1, not width bg.w = left + paneWidth; // @note: read as x1, not width
bg.y = bbox.y - fillMarginY; bg.y = bbox.y - fillMarginY;
bg.h = bbox.y + bbox.h + fillMarginY; // @note: read as y1, not width bg.h = bbox.y + bbox.h + fillMarginY; // @note: read as y1, not width
*/ */
} }
InventoryPane::~InventoryPane() { InventoryPane::~InventoryPane() {
delete _clickArea; delete _clickArea;
} }
void InventoryPane::renderBatch( std::vector<GridItem>& items, float alpha ) void InventoryPane::renderBatch( std::vector<GridItem>& items, float alpha )
{ {
//fill(bg.x, bg.y, bg.w, bg.h, 0xff333333); //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((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); //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); glEnable2(GL_BLEND);
glDisable2(GL_ALPHA_TEST); glDisable2(GL_ALPHA_TEST);
std::vector<const ItemInstance*> inventoryItems = screen->getItems(this); std::vector<const ItemInstance*> inventoryItems = screen->getItems(this);
glEnable2(GL_SCISSOR_TEST); glEnable2(GL_SCISSOR_TEST);
GLuint x = (GLuint)(screenScale * bbox.x); GLuint x = (GLuint)(screenScale * bbox.x);
GLuint y = mc->height - (GLuint)(screenScale * (bbox.y + bbox.h)); GLuint y = mc->height - (GLuint)(screenScale * (bbox.y + bbox.h));
GLuint w = (GLuint)(screenScale * bbox.w); GLuint w = (GLuint)(screenScale * bbox.w);
GLuint h = (GLuint)(screenScale * bbox.h); GLuint h = (GLuint)(screenScale * bbox.h);
glScissor(x, y, w, h); glScissor(x, y, w, h);
Tesselator& t = Tesselator::instance; Tesselator& t = Tesselator::instance;
t.beginOverride(); t.beginOverride();
t.colorABGR(0xffffffff); t.colorABGR(0xffffffff);
for (unsigned int i = 0; i < items.size(); ++i) { for (unsigned int i = 0; i < items.size(); ++i) {
GridItem& item = items[i]; GridItem& item = items[i];
blit(item.xf, item.yf, 200, 46, (float)itemBbox.w, (float)itemBbox.h, 16, 16); blit(item.xf, item.yf, 200, 46, (float)itemBbox.w, (float)itemBbox.h, 16, 16);
} }
mc->textures->loadAndBindTexture("gui/gui.png"); mc->textures->loadAndBindTexture("gui/gui.png");
t.endOverrideAndDraw(); t.endOverrideAndDraw();
GridItem* marked = NULL; GridItem* marked = NULL;
float mxx, myy; float mxx, myy;
t.beginOverride(); t.beginOverride();
for (unsigned int i = 0; i < items.size(); ++i) { for (unsigned int i = 0; i < items.size(); ++i) {
GridItem& item = items[i]; GridItem& item = items[i];
int j = item.id; int j = item.id;
const ItemInstance* citem = inventoryItems[j]; const ItemInstance* citem = inventoryItems[j];
if (!citem) continue; if (!citem) continue;
bool allowed = true; bool allowed = true;
t.enableColor(); t.enableColor();
//#ifdef DEMO_MODE //@huge @attn //#ifdef DEMO_MODE //@huge @attn
if (!screen->isAllowed(j)) { allowed = false; t.color( 64, 64, 64); } if (!screen->isAllowed(j)) { allowed = false; t.color( 64, 64, 64); }
else else
//#endif //#endif
if (lastItemTicks > 0 && lastItemIndex == j) { if (lastItemTicks > 0 && lastItemIndex == j) {
int gv = 255 - lastItemTicks * 15; int gv = 255 - lastItemTicks * 15;
t.color(gv, gv, gv, (allowed && citem->count <= 0)?0x60:0xff); t.color(gv, gv, gv, (allowed && citem->count <= 0)?0x60:0xff);
} else { } else {
t.color(255, 255, 255, (allowed && citem->count <= 0)?0x60:0xff); t.color(255, 255, 255, (allowed && citem->count <= 0)?0x60:0xff);
} }
t.noColor(); t.noColor();
float xx = Gui::floorAlignToScreenPixel(item.xf + BorderPixels + 4); float xx = Gui::floorAlignToScreenPixel(item.xf + BorderPixels + 4);
float yy = Gui::floorAlignToScreenPixel(item.yf + BorderPixels + 4); float yy = Gui::floorAlignToScreenPixel(item.yf + BorderPixels + 4);
ItemRenderer::renderGuiItem(NULL, mc->textures, citem, xx, yy, 16, 16, false); ItemRenderer::renderGuiItem(NULL, mc->textures, citem, xx, yy, 16, 16, false);
if (j == markerIndex && markerShare >= 0) if (j == markerIndex && markerShare >= 0)
marked = &item, mxx = xx, myy = yy; marked = &item, mxx = xx, myy = yy;
} }
t.endOverrideAndDraw(); t.endOverrideAndDraw();
if (marked) { if (marked) {
glDisable2(GL_TEXTURE_2D); glDisable2(GL_TEXTURE_2D);
const float yy0 = myy - 5.0f; const float yy0 = myy - 5.0f;
const float yy1 = yy0 + 2; const float yy1 = yy0 + 2;
fill(mxx, yy0, mxx + 16.0f, yy1, 0xff606060); fill(mxx, yy0, mxx + 16.0f, yy1, 0xff606060);
fill(mxx, yy0, mxx + markerShare * 16.0f, yy1, markerType==1?0xff00ff00:0xff476543); fill(mxx, yy0, mxx + markerShare * 16.0f, yy1, markerType==1?0xff00ff00:0xff476543);
glEnable2(GL_BLEND); glEnable2(GL_BLEND);
glEnable2(GL_TEXTURE_2D); glEnable2(GL_TEXTURE_2D);
} }
if (!mc->isCreativeMode()) { if (!mc->isCreativeMode()) {
const float ikText = Gui::InvGuiScale + Gui::InvGuiScale; const float ikText = Gui::InvGuiScale + Gui::InvGuiScale;
const float kText = 0.5f * Gui::GuiScale; const float kText = 0.5f * Gui::GuiScale;
t.beginOverride(); t.beginOverride();
t.scale2d(ikText, ikText); t.scale2d(ikText, ikText);
for (unsigned int i = 0; i < items.size(); ++i) { for (unsigned int i = 0; i < items.size(); ++i) {
GridItem& item = items[i]; GridItem& item = items[i];
const ItemInstance* citem = inventoryItems[item.id]; const ItemInstance* citem = inventoryItems[item.id];
if (!citem) continue; if (!citem) continue;
char buf[64] = {0}; char buf[64] = {0};
/*int c = */ Gui::itemCountItoa(buf, citem->count); /*int c = */ Gui::itemCountItoa(buf, citem->count);
float tx = Gui::floorAlignToScreenPixel(kText * (item.xf + BorderPixels + 3)); float tx = Gui::floorAlignToScreenPixel(kText * (item.xf + BorderPixels + 3));
float ty = Gui::floorAlignToScreenPixel(kText * (item.yf + BorderPixels + 3)); float ty = Gui::floorAlignToScreenPixel(kText * (item.yf + BorderPixels + 3));
mc->gui.renderSlotText(citem, tx, ty, true, true); mc->gui.renderSlotText(citem, tx, ty, true, true);
} }
t.resetScale(); t.resetScale();
glEnable2(GL_BLEND); glEnable2(GL_BLEND);
t.endOverrideAndDraw(); t.endOverrideAndDraw();
} }
if (renderDecorations) { if (renderDecorations) {
t.beginOverride(); t.beginOverride();
for (unsigned int i = 0; i < items.size(); ++i) { for (unsigned int i = 0; i < items.size(); ++i) {
GridItem& item = items[i]; GridItem& item = items[i];
const ItemInstance* citem = inventoryItems[item.id]; const ItemInstance* citem = inventoryItems[item.id];
if (!citem || citem->isNull()) continue; if (!citem || citem->isNull()) continue;
if (citem->isDamaged()) { if (citem->isDamaged()) {
ItemRenderer::renderGuiItemDecorations(citem, item.xf + 8, item.yf + 12); ItemRenderer::renderGuiItemDecorations(citem, item.xf + 8, item.yf + 12);
} }
} }
glDisable2(GL_TEXTURE_2D); glDisable2(GL_TEXTURE_2D);
t.endOverrideAndDraw(); t.endOverrideAndDraw();
glEnable2(GL_TEXTURE_2D); glEnable2(GL_TEXTURE_2D);
} }
glDisable2(GL_SCISSOR_TEST); 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.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(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, 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); fillGradient(bg.x - fillMarginX, bbox.y + bbox.h - 20, bg.w + fillMarginX, bbox.y + bbox.h, 0x00000000, 0x99000000);
drawScrollBar(hScroll); drawScrollBar(hScroll);
drawScrollBar(vScroll); drawScrollBar(vScroll);
} }
bool InventoryPane::onSelect( int gridId, bool selected ) bool InventoryPane::onSelect( int gridId, bool selected )
{ {
//screen->onItemSelected(gridId); //screen->onItemSelected(gridId);
if (screen->isAllowed(gridId)) if (screen->isAllowed(gridId))
if (screen->addItem(this, gridId)) { if (screen->addItem(this, gridId)) {
lastItemIndex = gridId; lastItemIndex = gridId;
lastItemTicks = 7; lastItemTicks = 7;
} }
return false; return false;
} }
void InventoryPane::drawScrollBar( ScrollBar& sb ) { void InventoryPane::drawScrollBar( ScrollBar& sb ) {
if (sb.alpha <= 0) if (sb.alpha <= 0)
return; return;
const int color = ((int)(255.0f * sb.alpha) << 24) | 0xaaaaaa; const int color = ((int)(255.0f * sb.alpha) << 24) | 0xaaaaaa;
const float xx = (float)(bbox.x + bbox.w); const float xx = (float)(bbox.x + bbox.w);
fill(xx - sb.w, sb.y, xx, sb.y + sb.h, color); fill(xx - sb.w, sb.y, xx, sb.y + sb.h, color);
} }
void InventoryPane::tick() void InventoryPane::tick()
{ {
--lastItemTicks; --lastItemTicks;
super::tick(); super::tick();
} }
void InventoryPane::setRenderDecorations( bool value ) { void InventoryPane::setRenderDecorations( bool value ) {
renderDecorations = value; renderDecorations = value;
} }
} }

View File

@@ -1,62 +1,60 @@
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__InventoryPane_H__ #pragma once
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__InventoryPane_H__
#include "ScrollingPane.hpp"
#include "ScrollingPane.h" #include "ImageButton.hpp"
#include "ImageButton.h"
class Minecraft;
class Minecraft; class ItemInstance;
class ItemInstance; class Font;
class Font; class IArea;
class IArea;
namespace Touch {
namespace Touch {
class IInventoryPaneCallback;
class IInventoryPaneCallback;
class InventoryPane: public ScrollingPane
class InventoryPane: public ScrollingPane {
{ typedef ScrollingPane super;
typedef ScrollingPane super; public:
public: InventoryPane(IInventoryPaneCallback* screen, Minecraft* mc, const IntRectangle& rect, int paneWidth, float clickMarginH, int numItems, int itemSize, int itemBorderSize);
InventoryPane(IInventoryPaneCallback* screen, Minecraft* mc, const IntRectangle& rect, int paneWidth, float clickMarginH, int numItems, int itemSize, int itemBorderSize); ~InventoryPane();
~InventoryPane();
void tick();
void tick(); void renderBatch( std::vector<GridItem>& item, float alpha );
void renderBatch( std::vector<GridItem>& item, float alpha ); bool onSelect( int gridId, bool selected );
bool onSelect( int gridId, bool selected ); void drawScrollBar( ScrollBar& hScroll );
void drawScrollBar( ScrollBar& hScroll );
void setRenderDecorations(bool value);
void setRenderDecorations(bool value);
IntRectangle rect;
IntRectangle rect; int paneWidth;
int paneWidth; IArea* _clickArea;
IArea* _clickArea; IInventoryPaneCallback* screen;
IInventoryPaneCallback* screen; Minecraft* mc;
Minecraft* mc;
int fillMarginX;
int fillMarginX; int fillMarginY;
int fillMarginY;
int markerType;
int markerType; int markerIndex;
int markerIndex; float markerShare;
float markerShare; private:
private: int lastItemIndex;
int lastItemIndex; int lastItemTicks;
int lastItemTicks; int BorderPixels;
int BorderPixels; bool renderDecorations;
bool renderDecorations;
IntRectangle bg;
IntRectangle bg; };
};
class IInventoryPaneCallback
class IInventoryPaneCallback {
{ public:
public: virtual ~IInventoryPaneCallback() {}
virtual ~IInventoryPaneCallback() {} virtual bool addItem(const InventoryPane* forPane, int index) = 0;
virtual bool addItem(const InventoryPane* forPane, int index) = 0; virtual bool isAllowed( int slot ) = 0;
virtual bool isAllowed( int slot ) = 0; virtual std::vector<const ItemInstance*> getItems(const InventoryPane* forPane) = 0;
virtual std::vector<const ItemInstance*> getItems(const InventoryPane* forPane) = 0; };
};
}
}
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__InventoryPane_H__*/

View File

@@ -1,148 +1,148 @@
#include "ItemPane.h" #include "ItemPane.hpp"
#include "../Gui.h" #include "client/gui/Gui.hpp"
#include "../../renderer/gles.h" #include "client/renderer/gles.hpp"
#include "../../renderer/Tesselator.h" #include "client/renderer/Tesselator.hpp"
#include "NinePatch.h" #include "NinePatch.hpp"
#include "../../renderer/entity/ItemRenderer.h" #include "client/renderer/entity/ItemRenderer.hpp"
const int rgbActive = 0xfff0f0f0; const int rgbActive = 0xfff0f0f0;
const int rgbInactive = 0xc0635558; const int rgbInactive = 0xc0635558;
const int rgbInactiveShadow = 0xc0aaaaaa; const int rgbInactiveShadow = 0xc0aaaaaa;
ItemPane::ItemPane( IItemPaneCallback* screen, ItemPane::ItemPane( IItemPaneCallback* screen,
Textures* textures, Textures* textures,
const IntRectangle& rect, const IntRectangle& rect,
int numItems, int numItems,
int guiHeight, int guiHeight,
int physicalScreenHeight, int physicalScreenHeight,
bool isVertical /*= true*/) bool isVertical /*= true*/)
: super( : super(
(isVertical?SF_LockX:SF_LockY)/*|SF_Scissor*/|SF_ShowScrollbar, (isVertical?SF_LockX:SF_LockY)/*|SF_Scissor*/|SF_ShowScrollbar,
rect, // Pane rect rect, // Pane rect
isVertical?IntRectangle(0, 0, rect.w, 22) // Item rect if vertical isVertical?IntRectangle(0, 0, rect.w, 22) // Item rect if vertical
:IntRectangle(0, 0, 32, rect.h), // Item rect if horizontal :IntRectangle(0, 0, 32, rect.h), // Item rect if horizontal
isVertical?1:numItems, numItems, Gui::GuiScale), isVertical?1:numItems, numItems, Gui::GuiScale),
screen(screen), screen(screen),
textures(textures), textures(textures),
physicalScreenHeight(physicalScreenHeight), physicalScreenHeight(physicalScreenHeight),
guiSlotItem(NULL), guiSlotItem(NULL),
guiSlotItemSelected(NULL), guiSlotItemSelected(NULL),
isVertical(isVertical) isVertical(isVertical)
{ {
// Expand the area to make it easier to scroll // Expand the area to make it easier to scroll
area._x0 -= 4; area._x0 -= 4;
area._x1 += 4; area._x1 += 4;
area._y0 = 0; area._y0 = 0;
area._y1 = (float)guiHeight; area._y1 = (float)guiHeight;
// GUI // GUI
NinePatchFactory builder(textures, "gui/spritesheet.png"); NinePatchFactory builder(textures, "gui/spritesheet.png");
guiSlotItem = builder.createSymmetrical(IntRectangle(20, 32, 8, 8), 2, 2); guiSlotItem = builder.createSymmetrical(IntRectangle(20, 32, 8, 8), 2, 2);
guiSlotItemSelected = builder.createSymmetrical(IntRectangle(28, 32, 8, 8), 2, 2); guiSlotItemSelected = builder.createSymmetrical(IntRectangle(28, 32, 8, 8), 2, 2);
guiSlotItem->setSize((float)rect.w + 4, 22); guiSlotItem->setSize((float)rect.w + 4, 22);
guiSlotItemSelected->setSize((float)rect.w + 4, 22); guiSlotItemSelected->setSize((float)rect.w + 4, 22);
} }
ItemPane::~ItemPane() { ItemPane::~ItemPane() {
delete guiSlotItem; delete guiSlotItem;
delete guiSlotItemSelected; delete guiSlotItemSelected;
} }
void ItemPane::renderBatch( std::vector<GridItem>& items, float alpha ) void ItemPane::renderBatch( std::vector<GridItem>& items, float alpha )
{ {
//fill(bbox.x, bbox.y, bbox.x + bbox.w, bbox.y + bbox.h, 0xff666666); //fill(bbox.x, bbox.y, bbox.x + bbox.w, bbox.y + bbox.h, 0xff666666);
const std::vector<CItem*>& cat = screen->getItems(this); const std::vector<CItem*>& cat = screen->getItems(this);
if (cat.empty()) return; if (cat.empty()) return;
glEnable2(GL_SCISSOR_TEST); glEnable2(GL_SCISSOR_TEST);
GLuint x = (GLuint)(screenScale * bbox.x); GLuint x = (GLuint)(screenScale * bbox.x);
GLuint y = physicalScreenHeight - (GLuint)(screenScale * (bbox.y + bbox.h)); GLuint y = physicalScreenHeight - (GLuint)(screenScale * (bbox.y + bbox.h));
GLuint w = (GLuint)(screenScale * bbox.w); GLuint w = (GLuint)(screenScale * bbox.w);
GLuint h = (GLuint)(screenScale * bbox.h); GLuint h = (GLuint)(screenScale * bbox.h);
glScissor(x, y, w, h); glScissor(x, y, w, h);
Tesselator& t = Tesselator::instance; Tesselator& t = Tesselator::instance;
t.beginOverride(); t.beginOverride();
for (unsigned int i = 0; i < items.size(); ++i) { for (unsigned int i = 0; i < items.size(); ++i) {
GridItem& item = items[i]; GridItem& item = items[i];
(item.selected? guiSlotItemSelected : guiSlotItem)->draw(t, Gui::floorAlignToScreenPixel(item.xf-1), Gui::floorAlignToScreenPixel(item.yf)); (item.selected? guiSlotItemSelected : guiSlotItem)->draw(t, Gui::floorAlignToScreenPixel(item.xf-1), Gui::floorAlignToScreenPixel(item.yf));
} }
t.endOverrideAndDraw(); t.endOverrideAndDraw();
t.beginOverride(); t.beginOverride();
for (unsigned int i = 0; i < items.size(); ++i) { for (unsigned int i = 0; i < items.size(); ++i) {
GridItem& item = items[i]; GridItem& item = items[i];
CItem* citem = cat[item.id]; CItem* citem = cat[item.id];
ItemRenderer::renderGuiItem(NULL, textures, &citem->item, ItemRenderer::renderGuiItem(NULL, textures, &citem->item,
Gui::floorAlignToScreenPixel(item.xf + itemBbox.w - 16), Gui::floorAlignToScreenPixel(item.xf + itemBbox.w - 16),
Gui::floorAlignToScreenPixel(2 + item.yf), 16, 16, false); Gui::floorAlignToScreenPixel(2 + item.yf), 16, 16, false);
} }
t.endOverrideAndDraw(); t.endOverrideAndDraw();
t.beginOverride(); t.beginOverride();
for (unsigned int i = 0; i < items.size(); ++i) { for (unsigned int i = 0; i < items.size(); ++i) {
GridItem& item = items[i]; GridItem& item = items[i];
CItem* citem = cat[item.id]; CItem* citem = cat[item.id];
char buf[64] = {0}; char buf[64] = {0};
int c = Gui::itemCountItoa(buf, citem->inventoryCount); int c = Gui::itemCountItoa(buf, citem->inventoryCount);
float xf = item.xf - 1; float xf = item.xf - 1;
if (citem->canCraft()) { if (citem->canCraft()) {
f->drawShadow(citem->text, f->drawShadow(citem->text,
Gui::floorAlignToScreenPixel(xf + 2), Gui::floorAlignToScreenPixel(xf + 2),
Gui::floorAlignToScreenPixel(item.yf + 6), rgbActive); Gui::floorAlignToScreenPixel(item.yf + 6), rgbActive);
t.scale2d(0.6667f, 0.6667f); t.scale2d(0.6667f, 0.6667f);
f->drawShadow(buf, f->drawShadow(buf,
Gui::floorAlignToScreenPixel(1.5f * (xf + itemBbox.w - c*4)), Gui::floorAlignToScreenPixel(1.5f * (xf + itemBbox.w - c*4)),
Gui::floorAlignToScreenPixel(1.5f * (item.yf + itemBbox.h - 8)), rgbActive); Gui::floorAlignToScreenPixel(1.5f * (item.yf + itemBbox.h - 8)), rgbActive);
t.resetScale(); t.resetScale();
} else { } else {
f->draw(citem->text, f->draw(citem->text,
Gui::floorAlignToScreenPixel(xf + 3), Gui::floorAlignToScreenPixel(xf + 3),
Gui::floorAlignToScreenPixel(item.yf + 7), rgbInactiveShadow); Gui::floorAlignToScreenPixel(item.yf + 7), rgbInactiveShadow);
f->draw(citem->text, f->draw(citem->text,
Gui::floorAlignToScreenPixel(xf + 2), Gui::floorAlignToScreenPixel(xf + 2),
Gui::floorAlignToScreenPixel(item.yf + 6), rgbInactive); Gui::floorAlignToScreenPixel(item.yf + 6), rgbInactive);
t.scale2d(0.6667f, 0.6667f); t.scale2d(0.6667f, 0.6667f);
f->draw(buf, f->draw(buf,
Gui::floorAlignToScreenPixel(1.5f * (xf + itemBbox.w - c*4)), Gui::floorAlignToScreenPixel(1.5f * (xf + itemBbox.w - c*4)),
Gui::floorAlignToScreenPixel(1.5f * (item.yf + itemBbox.h - 8)), rgbInactive); Gui::floorAlignToScreenPixel(1.5f * (item.yf + itemBbox.h - 8)), rgbInactive);
t.resetScale(); t.resetScale();
} }
} }
t.endOverrideAndDraw(); t.endOverrideAndDraw();
//fillGradient(bbox.x, bbox.y, bbox.x + bbox.w, 20, 0x00000000, 0x80ff0000) //fillGradient(bbox.x, bbox.y, bbox.x + bbox.w, 20, 0x00000000, 0x80ff0000)
if (isVertical) { if (isVertical) {
fillGradient(bbox.x, bbox.y, bbox.x + bbox.w, bbox.y + 28, 0xbb000000, 0x00000000); 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); fillGradient(bbox.x, bbox.y + bbox.h - 28, bbox.x + bbox.w, bbox.y + bbox.h, 0x00000000, 0xbb000000);//0xbb2A272B);
} else { } else {
fillHorizontalGradient(bbox.x, bbox.y, bbox.x + 28, bbox.y + bbox.h, 0xbb000000, 0x00000000); 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); 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); //LOGI("scroll: %f - %f, %f :: %f, %f\n", hScroll.alpha, hScroll.x, hScroll.y, hScroll.w, hScroll.h);
glDisable2(GL_SCISSOR_TEST); glDisable2(GL_SCISSOR_TEST);
drawScrollBar(hScroll); drawScrollBar(hScroll);
drawScrollBar(vScroll); drawScrollBar(vScroll);
} }
bool ItemPane::onSelect( int gridId, bool selected ) bool ItemPane::onSelect( int gridId, bool selected )
{ {
if (selected) if (selected)
screen->onItemSelected(this, gridId); screen->onItemSelected(this, gridId);
return selected; return selected;
} }
void ItemPane::drawScrollBar( ScrollBar& sb ) { void ItemPane::drawScrollBar( ScrollBar& sb ) {
if (sb.alpha <= 0) if (sb.alpha <= 0)
return; return;
int color = ((int)(255.0f * sb.alpha) << 24) | 0xffffff; 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); fill(2 + sb.x, sb.y, 2 + sb.x + sb.w, sb.y + sb.h, color);
} }

View File

@@ -1,95 +1,93 @@
#ifndef ITEMPANE_H__ #pragma once
#define ITEMPANE_H__
#include <string>
#include <string> #include <vector>
#include <vector> #include "ScrollingPane.hpp"
#include "ScrollingPane.h" #include "world/item/ItemInstance.hpp"
#include "../../../world/item/ItemInstance.h"
class Font;
class Font; class Textures;
class Textures; class NinePatchLayer;
class NinePatchLayer; class Recipe;
class Recipe; class ItemPane;
class ItemPane;
class CItem
class CItem {
{ public:
public: CItem(const ItemInstance& ins, Recipe* recipe, const std::string& text)
CItem(const ItemInstance& ins, Recipe* recipe, const std::string& text) : item(ins),
: item(ins), recipe(recipe),
recipe(recipe), text(text),
text(text), sortText(text),
sortText(text), //maxBuildCount(0),
//maxBuildCount(0), numBuilt(0),
numBuilt(0), inventoryCount(0),
inventoryCount(0), _canCraft(false)
_canCraft(false) {
{ }
}
typedef struct ReqItem {
typedef struct ReqItem { ReqItem() {}
ReqItem() {} ReqItem(const ItemInstance& needItem, int has)
ReqItem(const ItemInstance& needItem, int has) : item(needItem), has(has) {}
: item(needItem), has(has) {} ItemInstance item;
ItemInstance item; int has;
int has; bool enough() { return has >= item.count; }
bool enough() { return has >= item.count; } } ReqItem;
} ReqItem;
bool canCraft() {
bool canCraft() { return _canCraft;// || maxBuildCount > 0;
return _canCraft;// || maxBuildCount > 0; }
} void setCanCraft(bool status) {
void setCanCraft(bool status) { _canCraft = status;
_canCraft = status; }
}
ItemInstance item;
ItemInstance item; Recipe* recipe;
Recipe* recipe; std::string text;
std::string text; std::string sortText;
std::string sortText; //int maxBuildCount;
//int maxBuildCount; int numBuilt;
int numBuilt; int inventoryCount;
int inventoryCount; std::vector<ReqItem> neededItems;
std::vector<ReqItem> neededItems; private:
private: bool _canCraft;
bool _canCraft; };
};
class IItemPaneCallback
class IItemPaneCallback {
{ public:
public: virtual ~IItemPaneCallback() {}
virtual ~IItemPaneCallback() {} virtual void onItemSelected(const ItemPane* forPane, int index) = 0;
virtual void onItemSelected(const ItemPane* forPane, int index) = 0; virtual const std::vector<CItem*>& getItems(const ItemPane* forPane) = 0;
virtual const std::vector<CItem*>& getItems(const ItemPane* forPane) = 0; };
};
class ItemPane: public ScrollingPane
class ItemPane: public ScrollingPane {
{ typedef ScrollingPane super;
typedef ScrollingPane super; public:
public: ItemPane( IItemPaneCallback* screen,
ItemPane( IItemPaneCallback* screen, Textures* textures,
Textures* textures, const IntRectangle& rect,
const IntRectangle& rect, int numItems,
int numItems, int guiHeight,
int guiHeight, int physicalScreenHeight,
int physicalScreenHeight, bool isVertical = true);
bool isVertical = true); ~ItemPane();
~ItemPane();
void renderBatch( std::vector<GridItem>& item, float alpha );
void renderBatch( std::vector<GridItem>& item, float alpha ); bool onSelect( int gridId, bool selected );
bool onSelect( int gridId, bool selected ); void drawScrollBar( ScrollBar& hScroll );
void drawScrollBar( ScrollBar& hScroll ); //void setSize()
//void setSize()
Font* f;
Font* f; Textures* textures;
Textures* textures; IItemPaneCallback* screen;
IItemPaneCallback* screen;
int physicalScreenHeight; // Needed for glScissor
int physicalScreenHeight; // Needed for glScissor bool isVertical;
bool isVertical;
NinePatchLayer* guiSlotItem;
NinePatchLayer* guiSlotItem; NinePatchLayer* guiSlotItemSelected;
NinePatchLayer* guiSlotItemSelected; };
};
#endif /*ITEMPANE_H__*/

View File

@@ -1,5 +1,5 @@
#include "KeyOption.h" #include "KeyOption.hpp"
#include <client/Minecraft.h> #include <client/Minecraft.hpp>
KeyOption::KeyOption(Minecraft* minecraft, OptionId optId) KeyOption::KeyOption(Minecraft* minecraft, OptionId optId)
: Touch::TButton((int)optId, Keyboard::getKeyName(minecraft->options.getIntValue(optId))) {} : Touch::TButton((int)optId, Keyboard::getKeyName(minecraft->options.getIntValue(optId))) {}

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include "Button.h" #include "Button.hpp"
#include <client/Options.h> #include <client/Options.hpp>
class KeyOption : public Touch::TButton { class KeyOption : public Touch::TButton {
public: public:

View File

@@ -1,104 +1,104 @@
#include "LargeImageButton.h" #include "LargeImageButton.hpp"
#include "../../renderer/Tesselator.h" #include "client/renderer/Tesselator.hpp"
#include "../../Minecraft.h" #include "client/Minecraft.hpp"
#include "../../../util/Mth.h" #include "util/Mth.hpp"
#include "../../../platform/log.h" #include "platform/log.hpp"
#include "../../../util/Mth.h" #include "util/Mth.hpp"
#include "../../renderer/Textures.h" #include "client/renderer/Textures.hpp"
LargeImageButton::LargeImageButton(int id, const std::string& msg) LargeImageButton::LargeImageButton(int id, const std::string& msg)
: super(id, msg) : super(id, msg)
{ {
setupDefault(); setupDefault();
} }
LargeImageButton::LargeImageButton(int id, const std::string& msg, ImageDef& imagedef) LargeImageButton::LargeImageButton(int id, const std::string& msg, ImageDef& imagedef)
: super(id, msg) : super(id, msg)
{ {
_imageDef = imagedef; _imageDef = imagedef;
setupDefault(); setupDefault();
} }
void LargeImageButton::setupDefault() { void LargeImageButton::setupDefault() {
_buttonScale = 1; _buttonScale = 1;
width = 72; width = 72;
height = 72; height = 72;
} }
void LargeImageButton::render(Minecraft* minecraft, int xm, int ym) { void LargeImageButton::render(Minecraft* minecraft, int xm, int ym) {
if (!visible) return; if (!visible) return;
Font* font = minecraft->font; Font* font = minecraft->font;
//minecraft->textures->loadAndBindTexture("gui/gui.png"); //minecraft->textures->loadAndBindTexture("gui/gui.png");
glColor4f2(1, 1, 1, 1); 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 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); //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); //int yImage = getYImage(hovered || selected);
//blit(x, y, 0, 46 + yImage * 20, w / 2, h, 0, 20); //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); //blit(x + w / 2, y, 200 - w / 2, 46 + yImage * 20, w / 2, h, 0, 20);
renderBg(minecraft, xm, ym); renderBg(minecraft, xm, ym);
TextureId texId = (_imageDef.name.length() > 0)? minecraft->textures->loadAndBindTexture(_imageDef.name) : Textures::InvalidId; TextureId texId = (_imageDef.name.length() > 0)? minecraft->textures->loadAndBindTexture(_imageDef.name) : Textures::InvalidId;
if ( Textures::isTextureIdValid(texId) ) { if ( Textures::isTextureIdValid(texId) ) {
const ImageDef& d = _imageDef; const ImageDef& d = _imageDef;
Tesselator& t = Tesselator::instance; Tesselator& t = Tesselator::instance;
t.begin(); t.begin();
if (!active) t.color(0xff808080); if (!active) t.color(0xff808080);
//else if (hovered||selected) t.color(0xffffffff); //else if (hovered||selected) t.color(0xffffffff);
//else t.color(0xffe0e0e0); //else t.color(0xffe0e0e0);
else t.color(0xffffffff); else t.color(0xffffffff);
float hx = ((float) d.width) * 0.5f; float hx = ((float) d.width) * 0.5f;
float hy = ((float) d.height) * 0.5f; float hy = ((float) d.height) * 0.5f;
const float cx = ((float)x+d.x) + hx; const float cx = ((float)x+d.x) + hx;
const float cy = ((float)y+d.y) + hy; const float cy = ((float)y+d.y) + hy;
if (hovered) if (hovered)
_buttonScale = Mth::Max(0.95f, _buttonScale-0.025f); _buttonScale = Mth::Max(0.95f, _buttonScale-0.025f);
else else
_buttonScale = Mth::Min(1.00f, _buttonScale+0.025f); _buttonScale = Mth::Min(1.00f, _buttonScale+0.025f);
hx *= _buttonScale; hx *= _buttonScale;
hy *= _buttonScale; hy *= _buttonScale;
const IntRectangle* src = _imageDef.getSrc(); const IntRectangle* src = _imageDef.getSrc();
if (src) { if (src) {
const TextureData* d = minecraft->textures->getTemporaryTextureData(texId); const TextureData* d = minecraft->textures->getTemporaryTextureData(texId);
if (d != NULL) { if (d != NULL) {
float u0 = (src->x+(hovered?src->w:0)) / (float)d->w; 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 u1 = (src->x+(hovered?2*src->w:src->w)) / (float)d->w;
float v0 = src->y / (float)d->h; float v0 = src->y / (float)d->h;
float v1 = (src->y+src->h) / (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, v0);
t.vertexUV(cx-hx, cy+hy, blitOffset, u0, v1); 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, v1);
t.vertexUV(cx+hx, cy-hy, blitOffset, u1, v0); t.vertexUV(cx+hx, cy-hy, blitOffset, u1, v0);
} }
} else { } else {
t.vertexUV(cx-hx, cy-hy, blitOffset, 0, 0); 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, 0, 1);
t.vertexUV(cx+hx, cy+hy, blitOffset, 1, 1); t.vertexUV(cx+hx, cy+hy, blitOffset, 1, 1);
t.vertexUV(cx+hx, cy-hy, blitOffset, 1, 0); t.vertexUV(cx+hx, cy-hy, blitOffset, 1, 0);
} }
t.draw(); t.draw();
} }
//blit(0, 0, 0, 0, 64, 64, 256, 256); //blit(0, 0, 0, 0, 64, 64, 256, 256);
//LOGI("%d %d\n", x+d.x, x+d.x+d.w); //LOGI("%d %d\n", x+d.x, x+d.x+d.w);
if (!active) { if (!active) {
drawCenteredString(font, msg, x + width / 2, y + 11/*(h - 16)*/, 0xffa0a0a0); drawCenteredString(font, msg, x + width / 2, y + 11/*(h - 16)*/, 0xffa0a0a0);
} else { } else {
if (hovered || selected) { if (hovered || selected) {
drawCenteredString(font, msg, x + width / 2, y + 11/*(h - 16)*/, 0xffffa0); drawCenteredString(font, msg, x + width / 2, y + 11/*(h - 16)*/, 0xffffa0);
} else { } else {
drawCenteredString(font, msg, x + width / 2, y + 11/*(h - 48)*/, 0xe0e0e0); drawCenteredString(font, msg, x + width / 2, y + 11/*(h - 48)*/, 0xe0e0e0);
} }
} }
} }

View File

@@ -1,21 +1,19 @@
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__LargeImageButton_H__ #pragma once
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__LargeImageButton_H__
#include "ImageButton.hpp"
#include "ImageButton.h"
class LargeImageButton: public ImageButton
class LargeImageButton: public ImageButton {
{ typedef ImageButton super;
typedef ImageButton super; public:
public: LargeImageButton(int id, const std::string& msg);
LargeImageButton(int id, const std::string& msg); LargeImageButton(int id, const std::string& msg, ImageDef& imageDef);
LargeImageButton(int id, const std::string& msg, ImageDef& imageDef);
void render(Minecraft* minecraft, int xm, int ym);
void render(Minecraft* minecraft, int xm, int ym);
private:
private: void setupDefault();
void setupDefault();
float _buttonScale;
float _buttonScale; };
};
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__LargeImageButton_H__*/

View File

@@ -1,141 +1,141 @@
#include "NinePatch.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), 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), v0(y), v1(y + y1), v2(y + y2), v3(y + y3),
w(w), e(e), n(n), s(s), w(w), e(e), n(n), s(s),
imgW(-1), imgW(-1),
imgH(-1) { imgH(-1) {
} }
NinePatchDescription& NinePatchDescription::transformUVForImage( const TextureData& d ) { NinePatchDescription& NinePatchDescription::transformUVForImage( const TextureData& d ) {
return transformUVForImageSize(d.w, d.h); return transformUVForImageSize(d.w, d.h);
} }
NinePatchDescription& NinePatchDescription::transformUVForImageSize( int w, int h ) { NinePatchDescription& NinePatchDescription::transformUVForImageSize( int w, int h ) {
if (imgW < 0) if (imgW < 0)
imgW = imgH = 1; imgW = imgH = 1;
const float us = (float) imgW / w; // @todo: prepare for normal blit? (e.g. mult by 256) const float us = (float) imgW / w; // @todo: prepare for normal blit? (e.g. mult by 256)
const float vs = (float) imgH / h; const float vs = (float) imgH / h;
u0 *= us; u1 *= us; u2 *= us; u3 *= us; u0 *= us; u1 *= us; u2 *= us; u3 *= us;
v0 *= vs; v1 *= vs; v2 *= vs; v3 *= vs; v0 *= vs; v1 *= vs; v2 *= vs; v3 *= vs;
imgW = w; imgW = w;
imgH = h; imgH = h;
return *this; return *this;
} }
NinePatchDescription NinePatchDescription::createSymmetrical( int texWidth, int texHeight, const IntRectangle& src, int xCutAt, int yCutAt ) { 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 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)xCutAt, (float)(src.w-xCutAt), (float)src.w, // u tex coordinates
(float)yCutAt, (float)(src.h-yCutAt), (float)src.h, // v 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 (float)xCutAt, (float)xCutAt, (float)yCutAt, (float)yCutAt); // border width and heights
if (texWidth > 0) patch.transformUVForImageSize(texWidth, texHeight); if (texWidth > 0) patch.transformUVForImageSize(texWidth, texHeight);
return patch; return patch;
} }
NinePatchLayer::NinePatchLayer(const NinePatchDescription& desc, const std::string& imageName, Textures* textures, float w, float h) NinePatchLayer::NinePatchLayer(const NinePatchDescription& desc, const std::string& imageName, Textures* textures, float w, float h)
: desc(desc), : desc(desc),
imageName(imageName), imageName(imageName),
textures(textures), textures(textures),
w(-1), h(-1), w(-1), h(-1),
excluded(0) excluded(0)
{ {
setSize(w, h); setSize(w, h);
} }
void NinePatchLayer::setSize( float w, float h ) { void NinePatchLayer::setSize( float w, float h ) {
if (w == this->w && h == this->h) if (w == this->w && h == this->h)
return; return;
this->w = w; this->w = w;
this->h = h; this->h = h;
for (int i = 0; i < 9; ++i) for (int i = 0; i < 9; ++i)
buildQuad(i); buildQuad(i);
} }
void NinePatchLayer::draw( Tesselator& t, float x, float y ) { void NinePatchLayer::draw( Tesselator& t, float x, float y ) {
textures->loadAndBindTexture(imageName); textures->loadAndBindTexture(imageName);
t.begin(); t.begin();
t.addOffset(x, y, 0); t.addOffset(x, y, 0);
for (int i = 0, b = 1; i < 9; ++i, b += b) for (int i = 0, b = 1; i < 9; ++i, b += b)
if ((b & excluded) == 0) if ((b & excluded) == 0)
d(t, quads[i]); d(t, quads[i]);
t.addOffset(-x, -y, 0); t.addOffset(-x, -y, 0);
t.draw(); t.draw();
} }
NinePatchLayer* NinePatchLayer::exclude( int excludeId ) { NinePatchLayer* NinePatchLayer::exclude( int excludeId ) {
return setExcluded(excluded | (1 << excludeId)); return setExcluded(excluded | (1 << excludeId));
} }
NinePatchLayer* NinePatchLayer::setExcluded( int exludeBits ) { NinePatchLayer* NinePatchLayer::setExcluded( int exludeBits ) {
excluded = exludeBits; excluded = exludeBits;
return this; return this;
} }
void NinePatchLayer::buildQuad( int qid ) { void NinePatchLayer::buildQuad( int qid ) {
//@attn; fix //@attn; fix
CachedQuad& q = quads[qid]; CachedQuad& q = quads[qid];
const int yid = qid / 3; const int yid = qid / 3;
const int xid = qid - 3 * yid; const int xid = qid - 3 * yid;
q.u0 = (&desc.u0)[xid]; q.u0 = (&desc.u0)[xid];
q.u1 = (&desc.u0)[xid + 1]; q.u1 = (&desc.u0)[xid + 1];
q.v0 = (&desc.v0)[yid]; q.v0 = (&desc.v0)[yid];
q.v1 = (&desc.v0)[yid + 1]; q.v1 = (&desc.v0)[yid + 1];
q.z = 0; q.z = 0;
getPatchInfo(xid, yid, q.x0, q.x1, q.y0, q.y1); getPatchInfo(xid, yid, q.x0, q.x1, q.y0, q.y1);
/* q.x0 = w * (q.u0 - desc.u0); /* q.x0 = w * (q.u0 - desc.u0);
q.y0 = h * (q.v0 - desc.v0); q.y0 = h * (q.v0 - desc.v0);
q.x1 = w * (q.u1 - desc.u0); q.x1 = w * (q.u1 - desc.u0);
q.y1 = h * (q.v1 - desc.v0); q.y1 = h * (q.v1 - desc.v0);
*/ */
} }
void NinePatchLayer::getPatchInfo( int xc, int yc, float& x0, float& x1, float& y0, float& y1 ) { void NinePatchLayer::getPatchInfo( int xc, int yc, float& x0, float& x1, float& y0, float& y1 ) {
if (xc == 0) { x0 = 0; x1 = desc.w; } if (xc == 0) { x0 = 0; x1 = desc.w; }
else if (xc == 1) { x0 = desc.w; x1 = w - desc.e; } else if (xc == 1) { x0 = desc.w; x1 = w - desc.e; }
else if (xc == 2) { x0 = w-desc.e; x1 = w; } else if (xc == 2) { x0 = w-desc.e; x1 = w; }
if (yc == 0) { y0 = 0; y1 = desc.n; } if (yc == 0) { y0 = 0; y1 = desc.n; }
else if (yc == 1) { y0 = desc.n; y1 = h - desc.s; } else if (yc == 1) { y0 = desc.n; y1 = h - desc.s; }
else if (yc == 2) { y0 = h-desc.s; y1 = h; } else if (yc == 2) { y0 = h-desc.s; y1 = h; }
} }
void NinePatchLayer::d( Tesselator& t, const CachedQuad& q ) { void NinePatchLayer::d( Tesselator& t, const CachedQuad& q ) {
/* /*
t.vertexUV(x , y + h, blitOffset, (float)(sx ), (float)(sy + sh)); 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 + h, blitOffset, (float)(sx + sw), (float)(sy + sh));
t.vertexUV(x + w, y , blitOffset, (float)(sx + sw), (float)(sy )); t.vertexUV(x + w, y , blitOffset, (float)(sx + sw), (float)(sy ));
t.vertexUV(x , y , blitOffset, (float)(sx ), (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.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.y1, q.z, q.u1, q.v1);
t.vertexUV(q.x1, q.y0, q.z, q.u1, q.v0); t.vertexUV(q.x1, q.y0, q.z, q.u1, q.v0);
t.vertexUV(q.x0, q.y0, q.z, q.u0, q.v0); t.vertexUV(q.x0, q.y0, q.z, q.u0, q.v0);
} }
NinePatchFactory::NinePatchFactory( Textures* textures, const std::string& imageName ) : textures(textures), NinePatchFactory::NinePatchFactory( Textures* textures, const std::string& imageName ) : textures(textures),
imageName(imageName), imageName(imageName),
width(1), width(1),
height(1) { height(1) {
TextureId id = textures->loadTexture(imageName); TextureId id = textures->loadTexture(imageName);
if (id != Textures::InvalidId) { if (id != Textures::InvalidId) {
const TextureData* data = textures->getTemporaryTextureData(id); const TextureData* data = textures->getTemporaryTextureData(id);
if (data) { // This should never be false if (data) { // This should never be false
width = data->w; width = data->w;
height = data->h; height = data->h;
} }
} else { } else {
LOGE("Error @ NinePatchFactory::ctor - Couldn't find texture: %s\n", imageName.c_str()); 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*/ ) { NinePatchLayer* NinePatchFactory::createSymmetrical( const IntRectangle& src, int xCutAt, int yCutAt, float w /*= 32.0f*/, float h /*= 32.0f*/ ) {
return new NinePatchLayer( return new NinePatchLayer(
NinePatchDescription::createSymmetrical(width, height, src, xCutAt, yCutAt), NinePatchDescription::createSymmetrical(width, height, src, xCutAt, yCutAt),
imageName, textures, w, h); imageName, textures, w, h);
} }

View File

@@ -1,78 +1,76 @@
#ifndef NET_MINECRAFT_CLIENT_GUI__NinePatch_H__ #pragma once
#define NET_MINECRAFT_CLIENT_GUI__NinePatch_H__
#include "ImageButton.hpp"
#include "ImageButton.h" #include "client/renderer/TextureData.hpp"
#include "../../renderer/TextureData.h" #include "client/renderer/Textures.hpp"
#include "../../renderer/Textures.h" #include "client/renderer/Tesselator.hpp"
#include "../../renderer/Tesselator.h" #include "client/Minecraft.hpp"
#include "../../Minecraft.h"
class Tesselator;
class Tesselator;
class NinePatchDescription {
class NinePatchDescription { public:
public: NinePatchDescription& transformUVForImage(const TextureData& d);
NinePatchDescription& transformUVForImage(const TextureData& d); NinePatchDescription& transformUVForImageSize(int w, int h);
NinePatchDescription& transformUVForImageSize(int w, int h);
float u0, u1, u2, u3;
float u0, u1, u2, u3; float v0, v1, v2, v3;
float v0, v1, v2, v3; float w, e, n, s;
float w, e, n, s;
static NinePatchDescription createSymmetrical(int texWidth, int texHeight, const IntRectangle& src, int xCutAt, int yCutAt);
static NinePatchDescription createSymmetrical(int texWidth, int texHeight, const IntRectangle& src, int xCutAt, int yCutAt); private:
private: NinePatchDescription( float x, float y, float x1, float x2, float x3, float y1, float y2, float y3,
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);
float w, float e, float n, float s);
int imgW;
int imgW; int imgH;
int imgH; };
};
class NinePatchLayer: public GuiElement
class NinePatchLayer: public GuiElement {
{ struct CachedQuad;
struct CachedQuad; public:
public: NinePatchLayer(const NinePatchDescription& desc, const std::string& imageName, Textures* textures, float w = 32, float h = 32);
NinePatchLayer(const NinePatchDescription& desc, const std::string& imageName, Textures* textures, float w = 32, float h = 32); virtual ~NinePatchLayer() {};
virtual ~NinePatchLayer() {}; void setSize(float w, float h);
void setSize(float w, float h);
void draw(Tesselator& t, float x, float y);
void draw(Tesselator& t, float x, float y);
NinePatchLayer* exclude(int excludeId);
NinePatchLayer* exclude(int excludeId); NinePatchLayer* setExcluded(int exludeBits);
NinePatchLayer* setExcluded(int exludeBits);
float getWidth() { return w; }
float getWidth() { return w; } float getHeight() { return h; }
float getHeight() { return h; }
private:
private: void buildQuad(int qid);
void buildQuad(int qid); void getPatchInfo(int xc, int yc, float& x0, float& x1, float& y0, float& y1);
void getPatchInfo(int xc, int yc, float& x0, float& x1, float& y0, float& y1);
void d(Tesselator& t, const CachedQuad& q);
void d(Tesselator& t, const CachedQuad& q);
float w, h;
float w, h; NinePatchDescription desc;
NinePatchDescription desc; std::string imageName;
std::string imageName; Textures* textures;
Textures* textures; int excluded;
int excluded;
typedef struct CachedQuad {
typedef struct CachedQuad { float x0, x1, y0, y1, z;
float x0, x1, y0, y1, z; float u0, u1, v0, v1;
float u0, u1, v0, v1; } CachedQuad;
} CachedQuad; CachedQuad quads[9];
CachedQuad quads[9]; };
};
class NinePatchFactory {
class NinePatchFactory { public:
public: NinePatchFactory(Textures* textures, const std::string& imageName );
NinePatchFactory(Textures* textures, const std::string& imageName );
NinePatchLayer* createSymmetrical(const IntRectangle& src, int xCutAt, int yCutAt, float w = 32.0f, float h = 32.0f);
NinePatchLayer* createSymmetrical(const IntRectangle& src, int xCutAt, int yCutAt, float w = 32.0f, float h = 32.0f);
private:
private: Textures* textures;
Textures* textures; std::string imageName;
std::string imageName; int width;
int width; int height;
int height; };
};
#endif /*NET_MINECRAFT_CLIENT_GUI__NinePatch_H__*/

View File

@@ -1,115 +1,115 @@
#include "OptionsGroup.h" #include "OptionsGroup.hpp"
#include "../../Minecraft.h" #include "client/Minecraft.hpp"
#include "ImageButton.h" #include "ImageButton.hpp"
#include "OptionsItem.h" #include "OptionsItem.hpp"
#include "Slider.h" #include "Slider.hpp"
#include "../../../locale/I18n.h" #include "locale/I18n.hpp"
#include "TextOption.h" #include "TextOption.hpp"
#include "KeyOption.h" #include "KeyOption.hpp"
OptionsGroup::OptionsGroup( std::string labelID ) { OptionsGroup::OptionsGroup( std::string labelID ) {
label = I18n::get(labelID); label = I18n::get(labelID);
} }
void OptionsGroup::setupPositions() { void OptionsGroup::setupPositions() {
// First we write the header and then we add the items // First we write the header and then we add the items
int curY = y + 18; int curY = y + 18;
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) { for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
(*it)->width = width - 5; (*it)->width = width - 5;
(*it)->y = curY; (*it)->y = curY;
(*it)->x = x + 10; (*it)->x = x + 10;
(*it)->setupPositions(); (*it)->setupPositions();
curY += (*it)->height + 3; curY += (*it)->height + 3;
} }
height = curY; height = curY;
} }
void OptionsGroup::render( Minecraft* minecraft, int xm, int ym ) { void OptionsGroup::render( Minecraft* minecraft, int xm, int ym ) {
float padX = 10.0f; float padX = 10.0f;
float padY = 5.0f; float padY = 5.0f;
minecraft->font->draw(label, (float)x + padX, (float)y + padY, 0xffffffff, false); minecraft->font->draw(label, (float)x + padX, (float)y + padY, 0xffffffff, false);
super::render(minecraft, xm, ym); super::render(minecraft, xm, ym);
} }
OptionsGroup& OptionsGroup::addOptionItem(OptionId optId, Minecraft* minecraft ) { OptionsGroup& OptionsGroup::addOptionItem(OptionId optId, Minecraft* minecraft ) {
auto option = minecraft->options.getOpt(optId); auto option = minecraft->options.getOpt(optId);
if (option == nullptr) return *this; if (option == nullptr) return *this;
// TODO: do a options key class to check it faster via dynamic_cast // 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); 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<OptionBool*>(option)) createToggle(optId, minecraft);
else if (dynamic_cast<OptionFloat*>(option)) createProgressSlider(optId, minecraft); else if (dynamic_cast<OptionFloat*>(option)) createProgressSlider(optId, minecraft);
else if (dynamic_cast<OptionInt*>(option)) createStepSlider(optId, minecraft); else if (dynamic_cast<OptionInt*>(option)) createStepSlider(optId, minecraft);
else if (dynamic_cast<OptionString*>(option)) createTextbox(optId, minecraft); else if (dynamic_cast<OptionString*>(option)) createTextbox(optId, minecraft);
return *this; return *this;
} }
// TODO: wrap this copypaste shit into templates // TODO: wrap this copypaste shit into templates
void OptionsGroup::createToggle(OptionId optId, Minecraft* minecraft ) { void OptionsGroup::createToggle(OptionId optId, Minecraft* minecraft ) {
ImageDef def; ImageDef def;
def.setSrc(IntRectangle(160, 206, 39, 20)); def.setSrc(IntRectangle(160, 206, 39, 20));
def.name = "gui/touchgui.png"; def.name = "gui/touchgui.png";
def.width = 39 * 0.7f; def.width = 39 * 0.7f;
def.height = 20 * 0.7f; def.height = 20 * 0.7f;
OptionButton* element = new OptionButton(optId); OptionButton* element = new OptionButton(optId);
element->setImageDef(def, true); element->setImageDef(def, true);
element->updateImage(&minecraft->options); element->updateImage(&minecraft->options);
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId()); std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
OptionsItem* item = new OptionsItem(optId, itemLabel, element); OptionsItem* item = new OptionsItem(optId, itemLabel, element);
addChild(item); addChild(item);
setupPositions(); setupPositions();
} }
void OptionsGroup::createProgressSlider(OptionId optId, Minecraft* minecraft ) { void OptionsGroup::createProgressSlider(OptionId optId, Minecraft* minecraft ) {
Slider* element = new SliderFloat(minecraft, optId); Slider* element = new SliderFloat(minecraft, optId);
element->width = 100; element->width = 100;
element->height = 20; element->height = 20;
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId()); std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
OptionsItem* item = new OptionsItem(optId, itemLabel, element); OptionsItem* item = new OptionsItem(optId, itemLabel, element);
addChild(item); addChild(item);
setupPositions(); setupPositions();
} }
void OptionsGroup::createStepSlider(OptionId optId, Minecraft* minecraft ) { void OptionsGroup::createStepSlider(OptionId optId, Minecraft* minecraft ) {
Slider* element = new SliderInt(minecraft, optId); Slider* element = new SliderInt(minecraft, optId);
element->width = 100; element->width = 100;
element->height = 20; element->height = 20;
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId()); std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
OptionsItem* item = new OptionsItem(optId, itemLabel, element); OptionsItem* item = new OptionsItem(optId, itemLabel, element);
addChild(item); addChild(item);
setupPositions(); setupPositions();
} }
void OptionsGroup::createTextbox(OptionId optId, Minecraft* minecraft) { void OptionsGroup::createTextbox(OptionId optId, Minecraft* minecraft) {
TextBox* element = new TextOption(minecraft, optId); TextBox* element = new TextOption(minecraft, optId);
element->width = 100; element->width = 100;
element->height = 20; element->height = 20;
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId()); std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
OptionsItem* item = new OptionsItem(optId, itemLabel, element); OptionsItem* item = new OptionsItem(optId, itemLabel, element);
addChild(item); addChild(item);
setupPositions(); setupPositions();
} }
void OptionsGroup::createKey(OptionId optId, Minecraft* minecraft) { void OptionsGroup::createKey(OptionId optId, Minecraft* minecraft) {
KeyOption* element = new KeyOption(minecraft, optId); KeyOption* element = new KeyOption(minecraft, optId);
element->width = 50; element->width = 50;
element->height = 20; element->height = 20;
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId()); std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
OptionsItem* item = new OptionsItem(optId, itemLabel, element); OptionsItem* item = new OptionsItem(optId, itemLabel, element);
addChild(item); addChild(item);
setupPositions(); setupPositions();
} }

View File

@@ -1,32 +1,30 @@
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__OptionsGroup_H__ #pragma once
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__OptionsGroup_H__
//package net.minecraft.client.gui;
//package net.minecraft.client.gui;
#include <string>
#include <string> #include "GuiElementContainer.hpp"
#include "GuiElementContainer.h" #include "ScrollingPane.hpp"
#include "ScrollingPane.h" #include "client/Options.hpp"
#include "../../Options.h"
class Font;
class Font; class Minecraft;
class Minecraft;
class OptionsGroup: public GuiElementContainer {
class OptionsGroup: public GuiElementContainer { typedef GuiElementContainer super;
typedef GuiElementContainer super; public:
public: OptionsGroup(std::string labelID);
OptionsGroup(std::string labelID); virtual void setupPositions();
virtual void setupPositions(); virtual void render(Minecraft* minecraft, int xm, int ym);
virtual void render(Minecraft* minecraft, int xm, int ym); OptionsGroup& addOptionItem(OptionId optId, Minecraft* minecraft);
OptionsGroup& addOptionItem(OptionId optId, Minecraft* minecraft); protected:
protected:
void createToggle(OptionId optId, Minecraft* minecraft);
void createToggle(OptionId optId, Minecraft* minecraft); void createProgressSlider(OptionId optId, Minecraft* minecraft);
void createProgressSlider(OptionId optId, Minecraft* minecraft); void createStepSlider(OptionId optId, Minecraft* minecraft);
void createStepSlider(OptionId optId, Minecraft* minecraft); void createTextbox(OptionId optId, Minecraft* minecraft);
void createTextbox(OptionId optId, Minecraft* minecraft); void createKey(OptionId optId, Minecraft* minecraft);
void createKey(OptionId optId, Minecraft* minecraft);
std::string label;
std::string label; };
};
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__OptionsGroup_H__*/

View File

@@ -1,42 +1,42 @@
#include "OptionsItem.h" #include "OptionsItem.hpp"
#include "../../Minecraft.h" #include "client/Minecraft.hpp"
#include "../../../locale/I18n.h" #include "locale/I18n.hpp"
#include "../../../util/Mth.h" #include "util/Mth.hpp"
OptionsItem::OptionsItem( OptionId optionId, std::string label, GuiElement* element ) OptionsItem::OptionsItem( OptionId optionId, std::string label, GuiElement* element )
: GuiElementContainer(false, true, 0, 0, 24, 12), : GuiElementContainer(false, true, 0, 0, 24, 12),
m_optionId(optionId), m_optionId(optionId),
m_label(label) { m_label(label) {
addChild(element); addChild(element);
} }
void OptionsItem::setupPositions() { void OptionsItem::setupPositions() {
int currentHeight = 0; int currentHeight = 0;
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) { for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
(*it)->x = x + width - (*it)->width - 15; (*it)->x = x + width - (*it)->width - 15;
(*it)->y = y + currentHeight; (*it)->y = y + currentHeight;
currentHeight += (*it)->height; currentHeight += (*it)->height;
} }
height = currentHeight; height = currentHeight;
} }
void OptionsItem::render( Minecraft* minecraft, int xm, int ym ) { void OptionsItem::render( Minecraft* minecraft, int xm, int ym ) {
int yOffset = (height - 8) / 2; int yOffset = (height - 8) / 2;
std::string text = m_label; std::string text = m_label;
if (m_optionId == OPTIONS_GUI_SCALE) { if (m_optionId == OPTIONS_GUI_SCALE) {
int value = minecraft->options.getIntValue(OPTIONS_GUI_SCALE); int value = minecraft->options.getIntValue(OPTIONS_GUI_SCALE);
std::string scaleText; std::string scaleText;
switch (value) { switch (value) {
case 0: scaleText = I18n::get("options.guiScale.auto"); break; case 0: scaleText = I18n::get("options.guiScale.auto"); break;
case 1: scaleText = I18n::get("options.guiScale.small"); break; case 1: scaleText = I18n::get("options.guiScale.small"); break;
case 2: scaleText = I18n::get("options.guiScale.medium"); break; case 2: scaleText = I18n::get("options.guiScale.medium"); break;
case 3: scaleText = I18n::get("options.guiScale.large"); break; case 3: scaleText = I18n::get("options.guiScale.large"); break;
case 4: scaleText = I18n::get("options.guiScale.larger"); break; case 4: scaleText = I18n::get("options.guiScale.larger"); break;
case 5: scaleText = I18n::get("options.guiScale.largest"); break; case 5: scaleText = I18n::get("options.guiScale.largest"); break;
default: scaleText = I18n::get("options.guiScale.auto"); break; default: scaleText = I18n::get("options.guiScale.auto"); break;
} }
text += ": " + scaleText; text += ": " + scaleText;
} }
minecraft->font->draw(text, (float)x, (float)y + yOffset, 0x909090, false); minecraft->font->draw(text, (float)x, (float)y + yOffset, 0x909090, false);
super::render(minecraft, xm, ym); super::render(minecraft, xm, ym);
} }

View File

@@ -1,27 +1,25 @@
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__OptionsItem_H__ #pragma once
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__OptionsItem_H__
#include <string>
#include <string> #include <vector>
#include <vector> #include "GuiElementContainer.hpp"
#include "GuiElementContainer.h" #include "world/item/ItemInstance.hpp"
#include "../../../world/item/ItemInstance.h" #include "client/Options.hpp"
#include "../../../client/Options.h" class Font;
class Font; class Textures;
class Textures; class NinePatchLayer;
class NinePatchLayer; class ItemPane;
class ItemPane;
class OptionsItem: public GuiElementContainer
class OptionsItem: public GuiElementContainer {
{ typedef GuiElementContainer super;
typedef GuiElementContainer super; public:
public: OptionsItem(OptionId optionId, std::string label, GuiElement* element);
OptionsItem(OptionId optionId, std::string label, GuiElement* element); virtual void render(Minecraft* minecraft, int xm, int ym);
virtual void render(Minecraft* minecraft, int xm, int ym); void setupPositions();
void setupPositions();
private:
private: OptionId m_optionId;
OptionId m_optionId; std::string m_label;
std::string m_label; };
};
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__OptionsItem_H__*/

View File

@@ -1,299 +1,299 @@
#include "RolledSelectionListH.h" #include "RolledSelectionListH.hpp"
#include "../../Minecraft.h" #include "client/renderer/Tesselator.hpp"
#include "../../renderer/Tesselator.h" #include "client/renderer/gles.hpp"
#include "../../renderer/gles.h" #include "platform/input/Mouse.hpp"
#include "../../../platform/input/Mouse.h" #include "platform/input/Multitouch.hpp"
#include "../../../platform/input/Multitouch.h" #include "util/Mth.hpp"
#include "../../../util/Mth.h" #include "client/renderer/Textures.hpp"
#include "../../renderer/Textures.h" #include "MinecraftClient.hpp"
RolledSelectionListH::RolledSelectionListH( Minecraft* minecraft, int width, int height, int x0, int x1, int y0, int y1, int itemWidth ) RolledSelectionListH::RolledSelectionListH( MinecraftClient& minecraft, int width, int height, int x0, int x1, int y0, int y1, int itemWidth )
: minecraft(minecraft), : minecraft(minecraft),
width(width), width(width),
height(height), height(height),
x0((float)x0), x0((float)x0),
x1((float)x1), x1((float)x1),
y0((float)y0), y0((float)y0),
y1((float)y1), y1((float)y1),
itemWidth(itemWidth), itemWidth(itemWidth),
selectionX(-1), selectionX(-1),
lastSelectionTime(0), lastSelectionTime(0),
lastSelection(-1), lastSelection(-1),
renderSelection(true), renderSelection(true),
doRenderHeader(false), doRenderHeader(false),
headerWidth(0), headerWidth(0),
dragState(DRAG_OUTSIDE), dragState(DRAG_OUTSIDE),
xDrag(0.0f), xDrag(0.0f),
xo(0.0f), xo(0.0f),
xoo(0.0f), xoo(0.0f),
xInertia(0.0f), xInertia(0.0f),
_componentSelected(false), _componentSelected(false),
_renderTopBorder(true), _renderTopBorder(true),
_renderBottomBorder(true), _renderBottomBorder(true),
_lastxoo(0), _lastxoo(0),
_xinertia(0) _xinertia(0)
{ {
xo = xoo = (float)(itemWidth-width) * 0.5f; xo = xoo = (float)(itemWidth-width) * 0.5f;
_lastxoo = xoo; _lastxoo = xoo;
} }
void RolledSelectionListH::setRenderSelection( bool _renderSelection ) void RolledSelectionListH::setRenderSelection( bool _renderSelection )
{ {
renderSelection = _renderSelection; renderSelection = _renderSelection;
} }
void RolledSelectionListH::setComponentSelected(bool selected) { void RolledSelectionListH::setComponentSelected(bool selected) {
_componentSelected = selected; _componentSelected = selected;
} }
void RolledSelectionListH::setRenderHeader( bool _renderHeader, int _headerHeight ) void RolledSelectionListH::setRenderHeader( bool _renderHeader, int _headerHeight )
{ {
doRenderHeader = _renderHeader; doRenderHeader = _renderHeader;
headerWidth = _headerHeight; headerWidth = _headerHeight;
if (!doRenderHeader) { if (!doRenderHeader) {
headerWidth = 0; headerWidth = 0;
} }
} }
int RolledSelectionListH::getMaxPosition() int RolledSelectionListH::getMaxPosition()
{ {
return getNumberOfItems() * itemWidth + headerWidth; return getNumberOfItems() * itemWidth + headerWidth;
} }
int RolledSelectionListH::getItemAtPosition( int x, int y ) int RolledSelectionListH::getItemAtPosition( int x, int y )
{ {
int clickSlotPos = (int)(x - x0 - headerWidth + (int) xo - 4); int clickSlotPos = (int)(x - x0 - headerWidth + (int) xo - 4);
int isInsideY = y >= y0 && y <= y1; int isInsideY = y >= y0 && y <= y1;
return isInsideY? getItemAtXPositionRaw(clickSlotPos) : -1; return isInsideY? getItemAtXPositionRaw(clickSlotPos) : -1;
} }
int RolledSelectionListH::getItemAtXPositionRaw(int x) { int RolledSelectionListH::getItemAtXPositionRaw(int x) {
int slot = x / itemWidth; int slot = x / itemWidth;
bool isInsideX = slot >= 0 && x >= 0 && slot < getNumberOfItems(); bool isInsideX = slot >= 0 && x >= 0 && slot < getNumberOfItems();
return isInsideX? slot : -1; return isInsideX? slot : -1;
} }
bool RolledSelectionListH::capXPosition() bool RolledSelectionListH::capXPosition()
{ {
const float MinX = (float)(itemWidth-width)/2; const float MinX = (float)(itemWidth-width)/2;
const float MaxX = MinX + (getNumberOfItems()-1) * itemWidth; const float MaxX = MinX + (getNumberOfItems()-1) * itemWidth;
if (xo < MinX) { xo = MinX; xInertia = 0; return true; } if (xo < MinX) { xo = MinX; xInertia = 0; return true; }
if (xo > MaxX) { xo = MaxX; xInertia = 0; return true; } if (xo > MaxX) { xo = MaxX; xInertia = 0; return true; }
return false; return false;
} }
void RolledSelectionListH::tick() { void RolledSelectionListH::tick() {
//if (Mouse::isButtonDown(MouseAction::ACTION_LEFT)) //if (Mouse::isButtonDown(MouseAction::ACTION_LEFT))
{ {
_xinertia = _lastxoo - xoo; _xinertia = _lastxoo - xoo;
} }
_lastxoo = xoo; _lastxoo = xoo;
xoo = xo - xInertia; xoo = xo - xInertia;
} }
float RolledSelectionListH::getPos(float alpha) { float RolledSelectionListH::getPos(float alpha) {
return xoo - xInertia * alpha; return xoo - xInertia * alpha;
} }
void RolledSelectionListH::render( int xm, int ym, float a ) void RolledSelectionListH::render( int xm, int ym, float a )
{ {
renderBackground(); renderBackground();
int itemCount = getNumberOfItems(); int itemCount = getNumberOfItems();
//float yy0 = height / 2.0f + 124; //float yy0 = height / 2.0f + 124;
//float yy1 = yy0 + 6; //float yy1 = yy0 + 6;
if (Mouse::isButtonDown(MouseAction::ACTION_LEFT)) { if (Mouse::isButtonDown(MouseAction::ACTION_LEFT)) {
touched(); touched();
//LOGI("DOWN ym: %d\n", ym); //LOGI("DOWN ym: %d\n", ym);
if (ym >= y0 && ym <= y1) { if (ym >= y0 && ym <= y1) {
if (dragState == NO_DRAG) { if (dragState == NO_DRAG) {
lastSelectionTime = getTimeMs(); lastSelectionTime = getTimeMs();
lastSelection = getItemAtPosition(xm, height/2); lastSelection = getItemAtPosition(xm, height/2);
//float localX = (float)(xm*Gui::InvGuiScale - x0 - xo + lastSelection * itemWidth + headerWidth); //float localX = (float)(xm*Gui::InvGuiScale - x0 - xo + lastSelection * itemWidth + headerWidth);
selectStart(lastSelection, 0, 0);//localX, ym-y0); selectStart(lastSelection, 0, 0);//localX, ym-y0);
selectionX = xm; selectionX = xm;
} }
else if (dragState >= 0) { else if (dragState >= 0) {
xo -= (xm - xDrag); xo -= (xm - xDrag);
xoo = xo; xoo = xo;
} }
dragState = DRAG_NORMAL; dragState = DRAG_NORMAL;
//const int* ids; //const int* ids;
//LOGI("mtouch: %d\n", Multitouch::getActivePointerIds(&ids)); //LOGI("mtouch: %d\n", Multitouch::getActivePointerIds(&ids));
} }
} else { } else {
if (dragState >= 0) { if (dragState >= 0) {
if (dragState >= 0) { if (dragState >= 0) {
xInertia = _xinertia < 0? Mth::Max(-20.0f, _xinertia) : Mth::Min(20.0f, _xinertia); 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); //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 // kill small inertia values when releasing scrollist
if (std::abs(xInertia) <= 2.0001f) { if (std::abs(xInertia) <= 2.0001f) {
xInertia = 0.0f; xInertia = 0.0f;
} }
if (std::abs(xInertia) <= 10 && getTimeMs() - lastSelectionTime < 300) if (std::abs(xInertia) <= 10 && getTimeMs() - lastSelectionTime < 300)
{ {
int slot = getItemAtPosition(xm, height/2); int slot = getItemAtPosition(xm, height/2);
//LOGI("slot: %d, lt: %d. diff: %d - %d\n", slot, lastSelection, selectionX, xm); //LOGI("slot: %d, lt: %d. diff: %d - %d\n", slot, lastSelection, selectionX, xm);
if (slot >= 0 && slot == lastSelection && std::abs(selectionX - xm) < 10) if (slot >= 0 && slot == lastSelection && std::abs(selectionX - xm) < 10)
selectItem(slot, false); selectItem(slot, false);
else else
selectCancel(); selectCancel();
} else { } else {
selectCancel(); selectCancel();
} }
} }
// if (slot >= 0 && std::abs(selectionX - xm) < itemWidth) // if (slot >= 0 && std::abs(selectionX - xm) < itemWidth)
// { // {
// bool doubleClick = false; // bool doubleClick = false;
// selectItem(slot, doubleClick); // selectItem(slot, doubleClick);
// //xInertia = 0.0f; // //xInertia = 0.0f;
// } // }
//} //}
dragState = NO_DRAG; dragState = NO_DRAG;
xo = getPos(a); xo = getPos(a);
} }
xDrag = (float)xm; xDrag = (float)xm;
capXPosition(); capXPosition();
Tesselator& t = Tesselator::instance; Tesselator& t = Tesselator::instance;
float by0 = _renderTopBorder? y0 : 0; float by0 = _renderTopBorder? y0 : 0;
float by1 = _renderBottomBorder? y1 : height; float by1 = _renderBottomBorder? y1 : height;
//LOGI("x: %f\n", xo); //LOGI("x: %f\n", xo);
minecraft->textures->loadAndBindTexture("gui/background.png"); minecraft.textures().loadAndBindTexture("gui/background.png");
glColor4f2(1.0f, 1, 1, 1); glColor4f2(1.0f, 1, 1, 1);
float s = 32; float s = 32;
t.begin(); t.begin();
t.color(0x202020); t.color(0x202020);
t.vertexUV(x0, by1, 0, (x0 + (int) xo) / s, by1 / s); 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, by1, 0, (x1 + (int) xo) / s, by1 / s);
t.vertexUV(x1, by0, 0, (x1 + (int) xo) / s, by0 / s); t.vertexUV(x1, by0, 0, (x1 + (int) xo) / s, by0 / s);
t.vertexUV(x0, by0, 0, (x0 + (int) xo) / s, by0 / s); t.vertexUV(x0, by0, 0, (x0 + (int) xo) / s, by0 / s);
t.draw(); t.draw();
const int HalfHeight = 48; const int HalfHeight = 48;
if (getNumberOfItems() == 0) xo = 0; if (getNumberOfItems() == 0) xo = 0;
int rowY = (int)(height / 2 - HalfHeight + 8); int rowY = (int)(height / 2 - HalfHeight + 8);
int rowBaseX = (int)(x0 /*+ 4*/ - (int) xo); int rowBaseX = (int)(x0 /*+ 4*/ - (int) xo);
if (doRenderHeader) { if (doRenderHeader) {
renderHeader(rowBaseX, rowY, t); renderHeader(rowBaseX, rowY, t);
} }
for (int i = 0; i < itemCount; i++) { for (int i = 0; i < itemCount; i++) {
float x = (float)(rowBaseX + (i) * itemWidth + headerWidth); float x = (float)(rowBaseX + (i) * itemWidth + headerWidth);
float h = (float)itemWidth; float h = (float)itemWidth;
if (x > x1 || (x + h) < x0) { if (x > x1 || (x + h) < x0) {
continue; continue;
} }
if (renderSelection && isSelectedItem(i)) { if (renderSelection && isSelectedItem(i)) {
float y0 = height / 2.0f - HalfHeight - 4; //@kindle-res:+2 float y0 = height / 2.0f - HalfHeight - 4; //@kindle-res:+2
float y1 = height / 2.0f + HalfHeight - 4; //@kindle-res:-6 float y1 = height / 2.0f + HalfHeight - 4; //@kindle-res:-6
glColor4f2(1, 1, 1, 1); glColor4f2(1, 1, 1, 1);
glDisable2(GL_TEXTURE_2D); glDisable2(GL_TEXTURE_2D);
int ew = 0; int ew = 0;
int color = 0x808080; int color = 0x808080;
if (_componentSelected) { if (_componentSelected) {
ew = 0; ew = 0;
color = 0x7F89BF; color = 0x7F89BF;
} }
t.begin(); t.begin();
t.color(color); t.color(color);
t.vertex(x - 1 - ew, y0 - ew, 0); t.vertex(x - 1 - ew, y0 - ew, 0);
t.vertex(x - 1 - ew, y1 + 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, y1 + ew, 0);
t.vertex(x + h + 1 + ew, y0 - ew, 0); t.vertex(x + h + 1 + ew, y0 - ew, 0);
t.color(0x000000); t.color(0x000000);
t.vertex(x, y0 + 1, 0); t.vertex(x, y0 + 1, 0);
t.vertex(x, y1 - 1, 0); t.vertex(x, y1 - 1, 0);
t.vertex(x + h, y1 - 1, 0); t.vertex(x + h, y1 - 1, 0);
t.vertex(x + h, y0 + 1, 0); t.vertex(x + h, y0 + 1, 0);
t.draw(); t.draw();
glEnable2(GL_TEXTURE_2D); glEnable2(GL_TEXTURE_2D);
} }
renderItem(i, (int)x, rowY, (int)h, t); renderItem(i, (int)x, rowY, (int)h, t);
} }
glDisable2(GL_DEPTH_TEST); glDisable2(GL_DEPTH_TEST);
if (_renderTopBorder) if (_renderTopBorder)
renderHoleBackground(0, y0, 255, 255); renderHoleBackground(0, y0, 255, 255);
if (_renderBottomBorder) if (_renderBottomBorder)
renderHoleBackground(y1, (float)height, 255, 255); renderHoleBackground(y1, (float)height, 255, 255);
//glEnable2(GL_BLEND); //glEnable2(GL_BLEND);
//glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glDisable2(GL_ALPHA_TEST); //glDisable2(GL_ALPHA_TEST);
//glShadeModel2(GL_SMOOTH); //glShadeModel2(GL_SMOOTH);
//glDisable2(GL_TEXTURE_2D); //glDisable2(GL_TEXTURE_2D);
//const int d = 4; //const int d = 4;
//t.begin(); //t.begin();
//t.color(0x000000, 0); //t.color(0x000000, 0);
//t.vertexUV(y0, x0 + d, 0, 0, 1); //t.vertexUV(y0, x0 + d, 0, 0, 1);
//t.vertexUV(y1, x0 + d, 0, 1, 1); //t.vertexUV(y1, x0 + d, 0, 1, 1);
//t.color(0x000000, 255); //t.color(0x000000, 255);
//t.vertexUV(y1, x0, 0, 1, 0); //t.vertexUV(y1, x0, 0, 1, 0);
//t.vertexUV(y0, x0, 0, 0, 0); //t.vertexUV(y0, x0, 0, 0, 0);
//t.draw(); //t.draw();
//t.begin(); //t.begin();
//t.color(0x000000, 255); //t.color(0x000000, 255);
//t.vertexUV(y0, x1, 0, 0, 1); //t.vertexUV(y0, x1, 0, 0, 1);
//t.vertexUV(y1, x1, 0, 1, 1); //t.vertexUV(y1, x1, 0, 1, 1);
//t.color(0x000000, 0); //t.color(0x000000, 0);
//t.vertexUV(y1, x1 - d, 0, 1, 0); //t.vertexUV(y1, x1 - d, 0, 1, 0);
//t.vertexUV(y0, x1 - d, 0, 0, 0); //t.vertexUV(y0, x1 - d, 0, 0, 0);
//t.draw(); //t.draw();
//renderDecorations(xm, ym); //renderDecorations(xm, ym);
//glEnable2(GL_TEXTURE_2D); //glEnable2(GL_TEXTURE_2D);
glEnable2(GL_DEPTH_TEST); glEnable2(GL_DEPTH_TEST);
//glShadeModel2(GL_FLAT); //glShadeModel2(GL_FLAT);
//glEnable2(GL_ALPHA_TEST); //glEnable2(GL_ALPHA_TEST);
//glDisable2(GL_BLEND); //glDisable2(GL_BLEND);
} }
void RolledSelectionListH::renderHoleBackground( /*float x0, float x1,*/ float y0, float y1, int a0, int a1 ) void RolledSelectionListH::renderHoleBackground( /*float x0, float x1,*/ float y0, float y1, int a0, int a1 )
{ {
Tesselator& t = Tesselator::instance; Tesselator& t = Tesselator::instance;
minecraft->textures->loadAndBindTexture("gui/background.png"); minecraft.textures().loadAndBindTexture("gui/background.png");
glColor4f2(1.0f, 1, 1, 1); glColor4f2(1.0f, 1, 1, 1);
float s = 32; float s = 32;
t.begin(); t.begin();
t.color(0x505050, a1); t.color(0x505050, a1);
t.vertexUV(0, y1, 0, 0, y1 / s); t.vertexUV(0, y1, 0, 0, y1 / s);
t.vertexUV((float)width, y1, 0, width / s, y1 / s); t.vertexUV((float)width, y1, 0, width / s, y1 / s);
t.color(0x505050, a0); t.color(0x505050, a0);
t.vertexUV((float)width, y0, 0, width / s, y0 / s); t.vertexUV((float)width, y0, 0, width / s, y0 / s);
t.vertexUV(0, y0, 0, 0, y0 / s); t.vertexUV(0, y0, 0, 0, y0 / s);
t.draw(); t.draw();
//printf("x, y, x1, y1: %d, %d, %d, %d\n", 0, (int)y0, width, (int)y1); //printf("x, y, x1, y1: %d, %d, %d, %d\n", 0, (int)y0, width, (int)y1);
} }
void RolledSelectionListH::touched() void RolledSelectionListH::touched()
{ {
} }

View File

@@ -1,82 +1,80 @@
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__RolledSelectionListH_H__ #pragma once
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__RolledSelectionListH_H__
#include "client/gui/GuiComponent.hpp"
#include "../GuiComponent.h" class MinecraftClient;
class Minecraft; class Tesselator;
class Tesselator;
class RolledSelectionListH : public GuiComponent
class RolledSelectionListH : public GuiComponent {
{ static const int NO_DRAG = -1;
static const int NO_DRAG = -1; static const int DRAG_OUTSIDE = -2;
static const int DRAG_OUTSIDE = -2; static const int DRAG_NORMAL = 0;
static const int DRAG_NORMAL = 0; public:
public: RolledSelectionListH(MinecraftClient& minecraft, int width, int height, int x0, int x1, int y0, int y1, int itemWidth);
RolledSelectionListH(Minecraft* minecraft, int width, int height, int x0, int x1, int y0, int y1, int itemWidth);
virtual int getItemAtPosition(int x, int y);
virtual int getItemAtPosition(int x, int y);
virtual bool capXPosition();
virtual bool capXPosition();
virtual void tick();
virtual void tick(); virtual void render(int xm, int ym, float a);
virtual void render(int xm, int ym, float a); virtual void renderHoleBackground(/*float x0, float x1,*/ float y0, float y1, int a0, int a1);
virtual void renderHoleBackground(/*float x0, float x1,*/ float y0, float y1, int a0, int a1); virtual void setRenderSelection(bool _renderSelection);
virtual void setRenderSelection(bool _renderSelection); virtual void setComponentSelected(bool selected);
virtual void setComponentSelected(bool selected); protected:
protected: void setRenderHeader(bool _renderHeader, int _headerHeight);
void setRenderHeader(bool _renderHeader, int _headerHeight);
virtual int getNumberOfItems() = 0;
virtual int getNumberOfItems() = 0;
virtual void selectStart(int item, int localX, int localY) {}
virtual void selectStart(int item, int localX, int localY) {} virtual void selectCancel() {}
virtual void selectCancel() {} virtual void selectItem(int item, bool doubleClick) = 0;
virtual void selectItem(int item, bool doubleClick) = 0; virtual bool isSelectedItem(int item) = 0;
virtual bool isSelectedItem(int item) = 0;
virtual int getMaxPosition();
virtual int getMaxPosition(); virtual float getPos(float alpha);
virtual float getPos(float alpha); virtual void touched();
virtual void touched();
virtual void renderItem(int i, int x, int y, int h, Tesselator& t) = 0;
virtual void renderItem(int i, int x, int y, int h, Tesselator& t) = 0; virtual void renderHeader(int x, int y, Tesselator& t) {}
virtual void renderHeader(int x, int y, Tesselator& t) {} virtual void renderBackground() = 0;
virtual void renderBackground() = 0; virtual void renderDecorations(int mouseX, int mouseY) {}
virtual void renderDecorations(int mouseX, int mouseY) {}
virtual void clickedHeader(int headerMouseX, int headerMouseY) {}
virtual void clickedHeader(int headerMouseX, int headerMouseY) {} int getItemAtXPositionRaw(int x);
int getItemAtXPositionRaw(int x); protected:
protected: MinecraftClient& minecraft;
Minecraft* minecraft;
float x0;
float x0; float x1;
float x1; int itemWidth;
int itemWidth; int width;
int width; int height;
int height; //private:
//private: float y0;
float y0; float y1;
float y1;
int dragState;
int dragState; float xDrag;
float xDrag; float xo;
float xo; float xoo;
float xoo; float xInertia;
float xInertia; float _xinertia;
float _xinertia;
int selectionX;
int selectionX; bool renderSelection;
bool renderSelection; bool _componentSelected;
bool _componentSelected;
bool _renderTopBorder;
bool _renderTopBorder; bool _renderBottomBorder;
bool _renderBottomBorder;
private:
private: int headerWidth;
int headerWidth; bool doRenderHeader;
bool doRenderHeader; long lastSelectionTime;
long lastSelectionTime; int lastSelection;
int lastSelection;
float _lastxoo;
float _lastxoo; };
};
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__RolledSelectionListH_H__*/

View File

@@ -1,352 +1,352 @@
#include "RolledSelectionListV.h" #include "RolledSelectionListV.hpp"
#include "../../Minecraft.h" #include "client/Minecraft.hpp"
#include "../../renderer/Tesselator.h" #include "client/renderer/Tesselator.hpp"
#include "../../renderer/gles.h" #include "client/renderer/gles.hpp"
#include "../../../platform/input/Mouse.h" #include "platform/input/Mouse.hpp"
#include "../../../util/Mth.h" #include "util/Mth.hpp"
#include "../../renderer/Textures.h" #include "client/renderer/Textures.hpp"
RolledSelectionListV::RolledSelectionListV( Minecraft* minecraft_, int width_, int height_, int x0_, int x1_, int y0_, int y1_, int itemHeight_ ) RolledSelectionListV::RolledSelectionListV( Minecraft* minecraft_, int width_, int height_, int x0_, int x1_, int y0_, int y1_, int itemHeight_ )
: minecraft(minecraft_), : minecraft(minecraft_),
width(width_), width(width_),
height(height_), height(height_),
x0((float)x0_), x0((float)x0_),
x1((float)x1_), x1((float)x1_),
y0((float)y0_), y0((float)y0_),
y1((float)y1_), y1((float)y1_),
itemHeight(itemHeight_), itemHeight(itemHeight_),
selectionY(-1), selectionY(-1),
lastSelectionTime(0), lastSelectionTime(0),
lastSelection(-1), lastSelection(-1),
renderSelection(true), renderSelection(true),
doRenderHeader(false), doRenderHeader(false),
headerHeight(0), headerHeight(0),
dragState(DRAG_OUTSIDE), dragState(DRAG_OUTSIDE),
yDrag(0.0f), yDrag(0.0f),
yo(0.0f), yo(0.0f),
yoo(0.0f), yoo(0.0f),
yInertia(0.0f), yInertia(0.0f),
_componentSelected(false), _componentSelected(false),
_renderDirtBackground(true), _renderDirtBackground(true),
_renderTopBorder(true), _renderTopBorder(true),
_renderBottomBorder(true), _renderBottomBorder(true),
_lastyoo(0), _lastyoo(0),
_yinertia(0), _yinertia(0),
_stickPixels(0), _stickPixels(0),
_lastxm(0), _lastxm(0),
_lastym(0) _lastym(0)
{ {
yo = yoo = 0;//(float)(-itemHeight) * 0.5f; yo = yoo = 0;//(float)(-itemHeight) * 0.5f;
_lastyoo = yoo; _lastyoo = yoo;
} }
void RolledSelectionListV::setRenderSelection( bool _renderSelection ) void RolledSelectionListV::setRenderSelection( bool _renderSelection )
{ {
renderSelection = _renderSelection; renderSelection = _renderSelection;
} }
void RolledSelectionListV::setComponentSelected(bool selected) { void RolledSelectionListV::setComponentSelected(bool selected) {
_componentSelected = selected; _componentSelected = selected;
} }
void RolledSelectionListV::setRenderHeader( bool _renderHeader, int _headerHeight ) void RolledSelectionListV::setRenderHeader( bool _renderHeader, int _headerHeight )
{ {
doRenderHeader = _renderHeader; doRenderHeader = _renderHeader;
headerHeight = _headerHeight; headerHeight = _headerHeight;
if (!doRenderHeader) { if (!doRenderHeader) {
headerHeight = 0; headerHeight = 0;
} }
} }
int RolledSelectionListV::getMaxPosition() int RolledSelectionListV::getMaxPosition()
{ {
return getNumberOfItems() * itemHeight + headerHeight; return getNumberOfItems() * itemHeight + headerHeight;
} }
int RolledSelectionListV::getItemAtPosition( int x, int y ) int RolledSelectionListV::getItemAtPosition( int x, int y )
{ {
int clickSlotPos = (int)(y - y0 - headerHeight + (int) yo - 4); int clickSlotPos = (int)(y - y0 - headerHeight + (int) yo - 4);
int isInsideX = x >= x0 && x <= x1; int isInsideX = x >= x0 && x <= x1;
return isInsideX? getItemAtYPositionRaw(clickSlotPos) : -1; return isInsideX? getItemAtYPositionRaw(clickSlotPos) : -1;
} }
int RolledSelectionListV::getItemAtYPositionRaw(int y) { int RolledSelectionListV::getItemAtYPositionRaw(int y) {
int slot = y / itemHeight; int slot = y / itemHeight;
bool isInsideX = slot >= 0 && y >= 0 && slot < getNumberOfItems(); bool isInsideX = slot >= 0 && y >= 0 && slot < getNumberOfItems();
return isInsideX? slot : -1; return isInsideX? slot : -1;
} }
bool RolledSelectionListV::capYPosition() bool RolledSelectionListV::capYPosition()
{ {
float max = getMaxPosition() - (y1 - y0 - 4); float max = getMaxPosition() - (y1 - y0 - 4);
if (max < 0) max /= 2; if (max < 0) max /= 2;
if (yo < 0) yo = 0; if (yo < 0) yo = 0;
if (yo > max) yo = max; if (yo > max) yo = max;
return false; return false;
/* /*
const float MinY = -itemHeight/2;//(float)(itemHeight-height)/2; const float MinY = -itemHeight/2;//(float)(itemHeight-height)/2;
const float MaxY = MinY + (getNumberOfItems()-1) * itemHeight; const float MaxY = MinY + (getNumberOfItems()-1) * itemHeight;
if (yo < MinY) { yo = MinY; yInertia = 0; return true; } if (yo < MinY) { yo = MinY; yInertia = 0; return true; }
if (yo > MaxY) { yo = MaxY; yInertia = 0; return true; } if (yo > MaxY) { yo = MaxY; yInertia = 0; return true; }
return false; return false;
*/ */
} }
void RolledSelectionListV::tick() { void RolledSelectionListV::tick() {
if (Mouse::isButtonDown(MouseAction::ACTION_LEFT)) if (Mouse::isButtonDown(MouseAction::ACTION_LEFT))
{ {
_yinertia = _lastyoo - yoo; _yinertia = _lastyoo - yoo;
} }
_lastyoo = yoo; _lastyoo = yoo;
//yInertia = Mth::absDecrease(yInertia, 1.0f, 0); //yInertia = Mth::absDecrease(yInertia, 1.0f, 0);
yoo = yo - yInertia; yoo = yo - yInertia;
//LOGI("tick: %f, %f, %f\n", yo, yInertia, _yinertia); //LOGI("tick: %f, %f, %f\n", yo, yInertia, _yinertia);
} }
float RolledSelectionListV::getPos(float alpha) { float RolledSelectionListV::getPos(float alpha) {
return yoo - yInertia * alpha; return yoo - yInertia * alpha;
} }
void RolledSelectionListV::render( int xm, int ym, float a ) void RolledSelectionListV::render( int xm, int ym, float a )
{ {
_lastxm = xm; _lastxm = xm;
_lastym = ym; _lastym = ym;
renderBackground(); renderBackground();
int itemCount = getNumberOfItems(); int itemCount = getNumberOfItems();
//float yy0 = height / 2.0f + 124; //float yy0 = height / 2.0f + 124;
//float yy1 = yy0 + 6; //float yy1 = yy0 + 6;
if (Mouse::isButtonDown(MouseAction::ACTION_LEFT)) { if (Mouse::isButtonDown(MouseAction::ACTION_LEFT)) {
touched(); touched();
//LOGI("DOWN ym: %d\n", ym); //LOGI("DOWN ym: %d\n", ym);
if (ym >= y0 && ym <= y1) { if (ym >= y0 && ym <= y1) {
if (dragState == NO_DRAG) { if (dragState == NO_DRAG) {
lastSelectionTime = getTimeMs(); lastSelectionTime = getTimeMs();
lastSelection = convertSelection( getItemAtPosition(width/2, ym), xm, ym ); lastSelection = convertSelection( getItemAtPosition(width/2, ym), xm, ym );
selectStart(lastSelection); selectStart(lastSelection);
//LOGI("Sel : %d\n", lastSelection); //LOGI("Sel : %d\n", lastSelection);
selectionY = ym; selectionY = ym;
_stickPixels = 10; _stickPixels = 10;
} }
else if (dragState >= 0) { else if (dragState >= 0) {
float delta = (ym - yDrag); float delta = (ym - yDrag);
float absDelta = Mth::abs(delta); float absDelta = Mth::abs(delta);
if (absDelta > _stickPixels) { if (absDelta > _stickPixels) {
_stickPixels = 0; _stickPixels = 0;
delta -= delta>0? _stickPixels : -_stickPixels; delta -= delta>0? _stickPixels : -_stickPixels;
} else { } else {
delta = 0; delta = 0;
_stickPixels -= absDelta; _stickPixels -= absDelta;
} }
yo -= delta; yo -= delta;
yoo = yo; yoo = yo;
} }
dragState = DRAG_NORMAL; dragState = DRAG_NORMAL;
} }
} else { } else {
if (dragState >= 0) { if (dragState >= 0) {
if (dragState >= 0) { if (dragState >= 0) {
yInertia = _yinertia < 0? Mth::Max(-10.0f, _yinertia) : Mth::Min(10.0f, _yinertia); yInertia = _yinertia < 0? Mth::Max(-10.0f, _yinertia) : Mth::Min(10.0f, _yinertia);
} }
// kill small inertia values when releasing scrollist // kill small inertia values when releasing scrollist
if (std::abs(yInertia) <= 2.0001f) { if (std::abs(yInertia) <= 2.0001f) {
yInertia = 0.0f; yInertia = 0.0f;
} }
if (std::abs(yInertia) <= 10 /*&& getTimeMs() - lastSelectionTime < 300 */) if (std::abs(yInertia) <= 10 /*&& getTimeMs() - lastSelectionTime < 300 */)
{ {
//float clickSlotPos = (ym - x0 - headerHeight + (int) yo - 4); //float clickSlotPos = (ym - x0 - headerHeight + (int) yo - 4);
int slot = convertSelection( getItemAtPosition(width/2, ym), xm, ym); int slot = convertSelection( getItemAtPosition(width/2, ym), xm, ym);
//LOGI("slot: %d, lt: %d. diff: %d - %d\n", slot, lastSelection, selectionX, xm); //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) if (xm >= x0 && xm <= x1 && slot >= 0 && slot == lastSelection && std::abs(selectionY - ym) < 10)
selectItem(slot, false); selectItem(slot, false);
} else { } else {
selectCancel(); selectCancel();
} }
} }
// if (slot >= 0 && std::abs(selectionX - xm) < itemWidth) // if (slot >= 0 && std::abs(selectionX - xm) < itemWidth)
// { // {
// bool doubleClick = false; // bool doubleClick = false;
// selectItem(slot, doubleClick); // selectItem(slot, doubleClick);
// //xInertia = 0.0f; // //xInertia = 0.0f;
// } // }
//} //}
dragState = NO_DRAG; dragState = NO_DRAG;
yo = getPos(a); yo = getPos(a);
} }
yDrag = (float)ym; yDrag = (float)ym;
evaluate(xm, ym); evaluate(xm, ym);
capYPosition(); capYPosition();
Tesselator& t = Tesselator::instance; Tesselator& t = Tesselator::instance;
const int HalfWidth = 48; const int HalfWidth = 48;
int rowX = (int)(width / 2 - HalfWidth + 8); int rowX = (int)(width / 2 - HalfWidth + 8);
int rowBaseY = (int)(y0 + 4 - (int) yo); int rowBaseY = (int)(y0 + 4 - (int) yo);
if (_renderDirtBackground) if (_renderDirtBackground)
renderDirtBackground(); renderDirtBackground();
if (getNumberOfItems() == 0) yo = 0; if (getNumberOfItems() == 0) yo = 0;
//int rowY = (int)(height / 2 - HalfHeight + 8); //int rowY = (int)(height / 2 - HalfHeight + 8);
if (doRenderHeader) { if (doRenderHeader) {
const int HalfWidth = 48; const int HalfWidth = 48;
int rowX = (int)(width / 2 - HalfWidth + 8); int rowX = (int)(width / 2 - HalfWidth + 8);
int rowBaseY = (int)(y0 + 4 - (int) yo); int rowBaseY = (int)(y0 + 4 - (int) yo);
renderHeader(rowX, rowBaseY, t); renderHeader(rowX, rowBaseY, t);
} }
onPreRender(); onPreRender();
for (int i = 0; i < itemCount; i++) { for (int i = 0; i < itemCount; i++) {
float y = (float)(rowBaseY + (i) * itemHeight + headerHeight); float y = (float)(rowBaseY + (i) * itemHeight + headerHeight);
float h = itemHeight - 4.0f; float h = itemHeight - 4.0f;
if (y > y1 || (y + h) < y0) { if (y > y1 || (y + h) < y0) {
continue; continue;
} }
if (renderSelection && isSelectedItem(i)) { if (renderSelection && isSelectedItem(i)) {
//float y0 = height / 2.0f - HalfHeight - 4; //float y0 = height / 2.0f - HalfHeight - 4;
//float y1 = height / 2.0f + HalfHeight - 4; //float y1 = height / 2.0f + HalfHeight - 4;
//glColor4f2(1, 1, 1, 1); //glColor4f2(1, 1, 1, 1);
//glDisable2(GL_TEXTURE_2D); //glDisable2(GL_TEXTURE_2D);
//int ew = 0; //int ew = 0;
//int color = 0x808080; //int color = 0x808080;
//if (_componentSelected) { //if (_componentSelected) {
// ew = 0; // ew = 0;
// color = 0x7F89BF; // color = 0x7F89BF;
//} //}
//t.begin(); //t.begin();
//t.color(color); //t.color(color);
//t.vertex(x - 2 - ew, y0 - ew, 0); //t.vertex(x - 2 - ew, y0 - ew, 0);
//t.vertex(x - 2 - ew, y1 + 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, y1 + ew, 0);
//t.vertex(x + h + 2 + ew, y0 - ew, 0); //t.vertex(x + h + 2 + ew, y0 - ew, 0);
//t.color(0x000000); //t.color(0x000000);
//t.vertex(x - 1, y0 + 1, 0); //t.vertex(x - 1, y0 + 1, 0);
//t.vertex(x - 1, y1 - 1, 0); //t.vertex(x - 1, y1 - 1, 0);
//t.vertex(x + h + 1, y1 - 1, 0); //t.vertex(x + h + 1, y1 - 1, 0);
//t.vertex(x + h + 1, y0 + 1, 0); //t.vertex(x + h + 1, y0 + 1, 0);
//t.draw(); //t.draw();
//glEnable2(GL_TEXTURE_2D); //glEnable2(GL_TEXTURE_2D);
} }
renderItem(i, rowX, (int)y, (int)h, t); renderItem(i, rowX, (int)y, (int)h, t);
} }
onPostRender(); onPostRender();
glDisable2(GL_DEPTH_TEST); glDisable2(GL_DEPTH_TEST);
if (_renderTopBorder) if (_renderTopBorder)
renderHoleBackground(0, y0, 255, 255); renderHoleBackground(0, y0, 255, 255);
if (_renderBottomBorder) if (_renderBottomBorder)
renderHoleBackground(y1, (float)height, 255, 255); renderHoleBackground(y1, (float)height, 255, 255);
renderForeground(); renderForeground();
//glEnable2(GL_BLEND); //glEnable2(GL_BLEND);
//glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glDisable2(GL_ALPHA_TEST); //glDisable2(GL_ALPHA_TEST);
//glShadeModel2(GL_SMOOTH); //glShadeModel2(GL_SMOOTH);
//glDisable2(GL_TEXTURE_2D); //glDisable2(GL_TEXTURE_2D);
//const int d = 4; //const int d = 4;
//t.begin(); //t.begin();
//t.color(0x000000, 0); //t.color(0x000000, 0);
//t.vertexUV(y0, x0 + d, 0, 0, 1); //t.vertexUV(y0, x0 + d, 0, 0, 1);
//t.vertexUV(y1, x0 + d, 0, 1, 1); //t.vertexUV(y1, x0 + d, 0, 1, 1);
//t.color(0x000000, 255); //t.color(0x000000, 255);
//t.vertexUV(y1, x0, 0, 1, 0); //t.vertexUV(y1, x0, 0, 1, 0);
//t.vertexUV(y0, x0, 0, 0, 0); //t.vertexUV(y0, x0, 0, 0, 0);
//t.draw(); //t.draw();
//t.begin(); //t.begin();
//t.color(0x000000, 255); //t.color(0x000000, 255);
//t.vertexUV(y0, x1, 0, 0, 1); //t.vertexUV(y0, x1, 0, 0, 1);
//t.vertexUV(y1, x1, 0, 1, 1); //t.vertexUV(y1, x1, 0, 1, 1);
//t.color(0x000000, 0); //t.color(0x000000, 0);
//t.vertexUV(y1, x1 - d, 0, 1, 0); //t.vertexUV(y1, x1 - d, 0, 1, 0);
//t.vertexUV(y0, x1 - d, 0, 0, 0); //t.vertexUV(y0, x1 - d, 0, 0, 0);
//t.draw(); //t.draw();
//renderDecorations(xm, ym); //renderDecorations(xm, ym);
//glEnable2(GL_TEXTURE_2D); //glEnable2(GL_TEXTURE_2D);
//glEnable2(GL_DEPTH_TEST); //glEnable2(GL_DEPTH_TEST);
//glShadeModel2(GL_FLAT); //glShadeModel2(GL_FLAT);
//glEnable2(GL_ALPHA_TEST); //glEnable2(GL_ALPHA_TEST);
//glDisable2(GL_BLEND); //glDisable2(GL_BLEND);
} }
void RolledSelectionListV::renderHoleBackground( /*float x0, float x1,*/ float y0, float y1, int a0, int a1 ) void RolledSelectionListV::renderHoleBackground( /*float x0, float x1,*/ float y0, float y1, int a0, int a1 )
{ {
Tesselator& t = Tesselator::instance; Tesselator& t = Tesselator::instance;
minecraft->textures->loadAndBindTexture("gui/background.png"); minecraft->textures->loadAndBindTexture("gui/background.png");
glColor4f2(1.0f, 1, 1, 1); glColor4f2(1.0f, 1, 1, 1);
float s = 32; float s = 32;
t.begin(); t.begin();
t.color(0x505050, a1); t.color(0x505050, a1);
t.vertexUV(0, y1, 0, 0, y1 / s); t.vertexUV(0, y1, 0, 0, y1 / s);
t.vertexUV((float)width, y1, 0, width / s, y1 / s); t.vertexUV((float)width, y1, 0, width / s, y1 / s);
t.color(0x505050, a0); t.color(0x505050, a0);
t.vertexUV((float)width, y0, 0, width / s, y0 / s); t.vertexUV((float)width, y0, 0, width / s, y0 / s);
t.vertexUV(0, y0, 0, 0, y0 / s); t.vertexUV(0, y0, 0, 0, y0 / s);
t.draw(); t.draw();
//printf("x, y, x1, y1: %d, %d, %d, %d\n", 0, (int)y0, width, (int)y1); //printf("x, y, x1, y1: %d, %d, %d, %d\n", 0, (int)y0, width, (int)y1);
} }
void RolledSelectionListV::touched() void RolledSelectionListV::touched()
{ {
} }
void RolledSelectionListV::evaluate(int xm, int ym) void RolledSelectionListV::evaluate(int xm, int ym)
{ {
if (std::abs(selectionY - ym) >= 10) { if (std::abs(selectionY - ym) >= 10) {
lastSelection = -1; lastSelection = -1;
selectCancel(); selectCancel();
} }
} }
void RolledSelectionListV::onPreRender() void RolledSelectionListV::onPreRender()
{ {
} }
void RolledSelectionListV::onPostRender() void RolledSelectionListV::onPostRender()
{ {
} }
void RolledSelectionListV::renderDirtBackground() void RolledSelectionListV::renderDirtBackground()
{ {
float by0 = _renderTopBorder? y0 : 0; float by0 = _renderTopBorder? y0 : 0;
float by1 = _renderBottomBorder? y1 : height; float by1 = _renderBottomBorder? y1 : height;
minecraft->textures->loadAndBindTexture("gui/background.png"); minecraft->textures->loadAndBindTexture("gui/background.png");
glColor4f2(1.0f, 1, 1, 1); glColor4f2(1.0f, 1, 1, 1);
float s = 32; float s = 32;
const float uvy = (float)((int) yo); const float uvy = (float)((int) yo);
Tesselator& t = Tesselator::instance; Tesselator& t = Tesselator::instance;
t.begin(); t.begin();
t.color(0x202020); t.color(0x202020);
t.vertexUV(x0, by1, 0, x0 / s, (by1+uvy) / s); t.vertexUV(x0, by1, 0, x0 / s, (by1+uvy) / s);
t.vertexUV(x1, by1, 0, x1 / 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(x1, by0, 0, x1 / s, (by0+uvy) / s);
t.vertexUV(x0, by0, 0, x0 / s, (by0+uvy) / s); t.vertexUV(x0, by0, 0, x0 / s, (by0+uvy) / s);
t.draw(); t.draw();
//LOGI("%f, %f - %f, %f\n", x0, by0, x1, by1); //LOGI("%f, %f - %f, %f\n", x0, by0, x1, by1);
} }

View File

@@ -1,94 +1,92 @@
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__RolledSelectionListV_H__ #pragma once
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__RolledSelectionListV_H__
#include "client/gui/GuiComponent.hpp"
#include "../GuiComponent.h" class Minecraft;
class Minecraft; class Tesselator;
class Tesselator;
class RolledSelectionListV : public GuiComponent
class RolledSelectionListV : public GuiComponent {
{ static const int NO_DRAG = -1;
static const int NO_DRAG = -1; static const int DRAG_OUTSIDE = -2;
static const int DRAG_OUTSIDE = -2; static const int DRAG_NORMAL = 0;
static const int DRAG_NORMAL = 0; public:
public: RolledSelectionListV(Minecraft* minecraft, int width, int height, int x0, int x1, int y0, int y1, int itemHeight);
RolledSelectionListV(Minecraft* minecraft, int width, int height, int x0, int x1, int y0, int y1, int itemHeight);
virtual int getItemAtPosition(int x, int y);
virtual int getItemAtPosition(int x, int y);
virtual bool capYPosition();
virtual bool capYPosition();
virtual void tick();
virtual void tick(); virtual void render(int xm, int ym, float a);
virtual void render(int xm, int ym, float a); virtual void renderHoleBackground(/*float x0, float x1,*/ float y0, float y1, int a0, int a1);
virtual void renderHoleBackground(/*float x0, float x1,*/ float y0, float y1, int a0, int a1); virtual void setRenderSelection(bool _renderSelection);
virtual void setRenderSelection(bool _renderSelection); virtual void setComponentSelected(bool selected);
virtual void setComponentSelected(bool selected); protected:
protected: void setRenderHeader(bool _renderHeader, int _headerHeight);
void setRenderHeader(bool _renderHeader, int _headerHeight);
virtual int getNumberOfItems() = 0;
virtual int getNumberOfItems() = 0;
virtual void selectStart(int item) {}
virtual void selectStart(int item) {} virtual void selectCancel() {}
virtual void selectCancel() {} virtual void selectItem(int item, bool doubleClick) = 0;
virtual void selectItem(int item, bool doubleClick) = 0; virtual bool isSelectedItem(int item) = 0;
virtual bool isSelectedItem(int item) = 0;
virtual int getMaxPosition();
virtual int getMaxPosition(); virtual float getPos(float alpha);
virtual float getPos(float alpha); virtual void touched();
virtual void touched();
virtual void renderItem(int i, int x, int y, int h, Tesselator& t) = 0;
virtual void renderItem(int i, int x, int y, int h, Tesselator& t) = 0; virtual void renderHeader(int x, int y, Tesselator& t) {}
virtual void renderHeader(int x, int y, Tesselator& t) {} virtual void renderBackground() = 0;
virtual void renderBackground() = 0; virtual void renderForeground() {}
virtual void renderForeground() {} virtual void renderDecorations(int mouseX, int mouseY) {}
virtual void renderDecorations(int mouseX, int mouseY) {}
virtual void clickedHeader(int headerMouseX, int headerMouseY) {}
virtual void clickedHeader(int headerMouseX, int headerMouseY) {} virtual int convertSelection(int item, int xm, int ym) { return item; }
virtual int convertSelection(int item, int xm, int ym) { return item; }
int getItemAtYPositionRaw(int y);
int getItemAtYPositionRaw(int y); void evaluate(int xm, int ym);
void evaluate(int xm, int ym); virtual void onPreRender();
virtual void onPreRender(); virtual void onPostRender();
virtual void onPostRender(); void renderDirtBackground();
void renderDirtBackground(); protected:
protected: Minecraft* minecraft;
Minecraft* minecraft;
float x0;
float x0; float x1;
float x1; int itemHeight;
int itemHeight; int width;
int width; int height;
int height; //private:
//private: float y0;
float y0; float y1;
float y1;
int dragState;
int dragState; float yDrag;
float yDrag; float yo;
float yo; float yoo;
float yoo; float yInertia;
float yInertia; float _yinertia;
float _yinertia;
int selectionY;
int selectionY; bool renderSelection;
bool renderSelection; bool _componentSelected;
bool _componentSelected;
bool _renderDirtBackground;
bool _renderDirtBackground; bool _renderTopBorder;
bool _renderTopBorder; bool _renderBottomBorder;
bool _renderBottomBorder;
int _lastxm;
int _lastxm; int _lastym;
int _lastym; private:
private: int headerHeight;
int headerHeight; bool doRenderHeader;
bool doRenderHeader; long lastSelectionTime;
long lastSelectionTime; int lastSelection;
int lastSelection;
float _lastyoo;
float _lastyoo;
float _stickPixels;
float _stickPixels; };
};
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__RolledSelectionListV_H__*/

View File

@@ -1,296 +1,296 @@
#include "ScrolledSelectionList.h" #include "ScrolledSelectionList.hpp"
#include "../../Minecraft.h" #include "client/Minecraft.hpp"
#include "../../renderer/Tesselator.h" #include "client/renderer/Tesselator.hpp"
#include "../../renderer/gles.h" #include "client/renderer/gles.hpp"
#include "../../../platform/input/Mouse.h" #include "platform/input/Mouse.hpp"
#include "../../renderer/Textures.h" #include "client/renderer/Textures.hpp"
static int Abs(int d) { static int Abs(int d) {
return d >= 0? d : -d; return d >= 0? d : -d;
} }
ScrolledSelectionList::ScrolledSelectionList( Minecraft* _minecraft, int _width, int _height, int _y0, int _y1, int _itemHeight ) ScrolledSelectionList::ScrolledSelectionList( Minecraft* _minecraft, int _width, int _height, int _y0, int _y1, int _itemHeight )
: minecraft(_minecraft), : minecraft(_minecraft),
width(_width), width(_width),
height(_height), height(_height),
y0((float)_y0), y0((float)_y0),
y1((float)_y1), y1((float)_y1),
itemHeight(_itemHeight), itemHeight(_itemHeight),
x0(0.0f), x0(0.0f),
x1((float)_width), x1((float)_width),
selectionY(-1), selectionY(-1),
lastSelectionTime(0), lastSelectionTime(0),
renderSelection(true), renderSelection(true),
doRenderHeader(false), doRenderHeader(false),
headerHeight(0), headerHeight(0),
dragState(DRAG_OUTSIDE), dragState(DRAG_OUTSIDE),
yDrag(0.0f), yDrag(0.0f),
yo(0.0f), yo(0.0f),
yInertia(0.0f) yInertia(0.0f)
{ {
} }
void ScrolledSelectionList::setRenderSelection( bool _renderSelection ) void ScrolledSelectionList::setRenderSelection( bool _renderSelection )
{ {
renderSelection = _renderSelection; renderSelection = _renderSelection;
} }
void ScrolledSelectionList::setRenderHeader( bool _renderHeader, int _headerHeight ) void ScrolledSelectionList::setRenderHeader( bool _renderHeader, int _headerHeight )
{ {
doRenderHeader = _renderHeader; doRenderHeader = _renderHeader;
headerHeight = _headerHeight; headerHeight = _headerHeight;
if (!doRenderHeader) { if (!doRenderHeader) {
headerHeight = 0; headerHeight = 0;
} }
} }
int ScrolledSelectionList::getMaxPosition() int ScrolledSelectionList::getMaxPosition()
{ {
return getNumberOfItems() * itemHeight + headerHeight; return getNumberOfItems() * itemHeight + headerHeight;
} }
int ScrolledSelectionList::getItemAtPosition( int x, int y ) int ScrolledSelectionList::getItemAtPosition( int x, int y )
{ {
int x0 = width / 2 - (92 + 16 + 2); int x0 = width / 2 - (92 + 16 + 2);
int x1 = width / 2 + (92 + 16 + 2); int x1 = width / 2 + (92 + 16 + 2);
int clickSlotPos = (int)(y - y0 - headerHeight + (int) yo - 4); int clickSlotPos = (int)(y - y0 - headerHeight + (int) yo - 4);
int slot = clickSlotPos / itemHeight; int slot = clickSlotPos / itemHeight;
if (x >= x0 && x <= x1 && slot >= 0 && clickSlotPos >= 0 && slot < getNumberOfItems()) { if (x >= x0 && x <= x1 && slot >= 0 && clickSlotPos >= 0 && slot < getNumberOfItems()) {
return slot; return slot;
} }
return -1; return -1;
} }
void ScrolledSelectionList::capYPosition() void ScrolledSelectionList::capYPosition()
{ {
float max = getMaxPosition() - (y1 - y0 - 4); float max = getMaxPosition() - (y1 - y0 - 4);
if (max < 0) max /= 2; if (max < 0) max /= 2;
if (yo < 0) yo = 0; if (yo < 0) yo = 0;
if (yo > max) yo = max; if (yo > max) yo = max;
} }
void ScrolledSelectionList::render( int xm, int ym, float a ) void ScrolledSelectionList::render( int xm, int ym, float a )
{ {
renderBackground(); renderBackground();
int itemCount = getNumberOfItems(); int itemCount = getNumberOfItems();
//float xx0 = width / 2.0f + 124; //float xx0 = width / 2.0f + 124;
//float xx1 = xx0 + 6; //float xx1 = xx0 + 6;
if (Mouse::isButtonDown(MouseAction::ACTION_LEFT)) { if (Mouse::isButtonDown(MouseAction::ACTION_LEFT)) {
//LOGI("DOWN ym: %d\n", ym); //LOGI("DOWN ym: %d\n", ym);
if (ym >= y0 && ym <= y1 && ym != ignoreY) { if (ym >= y0 && ym <= y1 && ym != ignoreY) {
if (dragState == NO_DRAG) { if (dragState == NO_DRAG) {
dragState = DRAG_SKIP; dragState = DRAG_SKIP;
} }
else if (dragState >= 0) else if (dragState >= 0)
{ {
if (dragState == DRAG_SKIP) if (dragState == DRAG_SKIP)
{ {
lastSelectionTime = getTimeMs(); lastSelectionTime = getTimeMs();
selectionY = ym; selectionY = ym;
} }
else if (dragState == DRAG_NORMAL) else if (dragState == DRAG_NORMAL)
{ {
yo -= (ym - yDrag); yo -= (ym - yDrag);
yInertia += (float)(ym - yDrag); yInertia += (float)(ym - yDrag);
} }
dragState = DRAG_NORMAL; dragState = DRAG_NORMAL;
} }
ignoreY = -1; ignoreY = -1;
} }
} else { } else {
if (dragState != NO_DRAG) if (dragState != NO_DRAG)
{ {
//LOGI("UP ym: %d\n", ym); //LOGI("UP ym: %d\n", ym);
} }
//ignoreY = ym; //ignoreY = ym;
// kill small inertia values when releasing scrollist // kill small inertia values when releasing scrollist
if (dragState >= 0 && std::abs(yInertia) < 2) if (dragState >= 0 && std::abs(yInertia) < 2)
{ {
yInertia = 0.0f; yInertia = 0.0f;
} }
if (dragState >= 0 && getTimeMs() - lastSelectionTime < 300) if (dragState >= 0 && getTimeMs() - lastSelectionTime < 300)
{ {
float clickSlotPos = (ym - y0 - headerHeight + (int) yo - 4); float clickSlotPos = (ym - y0 - headerHeight + (int) yo - 4);
int slot = (int)clickSlotPos / itemHeight; int slot = (int)clickSlotPos / itemHeight;
if (slot >= 0 && Abs(selectionY - ym) < itemHeight) if (slot >= 0 && Abs(selectionY - ym) < itemHeight)
{ {
bool doubleClick = false; bool doubleClick = false;
selectItem(slot, doubleClick); selectItem(slot, doubleClick);
yInertia = 0.0f; yInertia = 0.0f;
} }
} }
dragState = NO_DRAG; dragState = NO_DRAG;
yo -= yInertia; yo -= yInertia;
} }
yInertia = yInertia * .75f; yInertia = yInertia * .75f;
yDrag = (float)ym; yDrag = (float)ym;
capYPosition(); capYPosition();
Tesselator& t = Tesselator::instance; Tesselator& t = Tesselator::instance;
renderDirtBackground(); renderDirtBackground();
int rowX = (int)(width / 2 - 92 - 16); int rowX = (int)(width / 2 - 92 - 16);
int rowBaseY = (int)(y0 + 4 - (int) yo); int rowBaseY = (int)(y0 + 4 - (int) yo);
if (doRenderHeader) { if (doRenderHeader) {
renderHeader(rowX, rowBaseY, t); renderHeader(rowX, rowBaseY, t);
} }
for (int i = 0; i < itemCount; i++) { for (int i = 0; i < itemCount; i++) {
float y = (float)(rowBaseY + (i) * itemHeight + headerHeight); float y = (float)(rowBaseY + (i) * itemHeight + headerHeight);
float h = itemHeight - 4.0f; float h = itemHeight - 4.0f;
if (y > y1 || (y + h) < y0) { if (y > y1 || (y + h) < y0) {
continue; continue;
} }
if (renderSelection && isSelectedItem(i)) { if (renderSelection && isSelectedItem(i)) {
float x0 = width / 2.0f - (92 + 16 + 2); float x0 = width / 2.0f - (92 + 16 + 2);
float x1 = width / 2.0f + (92 + 16 + 2); float x1 = width / 2.0f + (92 + 16 + 2);
glColor4f2(1, 1, 1, 1); glColor4f2(1, 1, 1, 1);
glDisable2(GL_TEXTURE_2D); glDisable2(GL_TEXTURE_2D);
t.begin(); t.begin();
t.color(0x808080); t.color(0x808080);
t.vertexUV(x0, y + h + 2, 0, 0, 1); t.vertexUV(x0, y + h + 2, 0, 0, 1);
t.vertexUV(x1, y + h + 2, 0, 1, 1); t.vertexUV(x1, y + h + 2, 0, 1, 1);
t.vertexUV(x1, y - 2, 0, 1, 0); t.vertexUV(x1, y - 2, 0, 1, 0);
t.vertexUV(x0, y - 2, 0, 0, 0); t.vertexUV(x0, y - 2, 0, 0, 0);
t.color(0x000000); t.color(0x000000);
t.vertexUV(x0 + 1, y + h + 1, 0, 0, 1); 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 + h + 1, 0, 1, 1);
t.vertexUV(x1 - 1, y - 1, 0, 1, 0); t.vertexUV(x1 - 1, y - 1, 0, 1, 0);
t.vertexUV(x0 + 1, y - 1, 0, 0, 0); t.vertexUV(x0 + 1, y - 1, 0, 0, 0);
t.draw(); t.draw();
glEnable2(GL_TEXTURE_2D); glEnable2(GL_TEXTURE_2D);
} }
renderItem(i, rowX, (int)y, (int)h, t); renderItem(i, rowX, (int)y, (int)h, t);
} }
glDisable2(GL_DEPTH_TEST); glDisable2(GL_DEPTH_TEST);
int d = 4; int d = 4;
renderHoleBackground(0, y0, 255, 255); renderHoleBackground(0, y0, 255, 255);
renderHoleBackground(y1, (float)height, 255, 255); renderHoleBackground(y1, (float)height, 255, 255);
glEnable2(GL_BLEND); glEnable2(GL_BLEND);
glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable2(GL_ALPHA_TEST); glDisable2(GL_ALPHA_TEST);
glShadeModel2(GL_SMOOTH); glShadeModel2(GL_SMOOTH);
glDisable2(GL_TEXTURE_2D); glDisable2(GL_TEXTURE_2D);
t.begin(); t.begin();
t.color(0x000000, 0); t.color(0x000000, 0);
t.vertexUV(x0, y0 + d, 0, 0, 1); t.vertexUV(x0, y0 + d, 0, 0, 1);
t.vertexUV(x1, y0 + d, 0, 1, 1); t.vertexUV(x1, y0 + d, 0, 1, 1);
t.color(0x000000, 255); t.color(0x000000, 255);
t.vertexUV(x1, y0, 0, 1, 0); t.vertexUV(x1, y0, 0, 1, 0);
t.vertexUV(x0, y0, 0, 0, 0); t.vertexUV(x0, y0, 0, 0, 0);
t.draw(); t.draw();
t.begin(); t.begin();
t.color(0x000000, 255); t.color(0x000000, 255);
t.vertexUV(x0, y1, 0, 0, 1); t.vertexUV(x0, y1, 0, 0, 1);
t.vertexUV(x1, y1, 0, 1, 1); t.vertexUV(x1, y1, 0, 1, 1);
t.color(0x000000, 0); t.color(0x000000, 0);
t.vertexUV(x1, y1 - d, 0, 1, 0); t.vertexUV(x1, y1 - d, 0, 1, 0);
t.vertexUV(x0, y1 - d, 0, 0, 0); t.vertexUV(x0, y1 - d, 0, 0, 0);
t.draw(); t.draw();
// { // {
// float max = getMaxPosition() - (y1 - y0 - 4); // float max = getMaxPosition() - (y1 - y0 - 4);
// if (max > 0) { // if (max > 0) {
// float barHeight = (y1 - y0) * (y1 - y0) / (getMaxPosition()); // float barHeight = (y1 - y0) * (y1 - y0) / (getMaxPosition());
// if (barHeight < 32) barHeight = 32; // if (barHeight < 32) barHeight = 32;
// if (barHeight > (y1 - y0 - 8)) barHeight = (y1 - y0 - 8); // if (barHeight > (y1 - y0 - 8)) barHeight = (y1 - y0 - 8);
// //
// float yp = (int) yo * (y1 - y0 - barHeight) / max + y0; // float yp = (int) yo * (y1 - y0 - barHeight) / max + y0;
// if (yp < y0) yp = y0; // if (yp < y0) yp = y0;
// //
// t.begin(); // t.begin();
// t.color(0x000000, 255); // t.color(0x000000, 255);
// t.vertexUV(xx0, y1, 0.0f, 0.0f, 1.0f); // t.vertexUV(xx0, y1, 0.0f, 0.0f, 1.0f);
// t.vertexUV(xx1, y1, 0.0f, 1.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(xx1, y0, 0.0f, 1.0f, 0.0f);
// t.vertexUV(xx0, y0, 0.0f, 0.0f, 0.0f); // t.vertexUV(xx0, y0, 0.0f, 0.0f, 0.0f);
// t.draw(); // t.draw();
// //
// t.begin(); // t.begin();
// t.color(0x808080, 255); // t.color(0x808080, 255);
// t.vertexUV(xx0, yp + barHeight, 0, 0, 1); // t.vertexUV(xx0, yp + barHeight, 0, 0, 1);
// t.vertexUV(xx1, yp + barHeight, 0, 1, 1); // t.vertexUV(xx1, yp + barHeight, 0, 1, 1);
// t.vertexUV(xx1, yp, 0, 1, 0); // t.vertexUV(xx1, yp, 0, 1, 0);
// t.vertexUV(xx0, yp, 0, 0, 0); // t.vertexUV(xx0, yp, 0, 0, 0);
// t.draw(); // t.draw();
// //
// t.begin(); // t.begin();
// t.color(0xc0c0c0, 255); // t.color(0xc0c0c0, 255);
// t.vertexUV(xx0, yp + barHeight - 1, 0, 0, 1); // t.vertexUV(xx0, yp + barHeight - 1, 0, 0, 1);
// t.vertexUV(xx1 - 1, yp + barHeight - 1, 0, 1, 1); // t.vertexUV(xx1 - 1, yp + barHeight - 1, 0, 1, 1);
// t.vertexUV(xx1 - 1, yp, 0, 1, 0); // t.vertexUV(xx1 - 1, yp, 0, 1, 0);
// t.vertexUV(xx0, yp, 0, 0, 0); // t.vertexUV(xx0, yp, 0, 0, 0);
// t.draw(); // t.draw();
// } // }
// } // }
renderDecorations(xm, ym); renderDecorations(xm, ym);
glEnable2(GL_TEXTURE_2D); glEnable2(GL_TEXTURE_2D);
glEnable2(GL_DEPTH_TEST); glEnable2(GL_DEPTH_TEST);
glShadeModel2(GL_FLAT); glShadeModel2(GL_FLAT);
glEnable2(GL_ALPHA_TEST); glEnable2(GL_ALPHA_TEST);
glDisable2(GL_BLEND); glDisable2(GL_BLEND);
} }
void ScrolledSelectionList::renderHoleBackground( float y0, float y1, int a0, int a1 ) void ScrolledSelectionList::renderHoleBackground( float y0, float y1, int a0, int a1 )
{ {
Tesselator& t = Tesselator::instance; Tesselator& t = Tesselator::instance;
minecraft->textures->loadAndBindTexture("gui/background.png"); minecraft->textures->loadAndBindTexture("gui/background.png");
glColor4f2(1.0f, 1, 1, 1); glColor4f2(1.0f, 1, 1, 1);
float s = 32; float s = 32;
t.begin(); t.begin();
t.color(0x505050, a1); t.color(0x505050, a1);
t.vertexUV(0, y1, 0, 0, y1 / s); t.vertexUV(0, y1, 0, 0, y1 / s);
t.vertexUV((float)width, y1, 0, width / s, y1 / s); t.vertexUV((float)width, y1, 0, width / s, y1 / s);
t.color(0x505050, a0); t.color(0x505050, a0);
t.vertexUV((float)width, y0, 0, width / s, y0 / s); t.vertexUV((float)width, y0, 0, width / s, y0 / s);
t.vertexUV(0, y0, 0, 0, y0 / s); t.vertexUV(0, y0, 0, 0, y0 / s);
t.draw(); t.draw();
} }
void ScrolledSelectionList::renderDirtBackground() void ScrolledSelectionList::renderDirtBackground()
{ {
Tesselator& t = Tesselator::instance; Tesselator& t = Tesselator::instance;
minecraft->textures->loadAndBindTexture("gui/background.png"); minecraft->textures->loadAndBindTexture("gui/background.png");
glColor4f2(1.0f, 1, 1, 1); glColor4f2(1.0f, 1, 1, 1);
float s = 32; float s = 32;
t.begin(); t.begin();
t.color(0x202020); t.color(0x202020);
t.vertexUV(x0, y1, 0, x0 / s, (y1 + (int) yo) / s); 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, y1, 0, x1 / s, (y1 + (int) yo) / s);
t.vertexUV(x1, y0, 0, x1 / s, (y0 + (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.vertexUV(x0, y0, 0, x0 / s, (y0 + (int) yo) / s);
t.draw(); t.draw();
} }

View File

@@ -1,69 +1,67 @@
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__ScrolledSelectionList_H__ #pragma once
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__ScrolledSelectionList_H__
#include "client/gui/GuiComponent.hpp"
#include "../GuiComponent.h" class Minecraft;
class Minecraft; class Tesselator;
class Tesselator;
class ScrolledSelectionList : public GuiComponent
class ScrolledSelectionList : public GuiComponent {
{ static const int NO_DRAG = -1;
static const int NO_DRAG = -1; static const int DRAG_OUTSIDE = -2;
static const int DRAG_OUTSIDE = -2; static const int DRAG_NORMAL = 0;
static const int DRAG_NORMAL = 0; static const int DRAG_SKIP = 1; // special case to fix android jump bug
static const int DRAG_SKIP = 1; // special case to fix android jump bug public:
public: ScrolledSelectionList(Minecraft* _minecraft, int _width, int _height, int _y0, int _y1, int _itemHeight);
ScrolledSelectionList(Minecraft* _minecraft, int _width, int _height, int _y0, int _y1, int _itemHeight);
virtual void setRenderSelection(bool _renderSelection);
virtual void setRenderSelection(bool _renderSelection); protected:
protected: void setRenderHeader(bool _renderHeader, int _headerHeight);
void setRenderHeader(bool _renderHeader, int _headerHeight);
virtual int getNumberOfItems() = 0;
virtual int getNumberOfItems() = 0;
virtual void selectItem(int item, bool doubleClick) = 0;
virtual void selectItem(int item, bool doubleClick) = 0; virtual bool isSelectedItem(int item) = 0;
virtual bool isSelectedItem(int item) = 0;
virtual int getMaxPosition();
virtual int getMaxPosition();
virtual void renderItem(int i, int x, int y, int h, Tesselator& t) = 0;
virtual void renderItem(int i, int x, int y, int h, Tesselator& t) = 0; virtual void renderHeader(int x, int y, Tesselator& t) {}
virtual void renderHeader(int x, int y, Tesselator& t) {} virtual void renderBackground() = 0;
virtual void renderBackground() = 0; virtual void renderDecorations(int mouseX, int mouseY) {}
virtual void renderDecorations(int mouseX, int mouseY) {}
virtual void clickedHeader(int headerMouseX, int headerMouseY) {}
virtual void clickedHeader(int headerMouseX, int headerMouseY) {} public:
public: virtual int getItemAtPosition(int x, int y);
virtual int getItemAtPosition(int x, int y);
virtual void capYPosition();
virtual void capYPosition();
virtual void render(int xm, int ym, float a);
virtual void render(int xm, int ym, float a); virtual void renderHoleBackground(float y0, float y1, int a0, int a1);
virtual void renderHoleBackground(float y0, float y1, int a0, int a1); void renderDirtBackground();
void renderDirtBackground(); protected:
protected: Minecraft* minecraft;
Minecraft* minecraft;
float y0;
float y0; float y1;
float y1; int itemHeight;
int itemHeight; private:
private: int width;
int width; int height;
int height; float x1;
float x1; float x0;
float x0;
int ignoreY; // new attempt to fix android jump bug
int ignoreY; // new attempt to fix android jump bug int dragState;
int dragState; float yDrag;
float yDrag; float yo;
float yo; float yInertia;
float yInertia;
int selectionY;
int selectionY; long lastSelectionTime;
long lastSelectionTime;
bool renderSelection;
bool renderSelection; bool doRenderHeader;
bool doRenderHeader; int headerHeight;
int headerHeight; };
};
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__ScrolledSelectionList_H__*/

File diff suppressed because it is too large Load Diff

View File

@@ -1,203 +1,201 @@
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__ScrollingPane_H__ #pragma once
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__ScrollingPane_H__
#include "client/gui/GuiComponent.hpp"
#include "../GuiComponent.h" #include "ImageButton.hpp"
#include "ImageButton.h" #include "client/player/input/touchscreen/TouchAreaModel.hpp"
#include "../../player/input/touchscreen/TouchAreaModel.h" #include "world/phys/Vec3.hpp"
#include "../../../world/phys/Vec3.h" #include "client/Timer.hpp"
#include "../../Timer.h"
enum ScrollingPaneFlags {
enum ScrollingPaneFlags { SF_LockX = 1 << 0,
SF_LockX = 1 << 0, SF_LockY = 1 << 1,
SF_LockY = 1 << 1, SF_WrapX = 1 << 2,
SF_WrapX = 1 << 2, SF_WrapY = 1 << 3,
SF_WrapY = 1 << 3, SF_HardLimits = 1 << 4,
SF_HardLimits = 1 << 4, SF_MultiSelect = 1 << 5,
SF_MultiSelect = 1 << 5, //SF_Snap = 1 << 6,
//SF_Snap = 1 << 6, //SF_CustomSnap = 1 << 7,
//SF_CustomSnap = 1 << 7, //SF_Scissor = 1 << 8,
//SF_Scissor = 1 << 8, SF_ShowScrollbar= 1 << 9,
SF_ShowScrollbar= 1 << 9, SF_NoHoldSelect = 1 << 10
SF_NoHoldSelect = 1 << 10 };
};
typedef struct ScrollBar {
typedef struct ScrollBar { ScrollBar()
ScrollBar() : alpha(0),
: alpha(0), fading(-1)
fading(-1) {}
{} float x;
float x; float y;
float y; float w;
float w; float h;
float h; //bool visible;
//bool visible; float alpha;
float alpha; int fading;
int fading; } ScrollBar;
} ScrollBar;
class ScrollingPane: public GuiComponent {
class ScrollingPane: public GuiComponent { public:
public: typedef struct GridItem {
typedef struct GridItem { int id;
int id; int x, y;
int x, y; // The GUI coordinates comes in (xf, yf)
// The GUI coordinates comes in (xf, yf) float xf, yf;
float xf, yf; bool selected;
bool selected; } GridItem;
} GridItem;
ScrollingPane(int flags, const IntRectangle& boundingBox, const IntRectangle& itemRect, int columns, int numItems, float screenScale = 1.0f, const IntRectangle& itemBoundingRect = IntRectangle(0,0,0,0));
ScrollingPane(int flags, const IntRectangle& boundingBox, const IntRectangle& itemRect, int columns, int numItems, float screenScale = 1.0f, const IntRectangle& itemBoundingRect = IntRectangle(0,0,0,0)); ~ScrollingPane();
~ScrollingPane(); //void init(Minecraft*, int width, int height);
//void init(Minecraft*, int width, int height); void tick();
void tick(); void render(int xm, int ym, float alpha);
void render(int xm, int ym, float alpha);
// scroll the content by the given amount (dx horizontal, dy vertical)
// scroll the content by the given amount (dx horizontal, dy vertical) // positive values move content downward/rightward
// positive values move content downward/rightward void scrollBy(float dx, float dy);
void scrollBy(float dx, float dy);
bool getGridItemFor_slow(int itemIndex, GridItem& out);
bool getGridItemFor_slow(int itemIndex, GridItem& out);
void setSelected(int id, bool selected);
void setSelected(int id, bool selected);
// This function is called with all visible GridItems. The base
// This function is called with all visible GridItems. The base // implementation just dispatches each item to renderItem in y,x order
// implementation just dispatches each item to renderItem in y,x order virtual void renderBatch(std::vector<GridItem>& items, float alpha);
virtual void renderBatch(std::vector<GridItem>& items, float alpha); virtual void renderItem(GridItem& item, float alpha);
virtual void renderItem(GridItem& item, float alpha);
//void render(int xx, int yy);
//void render(int xx, int yy); bool queryHoldTime(int* gridId, int* heldMs);
bool queryHoldTime(int* gridId, int* heldMs);
protected:
protected: GridItem getItemForPos(float x, float y, bool isScreenPos);
GridItem getItemForPos(float x, float y, bool isScreenPos); void handleUserInput();
void handleUserInput(); void addDeltaPos(float x, float y, float dt, int z);
void addDeltaPos(float x, float y, float dt, int z);
void translate(float xo, float yo);
void translate(float xo, float yo);
int flags;
int flags;
int columns;
int columns; int rows;
int rows; int numItems;
int numItems;
int px, py;
int px, py; float fpx, fpy;
float fpx, fpy;
float screenScale;
float screenScale; float invScreenScale;
float invScreenScale; //bool hasItemBounding;
//bool hasItemBounding;
IntRectangle bbox;
IntRectangle bbox; IntRectangle itemRect;
IntRectangle itemRect; IntRectangle itemBbox;
IntRectangle itemBbox; RectangleArea area;
RectangleArea area; RectangleArea bboxArea;
RectangleArea bboxArea;
// Dragging info
// Dragging info std::vector<float> dragDeltas;
std::vector<float> dragDeltas; int dragState;
int dragState; Vec3 dragBeginPos;
Vec3 dragBeginPos; Vec3 dragBeginScreenPos;
Vec3 dragBeginScreenPos; int dragTicks;
int dragTicks; float dragLastDeltaTimeStamp;
float dragLastDeltaTimeStamp; Vec3 dragLastPos;
Vec3 dragLastPos;
float dx, dy;
float dx, dy; float friction;
float friction;
float dstx, dsty;
float dstx, dsty;
// Rewrite
// Rewrite bool dragging; //!
bool dragging; //! bool decelerating;
bool decelerating; bool tracking; //!
bool tracking; //!
bool pagingEnabled; //!
bool pagingEnabled; //!
Vec3 _contentOffset; //!
Vec3 _contentOffset; //! Vec3 _contentOffsetBeforeDeceleration; //*
Vec3 _contentOffsetBeforeDeceleration; //*
int lastEventTime; //<
int lastEventTime; //<
Vec3 decelerationVelocity; //*
Vec3 decelerationVelocity; //* Vec3 minDecelerationPoint; //*
Vec3 minDecelerationPoint; //* Vec3 maxDecelerationPoint; //*
Vec3 maxDecelerationPoint; //*
float penetrationDeceleration; //<
float penetrationDeceleration; //< float penetrationAcceleration; //<
float penetrationAcceleration; //<
Vec3 minPoint; //*
Vec3 minPoint; //* Vec3 startPosition; //*
Vec3 startPosition; //* Vec3 startTouchPosition; //*
Vec3 startTouchPosition; //* Vec3 startTimePosition; //*
Vec3 startTimePosition; //*
bool wasDeceleratingWhenTouchesBegan; //*
bool wasDeceleratingWhenTouchesBegan; //* bool firstDrag; //<
bool firstDrag; //<
float startTime; //<
float startTime; //< //float startTime
//float startTime
IntRectangle size;
IntRectangle size; int lastFrame;
int lastFrame;
bool _scrollEnabled; //!
bool _scrollEnabled; //! bool touchesHaveMoved; //*
bool touchesHaveMoved; //*
virtual void didEndDragging() {}
virtual void didEndDragging() {} virtual void didEndDecelerating() {}
virtual void didEndDecelerating() {} virtual void willBeginDecelerating() {}
virtual void willBeginDecelerating() {} virtual void willBeginDragging() {}
virtual void willBeginDragging() {}
int te_moved,
int te_moved, te_ended,
te_ended, te_highlight;
te_highlight; int highlightTimer;
int highlightTimer; int highlightStarted;
int highlightStarted; GridItem highlightItem;
GridItem highlightItem;
bool* selected;
bool* selected; int selectedId;
int selectedId;
ScrollBar vScroll, hScroll;
ScrollBar vScroll, hScroll;
IntRectangle adjustedContentSize;
IntRectangle adjustedContentSize; void touchesBegan(float x, float y, int t);
void touchesBegan(float x, float y, int t); void touchesMoved(float x, float y, int t);
void touchesMoved(float x, float y, int t); void touchesEnded(float x, float y, int t);
void touchesEnded(float x, float y, int t); void touchesCancelled(float x, float y, int t);
void touchesCancelled(float x, float y, int t); void beginTracking(float x, float y, int t);
void beginTracking(float x, float y, int t); void onHoldItem();
void onHoldItem();
void _onSelect( int id );
void _onSelect( int id ); virtual bool onSelect(int gridId, bool selected);
virtual bool onSelect(int gridId, bool selected);
Vec3& contentOffset();
Vec3& contentOffset();
void startDecelerationAnimation(bool force);
void startDecelerationAnimation(bool force); void stopDecelerationAnimation();
void stopDecelerationAnimation(); void stepThroughDecelerationAnimation(bool f);
void stepThroughDecelerationAnimation(bool f);
void setContentOffset(float x, float y);
void setContentOffset(float x, float y); void setContentOffset(Vec3 a);
void setContentOffset(Vec3 a); void setContentOffsetWithAnimation(Vec3 b, bool doScroll);
void setContentOffsetWithAnimation(Vec3 b, bool doScroll); void snapContentOffsetToBounds(bool snap); //*
void snapContentOffsetToBounds(bool snap); //* void adjustContentSize();
void adjustContentSize(); //TouchAreaModel _areaModel;
//TouchAreaModel _areaModel;
bool isAllSet(int flag) { return (flags & flag) == flag; }
bool isAllSet(int flag) { return (flags & flag) == flag; } bool isSet(int flag) { return (flags & flag) != 0; }
bool isSet(int flag) { return (flags & flag) != 0; } bool isNotSet(int flag) { return !isSet(flag); }
bool isNotSet(int flag) { return !isSet(flag); }
void updateHorizontalScrollIndicator();
void updateHorizontalScrollIndicator(); void updateVerticalScrollIndicator();
void updateVerticalScrollIndicator(); void hideScrollIndicators(); //*
void hideScrollIndicators(); //* void updateScrollFade( ScrollBar& vScroll );
void updateScrollFade( ScrollBar& vScroll ); private:
private: Timer _timer;
Timer _timer; bool _doStepTimer;
bool _doStepTimer; bool _wasDown;
bool _wasDown; float _lx;
float _lx; float _ly;
float _ly; };
};
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__ScrollingPane_H__*/

View File

@@ -1,94 +1,94 @@
#include "Slider.h" #include "Slider.hpp"
#include "../../Minecraft.h" #include "client/Minecraft.hpp"
#include "../../renderer/Textures.h" #include "client/renderer/Textures.hpp"
#include "../Screen.h" #include "client/gui/Screen.hpp"
#include "../../../locale/I18n.h" #include "locale/I18n.hpp"
#include "../../../util/Mth.h" #include "util/Mth.hpp"
#include <algorithm> #include <algorithm>
#include <assert.h> #include <assert.h>
Slider::Slider(OptionId optId) : m_mouseDownOnElement(false), m_optId(optId), m_numSteps(0) {} Slider::Slider(OptionId optId) : m_mouseDownOnElement(false), m_optId(optId), m_numSteps(0) {}
void Slider::render( Minecraft* minecraft, int xm, int ym ) { void Slider::render( Minecraft* minecraft, int xm, int ym ) {
int xSliderStart = x + 5; int xSliderStart = x + 5;
int xSliderEnd = x + width - 5; int xSliderEnd = x + width - 5;
int ySliderStart = y + 6; int ySliderStart = y + 6;
int ySliderEnd = y + 9; int ySliderEnd = y + 9;
int handleSizeX = 9; int handleSizeX = 9;
int handleSizeY = 15; int handleSizeY = 15;
int barWidth = xSliderEnd - xSliderStart; int barWidth = xSliderEnd - xSliderStart;
//fill(x, y + 8, x + (int)(width * percentage), y + height, 0xffff00ff); //fill(x, y + 8, x + (int)(width * percentage), y + height, 0xffff00ff);
fill(xSliderStart, ySliderStart, xSliderEnd, ySliderEnd, 0xff606060); fill(xSliderStart, ySliderStart, xSliderEnd, ySliderEnd, 0xff606060);
if (m_numSteps > 2) { if (m_numSteps > 2) {
int stepDistance = barWidth / (m_numSteps-1); int stepDistance = barWidth / (m_numSteps-1);
for(int a = 0; a < m_numSteps; ++a) { for(int a = 0; a < m_numSteps; ++a) {
int renderSliderStepPosX = xSliderStart + a * stepDistance + 1; int renderSliderStepPosX = xSliderStart + a * stepDistance + 1;
fill(renderSliderStepPosX - 1, ySliderStart - 2, renderSliderStepPosX + 1, ySliderEnd + 2, 0xff606060); fill(renderSliderStepPosX - 1, ySliderStart - 2, renderSliderStepPosX + 1, ySliderEnd + 2, 0xff606060);
} }
} }
minecraft->textures->loadAndBindTexture("gui/touchgui.png"); minecraft->textures->loadAndBindTexture("gui/touchgui.png");
blit(xSliderStart + (int)(m_percentage * barWidth) - handleSizeX / 2, y, 226, 126, handleSizeX, handleSizeY, handleSizeX, handleSizeY); 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 ) { void Slider::mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ) {
if(pointInside(x, y)) { if(pointInside(x, y)) {
m_mouseDownOnElement = true; m_mouseDownOnElement = true;
} }
} }
void Slider::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) { void Slider::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) {
m_mouseDownOnElement = false; m_mouseDownOnElement = false;
} }
void Slider::tick(Minecraft* minecraft) { void Slider::tick(Minecraft* minecraft) {
if(minecraft->screen != NULL) { if(minecraft->screen != NULL) {
int xm = Mouse::getX(); int xm = Mouse::getX();
int ym = Mouse::getY(); int ym = Mouse::getY();
minecraft->screen->toGUICoordinate(xm, ym); minecraft->screen->toGUICoordinate(xm, ym);
if(m_mouseDownOnElement) { if(m_mouseDownOnElement) {
m_percentage = float(xm - x) / float(width); m_percentage = float(xm - x) / float(width);
m_percentage = Mth::clamp(m_percentage, 0.0f, 1.0f); m_percentage = Mth::clamp(m_percentage, 0.0f, 1.0f);
} }
} }
} }
SliderFloat::SliderFloat(Minecraft* minecraft, OptionId option) SliderFloat::SliderFloat(Minecraft* minecraft, OptionId option)
: Slider(option), m_option(dynamic_cast<OptionFloat*>(minecraft->options.getOpt(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); 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) SliderInt::SliderInt(Minecraft* minecraft, OptionId option)
: Slider(option), m_option(dynamic_cast<OptionInt*>(minecraft->options.getOpt(option))) : Slider(option), m_option(dynamic_cast<OptionInt*>(minecraft->options.getOpt(option)))
{ {
m_numSteps = m_option->getMax() - m_option->getMin() + 1; m_numSteps = m_option->getMax() - m_option->getMin() + 1;
m_percentage = float(m_option->get() - m_option->getMin()) / (m_numSteps-1); m_percentage = float(m_option->get() - m_option->getMin()) / (m_numSteps-1);
} }
void SliderInt::render( Minecraft* minecraft, int xm, int ym ) { void SliderInt::render( Minecraft* minecraft, int xm, int ym ) {
Slider::render(minecraft, xm, ym); Slider::render(minecraft, xm, ym);
} }
void SliderInt::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) { void SliderInt::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) {
Slider::mouseReleased(minecraft, x, y, buttonNum); Slider::mouseReleased(minecraft, x, y, buttonNum);
if (pointInside(x, y)) { if (pointInside(x, y)) {
int curStep = int(m_percentage * (m_numSteps-1) + 0.5f); int curStep = int(m_percentage * (m_numSteps-1) + 0.5f);
curStep = Mth::clamp(curStep + m_option->getMin(), m_option->getMin(), m_option->getMax()); curStep = Mth::clamp(curStep + m_option->getMin(), m_option->getMin(), m_option->getMax());
m_percentage = float(curStep - m_option->getMin()) / (m_numSteps-1); m_percentage = float(curStep - m_option->getMin()) / (m_numSteps-1);
minecraft->options.set(m_optId, curStep); minecraft->options.set(m_optId, curStep);
} }
} }
void SliderFloat::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) { void SliderFloat::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) {
Slider::mouseReleased(minecraft, x, y, buttonNum); Slider::mouseReleased(minecraft, x, y, buttonNum);
if (pointInside(x, y)) { if (pointInside(x, y)) {
minecraft->options.set(m_optId, m_percentage * (m_option->getMax() - m_option->getMin()) + m_option->getMin()); minecraft->options.set(m_optId, m_percentage * (m_option->getMax() - m_option->getMin()) + m_option->getMin());
} }
} }

View File

@@ -1,48 +1,46 @@
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__Slider_H__ #pragma once
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__Slider_H__
#include "GuiElement.hpp"
#include "GuiElement.h" #include "client/Options.hpp"
#include "../../../client/Options.h" #include <client/Option.hpp>
#include <client/Option.h>
class Slider : public GuiElement {
class Slider : public GuiElement { typedef GuiElement super;
typedef GuiElement super; public:
public: virtual void render( Minecraft* minecraft, int xm, int ym );
virtual void render( Minecraft* minecraft, int xm, int ym ); virtual void mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum );
virtual void mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ); virtual void mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum );
virtual void mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ); virtual void tick(Minecraft* minecraft);
virtual void tick(Minecraft* minecraft);
protected:
protected: Slider(OptionId optId);
Slider(OptionId optId);
OptionId m_optId;
OptionId m_optId;
bool m_mouseDownOnElement;
bool m_mouseDownOnElement; float m_percentage;
float m_percentage; int m_numSteps;
int m_numSteps; };
};
class SliderFloat : public Slider {
class SliderFloat : public Slider { public:
public: SliderFloat(Minecraft* minecraft, OptionId option);
SliderFloat(Minecraft* minecraft, OptionId option);
virtual void mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) override;
virtual void mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) override;
protected:
protected: OptionFloat* m_option;
OptionFloat* m_option; };
};
class SliderInt : public Slider {
class SliderInt : public Slider { public:
public: SliderInt(Minecraft* minecraft, OptionId option);
SliderInt(Minecraft* minecraft, OptionId option);
virtual void render( Minecraft* minecraft, int xm, int ym ) override;
virtual void render( Minecraft* minecraft, int xm, int ym ) override; virtual void mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) override;
virtual void mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) override;
protected:
protected: OptionInt* m_option;
OptionInt* m_option; };
};
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__Slider_H__*/

View File

@@ -1,102 +1,102 @@
#include "TextBox.h" #include "TextBox.hpp"
#include "../Gui.h" #include "client/gui/Gui.hpp"
#include "../../Minecraft.h" #include "client/Minecraft.hpp"
#include "../../../AppPlatform.h" #include "AppPlatform.hpp"
#include "../../../platform/input/Mouse.h" #include "platform/input/Mouse.hpp"
// delegate constructors // delegate constructors
TextBox::TextBox(int id, const std::string& msg) TextBox::TextBox(int id, const std::string& msg)
: TextBox(id, 0, 0, msg) : TextBox(id, 0, 0, msg)
{ {
} }
TextBox::TextBox(int id, int x, int y, const std::string& msg) TextBox::TextBox(int id, int x, int y, const std::string& msg)
: TextBox(id, x, y, 24, Font::DefaultLineHeight + 4, 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) TextBox::TextBox(int id, int x, int y, int w, int h, const std::string& msg)
: GuiElement(true, true, x, y, w, h), : GuiElement(true, true, x, y, w, h),
id(id), hint(msg), focused(false), blink(false), blinkTicks(0) id(id), hint(msg), focused(false), blink(false), blinkTicks(0)
{ {
} }
void TextBox::setFocus(Minecraft* minecraft) { void TextBox::setFocus(Minecraft* minecraft) {
if (!focused) { if (!focused) {
minecraft->platform()->showKeyboard(); minecraft->platform()->showKeyboard();
focused = true; focused = true;
blinkTicks = 0; blinkTicks = 0;
blink = false; blink = false;
} }
} }
bool TextBox::loseFocus(Minecraft* minecraft) { bool TextBox::loseFocus(Minecraft* minecraft) {
if (focused) { if (focused) {
minecraft->platform()->hideKeyboard(); minecraft->platform()->hideKeyboard();
focused = false; focused = false;
return true; return true;
} }
return false; return false;
} }
void TextBox::mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum) { void TextBox::mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum) {
if (buttonNum == MouseAction::ACTION_LEFT) { if (buttonNum == MouseAction::ACTION_LEFT) {
if (pointInside(x, y)) { if (pointInside(x, y)) {
setFocus(minecraft); setFocus(minecraft);
} else { } else {
loseFocus(minecraft); loseFocus(minecraft);
} }
} }
} }
void TextBox::charPressed(Minecraft* minecraft, char c) { void TextBox::charPressed(Minecraft* minecraft, char c) {
if (focused && c >= 32 && c < 127 && (int)text.size() < 256) { if (focused && c >= 32 && c < 127 && (int)text.size() < 256) {
text.push_back(c); text.push_back(c);
} }
} }
void TextBox::keyPressed(Minecraft* minecraft, int key) { void TextBox::keyPressed(Minecraft* minecraft, int key) {
if (focused && key == Keyboard::KEY_BACKSPACE && !text.empty()) { if (focused && key == Keyboard::KEY_BACKSPACE && !text.empty()) {
text.pop_back(); text.pop_back();
} }
} }
void TextBox::tick(Minecraft* minecraft) { void TextBox::tick(Minecraft* minecraft) {
blinkTicks++; blinkTicks++;
if (blinkTicks >= 5) { if (blinkTicks >= 5) {
blink = !blink; blink = !blink;
blinkTicks = 0; blinkTicks = 0;
} }
} }
void TextBox::render(Minecraft* minecraft, int xm, int ym) { void TextBox::render(Minecraft* minecraft, int xm, int ym) {
// textbox like in beta 1.7.3 // textbox like in beta 1.7.3
// change appearance when focused so the user can tell it's active // change appearance when focused so the user can tell it's active
// active background darker gray with a subtle border // active background darker gray with a subtle border
uint32_t bgColor = focused ? 0xffa0a0a0 : 0xffa0a0a0; uint32_t bgColor = focused ? 0xffa0a0a0 : 0xffa0a0a0;
uint32_t borderColor = focused ? 0xff000000 : 0xff000000; uint32_t borderColor = focused ? 0xff000000 : 0xff000000;
fill(x, y, x + width, y + height, bgColor); fill(x, y, x + width, y + height, bgColor);
fill(x + 1, y + 1, x + width - 1, y + height - 1, borderColor); fill(x + 1, y + 1, x + width - 1, y + height - 1, borderColor);
glEnable2(GL_SCISSOR_TEST); glEnable2(GL_SCISSOR_TEST);
glScissor( glScissor(
Gui::GuiScale * (x + 2), Gui::GuiScale * (x + 2),
minecraft->height - Gui::GuiScale * (y + height - 2), minecraft->height - Gui::GuiScale * (y + height - 2),
Gui::GuiScale * (width - 2), Gui::GuiScale * (width - 2),
Gui::GuiScale * (height - 2) Gui::GuiScale * (height - 2)
); );
int _y = y + (height - Font::DefaultLineHeight) / 2; int _y = y + (height - Font::DefaultLineHeight) / 2;
if (text.empty() && !focused) { if (text.empty() && !focused) {
drawString(minecraft->font, hint, x + 2, _y, 0xff5e5e5e); drawString(minecraft->font, hint, x + 2, _y, 0xff5e5e5e);
} }
if (focused && blink) text.push_back('_'); if (focused && blink) text.push_back('_');
drawString(minecraft->font, text, x + 2, _y, 0xffffffff); drawString(minecraft->font, text, x + 2, _y, 0xffffffff);
if (focused && blink) text.pop_back(); if (focused && blink) text.pop_back();
glDisable2(GL_SCISSOR_TEST); glDisable2(GL_SCISSOR_TEST);
} }

View File

@@ -1,44 +1,42 @@
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__TextBox_H__ #pragma once
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__TextBox_H__
//package net.minecraft.client.gui;
//package net.minecraft.client.gui;
#include <string>
#include <string> #include "GuiElement.hpp"
#include "GuiElement.h" #include "client/Options.hpp"
#include "../../Options.h" #include "platform/input/Mouse.hpp"
#include "../../../platform/input/Mouse.h" #include "platform/input/Keyboard.hpp"
#include "../../../platform/input/Keyboard.h"
class Font;
class Font; class Minecraft;
class Minecraft;
class TextBox: public GuiElement
class TextBox: public GuiElement {
{ public:
public: TextBox(int id, const std::string& msg);
TextBox(int id, const std::string& msg); TextBox(int id, int x, int y, const std::string& msg);
TextBox(int id, int x, int y, const std::string& msg); TextBox(int id, int x, int y, int w, int h, const std::string& msg);
TextBox(int id, int x, int y, int w, int h, const std::string& msg);
virtual void mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum);
virtual void mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum);
virtual void setFocus(Minecraft* minecraft);
virtual void setFocus(Minecraft* minecraft); virtual bool loseFocus(Minecraft* minecraft);
virtual bool loseFocus(Minecraft* minecraft);
virtual void render(Minecraft* minecraft, int xm, int ym);
virtual void render(Minecraft* minecraft, int xm, int ym);
virtual void keyPressed(Minecraft* minecraft, int key);
virtual void keyPressed(Minecraft* minecraft, int key); virtual void charPressed(Minecraft* minecraft, char c);
virtual void charPressed(Minecraft* minecraft, char c); virtual void tick(Minecraft* minecraft);
virtual void tick(Minecraft* minecraft);
public:
public: std::string hint;
std::string hint; std::string text;
std::string text; int id;
int id;
int blinkTicks;
int blinkTicks;
bool focused;
bool focused; bool blink;
bool blink; };
};
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__TextBox_H__*/

View File

@@ -1,5 +1,5 @@
#include "TextOption.h" #include "TextOption.hpp"
#include <client/Minecraft.h> #include <client/Minecraft.hpp>
TextOption::TextOption(Minecraft* minecraft, OptionId optId) TextOption::TextOption(Minecraft* minecraft, OptionId optId)
: TextBox((int)optId, minecraft->options.getOpt(optId)->getStringId()) : TextBox((int)optId, minecraft->options.getOpt(optId)->getStringId())

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include "TextBox.h" #include "TextBox.hpp"
#include <client/Options.h> #include <client/Options.hpp>
class TextOption : public TextBox { class TextOption : public TextBox {
public: public:

View File

@@ -1,370 +1,370 @@
#include "ArmorScreen.h" #include "ArmorScreen.hpp"
#include "../Screen.h" #include "client/gui/Screen.hpp"
#include "../components/NinePatch.h" #include "client/gui/components/NinePatch.hpp"
#include "../../Minecraft.h" #include "client/Minecraft.hpp"
#include "../../player/LocalPlayer.h" #include "client/player/LocalPlayer.hpp"
#include "../../renderer/Tesselator.h" #include "client/renderer/Tesselator.hpp"
#include "../../renderer/entity/ItemRenderer.h" #include "client/renderer/entity/ItemRenderer.hpp"
#include "../../../world/item/Item.h" #include "world/item/Item.hpp"
#include "../../../world/item/ItemCategory.h" #include "world/item/ItemCategory.hpp"
#include "../../../world/entity/player/Inventory.h" #include "world/entity/player/Inventory.hpp"
#include "../../../world/entity/item/ItemEntity.h" #include "world/entity/item/ItemEntity.hpp"
#include "../../../world/level/Level.h" #include "world/level/Level.hpp"
#include "../../../network/RakNetInstance.h" #include "network/RakNetInstance.hpp"
#include "../../renderer/entity/EntityRenderDispatcher.h" #include "client/renderer/entity/EntityRenderDispatcher.hpp"
#include "../../../world/item/ArmorItem.h" #include "world/item/ArmorItem.hpp"
static void setIfNotSet(bool& ref, bool condition) { static void setIfNotSet(bool& ref, bool condition) {
ref = (ref || condition); ref = (ref || condition);
} }
const int descFrameWidth = 100; const int descFrameWidth = 100;
const int rgbActive = 0xfff0f0f0; const int rgbActive = 0xfff0f0f0;
const int rgbInactive = 0xc0635558; const int rgbInactive = 0xc0635558;
const int rgbInactiveShadow = 0xc0aaaaaa; const int rgbInactiveShadow = 0xc0aaaaaa;
#ifdef __APPLE__ #ifdef __APPLE__
static const float BorderPixels = 4; static const float BorderPixels = 4;
#ifdef DEMO_MODE #ifdef DEMO_MODE
static const float BlockPixels = 22; static const float BlockPixels = 22;
#else #else
static const float BlockPixels = 22; static const float BlockPixels = 22;
#endif #endif
#else #else
static const float BorderPixels = 4; static const float BorderPixels = 4;
static const float BlockPixels = 24; static const float BlockPixels = 24;
#endif #endif
static const int ItemSize = (int)(BlockPixels + 2*BorderPixels); static const int ItemSize = (int)(BlockPixels + 2*BorderPixels);
static const int Bx = 10; // Border Frame width static const int Bx = 10; // Border Frame width
static const int By = 6; // Border Frame height static const int By = 6; // Border Frame height
ArmorScreen::ArmorScreen(): ArmorScreen::ArmorScreen():
inventoryPane(NULL), inventoryPane(NULL),
btnArmor0(0), btnArmor0(0),
btnArmor1(1), btnArmor1(1),
btnArmor2(2), btnArmor2(2),
btnArmor3(3), btnArmor3(3),
btnClose(4, ""), btnClose(4, ""),
bHeader (5, "Armor"), bHeader (5, "Armor"),
guiBackground(NULL), guiBackground(NULL),
guiSlot(NULL), guiSlot(NULL),
guiPaneFrame(NULL), guiPaneFrame(NULL),
guiPlayerBg(NULL), guiPlayerBg(NULL),
doRecreatePane(false), doRecreatePane(false),
descWidth(90) descWidth(90)
//guiSlotItem(NULL), //guiSlotItem(NULL),
//guiSlotItemSelected(NULL) //guiSlotItemSelected(NULL)
{ {
//LOGI("Creating ArmorScreen with %p, %d\n", furnace, furnace->runningId); //LOGI("Creating ArmorScreen with %p, %d\n", furnace, furnace->runningId);
} }
ArmorScreen::~ArmorScreen() { ArmorScreen::~ArmorScreen() {
delete inventoryPane; delete inventoryPane;
delete guiBackground; delete guiBackground;
delete guiSlot; delete guiSlot;
delete guiPaneFrame; delete guiPaneFrame;
delete guiPlayerBg; delete guiPlayerBg;
} }
void ArmorScreen::init() { void ArmorScreen::init() {
super::init(); super::init();
player = minecraft->player; player = minecraft->player;
ImageDef def; ImageDef def;
def.name = "gui/spritesheet.png"; def.name = "gui/spritesheet.png";
def.x = 0; def.x = 0;
def.y = 1; def.y = 1;
def.width = def.height = 18; def.width = def.height = 18;
def.setSrc(IntRectangle(60, 0, 18, 18)); def.setSrc(IntRectangle(60, 0, 18, 18));
btnClose.setImageDef(def, true); btnClose.setImageDef(def, true);
btnClose.scaleWhenPressed = false; btnClose.scaleWhenPressed = false;
buttons.push_back(&bHeader); buttons.push_back(&bHeader);
buttons.push_back(&btnClose); buttons.push_back(&btnClose);
armorButtons[0] = &btnArmor0; armorButtons[0] = &btnArmor0;
armorButtons[1] = &btnArmor1; armorButtons[1] = &btnArmor1;
armorButtons[2] = &btnArmor2; armorButtons[2] = &btnArmor2;
armorButtons[3] = &btnArmor3; armorButtons[3] = &btnArmor3;
for (int i = 0; i < NUM_ARMORBUTTONS; ++i) for (int i = 0; i < NUM_ARMORBUTTONS; ++i)
buttons.push_back(armorButtons[i]); buttons.push_back(armorButtons[i]);
// GUI - nine patches // GUI - nine patches
NinePatchFactory builder(minecraft->textures, "gui/spritesheet.png"); NinePatchFactory builder(minecraft->textures, "gui/spritesheet.png");
guiBackground = builder.createSymmetrical(IntRectangle(0, 0, 16, 16), 4, 4); guiBackground = builder.createSymmetrical(IntRectangle(0, 0, 16, 16), 4, 4);
guiSlot = builder.createSymmetrical(IntRectangle(0, 32, 8, 8), 3, 3, 20, 20); 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); guiPaneFrame = builder.createSymmetrical(IntRectangle(28, 42, 4, 4), 1, 1)->setExcluded(1 << 4);
guiPlayerBg = builder.createSymmetrical(IntRectangle(0, 20, 8, 8), 3, 3); guiPlayerBg = builder.createSymmetrical(IntRectangle(0, 20, 8, 8), 3, 3);
updateItems(); updateItems();
} }
void ArmorScreen::setupPositions() { void ArmorScreen::setupPositions() {
// Left - Categories // Left - Categories
bHeader.x = bHeader.y = 0; bHeader.x = bHeader.y = 0;
bHeader.width = width;// - bDone.w; bHeader.width = width;// - bDone.w;
btnClose.width = btnClose.height = 19; btnClose.width = btnClose.height = 19;
btnClose.x = width - btnClose.width; btnClose.x = width - btnClose.width;
btnClose.y = 0; btnClose.y = 0;
// Inventory pane // Inventory pane
const int maxWidth = (int)(width/1.8f) - Bx - Bx; const int maxWidth = (int)(width/1.8f) - Bx - Bx;
const int InventoryColumns = maxWidth / ItemSize; const int InventoryColumns = maxWidth / ItemSize;
const int realWidth = InventoryColumns * ItemSize; const int realWidth = InventoryColumns * ItemSize;
const int paneWidth = realWidth + Bx + Bx; const int paneWidth = realWidth + Bx + Bx;
const int realBx = (paneWidth - realWidth) / 2; const int realBx = (paneWidth - realWidth) / 2;
inventoryPaneRect = IntRectangle(realBx, inventoryPaneRect = IntRectangle(realBx,
#ifdef __APPLE__ #ifdef __APPLE__
26 + By - ((width==240)?1:0), realWidth, ((width==240)?1:0) + height-By-By-28); 26 + By - ((width==240)?1:0), realWidth, ((width==240)?1:0) + height-By-By-28);
#else #else
26 + By, realWidth, height-By-By-28); 26 + By, realWidth, height-By-By-28);
#endif #endif
for (int i = 0; i < NUM_ARMORBUTTONS; ++i) { for (int i = 0; i < NUM_ARMORBUTTONS; ++i) {
Button& b = *armorButtons[i]; Button& b = *armorButtons[i];
b.x = paneWidth; b.x = paneWidth;
b.y = inventoryPaneRect.y + 24 * i; b.y = inventoryPaneRect.y + 24 * i;
b.width = 20; b.width = 20;
b.height = 20; b.height = 20;
} }
guiPlayerBgRect.y = inventoryPaneRect.y; guiPlayerBgRect.y = inventoryPaneRect.y;
int xx = armorButtons[0]->x + armorButtons[0]->width; int xx = armorButtons[0]->x + armorButtons[0]->width;
int xw = width - xx; int xw = width - xx;
guiPlayerBgRect.x = xx + xw / 10; guiPlayerBgRect.x = xx + xw / 10;
guiPlayerBgRect.w = xw - (xw / 10) * 2; guiPlayerBgRect.w = xw - (xw / 10) * 2;
guiPlayerBgRect.h = inventoryPaneRect.h; guiPlayerBgRect.h = inventoryPaneRect.h;
guiPaneFrame->setSize((float)inventoryPaneRect.w + 2, (float)inventoryPaneRect.h + 2); guiPaneFrame->setSize((float)inventoryPaneRect.w + 2, (float)inventoryPaneRect.h + 2);
guiPlayerBg->setSize((float)guiPlayerBgRect.w, (float)guiPlayerBgRect.h); guiPlayerBg->setSize((float)guiPlayerBgRect.w, (float)guiPlayerBgRect.h);
guiBackground->setSize((float)width, (float)height); guiBackground->setSize((float)width, (float)height);
updateItems(); updateItems();
setupInventoryPane(); setupInventoryPane();
} }
void ArmorScreen::tick() { void ArmorScreen::tick() {
if (inventoryPane) if (inventoryPane)
inventoryPane->tick(); inventoryPane->tick();
if (doRecreatePane) { if (doRecreatePane) {
updateItems(); updateItems();
setupInventoryPane(); setupInventoryPane();
doRecreatePane = false; doRecreatePane = false;
} }
} }
void ArmorScreen::handleRenderPane(Touch::InventoryPane* pane, Tesselator& t, int xm, int ym, float a) { void ArmorScreen::handleRenderPane(Touch::InventoryPane* pane, Tesselator& t, int xm, int ym, float a) {
if (pane) { if (pane) {
pane->render(xm, ym, a); pane->render(xm, ym, a);
guiPaneFrame->draw(t, (float)(pane->rect.x - 1), (float)(pane->rect.y - 1)); guiPaneFrame->draw(t, (float)(pane->rect.x - 1), (float)(pane->rect.y - 1));
} }
} }
void ArmorScreen::render(int xm, int ym, float a) { void ArmorScreen::render(int xm, int ym, float a) {
//renderBackground(); //renderBackground();
Tesselator& t = Tesselator::instance; Tesselator& t = Tesselator::instance;
t.addOffset(0, 0, -500); t.addOffset(0, 0, -500);
guiBackground->draw(t, 0, 0); guiBackground->draw(t, 0, 0);
t.addOffset(0, 0, 500); t.addOffset(0, 0, 500);
glEnable2(GL_ALPHA_TEST); glEnable2(GL_ALPHA_TEST);
// Buttons (Left side + crafting) // Buttons (Left side + crafting)
super::render(xm, ym, a); super::render(xm, ym, a);
handleRenderPane(inventoryPane, t, xm, ym, a); handleRenderPane(inventoryPane, t, xm, ym, a);
t.colorABGR(0xffffffff); t.colorABGR(0xffffffff);
glColor4f2(1, 1, 1, 1); glColor4f2(1, 1, 1, 1);
t.addOffset(0, 0, -490); t.addOffset(0, 0, -490);
guiPlayerBg->draw(t, (float)guiPlayerBgRect.x, (float)guiPlayerBgRect.y); guiPlayerBg->draw(t, (float)guiPlayerBgRect.x, (float)guiPlayerBgRect.y);
t.addOffset(0, 0, 490); t.addOffset(0, 0, 490);
renderPlayer((float)(guiPlayerBgRect.x + guiPlayerBgRect.w / 2), 0.85f * height); renderPlayer((float)(guiPlayerBgRect.x + guiPlayerBgRect.w / 2), 0.85f * height);
for (int i = 0; i < NUM_ARMORBUTTONS; ++i) { for (int i = 0; i < NUM_ARMORBUTTONS; ++i) {
drawSlotItemAt(t, i, player->getArmor(i), armorButtons[i]->x, armorButtons[i]->y); drawSlotItemAt(t, i, player->getArmor(i), armorButtons[i]->x, armorButtons[i]->y);
} }
glDisable2(GL_ALPHA_TEST); glDisable2(GL_ALPHA_TEST);
} }
void ArmorScreen::buttonClicked(Button* button) { void ArmorScreen::buttonClicked(Button* button) {
if (button == &btnClose) { if (button == &btnClose) {
minecraft->setScreen(NULL); minecraft->setScreen(NULL);
} }
if (button->id >= 0 && button->id <= 3) { if (button->id >= 0 && button->id <= 3) {
takeAndClearSlot(button->id); takeAndClearSlot(button->id);
} }
} }
bool ArmorScreen::addItem(const Touch::InventoryPane* forPane, int itemIndex) { bool ArmorScreen::addItem(const Touch::InventoryPane* forPane, int itemIndex) {
const ItemInstance* instance = armorItems[itemIndex]; const ItemInstance* instance = armorItems[itemIndex];
if (!ItemInstance::isArmorItem(instance)) if (!ItemInstance::isArmorItem(instance))
return false; return false;
ArmorItem* item = (ArmorItem*) instance->getItem(); ArmorItem* item = (ArmorItem*) instance->getItem();
ItemInstance* old = player->getArmor(item->slot); ItemInstance* old = player->getArmor(item->slot);
ItemInstance oldArmor; ItemInstance oldArmor;
if (ItemInstance::isArmorItem(old)) { if (ItemInstance::isArmorItem(old)) {
oldArmor = *old; oldArmor = *old;
} }
player->setArmor(item->slot, instance); player->setArmor(item->slot, instance);
player->inventory->removeItem(instance); player->inventory->removeItem(instance);
//@attn: this is hugely important //@attn: this is hugely important
armorItems[itemIndex] = NULL; armorItems[itemIndex] = NULL;
if (!oldArmor.isNull()) { if (!oldArmor.isNull()) {
if (!player->inventory->add(&oldArmor)) { if (!player->inventory->add(&oldArmor)) {
player->drop(new ItemInstance(oldArmor), false); player->drop(new ItemInstance(oldArmor), false);
} }
} }
doRecreatePane = true; doRecreatePane = true;
return true; return true;
} }
bool ArmorScreen::isAllowed( int slot ) { bool ArmorScreen::isAllowed( int slot ) {
return true; return true;
} }
bool ArmorScreen::renderGameBehind() { bool ArmorScreen::renderGameBehind() {
return false; return false;
} }
std::vector<const ItemInstance*> ArmorScreen::getItems( const Touch::InventoryPane* forPane ) { std::vector<const ItemInstance*> ArmorScreen::getItems( const Touch::InventoryPane* forPane ) {
return armorItems; return armorItems;
} }
void ArmorScreen::updateItems() { void ArmorScreen::updateItems() {
armorItems.clear(); armorItems.clear();
for (int i = Inventory::MAX_SELECTION_SIZE; i < minecraft->player->inventory->getContainerSize(); ++i) { for (int i = Inventory::MAX_SELECTION_SIZE; i < minecraft->player->inventory->getContainerSize(); ++i) {
ItemInstance* item = minecraft->player->inventory->getItem(i); ItemInstance* item = minecraft->player->inventory->getItem(i);
if (ItemInstance::isArmorItem(item)) if (ItemInstance::isArmorItem(item))
armorItems.push_back(item); armorItems.push_back(item);
} }
} }
bool ArmorScreen::canMoveToSlot(int slot, const ItemInstance* item) { bool ArmorScreen::canMoveToSlot(int slot, const ItemInstance* item) {
return ItemInstance::isArmorItem(item) return ItemInstance::isArmorItem(item)
&& ((ArmorItem*)item)->slot == slot; && ((ArmorItem*)item)->slot == slot;
} }
void ArmorScreen::setupInventoryPane() { void ArmorScreen::setupInventoryPane() {
// IntRectangle(0, 0, 100, 100) // IntRectangle(0, 0, 100, 100)
if (inventoryPane) delete inventoryPane; if (inventoryPane) delete inventoryPane;
inventoryPane = new Touch::InventoryPane(this, minecraft, inventoryPaneRect, inventoryPaneRect.w, BorderPixels, armorItems.size(), ItemSize, (int)BorderPixels); inventoryPane = new Touch::InventoryPane(this, minecraft, inventoryPaneRect, inventoryPaneRect.w, BorderPixels, armorItems.size(), ItemSize, (int)BorderPixels);
inventoryPane->fillMarginX = 0; inventoryPane->fillMarginX = 0;
inventoryPane->fillMarginY = 0; inventoryPane->fillMarginY = 0;
//LOGI("Creating new pane: %d %p\n", inventoryItems.size(), inventoryPane); //LOGI("Creating new pane: %d %p\n", inventoryItems.size(), inventoryPane);
} }
void ArmorScreen::drawSlotItemAt( Tesselator& t, int slot, const ItemInstance* item, int x, int y) void ArmorScreen::drawSlotItemAt( Tesselator& t, int slot, const ItemInstance* item, int x, int y)
{ {
float xx = (float)x; float xx = (float)x;
float yy = (float)y; float yy = (float)y;
guiSlot->draw(t, xx, yy); guiSlot->draw(t, xx, yy);
if (item && !item->isNull()) { if (item && !item->isNull()) {
ItemRenderer::renderGuiItem(minecraft->font, minecraft->textures, item, xx + 2, yy, true); ItemRenderer::renderGuiItem(minecraft->font, minecraft->textures, item, xx + 2, yy, true);
glDisable2(GL_TEXTURE_2D); glDisable2(GL_TEXTURE_2D);
ItemRenderer::renderGuiItemDecorations(item, xx + 2, yy + 3); ItemRenderer::renderGuiItemDecorations(item, xx + 2, yy + 3);
glEnable2(GL_TEXTURE_2D); glEnable2(GL_TEXTURE_2D);
//minecraft->gui.renderSlotText(item, xx + 3, yy + 3, true, true); //minecraft->gui.renderSlotText(item, xx + 3, yy + 3, true, true);
} else { } else {
minecraft->textures->loadAndBindTexture("gui/items.png"); minecraft->textures->loadAndBindTexture("gui/items.png");
blit(x + 2, y, 15 * 16, slot * 16, 16, 16, 16, 16); blit(x + 2, y, 15 * 16, slot * 16, 16, 16, 16, 16);
} }
} }
void ArmorScreen::takeAndClearSlot( int slot ) { void ArmorScreen::takeAndClearSlot( int slot ) {
ItemInstance* item = player->getArmor(slot); ItemInstance* item = player->getArmor(slot);
if (!item) if (!item)
return; return;
int oldSize = minecraft->player->inventory->getNumEmptySlots(); int oldSize = minecraft->player->inventory->getNumEmptySlots();
if (!minecraft->player->inventory->add(item)) if (!minecraft->player->inventory->add(item))
minecraft->player->drop(new ItemInstance(*item), false); minecraft->player->drop(new ItemInstance(*item), false);
player->setArmor(slot, NULL); player->setArmor(slot, NULL);
int newSize = minecraft->player->inventory->getNumEmptySlots(); int newSize = minecraft->player->inventory->getNumEmptySlots();
setIfNotSet(doRecreatePane, newSize != oldSize); setIfNotSet(doRecreatePane, newSize != oldSize);
} }
void ArmorScreen::renderPlayer(float xo, float yo) { void ArmorScreen::renderPlayer(float xo, float yo) {
// Push GL and player state // Push GL and player state
glPushMatrix(); glPushMatrix();
glTranslatef(xo, yo, -200); glTranslatef(xo, yo, -200);
float ss = 45; float ss = 45;
glScalef(-ss, ss, ss); glScalef(-ss, ss, ss);
glRotatef(180, 0, 0, 1); glRotatef(180, 0, 0, 1);
//glDisable(GL_DEPTH_TEST); //glDisable(GL_DEPTH_TEST);
Player* player = (Player*) minecraft->player; Player* player = (Player*) minecraft->player;
float oybr = player->yBodyRot; float oybr = player->yBodyRot;
float oyr = player->yRot; float oyr = player->yRot;
float oxr = player->xRot; float oxr = player->xRot;
float t = getTimeS(); float t = getTimeS();
float xd = 10 * Mth::sin(t);//(xo + 51) - xm; float xd = 10 * Mth::sin(t);//(xo + 51) - xm;
float yd = 10 * Mth::cos(t * 0.05f);//(yo + 75 - 50) - ym; float yd = 10 * Mth::cos(t * 0.05f);//(yo + 75 - 50) - ym;
glRotatef(45 + 90, 0, 1, 0); glRotatef(45 + 90, 0, 1, 0);
glRotatef(-45 - 90, 0, 1, 0); glRotatef(-45 - 90, 0, 1, 0);
const float xtan = Mth::atan(xd / 40.0f) * +20; const float xtan = Mth::atan(xd / 40.0f) * +20;
const float ytan = Mth::atan(yd / 40.0f) * -20; const float ytan = Mth::atan(yd / 40.0f) * -20;
glRotatef(ytan, 1, 0, 0); glRotatef(ytan, 1, 0, 0);
player->yBodyRot = xtan; player->yBodyRot = xtan;
player->yRot = xtan + xtan; player->yRot = xtan + xtan;
player->xRot = ytan; player->xRot = ytan;
glTranslatef(0, player->heightOffset, 0); glTranslatef(0, player->heightOffset, 0);
// Push walking anim // Push walking anim
float oldWAP = player->walkAnimPos; float oldWAP = player->walkAnimPos;
float oldWAS = player->walkAnimSpeed; float oldWAS = player->walkAnimSpeed;
float oldWASO = player->walkAnimSpeedO; float oldWASO = player->walkAnimSpeedO;
// Set new walking anim // Set new walking anim
player->walkAnimSpeedO = player->walkAnimSpeed = 0.25f; player->walkAnimSpeedO = player->walkAnimSpeed = 0.25f;
player->walkAnimPos = getTimeS() * player->walkAnimSpeed * SharedConstants::TicksPerSecond; player->walkAnimPos = getTimeS() * player->walkAnimSpeed * SharedConstants::TicksPerSecond;
EntityRenderDispatcher* rd = EntityRenderDispatcher::getInstance(); EntityRenderDispatcher* rd = EntityRenderDispatcher::getInstance();
rd->playerRotY = 180; rd->playerRotY = 180;
rd->render(player, 0, 0, 0, 0, 1); rd->render(player, 0, 0, 0, 0, 1);
// Pop walking anim // Pop walking anim
player->walkAnimPos = oldWAP; player->walkAnimPos = oldWAP;
player->walkAnimSpeed = oldWAS; player->walkAnimSpeed = oldWAS;
player->walkAnimSpeedO = oldWASO; player->walkAnimSpeedO = oldWASO;
//glEnable(GL_DEPTH_TEST); //glEnable(GL_DEPTH_TEST);
// Pop GL and player state // Pop GL and player state
player->yBodyRot = oybr; player->yBodyRot = oybr;
player->yRot = oyr; player->yRot = oyr;
player->xRot = oxr; player->xRot = oxr;
glPopMatrix(); glPopMatrix();
} }

View File

@@ -1,79 +1,77 @@
#ifndef NET_MINECRAFT_CLIENT_GUI_SCREENS__ArmorScreen_H__ #pragma once
#define NET_MINECRAFT_CLIENT_GUI_SCREENS__ArmorScreen_H__
#include "BaseContainerScreen.hpp"
#include "BaseContainerScreen.h"
#include "client/gui/components/InventoryPane.hpp"
#include "../components/InventoryPane.h" #include "client/gui/components/Button.hpp"
#include "../components/Button.h"
class Font;
class Font; class CItem;
class CItem; class Textures;
class Textures; class NinePatchLayer;
class NinePatchLayer; class Tesselator;
class Tesselator;
class ArmorScreen: public Screen,
class ArmorScreen: public Screen, public Touch::IInventoryPaneCallback
public Touch::IInventoryPaneCallback {
{ typedef Screen super;
typedef Screen super; typedef std::vector<CItem*> ItemList;
typedef std::vector<CItem*> ItemList;
static const int NUM_ARMORBUTTONS = 4;
static const int NUM_ARMORBUTTONS = 4; public:
public: ArmorScreen();
ArmorScreen(); ~ArmorScreen();
~ArmorScreen();
void init();
void init(); void setupPositions();
void setupPositions();
void tick();
void tick(); void render(int xm, int ym, float a);
void render(int xm, int ym, float a); bool renderGameBehind();
bool renderGameBehind(); void buttonClicked(Button* button);
void buttonClicked(Button* button);
// IInventoryPaneCallback
// IInventoryPaneCallback bool addItem(const Touch::InventoryPane* pane, int itemId);
bool addItem(const Touch::InventoryPane* pane, int itemId); bool isAllowed( int slot );
bool isAllowed( int slot ); std::vector<const ItemInstance*> getItems( const Touch::InventoryPane* forPane );
std::vector<const ItemInstance*> getItems( const Touch::InventoryPane* forPane ); private:
private: void renderPlayer(float xo, float yo);
void renderPlayer(float xo, float yo);
void setupInventoryPane();
void setupInventoryPane(); void updateItems();
void updateItems();
void drawSlotItemAt(Tesselator& t, int slot, const ItemInstance* item, int x, int y);
void drawSlotItemAt(Tesselator& t, int slot, const ItemInstance* item, int x, int y); ItemInstance moveOver(const ItemInstance* item, int maxCount);
ItemInstance moveOver(const ItemInstance* item, int maxCount); void takeAndClearSlot( int slot );
void takeAndClearSlot( int slot ); void handleRenderPane(Touch::InventoryPane* pane, Tesselator& t, int xm, int ym, float a);
void handleRenderPane(Touch::InventoryPane* pane, Tesselator& t, int xm, int ym, float a); bool canMoveToSlot(int slot, const ItemInstance* item);
bool canMoveToSlot(int slot, const ItemInstance* item); ItemList _items;
ItemList _items;
std::string currentItemDesc;
std::string currentItemDesc; ItemInstance burnResult;
ItemInstance burnResult; float descWidth;
float descWidth; ImageButton btnClose;
ImageButton btnClose;
BlankButton btnArmor0;
BlankButton btnArmor0; BlankButton btnArmor1;
BlankButton btnArmor1; BlankButton btnArmor2;
BlankButton btnArmor2; BlankButton btnArmor3;
BlankButton btnArmor3; BlankButton* armorButtons[4];
BlankButton* armorButtons[4];
Touch::THeader bHeader;
Touch::THeader bHeader;
Touch::InventoryPane* inventoryPane;
Touch::InventoryPane* inventoryPane; IntRectangle inventoryPaneRect;
IntRectangle inventoryPaneRect; IntRectangle guiPlayerBgRect;
IntRectangle guiPlayerBgRect;
std::vector<const ItemInstance*> armorItems;
std::vector<const ItemInstance*> armorItems; bool doRecreatePane;
bool doRecreatePane;
// GUI elements such as 9-Patches
// GUI elements such as 9-Patches NinePatchLayer* guiBackground;
NinePatchLayer* guiBackground; NinePatchLayer* guiSlot;
NinePatchLayer* guiSlot; NinePatchLayer* guiPaneFrame;
NinePatchLayer* guiPaneFrame; NinePatchLayer* guiPlayerBg;
NinePatchLayer* guiPlayerBg; Player* player;
Player* player; };
};
#endif /*NET_MINECRAFT_CLIENT_GUI_SCREENS__ArmorScreen_H__*/

View File

@@ -1,50 +1,48 @@
#ifndef NET_MINECRAFT_CLIENT_GUI__BaseContainerScreen_H__ #pragma once
#define NET_MINECRAFT_CLIENT_GUI__BaseContainerScreen_H__
//package net.minecraft.client.gui.screens;
//package net.minecraft.client.gui.screens;
#include <vector>
#include <vector> #include "client/gui/Screen.hpp"
#include "../Screen.h" #include "client/Minecraft.hpp"
#include "../../Minecraft.h" #include "client/player/LocalPlayer.hpp"
#include "../../player/LocalPlayer.h"
class BaseContainerMenu;
class BaseContainerMenu;
class BaseContainerScreen: public Screen
class BaseContainerScreen: public Screen {
{ typedef Screen super;
typedef Screen super; public:
public: BaseContainerScreen(BaseContainerMenu* menu)
BaseContainerScreen(BaseContainerMenu* menu) : menu(menu)
: menu(menu) {
{ }
}
virtual void init() {
virtual void init() { super::init();
super::init(); minecraft->player->containerMenu = menu;
minecraft->player->containerMenu = menu; }
}
virtual void tick() {
virtual void tick() { super::tick();
super::tick(); if (!minecraft->player->isAlive() || minecraft->player->removed)
if (!minecraft->player->isAlive() || minecraft->player->removed) minecraft->player->closeContainer();
minecraft->player->closeContainer(); }
}
virtual void keyPressed( int eventKey )
virtual void keyPressed( int eventKey ) {
{ if (eventKey == Keyboard::KEY_ESCAPE) {
if (eventKey == Keyboard::KEY_ESCAPE) { minecraft->player->closeContainer();
minecraft->player->closeContainer(); } else {
} else { super::keyPressed(eventKey);
super::keyPressed(eventKey); }
} }
}
virtual bool closeOnPlayerHurt() {
virtual bool closeOnPlayerHurt() { return true;
return true; }
}
protected:
protected: BaseContainerMenu* menu;
BaseContainerMenu* menu; };
};
#endif /*NET_MINECRAFT_CLIENT_GUI__BaseContainerScreen_H__*/

View File

@@ -1,24 +1,24 @@
#include "ChatScreen.h" #include "ChatScreen.hpp"
#include "DialogDefinitions.h" #include "DialogDefinitions.hpp"
#include "../Gui.h" #include "client/gui/Gui.hpp"
#include "../../Minecraft.h" #include "client/Minecraft.hpp"
#include "../../../AppPlatform.h" #include "AppPlatform.hpp"
#include "../../../platform/log.h" #include "platform/log.hpp"
void ChatScreen::init() { void ChatScreen::init() {
minecraft->platform()->createUserInput(DialogDefinitions::DIALOG_NEW_CHAT_MESSAGE); minecraft->platform()->createUserInput(DialogDefinitions::DIALOG_NEW_CHAT_MESSAGE);
} }
void ChatScreen::render(int xm, int ym, float a) void ChatScreen::render(int xm, int ym, float a)
{ {
int status = minecraft->platform()->getUserInputStatus(); int status = minecraft->platform()->getUserInputStatus();
if (status > -1) { if (status > -1) {
if (status == 1) { if (status == 1) {
std::vector<std::string> v = minecraft->platform()->getUserInput(); std::vector<std::string> v = minecraft->platform()->getUserInput();
if (v.size() && v[0].length() > 0) if (v.size() && v[0].length() > 0)
minecraft->gui.addMessage(v[0]); minecraft->gui.addMessage(v[0]);
} }
minecraft->setScreen(NULL); minecraft->setScreen(NULL);
} }
} }

View File

@@ -1,21 +0,0 @@
#ifndef NET_MINECRAFT_CLIENT_GUI_SCREENS__ChatScreen_H__
#define NET_MINECRAFT_CLIENT_GUI_SCREENS__ChatScreen_H__
#include "../Screen.h"
class ChatScreen: public Screen
{
public:
ChatScreen() {}
virtual ~ChatScreen() {}
void init();
void render(int xm, int ym, float a);
void buttonClicked(Button* button) {};
private:
};
#endif /*NET_MINECRAFT_CLIENT_GUI_SCREENS__ChatScreen_H__*/

View File

@@ -0,0 +1,19 @@
#pragma once
#include "client/gui/Screen.hpp"
class ChatScreen: public Screen
{
public:
ChatScreen() {}
virtual ~ChatScreen() {}
void init();
void render(int xm, int ym, float a);
void buttonClicked(Button* button) {};
private:
};

Some files were not shown because too many files have changed in this diff Show More