Skip to content

Commit c4a7f74

Browse files
authored
Merge pull request #5 from kolyaka32/Dev-branch
Preloaded systems rework
2 parents 40dfaab + 56b874c commit c4a7f74

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+451
-501
lines changed

src/GUI/baseGUI.hpp

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,20 @@ namespace GUI {
1919

2020

2121
// Graphic user interface template for other objects
22-
class GUItemplate {
22+
class Template {
2323
protected:
2424
SDL_Texture* texture;
2525
SDL_FRect rect;
26+
2627
public:
27-
GUItemplate();
28+
Template();
2829
virtual void blit() const;
2930
bool in(const Mouse mouse) const;
3031
};
3132

3233

3334
// Static text on screen
34-
class StaticText : public GUItemplate {
35+
class StaticText : public Template {
3536
public:
3637
StaticText(float X, float Y, const LanguagedText texts,
3738
float size, Color color = WHITE, Aligment aligment = Aligment::Midle);
@@ -40,22 +41,22 @@ namespace GUI {
4041

4142

4243
// Static text on screen
43-
class HighlightedStaticText : public GUItemplate {
44+
class HighlightedStaticText : public Template {
4445
public:
45-
HighlightedStaticText(float X, float Y, const LanguagedText texts,
46+
HighlightedStaticText(float X, float Y, const LanguagedText texts,
4647
int frameThickness, float size, Color color = WHITE, Aligment aligment = Aligment::Midle);
4748
~HighlightedStaticText();
4849
};
4950

5051

5152
// Dynamicly updated text on screen
52-
class DynamicText : public GUItemplate {
53+
class DynamicText : public Template {
5354
private:
54-
const LanguagedText texts; // Text to create from
55-
const float posX; // Relative positions on screen
56-
const Aligment aligment; // Aligment type to improve displasment
57-
const Color color; // Base draw color
58-
const float height; // Height of text to draw
55+
const LanguagedText texts; // Text to create from
56+
const float posX; // Relative positions on screen
57+
const Aligment aligment; // Aligment type to improve displasment
58+
const Color color; // Base draw color
59+
const float height; // Height of text to draw
5960

6061
public:
6162
DynamicText(float X, float Y, const LanguagedText texts,
@@ -65,10 +66,10 @@ namespace GUI {
6566
void setValues(Args&& ...args) {
6667
// Checking for all chars
6768
char buffer[100];
68-
std::sprintf(buffer, texts.getString().c_str(), std::forward<Args>(args)...);
69+
std::snprintf(buffer, sizeof(buffer), texts.getString().c_str(), args...);
6970

7071
// Creating surface with text
71-
texture = window.createTexture(FNT_MAIN, height, buffer, 0, color);
72+
texture = window.createTexture(Fonts::Main, height, buffer, 0, color);
7273

7374
// Moving draw rect to new place
7475
rect.w = texture->w;
@@ -79,35 +80,34 @@ namespace GUI {
7980

8081

8182
// Class of slider bar with point on it to control need parameter
82-
class Slider : public GUItemplate {
83+
class Slider : public Template {
8384
private:
8485
SDL_Texture *textureButton; // Texture of line (upper part of slider)
8586
SDL_FRect buttonRect; // Place for rendering upper part
8687
const unsigned maxValue; // Maximal value of state
8788

8889
public:
8990
// Create slide with need line and button images
90-
Slider(float X, float Y, float width, unsigned startValue, IMG_names lineImage = IMG_GUI_SLIDER_LINE,
91-
IMG_names buttonImage = IMG_GUI_SLIDER_BUTTON, unsigned max = 255);
91+
Slider(float X, float Y, float width, unsigned startValue, Textures lineImage = Textures::SliderLine,
92+
Textures buttonImage = Textures::SliderButton, unsigned max = 255);
9293
unsigned setValue(float mouseX); // Setting new state from mouse position
9394
unsigned scroll(float wheelY); // Checking mouse wheel action
9495
void blit() const override; // Drawing slider with need button position
9596
};
9697

9798

9899
// Class of buttons with image on it
99-
class ImageButton : public GUItemplate {
100-
public:
101-
ImageButton(float X, float Y, float width, IMG_names textureIndex);
100+
class ImageButton : public Template {
101+
public:
102+
ImageButton(float X, float Y, float width, Textures name);
102103
};
103104

104105

105106
// GIF-animations
106107
#if ANI_count
107-
class GIFAnimation : public GUItemplate {
108+
class GIFAnimation : public Template {
108109
private:
109110
const Uint8 type;
110-
SDL_Texture* texture = nullptr;
111111
Uint64 prevTick;
112112
const SDL_FRect dest;
113113

@@ -167,7 +167,7 @@ namespace GUI {
167167
};
168168

169169
// Class of backplate for
170-
class Backplate : public GUItemplate {
170+
class Backplate : public Template {
171171
public:
172172
Backplate(float centerX, float centerY, float width, float height, float radius, float border,
173173
Color frontColor = GREY, Color backColor = BLACK);
@@ -176,6 +176,7 @@ namespace GUI {
176176
~Backplate();
177177
};
178178

179+
179180
// Class of buttons with text on it
180181
class TextButton : public HighlightedStaticText {
181182
private:
@@ -187,6 +188,7 @@ namespace GUI {
187188
void blit() const override;
188189
};
189190

191+
190192
// Class of appearing for time and hidden by time text
191193
class InfoBox : public HighlightedStaticText {
192194
private:

src/GUI/dynamicText.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ texts(_texts),
1616
height(_height) {
1717
rect.y = window.getHeight() * _Y - height / 2;
1818
// Creating surface with text
19-
texture = window.createTexture(FNT_MAIN, height, texts.getString().c_str(), 0, color);
19+
texture = window.createTexture(Fonts::Main, height, texts.getString().c_str(), 0, color);
2020

2121
// Moving draw rect to new place
2222
rect.w = texture->w;

src/GUI/highlightedStaticText.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
GUI::HighlightedStaticText::HighlightedStaticText(float _X, float _Y,
1010
const LanguagedText _texts, int frame, float _height, Color _color, Aligment _aligment) {
1111
// Creating texture of text
12-
TTF_Font* font = window.getFont(FNT_MAIN);
12+
TTF_Font* font = window.getFont(Fonts::Main);
1313
TTF_SetFontSize(font, _height);
1414
TTF_SetFontOutline(font, frame);
1515

src/GUI/imageButton.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
#include "baseGUI.hpp"
77

88

9-
GUI::ImageButton::ImageButton(float _X, float _Y, float _width, IMG_names _index) {
9+
GUI::ImageButton::ImageButton(float _X, float _Y, float _width, Textures _index) {
1010
// Setting base texture
1111
texture = window.getTexture(_index);
1212

1313
// Setting destination
1414
SDL_GetTextureSize(texture, &rect.w, &rect.h);
1515
rect.w = _width * window.getWidth();
1616
rect.h = texture->h * rect.w / texture->w;
17-
17+
1818
rect.x = window.getWidth() * _X - rect.w / 2;
1919
rect.y = window.getHeight() * _Y - rect.h / 2;
2020
}

src/GUI/slider.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
// Slider class
1010
GUI::Slider::Slider(float _X, float _Y, float _width, unsigned _startValue,
11-
IMG_names _lineImage, IMG_names _buttonImage, unsigned _max)
11+
Textures _lineImage, Textures _buttonImage, unsigned _max)
1212
: maxValue(_max) {
1313
// Getting need texture
1414
texture = window.getTexture(_lineImage);
@@ -22,7 +22,7 @@ GUI::Slider::Slider(float _X, float _Y, float _width, unsigned _startValue,
2222
rect.x = window.getWidth() * _X - rect.w / 2;
2323
rect.y = window.getHeight() * _Y - rect.h / 2;
2424
buttonRect.y = window.getHeight() * _Y - buttonRect.h / 2;
25-
buttonRect.x = rect.x + _startValue - buttonRect.w / 2;
25+
buttonRect.x = rect.x + rect.w * _startValue / maxValue - buttonRect.w / 2;
2626
}
2727

2828
void GUI::Slider::blit() const {

src/GUI/staticText.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
GUI::StaticText::StaticText(float _X, float _Y, const LanguagedText _texts,
1111
float _height, Color _color, Aligment _aligment) {
1212
// Creating texture of text
13-
texture = window.createTexture(FNT_MAIN, _height, _texts.getString().c_str(), 0, _color);
13+
texture = window.createTexture(Fonts::Main, _height, _texts.getString().c_str(), 0, _color);
1414

1515
// Updating rect height for correct button
1616
SDL_GetTextureSize(texture, &rect.w, &rect.h);

src/GUI/template.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77

88

99
// Tempate function for resetting texture
10-
GUI::GUItemplate::GUItemplate() {
10+
GUI::Template::Template() {
1111
texture = nullptr;
1212
}
1313

1414
// Template function for draw
15-
void GUI::GUItemplate::blit() const {
15+
void GUI::Template::blit() const {
1616
window.blit(texture, rect);
1717
}
1818

1919
// Template function for check, if mouse press in object
20-
bool GUI::GUItemplate::in(const Mouse mouse) const {
20+
bool GUI::Template::in(const Mouse mouse) const {
2121
return mouse.in(rect);
2222
}

src/GUI/typeField.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ GUI::TypeField<bufferSize>::TypeField(float _X, float _Y, float _height, const c
1414
: posX(window.getWidth()*_X),
1515
aligment(_aligment),
1616
textColor(_color),
17-
font(window.createFontCopy(FNT_MAIN, _height)),
18-
backRect({_X*window.getWidth()-(6.5f*bufferSize+2), _Y*window.getHeight()-_height*0.9f, 13.0f*bufferSize+4, _height*1.8f}) {
17+
font(window.createFontCopy(Fonts::Main, _height)),
18+
backRect({_X*window.getWidth() - (6.5f*bufferSize+2), _Y*window.getHeight()-_height * 0.9f,
19+
13.0f * bufferSize+4, _height * 1.8f}) {
1920
// Setting rects
2021
textRect = {0, window.getHeight()*_Y-_height/2-1, 0, 0};
2122
caretRect = {0, window.getHeight()*_Y-_height/2-1, 2, _height*1.3f};
@@ -99,7 +100,7 @@ void GUI::TypeField<bufferSize>::updateTexture() {
99100
textRect.w = textTexture->w;
100101
textRect.h = textTexture->h;
101102
textRect.x = SDL_floorf(posX - textRect.w * (unsigned)aligment / 2);
102-
103+
103104
// Update caret place
104105
if (caret) {
105106
int caretX = 0;

src/cycles/baseCycle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
// Base cycle class
1010
BaseCycle::BaseCycle()
11-
: exitButton(0.04, 0.05, 0.08, IMG_GUI_QUIT_BUTTON),
11+
: exitButton(0.04, 0.05, 0.08, Textures::QuitButton),
1212
settings() {}
1313

1414
bool BaseCycle::inputMouseDown() {

src/cycles/clientGame.cpp

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "selectCycle.hpp"
88

99

10-
ClientGameCycle::ClientGameCycle(Connection& _client)
10+
ClientGameCycle::ClientGameCycle(const Connection& _client)
1111
: InternetCycle(),
1212
connection(_client),
1313
waitText(0.5, 0.05, {"Wait start", "Ожидайте начала", "Warte auf Start", "Чаканне старту"}, 24) {}
@@ -29,16 +29,11 @@ bool ClientGameCycle::inputMouseDown() {
2929
if (field.tryClickMultiplayerCurrent(mouse)) {
3030
// Making sound
3131
sounds.play(Sounds::Turn);
32+
music.startFromCurrent(Music::MainCombat);
33+
3234
// Sending to opponent
33-
connection.sendConfirmed<Uint8, Uint8>(ConnectionCode::GameTurn, field.getXPos(mouse), field.getYPos(mouse));
34-
// Changing music theme
35-
if (firstTurn) {
36-
music.startFromCurrent(Music::MainCombat);
37-
firstTurn = false;
38-
#if CHECK_ALL
39-
SDL_Log("Start combat music");
40-
#endif
41-
}
35+
connection.sendConfirmed<Uint8, Uint8>(ConnectionCode::GameTurn,
36+
field.getXPos(mouse), field.getYPos(mouse));
4237
}
4338
}
4439
return false;
@@ -59,37 +54,28 @@ void ClientGameCycle::update() {
5954
case ConnectionCode::GameTurn:
6055
if (connection.lastPacket->isBytesAvaliable(4)) {
6156
#if CHECK_CORRECTION
62-
SDL_Log("Turn of opponent player: from %u to %u", connection.lastPacket->getData<Uint8>(2), connection.lastPacket->getData<Uint8>(3));
57+
SDL_Log("Turn of opponent player: from %u to %u",
58+
connection.lastPacket->getData<Uint8>(2), connection.lastPacket->getData<Uint8>(3));
6359
#endif
64-
field.clickMultiplayerOpponent(connection.lastPacket->getData<Uint8>(2), connection.lastPacket->getData<Uint8>(3));
60+
field.clickMultiplayerOpponent(connection.lastPacket->getData<Uint8>(2),
61+
connection.lastPacket->getData<Uint8>(3));
6562
// Making sound
6663
sounds.play(Sounds::Turn);
6764
// Changing music theme
68-
if (firstTurn) {
69-
music.startFromCurrent(Music::MainCombat);
70-
firstTurn = false;
71-
#if CHECK_ALL
72-
SDL_Log("Start combat music");
73-
#endif
74-
}
65+
music.startFromCurrent(Music::MainCombat);
7566
}
7667
return;
7768

7869
case ConnectionCode::GameClear:
70+
// Making sound
71+
sounds.play(Sounds::Reset);
72+
music.startFromCurrent(Music::MainCalm);
73+
7974
// Resetting game
75+
field.reset();
8076
#if CHECK_CORRECTION
8177
SDL_Log("Resetting game by connection");
8278
#endif
83-
field.reset();
84-
if (!firstTurn) {
85-
music.startFromCurrent(Music::MainCalm);
86-
#if CHECK_ALL
87-
SDL_Log("Stop combat music");
88-
#endif
89-
}
90-
firstTurn = true;
91-
// Making sound
92-
sounds.play(Sounds::Reset);
9379
return;
9480

9581
case ConnectionCode::GameStart:

0 commit comments

Comments
 (0)