aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code/Screens/UScreenPartyNewRoundM2.pas
blob: 7fe94ac2e15b2c62741a2140f98f5f6fb6214df9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
unit UScreenPartyNewRoundM2;

interface

uses
  UMenu, SDL, UDisplay, UMusic, UFiles, SysUtils, UThemes;

type
  TScreenPartyNewRoundM2 = class(TMenu)
    public
      //Texts:
      TextRound: array [1..9] of cardinal;
      TextWinner: array [1..9] of cardinal;

      TextNextRound: cardinal;

      TextNextPlayer1: cardinal;
      TextNextPlayer2: cardinal;
      TextHandicap:    cardinal;

      //Statics
      StaticRound: array [1..9] of cardinal;
      StaticTable: array [1..9] of cardinal;

      StaticNextPlayer1: cardinal;
      StaticNextPlayer2: cardinal;
      StaticHandicap: cardinal;

      TextTableName: array[1..9,1..7] of cardinal;

      ScreenRound:  Integer;

      constructor Create; override;
      function ParseInput(PressedKey: Cardinal; ScanCode: byte; PressedDown: Boolean): Boolean; override;
      function FillNulls(number: integer): String;
      procedure onShow; override;
      procedure SetAnimationProgress(Progress: real); override;
      procedure Update;
  end;

const
  ID='ID_019';   //for help system
  
implementation

uses UGraphic, UMain, UIni, UTexture, UPartyM2, UDLLManager, ULanguage, ULog, UHelp;

function TScreenPartyNewRoundM2.ParseInput(PressedKey: Cardinal; ScanCode: byte; PressedDown: Boolean): Boolean;
begin
  Result := true;
  If (PressedDown) Then
  begin // Key Down
    case PressedKey of
      SDLK_TAB:
        begin
          ScreenPopupHelp.ShowPopup();
        end;

      SDLK_Q:
        begin
          Result := false;
        end;

      SDLK_ESCAPE,
      SDLK_BACKSPACE :
        begin
          Music.PlayBack;
          CheckFadeTo(@ScreenMain,'MSG_END_PARTY');
        end;

      SDLK_RETURN:
        begin
          if(PartySessionM2.CurRound<Length(PartySessionM2.Rounds)) then
          begin
            Music.PlayStart;
            //Select PartyMode M2 ScreenSong
            //Select PartyMode ScreenSong
            ScreenSong.Mode := smChallenge;
            FadeTo(@ScreenSong);
          end else
          begin
            Music.PlayBack;
            CheckFadeTo(@ScreenMain,'MSG_END_PARTY');
          end;
        end;
      SDLK_DOWN:
        begin
          if ScreenRound<=(Length(PartySessionM2.Rounds)-9) then
             inc(ScreenRound);
          Update;
        end;
      SDLK_UP:
        begin
          if ScreenRound>=1 then
             dec(ScreenRound);
          Update;
        end;
      SDLK_RIGHT:
        begin
          if ScreenRound<=(Length(PartySessionM2.Rounds)-9) then
             inc(ScreenRound);
          Update;
        end;
      SDLK_LEFT:
        begin
          if ScreenRound>=1 then
             dec(ScreenRound);
          Update;
        end;
    end;
  end;
end;

constructor TScreenPartyNewRoundM2.Create;
var
  I, J:    integer;
begin
  inherited Create;

  LoadFromTheme(Theme.PartyNewRoundM2);

  for I := 1 to 9 do
  begin
    TextRound[I] := AddText (Theme.PartyNewRoundM2.TextRound[I]);
    TextWinner[I] := AddText (Theme.PartyNewRoundM2.TextWinner[I]);
    StaticRound[I] := AddStatic (Theme.PartyNewRoundM2.StaticRound[I]);
    StaticTable[I] := AddStatic (Theme.PartyNewRoundM2.StaticTable[I]);
  end;

  TextNextRound := AddText (Theme.PartyNewRoundM2.TextNextRound);
  TextNextPlayer1 := AddText (Theme.PartyNewRoundM2.TextNextPlayer1);
  TextNextPlayer2 := AddText (Theme.PartyNewRoundM2.TextNextPlayer2);
  TextHandicap := AddText (Theme.PartyNewRoundM2.TextHandicap);

  StaticNextPlayer1 := AddStatic (Theme.PartyNewRoundM2.StaticNextPlayer1);
  StaticNextPlayer2 := AddStatic (Theme.PartyNewRoundM2.StaticNextPlayer2);
  StaticHandicap := AddStatic (Theme.PartyNewRoundM2.StaticHandicap);

  //Table
  for I := 1 to 9 do
  begin
    for J := 1 to 7 do
    begin
      TextTableName[I,J] := AddText (Theme.PartyNewRoundM2.TextTableName[I,J]);
    end;
  end;
end;

procedure TScreenPartyNewRoundM2.onShow;
var
  x,y: Integer;
