hedgewars/uMobile.pas
author Xeli
Sun, 29 Jan 2012 00:48:39 +0100
changeset 6610 84b0bc1bf399
parent 6601 5965e2927b3d
child 6624 e049b5bb0ad1
permissions -rw-r--r--
koda/ammomenu on desktop fix!
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3928
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
     1
(*
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4948
diff changeset
     3
 * Copyright (c) 2004-2011 Andrey Korotaev <unC0Rr@gmail.com>
3928
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
     4
 *
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
     8
 *
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    12
 * GNU General Public License for more details.
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    13
 *
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    17
 *)
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    18
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    19
{$INCLUDE "options.inc"}
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    20
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    21
unit uMobile;
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    22
interface
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    23
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    24
{$IFDEF IPHONEOS}
4034
634a8c8682de add some phone rumbling to big explosions, airbomb and sinegun
koda
parents: 3952
diff changeset
    25
(*  iOS calls written in ObjcExports.m  *)
3928
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    26
procedure clearView; cdecl; external;
6247
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 5994
diff changeset
    27
procedure startLoadingIndicator; cdecl; external;
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 5994
diff changeset
    28
procedure stopLoadingIndicator; cdecl; external;
5180
a881cd3d3163 small cosmetics
koda
parents: 5178
diff changeset
    29
procedure saveFinishedSynching; cdecl; external;
3928
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    30
procedure updateVisualsNewTurn; cdecl; external;
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    31
function  isApplePhone: Boolean; cdecl; external;
4034
634a8c8682de add some phone rumbling to big explosions, airbomb and sinegun
koda
parents: 3952
diff changeset
    32
procedure AudioServicesPlaySystemSound(num: LongInt); cdecl; external;
3928
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    33
{$ENDIF}
3948
24daa33a3114 some rethinking of initial menu presentation and initial orientation (also merging images should be threadsafe now)
koda
parents: 3940
diff changeset
    34
function  isPhone: Boolean; inline;
4034
634a8c8682de add some phone rumbling to big explosions, airbomb and sinegun
koda
parents: 3952
diff changeset
    35
procedure performRumble; inline;
5167
7b515d0945b1 Clean Augean stables 2 (pascal has classnames available)
koda
parents: 4976
diff changeset
    36
5174
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5168
diff changeset
    37
procedure GameLoading; inline;
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5168
diff changeset
    38
procedure GameLoaded; inline;
5994
3c578f531cc1 don't rumble while synchronising a demo/save
koda
parents: 5180
diff changeset
    39
procedure AmmoUpdate; // do not inline
5167
7b515d0945b1 Clean Augean stables 2 (pascal has classnames available)
koda
parents: 4976
diff changeset
    40
procedure NewTurnBeginning; inline;
6247
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 5994
diff changeset
    41
procedure SaveLoadingEnded; inline;
3928
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    42
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    43
implementation
6601
5965e2927b3d fixed the ammo menu on android, on tablets all weapons are 'choosable' and on phones I've moved the ammomenu up a bit
Xeli
parents: 6580
diff changeset
    44
uses uVariables, uConsole;
3928
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    45
5994
3c578f531cc1 don't rumble while synchronising a demo/save
koda
parents: 5180
diff changeset
    46
// this function is just to determine whether we are running on a limited screen device
3948
24daa33a3114 some rethinking of initial menu presentation and initial orientation (also merging images should be threadsafe now)
koda
parents: 3940
diff changeset
    47
function isPhone: Boolean; inline;
3928
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    48
begin
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    49
{$IFDEF IPHONEOS}
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    50
    exit(isApplePhone());
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    51
{$ENDIF}
6601
5965e2927b3d fixed the ammo menu on android, on tablets all weapons are 'choosable' and on phones I've moved the ammomenu up a bit
Xeli
parents: 6580
diff changeset
    52
{$IFDEF ANDROID}
5965e2927b3d fixed the ammo menu on android, on tablets all weapons are 'choosable' and on phones I've moved the ammomenu up a bit
Xeli
parents: 6580
diff changeset
    53
    //nasty nasty hack. TODO: implement callback to java to have a unified way of determining if it is a tablet
5965e2927b3d fixed the ammo menu on android, on tablets all weapons are 'choosable' and on phones I've moved the ammomenu up a bit
Xeli
parents: 6580
diff changeset
    54
    if (cScreenWidth < 1000) and (cScreenHeight < 500) then
5965e2927b3d fixed the ammo menu on android, on tablets all weapons are 'choosable' and on phones I've moved the ammomenu up a bit
Xeli
parents: 6580
diff changeset
    55
    begin
5965e2927b3d fixed the ammo menu on android, on tablets all weapons are 'choosable' and on phones I've moved the ammomenu up a bit
Xeli
parents: 6580
diff changeset
    56
        exit(true);
5965e2927b3d fixed the ammo menu on android, on tablets all weapons are 'choosable' and on phones I've moved the ammomenu up a bit
Xeli
parents: 6580
diff changeset
    57
    end
