Player12
An open source football management simulator
Loading...
Searching...
No Matches
transfer_terms_editor.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2// Football Management Project
3// Copyright (c) 2025 - 2026 Flavio Milinanni. All Rights Reserved.
4//
5// This file is part of the Football Management Project.
6// See the LICENSE file in the project root.
7// -----------------------------------------------------------------------------
8
9#pragma once
10
11#include <array>
12#include <cstddef>
13#include <cstdint>
14#include <cstdlib>
15#include <initializer_list>
16#include <span>
17#include <string>
18
19#include "gui/widgets/widgets.h"
21
28namespace TransferTermsEditor
29{
30// Every value the buyer AI can propose is a segment (aiOfferTerms pays 50%
31// upfront, a spread goes down to 30% and 20%, a sell-on cut ends on 5% or
32// 25%): the highlighted segment is always the value that will be sent.
33inline constexpr std::array<std::uint8_t, 7> UPFRONT_OPTIONS = {100, 80, 60, 50,
34 40, 30, 20};
35inline constexpr std::array<const char*, 7> UPFRONT_LABELS = {
36 "100%", "80%", "60%", "50%", "40%", "30%", "20%"};
37inline constexpr std::array<const char*, 5> YEAR_LABELS = {"1", "2", "3", "4",
38 "5"};
39inline constexpr std::array<std::uint16_t, 4> APPEARANCE_TARGETS = {10, 20, 30,
40 50};
41inline constexpr std::array<std::uint16_t, 4> GOAL_TARGETS = {5, 10, 15, 20};
42inline constexpr std::array<std::uint8_t, 7> SELL_ON_OPTIONS = {0, 5, 10, 15,
43 20, 25, 30};
44inline constexpr std::array<const char*, 7> SELL_ON_LABELS = {
45 "0%", "5%", "10%", "15%", "20%", "25%", "30%"};
46inline constexpr std::uint8_t DEFAULT_INSTALMENT_YEARS = 2;
47inline constexpr std::int64_t FEE_STEP = 10'000;
48
50template <typename T, typename V>
51int optionIndex(std::span<const T> options, V value)
52{
53 std::size_t best = 0;
54 for (std::size_t index = 1; index < options.size(); ++index)
55 {
56 if (std::abs(static_cast<int>(options[index]) - static_cast<int>(value)) <
57 std::abs(static_cast<int>(options[best]) - static_cast<int>(value)))
58 best = index;
59 }
60 return static_cast<int>(best);
61}
62
63template <typename T, std::size_t N, typename V>
64int optionIndex(const std::array<T, N>& options, V value)
65{
66 return optionIndex(std::span<const T>(options), value);
67}
68
70void formLabel(const char* text);
71
74void alignActions(std::initializer_list<const char*> labels);
75
81bool beginPanel(const char* id, const char* title);
82void endPanel();
83
91
98 std::span<const UI::MoneyChip> fee_chips);
99
101std::string structureText(const TransferNegotiation::OfferTerms& terms);
102
103// Loan terms: the borrower proposes shares in steps of LOAN_WAGE_SHARE_STEP
104// and guaranteed appearances among MIN_APPEARANCE_OPTIONS.
105inline constexpr int LOAN_WAGE_SHARE_STEP = 5;
106inline constexpr std::array<std::uint8_t, 7> MIN_APPEARANCE_OPTIONS = {
107 0, 5, 10, 15, 20, 25, 30};
108
111
119 std::uint32_t market_value);
120
123std::string loanTermsLine(const TransferNegotiation::LoanTerms& terms);
124
125} // namespace TransferTermsEditor
Pieces shared by the transfer dialogs: the structured offer editor (fee, upfront share,...
Definition transfer_terms_editor.cpp:23
constexpr std::array< std::uint8_t, 7 > MIN_APPEARANCE_OPTIONS
Definition transfer_terms_editor.h:106
void alignActions(std::initializer_list< const char * > labels)
Definition transfer_terms_editor.cpp:31
void endPanel()
Definition transfer_terms_editor.cpp:67
bool editLoan(TransferNegotiation::LoanTerms &terms, std::uint32_t market_value)
Definition transfer_terms_editor.cpp:242
constexpr std::int64_t FEE_STEP
Definition transfer_terms_editor.h:47
bool snapToOptions(TransferNegotiation::OfferTerms &terms)
Definition transfer_terms_editor.cpp:111
int optionIndex(std::span< const T > options, V value)
Definition transfer_terms_editor.h:51
bool edit(TransferNegotiation::OfferTerms &terms, std::span< const UI::MoneyChip > fee_chips)
Definition transfer_terms_editor.cpp:132
constexpr std::array< std::uint16_t, 4 > APPEARANCE_TARGETS
Definition transfer_terms_editor.h:39
constexpr std::array< const char *, 7 > SELL_ON_LABELS
Definition transfer_terms_editor.h:44
constexpr std::uint8_t DEFAULT_INSTALMENT_YEARS
Definition transfer_terms_editor.h:46
constexpr std::array< const char *, 5 > YEAR_LABELS
Definition transfer_terms_editor.h:37
constexpr std::array< std::uint16_t, 4 > GOAL_TARGETS
Definition transfer_terms_editor.h:41
constexpr std::array< std::uint8_t, 7 > UPFRONT_OPTIONS
Definition transfer_terms_editor.h:33
std::string structureText(const TransferNegotiation::OfferTerms &terms)
Definition transfer_terms_editor.cpp:390
std::string loanTermsLine(const TransferNegotiation::LoanTerms &terms)
Definition transfer_terms_editor.cpp:369
constexpr std::array< std::uint8_t, 7 > SELL_ON_OPTIONS
Definition transfer_terms_editor.h:42
constexpr std::array< const char *, 7 > UPFRONT_LABELS
Definition transfer_terms_editor.h:35
bool snapLoanToOptions(TransferNegotiation::LoanTerms &terms)
Definition transfer_terms_editor.cpp:225
constexpr int LOAN_WAGE_SHARE_STEP
Definition transfer_terms_editor.h:105
int index
Definition runtime_editor.cpp:94
Definition transfer_negotiation.h:299
A club-to-club offer: fee, instalments, add-ons and sell-on.
Definition transfer_negotiation.h:100
std::array< const char *, 6 > labels
Definition transfer_terms_editor.cpp:77