begin
  inherited;
  if not Help.SetHelpID(ID) then
    Log.LogError('No Entry for Help-ID ' + ID + ' (ScreenPartyNewRoundM2)');

  PartySessionM2.StartRound;
  ScreenRound:=PartySessionM2.CurRound-2;
  if ScreenRound<0 then
  begin
    ScreenRound:=PartySessionM2.CurRound-1;
    if ScreenRound<0 then
      ScreenRound:=0;
  end;
  Update;

  //Display Scores
  for x := 1 to 9 do
  begin
    if x<=PartySessionM2.Players.NumPlayer then
    begin
      Static[StaticTable[x]].Visible := true;
      Text[TextTableName[x,1]].Text := IntToStr(x);
      Text[TextTableName[x,2]].Text := PartySessionM2.Players.Playerinfo[PartySessionM2.Order[x-1]].Name;
      Text[TextTableName[x,3]].Text := IntToStr(PartySessionM2.Players.Playerinfo[PartySessionM2.Order[x-1]].Wins);
      Text[TextTableName[x,4]].Text := IntToStr(PartySessionM2.Players.Playerinfo[PartySessionM2.Order[x-1]].Draws);
      Text[TextTableName[x,5]].Text := IntToStr(PartySessionM2.Players.Playerinfo[PartySessionM2.Order[x-1]].Defeats);
      Text[TextTableName[x,6]].Text := IntToStr(PartySessionM2.Players.Playerinfo[PartySessionM2.Order[x-1]].ScoreP -
                                                PartySessionM2.Players.Playerinfo[PartySessionM2.Order[x-1]].ScoreN);
      Text[TextTableName[x,7]].Text := IntToStr(PartySessionM2.Players.Playerinfo[PartySessionM2.Order[x-1]].Points);
    end else
    begin
      for y := 1 to 7 do
      begin
        Text[TextTableName[x,y]].Text := '';
        Static[StaticTable[x]].Visible := false;
      end;
    end;
  end;

  //nextRound Texts
  if PartySessionM2.CurRound<Length(PartySessionM2.Rounds) then
  begin
    if PartySessionM2.Option_Plugins then
    begin
      Text[TextNextRound].Text := Language.Translate('PARTY_ROUND') + ' ' + IntToStr(PartySessionM2.CurRound + 1) +
        ': ' + PartySessionM2.Plugins[PartySessionM2.Rounds[PartySessionM2.CurRound].PluginNr].Name;
    end else
      Text[TextNextRound].Text := Language.Translate('PARTY_ROUND') + ' ' + IntToStr(PartySessionM2.CurRound + 1);

    Text[TextNextPlayer1].Text := PartySessionM2.Players.Playerinfo[PartySessionM2.Rounds[PartySessionM2.CurRound].Player1].Name;
    Text[TextNextPlayer1].Visible := true;

    Text[TextNextPlayer2].Text := PartySessionM2.Players.Playerinfo[PartySessionM2.Rounds[PartySessionM2.CurRound].Player2].Name;
    Text[TextNextPlayer2].Visible := true;

    Static[StaticNextPlayer1].Visible := true;
    Static[StaticNextPlayer2].Visible := true;

    //Handicap-mode
    if PartySessionM2.HandicapMode then
    begin
      Text[TextHandicap].Text := '[' + FormatFloat('#0.00', PartySessionM2.Handicap.P1m) +
        ' : ' + FormatFloat('#0.00', PartySessionM2.Handicap.P2m) + ']';
      Text[TextHandicap].visible := true;
      Static[StaticHandicap].visible := true;
    end else
    begin
      Text[TextHandicap].visible := false;
      Static[StaticHandicap].visible := false;
    end;
  end else
  begin
    Text[TextNextRound].Text := Language.Translate('PARTY_ROUNDM2_END');

    Text[TextNextPlayer1].Visible := false;
    Text[TextNextPlayer2].Visible := false;

    Static[StaticNextPlayer1].Visible := false;
    Static[StaticNextPlayer2].Visible := false;
  end;
end;

procedure TScreenPartyNewRoundM2.Update;
var
  N, R: Integer;
  T: Integer;
  NumRounds: Integer;
begin
  //current round-number
  R:=PartySessionM2.CurRound;

  //Set Visibility of Round Infos
  NumRounds := Length(PartySessionM2.Rounds);

  N:=ScreenRound;

  if ((NumRounds-9)<N) then
  begin
    N:=NumRounds-9;
    ScreenRound:=N;
  end;

  if (N<0) then
  begin
    N:=0;
    ScreenRound:=0;
  end;

  for T := 1 to 9 do
  begin
    if (NumRounds >= T) then
    begin
      Static[StaticRound[T]].Visible := true;
      Text[TextRound[T]].Visible := true;
      if (N+T-1<R) then
        Text[TextWinner[T]].Visible := true
      else
        Text[TextWinner[T]].Visible := false;

      //Texts:
      if (N+T-1<R) then
        Text[TextRound[T]].Text := IntToStr(N+T)+ ') ' + PartySessionM2.Players.Playerinfo[PartySessionM2.Rounds[N+T-1].Player1].Name +
          ' - ' + PartySessionM2.Players.Playerinfo[PartySessionM2.Rounds[N+T-1].Player2].Name
      else
      begin
        Text[TextRound[T]].Text := IntToStr(N+T)+ ') ';
        Text[TextRound[T]].Text := Text[TextRound[T]].Text +
          PartySessionM2.Plugins[PartySessionM2.Rounds[N+T-1].PluginNr].Name
      end;

      Text[TextWinner[T]].Text :=FillNulls(PartySessionM2.Rounds[N+T-1].ScoreP) +
        ':' + FillNulls(PartySessionM2.Rounds[N+T-1].ScoreN);
    end else
    begin
      Static[StaticRound[T]].Visible := false;
      Text[TextRound[T]].Visible := false;
      Text[TextWinner[T]].Visible := false;
    end;
  end;
end;

function TScreenPartyNewRoundM2.FillNulls(number: integer): String;
begin
  if number<10 then
    Result := '000' + IntToStr(number)
  else if number<100 then
    Result := '00' + IntToStr(number)
  else if number <1000 then
    Result := '0' + IntToStr(number)
  else
    Result := IntToStr(number);
end;

procedure TScreenPartyNewRoundM2.SetAnimationProgress(Progress: real);
begin
  {Button[0].Texture.ScaleW := Progress;
  Button[1].Texture.ScaleW := Progress;
  Button[2].Texture.ScaleW := Progress; }
end;

end.