Freeciv21
Develop your civilization from humble roots to a global empire
featured_text.h File Reference
#include <QString>
#include "speclist.h"
+ Include dependency graph for featured_text.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ft_color
 

Macros

#define FT_OFFSET_UNSET   ((ft_offset_t) -1)
 
#define SPECLIST_TAG   text_tag
 
#define SPECLIST_TYPE   struct text_tag
 
#define text_tag_list_iterate(tags, ptag)    TYPED_LIST_ITERATE(struct text_tag, tags, ptag)
 
#define text_tag_list_iterate_end   LIST_ITERATE_END
 
#define MAX_LEN_LINK   128
 
#define FT_COLOR(fg, bg)
 
#define text_tag_list_new()   text_tag_list_new_full(text_tag_destroy)
 
#define text_tag_list_copy(tags)    text_tag_list_copy_full(tags, text_tag_copy, text_tag_destroy)
 

Typedefs

typedef int ft_offset_t
 

Enumerations

enum  text_tag_type {
  TTT_BOLD = 0 , TTT_ITALIC , TTT_STRIKE , TTT_UNDERLINE ,
  TTT_COLOR , TTT_LINK , TTT_INVALID
}
 
enum  text_link_type { TLT_CITY , TLT_TILE , TLT_UNIT , TLT_INVALID }
 

Functions

static struct ft_color ft_color_construct (const char *foreground, const char *background)
 
static bool ft_color_requested (const struct ft_color color)
 
size_t featured_text_to_plain_text (const char *featured_text, char *plain_text, size_t plain_text_len, struct text_tag_list **tags, bool replace_link_text)
 Separate the text from the text features. More...
 
size_t featured_text_apply_tag (const char *text_source, char *featured_text, size_t featured_text_len, enum text_tag_type tag_type, ft_offset_t start_offset, ft_offset_t stop_offset,...)
 Apply a tag to a text. More...
 
struct text_tagtext_tag_new (enum text_tag_type tag_type, ft_offset_t start_offset, ft_offset_t stop_offset,...)
 Returns a new text_tag or nullptr on error. More...
 
struct text_tagtext_tag_copy (const struct text_tag *ptag)
 This function returns a new pointer to a text_tag which is similar to the 'ptag' argument. More...
 
void text_tag_destroy (struct text_tag *ptag)
 Free a text_tag structure. More...
 
enum text_tag_type text_tag_type (const struct text_tag *ptag)
 Return the type of this text tag. More...
 
ft_offset_t text_tag_start_offset (const struct text_tag *ptag)
 Return the start offset (in bytes) of this text tag. More...
 
ft_offset_t text_tag_stop_offset (const struct text_tag *ptag)
 Return the stop offset (in bytes) of this text tag. More...
 
QString text_tag_color_foreground (const struct text_tag *ptag)
 Return the foreground color suggested by this text tag. More...
 
QString text_tag_color_background (const struct text_tag *ptag)
 Return the background color suggested by this text tag. More...
 
enum text_link_type text_tag_link_type (const struct text_tag *ptag)
 Return the link target type suggested by this text tag. More...
 
int text_tag_link_id (const struct text_tag *ptag)
 Return the link target id suggested by this text tag (city id, tile index or unit id). More...
 
const char * city_link (const struct city *pcity)
 Get a text link to a city. More...
 
const char * city_tile_link (const struct city *pcity)
 Get a text link to a city tile (make a clickable link to a tile with the city name as text). More...
 
const char * tile_link (const struct tile *ptile)
 Get a text link to a tile. More...
 
const char * unit_link (const struct unit *punit)
 Get a text link to an unit. More...
 
const char * unit_tile_link (const struct unit *punit)
 Get a text link to a unit tile (make a clickable link to a tile with the unit type name as text). More...
 
const char * unit_veteran_level_and_bonus (const struct unit *punit)
 
const char * unit_veteran_level_string (const struct unit *punit)
 Get a text of a unit's vet level. More...
 
const char * unit_achieved_rank_string (const struct unit *punit)
 Get string of when unit gets upgraded to new veteran level. More...
 
const char * unit_tired_attack_string (const struct unit *punit)
 Get string of unit's attack would be a tired attack or not. More...
 
