void GUIPauseMenu::regenerateGui(v2u32 screensize) { /* Remove stuff */ removeChildren(); /* Calculate new sizes and positions */ core::rect<s32> rect( screensize.X/2 - 580/2, screensize.Y/2 - 300/2, screensize.X/2 + 580/2, screensize.Y/2 + 300/2 ); DesiredRect = rect; recalculateAbsolutePosition(false); v2s32 size = rect.getSize(); /* Add stuff */ const s32 btn_height = 30; const s32 btn_gap = 20; const s32 btn_num = 4; s32 btn_y = size.Y/2-((btn_num*btn_height+(btn_num-1)*btn_gap))/2; changeCtype(""); { core::rect<s32> rect(0, 0, 140, btn_height); rect = rect + v2s32(size.X/2-140/2, btn_y); Environment->addButton(rect, this, 256, wgettext("Continue")); } btn_y += btn_height + btn_gap; { core::rect<s32> rect(0, 0, 140, btn_height); rect = rect + v2s32(size.X/2-140/2, btn_y); Environment->addButton(rect, this, 261, wgettext("Change Password")); } btn_y += btn_height + btn_gap; { core::rect<s32> rect(0, 0, 140, btn_height); rect = rect + v2s32(size.X/2-140/2, btn_y); Environment->addButton(rect, this, 260, wgettext("Disconnect")); } btn_y += btn_height + btn_gap; { core::rect<s32> rect(0, 0, 140, btn_height); rect = rect + v2s32(size.X/2-140/2, btn_y); Environment->addButton(rect, this, 257, wgettext("Exit to OS")); } { core::rect<s32> rect(0, 0, 180, 240); rect = rect + v2s32(size.X/2 + 90, size.Y/2-rect.getHeight()/2); Environment->addStaticText(chartowchar_t(gettext( "Default Controls:\n" "- WASD: Walk\n" "- Mouse left: dig/hit\n" "- Mouse right: place/use\n" "- Mouse wheel: select item\n" "- 0...9: select item\n" "- Shift: sneak\n" "- R: Toggle viewing all loaded chunks\n" "- I: Inventory menu\n" "- ESC: This menu\n" "- T: Chat\n" )), rect, false, true, this, 258); } { core::rect<s32> rect(0, 0, 180, 220); rect = rect + v2s32(size.X/2 - 90 - rect.getWidth(), size.Y/2-rect.getHeight()/2); v2u32 max_texture_size; { video::IVideoDriver* driver = Environment->getVideoDriver(); max_texture_size = driver->getMaxTextureSize(); } /*wchar_t text[200]; swprintf(text, 200, L"Minetest-c55\n" L"by Perttu Ahola\n" L"[email protected]\n\n" SWPRINTF_CHARSTRING L"\n" L"userdata path = " SWPRINTF_CHARSTRING , BUILD_INFO, porting::path_userdata.c_str() );*/ std::ostringstream os; os<<"Minetest\n"; os<<"by Perttu Ahola and contributors\n"; os<<"[email protected]\n"; os<<BUILD_INFO<<"\n"; os<<"ud_path = "<<wrap_rows(porting::path_userdata, 20)<<"\n"; Environment->addStaticText(narrow_to_wide(os.str()).c_str(), rect, false, true, this, 259); } changeCtype("C"); }
void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s32 count, v2s32 offset, v2s32 size) { const video::SColor color(255, 255, 255, 255); const video::SColor colors[] = {color, color, color, color}; video::ITexture *stat_texture = tsrc->getTexture(texture); if (!stat_texture) return; core::dimension2di srcd(stat_texture->getOriginalSize()); core::dimension2di dstd; if (size == v2s32()) { dstd = srcd; } else { double size_factor = g_settings->getFloat("hud_scaling") * porting::getDisplayDensity(); dstd.Height = size.Y * size_factor; dstd.Width = size.X * size_factor; offset.X *= size_factor; offset.Y *= size_factor; } v2s32 p = pos; if (corner & HUD_CORNER_LOWER) p -= dstd.Height; p += offset; v2s32 steppos; switch (drawdir) { case HUD_DIR_RIGHT_LEFT: steppos = v2s32(-1, 0); break; case HUD_DIR_TOP_BOTTOM: steppos = v2s32(0, 1); break; case HUD_DIR_BOTTOM_TOP: steppos = v2s32(0, -1); break; default: steppos = v2s32(1, 0); } steppos.X *= dstd.Width; steppos.Y *= dstd.Height; for (s32 i = 0; i < count / 2; i++) { core::rect<s32> srcrect(0, 0, srcd.Width, srcd.Height); core::rect<s32> dstrect(0,0, dstd.Width, dstd.Height); dstrect += p; driver->draw2DImage(stat_texture, dstrect, srcrect, NULL, colors, true); p += steppos; } if (count % 2 == 1) { core::rect<s32> srcrect(0, 0, srcd.Width / 2, srcd.Height); core::rect<s32> dstrect(0,0, dstd.Width / 2, dstd.Height); dstrect += p; driver->draw2DImage(stat_texture, dstrect, srcrect, NULL, colors, true); } }
virtual void setMousePos(s32 x, s32 y) { mousepos = v2s32(x,y); }
GUIEngine::GUIEngine( irr::IrrlichtDevice* dev, JoystickController *joystick, gui::IGUIElement* parent, IMenuManager *menumgr, scene::ISceneManager* smgr, MainMenuData* data, bool& kill) : m_device(dev), m_parent(parent), m_menumanager(menumgr), m_smgr(smgr), m_data(data), m_texture_source(NULL), m_sound_manager(NULL), m_formspecgui(0), m_buttonhandler(0), m_menu(0), m_kill(kill), m_startgame(false), m_script(0), m_scriptdir(""), m_irr_toplefttext(0), m_clouds_enabled(true), m_cloud() { //initialize texture pointers for (unsigned int i = 0; i < TEX_LAYER_MAX; i++) { m_textures[i].texture = NULL; } // is deleted by guiformspec! m_buttonhandler = new TextDestGuiEngine(this); //create texture source m_texture_source = new MenuTextureSource(m_device->getVideoDriver()); //create soundmanager MenuMusicFetcher soundfetcher; #if USE_SOUND m_sound_manager = createOpenALSoundManager(&soundfetcher); #endif if(!m_sound_manager) m_sound_manager = &dummySoundManager; //create topleft header m_toplefttext = L""; core::rect<s32> rect(0, 0, g_fontengine->getTextWidth(m_toplefttext.c_str()), g_fontengine->getTextHeight()); rect += v2s32(4, 0); m_irr_toplefttext = addStaticText(m_device->getGUIEnvironment(), m_toplefttext, rect, false, true, 0, -1); //create formspecsource m_formspecgui = new FormspecFormSource(""); /* Create menu */ m_menu = new GUIFormSpecMenu(m_device, joystick, m_parent, -1, m_menumanager, NULL /* &client */, NULL /* gamedef */, m_texture_source, m_formspecgui, m_buttonhandler, NULL, false); m_menu->allowClose(false); m_menu->lockSize(true,v2u32(800,600)); // Initialize scripting infostream << "GUIEngine: Initializing Lua" << std::endl; m_script = new MainMenuScripting(this); try { m_script->setMainMenuData(&m_data->script_data); m_data->script_data.errormessage = ""; if (!loadMainMenuScript()) { errorstream << "No future without mainmenu" << std::endl; abort(); } run(); } catch (LuaError &e) { errorstream << "MAINMENU ERROR: " << e.what() << std::endl; m_data->script_data.errormessage = e.what(); } m_menu->quitMenu(); m_menu->drop(); m_menu = NULL; }
//NOTE: selectitem = 0 -> no selected; selectitem 1-based void Hud::drawItems(v2s32 upperleftpos, s32 itemcount, s32 offset, InventoryList *mainlist, u16 selectitem, u16 direction) { #ifdef HAVE_TOUCHSCREENGUI if ( (g_touchscreengui) && (offset == 0)) g_touchscreengui->resetHud(); #endif // Position of upper left corner of bar v2s32 pos = upperleftpos; if (hotbar_image != player->hotbar_image) { hotbar_image = player->hotbar_image; if (hotbar_image != "") use_hotbar_image = tsrc->isKnownSourceImage(hotbar_image); else use_hotbar_image = false; } if (hotbar_selected_image != player->hotbar_selected_image) { hotbar_selected_image = player->hotbar_selected_image; if (hotbar_selected_image != "") use_hotbar_selected_image = tsrc->isKnownSourceImage(hotbar_selected_image); else use_hotbar_selected_image = false; } /* draw customized item background */ if (use_hotbar_image) { video::ITexture *texture = tsrc->getTexture(hotbar_image); core::dimension2di imgsize(texture->getOriginalSize()); core::rect<s32> rect(-m_padding, -m_padding, m_hotbar_imagesize + m_padding, m_hotbar_imagesize + m_padding); rect += pos; core::position2d<s32> step(0, 0); (direction == HUD_DIR_TOP_BOTTOM || direction == HUD_DIR_BOTTOM_TOP ? step.Y : step.X) = m_hotbar_imagesize + m_padding * 2; for (int i = 0; i < itemcount - offset; i++) { driver->draw2DImage(texture, rect, core::rect<s32>(core::position2d<s32>(0, 0), imgsize), NULL, hbar_colors, true); rect += step; } } for (s32 i = offset; i < itemcount && (size_t)i < mainlist->getSize(); i++) { v2s32 steppos; s32 fullimglen = m_hotbar_imagesize + m_padding * 2; core::rect<s32> imgrect(-m_padding, -m_padding, m_hotbar_imagesize - m_padding, m_hotbar_imagesize - m_padding); switch (direction) { case HUD_DIR_RIGHT_LEFT: steppos = v2s32(-(m_padding + (i - offset) * fullimglen), m_padding); break; case HUD_DIR_TOP_BOTTOM: steppos = v2s32(m_padding, m_padding + (i - offset) * fullimglen); break; case HUD_DIR_BOTTOM_TOP: steppos = v2s32(m_padding, -(m_padding + (i - offset) * fullimglen)); break; default: steppos = v2s32(m_padding + (i - offset) * fullimglen, m_padding); break; } drawItem(mainlist->getItem(i), (imgrect + pos + steppos), (i +1) == selectitem ); #ifdef HAVE_TOUCHSCREENGUI if (g_touchscreengui) g_touchscreengui->registerHudItem(i, (imgrect + pos + steppos)); #endif } }
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 GUIPasswordChange::regenerateGui(v2u32 screensize) { /* Remove stuff */ removeChildren(); /* Calculate new sizes and positions */ core::rect<s32> rect( screensize.X/2 - 580/2, screensize.Y/2 - 300/2, screensize.X/2 + 580/2, screensize.Y/2 + 300/2 ); DesiredRect = rect; recalculateAbsolutePosition(false); v2s32 size = rect.getSize(); v2s32 topleft_client(40, 0); const wchar_t *text; /* Add stuff */ s32 ypos = 50; { core::rect<s32> rect(0, 0, 150, 20); rect += topleft_client + v2s32(25, ypos+6); text = wgettext("Old Password"); Environment->addStaticText(text, rect, false, true, this, -1); delete[] text; } { core::rect<s32> rect(0, 0, 230, 30); rect += topleft_client + v2s32(160, ypos); gui::IGUIEditBox *e = Environment->addEditBox(L"", rect, true, this, ID_oldPassword); Environment->setFocus(e); e->setPasswordBox(true); } ypos += 50; { core::rect<s32> rect(0, 0, 150, 20); rect += topleft_client + v2s32(25, ypos+6); text = wgettext("New Password"); Environment->addStaticText(text, rect, false, true, this, -1); delete[] text; } { core::rect<s32> rect(0, 0, 230, 30); rect += topleft_client + v2s32(160, ypos); gui::IGUIEditBox *e = Environment->addEditBox(L"", rect, true, this, ID_newPassword1); e->setPasswordBox(true); } ypos += 50; { core::rect<s32> rect(0, 0, 150, 20); rect += topleft_client + v2s32(25, ypos+6); text = wgettext("Confirm Password"); Environment->addStaticText(text, rect, false, true, this, -1); delete[] text; } { core::rect<s32> rect(0, 0, 230, 30); rect += topleft_client + v2s32(160, ypos); gui::IGUIEditBox *e = Environment->addEditBox(L"", rect, true, this, ID_newPassword2); e->setPasswordBox(true); } ypos += 50; { core::rect<s32> rect(0, 0, 140, 30); rect = rect + v2s32(size.X/2-140/2, ypos); text = wgettext("Change"); Environment->addButton(rect, this, ID_change, text); delete[] text; } ypos += 50; { core::rect<s32> rect(0, 0, 300, 20); rect += topleft_client + v2s32(35, ypos); text = wgettext("Passwords do not match!"); IGUIElement *e = Environment->addStaticText( text, rect, false, true, this, ID_message); e->setVisible(false); delete[] text; } }
void GUIConfirmRegistration::regenerateGui(v2u32 screensize) { acceptInput(); removeChildren(); /* Calculate new sizes and positions */ const float s = m_gui_scale; DesiredRect = core::rect<s32>( screensize.X / 2 - 600 * s / 2, screensize.Y / 2 - 360 * s / 2, screensize.X / 2 + 600 * s / 2, screensize.Y / 2 + 360 * s / 2 ); recalculateAbsolutePosition(false); v2s32 size = DesiredRect.getSize(); v2s32 topleft_client(0, 0); const wchar_t *text; /* Add stuff */ s32 ypos = 30 * s; { std::string address = m_address; if (address.empty()) address = "localhost"; core::rect<s32> rect2(0, 0, 540 * s, 180 * s); rect2 += topleft_client + v2s32(30 * s, ypos); static const std::string info_text_template = strgettext( "You are about to join the server at %1$s with the " "name \"%2$s\" for the first time. If you proceed, a " "new account using your credentials will be created " "on this server.\n" "Please retype your password and click Register and " "Join to confirm account creation or click Cancel to " "abort."); char info_text_buf[1024]; porting::mt_snprintf(info_text_buf, sizeof(info_text_buf), info_text_template.c_str(), address.c_str(), m_playername.c_str()); wchar_t *info_text_buf_wide = utf8_to_wide_c(info_text_buf); gui::IGUIEditBox *e = new gui::intlGUIEditBox(info_text_buf_wide, true, Environment, this, ID_message, rect2, false, true); delete[] info_text_buf_wide; e->drop(); e->setMultiLine(true); e->setWordWrap(true); e->setTextAlignment(gui::EGUIA_UPPERLEFT, gui::EGUIA_CENTER); } ypos += 210 * s; { core::rect<s32> rect2(0, 0, 540 * s, 30 * s); rect2 += topleft_client + v2s32(30 * s, ypos); gui::IGUIEditBox *e = Environment->addEditBox(m_pass_confirm.c_str(), rect2, true, this, ID_confirmPassword); e->setPasswordBox(true); } ypos += 60 * s; { core::rect<s32> rect2(0, 0, 230 * s, 35 * s); rect2 = rect2 + v2s32(size.X / 2 - 220 * s, ypos); text = wgettext("Register and Join"); Environment->addButton(rect2, this, ID_confirm, text); delete[] text; } { core::rect<s32> rect2(0, 0, 120 * s, 35 * s); rect2 = rect2 + v2s32(size.X / 2 + 70 * s, ypos); text = wgettext("Cancel"); Environment->addButton(rect2, this, ID_cancel, text); delete[] text; } { core::rect<s32> rect2(0, 0, 200 * s, 20 * s); rect2 += topleft_client + v2s32(30 * s, ypos - 40 * s); text = wgettext("Passwords do not match!"); IGUIElement *e = Environment->addStaticText( text, rect2, false, true, this, ID_message); e->setVisible(false); delete[] text; } }
void GUIKeyChangeMenu::regenerateGui(v2u32 screensize) { /* Remove stuff */ removeChildren(); /* Calculate new sizes and positions */ 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); changeCtype(""); { core::rect < s32 > rect(0, 0, 500, 20); rect += topleft + v2s32(25, 3); //gui::IGUIStaticText *t = Environment->addStaticText(wgettext("KEYBINDINGS (If this menu screws up, see minetest.conf)"), rect, false, true, this, -1); //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } v2s32 offset(25, 40); // buttons { core::rect < s32 > rect(0, 0, 100, 20); rect += topleft + v2s32(offset.X, offset.Y); Environment->addStaticText(wgettext("Forward"), rect, false, true, this, -1); //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } { core::rect < s32 > rect(0, 0, 100, 30); rect += topleft + v2s32(offset.X + 105, offset.Y - 5); this->forward = Environment->addButton(rect, this, GUI_ID_KEY_FORWARD_BUTTON, wgettext(key_forward.name())); } offset += v2s32(0, 25); { core::rect < s32 > rect(0, 0, 100, 20); rect += topleft + v2s32(offset.X, offset.Y); Environment->addStaticText(wgettext("Backward"), rect, false, true, this, -1); //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } { core::rect < s32 > rect(0, 0, 100, 30); rect += topleft + v2s32(offset.X + 105, offset.Y - 5); this->backward = Environment->addButton(rect, this, GUI_ID_KEY_BACKWARD_BUTTON, wgettext(key_backward.name())); } offset += v2s32(0, 25); { core::rect < s32 > rect(0, 0, 100, 20); rect += topleft + v2s32(offset.X, offset.Y); Environment->addStaticText(wgettext("Left"), rect, false, true, this, -1); //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } { core::rect < s32 > rect(0, 0, 100, 30); rect += topleft + v2s32(offset.X + 105, offset.Y - 5); this->left = Environment->addButton(rect, this, GUI_ID_KEY_LEFT_BUTTON, wgettext(key_left.name())); } offset += v2s32(0, 25); { core::rect < s32 > rect(0, 0, 100, 20); rect += topleft + v2s32(offset.X, offset.Y); Environment->addStaticText(wgettext("Right"), rect, false, true, this, -1); //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } { core::rect < s32 > rect(0, 0, 100, 30); rect += topleft + v2s32(offset.X + 105, offset.Y - 5); this->right = Environment->addButton(rect, this, GUI_ID_KEY_RIGHT_BUTTON, wgettext(key_right.name())); } offset += v2s32(0, 25); { core::rect < s32 > rect(0, 0, 100, 20); rect += topleft + v2s32(offset.X, offset.Y); Environment->addStaticText(wgettext("Use"), rect, false, true, this, -1); //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } { core::rect < s32 > rect(0, 0, 100, 30); rect += topleft + v2s32(offset.X + 105, offset.Y - 5); this->use = Environment->addButton(rect, this, GUI_ID_KEY_USE_BUTTON, wgettext(key_use.name())); } offset += v2s32(0, 25); { core::rect < s32 > rect(0, 0, 100, 20); rect += topleft + v2s32(offset.X, offset.Y); Environment->addStaticText(wgettext("Sneak"), rect, false, true, this, -1); //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } { core::rect < s32 > rect(0, 0, 100, 30); rect += topleft + v2s32(offset.X + 105, offset.Y - 5); this->sneak = Environment->addButton(rect, this, GUI_ID_KEY_SNEAK_BUTTON, wgettext(key_sneak.name())); } offset += v2s32(0, 25); { core::rect < s32 > rect(0, 0, 100, 20); rect += topleft + v2s32(offset.X, offset.Y); Environment->addStaticText(wgettext("Jump"), rect, false, true, this, -1); //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } { core::rect < s32 > rect(0, 0, 100, 30); rect += topleft + v2s32(offset.X + 105, offset.Y - 5); this->jump = Environment->addButton(rect, this, GUI_ID_KEY_JUMP_BUTTON, wgettext(key_jump.name())); } offset += v2s32(0, 25); { core::rect < s32 > rect(0, 0, 100, 20); rect += topleft + v2s32(offset.X, offset.Y); Environment->addStaticText(wgettext("Drop"), rect, false, true, this, -1); //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } { core::rect < s32 > rect(0, 0, 100, 30); rect += topleft + v2s32(offset.X + 105, offset.Y - 5); this->dropbtn = Environment->addButton(rect, this, GUI_ID_KEY_DROP_BUTTON, wgettext(key_drop.name())); } offset += v2s32(0, 25); { core::rect < s32 > rect(0, 0, 100, 20); rect += topleft + v2s32(offset.X, offset.Y); Environment->addStaticText(wgettext("Inventory"), rect, false, true, this, -1); //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } { core::rect < s32 > rect(0, 0, 100, 30); rect += topleft + v2s32(offset.X + 105, offset.Y - 5); this->inventory = Environment->addButton(rect, this, GUI_ID_KEY_INVENTORY_BUTTON, wgettext(key_inventory.name())); } offset += v2s32(0, 25); { core::rect < s32 > rect(0, 0, 100, 20); rect += topleft + v2s32(offset.X, offset.Y); Environment->addStaticText(wgettext("Chat"), rect, false, true, this, -1); //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } { core::rect < s32 > rect(0, 0, 100, 30); rect += topleft + v2s32(offset.X + 105, offset.Y - 5); this->chat = Environment->addButton(rect, this, GUI_ID_KEY_CHAT_BUTTON, wgettext(key_chat.name())); } offset += v2s32(0, 25); { core::rect < s32 > rect(0, 0, 100, 20); rect += topleft + v2s32(offset.X, offset.Y); Environment->addStaticText(wgettext("Command"), rect, false, true, this, -1); //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } { core::rect < s32 > rect(0, 0, 100, 30); rect += topleft + v2s32(offset.X + 105, offset.Y - 5); this->cmd = Environment->addButton(rect, this, GUI_ID_KEY_CMD_BUTTON, wgettext(key_cmd.name())); } offset += v2s32(0, 25); { core::rect < s32 > rect(0, 0, 100, 20); rect += topleft + v2s32(offset.X, offset.Y); Environment->addStaticText(wgettext("Console"), rect, false, true, this, -1); //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } { core::rect < s32 > rect(0, 0, 100, 30); rect += topleft + v2s32(offset.X + 105, offset.Y - 5); this->console = Environment->addButton(rect, this, GUI_ID_KEY_CONSOLE_BUTTON, wgettext(key_console.name())); } //next col offset = v2s32(250, 40); { core::rect < s32 > rect(0, 0, 100, 20); rect += topleft + v2s32(offset.X, offset.Y); Environment->addStaticText(wgettext("Toggle fly"), rect, false, true, this, -1); //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } { core::rect < s32 > rect(0, 0, 100, 30); rect += topleft + v2s32(offset.X + 105, offset.Y - 5); this->fly = Environment->addButton(rect, this, GUI_ID_KEY_FLY_BUTTON, wgettext(key_fly.name())); } offset += v2s32(0, 25); { core::rect < s32 > rect(0, 0, 100, 20); rect += topleft + v2s32(offset.X, offset.Y); Environment->addStaticText(wgettext("Toggle fast"), rect, false, true, this, -1); //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } { core::rect < s32 > rect(0, 0, 100, 30); rect += topleft + v2s32(offset.X + 105, offset.Y - 5); this->fast = Environment->addButton(rect, this, GUI_ID_KEY_FAST_BUTTON, wgettext(key_fast.name())); } offset += v2s32(0, 25); { core::rect < s32 > rect(0, 0, 100, 20); rect += topleft + v2s32(offset.X, offset.Y); Environment->addStaticText(wgettext("Range select"), rect, false, true, this, -1); //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } { core::rect < s32 > rect(0, 0, 100, 30); rect += topleft + v2s32(offset.X + 105, offset.Y - 5); this->range = Environment->addButton(rect, this, GUI_ID_KEY_RANGE_BUTTON, wgettext(key_range.name())); } offset += v2s32(0, 25); { core::rect < s32 > rect(0, 0, 100, 20); rect += topleft + v2s32(offset.X, offset.Y); Environment->addStaticText(wgettext("Print stacks"), rect, false, true, this, -1); //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } { core::rect < s32 > rect(0, 0, 100, 30); rect += topleft + v2s32(offset.X + 105, offset.Y - 5); this->dump = Environment->addButton(rect, this, GUI_ID_KEY_DUMP_BUTTON, wgettext(key_dump.name())); } { core::rect < s32 > rect(0, 0, 100, 30); rect += topleft + v2s32(size.X - 100 - 20, size.Y - 40); Environment->addButton(rect, this, GUI_ID_BACK_BUTTON, wgettext("Save")); } { core::rect < s32 > rect(0, 0, 100, 30); rect += topleft + v2s32(size.X - 100 - 20 - 100 - 20, size.Y - 40); Environment->addButton(rect, this, GUI_ID_ABORT_BUTTON, wgettext("Cancel")); } changeCtype("C"); }
void GUICharDefMenu::regenerateGui(v2u32 screensize) { m_screensize = screensize; /* Remove stuff */ removeChildren(); /* Calculate new sizes and positions */ v2s32 size(250, 500); core::rect<s32> rect( 10, screensize.Y/2 - size.Y/2, screensize.X - 10, screensize.Y/2 + size.Y/2 ); v2s32 leftside(0, 0); v2s32 rightside(screensize.X - (size.X+10), 0); DesiredRect = rect; recalculateAbsolutePosition(false); { core::rect<s32> rect(0, 0, 230, 300); rect += leftside + v2s32(10, 220); gui::IGUIStaticText *t = Environment->addStaticText( wgettext( "Here you can create your default character," " this is how other players will see you in-game." " When you join a new server you will start with" " the clothing you select here. Additional" " clothing, both protective and decorative," " can be crafted in-game.\n" "You can return here from the main menu anytime to" " change your character." ), rect, false, true, this, -1 ); t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } { core::rect<s32> rect(0, 0, 250, 20); rect += rightside + v2s32(0, 20); gui::IGUIStaticText *t = Environment->addStaticText(wgettext("Create Your Character"), rect, false, true, this, -1); t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } // gender { core::rect<s32> rect(0, 0, 105, 30); rect += rightside + v2s32(15, 50); Environment->addButton(rect, this, GUI_ID_CD_MALE_BUTTON, wgettext("Male")); } { core::rect<s32> rect(0, 0, 105, 30); rect += rightside + v2s32(130, 50); Environment->addButton(rect, this, GUI_ID_CD_FEMALE_BUTTON, wgettext("Female")); } // Yscale { core::rect<s32> rect(0, 0, 105, 30); rect += rightside + v2s32(15, 95); Environment->addButton(rect, this, GUI_ID_CD_TALLER_BUTTON, wgettext("Taller")); } { core::rect<s32> rect(0, 0, 105, 30); rect += rightside + v2s32(15, 130); Environment->addButton(rect, this, GUI_ID_CD_SHORTER_BUTTON, wgettext("Shorter")); } // XZscale { core::rect<s32> rect(0, 0, 105, 30); rect += rightside + v2s32(130, 95); Environment->addButton(rect, this, GUI_ID_CD_WIDER_BUTTON, wgettext("Wider")); } { core::rect<s32> rect(0, 0, 105, 30); rect += rightside + v2s32(130, 130); Environment->addButton(rect, this, GUI_ID_CD_THINNER_BUTTON, wgettext("Thinner")); } // skintone //185 { core::rect<s32> rect(0, 0, 160, 20); rect += rightside + v2s32(45, 170); gui::IGUIStaticText *t = Environment->addStaticText(m_skintone_types[m_parts["skintone"]].c_str(), rect, false, true, this, -1); t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } { core::rect<s32> rect(0, 0, 30, 30); rect += rightside + v2s32(15, 165); Environment->addButton(rect, this, GUI_ID_CD_SKINTONE_PREV_BUTTON, L"<<"); } { core::rect<s32> rect(0, 0, 30, 30); rect += rightside + v2s32(205, 165); Environment->addButton(rect, this, GUI_ID_CD_SKINTONE_NEXT_BUTTON, L">>"); } // face //220 { core::rect<s32> rect(0, 0, 160, 20); rect += rightside + v2s32(45, 205); gui::IGUIStaticText *t = Environment->addStaticText(m_face_types[m_parts["face"]].c_str(), rect, false, true, this, -1); t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } { core::rect<s32> rect(0, 0, 30, 30); rect += rightside + v2s32(15, 200); Environment->addButton(rect, this, GUI_ID_CD_FACE_PREV_BUTTON, L"<<"); } { core::rect<s32> rect(0, 0, 30, 30); rect += rightside + v2s32(205, 200); Environment->addButton(rect, this, GUI_ID_CD_FACE_NEXT_BUTTON, L">>"); } // hairtone //255 { core::rect<s32> rect(0, 0, 160, 20); rect += rightside + v2s32(45, 240); gui::IGUIStaticText *t = Environment->addStaticText(m_hairtone_types[m_parts["hairtone"]].c_str(), rect, false, true, this, -1); t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } { core::rect<s32> rect(0, 0, 30, 30); rect += rightside + v2s32(15, 235); Environment->addButton(rect, this, GUI_ID_CD_HAIRTONE_PREV_BUTTON, L"<<"); } { core::rect<s32> rect(0, 0, 30, 30); rect += rightside + v2s32(205, 235); Environment->addButton(rect, this, GUI_ID_CD_HAIRTONE_NEXT_BUTTON, L">>"); } // hair //290 { core::rect<s32> rect(0, 0, 160, 20); rect += rightside + v2s32(45, 275); gui::IGUIStaticText *t = Environment->addStaticText(m_hair_types[m_parts["hair"]].c_str(), rect, false, true, this, -1); t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } { core::rect<s32> rect(0, 0, 30, 30); rect += rightside + v2s32(15, 270); Environment->addButton(rect, this, GUI_ID_CD_HAIR_PREV_BUTTON, L"<<"); } { core::rect<s32> rect(0, 0, 30, 30); rect += rightside + v2s32(205, 270); Environment->addButton(rect, this, GUI_ID_CD_HAIR_NEXT_BUTTON, L">>"); } // eyes //325 { core::rect<s32> rect(0, 0, 160, 20); rect += rightside + v2s32(45, 315); gui::IGUIStaticText *t = Environment->addStaticText(m_eyes_types[m_parts["eyes"]].c_str(), rect, false, true, this, -1); t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } { core::rect<s32> rect(0, 0, 30, 30); rect += rightside + v2s32(15, 305); Environment->addButton(rect, this, GUI_ID_CD_EYES_PREV_BUTTON, L"<<"); } { core::rect<s32> rect(0, 0, 30, 30); rect += rightside + v2s32(205, 305); Environment->addButton(rect, this, GUI_ID_CD_EYES_NEXT_BUTTON, L">>"); } // t-shirt //370 { core::rect<s32> rect(0, 0, 160, 20); rect += rightside + v2s32(45, 355); gui::IGUIStaticText *t = Environment->addStaticText(m_shirt_types[m_parts["shirt"]].c_str(), rect, false, true, this, -1); t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } { core::rect<s32> rect(0, 0, 30, 30); rect += rightside + v2s32(15, 350); Environment->addButton(rect, this, GUI_ID_CD_SHIRT_PREV_BUTTON, L"<<"); } { core::rect<s32> rect(0, 0, 30, 30); rect += rightside + v2s32(205, 350); Environment->addButton(rect, this, GUI_ID_CD_SHIRT_NEXT_BUTTON, L">>"); } // pants //405 { core::rect<s32> rect(0, 0, 160, 20); rect += rightside + v2s32(45, 390); gui::IGUIStaticText *t = Environment->addStaticText(m_pants_types[m_parts["pants"]].c_str(), rect, false, true, this, -1); t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } { core::rect<s32> rect(0, 0, 30, 30); rect += rightside + v2s32(15, 385); Environment->addButton(rect, this, GUI_ID_CD_PANTS_PREV_BUTTON, L"<<"); } { core::rect<s32> rect(0, 0, 30, 30); rect += rightside + v2s32(205, 385); Environment->addButton(rect, this, GUI_ID_CD_PANTS_NEXT_BUTTON, L">>"); } // shoes //440 { core::rect<s32> rect(0, 0, 160, 20); rect += rightside + v2s32(45, 425); gui::IGUIStaticText *t = Environment->addStaticText(m_shoes_types[m_parts["shoes"]].c_str(), rect, false, true, this, -1); t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } { core::rect<s32> rect(0, 0, 30, 30); rect += rightside + v2s32(15, 420); Environment->addButton(rect, this, GUI_ID_CD_SHOES_PREV_BUTTON, L"<<"); } { core::rect<s32> rect(0, 0, 30, 30); rect += rightside + v2s32(205, 420); Environment->addButton(rect, this, GUI_ID_CD_SHOES_NEXT_BUTTON, L">>"); } // save/cancel { core::rect<s32> rect(0, 0, 105, 30); rect += rightside + v2s32(15, 460); Environment->addButton(rect, this, GUI_ID_CD_SAVE_BUTTON, wgettext("Done")); } { core::rect<s32> rect(0, 0, 105, 30); rect += rightside + v2s32(130, 460); Environment->addButton(rect, this, GUI_ID_CD_QUIT_BUTTON, wgettext("Cancel")); } }
void GUIInventoryMenu::regenerateGui(v2u32 screensize) { // Remove children removeChildren(); /*padding = v2s32(24,24); spacing = v2s32(60,56); imgsize = v2s32(48,48);*/ padding = v2s32(screensize.Y/40, screensize.Y/40); spacing = v2s32(screensize.Y/12, screensize.Y/13); imgsize = v2s32(screensize.Y/15, screensize.Y/15); s32 helptext_h = 15; v2s32 size( padding.X*2+spacing.X*(m_menu_size.X-1)+imgsize.X, padding.Y*2+spacing.Y*(m_menu_size.Y-1)+imgsize.Y + helptext_h ); 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 basepos = getBasePos(); m_draw_spec.clear(); for(u16 i=0; i<m_init_draw_spec.size(); i++) { DrawSpec &s = m_init_draw_spec[i]; if(s.type == "list") { m_draw_spec.push_back(ListDrawSpec(s.name, s.subname, basepos + v2s32(spacing.X*s.pos.X, spacing.Y*s.pos.Y), s.geom)); } } /* m_draw_spec.clear(); m_draw_spec.push_back(ListDrawSpec("main", basepos + v2s32(spacing.X*0, spacing.Y*3), v2s32(8, 4))); m_draw_spec.push_back(ListDrawSpec("craft", basepos + v2s32(spacing.X*3, spacing.Y*0), v2s32(3, 3))); m_draw_spec.push_back(ListDrawSpec("craftresult", basepos + v2s32(spacing.X*7, spacing.Y*1), v2s32(1, 1))); */ // Add children { core::rect<s32> rect(0, 0, size.X-padding.X*2, helptext_h); rect = rect + v2s32(size.X/2 - rect.getWidth()/2, size.Y-rect.getHeight()-15); const wchar_t *text = L"Left click: Move all items, Right click: Move single item"; Environment->addStaticText(text, rect, false, true, this, 256); } }
void TextureSource::buildMainAtlas(class IGameDef *gamedef) { assert(gamedef->tsrc() == this); INodeDefManager *ndef = gamedef->ndef(); infostream<<"TextureSource::buildMainAtlas()"<<std::endl; //return; // Disable (for testing) video::IVideoDriver* driver = m_device->getVideoDriver(); assert(driver); JMutexAutoLock lock(m_atlaspointer_cache_mutex); // Create an image of the right size core::dimension2d<u32> atlas_dim(1024,1024); video::IImage *atlas_img = driver->createImage(video::ECF_A8R8G8B8, atlas_dim); //assert(atlas_img); if(atlas_img == NULL) { errorstream<<"TextureSource::buildMainAtlas(): Failed to create atlas " "image; not building texture atlas."<<std::endl; return; } /* Grab list of stuff to include in the texture atlas from the main content features */ core::map<std::string, bool> sourcelist; for(u16 j=0; j<MAX_CONTENT+1; j++) { if(j == CONTENT_IGNORE || j == CONTENT_AIR) continue; const ContentFeatures &f = ndef->get(j); for(u32 i=0; i<6; i++) { std::string name = f.tname_tiles[i]; sourcelist[name] = true; } } infostream<<"Creating texture atlas out of textures: "; for(core::map<std::string, bool>::Iterator i = sourcelist.getIterator(); i.atEnd() == false; i++) { std::string name = i.getNode()->getKey(); infostream<<"\""<<name<<"\" "; } infostream<<std::endl; // Padding to disallow texture bleeding s32 padding = 16; s32 column_width = 256; s32 column_padding = 16; /* First pass: generate almost everything */ core::position2d<s32> pos_in_atlas(0,0); pos_in_atlas.Y = padding; for(core::map<std::string, bool>::Iterator i = sourcelist.getIterator(); i.atEnd() == false; i++) { std::string name = i.getNode()->getKey(); // Generate image by name video::IImage *img2 = generate_image_from_scratch(name, m_device, &m_sourcecache); if(img2 == NULL) { errorstream<<"TextureSource::buildMainAtlas(): " <<"Couldn't generate image \""<<name<<"\""<<std::endl; continue; } core::dimension2d<u32> dim = img2->getDimension(); // Don't add to atlas if image is large core::dimension2d<u32> max_size_in_atlas(32,32); if(dim.Width > max_size_in_atlas.Width || dim.Height > max_size_in_atlas.Height) { infostream<<"TextureSource::buildMainAtlas(): Not adding " <<"\""<<name<<"\" because image is large"<<std::endl; continue; } // Wrap columns and stop making atlas if atlas is full if(pos_in_atlas.Y + dim.Height > atlas_dim.Height) { if(pos_in_atlas.X > (s32)atlas_dim.Width - 256 - padding){ errorstream<<"TextureSource::buildMainAtlas(): " <<"Atlas is full, not adding more textures." <<std::endl; break; } pos_in_atlas.Y = padding; pos_in_atlas.X += column_width + column_padding; } /*infostream<<"TextureSource::buildMainAtlas(): Adding \""<<name <<"\" to texture atlas"<<std::endl;*/ // Tile it a few times in the X direction u16 xwise_tiling = column_width / dim.Width; if(xwise_tiling > 16) // Limit to 16 (more gives no benefit) xwise_tiling = 16; for(u32 j=0; j<xwise_tiling; j++) { // Copy the copy to the atlas /*img2->copyToWithAlpha(atlas_img, pos_in_atlas + v2s32(j*dim.Width,0), core::rect<s32>(v2s32(0,0), dim), video::SColor(255,255,255,255), NULL);*/ img2->copyTo(atlas_img, pos_in_atlas + v2s32(j*dim.Width,0), core::rect<s32>(v2s32(0,0), dim), NULL); } // Copy the borders a few times to disallow texture bleeding for(u32 side=0; side<2; side++) // top and bottom for(s32 y0=0; y0<padding; y0++) for(s32 x0=0; x0<(s32)xwise_tiling*(s32)dim.Width; x0++) { s32 dst_y; s32 src_y; if(side==0) { dst_y = y0 + pos_in_atlas.Y + dim.Height; src_y = pos_in_atlas.Y + dim.Height - 1; } else { dst_y = -y0 + pos_in_atlas.Y-1; src_y = pos_in_atlas.Y; } s32 x = x0 + pos_in_atlas.X; video::SColor c = atlas_img->getPixel(x, src_y); atlas_img->setPixel(x,dst_y,c); } img2->drop(); /* Add texture to caches */ bool reuse_old_id = false; u32 id = m_atlaspointer_cache.size(); // Check old id without fetching a texture core::map<std::string, u32>::Node *n; n = m_name_to_id.find(name); // If it exists, we will replace the old definition if(n){ id = n->getValue(); reuse_old_id = true; /*infostream<<"TextureSource::buildMainAtlas(): " <<"Replacing old AtlasPointer"<<std::endl;*/ } // Create AtlasPointer AtlasPointer ap(id); ap.atlas = NULL; // Set on the second pass ap.pos = v2f((float)pos_in_atlas.X/(float)atlas_dim.Width, (float)pos_in_atlas.Y/(float)atlas_dim.Height); ap.size = v2f((float)dim.Width/(float)atlas_dim.Width, (float)dim.Width/(float)atlas_dim.Height); ap.tiled = xwise_tiling; // Create SourceAtlasPointer and add to containers SourceAtlasPointer nap(name, ap, atlas_img, pos_in_atlas, dim); if(reuse_old_id) m_atlaspointer_cache[id] = nap; else m_atlaspointer_cache.push_back(nap); m_name_to_id[name] = id; // Increment position pos_in_atlas.Y += dim.Height + padding * 2; } /* Make texture */ video::ITexture *t = driver->addTexture("__main_atlas__", atlas_img); assert(t); /* Second pass: set texture pointer in generated AtlasPointers */ for(core::map<std::string, bool>::Iterator i = sourcelist.getIterator(); i.atEnd() == false; i++) { std::string name = i.getNode()->getKey(); if(m_name_to_id.find(name) == NULL) continue; u32 id = m_name_to_id[name]; //infostream<<"id of name "<<name<<" is "<<id<<std::endl; m_atlaspointer_cache[id].a.atlas = t; } /* Write image to file so that it can be inspected */ /*std::string atlaspath = porting::path_user + DIR_DELIM + "generated_texture_atlas.png"; infostream<<"Removing and writing texture atlas for inspection to " <<atlaspath<<std::endl; fs::RecursiveDelete(atlaspath); driver->writeImageToFile(atlas_img, atlaspath.c_str());*/ }
bool generate_image(std::string part_of_name, video::IImage *& baseimg, IrrlichtDevice *device, SourceImageCache *sourcecache) { video::IVideoDriver* driver = device->getVideoDriver(); assert(driver); // Stuff starting with [ are special commands if(part_of_name.size() == 0 || part_of_name[0] != '[') { video::IImage *image = sourcecache->getOrLoad(part_of_name, device); if(image == NULL) { if(part_of_name != ""){ errorstream<<"generate_image(): Could not load image \"" <<part_of_name<<"\""<<" while building texture"<<std::endl; errorstream<<"generate_image(): Creating a dummy" <<" image for \""<<part_of_name<<"\""<<std::endl; } // Just create a dummy image //core::dimension2d<u32> dim(2,2); core::dimension2d<u32> dim(1,1); image = driver->createImage(video::ECF_A8R8G8B8, dim); assert(image); /*image->setPixel(0,0, video::SColor(255,255,0,0)); image->setPixel(1,0, video::SColor(255,0,255,0)); image->setPixel(0,1, video::SColor(255,0,0,255)); image->setPixel(1,1, video::SColor(255,255,0,255));*/ image->setPixel(0,0, video::SColor(255,myrand()%256, myrand()%256,myrand()%256)); /*image->setPixel(1,0, video::SColor(255,myrand()%256, myrand()%256,myrand()%256)); image->setPixel(0,1, video::SColor(255,myrand()%256, myrand()%256,myrand()%256)); image->setPixel(1,1, video::SColor(255,myrand()%256, myrand()%256,myrand()%256));*/ } // If base image is NULL, load as base. if(baseimg == NULL) { //infostream<<"Setting "<<part_of_name<<" as base"<<std::endl; /* Copy it this way to get an alpha channel. Otherwise images with alpha cannot be blitted on images that don't have alpha in the original file. */ core::dimension2d<u32> dim = image->getDimension(); baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); image->copyTo(baseimg); image->drop(); } // Else blit on base. else { //infostream<<"Blitting "<<part_of_name<<" on base"<<std::endl; // Size of the copied area core::dimension2d<u32> dim = image->getDimension(); //core::dimension2d<u32> dim(16,16); // Position to copy the blitted to in the base image core::position2d<s32> pos_to(0,0); // Position to copy the blitted from in the blitted image core::position2d<s32> pos_from(0,0); // Blit image->copyToWithAlpha(baseimg, pos_to, core::rect<s32>(pos_from, dim), video::SColor(255,255,255,255), NULL); // Drop image image->drop(); } } else { // A special texture modification /*infostream<<"generate_image(): generating special " <<"modification \""<<part_of_name<<"\"" <<std::endl;*/ /* This is the simplest of all; it just adds stuff to the name so that a separate texture is created. It is used to make textures for stuff that doesn't want to implement getting the texture from a bigger texture atlas. */ if(part_of_name == "[forcesingle") { // If base image is NULL, create a random color if(baseimg == NULL) { core::dimension2d<u32> dim(1,1); baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); assert(baseimg); baseimg->setPixel(0,0, video::SColor(255,myrand()%256, myrand()%256,myrand()%256)); } } /* [crackN Adds a cracking texture */ else if(part_of_name.substr(0,6) == "[crack") { if(baseimg == NULL) { errorstream<<"generate_image(): baseimg==NULL " <<"for part_of_name=\""<<part_of_name <<"\", cancelling."<<std::endl; return false; } // Crack image number and overlay option s32 progression = 0; bool use_overlay = false; if(part_of_name.substr(6,1) == "o") { progression = stoi(part_of_name.substr(7)); use_overlay = true; } else { progression = stoi(part_of_name.substr(6)); use_overlay = false; } // Size of the base image core::dimension2d<u32> dim_base = baseimg->getDimension(); /* Load crack image. It is an image with a number of cracking stages horizontally tiled. */ video::IImage *img_crack = sourcecache->getOrLoad("crack.png", device); if(img_crack && progression >= 0) { // Dimension of original image core::dimension2d<u32> dim_crack = img_crack->getDimension(); // Count of crack stages s32 crack_count = dim_crack.Height / dim_crack.Width; // Limit progression if(progression > crack_count-1) progression = crack_count-1; // Dimension of a single crack stage core::dimension2d<u32> dim_crack_cropped( dim_crack.Width, dim_crack.Width ); // Create cropped and scaled crack images video::IImage *img_crack_cropped = driver->createImage( video::ECF_A8R8G8B8, dim_crack_cropped); video::IImage *img_crack_scaled = driver->createImage( video::ECF_A8R8G8B8, dim_base); if(img_crack_cropped && img_crack_scaled) { // Crop crack image v2s32 pos_crack(0, progression*dim_crack.Width); img_crack->copyTo(img_crack_cropped, v2s32(0,0), core::rect<s32>(pos_crack, dim_crack_cropped)); // Scale crack image by copying img_crack_cropped->copyToScaling(img_crack_scaled); // Copy or overlay crack image if(use_overlay) { overlay(baseimg, img_crack_scaled); } else { img_crack_scaled->copyToWithAlpha( baseimg, v2s32(0,0), core::rect<s32>(v2s32(0,0), dim_base), video::SColor(255,255,255,255)); } } if(img_crack_scaled) img_crack_scaled->drop(); if(img_crack_cropped) img_crack_cropped->drop(); img_crack->drop(); } } /* [combine:WxH:X,Y=filename:X,Y=filename2 Creates a bigger texture from an amount of smaller ones */ else if(part_of_name.substr(0,8) == "[combine") { Strfnd sf(part_of_name); sf.next(":"); u32 w0 = stoi(sf.next("x")); u32 h0 = stoi(sf.next(":")); infostream<<"combined w="<<w0<<" h="<<h0<<std::endl; core::dimension2d<u32> dim(w0,h0); baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); while(sf.atend() == false) { u32 x = stoi(sf.next(",")); u32 y = stoi(sf.next("=")); std::string filename = sf.next(":"); infostream<<"Adding \""<<filename <<"\" to combined ("<<x<<","<<y<<")" <<std::endl; video::IImage *img = sourcecache->getOrLoad(filename, device); if(img) { core::dimension2d<u32> dim = img->getDimension(); infostream<<"Size "<<dim.Width <<"x"<<dim.Height<<std::endl; core::position2d<s32> pos_base(x, y); video::IImage *img2 = driver->createImage(video::ECF_A8R8G8B8, dim); img->copyTo(img2); img->drop(); img2->copyToWithAlpha(baseimg, pos_base, core::rect<s32>(v2s32(0,0), dim), video::SColor(255,255,255,255), NULL); img2->drop(); } else { infostream<<"img==NULL"<<std::endl; } } } /* "[brighten" */ else if(part_of_name.substr(0,9) == "[brighten") { if(baseimg == NULL) { errorstream<<"generate_image(): baseimg==NULL " <<"for part_of_name=\""<<part_of_name <<"\", cancelling."<<std::endl; return false; } brighten(baseimg); } /* "[noalpha" Make image completely opaque. Used for the leaves texture when in old leaves mode, so that the transparent parts don't look completely black when simple alpha channel is used for rendering. */ else if(part_of_name.substr(0,8) == "[noalpha") { if(baseimg == NULL) { errorstream<<"generate_image(): baseimg==NULL " <<"for part_of_name=\""<<part_of_name <<"\", cancelling."<<std::endl; return false; } core::dimension2d<u32> dim = baseimg->getDimension(); // Set alpha to full for(u32 y=0; y<dim.Height; y++) for(u32 x=0; x<dim.Width; x++) { video::SColor c = baseimg->getPixel(x,y); c.setAlpha(255); baseimg->setPixel(x,y,c); } } /* "[makealpha:R,G,B" Convert one color to transparent. */ else if(part_of_name.substr(0,11) == "[makealpha:") { if(baseimg == NULL) { errorstream<<"generate_image(): baseimg==NULL " <<"for part_of_name=\""<<part_of_name <<"\", cancelling."<<std::endl; return false; } Strfnd sf(part_of_name.substr(11)); u32 r1 = stoi(sf.next(",")); u32 g1 = stoi(sf.next(",")); u32 b1 = stoi(sf.next("")); std::string filename = sf.next(""); core::dimension2d<u32> dim = baseimg->getDimension(); /*video::IImage *oldbaseimg = baseimg; baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); oldbaseimg->copyTo(baseimg); oldbaseimg->drop();*/ // Set alpha to full for(u32 y=0; y<dim.Height; y++) for(u32 x=0; x<dim.Width; x++) { video::SColor c = baseimg->getPixel(x,y); u32 r = c.getRed(); u32 g = c.getGreen(); u32 b = c.getBlue(); if(!(r == r1 && g == g1 && b == b1)) continue; c.setAlpha(0); baseimg->setPixel(x,y,c); } } /* [inventorycube{topimage{leftimage{rightimage In every subimage, replace ^ with &. Create an "inventory cube". NOTE: This should be used only on its own. Example (a grass block (not actually used in game): "[inventorycube{grass.png{mud.png&grass_side.png{mud.png&grass_side.png" */ else if(part_of_name.substr(0,14) == "[inventorycube") { if(baseimg != NULL) { errorstream<<"generate_image(): baseimg!=NULL " <<"for part_of_name=\""<<part_of_name <<"\", cancelling."<<std::endl; return false; } str_replace_char(part_of_name, '&', '^'); Strfnd sf(part_of_name); sf.next("{"); std::string imagename_top = sf.next("{"); std::string imagename_left = sf.next("{"); std::string imagename_right = sf.next("{"); // Generate images for the faces of the cube video::IImage *img_top = generate_image_from_scratch( imagename_top, device, sourcecache); video::IImage *img_left = generate_image_from_scratch( imagename_left, device, sourcecache); video::IImage *img_right = generate_image_from_scratch( imagename_right, device, sourcecache); assert(img_top && img_left && img_right); // Create textures from images video::ITexture *texture_top = driver->addTexture( (imagename_top + "__temp__").c_str(), img_top); video::ITexture *texture_left = driver->addTexture( (imagename_left + "__temp__").c_str(), img_left); video::ITexture *texture_right = driver->addTexture( (imagename_right + "__temp__").c_str(), img_right); assert(texture_top && texture_left && texture_right); // Drop images img_top->drop(); img_left->drop(); img_right->drop(); /* Draw a cube mesh into a render target texture */ scene::IMesh* cube = createCubeMesh(v3f(1, 1, 1)); setMeshColor(cube, video::SColor(255, 255, 255, 255)); cube->getMeshBuffer(0)->getMaterial().setTexture(0, texture_top); cube->getMeshBuffer(1)->getMaterial().setTexture(0, texture_top); cube->getMeshBuffer(2)->getMaterial().setTexture(0, texture_right); cube->getMeshBuffer(3)->getMaterial().setTexture(0, texture_right); cube->getMeshBuffer(4)->getMaterial().setTexture(0, texture_left); cube->getMeshBuffer(5)->getMaterial().setTexture(0, texture_left); core::dimension2d<u32> dim(64,64); std::string rtt_texture_name = part_of_name + "_RTT"; v3f camera_position(0, 1.0, -1.5); camera_position.rotateXZBy(45); v3f camera_lookat(0, 0, 0); core::CMatrix4<f32> camera_projection_matrix; // Set orthogonal projection camera_projection_matrix.buildProjectionMatrixOrthoLH( 1.65, 1.65, 0, 100); video::SColorf ambient_light(0.2,0.2,0.2); v3f light_position(10, 100, -50); video::SColorf light_color(0.5,0.5,0.5); f32 light_radius = 1000; video::ITexture *rtt = generateTextureFromMesh( cube, device, dim, rtt_texture_name, camera_position, camera_lookat, camera_projection_matrix, ambient_light, light_position, light_color, light_radius); // Drop mesh cube->drop(); // Free textures of images driver->removeTexture(texture_top); driver->removeTexture(texture_left); driver->removeTexture(texture_right); if(rtt == NULL) { baseimg = generate_image_from_scratch( imagename_top, device, sourcecache); return true; } // Create image of render target video::IImage *image = driver->createImage(rtt, v2s32(0,0), dim); assert(image); baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); if(image) { image->copyTo(baseimg); image->drop(); } } else { errorstream<<"generate_image(): Invalid " " modification: \""<<part_of_name<<"\""<<std::endl; } } return true; }
GUIEngine::GUIEngine(JoystickController *joystick, gui::IGUIElement *parent, IMenuManager *menumgr, MainMenuData *data, bool &kill) : m_parent(parent), m_menumanager(menumgr), m_smgr(RenderingEngine::get_scene_manager()), m_data(data), m_kill(kill) { //initialize texture pointers for (image_definition &texture : m_textures) { texture.texture = NULL; } // is deleted by guiformspec! m_buttonhandler = new TextDestGuiEngine(this); //create texture source m_texture_source = new MenuTextureSource(RenderingEngine::get_video_driver()); //create soundmanager MenuMusicFetcher soundfetcher; #if USE_SOUND if (g_settings->getBool("enable_sound")) m_sound_manager = createOpenALSoundManager(g_sound_manager_singleton.get(), &soundfetcher); #endif if(!m_sound_manager) m_sound_manager = &dummySoundManager; //create topleft header m_toplefttext = L""; core::rect<s32> rect(0, 0, g_fontengine->getTextWidth(m_toplefttext.c_str()), g_fontengine->getTextHeight()); rect += v2s32(4, 0); m_irr_toplefttext = gui::StaticText::add(RenderingEngine::get_gui_env(), m_toplefttext, rect, false, true, 0, -1); //create formspecsource m_formspecgui = new FormspecFormSource(""); /* Create menu */ m_menu = new GUIFormSpecMenu(joystick, m_parent, -1, m_menumanager, NULL /* &client */, m_texture_source, m_formspecgui, m_buttonhandler, "", false); m_menu->allowClose(false); m_menu->lockSize(true,v2u32(800,600)); // Initialize scripting infostream << "GUIEngine: Initializing Lua" << std::endl; m_script = new MainMenuScripting(this); try { m_script->setMainMenuData(&m_data->script_data); m_data->script_data.errormessage = ""; if (!loadMainMenuScript()) { errorstream << "No future without main menu!" << std::endl; abort(); } run(); } catch (LuaError &e) { errorstream << "Main menu error: " << e.what() << std::endl; m_data->script_data.errormessage = e.what(); } m_menu->quitMenu(); m_menu->drop(); m_menu = NULL; }
// hud_add(self, form) int ObjectRef::l_hud_add(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); Player *player = getplayer(ref); if (player == NULL) return 0; HudElement *elem = new HudElement; elem->type = (HudElementType)getenumfield(L, 2, "hud_elem_type", es_HudElementType, HUD_ELEM_TEXT); lua_getfield(L, 2, "position"); elem->pos = lua_istable(L, -1) ? read_v2f(L, -1) : v2f(); lua_pop(L, 1); lua_getfield(L, 2, "scale"); elem->scale = lua_istable(L, -1) ? read_v2f(L, -1) : v2f(); lua_pop(L, 1); lua_getfield(L, 2, "size"); elem->size = lua_istable(L, -1) ? read_v2s32(L, -1) : v2s32(); lua_pop(L, 1); elem->name = getstringfield_default(L, 2, "name", ""); elem->text = getstringfield_default(L, 2, "text", ""); elem->number = getintfield_default(L, 2, "number", 0); elem->item = getintfield_default(L, 2, "item", 0); elem->dir = getintfield_default(L, 2, "direction", 0); // Deprecated, only for compatibility's sake if (elem->dir == 0) elem->dir = getintfield_default(L, 2, "dir", 0); lua_getfield(L, 2, "alignment"); elem->align = lua_istable(L, -1) ? read_v2f(L, -1) : v2f(); lua_pop(L, 1); lua_getfield(L, 2, "offset"); elem->offset = lua_istable(L, -1) ? read_v2f(L, -1) : v2f(); lua_pop(L, 1); lua_getfield(L, 2, "world_pos"); elem->world_pos = lua_istable(L, -1) ? read_v3f(L, -1) : v3f(); lua_pop(L, 1); /* check for known deprecated element usage */ if ((elem->type == HUD_ELEM_STATBAR) && (elem->size == v2s32())) { log_deprecated(L,"Deprecated usage of statbar without size!"); } u32 id = getServer(L)->hudAdd(player, elem); if (id == U32_MAX) { delete elem; return 0; } lua_pushnumber(L, id); return 1; }
//NOTE: selectitem = 0 -> no selected; selectitem 1-based void Hud::drawItems(v2s32 upperleftpos, s32 itemcount, s32 offset, InventoryList *mainlist, u16 selectitem, u16 direction) { s32 height = m_hotbar_imagesize + m_padding * 2; s32 width = (itemcount - offset) * (m_hotbar_imagesize + m_padding * 2); if (direction == HUD_DIR_TOP_BOTTOM || direction == HUD_DIR_BOTTOM_TOP) { width = m_hotbar_imagesize + m_padding * 2; height = (itemcount - offset) * (m_hotbar_imagesize + m_padding * 2); } // Position of upper left corner of bar v2s32 pos = upperleftpos; if (hotbar_image != player->hotbar_image) { hotbar_image = player->hotbar_image; if (hotbar_image != "") use_hotbar_image = tsrc->isKnownSourceImage(hotbar_image); else use_hotbar_image = false; } if (hotbar_selected_image != player->hotbar_selected_image) { hotbar_selected_image = player->hotbar_selected_image; if (hotbar_selected_image != "") use_hotbar_selected_image = tsrc->isKnownSourceImage(hotbar_selected_image); else use_hotbar_selected_image = false; } /* draw customized item background */ if (use_hotbar_image) { core::rect<s32> imgrect2(-m_padding/2, -m_padding/2, width+m_padding/2, height+m_padding/2); core::rect<s32> rect2 = imgrect2 + pos; video::ITexture *texture = tsrc->getTexture(hotbar_image); core::dimension2di imgsize(texture->getOriginalSize()); driver->draw2DImage(texture, rect2, core::rect<s32>(core::position2d<s32>(0,0), imgsize), NULL, hbar_colors, true); } for (s32 i = offset; i < itemcount && (size_t)i < mainlist->getSize(); i++) { v2s32 steppos; s32 fullimglen = m_hotbar_imagesize + m_padding * 2; core::rect<s32> imgrect(0, 0, m_hotbar_imagesize, m_hotbar_imagesize); switch (direction) { case HUD_DIR_RIGHT_LEFT: steppos = v2s32(-(m_padding + (i - offset) * fullimglen), m_padding); break; case HUD_DIR_TOP_BOTTOM: steppos = v2s32(m_padding, m_padding + (i - offset) * fullimglen); break; case HUD_DIR_BOTTOM_TOP: steppos = v2s32(m_padding, -(m_padding + (i - offset) * fullimglen)); break; default: steppos = v2s32(m_padding + (i - offset) * fullimglen, m_padding); break; } drawItem(mainlist->getItem(i), (imgrect + pos + steppos), (i +1) == selectitem ); } }
void GUIMultiplayerMenu::regenerateGui(v2u32 screensize) { std::wstring text_name; std::wstring text_address; std::wstring text_port; m_screensize = screensize; // Client options { gui::IGUIElement *e = getElementFromId(GUI_ID_NAME_INPUT); if (e != NULL) { text_name = e->getText(); }else{ text_name = m_data.mmdata->name; } if (text_name == L"") text_name = narrow_to_wide(porting::getUser()); } { gui::IGUIElement *e = getElementFromId(GUI_ID_ADDRESS_INPUT); if (e != NULL) { text_address = e->getText(); }else{ text_address = m_data.mmdata->address; } } { gui::IGUIElement *e = getElementFromId(GUI_ID_PORT_INPUT); if (e != NULL) { text_port = e->getText(); }else{ text_port = m_data.mmdata->port; } } /* Remove stuff */ removeChildren(); /* Calculate new sizes and positions */ v2s32 size(800, 500); 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); // Main Menu button { core::rect<s32> rect(0, 0, 200, 40); rect += v2s32(25, 200); Environment->addButton(rect, this, GUI_ID_TAB_MP_MAINMENU, wgettext("Main Menu")); } // Dynamic List button { core::rect<s32> rect(0, 0, 180, 40); rect += v2s32(35, 260); Environment->addButton(rect, this, GUI_ID_TAB_MP_LIST, wgettext("All Servers")); } // Favourites List button { core::rect<s32> rect(0, 0, 180, 40); rect += v2s32(35, 305); Environment->addButton(rect, this, GUI_ID_TAB_MP_FAVOURITES, wgettext("Favourite Servers")); } // Custom Connect button (the old multiplayer menu) { core::rect<s32> rect(0, 0, 180, 40); rect += v2s32(35, 350); Environment->addButton(rect, this, GUI_ID_TAB_MP_CUSTOM, wgettext("Custom Connect")); } v2s32 topleft_content(250, 0); { core::rect<s32> rect(0, 0, 550, 20); rect += topleft_content + v2s32(0, 10); gui::IGUIStaticText *t = Environment->addStaticText(wgettext("Multi Player"), rect, false, true, this, -1); t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } if (m_data.selected_tab == TAB_MP_CUSTOM) { { core::rect<s32> rect(0, 0, 550, 20); rect += topleft_content + v2s32(0, 30); gui::IGUIStaticText *t = Environment->addStaticText(wgettext("Custom Connection"), rect, false, true, this, -1); t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } // Address + port { core::rect<s32> rect(0, 0, 110, 20); rect += topleft_content + v2s32(120, 60); Environment->addStaticText(wgettext("Address/Port"), rect, false, true, this, -1); } { if (text_address == L"") text_address = L"servers.voxelands.com"; core::rect<s32> rect(0, 0, 230, 30); rect += topleft_content + v2s32(135, 90); #if USE_FREETYPE new gui::intlGUIEditBox(text_address.c_str(), true, Environment, this, GUI_ID_ADDRESS_INPUT, rect); #else Environment->addEditBox(text_address.c_str(), rect, false, this, GUI_ID_ADDRESS_INPUT); #endif } { core::rect<s32> rect(0, 0, 120, 30); rect += topleft_content + v2s32(245, 125); #if USE_FREETYPE new gui::intlGUIEditBox(text_port.c_str(), true, Environment, this, GUI_ID_PORT_INPUT, rect); #else Environment->addEditBox(text_port.c_str(), rect, false, this, GUI_ID_PORT_INPUT); #endif } { core::rect<s32> rect(0, 0, 180, 30); rect += topleft_content + v2s32(80, 160); Environment->addButton(rect, this, GUI_ID_ADDFAV_BUTTON, wgettext("Add to Favourites")); } { core::rect<s32> rect(0, 0, 180, 30); rect += topleft_content + v2s32(270, 160); Environment->addButton(rect, this, GUI_ID_CONNECT_BUTTON, wgettext("Connect")); } }else if (m_data.selected_tab == TAB_MP_CONNECT) { // Nickname + password { core::rect<s32> rect(0, 0, 110, 20); rect += topleft_content + v2s32(120, 60); Environment->addStaticText(wgettext("Name/Password"), rect, false, true, this, -1); } { core::rect<s32> rect(0, 0, 230, 30); rect += topleft_content + v2s32(135, 90); #if USE_FREETYPE new gui::intlGUIEditBox(text_name.c_str(), true, Environment, this, GUI_ID_NAME_INPUT, rect); #else Environment->addEditBox(text_name.c_str(), rect, false, this, GUI_ID_NAME_INPUT); #endif } { core::rect<s32> rect(0, 0, 230, 30); rect += topleft_content + v2s32(135, 125); gui::IGUIEditBox *e; #if USE_FREETYPE e = (gui::IGUIEditBox *) new gui::intlGUIEditBox(L"", true, Environment, this, GUI_ID_PW_INPUT, rect); #else e = Environment->addEditBox(L"", rect, false, this, GUI_ID_PW_INPUT); #endif e->setPasswordBox(true); Environment->setFocus(e); // Start game button { core::rect<s32> rect(0, 0, 180, 30); rect += topleft_content + v2s32(160, 160); Environment->addButton(rect, this, GUI_ID_START_BUTTON, wgettext("Join Server")); } } }else{ gui::IGUIListBox *box = NULL; gui::IGUIStaticText *header = NULL; std::vector<ServerInfo> *list = NULL; { core::rect<s32> rect(0, 0, 550, 20); rect += topleft_content + v2s32(0, 30); header = Environment->addStaticText(L"", rect, false, true, this, -1); header->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } { core::rect<s32> rect(0, 0, 350, 200); rect += topleft_content + v2s32(100, 60); box = Environment->addListBox(rect, this, GUI_ID_SERVER_LIST, true); box->setItemHeight(25); } if (m_data.selected_tab == TAB_MP_FAVOURITES) { header->setText(wgettext("My Favourites")); list = &m_data.favourites; }else{ header->setText(wgettext("Server List")); list = &m_data.servers; { core::rect<s32> rect(0, 0, 180, 25); rect += topleft_content + v2s32(270, 260); Environment->addButton(rect, this, GUI_ID_REFRESH_BUTTON, wgettext("Get New List")); } } for (std::vector<ServerInfo>::iterator i = list->begin(); i != list->end(); i++) { box->addItem(i->name.c_str()); } if (m_data.selected_row > -1) { ServerInfo info = list->at(m_data.selected_row); if (info.name == L"") { m_data.selected_row = -1; }else{ box->setSelected(m_data.selected_row); { core::rect<s32> rect(0, 0, 550, 20); rect += topleft_content + v2s32(0, 300); gui::IGUIStaticText *t = Environment->addStaticText(info.name.c_str(), rect, false, true, this, -1); t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } { core::rect<s32> rect(0, 0, 350, 20); rect += topleft_content + v2s32(100, 330); gui::IGUIStaticText *t = Environment->addStaticText(info.addr.c_str(), rect, false, true, this, -1); t->setTextAlignment(gui::EGUIA_UPPERLEFT, gui::EGUIA_UPPERLEFT); } { core::rect<s32> rect(0, 0, 350, 20); rect += topleft_content + v2s32(100, 350); gui::IGUIStaticText *t = Environment->addStaticText(info.mode.c_str(), rect, false, true, this, -1); t->setTextAlignment(gui::EGUIA_UPPERLEFT, gui::EGUIA_UPPERLEFT); } if (info.is_favourite) { { core::rect<s32> rect(0, 0, 180, 30); rect += topleft_content + v2s32(80, 390); Environment->addButton(rect, this, GUI_ID_REMFAV_BUTTON, wgettext("Remove from Favourites")); } }else{ { core::rect<s32> rect(0, 0, 180, 30); rect += topleft_content + v2s32(80, 390); Environment->addButton(rect, this, GUI_ID_ADDFAV_BUTTON, wgettext("Add to Favourites")); } } { core::rect<s32> rect(0, 0, 180, 30); rect += topleft_content + v2s32(270, 390); Environment->addButton(rect, this, GUI_ID_CONNECT_BUTTON, wgettext("Connect")); } } } } }
void GUIMainMenu::regenerateGui(v2u32 screensize) { m_is_regenerating = true; /* Read stuff from elements into m_data */ readInput(m_data); /* Remove stuff */ removeChildren(); /* Calculate new sizes and positions */ v2s32 size(screensize.X, screensize.Y); 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 size = rect.getSize(); /* Add stuff */ changeCtype(""); // Version //if(m_data->selected_tab != TAB_CREDITS) { core::rect<s32> rect(0, 0, size.X, 40); rect += v2s32(4, 0); Environment->addStaticText(narrow_to_wide( "Minetest-c55 " VERSION_STRING).c_str(), rect, false, true, this, -1); } //v2s32 center(size.X/2, size.Y/2); v2s32 c800(size.X/2-400, size.Y/2-300); m_topleft_client = c800 + v2s32(90, 70+50+30); m_size_client = v2s32(620, 270); m_size_server = v2s32(620, 140); if(m_data->selected_tab == TAB_ADVANCED) { m_topleft_client = c800 + v2s32(90, 70+50+30); m_size_client = v2s32(620, 200); m_size_server = v2s32(620, 140); } m_topleft_server = m_topleft_client + v2s32(0, m_size_client.Y+20); // Tabs #if 1 { core::rect<s32> rect(0, 0, m_size_client.X, 30); rect += m_topleft_client + v2s32(0, -30); gui::IGUITabControl *e = Environment->addTabControl( rect, this, true, true, GUI_ID_TAB_CONTROL); e->addTab(L"Singleplayer"); e->addTab(L"Multiplayer"); e->addTab(L"Advanced"); e->addTab(L"Settings"); e->addTab(L"Credits"); e->setActiveTab(m_data->selected_tab); } #endif if(m_data->selected_tab == TAB_SINGLEPLAYER) { // HYBRID { core::rect<s32> rect(0, 0, 10, m_size_client.Y); rect += m_topleft_client + v2s32(15, 0); //const wchar_t *text = L"H\nY\nB\nR\nI\nD"; const wchar_t *text = L"T\nA\nP\nE\n\nA\nN\nD\n\nG\nL\nU\nE"; gui::IGUIStaticText *t = Environment->addStaticText(text, rect, false, false, this, -1); t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER); } u32 bs = 5; // World selection listbox u32 world_sel_h = 160; u32 world_sel_w = 365; //s32 world_sel_x = 50; s32 world_sel_x = m_size_client.X-world_sel_w-30; s32 world_sel_y = 30; u32 world_button_count = 3; u32 world_button_w = (world_sel_w)/world_button_count - bs + bs/(world_button_count-1); { core::rect<s32> rect(0, 0, world_sel_w-4, 20); rect += m_topleft_client + v2s32(world_sel_x+4, world_sel_y-20); /*gui::IGUIStaticText *e =*/ Environment->addStaticText( wgettext("Select World:"), rect, false, true, this, -1); /*e->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);*/ } { core::rect<s32> rect(0, 0, world_sel_w, world_sel_h); rect += m_topleft_client + v2s32(world_sel_x, world_sel_y); gui::IGUIListBox *e = Environment->addListBox(rect, this, GUI_ID_WORLD_LISTBOX); e->setDrawBackground(true); for(std::vector<WorldSpec>::const_iterator i = m_data->worlds.begin(); i != m_data->worlds.end(); i++){ e->addItem(narrow_to_wide(i->name+" ["+i->gameid+"]").c_str()); } e->setSelected(m_data->selected_world); Environment->setFocus(e); } // Delete world button { core::rect<s32> rect(0, 0, world_button_w, 30); rect += m_topleft_client + v2s32(world_sel_x, world_sel_y+world_sel_h+0); Environment->addButton(rect, this, GUI_ID_DELETE_WORLD_BUTTON, wgettext("Delete")); } // Create world button { core::rect<s32> rect(0, 0, world_button_w, 30); rect += m_topleft_client + v2s32(world_sel_x+world_button_w+bs, world_sel_y+world_sel_h+0); Environment->addButton(rect, this, GUI_ID_CREATE_WORLD_BUTTON, wgettext("New")); } // Configure world button { core::rect<s32> rect(0, 0, world_button_w, 30); rect += m_topleft_client + v2s32(world_sel_x+(world_button_w+bs)*2, world_sel_y+world_sel_h+0); Environment->addButton(rect, this, GUI_ID_CONFIGURE_WORLD_BUTTON, wgettext("Configure")); } // Start game button { /*core::rect<s32> rect(0, 0, world_button_w, 30); rect += m_topleft_client + v2s32(world_sel_x+(world_button_w+bs)*3, world_sel_y+world_sel_h+0);*/ u32 bw = 160; /*core::rect<s32> rect(0, 0, bw, 30); rect += m_topleft_client + v2s32(m_size_client.X-bw-30, m_size_client.Y-30-15);*/ core::rect<s32> rect(0, 0, bw, 30); rect += m_topleft_client + v2s32(world_sel_x+world_sel_w-bw, world_sel_y+world_sel_h+30+bs); Environment->addButton(rect, this, GUI_ID_JOIN_GAME_BUTTON, wgettext("Play")); } // Options s32 option_x = 50; //s32 option_x = 50+world_sel_w+20; s32 option_y = 30; u32 option_w = 150; { core::rect<s32> rect(0, 0, option_w, 30); rect += m_topleft_client + v2s32(option_x, option_y+20*0); Environment->addCheckBox(m_data->creative_mode, rect, this, GUI_ID_CREATIVE_CB, wgettext("Creative Mode")); } { core::rect<s32> rect(0, 0, option_w, 30); rect += m_topleft_client + v2s32(option_x, option_y+20*1); Environment->addCheckBox(m_data->enable_damage, rect, this, GUI_ID_DAMAGE_CB, wgettext("Enable Damage")); } changeCtype("C"); } else if(m_data->selected_tab == TAB_MULTIPLAYER) { changeCtype(""); // CLIENT { core::rect<s32> rect(0, 0, 10, m_size_client.Y); rect += m_topleft_client + v2s32(15, 0); const wchar_t *text = L"C\nL\nI\nE\nN\nT"; gui::IGUIStaticText *t = Environment->addStaticText(text, rect, false, false, this, -1); t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER); } // Nickname + password { core::rect<s32> rect(0, 0, 110, 20); rect += m_topleft_client + v2s32(35+30, 50+6); Environment->addStaticText(wgettext("Name/Password"), rect, false, true, this, -1); } changeCtype("C"); { core::rect<s32> rect(0, 0, 230, 30); rect += m_topleft_client + v2s32(160+30, 50); gui::IGUIElement *e = Environment->addEditBox(m_data->name.c_str(), rect, true, this, GUI_ID_NAME_INPUT); if(m_data->name == L"") Environment->setFocus(e); } { core::rect<s32> rect(0, 0, 120, 30); rect += m_topleft_client + v2s32(m_size_client.X-60-100, 50); gui::IGUIEditBox *e = Environment->addEditBox(L"", rect, true, this, 264); e->setPasswordBox(true); if(m_data->name != L"" && m_data->address != L"") Environment->setFocus(e); } changeCtype(""); // Address + port { core::rect<s32> rect(0, 0, 110, 20); rect += m_topleft_client + v2s32(35+30, 100+6); Environment->addStaticText(wgettext("Address/Port"), rect, false, true, this, -1); } changeCtype("C"); { core::rect<s32> rect(0, 0, 230, 30); rect += m_topleft_client + v2s32(160+30, 100); gui::IGUIElement *e = Environment->addEditBox(m_data->address.c_str(), rect, true, this, GUI_ID_ADDRESS_INPUT); if(m_data->name != L"" && m_data->address == L"") Environment->setFocus(e); } { core::rect<s32> rect(0, 0, 120, 30); rect += m_topleft_client + v2s32(m_size_client.X-60-100, 100); Environment->addEditBox(m_data->port.c_str(), rect, true, this, GUI_ID_PORT_INPUT); } changeCtype(""); // Start game button { core::rect<s32> rect(0, 0, 180, 30); rect += m_topleft_client + v2s32(m_size_client.X-180-30, m_size_client.Y-30-15); Environment->addButton(rect, this, GUI_ID_JOIN_GAME_BUTTON, wgettext("Start Game / Connect")); } changeCtype("C"); } else if(m_data->selected_tab == TAB_ADVANCED) { changeCtype(""); // CLIENT { core::rect<s32> rect(0, 0, 10, m_size_client.Y); rect += m_topleft_client + v2s32(15, 0); const wchar_t *text = L"C\nL\nI\nE\nN\nT"; gui::IGUIStaticText *t = Environment->addStaticText(text, rect, false, false, this, -1); t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER); } // Nickname + password { core::rect<s32> rect(0, 0, 110, 20); rect += m_topleft_client + v2s32(35+30, 35+6); Environment->addStaticText(wgettext("Name/Password"), rect, false, true, this, -1); } changeCtype("C"); { core::rect<s32> rect(0, 0, 230, 30); rect += m_topleft_client + v2s32(160+30, 35); gui::IGUIElement *e = Environment->addEditBox(m_data->name.c_str(), rect, true, this, GUI_ID_NAME_INPUT); if(m_data->name == L"") Environment->setFocus(e); } { core::rect<s32> rect(0, 0, 120, 30); rect += m_topleft_client + v2s32(m_size_client.X-60-100, 35); gui::IGUIEditBox *e = Environment->addEditBox(L"", rect, true, this, 264); e->setPasswordBox(true); if(m_data->name != L"" && m_data->address != L"") Environment->setFocus(e); } changeCtype(""); // Address + port { core::rect<s32> rect(0, 0, 110, 20); rect += m_topleft_client + v2s32(35+30, 75+6); Environment->addStaticText(wgettext("Address/Port"), rect, false, true, this, -1); } changeCtype("C"); { core::rect<s32> rect(0, 0, 230, 30); rect += m_topleft_client + v2s32(160+30, 75); gui::IGUIElement *e = Environment->addEditBox(m_data->address.c_str(), rect, true, this, GUI_ID_ADDRESS_INPUT); if(m_data->name != L"" && m_data->address == L"") Environment->setFocus(e); } { core::rect<s32> rect(0, 0, 120, 30); rect += m_topleft_client + v2s32(m_size_client.X-60-100, 75); Environment->addEditBox(m_data->port.c_str(), rect, true, this, GUI_ID_PORT_INPUT); } changeCtype(""); { core::rect<s32> rect(0, 0, 400, 20); rect += m_topleft_client + v2s32(160+30, 75+35); Environment->addStaticText(wgettext("Leave address blank to start a local server."), rect, false, true, this, -1); } // Start game button { core::rect<s32> rect(0, 0, 180, 30); rect += m_topleft_client + v2s32(m_size_client.X-180-30, m_size_client.Y-30-20); Environment->addButton(rect, this, GUI_ID_JOIN_GAME_BUTTON, wgettext("Start Game / Connect")); } /* Server section */ // SERVER { core::rect<s32> rect(0, 0, 10, m_size_server.Y); rect += m_topleft_server + v2s32(15, 0); const wchar_t *text = L"S\nE\nR\nV\nE\nR"; gui::IGUIStaticText *t = Environment->addStaticText(text, rect, false, false, this, -1); t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER); } // Server parameters { core::rect<s32> rect(0, 0, 250, 30); rect += m_topleft_server + v2s32(30+20+250+20, 20); Environment->addCheckBox(m_data->creative_mode, rect, this, GUI_ID_CREATIVE_CB, wgettext("Creative Mode")); } { core::rect<s32> rect(0, 0, 250, 30); rect += m_topleft_server + v2s32(30+20+250+20, 40); Environment->addCheckBox(m_data->enable_damage, rect, this, GUI_ID_DAMAGE_CB, wgettext("Enable Damage")); } // Delete world button { core::rect<s32> rect(0, 0, 130, 30); rect += m_topleft_server + v2s32(30+20+250+20, 90); Environment->addButton(rect, this, GUI_ID_DELETE_WORLD_BUTTON, wgettext("Delete world")); } // Create world button { core::rect<s32> rect(0, 0, 130, 30); rect += m_topleft_server + v2s32(30+20+250+20+140, 90); Environment->addButton(rect, this, GUI_ID_CREATE_WORLD_BUTTON, wgettext("Create world")); } // World selection listbox { core::rect<s32> rect(0, 0, 250, 120); rect += m_topleft_server + v2s32(30+20, 10); gui::IGUIListBox *e = Environment->addListBox(rect, this, GUI_ID_WORLD_LISTBOX); e->setDrawBackground(true); for(std::vector<WorldSpec>::const_iterator i = m_data->worlds.begin(); i != m_data->worlds.end(); i++){ e->addItem(narrow_to_wide(i->name+" ["+i->gameid+"]").c_str()); } e->setSelected(m_data->selected_world); } changeCtype("C"); } else if(m_data->selected_tab == TAB_SETTINGS) { { core::rect<s32> rect(0, 0, 10, m_size_client.Y); rect += m_topleft_client + v2s32(15, 0); const wchar_t *text = L"S\nE\nT\nT\nI\nN\nG\nS"; gui::IGUIStaticText *t = Environment->addStaticText(text, rect, false, false, this, -1); t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER); } s32 option_x = 70; s32 option_y = 50; u32 option_w = 150; { core::rect<s32> rect(0, 0, option_w, 30); rect += m_topleft_client + v2s32(option_x, option_y); Environment->addCheckBox(m_data->fancy_trees, rect, this, GUI_ID_FANCYTREE_CB, wgettext("Fancy trees")); } { core::rect<s32> rect(0, 0, option_w, 30); rect += m_topleft_client + v2s32(option_x, option_y+20); Environment->addCheckBox(m_data->smooth_lighting, rect, this, GUI_ID_SMOOTH_LIGHTING_CB, wgettext("Smooth Lighting")); } { core::rect<s32> rect(0, 0, option_w, 30); rect += m_topleft_client + v2s32(option_x, option_y+20*2); Environment->addCheckBox(m_data->clouds_3d, rect, this, GUI_ID_3D_CLOUDS_CB, wgettext("3D Clouds")); } { core::rect<s32> rect(0, 0, option_w, 30); rect += m_topleft_client + v2s32(option_x, option_y+20*3); Environment->addCheckBox(m_data->opaque_water, rect, this, GUI_ID_OPAQUE_WATER_CB, wgettext("Opaque water")); } // Key change button { core::rect<s32> rect(0, 0, 120, 30); /*rect += m_topleft_client + v2s32(m_size_client.X-120-30, m_size_client.Y-30-20);*/ rect += m_topleft_client + v2s32(option_x, option_y+120); Environment->addButton(rect, this, GUI_ID_CHANGE_KEYS_BUTTON, wgettext("Change keys")); } changeCtype("C"); } else if(m_data->selected_tab == TAB_CREDITS) { // CREDITS { core::rect<s32> rect(0, 0, 10, m_size_client.Y); rect += m_topleft_client + v2s32(15, 0); const wchar_t *text = L"C\nR\nE\nD\nI\nT\nS"; gui::IGUIStaticText *t = Environment->addStaticText(text, rect, false, false, this, -1); t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER); } { core::rect<s32> rect(0, 0, 620, 250); rect += m_topleft_client + v2s32(130+14, 50+35); Environment->addStaticText(narrow_to_wide( "Minetest-c55 " VERSION_STRING "\n" "http://c55.me/minetest/\n" "\n" "by Perttu Ahola <*****@*****.**>\n" "and contributors" ).c_str(), rect, false, true, this, -1); } } m_is_regenerating = false; }
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 GUIMainMenu::drawMenu() { gui::IGUISkin* skin = Environment->getSkin(); if (!skin) return; video::IVideoDriver* driver = Environment->getVideoDriver(); /*video::SColor bgcolor(140,0,0,0); driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);*/ video::SColor bgcolor(140,0,0,0); if(getTab() == TAB_SINGLEPLAYER) { { core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y); rect += AbsoluteRect.UpperLeftCorner + m_topleft_client; driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect); } } else if(getTab() == TAB_MULTIPLAYER) { { core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y); rect += AbsoluteRect.UpperLeftCorner + m_topleft_client; driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect); } } else if(getTab() == TAB_ADVANCED) { { core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y); rect += AbsoluteRect.UpperLeftCorner + m_topleft_client; driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect); } { core::rect<s32> rect(0, 0, m_size_server.X, m_size_server.Y); rect += AbsoluteRect.UpperLeftCorner + m_topleft_server; driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect); } } else if(getTab() == TAB_SETTINGS) { { core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y); rect += AbsoluteRect.UpperLeftCorner + m_topleft_client; driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect); } } else if(getTab() == TAB_CREDITS) { { core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y); rect += AbsoluteRect.UpperLeftCorner + m_topleft_client; driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect); } video::ITexture *logotexture = driver->getTexture(getTexturePath("menulogo.png").c_str()); if(logotexture) { v2s32 logosize(logotexture->getOriginalSize().Width, logotexture->getOriginalSize().Height); logosize *= 2; core::rect<s32> rect(0,0,logosize.X,logosize.Y); rect += AbsoluteRect.UpperLeftCorner + m_topleft_client; rect += v2s32(130, 50); driver->draw2DImage(logotexture, rect, core::rect<s32>(core::position2d<s32>(0,0), core::dimension2di(logotexture->getSize())), NULL, NULL, true); } } gui::IGUIElement::draw(); }
GUIEngine::GUIEngine( irr::IrrlichtDevice* dev, gui::IGUIElement* parent, IMenuManager *menumgr, scene::ISceneManager* smgr, MainMenuData* data, bool& kill) : m_device(dev), m_parent(parent), m_menumanager(menumgr), m_smgr(smgr), m_data(data), m_texture_source(NULL), m_sound_manager(NULL), m_formspecgui(0), m_buttonhandler(0), m_menu(0), m_kill(kill), m_startgame(false), m_script(0), m_scriptdir(""), m_irr_toplefttext(0), m_clouds_enabled(true), m_cloud() { //initialize texture pointers for (unsigned int i = 0; i < TEX_LAYER_MAX; i++) { m_textures[i] = 0; } // is deleted by guiformspec! m_buttonhandler = new TextDestGuiEngine(this); //create texture source m_texture_source = new MenuTextureSource(m_device->getVideoDriver()); //create soundmanager MenuMusicFetcher soundfetcher; #if USE_SOUND m_sound_manager = createOpenALSoundManager(&soundfetcher); #endif if(!m_sound_manager) m_sound_manager = &dummySoundManager; //create topleft header core::rect<s32> rect(0, 0, 500, 20); rect += v2s32(4, 0); std::string t = std::string("Freeminer ") + minetest_version_hash; m_irr_toplefttext = m_device->getGUIEnvironment()->addStaticText(narrow_to_wide(t).c_str(), rect,false,true,0,-1); //create formspecsource m_formspecgui = new FormspecFormSource("",&m_formspecgui); /* Create menu */ m_menu = new GUIFormSpecMenu( m_device, m_parent, -1, m_menumanager, 0 /* &client */, 0 /* gamedef */, m_texture_source); m_menu->allowClose(false); m_menu->lockSize(true,v2u32(800,600)); m_menu->setFormSource(m_formspecgui); m_menu->setTextDest(m_buttonhandler); // Initialize scripting infostream<<"GUIEngine: Initializing Lua"<<std::endl; m_script = new MainMenuScripting(this); try { if (m_data->errormessage != "") { m_script->setMainMenuErrorMessage(m_data->errormessage); m_data->errormessage = ""; } if (!loadMainMenuScript()) assert("no future without mainmenu" == 0); run(); } catch(LuaError &e) { errorstream << "MAINMENU ERROR: " << e.what() << std::endl; m_data->errormessage = e.what(); } m_menu->quitMenu(); m_menu->drop(); m_menu = 0; }
void GUIMainMenu::regenerateGui(v2u32 screensize) { std::wstring text_name; std::wstring text_address; std::wstring text_port; bool creative_mode; bool enable_damage; bool fancy_trees; bool smooth_lighting; // Client options { gui::IGUIElement *e = getElementFromId(GUI_ID_NAME_INPUT); if(e != NULL) text_name = e->getText(); else text_name = m_data->name; } { gui::IGUIElement *e = getElementFromId(GUI_ID_ADDRESS_INPUT); if(e != NULL) text_address = e->getText(); else text_address = m_data->address; } { gui::IGUIElement *e = getElementFromId(GUI_ID_PORT_INPUT); if(e != NULL) text_port = e->getText(); else text_port = m_data->port; } { gui::IGUIElement *e = getElementFromId(GUI_ID_FANCYTREE_CB); if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX) fancy_trees = ((gui::IGUICheckBox*)e)->isChecked(); else fancy_trees = m_data->fancy_trees; } { gui::IGUIElement *e = getElementFromId(GUI_ID_SMOOTH_LIGHTING_CB); if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX) smooth_lighting = ((gui::IGUICheckBox*)e)->isChecked(); else smooth_lighting = m_data->smooth_lighting; } // Server options { gui::IGUIElement *e = getElementFromId(GUI_ID_CREATIVE_CB); if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX) creative_mode = ((gui::IGUICheckBox*)e)->isChecked(); else creative_mode = m_data->creative_mode; } { gui::IGUIElement *e = getElementFromId(GUI_ID_DAMAGE_CB); if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX) enable_damage = ((gui::IGUICheckBox*)e)->isChecked(); else enable_damage = m_data->enable_damage; } /* Remove stuff */ removeChildren(); /* Calculate new sizes and positions */ 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 size = rect.getSize(); /* Add stuff */ /* Client section */ v2s32 topleft_client(40, 0); v2s32 size_client = size - v2s32(40, 0); changeCtype(""); { core::rect<s32> rect(0, 0, 20, 125); rect += topleft_client + v2s32(-15, 60); const wchar_t *text = L"C\nL\nI\nE\nN\nT"; //gui::IGUIStaticText *t = Environment->addStaticText(text, rect, false, true, this, -1); //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } // Nickname + password { core::rect<s32> rect(0, 0, 110, 20); rect += topleft_client + v2s32(35, 50+6); Environment->addStaticText(wgettext("Name/Password"), rect, false, true, this, -1); } changeCtype("C"); { core::rect<s32> rect(0, 0, 230, 30); rect += topleft_client + v2s32(160, 50); gui::IGUIElement *e = Environment->addEditBox(text_name.c_str(), rect, true, this, GUI_ID_NAME_INPUT); if(text_name == L"") Environment->setFocus(e); } { core::rect<s32> rect(0, 0, 120, 30); rect += topleft_client + v2s32(size_client.X-60-100, 50); gui::IGUIEditBox *e = Environment->addEditBox(L"", rect, true, this, 264); e->setPasswordBox(true); if(text_name != L"" && text_address != L"") Environment->setFocus(e); } changeCtype(""); // Address + port { core::rect<s32> rect(0, 0, 110, 20); rect += topleft_client + v2s32(35, 100+6); Environment->addStaticText(wgettext("Address/Port"), rect, false, true, this, -1); } changeCtype("C"); { core::rect<s32> rect(0, 0, 230, 30); rect += topleft_client + v2s32(160, 100); gui::IGUIElement *e = Environment->addEditBox(text_address.c_str(), rect, true, this, GUI_ID_ADDRESS_INPUT); if(text_name != L"" && text_address == L"") Environment->setFocus(e); } { core::rect<s32> rect(0, 0, 120, 30); //rect += topleft_client + v2s32(160+250+20, 125); rect += topleft_client + v2s32(size_client.X-60-100, 100); Environment->addEditBox(text_port.c_str(), rect, true, this, GUI_ID_PORT_INPUT); } changeCtype(""); { core::rect<s32> rect(0, 0, 400, 20); rect += topleft_client + v2s32(160, 100+35); Environment->addStaticText(wgettext("Leave address blank to start a local server."), rect, false, true, this, -1); } { core::rect<s32> rect(0, 0, 250, 30); rect += topleft_client + v2s32(35, 150); Environment->addCheckBox(fancy_trees, rect, this, GUI_ID_FANCYTREE_CB, wgettext("Fancy trees")); } { core::rect<s32> rect(0, 0, 250, 30); rect += topleft_client + v2s32(35, 150+30); Environment->addCheckBox(smooth_lighting, rect, this, GUI_ID_SMOOTH_LIGHTING_CB, wgettext("Smooth Lighting")); } // Start game button { core::rect<s32> rect(0, 0, 180, 30); //rect += topleft_client + v2s32(size_client.X/2-180/2, 225-30/2); rect += topleft_client + v2s32(size_client.X-180-40, 150+25); Environment->addButton(rect, this, GUI_ID_JOIN_GAME_BUTTON, wgettext("Start Game / Connect")); } // Key change button { core::rect<s32> rect(0, 0, 100, 30); //rect += topleft_client + v2s32(size_client.X/2-180/2, 225-30/2); rect += topleft_client + v2s32(size_client.X-180-40-100-20, 150+25); Environment->addButton(rect, this, GUI_ID_CHANGE_KEYS_BUTTON, wgettext("Change keys")); } /* Server section */ v2s32 topleft_server(40, 250); v2s32 size_server = size - v2s32(40, 0); { core::rect<s32> rect(0, 0, 20, 125); rect += topleft_server + v2s32(-15, 40); const wchar_t *text = L"S\nE\nR\nV\nE\nR"; //gui::IGUIStaticText *t = Environment->addStaticText(text, rect, false, true, this, -1); //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } // Server parameters { core::rect<s32> rect(0, 0, 250, 30); rect += topleft_server + v2s32(35, 30); Environment->addCheckBox(creative_mode, rect, this, GUI_ID_CREATIVE_CB, wgettext("Creative Mode")); } { core::rect<s32> rect(0, 0, 250, 30); rect += topleft_server + v2s32(35, 60); Environment->addCheckBox(enable_damage, rect, this, GUI_ID_DAMAGE_CB, wgettext("Enable Damage")); } // Map delete button { core::rect<s32> rect(0, 0, 130, 30); //rect += topleft_server + v2s32(size_server.X-40-130, 100+25); rect += topleft_server + v2s32(40, 100+25); Environment->addButton(rect, this, GUI_ID_DELETE_MAP_BUTTON, wgettext("Delete map")); } changeCtype("C"); }
void ProfilerGraph::draw(s32 x_left, s32 y_bottom, video::IVideoDriver *driver, gui::IGUIFont *font) const { // Do *not* use UNORDERED_MAP here as the order needs // to be the same for each call to prevent flickering std::map<std::string, Meta> m_meta; for (const Piece &piece : m_log) { for (const auto &i : piece.values) { const std::string &id = i.first; const float &value = i.second; std::map<std::string, Meta>::iterator j = m_meta.find(id); if (j == m_meta.end()) { m_meta[id] = Meta(value); continue; } if (value < j->second.min) j->second.min = value; if (value > j->second.max) j->second.max = value; } } // Assign colors static const video::SColor usable_colors[] = {video::SColor(255, 255, 100, 100), video::SColor(255, 90, 225, 90), video::SColor(255, 100, 100, 255), video::SColor(255, 255, 150, 50), video::SColor(255, 220, 220, 100)}; static const u32 usable_colors_count = sizeof(usable_colors) / sizeof(*usable_colors); u32 next_color_i = 0; for (auto &i : m_meta) { Meta &meta = i.second; video::SColor color(255, 200, 200, 200); if (next_color_i < usable_colors_count) color = usable_colors[next_color_i++]; meta.color = color; } s32 graphh = 50; s32 textx = x_left + m_log_max_size + 15; s32 textx2 = textx + 200 - 15; s32 meta_i = 0; for (const auto &p : m_meta) { const std::string &id = p.first; const Meta &meta = p.second; s32 x = x_left; s32 y = y_bottom - meta_i * 50; float show_min = meta.min; float show_max = meta.max; if (show_min >= -0.0001 && show_max >= -0.0001) { if (show_min <= show_max * 0.5) show_min = 0; } s32 texth = 15; char buf[10]; porting::mt_snprintf(buf, sizeof(buf), "%.3g", show_max); font->draw(utf8_to_wide(buf).c_str(), core::rect<s32>(textx, y - graphh, textx2, y - graphh + texth), meta.color); porting::mt_snprintf(buf, sizeof(buf), "%.3g", show_min); font->draw(utf8_to_wide(buf).c_str(), core::rect<s32>(textx, y - texth, textx2, y), meta.color); font->draw(utf8_to_wide(id).c_str(), core::rect<s32>(textx, y - graphh / 2 - texth / 2, textx2, y - graphh / 2 + texth / 2), meta.color); s32 graph1y = y; s32 graph1h = graphh; bool relativegraph = (show_min != 0 && show_min != show_max); float lastscaledvalue = 0.0; bool lastscaledvalue_exists = false; for (const Piece &piece : m_log) { float value = 0; bool value_exists = false; Profiler::GraphValues::const_iterator k = piece.values.find(id); if (k != piece.values.end()) { value = k->second; value_exists = true; } if (!value_exists) { x++; lastscaledvalue_exists = false; continue; } float scaledvalue = 1.0; if (show_max != show_min) scaledvalue = (value - show_min) / (show_max - show_min); if (scaledvalue == 1.0 && value == 0) { x++; lastscaledvalue_exists = false; continue; } if (relativegraph) { if (lastscaledvalue_exists) { s32 ivalue1 = lastscaledvalue * graph1h; s32 ivalue2 = scaledvalue * graph1h; driver->draw2DLine( v2s32(x - 1, graph1y - ivalue1), v2s32(x, graph1y - ivalue2), meta.color); } lastscaledvalue = scaledvalue; lastscaledvalue_exists = true; } else { s32 ivalue = scaledvalue * graph1h; driver->draw2DLine(v2s32(x, graph1y), v2s32(x, graph1y - ivalue), meta.color); } x++; } meta_i++; } }
static void draw_crack(video::IImage *crack, video::IImage *dst, bool use_overlay, s32 frame_count, s32 progression, video::IVideoDriver *driver) { // Dimension of destination image core::dimension2d<u32> dim_dst = dst->getDimension(); // Dimension of original image core::dimension2d<u32> dim_crack = crack->getDimension(); // Count of crack stages s32 crack_count = dim_crack.Height / dim_crack.Width; // Limit frame_count if(frame_count > (s32) dim_dst.Height) frame_count = dim_dst.Height; if(frame_count < 1) frame_count = 1; // Limit progression if(progression > crack_count-1) progression = crack_count-1; // Dimension of a single crack stage core::dimension2d<u32> dim_crack_cropped( dim_crack.Width, dim_crack.Width ); // Dimension of the scaled crack stage, // which is the same as the dimension of a single destination frame core::dimension2d<u32> dim_crack_scaled( dim_dst.Width, dim_dst.Height / frame_count ); // Create cropped and scaled crack images video::IImage *crack_cropped = driver->createImage( video::ECF_A8R8G8B8, dim_crack_cropped); video::IImage *crack_scaled = driver->createImage( video::ECF_A8R8G8B8, dim_crack_scaled); if(crack_cropped && crack_scaled) { // Crop crack image v2s32 pos_crack(0, progression*dim_crack.Width); crack->copyTo(crack_cropped, v2s32(0,0), core::rect<s32>(pos_crack, dim_crack_cropped)); // Scale crack image by copying crack_cropped->copyToScaling(crack_scaled); // Copy or overlay crack image onto each frame for(s32 i = 0; i < frame_count; ++i) { v2s32 dst_pos(0, dim_crack_scaled.Height * i); if(use_overlay) { blit_with_alpha_overlay(crack_scaled, dst, v2s32(0,0), dst_pos, dim_crack_scaled); } else { blit_with_alpha(crack_scaled, dst, v2s32(0,0), dst_pos, dim_crack_scaled); } } } if(crack_scaled) crack_scaled->drop(); if(crack_cropped) crack_cropped->drop(); }
void Hud::drawLuaElements(v3s16 camera_offset) { u32 text_height = g_fontengine->getTextHeight(); irr::gui::IGUIFont* font = g_fontengine->getFont(); for (size_t i = 0; i != player->maxHudId(); i++) { HudElement *e = player->getHud(i); if (!e) continue; v2s32 pos(floor(e->pos.X * (float) m_screensize.X + 0.5), floor(e->pos.Y * (float) m_screensize.Y + 0.5)); switch (e->type) { case HUD_ELEM_IMAGE: { video::ITexture *texture = tsrc->getTexture(e->text); if (!texture) continue; const video::SColor color(255, 255, 255, 255); const video::SColor colors[] = {color, color, color, color}; core::dimension2di imgsize(texture->getOriginalSize()); v2s32 dstsize(imgsize.Width * e->scale.X, imgsize.Height * e->scale.Y); if (e->scale.X < 0) dstsize.X = m_screensize.X * (e->scale.X * -0.01); if (e->scale.Y < 0) dstsize.Y = m_screensize.Y * (e->scale.Y * -0.01); v2s32 offset((e->align.X - 1.0) * dstsize.X / 2, (e->align.Y - 1.0) * dstsize.Y / 2); core::rect<s32> rect(0, 0, dstsize.X, dstsize.Y); rect += pos + offset + v2s32(e->offset.X, e->offset.Y); driver->draw2DImage(texture, rect, core::rect<s32>(core::position2d<s32>(0,0), imgsize), NULL, colors, true); break; } case HUD_ELEM_TEXT: { video::SColor color(255, (e->number >> 16) & 0xFF, (e->number >> 8) & 0xFF, (e->number >> 0) & 0xFF); core::rect<s32> size(0, 0, e->scale.X, text_height * e->scale.Y); std::wstring text = narrow_to_wide(e->text); core::dimension2d<u32> textsize = font->getDimension(text.c_str()); v2s32 offset((e->align.X - 1.0) * (textsize.Width / 2), (e->align.Y - 1.0) * (textsize.Height / 2)); v2s32 offs(e->offset.X, e->offset.Y); font->draw(text.c_str(), size + pos + offset + offs, color); break; } case HUD_ELEM_STATBAR: { v2s32 offs(e->offset.X, e->offset.Y); drawStatbar(pos, HUD_CORNER_UPPER, e->dir, e->text, e->number, offs, e->size); break; } case HUD_ELEM_INVENTORY: { InventoryList *inv = inventory->getList(e->text); drawItems(pos, e->number, 0, inv, e->item, e->dir); break; } case HUD_ELEM_WAYPOINT: { v3f p_pos = player->getPosition() / BS; v3f w_pos = e->world_pos * BS; float distance = floor(10 * p_pos.getDistanceFrom(e->world_pos)) / 10; scene::ICameraSceneNode* camera = smgr->getActiveCamera(); w_pos -= intToFloat(camera_offset, BS); core::matrix4 trans = camera->getProjectionMatrix(); trans *= camera->getViewMatrix(); f32 transformed_pos[4] = { w_pos.X, w_pos.Y, w_pos.Z, 1.0f }; trans.multiplyWith1x4Matrix(transformed_pos); if (transformed_pos[3] < 0) break; f32 zDiv = transformed_pos[3] == 0.0f ? 1.0f : core::reciprocal(transformed_pos[3]); pos.X = m_screensize.X * (0.5 * transformed_pos[0] * zDiv + 0.5); pos.Y = m_screensize.Y * (0.5 - transformed_pos[1] * zDiv * 0.5); video::SColor color(255, (e->number >> 16) & 0xFF, (e->number >> 8) & 0xFF, (e->number >> 0) & 0xFF); core::rect<s32> size(0, 0, 200, 2 * text_height); std::wstring text = narrow_to_wide(e->name); font->draw(text.c_str(), size + pos, color); std::ostringstream os; os<<distance<<e->text; text = narrow_to_wide(os.str()); pos.Y += text_height; font->draw(text.c_str(), size + pos, color); break; } default: infostream << "Hud::drawLuaElements: ignoring drawform " << e->type << " of hud element ID " << i << " due to unrecognized type" << std::endl; } } }
/* This method generates all the textures */ u32 TextureSource::getTextureIdDirect(const std::string &name) { //infostream<<"getTextureIdDirect(): name=\""<<name<<"\""<<std::endl; // Empty name means texture 0 if(name == "") { infostream<<"getTextureIdDirect(): name is empty"<<std::endl; return 0; } /* Calling only allowed from main thread */ if(get_current_thread_id() != m_main_thread) { errorstream<<"TextureSource::getTextureIdDirect() " "called not from main thread"<<std::endl; return 0; } /* See if texture already exists */ { JMutexAutoLock lock(m_textureinfo_cache_mutex); std::map<std::string, u32>::iterator n; n = m_name_to_id.find(name); if(n != m_name_to_id.end()) { /*infostream<<"getTextureIdDirect(): \""<<name <<"\" found in cache"<<std::endl;*/ return n->second; } } /*infostream<<"getTextureIdDirect(): \""<<name <<"\" NOT found in cache. Creating it."<<std::endl;*/ /* Get the base image */ char separator = '^'; /* This is set to the id of the base image. If left 0, there is no base image and a completely new image is made. */ u32 base_image_id = 0; // Find last meta separator in name s32 last_separator_position = -1; for(s32 i=name.size()-1; i>=0; i--) { if(name[i] == separator) { last_separator_position = i; break; } } /* If separator was found, construct the base name and make the base image using a recursive call */ std::string base_image_name; if(last_separator_position != -1) { // Construct base name base_image_name = name.substr(0, last_separator_position); /*infostream<<"getTextureIdDirect(): Calling itself recursively" " to get base image of \""<<name<<"\" = \"" <<base_image_name<<"\""<<std::endl;*/ base_image_id = getTextureIdDirect(base_image_name); } //infostream<<"base_image_id="<<base_image_id<<std::endl; video::IVideoDriver* driver = m_device->getVideoDriver(); assert(driver); video::ITexture *t = NULL; /* An image will be built from files and then converted into a texture. */ video::IImage *baseimg = NULL; // If a base image was found, copy it to baseimg if(base_image_id != 0) { JMutexAutoLock lock(m_textureinfo_cache_mutex); TextureInfo *ti = &m_textureinfo_cache[base_image_id]; if(ti->img == NULL) { infostream<<"getTextureIdDirect(): WARNING: NULL image in " <<"cache: \""<<base_image_name<<"\"" <<std::endl; } else { core::dimension2d<u32> dim = ti->img->getDimension(); baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); ti->img->copyTo( baseimg, // target v2s32(0,0), // position in target core::rect<s32>(v2s32(0,0), dim) // from ); /*infostream<<"getTextureIdDirect(): Loaded \"" <<base_image_name<<"\" from image cache" <<std::endl;*/ } } /* Parse out the last part of the name of the image and act according to it */ std::string last_part_of_name = name.substr(last_separator_position+1); //infostream<<"last_part_of_name=\""<<last_part_of_name<<"\""<<std::endl; // Generate image according to part of name if(!generateImage(last_part_of_name, baseimg)) { errorstream<<"getTextureIdDirect(): " "failed to generate \""<<last_part_of_name<<"\"" <<std::endl; } // If no resulting image, print a warning if(baseimg == NULL) { errorstream<<"getTextureIdDirect(): baseimg is NULL (attempted to" " create texture \""<<name<<"\""<<std::endl; } if(baseimg != NULL) { // Create texture from resulting image t = driver->addTexture(name.c_str(), baseimg); } /* Add texture to caches (add NULL textures too) */ JMutexAutoLock lock(m_textureinfo_cache_mutex); u32 id = m_textureinfo_cache.size(); TextureInfo ti(name, t, baseimg); m_textureinfo_cache.push_back(ti); m_name_to_id[name] = id; /*infostream<<"getTextureIdDirect(): " <<"Returning id="<<id<<" for name \""<<name<<"\""<<std::endl;*/ return id; }
void Hud::drawItem(const ItemStack &item, const core::rect<s32>& rect, bool selected) { if (selected) { /* draw hihlighting around selected item */ if (use_hotbar_selected_image) { core::rect<s32> imgrect2 = rect; imgrect2.UpperLeftCorner.X -= (m_padding*2); imgrect2.UpperLeftCorner.Y -= (m_padding*2); imgrect2.LowerRightCorner.X += (m_padding*2); imgrect2.LowerRightCorner.Y += (m_padding*2); video::ITexture *texture = tsrc->getTexture(hotbar_selected_image); core::dimension2di imgsize(texture->getOriginalSize()); driver->draw2DImage(texture, imgrect2, core::rect<s32>(core::position2d<s32>(0,0), imgsize), NULL, hbar_colors, true); } else { video::SColor c_outside(255,255,0,0); //video::SColor c_outside(255,0,0,0); //video::SColor c_inside(255,192,192,192); s32 x1 = rect.UpperLeftCorner.X; s32 y1 = rect.UpperLeftCorner.Y; s32 x2 = rect.LowerRightCorner.X; s32 y2 = rect.LowerRightCorner.Y; // Black base borders driver->draw2DRectangle(c_outside, core::rect<s32>( v2s32(x1 - m_padding, y1 - m_padding), v2s32(x2 + m_padding, y1) ), NULL); driver->draw2DRectangle(c_outside, core::rect<s32>( v2s32(x1 - m_padding, y2), v2s32(x2 + m_padding, y2 + m_padding) ), NULL); driver->draw2DRectangle(c_outside, core::rect<s32>( v2s32(x1 - m_padding, y1), v2s32(x1, y2) ), NULL); driver->draw2DRectangle(c_outside, core::rect<s32>( v2s32(x2, y1), v2s32(x2 + m_padding, y2) ), NULL); /*// Light inside borders driver->draw2DRectangle(c_inside, core::rect<s32>( v2s32(x1 - padding/2, y1 - padding/2), v2s32(x2 + padding/2, y1) ), NULL); driver->draw2DRectangle(c_inside, core::rect<s32>( v2s32(x1 - padding/2, y2), v2s32(x2 + padding/2, y2 + padding/2) ), NULL); driver->draw2DRectangle(c_inside, core::rect<s32>( v2s32(x1 - padding/2, y1), v2s32(x1, y2) ), NULL); driver->draw2DRectangle(c_inside, core::rect<s32>( v2s32(x2, y1), v2s32(x2 + padding/2, y2) ), NULL); */ } } video::SColor bgcolor2(128, 0, 0, 0); if (!use_hotbar_image) driver->draw2DRectangle(bgcolor2, rect, NULL); drawItemStack(driver, g_fontengine->getFont(), item, rect, NULL, gamedef); }
bool TextureSource::generateImage(std::string part_of_name, video::IImage *& baseimg) { video::IVideoDriver* driver = m_device->getVideoDriver(); assert(driver); // Stuff starting with [ are special commands if(part_of_name.size() == 0 || part_of_name[0] != '[') { video::IImage *image = m_sourcecache.getOrLoad(part_of_name, m_device); if(image == NULL) { if(part_of_name != ""){ errorstream<<"generateImage(): Could not load image \"" <<part_of_name<<"\""<<" while building texture"<<std::endl; errorstream<<"generateImage(): Creating a dummy" <<" image for \""<<part_of_name<<"\""<<std::endl; } // Just create a dummy image //core::dimension2d<u32> dim(2,2); core::dimension2d<u32> dim(1,1); image = driver->createImage(video::ECF_A8R8G8B8, dim); assert(image); /*image->setPixel(0,0, video::SColor(255,255,0,0)); image->setPixel(1,0, video::SColor(255,0,255,0)); image->setPixel(0,1, video::SColor(255,0,0,255)); image->setPixel(1,1, video::SColor(255,255,0,255));*/ image->setPixel(0,0, video::SColor(255,myrand()%256, myrand()%256,myrand()%256)); /*image->setPixel(1,0, video::SColor(255,myrand()%256, myrand()%256,myrand()%256)); image->setPixel(0,1, video::SColor(255,myrand()%256, myrand()%256,myrand()%256)); image->setPixel(1,1, video::SColor(255,myrand()%256, myrand()%256,myrand()%256));*/ } // If base image is NULL, load as base. if(baseimg == NULL) { //infostream<<"Setting "<<part_of_name<<" as base"<<std::endl; /* Copy it this way to get an alpha channel. Otherwise images with alpha cannot be blitted on images that don't have alpha in the original file. */ core::dimension2d<u32> dim = image->getDimension(); baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); image->copyTo(baseimg); } // Else blit on base. else { //infostream<<"Blitting "<<part_of_name<<" on base"<<std::endl; // Size of the copied area core::dimension2d<u32> dim = image->getDimension(); //core::dimension2d<u32> dim(16,16); // Position to copy the blitted to in the base image core::position2d<s32> pos_to(0,0); // Position to copy the blitted from in the blitted image core::position2d<s32> pos_from(0,0); // Blit /*image->copyToWithAlpha(baseimg, pos_to, core::rect<s32>(pos_from, dim), video::SColor(255,255,255,255), NULL);*/ blit_with_alpha(image, baseimg, pos_from, pos_to, dim); } //cleanup image->drop(); } else { // A special texture modification /*infostream<<"generateImage(): generating special " <<"modification \""<<part_of_name<<"\"" <<std::endl;*/ /* [crack:N:P [cracko:N:P Adds a cracking texture N = animation frame count, P = crack progression */ if(part_of_name.substr(0,6) == "[crack") { if(baseimg == NULL) { errorstream<<"generateImage(): baseimg==NULL " <<"for part_of_name=\""<<part_of_name <<"\", cancelling."<<std::endl; return false; } // Crack image number and overlay option bool use_overlay = (part_of_name[6] == 'o'); Strfnd sf(part_of_name); sf.next(":"); s32 frame_count = stoi(sf.next(":")); s32 progression = stoi(sf.next(":")); /* Load crack image. It is an image with a number of cracking stages horizontally tiled. */ video::IImage *img_crack = m_sourcecache.getOrLoad( "crack_anylength.png", m_device); if(img_crack && progression >= 0) { draw_crack(img_crack, baseimg, use_overlay, frame_count, progression, driver); img_crack->drop(); } } /* [combine:WxH:X,Y=filename:X,Y=filename2 Creates a bigger texture from an amount of smaller ones */ else if(part_of_name.substr(0,8) == "[combine") { Strfnd sf(part_of_name); sf.next(":"); u32 w0 = stoi(sf.next("x")); u32 h0 = stoi(sf.next(":")); infostream<<"combined w="<<w0<<" h="<<h0<<std::endl; core::dimension2d<u32> dim(w0,h0); if(baseimg == NULL) { baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); baseimg->fill(video::SColor(0,0,0,0)); } while(sf.atend() == false) { u32 x = stoi(sf.next(",")); u32 y = stoi(sf.next("=")); std::string filename = sf.next(":"); infostream<<"Adding \""<<filename <<"\" to combined ("<<x<<","<<y<<")" <<std::endl; video::IImage *img = m_sourcecache.getOrLoad(filename, m_device); if(img) { core::dimension2d<u32> dim = img->getDimension(); infostream<<"Size "<<dim.Width <<"x"<<dim.Height<<std::endl; core::position2d<s32> pos_base(x, y); video::IImage *img2 = driver->createImage(video::ECF_A8R8G8B8, dim); img->copyTo(img2); img->drop(); /*img2->copyToWithAlpha(baseimg, pos_base, core::rect<s32>(v2s32(0,0), dim), video::SColor(255,255,255,255), NULL);*/ blit_with_alpha(img2, baseimg, v2s32(0,0), pos_base, dim); img2->drop(); } else { infostream<<"img==NULL"<<std::endl; } } } /* "[brighten" */ else if(part_of_name.substr(0,9) == "[brighten") { if(baseimg == NULL) { errorstream<<"generateImage(): baseimg==NULL " <<"for part_of_name=\""<<part_of_name <<"\", cancelling."<<std::endl; return false; } brighten(baseimg); } /* "[noalpha" Make image completely opaque. Used for the leaves texture when in old leaves mode, so that the transparent parts don't look completely black when simple alpha channel is used for rendering. */ else if(part_of_name.substr(0,8) == "[noalpha") { if(baseimg == NULL) { errorstream<<"generateImage(): baseimg==NULL " <<"for part_of_name=\""<<part_of_name <<"\", cancelling."<<std::endl; return false; } core::dimension2d<u32> dim = baseimg->getDimension(); // Set alpha to full for(u32 y=0; y<dim.Height; y++) for(u32 x=0; x<dim.Width; x++) { video::SColor c = baseimg->getPixel(x,y); c.setAlpha(255); baseimg->setPixel(x,y,c); } } /* "[makealpha:R,G,B" Convert one color to transparent. */ else if(part_of_name.substr(0,11) == "[makealpha:") { if(baseimg == NULL) { errorstream<<"generateImage(): baseimg==NULL " <<"for part_of_name=\""<<part_of_name <<"\", cancelling."<<std::endl; return false; } Strfnd sf(part_of_name.substr(11)); u32 r1 = stoi(sf.next(",")); u32 g1 = stoi(sf.next(",")); u32 b1 = stoi(sf.next("")); std::string filename = sf.next(""); core::dimension2d<u32> dim = baseimg->getDimension(); /*video::IImage *oldbaseimg = baseimg; baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); oldbaseimg->copyTo(baseimg); oldbaseimg->drop();*/ // Set alpha to full for(u32 y=0; y<dim.Height; y++) for(u32 x=0; x<dim.Width; x++) { video::SColor c = baseimg->getPixel(x,y); u32 r = c.getRed(); u32 g = c.getGreen(); u32 b = c.getBlue(); if(!(r == r1 && g == g1 && b == b1)) continue; c.setAlpha(0); baseimg->setPixel(x,y,c); } } /* "[transformN" Rotates and/or flips the image. N can be a number (between 0 and 7) or a transform name. Rotations are counter-clockwise. 0 I identity 1 R90 rotate by 90 degrees 2 R180 rotate by 180 degrees 3 R270 rotate by 270 degrees 4 FX flip X 5 FXR90 flip X then rotate by 90 degrees 6 FY flip Y 7 FYR90 flip Y then rotate by 90 degrees Note: Transform names can be concatenated to produce their product (applies the first then the second). The resulting transform will be equivalent to one of the eight existing ones, though (see: dihedral group). */ else if(part_of_name.substr(0,10) == "[transform") { if(baseimg == NULL) { errorstream<<"generateImage(): baseimg==NULL " <<"for part_of_name=\""<<part_of_name <<"\", cancelling."<<std::endl; return false; } u32 transform = parseImageTransform(part_of_name.substr(10)); core::dimension2d<u32> dim = imageTransformDimension( transform, baseimg->getDimension()); video::IImage *image = driver->createImage( baseimg->getColorFormat(), dim); assert(image); imageTransform(transform, baseimg, image); baseimg->drop(); baseimg = image; } /* [inventorycube{topimage{leftimage{rightimage In every subimage, replace ^ with &. Create an "inventory cube". NOTE: This should be used only on its own. Example (a grass block (not actually used in game): "[inventorycube{grass.png{mud.png&grass_side.png{mud.png&grass_side.png" */ else if(part_of_name.substr(0,14) == "[inventorycube") { if(baseimg != NULL) { errorstream<<"generateImage(): baseimg!=NULL " <<"for part_of_name=\""<<part_of_name <<"\", cancelling."<<std::endl; return false; } str_replace_char(part_of_name, '&', '^'); Strfnd sf(part_of_name); sf.next("{"); std::string imagename_top = sf.next("{"); std::string imagename_left = sf.next("{"); std::string imagename_right = sf.next("{"); // Generate images for the faces of the cube video::IImage *img_top = generateImageFromScratch(imagename_top); video::IImage *img_left = generateImageFromScratch(imagename_left); video::IImage *img_right = generateImageFromScratch(imagename_right); assert(img_top && img_left && img_right); // Create textures from images video::ITexture *texture_top = driver->addTexture( (imagename_top + "__temp__").c_str(), img_top); video::ITexture *texture_left = driver->addTexture( (imagename_left + "__temp__").c_str(), img_left); video::ITexture *texture_right = driver->addTexture( (imagename_right + "__temp__").c_str(), img_right); assert(texture_top && texture_left && texture_right); // Drop images img_top->drop(); img_left->drop(); img_right->drop(); /* Draw a cube mesh into a render target texture */ scene::IMesh* cube = createCubeMesh(v3f(1, 1, 1)); setMeshColor(cube, video::SColor(255, 255, 255, 255)); cube->getMeshBuffer(0)->getMaterial().setTexture(0, texture_top); cube->getMeshBuffer(1)->getMaterial().setTexture(0, texture_top); cube->getMeshBuffer(2)->getMaterial().setTexture(0, texture_right); cube->getMeshBuffer(3)->getMaterial().setTexture(0, texture_right); cube->getMeshBuffer(4)->getMaterial().setTexture(0, texture_left); cube->getMeshBuffer(5)->getMaterial().setTexture(0, texture_left); TextureFromMeshParams params; params.mesh = cube; params.dim.set(64, 64); params.rtt_texture_name = part_of_name + "_RTT"; // We will delete the rtt texture ourselves params.delete_texture_on_shutdown = false; params.camera_position.set(0, 1.0, -1.5); params.camera_position.rotateXZBy(45); params.camera_lookat.set(0, 0, 0); // Set orthogonal projection params.camera_projection_matrix.buildProjectionMatrixOrthoLH( 1.65, 1.65, 0, 100); params.ambient_light.set(1.0, 0.2, 0.2, 0.2); params.light_position.set(10, 100, -50); params.light_color.set(1.0, 0.5, 0.5, 0.5); params.light_radius = 1000; video::ITexture *rtt = generateTextureFromMesh(params); // Drop mesh cube->drop(); // Free textures of images driver->removeTexture(texture_top); driver->removeTexture(texture_left); driver->removeTexture(texture_right); if(rtt == NULL) { baseimg = generateImageFromScratch(imagename_top); return true; } // Create image of render target video::IImage *image = driver->createImage(rtt, v2s32(0,0), params.dim); assert(image); // Cleanup texture driver->removeTexture(rtt); baseimg = driver->createImage(video::ECF_A8R8G8B8, params.dim); if(image) { image->copyTo(baseimg); image->drop(); } } /* [lowpart:percent:filename Adds the lower part of a texture */ else if(part_of_name.substr(0,9) == "[lowpart:") { Strfnd sf(part_of_name); sf.next(":"); u32 percent = stoi(sf.next(":")); std::string filename = sf.next(":"); //infostream<<"power part "<<percent<<"%% of "<<filename<<std::endl; if(baseimg == NULL) baseimg = driver->createImage(video::ECF_A8R8G8B8, v2u32(16,16)); video::IImage *img = m_sourcecache.getOrLoad(filename, m_device); if(img) { core::dimension2d<u32> dim = img->getDimension(); core::position2d<s32> pos_base(0, 0); video::IImage *img2 = driver->createImage(video::ECF_A8R8G8B8, dim); img->copyTo(img2); img->drop(); core::position2d<s32> clippos(0, 0); clippos.Y = dim.Height * (100-percent) / 100; core::dimension2d<u32> clipdim = dim; clipdim.Height = clipdim.Height * percent / 100 + 1; core::rect<s32> cliprect(clippos, clipdim); img2->copyToWithAlpha(baseimg, pos_base, core::rect<s32>(v2s32(0,0), dim), video::SColor(255,255,255,255), &cliprect); img2->drop(); } } /* [verticalframe:N:I Crops a frame of a vertical animation. N = frame count, I = frame index */ else if(part_of_name.substr(0,15) == "[verticalframe:") { Strfnd sf(part_of_name); sf.next(":"); u32 frame_count = stoi(sf.next(":")); u32 frame_index = stoi(sf.next(":")); if(baseimg == NULL){ errorstream<<"generateImage(): baseimg!=NULL " <<"for part_of_name=\""<<part_of_name <<"\", cancelling."<<std::endl; return false; } v2u32 frame_size = baseimg->getDimension(); if (frame_count) frame_size.Y /= frame_count; video::IImage *img = driver->createImage(video::ECF_A8R8G8B8, frame_size); if(!img){ errorstream<<"generateImage(): Could not create image " <<"for part_of_name=\""<<part_of_name <<"\", cancelling."<<std::endl; return false; } // Fill target image with transparency img->fill(video::SColor(0,0,0,0)); core::dimension2d<u32> dim = frame_size; core::position2d<s32> pos_dst(0, 0); core::position2d<s32> pos_src(0, frame_index * frame_size.Y); baseimg->copyToWithAlpha(img, pos_dst, core::rect<s32>(pos_src, dim), video::SColor(255,255,255,255), NULL); // Replace baseimg baseimg->drop(); baseimg = img; } else { errorstream<<"generateImage(): Invalid " " modification: \""<<part_of_name<<"\""<<std::endl; } } return true; }
virtual void step(float dtime) { { static float counter1 = 0; counter1 -= dtime; if(counter1 < 0.0) { counter1 = 0.1*Rand(1, 40); keydown.toggle(getKeySetting("keymap_jump")); } } { static float counter1 = 0; counter1 -= dtime; if(counter1 < 0.0) { counter1 = 0.1*Rand(1, 40); keydown.toggle(getKeySetting("keymap_special1")); } } { static float counter1 = 0; counter1 -= dtime; if(counter1 < 0.0) { counter1 = 0.1*Rand(1, 40); keydown.toggle(getKeySetting("keymap_forward")); } } { static float counter1 = 0; counter1 -= dtime; if(counter1 < 0.0) { counter1 = 0.1*Rand(1, 40); keydown.toggle(getKeySetting("keymap_left")); } } { static float counter1 = 0; counter1 -= dtime; if(counter1 < 0.0) { counter1 = 0.1*Rand(1, 20); mousespeed = v2s32(Rand(-20,20), Rand(-15,20)); } } { static float counter1 = 0; counter1 -= dtime; if(counter1 < 0.0) { counter1 = 0.1*Rand(1, 30); leftdown = !leftdown; if(leftdown) leftclicked = true; if(!leftdown) leftreleased = true; } } { static float counter1 = 0; counter1 -= dtime; if(counter1 < 0.0) { counter1 = 0.1*Rand(1, 15); rightdown = !rightdown; if(rightdown) rightclicked = true; if(!rightdown) rightreleased = true; } } mousepos += mousespeed; }
void GUIPauseMenu::regenerateGui(v2u32 screensize) { /* Remove stuff */ removeChildren(); /* Calculate new sizes and positions */ core::rect<s32> rect( screensize.X/2 - 280/2, screensize.Y/2 - 300/2, screensize.X/2 + 280/2, screensize.Y/2 + 300/2 ); DesiredRect = rect; recalculateAbsolutePosition(false); v2s32 size = rect.getSize(); /* Add stuff */ const s32 btn_height = 30; const s32 btn_gap = 20; const s32 btn_num = m_simple_singleplayer_mode ? 4 : 5; s32 btn_y = size.Y/2-((btn_num*btn_height+(btn_num-1)*btn_gap))/2; { core::rect<s32> rect(0, 0, 140, btn_height); rect = rect + v2s32(size.X/2-140/2, btn_y); wchar_t* text = wgettext("Continue"); Environment->addButton(rect, this, 256, text); delete[] text; } btn_y += btn_height + btn_gap; if(!m_simple_singleplayer_mode) { { core::rect<s32> rect(0, 0, 140, btn_height); rect = rect + v2s32(size.X/2-140/2, btn_y); wchar_t* text = wgettext("Change Password"); Environment->addButton(rect, this, 261, text); delete[] text; } btn_y += btn_height + btn_gap; } { core::rect<s32> rect(0, 0, 140, btn_height); rect = rect + v2s32(size.X/2-140/2, btn_y); wchar_t* text = wgettext("Sound Volume"); Environment->addButton(rect, this, 262, text); delete[] text; } btn_y += btn_height + btn_gap; { core::rect<s32> rect(0, 0, 140, btn_height); rect = rect + v2s32(size.X/2-140/2, btn_y); wchar_t* text = wgettext("Exit to Menu"); Environment->addButton(rect, this, 260, text); delete[] text; } btn_y += btn_height + btn_gap; { core::rect<s32> rect(0, 0, 140, btn_height); rect = rect + v2s32(size.X/2-140/2, btn_y); wchar_t* text = wgettext("Exit to OS"); Environment->addButton(rect, this, 257, text); delete[] text; } }