main_gui.c
changeset 1799 6d82d202c145
parent 1793 b9a37c98b468
child 1820 d03c56850dc2
equal deleted inserted replaced
1798:7098e1e359eb 1799:6d82d202c145
    57 		break;
    57 		break;
    58 #endif /* ENABLE_NETWORK */
    58 #endif /* ENABLE_NETWORK */
    59 	}
    59 	}
    60 }
    60 }
    61 
    61 
    62 void HandleOnEditText(WindowEvent *e) {
    62 void HandleOnEditText(WindowEvent *e)
       
    63 {
    63 	const char *b = e->edittext.str;
    64 	const char *b = e->edittext.str;
    64 	int id;
    65 	int id;
    65 	memcpy(_decode_parameters, b, 32);
    66 	memcpy(_decode_parameters, b, 32);
    66 
    67 
    67 	id = _rename_id;
    68 	id = _rename_id;
    68 
    69 
    69 	switch(_rename_what) {
    70 	switch (_rename_what) {
    70 	case 0:
    71 	case 0: /* Rename a s sign, if string is empty, delete sign */
    71 		// for empty string send "remove sign" parameter
       
    72 		DoCommandP(0, id, 0, NULL, CMD_RENAME_SIGN | CMD_MSG(STR_280C_CAN_T_CHANGE_SIGN_NAME));
    72 		DoCommandP(0, id, 0, NULL, CMD_RENAME_SIGN | CMD_MSG(STR_280C_CAN_T_CHANGE_SIGN_NAME));
    73 		break;
    73 		break;
    74 	case 1:
    74 	case 1: /* Rename a waypoint */
    75 		if(*b == 0)
    75 		if (*b == 0) return;
    76 			return;
       
    77 		DoCommandP(0, id, 0, NULL, CMD_RENAME_WAYPOINT | CMD_MSG(STR_CANT_CHANGE_WAYPOINT_NAME));
    76 		DoCommandP(0, id, 0, NULL, CMD_RENAME_WAYPOINT | CMD_MSG(STR_CANT_CHANGE_WAYPOINT_NAME));
    78 		break;
    77 		break;
    79 #ifdef ENABLE_NETWORK
    78 #ifdef ENABLE_NETWORK
    80 	case 2:
    79 	case 2: /* Speak to.. */
    81 		// Speak to..
       
    82 		if (!_network_server)
    80 		if (!_network_server)
    83 			SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_CHAT + (id & 0xFF), id & 0xFF, (id >> 8) & 0xFF, e->edittext.str);
    81 			SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_CHAT + (id & 0xFF), id & 0xFF, (id >> 8) & 0xFF, e->edittext.str);
    84 		else
    82 		else
    85 			NetworkServer_HandleChat(NETWORK_ACTION_CHAT + (id & 0xFF), id & 0xFF, (id >> 8) & 0xFF, e->edittext.str, NETWORK_SERVER_INDEX);
    83 			NetworkServer_HandleChat(NETWORK_ACTION_CHAT + (id & 0xFF), id & 0xFF, (id >> 8) & 0xFF, e->edittext.str, NETWORK_SERVER_INDEX);
    86 		break;
    84 		break;
    87 	case 3: {
    85 	case 3: { /* Give money, you can only give money in excess of loan */
    88 		// Give money
    86 		const Player *p = DEREF_PLAYER(_current_player);
    89 		int32 money = atoi(e->edittext.str) / GetCurrentCurrencyRate();
    87 		int32 money = min(p->money64 - p->current_loan, atoi(e->edittext.str) / GetCurrentCurrencyRate());
    90 		char msg[100];
    88 		char msg[20];
    91 
    89 
    92 		money = clamp(money, 0, 0xFFFFFF); // Clamp between 16 million and 0
    90 		money = clamp(money, 0, 20000000); // Clamp between 20 million and 0
    93 
    91 
    94 		// Give 'id' the money, and substract it from ourself
    92 		// Give 'id' the money, and substract it from ourself
    95 		if (!DoCommandP(0, money, id, NULL, CMD_GIVE_MONEY)) break;
    93 		if (!DoCommandP(0, money, id, NULL, CMD_GIVE_MONEY | CMD_MSG(STR_INSUFFICIENT_FUNDS))) break;
    96 
    94 
    97 		// Inform the player of this action
    95 		// Inform the player of this action
    98 		snprintf(msg, 100, "%d", money);
    96 		snprintf(msg, sizeof(msg), "%d", money);
    99 
    97 
   100 		if (!_network_server)
    98 		if (!_network_server)
   101 			SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_PLAYER, id + 1, msg);
    99 			SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_PLAYER, id + 1, msg);
   102 		else
   100 		else
   103 			NetworkServer_HandleChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_PLAYER, id + 1, msg, NETWORK_SERVER_INDEX);
   101 			NetworkServer_HandleChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_PLAYER, id + 1, msg, NETWORK_SERVER_INDEX);
   104 		break;
   102 		break;
   105 	}
   103 	}
   106 	case 4: {// Game-Password and Company-Password
   104 	case 4: /* Game-Password and Company-Password */
   107 		SEND_COMMAND(PACKET_CLIENT_PASSWORD)(id, e->edittext.str);
   105 		SEND_COMMAND(PACKET_CLIENT_PASSWORD)(id, e->edittext.str);
   108 		break;
   106 		break;
   109 	}
       
   110 #endif /* ENABLE_NETWORK */
   107 #endif /* ENABLE_NETWORK */
   111 	}
   108 	}
   112 }
   109 }
   113 
   110 
   114 /**
   111 /**