From 702232fc2d42cf694d17bc84469a07a0d958588f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=28=C2=B4=E3=83=BB=CF=89=E3=83=BB=EF=BD=80=29?= Date: Sat, 21 Aug 2021 17:32:09 +0900 Subject: [PATCH] ADD: company abbreviation can be registered (only registered, not used yet) --- gui/password_frame.cc | 24 ++++++++++++++++++++++++ gui/password_frame.h | 5 +++-- player/simplay.cc | 14 ++++++++++++++ player/simplay.h | 5 +++++ 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/gui/password_frame.cc b/gui/password_frame.cc index a3f236e1c9..bf1b2bebfb 100644 --- a/gui/password_frame.cc +++ b/gui/password_frame.cc @@ -39,6 +39,19 @@ password_frame_t::password_frame_t( player_t *player ) : const_player_name.set_text( player->get_name() ); add_component(&const_player_name, 2); } + new_component("Company abbreviation"); + if( !player->is_locked() || (welt->get_active_player_nr()==1 && !welt->get_public_player()->is_locked()) ) { + tstrncpy( player_short_name_str, player->get_short_name(), lengthof(player_short_name_str) ); + player_short_name.set_text(player_short_name_str, lengthof(player_short_name_str)); + player_short_name.add_listener(this); + add_component(&player_short_name); + } + else { + const_player_short_name.set_text( player->get_short_name() ); + const_player_short_name.set_color( color_idx_to_rgb(player->get_player_color1()+env_t::gui_player_color_dark) ); + const_player_short_name.set_shadow(SYSCOL_SHADOW, true); + add_component(&const_player_short_name); + } fnlabel.set_text( "Password" ); // so we have a width now add_component(&fnlabel); @@ -113,6 +126,17 @@ bool password_frame_t::action_triggered( gui_action_creator_t *comp, value_t p ) delete tmp_tool; } + if( comp == &player_short_name ) { + if (!player->is_locked() || (welt->get_active_player_nr() == 1 && !welt->get_public_player()->is_locked())) { + // set a company abbreviation + player->set_short_name(player_short_name.get_text()); + } + else{ + // permission error, the input field is not displayed for locked players though... + dbg->warning("password_frame_t::action_triggered", "The locked player%i's abbreviation was about to change by player%u", player->get_player_nr(), welt->get_active_player_nr()); + } + } + if( p.i==1 ) { // destroy window after enter is pressed destroy_win(this); diff --git a/gui/password_frame.h b/gui/password_frame.h index a1f1c37bab..84760abb1d 100644 --- a/gui/password_frame.h +++ b/gui/password_frame.h @@ -17,14 +17,15 @@ class password_frame_t : public gui_frame_t, action_listener_t { private: - char ibuf[256], player_name_str[256]; + char ibuf[256], player_name_str[256], player_short_name_str[7]; protected: player_t *player; gui_textinput_t player_name; + gui_textinput_t player_short_name; gui_hidden_textinput_t password; - gui_label_t fnlabel, const_player_name; + gui_label_t fnlabel, const_player_name, const_player_short_name; public: password_frame_t( player_t *player ); diff --git a/player/simplay.cc b/player/simplay.cc index 775771e9d2..94d3d5c48b 100644 --- a/player/simplay.cc +++ b/player/simplay.cc @@ -192,6 +192,16 @@ void player_t::set_name(const char *new_name) } } +void player_t::set_short_name(const char *new_name) +{ + tstrncpy( player_short_name_buf, new_name, lengthof(player_short_name_buf) ); + + // update player window + if (ki_kontroll_t *frame = dynamic_cast(win_get_magic(magic_ki_kontroll_t))) { + frame->update_data(); + } +} + player_t::income_message_t::income_message_t( sint64 betrag, koord p ) { @@ -756,6 +766,10 @@ DBG_DEBUG("player_t::rdwr()","player %i: loading %i halts.",welt->sp2num( this ) if( file->is_version_atleast(112, 2) ) { file->rdwr_short( player_age ); } + + if( file->is_version_atleast(122, 1) ) { + file->rdwr_str(player_short_name_buf, lengthof(player_short_name_buf)); + } } diff --git a/player/simplay.h b/player/simplay.h index 8527e95d45..be967646ed 100644 --- a/player/simplay.h +++ b/player/simplay.h @@ -49,6 +49,7 @@ class player_t protected: char player_name_buf[256]; + char player_short_name_buf[7] = "\0"; /* "new" finance history */ finance_t *finance; @@ -238,6 +239,10 @@ class player_t const char* get_name() const; void set_name(const char *); + // @return the player abbreviation + const char* get_short_name() const { return player_short_name_buf; } + void set_short_name(const char *); + sint8 get_player_nr() const {return player_nr; } /**