aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.hpp
blob: 294b842982b278ad97a18977e76106266c528605 (plain) (blame)
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
#pragma once

#include <godot_cpp/classes/image_texture.hpp>

#include <openvic-simulation/country/Country.hpp>
#include <openvic-simulation/interface/GFX.hpp>

#include "openvic-extension/classes/GFXButtonStateTexture.hpp"

namespace OpenVic {
   class GFXMaskedFlagTexture : public godot::ImageTexture {
      GDCLASS(GFXMaskedFlagTexture, godot::ImageTexture)

      GFX::MaskedFlag const* PROPERTY(gfx_masked_flag);
      Country const* PROPERTY(flag_country);
      godot::StringName PROPERTY(flag_type);

      godot::Ref<godot::Image> overlay_image, mask_image, flag_image, combined_image;

      static godot::StringName const& _signal_image_updated();

      godot::Error _generate_combined_image();

   protected:
      static void _bind_methods();

   public:
      GFXMaskedFlagTexture();

      /* Create a GFXMaskedFlagTexture using the specified GFX::MaskedFlag. Returns nullptr if gfx_masked_flag fails.
       * Connects the provided GFXButtonStateTextures (if any) to the GFXMaskedFlagTexture's image_updated signal. */
      static godot::Ref<GFXMaskedFlagTexture> make_gfx_masked_flag_texture(
         GFX::MaskedFlag const* gfx_masked_flag,
         std::vector<godot::Ref<GFXButtonStateTexture>> const& button_state_textures = {}
      );

      /* Reset gfx_masked_flag, flag_country and flag_type to nullptr/an empty string, and unreference all images.
       * This does not affect the godot::ImageTexture, which cannot be reset to a null or empty image. */
      void clear();

      /* Set the GFX::MaskedFlag, load its overlay and mask textures, and regenerate the combined image. */
      godot::Error set_gfx_masked_flag(GFX::MaskedFlag const* new_gfx_masked_flag);

      /* Search for a GFX::MaskedFlag with the specfied name and, if successful, set it using set_gfx_masked_flag. */
      godot::Error set_gfx_masked_flag_name(godot::String const& gfx_masked_flag_name);

      /* Return the name of the GFX::MaskedFlag, or an empty String if it's null. */
      godot::String get_gfx_masked_flag_name() const;

      /* Set flag_country and flag_type and update the combined image to use that flag, or no flag if it doesn't exist. */
      godot::Error set_flag_country_and_type(Country const* new_flag_country, godot::StringName const& new_flag_type);

      /* Look up the country with the specified identifier, then call set_flag_country_and_type with the country and
       * specified flag_type as arguments. */
      godot::Error set_flag_country_name_and_type(
         godot::String const& new_flag_country_name, godot::StringName const& new_flag_type
      );

      /* Look up the specified country's current flag type, then call set_flag_country_and_type
       * with the country and its flag type as arguments. */
      godot::Error set_flag_country(Country const* new_flag_country);

      /* Look up the country with the specified identifier, then call set_flag_country with the country its argument. */
      godot::Error set_flag_country_name(godot::String const& new_flag_country_name);

      /* Return the name of the selected flag's country, or an empty String if it's null. */
      godot::String get_flag_country_name() const;
   };
}