const char * unit_firepower_if_not_one (int firepower)
 Get string of unit's firepower text, i.e. More...
 

Variables

const struct ft_color ftc_any
 
const struct ft_color ftc_warning
 
const struct ft_color ftc_log
 
const struct ft_color ftc_server
 
const struct ft_color ftc_client
 
const struct ft_color ftc_editor
 
const struct ft_color ftc_command
 
struct ft_color ftc_changed
 
const struct ft_color ftc_server_prompt
 
const struct ft_color ftc_player_lost
 
const struct ft_color ftc_game_start
 
const struct ft_color ftc_chat_public
 
const struct ft_color ftc_chat_ally
 
const struct ft_color ftc_chat_private
 
const struct ft_color ftc_chat_luaconsole
 
const struct ft_color ftc_vote_public
 
const struct ft_color ftc_vote_team
 
const struct ft_color ftc_vote_passed
 
const struct ft_color ftc_vote_failed
 
const struct ft_color ftc_vote_yes
 
const struct ft_color ftc_vote_no
 
const struct ft_color ftc_vote_abstain
 
const struct ft_color ftc_luaconsole_input
 
const struct ft_color ftc_luaconsole_error
 
const struct ft_color ftc_luaconsole_warn
 
const struct ft_color ftc_luaconsole_normal
 
const struct ft_color ftc_luaconsole_verbose
 

Macro Definition Documentation

◆ FT_COLOR

#define FT_COLOR (   fg,
  bg 
)
Value:
{ \
fg, bg \
}

Definition at line 138 of file featured_text.h.

◆ FT_OFFSET_UNSET

#define FT_OFFSET_UNSET   ((ft_offset_t) -1)

Definition at line 95 of file featured_text.h.

◆ MAX_LEN_LINK

#define MAX_LEN_LINK   128

Definition at line 131 of file featured_text.h.

◆ SPECLIST_TAG

#define SPECLIST_TAG   text_tag

Definition at line 101 of file featured_text.h.

◆ SPECLIST_TYPE

#define SPECLIST_TYPE   struct text_tag

Definition at line 102 of file featured_text.h.

◆ text_tag_list_copy

#define text_tag_list_copy (   tags)     text_tag_list_copy_full(tags, text_tag_copy, text_tag_destroy)

Definition at line 208 of file featured_text.h.

◆ text_tag_list_iterate

#define text_tag_list_iterate (   tags,
  ptag 
)     TYPED_LIST_ITERATE(struct text_tag, tags, ptag)

Definition at line 105 of file featured_text.h.

◆ text_tag_list_iterate_end

#define text_tag_list_iterate_end   LIST_ITERATE_END

Definition at line 107 of file featured_text.h.

◆ text_tag_list_new

#define text_tag_list_new ( )    text_tag_list_new_full(text_tag_destroy)

Definition at line 207 of file featured_text.h.

Typedef Documentation

◆ ft_offset_t

typedef int ft_offset_t

Definition at line 93 of file featured_text.h.

Enumeration Type Documentation

◆ text_link_type

Enumerator
TLT_CITY 
TLT_TILE 
TLT_UNIT 
TLT_INVALID 

Definition at line 123 of file featured_text.h.

◆ text_tag_type

Enumerator
TTT_BOLD 
TTT_ITALIC 
TTT_STRIKE 
TTT_UNDERLINE 
TTT_COLOR 
TTT_LINK 
TTT_INVALID 

Definition at line 111 of file featured_text.h.

Function Documentation

◆ city_link()

const char* city_link ( const struct city pcity)

Get a text link to a city.

N.B.: The returned string is static, so every call to this function overwrites the previous.

Definition at line 1055 of file featured_text.cpp.

