Widget* TeamBox::ClickUp(const Point2i &mousePosition, uint button) { if (associated_team) { if (!associated_team->IsLocal()) return NULL; // it's not a local team, we can't configure it !! Widget* w = WidgetList::ClickUp(mousePosition, button); if (w == nb_characters) { if (Network::GetInstance()->IsConnected()) { ValidOptions(); } return w; } if (w == player_name) { return w; } if (w == nullw) { if (button == Mouse::BUTTON_LEFT()) { if (group == MAX_TEAM_GROUPS-1) group = 0; else group++; } else { if (group == 0) group = MAX_TEAM_GROUPS-1; else group--; } SetGroup(group); UpdateTeam(associated_team->GetId()); } if (!w) { return w; } if (!custom_team_list.empty()) { if (w == next_custom_team) { player_name->SetText(custom_team_list[custom_team_current_id]->GetName()); if (custom_team_current_id == custom_team_list.size()-1) { custom_team_current_id = 0; } else { custom_team_current_id++; } } if (w == previous_custom_team) { player_name->SetText(custom_team_list[custom_team_current_id]->GetName()); if (custom_team_current_id == 0) { custom_team_current_id = custom_team_list.size()-1; } else { custom_team_current_id--; } } } } return NULL; }
void TeamBox::SetTeam(Team& _team, bool read_team_values) { Team* old_team = associated_team; associated_team = &_team; if (_team.IsRemote()) { team_name->SetFont(dark_gray_color, Font::FONT_MEDIUM, Font::FONT_BOLD, false); // translators: this is the team listing and will expand in a context like "OOo team - Remote" team_name->SetText(Format(_("%s Team - Remote"), _team.GetName().c_str())); if (previous_custom_team) { previous_custom_team->SetVisible(false); next_custom_team->SetVisible(false); } } else { team_name->SetFont(primary_red_color, Font::FONT_MEDIUM, Font::FONT_BOLD, true); team_name->SetText(Format(_("%s Team"), _team.GetName().c_str())); if (previous_custom_team) { previous_custom_team->SetVisible(true); next_custom_team->SetVisible(true); } } UpdatePlayerType(); team_logo->SetSurface(_team.GetFlag()); // Update group SetGroup(_team.GetGroup()); if (read_team_values) { player_name->SetText(_team.GetPlayerName()); nb_characters->SetValue(_team.GetNbCharacters()); for (uint i=0; i<4; i++) { if (ai_names[i] == _team.GetAIName()) { SetAILevel(i); break; } } } else if (old_team) { UpdateTeam(old_team->GetId()); } previous_player_name = player_name->GetText(); NeedRedrawing(); }
void D_ReadUserInfoStrings (int pnum, BYTE **stream, bool update) { userinfo_t *info = &players[pnum].userinfo; TArray<FName> compact_names(info->CountUsed()); FBaseCVar **cvar_ptr; const char *ptr = *((const char **)stream); const char *breakpt; FString value; bool compact; FName keyname; unsigned int infotype = 0; if (*ptr++ != '\\') return; compact = (*ptr == '\\') ? ptr++, true : false; // We need the cvar names in sorted order for compact mode if (compact) { TMap<FName, FBaseCVar *>::Iterator it(*info); TMap<FName, FBaseCVar *>::Pair *pair; while (it.NextPair(pair)) { compact_names.Push(pair->Key); } qsort(&compact_names[0], compact_names.Size(), sizeof(FName), namesortfunc); } if (pnum < MAXPLAYERS) { for (breakpt = ptr; breakpt != NULL; ptr = breakpt + 1) { breakpt = strchr(ptr, '\\'); if (compact) { // Compact has just the value. if (infotype >= compact_names.Size()) { // Too many entries! OMG! break; } keyname = compact_names[infotype++]; value = D_UnescapeUserInfo(ptr, breakpt != NULL ? breakpt - ptr : strlen(ptr)); } else { // Verbose has both the key name and its value. assert(breakpt != NULL); // A malicious remote machine could invalidate the above assert. if (breakpt == NULL) { break; } const char *valstart = breakpt + 1; if ( (breakpt = strchr (valstart, '\\')) != NULL ) { value = D_UnescapeUserInfo(valstart, breakpt - valstart); } else { value = D_UnescapeUserInfo(valstart, strlen(valstart)); } keyname = FName(ptr, valstart - ptr - 1, true); } // A few of these need special handling. switch (keyname) { case NAME_Gender: info->GenderChanged(value); break; case NAME_PlayerClass: info->PlayerClassChanged(value); break; case NAME_Skin: info->SkinChanged(value); if (players[pnum].mo != NULL) { if (players[pnum].cls != NULL && !(players[pnum].mo->flags4 & MF4_NOSKIN) && players[pnum].mo->state->sprite == GetDefaultByType (players[pnum].cls)->SpawnState->sprite) { // Only change the sprite if the player is using a standard one players[pnum].mo->sprite = skins[info->GetSkin()].sprite; } } // Rebuild translation in case the new skin uses a different range // than the old one. R_BuildPlayerTranslation(pnum); break; case NAME_Team: UpdateTeam(pnum, atoi(value), update); break; case NAME_Color: info->ColorChanged(value); break; default: cvar_ptr = info->CheckKey(keyname); if (cvar_ptr != NULL) { assert(*cvar_ptr != NULL); UCVarValue val; FString oldname; if (keyname == NAME_Name) { val = (*cvar_ptr)->GetGenericRep(CVAR_String); oldname = val.String; } val.String = CleanseString(value.LockBuffer()); (*cvar_ptr)->SetGenericRep(val, CVAR_String); value.UnlockBuffer(); if (keyname == NAME_Name && update && oldname != value) { Printf("%s is now known as %s\n", oldname.GetChars(), value.GetChars()); } } break; } if (keyname == NAME_Color || keyname == NAME_ColorSet) { R_BuildPlayerTranslation(pnum); if (StatusBar != NULL && pnum == StatusBar->GetPlayer()) { StatusBar->AttachToPlayer(&players[pnum]); } } } } *stream += strlen (*((char **)stream)) + 1; }
static const char *SetServerVar (char *name, ECVarType type, BYTE **stream, bool singlebit) { FBaseCVar *var = FindCVar (name, NULL); UCVarValue value; if (singlebit) { if (var != NULL) { int bitdata; int mask; value = var->GetFavoriteRep (&type); if (type != CVAR_Int) { return NULL; } bitdata = ReadByte (stream); mask = 1 << (bitdata & 31); if (bitdata & 32) { value.Int |= mask; } else { value.Int &= ~mask; } } } else { switch (type) { case CVAR_Bool: value.Bool = ReadByte (stream) ? 1 : 0; break; case CVAR_Int: value.Int = ReadLong (stream); break; case CVAR_Float: value.Float = ReadFloat (stream); break; case CVAR_String: value.String = ReadString (stream); break; default: break; // Silence GCC } } if (var) { var->ForceSet (value, type); } if (type == CVAR_String) { delete[] value.String; } if (var == &teamplay) { // Put players on teams if teamplay turned on for (int i = 0; i < MAXPLAYERS; ++i) { if (playeringame[i]) { UpdateTeam (i, players[i].userinfo.GetTeam(), true); } } } if (var) { value = var->GetGenericRep (CVAR_String); return value.String; } return NULL; }
void TeamBox::ValidOptions() const { UpdateTeam(associated_team->GetId()); }
void D_ReadUserInfoStrings (int i, BYTE **stream, bool update) { userinfo_t *info = &players[i].userinfo; const char *ptr = *((const char **)stream); const char *breakpt; FString value; bool compact; int infotype = -1; if (*ptr++ != '\\') return; compact = (*ptr == '\\') ? ptr++, true : false; if (i < MAXPLAYERS) { for (;;) { int j; breakpt = strchr (ptr, '\\'); if (compact) { value = D_UnescapeUserInfo(ptr, breakpt != NULL ? breakpt - ptr : strlen(ptr)); infotype++; } else { assert(breakpt != NULL); // A malicious remote machine could invalidate the above assert. if (breakpt == NULL) { break; } const char *valstart = breakpt + 1; if ( (breakpt = strchr (valstart, '\\')) != NULL ) { value = D_UnescapeUserInfo(valstart, breakpt - valstart); } else { value = D_UnescapeUserInfo(valstart, strlen(valstart)); } for (j = 0; UserInfoStrings[j] && strnicmp (UserInfoStrings[j], ptr, valstart - ptr - 1) != 0; ++j) { } if (UserInfoStrings[j] == NULL) { infotype = -1; } else { infotype = j; } } switch (infotype) { case INFO_Autoaim: { double angles; angles = atof (value); if (angles > 35.f || angles < 0.f) { info->aimdist = ANGLE_1*35; } else { info->aimdist = abs ((int)(angles * (float)ANGLE_1)); } } break; case INFO_Name: { char oldname[MAXPLAYERNAME+1]; strcpy (oldname, info->netname); strncpy (info->netname, value, MAXPLAYERNAME); info->netname[MAXPLAYERNAME] = 0; CleanseString(info->netname); if (update && strcmp (oldname, info->netname) != 0) { Printf ("%s is now known as %s\n", oldname, info->netname); } } break; case INFO_Team: UpdateTeam (i, atoi(value), update); break; case INFO_Color: info->color = V_GetColorFromString (NULL, value); R_BuildPlayerTranslation (i); if (StatusBar != NULL && i == StatusBar->GetPlayer()) { StatusBar->AttachToPlayer (&players[i]); } break; case INFO_Skin: info->skin = R_FindSkin (value, players[i].CurrentPlayerClass); if (players[i].mo != NULL) { if (players[i].cls != NULL && players[i].mo->state->sprite == GetDefaultByType (players[i].cls)->SpawnState->sprite) { // Only change the sprite if the player is using a standard one players[i].mo->sprite = skins[info->skin].sprite; players[i].mo->scaleX = skins[info->skin].ScaleX; players[i].mo->scaleY = skins[info->skin].ScaleY; } } // Rebuild translation in case the new skin uses a different range // than the old one. R_BuildPlayerTranslation (i); if (StatusBar != NULL && i == StatusBar->GetPlayer()) { StatusBar->SetFace (&skins[info->skin]); } break; case INFO_Gender: info->gender = D_GenderToInt (value); break; case INFO_NeverSwitchOnPickup: if (value[0] >= '0' && value[0] <= '9') { info->neverswitch = atoi (value) ? true : false; } else if (stricmp (value, "true") == 0) { info->neverswitch = 1; } else { info->neverswitch = 0; } break; case INFO_MoveBob: info->MoveBob = (fixed_t)(atof (value) * 65536.f); break; case INFO_StillBob: info->StillBob = (fixed_t)(atof (value) * 65536.f); break; case INFO_PlayerClass: info->PlayerClass = D_PlayerClassToInt (value); break; default: break; } if (breakpt) { ptr = breakpt + 1; } else { break; } } } *stream += strlen (*((char **)stream)) + 1; }