Translated using Weblate (Chinese (Simplified))
[oweals/minetest.git] / src / client / hud.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4 Copyright (C) 2017 red-001 <red-001@outlook.ie>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21 #pragma once
22
23 #include <vector>
24 #include <IGUIFont.h>
25 #include "irr_aabb3d.h"
26 #include "../hud.h"
27
28 class Client;
29 class ITextureSource;
30 class Inventory;
31 class InventoryList;
32 class LocalPlayer;
33 struct ItemStack;
34
35 class Hud
36 {
37 public:
38         video::IVideoDriver *driver;
39         scene::ISceneManager *smgr;
40         gui::IGUIEnvironment *guienv;
41         Client *client;
42         LocalPlayer *player;
43         Inventory *inventory;
44         ITextureSource *tsrc;
45
46         video::SColor crosshair_argb;
47         video::SColor selectionbox_argb;
48         bool use_crosshair_image = false;
49         std::string hotbar_image = "";
50         bool use_hotbar_image = false;
51         std::string hotbar_selected_image = "";
52         bool use_hotbar_selected_image = false;
53
54         Hud(gui::IGUIEnvironment *guienv, Client *client, LocalPlayer *player,
55                         Inventory *inventory);
56         ~Hud();
57
58         void drawHotbar(u16 playeritem);
59         void resizeHotbar();
60         void drawCrosshair();
61         void drawSelectionMesh();
62         void updateSelectionMesh(const v3s16 &camera_offset);
63
64         std::vector<aabb3f> *getSelectionBoxes() { return &m_selection_boxes; }
65
66         void setSelectionPos(const v3f &pos, const v3s16 &camera_offset);
67
68         v3f getSelectionPos() const { return m_selection_pos; }
69
70         void setSelectionMeshColor(const video::SColor &color)
71         {
72                 m_selection_mesh_color = color;
73         }
74
75         void setSelectedFaceNormal(const v3f &face_normal)
76         {
77                 m_selected_face_normal = face_normal;
78         }
79
80         void drawLuaElements(const v3s16 &camera_offset);
81
82 private:
83         bool calculateScreenPos(const v3s16 &camera_offset, HudElement *e, v2s32 *pos);
84         void drawStatbar(v2s32 pos, u16 corner, u16 drawdir,
85                         const std::string &texture, const std::string& bgtexture,
86                         s32 count, s32 maxcount, v2s32 offset, v2s32 size = v2s32());
87
88         void drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount,
89                         s32 inv_offset, InventoryList *mainlist, u16 selectitem,
90                         u16 direction);
91
92         void drawItem(const ItemStack &item, const core::rect<s32> &rect, bool selected);
93
94         float m_hud_scaling; // cached minetest setting
95         float m_scale_factor;
96         v3s16 m_camera_offset;
97         v2u32 m_screensize;
98         v2s32 m_displaycenter;
99         s32 m_hotbar_imagesize; // Takes hud_scaling into account, updated by resizeHotbar()
100         s32 m_padding; // Takes hud_scaling into account, updated by resizeHotbar()
101         video::SColor hbar_colors[4];
102
103         std::vector<aabb3f> m_selection_boxes;
104         std::vector<aabb3f> m_halo_boxes;
105         v3f m_selection_pos;
106         v3f m_selection_pos_with_offset;
107
108         scene::IMesh *m_selection_mesh = nullptr;
109         video::SColor m_selection_mesh_color;
110         v3f m_selected_face_normal;
111
112         video::SMaterial m_selection_material;
113
114         enum
115         {
116                 HIGHLIGHT_BOX,
117                 HIGHLIGHT_HALO,
118                 HIGHLIGHT_NONE
119         } m_mode;
120 };
121
122 enum ItemRotationKind
123 {
124         IT_ROT_SELECTED,
125         IT_ROT_HOVERED,
126         IT_ROT_DRAGGED,
127         IT_ROT_OTHER,
128         IT_ROT_NONE, // Must be last, also serves as number
129 };
130
131 void drawItemStack(video::IVideoDriver *driver,
132                 gui::IGUIFont *font,
133                 const ItemStack &item,
134                 const core::rect<s32> &rect,
135                 const core::rect<s32> *clip,
136                 Client *client,
137                 ItemRotationKind rotation_kind);
138
139 void drawItemStack(
140                 video::IVideoDriver *driver,
141                 gui::IGUIFont *font,
142                 const ItemStack &item,
143                 const core::rect<s32> &rect,
144                 const core::rect<s32> *clip,
145                 Client *client,
146                 ItemRotationKind rotation_kind,
147                 const v3s16 &angle,
148                 const v3s16 &rotation_speed);
149