Referenced by announce_trade_route_removal(), apply_disaster(), auto_arrange_workers(), build_free_small_wonders(), trade_generator::calculate(), change_build_target(), check_city_migrations_player(), check_pollution(), city_add_unit(), city_build_building(), city_build_unit(), city_distribute_surplus_shields(), city_empty_food_stock(), city_global_turn_notify(), city_handle_disorder(), city_illness_strike(), city_increase_size(), city_landlocked_sell_coastal_improvements(), city_populate(), city_turn_notify(), cityrep_buy(), civil_war(), create_city(), dai_city_sell_noncritical(), diplomat_embassy(), diplomat_escape(), diplomat_escape_full(), diplomat_get_tech(), diplomat_incite(), diplomat_infiltrate_tile(), diplomat_investigate(), diplomat_sabotage(), disband_city(), do_city_migration(), do_nuke_tile(), do_unit_change_homecity(), do_unit_conquer_city(), do_unit_establish_trade(), do_unit_strike_city_building(), do_unit_strike_city_production(), found_new_tech(), cma_yoloswag::handle_city(), handle_diplomacy_accept_treaty_req(), handle_edit_city(), chat_widget::make_link(), really_handle_city_sell(), remove_city(), remove_obsolete_buildings_city(), research_tech_lost(), sell_random_building(), map_view::shortcut_pressed(), spy_nuke_city(), spy_poison(), spy_spread_plague(), spy_steal_gold(), spy_steal_some_maps(), teleport_unit_to_city(), transfer_city(), transfer_unit(), try_summon_barbarians(), try_to_save_unit(), unit_conquer_city(), unit_do_destroy_city(), unit_do_help_build(), unit_nuke(), update_city_activity(), upgrade_building_prod(), upgrade_unit_prod(), worklist_change_build_target(), and worklist_item_postpone_req_vec().

◆ city_tile_link()

const char* city_tile_link ( const struct city pcity)

Get a text link to a city tile (make a clickable link to a tile with the city name as text).

N.B.: The returned string is static, so every call to this function overwrites the previous.

Definition at line 1072 of file featured_text.cpp.

Referenced by disband_city(), do_city_migration(), remove_city(), unit_conquer_city(), and unit_do_destroy_city().

◆ featured_text_apply_tag()

size_t featured_text_apply_tag ( const char *  text_source,
char *  featured_text,
size_t  featured_text_len,
enum text_tag_type  tag_type,
ft_offset_t  start_offset,
ft_offset_t  stop_offset,
  ... 
)

Apply a tag to a text.

This text can already containing escape sequences. Returns 0 on error.

Prototype:

  • If tag_type is TTT_BOLD, TTT_ITALIC, TTT_STRIKE or TTT_UNDERLINE, there shouldn't be any extra argument.
  • If tag_type is TTT_COLOR: size_t featured_text_apply_tag(..., const struct ft_color color);
  • If tag_type is TTT_LINK and you want a city link: size_t featured_text_apply_tag(..., TLT_CITY, struct city *pcity);
  • If tag_type is TTT_LINK and you want a tile link: size_t featured_text_apply_tag(..., TLT_TILE, struct tile *ptile);
  • If tag_type is TTT_LINK and you want an unit link: size_t featured_text_apply_tag(..., TLT_UNIT, struct unit *punit);

See also comment for text_tag_initv().

Definition at line 982 of file featured_text.cpp.

Referenced by create_event(), package_event_full(), player_color_ftstr(), show_players(), and show_settings_one().

◆ featured_text_to_plain_text()

size_t featured_text_to_plain_text ( const char *  featured_text,
char *  plain_text,
size_t  plain_text_len,
struct text_tag_list **  tags,
bool  replace_link_text 
)

Separate the text from the text features.

'tags' can be nullptr.

When 'replace_link_text' is set, the text used for the signal sequence links will be overwritten. It is used on client side to have updated links in chatline, to communicate when users don't know share the city names, and avoid users making voluntary confusing names when editing links in chatline.

Definition at line 861 of file featured_text.cpp.

Referenced by con_write(), handle_event(), luaconsole_append(), and output_window_append().

◆ ft_color_construct()

static struct ft_color ft_color_construct ( const char *  foreground,
const char *  background 
)
inlinestatic

Definition at line 93 of file featured_text.h.

Referenced by option_dialog::apply_options().

◆ ft_color_requested()

static bool ft_color_requested ( const struct ft_color  color)
inlinestatic

◆ text_tag_color_background()

QString text_tag_color_background ( const struct text_tag ptag)

Return the background color suggested by this text tag.

This requires the tag type to be TTT_COLOR. Returns nullptr on error, "" if unset.

Definition at line 715 of file featured_text.cpp.

Referenced by apply_tags().

◆ text_tag_color_foreground()

QString text_tag_color_foreground ( const struct text_tag ptag)

