diff --git a/data/lang/en_US.lang b/data/lang/en_US.lang index d9c161c..bdc0b35 100755 --- a/data/lang/en_US.lang +++ b/data/lang/en_US.lang @@ -145,6 +145,7 @@ options.gamma=Brightness options.gamma.min=Moody options.gamma.max=Bright options.group.mojang=Login +options.group.general=General options.group.game=Game options.group.controls=Controls options.group.graphics=Graphics @@ -187,6 +188,15 @@ options.particles=Particles options.particles.all=All options.particles.decreased=Decreased options.particles.minimal=Minimal +options.username=Username +options.smoothCamera=Smooth camera +options.destroyVibration=Destroy vibration +options.isLeftHanded=Left handed +options.useTouchscreen=Use touchscreen +options.fancyGraphics=Fancy graphics +options.renderDebug=Debug render +options.anaglyph3d=3D anaglyph + performance.max=Max FPS performance.balanced=Balanced @@ -194,21 +204,21 @@ performance.powersaver=Power saver controls.title=Controls -key.forward=Forward -key.left=Left -key.back=Back -key.right=Right -key.jump=Jump -key.inventory=Inventory -key.drop=Drop -key.chat=Chat -key.fog=Toggle Fog -key.sneak=Sneak -key.playerlist=List Players -key.attack=Attack -key.use=Use Item -key.pickItem=Pick Block -key.mouseButton=Button %1$s +options.key.forward=Forward +options.key.left=Left +options.key.back=Back +options.key.right=Right +options.key.jump=Jump +options.key.inventory=Inventory +options.key.drop=Drop +options.key.chat=Chat +options.key.fog=Toggle Fog +options.key.sneak=Sneak +options.key.playerlist=List Players +options.key.attack=Attack +options.key.use=Use Item +options.key.pickItem=Pick Block +options.key.mouseButton=Button %1$s texturePack.openFolder=Open texture pack folder texturePack.title=Select Texture Pack diff --git a/src/NinecraftApp.cpp b/src/NinecraftApp.cpp index be52b16..7d3cb7a 100755 --- a/src/NinecraftApp.cpp +++ b/src/NinecraftApp.cpp @@ -111,7 +111,9 @@ void NinecraftApp::init() #ifndef STANDALONE_SERVER LOGI("This: %p\n", this); screenChooser.setScreen(SCREEN_STARTMENU); - if (options.username.empty()) { + + if (options.getBooleanValue(OPTIONS_FIRST_LAUNCH)) { + options.toggle(OPTIONS_FIRST_LAUNCH); setScreen(new UsernameScreen()); } #else diff --git a/src/client/KeyMapping.h b/src/client/KeyMapping.h deleted file mode 100755 index 06740c8..0000000 --- a/src/client/KeyMapping.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef NET_MINECRAFT_CLIENT__KeyMapping_H__ -#define NET_MINECRAFT_CLIENT__KeyMapping_H__ - -//package net.minecraft.client; -#include - -class KeyMapping -{ -public: - std::string name; - int key; - - KeyMapping() {} - - KeyMapping(const std::string& name_, int key_) - : name(name_), - key(key_) - {} -}; - -#endif /*NET_MINECRAFT_CLIENT__KeyMapping_H__*/ diff --git a/src/client/Minecraft.cpp b/src/client/Minecraft.cpp index dde030e..1c9ba00 100755 --- a/src/client/Minecraft.cpp +++ b/src/client/Minecraft.cpp @@ -188,7 +188,7 @@ Minecraft::Minecraft() _powerVr(false), commandPort(4711), reserved_d1(0),reserved_d2(0), - reserved_f1(0),reserved_f2(0) + reserved_f1(0),reserved_f2(0), options(this) { //#ifdef ANDROID @@ -490,7 +490,7 @@ void Minecraft::update() { #ifndef STANDALONE_SERVER checkGlError("Update finished"); - if (options.renderDebug) { + if (options.getBooleanValue(OPTIONS_RENDER_DEBUG)) { #ifndef PLATFORM_DESKTOP if (!PerfTimer::enabled) { PerfTimer::reset(); @@ -558,7 +558,7 @@ void Minecraft::tick(int nTick, int maxTick) { TIMER_POP_PUSH("levelRenderer"); levelRenderer->tick(); #endif - level->difficulty = options.difficulty; + level->difficulty = options.getIntValue(OPTIONS_DIFFICULTY); if (level->isClientSide) level->difficulty = Difficulty::EASY; TIMER_POP_PUSH("level"); @@ -733,7 +733,7 @@ void Minecraft::tickInput() { } if (key == Keyboard::KEY_F5) { - options.thirdPersonView = !options.thirdPersonView; + options.toggle(OPTIONS_THIRD_PERSON_VIEW); /* ImprovedNoise noise; for (int i = 0; i < 16; ++i) @@ -1102,21 +1102,19 @@ bool Minecraft::useTouchscreen() { #ifdef RPI return false; #endif - return options.useTouchScreen || !_supportsNonTouchscreen; + return options.getBooleanValue(OPTIONS_USE_TOUCHSCREEN) || !_supportsNonTouchscreen; } bool Minecraft::supportNonTouchScreen() { return _supportsNonTouchscreen; } void Minecraft::init() { - options.minecraft = this; - options.initDefaultValues(); #ifndef STANDALONE_SERVER checkGlError("Init enter"); _supportsNonTouchscreen = !platform()->supportsTouchscreen(); - LOGI("IS TOUCHSCREEN? %d\n", options.useTouchScreen); + LOGI("IS TOUCHSCREEN? %d\n", options.getBooleanValue(OPTIONS_USE_TOUCHSCREEN)); textures = new Textures(&options, platform()); textures->addDynamicTexture(new WaterTexture()); @@ -1148,10 +1146,12 @@ void Minecraft::setSize(int w, int h) { width = w; height = h; + int guiScale = options.getIntValue(OPTIONS_GUI_SCALE); + // determine gui scale, optionally overriding auto - if (options.guiScale != 0) { + if (guiScale != 0) { // manual selection: 1->small, 2->normal, 3->large, 4->larger - switch (options.guiScale) { + switch (guiScale) { case 1: Gui::GuiScale = 2.0f; break; case 2: Gui::GuiScale = 3.0f; break; case 3: Gui::GuiScale = 4.0f; break; @@ -1184,11 +1184,11 @@ void Minecraft::setSize(int w, int h) { int screenWidth = (int)(width * Gui::InvGuiScale); int screenHeight = (int)(height * Gui::InvGuiScale); - if (platform()) { - float pixelsPerMillimeter = options.getProgressValue(&Options::Option::PIXELS_PER_MILLIMETER); - pixelCalc.setPixelsPerMillimeter(pixelsPerMillimeter); - pixelCalcUi.setPixelsPerMillimeter(pixelsPerMillimeter * Gui::InvGuiScale); - } + // if (platform()) { + // float pixelsPerMillimeter = options.getProgressValue(&Options::Option::PIXELS_PER_MILLIMETER); + // pixelCalc.setPixelsPerMillimeter(pixelsPerMillimeter); + // pixelCalcUi.setPixelsPerMillimeter(pixelsPerMillimeter * Gui::InvGuiScale); + // } Config config = createConfig(this); gui.onConfigChanged(config); @@ -1209,16 +1209,16 @@ void Minecraft::setSize(int w, int h) { } void Minecraft::reloadOptions() { - options.update(); options.save(); - bool wasTouchscreen = options.useTouchScreen; - options.useTouchScreen = useTouchscreen(); + bool wasTouchscreen = options.getBooleanValue(OPTIONS_USE_TOUCHSCREEN); + options.set(OPTIONS_USE_TOUCHSCREEN, useTouchscreen()); options.save(); - if ((wasTouchscreen != options.useTouchScreen) || (inputHolder == 0)) + if ((wasTouchscreen != useTouchscreen()) || (inputHolder == 0)) _reloadInput(); - user->name = options.username; + // TODO: + // user->name = options.username; LOGI("Reloading-options\n"); @@ -1523,24 +1523,24 @@ ICreator* Minecraft::getCreator() #endif } -void Minecraft::optionUpdated( const Options::Option* option, bool value ) { - if(netCallback != NULL && option == &Options::Option::SERVER_VISIBLE) { +void Minecraft::optionUpdated(OptionId option, bool value ) { + if(netCallback != NULL && option == OPTIONS_SERVER_VISIBLE) { ServerSideNetworkHandler* ss = (ServerSideNetworkHandler*) netCallback; ss->allowIncomingConnections(value); } } -void Minecraft::optionUpdated( const Options::Option* option, float value ) { -#ifndef STANDALONE_SERVER - if(option == &Options::Option::PIXELS_PER_MILLIMETER) { - pixelCalcUi.setPixelsPerMillimeter(value * Gui::InvGuiScale); - pixelCalc.setPixelsPerMillimeter(value); - } -#endif +void Minecraft::optionUpdated(OptionId option, float value ) { +// #ifndef STANDALONE_SERVER +// if(option == OPTIONS_PIXELS_PER_MILLIMETER) { +// pixelCalcUi.setPixelsPerMillimeter(value * Gui::InvGuiScale); +// pixelCalc.setPixelsPerMillimeter(value); +// } +// #endif } -void Minecraft::optionUpdated( const Options::Option* option, int value ) { - if(option == &Options::Option::GUI_SCALE) { +void Minecraft::optionUpdated(OptionId option, int value ) { + if(option == OPTIONS_GUI_SCALE) { // reapply screen scaling using current window size setSize(width, height); } diff --git a/src/client/Minecraft.h b/src/client/Minecraft.h index e333bab..1f9b3d7 100755 --- a/src/client/Minecraft.h +++ b/src/client/Minecraft.h @@ -116,9 +116,9 @@ public: bool isPowerVR() { return _powerVr; } bool isKindleFire(int kindleVersion); bool transformResolution(int* w, int* h); - void optionUpdated(const Options::Option* option, bool value); - void optionUpdated(const Options::Option* option, float value); - void optionUpdated(const Options::Option* option, int value); + void optionUpdated(OptionId option, bool value); + void optionUpdated(OptionId option, float value); + void optionUpdated(OptionId option, int value); #ifdef __APPLE__ bool _isSuperFast; bool isSuperFast() { return _isSuperFast; } diff --git a/src/client/Option.cpp b/src/client/Option.cpp new file mode 100644 index 0000000..0e92abc --- /dev/null +++ b/src/client/Option.cpp @@ -0,0 +1,49 @@ +#include "Option.h" +#include + +bool Option::parse_bool_like(const std::string& value, bool& out) { + if (value == "true" || value == "YES") { + out = true; + return true; + } + + if (value == "false" || value == "NO") { + out = false; + return true; + } + + return false; +} + +bool OptionFloat::parse(const std::string& value) { + bool b; + + if (parse_bool_like(value, b)) { + m_value = b ? 1.f : 0.f; + return true; + } + + return std::sscanf(value.c_str(), "%f", &m_value) == 1; +} +bool OptionInt::parse(const std::string& value) { + bool b; + if (parse_bool_like(value, b)) { + m_value = b ? 1 : 0; + return true; + } + + return std::sscanf(value.c_str(), "%d", &m_value) == 1; +} +bool OptionBool::parse(const std::string& value) { + if (value == "0") { + m_value = false; + return true; + } + + if (value == "1") { + m_value = true; + return true; + } + + return parse_bool_like(value, m_value); +} \ No newline at end of file diff --git a/src/client/Option.h b/src/client/Option.h new file mode 100644 index 0000000..5bb0e56 --- /dev/null +++ b/src/client/Option.h @@ -0,0 +1,107 @@ +#pragma once +#include +#include +#include +/* +template +struct is_option_type : std::false_type {}; + +template<> struct is_option_type : std::true_type {}; +template<> struct is_option_type : std::true_type {}; +template<> struct is_option_type : std::true_type {}; +template<> struct is_option_type : std::true_type {}; + +template +struct is_min_max_option : std::false_type {}; + +template<> struct is_min_max_option : std::true_type {}; +template<> struct is_min_max_option : std::true_type {}; +*/ + +class Option { +public: + Option(const std::string& key) : m_key("options." + key) {} + virtual ~Option() = default; + + const std::string& getStringId() { return m_key; } + + virtual bool parse(const std::string& value) { return false; } + virtual std::string serialize() { return m_key + ":"; } + +protected: + std::string m_key; + + template + std::string serialize_value(const T& value) const { + std::ostringstream ss; + ss << m_key << ":" << value; + return ss.str(); + } + + bool parse_bool_like(const std::string& value, bool& out); +}; + +class OptionFloat : public Option { +public: + OptionFloat(const std::string& key, float value = 0.f, float min = 0.f, float max = 1.f) : + Option(key), m_value(value), m_min(min), m_max(max) {} + + float get() { return m_value; } + void set(float value) { m_value = Mth::clamp(value, m_min, m_max); } + + float getMin() { return m_min; } + float getMax() { return m_max; } + + virtual bool parse(const std::string& value); + virtual std::string serialize() { return serialize_value(m_value); } + +private: + float m_value, m_min, m_max; +}; + +class OptionInt : public Option { +public: + OptionInt(const std::string& key, int value = 0, int min = -999999, int max = 999999) : + Option(key), m_value(value), m_min(min), m_max(max) {} + + int get() { return m_value; } + void set(int value) { m_value = Mth::clamp(value, m_min, m_max); } + + int getMin() { return m_min; } + int getMax() { return m_max; } + + virtual bool parse(const std::string& value); + virtual std::string serialize() { return serialize_value(m_value); } + +private: + int m_value, m_min, m_max; +}; + +class OptionBool : public Option { +public: + OptionBool(const std::string& key, bool value = false) : Option(key), m_value(value) {} + + bool get() { return m_value; } + void set(int value) { m_value = value; } + void toggle() { m_value = !m_value; } + + virtual bool parse(const std::string& value); + virtual std::string serialize() { return serialize_value(m_value); } + +private: + bool m_value; +}; + +class OptionString : public Option { +public: + OptionString(const std::string& key, const std::string& str = "") : Option(key), m_value(str) {} + + const std::string& get() { return m_value; } + void set(const std::string& value) { m_value = value; } + + virtual bool parse(const std::string& value) { m_value = value; return true; } + virtual std::string serialize() { return m_key + ":" + m_value; } + +private: + std::string m_value; +}; \ No newline at end of file diff --git a/src/client/OptionStrings.cpp b/src/client/OptionStrings.cpp index 9edeb85..2a68643 100755 --- a/src/client/OptionStrings.cpp +++ b/src/client/OptionStrings.cpp @@ -16,3 +16,4 @@ const char* OptionStrings::Controls_IsLefthanded = "ctrl_islefthanded"; const char* OptionStrings::Controls_FeedbackVibration = "feedback_vibration"; const char* OptionStrings::Game_DifficultyLevel = "game_difficulty"; + diff --git a/src/client/Options.cpp b/src/client/Options.cpp index eda251c..029df47 100755 --- a/src/client/Options.cpp +++ b/src/client/Options.cpp @@ -4,476 +4,289 @@ #include "../platform/log.h" #include "../world/Difficulty.h" #include -#include -/*static*/ + +#include + bool Options::debugGl = false; -void Options::initDefaultValues() { - difficulty = Difficulty::NORMAL; - hideGui = false; - thirdPersonView = false; - renderDebug = false; - isFlying = false; - smoothCamera = true; - fixedCamera = false; - flySpeed = 1; - cameraSpeed = 1; - guiScale = 0; +// OPTIONS TABLE - useMouseForDigging = false; - destroyVibration = true; - isLeftHanded = false; +OptionInt difficulty("difficulty", Difficulty::NORMAL, 0, Difficulty::COUNT); +OptionBool hidegui("hidegui", false); +OptionBool thirdPersonView("thirdperson", false); +OptionBool renderDebug("renderDebug", false); +OptionBool smoothCamera("smoothCamera", false); +OptionBool fixedCamera("fixedCamera", false); +OptionBool isFlying("isflying", false); - isJoyTouchArea = false; +OptionFloat flySpeed("flySpeed", 1.f); +OptionFloat cameraSpeed("cameraSpeed", 1.f); - music = 1; - sound = 1; - sensitivity = 0.5f; - invertYMouse = false; - viewDistance = 2; - bobView = true; - anaglyph3d = false; - limitFramerate = false; - vsync = true; - fancyGraphics = true;//false; - ambientOcclusion = false; - if(minecraft->supportNonTouchScreen()) - useTouchScreen = false; - else - useTouchScreen = true; - pixelsPerMillimeter = minecraft->platform()->getPixelsPerMillimeter(); - //useMouseForDigging = true; +OptionInt guiScale("guiScale", 0, 0, 5); - //skin = "Default"; - username = ""; - serverVisible = true; +OptionString skin("skin", "Default"); - keyUp = KeyMapping("key.forward", Keyboard::KEY_W); - keyLeft = KeyMapping("key.left", Keyboard::KEY_A); - keyDown = KeyMapping("key.back", Keyboard::KEY_S); - keyRight = KeyMapping("key.right", Keyboard::KEY_D); - keyJump = KeyMapping("key.jump", Keyboard::KEY_SPACE); - keyBuild = KeyMapping("key.inventory", Keyboard::KEY_E); - keySneak = KeyMapping("key.sneak", Keyboard::KEY_LSHIFT); -#ifndef RPI - // keyCraft = KeyMapping("key.crafting", Keyboard::KEY_Q); - keyDrop = KeyMapping("key.drop", Keyboard::KEY_Q); - keyChat = KeyMapping("key.chat", Keyboard::KEY_T); - keyFog = KeyMapping("key.fog", Keyboard::KEY_F); - keyDestroy=KeyMapping("key.destroy", 88); // @todo @fix - keyUse = KeyMapping("key.use", Keyboard::KEY_U); +#ifdef RPI +OptionString username("username", "StevePi"); +#else +OptionString username("username", "Steve"); #endif - //const int Unused = 99999; - keyMenuNext = KeyMapping("key.menu.next", 40); - keyMenuPrevious = KeyMapping("key.menu.previous", 38); - keyMenuOk = KeyMapping("key.menu.ok", 13); - keyMenuCancel = KeyMapping("key.menu.cancel", 8); +OptionBool destroyVibration("destroyVibration", true); +OptionBool isLeftHanded("isLeftHanded", false); +OptionBool isJoyTouchArea("isJoyTouchArea", false); - int k = 0; - keyMappings[k++] = &keyUp; - keyMappings[k++] = &keyLeft; - keyMappings[k++] = &keyDown; - keyMappings[k++] = &keyRight; - keyMappings[k++] = &keyJump; - keyMappings[k++] = &keySneak; - keyMappings[k++] = &keyDrop; - keyMappings[k++] = &keyBuild; - keyMappings[k++] = &keyChat; - keyMappings[k++] = &keyFog; - keyMappings[k++] = &keyDestroy; - keyMappings[k++] = &keyUse; +OptionFloat musicVolume("music", 1.f, MUSIC_MIN_VALUE, MUSIC_MAX_VALUE); +OptionFloat soundVolume("sound", 1.f, SOUND_MIN_VALUE, SOUND_MAX_VALUE); - keyMappings[k++] = &keyMenuNext; - keyMappings[k++] = &keyMenuPrevious; - keyMappings[k++] = &keyMenuOk; - keyMappings[k++] = &keyMenuCancel; +OptionFloat sensitivityOpt("sensitivity", 0.5f, SENSITIVITY_MIN_VALUE, SENSITIVITY_MAX_VALUE); -// "Polymorphism" at it's worst. At least it's better to have it here -// for now, then to have it spread all around the game code (even if -// it would be slightly better performance with it inlined. Should -// probably create separate subclasses (or read from file). @fix @todo. -#if defined(ANDROID) || defined(__APPLE__) || defined(RPI) - viewDistance = 2; - thirdPersonView = false; - useMouseForDigging = false; - fancyGraphics = false; +OptionBool invertYMouse("invertMouse", false); +OptionInt viewDistance("renderDistance", 2, 0, 4); - //renderDebug = true; - #if !defined(RPI) - keyUp.key = 19; - keyDown.key = 20; - keyLeft.key = 21; - keyRight.key = 22; - keyJump.key = 23; - keyUse.key = 103; - keyDestroy.key = 102; - keyCraft.key = 109; +OptionBool anaglyph3d("anaglyph3d", false); +OptionBool limitFramerate("limitFramerate", false); +OptionBool vsync("vsync", true); +OptionBool fancyGraphics("fancyGraphics", true); +OptionBool viewBobbing("viewBobbing", true); +OptionBool ambientOcclusion("ao", false); - keyMenuNext.key = 20; - keyMenuPrevious.key = 19; - keyMenuOk.key = 23; - keyMenuCancel.key = 4; +OptionBool useTouchscreen("useTouchscreen", true); + +OptionBool serverVisible("servervisible", true); + +OptionInt keyForward("key.forward", Keyboard::KEY_W); +OptionInt keyLeft("key.left", Keyboard::KEY_A); +OptionInt keyBack("key.back", Keyboard::KEY_S); +OptionInt keyRight("key.right", Keyboard::KEY_D); +OptionInt keyJump("key.jump", Keyboard::KEY_SPACE); +OptionInt keyInventory("key.inventory", Keyboard::KEY_E); +OptionInt keySneak("key.sneak", Keyboard::KEY_LSHIFT); +OptionInt keyDrop("key.drop", Keyboard::KEY_Q); +OptionInt keyChat("key.chat", Keyboard::KEY_T); +OptionInt keyFog("key.fog", Keyboard::KEY_F); +OptionInt keyUse("key.use", Keyboard::KEY_U); + +// TODO: make human readable keycodes here +OptionInt keyMenuNext("key.menu.next", 40); +OptionInt keyMenuPrev("key.menu.previous", 38); +OptionInt keyMenuOk("key.menu.ok", 13); +OptionInt keyMenuCancel("key.menu.cancel", 8); + +OptionBool firstLaunch("firstLaunch", true); + +void Options::initTable() { + m_options[OPTIONS_DIFFICULTY] = &difficulty; + m_options[OPTIONS_HIDEGUI] = &hidegui; + m_options[OPTIONS_THIRD_PERSON_VIEW] = &thirdPersonView; + m_options[OPTIONS_RENDER_DEBUG] = &renderDebug; + m_options[OPTIONS_SMOOTH_CAMERA] = &smoothCamera; + m_options[OPTIONS_FIXED_CAMERA] = &fixedCamera; + m_options[OPTIONS_IS_FLYING] = &isFlying; + + m_options[OPTIONS_FLY_SPEED] = &flySpeed; + m_options[OPTIONS_CAMERA_SPEED] = &cameraSpeed; + + m_options[OPTIONS_GUI_SCALE] = &guiScale; + + m_options[OPTIONS_DESTROY_VIBRATION] = &destroyVibration; + + m_options[OPTIONS_IS_LEFT_HANDED] = &isLeftHanded; + m_options[OPTIONS_IS_JOY_TOUCH_AREA] = &isJoyTouchArea; + + m_options[OPTIONS_MUSIC_VOLUME] = &musicVolume; + m_options[OPTIONS_SOUND_VOLUME] = &soundVolume; + + #if defined(PLATFORM_DESKTOP) || defined(RPI) + float sensitivity = sensitivityOpt.get(); + sensitivity *= 0.4f; + sensitivityOpt.set(sensitivity); #endif -#endif -#if defined(PLATFORM_DESKTOP) || defined(RPI) - sensitivity *= 0.4f; -#endif -#if defined(RPI) - username = "StevePi"; - useMouseForDigging = true; -#endif + + + m_options[OPTIONS_GUI_SCALE] = &guiScale; + + m_options[OPTIONS_SKIN] = &skin; + m_options[OPTIONS_USERNAME] = &username; + + m_options[OPTIONS_DESTROY_VIBRATION] = &destroyVibration; + m_options[OPTIONS_IS_LEFT_HANDED] = &isLeftHanded; + + m_options[OPTIONS_MUSIC_VOLUME] = &musicVolume; + m_options[OPTIONS_SOUND_VOLUME] = &soundVolume; + + m_options[OPTIONS_SENSITIVITY] = &sensitivityOpt; + + m_options[OPTIONS_INVERT_Y_MOUSE] = &invertYMouse; + m_options[OPTIONS_VIEW_DISTANCE] = &viewDistance; + + m_options[OPTIONS_ANAGLYPH_3D] = &anaglyph3d; + m_options[OPTIONS_LIMIT_FRAMERATE] = &limitFramerate; + m_options[OPTIONS_VSYNC] = &vsync; + m_options[OPTIONS_FANCY_GRAPHICS] = &fancyGraphics; + m_options[OPTIONS_VIEW_BOBBING] = &viewBobbing; + m_options[OPTIONS_AMBIENT_OCCLUSION] = &ambientOcclusion; + + m_options[OPTIONS_USE_TOUCHSCREEN] = &useTouchscreen; + + m_options[OPTIONS_SERVER_VISIBLE] = &serverVisible; + + m_options[OPTIONS_KEY_FORWARD] = &keyForward; + m_options[OPTIONS_KEY_LEFT] = &keyLeft; + m_options[OPTIONS_KEY_BACK] = &keyBack; + m_options[OPTIONS_KEY_RIGHT] = &keyRight; + m_options[OPTIONS_KEY_JUMP] = &keyJump; + m_options[OPTIONS_KEY_INVENTORY] = &keyInventory; + m_options[OPTIONS_KEY_SNEAK] = &keySneak; + m_options[OPTIONS_KEY_DROP] = &keyDrop; + m_options[OPTIONS_KEY_CHAT] = &keyChat; + m_options[OPTIONS_KEY_FOG] = &keyFog; + m_options[OPTIONS_KEY_USE] = &keyUse; + + m_options[OPTIONS_KEY_MENU_NEXT] = &keyMenuNext; + m_options[OPTIONS_KEY_MENU_PREV] = &keyMenuPrev; + m_options[OPTIONS_KEY_MENU_OK] = &keyMenuOk; + m_options[OPTIONS_KEY_MENU_CANCEL] = &keyMenuCancel; + + m_options[OPTIONS_FIRST_LAUNCH] = &firstLaunch; } -const Options::Option - Options::Option::MUSIC (0, "options.music", true, false), - Options::Option::SOUND (1, "options.sound", true, false), - Options::Option::INVERT_MOUSE (2, "options.invertMouse", false, true), - Options::Option::SENSITIVITY (3, "options.sensitivity", true, false), - Options::Option::RENDER_DISTANCE (4, "options.renderDistance",false, false), - Options::Option::VIEW_BOBBING (5, "options.viewBobbing", false, true), - Options::Option::ANAGLYPH (6, "options.anaglyph", false, true), - Options::Option::LIMIT_FRAMERATE (7, "options.limitFramerate",false, true), - Options::Option::DIFFICULTY (8, "options.difficulty", false, false), - Options::Option::GRAPHICS (9, "options.graphics", false, false), - Options::Option::AMBIENT_OCCLUSION (10, "options.ao", false, true), - Options::Option::GUI_SCALE (11, "options.guiScale", false, false), - Options::Option::THIRD_PERSON (12, "options.thirdperson", false, true), - Options::Option::HIDE_GUI (13, "options.hidegui", false, true), - Options::Option::SERVER_VISIBLE (14, "options.servervisible", false, true), - Options::Option::LEFT_HANDED (15, "options.lefthanded", false, true), - Options::Option::USE_TOUCHSCREEN (16, "options.usetouchscreen", false, true), - Options::Option::USE_TOUCH_JOYPAD (17, "options.usetouchpad", false, true), - Options::Option::DESTROY_VIBRATION (18, "options.destroyvibration", false, true), - Options::Option::PIXELS_PER_MILLIMETER(19, "options.pixelspermilimeter", true, false), - Options::Option::VSYNC (20, "options.vsync", false, true); +void Options::set(OptionId key, const std::string& value) { + auto option = opt(key); -/* private */ -const float Options::SOUND_MIN_VALUE = 0.0f; -const float Options::SOUND_MAX_VALUE = 1.0f; -const float Options::MUSIC_MIN_VALUE = 0.0f; -const float Options::MUSIC_MAX_VALUE = 1.0f; -const float Options::SENSITIVITY_MIN_VALUE = 0.0f; -const float Options::SENSITIVITY_MAX_VALUE = 1.0f; -const float Options::PIXELS_PER_MILLIMETER_MIN_VALUE = 3.0f; -const float Options::PIXELS_PER_MILLIMETER_MAX_VALUE = 4.0f; -const int DIFFICULY_LEVELS[] = { - Difficulty::PEACEFUL, - Difficulty::NORMAL -}; + if (option) { + option->set(value); -/*private*/ -const char* Options::RENDER_DISTANCE_NAMES[] = { - "options.renderDistance.far", - "options.renderDistance.normal", - "options.renderDistance.short", - "options.renderDistance.tiny" -}; + notifyOptionUpdate(key, value); + save(); + } +} -/*private*/ -const char* Options::DIFFICULTY_NAMES[] = { - "options.difficulty.peaceful", - "options.difficulty.easy", - "options.difficulty.normal", - "options.difficulty.hard" -}; +void Options::set(OptionId key, float value) { + auto option = opt(key); -/*private*/ -const char* Options::GUI_SCALE[] = { - "options.guiScale.auto", - "options.guiScale.small", - "options.guiScale.normal", - "options.guiScale.large", - "options.guiScale.larger" -}; + if (option) { + option->set(value); -void Options::update() -{ - viewDistance = 2; + notifyOptionUpdate(key, value); + save(); + } +} + +void Options::set(OptionId key, int value) { + auto option = opt(key); + + if (option) { + option->set(value); + + notifyOptionUpdate(key, value); + save(); + } +} + +void Options::toggle(OptionId key) { + auto option = opt(key); + + if (option) { + option->toggle(); + + notifyOptionUpdate(key, option->get()); + save(); + } +} + +void Options::load() { StringVector optionStrings = optionsFile.getOptionStrings(); - for (unsigned int i = 0; i < optionStrings.size(); i += 2) { + + for (auto i = 0; i < optionStrings.size(); i += 2) { const std::string& key = optionStrings[i]; const std::string& value = optionStrings[i+1]; - //LOGI("reading key: %s (%s)\n", key.c_str(), value.c_str()); + // FIXME: woah this is so slow + auto opt = std::find_if(m_options.begin(), m_options.end(), [&](auto& it) { + return it != nullptr && it->getStringId() == key; + }); + + if (opt == m_options.end()) continue; + + (*opt)->parse(value); +/* + // //LOGI("reading key: %s (%s)\n", key.c_str(), value.c_str()); - // Multiplayer - if (key == OptionStrings::Multiplayer_Username) username = value; - if (key == OptionStrings::Multiplayer_ServerVisible) readBool(value, serverVisible); + // // Multiplayer + // // if (key == OptionStrings::Multiplayer_Username) username = value; + // if (key == OptionStrings::Multiplayer_ServerVisible) { + // m_options[OPTIONS_SERVER_VISIBLE] = readBool(value); + // } - // Controls - if (key == OptionStrings::Controls_Sensitivity) { - float sens; - if (readFloat(value, sens)) { - // sens is in range [0,1] with default/center at 0.5 (for aesthetics) - // We wanna map it to something like [0.3, 0.9] BUT keep 0.5 @ ~0.5... - sensitivity = 0.3f + std::pow(1.1f * sens, 1.3f) * 0.42f; - } - } - if (key == OptionStrings::Controls_InvertMouse) { - readBool(value, invertYMouse); - } - if (key == OptionStrings::Controls_IsLefthanded) { - readBool(value, isLeftHanded); - } - if (key == OptionStrings::Controls_UseTouchJoypad) { - readBool(value, isJoyTouchArea); - if (!minecraft->useTouchscreen()) - isJoyTouchArea = false; - } + // // Controls + // if (key == OptionStrings::Controls_Sensitivity) { + // float sens = readFloat(value); - // Feedback - if (key == OptionStrings::Controls_FeedbackVibration) - readBool(value, destroyVibration); + // // sens is in range [0,1] with default/center at 0.5 (for aesthetics) + // // We wanna map it to something like [0.3, 0.9] BUT keep 0.5 @ ~0.5... + // m_options[OPTIONS_SENSITIVITY] = 0.3f + std::pow(1.1f * sens, 1.3f) * 0.42f; + // } - // Graphics - if (key == OptionStrings::Graphics_Fancy) { - readBool(value, fancyGraphics); - } - if (key == OptionStrings::Graphics_LowQuality) { - bool isLow; - readBool(value, isLow); - if (isLow) { - viewDistance = 3; - fancyGraphics = false; - } - } - // Graphics extras - if (key == OptionStrings::Graphics_Vsync) - readBool(value, vsync); - if (key == OptionStrings::Graphics_GUIScale) { - int v; - if (readInt(value, v)) guiScale = v % 5; - } - // Game - 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; - } + // if (key == OptionStrings::Controls_InvertMouse) { + // m_options[OPTIONS_INVERT_Y_MOUSE] = readBool(value); + // } + + // if (key == OptionStrings::Controls_IsLefthanded) { + // m_options[OPTIONS_IS_LEFT_HANDED] = readBool(value); + // } + + // if (key == OptionStrings::Controls_UseTouchJoypad) { + // m_options[OPTIONS_IS_JOY_TOUCH_AREA] = readBool(value) && minecraft->useTouchscreen(); + // } + + // // Feedback + // if (key == OptionStrings::Controls_FeedbackVibration) { + // m_options[OPTIONS_DESTROY_VIBRATION] = readBool(value); + // } + + // // Graphics + // if (key == OptionStrings::Graphics_Fancy) { + // m_options[OPTIONS_FANCY_GRAPHICS] = readBool(value); + // } + + // // Graphics extras + // if (key == OptionStrings::Graphics_Vsync) { + // m_options[OPTIONS_VSYNC] = readBool(value); + // } + + // if (key == OptionStrings::Graphics_GUIScale) { + // m_options[OPTIONS_GUI_SCALE] = readInt(value) % 5; + // } + + // // Game + // 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; + // }*/ } - -#ifdef __APPLE__ -// if (minecraft->isSuperFast()) { -// viewDistance = (viewDistance>0)? --viewDistance : 0; -// } -// LOGI("Is this card super fast?: %d\n", viewDistance); -#endif - - //LOGI("Lefty is: %d\n", isLeftHanded); } -void Options::load() -{ - int a = 0; - //try { - // if (!optionsFile.exists()) return; - // BufferedReader br = /*new*/ BufferedReader(/*new*/ FileReader(optionsFile)); - // std::string line = ""; - // while ((line = br.readLine()) != NULL) { - // std::string[] cmds = line.split(":"); - // if (cmds[0].equals("music")) music = readFloat(cmds[1]); - // if (cmds[0].equals("sound")) sound = readFloat(cmds[1]); - // if (cmds[0].equals("mouseSensitivity")) sensitivity = readFloat(cmds[1]); - // if (cmds[0].equals("invertYMouse")) invertYMouse = cmds[1].equals("true"); - // if (cmds[0].equals("viewDistance")) viewDistance = Integer.parseInt(cmds[1]); - // if (cmds[0].equals("guiScale")) guiScale = Integer.parseInt(cmds[1]); - // if (cmds[0].equals("bobView")) bobView = cmds[1].equals("true"); - // if (cmds[0].equals("anaglyph3d")) anaglyph3d = cmds[1].equals("true"); - // if (cmds[0].equals("limitFramerate")) limitFramerate = cmds[1].equals("true"); - // if (cmds[0].equals("difficulty")) difficulty = Integer.parseInt(cmds[1]); - // if (cmds[0].equals("fancyGraphics")) fancyGraphics = cmds[1].equals("true"); - // if (cmds[0].equals("ao")) ambientOcclusion = cmds[1].equals("true"); - // if (cmds[0].equals("skin")) skin = cmds[1]; - // if (cmds[0].equals("lastServer") && cmds.length >= 2) lastMpIp = cmds[1]; - - // for (int i = 0; i < keyMappings.length; i++) { - // if (cmds[0].equals("key_" + keyMappings[i].name)) { - // keyMappings[i].key = Integer.parseInt(cmds[1]); - // } - // } - // } - // br.close(); - //} catch (Exception e) { - // System.out.println("Failed to load options"); - // e.printStackTrace(); - //} -} - -void Options::save() -{ +void Options::save() { StringVector stringVec; - // Login - addOptionToSaveOutput(stringVec, OptionStrings::Multiplayer_Username, username); - // Game - addOptionToSaveOutput(stringVec, OptionStrings::Multiplayer_ServerVisible, serverVisible); - addOptionToSaveOutput(stringVec, OptionStrings::Game_DifficultyLevel, difficulty); + + for (auto& it : m_options) { + if (it) stringVec.push_back(it->serialize()); + } - // Input - addOptionToSaveOutput(stringVec, OptionStrings::Controls_InvertMouse, invertYMouse); - addOptionToSaveOutput(stringVec, OptionStrings::Controls_Sensitivity, sensitivity); - addOptionToSaveOutput(stringVec, OptionStrings::Controls_IsLefthanded, isLeftHanded); - addOptionToSaveOutput(stringVec, OptionStrings::Controls_UseTouchScreen, useTouchScreen); - addOptionToSaveOutput(stringVec, OptionStrings::Controls_UseTouchJoypad, isJoyTouchArea); - addOptionToSaveOutput(stringVec, OptionStrings::Controls_FeedbackVibration, destroyVibration); - addOptionToSaveOutput(stringVec, OptionStrings::Graphics_Vsync, vsync); - addOptionToSaveOutput(stringVec, OptionStrings::Graphics_GUIScale, guiScale); -// -// static const Option MUSIC; -// static const Option SOUND; -// static const Option INVERT_MOUSE; -// static const Option SENSITIVITY; -// static const Option RENDER_DISTANCE; -// static const Option VIEW_BOBBING; -// static const Option ANAGLYPH; -// static const Option LIMIT_FRAMERATE; -// static const Option DIFFICULTY; -// static const Option GRAPHICS; -// static const Option AMBIENT_OCCLUSION; -// static const Option GUI_SCALE; -// -// static const Option THIRD_PERSON; -// static const Option HIDE_GUI; - //try { - // PrintWriter pw = /*new*/ PrintWriter(/*new*/ FileWriter(optionsFile)); - - // pw.println("music:" + music); - // pw.println("sound:" + sound); - // pw.println("invertYMouse:" + invertYMouse); - // pw.println("mouseSensitivity:" + sensitivity); - // pw.println("viewDistance:" + viewDistance); - // pw.println("guiScale:" + guiScale); - // pw.println("bobView:" + bobView); - // pw.println("anaglyph3d:" + anaglyph3d); - // pw.println("limitFramerate:" + limitFramerate); - // pw.println("difficulty:" + difficulty); - // pw.println("fancyGraphics:" + fancyGraphics); - // pw.println("ao:" + ambientOcclusion); - // pw.println("skin:" + skin); - // pw.println("lastServer:" + lastMpIp); - - // for (int i = 0; i < keyMappings.length; i++) { - // pw.println("key_" + keyMappings[i].name + ":" + keyMappings[i].key); - // } - - // pw.close(); - //} catch (Exception e) { - // System.out.println("Failed to save options"); - // e.printStackTrace(); - //} optionsFile.save(stringVec); } -void Options::addOptionToSaveOutput(StringVector& stringVector, std::string name, bool boolValue) { - std::stringstream ss; - ss << name << ":" << boolValue; - stringVector.push_back(ss.str()); -} -void Options::addOptionToSaveOutput(StringVector& stringVector, std::string name, float floatValue) { - std::stringstream ss; - ss << name << ":" << floatValue; - stringVector.push_back(ss.str()); -} -void Options::addOptionToSaveOutput(StringVector& stringVector, std::string name, int intValue) { - std::stringstream ss; - ss << name << ":" << intValue; - stringVector.push_back(ss.str()); -} -void Options::addOptionToSaveOutput(StringVector& stringVector, std::string name, const std::string& strValue) { - stringVector.push_back(name + ":" + strValue); + +void Options::notifyOptionUpdate(OptionId key, bool value) { + minecraft->optionUpdated(key, value); } -std::string Options::getMessage( const Option* item ) -{ - return "Options::getMessage - Not implemented"; - - //Language language = Language.getInstance(); - //std::string caption = language.getElement(item.getCaptionId()) + ": "; - - //if (item.isProgress()) { - // float progressValue = getProgressValue(item); - - // if (item == Option.SENSITIVITY) { - // if (progressValue == 0) { - // return caption + language.getElement("options.sensitivity.min"); - // } - // if (progressValue == 1) { - // return caption + language.getElement("options.sensitivity.max"); - // } - // return caption + (int) (progressValue * 200) + "%"; - // } else { - // if (progressValue == 0) { - // return caption + language.getElement("options.off"); - // } - // return caption + (int) (progressValue * 100) + "%"; - // } - //} else if (item.isBoolean()) { - - // bool booleanValue = getBooleanValue(item); - // if (booleanValue) { - // return caption + language.getElement("options.on"); - // } - // return caption + language.getElement("options.off"); - //} else if (item == Option.RENDER_DISTANCE) { - // return caption + language.getElement(RENDER_DISTANCE_NAMES[viewDistance]); - //} else if (item == Option.DIFFICULTY) { - // return caption + language.getElement(DIFFICULTY_NAMES[difficulty]); - //} else if (item == Option.GUI_SCALE) { - // return caption + language.getElement(GUI_SCALE[guiScale]); - //} else if (item == Option.GRAPHICS) { - // if (fancyGraphics) { - // return caption + language.getElement("options.graphics.fancy"); - // } - // return caption + language.getElement("options.graphics.fast"); - //} - - //return caption; +void Options::notifyOptionUpdate(OptionId key, float value) { + minecraft->optionUpdated(key, value); } -/*static*/ -bool Options::readFloat(const std::string& string, float& value) { - if (string == "true" || string == "YES") { value = 1; return true; } - if (string == "false" || string == "NO") { value = 0; return true; } -#ifdef _WIN32 - if (sscanf_s(string.c_str(), "%f", &value)) - return true; -#else - if (sscanf(string.c_str(), "%f", &value)) - return true; -#endif - return false; -} - -/*static*/ -bool Options::readInt(const std::string& string, int& value) { - if (string == "true" || string == "YES") { value = 1; return true; } - if (string == "false" || string == "NO") { value = 0; return true; } -#ifdef _WIN32 - if (sscanf_s(string.c_str(), "%d", &value)) - return true; -#else - if (sscanf(string.c_str(), "%d", &value)) - return true; -#endif - return false; -} - -/*static*/ -bool Options::readBool(const std::string& string, bool& value) { - std::string s = Util::stringTrim(string); - if (string == "true" || string == "1" || string == "YES") { value = true; return true; } - if (string == "false" || string == "0" || string == "NO") { value = false; return true; } - return false; -} - -void Options::notifyOptionUpdate( const Option* option, bool value ) { - minecraft->optionUpdated(option, value); -} - -void Options::notifyOptionUpdate( const Option* option, float value ) { - minecraft->optionUpdated(option, value); -} - -void Options::notifyOptionUpdate( const Option* option, int value ) { - minecraft->optionUpdated(option, value); +void Options::notifyOptionUpdate(OptionId key, int value) { + minecraft->optionUpdated(key, value); } diff --git a/src/client/Options.h b/src/client/Options.h index 5332880..dae75dd 100755 --- a/src/client/Options.h +++ b/src/client/Options.h @@ -1,16 +1,87 @@ #ifndef NET_MINECRAFT_CLIENT__Options_H__ #define NET_MINECRAFT_CLIENT__Options_H__ +#define SOUND_MIN_VALUE 0.0f +#define SOUND_MAX_VALUE 1.0f +#define MUSIC_MIN_VALUE 0.0f +#define MUSIC_MAX_VALUE 1.0f +#define SENSITIVITY_MIN_VALUE 0.0f +#define SENSITIVITY_MAX_VALUE 1.0f +#define PIXELS_PER_MILLIMETER_MIN_VALUE 3.0f +#define PIXELS_PER_MILLIMETER_MAX_VALUE 4.0f + //package net.minecraft.client; //#include "locale/Language.h" #include #include -#include "KeyMapping.h" #include "../platform/input/Keyboard.h" #include "../util/StringUtils.h" #include "OptionsFile.h" +#include "Option.h" +#include + +enum OptionId { + // General + OPTIONS_DIFFICULTY, + OPTIONS_HIDEGUI, + OPTIONS_THIRD_PERSON_VIEW, + OPTIONS_GUI_SCALE, + OPTIONS_DESTROY_VIBRATION, + OPTIONS_MUSIC_VOLUME, + OPTIONS_SOUND_VOLUME, + OPTIONS_SKIN, + OPTIONS_USERNAME, + OPTIONS_SERVER_VISIBLE, + + // Graphics + OPTIONS_RENDER_DEBUG, + OPTIONS_SMOOTH_CAMERA, + OPTIONS_FIXED_CAMERA, + OPTIONS_VIEW_DISTANCE, + OPTIONS_VIEW_BOBBING, + OPTIONS_AMBIENT_OCCLUSION, + OPTIONS_ANAGLYPH_3D, + OPTIONS_LIMIT_FRAMERATE, + OPTIONS_VSYNC, + OPTIONS_FANCY_GRAPHICS, + + // Cheats / debug + OPTIONS_FLY_SPEED, + OPTIONS_CAMERA_SPEED, + OPTIONS_IS_FLYING, + + // Control + OPTIONS_USE_MOUSE_FOR_DIGGING, + OPTIONS_IS_LEFT_HANDED, + OPTIONS_IS_JOY_TOUCH_AREA, + OPTIONS_SENSITIVITY, + OPTIONS_INVERT_Y_MOUSE, + OPTIONS_USE_TOUCHSCREEN, + + OPTIONS_KEY_FORWARD, + OPTIONS_KEY_LEFT, + OPTIONS_KEY_BACK, + OPTIONS_KEY_RIGHT, + OPTIONS_KEY_JUMP, + OPTIONS_KEY_INVENTORY, + OPTIONS_KEY_SNEAK, + OPTIONS_KEY_DROP, + OPTIONS_KEY_CHAT, + OPTIONS_KEY_FOG, + OPTIONS_KEY_USE, + + OPTIONS_KEY_MENU_NEXT, + OPTIONS_KEY_MENU_PREV, + OPTIONS_KEY_MENU_OK, + OPTIONS_KEY_MENU_CANCEL, + + OPTIONS_FIRST_LAUNCH, + + // Should be last! + OPTIONS_COUNT +}; class Minecraft; typedef std::vector StringVector; @@ -18,320 +89,72 @@ typedef std::vector StringVector; class Options { public: - class Option - { - const bool _isProgress; - const bool _isBoolean; - const std::string _captionId; - const int _ordinal; - - public: - static const Option MUSIC; - static const Option SOUND; - static const Option INVERT_MOUSE; - static const Option SENSITIVITY; - static const Option RENDER_DISTANCE; - static const Option VIEW_BOBBING; - static const Option ANAGLYPH; - static const Option LIMIT_FRAMERATE; - static const Option DIFFICULTY; - static const Option GRAPHICS; - static const Option AMBIENT_OCCLUSION; - static const Option GUI_SCALE; - - static const Option THIRD_PERSON; - static const Option HIDE_GUI; - static const Option SERVER_VISIBLE; - static const Option LEFT_HANDED; - static const Option USE_TOUCHSCREEN; - static const Option USE_TOUCH_JOYPAD; - static const Option DESTROY_VIBRATION; - - static const Option PIXELS_PER_MILLIMETER; - static const Option VSYNC; - - /* - static Option* getItem(int id) { - for (Option item : Option.values()) { - if (item.getId() == id) { - return item; - } - } - return NULL; - } - */ - - Option(int ordinal, const std::string& captionId, bool hasProgress, bool isBoolean) - : _captionId(captionId), - _isProgress(hasProgress), - _isBoolean(isBoolean), - _ordinal(ordinal) - {} - - bool isProgress() const { - return _isProgress; - } - - bool isBoolean() const { - return _isBoolean; - } - - bool isInt() const { - return (!_isBoolean && !_isProgress); - } - - int getId() { - return _ordinal; - } - - std::string getCaptionId() const { - return _captionId; - } - }; - -private: - static const float SOUND_MIN_VALUE; - static const float SOUND_MAX_VALUE; - static const float MUSIC_MIN_VALUE; - static const float MUSIC_MAX_VALUE; - static const float SENSITIVITY_MIN_VALUE; - static const float SENSITIVITY_MAX_VALUE; - static const float PIXELS_PER_MILLIMETER_MIN_VALUE; - static const float PIXELS_PER_MILLIMETER_MAX_VALUE; - static const char* RENDER_DISTANCE_NAMES[]; - static const char* DIFFICULTY_NAMES[]; - static const char* GUI_SCALE[]; - static const int DIFFICULY_LEVELS[]; -public: - static bool debugGl; - - float music; - float sound; - //note: sensitivity is transformed in Options::update - float sensitivity; - bool invertYMouse; - int viewDistance; - bool bobView; - bool anaglyph3d; - bool limitFramerate; - bool vsync; - bool fancyGraphics; - bool ambientOcclusion; - bool useMouseForDigging; - bool isLeftHanded; - bool destroyVibration; - //std::string skin; - - KeyMapping keyUp; - KeyMapping keyLeft; - KeyMapping keyDown; - KeyMapping keyRight; - KeyMapping keyJump; - KeyMapping keyBuild; - KeyMapping keyDrop; - KeyMapping keyChat; - KeyMapping keyFog; - KeyMapping keySneak; - KeyMapping keyCraft; - KeyMapping keyDestroy; - KeyMapping keyUse; - - KeyMapping keyMenuNext; - KeyMapping keyMenuPrevious; - KeyMapping keyMenuOk; - KeyMapping keyMenuCancel; - - KeyMapping* keyMappings[16]; - - /*protected*/ Minecraft* minecraft; - ///*private*/ File optionsFile; - - int difficulty; - bool hideGui; - bool thirdPersonView; - bool renderDebug; - - bool isFlying; - bool smoothCamera; - bool fixedCamera; - float flySpeed; - float cameraSpeed; - int guiScale; - std::string username; - - bool serverVisible; - bool isJoyTouchArea; - bool useTouchScreen; - float pixelsPerMillimeter; - Options(Minecraft* minecraft, const std::string& workingDirectory) - : minecraft(minecraft) - { - //optionsFile = /*new*/ File(workingDirectory, "options.txt"); - initDefaultValues(); + static bool debugGl; + Options(Minecraft* minecraft, const std::string& workingDirectory = "") + : minecraft(minecraft) { + initTable(); load(); } - Options() - : minecraft(NULL) - { - - } + void initTable(); - void initDefaultValues(); + void set(OptionId key, int value); + void set(OptionId key, float value); + void set(OptionId key, const std::string& value); + void toggle(OptionId key); - std::string getKeyDescription(int i) { - //Language language = Language.getInstance(); - //return language.getElement(keyMappings[i].name); - return "Options::getKeyDescription not implemented"; + int getIntValue(OptionId key) { + auto option = opt(key); + return (option)? option->get() : 0; } - std::string getKeyMessage(int i) { - //return Keyboard.getKeyName(keyMappings[i].key); - return "Options::getKeyMessage not implemented"; + std::string getStringValue(OptionId key) { + auto option = opt(key); + return (option)? option->get() : ""; } - void setKey(int i, int key) { - keyMappings[i]->key = key; - save(); + float getProgressValue(OptionId key) { + auto option = opt(key); + return (option)? option->get() : 0.f; } - void set(const Option* item, float value) { - if (item == &Option::MUSIC) { - music = value; - //minecraft.soundEngine.updateOptions(); - } else if (item == &Option::SOUND) { - sound = value; - //minecraft.soundEngine.updateOptions(); - } else if (item == &Option::SENSITIVITY) { - sensitivity = value; - } else if (item == &Option::PIXELS_PER_MILLIMETER) { - pixelsPerMillimeter = value; - } - notifyOptionUpdate(item, value); save(); } - void set(const Option* item, int value) { - if(item == &Option::DIFFICULTY) { - difficulty = value; - } else if(item == &Option::GUI_SCALE) { - guiScale = value % 5; - } - notifyOptionUpdate(item, value); - save(); - } - - void toggle(const Option* option, int dir) { - if (option == &Option::INVERT_MOUSE) invertYMouse = !invertYMouse; - if (option == &Option::RENDER_DISTANCE) viewDistance = (viewDistance + dir) & 3; - if (option == &Option::GUI_SCALE) guiScale = (guiScale + dir) % 5; - if (option == &Option::VIEW_BOBBING) bobView = !bobView; - if (option == &Option::THIRD_PERSON) thirdPersonView = !thirdPersonView; - if (option == &Option::HIDE_GUI) hideGui = !hideGui; - if (option == &Option::SERVER_VISIBLE) serverVisible = !serverVisible; - if (option == &Option::LEFT_HANDED) isLeftHanded = !isLeftHanded; - if (option == &Option::USE_TOUCHSCREEN) useTouchScreen = !useTouchScreen; - if (option == &Option::USE_TOUCH_JOYPAD) isJoyTouchArea = !isJoyTouchArea; - if (option == &Option::DESTROY_VIBRATION) destroyVibration = !destroyVibration; - if (option == &Option::ANAGLYPH) { - anaglyph3d = !anaglyph3d; - //minecraft->textures.reloadAll(); - } - if (option == &Option::LIMIT_FRAMERATE) limitFramerate = !limitFramerate; - if (option == &Option::VSYNC) vsync = !vsync; - if (option == &Option::DIFFICULTY) difficulty = (difficulty + dir) & 3; - if (option == &Option::GRAPHICS) { - fancyGraphics = !fancyGraphics; - //minecraft->levelRenderer.allChanged(); - } - if (option == &Option::AMBIENT_OCCLUSION) { - ambientOcclusion = !ambientOcclusion; - //minecraft->levelRenderer.allChanged(); - } - notifyOptionUpdate(option, getBooleanValue(option)); - save(); + bool getBooleanValue(OptionId key) { + auto option = opt(key); + return (option)? option->get() : false; } - int getIntValue(const Option* item) { - if(item == &Option::DIFFICULTY) return difficulty; - if(item == &Option::GUI_SCALE) return guiScale; - return 0; - } - - float getProgressValue(const Option* item) { - if (item == &Option::MUSIC) return music; - if (item == &Option::SOUND) return sound; - if (item == &Option::SENSITIVITY) return sensitivity; - if (item == &Option::PIXELS_PER_MILLIMETER) return pixelsPerMillimeter; - return 0; + float getProgrssMin(OptionId key) { + auto option = opt(key); + return (option)? option->getMin() : 0.f; } - bool getBooleanValue(const Option* item) { - if (item == &Option::INVERT_MOUSE) - return invertYMouse; - if (item == &Option::VIEW_BOBBING) - return bobView; - if (item == &Option::ANAGLYPH) - return anaglyph3d; - if (item == &Option::LIMIT_FRAMERATE) - return limitFramerate; - if (item == &Option::VSYNC) - return vsync; - if (item == &Option::AMBIENT_OCCLUSION) - return ambientOcclusion; - if (item == &Option::THIRD_PERSON) - return thirdPersonView; - if (item == &Option::HIDE_GUI) - return hideGui; - if (item == &Option::THIRD_PERSON) - return thirdPersonView; - if (item == &Option::SERVER_VISIBLE) - return serverVisible; - if (item == &Option::LEFT_HANDED) - return isLeftHanded; - if (item == &Option::USE_TOUCHSCREEN) - return useTouchScreen; - if (item == &Option::USE_TOUCH_JOYPAD) - return isJoyTouchArea; - if (item == &Option::DESTROY_VIBRATION) - return destroyVibration; - return false; - } + float getProgrssMax(OptionId key) { + auto option = opt(key); + return (option)? option->getMax() : 0.f; + } - float getProgrssMin(const Option* item) { - if (item == &Option::MUSIC) return MUSIC_MIN_VALUE; - if (item == &Option::SOUND) return SOUND_MIN_VALUE; - if (item == &Option::SENSITIVITY) return SENSITIVITY_MIN_VALUE; - if (item == &Option::PIXELS_PER_MILLIMETER) return PIXELS_PER_MILLIMETER_MIN_VALUE; - return 0; - } + Option* getOpt(OptionId id) { return m_options[id]; } - float getProgrssMax(const Option* item) { - if (item == &Option::MUSIC) return MUSIC_MAX_VALUE; - if (item == &Option::SOUND) return SOUND_MAX_VALUE; - if (item == &Option::SENSITIVITY) return SENSITIVITY_MAX_VALUE; - if (item == &Option::PIXELS_PER_MILLIMETER) return PIXELS_PER_MILLIMETER_MAX_VALUE; - return 1.0f; - } - - std::string getMessage(const Option* item); - - void update(); void load(); void save(); - void addOptionToSaveOutput(StringVector& stringVector, std::string name, bool boolValue); - void addOptionToSaveOutput(StringVector& stringVector, std::string name, float floatValue); - void addOptionToSaveOutput(StringVector& stringVector, std::string name, int intValue); - void addOptionToSaveOutput(StringVector& stringVector, std::string name, const std::string& strValue); - void notifyOptionUpdate(const Option* option, bool value); - void notifyOptionUpdate(const Option* option, float value); - void notifyOptionUpdate(const Option* option, int value); -private: - static bool readFloat(const std::string& string, float& value); - static bool readInt(const std::string& string, int& value); - static bool readBool(const std::string& string, bool& value); + + void notifyOptionUpdate(OptionId key, bool value); + void notifyOptionUpdate(OptionId key, float value); + void notifyOptionUpdate(OptionId key, int value); + void notifyOptionUpdate(OptionId key, const std::string& value) {} private: + template + T* opt(OptionId key) { + if (m_options[key] == nullptr) return nullptr; + return dynamic_cast(m_options[key]); + } + + std::array m_options; OptionsFile optionsFile; - + + Minecraft* minecraft; }; #endif /*NET_MINECRAFT_CLIENT__Options_H__*/ diff --git a/src/client/gamemode/GameMode.cpp b/src/client/gamemode/GameMode.cpp index 7535f35..8a71a82 100755 --- a/src/client/gamemode/GameMode.cpp +++ b/src/client/gamemode/GameMode.cpp @@ -74,7 +74,7 @@ bool GameMode::destroyBlock(int x, int y, int z, int face) { minecraft->soundEngine->play(oldTile->soundType->getBreakSound(), x + 0.5f, y + 0.5f, z + 0.5f, (oldTile->soundType->getVolume() + 1) / 2, oldTile->soundType->getPitch() * 0.8f); #endif oldTile->destroy(level, x, y, z, data); - if (minecraft->options.destroyVibration) minecraft->platform()->vibrate(24); + if (minecraft->options.getBooleanValue(OPTIONS_DESTROY_VIBRATION)) minecraft->platform()->vibrate(24); if (minecraft->isOnline()) { RemoveBlockPacket packet(minecraft->player, x, y, z); diff --git a/src/client/gui/Gui.cpp b/src/client/gui/Gui.cpp index d6ddc14..27f19e0 100755 --- a/src/client/gui/Gui.cpp +++ b/src/client/gui/Gui.cpp @@ -119,7 +119,7 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) { #if defined(RPI) renderDebugInfo(); #elif defined(PLATFORM_DESKTOP) - if (minecraft->options.renderDebug) + if (minecraft->options.getBooleanValue(OPTIONS_RENDER_DEBUG)) renderDebugInfo(); #endif @@ -219,7 +219,7 @@ void Gui::handleKeyPressed(int key) { minecraft->screenChooser.setScreen(SCREEN_BLOCKSELECTION); } - else if (key == minecraft->options.keyDrop.key) + else if (key == minecraft->options.getIntValue(OPTIONS_KEY_DROP)) { minecraft->player->inventory->dropSlot(minecraft->player->inventory->selected, false); } @@ -402,7 +402,7 @@ void Gui::onConfigChanged( const Config& c ) { if (c.minecraft->useTouchscreen()) { // I'll bump this up to 6. int num = 6; // without "..." dots - if (!c.minecraft->options.isJoyTouchArea && c.width > 480) { + if (!c.minecraft->options.getBooleanValue(OPTIONS_IS_JOY_TOUCH_AREA) && c.width > 480) { while (num < Inventory::MAX_SELECTION_SIZE - 1) { int x0, x1, y; getSlotPos(0, x0, y); @@ -516,7 +516,7 @@ void Gui::renderProgressIndicator( const bool isTouchInterface, const int screen ItemInstance* currentItem = minecraft->player->inventory->getSelected(); bool bowEquipped = currentItem != NULL ? currentItem->getItem() == Item::bow : false; bool itemInUse = currentItem != NULL ? currentItem->getItem() == minecraft->player->getUseItem()->getItem() : false; - if (!isTouchInterface || minecraft->options.isJoyTouchArea || (bowEquipped && itemInUse)) { + if (!isTouchInterface || minecraft->options.getBooleanValue(OPTIONS_IS_JOY_TOUCH_AREA) || (bowEquipped && itemInUse)) { minecraft->textures->loadAndBindTexture("gui/icons.png"); glEnable(GL_BLEND); glBlendFunc2(GL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_SRC_COLOR); diff --git a/src/client/gui/Screen.cpp b/src/client/gui/Screen.cpp index cc6c0c7..d9bcaea 100755 --- a/src/client/gui/Screen.cpp +++ b/src/client/gui/Screen.cpp @@ -104,7 +104,7 @@ void Screen::keyboardEvent() } void Screen::keyboardTextEvent() { - keyboardNewChar(Keyboard::getChar()); + charPressed(Keyboard::getChar()); } void Screen::renderBackground() { @@ -166,7 +166,7 @@ void Screen::keyPressed( int eventKey ) // pass key events to any text boxes first for (auto& textbox : textBoxes) { - textbox->handleKey(eventKey); + textbox->keyPressed(minecraft, eventKey); } if (minecraft->useTouchscreen()) @@ -178,11 +178,11 @@ void Screen::keyPressed( int eventKey ) return; Options& o = minecraft->options; - if (eventKey == o.keyMenuNext.key) + if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_NEXT)) if (++tabButtonIndex == tabButtonCount) tabButtonIndex = 0; - if (eventKey == o.keyMenuPrevious.key) + if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_PREV)) if (--tabButtonIndex == -1) tabButtonIndex = tabButtonCount-1; - if (eventKey == o.keyMenuOk.key) { + if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_OK)) { Button* button = tabButtons[tabButtonIndex]; if (button->active) { minecraft->soundEngine->playUI("random.click", 1, 1); @@ -193,6 +193,12 @@ void Screen::keyPressed( int eventKey ) updateTabButtonSelection(); } +void Screen::charPressed(char inputChar) { + for (auto& textbox : textBoxes) { + textbox->charPressed(minecraft, inputChar); + } +} + void Screen::updateTabButtonSelection() { if (minecraft->useTouchscreen()) diff --git a/src/client/gui/Screen.h b/src/client/gui/Screen.h index eebe588..72d3453 100755 --- a/src/client/gui/Screen.h +++ b/src/client/gui/Screen.h @@ -58,7 +58,7 @@ protected: virtual void mouseReleased(int x, int y, int buttonNum); virtual void keyPressed(int eventKey); - virtual void keyboardNewChar(char inputChar) {} + virtual void charPressed(char inputChar); public: int width; int height; diff --git a/src/client/gui/components/GuiElement.h b/src/client/gui/components/GuiElement.h index d54a371..f0a0a33 100755 --- a/src/client/gui/components/GuiElement.h +++ b/src/client/gui/components/GuiElement.h @@ -9,13 +9,20 @@ class GuiElement : public GuiComponent { public: GuiElement(bool active=false, bool visible=true, int x = 0, int y = 0, int width=24, int height=24); virtual ~GuiElement() {} - virtual void tick(Minecraft* minecraft) {} + + virtual void tick(Minecraft* minecraft) {} virtual void render(Minecraft* minecraft, int xm, int ym) { } virtual void setupPositions() {} + virtual void mouseClicked(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 charPressed(Minecraft* minecraft, char key) {} + virtual bool pointInside(int x, int y); + void setVisible(bool visible); + bool active; bool visible; int x; diff --git a/src/client/gui/components/GuiElementContainer.cpp b/src/client/gui/components/GuiElementContainer.cpp index b9ea085..9cfbb09 100755 --- a/src/client/gui/components/GuiElementContainer.cpp +++ b/src/client/gui/components/GuiElementContainer.cpp @@ -52,3 +52,15 @@ void GuiElementContainer::mouseReleased( Minecraft* minecraft, int x, int y, int (*it)->mouseReleased(minecraft, x, y, buttonNum); } } + +void GuiElementContainer::keyPressed(Minecraft* minecraft, int key) { + for(std::vector::iterator it = children.begin(); it != children.end(); ++it) { + (*it)->keyPressed(minecraft, key); + } +} + +void GuiElementContainer::charPressed(Minecraft* minecraft, char key) { + for(std::vector::iterator it = children.begin(); it != children.end(); ++it) { + (*it)->charPressed(minecraft, key); + } +} \ No newline at end of file diff --git a/src/client/gui/components/GuiElementContainer.h b/src/client/gui/components/GuiElementContainer.h index 3b20bae..d20f9d3 100755 --- a/src/client/gui/components/GuiElementContainer.h +++ b/src/client/gui/components/GuiElementContainer.h @@ -17,8 +17,9 @@ public: virtual void tick( Minecraft* minecraft ); virtual void mouseClicked( 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 charPressed(Minecraft* minecraft, char key); protected: std::vector children; diff --git a/src/client/gui/components/ImageButton.cpp b/src/client/gui/components/ImageButton.cpp index ce01534..1c7a57a 100755 --- a/src/client/gui/components/ImageButton.cpp +++ b/src/client/gui/components/ImageButton.cpp @@ -4,6 +4,7 @@ #include "../../../platform/log.h" #include "../../../util/Mth.h" #include "../../renderer/Textures.h" +#include ImageButton::ImageButton(int id, const std::string& msg) @@ -112,43 +113,17 @@ void ImageButton::render(Minecraft* minecraft, int xm, int ym) { // // A toggleable Button // -OptionButton::OptionButton(const Options::Option* option) -: _option(option), - _isFloat(false), - super(ButtonId, "") -{ -} - -OptionButton::OptionButton(const Options::Option* option, float onValue, float offValue) -: _option(option), - _isFloat(true), - _onValue(onValue), - _offValue(offValue), - super(ButtonId, "") -{ -} - -bool OptionButton::isSecondImage(bool hovered) { - return _secondImage; -} +OptionButton::OptionButton(OptionId option) : m_optId(option), super(ButtonId, "") {} void OptionButton::toggle(Options* options) { - if (_isFloat) { - options->set(_option, (Mth::abs(_current - _onValue) < 0.01f) ? _offValue : _onValue); - } else { - options->toggle(_option, 1); - } + options->toggle(m_optId); + // Update graphics here updateImage(options); } void OptionButton::updateImage(Options* options) { - if (_isFloat) { - _current = options->getProgressValue(_option); - _secondImage = Mth::abs(_current - _onValue) < 0.01f; - } else { - _secondImage = options->getBooleanValue(_option); - } + _secondImage = options->getBooleanValue(m_optId); } void OptionButton::mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ) { diff --git a/src/client/gui/components/ImageButton.h b/src/client/gui/components/ImageButton.h index f14c25f..a1bd777 100755 --- a/src/client/gui/components/ImageButton.h +++ b/src/client/gui/components/ImageButton.h @@ -77,28 +77,20 @@ class OptionButton: public ImageButton { typedef ImageButton super; public: - OptionButton(const Options::Option* option); - OptionButton(const Options::Option* option, float onValue, float offValue); + OptionButton(OptionId optId); void toggle(Options* options); void updateImage(Options* options); static const int ButtonId = 9999999; protected: - bool isSecondImage(bool hovered); + bool isSecondImage(bool hovered) { return _secondImage; } virtual void mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ); private: - - const Options::Option* _option; + OptionId m_optId; bool _secondImage; - - // If not float, it's considered to be a boolean value - bool _isFloat; - float _onValue; - float _offValue; - float _current; }; diff --git a/src/client/gui/components/KeyOption.cpp b/src/client/gui/components/KeyOption.cpp new file mode 100644 index 0000000..36b4c7f --- /dev/null +++ b/src/client/gui/components/KeyOption.cpp @@ -0,0 +1,22 @@ +#include "KeyOption.h" +#include + +KeyOption::KeyOption(Minecraft* minecraft, OptionId optId) + : Touch::TButton((int)optId, Keyboard::getKeyName(minecraft->options.getIntValue(optId))) {} + + +void KeyOption::mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum) { + selected = isInside(x, y); + msg = (selected)? "..." : Keyboard::getKeyName(minecraft->options.getIntValue((OptionId)id)); +} + +void KeyOption::keyPressed(Minecraft* minecraft, int key) { + if (!selected) return; + + if (key != Keyboard::KEY_ESCAPE) { + minecraft->options.set((OptionId)id, key); + } + + selected = false; + msg = Keyboard::getKeyName(minecraft->options.getIntValue((OptionId)id)); +} \ No newline at end of file diff --git a/src/client/gui/components/KeyOption.h b/src/client/gui/components/KeyOption.h new file mode 100644 index 0000000..fabdc7a --- /dev/null +++ b/src/client/gui/components/KeyOption.h @@ -0,0 +1,14 @@ +#pragma once +#include "Button.h" +#include + +class KeyOption : public Touch::TButton { +public: + KeyOption(Minecraft* minecraft, OptionId optId); + + virtual void mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum); + virtual void released(int mx, int my) {} + virtual void keyPressed(Minecraft* minecraft, int key); +protected: + bool m_captureMode; +}; \ No newline at end of file diff --git a/src/client/gui/components/OptionsGroup.cpp b/src/client/gui/components/OptionsGroup.cpp index 3879adb..89e7915 100755 --- a/src/client/gui/components/OptionsGroup.cpp +++ b/src/client/gui/components/OptionsGroup.cpp @@ -4,6 +4,9 @@ #include "OptionsItem.h" #include "Slider.h" #include "../../../locale/I18n.h" +#include "TextOption.h" +#include "KeyOption.h" + OptionsGroup::OptionsGroup( std::string labelID ) { label = I18n::get(labelID); } @@ -25,74 +28,88 @@ void OptionsGroup::setupPositions() { void OptionsGroup::render( Minecraft* minecraft, int xm, int ym ) { float padX = 10.0f; float padY = 5.0f; + minecraft->font->draw(label, (float)x + padX, (float)y + padY, 0xffffffff, false); + super::render(minecraft, xm, ym); } -OptionsGroup& OptionsGroup::addOptionItem( const Options::Option* option, Minecraft* minecraft ) { - if(option->isBoolean()) - createToggle(option, minecraft); - else if(option->isProgress()) - createProgressSlider(option, minecraft); - else if(option->isInt()) - createStepSlider(option, minecraft); +OptionsGroup& OptionsGroup::addOptionItem(OptionId optId, Minecraft* minecraft ) { + auto option = minecraft->options.getOpt(optId); + + if (option == nullptr) return *this; + + // TODO: do a options key class to check it faster via dynamic_cast + if (option->getStringId().find("options.key") != std::string::npos) createKey(optId, minecraft); + else if (dynamic_cast(option)) createToggle(optId, minecraft); + else if (dynamic_cast(option)) createProgressSlider(optId, minecraft); + else if (dynamic_cast(option)) createStepSlider(optId, minecraft); + else if (dynamic_cast(option)) createTextbox(optId, minecraft); + return *this; } -void OptionsGroup::createToggle( const Options::Option* option, Minecraft* minecraft ) { +// TODO: wrap this copypaste shit into templates + +void OptionsGroup::createToggle(OptionId optId, Minecraft* minecraft ) { ImageDef def; + def.setSrc(IntRectangle(160, 206, 39, 20)); def.name = "gui/touchgui.png"; def.width = 39 * 0.7f; def.height = 20 * 0.7f; - OptionButton* element = new OptionButton(option); + + OptionButton* element = new OptionButton(optId); element->setImageDef(def, true); element->updateImage(&minecraft->options); - std::string itemLabel = I18n::get(option->getCaptionId()); + + std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId()); + + OptionsItem* item = new OptionsItem(itemLabel, element); + + addChild(item); + setupPositions(); +} + +void OptionsGroup::createProgressSlider(OptionId optId, Minecraft* minecraft ) { + Slider* element = new SliderFloat(minecraft, optId); + element->width = 100; + element->height = 20; + + std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId()); OptionsItem* item = new OptionsItem(itemLabel, element); addChild(item); setupPositions(); } -void OptionsGroup::createProgressSlider( const Options::Option* option, Minecraft* minecraft ) { - Slider* element = new Slider(minecraft, - option, - minecraft->options.getProgrssMin(option), - minecraft->options.getProgrssMax(option)); +void OptionsGroup::createStepSlider(OptionId optId, Minecraft* minecraft ) { + Slider* element = new SliderInt(minecraft, optId); element->width = 100; element->height = 20; - std::string itemLabel = I18n::get(option->getCaptionId()); + std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId()); OptionsItem* item = new OptionsItem(itemLabel, element); addChild(item); setupPositions(); } -void OptionsGroup::createStepSlider( const Options::Option* option, Minecraft* minecraft ) { - // integer-valued option; use step slider - std::vector steps; - // render distance was removed; fall through to other cases - if(option == &Options::Option::DIFFICULTY) { - steps.push_back(0); - steps.push_back(1); - steps.push_back(2); - steps.push_back(3); - } else if(option == &Options::Option::GUI_SCALE) { - // slider order: small,normal,large,larger,auto - steps.push_back(1); - steps.push_back(2); - steps.push_back(3); - steps.push_back(4); - steps.push_back(0); - } else { - // fallback: use single value; duplicate so numSteps>1 and avoid divide-by-zero - steps.push_back(0); - steps.push_back(0); - } - Slider* element = new Slider(minecraft, option, steps); +void OptionsGroup::createTextbox(OptionId optId, Minecraft* minecraft) { + TextBox* element = new TextOption(minecraft, optId); element->width = 100; element->height = 20; - std::string itemLabel = I18n::get(option->getCaptionId()); + + std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId()); OptionsItem* item = new OptionsItem(itemLabel, element); addChild(item); setupPositions(); } + +void OptionsGroup::createKey(OptionId optId, Minecraft* minecraft) { + KeyOption* element = new KeyOption(minecraft, optId); + element->width = 50; + element->height = 20; + + std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId()); + OptionsItem* item = new OptionsItem(itemLabel, element); + addChild(item); + setupPositions(); +} \ No newline at end of file diff --git a/src/client/gui/components/OptionsGroup.h b/src/client/gui/components/OptionsGroup.h index 5fbe0c0..24d28bd 100755 --- a/src/client/gui/components/OptionsGroup.h +++ b/src/client/gui/components/OptionsGroup.h @@ -5,6 +5,7 @@ #include #include "GuiElementContainer.h" +#include "ScrollingPane.h" #include "../../Options.h" class Font; @@ -16,11 +17,15 @@ public: OptionsGroup(std::string labelID); virtual void setupPositions(); virtual void render(Minecraft* minecraft, int xm, int ym); - virtual OptionsGroup& addOptionItem(const Options::Option* option, Minecraft* minecraft); + OptionsGroup& addOptionItem(OptionId optId, Minecraft* minecraft); protected: - virtual void createToggle(const Options::Option* option, Minecraft* minecraft); - virtual void createProgressSlider(const Options::Option* option, Minecraft* minecraft); - virtual void createStepSlider(const Options::Option* option, Minecraft* minecraft); + + void createToggle(OptionId optId, Minecraft* minecraft); + void createProgressSlider(OptionId optId, Minecraft* minecraft); + void createStepSlider(OptionId optId, Minecraft* minecraft); + void createTextbox(OptionId optId, Minecraft* minecraft); + void createKey(OptionId optId, Minecraft* minecraft); + std::string label; }; diff --git a/src/client/gui/components/OptionsPane.cpp b/src/client/gui/components/OptionsPane.cpp deleted file mode 100755 index f00f5f0..0000000 --- a/src/client/gui/components/OptionsPane.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include "OptionsPane.h" -#include "OptionsGroup.h" -#include "OptionsItem.h" -#include "ImageButton.h" -#include "Slider.h" -#include "../../Minecraft.h" - -OptionsPane::OptionsPane() { - -} - -void OptionsPane::setupPositions() { - int currentHeight = y + 1; - for(std::vector::iterator it = children.begin(); it != children.end(); ++it ) { - (*it)->width = width; - (*it)->y = currentHeight; - (*it)->x = x; - currentHeight += (*it)->height + 1; - } - height = currentHeight; - super::setupPositions(); -} - -OptionsGroup& OptionsPane::createOptionsGroup( std::string label ) { - OptionsGroup* newGroup = new OptionsGroup(label); - children.push_back(newGroup); - // create and return a new group index - return *newGroup; -} - -void OptionsPane::createToggle( unsigned int group, std::string label, const Options::Option* option ) { -// if(group > children.size()) return; -// ImageDef def; -// def.setSrc(IntRectangle(160, 206, 39, 20)); -// def.name = "gui/touchgui.png"; -// def.width = 39 * 0.7f; -// def.height = 20 * 0.7f; -// OptionButton* element = new OptionButton(option); -// element->setImageDef(def, true); -// OptionsItem* item = new OptionsItem(label, element); -// ((OptionsGroup*)children[group])->addChild(item); -// setupPositions(); -} - -void OptionsPane::createProgressSlider( Minecraft* minecraft, unsigned int group, std::string label, const Options::Option* option, float progressMin/*=1.0f*/, float progressMax/*=1.0f */ ) { -// if(group > children.size()) return; -// Slider* element = new Slider(minecraft, option, progressMin, progressMax); -// element->width = 100; -// element->height = 20; -// OptionsItem* item = new OptionsItem(label, element); -// ((OptionsGroup*)children[group])->addChild(item); -// setupPositions(); -} - -void OptionsPane::createStepSlider( Minecraft* minecraft, unsigned int group, std::string label, const Options::Option* option, const std::vector& stepVec ) { -// if(group > children.size()) return; -// Slider* element = new Slider(minecraft, option, stepVec); -// element->width = 100; -// element->height = 20; -// sliders.push_back(element); -// OptionsItem* item = new OptionsItem(label, element); -// ((OptionsGroup*)children[group])->addChild(item); -// setupPositions(); -} \ No newline at end of file diff --git a/src/client/gui/components/OptionsPane.h b/src/client/gui/components/OptionsPane.h deleted file mode 100755 index 5eb9652..0000000 --- a/src/client/gui/components/OptionsPane.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef ITEMPANE_H__ -#define ITEMPANE_H__ - -#include -#include -#include "GuiElementContainer.h" -#include "../../../world/item/ItemInstance.h" -#include "../../../client/Options.h" -class Font; -class Textures; -class NinePatchLayer; -class ItemPane; -class OptionButton; -class Button; -class OptionsGroup; -class Slider; -class Minecraft; -class OptionsPane: public GuiElementContainer -{ - typedef GuiElementContainer super; -public: - OptionsPane(); - OptionsGroup& createOptionsGroup( std::string label ); - void createToggle( unsigned int group, std::string label, const Options::Option* option ); - void createProgressSlider(Minecraft* minecraft, unsigned int group, std::string label, const Options::Option* option, float progressMin=1.0f, float progressMax=1.0f ); - void createStepSlider(Minecraft* minecraft, unsigned int group, std::string label, const Options::Option* option, const std::vector& stepVec ); - void setupPositions(); -}; - -#endif /*ITEMPANE_H__*/ diff --git a/src/client/gui/components/Slider.cpp b/src/client/gui/components/Slider.cpp index 791058e..68dba4a 100755 --- a/src/client/gui/components/Slider.cpp +++ b/src/client/gui/components/Slider.cpp @@ -5,39 +5,8 @@ #include "../../../util/Mth.h" #include #include -Slider::Slider(Minecraft* minecraft, const Options::Option* option, float progressMin, float progressMax) -: sliderType(SliderProgress), mouseDownOnElement(false), option(option), numSteps(0), progressMin(progressMin), progressMax(progressMax) { - if(option != NULL) { - percentage = (minecraft->options.getProgressValue(option) - progressMin) / (progressMax - progressMin); - } -} -Slider::Slider(Minecraft* minecraft, const Options::Option* option, const std::vector& stepVec ) -: sliderType(SliderStep), - curStepValue(0), - curStep(0), - sliderSteps(stepVec), - mouseDownOnElement(false), - option(option), - percentage(0), - progressMin(0.0f), - progressMax(1.0) { - assert(stepVec.size() > 1); - numSteps = sliderSteps.size(); - if(option != NULL) { - // initialize slider position based on the current option value - curStepValue = minecraft->options.getIntValue(option); - auto currentItem = std::find(sliderSteps.begin(), sliderSteps.end(), curStepValue); - if(currentItem != sliderSteps.end()) { - curStep = static_cast(currentItem - sliderSteps.begin()); - } else { - // fallback to first step - curStep = 0; - curStepValue = sliderSteps[0]; - } - percentage = float(curStep) / float(numSteps - 1); - } -} +Slider::Slider(OptionId optId) : m_mouseDownOnElement(false), m_optId(optId), m_numSteps(0) {} void Slider::render( Minecraft* minecraft, int xm, int ym ) { int xSliderStart = x + 5; @@ -49,61 +18,71 @@ void Slider::render( Minecraft* minecraft, int xm, int ym ) { int barWidth = xSliderEnd - xSliderStart; //fill(x, y + 8, x + (int)(width * percentage), y + height, 0xffff00ff); fill(xSliderStart, ySliderStart, xSliderEnd, ySliderEnd, 0xff606060); - if(sliderType == SliderStep) { - // numSteps should be >=2; protect against bad input (zero division) - if(numSteps <= 1) { - // nothing to render - } else { - int stepDistance = barWidth / (numSteps -1); - for(int a = 0; a <= numSteps - 1; ++a) { - int renderSliderStepPosX = xSliderStart + a * stepDistance + 1; - fill(renderSliderStepPosX - 1, ySliderStart - 2, renderSliderStepPosX + 1, ySliderEnd + 2, 0xff606060); - } + + if (m_numSteps > 2) { + int stepDistance = barWidth / (m_numSteps-1); + for(int a = 0; a <= m_numSteps; ++a) { + int renderSliderStepPosX = xSliderStart + a * stepDistance + 1; + fill(renderSliderStepPosX - 1, ySliderStart - 2, renderSliderStepPosX + 1, ySliderEnd + 2, 0xff606060); } } + minecraft->textures->loadAndBindTexture("gui/touchgui.png"); - blit(xSliderStart + (int)(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 ) { if(pointInside(x, y)) { - mouseDownOnElement = true; + m_mouseDownOnElement = true; } } void Slider::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) { - mouseDownOnElement = false; - if(sliderType == SliderStep) { - curStep = Mth::floor((percentage * (numSteps-1) + 0.5f)); - curStepValue = sliderSteps[Mth::Min(curStep, numSteps-1)]; - percentage = float(curStep) / (numSteps - 1); - setOption(minecraft); - } -} + m_mouseDownOnElement = false; +} void Slider::tick(Minecraft* minecraft) { if(minecraft->screen != NULL) { int xm = Mouse::getX(); int ym = Mouse::getY(); + minecraft->screen->toGUICoordinate(xm, ym); - if(mouseDownOnElement) { - percentage = float(xm - x) / float(width); - percentage = Mth::clamp(percentage, 0.0f, 1.0f); - setOption(minecraft); + + if(m_mouseDownOnElement) { + m_percentage = float(xm - x) / float(width); + m_percentage = Mth::clamp(m_percentage, 0.0f, 1.0f); } } } -void Slider::setOption( Minecraft* minecraft ) { - if(option != NULL) { - if(sliderType == SliderStep) { - if(minecraft->options.getIntValue(option) != curStepValue) { - minecraft->options.set(option, curStepValue); - } - } else { - if(minecraft->options.getProgressValue(option) != percentage * (progressMax - progressMin) + progressMin) { - minecraft->options.set(option, percentage * (progressMax - progressMin) + progressMin); - } - } +SliderFloat::SliderFloat(Minecraft* minecraft, OptionId option) +: Slider(option), m_option(dynamic_cast(minecraft->options.getOpt(option))) +{ + m_percentage = Mth::clamp((m_option->get() - m_option->getMin()) / (m_option->getMax() - m_option->getMin()), 0.f, 1.f); +} + +SliderInt::SliderInt(Minecraft* minecraft, OptionId option) +: Slider(option), m_option(dynamic_cast(minecraft->options.getOpt(option))) +{ + m_numSteps = m_option->getMax() - m_option->getMin(); + m_percentage = float(m_option->get() - m_option->getMin()) / (m_numSteps-1); +} + +void SliderInt::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) { + Slider::mouseReleased(minecraft, x, y, buttonNum); + + if (pointInside(x, y)) { + int curStep = Mth::floor(m_percentage * (m_numSteps-1)); + m_percentage = float(curStep - m_option->getMin()) / (m_numSteps-1); + + minecraft->options.set(m_optId, curStep); } } + +void SliderFloat::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) { + Slider::mouseReleased(minecraft, x, y, buttonNum); + + if (pointInside(x, y)) { + minecraft->options.set(m_optId, m_percentage * (m_option->getMax() - m_option->getMin()) + m_option->getMin()); + } +} \ No newline at end of file diff --git a/src/client/gui/components/Slider.h b/src/client/gui/components/Slider.h index d51b507..ef57450 100755 --- a/src/client/gui/components/Slider.h +++ b/src/client/gui/components/Slider.h @@ -3,38 +3,45 @@ #include "GuiElement.h" #include "../../../client/Options.h" -enum SliderType { - SliderProgress, // Sets slider between {0..1} - SliderStep // Uses the closest step -}; +#include + class Slider : public GuiElement { typedef GuiElement super; public: - // Creates a progress slider with no steps - Slider(Minecraft* minecraft, const Options::Option* option, float progressMin, float progressMax); - Slider(Minecraft* minecraft, const Options::Option* option, const std::vector& stepVec); virtual void render( Minecraft* minecraft, int xm, int ym ); - virtual void mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ); - virtual void mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ); - virtual void tick(Minecraft* minecraft); - -private: - virtual void setOption(Minecraft* minecraft); -private: - SliderType sliderType; - std::vector sliderSteps; - bool mouseDownOnElement; - float percentage; - int curStepValue; - int curStep; - int numSteps; - float progressMin; - float progressMax; - const Options::Option* option; +protected: + Slider(OptionId optId); + + OptionId m_optId; + + bool m_mouseDownOnElement; + float m_percentage; + int m_numSteps; +}; + +class SliderFloat : public Slider { +public: + SliderFloat(Minecraft* minecraft, OptionId option); + + virtual void mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) override; + +protected: + OptionFloat* m_option; +}; + + +class SliderInt : public Slider { +public: + SliderInt(Minecraft* minecraft, OptionId option); + + virtual void mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) override; + +protected: + OptionInt* m_option; }; #endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__Slider_H__*/ diff --git a/src/client/gui/components/SmallButton.cpp b/src/client/gui/components/SmallButton.cpp deleted file mode 100755 index e2ebfaa..0000000 --- a/src/client/gui/components/SmallButton.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "SmallButton.h" - -SmallButton::SmallButton( int id, int x, int y, const std::string& msg ) -: super(id, x, y, 150, 20, msg), - option(NULL) -{ -} - -SmallButton::SmallButton( int id, int x, int y, int width, int height, const std::string& msg ) -: super(id, x, y, width, height, msg), - option(NULL) -{ -} - -SmallButton::SmallButton( int id, int x, int y, Options::Option* item, const std::string& msg ) -: super(id, x, y, 150, 20, msg), - option(item) -{ -} - -Options::Option* SmallButton::getOption() -{ - return option; -} diff --git a/src/client/gui/components/SmallButton.h b/src/client/gui/components/SmallButton.h deleted file mode 100755 index 05ae378..0000000 --- a/src/client/gui/components/SmallButton.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__SmallButton_H__ -#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__SmallButton_H__ - -//package net.minecraft.client.gui; - -#include -#include "Button.h" -#include "../../Options.h" - -class SmallButton: public Button -{ - typedef Button super; -public: - SmallButton(int id, int x, int y, const std::string& msg); - SmallButton(int id, int x, int y, int width, int height, const std::string& msg); - SmallButton(int id, int x, int y, Options::Option* item, const std::string& msg); - - Options::Option* getOption(); -private: - Options::Option* option; -}; - -#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__SmallButton_H__*/ diff --git a/src/client/gui/components/TextBox.cpp b/src/client/gui/components/TextBox.cpp index 21f0d28..16bf8a6 100755 --- a/src/client/gui/components/TextBox.cpp +++ b/src/client/gui/components/TextBox.cpp @@ -49,13 +49,13 @@ void TextBox::mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum) { } } -void TextBox::handleChar(char c) { +void TextBox::charPressed(Minecraft* minecraft, char c) { if (focused && c >= 32 && c < 127 && (int)text.size() < 256) { text.push_back(c); } } -void TextBox::handleKey(int key) { +void TextBox::keyPressed(Minecraft* minecraft, int key) { if (focused && key == Keyboard::KEY_BACKSPACE && !text.empty()) { text.pop_back(); } diff --git a/src/client/gui/components/TextBox.h b/src/client/gui/components/TextBox.h index 5a2d4c6..34ea5a7 100755 --- a/src/client/gui/components/TextBox.h +++ b/src/client/gui/components/TextBox.h @@ -26,8 +26,8 @@ public: virtual void render(Minecraft* minecraft, int xm, int ym); - virtual void handleKey(int key); - virtual void handleChar(char c); + virtual void keyPressed(Minecraft* minecraft, int key); + virtual void charPressed(Minecraft* minecraft, char c); virtual void tick(Minecraft* minecraft); public: diff --git a/src/client/gui/components/TextOption.cpp b/src/client/gui/components/TextOption.cpp new file mode 100644 index 0000000..83b8535 --- /dev/null +++ b/src/client/gui/components/TextOption.cpp @@ -0,0 +1,17 @@ +#include "TextOption.h" +#include + +TextOption::TextOption(Minecraft* minecraft, OptionId optId) + : TextBox((int)optId, minecraft->options.getOpt(optId)->getStringId()) +{ + text = minecraft->options.getStringValue(optId); +} + +bool TextOption::loseFocus(Minecraft* minecraft) { + if (TextBox::loseFocus(minecraft)) { + minecraft->options.set((OptionId)id, text); + return true; + } + + return false; +} \ No newline at end of file diff --git a/src/client/gui/components/TextOption.h b/src/client/gui/components/TextOption.h new file mode 100644 index 0000000..89c545c --- /dev/null +++ b/src/client/gui/components/TextOption.h @@ -0,0 +1,10 @@ +#pragma once +#include "TextBox.h" +#include + +class TextOption : public TextBox { +public: + TextOption(Minecraft* minecraft, OptionId optId); + + virtual bool loseFocus(Minecraft* minecraft); +}; \ No newline at end of file diff --git a/src/client/gui/screens/ConfirmScreen.h b/src/client/gui/screens/ConfirmScreen.h index 07f40b3..0fedbe9 100755 --- a/src/client/gui/screens/ConfirmScreen.h +++ b/src/client/gui/screens/ConfirmScreen.h @@ -4,7 +4,6 @@ //package net.minecraft.client.gui; #include "../Screen.h" -#include "../components/SmallButton.h" #include class ConfirmScreen: public Screen diff --git a/src/client/gui/screens/ConsoleScreen.cpp b/src/client/gui/screens/ConsoleScreen.cpp index 869eded..b3d45d3 100644 --- a/src/client/gui/screens/ConsoleScreen.cpp +++ b/src/client/gui/screens/ConsoleScreen.cpp @@ -48,7 +48,7 @@ void ConsoleScreen::keyPressed(int eventKey) } } -void ConsoleScreen::keyboardNewChar(char inputChar) +void ConsoleScreen::charPressed(char inputChar) { if (inputChar >= 32 && inputChar < 127) _input += inputChar; diff --git a/src/client/gui/screens/ConsoleScreen.h b/src/client/gui/screens/ConsoleScreen.h index f2e7bce..e0074b9 100644 --- a/src/client/gui/screens/ConsoleScreen.h +++ b/src/client/gui/screens/ConsoleScreen.h @@ -20,7 +20,7 @@ public: virtual bool isPauseScreen() { return false; } virtual void keyPressed(int eventKey); - virtual void keyboardNewChar(char inputChar); + virtual void charPressed(char inputChar); virtual bool handleBackEvent(bool isDown); private: diff --git a/src/client/gui/screens/IngameBlockSelectionScreen.cpp b/src/client/gui/screens/IngameBlockSelectionScreen.cpp index bc6fc64..181d69f 100755 --- a/src/client/gui/screens/IngameBlockSelectionScreen.cpp +++ b/src/client/gui/screens/IngameBlockSelectionScreen.cpp @@ -169,19 +169,19 @@ void IngameBlockSelectionScreen::keyPressed(int eventKey) int tmpSelectedSlot = selectedItem; Options& o = minecraft->options; - if (eventKey == o.keyLeft.key && selX > 0) + if (eventKey == o.getIntValue(OPTIONS_KEY_LEFT) && selX > 0) { tmpSelectedSlot -= 1; } - else if (eventKey == o.keyRight.key && selX < (InventoryCols - 1)) + else if (eventKey == o.getIntValue(OPTIONS_KEY_RIGHT) && selX < (InventoryCols - 1)) { tmpSelectedSlot += 1; } - else if (eventKey == o.keyDown.key && selY < (InventoryRows - 1)) + else if (eventKey == o.getIntValue(OPTIONS_KEY_BACK) && selY < (InventoryRows - 1)) { tmpSelectedSlot += InventoryCols; } - else if (eventKey == o.keyUp.key && selY > 0) + else if (eventKey == o.getIntValue(OPTIONS_KEY_FORWARD) && selY > 0) { tmpSelectedSlot -= InventoryCols; } @@ -189,15 +189,15 @@ void IngameBlockSelectionScreen::keyPressed(int eventKey) if (isAllowed(tmpSelectedSlot)) selectedItem = tmpSelectedSlot; - if (eventKey == o.keyMenuOk.key) + if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_OK)) selectSlotAndClose(); #ifdef RPI - if (eventKey == o.keyMenuCancel.key + if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_CANCEL) || eventKey == Keyboard::KEY_ESCAPE) minecraft->setScreen(NULL); #else - if (eventKey == o.keyMenuCancel.key) + if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_CANCEL)) minecraft->setScreen(NULL); #endif } diff --git a/src/client/gui/screens/JoinGameScreen.h b/src/client/gui/screens/JoinGameScreen.h index f4d5cbc..4c6fc20 100755 --- a/src/client/gui/screens/JoinGameScreen.h +++ b/src/client/gui/screens/JoinGameScreen.h @@ -3,7 +3,6 @@ #include "../Screen.h" #include "../components/Button.h" -#include "../components/SmallButton.h" #include "../components/ScrolledSelectionList.h" #include "../../Minecraft.h" #include "../../../network/RakNetInstance.h" diff --git a/src/client/gui/screens/OptionsScreen.cpp b/src/client/gui/screens/OptionsScreen.cpp index 0a4ca89..9c37a22 100755 --- a/src/client/gui/screens/OptionsScreen.cpp +++ b/src/client/gui/screens/OptionsScreen.cpp @@ -7,14 +7,12 @@ #include "../../../AppPlatform.h" #include "CreditsScreen.h" -#include "../components/OptionsPane.h" #include "../components/ImageButton.h" #include "../components/OptionsGroup.h" OptionsScreen::OptionsScreen() : btnClose(NULL), bHeader(NULL), - btnChangeUsername(NULL), btnCredits(NULL), selectedCategory(0) { } @@ -31,11 +29,6 @@ OptionsScreen::~OptionsScreen() { bHeader = NULL; } - if (btnChangeUsername != NULL) { - delete btnChangeUsername; - btnChangeUsername = NULL; - } - if (btnCredits != NULL) { delete btnCredits; btnCredits = NULL; @@ -48,7 +41,7 @@ OptionsScreen::~OptionsScreen() { } } - for (std::vector::iterator it = optionPanes.begin(); it != optionPanes.end(); ++it) { + for (std::vector::iterator it = optionPanes.begin(); it != optionPanes.end(); ++it) { if (*it != NULL) { delete* it; *it = NULL; @@ -72,17 +65,15 @@ void OptionsScreen::init() { def.setSrc(IntRectangle(150, 0, (int)def.width, (int)def.height)); btnClose->setImageDef(def, true); - categoryButtons.push_back(new Touch::TButton(2, "Login")); + categoryButtons.push_back(new Touch::TButton(2, "General")); categoryButtons.push_back(new Touch::TButton(3, "Game")); categoryButtons.push_back(new Touch::TButton(4, "Controls")); categoryButtons.push_back(new Touch::TButton(5, "Graphics")); - btnChangeUsername = new Touch::TButton(10, "Username"); btnCredits = new Touch::TButton(11, "Credits"); buttons.push_back(bHeader); buttons.push_back(btnClose); - buttons.push_back(btnChangeUsername); buttons.push_back(btnCredits); for (std::vector::iterator it = categoryButtons.begin(); it != categoryButtons.end(); ++it) { @@ -118,27 +109,13 @@ void OptionsScreen::setupPositions() { bHeader->width = width - btnClose->width; bHeader->height = btnClose->height; - // Username button (bottom-left) - if (btnChangeUsername != NULL) { - - btnChangeUsername->width = categoryButtons.empty() ? 80 : categoryButtons[0]->width; - btnChangeUsername->height = btnClose->height; - - btnChangeUsername->x = 0; - btnChangeUsername->y = height - btnChangeUsername->height; - } - // Credits button (bottom-right) if (btnCredits != NULL) { - - btnCredits->width = btnChangeUsername->width; - btnCredits->height = btnChangeUsername->height; - btnCredits->x = width - btnCredits->width; btnCredits->y = height - btnCredits->height; } - for (std::vector::iterator it = optionPanes.begin(); it != optionPanes.end(); ++it) { + for (std::vector::iterator it = optionPanes.begin(); it != optionPanes.end(); ++it) { if (categoryButtons.size() > 0 && categoryButtons[0] != NULL) { @@ -158,13 +135,13 @@ void OptionsScreen::render(int xm, int ym, float a) { renderBackground(); - super::render(xm, ym, a); - int xmm = xm * width / minecraft->width; int ymm = ym * height / minecraft->height - 1; - if (currentOptionPane != NULL) - currentOptionPane->render(minecraft, xmm, ymm); + if (currentOptionsGroup != NULL) + currentOptionsGroup->render(minecraft, xmm, ymm); + + super::render(xm, ym, a); } void OptionsScreen::removed() { @@ -173,16 +150,9 @@ void OptionsScreen::removed() { void OptionsScreen::buttonClicked(Button* button) { if (button == btnClose) { - minecraft->options.save(); minecraft->screenChooser.setScreen(SCREEN_STARTMENU); - } - else if (button == btnChangeUsername) { - - minecraft->options.save(); - minecraft->setScreen(new UsernameScreen()); - } else if (button->id > 1 && button->id < 7) { @@ -212,63 +182,88 @@ void OptionsScreen::selectCategory(int index) { } if (index < (int)optionPanes.size()) - currentOptionPane = optionPanes[index]; + currentOptionsGroup = optionPanes[index]; } void OptionsScreen::generateOptionScreens() { + // how the fuck it works - optionPanes.push_back(new OptionsPane()); - optionPanes.push_back(new OptionsPane()); - optionPanes.push_back(new OptionsPane()); - optionPanes.push_back(new OptionsPane()); + optionPanes.push_back(new OptionsGroup("options.group.general")); + optionPanes.push_back(new OptionsGroup("options.group.game")); + optionPanes.push_back(new OptionsGroup("options.group.control")); + optionPanes.push_back(new OptionsGroup("options.group.graphics")); - // Login Pane - optionPanes[0]->createOptionsGroup("options.group.mojang") - .addOptionItem(&Options::Option::SENSITIVITY, minecraft); + // General Pane + optionPanes[0]->addOptionItem(OPTIONS_USERNAME, minecraft) + .addOptionItem(OPTIONS_SENSITIVITY, minecraft); // Game Pane - optionPanes[1]->createOptionsGroup("options.group.game") - .addOptionItem(&Options::Option::DIFFICULTY, minecraft) - .addOptionItem(&Options::Option::SERVER_VISIBLE, minecraft) - .addOptionItem(&Options::Option::THIRD_PERSON, minecraft) - .addOptionItem(&Options::Option::GUI_SCALE, minecraft); + optionPanes[1]->addOptionItem(OPTIONS_DIFFICULTY, minecraft) + .addOptionItem(OPTIONS_SERVER_VISIBLE, minecraft) + .addOptionItem(OPTIONS_THIRD_PERSON_VIEW, minecraft) + .addOptionItem(OPTIONS_GUI_SCALE, minecraft) + .addOptionItem(OPTIONS_SENSITIVITY, minecraft) + .addOptionItem(OPTIONS_MUSIC_VOLUME, minecraft) + .addOptionItem(OPTIONS_SOUND_VOLUME, minecraft) + .addOptionItem(OPTIONS_SMOOTH_CAMERA, minecraft) + .addOptionItem(OPTIONS_DESTROY_VIBRATION, minecraft) + .addOptionItem(OPTIONS_IS_LEFT_HANDED, minecraft); - // Controls Pane - optionPanes[2]->createOptionsGroup("options.group.controls") - .addOptionItem(&Options::Option::INVERT_MOUSE, minecraft); + // // Controls Pane + optionPanes[2]->addOptionItem(OPTIONS_INVERT_Y_MOUSE, minecraft) + .addOptionItem(OPTIONS_USE_TOUCHSCREEN, minecraft); - // Graphics Pane - optionPanes[3]->createOptionsGroup("options.group.graphics") - .addOptionItem(&Options::Option::GRAPHICS, minecraft) - .addOptionItem(&Options::Option::VIEW_BOBBING, minecraft) - .addOptionItem(&Options::Option::AMBIENT_OCCLUSION, minecraft) - .addOptionItem(&Options::Option::ANAGLYPH, minecraft) - .addOptionItem(&Options::Option::LIMIT_FRAMERATE, minecraft) - .addOptionItem(&Options::Option::VSYNC, minecraft) - .addOptionItem(&Options::Option::MUSIC, minecraft) - .addOptionItem(&Options::Option::SOUND, minecraft); + for (int i = OPTIONS_KEY_FORWARD; i <= OPTIONS_KEY_USE; i++) { + optionPanes[2]->addOptionItem((OptionId)i, minecraft); + } + + // // Graphics Pane + optionPanes[3]->addOptionItem(OPTIONS_FANCY_GRAPHICS, minecraft) + // .addOptionItem(&Options::Option::VIEW_BOBBING, minecraft) + // .addOptionItem(&Options::Option::AMBIENT_OCCLUSION, minecraft) + // .addOptionItem(&Options::Option::ANAGLYPH, minecraft) + .addOptionItem(OPTIONS_LIMIT_FRAMERATE, minecraft) + .addOptionItem(OPTIONS_VSYNC, minecraft) + .addOptionItem(OPTIONS_RENDER_DEBUG, minecraft) + .addOptionItem(OPTIONS_ANAGLYPH_3D, minecraft) + .addOptionItem(OPTIONS_VIEW_BOBBING, minecraft) + .addOptionItem(OPTIONS_AMBIENT_OCCLUSION, minecraft); } void OptionsScreen::mouseClicked(int x, int y, int buttonNum) { - if (currentOptionPane != NULL) - currentOptionPane->mouseClicked(minecraft, x, y, buttonNum); + if (currentOptionsGroup != NULL) + currentOptionsGroup->mouseClicked(minecraft, x, y, buttonNum); super::mouseClicked(x, y, buttonNum); } void OptionsScreen::mouseReleased(int x, int y, int buttonNum) { - if (currentOptionPane != NULL) - currentOptionPane->mouseReleased(minecraft, x, y, buttonNum); + if (currentOptionsGroup != NULL) + currentOptionsGroup->mouseReleased(minecraft, x, y, buttonNum); super::mouseReleased(x, y, buttonNum); } +void OptionsScreen::keyPressed(int eventKey) { + if (currentOptionsGroup != NULL) + currentOptionsGroup->keyPressed(minecraft, eventKey); + + super::keyPressed(eventKey); +} + +void OptionsScreen::charPressed(char inputChar) { + if (currentOptionsGroup != NULL) + currentOptionsGroup->charPressed(minecraft, inputChar); + + super::keyPressed(inputChar); +} + void OptionsScreen::tick() { - if (currentOptionPane != NULL) - currentOptionPane->tick(minecraft); + if (currentOptionsGroup != NULL) + currentOptionsGroup->tick(minecraft); super::tick(); } \ No newline at end of file diff --git a/src/client/gui/screens/OptionsScreen.h b/src/client/gui/screens/OptionsScreen.h index 10379ab..b02c7b8 100755 --- a/src/client/gui/screens/OptionsScreen.h +++ b/src/client/gui/screens/OptionsScreen.h @@ -3,6 +3,7 @@ #include "../Screen.h" #include "../components/Button.h" +#include "../components/OptionsGroup.h" class ImageButton; class OptionsPane; @@ -26,19 +27,21 @@ public: virtual void mouseClicked(int x, int y, int buttonNum); virtual void mouseReleased(int x, int y, int buttonNum); + virtual void keyPressed(int eventKey); + virtual void charPressed(char inputChar); + virtual void tick(); private: Touch::THeader* bHeader; ImageButton* btnClose; - Button* btnChangeUsername; Button* btnCredits; // <-- ADD THIS std::vector categoryButtons; - std::vector optionPanes; + std::vector optionPanes; - OptionsPane* currentOptionPane; + OptionsGroup* currentOptionsGroup; int selectedCategory; }; diff --git a/src/client/gui/screens/PauseScreen.cpp b/src/client/gui/screens/PauseScreen.cpp index ca3d4d6..aac6f21 100755 --- a/src/client/gui/screens/PauseScreen.cpp +++ b/src/client/gui/screens/PauseScreen.cpp @@ -15,9 +15,9 @@ PauseScreen::PauseScreen(bool wasBackPaused) bServerVisibility(0), // bThirdPerson(0), wasBackPaused(wasBackPaused), - bSound(&Options::Option::SOUND, 1, 0), - bThirdPerson(&Options::Option::THIRD_PERSON), - bHideGui(&Options::Option::HIDE_GUI) + // bSound(OPTIONS_SOUND_VOLUME, 1, 0), + bThirdPerson(OPTIONS_THIRD_PERSON_VIEW), + bHideGui(OPTIONS_HIDEGUI) { ImageDef def; def.setSrc(IntRectangle(160, 144, 39, 31)); @@ -27,7 +27,7 @@ PauseScreen::PauseScreen(bool wasBackPaused) def.width = defSrc.w * 0.666667f; def.height = defSrc.h * 0.666667f; - bSound.setImageDef(def, true); + // bSound.setImageDef(def, true); defSrc.y += defSrc.h; bThirdPerson.setImageDef(def, true); bHideGui.setImageDef(def, true); @@ -60,10 +60,10 @@ void PauseScreen::init() { buttons.push_back(bContinue); buttons.push_back(bQuit); - bSound.updateImage(&minecraft->options); + // bSound.updateImage(&minecraft->options); bThirdPerson.updateImage(&minecraft->options); bHideGui.updateImage(&minecraft->options); - buttons.push_back(&bSound); + // buttons.push_back(&bSound); buttons.push_back(&bThirdPerson); //buttons.push_back(&bHideGui); @@ -88,7 +88,7 @@ void PauseScreen::init() { // buttons.push_back(bThirdPerson); for (unsigned int i = 0; i < buttons.size(); ++i) { - if (buttons[i] == &bSound) continue; + // if (buttons[i] == &bSound) continue; if (buttons[i] == &bThirdPerson) continue; if (buttons[i] == &bHideGui) continue; tabButtons.push_back(buttons[i]); @@ -115,10 +115,10 @@ void PauseScreen::setupPositions() { bQuitAndSaveLocally->x = bServerVisibility->x = (width - bQuitAndSaveLocally->width) / 2; bQuitAndSaveLocally->y = bServerVisibility->y = yBase + 32 * 3; - bSound.y = bThirdPerson.y = 8; - bSound.x = 4; - bThirdPerson.x = bSound.x + 4 + bSound.width; - bHideGui.x = bThirdPerson.x + 4 + bThirdPerson.width; + // bSound.y = bThirdPerson.y = 8; + // bSound.x = 4; + // bThirdPerson.x = bSound.x + 4 + bSound.width; + // bHideGui.x = bThirdPerson.x + 4 + bThirdPerson.width; //bThirdPerson->x = (width - bThirdPerson->w) / 2; //bThirdPerson->y = yBase + 32 * 4; diff --git a/src/client/gui/screens/PauseScreen.h b/src/client/gui/screens/PauseScreen.h index 1df9dbf..6f6a078 100755 --- a/src/client/gui/screens/PauseScreen.h +++ b/src/client/gui/screens/PauseScreen.h @@ -35,7 +35,7 @@ private: Button* bServerVisibility; // Button* bThirdPerson; - OptionButton bSound; + // OptionButton bSound; OptionButton bThirdPerson; OptionButton bHideGui; }; diff --git a/src/client/gui/screens/ScreenChooser.cpp b/src/client/gui/screens/ScreenChooser.cpp index 63d0da1..12bedd5 100755 --- a/src/client/gui/screens/ScreenChooser.cpp +++ b/src/client/gui/screens/ScreenChooser.cpp @@ -12,6 +12,8 @@ #include "../../Minecraft.h" +#include + Screen* ScreenChooser::createScreen( ScreenId id ) { Screen* screen = NULL; diff --git a/src/client/gui/screens/SelectWorldScreen.cpp b/src/client/gui/screens/SelectWorldScreen.cpp index 8ec3f3c..b0f583c 100755 --- a/src/client/gui/screens/SelectWorldScreen.cpp +++ b/src/client/gui/screens/SelectWorldScreen.cpp @@ -415,9 +415,9 @@ bool SelectWorldScreen::isInGameScreen() { return true; } void SelectWorldScreen::keyPressed( int eventKey ) { if (bWorldView.selected) { - if (eventKey == minecraft->options.keyLeft.key) + if (eventKey == minecraft->options.getIntValue(OPTIONS_KEY_RIGHT)) worldsList->stepLeft(); - if (eventKey == minecraft->options.keyRight.key) + if (eventKey == minecraft->options.getIntValue(OPTIONS_KEY_LEFT)) worldsList->stepRight(); } diff --git a/src/client/gui/screens/SelectWorldScreen.h b/src/client/gui/screens/SelectWorldScreen.h index 8b45bb2..7c36085 100755 --- a/src/client/gui/screens/SelectWorldScreen.h +++ b/src/client/gui/screens/SelectWorldScreen.h @@ -4,7 +4,6 @@ #include "../Screen.h" #include "../TweenData.h" #include "../components/Button.h" -#include "../components/SmallButton.h" #include "../components/RolledSelectionListH.h" #include "../../Minecraft.h" #include "../../../world/level/storage/LevelStorageSource.h" diff --git a/src/client/gui/screens/SimpleChooseLevelScreen.cpp b/src/client/gui/screens/SimpleChooseLevelScreen.cpp index 956863e..353748a 100755 --- a/src/client/gui/screens/SimpleChooseLevelScreen.cpp +++ b/src/client/gui/screens/SimpleChooseLevelScreen.cpp @@ -223,12 +223,6 @@ void SimpleChooseLevelScreen::keyPressed(int eventKey) Screen::keyPressed(eventKey); } -void SimpleChooseLevelScreen::keyboardNewChar(char inputChar) -{ - // forward character input to focused textbox(s) - for (auto* tb : textBoxes) tb->handleChar(inputChar); -} - bool SimpleChooseLevelScreen::handleBackEvent(bool isDown) { if (!isDown) minecraft->screenChooser.setScreen(SCREEN_STARTMENU); diff --git a/src/client/gui/screens/SimpleChooseLevelScreen.h b/src/client/gui/screens/SimpleChooseLevelScreen.h index 893876d..457a8db 100755 --- a/src/client/gui/screens/SimpleChooseLevelScreen.h +++ b/src/client/gui/screens/SimpleChooseLevelScreen.h @@ -23,7 +23,6 @@ public: void buttonClicked(Button* button); bool handleBackEvent(bool isDown); virtual void keyPressed(int eventKey); - virtual void keyboardNewChar(char inputChar); virtual void mouseClicked(int x, int y, int buttonNum); private: diff --git a/src/client/gui/screens/StartMenuScreen.cpp b/src/client/gui/screens/StartMenuScreen.cpp index 6670750..040ede3 100755 --- a/src/client/gui/screens/StartMenuScreen.cpp +++ b/src/client/gui/screens/StartMenuScreen.cpp @@ -10,7 +10,6 @@ #include "../../../util/Mth.h" #include "../Font.h" -#include "../components/SmallButton.h" #include "../components/ScrolledSelectionList.h" #include "../../Minecraft.h" @@ -38,7 +37,7 @@ void StartMenuScreen::init() bJoin.active = bHost.active = bOptions.active = true; - if (minecraft->options.username.empty()) { + if (minecraft->options.getStringValue(OPTIONS_USERNAME).empty()) { return; // tick() will redirect to UsernameScreen } @@ -105,7 +104,7 @@ void StartMenuScreen::setupPositions() { } void StartMenuScreen::tick() { - if (minecraft->options.username.empty()) { + if (minecraft->options.getStringValue(OPTIONS_USERNAME).empty()) { minecraft->setScreen(new UsernameScreen()); return; } diff --git a/src/client/gui/screens/TextEditScreen.cpp b/src/client/gui/screens/TextEditScreen.cpp index 115db91..1159e67 100755 --- a/src/client/gui/screens/TextEditScreen.cpp +++ b/src/client/gui/screens/TextEditScreen.cpp @@ -132,7 +132,7 @@ void TextEditScreen::keyPressed( int eventKey ) { } } -void TextEditScreen::keyboardNewChar( char inputChar ) { +void TextEditScreen::charPressed( char inputChar ) { std::string fullstring = sign->messages[line] + inputChar; if(fullstring.length() < 16) { sign->messages[line] = fullstring; diff --git a/src/client/gui/screens/TextEditScreen.h b/src/client/gui/screens/TextEditScreen.h index 2ba7c4b..2fea9fc 100755 --- a/src/client/gui/screens/TextEditScreen.h +++ b/src/client/gui/screens/TextEditScreen.h @@ -20,7 +20,7 @@ public: void render(int xm, int ym, float a); virtual void lostFocus(); virtual void keyPressed(int eventKey); - virtual void keyboardNewChar(char inputChar); + virtual void charPressed(char inputChar); void setupPositions(); void buttonClicked(Button* button); protected: diff --git a/src/client/gui/screens/UsernameScreen.cpp b/src/client/gui/screens/UsernameScreen.cpp index c1455d9..43e334e 100644 --- a/src/client/gui/screens/UsernameScreen.cpp +++ b/src/client/gui/screens/UsernameScreen.cpp @@ -63,30 +63,6 @@ void UsernameScreen::keyPressed(int eventKey) Screen::keyPressed(eventKey); } -void UsernameScreen::keyboardNewChar(char inputChar) -{ - for (auto* tb : textBoxes) tb->handleChar(inputChar); -} - -void UsernameScreen::mouseClicked(int x, int y, int button) -{ - int lvlTop = tUsername.y - (Font::DefaultLineHeight + 4); - int lvlBottom = tUsername.y + tUsername.height; - int lvlLeft = tUsername.x; - int lvlRight = tUsername.x + tUsername.width; - bool clickedLevel = x >= lvlLeft && x < lvlRight && y >= lvlTop && y < lvlBottom; - - if (clickedLevel) { - tUsername.setFocus(minecraft); - } else { - // click outside both fields -> blur both - tUsername.loseFocus(minecraft); - } - - // also let the parent class handle button presses/etc. - Screen::mouseClicked(x, y, button); -} - void UsernameScreen::removed() { minecraft->platform()->hideKeyboard(); @@ -95,7 +71,7 @@ void UsernameScreen::removed() void UsernameScreen::buttonClicked(Button* button) { if (button == &_btnDone && !tUsername.text.empty()) { - minecraft->options.username = tUsername.text; + minecraft->options.set(OPTIONS_USERNAME, tUsername.text); minecraft->options.save(); minecraft->user->name = tUsername.text; minecraft->setScreen(NULL); // goes to StartMenuScreen diff --git a/src/client/gui/screens/UsernameScreen.h b/src/client/gui/screens/UsernameScreen.h index 3f94f54..c1d750e 100644 --- a/src/client/gui/screens/UsernameScreen.h +++ b/src/client/gui/screens/UsernameScreen.h @@ -13,24 +13,22 @@ public: UsernameScreen(); virtual ~UsernameScreen(); - void init(); + void init() override; virtual void setupPositions() override; - void render(int xm, int ym, float a); - void tick(); + void render(int xm, int ym, float a) override; + void tick() override; - virtual bool isPauseScreen() { return false; } + virtual bool isPauseScreen() override { return false; } - virtual void keyPressed(int eventKey); - virtual void keyboardNewChar(char inputChar); - virtual bool handleBackEvent(bool isDown) { return true; } // block back/escape - virtual void removed(); - virtual void mouseClicked(int x, int y, int button); + virtual void keyPressed(int eventKey) override; + virtual bool handleBackEvent(bool isDown) override { return true; } // block back/escape + virtual void removed() override; protected: - virtual void buttonClicked(Button* button); + virtual void buttonClicked(Button* button) override; private: - Button _btnDone; + Touch::TButton _btnDone; TextBox tUsername; std::string _input; int _cursorBlink; diff --git a/src/client/gui/screens/touch/TouchJoinGameScreen.h b/src/client/gui/screens/touch/TouchJoinGameScreen.h index c64d36c..2205bf6 100755 --- a/src/client/gui/screens/touch/TouchJoinGameScreen.h +++ b/src/client/gui/screens/touch/TouchJoinGameScreen.h @@ -3,7 +3,6 @@ #include "../../Screen.h" #include "../../components/Button.h" -#include "../../components/SmallButton.h" #include "../../components/RolledSelectionListV.h" #include "../../../Minecraft.h" #include "../../../../platform/input/Multitouch.h" diff --git a/src/client/gui/screens/touch/TouchSelectWorldScreen.cpp b/src/client/gui/screens/touch/TouchSelectWorldScreen.cpp index e294a6d..377fe53 100755 --- a/src/client/gui/screens/touch/TouchSelectWorldScreen.cpp +++ b/src/client/gui/screens/touch/TouchSelectWorldScreen.cpp @@ -552,9 +552,9 @@ bool SelectWorldScreen::isInGameScreen() { return true; } void SelectWorldScreen::keyPressed( int eventKey ) { if (bWorldView.selected) { - if (eventKey == minecraft->options.keyLeft.key) + if (eventKey == minecraft->options.getIntValue(OPTIONS_KEY_LEFT)) worldsList->stepLeft(); - if (eventKey == minecraft->options.keyRight.key) + if (eventKey == minecraft->options.getIntValue(OPTIONS_KEY_RIGHT)) worldsList->stepRight(); } diff --git a/src/client/gui/screens/touch/TouchStartMenuScreen.cpp b/src/client/gui/screens/touch/TouchStartMenuScreen.cpp index c5d704e..16d755e 100755 --- a/src/client/gui/screens/touch/TouchStartMenuScreen.cpp +++ b/src/client/gui/screens/touch/TouchStartMenuScreen.cpp @@ -4,7 +4,6 @@ #include "../PauseScreen.h" #include "../../Font.h" -#include "../../components/SmallButton.h" #include "../../components/ScrolledSelectionList.h" #include "../../components/GuiElement.h" @@ -58,7 +57,6 @@ void StartMenuScreen::init() buttons.push_back(&bHost); buttons.push_back(&bJoin); buttons.push_back(&bOptions); - tabButtons.push_back(&bHost); diff --git a/src/client/player/LocalPlayer.cpp b/src/client/player/LocalPlayer.cpp index fbc52c7..8b98293 100755 --- a/src/client/player/LocalPlayer.cpp +++ b/src/client/player/LocalPlayer.cpp @@ -72,22 +72,24 @@ LocalPlayer::~LocalPlayer() { /*private*/ void LocalPlayer::calculateFlight(float xa, float ya, float za) { + float flySpeed = minecraft->options.getProgressValue(OPTIONS_FLY_SPEED); + float sensivity = minecraft->options.getProgressValue(OPTIONS_SENSITIVITY); - xa = xa * minecraft->options.flySpeed; + xa = xa * flySpeed; ya = 0; - za = za * minecraft->options.flySpeed; + za = za * flySpeed; #ifdef ANDROID if (Keyboard::isKeyDown(103)) ya = .2f * minecraft->options.flySpeed; if (Keyboard::isKeyDown(102)) ya = -.2f * minecraft->options.flySpeed; #else - if (Keyboard::isKeyDown(Keyboard::KEY_E)) ya = .2f * minecraft->options.flySpeed; - if (Keyboard::isKeyDown(Keyboard::KEY_Q)) ya = -.2f * minecraft->options.flySpeed; + if (Keyboard::isKeyDown(Keyboard::KEY_E)) ya = .2f * flySpeed; + if (Keyboard::isKeyDown(Keyboard::KEY_Q)) ya = -.2f * flySpeed; #endif - flyX = 10 * smoothFlyX.getNewDeltaValue(xa, .35f * minecraft->options.sensitivity); - flyY = 10 * smoothFlyY.getNewDeltaValue(ya, .35f * minecraft->options.sensitivity); - flyZ = 10 * smoothFlyZ.getNewDeltaValue(za, .35f * minecraft->options.sensitivity); + flyX = 10 * smoothFlyX.getNewDeltaValue(xa, .35f * sensivity); + flyY = 10 * smoothFlyY.getNewDeltaValue(ya, .35f * sensivity); + flyZ = 10 * smoothFlyZ.getNewDeltaValue(za, .35f * sensivity); } bool LocalPlayer::isSolidTile(int x, int y, int z) { @@ -152,7 +154,7 @@ void LocalPlayer::tick() { printf("armor %d: %d\n", i, a->getAuxValue()); } -/**/ +*/ updateArmorTypeHash(); #ifndef STANDALONE_SERVER @@ -251,7 +253,7 @@ void LocalPlayer::closeContainer() { //@Override void LocalPlayer::move(float xa, float ya, float za) { //@note: why is this == minecraft->player needed? - if (this == minecraft->player && minecraft->options.isFlying) { + if (this == minecraft->player && minecraft->options.getBooleanValue(OPTIONS_IS_FLYING)) { noPhysics = true; float tmp = walkDist; // update calculateFlight((float) xa, (float) ya, (float) za); diff --git a/src/client/player/input/KeyboardInput.cpp b/src/client/player/input/KeyboardInput.cpp index 9b60759..674838d 100755 --- a/src/client/player/input/KeyboardInput.cpp +++ b/src/client/player/input/KeyboardInput.cpp @@ -12,14 +12,12 @@ KeyboardInput::KeyboardInput( Options* options ) void KeyboardInput::setKey( int key, bool state ) { int id = -1; - if (key == options->keyUp.key) id = KEY_UP; - if (key == options->keyDown.key) id = KEY_DOWN; - if (key == options->keyLeft.key) id = KEY_LEFT; - if (key == options->keyRight.key) id = KEY_RIGHT; - if (key == options->keyJump.key) id = KEY_JUMP; - if (key == options->keySneak.key) id = KEY_SNEAK; - if (key == options->keyCraft.key) id = KEY_CRAFT; - //printf("key: %d\n", id); + if (key == options->getIntValue(OPTIONS_KEY_FORWARD)) id = KEY_UP; + if (key == options->getIntValue(OPTIONS_KEY_BACK)) id = KEY_DOWN; + if (key == options->getIntValue(OPTIONS_KEY_LEFT)) id = KEY_LEFT; + if (key == options->getIntValue(OPTIONS_KEY_RIGHT)) id = KEY_RIGHT; + if (key == options->getIntValue(OPTIONS_KEY_JUMP)) id = KEY_JUMP; + if (key == options->getIntValue(OPTIONS_KEY_SNEAK)) id = KEY_SNEAK; if (id >= 0) { keys[id] = state; } diff --git a/src/client/player/input/touchscreen/TouchInputHolder.h b/src/client/player/input/touchscreen/TouchInputHolder.h index 9ed2647..d2d238d 100755 --- a/src/client/player/input/touchscreen/TouchInputHolder.h +++ b/src/client/player/input/touchscreen/TouchInputHolder.h @@ -89,7 +89,7 @@ public: } virtual void onConfigChanged(const Config& c) { - if (false && _options->isJoyTouchArea) { + if (false && _options->getBooleanValue(OPTIONS_IS_JOY_TOUCH_AREA)) { int touchWidth = c.width - (int)inventoryArea._x1; if (touchWidth > (int)c.minecraft->pixelCalc.millimetersToPixels(60)) touchWidth = (int)c.minecraft->pixelCalc.millimetersToPixels(60); @@ -293,7 +293,7 @@ public: } void render(float alpha) { - if (_options->isJoyTouchArea) { + if (_options->getBooleanValue(OPTIONS_IS_JOY_TOUCH_AREA)) { fill( (int) (Gui::InvGuiScale * joyTouchArea._x0), (int) (Gui::InvGuiScale * joyTouchArea._y0), (int) (Gui::InvGuiScale * joyTouchArea._x1), @@ -429,8 +429,8 @@ public: #ifdef __APPLE__ _turnBuild.pauseArea = _move.getPauseRectangleArea(); #endif - _turnBuild.inventoryArea = _mc->gui.getRectangleArea( _mc->options.isLeftHanded? 1 : -1 ); - _turnBuild.setSensitivity(c.options->isJoyTouchArea? 1.8f : 1.0f); + _turnBuild.inventoryArea = _mc->gui.getRectangleArea( _mc->options.getBooleanValue(OPTIONS_IS_LEFT_HANDED)? 1 : -1 ); + _turnBuild.setSensitivity(c.options->getBooleanValue(OPTIONS_IS_JOY_TOUCH_AREA)? 1.8f : 1.0f); ((ITurnInput*)&_turnBuild)->onConfigChanged(c); } diff --git a/src/client/player/input/touchscreen/TouchscreenInput.cpp b/src/client/player/input/touchscreen/TouchscreenInput.cpp index 7d58b1c..ce08b8d 100755 --- a/src/client/player/input/touchscreen/TouchscreenInput.cpp +++ b/src/client/player/input/touchscreen/TouchscreenInput.cpp @@ -134,7 +134,7 @@ void TouchscreenInput_TestFps::onConfigChanged(const Config& c) { float yy; const float BaseY = -8 + h - 3.0f * Bh; - const float BaseX = _options->isLeftHanded? -8 + w - 3 * Bw + const float BaseX = _options->getBooleanValue(OPTIONS_IS_LEFT_HANDED)? -8 + w - 3 * Bw : 8 + 0; // Setup the bounding rectangle _boundingRectangle = RectangleArea(BaseX, BaseY, BaseX + 3 * Bw, BaseY + 3 * Bh); @@ -418,7 +418,7 @@ const RectangleArea& TouchscreenInput_TestFps::getPauseRectangleArea() } void TouchscreenInput_TestFps::rebuild() { - if (_options->hideGui) + if (_options->getBooleanValue(OPTIONS_HIDEGUI)) return; Tesselator& t = Tesselator::instance; diff --git a/src/client/renderer/GameRenderer.cpp b/src/client/renderer/GameRenderer.cpp index 1ca6ce3..ea60c10 100755 --- a/src/client/renderer/GameRenderer.cpp +++ b/src/client/renderer/GameRenderer.cpp @@ -89,9 +89,9 @@ void renderCursor(float x, float y, Minecraft* minecraft) { /*private*/ void GameRenderer::setupCamera(float a, int eye) { - renderDistance = (float) (16 * 16 >> (mc->options.viewDistance)); + renderDistance = (float) (16 * 16 >> (mc->options.getIntValue(OPTIONS_VIEW_DISTANCE))); #if defined(ANDROID) - if (mc->isPowerVR() && mc->options.viewDistance <= 2) + if (mc->isPowerVR() && mc->options.getIntValue(OPTIONS_VIEW_DISTANCE) <= 2) renderDistance *= 0.8f; #endif @@ -99,7 +99,7 @@ void GameRenderer::setupCamera(float a, int eye) { glLoadIdentity2(); float stereoScale = 0.07f; - if (mc->options.anaglyph3d) glTranslatef2(-(eye * 2 - 1) * stereoScale, 0, 0); + if (mc->options.getBooleanValue(OPTIONS_ANAGLYPH_3D)) glTranslatef2(-(eye * 2 - 1) * stereoScale, 0, 0); if (zoom != 1) { glTranslatef2((float) zoom_x, (float) -zoom_y, 0); glScalef2(zoom, zoom, 1); @@ -110,10 +110,10 @@ void GameRenderer::setupCamera(float a, int eye) { glMatrixMode(GL_MODELVIEW); glLoadIdentity2(); - if (mc->options.anaglyph3d) glTranslatef2((eye * 2 - 1) * 0.10f, 0, 0); + if (mc->options.getBooleanValue(OPTIONS_ANAGLYPH_3D)) glTranslatef2((eye * 2 - 1) * 0.10f, 0, 0); bobHurt(a); - if (mc->options.bobView) bobView(a); + if (mc->options.getBooleanValue(OPTIONS_VIEW_BOBBING)) bobView(a); moveCameraToPlayer(a); } @@ -127,7 +127,7 @@ void GameRenderer::render(float a) { mc->mouseHandler.poll(); //printf("Controller.x,y : %f,%f\n", Controller::getX(0), Controller::getY(0)); - float ss = mc->options.sensitivity * 0.6f + 0.2f; + float ss = mc->options.getProgressValue(OPTIONS_SENSITIVITY) * 0.6f + 0.2f; float sens = (ss * ss * ss) * 8; float xo = mc->mouseHandler.xd * sens * 4.f; float yo = mc->mouseHandler.yd * sens * 4.f; @@ -141,7 +141,7 @@ void GameRenderer::render(float a) { _rotY += yo; int yAxis = -1; - if (mc->options.invertYMouse) yAxis = 1; + if (mc->options.getBooleanValue(OPTIONS_INVERT_Y_MOUSE)) yAxis = 1; bool screenCovering = mc->screen && !mc->screen->passEvents; if (!screenCovering) @@ -181,7 +181,7 @@ void GameRenderer::render(float a) { renderLevel(a); hasClearedColorBuffer = true; - if (!mc->options.hideGui) { + if (!mc->options.getBooleanValue(OPTIONS_HIDEGUI)) { TIMER_POP_PUSH("gui"); setupGuiScreen(false); hasSetupGuiScreen = true; @@ -248,7 +248,7 @@ void GameRenderer::renderLevel(float a) { float zOff = cameraEntity->zOld + (cameraEntity->z - cameraEntity->zOld) * a; for (int i = 0; i < 2; i++) { - if (mc->options.anaglyph3d) { + if (mc->options.getBooleanValue(OPTIONS_ANAGLYPH_3D)) { if (i == 0) glColorMask(false, true, true, false); else glColorMask(true, false, false, false); } @@ -270,7 +270,7 @@ void GameRenderer::renderLevel(float a) { screenScissorArea.w, screenScissorArea.h); } - if(mc->options.fancyGraphics) { + if(mc->options.getBooleanValue(OPTIONS_FANCY_GRAPHICS)) { setupFog(-1); TIMER_POP_PUSH("sky"); glFogf(GL_FOG_START, renderDistance * 0.2f); @@ -282,7 +282,7 @@ void GameRenderer::renderLevel(float a) { glEnable2(GL_FOG); setupFog(1); - if (mc->options.ambientOcclusion) { + if (mc->options.getBooleanValue(OPTIONS_AMBIENT_OCCLUSION)) { glShadeModel2(GL_SMOOTH); } @@ -294,7 +294,7 @@ void GameRenderer::renderLevel(float a) { mc->levelRenderer->cull(&frustum, a); mc->levelRenderer->updateDirtyChunks(cameraEntity, false); - if(mc->options.fancyGraphics) { + if(mc->options.getBooleanValue(OPTIONS_FANCY_GRAPHICS)) { prepareAndRenderClouds(levelRenderer, a); } @@ -379,7 +379,7 @@ void GameRenderer::renderLevel(float a) { renderItemInHand(a, i); } - if (!mc->options.anaglyph3d) { + if (!mc->options.getBooleanValue(OPTIONS_ANAGLYPH_3D)) { TIMER_POP(); return; } @@ -431,7 +431,7 @@ void GameRenderer::moveCameraToPlayer(float a) { if(player->isPlayer() && ((Player*)player)->isSleeping()) { heightOffset += 1.0; glTranslatef(0.0f, 0.3f, 0); - if (!mc->options.fixedCamera) { + if (!mc->options.getBooleanValue(OPTIONS_FIXED_CAMERA)) { int t = mc->level->getTile(Mth::floor(player->x), Mth::floor(player->y), Mth::floor(player->z)); if (t == Tile::bed->id) { int data = mc->level->getData(Mth::floor(player->x), Mth::floor(player->y), Mth::floor(player->z)); @@ -442,10 +442,10 @@ void GameRenderer::moveCameraToPlayer(float a) { glRotatef(player->yRotO + (player->yRot - player->yRotO) * a + 180, 0, -1, 0); glRotatef(player->xRotO + (player->xRot - player->xRotO) * a, -1, 0, 0); } - } else if (mc->options.thirdPersonView/* || (player->isPlayer() && !player->isAlive())*/) { + } else if (mc->options.getBooleanValue(OPTIONS_THIRD_PERSON_VIEW)/* || (player->isPlayer() && !player->isAlive())*/) { float cameraDist = thirdDistanceO + (thirdDistance - thirdDistanceO) * a; - if (mc->options.fixedCamera) { + if (mc->options.getBooleanValue(OPTIONS_FIXED_CAMERA)) { float rotationY = thirdRotationO + (thirdRotation - thirdRotationO) * a; float xRot = thirdTiltO + (thirdTilt - thirdTiltO) * a; @@ -488,7 +488,7 @@ void GameRenderer::moveCameraToPlayer(float a) { glTranslatef2(0, 0, -0.1f); } - if (!mc->options.fixedCamera) { + if (!mc->options.getBooleanValue(OPTIONS_FIXED_CAMERA)) { glRotatef2(player->xRotO + (player->xRot - player->xRotO) * a, 1.0f, 0.0f, 0.0f); glRotatef2(player->yRotO + (player->yRot - player->yRotO) * a + 180, 0, 1, 0); //if (_t_keepPic > 0) @@ -609,7 +609,7 @@ bool GameRenderer::updateFreeformPickDirection(float a, Vec3& outDir) { Vec3 c = mc->cameraTargetPlayer->getPos(a); - bool firstPerson = !mc->options.thirdPersonView; + bool firstPerson = !mc->options.getBooleanValue(OPTIONS_THIRD_PERSON_VIEW); const float PickingDistance = firstPerson? 6.0f : 12.0f; _shTicks = -1; @@ -785,7 +785,7 @@ void GameRenderer::tick(int nTick, int maxTick) { Mth::floor(mc->cameraTargetPlayer->y), Mth::floor(mc->cameraTargetPlayer->z)); - float whiteness = (3 - mc->options.viewDistance) / 3.0f; + float whiteness = (3 - mc->options.getIntValue(OPTIONS_VIEW_DISTANCE)) / 3.0f; float fogBrT = brr * (1 - whiteness) + whiteness; fogBr += (fogBrT - fogBr) * 0.1f; @@ -800,7 +800,7 @@ void GameRenderer::setupClearColor(float a) { Level* level = mc->level; Mob* player = mc->cameraTargetPlayer; - float whiteness = 1.0f / (4 - mc->options.viewDistance); + float whiteness = 1.0f / (4 - mc->options.getIntValue(OPTIONS_VIEW_DISTANCE)); whiteness = 1 - (float) pow(whiteness, 0.25f); Vec3 skyColor = level->getSkyColor(mc->cameraTargetPlayer, a); @@ -832,7 +832,7 @@ void GameRenderer::setupClearColor(float a) { fg *= brr; fb *= brr; - if (mc->options.anaglyph3d) { + if (mc->options.getBooleanValue(OPTIONS_ANAGLYPH_3D)) { float frr = (fr * 30 + fg * 59 + fb * 11) / 100; float fgg = (fr * 30 + fg * 70) / (100); float fbb = (fr * 30 + fb * 70) / (100); @@ -878,14 +878,14 @@ void GameRenderer::setupGuiScreen( bool clearColorBuffer ) /*private*/ void GameRenderer::renderItemInHand(float a, int eye) { glLoadIdentity2(); - if (mc->options.anaglyph3d) glTranslatef2((eye * 2 - 1) * 0.10f, 0, 0); + if (mc->options.getBooleanValue(OPTIONS_ANAGLYPH_3D)) glTranslatef2((eye * 2 - 1) * 0.10f, 0, 0); glPushMatrix2(); bobHurt(a); - if (mc->options.bobView) bobView(a); + if (mc->options.getBooleanValue(OPTIONS_VIEW_BOBBING)) bobView(a); - if (!mc->options.thirdPersonView && (mc->cameraTargetPlayer->isPlayer() && !((Player*)mc->cameraTargetPlayer)->isSleeping())) { - if (!mc->options.hideGui) { + if (!mc->options.getBooleanValue(OPTIONS_THIRD_PERSON_VIEW) && (mc->cameraTargetPlayer->isPlayer() && !((Player*)mc->cameraTargetPlayer)->isSleeping())) { + if (!mc->options.getBooleanValue(OPTIONS_HIDEGUI)) { float fov = getFov(a, false); if (fov != _setupCameraFov) { glMatrixMode(GL_PROJECTION); @@ -898,11 +898,11 @@ void GameRenderer::renderItemInHand(float a, int eye) { } glPopMatrix2(); - if (!mc->options.thirdPersonView && (mc->cameraTargetPlayer->isPlayer() && !((Player*)mc->cameraTargetPlayer)->isSleeping())) { + if (!mc->options.getBooleanValue(OPTIONS_THIRD_PERSON_VIEW) && (mc->cameraTargetPlayer->isPlayer() && !((Player*)mc->cameraTargetPlayer)->isSleeping())) { itemInHandRenderer->renderScreenEffect(a); bobHurt(a); } - if (mc->options.bobView) bobView(a); + if (mc->options.getBooleanValue(OPTIONS_VIEW_BOBBING)) bobView(a); } void GameRenderer::onGraphicsReset() diff --git a/src/client/renderer/LevelRenderer.cpp b/src/client/renderer/LevelRenderer.cpp index 2ccc821..3520732 100755 --- a/src/client/renderer/LevelRenderer.cpp +++ b/src/client/renderer/LevelRenderer.cpp @@ -149,9 +149,11 @@ void LevelRenderer::allChanged() { deleteChunks(); - Tile::leaves->setFancy(mc->options.fancyGraphics); - Tile::leaves_carried->setFancy(mc->options.fancyGraphics); - lastViewDistance = mc->options.viewDistance; + bool fancy = mc->options.getBooleanValue(OPTIONS_FANCY_GRAPHICS); + + Tile::leaves->setFancy(fancy); + Tile::leaves_carried->setFancy(fancy); + lastViewDistance = mc->options.getIntValue(OPTIONS_VIEW_DISTANCE); int dist = (512 >> 3) << (3 - lastViewDistance); if (lastViewDistance <= 2 && mc->isPowerVR()) @@ -295,7 +297,7 @@ void LevelRenderer::resortChunks( int xc, int yc, int zc ) int LevelRenderer::render( Mob* player, int layer, float alpha ) { - if (mc->options.viewDistance != lastViewDistance) { + if (mc->options.getIntValue(OPTIONS_VIEW_DISTANCE) != lastViewDistance) { allChanged(); } @@ -334,7 +336,7 @@ int LevelRenderer::render( Mob* player, int layer, float alpha ) } int count = 0; - if (occlusionCheck && !mc->options.anaglyph3d && layer == 0) { + if (occlusionCheck && !mc->options.getBooleanValue(OPTIONS_ANAGLYPH_3D) && layer == 0) { int from = 0; int to = 16; //checkQueryResults(from, to); @@ -938,10 +940,12 @@ void LevelRenderer::renderEntities(Vec3 cam, Culler* culler, float a) { for (int i = 0; i < totalEntities; i++) { Entity* entity = entities[i]; + bool thirdPerson = mc->options.getBooleanValue(OPTIONS_THIRD_PERSON_VIEW); + if (entity->shouldRender(cam) && culler->isVisible(entity->bb)) { - if (entity == mc->cameraTargetPlayer && mc->options.thirdPersonView == 0 && mc->cameraTargetPlayer->isPlayer() && !((Player*)mc->cameraTargetPlayer)->isSleeping()) continue; - if (entity == mc->cameraTargetPlayer && !mc->options.thirdPersonView) + if (entity == mc->cameraTargetPlayer && thirdPerson == 0 && mc->cameraTargetPlayer->isPlayer() && !((Player*)mc->cameraTargetPlayer)->isSleeping()) continue; + if (entity == mc->cameraTargetPlayer && !thirdPerson) continue; if (!level->hasChunkAt(Mth::floor(entity->x), Mth::floor(entity->y), Mth::floor(entity->z))) continue; @@ -996,7 +1000,7 @@ void LevelRenderer::renderSky(float alpha) { float sg = (float) sc.y; float sb = (float) sc.z;// + 0.5f; - if (mc->options.anaglyph3d) { + if (mc->options.getBooleanValue(OPTIONS_ANAGLYPH_3D)) { float srr = (sr * 30.0f + sg * 59.0f + sb * 11.0f) / 100.0f; float sgg = (sr * 30.0f + sg * 70.0f) / (100.0f); float sbb = (sr * 30.0f + sb * 70.0f) / (100.0f); @@ -1258,20 +1262,20 @@ void LevelRenderer::takePicture( TripodCamera* cam, Entity* entity ) { // Push old values Mob* oldCameraEntity = mc->cameraTargetPlayer; - bool hideGui = mc->options.hideGui; - bool thirdPerson = mc->options.thirdPersonView; + bool hideGui = mc->options.getBooleanValue(OPTIONS_HIDEGUI); + bool thirdPerson = mc->options.getBooleanValue(OPTIONS_THIRD_PERSON_VIEW); // @huge @attn: This is highly illegal, super temp! mc->cameraTargetPlayer = (Mob*)cam; - mc->options.hideGui = true; - mc->options.thirdPersonView = false; + mc->options.set(OPTIONS_HIDEGUI, true); + mc->options.set(OPTIONS_THIRD_PERSON_VIEW, false); mc->gameRenderer->renderLevel(0); // Pop values back mc->cameraTargetPlayer = oldCameraEntity; - mc->options.hideGui = hideGui; - mc->options.thirdPersonView = thirdPerson; + mc->options.set(OPTIONS_HIDEGUI, hideGui); + mc->options.set(OPTIONS_THIRD_PERSON_VIEW, thirdPerson); _t_keepPic = -1; diff --git a/src/client/sound/SoundEngine.cpp b/src/client/sound/SoundEngine.cpp index b283d54..0af6d43 100755 --- a/src/client/sound/SoundEngine.cpp +++ b/src/client/sound/SoundEngine.cpp @@ -26,7 +26,10 @@ void SoundEngine::init( Minecraft* mc, Options* options ) this->mc = mc; this->options = options; - if (/*!loaded && */(options == NULL || (options->sound != 0 || options->music != 0))) { + if (/*!loaded && */(options == NULL || + (options->getProgressValue(OPTIONS_SOUND_VOLUME) != 0.f || + options->getProgressValue(OPTIONS_MUSIC_VOLUME) != 0.f))) + { loadLibrary(); } @@ -165,7 +168,7 @@ void SoundEngine::destroy() void SoundEngine::update( Mob* player, float a ) { - if (/*!loaded || */options->sound == 0) return; + if (/*!loaded || */options->getProgressValue(OPTIONS_SOUND_VOLUME) == 0) return; if (player == NULL) return; _x = player->xo + (player->x - player->xo) * a; @@ -190,20 +193,20 @@ float SoundEngine::_getVolumeMult( float x, float y, float z ) #if defined(PRE_ANDROID23) void SoundEngine::play(const std::string& name, float x, float y, float z, float volume, float pitch) { //volume *= (2.0f * _getVolumeMult(x, y, z)) - if ((volume *= options->sound) <= 0) return; + if ((volume *= options->getProgressValue(OPTIONS_SOUND_VOLUME)) <= 0) return; volume *= _getVolumeMult(x, y, z); mc->platform()->playSound(name, volume, pitch); } void SoundEngine::playUI(const std::string& name, float volume, float pitch) { - if ((volume *= options->sound) <= 0) return; + if ((volume *= options->getProgressValue(OPTIONS_SOUND_VOLUME)) <= 0) return; //volume *= 2.0f; mc->platform()->playSound(name, volume, pitch); } #elif defined(__APPLE__) void SoundEngine::play(const std::string& name, float x, float y, float z, float volume, float pitch) { - if ((volume *= options->sound) <= 0) return; + if ((volume *= options->getProgressValue(OPTIONS_SOUND_VOLUME)) <= 0) return; volume = Mth::clamp(volume, 0.0f, 1.0f); @@ -213,10 +216,10 @@ void SoundEngine::play(const std::string& name, float x, float y, float z, float } } void SoundEngine::playUI(const std::string& name, float volume, float pitch) { - if ((volume *= options->sound) <= 0) return; + if ((volume *= options->getProgressValue(OPTIONS_SOUND_VOLUME)) <= 0) return; volume = Mth::clamp(volume, 0.0f, 1.0f); - if (/*!loaded || */options->sound == 0 || volume <= 0) return; + if (/*!loaded || */options->getProgressValue(OPTIONS_SOUND_VOLUME) == 0 || volume <= 0) return; SoundDesc sound; if (sounds.get(name, sound)) { @@ -228,10 +231,10 @@ void SoundEngine::play(const std::string& name, float x, float y, float z, float void SoundEngine::playUI(const std::string& name, float volume, float pitch) {} #else void SoundEngine::play(const std::string& name, float x, float y, float z, float volume, float pitch) { - if ((volume *= options->sound) <= 0) return; + if ((volume *= options->getProgressValue(OPTIONS_SOUND_VOLUME)) <= 0) return; volume = Mth::clamp( volume * _getVolumeMult(x, y, z), 0.0f, 1.0f); - if (/*!loaded || */options->sound == 0 || volume <= 0) return; + if (/*!loaded || */options->getProgressValue(OPTIONS_SOUND_VOLUME) == 0 || volume <= 0) return; SoundDesc sound; if (sounds.get(name, sound)) { @@ -241,10 +244,10 @@ void SoundEngine::play(const std::string& name, float x, float y, float z, float } } void SoundEngine::playUI(const std::string& name, float volume, float pitch) { - if ((volume *= options->sound) <= 0) return; + if ((volume *= options->getProgressValue(OPTIONS_SOUND_VOLUME)) <= 0) return; volume = Mth::clamp(volume, 0.0f, 1.0f); - if (/*!loaded || */options->sound == 0 || volume <= 0) return; + if (/*!loaded || */options->getProgressValue(OPTIONS_SOUND_VOLUME) == 0 || volume <= 0) return; SoundDesc sound; if (sounds.get(name, sound)) { diff --git a/src/main_glfw.h b/src/main_glfw.h index 9aa46a5..a9acc36 100755 --- a/src/main_glfw.h +++ b/src/main_glfw.h @@ -165,8 +165,8 @@ int main(void) { glfwSwapBuffers(window); glfwPollEvents(); - glfwSwapInterval(((MAIN_CLASS*)app)->options.vsync ? 1 : 0); - if(((MAIN_CLASS*)app)->options.limitFramerate) { + glfwSwapInterval(((MAIN_CLASS*)app)->options.getBooleanValue(OPTIONS_VSYNC) ? 1 : 0); + if(((MAIN_CLASS*)app)->options.getBooleanValue(OPTIONS_LIMIT_FRAMERATE)) { auto frameEnd = clock::now(); auto elapsed = std::chrono::duration_cast(frameEnd - frameStart); auto target = std::chrono::microseconds(33333); // ~30 fps diff --git a/src/network/ServerSideNetworkHandler.cpp b/src/network/ServerSideNetworkHandler.cpp index 26021ca..7736908 100755 --- a/src/network/ServerSideNetworkHandler.cpp +++ b/src/network/ServerSideNetworkHandler.cpp @@ -415,7 +415,7 @@ void ServerSideNetworkHandler::levelGenerated( Level* level ) level->addListener(this); #ifndef STANDALONE_SERVER - allowIncomingConnections(minecraft->options.serverVisible); + allowIncomingConnections(minecraft->options.getBooleanValue(OPTIONS_SERVER_VISIBLE)); #else allowIncomingConnections(true); #endif @@ -672,7 +672,7 @@ void ServerSideNetworkHandler::handle( const RakNet::RakNetGUID& source, SignUpd void ServerSideNetworkHandler::allowIncomingConnections( bool doAllow ) { if (doAllow) { - raknetInstance->announceServer(minecraft->options.username); + raknetInstance->announceServer(minecraft->options.getStringValue(OPTIONS_USERNAME)); } else { raknetInstance->announceServer(""); } diff --git a/src/platform/input/Keyboard.cpp b/src/platform/input/Keyboard.cpp index 78ead92..4baf5d5 100755 --- a/src/platform/input/Keyboard.cpp +++ b/src/platform/input/Keyboard.cpp @@ -1,20 +1,59 @@ #include "Keyboard.h" -/* -const int KeyboardAction::KEYUP = 0; -const int KeyboardAction::KEYDOWN = 1; -*/ +int Keyboard::_states[256] = {0}; -int - Keyboard::_states[256] = {0}; +std::vector Keyboard::_inputs; +std::vector Keyboard::_inputText; -std::vector - Keyboard::_inputs; -std::vector - Keyboard::_inputText; +int Keyboard::_index = -1; -int - Keyboard::_index = -1; +int Keyboard::_textIndex = -1; -int - Keyboard::_textIndex = -1; \ No newline at end of file +const char* Keyboard::getKeyName(int key) { + switch (key) { + case KEY_A: return "A"; + case KEY_B: return "B"; + case KEY_C: return "C"; + case KEY_D: return "D"; + case KEY_E: return "E"; + case KEY_F: return "F"; + case KEY_G: return "G"; + case KEY_H: return "H"; + case KEY_I: return "I"; + case KEY_J: return "J"; + case KEY_K: return "K"; + case KEY_L: return "L"; + case KEY_M: return "M"; + case KEY_N: return "N"; + case KEY_O: return "O"; + case KEY_P: return "P"; + case KEY_Q: return "Q"; + case KEY_R: return "R"; + case KEY_S: return "S"; + case KEY_T: return "T"; + case KEY_U: return "U"; + case KEY_V: return "V"; + case KEY_W: return "W"; + case KEY_X: return "X"; + case KEY_Y: return "Y"; + case KEY_Z: return "Z"; + case KEY_BACKSPACE: return "Backspace"; + case KEY_RETURN: return "Return"; + case KEY_F1: return "F1"; + case KEY_F2: return "F2"; + case KEY_F3: return "F3"; + case KEY_F4: return "F4"; + case KEY_F5: return "F5"; + case KEY_F6: return "F6"; + case KEY_F7: return "F7"; + case KEY_F8: return "F8"; + case KEY_F9: return "F9"; + case KEY_F10: return "F10"; + case KEY_F11: return "F11"; + case KEY_F12: return "F12"; + case KEY_ESCAPE: return "Esc"; + case KEY_SPACE: return "Space"; + case KEY_LSHIFT: return "Left Shift"; + default: "Unknown"; + } +} \ No newline at end of file diff --git a/src/platform/input/Keyboard.h b/src/platform/input/Keyboard.h index aaf7a89..eef7ef8 100755 --- a/src/platform/input/Keyboard.h +++ b/src/platform/input/Keyboard.h @@ -125,6 +125,8 @@ public: static char getChar() { return _inputText[_textIndex]; } + + static const char* getKeyName(int key); private: static int _index; static int _textIndex; diff --git a/src/world/Difficulty.h b/src/world/Difficulty.h index 8961834..a437eeb 100755 --- a/src/world/Difficulty.h +++ b/src/world/Difficulty.h @@ -3,12 +3,13 @@ //package net.minecraft.world; -class Difficulty { -public: - static const int PEACEFUL = 0; - static const int EASY = 1; - static const int NORMAL = 2; - static const int HARD = 3; +enum Difficulty { + PEACEFUL = 0, + EASY = 1, + NORMAL = 2, + HARD = 3, + + COUNT }; #endif /*NET_MINECRAFT_WORLD__Difficulty_H__*/