Changeset 666


Ignore:
Timestamp:
Jul 9, 2025, 10:36:23 PM (7 hours ago)
Author:
chronos
Message:
  • Added: Music volume option in game settings form.
Location:
trunk
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/Direct.pas

    r664 r666  
    135135        Background.Update;
    136136      end;
    137       MusicPlayer.LoadPlaylistFromDir(GetMusicDir);
    138       MusicPlayer.RandomizePlaylist;
    139       if MusicPlayer.Playlist.Count > 0 then MusicPlayer.Play;
     137      if MusicEnabled then begin
     138        MusicPlayer.LoadPlaylistFromDir(GetMusicDir);
     139        MusicPlayer.RandomizePlaylist;
     140        if MusicPlayer.Playlist.Count > 0 then MusicPlayer.Play;
     141      end;
    140142    end;
    141143    ntStartGo, ntStartGoRefresh, ntStartGoRefreshMaps:
  • trunk/Language.txt

    r614 r666  
    964964Custom DPI
    965965DPI
     966Music
  • trunk/Language2.txt

    r304 r666  
    2727
    2828'Start Dialog
    29 #ACTIONHEADER_CONFIG Configurator
    30 #ACTION_CONFIG Change language, add maps and AIs
     29#ACTIONHEADER_CONFIG Configuration
     30#ACTION_CONFIG Change language, key bindings, audio
    3131#ACTIONHEADER_MANUAL Manual
    3232#ACTION_MANUAL Rules and user interface in detail
     
    6767#AITSTAT
    6868No. of rounds colony ship was completed
    69 No. of rounds all other nations were erased 
    70 No. of rounds own nation was erased 
     69No. of rounds all other nations were erased
     70No. of rounds own nation was erased
    7171Share of total calculation time
  • trunk/LocalPlayer/Term.pas

    r660 r666  
    655655
    656656uses
    657   Directories, Log, Sound, Registry, Global, KeyBindings, CmdList;
     657  Directories, Log, Sound, Registry, Global, KeyBindings, CmdList, Music;
    658658
    659659{$R *.lfm}
     
    80948094    else TermBounds := BoundsRect;
    80958095  Timer1.Enabled := False;
     8096  if MusicPlayer.Playing then MusicPlayer.Stop;
    80968097end;
    80978098
  • trunk/Localization/cs/Language.txt

    r614 r666  
    964964Vlastní DPI
    965965DPI
     966Hudba
  • trunk/Localization/cs/Language2.txt

    r436 r666  
    2727
    2828'Start Dialog
    29 #ACTIONHEADER_CONFIG Konfigurátor
    30 #ACTION_CONFIG Změna jazyka, přidání map a AI
     29#ACTIONHEADER_CONFIG Nastavení
     30#ACTION_CONFIG Změna jazyka, přiřazení kláves, zvuku
    3131#ACTIONHEADER_MANUAL Příručka
    3232#ACTION_MANUAL Popis pravidel a uživatelského rozhraní
     
    6767#AITSTAT
    6868Počet kol, kdy byla dokončena kolonizační loď
    69 Počet kol, kdy byly zničeny všechny ostatní národy 
    70 Počet kol, kdy byl zničen náš národ 
     69Počet kol, kdy byly zničeny všechny ostatní národy
     70Počet kol, kdy byl zničen náš národ
    7171Podíl na celkovém času
  • trunk/Localization/de/Language.txt

    r614 r666  
    982982Custom DPI
    983983DPI
     984Musik
  • trunk/Localization/de/Language2.txt

    r454 r666  
    2727
    2828'Start Dialog
    29 #ACTIONHEADER_CONFIG Konfigurator
    30 #ACTION_CONFIG Sprache ändern, Karten und KIs hinzufügen
     29#ACTIONHEADER_CONFIG Einstellungen
     30#ACTION_CONFIG Ändern von Sprache, Tastenbelegung, Ton
    3131#ACTIONHEADER_MANUAL Handbuch
    3232#ACTION_MANUAL Regeln und Benutzeroberfläche im Detail
     
    6767#AITSTAT
    6868Anzahl der Runden Kolonieschiff wurde abgeschlossen
    69 Anzahl der Runden alle anderen Nationen wurden gelöscht 
    70 Anzahl der Runden eigene Nation wurde gelöscht 
     69Anzahl der Runden alle anderen Nationen wurden gelöscht
     70Anzahl der Runden eigene Nation wurde gelöscht
    7171Anteil an der Gesamtberechnungszeit
  • trunk/Localization/fr/Language.txt

    r643 r666  
    964964DPI personnalisé
    965965DPI
     966Musique
  • trunk/Localization/fr/Language2.txt

    r453 r666  
    2828'Start Dialog
    2929#ACTIONHEADER_CONFIG Configurateur
    30 #ACTION_CONFIG Changer de langue, ajouter des cartes et des IA
     30#ACTION_CONFIG Modification de la langue, des affectations de touches
    3131#ACTIONHEADER_MANUAL Manuel
    3232#ACTION_MANUAL Règles et interface utilisateur en détail
  • trunk/Localization/it/Language.txt

    r614 r666  
    954954Custom DPI
    955955DPI
     956Musica
  • trunk/Localization/it/Language2.txt

    r304 r666  
    2727
    2828'Start Dialog
    29 #ACTIONHEADER_CONFIG Configuratore
    30 #ACTION_CONFIG Cambia lingua, aggiungi mappe e I.A.
     29#ACTIONHEADER_CONFIG Impostazioni
     30#ACTION_CONFIG Modifica della lingua, assegnazione dei tasti
    3131#ACTIONHEADER_MANUAL Manuale
    3232#ACTION_MANUAL Regole e interfaccia in dettaglio
  • trunk/Localization/ru/Language.txt

    r614 r666  
    989989Custom DPI
    990990DPI
     991Музыка
  • trunk/Localization/zh-Hans/Language.txt

    r614 r666  
    981981Custom DPI
    982982DPI
     983Music
  • trunk/Localization/zh-Hant/Language.txt

    r614 r666  
    981981Custom DPI
    982982DPI
     983Music
  • trunk/Music.pas

    r665 r666  
    1212  TMusicPlayer = class
    1313  private
     14    FVolume: Single;
    1415    PlayerIndex1: Integer;
    1516    InputIndex1: Integer;
     
    1819    InputLength: Integer;
    1920    AutoPlayNext: Boolean;
     21    function GetPlaying: Boolean;
    2022    procedure Initialize;
    2123    procedure EndPlay(PlayerIndex: cint32);
    2224    function GetNextPlaylistItem: string;
    2325    procedure PlayNext(Data: PtrInt);
     26    procedure SetVolume(AValue: Single);
    2427  public
    2528    Playlist: TStringList;
     
    3033    procedure Play;
    3134    procedure Stop;
     35    property Playing: Boolean read GetPlaying;
     36    property Volume: Single read FVolume write SetVolume;
    3237  end;
    3338
     
    7883end;
    7984
     85function TMusicPlayer.GetPlaying: Boolean;
     86begin
     87  Result := PlayerIndex1 >= 0;
     88end;
     89
    8090procedure TMusicPlayer.EndPlay(PlayerIndex: cint32);
    8191begin
    82   if AutoPlayNext and (PlayerIndex = PlayerIndex1) then Application.QueueAsyncCall(PlayNext, 0);
     92  if AutoPlayNext then begin
     93    if PlayerIndex = PlayerIndex1 then Application.QueueAsyncCall(PlayNext, 0);
     94  end else PlayerIndex1 := -1;
    8395end;
    8496
     
    95107end;
    96108
     109procedure TMusicPlayer.SetVolume(AValue: Single);
     110begin
     111  if FVolume = AValue then Exit;
     112  FVolume := AValue;
     113  if FVolume > 1 then FVolume := 1;
     114  if FVolume < 0 then FVolume := 0;
     115  if Playing then
     116    uos_InputSetDSPVolume(PlayerIndex1, InputIndex1, Volume, Volume, True);
     117end;
     118
    97119constructor TMusicPlayer.Create;
    98120begin
    99121  Playlist := TStringList.Create;
     122  PlayerIndex1 := -1;
     123  FVolume := 1;
    100124end;
    101125
     
    154178
    155179  AutoPlayNext := False;
    156   uos_Stop(PlayerIndex1);
     180  if PlayerIndex1 >= 0 then uos_Stop(PlayerIndex1);
    157181
    158182  Inc(PlayerIndex1);
     
    171195  uos_InputSetPositionEnable(PlayerIndex1, InputIndex1, 1);
    172196  InputLength := uos_InputLength(PlayerIndex1, InputIndex1);
    173   uos_InputAddDSPVolume(PlayerIndex1, InputIndex1, 0.5, 0.5);
     197  uos_InputAddDSPVolume(PlayerIndex1, InputIndex1, Volume, Volume);
    174198
    175199  OutputIndex1 := uos_AddIntoDevOut(PlayerIndex1, -1, -1, -1, -1, -1, -1, -1);
     
    185209procedure TMusicPlayer.Stop;
    186210begin
    187   Initialize;
    188211  AutoPlayNext := False;
    189   uos_Stop(PlayerIndex1);
     212  if PlayerIndex1 >= 0 then begin
     213    Initialize;
     214    uos_Stop(PlayerIndex1);
     215  end;
     216  PlayerIndex1 := -1;
    190217end;
    191218
  • trunk/Packages/CevoComponents/ScreenTools.pas

    r659 r666  
    197197  DrawBuffer: TBitmap;
    198198  FullScreen: Boolean;
     199  MusicEnabled: Boolean;
     200  MusicVolume: Single;
    199201  TermBounds: TRect;
    200202  GenerateNames: Boolean;
  • trunk/Settings.lfm

    r568 r666  
    1111  DesignTimePPI = 144
    1212  Font.Color = clWindowText
    13   Font.Height = -11
     13  Font.Height = -17
    1414  Font.Name = 'MS Sans Serif'
    1515  FormStyle = fsStayOnTop
     16  Position = poScreenCenter
     17  LCLVersion = '4.0.0.4'
     18  Scaled = False
    1619  OnClose = FormClose
    1720  OnCreate = FormCreate
     
    1922  OnPaint = FormPaint
    2023  OnShow = FormShow
    21   Position = poScreenCenter
    22   LCLVersion = '2.2.6.0'
    23   Scaled = False
    2424  object ListLanguages: TListBoxEx
    2525    Tag = 15360
    2626    Left = 16
    27     Height = 291
     27    Height = 280
    2828    Top = 32
    2929    Width = 144
     
    3939    ParentFont = False
    4040    ScrollWidth = 144
     41    Style = lbOwnerDrawVariable
    4142    TabOrder = 1
    4243    TabStop = False
     
    6263  end
    6364  object ButtonFullscreen: TButtonC
    64     Left = 24
     65    Left = 16
    6566    Height = 18
    6667    Top = 368
     
    110111    ParentFont = False
    111112    ScrollWidth = 288
     113    Style = lbOwnerDrawVariable
    112114    TabOrder = 0
    113115    TabStop = False
    114116    TopIndex = -1
    115117    OnSelectionChange = ListKeyBindingsSelectionChange
    116   end
    117   object EditShortCutPrimary: TEdit
    118     Left = 176
    119     Height = 27
    120     Top = 296
    121     Width = 136
    122     BorderStyle = bsNone
    123     Color = clBlack
    124     Enabled = False
    125     Font.Color = 4176863
    126     Font.Height = -15
    127     Font.Name = 'Times New Roman'
    128     Font.Style = [fsBold]
    129     ParentFont = False
    130     TabOrder = 2
    131     OnKeyUp = EditShortCutPrimaryKeyUp
    132   end
    133   object EditShortCutSecondary: TEdit
    134     Left = 328
    135     Height = 27
    136     Top = 296
    137     Width = 136
    138     BorderStyle = bsNone
    139     Color = clBlack
    140     Enabled = False
    141     Font.Color = 4176863
    142     Font.Height = -15
    143     Font.Name = 'Times New Roman'
    144     Font.Style = [fsBold]
    145     ParentFont = False
    146     TabOrder = 3
    147     OnKeyUp = EditShortCutSecondaryKeyUp
    148118  end
    149119  object ButtonReset: TButtonA
     
    157127  end
    158128  object ButtonCustomDpi: TButtonC
    159     Left = 24
     129    Left = 176
    160130    Height = 18
    161     Top = 336
     131    Top = 334
    162132    Width = 18
    163133    Down = False
     
    188158    ButtonIndex = 0
    189159  end
     160  object ButtonMusicVolumeDown: TButtonC
     161    Tag = 6912
     162    Left = 136
     163    Height = 12
     164    Top = 340
     165    Width = 12
     166    Down = False
     167    Permanent = False
     168    OnClick = ButtonMusicVolumeDownClick
     169    ButtonIndex = 0
     170  end
     171  object ButtonMusicVolumeUp: TButtonC
     172    Tag = 6912
     173    Left = 136
     174    Height = 12
     175    Top = 328
     176    Width = 12
     177    Down = False
     178    Permanent = False
     179    OnClick = ButtonMusicVolumeUpClick
     180    ButtonIndex = 1
     181  end
     182  object EditShortCutPrimary: TEdit
     183    AutoSize = True
     184    ClientHeight = 27
     185    ClientWidth = 136
     186    Top = 296
     187    Left = 176
     188    Width = 136
     189    Height = 27
     190    Enabled = False
     191    ShowHint = False
     192    Font.Color = 4176863
     193    Font.Name = 'Times New Roman'
     194    Font.Style = [fsBold]
     195    Font.PixelsPerInch = 96
     196    Font.Height = -15
     197    Align = alNone
     198    Color = clBlack
     199    TabStop = True
     200    OnKeyUp = EditShortCutPrimaryKeyUp
     201    BorderStyle = bsNone
     202    ParentFont = False
     203  end
     204  object EditShortCutSecondary: TEdit
     205    AutoSize = True
     206    ClientHeight = 27
     207    ClientWidth = 136
     208    Top = 296
     209    Left = 328
     210    Width = 136
     211    Height = 27
     212    Enabled = False
     213    ShowHint = False
     214    Font.Color = 4176863
     215    Font.Name = 'Times New Roman'
     216    Font.Style = [fsBold]
     217    Font.PixelsPerInch = 96
     218    Font.Height = -15
     219    Align = alNone
     220    Color = clBlack
     221    TabStop = True
     222    OnKeyUp = EditShortCutSecondaryKeyUp
     223    BorderStyle = bsNone
     224    ParentFont = False
     225  end
    190226end
  • trunk/Settings.pas

    r570 r666  
    1313
    1414  TSettingsDlg = class(TDrawDlg)
     15    ButtonMusicVolumeDown: TButtonC;
     16    ButtonMusicVolumeUp: TButtonC;
    1517    ButtonFullscreen: TButtonC;
    1618    ButtonCustomDpi: TButtonC;
     
    3133    procedure ButtonFullscreenClick(Sender: TObject);
    3234    procedure ButtonCancelClick(Sender: TObject);
     35    procedure ButtonMusicVolumeDownClick(Sender: TObject);
     36    procedure ButtonMusicVolumeUpClick(Sender: TObject);
    3337    procedure ButtonResetClick(Sender: TObject);
    3438    procedure ButtonGammaDownClick(Sender: TObject);
     
    4852    LocalGamma: Integer;
    4953    LocalKeyBindings: TKeyBindings;
     54    LocalMusicVolume: Integer;
    5055    CurrentKeyBinding: TKeyBinding;
    5156    LocalDpi: Integer;
     
    6570  DpiMax = 500;
    6671  DpiStep = 25;
     72  MusicVolumeMin = 0;
     73  MusicVolumeMax = 100;
     74  MusicVolumeStep = 10;
    6775
    6876
     
    7684var
    7785  SFullScreen, SGamma, SRestartMsg, SShortCutPrimary, SShortCutSecondary,
    78   SLanguages, SKeyBindings, SCustomDpi, SDpi: string;
     86  SLanguages, SKeyBindings, SCustomDpi, SDpi, SMusic: string;
    7987
    8088procedure ReloadLanguages;
     
    8997  SCustomDpi := Phrases.Lookup('SETTINGS', 7);
    9098  SDpi := Phrases.Lookup('SETTINGS', 8);
     99  SMusic := Phrases.Lookup('SETTINGS', 9);
    91100end;
    92101
     
    112121end;
    113122
     123procedure TSettingsDlg.ButtonMusicVolumeDownClick(Sender: TObject);
     124begin
     125  Dec(LocalMusicVolume, MusicVolumeStep);
     126  if LocalMusicVolume < MusicVolumeMin then LocalMusicVolume := MusicVolumeMin;
     127  Invalidate;
     128end;
     129
     130procedure TSettingsDlg.ButtonMusicVolumeUpClick(Sender: TObject);
     131begin
     132  Inc(LocalMusicVolume, MusicVolumeStep);
     133  if LocalMusicVolume > MusicVolumeMax then LocalMusicVolume := MusicVolumeMax;
     134  Invalidate;
     135end;
     136
    114137procedure TSettingsDlg.ButtonResetClick(Sender: TObject);
    115138begin
     
    117140  ListLanguages.ItemIndex := 0;
    118141  ButtonFullscreen.ButtonIndex := 3;
     142  LocalMusicVolume := 50;
    119143  ButtonCustomDpi.ButtonIndex := 2;
    120144  LocalDpi := 100;
     
    202226
    203227procedure TSettingsDlg.FormPaint(Sender: TObject);
     228const
     229  TextDistanceX = 20;
     230  UpDownTextWidth = 120;
    204231begin
    205232  PaintBackground(Canvas, 3, 3, ClientWidth - 6, ClientHeight - 6,
     
    223250    ButtonCustomDpi.Left + 12, ButtonCustomDpi.Top + 12, MainTexture.ColorBevelShade,
    224251    MainTexture.ColorBevelLight);
    225   LoweredTextOut(Canvas, -2, MainTexture, ButtonCustomDpi.Left + 32,
     252  LoweredTextOut(Canvas, -2, MainTexture, ButtonCustomDpi.Left + TextDistanceX,
    226253    ButtonCustomDpi.Top - 4, SCustomDpi);
    227254  UnderlinedTitleValue(Canvas, SDpi, IntToStr(LocalDpi) + '%',
    228     ButtonDpiUp.Left - 150 - 4, ButtonDpiUp.Top + 2, 150);
     255    ButtonDpiUp.Left - UpDownTextWidth - 4, ButtonDpiUp.Top + 2, UpDownTextWidth);
    229256  {$ENDIF}
     257
     258  UnderlinedTitleValue(Canvas, SMusic, IntToStr(LocalMusicVolume) + '%',
     259    ButtonMusicVolumeUp.Left - UpDownTextWidth - 4, ButtonMusicVolumeUp.Top + 2, UpDownTextWidth);
    230260
    231261  LoweredTextOut(Canvas, -2, MainTexture, ListLanguages.Left,
     
    233263  LoweredTextOut(Canvas, -2, MainTexture, ListKeyBindings.Left,
    234264    ListKeyBindings.Top - 26, SKeyBindings);
    235   LoweredTextOut(Canvas, -2, MainTexture, ButtonFullscreen.Left + 32,
     265  LoweredTextOut(Canvas, -2, MainTexture, ButtonFullscreen.Left + TextDistanceX,
    236266    ButtonFullscreen.Top - 4, SFullScreen);
    237267  UnderlinedTitleValue(Canvas, SGamma, IntToStr(LocalGamma) + '%',
    238     ButtonGammaUp.Left - 150 - 4, ButtonGammaUp.Top + 2, 150);
     268    ButtonGammaUp.Left - UpDownTextWidth - 4, ButtonGammaUp.Top + 2, UpDownTextWidth);
    239269  LoweredTextOut(Canvas, -2, MainTexture, EditShortCutPrimary.Left,
    240270    EditShortCutPrimary.Top - 26, SShortCutPrimary);
     
    343373  if FullScreen then ButtonFullscreen.ButtonIndex := 3
    344374    else ButtonFullscreen.ButtonIndex := 2;
     375  if MusicEnabled then LocalMusicVolume := Round(MusicVolume * 100)
     376    else LocalMusicVolume := 0;
    345377  LocalGamma := Gamma;
    346378  LocalKeyBindings.Assign(KeyBindings.KeyBindings);
     
    366398  end;
    367399  FullScreen := (ButtonFullscreen.ButtonIndex and 1) = 1;
     400  MusicEnabled := LocalMusicVolume > 0;
     401  MusicVolume := LocalMusicVolume / 100;
    368402  Gamma := LocalGamma;
    369403  ScreenTools.CustomDpiEnabled := CustomDpiEnabled;
  • trunk/Start.pas

    r664 r666  
    123123    LastGame: string;
    124124    LastMap: string;
     125    procedure UpdateMusic;
    125126    procedure DrawAction(Y, IconIndex: Integer; HeaderItem, TextItem: string);
    126127    procedure InitPopup(PlayerIndex: Integer);
     
    337338
    338339procedure TStartDlg.SmartInvalidate(x0, y0, x1, y1: Integer;
    339   invalidateTab0: Boolean);
     340  InvalidateTab0: Boolean);
    340341var
    341342  I: Integer;
     
    414415      else ScreenMode := 1;
    415416    FullScreen := ScreenMode > 0;
     417    if ValueExists('MusicEnabled') then MusicEnabled := ReadBool('MusicEnabled')
     418      else MusicEnabled := True;
     419    if ValueExists('MusicVolume') then MusicVolume := ReadFloat('MusicVolume')
     420      else MusicVolume := 0.5;
    416421    if ValueExists('TermLeft') then TermBounds.Left := ReadInteger('TermLeft')
    417422      else TermBounds.Left := 0;
     
    460465    if FullScreen then WriteInteger('ScreenMode', 1)
    461466      else WriteInteger('ScreenMode', 0);
     467    WriteBool('MusicEnabled', MusicEnabled);
     468    WriteFloat('MusicVolume', MusicVolume);
    462469    WriteInteger('TermWidth', TermBounds.Width);
    463470    WriteInteger('TermHeight', TermBounds.Height);
     
    537544    UpdateInterface;
    538545    Background.UpdateInterface;
     546    UpdateMusic;
    539547  end;
    540548  FreeAndNil(SettingsDlg);
     
    943951  Background.Enabled := False;
    944952
    945   MusicPlayer.LoadPlaylistFromDir(GetMusicDir + DirectorySeparator + 'Start');
    946   MusicPlayer.RandomizePlaylist;
    947   if MusicPlayer.Playlist.Count > 0 then MusicPlayer.Play;
     953  UpdateMusic;
    948954end;
    949955
     
    19611967end;
    19621968
     1969procedure TStartDlg.UpdateMusic;
     1970begin
     1971  if MusicEnabled then begin
     1972    MusicPlayer.Volume := MusicVolume;
     1973    if not MusicPlayer.Playing then begin
     1974      MusicPlayer.LoadPlaylistFromDir(GetMusicDir + DirectorySeparator + 'Start');
     1975      MusicPlayer.RandomizePlaylist;
     1976      if MusicPlayer.Playlist.Count > 0 then MusicPlayer.Play;
     1977    end;
     1978  end else begin
     1979    if MusicPlayer.Playing then MusicPlayer.Stop;
     1980  end;
     1981end;
     1982
    19631983end.
Note: See TracChangeset for help on using the changeset viewer.