Return the foreground color suggested by this text tag.

This requires the tag type to be TTT_COLOR. Returns nullptr on error, "" if unset.

Definition at line 701 of file featured_text.cpp.

Referenced by apply_tags().

◆ text_tag_copy()

struct text_tag* text_tag_copy ( const struct text_tag ptag)

This function returns a new pointer to a text_tag which is similar to the 'ptag' argument.

Definition at line 656 of file featured_text.cpp.

◆ text_tag_destroy()

void text_tag_destroy ( struct text_tag ptag)

Free a text_tag structure.

Definition at line 671 of file featured_text.cpp.

Referenced by featured_text_to_plain_text().

◆ text_tag_link_id()

int text_tag_link_id ( const struct text_tag ptag)

Return the link target id suggested by this text tag (city id, tile index or unit id).

This requires the tag type to be TTT_LINK. Returns -1 on error.

Definition at line 744 of file featured_text.cpp.

Referenced by apply_tags(), and handle_event().

◆ text_tag_link_type()

enum text_link_type text_tag_link_type ( const struct text_tag ptag)

Return the link target type suggested by this text tag.

This requires the tag type to be TTT_LINK. Returns -1 on error.

Definition at line 715 of file featured_text.cpp.

Referenced by apply_tags(), and handle_event().

◆ text_tag_new()

struct text_tag* text_tag_new ( enum text_tag_type  tag_type,
ft_offset_t  start_offset,
ft_offset_t  stop_offset,
  ... 
)

Returns a new text_tag or nullptr on error.

Prototype:

  • If tag_type is TTT_BOLD, TTT_ITALIC, TTT_STRIKE or TTT_UNDERLINE, there shouldn't be any extra argument.
  • If tag_type is TTT_COLOR: struct text_tag *text_tag_new(..., const struct ft_color color);
  • If tag_type is TTT_LINK and you want a city link: struct text_tag *text_tag_new(..., TLT_CITY, struct city *pcity);
  • If tag_type is TTT_LINK and you want a tile link: struct text_tag *text_tag_new(..., TLT_TILE, struct tile *ptile);
  • If tag_type is TTT_LINK and you want an unit link: struct text_tag *text_tag_new(..., TLT_UNIT, struct unit *punit);

See also comment for text_tag_initv().

Definition at line 632 of file featured_text.cpp.

Referenced by handle_event(), luaconsole_append(), and output_window_append().

◆ text_tag_start_offset()

ft_offset_t text_tag_start_offset ( const struct text_tag ptag)

Return the start offset (in bytes) of this text tag.

Definition at line 684 of file featured_text.cpp.

Referenced by apply_tags().

◆ text_tag_stop_offset()

ft_offset_t text_tag_stop_offset ( const struct text_tag ptag)

Return the stop offset (in bytes) of this text tag.

Definition at line 692 of file featured_text.cpp.

Referenced by apply_tags().

◆ text_tag_type()

enum text_tag_type text_tag_type ( const struct text_tag ptag)

Return the type of this text tag.

Definition at line 671 of file featured_text.cpp.

◆ tile_link()

◆ unit_achieved_rank_string()

const char* unit_achieved_rank_string ( const struct unit punit)

Get string of when unit gets upgraded to new veteran level.

N.B.: The returned string is static, so every call to this function overwrites the previous.

Definition at line 1183 of file featured_text.cpp.

Referenced by do_attack().

◆ unit_firepower_if_not_one()

const char* unit_firepower_if_not_one ( int  firepower)

Get string of unit's firepower text, i.e.

"FP:2 " If firepower is equal to one, then an empty string is returned so as to shorten the text output. N.B.: The returned string is static, so every call to this function overwrites the previous.

Definition at line 1220 of file featured_text.cpp.

Referenced by do_attack().

◆ unit_link()

◆ unit_tile_link()

◆ unit_tired_attack_string()

const char* unit_tired_attack_string ( const struct unit punit)

Get string of unit's attack would be a tired attack or not.

N.B.: The returned string is static, so every call to this function overwrites the previous.

Definition at line 1199 of file featured_text.cpp.

Referenced by do_attack().

◆ unit_veteran_level_and_bonus()

const char* unit_veteran_level_and_bonus ( const struct unit punit)

◆ unit_veteran_level_string()

