1 /*
2  * This file is part of EasyRPG Player.
3  *
4  * EasyRPG Player is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * EasyRPG Player is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef EP_GAME_PICTURE_H
19 #define EP_GAME_PICTURE_H
20 
21 // Headers
22 #include <string>
23 #include <deque>
24 #include "async_handler.h"
25 #include <lcf/rpg/savepicture.h>
26 #include "sprite_picture.h"
27 
28 class Sprite_Picture;
29 class Scene;
30 
31 /**
32  * Pictures class.
33  */
34 class Game_Pictures {
35 public:
36 	Game_Pictures() = default;
37 
38 	void SetSaveData(std::vector<lcf::rpg::SavePicture> save);
39 	std::vector<lcf::rpg::SavePicture> GetSaveData() const;
40 
41 	void InitGraphics();
42 
43 	static int GetDefaultNumberOfPictures();
44 
45 	struct Params {
46 		int position_x = 0;
47 		int position_y = 0;
48 		int magnify = 100;
49 		int top_trans = 0;
50 		int bottom_trans = 0;
51 		int red = 100;
52 		int green = 100;
53 		int blue = 100;
54 		int saturation = 100;
55 		int effect_mode = 0;
56 		int effect_power = 0;
57 		// Extensions
58 		bool flip_x = false;
59 		bool flip_y = false;
60 		int blend_mode = 0;
61 	};
62 	struct ShowParams : Params {
63 		std::string name;
64 		// RPG Maker 2k3 1.12
65 		int spritesheet_cols = 1;
66 		int spritesheet_rows = 1;
67 		int spritesheet_frame = 0;
68 		int spritesheet_speed = 0;
69 		int map_layer = 7;
70 		int battle_layer = 0;
71 		// erase_on_map_change | affected_by_flash | affected_by_shake
72 		int flags = 1 | 32 | 64;
73 		bool spritesheet_play_once = false;
74 		bool use_transparent_color = false;
75 		bool fixed_to_map = false;
76 	};
77 
78 	struct MoveParams : Params {
79 		int duration = 0;
80 	};
81 
82 	void Show(int id, const ShowParams& params);
83 	void Move(int id, const MoveParams& params);
84 	void Erase(int id);
85 	void EraseAll();
86 
87 	void Update(bool is_battle);
88 
89 	void OnMapChange();
90 	void OnBattleEnd();
91 	void OnMapScrolled(int dx, int dy);
92 
93 	struct Picture {
PicturePicture94 		Picture(int id) { data.ID = id; }
95 		Picture(lcf::rpg::SavePicture data);
96 
97 		Sprite_Picture* sprite = nullptr;
98 		lcf::rpg::SavePicture data;
99 		FileRequestBinding request_id;
100 		bool needs_update = false;
101 
102 		void Update(bool is_battle);
103 
104 		bool IsOnMap() const;
105 		bool IsOnBattle() const;
106 		int NumSpriteSheetFrames() const;
107 
108 		ShowParams GetShowParams() const;
109 		void SetNonEffectParams(const Params& params, bool set_positions);
110 
111 		bool Show(const ShowParams& params);
112 		void Move(const MoveParams& params);
113 		void Erase();
114 		bool Exists() const;
115 
116 		void OnPictureSpriteReady();
117 		void OnMapScrolled(int dx, int dy);
118 	};
119 
120 	Picture& GetPicture(int id);
121 	Picture* GetPicturePtr(int id);
122 
123 private:
124 	void RequestPictureSprite(Picture& pic);
125 	void OnPictureSpriteReady(int id);
126 
127 	std::vector<Picture> pictures;
128 	std::deque<Sprite_Picture> sprites;
129 	int frame_counter = 0;
130 };
131 
IsOnMap()132 inline bool Game_Pictures::Picture::IsOnMap() const {
133 	return data.map_layer > 0;
134 }
135 
IsOnBattle()136 inline bool Game_Pictures::Picture::IsOnBattle() const {
137 	return data.battle_layer > 0;
138 }
139 
140 #endif
141