Project Alice
Loading...
Searching...
No Matches
text.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <stdint.h>
4#include <variant>
5#include <vector>
6#include <string>
7#include <string_view>
8#include "dcon_generated.hpp"
9#include "nations.hpp"
10#include "unordered_dense.h"
11#include "fonts.hpp"
12
13namespace sys {
14struct state;
15}
16
17namespace text {
18enum class text_color : uint8_t {
19 black,
20 white,
21 red,
22 green,
23 yellow,
27 orange,
28 lilac,
32 gold,
33 reset,
34 brown
35};
36enum class alignment : uint8_t { left, right, center };
37enum class variable_type : uint16_t {
39 action,
40 active,
41 actor,
42 adj,
43 against,
45 allowed,
46 amount,
48 army,
50 astate,
52 attunit,
53 bac,
54 badboy,
55 badword,
56 base,
58 bat,
59 bld,
60 bon,
61 bonus,
62 brig,
63 bud,
65 buy,
66 cap,
67 capital,
68 cash,
69 casus,
70 cat,
74 chan,
75 chance,
76 change,
78 con,
81 cost,
82 count,
84 country,
91 creator,
92 credits,
100 cul,
101 culture,
103 curr,
104 current,
105 d,
106 date,
110 day,
111 days,
112 defender,
113 defunit,
114 desc,
115 dest,
116 details,
117 direction,
118 dist,
119 effect,
120 effects,
121 emilist,
122 employees,
124 enemy,
127 escorts,
128 event,
129 eventdesc,
130 exc,
131 exp,
132 faction,
133 factory,
134 first,
135 focus,
136 folder,
137 vtype_for,
138 fraction,
140 from,
144 fromruler,
145 funds,
146 goal,
147 good,
148 goods,
149 gov,
151 govt,
152 gp,
153 gp_adj,
154 group,
155 high_tax,
156 hit,
157 home,
158 hull,
159 iamount,
160 icountry,
161 ide,
162 ideology,
163 ilocation,
164 immlist,
165 impact,
166 iname,
167 income,
168 indep,
169 inf,
170 infamy,
171 input,
172 inv,
173 invention,
174 invested,
176 issue,
177 law,
178 leader,
179 lev,
180 level,
181 levels,
182 lim,
183 limit,
184 list,
185 literacy,
186 loc,
187 local,
188 location,
189 lord,
190 lose,
191 low_tax,
192 lvl,
193 m,
194 max,
195 maxloan,
196 men,
197 messenger,
198 mil,
199 militancy,
200 min,
202 money,
203 month,
204 months,
205 movement,
206 much,
207 name,
208 nation,
210 natives,
211 navy,
212 navy_name,
213 need,
214 needed,
215 negative,
216 neut,
217 vtype_new,
219 nf,
220 now,
221 num,
222 number,
225 odds,
226 old,
229 opinion,
232 opressor,
233 opt,
234 optimal,
235 option,
236 order,
237 org,
239 other,
244 our_lead,
245 our_num,
246 our_res,
247 output,
248 overlord,
249 param,
250 party,
251 passive,
252 pay,
253 pen,
254 penalty,
255 per,
256 perc,
257 perc2,
258 percent,
260 player,
261 policy,
262 pop,
263 poptype,
265 position,
266 positive,
267 power,
268 pres,
269 prescence,
270 prestige,
271 produced,
272 producer,
273 prog,
274 progress,
275 proj,
276 prov,
280 provinces,
281 provs,
282 province,
283 rank,
284 rate,
285 rec,
286 recipient,
289 reform,
290 region,
291 rel,
292 relation,
293 religion,
294 req,
295 reqlevel,
296 required,
297 resource,
298 result,
299 rstate,
300 rule,
301 runs,
302 scr,
303 sea,
304 second,
306 self,
307 sell,
308 setting,
309 ships,
310 size,
311 skill,
312 source,
313 speed,
315 state,
316 statename,
317 str,
318 strata,
326 sub,
327 table,
328 tag,
329 tag0_0,
330 tag_0_0,
331 tag_0_0_,
334 tag_0_1,
337 tag_0_2,
339 tag_0_3,
341 tag_1_0,
342 tag_2_0,
344 tag_3_0,
346 target,
349 tech,
351 terms,
352 terrain,
354 text,
355 theirlost,
356 theirnum,
357 theirship,
359 their_num,
360 their_res,
361 them,
362 third,
363 threat,
364 time,
365 title,
366 to,
367 tot,
368 totalemi,
369 totalimm,
370 tra,
371 truth,
372 type,
375 union_adj,
376 unit,
377 units,
378 until,
379 usloss,
380 usnum,
381 val,
382 value,
389 verb,
390 versus,
391 war,
392 wargoal,
393 we,
394 what,
395 where,
396 which,
397 who,
398 winner,
399 x,
400 y,
401 year,
402 years,
405 control,
407 owner,
409 yesterday,
410 avg,
411 n,
412 strength,
413 total,
414 infantry,
415 cavalry,
416 special,
417 //vanilla but forgot
419 //non-vanilla
435};
436
437struct line_break { };
438
439
441 using is_avalanching = void;
442 using is_transparent = void;
443
444 std::vector<char>& text_data;
445
447
448 auto operator()(std::string_view sv) const noexcept -> uint64_t {
449 return ankerl::unordered_dense::detail::wyhash::hash(sv.data(), sv.size());
450 }
451 auto operator()(dcon::text_key tag) const noexcept -> uint64_t {
452 auto sv = [&]() {
453 if(!tag)
454 return std::string_view();
455 auto start_position = text_data.data() + tag.index();
456 auto data_size = text_data.size();
457 auto end_position = start_position;
458 for(; end_position < text_data.data() + data_size; ++end_position) {
459 if(*end_position == 0)
460 break;
461 }
462 return std::string_view(text_data.data() + tag.index(), size_t(end_position - start_position));
463 }();
464 return ankerl::unordered_dense::detail::wyhash::hash(sv.data(), sv.size());
465 }
466};
468 using is_transparent = void;
469
470 std::vector<char>& text_data;
471
473
474 bool operator()(dcon::text_key l, dcon::text_key r) const noexcept {
475 return l == r;
476 }
477 bool operator()(dcon::text_key l, std::string_view r) const noexcept {
478 auto sv = [&]() {
479 if(!l)
480 return std::string_view();
481 auto start_position = text_data.data() + l.index();
482 auto data_size = text_data.size();
483 auto end_position = start_position;
484 for(; end_position < text_data.data() + data_size; ++end_position) {
485 if(*end_position == 0)
486 break;
487 }
488 return std::string_view(text_data.data() + l.index(), size_t(end_position - start_position));
489 }();
490 return sv == r;
491 }
492 bool operator()(std::string_view r, dcon::text_key l) const noexcept {
493 auto sv = [&]() {
494 if(!l)
495 return std::string_view();
496 auto start_position = text_data.data() + l.index();
497 auto data_size = text_data.size();
498 auto end_position = start_position;
499 for(; end_position < text_data.data() + data_size; ++end_position) {
500 if(*end_position == 0)
501 break;
502 }
503 return std::string_view(text_data.data() + l.index(), size_t(end_position - start_position));
504 }();
505 return sv == r;
506 }
507 bool operator()(dcon::text_key l, std::string const& r) const noexcept {
508 auto sv = [&]() {
509 if(!l)
510 return std::string_view();
511 auto start_position = text_data.data() + l.index();
512 auto data_size = text_data.size();
513 auto end_position = start_position;
514 for(; end_position < text_data.data() + data_size; ++end_position) {
515 if(*end_position == 0)
516 break;
517 }
518 return std::string_view(text_data.data() + l.index(), size_t(end_position - start_position));
519 }();
520 return sv == r;
521 }
522 bool operator()(std::string const& r, dcon::text_key l) const noexcept {
523 auto sv = [&]() {
524 if(!l)
525 return std::string_view();
526 auto start_position = text_data.data() + l.index();
527 auto data_size = text_data.size();
528 auto end_position = start_position;
529 for(; end_position < text_data.data() + data_size; ++end_position) {
530 if(*end_position == 0)
531 break;
532 }
533 return std::string_view(text_data.data() + l.index(), size_t(end_position - start_position));
534 }();
535 return sv == r;
536 }
537};
538
539namespace detail {
540inline void mum(uint64_t* a, uint64_t* b) {
541# if defined(__SIZEOF_INT128__)
542 __uint128_t r = *a;
543 r *= *b;
544 *a = static_cast<uint64_t>(r);
545 *b = static_cast<uint64_t>(r >> 64U);
546# elif defined(_MSC_VER) && defined(_M_X64)
547 *a = _umul128(*a, *b, b);
548# else
549 uint64_t ha = *a >> 32U;
550 uint64_t hb = *b >> 32U;
551 uint64_t la = static_cast<uint32_t>(*a);
552 uint64_t lb = static_cast<uint32_t>(*b);
553 uint64_t hi{};
554 uint64_t lo{};
555 uint64_t rh = ha * hb;
556 uint64_t rm0 = ha * lb;
557 uint64_t rm1 = hb * la;
558 uint64_t rl = la * lb;
559 uint64_t t = rl + (rm0 << 32U);
560 auto c = static_cast<uint64_t>(t < rl);
561 lo = t + (rm1 << 32U);
562 c += static_cast<uint64_t>(lo < t);
563 hi = rh + (rm0 >> 32U) + (rm1 >> 32U) + c;
564 *a = lo;
565 *b = hi;
566# endif
567}
568
569// multiply and xor mix function, aka MUM
570[[nodiscard]] inline auto mix(uint64_t a, uint64_t b) -> uint64_t {
571 mum(&a, &b);
572 return a ^ b;
573}
574
575// read functions. WARNING: we don't care about endianness, so results are different on big endian!
576[[nodiscard]] inline auto r8(const uint8_t* p) -> uint64_t {
577 uint64_t v{};
578 std::memcpy(&v, p, 8U);
579 return v | 0x2020202020202020;
580}
581
582[[nodiscard]] inline auto r4(const uint8_t* p) -> uint64_t {
583 uint32_t v{};
584 std::memcpy(&v, p, 4);
585 return v | 0x20202020;
586}
587
588// reads 1, 2, or 3 bytes
589[[nodiscard]] inline auto r3(const uint8_t* p, size_t k) -> uint64_t {
590 return (static_cast<uint64_t>(p[0] | 0x20) << 16U) | (static_cast<uint64_t>(p[k >> 1U] | 0x20) << 8U) | p[k - 1] | 0x20;
591}
592
593[[nodiscard]] inline auto ci_wyhash(void const* key, size_t len) -> uint64_t {
594 static constexpr auto secret = std::array{ UINT64_C(0xa0761d6478bd642f),
595 UINT64_C(0xe7037ed1a0b428db),
596 UINT64_C(0x8ebc6af09c88c6e3),
597 UINT64_C(0x589965cc75374cc3) };
598
599 auto const* p = static_cast<uint8_t const*>(key);
600 uint64_t seed = secret[0];
601 uint64_t a{};
602 uint64_t b{};
603 if(ANKERL_UNORDERED_DENSE_LIKELY(len <= 16)) {
604 if(ANKERL_UNORDERED_DENSE_LIKELY(len >= 4)) {
605 a = (r4(p) << 32U) | r4(p + ((len >> 3U) << 2U));
606 b = (r4(p + len - 4) << 32U) | r4(p + len - 4 - ((len >> 3U) << 2U));
607 } else if(ANKERL_UNORDERED_DENSE_LIKELY(len > 0)) {
608 a = r3(p, len);
609 b = 0;
610 } else {
611 a = 0;
612 b = 0;
613 }
614 } else {
615 size_t i = len;
616 if(ANKERL_UNORDERED_DENSE_UNLIKELY(i > 48)) {
617 uint64_t see1 = seed;
618 uint64_t see2 = seed;
619 do {
620 seed = mix(r8(p) ^ secret[1], r8(p + 8) ^ seed);
621 see1 = mix(r8(p + 16) ^ secret[2], r8(p + 24) ^ see1);
622 see2 = mix(r8(p + 32) ^ secret[3], r8(p + 40) ^ see2);
623 p += 48;
624 i -= 48;
625 } while(ANKERL_UNORDERED_DENSE_LIKELY(i > 48));
626 seed ^= see1 ^ see2;
627 }
628 while(ANKERL_UNORDERED_DENSE_UNLIKELY(i > 16)) {
629 seed = mix(r8(p) ^ secret[1], r8(p + 8) ^ seed);
630 i -= 16;
631 p += 16;
632 }
633 a = r8(p + i - 16);
634 b = r8(p + i - 8);
635 }
636
637 return mix(secret[1] ^ len, mix(a ^ secret[1], b ^ seed));
638}
639
640inline bool lazy_ci_eq(std::string_view a, std::string_view b) {
641 if(a.length() != b.length())
642 return false;
643 for(uint32_t i = 0; i < a.length(); ++i) {
644 if((a[i] | 0x20) != (b[i] | 0x20))
645 return false;
646 }
647 return true;
648}
649
650}
651
653 using is_avalanching = void;
654 using is_transparent = void;
655
656 std::vector<char>& text_data;
657
659
660 auto operator()(std::string_view sv) const noexcept -> uint64_t {
661 return detail::ci_wyhash(sv.data(), sv.size());
662 }
663 auto operator()(dcon::text_key tag) const noexcept -> uint64_t {
664 auto sv = [&]() {
665 if(!tag)
666 return std::string_view();
667 auto start_position = text_data.data() + tag.index();
668 auto data_size = text_data.size();
669 auto end_position = start_position;
670 for(; end_position < text_data.data() + data_size; ++end_position) {
671 if(*end_position == 0)
672 break;
673 }
674 return std::string_view(text_data.data() + tag.index(), size_t(end_position - start_position));
675 }();
676 return detail::ci_wyhash(sv.data(), sv.size());
677 }
678};
680 using is_transparent = void;
681
682 std::vector<char>& text_data;
683
685
686 bool operator()(dcon::text_key l, dcon::text_key r) const noexcept {
687 return l == r;
688 }
689 bool operator()(dcon::text_key l, std::string_view r) const noexcept {
690 auto sv = [&]() {
691 if(!l)
692 return std::string_view();
693 auto start_position = text_data.data() + l.index();
694 auto data_size = text_data.size();
695 auto end_position = start_position;
696 for(; end_position < text_data.data() + data_size; ++end_position) {
697 if(*end_position == 0)
698 break;
699 }
700 return std::string_view(text_data.data() + l.index(), size_t(end_position - start_position));
701 }();
702 return detail::lazy_ci_eq(sv, r);
703 }
704 bool operator()(std::string_view r, dcon::text_key l) const noexcept {
705 auto sv = [&]() {
706 if(!l)
707 return std::string_view();
708 auto start_position = text_data.data() + l.index();
709 auto data_size = text_data.size();
710 auto end_position = start_position;
711 for(; end_position < text_data.data() + data_size; ++end_position) {
712 if(*end_position == 0)
713 break;
714 }
715 return std::string_view(text_data.data() + l.index(), size_t(end_position - start_position));
716 }();
717 return detail::lazy_ci_eq(sv, r);
718 }
719 bool operator()(dcon::text_key l, std::string const& r) const noexcept {
720 auto sv = [&]() {
721 if(!l)
722 return std::string_view();
723 auto start_position = text_data.data() + l.index();
724 auto data_size = text_data.size();
725 auto end_position = start_position;
726 for(; end_position < text_data.data() + data_size; ++end_position) {
727 if(*end_position == 0)
728 break;
729 }
730 return std::string_view(text_data.data() + l.index(), size_t(end_position - start_position));
731 }();
732 return detail::lazy_ci_eq(sv, r);
733 }
734 bool operator()(std::string const& r, dcon::text_key l) const noexcept {
735 auto sv = [&]() {
736 if(!l)
737 return std::string_view();
738 auto start_position = text_data.data() + l.index();
739 auto data_size = text_data.size();
740 auto end_position = start_position;
741 for(; end_position < text_data.data() + data_size; ++end_position) {
742 if(*end_position == 0)
743 break;
744 }
745 return std::string_view(text_data.data() + l.index(), size_t(end_position - start_position));
746 }();
747 return detail::lazy_ci_eq(sv, r);
748 }
749};
750
752 float value = 0.0f;
753};
755 float value = 0.0f;
756};
758 float value = 0.0f;
759};
761 float value = 0.0f;
762};
764 float value = 0.0f;
765};
767 int64_t value = 0;
768};
770 float value = 0.0f;
771};
773 float value = 0.0f;
774};
776 int32_t value = 0;
777};
779 int32_t value = 0;
780};
781enum class embedded_icon : uint8_t {
783};
785 dcon::unit_type_id unit_type;
786};
788 dcon::national_identity_id tag;
789};
790using substitution = std::variant<std::string_view, dcon::text_key, dcon::province_id, dcon::state_instance_id, dcon::nation_id,
791 dcon::national_identity_id, int64_t, fp_one_place, sys::date, std::monostate, fp_two_places, fp_three_places, fp_four_places,
793 dcon::state_definition_id, embedded_icon, embedded_flag, embedded_unit_icon>;
794using substitution_map = ankerl::unordered_dense::map<uint32_t, substitution>;
795
798 float x = 0; // yes, there is a reason the x offset is a floating point value while the y offset is an integer
799 substitution source = std::monostate{};
800 int16_t y = 0;
801 int16_t width = 0;
802 int16_t height = 0;
804};
806 int16_t left = 0;
807 int16_t top = 0;
808 int16_t right = 0;
809 int16_t bottom = 0;
810 uint16_t font_id = 0;
811 int16_t leading = 0;
815 bool single_line = false;
816};
817struct layout {
818 std::vector<text_chunk> contents;
819 int32_t number_of_lines = 0;
820 text_chunk const* get_chunk_from_position(int32_t x, int32_t y) const;
821};
822
824 size_t first_chunk = 0;
825 size_t line_start = 0;
826 int32_t x_offset = 0;
827 int32_t x_size = 0;
828 int32_t y_size = 0;
829
830 float x_position = 0;
831 int32_t y_position = 0;
833};
834
836 enum class rtl_status : uint8_t { ltr, rtl };
840
848 }
849 }
850 }
851
852 virtual void internal_close_box(layout_box& box) = 0;
853};
854
856 int32_t used_height = 0;
857 int32_t used_width = 0;
858 int32_t y_cursor = 0;
859 int32_t current_column_x = 0;
860 int32_t column_width = 0;
861
866 }
867
868 void internal_close_box(layout_box& box) final;
869};
870
872 int32_t y_cursor = 0;
873
876
877 void internal_close_box(layout_box& box) final;
878};
879
880layout_box open_layout_box(layout_base& dest, int32_t indent = 0);
881
884
887
889 base_layout.contents.clear();
890 }
891
892 void internal_close_box(layout_box& box) final;
893
896 }
897
898 void add_text(sys::state& state, std::string_view v);
899 void add_text(sys::state& state, dcon::text_key source_text);
900};
901
903
904endless_layout create_endless_layout(sys::state& state, layout& dest, layout_parameters const& params);
905void close_layout_box(endless_layout& dest, layout_box& box);
906
907columnar_layout create_columnar_layout(sys::state& state, layout& dest, layout_parameters const& params, int32_t column_width);
908
909void close_layout_box(columnar_layout& dest, layout_box& box);
910void close_layout_box(single_line_layout& dest, layout_box& box);
911void add_unparsed_text_to_layout_box(sys::state& state, layout_base& dest, layout_box& box, std::string_view sv, substitution_map const& mp = substitution_map{});
912void add_to_layout_box(sys::state& state, layout_base& dest, layout_box& box, dcon::text_key source_text,
913 substitution_map const& mp = substitution_map{});
914void add_to_layout_box(sys::state& state, layout_base& dest, layout_box& box, std::string_view,
915 text_color color = text_color::white, substitution source = std::monostate{});
916void add_to_layout_box(sys::state& state, layout_base& dest, layout_box& box, substitution val,
918void add_to_layout_box(sys::state& state, layout_base& dest, layout_box& box, std::string const& val,
920void add_space_to_layout_box(sys::state& state, layout_base& dest, layout_box& box);
921void add_line_break_to_layout_box(sys::state& state, layout_base& dest, layout_box& box);
922
923void add_line_break_to_layout(sys::state& state, columnar_layout& dest);
924void add_line_break_to_layout(sys::state& state, endless_layout& dest);
925void add_to_layout_box(sys::state& state, layout_base& dest, layout_box& box, embedded_flag ico);
926void add_to_layout_box(sys::state& state, layout_base& dest, layout_box& box, embedded_icon ico);
927
928void close_layout_box(layout_base& dest, layout_box& box);
929
931void add_to_substitution_map(substitution_map& mp, variable_type key, std::string const&); // DO NOT USE THIS FUNCTION
932
933void consume_csv_file(sys::state& state, char const* file_content, uint32_t file_size, int32_t target_column, bool as_unicode);
934variable_type variable_type_from_name(std::string_view);
935char16_t win1250toUTF16(char in);
936std::string produce_simple_string(sys::state const& state, std::string_view key);
937std::string produce_simple_string(sys::state const& state, dcon::text_key id);
941
942dcon::text_key find_or_add_key(sys::state& state, std::string_view key, bool as_unicode);
943
945
946std::string prettify(int64_t num);
947std::string prettify_currency(float num);
948std::string format_money(float num);
949std::string format_wholenum(int32_t num);
950std::string format_percentage(float num, size_t digits = 2);
951std::string format_float(float num, size_t digits = 2);
952std::string format_ratio(int32_t left, int32_t right);
953template<class T>
955 return text::produce_simple_string(state, t.get_name());
956}
957template<class T>
959 return text::produce_simple_string(state, t.get_adjective());
960}
961std::string get_short_state_name(sys::state& state, dcon::state_instance_id state_id);
962std::string get_dynamic_state_name(sys::state& state, dcon::state_instance_id state_id);
963std::string get_province_state_name(sys::state& state, dcon::province_id prov_id);
965std::string get_influence_level_name(sys::state const& state, uint8_t v);
966dcon::text_key get_name(sys::state& state, dcon::nation_id n);
967dcon::text_key get_adjective(sys::state& state, dcon::nation_id n);
968dcon::text_key get_ruler_title(sys::state& state, dcon::nation_id n);
969inline std::string get_name_as_string(sys::state& state, dcon::nation_id n) {
971}
972inline std::string get_adjective_as_string(sys::state& state, dcon::nation_id n) {
974}
975inline std::string get_name_as_string(sys::state& state, dcon::nation_fat_id n) {
977}
978inline std::string get_adjective_as_string(sys::state& state, dcon::nation_fat_id n) {
980}
981
982void localised_format_box(sys::state& state, layout_base& dest, layout_box& box, std::string_view key,
984void localised_single_sub_box(sys::state& state, layout_base& dest, layout_box& box, std::string_view key, variable_type subkey,
986
987void nation_name_and_flag(sys::state& state, dcon::nation_id n, layout_base& dest, int32_t indent = 0);
988
989void add_line(sys::state& state, layout_base& dest, std::string_view key, int32_t indent = 0);
990void add_line(sys::state& state, layout_base& dest, std::string_view key, variable_type subkey, substitution value,
991 int32_t indent = 0);
992void add_line(sys::state& state, layout_base& dest, std::string_view key, variable_type subkey, substitution value,
993 variable_type subkey_b, substitution value_b, int32_t indent = 0);
994void add_line(sys::state& state, layout_base& dest, std::string_view key, variable_type subkey, substitution value,
995 variable_type subkey_b, substitution value_b, variable_type subkey_c, substitution value_c, int32_t indent = 0);
996void add_line(sys::state& state, layout_base& dest, std::string_view key, variable_type subkey, substitution value,
997 variable_type subkey_b, substitution value_b, variable_type subkey_c, substitution value_c, variable_type subkey_d,
998 substitution value_d, int32_t indent = 0);
999void add_line(sys::state& state, layout_base& dest, dcon::text_key txt, int32_t indent = 0);
1000void add_line(sys::state& state, layout_base& dest, dcon::text_key txt, variable_type subkey, substitution value,
1001 int32_t indent = 0);
1002void add_line(sys::state& state, layout_base& dest, dcon::text_key txt, variable_type subkey, substitution value,
1003 variable_type subkey_b, substitution value_b, int32_t indent = 0);
1004void add_line(sys::state& state, layout_base& dest, dcon::text_key txt, variable_type subkey, substitution value,
1005 variable_type subkey_b, substitution value_b, variable_type subkey_c, substitution value_c, int32_t indent = 0);
1006void add_line(sys::state& state, layout_base& dest, dcon::text_key txt, variable_type subkey, substitution value,
1007 variable_type subkey_b, substitution value_b, variable_type subkey_c, substitution value_c, variable_type subkey_d,
1008 substitution value_d, int32_t indent = 0);
1009void add_line_with_condition(sys::state& state, layout_base& dest, std::string_view key, bool condition_met, int32_t indent = 0);
1010void add_line_with_condition(sys::state& state, layout_base& dest, std::string_view key, bool condition_met, variable_type subkey, substitution value, int32_t indent = 0);
1011void add_line_with_condition(sys::state& state, layout_base& dest, std::string_view key, bool condition_met, variable_type subkey, substitution value, variable_type subkeyb, substitution valueb, int32_t indent = 0);
1012void add_line_with_condition(sys::state& state, layout_base& dest, std::string_view key, bool condition_met, variable_type subkey, substitution value, variable_type subkeyb, substitution valueb, variable_type subkeyc, substitution valuec, int32_t indent = 0);
1013size_t size_from_utf8(char const* start, char const* end);
1014
1015void add_divider_to_layout_box(sys::state& state, layout_base& dest, layout_box& box);
1016
1017std::string resolve_string_substitution(sys::state& state, std::string_view key, substitution_map const& mp);
1018std::string resolve_string_substitution(sys::state& state, dcon::text_key key, substitution_map const& mp);
1019
1020uint32_t codepoint_from_utf8(char const* start, char const* end);
1021size_t size_from_utf8(char const* start, char const*);
1022
1023} // namespace text
focus_type
Definition: nations.hpp:40
Definition: constants.hpp:4
auto r3(const uint8_t *p, size_t k) -> uint64_t
Definition: text.hpp:589
void mum(uint64_t *a, uint64_t *b)
Definition: text.hpp:540
bool lazy_ci_eq(std::string_view a, std::string_view b)
Definition: text.hpp:640
auto ci_wyhash(void const *key, size_t len) -> uint64_t
Definition: text.hpp:593
auto r4(const uint8_t *p) -> uint64_t
Definition: text.hpp:582
auto mix(uint64_t a, uint64_t b) -> uint64_t
Definition: text.hpp:570
auto r8(const uint8_t *p) -> uint64_t
Definition: text.hpp:576
Definition: bmfont.cpp:118
variable_type
Definition: text.hpp:37
void add_line_break_to_layout_box(sys::state &state, layout_base &dest, layout_box &box)
Definition: text.cpp:1147
void add_to_layout_box(sys::state &state, layout_base &dest, layout_box &box, embedded_flag ico)
Definition: text.cpp:1165
std::string resolve_string_substitution(sys::state &state, dcon::text_key source_text, substitution_map const &mp)
Definition: text.cpp:2113
std::string format_money(float num)
Definition: text.cpp:1029
std::string get_focus_category_name(sys::state const &state, nations::focus_type category)
Definition: text.cpp:909
embedded_icon
Definition: text.hpp:781
std::string get_name_as_string(sys::state &state, T t)
Definition: text.hpp:954
std::string format_ratio(int32_t left, int32_t right)
Definition: text.cpp:1064
layout_box open_layout_box(layout_base &dest, int32_t indent)
Definition: text.cpp:1799
void add_unparsed_text_to_layout_box(sys::state &state, layout_base &dest, layout_box &box, std::string_view sv, substitution_map const &mp)
Definition: text.cpp:1601
columnar_layout create_columnar_layout(sys::state &state, layout &dest, layout_parameters const &params, int32_t column_width)
Definition: text.cpp:1873
std::string date_to_string(sys::state &state, sys::date date)
Definition: text.cpp:1082
alignment
Definition: text.hpp:36
void localised_single_sub_box(sys::state &state, layout_base &dest, layout_box &box, std::string_view key, variable_type subkey, substitution value)
Definition: text.cpp:1888
void localised_format_box(sys::state &state, layout_base &dest, layout_box &box, std::string_view key, text::substitution_map const &sub)
Definition: text.cpp:1880
std::string prettify(int64_t num)
Definition: text.cpp:762
endless_layout create_endless_layout(sys::state &state, layout &dest, layout_parameters const &params)
Definition: text.cpp:1100
std::string format_float(float num, size_t digits)
Definition: text.cpp:981
dcon::text_key get_ruler_title(sys::state &state, dcon::nation_id n)
Definition: text.cpp:899
void add_line(sys::state &state, layout_base &dest, dcon::text_key txt, int32_t indent)
Definition: text.cpp:1899
std::string get_short_state_name(sys::state &state, dcon::state_instance_id state_id)
Definition: text.cpp:821
uint32_t codepoint_from_utf8(char const *start, char const *end)
Definition: text.cpp:66
void add_line_with_condition(sys::state &state, layout_base &dest, std::string_view key, bool condition_met, int32_t indent)
Definition: text.cpp:1955
void add_line_break_to_layout(sys::state &state, columnar_layout &dest)
Definition: text.cpp:1152
text::alignment to_text_alignment(ui::alignment in)
Definition: text.cpp:1217
text_color char_to_color(char in)
Definition: text.cpp:18
char16_t win1250toUTF16(char in)
Definition: text.cpp:587
void add_to_substitution_map(substitution_map &mp, variable_type key, substitution value)
Definition: text.cpp:1068
void add_divider_to_layout_box(sys::state &state, layout_base &dest, layout_box &box)
Definition: text.cpp:2098
dcon::text_key get_adjective(sys::state &state, dcon::nation_id id)
Definition: text.cpp:890
std::string get_dynamic_state_name(sys::state &state, dcon::state_instance_id state_id)
Definition: text.cpp:837
std::string format_wholenum(int32_t num)
Definition: text.cpp:1033
size_t size_from_utf8(char const *start, char const *)
Definition: text.cpp:82
ankerl::unordered_dense::map< uint32_t, substitution > substitution_map
Definition: text.hpp:794
std::string produce_simple_string(sys::state const &state, dcon::text_key id)
Definition: text.cpp:617
std::string get_adjective_as_string(sys::state &state, T t)
Definition: text.hpp:958
text_color
Definition: text.hpp:18
dcon::text_key get_name(sys::state &state, dcon::nation_id id)
Definition: text.cpp:880
std::string format_percentage(float num, size_t digits)
Definition: text.cpp:977
void consume_csv_file(sys::state &state, char const *file_content, uint32_t file_size, int32_t target_column, bool as_unicode)
Definition: text.cpp:96
text::alignment localized_alignment(sys::state &state, text::alignment in)
Definition: text.cpp:1201
std::string get_influence_level_name(sys::state const &state, uint8_t v)
Definition: text.cpp:958
variable_type variable_type_from_name(std::string_view v)
Definition: text.cpp:137
void add_space_to_layout_box(sys::state &state, layout_base &dest, layout_box &box)
Definition: text.cpp:1788
void nation_name_and_flag(sys::state &state, dcon::nation_id n, layout_base &dest, int32_t indent)
Definition: text.cpp:2104
std::string get_province_state_name(sys::state &state, dcon::province_id prov_id)
Definition: text.cpp:864
dcon::text_key find_or_add_key(sys::state &state, std::string_view key, bool as_unicode)
Definition: text.cpp:695
std::string prettify_currency(float num)
Definition: text.cpp:702
void close_layout_box(columnar_layout &dest, layout_box &box)
Definition: text.cpp:1807
std::variant< std::string_view, dcon::text_key, dcon::province_id, dcon::state_instance_id, dcon::nation_id, dcon::national_identity_id, int64_t, fp_one_place, sys::date, std::monostate, fp_two_places, fp_three_places, fp_four_places, fp_currency, pretty_integer, fp_percentage, fp_percentage_one_place, int_percentage, int_wholenum, dcon::state_definition_id, embedded_icon, embedded_flag, embedded_unit_icon > substitution
Definition: text.hpp:793
#define UINT64_C(x)
uint uint32_t
ulong uint64_t
uchar uint8_t
int32_t column_width
Definition: text.hpp:860
columnar_layout(layout &base_layout, layout_parameters const &fixed_parameters, layout_base::rtl_status native_rtl, int32_t used_height=0, int32_t used_width=0, int32_t y_cursor=0, int32_t column_width=0)
Definition: text.hpp:862
int32_t current_column_x
Definition: text.hpp:859
void internal_close_box(layout_box &box) final
Definition: text.cpp:1863
int32_t used_height
Definition: text.hpp:856
int32_t used_width
Definition: text.hpp:857
dcon::national_identity_id tag
Definition: text.hpp:788
dcon::unit_type_id unit_type
Definition: text.hpp:785
void internal_close_box(layout_box &box) final
Definition: text.cpp:1866
endless_layout(layout &base_layout, layout_parameters const &fixed_parameters, layout_base::rtl_status native_rtl, int32_t y_cursor=0)
Definition: text.hpp:874
int32_t y_cursor
Definition: text.hpp:872
int32_t value
Definition: text.hpp:779
virtual void internal_close_box(layout_box &box)=0
rtl_status native_rtl
Definition: text.hpp:839
layout_parameters fixed_parameters
Definition: text.hpp:838
layout_base(layout &base_layout, layout_parameters const &fixed_parameters, rtl_status native_rtl)
Definition: text.hpp:841
layout & base_layout
Definition: text.hpp:837
size_t first_chunk
Definition: text.hpp:824
size_t line_start
Definition: text.hpp:825
int32_t y_position
Definition: text.hpp:831
int32_t y_size
Definition: text.hpp:828
int32_t x_offset
Definition: text.hpp:826
int32_t x_size
Definition: text.hpp:827
text_color color
Definition: text.hpp:832
float x_position
Definition: text.hpp:830
text_color color
Definition: text.hpp:813
text_chunk const * get_chunk_from_position(int32_t x, int32_t y) const
Definition: text.cpp:1091
std::vector< text_chunk > contents
Definition: text.hpp:818
int32_t number_of_lines
Definition: text.hpp:819
single_line_layout(layout &base_layout, layout_parameters const &fixed_parameters, layout_base::rtl_status native_rtl)
Definition: text.hpp:885
void internal_close_box(layout_box &box) final
Definition: text.cpp:1869
void add_text(sys::state &state, std::string_view v)
Definition: text.cpp:2212
int16_t y
Definition: text.hpp:800
int16_t width
Definition: text.hpp:801
substitution source
Definition: text.hpp:799
text_color color
Definition: text.hpp:803
text::stored_glyphs unicodechars
Definition: text.hpp:797
int16_t height
Definition: text.hpp:802
std::vector< char > & text_data
Definition: text.hpp:682
bool operator()(dcon::text_key l, std::string_view r) const noexcept
Definition: text.hpp:689
bool operator()(std::string const &r, dcon::text_key l) const noexcept
Definition: text.hpp:734
vector_backed_ci_eq(std::vector< char > &text_data)
Definition: text.hpp:684
bool operator()(dcon::text_key l, std::string const &r) const noexcept
Definition: text.hpp:719
bool operator()(std::string_view r, dcon::text_key l) const noexcept
Definition: text.hpp:704
bool operator()(dcon::text_key l, dcon::text_key r) const noexcept
Definition: text.hpp:686
std::vector< char > & text_data
Definition: text.hpp:656
auto operator()(dcon::text_key tag) const noexcept -> uint64_t
Definition: text.hpp:663
auto operator()(std::string_view sv) const noexcept -> uint64_t
Definition: text.hpp:660
vector_backed_ci_hash(std::vector< char > &text_data)
Definition: text.hpp:658
vector_backed_eq(std::vector< char > &text_data)
Definition: text.hpp:472
bool operator()(std::string_view r, dcon::text_key l) const noexcept
Definition: text.hpp:492
bool operator()(dcon::text_key l, std::string const &r) const noexcept
Definition: text.hpp:507
std::vector< char > & text_data
Definition: text.hpp:470
bool operator()(dcon::text_key l, dcon::text_key r) const noexcept
Definition: text.hpp:474
bool operator()(std::string const &r, dcon::text_key l) const noexcept
Definition: text.hpp:522
bool operator()(dcon::text_key l, std::string_view r) const noexcept
Definition: text.hpp:477
auto operator()(dcon::text_key tag) const noexcept -> uint64_t
Definition: text.hpp:451
vector_backed_hash(std::vector< char > &text_data)
Definition: text.hpp:446
std::vector< char > & text_data
Definition: text.hpp:444
auto operator()(std::string_view sv) const noexcept -> uint64_t
Definition: text.hpp:448