const char* unit_veteran_level_string ( const struct unit punit)

Get a text of a unit's vet level.

N.B.: The returned string is static, so every call to this function overwrites the previous.

Definition at line 1163 of file featured_text.cpp.

Referenced by do_attack(), unit_achieved_rank_string(), unit_bombard(), and wakeup_neighbor_sentries().

Variable Documentation

◆ ftc_any

◆ ftc_changed

struct ft_color ftc_changed
extern

Definition at line 1 of file featured_text.cpp.

Referenced by show_players(), and show_settings_one().

◆ ftc_chat_ally

const struct ft_color ftc_chat_ally
extern

Definition at line 1 of file featured_text.cpp.

Referenced by chat_msg_to_allies(), and chat_msg_to_global_observers().

◆ ftc_chat_luaconsole

const struct ft_color ftc_chat_luaconsole
extern

Definition at line 1 of file featured_text.cpp.

Referenced by api_client_chat_base().

◆ ftc_chat_private

const struct ft_color ftc_chat_private
extern

Definition at line 1 of file featured_text.cpp.

Referenced by chat_msg_to_conn(), chat_msg_to_player(), and dai_diplo_notify().

◆ ftc_chat_public

const struct ft_color ftc_chat_public
extern

Definition at line 1 of file featured_text.cpp.

Referenced by chat_msg_to_all().

◆ ftc_client

◆ ftc_command

const struct ft_color ftc_command
extern

Definition at line 1 of file featured_text.cpp.

Referenced by cmd_reply_line().

◆ ftc_editor

◆ ftc_game_start

const struct ft_color ftc_game_start
extern

Definition at line 1 of file featured_text.cpp.

Referenced by start_command().

◆ ftc_log

const struct ft_color ftc_log
extern

Definition at line 1 of file featured_text.cpp.

Referenced by debug_command(), and timing_results_real().

◆ ftc_luaconsole_error

const struct ft_color ftc_luaconsole_error
extern

Definition at line 1 of file featured_text.cpp.

Referenced by script_client_output().

◆ ftc_luaconsole_input

const struct ft_color ftc_luaconsole_input
extern

Definition at line 1 of file featured_text.cpp.

◆ ftc_luaconsole_normal

const struct ft_color ftc_luaconsole_normal
extern

Definition at line 1 of file featured_text.cpp.

Referenced by script_client_output().

◆ ftc_luaconsole_verbose

const struct ft_color ftc_luaconsole_verbose
extern

Definition at line 1 of file featured_text.cpp.

Referenced by script_client_output().

◆ ftc_luaconsole_warn

const struct ft_color ftc_luaconsole_warn
extern

Definition at line 1 of file featured_text.cpp.

Referenced by script_client_output().

◆ ftc_player_lost

const struct ft_color ftc_player_lost
extern

Definition at line 1 of file featured_text.cpp.

Referenced by lost_connection_to_client().

◆ ftc_server

const struct ft_color ftc_server
extern

Definition at line 1 of file featured_text.cpp.

