aboutsummaryrefslogtreecommitdiff
path: root/src/map.h
Commit message (Expand)AuthorAge
* Use unordered_map instead of map for MapSectorsRichard Try2022-05-23
* Add more Prometheus metrics (#12274)sfan52022-05-09
* Async environment for mods to do concurrent tasks (#11131)sfan52022-05-02
* Deal with compiler warningssfan52022-04-30
* Disentangle map implementations (#12148)Jude Melton-Houghton2022-04-07
* Remove a few unused functions reported by callcatcher (#11658)SmallJoker2021-10-12
* Add core.compare_block_status function (#11247)SmallJoker2021-05-30
* Remove dead code (#10845)rubenwardy2021-01-22
* Allow configuring block disk and net compression. Change default disk level.Lars2020-12-15
* Avoid generating the same chunk more than once with multiple emerge threads.Lars2020-11-26
* Remove unused functions reported by cppcheck (#10463)SmallJoker2020-10-05
* Revert "Verify database connection on interval (#9665)"rubenwardy2020-07-07
* Add MetricsBackend with prometheus counter supportLoic Blot2020-04-29
* Verify database connection on interval (#9665)Loïc Blot2020-04-15
* Remove legacy flat-file map coderandom-geek2019-10-23
* Fix some reference counters (memleak) (#8981)SmallJoker2019-09-24
* Improve occlusion culling in corridors with additional checksfan52019-08-24
* Restore approximate occlusion checksfan52019-08-24
* Occlusion: Check for light_propagates and do mapblock bounds checksSmallJoker2019-08-23
* Occlusion: Begin cleanupSmallJoker2019-08-23
* Fix unnecessary exception use in Map::getSectorXXX (#8792)Jozef Behran2019-08-13
* Merge pull request #8776 from osjc/FixGetNodeJozef Behran2019-08-10
* Optimize string (mis)handling (#8128)Jozef Behran2019-05-18
* Send only changed node metadata to clients instead of whole mapblock (#5268)SmallJoker2018-12-04
* Check node updates whether the blocks are known (#7568)SmallJoker2018-08-16
* Allow an optional readonly base database (#7544)lhofhansl2018-07-25
* SAO limits: Allow SAOs to exist outside the set 'mapgen limit'paramat2018-02-26
* map.cpp: Initialize NodeNeighbor, set NeighborType to u8 & cleanupLoic Blot2018-02-11
* Node definition manager refactor (#7016)Dániel Juhász2018-02-10
* ServerMap saving: cleanups (#6274)Loïc Blot2017-08-19
* Code modernization: src/m* (part 2)Loic Blot2017-08-19
* Optimize headers (part 2) (#6272)Loïc Blot2017-08-18
* Modernize various files (src/m*) (#6267)Loïc Blot2017-08-18
* C++ modernize: Pragma once (#6264)Loïc Blot2017-08-17
* Remove unused Map::getDayNightDiff + fix one undefined variable in mapblock.cppLoic Blot2017-07-26
* Cpp11 initializers 2 (#5999)Loïc Blot2017-06-17
* C++11 patchset 6: forbid object copy using assigment/copy function deleters (...Loïc Blot2017-06-10
* C++11 patchset 2: remove util/cpp11.h and util/cpp11_container.h (#5821)Loïc Blot2017-06-04
* Properly remove SAO when worldedges are overtaken (#5889)Loïc Blot2017-06-03
* Time: Change old `u32` timestamps to 64-bit (#5818)SmallJoker2017-05-26
* Player data to Database (#5475)Loïc Blot2017-04-23
* Add on_flood() callback.Auke Kok2017-04-22
* Light update for map blocksDániel Juhász2017-04-20
* Fix various copy instead of const ref reported by cppcheck (part 3) (#5616)Loïc Blot2017-04-20
* Fix various variables passed by copy instead of const ref (#5610)Loïc Blot2017-04-19
* Map generation limit: Make per-worldparamat2017-03-27
* Allow server side occlusion culling.Lars Hofhansl2017-03-11
* Light calculation: New bulk node lighting codeDániel Juhász2017-03-11
* Improve getPointedThing() (#4346)Dániel Juhász2017-01-04
* Improved lightingDániel Juhász2016-10-27
pan class="hl com"> (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "guiKeyChangeMenu.h" #include "debug.h" #include "serialization.h" #include "main.h" #include <string> #include <IGUICheckBox.h> #include <IGUIEditBox.h> #include <IGUIButton.h> #include <IGUIStaticText.h> #include <IGUIFont.h> #include "settings.h" #include <algorithm> #include "mainmenumanager.h" // for g_gamecallback #define KMaxButtonPerColumns 12 extern MainGameCallback *g_gamecallback; enum { GUI_ID_BACK_BUTTON = 101, GUI_ID_ABORT_BUTTON, GUI_ID_SCROLL_BAR, // buttons GUI_ID_KEY_FORWARD_BUTTON, GUI_ID_KEY_BACKWARD_BUTTON, GUI_ID_KEY_LEFT_BUTTON, GUI_ID_KEY_RIGHT_BUTTON, GUI_ID_KEY_USE_BUTTON, GUI_ID_KEY_FLY_BUTTON, GUI_ID_KEY_FAST_BUTTON, GUI_ID_KEY_JUMP_BUTTON, GUI_ID_KEY_NOCLIP_BUTTON, GUI_ID_KEY_CHAT_BUTTON, GUI_ID_KEY_CMD_BUTTON, GUI_ID_KEY_CONSOLE_BUTTON, GUI_ID_KEY_SNEAK_BUTTON, GUI_ID_KEY_DROP_BUTTON, GUI_ID_KEY_INVENTORY_BUTTON, GUI_ID_KEY_DUMP_BUTTON, GUI_ID_KEY_RANGE_BUTTON, // other GUI_ID_CB_AUX1_DESCENDS, GUI_ID_CB_DOUBLETAP_JUMP, }; GUIKeyChangeMenu::GUIKeyChangeMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id, IMenuManager *menumgr) : GUIModalMenu(env, parent, id, menumgr) { shift_down = false; activeKey = -1; this->key_used_text = NULL; init_keys(); for(size_t i=0; i<key_settings.size(); i++) this->key_used.push_back(key_settings.at(i)->key); } GUIKeyChangeMenu::~GUIKeyChangeMenu() { removeChildren(); for (std::vector<key_setting*>::iterator iter = key_settings.begin(); iter != key_settings.end(); iter ++) { delete[] (*iter)->button_name; delete (*iter); } key_settings.clear(); } void GUIKeyChangeMenu::removeChildren() { const core::list<gui::IGUIElement*> &children = getChildren(); core::list<gui::IGUIElement*> children_copy; for (core::list<gui::IGUIElement*>::ConstIterator i = children.begin(); i != children.end(); i++) { children_copy.push_back(*i); } for (core::list<gui::IGUIElement*>::Iterator i = children_copy.begin(); i != children_copy.end(); i++) { (*i)->remove(); } } void GUIKeyChangeMenu::regenerateGui(v2u32 screensize) { removeChildren(); v2s32 size(620, 430); core::rect < s32 > rect(screensize.X / 2 - size.X / 2, screensize.Y / 2 - size.Y / 2, screensize.X / 2 + size.X / 2, screensize.Y / 2 + size.Y / 2); DesiredRect = rect; recalculateAbsolutePosition(false); v2s32 topleft(0, 0); { core::rect < s32 > rect(0, 0, 600, 40); rect += topleft + v2s32(25, 3); //gui::IGUIStaticText *t = wchar_t* text = wgettext("Keybindings. (If this menu screws up, remove stuff from minetest.conf)"); Environment->addStaticText(text, rect, false, true, this, -1); delete[] text; //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } // Build buttons v2s32 offset(25, 60); for(size_t i = 0; i < key_settings.size(); i++) { key_setting *k = key_settings.at(i); { core::rect < s32 > rect(0, 0, 100, 20); rect += topleft + v2s32(offset.X, offset.Y); Environment->addStaticText(k->button_name, rect, false, true, this, -1); } { core::rect < s32 > rect(0, 0, 100, 30); rect += topleft + v2s32(offset.X + 105, offset.Y - 5); wchar_t* text = wgettext(k->key.name()); k->button = Environment->addButton(rect, this, k->id, text ); delete[] text; } if(i + 1 == KMaxButtonPerColumns) offset = v2s32(250, 60); else offset += v2s32(0, 25); } { s32 option_x = offset.X + 10; s32 option_y = offset.Y; u32 option_w = 180; { core::rect<s32> rect(0, 0, option_w, 30); rect += topleft + v2s32(option_x, option_y); wchar_t* text = wgettext("\"Use\" = climb down"); Environment->addCheckBox(g_settings->getBool("aux1_descends"), rect, this, GUI_ID_CB_AUX1_DESCENDS, text); delete[] text; } offset += v2s32(0, 25); } { s32 option_x = offset.X + 10; s32 option_y = offset.Y; u32 option_w = 220; { core::rect<s32> rect(0, 0, option_w, 30); rect += topleft + v2s32(option_x, option_y); wchar_t* text = wgettext("Double tap \"jump\" to toggle fly"); Environment->addCheckBox(g_settings->getBool("doubletap_jump"), rect, this, GUI_ID_CB_DOUBLETAP_JUMP, text); delete[] text; } offset += v2s32(0, 25); } { core::rect < s32 > rect(0, 0, 100, 30); rect += topleft + v2s32(size.X - 100 - 20, size.Y - 40); wchar_t* text = wgettext("Save"); Environment->addButton(rect, this, GUI_ID_BACK_BUTTON, text); delete[] text; } { core::rect < s32 > rect(0, 0, 100, 30); rect += topleft + v2s32(size.X - 100 - 20 - 100 - 20, size.Y - 40); wchar_t* text = wgettext("Cancel"); Environment->addButton(rect, this, GUI_ID_ABORT_BUTTON, text ); delete[] text; } } void GUIKeyChangeMenu::drawMenu() { gui::IGUISkin* skin = Environment->getSkin(); if (!skin) return; video::IVideoDriver* driver = Environment->getVideoDriver(); video::SColor bgcolor(140, 0, 0, 0); { core::rect < s32 > rect(0, 0, 620, 620); rect += AbsoluteRect.UpperLeftCorner; driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect); } gui::IGUIElement::draw(); } bool GUIKeyChangeMenu::acceptInput() { for(size_t i = 0; i < key_settings.size(); i++) { key_setting *k = key_settings.at(i); g_settings->set(k->setting_name, k->key.sym()); } { gui::IGUIElement *e = getElementFromId(GUI_ID_CB_AUX1_DESCENDS); if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX) g_settings->setBool("aux1_descends", ((gui::IGUICheckBox*)e)->isChecked()); } { gui::IGUIElement *e = getElementFromId(GUI_ID_CB_DOUBLETAP_JUMP); if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX) g_settings->setBool("doubletap_jump", ((gui::IGUICheckBox*)e)->isChecked()); } clearKeyCache(); g_gamecallback->signalKeyConfigChange(); return true; } bool GUIKeyChangeMenu::resetMenu() { if (activeKey >= 0) { for(size_t i = 0; i < key_settings.size(); i++) { key_setting *k = key_settings.at(i); if(k->id == activeKey) { wchar_t* text = wgettext(k->key.name()); k->button->setText(text); delete[] text; break; } } activeKey = -1; return false; } return true; } bool GUIKeyChangeMenu::OnEvent(const SEvent& event) { if (event.EventType == EET_KEY_INPUT_EVENT && activeKey >= 0 && event.KeyInput.PressedDown) { bool prefer_character = shift_down; KeyPress kp(event.KeyInput, prefer_character); bool shift_went_down = false; if(!shift_down && (event.KeyInput.Key == irr::KEY_SHIFT || event.KeyInput.Key == irr::KEY_LSHIFT || event.KeyInput.Key == irr::KEY_RSHIFT)) shift_went_down = true; // Remove Key already in use message if(this->key_used_text) { this->key_used_text->remove(); this->key_used_text = NULL; } // Display Key already in use message if (std::find(this->key_used.begin(), this->key_used.end(), kp) != this->key_used.end()) { core::rect < s32 > rect(0, 0, 600, 40); rect += v2s32(0, 0) + v2s32(25, 30); wchar_t* text = wgettext("Key already in use"); this->key_used_text = Environment->addStaticText(text, rect, false, true, this, -1); delete[] text; //infostream << "Key already in use" << std::endl; } // But go on { key_setting *k=NULL; for(size_t i = 0; i < key_settings.size(); i++) { if(key_settings.at(i)->id == activeKey) { k = key_settings.at(i); break; } } assert(k); k->key = kp; wchar_t* text = wgettext(k->key.name()); k->button->setText(text); delete[] text; this->key_used.push_back(kp); // Allow characters made with shift if(shift_went_down){ shift_down = true; return false; }else{ activeKey = -1; return true; } } } if (event.EventType == EET_GUI_EVENT) { if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST && isVisible()) { if (!canTakeFocus(event.GUIEvent.Element)) { dstream << "GUIMainMenu: Not allowing focus change." << std::endl; // Returning true disables focus change return true; } } if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED) { switch (event.GUIEvent.Caller->getID()) { case GUI_ID_BACK_BUTTON: //back acceptInput(); quitMenu(); return true; case GUI_ID_ABORT_BUTTON: //abort quitMenu(); return true; default: key_setting *k = NULL; for(size_t i = 0; i < key_settings.size(); i++) { if(key_settings.at(i)->id == event.GUIEvent.Caller->getID()) { k = key_settings.at(i); break; } } assert(k); resetMenu(); shift_down = false; activeKey = event.GUIEvent.Caller->getID(); wchar_t* text = wgettext("press key"); k->button->setText(text); delete[] text; this->key_used.erase(std::remove(this->key_used.begin(), this->key_used.end(), k->key), this->key_used.end()); break; } Environment->setFocus(this); } } return Parent ? Parent->OnEvent(event) : false; } void GUIKeyChangeMenu::add_key(int id, wchar_t* button_name, std::string setting_name) { key_setting *k = new key_setting; k->id = id; k->button_name = button_name; k->setting_name = setting_name; k->key = getKeySetting(k->setting_name.c_str()); key_settings.push_back(k); } void GUIKeyChangeMenu::init_keys() { this->add_key(GUI_ID_KEY_FORWARD_BUTTON, wgettext("Forward"), "keymap_forward"); this->add_key(GUI_ID_KEY_BACKWARD_BUTTON, wgettext("Backward"), "keymap_backward"); this->add_key(GUI_ID_KEY_LEFT_BUTTON, wgettext("Left"), "keymap_left"); this->add_key(GUI_ID_KEY_RIGHT_BUTTON, wgettext("Right"), "keymap_right"); this->add_key(GUI_ID_KEY_USE_BUTTON, wgettext("Use"), "keymap_special1"); this->add_key(GUI_ID_KEY_JUMP_BUTTON, wgettext("Jump"), "keymap_jump"); this->add_key(GUI_ID_KEY_SNEAK_BUTTON, wgettext("Sneak"), "keymap_sneak"); this->add_key(GUI_ID_KEY_DROP_BUTTON, wgettext("Drop"), "keymap_drop"); this->add_key(GUI_ID_KEY_INVENTORY_BUTTON, wgettext("Inventory"), "keymap_inventory"); this->add_key(GUI_ID_KEY_CHAT_BUTTON, wgettext("Chat"), "keymap_chat"); this->add_key(GUI_ID_KEY_CMD_BUTTON, wgettext("Command"), "keymap_cmd"); this->add_key(GUI_ID_KEY_CONSOLE_BUTTON, wgettext("Console"), "keymap_console"); this->add_key(GUI_ID_KEY_FLY_BUTTON, wgettext("Toggle fly"), "keymap_freemove"); this->add_key(GUI_ID_KEY_FAST_BUTTON, wgettext("Toggle fast"), "keymap_fastmove"); this->add_key(GUI_ID_KEY_NOCLIP_BUTTON, wgettext("Toggle noclip"), "keymap_noclip"); this->add_key(GUI_ID_KEY_RANGE_BUTTON, wgettext("Range select"), "keymap_rangeselect"); this->add_key(GUI_ID_KEY_DUMP_BUTTON, wgettext("Print stacks"), "keymap_print_debug_stacks"); }