Page 1 of 1

allow utility-sprites in add_custom_alert

Posted: Tue Aug 25, 2020 5:07 pm
by Optera
What?
Extend add_custom_alert to allow utility sprites
Why?
To use for example warning-icon.png with add_custom_alert mods have to create a virtual signal for something that's already defined as utility-sprite.
It feels weird how we can use

Code: Select all

[img=utility/warning_icon]
in normal rich text but not as icon for custom alerts.

Re: allow utility-sprites in add_custom_alert

Posted: Tue Aug 25, 2020 8:25 pm
by Rseding91
Custom alerts were created for the programmable speaker and use in conjunction with the circuit network (which also uses SignalID). As a result the custom alert class doesn't store images. It stores SignalIDs, so this simply isn't possible.

Code: Select all

class CustomAlert : public Alert
{
  using super = Alert;
public:
  CustomAlert() = default;
  CustomAlert(Entity* entity, MapPosition position, uint32_t tick, SignalID icon, const LocalisedString& message, bool showOnMap);
  CustomAlert(const CustomAlert&) = delete;
  CustomAlert(CustomAlert&& other) noexcept;
  void load(MapDeserialiser& input);
  void save(MapSerialiser& output) const;
  CustomAlert& operator=(const CustomAlert&) = delete;
  CustomAlert& operator=(CustomAlert&& other) noexcept;

  const Sprite* getIcon() const;

  SignalID signalID; // used to determine the icon showed
  LocalisedString message;
  bool showOnMap = true;
};
The class would have to be altered to store additionally the string sprite name as defined by Lua, save/load logic added for it, and the surrounding code altered. That all seems well outside of what I want to do.