From: Stas'M Date: Sat, 13 Jan 2018 14:57:33 +0000 (+0300) Subject: Chat sounds: Add config and menu option X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=5fe57354d3d9d2bc1d3d1828e17e5aebec306d6f;p=d2df-sdl.git Chat sounds: Add config and menu option --- diff --git a/src/game/g_game.pas b/src/game/g_game.pas index b1f5f9f..12e8798 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -310,6 +310,7 @@ var gVotesEnabled: Boolean = True; gEvents: Array of TGameEvent; gDelayedEvents: Array of TDelayedEvent; + gUseChatSounds: Boolean = True; gChatSounds: Array of TChatSound; // move button values: @@ -6958,25 +6959,40 @@ begin end; procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True); +const + punct: Array[0..13] of String = + ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^'); var i, j: Integer; ok: Boolean; fpText: String; + function IsPunctuation(S: String): Boolean; + var + i: Integer; + begin + Result := False; + if Length(S) <> 1 then + Exit; + for i := Low(punct) to High(punct) do + if S = punct[i] then + begin + Result := True; + break; + end; + end; function FilterPunctuation(S: String): String; + var + i: Integer; begin - S := StringReplace(S, '.', ' ', [rfReplaceAll]); - S := StringReplace(S, ',', ' ', [rfReplaceAll]); - S := StringReplace(S, ':', ' ', [rfReplaceAll]); - S := StringReplace(S, ';', ' ', [rfReplaceAll]); - S := StringReplace(S, '!', ' ', [rfReplaceAll]); - S := StringReplace(S, '?', ' ', [rfReplaceAll]); + for i := Low(punct) to High(punct) do + S := StringReplace(S, punct[i], ' ', [rfReplaceAll]); Result := S; end; begin - g_Sound_PlayEx('SOUND_GAME_RADIO'); + ok := False; - if Taunt and (gChatSounds <> nil) and (Pos(': ', Text) > 0) then + if gUseChatSounds and Taunt and (gChatSounds <> nil) and (Pos(': ', Text) > 0) then begin // remove player name Delete(Text, 1, Pos(': ', Text) + 2 - 1); @@ -6989,10 +7005,7 @@ begin ok := True; for j := 0 to Length(gChatSounds[i].Tags) - 1 do begin - if gChatSounds[i].FullWord and - (gChatSounds[i].Tags[j] <> '.') and (gChatSounds[i].Tags[j] <> ',') and - (gChatSounds[i].Tags[j] <> ':') and (gChatSounds[i].Tags[j] <> ';') and - (gChatSounds[i].Tags[j] <> '!') and (gChatSounds[i].Tags[j] <> '?') then + if gChatSounds[i].FullWord and (not IsPunctuation(gChatSounds[i].Tags[j])) then ok := Pos(' ' + gChatSounds[i].Tags[j] + ' ', fpText) > 0 else ok := Pos(gChatSounds[i].Tags[j], Text) > 0; @@ -7006,6 +7019,8 @@ begin end; end; end; + if not ok then + g_Sound_PlayEx('SOUND_GAME_RADIO'); end; procedure g_Game_Announce_GoodShot(SpawnerUID: Word); diff --git a/src/game/g_language.pas b/src/game/g_language.pas index 2bebf82..424aa2a 100644 --- a/src/game/g_language.pas +++ b/src/game/g_language.pas @@ -275,6 +275,7 @@ type I_MENU_SOUND_INACTIVE_SOUNDS_OFF, I_MENU_SOUND_ANNOUNCE, I_MENU_SOUND_COMPAT, + I_MENU_SOUND_CHAT, I_MENU_ANNOUNCE_NONE, I_MENU_ANNOUNCE_ME, I_MENU_ANNOUNCE_MEPLUS, @@ -1110,6 +1111,8 @@ const 'Îáúÿâëåíèÿ:'), ('MENU SOUND COMPAT', 'Sound FX set:', 'Íàáîð çâóêîâ:'), + ('MENU SOUND CHAT', 'Enable chat speech:', + 'Îçâó÷èâàòü ÷àò:'), ('MENU ANNOUNCE NONE', 'None', 'Íåò'), ('MENU ANNOUNCE ME', 'Only own announcers', diff --git a/src/game/g_menu.pas b/src/game/g_menu.pas index 9d5193d..0ba399a 100644 --- a/src/game/g_menu.pas +++ b/src/game/g_menu.pas @@ -128,6 +128,7 @@ begin gMuteWhenInactive := TGUISwitch(menu.GetControl('swInactiveSounds')).ItemIndex = 1; gAnnouncer := TGUISwitch(menu.GetControl('swAnnouncer')).ItemIndex; gSoundEffectsDF := TGUISwitch(menu.GetControl('swSoundEffects')).ItemIndex = 1; + gUseChatSounds := TGUISwitch(menu.GetControl('swChatSpeech')).ItemIndex = 0; menu := TGUIMenu(g_GUI_GetWindow('OptionsGameMenu').GetControl('mOptionsGameMenu')); @@ -346,6 +347,12 @@ begin else ItemIndex := 0; + with TGUISwitch(menu.GetControl('swChatSpeech')) do + if gUseChatSounds then + ItemIndex := 0 + else + ItemIndex := 1; + menu := TGUIMenu(g_GUI_GetWindow('OptionsControlsP1Menu').GetControl('mOptionsControlsP1Menu')); with menu, gGameControls.P1Control do begin @@ -2544,6 +2551,13 @@ begin AddItem(_lc[I_MENU_COMPAT_DOOM2]); AddItem(_lc[I_MENU_COMPAT_DF]); end; + // Ïåðåêëþ÷àòåëü çâóêîâ ÷àòà + with AddSwitch (_lc[I_MENU_SOUND_CHAT]) do + begin; + Name := 'swChatSpeech'; + AddItem(_lc[I_MENU_YES]); + AddItem(_lc[I_MENU_NO]); + end; with AddSwitch(_lc[I_MENU_SOUND_INACTIVE_SOUNDS]) do begin Name := 'swInactiveSounds'; diff --git a/src/game/g_options.pas b/src/game/g_options.pas index a3d7017..90effe0 100644 --- a/src/game/g_options.pas +++ b/src/game/g_options.pas @@ -147,6 +147,7 @@ begin gMuteWhenInactive := False; gAnnouncer := ANNOUNCE_MEPLUS; gSoundEffectsDF := True; + gUseChatSounds := True; g_GFX_SetMax(2000); g_Gibs_SetMax(150); g_Corpses_SetMax(20); @@ -312,6 +313,7 @@ begin gMuteWhenInactive := config.ReadBool('Sound', 'MuteInactive', False); gAnnouncer := Min(Max(config.ReadInt('Sound', 'Announcer', ANNOUNCE_MEPLUS), ANNOUNCE_NONE), ANNOUNCE_ALL); gSoundEffectsDF := config.ReadBool('Sound', 'SoundEffectsDF', True); + gUseChatSounds := config.ReadBool('Sound', 'ChatSounds', True); gsSDLSampleRate := Min(Max(config.ReadInt('Sound', 'SDLSampleRate', 44100), 11025), 96000); gsSDLBufferSize := Min(Max(config.ReadInt('Sound', 'SDLBufferSize', 2048), 64), 16384); @@ -559,6 +561,7 @@ begin config.WriteBool('Sound', 'MuteInactive', gMuteWhenInactive); config.WriteInt('Sound', 'Announcer', gAnnouncer); config.WriteBool('Sound', 'SoundEffectsDF', gSoundEffectsDF); + config.WriteBool('Sound', 'ChatSounds', gUseChatSounds); config.WriteInt('Sound', 'SDLSampleRate', gsSDLSampleRate); config.WriteInt('Sound', 'SDLBufferSize', gsSDLBufferSize);