aboutsummaryrefslogtreecommitdiff
path: root/builtin
Commit message (Collapse)AuthorAge
* Add formspec escaping to subgame list in create world dialog (#5808)rubenwardy2017-05-24
|
* [CSM] Add send_chat_message and run_server_chatcommand API functions (#5747)Pierre-Adrien Langrognet2017-05-21
| | | | | | | | | | | | * [CSM] Add send_chat_message and run_server_chatcommand API functions * Add client-side chat message rate limiting * Limit out chat queue size * [CSM] Add minetest.clear_out_chat_queue API function and .clear_chat_queue chatcommand * Last fixes/cleanups before merge
* Menu: Merge singleplayer and server tabs (#5627)Elijah Duffy2017-05-21
| | | Rename "Singleplayer" tab to "Play" and remove "Server" tab placing server functionality under a "Host Game" checkbox in "Play."
* Add /clearinv chat command (#4994)Elijah Duffy2017-05-20
| | | Allow players to clear their own inventory or that of another player with /clearinv command. server privilege is required to clear another player's inventory, no privileges are required to clear your own inventory.'
* Mainmenu: Fix issues while trying to enable all mods (#5770)SmallJoker2017-05-19
|
* Builtin: Fix subgame mod selection (#5367)SmallJoker2017-05-17
|
* CSM: Document forgotten functionsSmallJoker2017-05-16
|
* Add option to use neither node highlighting nor outliningezhh2017-05-15
|
* Menu: Fix starting a server if the server address is an empty string. (#5742)red-0012017-05-10
| | | Minetest uses an empty string internal to signal that a server should be started.
* minetest.deserialize: Throw error when argument not string (#5738)SmallJoker2017-05-09
|
* Android: Fix crash while loading main menu (#5736)red-0012017-05-09
| | | Broken by 43d1f37
* Move Pilzadam to previous developers. (#5735)Auke Kok2017-05-09
|
* Use a settings object for the main settingsShadowNinja2017-05-06
| | | | | | | This unifies the settings APIs. This also unifies the sync and async registration APIs, since the async registration API did not support adding non-functions to the API table.
* Add configurable key bindings for hotbar scrolling, and for changing volume.Wuzzy2017-05-06
|
* [CSM] add `on_item_use` (#5544)red-0012017-05-06
|
* Save minetest screen width/height options when modified (#5683)Loïc Blot2017-05-05
| | | | | | | | * Save minetest screen width/height options when modified * Add autosave_screensize setting (default true) * Fix @SmallJoker comments
* [CSM] Add event on_place_node API lua (#5548)Vincent Glize2017-04-29
| | | | * [CSM] Add event on_place_node API lua
* Footsteps without view bobbing (#5645)Louis Pearson2017-04-25
| | | | | | | | | | | | * Remove redundant view_bobbing setting Also fixes bug where disabling view_bobbing disables footstep sounds. * Removes redundant view_bobbing setting Setting view_bobbing amount to 0 is now the only way to turn view_bobbing on and off. Also fixed a bug where footstep sounds would not play when view_bobbing was disabled.
* Player data to Database (#5475)Loïc Blot2017-04-23
| | | | | | | | | | | | * Player data to Database Add player data into databases (SQLite3 & PG only) PostgreSQL & SQLite: better POO Design for databases Add --migrate-players argument to server + deprecation warning * Remove players directory if empty
* Add /fixlight chat commandDániel Juhász2017-04-22
|
* Conf.example: Move some lines to minetest.conf.example.extraparamat2017-04-19
| | | | | | | | Some information in conf.example cannot be generated from settingtypes.txt, moving it to a new file makes generating conf.example while preserving that information easier. Regenerate conf.example from settingtypes.txt.
* Pointed thing to face pos: Fix crash if opening door with slab or stairMarkuBu2017-04-19
| | | | | | Avoids crash caused when 'pointed thing -under' and '-above' are not face-neighbours, for example in the case of pointing to the top half of a door.
* MeshUpdateQueue: Add a MapBlock cache that minimizes the amount of MapBlock ↵Perttu Ahola2017-04-17
| | | | | | | | | | | | | | | | | | | | | copying done in the main thread Cache size is configurable by the meshgen_block_cache_size (default 20 MB). New profiler stats: - MeshUpdateQueue MapBlock cache hit % - MeshUpdateQueue MapBlock cache size kB Removes one type of stutter that was seen on the client when received MapBlocks were being handled. (the "MeshMakeData::fill" stutter) Kind of related to at least #5239 Originally preceded by these commits, now includes them: - Move the mesh generator thread into src/mesh_generator_thread.{cpp,h} - mesh_generator_thread.cpp: Update code style - MeshUpdateThread: Modify interface to house a different implementation: Actual functionality will be changed by next commits. - MeshMakeData: Add fillBlockData() interface (so that caller can fill in stuff from eg. a MapBlock cache)
* Implement delayed server shutdown with cancelation (#4664)Loïc Blot2017-04-15
|
* [CSM] Allow escaping chatcommands and add missing calls to gettext. (#5565)red-0012017-04-11
|
* [CSM] Use more gettext (#5553)red-0012017-04-10
|
* [CSM] Move `.list_players` and `.disconnect` to builtin. (#5550)red-0012017-04-10
|
* Hard-coded undersampling.number Zero2017-04-09
| | | | | | | | | | Adds uniform undersampling for the 3D rendered scene. GUI elements are not undersampled, resulting in better playability for users with low-performance platforms with readable fonts and formspecs. The undersampling setting can be set to 0 (disabled), 2, 3, 4 pixels which translates into a resolution reduction of x4, x9 or x16, and is significant.
* Hardware coloring for itemstacksDániel Juhász2017-04-08
| | | | | | | | | | Adds the possibility to colorize item stacks based on their metadata. In the item/node definition you can specify palette (an image file) and color (fallback color if the item has no palette or metadata). Then you can add palette_index to the metadata. Dropped itemstacks with different colors do not merge.
* Move chat command handling code from C++ to Lua (#5528)red-0012017-04-08
|
* [CSM] Add event on_connect player API lua (#5540)Vincent Glize2017-04-08
| | | | * Add event on_connect player API lua
* Settings: Update documentation (#5534)SmallJoker2017-04-07
| | | | | | | | | | | | Now documented (sorted a-z): enable_console enable_particles creative_mode hud_scaling inventory_image_hack keymap_console keymap_zoom shader_path view_bobbing
* Add Joystick type detection and Xbox controller supportrubenwardy2017-04-06
| | | | | | * Add joystick type detection (with joystick_type setting to override it) * Fix multiple joysticks from interfering with each other by only reading from one (add joystick_id setting) * Add support for Xbox controllers
* Expose vector helpers to CSMLoic Blot2017-04-06
|
* Mapgen documentation: Add descriptions to noise parametersparamat2017-04-05
| | | | | | Shorten 'readable names'. Add a new advanced settings menu section for Biome API noises. Various minor edits and improvements.
* Cavegen/Mgv5/Mgv7: Add optional giant cavernsparamat2017-04-03
| | | | | | | | | | | | | | Add to MapgenBasic for use by multiple mapgens. Add to mgv5 and mgv7, enabled by default. Similar to mgvalleys caverns but half the scale. Parameters for upper y limit, distance caverns taper to full size, and noise threshold (full cavern size). As with mgvalleys caverns are generated first and classic caves are disabled in any mapchunk containing a cavern, to avoid excessive spreading volumes of liquids. This also avoids floating blobs of liquid where a large classic cave has overgenerated out into a neighbouring previously-generated mapchunk.
* minetest.after(): simplify further, pause in singleplayer (#5500)Auke Kok2017-04-02
| | | | | | Using the `dtime` value entirely, this will stop the clock if the game is paused in singleplayer. Since most of the clocks were fixed a long time ago, this should again be safe to use.
* First commit for fine pointed (#5485)MarkuBu2017-04-01
|
* Add functions to strip color information. (#5472)Diego Martínez2017-03-28
|
* Fix a type bug in colorize functionLoïc Blot2017-03-28
| | | | This bug was introduced by dd2f1d7551bfd70357ad4f3fb180704194272147 and reported by @kilbith
* Map generation limit: Make per-worldparamat2017-03-27
| | | | | | | | | | | The setting limits map generation but affects nothing else. Add 'mapgen_limit' to global mapgen parameters. Move 'blockpos_over_mapgen_limit()' to the only place it is called from: map.cpp. Allow teleportation to any part of the world even if over the set mapgen limit. Simplify the reading of this limit in mgvalleys. Remove the 'map_generation_limit' setting.
* Change command prefix to "." and add "help" command.red-0012017-03-26
|
* Add mesh generation delaynumber Zero2017-03-26
|
* Typo fixLoïc Blot2017-03-24
|
* Add multiline support to colorize. (#5444)red-0012017-03-24
|
* Block access to the `io` libraryred-0012017-03-19
|
* Give CSM access to use `core.colorize()` (#5113)red-0012017-03-17
|
* Fix two nul deref if digging unknown nodes. (#5398)Auke Kok2017-03-15
| | | Introduced by d785456b3fa35faf47cb972fde9e8668382c5e22 (#5162)
* [CSM] Add enable_client_modding param (default: false)nerzhul2017-03-13
|
* [CSM] Add `on_punchnode` callbackred-0012017-03-13
|
s="hl opt">(crosshair_color.Z), 0, 255); u32 cross_a = rangelim(g_settings->getS32("crosshair_alpha"), 0, 255); crosshair_argb = video::SColor(cross_a, cross_r, cross_g, cross_b); v3f selectionbox_color = g_settings->getV3F("selectionbox_color"); u32 sbox_r = rangelim(myround(selectionbox_color.X), 0, 255); u32 sbox_g = rangelim(myround(selectionbox_color.Y), 0, 255); u32 sbox_b = rangelim(myround(selectionbox_color.Z), 0, 255); selectionbox_argb = video::SColor(255, sbox_r, sbox_g, sbox_b); use_crosshair_image = tsrc->isKnownSourceImage("crosshair.png"); m_selection_boxes.clear(); m_halo_boxes.clear(); std::string mode_setting = g_settings->get("node_highlighting"); if (mode_setting == "halo") { m_mode = HIGHLIGHT_HALO; } else if (mode_setting == "none") { m_mode = HIGHLIGHT_NONE; } else { m_mode = HIGHLIGHT_BOX; } m_selection_material.Lighting = false; if (g_settings->getBool("enable_shaders")) { IShaderSource *shdrsrc = client->getShaderSource(); u16 shader_id = shdrsrc->getShader( m_mode == HIGHLIGHT_HALO ? "selection_shader" : "default_shader", 1, 1); m_selection_material.MaterialType = shdrsrc->getShaderInfo(shader_id).material; } else { m_selection_material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; } if (m_mode == HIGHLIGHT_BOX) { m_selection_material.Thickness = rangelim(g_settings->getS16("selectionbox_width"), 1, 5); } else if (m_mode == HIGHLIGHT_HALO) { m_selection_material.setTexture(0, tsrc->getTextureForMesh("halo.png")); m_selection_material.setFlag(video::EMF_BACK_FACE_CULLING, true); } else { m_selection_material.MaterialType = video::EMT_SOLID; } } Hud::~Hud() { if (m_selection_mesh) m_selection_mesh->drop(); } 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()); draw2DImageFilterScaled(driver, 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, client, selected ? IT_ROT_SELECTED : IT_ROT_NONE); } //NOTE: selectitem = 0 -> no selected; selectitem 1-based void Hud::drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount, s32 inv_offset, InventoryList *mainlist, u16 selectitem, u16 direction) { #ifdef HAVE_TOUCHSCREENGUI if (g_touchscreengui && inv_offset == 0) g_touchscreengui->resetHud(); #endif s32 height = m_hotbar_imagesize + m_padding * 2; s32 width = (itemcount - inv_offset) * (m_hotbar_imagesize + m_padding * 2); if (direction == HUD_DIR_TOP_BOTTOM || direction == HUD_DIR_BOTTOM_TOP) { s32 tmp = height; height = width; width = tmp; } // Position of upper left corner of bar v2s32 pos = screen_offset; pos.X *= m_hud_scaling * RenderingEngine::getDisplayDensity(); pos.Y *= m_hud_scaling * RenderingEngine::getDisplayDensity(); pos += upperleftpos; // Store hotbar_image in member variable, used by drawItem() if (hotbar_image != player->hotbar_image) { hotbar_image = player->hotbar_image; if (!hotbar_image.empty()) use_hotbar_image = tsrc->isKnownSourceImage(hotbar_image); else use_hotbar_image = false; } // Store hotbar_selected_image in member variable, used by drawItem() if (hotbar_selected_image != player->hotbar_selected_image) { hotbar_selected_image = player->hotbar_selected_image; if (!hotbar_selected_image.empty()) 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()); draw2DImageFilterScaled(driver, texture, rect2, core::rect<s32>(core::position2d<s32>(0,0), imgsize), NULL, hbar_colors, true); } // Draw items core::rect<s32> imgrect(0, 0, m_hotbar_imagesize, m_hotbar_imagesize); for (s32 i = inv_offset; i < itemcount && (size_t)i < mainlist->getSize(); i++) { s32 fullimglen = m_hotbar_imagesize + m_padding * 2; v2s32 steppos; switch (direction) { case HUD_DIR_RIGHT_LEFT: steppos = v2s32(-(m_padding + (i - inv_offset) * fullimglen), m_padding); break; case HUD_DIR_TOP_BOTTOM: steppos = v2s32(m_padding, m_padding + (i - inv_offset) * fullimglen); break; case HUD_DIR_BOTTOM_TOP: steppos = v2s32(m_padding, -(m_padding + (i - inv_offset) * fullimglen)); break; default: steppos = v2s32(m_padding + (i - inv_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 Hud::drawLuaElements(const 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); draw2DImageFilterScaled(driver, 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 = unescape_translate(utf8_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, v2s32(e->offset.X, e->offset.Y), 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 = RenderingEngine::get_scene_manager()->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 = unescape_translate(utf8_to_wide(e->name)); font->draw(text.c_str(), size + pos, color); std::ostringstream os; os << distance << e->text; text = unescape_translate(utf8_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; } } } 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 { float size_factor = m_hud_scaling * RenderingEngine::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; core::rect<s32> srchalfrect, dsthalfrect; switch (drawdir) { case HUD_DIR_RIGHT_LEFT: steppos = v2s32(-1, 0); srchalfrect = core::rect<s32>(srcd.Width / 2, 0, srcd.Width, srcd.Height); dsthalfrect = core::rect<s32>(dstd.Width / 2, 0, dstd.Width, dstd.Height); break; case HUD_DIR_TOP_BOTTOM: steppos = v2s32(0, 1); srchalfrect = core::rect<s32>(0, 0, srcd.Width, srcd.Height / 2); dsthalfrect = core::rect<s32>(0, 0, dstd.Width, dstd.Height / 2); break; case HUD_DIR_BOTTOM_TOP: steppos = v2s32(0, -1); srchalfrect = core::rect<s32>(0, srcd.Height / 2, srcd.Width, srcd.Height); dsthalfrect = core::rect<s32>(0, dstd.Height / 2, dstd.Width, dstd.Height); break; default: steppos = v2s32(1, 0); srchalfrect = core::rect<s32>(0, 0, srcd.Width / 2, srcd.Height); dsthalfrect = core::rect<s32>(0, 0, dstd.Width / 2, dstd.Height); } 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; draw2DImageFilterScaled(driver, stat_texture, dstrect, srcrect, NULL, colors, true); p += steppos; } if (count % 2 == 1) { dsthalfrect += p; draw2DImageFilterScaled(driver, stat_texture, dsthalfrect, srchalfrect, NULL, colors, true); } } void Hud::drawHotbar(u16 playeritem) { v2s32 centerlowerpos(m_displaycenter.X, m_screensize.Y); InventoryList *mainlist = inventory->getList("main"); if (mainlist == NULL) { //silently ignore this we may not be initialized completely return; } s32 hotbar_itemcount = player->hud_hotbar_itemcount; s32 width = hotbar_itemcount * (m_hotbar_imagesize + m_padding * 2); v2s32 pos = centerlowerpos - v2s32(width / 2, m_hotbar_imagesize + m_padding * 3); const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize(); if ( (float) width / (float) window_size.X <= g_settings->getFloat("hud_hotbar_max_width")) { if (player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE) { drawItems(pos, v2s32(0, 0), hotbar_itemcount, 0, mainlist, playeritem + 1, 0); } } else { pos.X += width/4; v2s32 secondpos = pos; pos = pos - v2s32(0, m_hotbar_imagesize + m_padding); if (player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE) { drawItems(pos, v2s32(0, 0), hotbar_itemcount / 2, 0, mainlist, playeritem + 1, 0); drawItems(secondpos, v2s32(0, 0), hotbar_itemcount, hotbar_itemcount / 2, mainlist, playeritem + 1, 0); } } //////////////////////////// compatibility code to be removed ////////////// // this is ugly as hell but there's no other way to keep compatibility to // old servers if ((player->hud_flags & HUD_FLAG_HEALTHBAR_VISIBLE)) { drawStatbar(v2s32(floor(0.5 * (float)m_screensize.X + 0.5), floor(1 * (float) m_screensize.Y + 0.5)), HUD_CORNER_UPPER, 0, "heart.png", player->hp, v2s32((-10*24)-25,-(48+24+10)), v2s32(24,24)); } if ((player->hud_flags & HUD_FLAG_BREATHBAR_VISIBLE) && (player->getBreath() < 11)) { drawStatbar(v2s32(floor(0.5 * (float)m_screensize.X + 0.5), floor(1 * (float) m_screensize.Y + 0.5)), HUD_CORNER_UPPER, 0, "bubble.png", player->getBreath(), v2s32(25,-(48+24+10)), v2s32(24,24)); } //////////////////////////////////////////////////////////////////////////// } void Hud::drawCrosshair() { if (use_crosshair_image) { video::ITexture *crosshair = tsrc->getTexture("crosshair.png"); v2u32 size = crosshair->getOriginalSize(); v2s32 lsize = v2s32(m_displaycenter.X - (size.X / 2), m_displaycenter.Y - (size.Y / 2)); driver->draw2DImage(crosshair, lsize, core::rect<s32>(0, 0, size.X, size.Y), 0, crosshair_argb, true); } else { driver->draw2DLine(m_displaycenter - v2s32(10, 0), m_displaycenter + v2s32(10, 0), crosshair_argb); driver->draw2DLine(m_displaycenter - v2s32(0, 10), m_displaycenter + v2s32(0, 10), crosshair_argb); } } void Hud::setSelectionPos(const v3f &pos, const v3s16 &camera_offset) { m_camera_offset = camera_offset; m_selection_pos = pos; m_selection_pos_with_offset = pos - intToFloat(camera_offset, BS); } void Hud::drawSelectionMesh() { if (m_mode == HIGHLIGHT_BOX) { // Draw 3D selection boxes video::SMaterial oldmaterial = driver->getMaterial2D(); driver->setMaterial(m_selection_material); for (std::vector<aabb3f>::const_iterator i = m_selection_boxes.begin(); i != m_selection_boxes.end(); ++i) { aabb3f box = aabb3f( i->MinEdge + m_selection_pos_with_offset, i->MaxEdge + m_selection_pos_with_offset); u32 r = (selectionbox_argb.getRed() * m_selection_mesh_color.getRed() / 255); u32 g = (selectionbox_argb.getGreen() * m_selection_mesh_color.getGreen() / 255); u32 b = (selectionbox_argb.getBlue() * m_selection_mesh_color.getBlue() / 255); driver->draw3DBox(box, video::SColor(255, r, g, b)); } driver->setMaterial(oldmaterial); } else if (m_mode == HIGHLIGHT_HALO && m_selection_mesh) { // Draw selection mesh video::SMaterial oldmaterial = driver->getMaterial2D(); driver->setMaterial(m_selection_material); setMeshColor(m_selection_mesh, m_selection_mesh_color); video::SColor face_color(0, MYMIN(255, m_selection_mesh_color.getRed() * 1.5), MYMIN(255, m_selection_mesh_color.getGreen() * 1.5), MYMIN(255, m_selection_mesh_color.getBlue() * 1.5)); setMeshColorByNormal(m_selection_mesh, m_selected_face_normal, face_color); scene::IMesh* mesh = cloneMesh(m_selection_mesh); translateMesh(mesh, m_selection_pos_with_offset); u32 mc = m_selection_mesh->getMeshBufferCount(); for (u32 i = 0; i < mc; i++) { scene::IMeshBuffer *buf = mesh->getMeshBuffer(i); driver->drawMeshBuffer(buf); } mesh->drop(); driver->setMaterial(oldmaterial); } } void Hud::updateSelectionMesh(const v3s16 &camera_offset) { m_camera_offset = camera_offset; if (m_mode != HIGHLIGHT_HALO) return; if (m_selection_mesh) { m_selection_mesh->drop(); m_selection_mesh = NULL; } if (m_selection_boxes.empty()) { // No pointed object return; } // New pointed object, create new mesh. // Texture UV coordinates for selection boxes static f32 texture_uv[24] = { 0,0,1,1, 0,0,1,1, 0,0,1,1, 0,0,1,1, 0,0,1,1, 0,0,1,1 }; // Use single halo box instead of multiple overlapping boxes. // Temporary solution - problem can be solved with multiple // rendering targets, or some method to remove inner surfaces. // Thats because of halo transparency. aabb3f halo_box(100.0, 100.0, 100.0, -100.0, -100.0, -100.0); m_halo_boxes.clear(); for (const auto &selection_box : m_selection_boxes) { halo_box.addInternalBox(selection_box); } m_halo_boxes.push_back(halo_box); m_selection_mesh = convertNodeboxesToMesh( m_halo_boxes, texture_uv, 0.5); } void Hud::resizeHotbar() { const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize(); if (m_screensize != window_size) { m_hotbar_imagesize = floor(HOTBAR_IMAGE_SIZE * RenderingEngine::getDisplayDensity() + 0.5); m_hotbar_imagesize *= m_hud_scaling; m_padding = m_hotbar_imagesize / 12; m_screensize = window_size; m_displaycenter = v2s32(m_screensize.X/2,m_screensize.Y/2); } } struct MeshTimeInfo { u64 time; scene::IMesh *mesh; }; void drawItemStack(video::IVideoDriver *driver, gui::IGUIFont *font, const ItemStack &item, const core::rect<s32> &rect, const core::rect<s32> *clip, Client *client, ItemRotationKind rotation_kind) { static MeshTimeInfo rotation_time_infos[IT_ROT_NONE]; static thread_local bool enable_animations = g_settings->getBool("inventory_items_animations"); if (item.empty()) { if (rotation_kind < IT_ROT_NONE) { rotation_time_infos[rotation_kind].mesh = NULL; } return; } const ItemDefinition &def = item.getDefinition(client->idef()); ItemMesh *imesh = client->idef()->getWieldMesh(def.name, client); if (imesh && imesh->mesh) { scene::IMesh *mesh = imesh->mesh; driver->clearZBuffer(); s32 delta = 0; if (rotation_kind < IT_ROT_NONE) { MeshTimeInfo &ti = rotation_time_infos[rotation_kind]; if (mesh != ti.mesh) { ti.mesh = mesh; ti.time = porting::getTimeMs(); } else { delta = porting::getDeltaMs(ti.time, porting::getTimeMs()) % 100000; } } core::rect<s32> oldViewPort = driver->getViewPort(); core::matrix4 oldProjMat = driver->getTransform(video::ETS_PROJECTION); core::matrix4 oldViewMat = driver->getTransform(video::ETS_VIEW); core::matrix4 ProjMatrix; ProjMatrix.buildProjectionMatrixOrthoLH(2, 2, -1, 100); driver->setTransform(video::ETS_PROJECTION, ProjMatrix); driver->setTransform(video::ETS_VIEW, ProjMatrix); core::matrix4 matrix; matrix.makeIdentity(); if (enable_animations) { float timer_f = (float) delta / 5000.0; matrix.setRotationDegrees(core::vector3df(0, 360 * timer_f, 0)); } driver->setTransform(video::ETS_WORLD, matrix); driver->setViewPort(rect); video::SColor basecolor = client->idef()->getItemstackColor(item, client); u32 mc = mesh->getMeshBufferCount(); for (u32 j = 0; j < mc; ++j) { scene::IMeshBuffer *buf = mesh->getMeshBuffer(j); // we can modify vertices relatively fast, // because these meshes are not buffered. assert(buf->getHardwareMappingHint_Vertex() == scene::EHM_NEVER); video::SColor c = basecolor; if (imesh->buffer_colors.size() > j) { ItemPartColor *p = &imesh->buffer_colors[j]; if (p->override_base) c = p->color; } if (imesh->needs_shading) colorizeMeshBuffer(buf, &c); else setMeshBufferColor(buf, c); video::SMaterial &material = buf->getMaterial(); material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; material.Lighting = false; driver->setMaterial(material); driver->drawMeshBuffer(buf); } driver->setTransform(video::ETS_VIEW, oldViewMat); driver->setTransform(video::ETS_PROJECTION, oldProjMat); driver->setViewPort(oldViewPort); } if(def.type == ITEM_TOOL && item.wear != 0) { // Draw a progressbar float barheight = rect.getHeight()/16; float barpad_x = rect.getWidth()/16; float barpad_y = rect.getHeight()/16; core::rect<s32> progressrect( rect.UpperLeftCorner.X + barpad_x, rect.LowerRightCorner.Y - barpad_y - barheight, rect.LowerRightCorner.X - barpad_x, rect.LowerRightCorner.Y - barpad_y); // Shrink progressrect by amount of tool damage float wear = item.wear / 65535.0; int progressmid = wear * progressrect.UpperLeftCorner.X + (1-wear) * progressrect.LowerRightCorner.X; // Compute progressbar color // wear = 0.0: green // wear = 0.5: yellow // wear = 1.0: red video::SColor color(255,255,255,255); int wear_i = MYMIN(floor(wear * 600), 511); wear_i = MYMIN(wear_i + 10, 511); if(wear_i <= 255) color.set(255, wear_i, 255, 0); else color.set(255, 255, 511-wear_i, 0); core::rect<s32> progressrect2 = progressrect; progressrect2.LowerRightCorner.X = progressmid; driver->draw2DRectangle(color, progressrect2, clip); color = video::SColor(255,0,0,0); progressrect2 = progressrect; progressrect2.UpperLeftCorner.X = progressmid; driver->draw2DRectangle(color, progressrect2, clip); } if(font != NULL && item.count >= 2) { // Get the item count as a string std::string text = itos(item.count); v2u32 dim = font->getDimension(utf8_to_wide(text).c_str()); v2s32 sdim(dim.X,dim.Y); core::rect<s32> rect2( /*rect.UpperLeftCorner, core::dimension2d<u32>(rect.getWidth(), 15)*/ rect.LowerRightCorner - sdim, sdim ); video::SColor bgcolor(128,0,0,0); driver->draw2DRectangle(bgcolor, rect2, clip); video::SColor color(255,255,255,255); font->draw(text.c_str(), rect2, color, false, false, clip); } }