Referenced by aifill(), aifill_action(), announce_player(), announce_trade_route_removal(), api_edit_give_technology(), apply_disaster(), auto_arrange_workers(), begin_turn(), bounce_unit(), build_free_small_wonders(), can_unit_move_to_tile_with_notify(), cancelvote_command(), change_build_target(), check_city_migrations_player(), check_for_game_over(), check_player_max_rates(), check_pollution(), choose_tech_goal(), city_add_unit(), city_build(), city_build_building(), city_build_unit(), city_distribute_surplus_shields(), city_empty_food_stock(), city_global_turn_notify(), city_handle_disorder(), city_illness_strike(), city_increase_size(), city_landlocked_sell_coastal_improvements(), city_map_update_radius_sq(), city_populate(), city_turn_notify(), civil_war(), cmd_reply_line(), complain_ambiguous(), connection_detach(), create_barbarian_player(), create_city(), dai_city_sell_noncritical(), delegate_command(), diplomat_bribe(), diplomat_embassy(), diplomat_escape_full(), diplomat_get_tech(), diplomat_incite(), diplomat_infiltrate_tile(), diplomat_may_lose_gold(), diplomat_sabotage(), disband_city(), do_airline(), do_attack(), do_capture_units(), do_city_migration(), do_expel_unit(), do_heal_unit(), do_nuclear_explosion(), do_nuke_tile(), do_paradrop(), do_spaceship_place(), do_tech_parasite_effect(), do_unit_change_homecity(), do_unit_establish_trade(), do_unit_strike_city_building(), do_unit_strike_city_production(), do_unit_upgrade(), do_upgrade_effects(), end_command(), end_phase(), end_turn(), establish_new_connection(), execute_orders(), explain_why_no_action_enabled(), forget_tech_transfered(), found_new_tech(), global_warming(), government_change(), handle_chat_msg_req(), handle_city_change(), handle_city_rename(), handle_diplomacy_accept_treaty_req(), handle_diplomacy_cancel_pact_explicit(), handle_diplomacy_init_meeting_req(), handle_nation_select_req(), handle_player_change_government(), handle_player_rates(), handle_player_ready(), handle_report_req(), handle_spaceship_launch(), handle_unit_get_actions(), handle_unit_type_upgrade(), hut_get_limited(), illegal_action(), illegal_action_msg(), illegal_action_pay_price(), kill_player(), kill_unit(), lost_connection_to_client(), make_contact(), nationset_action(), notify_actor_caught(), notify_actor_success(), notify_global_caught(), notify_global_success(), notify_illegal_armistice_units(), notify_unit_experience(), notify_victim_caught(), notify_victim_success(), nuclear_winter(), player_limit_to_max_rates(), player_restore_units(), really_diplomacy_cancel_meeting(), really_handle_city_buy(), really_handle_city_sell(), remove_city(), remove_illegal_armistice_units(), remove_obsolete_buildings_city(), research_tech_lost(), revolution_length(), sell_random_building(), sell_random_unit(), send_delegation_info(), server_remove_unit_full(), set_command(), set_running_game_access_level(), spaceship_arrived(), spaceship_lost(), spy_nuke_city(), spy_poison(), spy_sabotage_unit(), spy_spread_plague(), spy_steal_gold(), spy_steal_some_maps(), srv_ready(), srv_scores(), start_cmd_reply(), start_game(), steal_a_tech(), surrender_command(), take_command(), tech_researched(), teleport_unit_to_city(), transfer_city(), transfer_city_units(), transfer_unit(), try_summon_barbarians(), try_to_save_unit(), unit_activities_cancel_all_illegal(), unit_bombard(), unit_can_do_action_now(), unit_conquer_city(), unit_convert(), unit_do_destroy_city(), unit_do_help_build(), unit_lost_with_transport(), unit_move_handling(), unit_nuke(), update_bulbs(), update_city_activities(), update_city_activity(), update_diplomatics(), update_timeout(), upgrade_all_city_extras(), upgrade_building_prod(), upgrade_unit_prod(), wakeup_neighbor_sentries(), worklist_change_build_target(), and worklist_item_postpone_req_vec().

◆ ftc_server_prompt

const struct ft_color ftc_server_prompt
extern

Definition at line 1 of file featured_text.cpp.

Referenced by handle_stdin_input_real(), and wall().

◆ ftc_vote_abstain

const struct ft_color ftc_vote_abstain
extern

Definition at line 1 of file featured_text.cpp.

Referenced by check_vote().

◆ ftc_vote_failed

const struct ft_color ftc_vote_failed
extern

Definition at line 1 of file featured_text.cpp.

Referenced by check_vote().

◆ ftc_vote_no

const struct ft_color ftc_vote_no
extern

Definition at line 1 of file featured_text.cpp.

Referenced by check_vote().

◆ ftc_vote_passed

const struct ft_color ftc_vote_passed
extern

Definition at line 1 of file featured_text.cpp.

Referenced by check_vote().

◆ ftc_vote_public

const struct ft_color ftc_vote_public
extern

Definition at line 1 of file featured_text.cpp.

Referenced by handle_stdin_input_real().

◆ ftc_vote_team

const struct ft_color ftc_vote_team
extern

Definition at line 1 of file featured_text.cpp.

Referenced by handle_stdin_input_real().

◆ ftc_vote_yes

const struct ft_color ftc_vote_yes
extern

Definition at line 1 of file featured_text.cpp.

Referenced by check_vote().

◆ ftc_warning