5965e2927b3d fixed the ammo menu on android, on tablets all weapons are 'choosable' and on phones I've moved the ammomenu up a bit
Xeli
parents: 6580
diff changeset
    58
    else exit(false);
5965e2927b3d fixed the ammo menu on android, on tablets all weapons are 'choosable' and on phones I've moved the ammomenu up a bit
Xeli
parents: 6580
diff changeset
    59
{$ELSE}
3928
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    60
    exit(false);
6601
5965e2927b3d fixed the ammo menu on android, on tablets all weapons are 'choosable' and on phones I've moved the ammomenu up a bit
Xeli
parents: 6580
diff changeset
    61
{$ENDIF}
3928
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    62
end;
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    63
5994
3c578f531cc1 don't rumble while synchronising a demo/save
koda
parents: 5180
diff changeset
    64
// this function should make the device vibrate in some way
4034
634a8c8682de add some phone rumbling to big explosions, airbomb and sinegun
koda
parents: 3952
diff changeset
    65
procedure performRumble; inline;
5168
8a074a255af0 small tweak to autogenerate the config.inc file in the ios project
koda
parents: 5167
diff changeset
    66
const kSystemSoundID_Vibrate = $00000FFF;
3928
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    67
begin
5994
3c578f531cc1 don't rumble while synchronising a demo/save
koda
parents: 5180
diff changeset
    68
    // do not vibrate while synchronising a demo/save
3c578f531cc1 don't rumble while synchronising a demo/save
koda
parents: 5180
diff changeset
    69
    if not fastUntilLag then
3c578f531cc1 don't rumble while synchronising a demo/save
koda
parents: 5180
diff changeset
    70
        begin
4034
634a8c8682de add some phone rumbling to big explosions, airbomb and sinegun
koda
parents: 3952
diff changeset
    71
{$IFDEF IPHONEOS}
5994
3c578f531cc1 don't rumble while synchronising a demo/save
koda
parents: 5180
diff changeset
    72
        AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
4034
634a8c8682de add some phone rumbling to big explosions, airbomb and sinegun
koda
parents: 3952
diff changeset
    73
{$ENDIF}
5994
3c578f531cc1 don't rumble while synchronising a demo/save
koda
parents: 5180
diff changeset
    74
        end;
3928
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    75
end;
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    76
5174
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5168
diff changeset
    77
procedure GameLoading; inline;
3928
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    78
begin
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    79
{$IFDEF IPHONEOS}
6247
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 5994
diff changeset
    80
    startLoadingIndicator();
3928
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    81
{$ENDIF}
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    82
end;
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    83
5174
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5168
diff changeset
    84
procedure GameLoaded; inline;
3928
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    85
begin
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    86
{$IFDEF IPHONEOS}
6247
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 5994
diff changeset
    87
    stopLoadingIndicator();
3928
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    88
{$ENDIF}
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    89
end;
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
    90
5994
3c578f531cc1 don't rumble while synchronising a demo/save
koda
parents: 5180
diff changeset
    91
procedure AmmoUpdate; // do not inline
3935
5ca27a0e9a63 made the new menu toggable
koda
parents: 3928
diff changeset
    92
begin
5ca27a0e9a63 made the new menu toggable
koda
parents: 3928
diff changeset
    93
{$IFDEF IPHONEOS}
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6247
diff changeset
    94
    if (CurrentTeam = nil) or (CurrentTeam^.ExtDriven) or (CurrentTeam^.Hedgehogs[0].BotLevel <> 0) then
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    95
        exit(); // the other way around throws a compiler error
3935
5ca27a0e9a63 made the new menu toggable
koda
parents: 3928
diff changeset
    96
    updateVisualsNewTurn();
5ca27a0e9a63 made the new menu toggable
koda
parents: 3928
diff changeset
    97
{$ENDIF}
5ca27a0e9a63 made the new menu toggable
koda
parents: 3928
diff changeset
    98
end;
5ca27a0e9a63 made the new menu toggable
koda
parents: 3928
diff changeset
    99
5167
7b515d0945b1 Clean Augean stables 2 (pascal has classnames available)
koda
parents: 4976
diff changeset
   100
procedure NewTurnBeginning; inline;
3928
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
   101
begin
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
   102
{$IFDEF IPHONEOS}
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
   103
    clearView();
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
   104
{$ENDIF}
5167
7b515d0945b1 Clean Augean stables 2 (pascal has classnames available)
koda
parents: 4976
diff changeset
   105
    AmmoUpdate();
3928
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
   106
end;
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
   107
6247
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 5994
diff changeset
   108
procedure SaveLoadingEnded; inline;
3928
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
   109
begin
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
   110
{$IFDEF IPHONEOS}
5174
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5168
diff changeset
   111
    saveFinishedSynching();
3928
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
   112
{$ENDIF}
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
   113
end;
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
   114
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
   115
2560731c860d move all mobile-related functions in their own module, provides a structure for future mobile ports
koda
parents:
diff changeset
   116
end.