This repository has been archived by the owner on Mar 24, 2022. It is now read-only.
forked from safePerformIO/MCLite-archive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Osd.hpp
105 lines (91 loc) · 2.95 KB
/
Osd.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* @file Osd.hpp
* @author H14
* @brief OSD (On Screen Display) shows the status of the player and the game, containing HPbar, weapon, player current holding item, and current game FPS
* @version 0.1
* @date 2021-11-30
*
* @copyright Copyright (c) 2021
*
*/
#pragma once
#include <QPainter>
#include <QGraphicsItem>
#include <QFont>
#include "./Block/Block.hpp"
struct Channel;
class Osd : public QGraphicsItem
{
public:
/**
* @brief Construct a new Osd object
*
* @param channel pass the channel to osd
*/
Osd(Channel *channel);
/**
* @brief Destroy the Osd object, using default destructor
*
*/
~Osd();
/**
* @brief this function overrides pure virtual function in QGraphicsItem
*
* @return QRectF
*/
QRectF boundingRect() const;
/**
* @brief this function is automatically called when the game refreshes, which will draw the OSD on the top and the bottom of the screen
*
* @param painter // this is the painter to draw image on screen
* @param option // automatically generated by Qt, unused
* @param widget // automatically generated by Qt, unused
*/
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
/**
* @brief Get the bounding area of weapons, used to check whether the player is clicking on the weapon icon
*
* @param weapon
* @return QRectF
*/
QRectF getWeaponRect(const HarvestLevel &weapon) const;
private:
Channel *channel; // the channel
/**
* @brief variables used to show the hp bar
*
*/
int hp = 100, // current hp value
last_hp = 100, // used to check whether hp is changed
pre_hp = 100; // used to paint the hp reduction effect
int hurt_process = 0; // used to paint the hp reduction effect
/**
* @brief image resources of weapons and HUDs, and also coordinates of them
*
*/
const QImage Weapon_pickaxe, Weapon_shovel, Weapon_sword, weapon_HUD, item_HUD; // the weapon images
QRectF Weapon_pickaxe_i, Weapon_pickaxe_b; // the weapon coordinates
QRectF Weapon_shovel_i, Weapon_shovel_b;
QRectF Weapon_sword_i, Weapon_sword_b;
QRectF Weapon_1, Weapon_2, Weapon_3;
QRectF Weapon_1_b, Weapon_2_b, Weapon_3_b;
QRectF hpBar; // the hpBar coordinates
/**
* @brief variables for FPS counting
*
*/
QFont FPSf; // the font to print FPS
int FPS, // the current FPS result
sF, // the current sum of frame
sT; // the current sum of time elapsed, used to count fram pre second
/**
* @brief this function is called once per frame by the 'paint' function, and it will update the status of the OSD
*
*/
void update();
/**
* @brief this function will count and return the current FPS, which is helpful for VFR (Variable Frame Rate)
*
*/
void getFPS();
};