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::commodity_id commodity;
789};
791 dcon::national_identity_id tag;
792};
793using substitution = std::variant<std::string_view, dcon::text_key, dcon::province_id, dcon::state_instance_id, dcon::nation_id,
794 dcon::national_identity_id, int64_t, fp_one_place, sys::date, std::monostate, fp_two_places, fp_three_places, fp_four_places,
797using substitution_map = ankerl::unordered_dense::map<uint32_t, substitution>;
798
801 float x = 0; // yes, there is a reason the x offset is a floating point value while the y offset is an integer
802 substitution source = std::monostate{};
803 int16_t y = 0;
804 int16_t width = 0;
805 int16_t height = 0;
807};
809 int16_t left = 0;
810 int16_t top = 0;
811 int16_t right = 0;
812 int16_t bottom = 0;
813 uint16_t font_id = 0;
814 int16_t leading = 0;
818 bool single_line = false;
819};
820struct layout {
821 std::vector<text_chunk> contents;
822 int32_t number_of_lines = 0;
823 text_chunk const* get_chunk_from_position(int32_t x, int32_t y) const;
824};
825
827 size_t first_chunk = 0;
828 size_t line_start = 0;
829 int32_t x_offset = 0;
830 int32_t x_size = 0;
831 int32_t y_size = 0;
832
833 float x_position = 0;
834 int32_t y_position = 0;
836};
837
839 enum class rtl_status : uint8_t { ltr, rtl };
843
851 }
852 }
853 }
854
855 virtual void internal_close_box(layout_box& box) = 0;
856};
857
859 int32_t used_height = 0;
860 int32_t used_width = 0;
861 int32_t y_cursor = 0;
862 int32_t current_column_x = 0;
863 int32_t column_width = 0;
864
869 }
870
871 void internal_close_box(layout_box& box) final;
872};
873
875 int32_t y_cursor = 0;
876
879
880 void internal_close_box(layout_box& box) final;
881};
882
883layout_box open_layout_box(layout_base& dest, int32_t indent = 0);
884
887
890
892 base_layout.contents.clear();
893 }
894
895 void internal_close_box(layout_box& box) final;
896
899 }
900
901 void add_text(sys::state& state, std::string_view v);
902 void add_text(sys::state& state, dcon::text_key source_text);
903};
904
906
907endless_layout create_endless_layout(sys::state& state, layout& dest, layout_parameters const& params);
908void close_layout_box(endless_layout& dest, layout_box& box);
909
910columnar_layout create_columnar_layout(sys::state& state, layout& dest, layout_parameters const& params, int32_t column_width);
911
912void close_layout_box(columnar_layout& dest, layout_box& box);
913void close_layout_box(single_line_layout& dest, layout_box& box);
914void 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{});
915void add_to_layout_box(sys::state& state, layout_base& dest, layout_box& box, dcon::text_key source_text,
916 substitution_map const& mp = substitution_map{});
917void add_to_layout_box(sys::state& state, layout_base& dest, layout_box& box, std::string_view,
918 text_color color = text_color::white, substitution source = std::monostate{});
919void add_to_layout_box(sys::state& state, layout_base& dest, layout_box& box, substitution val,
921void add_to_layout_box(sys::state& state, layout_base& dest, layout_box& box, std::string const& val,
923void add_space_to_layout_box(sys::state& state, layout_base& dest, layout_box& box);
924void add_line_break_to_layout_box(sys::state& state, layout_base& dest, layout_box& box);
925
926void add_line_break_to_layout(sys::state& state, columnar_layout& dest);
927void add_line_break_to_layout(sys::state& state, endless_layout& dest);
928void add_to_layout_box(sys::state& state, layout_base& dest, layout_box& box, embedded_flag ico);
929void add_to_layout_box(sys::state& state, layout_base& dest, layout_box& box, embedded_icon ico);
930
931void close_layout_box(layout_base& dest, layout_box& box);
932
934void add_to_substitution_map(substitution_map& mp, variable_type key, std::string const&); // DO NOT USE THIS FUNCTION
935
936void consume_csv_file(sys::state& state, char const* file_content, uint32_t file_size, int32_t target_column, bool as_unicode);
937variable_type variable_type_from_name(std::string_view);
938char16_t win1250toUTF16(char in);
939std::string produce_simple_string(sys::state const& state, std::string_view key);
940std::string produce_simple_string(sys::state const& state, dcon::text_key id);
944
945dcon::text_key find_or_add_key(sys::state& state, std::string_view key, bool as_unicode);
946
948
949std::string prettify(int64_t num);
950std::string prettify_currency(float num);
951std::string format_money(float num);
952std::string format_wholenum(int32_t num);
953std::string format_percentage(float num, size_t digits = 2);
954std::string format_float(float num, size_t digits = 2);
955std::string format_ratio(int32_t left, int32_t right);
956template<class T>
958 return text::produce_simple_string(state, t.get_name());
959}
960template<class T>
962 return text::produce_simple_string(state, t.get_adjective());
963}
964std::string get_short_state_name(sys::state& state, dcon::state_instance_id state_id);
965std::string get_dynamic_state_name(sys::state& state, dcon::state_instance_id state_id);
966std::string get_province_state_name(sys::state& state, dcon::province_id prov_id);
968std::string get_influence_level_name(sys::state const& state, uint8_t v);
969dcon::text_key get_name(sys::state& state, dcon::nation_id n);
970dcon::text_key get_adjective(sys::state& state, dcon::nation_id n);
971dcon::text_key get_ruler_title(sys::state& state, dcon::nation_id n);
972inline std::string get_name_as_string(sys::state& state, dcon::nation_id n) {
974}
975inline std::string get_adjective_as_string(sys::state& state, dcon::nation_id n) {
977}
978inline std::string get_name_as_string(sys::state& state, dcon::nation_fat_id n) {
980}
981inline std::string get_adjective_as_string(sys::state& state, dcon::nation_fat_id n) {
983}
984
985void localised_format_box(sys::state& state, layout_base& dest, layout_box& box, std::string_view key,
987void localised_single_sub_box(sys::state& state, layout_base& dest, layout_box& box, std::string_view key, variable_type subkey,
989
990void nation_name_and_flag(sys::state& state, dcon::nation_id n, layout_base& dest, int32_t indent = 0);
991
992void add_line(sys::state& state, layout_base& dest, std::string_view key, int32_t indent = 0);
993void add_line(sys::state& state, layout_base& dest, std::string_view key, variable_type subkey, substitution value,
994 int32_t indent = 0);
995void add_line(sys::state& state, layout_base& dest, std::string_view key, variable_type subkey, substitution value,
996 variable_type subkey_b, substitution value_b, int32_t indent = 0);
997void add_line(sys::state& state, layout_base& dest, std::string_view key, variable_type subkey, substitution value,
998 variable_type subkey_b, substitution value_b, variable_type subkey_c, substitution value_c, int32_t indent = 0);
999void add_line(sys::state& state, layout_base& dest, std::string_view key, variable_type subkey, substitution value,
1000 variable_type subkey_b, substitution value_b, variable_type subkey_c, substitution value_c, variable_type subkey_d,
1001 substitution value_d, int32_t indent = 0);
1002void add_line(sys::state& state, layout_base& dest, dcon::text_key txt, int32_t indent = 0);
1003void add_line(sys::state& state, layout_base& dest, dcon::text_key txt, variable_type subkey, substitution value,
1004 int32_t indent = 0);
1005void add_line(sys::state& state, layout_base& dest, dcon::text_key txt, variable_type subkey, substitution value,
1006 variable_type subkey_b, substitution value_b, int32_t indent = 0);
1007void add_line(sys::state& state, layout_base& dest, dcon::text_key txt, variable_type subkey, substitution value,
1008 variable_type subkey_b, substitution value_b, variable_type subkey_c, substitution value_c, int32_t indent = 0);
1009void add_line(sys::state& state, layout_base& dest, dcon::text_key txt, variable_type subkey, substitution value,
1010 variable_type subkey_b, substitution value_b, variable_type subkey_c, substitution value_c, variable_type subkey_d,
1011 substitution value_d, int32_t indent = 0);
1012void add_line_with_condition(sys::state& state, layout_base& dest, std::string_view key, bool condition_met, int32_t indent = 0);
1013void 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);
1014void 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);
1015void 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);
1016size_t size_from_utf8(char const* start, char const* end);
1017
1018void add_divider_to_layout_box(sys::state& state, layout_base& dest, layout_box& box);
1019
1020std::string resolve_string_substitution(sys::state& state, std::string_view key, substitution_map const& mp);
1021std::string resolve_string_substitution(sys::state& state, dcon::text_key key, substitution_map const& mp);
1022
1023uint32_t codepoint_from_utf8(char const* start, char const* end);
1024size_t size_from_utf8(char const* start, char const*);
1025
1026} // namespace text
detail namespace with internal helper functions
Definition: json.hpp:253
focus_type
Definition: nations.hpp:44
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:2137
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:957
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:1823
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:1612
columnar_layout create_columnar_layout(sys::state &state, layout &dest, layout_parameters const &params, int32_t column_width)
Definition: text.cpp:1897
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:1912
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:1904
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:1923
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:1979
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:1228
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:2122
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:797
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:961
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:1212
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:1812
void nation_name_and_flag(sys::state &state, dcon::nation_id n, layout_base &dest, int32_t indent)
Definition: text.cpp:2128
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:1831
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, embedded_commodity_icon > substitution
Definition: text.hpp:796
#define UINT64_C(x)
uint uint32_t
ulong uint64_t
uchar uint8_t
Holds important data about the game world, state, and other data regarding windowing,...
int32_t column_width
Definition: text.hpp:863
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:865
int32_t current_column_x
Definition: text.hpp:862
void internal_close_box(layout_box &box) final
Definition: text.cpp:1887
int32_t used_height
Definition: text.hpp:859
int32_t used_width
Definition: text.hpp:860
dcon::commodity_id commodity
Definition: text.hpp:788
dcon::national_identity_id tag
Definition: text.hpp:791
dcon::unit_type_id unit_type
Definition: text.hpp:785
void internal_close_box(layout_box &box) final
Definition: text.cpp:1890
endless_layout(layout &base_layout, layout_parameters const &fixed_parameters, layout_base::rtl_status native_rtl, int32_t y_cursor=0)
Definition: text.hpp:877
int32_t y_cursor
Definition: text.hpp:875
int32_t value
Definition: text.hpp:779
virtual void internal_close_box(layout_box &box)=0
rtl_status native_rtl
Definition: text.hpp:842
layout_parameters fixed_parameters
Definition: text.hpp:841
layout_base(layout &base_layout, layout_parameters const &fixed_parameters, rtl_status native_rtl)
Definition: text.hpp:844
layout & base_layout
Definition: text.hpp:840
size_t first_chunk
Definition: text.hpp:827
size_t line_start
Definition: text.hpp:828
int32_t y_position
Definition: text.hpp:834
int32_t y_size
Definition: text.hpp:831
int32_t x_offset
Definition: text.hpp:829
int32_t x_size
Definition: text.hpp:830
text_color color
Definition: text.hpp:835
float x_position
Definition: text.hpp:833
text_color color
Definition: text.hpp:816
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:821
int32_t number_of_lines
Definition: text.hpp:822
single_line_layout(layout &base_layout, layout_parameters const &fixed_parameters, layout_base::rtl_status native_rtl)
Definition: text.hpp:888
void internal_close_box(layout_box &box) final
Definition: text.cpp:1893
void add_text(sys::state &state, std::string_view v)
Definition: text.cpp:2236
int16_t y
Definition: text.hpp:803
int16_t width
Definition: text.hpp:804
substitution source
Definition: text.hpp:802
text_color color
Definition: text.hpp:806
text::stored_glyphs unicodechars
Definition: text.hpp:800
int16_t height
Definition: text.hpp:805
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