From 5c722451a2bb6702c628a1b7c1468160fc01734a Mon Sep 17 00:00:00 2001 From: Tomaz Noleto Date: Tue, 25 Oct 2011 17:13:31 +0200 Subject: chicken-wranglers: Initial commit Signed-off-by: Tomaz Noleto --- chicken-wranglers/.gitignore | 12 + chicken-wranglers/AUTHORS | 8 + chicken-wranglers/LICENSE | 2 + chicken-wranglers/README | 15 + .../characters/blue/back_stopped_1.png | Bin 0 -> 3848 bytes .../characters/blue/back_stopped_2.png | Bin 0 -> 3861 bytes .../characters/blue/back_walking_1.png | Bin 0 -> 4313 bytes .../characters/blue/back_walking_2.png | Bin 0 -> 4388 bytes chicken-wranglers/characters/blue/control.png | Bin 0 -> 238757 bytes .../characters/blue/front_stopped_1.png | Bin 0 -> 4548 bytes .../characters/blue/front_stopped_2.png | Bin 0 -> 4512 bytes .../characters/blue/front_walking_1.png | Bin 0 -> 4948 bytes .../characters/blue/front_walking_2.png | Bin 0 -> 4905 bytes chicken-wranglers/characters/blue/hencoop.png | Bin 0 -> 16566 bytes chicken-wranglers/characters/blue/name.png | Bin 0 -> 1684 bytes chicken-wranglers/characters/blue/score.png | Bin 0 -> 14463 bytes .../characters/blue/select_character.png | Bin 0 -> 16129 bytes .../characters/blue/side_stopped_1.png | Bin 0 -> 5594 bytes .../characters/blue/side_stopped_2.png | Bin 0 -> 5562 bytes .../characters/blue/side_walking_1.png | Bin 0 -> 5693 bytes .../characters/blue/side_walking_2.png | Bin 0 -> 5828 bytes chicken-wranglers/characters/blue/turnstile_1.png | Bin 0 -> 4001 bytes chicken-wranglers/characters/blue/turnstile_2.png | Bin 0 -> 9394 bytes chicken-wranglers/characters/blue/turnstile_3.png | Bin 0 -> 9557 bytes chicken-wranglers/characters/blue/unavailable.png | Bin 0 -> 31975 bytes chicken-wranglers/characters/blue/waitinglist.png | Bin 0 -> 8164 bytes .../characters/green/back_stopped_1.png | Bin 0 -> 3916 bytes .../characters/green/back_stopped_2.png | Bin 0 -> 3921 bytes .../characters/green/back_walking_1.png | Bin 0 -> 4386 bytes .../characters/green/back_walking_2.png | Bin 0 -> 4422 bytes chicken-wranglers/characters/green/control.png | Bin 0 -> 237623 bytes .../characters/green/front_stopped_1.png | Bin 0 -> 4558 bytes .../characters/green/front_stopped_2.png | Bin 0 -> 4541 bytes .../characters/green/front_walking_1.png | Bin 0 -> 4952 bytes .../characters/green/front_walking_2.png | Bin 0 -> 4904 bytes chicken-wranglers/characters/green/hencoop.png | Bin 0 -> 16754 bytes chicken-wranglers/characters/green/name.png | Bin 0 -> 2078 bytes chicken-wranglers/characters/green/score.png | Bin 0 -> 14014 bytes .../characters/green/select_character.png | Bin 0 -> 16096 bytes .../characters/green/side_stopped_1.png | Bin 0 -> 5648 bytes .../characters/green/side_stopped_2.png | Bin 0 -> 5554 bytes .../characters/green/side_walking_1.png | Bin 0 -> 5775 bytes .../characters/green/side_walking_2.png | Bin 0 -> 5876 bytes chicken-wranglers/characters/green/turnstile_1.png | Bin 0 -> 4038 bytes chicken-wranglers/characters/green/turnstile_2.png | Bin 0 -> 9344 bytes chicken-wranglers/characters/green/turnstile_3.png | Bin 0 -> 9603 bytes chicken-wranglers/characters/green/unavailable.png | Bin 0 -> 31975 bytes chicken-wranglers/characters/green/waitinglist.png | Bin 0 -> 8161 bytes .../characters/red/back_stopped_1.png | Bin 0 -> 3629 bytes .../characters/red/back_stopped_2.png | Bin 0 -> 3594 bytes .../characters/red/back_walking_1.png | Bin 0 -> 4075 bytes .../characters/red/back_walking_2.png | Bin 0 -> 4114 bytes chicken-wranglers/characters/red/control.png | Bin 0 -> 239380 bytes .../characters/red/front_stopped_1.png | Bin 0 -> 4325 bytes .../characters/red/front_stopped_2.png | Bin 0 -> 4253 bytes .../characters/red/front_walking_1.png | Bin 0 -> 4699 bytes .../characters/red/front_walking_2.png | Bin 0 -> 4733 bytes chicken-wranglers/characters/red/hencoop.png | Bin 0 -> 16096 bytes chicken-wranglers/characters/red/name.png | Bin 0 -> 1747 bytes chicken-wranglers/characters/red/score.png | Bin 0 -> 13692 bytes .../characters/red/select_character.png | Bin 0 -> 15189 bytes .../characters/red/side_stopped_1.png | Bin 0 -> 5318 bytes .../characters/red/side_stopped_2.png | Bin 0 -> 5217 bytes .../characters/red/side_walking_1.png | Bin 0 -> 5413 bytes .../characters/red/side_walking_2.png | Bin 0 -> 5506 bytes chicken-wranglers/characters/red/turnstile_1.png | Bin 0 -> 4024 bytes chicken-wranglers/characters/red/turnstile_2.png | Bin 0 -> 9263 bytes chicken-wranglers/characters/red/turnstile_3.png | Bin 0 -> 9509 bytes chicken-wranglers/characters/red/unavailable.png | Bin 0 -> 31975 bytes chicken-wranglers/characters/red/waitinglist.png | Bin 0 -> 7784 bytes .../characters/yellow/back_stopped_1.png | Bin 0 -> 3805 bytes .../characters/yellow/back_stopped_2.png | Bin 0 -> 3733 bytes .../characters/yellow/back_walking_1.png | Bin 0 -> 4301 bytes .../characters/yellow/back_walking_2.png | Bin 0 -> 4289 bytes chicken-wranglers/characters/yellow/control.png | Bin 0 -> 252568 bytes .../characters/yellow/front_stopped_1.png | Bin 0 -> 4477 bytes .../characters/yellow/front_stopped_2.png | Bin 0 -> 4399 bytes .../characters/yellow/front_walking_1.png | Bin 0 -> 4876 bytes .../characters/yellow/front_walking_2.png | Bin 0 -> 4817 bytes chicken-wranglers/characters/yellow/hencoop.png | Bin 0 -> 16885 bytes chicken-wranglers/characters/yellow/name.png | Bin 0 -> 2796 bytes chicken-wranglers/characters/yellow/score.png | Bin 0 -> 14113 bytes .../characters/yellow/select_character.png | Bin 0 -> 15813 bytes .../characters/yellow/side_stopped_1.png | Bin 0 -> 5495 bytes .../characters/yellow/side_stopped_2.png | Bin 0 -> 5367 bytes .../characters/yellow/side_walking_1.png | Bin 0 -> 5594 bytes .../characters/yellow/side_walking_2.png | Bin 0 -> 5660 bytes .../characters/yellow/turnstile_1.png | Bin 0 -> 4064 bytes .../characters/yellow/turnstile_2.png | Bin 0 -> 9472 bytes .../characters/yellow/turnstile_3.png | Bin 0 -> 9663 bytes .../characters/yellow/unavailable.png | Bin 0 -> 31975 bytes .../characters/yellow/waitinglist.png | Bin 0 -> 8024 bytes chicken-wranglers/chicken-wranglers.pro | 123 ++++++ chicken-wranglers/chicken-wranglers.spec | 58 +++ chicken-wranglers/data/chicken-wranglers.desktop | 8 + chicken-wranglers/data/chicken-wranglers.png | Bin 0 -> 4038 bytes chicken-wranglers/data/chicken-wranglers.svg | 492 +++++++++++++++++++++ chicken-wranglers/debian/changelog | 5 + chicken-wranglers/debian/compat | 1 + chicken-wranglers/debian/control | 14 + chicken-wranglers/debian/fixup-scratchbox | 53 +++ chicken-wranglers/debian/rules | 15 + chicken-wranglers/doc/class-diagram.dia | Bin 0 -> 5303 bytes chicken-wranglers/doc/standard/codecheck.sh | 56 +++ .../doc/standard/coding-standards.txt | 209 +++++++++ chicken-wranglers/examples/control/control.pro | 51 +++ chicken-wranglers/examples/control/main.cpp | 79 ++++ chicken-wranglers/examples/control/qml/Button.qml | 126 ++++++ .../examples/control/qml/ControlPad.qml | 201 +++++++++ chicken-wranglers/examples/control/qml/Options.qml | 108 +++++ chicken-wranglers/examples/control/qml/Slider.qml | 182 ++++++++ chicken-wranglers/examples/control/qml/main.qml | 62 +++ chicken-wranglers/examples/control/qml/qml.qrc | 9 + chicken-wranglers/examples/control/testcontrol.h | 23 + chicken-wranglers/examples/examples.pro | 4 + chicken-wranglers/examples/network/main.cpp | 62 +++ chicken-wranglers/examples/network/network.pro | 33 ++ chicken-wranglers/examples/network/widget.cpp | 198 +++++++++ chicken-wranglers/examples/network/widget.h | 89 ++++ chicken-wranglers/resources/common.qrc | 63 +++ .../images/battlefield/bg_fence_stones.png | Bin 0 -> 1921927 bytes .../images/battlefield/bg_fence_stones_mobile.png | Bin 0 -> 334816 bytes .../resources/images/battlefield/bt_quit.png | Bin 0 -> 3325 bytes .../images/battlefield/bt_quit_pressed.png | Bin 0 -> 3418 bytes .../resources/images/battlefield/clock.png | Bin 0 -> 6971 bytes .../battlefield/fence_corner_bottom_left.png | Bin 0 -> 3190 bytes .../battlefield/fence_corner_bottom_right.png | Bin 0 -> 3113 bytes .../images/battlefield/fence_corner_top_left.png | Bin 0 -> 2981 bytes .../images/battlefield/fence_corner_top_right.png | Bin 0 -> 2862 bytes .../images/battlefield/fence_layer_over.png | Bin 0 -> 11161 bytes .../resources/images/battlefield/hencoop_plate.png | Bin 0 -> 1672 bytes .../resources/images/chicken/back_stopped_1.png | Bin 0 -> 1287 bytes .../resources/images/chicken/back_stopped_2.png | Bin 0 -> 1273 bytes .../resources/images/chicken/back_walking_1.png | Bin 0 -> 1416 bytes .../resources/images/chicken/back_walking_2.png | Bin 0 -> 1439 bytes .../resources/images/chicken/front_stopped_1.png | Bin 0 -> 1093 bytes .../resources/images/chicken/front_stopped_2.png | Bin 0 -> 1078 bytes .../resources/images/chicken/front_walking_1.png | Bin 0 -> 1245 bytes .../resources/images/chicken/front_walking_2.png | Bin 0 -> 1287 bytes .../resources/images/chicken/side_stopped_1.png | Bin 0 -> 1418 bytes .../resources/images/chicken/side_stopped_2.png | Bin 0 -> 1406 bytes .../resources/images/chicken/side_walking_1.png | Bin 0 -> 1572 bytes .../resources/images/chicken/side_walking_2.png | Bin 0 -> 1631 bytes .../resources/images/general/bg_1280x768.png | Bin 0 -> 1007384 bytes .../resources/images/general/bg_800x480.png | Bin 0 -> 391695 bytes .../resources/images/general/bg_dialog.png | Bin 0 -> 70249 bytes .../images/general/bg_selectcharacter.png | Bin 0 -> 184593 bytes .../resources/images/general/bg_splash.png | Bin 0 -> 953893 bytes .../resources/images/general/bluetooth_icon.png | Bin 0 -> 2804 bytes chicken-wranglers/resources/images/general/bt.png | Bin 0 -> 2253 bytes .../resources/images/general/bt_back.png | Bin 0 -> 2099 bytes .../resources/images/general/bt_back_pressed.png | Bin 0 -> 2133 bytes .../resources/images/general/bt_close.png | Bin 0 -> 2766 bytes .../resources/images/general/bt_close_pressed.png | Bin 0 -> 2705 bytes .../resources/images/general/bt_disabled.png | Bin 0 -> 1863 bytes .../resources/images/general/bt_next.png | Bin 0 -> 11587 bytes .../resources/images/general/bt_pressed.png | Bin 0 -> 2276 bytes .../resources/images/general/bt_previous.png | Bin 0 -> 11325 bytes .../resources/images/general/bt_start.png | Bin 0 -> 2419 bytes .../resources/images/general/bt_start_disabled.png | Bin 0 -> 2074 bytes .../resources/images/general/bt_start_pressed.png | Bin 0 -> 2546 bytes .../images/general/character_highlight.png | Bin 0 -> 10268 bytes .../resources/images/general/feather1.png | Bin 0 -> 10933 bytes .../resources/images/general/feather2.png | Bin 0 -> 11395 bytes .../resources/images/general/feather3.png | Bin 0 -> 10586 bytes .../resources/images/general/feather4.png | Bin 0 -> 13434 bytes .../resources/images/general/feather5.png | Bin 0 -> 9469 bytes .../resources/images/general/line_divisor.png | Bin 0 -> 1099 bytes .../resources/images/general/list_line_divisor.png | Bin 0 -> 242 bytes .../resources/images/general/list_name_bg.png | Bin 0 -> 12302 bytes .../images/general/list_scrollbar_knob.png | Bin 0 -> 2621 bytes .../images/general/list_scrollbar_path.png | Bin 0 -> 4317 bytes .../images/general/list_selected_icon.png | Bin 0 -> 2475 bytes .../resources/images/general/list_status_ok.png | Bin 0 -> 3377 bytes .../images/general/list_unknown_character.png | Bin 0 -> 4222 bytes .../resources/images/general/ruller_path.png | Bin 0 -> 17104 bytes .../resources/images/general/ruller_selector.png | Bin 0 -> 9072 bytes .../images/general/slider_bluetooth_icon.png | Bin 0 -> 2804 bytes .../resources/images/general/slider_path.png | Bin 0 -> 14314 bytes .../resources/images/general/slider_selector.png | Bin 0 -> 7708 bytes .../resources/images/general/slider_wifi_icon.png | Bin 0 -> 2921 bytes .../images/general/symbian/bg_640x360.png | Bin 0 -> 255134 bytes .../resources/images/general/symbian/bg_dialog.png | Bin 0 -> 69294 bytes .../images/general/symbian/bg_selectcharacter.png | Bin 0 -> 123335 bytes .../resources/images/general/symbian/bg_splash.png | Bin 0 -> 188467 bytes .../resources/images/general/symbian/feather1.png | Bin 0 -> 5018 bytes .../resources/images/general/symbian/feather2.png | Bin 0 -> 5824 bytes .../resources/images/general/symbian/feather3.png | Bin 0 -> 4981 bytes .../resources/images/general/symbian/feather4.png | Bin 0 -> 6650 bytes .../resources/images/general/symbian/feather5.png | Bin 0 -> 4514 bytes .../resources/images/general/toggle_bt.png | Bin 0 -> 5778 bytes .../resources/images/general/toggle_lan.png | Bin 0 -> 5833 bytes .../resources/images/general/you_are_ready.png | Bin 0 -> 4985 bytes .../resources/images/laser/laser_horizontal_1.png | Bin 0 -> 2188 bytes .../resources/images/laser/laser_horizontal_2.png | Bin 0 -> 1914 bytes .../resources/images/laser/laser_horizontal_3.png | Bin 0 -> 2532 bytes .../resources/images/laser/laser_horizontal_4.png | Bin 0 -> 1546 bytes .../resources/images/laser/laser_vertical_1.png | Bin 0 -> 3708 bytes .../resources/images/laser/laser_vertical_2.png | Bin 0 -> 4182 bytes .../resources/images/laser/laser_vertical_3.png | Bin 0 -> 3744 bytes .../resources/images/laser/laser_vertical_4.png | Bin 0 -> 2668 bytes chicken-wranglers/resources/linux.qrc | 15 + chicken-wranglers/resources/symbian.qrc | 14 + chicken-wranglers/sounds/laser.raw | Bin 0 -> 132300 bytes chicken-wranglers/sounds/match.raw | Bin 0 -> 4066020 bytes chicken-wranglers/sounds/score.raw | Bin 0 -> 110248 bytes chicken-wranglers/src/ai/ai.pri | 9 + chicken-wranglers/src/ai/graph.cpp | 129 ++++++ chicken-wranglers/src/ai/graph.h | 114 +++++ chicken-wranglers/src/ai/matchai.cpp | 408 +++++++++++++++++ chicken-wranglers/src/ai/matchai.h | 78 ++++ chicken-wranglers/src/control/control.cpp | 79 ++++ chicken-wranglers/src/control/control.h | 82 ++++ chicken-wranglers/src/control/control.pri | 16 + chicken-wranglers/src/control/sensormovement.cpp | 192 ++++++++ chicken-wranglers/src/control/sensormovement.h | 148 +++++++ .../src/controllers/chickencontroller.cpp | 116 +++++ .../src/controllers/chickencontroller.h | 89 ++++ chicken-wranglers/src/controllers/controllers.pri | 13 + .../src/controllers/matchcontroller.cpp | 246 +++++++++++ .../src/controllers/matchcontroller.h | 132 ++++++ .../src/controllers/playercontroller.cpp | 127 ++++++ .../src/controllers/playercontroller.h | 93 ++++ chicken-wranglers/src/main/argumentparser.cpp | 118 +++++ chicken-wranglers/src/main/argumentparser.h | 73 +++ chicken-wranglers/src/main/game.cpp | 206 +++++++++ chicken-wranglers/src/main/game.h | 114 +++++ chicken-wranglers/src/main/gameclient.cpp | 423 ++++++++++++++++++ chicken-wranglers/src/main/gameclient.h | 156 +++++++ chicken-wranglers/src/main/gamehost.cpp | 199 +++++++++ chicken-wranglers/src/main/gamehost.h | 123 ++++++ chicken-wranglers/src/main/main.cpp | 93 ++++ chicken-wranglers/src/main/main.pri | 18 + chicken-wranglers/src/main/settings.cpp | 284 ++++++++++++ chicken-wranglers/src/main/settings.h | 108 +++++ chicken-wranglers/src/models/bluetoothdevice.cpp | 110 +++++ chicken-wranglers/src/models/bluetoothdevice.h | 90 ++++ chicken-wranglers/src/models/charactermodel.cpp | 217 +++++++++ chicken-wranglers/src/models/charactermodel.h | 121 +++++ .../src/models/connectivitylistmodel.cpp | 151 +++++++ .../src/models/connectivitylistmodel.h | 86 ++++ chicken-wranglers/src/models/models.pri | 15 + chicken-wranglers/src/models/playermodel.cpp | 466 +++++++++++++++++++ chicken-wranglers/src/models/playermodel.h | 175 ++++++++ .../src/network/bluetoothconnection.cpp | 119 +++++ .../src/network/bluetoothconnection.h | 89 ++++ chicken-wranglers/src/network/bluetoothhandler.cpp | 198 +++++++++ chicken-wranglers/src/network/bluetoothhandler.h | 100 +++++ chicken-wranglers/src/network/bthandler.cpp | 88 ++++ chicken-wranglers/src/network/bthandler.h | 86 ++++ .../src/network/connectionfactory.cpp | 70 +++ chicken-wranglers/src/network/connectionfactory.h | 65 +++ chicken-wranglers/src/network/lanhandler.cpp | 133 ++++++ chicken-wranglers/src/network/lanhandler.h | 82 ++++ chicken-wranglers/src/network/network.h | 67 +++ chicken-wranglers/src/network/network.pri | 37 ++ chicken-wranglers/src/network/networkclient.cpp | 196 ++++++++ chicken-wranglers/src/network/networkclient.h | 107 +++++ .../src/network/networkconnection.cpp | 144 ++++++ chicken-wranglers/src/network/networkconnection.h | 85 ++++ chicken-wranglers/src/network/networkmessage.cpp | 118 +++++ chicken-wranglers/src/network/networkmessage.h | 115 +++++ chicken-wranglers/src/network/networkserver.cpp | 255 +++++++++++ chicken-wranglers/src/network/networkserver.h | 120 +++++ chicken-wranglers/src/network/tcpconnection.cpp | 114 +++++ chicken-wranglers/src/network/tcpconnection.h | 87 ++++ chicken-wranglers/src/network/udphandler.cpp | 169 +++++++ chicken-wranglers/src/network/udphandler.h | 90 ++++ chicken-wranglers/src/qml/Being.qml | 150 +++++++ chicken-wranglers/src/qml/Character.qml | 121 +++++ .../src/qml/CharacterSelectionView.qml | 235 ++++++++++ chicken-wranglers/src/qml/Chicken.qml | 159 +++++++ chicken-wranglers/src/qml/ClientView.qml | 121 +++++ chicken-wranglers/src/qml/HenCoop.qml | 149 +++++++ chicken-wranglers/src/qml/HostView.qml | 94 ++++ chicken-wranglers/src/qml/Laser.qml | 147 ++++++ chicken-wranglers/src/qml/MatchView.qml | 345 +++++++++++++++ chicken-wranglers/src/qml/PlayerControlView.qml | 147 ++++++ chicken-wranglers/src/qml/PlayerReadyView.qml | 115 +++++ chicken-wranglers/src/qml/Score.qml | 128 ++++++ chicken-wranglers/src/qml/ScoreBox.qml | 81 ++++ chicken-wranglers/src/qml/Splash.qml | 79 ++++ chicken-wranglers/src/qml/StartView.qml | 246 +++++++++++ chicken-wranglers/src/qml/WaitingRoomView.qml | 288 ++++++++++++ chicken-wranglers/src/qml/client.js | 72 +++ chicken-wranglers/src/qml/common.js | 26 ++ chicken-wranglers/src/qml/host.js | 46 ++ chicken-wranglers/src/qml/main.qml | 126 ++++++ chicken-wranglers/src/qml/match.js | 310 +++++++++++++ chicken-wranglers/src/qml/qml.qrc | 43 ++ chicken-wranglers/src/qml/widgets/BaseDialog.qml | 112 +++++ chicken-wranglers/src/qml/widgets/Button.qml | 133 ++++++ .../src/qml/widgets/ConfirmationDialog.qml | 106 +++++ .../src/qml/widgets/ConnectivityDialog.qml | 185 ++++++++ .../src/qml/widgets/ConnectivityListModel.qml | 82 ++++ .../src/qml/widgets/ConnectivityListView.qml | 138 ++++++ chicken-wranglers/src/qml/widgets/Countdown.qml | 107 +++++ chicken-wranglers/src/qml/widgets/Feather.qml | 126 ++++++ chicken-wranglers/src/qml/widgets/FeatherFall.qml | 74 ++++ chicken-wranglers/src/qml/widgets/ImageButton.qml | 93 ++++ chicken-wranglers/src/qml/widgets/Loading.qml | 138 ++++++ .../src/qml/widgets/MessageDialog.qml | 85 ++++ chicken-wranglers/src/qml/widgets/OptionSlider.qml | 131 ++++++ chicken-wranglers/src/qml/widgets/Screen.qml | 86 ++++ chicken-wranglers/src/qml/widgets/Scrollbar.qml | 87 ++++ chicken-wranglers/src/qml/widgets/ToggleButton.qml | 67 +++ chicken-wranglers/src/qml/widgets/featherfall.js | 66 +++ chicken-wranglers/src/sound/sound.cpp | 62 +++ chicken-wranglers/src/sound/sound.h | 67 +++ chicken-wranglers/src/sound/sound.pri | 9 + chicken-wranglers/src/sound/sound_linux.cpp | 105 +++++ chicken-wranglers/src/sound/sound_linux.h | 70 +++ chicken-wranglers/src/sound/sound_linux.pri | 9 + chicken-wranglers/src/sound/soundmanager.cpp | 128 ++++++ chicken-wranglers/src/sound/soundmanager.h | 76 ++++ chicken-wranglers/src/utils/global.cpp | 135 ++++++ chicken-wranglers/src/utils/global.h | 102 +++++ chicken-wranglers/src/utils/utils.pri | 9 + 318 files changed, 16357 insertions(+) create mode 100644 chicken-wranglers/.gitignore create mode 100644 chicken-wranglers/AUTHORS create mode 100644 chicken-wranglers/LICENSE create mode 100644 chicken-wranglers/README create mode 100644 chicken-wranglers/characters/blue/back_stopped_1.png create mode 100644 chicken-wranglers/characters/blue/back_stopped_2.png create mode 100644 chicken-wranglers/characters/blue/back_walking_1.png create mode 100644 chicken-wranglers/characters/blue/back_walking_2.png create mode 100644 chicken-wranglers/characters/blue/control.png create mode 100644 chicken-wranglers/characters/blue/front_stopped_1.png create mode 100644 chicken-wranglers/characters/blue/front_stopped_2.png create mode 100644 chicken-wranglers/characters/blue/front_walking_1.png create mode 100644 chicken-wranglers/characters/blue/front_walking_2.png create mode 100644 chicken-wranglers/characters/blue/hencoop.png create mode 100644 chicken-wranglers/characters/blue/name.png create mode 100644 chicken-wranglers/characters/blue/score.png create mode 100644 chicken-wranglers/characters/blue/select_character.png create mode 100644 chicken-wranglers/characters/blue/side_stopped_1.png create mode 100644 chicken-wranglers/characters/blue/side_stopped_2.png create mode 100644 chicken-wranglers/characters/blue/side_walking_1.png create mode 100644 chicken-wranglers/characters/blue/side_walking_2.png create mode 100644 chicken-wranglers/characters/blue/turnstile_1.png create mode 100644 chicken-wranglers/characters/blue/turnstile_2.png create mode 100644 chicken-wranglers/characters/blue/turnstile_3.png create mode 100644 chicken-wranglers/characters/blue/unavailable.png create mode 100644 chicken-wranglers/characters/blue/waitinglist.png create mode 100644 chicken-wranglers/characters/green/back_stopped_1.png create mode 100644 chicken-wranglers/characters/green/back_stopped_2.png create mode 100644 chicken-wranglers/characters/green/back_walking_1.png create mode 100644 chicken-wranglers/characters/green/back_walking_2.png create mode 100644 chicken-wranglers/characters/green/control.png create mode 100644 chicken-wranglers/characters/green/front_stopped_1.png create mode 100644 chicken-wranglers/characters/green/front_stopped_2.png create mode 100644 chicken-wranglers/characters/green/front_walking_1.png create mode 100644 chicken-wranglers/characters/green/front_walking_2.png create mode 100644 chicken-wranglers/characters/green/hencoop.png create mode 100644 chicken-wranglers/characters/green/name.png create mode 100644 chicken-wranglers/characters/green/score.png create mode 100644 chicken-wranglers/characters/green/select_character.png create mode 100644 chicken-wranglers/characters/green/side_stopped_1.png create mode 100644 chicken-wranglers/characters/green/side_stopped_2.png create mode 100644 chicken-wranglers/characters/green/side_walking_1.png create mode 100644 chicken-wranglers/characters/green/side_walking_2.png create mode 100644 chicken-wranglers/characters/green/turnstile_1.png create mode 100644 chicken-wranglers/characters/green/turnstile_2.png create mode 100644 chicken-wranglers/characters/green/turnstile_3.png create mode 100644 chicken-wranglers/characters/green/unavailable.png create mode 100644 chicken-wranglers/characters/green/waitinglist.png create mode 100644 chicken-wranglers/characters/red/back_stopped_1.png create mode 100644 chicken-wranglers/characters/red/back_stopped_2.png create mode 100644 chicken-wranglers/characters/red/back_walking_1.png create mode 100644 chicken-wranglers/characters/red/back_walking_2.png create mode 100644 chicken-wranglers/characters/red/control.png create mode 100644 chicken-wranglers/characters/red/front_stopped_1.png create mode 100644 chicken-wranglers/characters/red/front_stopped_2.png create mode 100644 chicken-wranglers/characters/red/front_walking_1.png create mode 100644 chicken-wranglers/characters/red/front_walking_2.png create mode 100644 chicken-wranglers/characters/red/hencoop.png create mode 100644 chicken-wranglers/characters/red/name.png create mode 100644 chicken-wranglers/characters/red/score.png create mode 100644 chicken-wranglers/characters/red/select_character.png create mode 100644 chicken-wranglers/characters/red/side_stopped_1.png create mode 100644 chicken-wranglers/characters/red/side_stopped_2.png create mode 100644 chicken-wranglers/characters/red/side_walking_1.png create mode 100644 chicken-wranglers/characters/red/side_walking_2.png create mode 100644 chicken-wranglers/characters/red/turnstile_1.png create mode 100644 chicken-wranglers/characters/red/turnstile_2.png create mode 100644 chicken-wranglers/characters/red/turnstile_3.png create mode 100644 chicken-wranglers/characters/red/unavailable.png create mode 100644 chicken-wranglers/characters/red/waitinglist.png create mode 100644 chicken-wranglers/characters/yellow/back_stopped_1.png create mode 100644 chicken-wranglers/characters/yellow/back_stopped_2.png create mode 100644 chicken-wranglers/characters/yellow/back_walking_1.png create mode 100644 chicken-wranglers/characters/yellow/back_walking_2.png create mode 100644 chicken-wranglers/characters/yellow/control.png create mode 100644 chicken-wranglers/characters/yellow/front_stopped_1.png create mode 100644 chicken-wranglers/characters/yellow/front_stopped_2.png create mode 100644 chicken-wranglers/characters/yellow/front_walking_1.png create mode 100644 chicken-wranglers/characters/yellow/front_walking_2.png create mode 100644 chicken-wranglers/characters/yellow/hencoop.png create mode 100644 chicken-wranglers/characters/yellow/name.png create mode 100644 chicken-wranglers/characters/yellow/score.png create mode 100644 chicken-wranglers/characters/yellow/select_character.png create mode 100644 chicken-wranglers/characters/yellow/side_stopped_1.png create mode 100644 chicken-wranglers/characters/yellow/side_stopped_2.png create mode 100644 chicken-wranglers/characters/yellow/side_walking_1.png create mode 100644 chicken-wranglers/characters/yellow/side_walking_2.png create mode 100644 chicken-wranglers/characters/yellow/turnstile_1.png create mode 100644 chicken-wranglers/characters/yellow/turnstile_2.png create mode 100644 chicken-wranglers/characters/yellow/turnstile_3.png create mode 100644 chicken-wranglers/characters/yellow/unavailable.png create mode 100644 chicken-wranglers/characters/yellow/waitinglist.png create mode 100644 chicken-wranglers/chicken-wranglers.pro create mode 100644 chicken-wranglers/chicken-wranglers.spec create mode 100644 chicken-wranglers/data/chicken-wranglers.desktop create mode 100644 chicken-wranglers/data/chicken-wranglers.png create mode 100644 chicken-wranglers/data/chicken-wranglers.svg create mode 100644 chicken-wranglers/debian/changelog create mode 100644 chicken-wranglers/debian/compat create mode 100644 chicken-wranglers/debian/control create mode 100755 chicken-wranglers/debian/fixup-scratchbox create mode 100755 chicken-wranglers/debian/rules create mode 100644 chicken-wranglers/doc/class-diagram.dia create mode 100755 chicken-wranglers/doc/standard/codecheck.sh create mode 100644 chicken-wranglers/doc/standard/coding-standards.txt create mode 100644 chicken-wranglers/examples/control/control.pro create mode 100644 chicken-wranglers/examples/control/main.cpp create mode 100644 chicken-wranglers/examples/control/qml/Button.qml create mode 100644 chicken-wranglers/examples/control/qml/ControlPad.qml create mode 100644 chicken-wranglers/examples/control/qml/Options.qml create mode 100644 chicken-wranglers/examples/control/qml/Slider.qml create mode 100644 chicken-wranglers/examples/control/qml/main.qml create mode 100644 chicken-wranglers/examples/control/qml/qml.qrc create mode 100644 chicken-wranglers/examples/control/testcontrol.h create mode 100644 chicken-wranglers/examples/examples.pro create mode 100644 chicken-wranglers/examples/network/main.cpp create mode 100644 chicken-wranglers/examples/network/network.pro create mode 100644 chicken-wranglers/examples/network/widget.cpp create mode 100644 chicken-wranglers/examples/network/widget.h create mode 100644 chicken-wranglers/resources/common.qrc create mode 100644 chicken-wranglers/resources/images/battlefield/bg_fence_stones.png create mode 100644 chicken-wranglers/resources/images/battlefield/bg_fence_stones_mobile.png create mode 100644 chicken-wranglers/resources/images/battlefield/bt_quit.png create mode 100644 chicken-wranglers/resources/images/battlefield/bt_quit_pressed.png create mode 100644 chicken-wranglers/resources/images/battlefield/clock.png create mode 100644 chicken-wranglers/resources/images/battlefield/fence_corner_bottom_left.png create mode 100644 chicken-wranglers/resources/images/battlefield/fence_corner_bottom_right.png create mode 100644 chicken-wranglers/resources/images/battlefield/fence_corner_top_left.png create mode 100644 chicken-wranglers/resources/images/battlefield/fence_corner_top_right.png create mode 100644 chicken-wranglers/resources/images/battlefield/fence_layer_over.png create mode 100644 chicken-wranglers/resources/images/battlefield/hencoop_plate.png create mode 100644 chicken-wranglers/resources/images/chicken/back_stopped_1.png create mode 100644 chicken-wranglers/resources/images/chicken/back_stopped_2.png create mode 100644 chicken-wranglers/resources/images/chicken/back_walking_1.png create mode 100644 chicken-wranglers/resources/images/chicken/back_walking_2.png create mode 100644 chicken-wranglers/resources/images/chicken/front_stopped_1.png create mode 100644 chicken-wranglers/resources/images/chicken/front_stopped_2.png create mode 100644 chicken-wranglers/resources/images/chicken/front_walking_1.png create mode 100644 chicken-wranglers/resources/images/chicken/front_walking_2.png create mode 100644 chicken-wranglers/resources/images/chicken/side_stopped_1.png create mode 100644 chicken-wranglers/resources/images/chicken/side_stopped_2.png create mode 100644 chicken-wranglers/resources/images/chicken/side_walking_1.png create mode 100644 chicken-wranglers/resources/images/chicken/side_walking_2.png create mode 100644 chicken-wranglers/resources/images/general/bg_1280x768.png create mode 100644 chicken-wranglers/resources/images/general/bg_800x480.png create mode 100644 chicken-wranglers/resources/images/general/bg_dialog.png create mode 100644 chicken-wranglers/resources/images/general/bg_selectcharacter.png create mode 100644 chicken-wranglers/resources/images/general/bg_splash.png create mode 100644 chicken-wranglers/resources/images/general/bluetooth_icon.png create mode 100644 chicken-wranglers/resources/images/general/bt.png create mode 100644 chicken-wranglers/resources/images/general/bt_back.png create mode 100644 chicken-wranglers/resources/images/general/bt_back_pressed.png create mode 100644 chicken-wranglers/resources/images/general/bt_close.png create mode 100644 chicken-wranglers/resources/images/general/bt_close_pressed.png create mode 100644 chicken-wranglers/resources/images/general/bt_disabled.png create mode 100644 chicken-wranglers/resources/images/general/bt_next.png create mode 100644 chicken-wranglers/resources/images/general/bt_pressed.png create mode 100644 chicken-wranglers/resources/images/general/bt_previous.png create mode 100644 chicken-wranglers/resources/images/general/bt_start.png create mode 100644 chicken-wranglers/resources/images/general/bt_start_disabled.png create mode 100644 chicken-wranglers/resources/images/general/bt_start_pressed.png create mode 100644 chicken-wranglers/resources/images/general/character_highlight.png create mode 100644 chicken-wranglers/resources/images/general/feather1.png create mode 100644 chicken-wranglers/resources/images/general/feather2.png create mode 100644 chicken-wranglers/resources/images/general/feather3.png create mode 100644 chicken-wranglers/resources/images/general/feather4.png create mode 100644 chicken-wranglers/resources/images/general/feather5.png create mode 100644 chicken-wranglers/resources/images/general/line_divisor.png create mode 100644 chicken-wranglers/resources/images/general/list_line_divisor.png create mode 100644 chicken-wranglers/resources/images/general/list_name_bg.png create mode 100644 chicken-wranglers/resources/images/general/list_scrollbar_knob.png create mode 100644 chicken-wranglers/resources/images/general/list_scrollbar_path.png create mode 100644 chicken-wranglers/resources/images/general/list_selected_icon.png create mode 100644 chicken-wranglers/resources/images/general/list_status_ok.png create mode 100644 chicken-wranglers/resources/images/general/list_unknown_character.png create mode 100644 chicken-wranglers/resources/images/general/ruller_path.png create mode 100644 chicken-wranglers/resources/images/general/ruller_selector.png create mode 100644 chicken-wranglers/resources/images/general/slider_bluetooth_icon.png create mode 100644 chicken-wranglers/resources/images/general/slider_path.png create mode 100644 chicken-wranglers/resources/images/general/slider_selector.png create mode 100644 chicken-wranglers/resources/images/general/slider_wifi_icon.png create mode 100644 chicken-wranglers/resources/images/general/symbian/bg_640x360.png create mode 100644 chicken-wranglers/resources/images/general/symbian/bg_dialog.png create mode 100644 chicken-wranglers/resources/images/general/symbian/bg_selectcharacter.png create mode 100644 chicken-wranglers/resources/images/general/symbian/bg_splash.png create mode 100644 chicken-wranglers/resources/images/general/symbian/feather1.png create mode 100644 chicken-wranglers/resources/images/general/symbian/feather2.png create mode 100644 chicken-wranglers/resources/images/general/symbian/feather3.png create mode 100644 chicken-wranglers/resources/images/general/symbian/feather4.png create mode 100644 chicken-wranglers/resources/images/general/symbian/feather5.png create mode 100644 chicken-wranglers/resources/images/general/toggle_bt.png create mode 100644 chicken-wranglers/resources/images/general/toggle_lan.png create mode 100644 chicken-wranglers/resources/images/general/you_are_ready.png create mode 100644 chicken-wranglers/resources/images/laser/laser_horizontal_1.png create mode 100644 chicken-wranglers/resources/images/laser/laser_horizontal_2.png create mode 100644 chicken-wranglers/resources/images/laser/laser_horizontal_3.png create mode 100644 chicken-wranglers/resources/images/laser/laser_horizontal_4.png create mode 100644 chicken-wranglers/resources/images/laser/laser_vertical_1.png create mode 100644 chicken-wranglers/resources/images/laser/laser_vertical_2.png create mode 100644 chicken-wranglers/resources/images/laser/laser_vertical_3.png create mode 100644 chicken-wranglers/resources/images/laser/laser_vertical_4.png create mode 100644 chicken-wranglers/resources/linux.qrc create mode 100644 chicken-wranglers/resources/symbian.qrc create mode 100644 chicken-wranglers/sounds/laser.raw create mode 100644 chicken-wranglers/sounds/match.raw create mode 100644 chicken-wranglers/sounds/score.raw create mode 100644 chicken-wranglers/src/ai/ai.pri create mode 100644 chicken-wranglers/src/ai/graph.cpp create mode 100644 chicken-wranglers/src/ai/graph.h create mode 100644 chicken-wranglers/src/ai/matchai.cpp create mode 100644 chicken-wranglers/src/ai/matchai.h create mode 100644 chicken-wranglers/src/control/control.cpp create mode 100644 chicken-wranglers/src/control/control.h create mode 100644 chicken-wranglers/src/control/control.pri create mode 100644 chicken-wranglers/src/control/sensormovement.cpp create mode 100644 chicken-wranglers/src/control/sensormovement.h create mode 100644 chicken-wranglers/src/controllers/chickencontroller.cpp create mode 100644 chicken-wranglers/src/controllers/chickencontroller.h create mode 100644 chicken-wranglers/src/controllers/controllers.pri create mode 100644 chicken-wranglers/src/controllers/matchcontroller.cpp create mode 100644 chicken-wranglers/src/controllers/matchcontroller.h create mode 100644 chicken-wranglers/src/controllers/playercontroller.cpp create mode 100644 chicken-wranglers/src/controllers/playercontroller.h create mode 100644 chicken-wranglers/src/main/argumentparser.cpp create mode 100644 chicken-wranglers/src/main/argumentparser.h create mode 100644 chicken-wranglers/src/main/game.cpp create mode 100644 chicken-wranglers/src/main/game.h create mode 100644 chicken-wranglers/src/main/gameclient.cpp create mode 100644 chicken-wranglers/src/main/gameclient.h create mode 100644 chicken-wranglers/src/main/gamehost.cpp create mode 100644 chicken-wranglers/src/main/gamehost.h create mode 100644 chicken-wranglers/src/main/main.cpp create mode 100644 chicken-wranglers/src/main/main.pri create mode 100644 chicken-wranglers/src/main/settings.cpp create mode 100644 chicken-wranglers/src/main/settings.h create mode 100644 chicken-wranglers/src/models/bluetoothdevice.cpp create mode 100644 chicken-wranglers/src/models/bluetoothdevice.h create mode 100644 chicken-wranglers/src/models/charactermodel.cpp create mode 100644 chicken-wranglers/src/models/charactermodel.h create mode 100644 chicken-wranglers/src/models/connectivitylistmodel.cpp create mode 100644 chicken-wranglers/src/models/connectivitylistmodel.h create mode 100644 chicken-wranglers/src/models/models.pri create mode 100644 chicken-wranglers/src/models/playermodel.cpp create mode 100644 chicken-wranglers/src/models/playermodel.h create mode 100644 chicken-wranglers/src/network/bluetoothconnection.cpp create mode 100644 chicken-wranglers/src/network/bluetoothconnection.h create mode 100644 chicken-wranglers/src/network/bluetoothhandler.cpp create mode 100644 chicken-wranglers/src/network/bluetoothhandler.h create mode 100644 chicken-wranglers/src/network/bthandler.cpp create mode 100644 chicken-wranglers/src/network/bthandler.h create mode 100644 chicken-wranglers/src/network/connectionfactory.cpp create mode 100644 chicken-wranglers/src/network/connectionfactory.h create mode 100644 chicken-wranglers/src/network/lanhandler.cpp create mode 100644 chicken-wranglers/src/network/lanhandler.h create mode 100644 chicken-wranglers/src/network/network.h create mode 100644 chicken-wranglers/src/network/network.pri create mode 100644 chicken-wranglers/src/network/networkclient.cpp create mode 100644 chicken-wranglers/src/network/networkclient.h create mode 100644 chicken-wranglers/src/network/networkconnection.cpp create mode 100644 chicken-wranglers/src/network/networkconnection.h create mode 100644 chicken-wranglers/src/network/networkmessage.cpp create mode 100644 chicken-wranglers/src/network/networkmessage.h create mode 100644 chicken-wranglers/src/network/networkserver.cpp create mode 100644 chicken-wranglers/src/network/networkserver.h create mode 100644 chicken-wranglers/src/network/tcpconnection.cpp create mode 100644 chicken-wranglers/src/network/tcpconnection.h create mode 100644 chicken-wranglers/src/network/udphandler.cpp create mode 100644 chicken-wranglers/src/network/udphandler.h create mode 100644 chicken-wranglers/src/qml/Being.qml create mode 100644 chicken-wranglers/src/qml/Character.qml create mode 100644 chicken-wranglers/src/qml/CharacterSelectionView.qml create mode 100644 chicken-wranglers/src/qml/Chicken.qml create mode 100644 chicken-wranglers/src/qml/ClientView.qml create mode 100644 chicken-wranglers/src/qml/HenCoop.qml create mode 100644 chicken-wranglers/src/qml/HostView.qml create mode 100644 chicken-wranglers/src/qml/Laser.qml create mode 100644 chicken-wranglers/src/qml/MatchView.qml create mode 100644 chicken-wranglers/src/qml/PlayerControlView.qml create mode 100644 chicken-wranglers/src/qml/PlayerReadyView.qml create mode 100644 chicken-wranglers/src/qml/Score.qml create mode 100644 chicken-wranglers/src/qml/ScoreBox.qml create mode 100644 chicken-wranglers/src/qml/Splash.qml create mode 100644 chicken-wranglers/src/qml/StartView.qml create mode 100644 chicken-wranglers/src/qml/WaitingRoomView.qml create mode 100644 chicken-wranglers/src/qml/client.js create mode 100644 chicken-wranglers/src/qml/common.js create mode 100644 chicken-wranglers/src/qml/host.js create mode 100644 chicken-wranglers/src/qml/main.qml create mode 100644 chicken-wranglers/src/qml/match.js create mode 100644 chicken-wranglers/src/qml/qml.qrc create mode 100644 chicken-wranglers/src/qml/widgets/BaseDialog.qml create mode 100644 chicken-wranglers/src/qml/widgets/Button.qml create mode 100644 chicken-wranglers/src/qml/widgets/ConfirmationDialog.qml create mode 100644 chicken-wranglers/src/qml/widgets/ConnectivityDialog.qml create mode 100644 chicken-wranglers/src/qml/widgets/ConnectivityListModel.qml create mode 100644 chicken-wranglers/src/qml/widgets/ConnectivityListView.qml create mode 100644 chicken-wranglers/src/qml/widgets/Countdown.qml create mode 100644 chicken-wranglers/src/qml/widgets/Feather.qml create mode 100644 chicken-wranglers/src/qml/widgets/FeatherFall.qml create mode 100644 chicken-wranglers/src/qml/widgets/ImageButton.qml create mode 100644 chicken-wranglers/src/qml/widgets/Loading.qml create mode 100644 chicken-wranglers/src/qml/widgets/MessageDialog.qml create mode 100644 chicken-wranglers/src/qml/widgets/OptionSlider.qml create mode 100644 chicken-wranglers/src/qml/widgets/Screen.qml create mode 100644 chicken-wranglers/src/qml/widgets/Scrollbar.qml create mode 100644 chicken-wranglers/src/qml/widgets/ToggleButton.qml create mode 100644 chicken-wranglers/src/qml/widgets/featherfall.js create mode 100644 chicken-wranglers/src/sound/sound.cpp create mode 100644 chicken-wranglers/src/sound/sound.h create mode 100644 chicken-wranglers/src/sound/sound.pri create mode 100644 chicken-wranglers/src/sound/sound_linux.cpp create mode 100644 chicken-wranglers/src/sound/sound_linux.h create mode 100644 chicken-wranglers/src/sound/sound_linux.pri create mode 100644 chicken-wranglers/src/sound/soundmanager.cpp create mode 100644 chicken-wranglers/src/sound/soundmanager.h create mode 100644 chicken-wranglers/src/utils/global.cpp create mode 100644 chicken-wranglers/src/utils/global.h create mode 100644 chicken-wranglers/src/utils/utils.pri diff --git a/chicken-wranglers/.gitignore b/chicken-wranglers/.gitignore new file mode 100644 index 0000000..f44634f --- /dev/null +++ b/chicken-wranglers/.gitignore @@ -0,0 +1,12 @@ +*.swp +*.o +build* +Makefile +*.orig* +*.pro.user +.qmake.cache +moc_* +qrc_* +bin/ +lib/ +chicken-wranglers diff --git a/chicken-wranglers/AUTHORS b/chicken-wranglers/AUTHORS new file mode 100644 index 0000000..afe0620 --- /dev/null +++ b/chicken-wranglers/AUTHORS @@ -0,0 +1,8 @@ +Adenilson Cavalcanti +Diego Gonzalez +Edisson Braga +Frederico Duarte +Ragner Magalhaes +Rodrigo Belem +Rodrigo Goncalves +Tomaz Noleto diff --git a/chicken-wranglers/LICENSE b/chicken-wranglers/LICENSE new file mode 100644 index 0000000..5176706 --- /dev/null +++ b/chicken-wranglers/LICENSE @@ -0,0 +1,2 @@ +Chicken Wranglers artwork and sound assets by Nokia Corp. +under a Creative Commons Attribution 3.0 Unported License. diff --git a/chicken-wranglers/README b/chicken-wranglers/README new file mode 100644 index 0000000..29e4a2e --- /dev/null +++ b/chicken-wranglers/README @@ -0,0 +1,15 @@ +Requirements: + +* Qt >= 4.7 (Declarative module is used) +* QtMobility >= 1.2 (Connectivity and Sensors modules are used) + +Build: + +$ qmake +$ make -j2 + +The application file is generated in the 'bin' directory. + +Run: + +$ chicken-wranglers [-displaysize WIDTHxHEIGHT] [-connectivity bluetooth|lan] diff --git a/chicken-wranglers/characters/blue/back_stopped_1.png b/chicken-wranglers/characters/blue/back_stopped_1.png new file mode 100644 index 0000000..73903b2 Binary files /dev/null and b/chicken-wranglers/characters/blue/back_stopped_1.png differ diff --git a/chicken-wranglers/characters/blue/back_stopped_2.png b/chicken-wranglers/characters/blue/back_stopped_2.png new file mode 100644 index 0000000..94b2c50 Binary files /dev/null and b/chicken-wranglers/characters/blue/back_stopped_2.png differ diff --git a/chicken-wranglers/characters/blue/back_walking_1.png b/chicken-wranglers/characters/blue/back_walking_1.png new file mode 100644 index 0000000..abef09f Binary files /dev/null and b/chicken-wranglers/characters/blue/back_walking_1.png differ diff --git a/chicken-wranglers/characters/blue/back_walking_2.png b/chicken-wranglers/characters/blue/back_walking_2.png new file mode 100644 index 0000000..edee866 Binary files /dev/null and b/chicken-wranglers/characters/blue/back_walking_2.png differ diff --git a/chicken-wranglers/characters/blue/control.png b/chicken-wranglers/characters/blue/control.png new file mode 100644 index 0000000..fd6602a Binary files /dev/null and b/chicken-wranglers/characters/blue/control.png differ diff --git a/chicken-wranglers/characters/blue/front_stopped_1.png b/chicken-wranglers/characters/blue/front_stopped_1.png new file mode 100644 index 0000000..2ce0226 Binary files /dev/null and b/chicken-wranglers/characters/blue/front_stopped_1.png differ diff --git a/chicken-wranglers/characters/blue/front_stopped_2.png b/chicken-wranglers/characters/blue/front_stopped_2.png new file mode 100644 index 0000000..3eafc18 Binary files /dev/null and b/chicken-wranglers/characters/blue/front_stopped_2.png differ diff --git a/chicken-wranglers/characters/blue/front_walking_1.png b/chicken-wranglers/characters/blue/front_walking_1.png new file mode 100644 index 0000000..cc09254 Binary files /dev/null and b/chicken-wranglers/characters/blue/front_walking_1.png differ diff --git a/chicken-wranglers/characters/blue/front_walking_2.png b/chicken-wranglers/characters/blue/front_walking_2.png new file mode 100644 index 0000000..adcf817 Binary files /dev/null and b/chicken-wranglers/characters/blue/front_walking_2.png differ diff --git a/chicken-wranglers/characters/blue/hencoop.png b/chicken-wranglers/characters/blue/hencoop.png new file mode 100644 index 0000000..bb2e6e3 Binary files /dev/null and b/chicken-wranglers/characters/blue/hencoop.png differ diff --git a/chicken-wranglers/characters/blue/name.png b/chicken-wranglers/characters/blue/name.png new file mode 100644 index 0000000..d4c79d0 Binary files /dev/null and b/chicken-wranglers/characters/blue/name.png differ diff --git a/chicken-wranglers/characters/blue/score.png b/chicken-wranglers/characters/blue/score.png new file mode 100644 index 0000000..23cbe59 Binary files /dev/null and b/chicken-wranglers/characters/blue/score.png differ diff --git a/chicken-wranglers/characters/blue/select_character.png b/chicken-wranglers/characters/blue/select_character.png new file mode 100644 index 0000000..1119a1f Binary files /dev/null and b/chicken-wranglers/characters/blue/select_character.png differ diff --git a/chicken-wranglers/characters/blue/side_stopped_1.png b/chicken-wranglers/characters/blue/side_stopped_1.png new file mode 100644 index 0000000..cc6c88a Binary files /dev/null and b/chicken-wranglers/characters/blue/side_stopped_1.png differ diff --git a/chicken-wranglers/characters/blue/side_stopped_2.png b/chicken-wranglers/characters/blue/side_stopped_2.png new file mode 100644 index 0000000..be498e9 Binary files /dev/null and b/chicken-wranglers/characters/blue/side_stopped_2.png differ diff --git a/chicken-wranglers/characters/blue/side_walking_1.png b/chicken-wranglers/characters/blue/side_walking_1.png new file mode 100644 index 0000000..a560e37 Binary files /dev/null and b/chicken-wranglers/characters/blue/side_walking_1.png differ diff --git a/chicken-wranglers/characters/blue/side_walking_2.png b/chicken-wranglers/characters/blue/side_walking_2.png new file mode 100644 index 0000000..31354dd Binary files /dev/null and b/chicken-wranglers/characters/blue/side_walking_2.png differ diff --git a/chicken-wranglers/characters/blue/turnstile_1.png b/chicken-wranglers/characters/blue/turnstile_1.png new file mode 100644 index 0000000..3a1d8d4 Binary files /dev/null and b/chicken-wranglers/characters/blue/turnstile_1.png differ diff --git a/chicken-wranglers/characters/blue/turnstile_2.png b/chicken-wranglers/characters/blue/turnstile_2.png new file mode 100644 index 0000000..3137c6f Binary files /dev/null and b/chicken-wranglers/characters/blue/turnstile_2.png differ diff --git a/chicken-wranglers/characters/blue/turnstile_3.png b/chicken-wranglers/characters/blue/turnstile_3.png new file mode 100644 index 0000000..d6543f2 Binary files /dev/null and b/chicken-wranglers/characters/blue/turnstile_3.png differ diff --git a/chicken-wranglers/characters/blue/unavailable.png b/chicken-wranglers/characters/blue/unavailable.png new file mode 100644 index 0000000..0cdc4fa Binary files /dev/null and b/chicken-wranglers/characters/blue/unavailable.png differ diff --git a/chicken-wranglers/characters/blue/waitinglist.png b/chicken-wranglers/characters/blue/waitinglist.png new file mode 100644 index 0000000..40109e0 Binary files /dev/null and b/chicken-wranglers/characters/blue/waitinglist.png differ diff --git a/chicken-wranglers/characters/green/back_stopped_1.png b/chicken-wranglers/characters/green/back_stopped_1.png new file mode 100644 index 0000000..d395cda Binary files /dev/null and b/chicken-wranglers/characters/green/back_stopped_1.png differ diff --git a/chicken-wranglers/characters/green/back_stopped_2.png b/chicken-wranglers/characters/green/back_stopped_2.png new file mode 100644 index 0000000..df054c6 Binary files /dev/null and b/chicken-wranglers/characters/green/back_stopped_2.png differ diff --git a/chicken-wranglers/characters/green/back_walking_1.png b/chicken-wranglers/characters/green/back_walking_1.png new file mode 100644 index 0000000..7e0974f Binary files /dev/null and b/chicken-wranglers/characters/green/back_walking_1.png differ diff --git a/chicken-wranglers/characters/green/back_walking_2.png b/chicken-wranglers/characters/green/back_walking_2.png new file mode 100644 index 0000000..87f0693 Binary files /dev/null and b/chicken-wranglers/characters/green/back_walking_2.png differ diff --git a/chicken-wranglers/characters/green/control.png b/chicken-wranglers/characters/green/control.png new file mode 100644 index 0000000..4c6f054 Binary files /dev/null and b/chicken-wranglers/characters/green/control.png differ diff --git a/chicken-wranglers/characters/green/front_stopped_1.png b/chicken-wranglers/characters/green/front_stopped_1.png new file mode 100644 index 0000000..24f5c6c Binary files /dev/null and b/chicken-wranglers/characters/green/front_stopped_1.png differ diff --git a/chicken-wranglers/characters/green/front_stopped_2.png b/chicken-wranglers/characters/green/front_stopped_2.png new file mode 100644 index 0000000..60bded2 Binary files /dev/null and b/chicken-wranglers/characters/green/front_stopped_2.png differ diff --git a/chicken-wranglers/characters/green/front_walking_1.png b/chicken-wranglers/characters/green/front_walking_1.png new file mode 100644 index 0000000..744091a Binary files /dev/null and b/chicken-wranglers/characters/green/front_walking_1.png differ diff --git a/chicken-wranglers/characters/green/front_walking_2.png b/chicken-wranglers/characters/green/front_walking_2.png new file mode 100644 index 0000000..c0e0708 Binary files /dev/null and b/chicken-wranglers/characters/green/front_walking_2.png differ diff --git a/chicken-wranglers/characters/green/hencoop.png b/chicken-wranglers/characters/green/hencoop.png new file mode 100644 index 0000000..8be665d Binary files /dev/null and b/chicken-wranglers/characters/green/hencoop.png differ diff --git a/chicken-wranglers/characters/green/name.png b/chicken-wranglers/characters/green/name.png new file mode 100644 index 0000000..2ef832b Binary files /dev/null and b/chicken-wranglers/characters/green/name.png differ diff --git a/chicken-wranglers/characters/green/score.png b/chicken-wranglers/characters/green/score.png new file mode 100644 index 0000000..d8774dc Binary files /dev/null and b/chicken-wranglers/characters/green/score.png differ diff --git a/chicken-wranglers/characters/green/select_character.png b/chicken-wranglers/characters/green/select_character.png new file mode 100644 index 0000000..532d6eb Binary files /dev/null and b/chicken-wranglers/characters/green/select_character.png differ diff --git a/chicken-wranglers/characters/green/side_stopped_1.png b/chicken-wranglers/characters/green/side_stopped_1.png new file mode 100644 index 0000000..5f49b60 Binary files /dev/null and b/chicken-wranglers/characters/green/side_stopped_1.png differ diff --git a/chicken-wranglers/characters/green/side_stopped_2.png b/chicken-wranglers/characters/green/side_stopped_2.png new file mode 100644 index 0000000..d426af1 Binary files /dev/null and b/chicken-wranglers/characters/green/side_stopped_2.png differ diff --git a/chicken-wranglers/characters/green/side_walking_1.png b/chicken-wranglers/characters/green/side_walking_1.png new file mode 100644 index 0000000..7ad6072 Binary files /dev/null and b/chicken-wranglers/characters/green/side_walking_1.png differ diff --git a/chicken-wranglers/characters/green/side_walking_2.png b/chicken-wranglers/characters/green/side_walking_2.png new file mode 100644 index 0000000..83f8aca Binary files /dev/null and b/chicken-wranglers/characters/green/side_walking_2.png differ diff --git a/chicken-wranglers/characters/green/turnstile_1.png b/chicken-wranglers/characters/green/turnstile_1.png new file mode 100644 index 0000000..47f877d Binary files /dev/null and b/chicken-wranglers/characters/green/turnstile_1.png differ diff --git a/chicken-wranglers/characters/green/turnstile_2.png b/chicken-wranglers/characters/green/turnstile_2.png new file mode 100644 index 0000000..b8c681d Binary files /dev/null and b/chicken-wranglers/characters/green/turnstile_2.png differ diff --git a/chicken-wranglers/characters/green/turnstile_3.png b/chicken-wranglers/characters/green/turnstile_3.png new file mode 100644 index 0000000..019fe76 Binary files /dev/null and b/chicken-wranglers/characters/green/turnstile_3.png differ diff --git a/chicken-wranglers/characters/green/unavailable.png b/chicken-wranglers/characters/green/unavailable.png new file mode 100644 index 0000000..0cdc4fa Binary files /dev/null and b/chicken-wranglers/characters/green/unavailable.png differ diff --git a/chicken-wranglers/characters/green/waitinglist.png b/chicken-wranglers/characters/green/waitinglist.png new file mode 100644 index 0000000..503cb31 Binary files /dev/null and b/chicken-wranglers/characters/green/waitinglist.png differ diff --git a/chicken-wranglers/characters/red/back_stopped_1.png b/chicken-wranglers/characters/red/back_stopped_1.png new file mode 100644 index 0000000..75f686c Binary files /dev/null and b/chicken-wranglers/characters/red/back_stopped_1.png differ diff --git a/chicken-wranglers/characters/red/back_stopped_2.png b/chicken-wranglers/characters/red/back_stopped_2.png new file mode 100644 index 0000000..820aa2d Binary files /dev/null and b/chicken-wranglers/characters/red/back_stopped_2.png differ diff --git a/chicken-wranglers/characters/red/back_walking_1.png b/chicken-wranglers/characters/red/back_walking_1.png new file mode 100644 index 0000000..bcdafb7 Binary files /dev/null and b/chicken-wranglers/characters/red/back_walking_1.png differ diff --git a/chicken-wranglers/characters/red/back_walking_2.png b/chicken-wranglers/characters/red/back_walking_2.png new file mode 100644 index 0000000..1f685d4 Binary files /dev/null and b/chicken-wranglers/characters/red/back_walking_2.png differ diff --git a/chicken-wranglers/characters/red/control.png b/chicken-wranglers/characters/red/control.png new file mode 100644 index 0000000..85db1ac Binary files /dev/null and b/chicken-wranglers/characters/red/control.png differ diff --git a/chicken-wranglers/characters/red/front_stopped_1.png b/chicken-wranglers/characters/red/front_stopped_1.png new file mode 100644 index 0000000..979330f Binary files /dev/null and b/chicken-wranglers/characters/red/front_stopped_1.png differ diff --git a/chicken-wranglers/characters/red/front_stopped_2.png b/chicken-wranglers/characters/red/front_stopped_2.png new file mode 100644 index 0000000..e0216f7 Binary files /dev/null and b/chicken-wranglers/characters/red/front_stopped_2.png differ diff --git a/chicken-wranglers/characters/red/front_walking_1.png b/chicken-wranglers/characters/red/front_walking_1.png new file mode 100644 index 0000000..5bff6ad Binary files /dev/null and b/chicken-wranglers/characters/red/front_walking_1.png differ diff --git a/chicken-wranglers/characters/red/front_walking_2.png b/chicken-wranglers/characters/red/front_walking_2.png new file mode 100644 index 0000000..7a71031 Binary files /dev/null and b/chicken-wranglers/characters/red/front_walking_2.png differ diff --git a/chicken-wranglers/characters/red/hencoop.png b/chicken-wranglers/characters/red/hencoop.png new file mode 100644 index 0000000..56f5294 Binary files /dev/null and b/chicken-wranglers/characters/red/hencoop.png differ diff --git a/chicken-wranglers/characters/red/name.png b/chicken-wranglers/characters/red/name.png new file mode 100644 index 0000000..14c5792 Binary files /dev/null and b/chicken-wranglers/characters/red/name.png differ diff --git a/chicken-wranglers/characters/red/score.png b/chicken-wranglers/characters/red/score.png new file mode 100644 index 0000000..2da1497 Binary files /dev/null and b/chicken-wranglers/characters/red/score.png differ diff --git a/chicken-wranglers/characters/red/select_character.png b/chicken-wranglers/characters/red/select_character.png new file mode 100644 index 0000000..1928687 Binary files /dev/null and b/chicken-wranglers/characters/red/select_character.png differ diff --git a/chicken-wranglers/characters/red/side_stopped_1.png b/chicken-wranglers/characters/red/side_stopped_1.png new file mode 100644 index 0000000..ea3c0c0 Binary files /dev/null and b/chicken-wranglers/characters/red/side_stopped_1.png differ diff --git a/chicken-wranglers/characters/red/side_stopped_2.png b/chicken-wranglers/characters/red/side_stopped_2.png new file mode 100644 index 0000000..3ca7373 Binary files /dev/null and b/chicken-wranglers/characters/red/side_stopped_2.png differ diff --git a/chicken-wranglers/characters/red/side_walking_1.png b/chicken-wranglers/characters/red/side_walking_1.png new file mode 100644 index 0000000..2356795 Binary files /dev/null and b/chicken-wranglers/characters/red/side_walking_1.png differ diff --git a/chicken-wranglers/characters/red/side_walking_2.png b/chicken-wranglers/characters/red/side_walking_2.png new file mode 100644 index 0000000..8c56da6 Binary files /dev/null and b/chicken-wranglers/characters/red/side_walking_2.png differ diff --git a/chicken-wranglers/characters/red/turnstile_1.png b/chicken-wranglers/characters/red/turnstile_1.png new file mode 100644 index 0000000..73e4cfa Binary files /dev/null and b/chicken-wranglers/characters/red/turnstile_1.png differ diff --git a/chicken-wranglers/characters/red/turnstile_2.png b/chicken-wranglers/characters/red/turnstile_2.png new file mode 100644 index 0000000..cdf35cc Binary files /dev/null and b/chicken-wranglers/characters/red/turnstile_2.png differ diff --git a/chicken-wranglers/characters/red/turnstile_3.png b/chicken-wranglers/characters/red/turnstile_3.png new file mode 100644 index 0000000..e6a0396 Binary files /dev/null and b/chicken-wranglers/characters/red/turnstile_3.png differ diff --git a/chicken-wranglers/characters/red/unavailable.png b/chicken-wranglers/characters/red/unavailable.png new file mode 100644 index 0000000..0cdc4fa Binary files /dev/null and b/chicken-wranglers/characters/red/unavailable.png differ diff --git a/chicken-wranglers/characters/red/waitinglist.png b/chicken-wranglers/characters/red/waitinglist.png new file mode 100644 index 0000000..aba7bf5 Binary files /dev/null and b/chicken-wranglers/characters/red/waitinglist.png differ diff --git a/chicken-wranglers/characters/yellow/back_stopped_1.png b/chicken-wranglers/characters/yellow/back_stopped_1.png new file mode 100644 index 0000000..1c0b998 Binary files /dev/null and b/chicken-wranglers/characters/yellow/back_stopped_1.png differ diff --git a/chicken-wranglers/characters/yellow/back_stopped_2.png b/chicken-wranglers/characters/yellow/back_stopped_2.png new file mode 100644 index 0000000..cfd2cb7 Binary files /dev/null and b/chicken-wranglers/characters/yellow/back_stopped_2.png differ diff --git a/chicken-wranglers/characters/yellow/back_walking_1.png b/chicken-wranglers/characters/yellow/back_walking_1.png new file mode 100644 index 0000000..1a19f38 Binary files /dev/null and b/chicken-wranglers/characters/yellow/back_walking_1.png differ diff --git a/chicken-wranglers/characters/yellow/back_walking_2.png b/chicken-wranglers/characters/yellow/back_walking_2.png new file mode 100644 index 0000000..a02bef2 Binary files /dev/null and b/chicken-wranglers/characters/yellow/back_walking_2.png differ diff --git a/chicken-wranglers/characters/yellow/control.png b/chicken-wranglers/characters/yellow/control.png new file mode 100644 index 0000000..ddb64a0 Binary files /dev/null and b/chicken-wranglers/characters/yellow/control.png differ diff --git a/chicken-wranglers/characters/yellow/front_stopped_1.png b/chicken-wranglers/characters/yellow/front_stopped_1.png new file mode 100644 index 0000000..f2e9501 Binary files /dev/null and b/chicken-wranglers/characters/yellow/front_stopped_1.png differ diff --git a/chicken-wranglers/characters/yellow/front_stopped_2.png b/chicken-wranglers/characters/yellow/front_stopped_2.png new file mode 100644 index 0000000..de03f90 Binary files /dev/null and b/chicken-wranglers/characters/yellow/front_stopped_2.png differ diff --git a/chicken-wranglers/characters/yellow/front_walking_1.png b/chicken-wranglers/characters/yellow/front_walking_1.png new file mode 100644 index 0000000..5abff00 Binary files /dev/null and b/chicken-wranglers/characters/yellow/front_walking_1.png differ diff --git a/chicken-wranglers/characters/yellow/front_walking_2.png b/chicken-wranglers/characters/yellow/front_walking_2.png new file mode 100644 index 0000000..f3627f3 Binary files /dev/null and b/chicken-wranglers/characters/yellow/front_walking_2.png differ diff --git a/chicken-wranglers/characters/yellow/hencoop.png b/chicken-wranglers/characters/yellow/hencoop.png new file mode 100644 index 0000000..d9f250e Binary files /dev/null and b/chicken-wranglers/characters/yellow/hencoop.png differ diff --git a/chicken-wranglers/characters/yellow/name.png b/chicken-wranglers/characters/yellow/name.png new file mode 100644 index 0000000..eb6708c Binary files /dev/null and b/chicken-wranglers/characters/yellow/name.png differ diff --git a/chicken-wranglers/characters/yellow/score.png b/chicken-wranglers/characters/yellow/score.png new file mode 100644 index 0000000..67e05dc Binary files /dev/null and b/chicken-wranglers/characters/yellow/score.png differ diff --git a/chicken-wranglers/characters/yellow/select_character.png b/chicken-wranglers/characters/yellow/select_character.png new file mode 100644 index 0000000..da66f31 Binary files /dev/null and b/chicken-wranglers/characters/yellow/select_character.png differ diff --git a/chicken-wranglers/characters/yellow/side_stopped_1.png b/chicken-wranglers/characters/yellow/side_stopped_1.png new file mode 100644 index 0000000..d63eabc Binary files /dev/null and b/chicken-wranglers/characters/yellow/side_stopped_1.png differ diff --git a/chicken-wranglers/characters/yellow/side_stopped_2.png b/chicken-wranglers/characters/yellow/side_stopped_2.png new file mode 100644 index 0000000..1f212b7 Binary files /dev/null and b/chicken-wranglers/characters/yellow/side_stopped_2.png differ diff --git a/chicken-wranglers/characters/yellow/side_walking_1.png b/chicken-wranglers/characters/yellow/side_walking_1.png new file mode 100644 index 0000000..09312ac Binary files /dev/null and b/chicken-wranglers/characters/yellow/side_walking_1.png differ diff --git a/chicken-wranglers/characters/yellow/side_walking_2.png b/chicken-wranglers/characters/yellow/side_walking_2.png new file mode 100644 index 0000000..048913e Binary files /dev/null and b/chicken-wranglers/characters/yellow/side_walking_2.png differ diff --git a/chicken-wranglers/characters/yellow/turnstile_1.png b/chicken-wranglers/characters/yellow/turnstile_1.png new file mode 100644 index 0000000..8ca09ef Binary files /dev/null and b/chicken-wranglers/characters/yellow/turnstile_1.png differ diff --git a/chicken-wranglers/characters/yellow/turnstile_2.png b/chicken-wranglers/characters/yellow/turnstile_2.png new file mode 100644 index 0000000..6213024 Binary files /dev/null and b/chicken-wranglers/characters/yellow/turnstile_2.png differ diff --git a/chicken-wranglers/characters/yellow/turnstile_3.png b/chicken-wranglers/characters/yellow/turnstile_3.png new file mode 100644 index 0000000..ff623d3 Binary files /dev/null and b/chicken-wranglers/characters/yellow/turnstile_3.png differ diff --git a/chicken-wranglers/characters/yellow/unavailable.png b/chicken-wranglers/characters/yellow/unavailable.png new file mode 100644 index 0000000..0cdc4fa Binary files /dev/null and b/chicken-wranglers/characters/yellow/unavailable.png differ diff --git a/chicken-wranglers/characters/yellow/waitinglist.png b/chicken-wranglers/characters/yellow/waitinglist.png new file mode 100644 index 0000000..0d481ee Binary files /dev/null and b/chicken-wranglers/characters/yellow/waitinglist.png differ diff --git a/chicken-wranglers/chicken-wranglers.pro b/chicken-wranglers/chicken-wranglers.pro new file mode 100644 index 0000000..2384f04 --- /dev/null +++ b/chicken-wranglers/chicken-wranglers.pro @@ -0,0 +1,123 @@ +TEMPLATE = app +TARGET = chicken-wranglers + +QT += opengl + +CONFIG += warn_on release +MOBILITY = connectivity sensors + +INSTALL_PREFIX = $$PREFIX +isEmpty (INSTALL_PREFIX){ + INSTALL_PREFIX = /usr +} + +MOC_DIR = tmp +OBJECTS_DIR = tmp +RCC_DIR = tmp + +SOURCE_TREE = $$PWD +SRC_PATH = $$SOURCE_TREE + +INCLUDEPATH += \ + src/ai \ + src/control \ + src/controllers \ + src/main \ + src/models \ + src/network \ + src/sound \ + src/utils + +include(src/ai/ai.pri) +include(src/control/control.pri) +include(src/controllers/controllers.pri) +include(src/main/main.pri) +include(src/models/models.pri) +include(src/network/network.pri) +include(src/utils/utils.pri) + +RESOURCES += $$SRC_PATH/resources/common.qrc + +CONFIG(debug, debug|release) { + DEFINES += CW_DEBUG +} else { + RESOURCES += src/qml/qml.qrc +} + +unix:!symbian{ + RESOURCES += $$SRC_PATH/resources/linux.qrc + CONFIG += link_pkgconfig + PKGCONFIG += libpulse-simple + + include(src/sound/sound_linux.pri) + + desktop.files = data/chicken-wranglers.desktop + desktop.path = /usr/share/applications + maemo5: desktop.path = /usr/share/applications/hildon + INSTALLS += desktop + + icon.files = data/chicken-wranglers.svg + icon.path = $$INSTALL_PREFIX/share/icons/hicolor/scalable/apps + INSTALLS += icon + + icon64.files = data/chicken-wranglers.png + icon64.path = $$INSTALL_PREFIX/share/icons/hicolor/scalable/apps + INSTALLS += icon64 + + characters.files = characters + characters.path = $$INSTALL_PREFIX/share/chicken-wranglers + INSTALLS += characters + + sounds.files = sounds + sounds.path = $$INSTALL_PREFIX/share/chicken-wranglers + INSTALLS += sounds + + distclean-all.commands = rm -rf $$OUT_PWD/lib $$OUT_PWD/bin $$OUT_PWD/.qmake.cache + distclean-all.depends = distclean + !equals($$OUT_IN, $$OUT_PWD): dist-clean.commands += $$OUT_PWD + + QMAKE_EXTRA_TARGETS += distclean-all +} + +symbian { + RESOURCES += $$SRC_PATH/resources/symbian.qrc + + include(src/sound/sound.pri) + + TARGET.UID3 = 0xE9131562 + + TARGET.CAPABILITY = \ + NetworkServices \ + LocalServices \ + ReadUserData \ + UserEnvironment \ + WriteUserData + + symbian-abld|symbian-sbsv2 { + # ro-section in gui can exceed default allocated space, + # so move rw-section a little further + QMAKE_LFLAGS.ARMCC += --rw-base 0x800000 + QMAKE_LFLAGS.GCCE += -Tdata 0xC00000 + } + + TARGET.EPOCHEAPSIZE = 0x20000 0x8000000 + + TARGET.EPOCSTACKSIZE = 0x14000 + + characters.sources = characters + characters.path = C:\\DATA\\chicken-wranglers + DEPLOYMENT += characters + + LIBS += \ + -lavkon \ + -leikcore \ + -lcone + + ICON = $$SRC_PATH/data/chicken-wranglers.svg +} + +DESTDIR += $$OUT_PWD/bin + +target.path = $$INSTALL_PREFIX/bin + +INSTALLS += target diff --git a/chicken-wranglers/chicken-wranglers.spec b/chicken-wranglers/chicken-wranglers.spec new file mode 100644 index 0000000..0d75431 --- /dev/null +++ b/chicken-wranglers/chicken-wranglers.spec @@ -0,0 +1,58 @@ +# +Name: chicken-wranglers +Summary: Chicken Wranglers +Version: 0.1 +Release: 1%{?dist} +Group: Applications/Game +License: BSD +URL: http://qt.nokia.com +Source: %{name}-%{version}.tar.gz +Requires: qt +Requires: qt-mobility +BuildRequires: pkgconfig(QtOpenGL) +BuildRequires: pkgconfig(QtDeclarative) +BuildRequires: pkgconfig(QtConnectivity) +BuildRequires: pkgconfig(QtSensors) + +%description +Chicken Wranglers - chicken catch game + +%prep +%setup -q -n %{name}-%{version} + +%build +qmake PREFIX=%{_prefix} +make %{?_smp_mflags} + +%install +%qmake_install + +%clean +make distclean-all +rm -rf %{buildroot} + +%files +%defattr(-,root,root,-) +%attr(755,root,root)%{_bindir}/chicken-wranglers +%{_datadir}/icons/hicolor/scalable/apps/chicken-wranglers.png +%{_datadir}/icons/hicolor/32x32/apps/chicken-wranglers.png +%{_datadir}/applications/chicken-wranglers.desktop +%{_datadir}/chicken-wranglers/characters/blue/* +%{_datadir}/chicken-wranglers/characters/green/* +%{_datadir}/chicken-wranglers/characters/red/* +%{_datadir}/chicken-wranglers/characters/yellow/* +%{_datadir}/chicken-wranglers/sounds/* + + +%changelog +* Thu Jul 14 2011 Rodrigo Gonçalves de Oliveira - 0.0.4-1 +- New Release +* Thu May 21 2011 Rodrigo Belem - 0.0.3-1 +- New Release +* Thu Feb 11 2011 Rodrigo Belem - 0.0.2-1 +- New Release +- Added QtOpenGL as build requires +* Thu Feb 7 2011 Rodrigo Belem - 0.0.1-2 +- Package updated to match latest game changes +* Fri Jan 14 2011 Benedito Neto - 0.0.1-1 +- Packaging diff --git a/chicken-wranglers/data/chicken-wranglers.desktop b/chicken-wranglers/data/chicken-wranglers.desktop new file mode 100644 index 0000000..4daa55a --- /dev/null +++ b/chicken-wranglers/data/chicken-wranglers.desktop @@ -0,0 +1,8 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=1.0 +Type=Application +Name=Chicken Wranglers +Exec=chicken-wranglers +X-Osso-Type=application/x-executable +Icon=chicken-wranglers diff --git a/chicken-wranglers/data/chicken-wranglers.png b/chicken-wranglers/data/chicken-wranglers.png new file mode 100644 index 0000000..e15fa2d Binary files /dev/null and b/chicken-wranglers/data/chicken-wranglers.png differ diff --git a/chicken-wranglers/data/chicken-wranglers.svg b/chicken-wranglers/data/chicken-wranglers.svg new file mode 100644 index 0000000..036ac1d --- /dev/null +++ b/chicken-wranglers/data/chicken-wranglers.svg @@ -0,0 +1,492 @@ + + + + + + + + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 +M0uC8dMZIQHZz0/awxAhxhDhaSDWNSJs8AYR8IaeV40E5sul3jIDCwk0TmaJsL7CEGE3/8tKEz0C +FPlORapezkOHxIkE7E4V3J6ZokjFzNm3SgRhzPvkg5TB2PehXqpISTDIPdC70VUiROorl88OfBCN +MFQMb4Xe7FjJEQB7Cs2MIOixQa4AqOy7g4j5kAg3eYjGmaj1jN1I+AAQCLuCSM7bjRSjLWfsBufI +VBYAJCPVFgTvF4QDgDjDUoHwTNIdX59KPWCO1QSIeTVMPG4BQObIU41GPOHQBhNHsG3grT5MPOlj +NMS9i0hEBVHbPTMDSNkxNqGY725wMwqXcYtZnPdDCRfZiAsagPSyIVzDpfJR3kKx1LpRc6Urbp5r +d8r9COZ6fhjE6BWhmKVRqfiMhNEBWBnE4DG/bJrywyCWNlgpZssi03SDsyMloZjvbsyqdQweSwlz +SnxK9GORK9L2ST5GQQx2ZNEEQphL6xCLLMS9KeHeBieto7ZBtS9ulBCSc3KEkGLXkWdSXIIfrWNv +kcmUC2ZWe0OazKdfsKjNh+8idFpgJAUWXze21ISds1ZXzQK7/04I1UozTqMKCZqXhIlI+HVSTUS6 +WUoSsFqeEDzhiRZcSpai5KeaiCNvkBTFNTURR95L0J8vw1acPMFMfGVr641mNb2/7n1oSTlHbEPj +XPdNf8GmNcbz4br+Is6+uOGb+oskm5OImUfv+iuOeWHJNyLTp/LxUk0vizGVYdKkJ/idJsiLQFh9 +1d/AYTzVs/Iw6QgTKivpYxFnEQkgYGjMpc731vXEpyo5xQPKSoQw60DAVo6MH07lFQx0KPDtGd7/ +kjo/S2EsJU7ORoCfNzz5hubPps6fxNTJ1TcK9nWMSdZsriZhUvxwbGSuvmlYSEjgMVFI1bZWNz66 +azfQl62i9GUJa7ApYMZJQMJxVstln4DjDsV8Ti/AMYUooofKRVYpl/bWWteFg+Z2SA16PNzzes6l +wCabdqrLKhM/1CS9kzWCRc/2rZ8RHowDATPAsPWblJqFXL/n+PrxQRSennh6BEmq/irsZA8EGJd6 +TdSemhIBoA7i9yWBl1DPh4GC+5T69fcTpz29Gsm/dWFt93hHbc13U2RevIbEKhEF4e3kN6ylZf6k +jVglrr+8Rt/zn+nSWa6jLCvMdiRMGST5jrRDxh96Ept2eBqXGt0bCXcNlS1Grxxf5g== + + + 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 +R71BC+b8vb+xBD7RqofDxbNS4P8CX+KWWw== + + + diff --git a/chicken-wranglers/debian/changelog b/chicken-wranglers/debian/changelog new file mode 100644 index 0000000..55373cd --- /dev/null +++ b/chicken-wranglers/debian/changelog @@ -0,0 +1,5 @@ +chicken-wranglers (0.1-0) unstable; urgency=low + + * Initial release + + -- Rodrigo Belem Fri, 21 Oct 2011 07:09:00 -0400 diff --git a/chicken-wranglers/debian/compat b/chicken-wranglers/debian/compat new file mode 100644 index 0000000..7f8f011 --- /dev/null +++ b/chicken-wranglers/debian/compat @@ -0,0 +1 @@ +7 diff --git a/chicken-wranglers/debian/control b/chicken-wranglers/debian/control new file mode 100644 index 0000000..2a80b3a --- /dev/null +++ b/chicken-wranglers/debian/control @@ -0,0 +1,14 @@ +Source: chicken-wranglers +Section: user +Priority: extra +Maintainer: Rodrigo Belem +Build-Depends: debhelper (>= 5), cdbs, libpulse-dev, libqt4-dev (>= 4.7), + qtmobility-dev (>= 1.2) | libqtm-12-dev (>= 1.2) | libqtm-dev (>= 1.2) +Standards-Version: 3.8.0 +Homepage: http://qt.nokia.com + +Package: chicken-wranglers +Architecture: any +Depends: ${misc:Depends}, ${shlibs:Depends} +Description: Chicken Wranglers - chicken catch game + diff --git a/chicken-wranglers/debian/fixup-scratchbox b/chicken-wranglers/debian/fixup-scratchbox new file mode 100755 index 0000000..5e9896d --- /dev/null +++ b/chicken-wranglers/debian/fixup-scratchbox @@ -0,0 +1,53 @@ +#! /bin/sh + +# XXX - this needs to run under fakeroot... + +exec 3>&1 1>&2 + +real_dpkg_checkbuilddeps () { + SBOX_REDIRECT_IGNORE=/usr/bin/perl /usr/bin/perl /usr/bin/dpkg-checkbuilddeps "$@" +} + +finish () { + if ! real_dpkg_checkbuilddeps; then + echo "This package does not use any devkits." + echo "Please install all build dependencies as real packages." + echo >&3 FAIL + fi + exit 0 +} + +# The stamp file can not be in the source tree because then it would +# end up in the source package, which is not what we want. We put it +# into /var/tmp so that it gets deleted when a new rootstrap is +# extracted. + +STAMP=/var/tmp/SANITIZED.$(head debian/changelog | md5sum | cut -d' ' -f1) + +if [ -e $STAMP ]; then + exit 0; +fi + +# Only do permanent changes if this is BIFH + +echo "$USER" | grep -q 'bifh[0-9]' || finish + +# prevent bash from killing the system +rm -f /var/lib/bash/provide-sh + +# clean ~/.texmf-var to avoid trouble with stale things hiding there. +rm -rf ~/.texmf-var/ + +pfx="dpkg-checkbuilddeps: Unmet build dependencies:" +deps=`real_dpkg_checkbuilddeps 2>&1 | grep "^$pfx" | \ + sed -e "s/$pfx//" -e s'/([^)]*)//g' -e 's/|//'` +deps="$deps build-essential automake autoconf libtool ed gawk diff dpkg-dev" +for d in $deps; do + echo apt-get "$@" install $d + apt-get -o DPkg::Options::=--force-confold -q --force-yes --yes install $d +done +apt-get -o DPkg::Options::=--force-confold -q --force-yes --yes dist-upgrade + +touch $STAMP + +finish diff --git a/chicken-wranglers/debian/rules b/chicken-wranglers/debian/rules new file mode 100755 index 0000000..72c94da --- /dev/null +++ b/chicken-wranglers/debian/rules @@ -0,0 +1,15 @@ +#!/usr/bin/make -f + +ifneq (,$(wildcard /targets)) + ifeq (,$(SBOX_DONT_SANITIZE)) + export PATH:=/bin:/usr/bin + export MAKE:=make + export SBOX_REDIRECT_TO_DIRS:=/scratchbox/compilers/bin + ifneq (,$(shell debian/fixup-scratchbox)) + $(error Error) + endif + endif +endif + +include /usr/share/cdbs/1/rules/debhelper.mk +include /usr/share/cdbs/1/class/qmake.mk diff --git a/chicken-wranglers/doc/class-diagram.dia b/chicken-wranglers/doc/class-diagram.dia new file mode 100644 index 0000000..3074c9d Binary files /dev/null and b/chicken-wranglers/doc/class-diagram.dia differ diff --git a/chicken-wranglers/doc/standard/codecheck.sh b/chicken-wranglers/doc/standard/codecheck.sh new file mode 100755 index 0000000..e99eb25 --- /dev/null +++ b/chicken-wranglers/doc/standard/codecheck.sh @@ -0,0 +1,56 @@ +#!/bin/bash -e +# Script based on git://gitorious.org/qt-codecheck/qt-codecheck.git +# by Milton Soares Filho + +die () +{ + echo "FAIL!: $*" + exit 1 +} + +ASTYLE=$(which astyle) + +[ -z "${ASTYLE}" ] && die "missing astyle binary" + +ASTYLE_SUFFIX=.astyle.orig + +ASTYLE_OPTIONS="-n --indent=spaces=4 --brackets=linux \ + --indent-labels --indent-namespaces \ + --pad-oper --pad-header --keep-one-line-statements \ + --keep-one-line-blocks --convert-tabs --indent-preprocessor \ + --align-pointer=name --suffix=${ASTYLE_SUFFIX}" + +# this may not work with absolute paths +# FIXME: Check it later +#cd "$(dirname $0)/.." +#SUBDIRS="src tests" + +FILTERIN="-name '*.cpp' -o -name '*.cc' -o -name '*.h'" + +# Filter out moc generated files +FILTEROUT="-not -name 'moc_*'" + +SOURCES=$(find -type f -name '*.h' -o -name '*.cc' -o -name '*.cpp' -not -name 'moc_*' -not -name 'qrc_*') +sandboxdir=$(mktemp -dt astyle.XXXXXXXX) + +[ -z ${sandboxdir} ] && die "could not create tempdir" + +for f in ${SOURCES}; do + cp --parents $f ${sandboxdir} +done + +# many commands below have non-zero exit code +set +e + +pushd ${sandboxdir} > /dev/null + find . -type f -exec ${ASTYLE} ${ASTYLE_OPTIONS} {} \; | grep formatted +popd > /dev/null + +PATCH_FILE=astyle.patch +diff -ru . ${sandboxdir} | grep -ve '^Only in ' > ${PATCH_FILE} +count=$(cat ${PATCH_FILE} | wc -l) + +[ ${count} -eq 0 ] || die "bad formatting, check ${PATCH_FILE}" + +rm -f ${PATCH_FILE} +echo "PASS: coding style ok" diff --git a/chicken-wranglers/doc/standard/coding-standards.txt b/chicken-wranglers/doc/standard/coding-standards.txt new file mode 100644 index 0000000..95f42bd --- /dev/null +++ b/chicken-wranglers/doc/standard/coding-standards.txt @@ -0,0 +1,209 @@ +http://developer.qt.nokia.com/wiki/Qt_Coding_Style +http://techbase.kde.org/Policies/Kdelibs_Coding_Style + +Qt Coding Style + +This is an overview of the coding conventions we use when writing Qt code. +The data has been gathered by mining the Qt sources, discussion forums, email threads and through collaboration of the developers. + +Indentation +============ +4 spaces are used for indentation +Spaces, not tabs! + +Declaring variables +=================== +Declare each variable on a separate line +Avoid short (e.g. “aâ€, “rbarrâ€, “nughdegetâ€) names whenever possible +Single character variable names are only okay for counters and temporaries, where the purpose of the variable is obvious +Wait when declaring a variable until it is needed +// Wrong +int a, b; +char *c, *d; + +// Correct +int height; +int width; +char *nameOfThis; +char *nameOfThat; + +Variables and functions start with a lower-case letter. Each consecutive word in a variable’s name starts with an upper-case letter +Avoid abbreviations +// Wrong +short Cntr; +char ITEM_DELIM = '\t'; + +// Correct +short counter; +char itemDelimiter = '\t'; +Classes always start with an upper-case letter. Public classes start with a ‘Q’ (QRgb). Public functions most often start with a ‘q’ (qRgb). + +Whitespace +=============== +Use blank lines to group statements together where suited +Always use only one blank line +Always use a single space after a keyword and before a curly brace. +// Wrong +if(foo){ +} + +// Correct +if (foo) { +} + +For pointers or references, always use a single space between the type and ‘*’ or ‘&’, but no space between the ‘*’ or ‘&’ and the variable name. +char *x; +const QString &myString; +const char * const y = "hello"; +Surround binary operators with spaces. +No space after a cast. +Avoid C-style casts when possible. +// Wrong +char* blockOfMemory = (char* ) malloc(data.size()); + +// Correct +char *blockOfMemory = reinterpret_cast(malloc(data.size())); + +Braces +========== +As a base rule, the left curly brace goes on the same line as the start of the statement: +// Wrong +if (codec) +{ +} + +// Correct +if (codec) { +} +Exception: Function implementations and class declarations always have the left brace on the start of a line: +static void foo(int g) +{ + qDebug("foo: %i", g); +} + +class Moo +{ +}; +Use curly braces when the body of a conditional statement contains more than one line, and also if a single line statement is somewhat complex. +// Wrong +if (address.isEmpty()) { + return false; +} + +for (int i = 0; i < 10; ++i) { + qDebug("%i", i); +} + +// Correct +if (address.isEmpty()) + return false; + +for (int i = 0; i < 10; ++i) + qDebug("%i", i); +Exception 1: Use braces also if the parent statement covers several lines / wraps +// Correct +if (address.isEmpty() || !isValid() + || !codec) { + return false; +} +Exception 2: Use braces also in if-then-else blocks where either the if-code or the else-code covers several lines +// Wrong +if (address.isEmpty()) + return false; +else { + qDebug("%s", qPrintable(address)); + ++it; +} + +// Correct +if (address.isEmpty()) { + return false; +} else { + qDebug("%s", qPrintable(address)); + ++it; +} + +// Wrong +if (a) + if (b) + ... + else + ... + +// Correct +if (a) { + if (b) + ... + else + ... +} +Use curly braces when the body of a conditional statement is empty +// Wrong +while (a); + +// Correct +while (a) {} +Parentheses + +Use parentheses to group expressions: +// Wrong +if (a && b || c) + +// Correct +if ((a && b) || c) + +// Wrong +a + b & c + +// Correct +(a + b) & c + +Switch statements +==================== +The case labels are in the same column as the switch +Every case must have a break (or return) statement at the end or a comment to indicate that there’s intentionally no break +switch (myEnum) { +case Value1: + doSomething(); + break; +case Value2: + doSomethingElse(); + // fall through +default: + defaultHandling(); + break; +} + +Line breaks +=============== +Keep lines shorter than 100 characters; insert breaks if necessary. +Commas go at the end of a broken line; operators start at the beginning of the new line. An operator at the end of the line is easy to not see if your editor is too narrow. +// Correct +if (longExpression + + otherLongExpression + + otherOtherLongExpression) { +} + +// Wrong +if (longExpression + + otherLongExpression + + otherOtherLongExpression) { +} + +Inheritance and the `virtual` keyword +======================================== +When reimplementing a virtual method, do not put the `virtual` keyword in the header file. + +Line breaks +============ +Try to keep lines shorter than 100 characters, inserting line breaks as necessary. + +Qt Includes +============ +If you add #includes for Qt classes, use both the module and class name. This allows library code to be used by applications without excessive compiler include paths. +Example: +// wrong +#include + +// correct + diff --git a/chicken-wranglers/examples/control/control.pro b/chicken-wranglers/examples/control/control.pro new file mode 100644 index 0000000..f945f5e --- /dev/null +++ b/chicken-wranglers/examples/control/control.pro @@ -0,0 +1,51 @@ +TEMPLATE = app + +TARGET = control_example + +QT += declarative + +maemo5 { + CONFIG += mobility12 +} else { + CONFIG += mobility +} + +MOBILITY += sensors + +INCLUDEPATH += $$PWD/../../src/control \ + $$PWD/../../src/utils + +SOURCES += \ + main.cpp \ + $$PWD/../../src/control/control.cpp \ + $$PWD/../../src/control/sensormovement.cpp \ + $$PWD/../../src/utils/global.cpp \ + $$PWD/../../src/utils/screen.cpp +HEADERS += \ + $$PWD/../../src/control/control.h \ + $$PWD/../../src/control/sensormovement.h \ + $$PWD/../../src/utils/global.h \ + $$PWD/../../src/utils/screen.h \ + testcontrol.h + +RESOURCES += qml/qml.qrc + +symbian { + TARGET.UID3 = 0xE9131533 + + TARGET.CAPABILITY = \ + ReadUserData \ + UserEnvironment \ + WriteUserData + + TARGET.EPOCHEAPSIZE = 0x20000 0x8000000 + + TARGET.EPOCSTACKSIZE = 0x14000 + + + LIBS += \ + -lavkon \ + -leikcore \ + -lcone + +} diff --git a/chicken-wranglers/examples/control/main.cpp b/chicken-wranglers/examples/control/main.cpp new file mode 100644 index 0000000..d215516 --- /dev/null +++ b/chicken-wranglers/examples/control/main.cpp @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#include +#include +#include +#include +#include + +#include "control.h" +#include "sensormovement.h" +#include "testcontrol.h" +#include "screen.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + Control control; + SensorMovement *sensorMovement = control.sensorMovement(); + sensorMovement->setMinimumRotation(2.5); + sensorMovement->setThreshold(0.5); + control.start(); + + TestControl testControl; + QObject::connect(&control, SIGNAL(directionChanged(Global::Direction)), + &testControl, SLOT(onDirectionChanged(Global::Direction))); + + qmlRegisterType("game.types", 1, 0, "Global"); + + QDeclarativeView view; + view.rootContext()->setContextProperty("control", &control); + view.rootContext()->setContextProperty("sensorMovement", sensorMovement); + view.setSource(QString("qrc:main.qml")); + view.setResizeMode(QDeclarativeView::SizeRootObjectToView); + Utils::setOrientation(Utils::Landscape); + view.showFullScreen(); + + return app.exec(); +} diff --git a/chicken-wranglers/examples/control/qml/Button.qml b/chicken-wranglers/examples/control/qml/Button.qml new file mode 100644 index 0000000..b0e4ed4 --- /dev/null +++ b/chicken-wranglers/examples/control/qml/Button.qml @@ -0,0 +1,126 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +Rectangle { + id: button + + property string text: "Button" + + property bool isCheckable: false + property bool isToggled: false + property bool enabled: true + + property string normalColor: "lightgrey" + property string toggledColor: "steelblue" + property string pressedColor: "lightblue" + property string disabledColor: "white" + property string borderColor: "black" + property string labelColor: "black" + property string labelDisabledColor: "grey" + + signal clicked + signal toggled(bool isToggled) + + width: label.width + 20 + height: label.height + 20 + smooth: true + radius: 20 + + border { + width: 2 + color: borderColor + } + + MouseArea { + id: mouseArea + anchors.fill: parent + enabled: button.enabled + onClicked: { + if (isCheckable) { + isToggled = !isToggled + toggled(isToggled) + } + + button.clicked() + } + } + + Text { + id: label + anchors.centerIn: button + color: labelColor + text: button.text + font.pixelSize: 18 + font.family: "NokiaSans" + } + + states { + State { + name: "disabled"; when: !mouseArea.enabled + PropertyChanges { target: button; color: disabledColor } + PropertyChanges { target: label; color: labelDisabledColor } + } + + State { + name: "pressed"; when: mouseArea.pressed + PropertyChanges { target: button; color: pressedColor } + } + + State { + name: "normal"; when: !isToggled + PropertyChanges { target: button; color: normalColor } + } + + State { + name: "toggled"; when: isToggled + PropertyChanges { target: button; color: toggledColor } + } + } + + transitions { + Transition { + ColorAnimation { duration: 100 } + } + } +} diff --git a/chicken-wranglers/examples/control/qml/ControlPad.qml b/chicken-wranglers/examples/control/qml/ControlPad.qml new file mode 100644 index 0000000..11c1d3e --- /dev/null +++ b/chicken-wranglers/examples/control/qml/ControlPad.qml @@ -0,0 +1,201 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 +import game.types 1.0 + +Rectangle { + id: controlPad + + property bool touchEnabled: !sensorMovement.enabled + property int rectSize: 120 + + property string padColor: "lightgrey" + property string knobColor: "steelblue" + property string borderColor: "black" + + width: 400 + height: 480 + + Rectangle { + id: center + width: rectSize; height: rectSize; + anchors.centerIn: parent + } + + Rectangle { + id: up + color: padColor + width: rectSize; height: rectSize; + anchors.bottom: center.top + anchors.horizontalCenter: center.horizontalCenter + } + + Rectangle { + id: left + color: padColor + width: rectSize; height: rectSize; + anchors.right: center.left + anchors.verticalCenter: center.verticalCenter + } + + Rectangle { + id: right + color: padColor + width: rectSize; height: rectSize; + anchors.left: center.right + anchors.verticalCenter: center.verticalCenter + } + + Rectangle { + id: down + color: padColor + width: rectSize; height: rectSize; + anchors.top: center.bottom + anchors.horizontalCenter: center.horizontalCenter + } + + MouseArea { + hoverEnabled: true + anchors.fill: parent + + function setDirection(direction, knobState) { + knob.state = knobState + + if (control.direction != direction) + control.direction = direction + } + + function moveKnob(mouse) { + if (!pressed || !controlPad.touchEnabled) + return; + + var pos = mapToItem(parent, mouse.x, mouse.y) + + if (pos.x < 0 || pos.y < 0 || pos.x > parent.width || pos.y > parent.height) + return; + + if (pos.x < center.x) { + if (pos.y < center.y) + setDirection(Control.UpLeft, "UpLeft") + else if (pos.y > down.y) + setDirection(Control.DownLeft, "DownLeft") + else + setDirection(Control.Left, "Left") + } else if (pos.x > right.x) { + if (pos.y < center.y) + setDirection(Control.UpRight, "UpRight") + else if (pos.y > down.y) + setDirection(Control.DownRight, "DownRight") + else + setDirection(Control.Right, "Right") + } else { + if (pos.y < center.y) + setDirection(Control.Up, "Up") + else if (pos.y > down.y) + setDirection(Control.Down, "Down") + else + setDirection(Control.Stop, "Stop") + } + } + + function stopKnob() { + if (!controlPad.touchEnabled) + return; + + setDirection(Control.Stop, "Stop") + } + + onPositionChanged: moveKnob(mouse) + onPressed: moveKnob(mouse) + onReleased: stopKnob() + } + + Rectangle { + id: knob + color: knobColor; + + width: rectSize + height: rectSize + radius: rectSize + smooth: true; + + x: center.x + y: center.y + + Behavior on x { SpringAnimation { spring: 3; damping: 0.2 } } + Behavior on y { SpringAnimation { spring: 3; damping: 0.2 } } + + border { + color: borderColor + width: 2 + } + + states { + State { + name: "Up"; + PropertyChanges { target: knob; x: up.x; y: up.y; } + } + State { + name: "Down"; + PropertyChanges { target: knob; x: down.x; y: down.y } + } + State { + name: "Right"; + PropertyChanges { target: knob; x: right.x; y: right.y } + } + State { + name: "Left"; + PropertyChanges { target: knob; x: left.x; y: left.y } + } + State { + name: "Stop"; + PropertyChanges { target: knob; x: center.x; y: center.y } + } + } + + Connections { + target: control + onDirectionChanged: knob.state = control.directionString + } + } +} diff --git a/chicken-wranglers/examples/control/qml/Options.qml b/chicken-wranglers/examples/control/qml/Options.qml new file mode 100644 index 0000000..fc60fec --- /dev/null +++ b/chicken-wranglers/examples/control/qml/Options.qml @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +Rectangle { + id: settings + + width: 400 + height: 480 + + property int defaultWidth: 340 + + Column { + anchors.verticalCenter: parent.verticalCenter + anchors.horizontalCenter: parent.horizontalCenter + + spacing: 20 + + Button { + id: restartPositionButton + width: defaultWidth + text: "Reset start position" + onClicked: sensorMovement.resetStartPosition() + + } + + Button { + id: useSensorButton + width: defaultWidth + text: "Use sensor" + isCheckable: true + isToggled: sensorMovement.enabled + + onToggled: { + enabled: sensorMovement.enabled + sensorMovement.enabled = isToggled + useSensorButton.isToggled = sensorMovement.enabled + } + } + + Slider { + width: defaultWidth + text: "Minimum rotation (degrees):" + maxValue: 45 + currentValue: sensorMovement.minimumRotation + + onValueChanged: sensorMovement.minimumRotation = value + } + + Slider { + width: defaultWidth + text: "Treshold (degrees):" + maxValue: 20 + currentValue: sensorMovement.threshold + + onValueChanged: sensorMovement.threshold = value + } + + Slider { + width: defaultWidth + text: "Direction timeout (ms):" + maxValue: 500 + currentValue: sensorMovement.directionTimeout + + onValueChanged: sensorMovement.directionTimeout = value + } + } +} diff --git a/chicken-wranglers/examples/control/qml/Slider.qml b/chicken-wranglers/examples/control/qml/Slider.qml new file mode 100644 index 0000000..44daa7a --- /dev/null +++ b/chicken-wranglers/examples/control/qml/Slider.qml @@ -0,0 +1,182 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +Item { + id: slider + + height: 80 + + property int maxValue: 0 + property int currentValue: 0 + property string text: "Slider" + + property alias valueText: value.text + + property string borderColor: "black" + property string textColor: "black" + property string knobColor: "steelblue" + + signal valueChanged(int value) + + Text { + id: label + + color: textColor + font.family: "NokiaSans" + font.pixelSize: 18 + text: slider.text + + anchors { + top: parent.top + left: parent.left + } + } + + Text { + id: value + color: knobColor + font.family: "NokiaSans" + font.pixelSize: 18 + font.bold: true + text: currentValue + + anchors { + left: label.right + leftMargin: 10 + } + } + + Rectangle { + id: line + + color: "lightgrey" + width: slider.width + height: knob.height + 2 + radius: 50 + smooth: true + + anchors { + top: label.bottom + topMargin: 5 + } + + MouseArea { + anchors.fill: parent + onPressed: { + var pos = mouse.x - knob.width + if (pos < 0) + pos = 0 + + knob.x = pos + knob.checkPositionChange(pos) + } + } + } + + Rectangle { + id: lineFill + + color: "steelblue" + opacity: 0.5 + height: line.height + radius: line.radius + smooth: true + + anchors { + top: line.top + left: line.left + right: knob.right + } + } + + Rectangle { + id: knob + + function valueForPosition(pos) { + return Math.round(pos / ((line.width - knob.width) / slider.maxValue)) + } + + function positionForValue(value) { + return Math.round(value * ((line.width - knob.width) / slider.maxValue)) + } + + function checkPositionChange(pos) { + var newValue = knob.valueForPosition(pos) + + slider.currentValue = newValue + slider.valueText = currentValue + slider.valueChanged(newValue) + } + + color: knobColor + width: 50 + height: 50 + radius: 50 + smooth: true + + x: positionForValue(slider.currentValue) + + border { + color: borderColor + width: 2 + } + + MouseArea { + anchors.fill: parent + + drag.target: knob + drag.axis: Drag.XAxis + drag.minimumX: 0 + drag.maximumX: line.width - knob.width + + onPositionChanged: knob.checkPositionChange(knob.x) + } + + anchors { + verticalCenter: line.verticalCenter + } + + Behavior on x { NumberAnimation { duration: 120 } } + } +} diff --git a/chicken-wranglers/examples/control/qml/main.qml b/chicken-wranglers/examples/control/qml/main.qml new file mode 100644 index 0000000..ddcdfee --- /dev/null +++ b/chicken-wranglers/examples/control/qml/main.qml @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +Rectangle { + id: main + + width: 800 + height: 480 + + Row { + Options { + id: options + anchors.verticalCenter: parent.verticalCenter + } + + ControlPad { + id: controlPad + anchors.verticalCenter: parent.verticalCenter + } + } +} diff --git a/chicken-wranglers/examples/control/qml/qml.qrc b/chicken-wranglers/examples/control/qml/qml.qrc new file mode 100644 index 0000000..9d40a30 --- /dev/null +++ b/chicken-wranglers/examples/control/qml/qml.qrc @@ -0,0 +1,9 @@ + + + main.qml + Button.qml + Slider.qml + ControlPad.qml + Options.qml + + diff --git a/chicken-wranglers/examples/control/testcontrol.h b/chicken-wranglers/examples/control/testcontrol.h new file mode 100644 index 0000000..041abb9 --- /dev/null +++ b/chicken-wranglers/examples/control/testcontrol.h @@ -0,0 +1,23 @@ +#ifndef TESTCONTROL_H +#define TESTCONTROL_H + +#include "global.h" + +#include +#include + +class TestControl : public QObject +{ + Q_OBJECT + +public: + TestControl(QObject *parent = 0) : QObject(parent) {} + +public slots: + void onDirectionChanged(Global::Direction direction) + { + qDebug() << "Direction changed:" << Global::directionString(direction); + } +}; + +#endif diff --git a/chicken-wranglers/examples/examples.pro b/chicken-wranglers/examples/examples.pro new file mode 100644 index 0000000..69cb8dc --- /dev/null +++ b/chicken-wranglers/examples/examples.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs + +SUBDIRS += \ + control diff --git a/chicken-wranglers/examples/network/main.cpp b/chicken-wranglers/examples/network/main.cpp new file mode 100644 index 0000000..89a5b9d --- /dev/null +++ b/chicken-wranglers/examples/network/main.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#include + +#include "widget.h" + +int main(int argc, char **argv) +{ + QApplication application(argc, argv); + + Widget widget; + +#if defined(Q_WS_MAEMO_5) + widget.showMaximized(); +#else + widget.resize(400, 240); + widget.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + widget.show(); +#endif + + return application.exec(); +} diff --git a/chicken-wranglers/examples/network/network.pro b/chicken-wranglers/examples/network/network.pro new file mode 100644 index 0000000..5bbc892 --- /dev/null +++ b/chicken-wranglers/examples/network/network.pro @@ -0,0 +1,33 @@ +TEMPLATE = app + +QT += network + +BUILD_TESTS=$$BUILD_DEBUG +isEqual(BUILD_DEBUG, 1) { + CONFIG += debug +} + +CONFIG(debug, debug|release) { + TARGET = network_example_debug + + LIBS += -Wl,-rpath,$$BUILD_TREE/lib -L$$BUILD_TREE/lib \ + -lnetwork_debug +} else { + TARGET = network_example + + LIBS += -Wl,-rpath,$$BUILD_TREE/lib -L$$BUILD_TREE/lib \ + $$BUILD_TREE/lib/libnetwork.a + + DEFINES += QT_NO_DEBUG_OUTPUT QT_NO_WARNING_OUTPUT +} + +INCLUDEPATH += $$SOURCE_TREE/src/network + +SOURCES += \ + widget.cpp \ + main.cpp + +HEADERS += \ + widget.h + +DESTDIR = $$BUILD_TREE/bin diff --git a/chicken-wranglers/examples/network/widget.cpp b/chicken-wranglers/examples/network/widget.cpp new file mode 100644 index 0000000..ccdaded --- /dev/null +++ b/chicken-wranglers/examples/network/widget.cpp @@ -0,0 +1,198 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#include +#include +#include +#include +#include +#include + +#include "networkclient.h" + +#include "widget.h" + +Widget::Widget(QWidget *parent) + : QWidget(parent) + , m_client(0) + , m_server(0) +{ + setupWidgets(); + + setupLayouts(); + + setupConnections(); +} + +void Widget::onStartButtonClicked() +{ + m_startButton->setEnabled(false); + m_serverButton->setEnabled(false); + m_clientButton->setEnabled(false); + + if (m_serverButton->isChecked()) { + m_server = new NetworkServer(this); + connect(m_server, SIGNAL(messageSent(QHostAddress, quint16, quint16)), + this, SLOT(onMessageSent(QHostAddress, quint16, quint16))); + connect(m_server, SIGNAL(messageReceived(QHostAddress, quint16, quint16)), + this, SLOT(onMessageReceived(QHostAddress, quint16, quint16))); + connect(m_server, SIGNAL(error(NetworkServer::ServerError)), + this, SLOT(onServerError(NetworkServer::ServerError))); + + m_textEdit->append("----- Server started -----"); + + m_server->start(); + } else { + m_client = new NetworkClient(this); + connect(m_client, SIGNAL(messageSent(QHostAddress, quint16, quint16)), + this, SLOT(onMessageSent(QHostAddress, quint16, quint16))); + connect(m_client, SIGNAL(messageReceived(QHostAddress, quint16, quint16)), + this, SLOT(onMessageReceived(QHostAddress, quint16, quint16))); + + m_textEdit->append("----- Client started -----"); + + m_client->startDiscovery(); + } + + m_stopButton->setEnabled(true); +} + +void Widget::onStopButtonClicked() +{ + m_stopButton->setEnabled(false); + + if (m_serverButton->isChecked()) { + if (m_server != 0) { + m_textEdit->append("----- Server stopped -----"); + + m_server->deleteLater(); + m_server = 0; + } + } else { + if (m_client != 0) { + m_textEdit->append("----- Client stopped -----"); + + m_client->stopDiscovery(); + + m_client->deleteLater(); + m_client = 0; + } + } + + m_startButton->setEnabled(true); + m_serverButton->setEnabled(true); + m_clientButton->setEnabled(true); +} + +void Widget::onMessageSent(QHostAddress address, quint16 content, quint16 senderListenPort) +{ + QString string; + + string = "Sent \"" + QString::number(content) + "\" to " + address.toString() + + " at port " + QString::number(senderListenPort); + + m_textEdit->append(string); +} + +void Widget::onMessageReceived(QHostAddress address, quint16 content, quint16 port) +{ + QString string; + + string = "Received \"" + QString::number(content) + "\" from " + address.toString() + + " at port " + QString::number(port); + + m_textEdit->append(string); +} + +void Widget::onServerError(NetworkServer::ServerError error) +{ + if (error == NetworkServer::AnotherServerRunningError) + m_textEdit->append("Can't start a new server.. there is another one already running"); +} + +void Widget::setupWidgets() +{ + m_serverButton = new QRadioButton("Server"); + m_clientButton = new QRadioButton("Client"); + m_startButton = new QPushButton("Start"); + m_stopButton = new QPushButton("Stop"); + m_textEdit = new QTextEdit(); + + m_serverButton->setChecked(true); + m_startButton->setMinimumHeight(40); + m_stopButton->setMinimumHeight(40); + m_stopButton->setEnabled(false); + m_textEdit->setMaximumHeight(100); + m_textEdit->setReadOnly(true); +} + +void Widget::setupLayouts() +{ + m_verticalLayout = new QVBoxLayout(); + m_verticalLayout->setContentsMargins(0, 0, 0, 0); + m_verticalLayout->setSpacing(0); + + m_horizontalLayout = new QHBoxLayout(); + m_horizontalLayout->setContentsMargins(0, 0, 0, 0); + m_horizontalLayout->setSpacing(0); + + m_horizontalLayout->addStretch(); + m_horizontalLayout->addWidget(m_serverButton); + m_horizontalLayout->addStretch(); + m_horizontalLayout->addWidget(m_clientButton); + m_horizontalLayout->addStretch(); + + m_verticalLayout->addLayout(m_horizontalLayout); + m_verticalLayout->addWidget(m_startButton); + m_verticalLayout->addWidget(m_stopButton); + m_verticalLayout->addWidget(m_textEdit); + + setLayout(m_verticalLayout); +} + +void Widget::setupConnections() +{ + connect(m_startButton, SIGNAL(clicked()), + this, SLOT(onStartButtonClicked())); + connect(m_stopButton, SIGNAL(clicked()), + this, SLOT(onStopButtonClicked())); +} diff --git a/chicken-wranglers/examples/network/widget.h b/chicken-wranglers/examples/network/widget.h new file mode 100644 index 0000000..583c620 --- /dev/null +++ b/chicken-wranglers/examples/network/widget.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef WIDGET_H +#define WIDGET_H + +#include +#include + +#include "networkserver.h" + +class NetworkClient; + +class QHBoxLayout; +class QPushButton; +class QRadioButton; +class QTextEdit; +class QVBoxLayout; + +class Widget : public QWidget +{ + Q_OBJECT + +public: + Widget(QWidget *parent = 0); + +private slots: + void onStartButtonClicked(); + void onStopButtonClicked(); + void onMessageSent(QHostAddress address, quint16 content, quint16 senderListenPort); + void onMessageReceived(QHostAddress address, quint16 content, quint16 port); + void onServerError(NetworkServer::ServerError error); + +private: + void setupWidgets(); + void setupLayouts(); + void setupConnections(); + + QRadioButton *m_serverButton; + QRadioButton *m_clientButton; + QPushButton *m_startButton; + QPushButton *m_stopButton; + QTextEdit *m_textEdit; + QVBoxLayout *m_verticalLayout; + QHBoxLayout *m_horizontalLayout; + NetworkClient *m_client; + NetworkServer *m_server; +}; + +#endif diff --git a/chicken-wranglers/resources/common.qrc b/chicken-wranglers/resources/common.qrc new file mode 100644 index 0000000..ff793bd --- /dev/null +++ b/chicken-wranglers/resources/common.qrc @@ -0,0 +1,63 @@ + + + + images/general/toggle_lan.png + images/general/toggle_bt.png + images/general/bt.png + images/general/bt_disabled.png + images/general/bt_pressed.png + images/general/bt_back.png + images/general/bt_close.png + images/general/bt_close_pressed.png + images/general/bt_next.png + images/general/bt_previous.png + images/general/bt_back_pressed.png + images/general/bt_start.png + images/general/bt_start_disabled.png + images/general/bt_start_pressed.png + images/general/list_line_divisor.png + images/general/list_scrollbar_knob.png + images/general/list_scrollbar_path.png + images/general/list_selected_icon.png + images/general/character_highlight.png + images/general/list_name_bg.png + images/general/list_status_ok.png + images/general/list_unknown_character.png + images/general/you_are_ready.png + images/general/bluetooth_icon.png + images/general/line_divisor.png + + images/battlefield/fence_corner_top_left.png + images/battlefield/fence_corner_top_right.png + images/battlefield/fence_corner_bottom_left.png + images/battlefield/fence_corner_bottom_right.png + images/battlefield/fence_layer_over.png + images/battlefield/hencoop_plate.png + images/battlefield/clock.png + images/battlefield/bt_quit.png + images/battlefield/bt_quit_pressed.png + + images/laser/laser_horizontal_1.png + images/laser/laser_horizontal_2.png + images/laser/laser_horizontal_3.png + images/laser/laser_horizontal_4.png + images/laser/laser_vertical_1.png + images/laser/laser_vertical_2.png + images/laser/laser_vertical_3.png + images/laser/laser_vertical_4.png + + images/chicken/front_stopped_1.png + images/chicken/front_stopped_2.png + images/chicken/front_walking_1.png + images/chicken/front_walking_2.png + images/chicken/back_stopped_1.png + images/chicken/back_stopped_2.png + images/chicken/back_walking_1.png + images/chicken/back_walking_2.png + images/chicken/side_walking_1.png + images/chicken/side_walking_2.png + images/chicken/side_stopped_1.png + images/chicken/side_stopped_2.png + + + diff --git a/chicken-wranglers/resources/images/battlefield/bg_fence_stones.png b/chicken-wranglers/resources/images/battlefield/bg_fence_stones.png new file mode 100644 index 0000000..cc90ceb Binary files /dev/null and b/chicken-wranglers/resources/images/battlefield/bg_fence_stones.png differ diff --git a/chicken-wranglers/resources/images/battlefield/bg_fence_stones_mobile.png b/chicken-wranglers/resources/images/battlefield/bg_fence_stones_mobile.png new file mode 100644 index 0000000..55bfbd3 Binary files /dev/null and b/chicken-wranglers/resources/images/battlefield/bg_fence_stones_mobile.png differ diff --git a/chicken-wranglers/resources/images/battlefield/bt_quit.png b/chicken-wranglers/resources/images/battlefield/bt_quit.png new file mode 100644 index 0000000..f5a97d2 Binary files /dev/null and b/chicken-wranglers/resources/images/battlefield/bt_quit.png differ diff --git a/chicken-wranglers/resources/images/battlefield/bt_quit_pressed.png b/chicken-wranglers/resources/images/battlefield/bt_quit_pressed.png new file mode 100644 index 0000000..8412c4b Binary files /dev/null and b/chicken-wranglers/resources/images/battlefield/bt_quit_pressed.png differ diff --git a/chicken-wranglers/resources/images/battlefield/clock.png b/chicken-wranglers/resources/images/battlefield/clock.png new file mode 100644 index 0000000..88bf45c Binary files /dev/null and b/chicken-wranglers/resources/images/battlefield/clock.png differ diff --git a/chicken-wranglers/resources/images/battlefield/fence_corner_bottom_left.png b/chicken-wranglers/resources/images/battlefield/fence_corner_bottom_left.png new file mode 100644 index 0000000..5725b4d Binary files /dev/null and b/chicken-wranglers/resources/images/battlefield/fence_corner_bottom_left.png differ diff --git a/chicken-wranglers/resources/images/battlefield/fence_corner_bottom_right.png b/chicken-wranglers/resources/images/battlefield/fence_corner_bottom_right.png new file mode 100644 index 0000000..df4c751 Binary files /dev/null and b/chicken-wranglers/resources/images/battlefield/fence_corner_bottom_right.png differ diff --git a/chicken-wranglers/resources/images/battlefield/fence_corner_top_left.png b/chicken-wranglers/resources/images/battlefield/fence_corner_top_left.png new file mode 100644 index 0000000..0357fa5 Binary files /dev/null and b/chicken-wranglers/resources/images/battlefield/fence_corner_top_left.png differ diff --git a/chicken-wranglers/resources/images/battlefield/fence_corner_top_right.png b/chicken-wranglers/resources/images/battlefield/fence_corner_top_right.png new file mode 100644 index 0000000..d28e105 Binary files /dev/null and b/chicken-wranglers/resources/images/battlefield/fence_corner_top_right.png differ diff --git a/chicken-wranglers/resources/images/battlefield/fence_layer_over.png b/chicken-wranglers/resources/images/battlefield/fence_layer_over.png new file mode 100644 index 0000000..920c634 Binary files /dev/null and b/chicken-wranglers/resources/images/battlefield/fence_layer_over.png differ diff --git a/chicken-wranglers/resources/images/battlefield/hencoop_plate.png b/chicken-wranglers/resources/images/battlefield/hencoop_plate.png new file mode 100644 index 0000000..531c406 Binary files /dev/null and b/chicken-wranglers/resources/images/battlefield/hencoop_plate.png differ diff --git a/chicken-wranglers/resources/images/chicken/back_stopped_1.png b/chicken-wranglers/resources/images/chicken/back_stopped_1.png new file mode 100644 index 0000000..8c4fbbe Binary files /dev/null and b/chicken-wranglers/resources/images/chicken/back_stopped_1.png differ diff --git a/chicken-wranglers/resources/images/chicken/back_stopped_2.png b/chicken-wranglers/resources/images/chicken/back_stopped_2.png new file mode 100644 index 0000000..2507371 Binary files /dev/null and b/chicken-wranglers/resources/images/chicken/back_stopped_2.png differ diff --git a/chicken-wranglers/resources/images/chicken/back_walking_1.png b/chicken-wranglers/resources/images/chicken/back_walking_1.png new file mode 100644 index 0000000..358c382 Binary files /dev/null and b/chicken-wranglers/resources/images/chicken/back_walking_1.png differ diff --git a/chicken-wranglers/resources/images/chicken/back_walking_2.png b/chicken-wranglers/resources/images/chicken/back_walking_2.png new file mode 100644 index 0000000..9534847 Binary files /dev/null and b/chicken-wranglers/resources/images/chicken/back_walking_2.png differ diff --git a/chicken-wranglers/resources/images/chicken/front_stopped_1.png b/chicken-wranglers/resources/images/chicken/front_stopped_1.png new file mode 100644 index 0000000..4f47d4c Binary files /dev/null and b/chicken-wranglers/resources/images/chicken/front_stopped_1.png differ diff --git a/chicken-wranglers/resources/images/chicken/front_stopped_2.png b/chicken-wranglers/resources/images/chicken/front_stopped_2.png new file mode 100644 index 0000000..7e7e2f7 Binary files /dev/null and b/chicken-wranglers/resources/images/chicken/front_stopped_2.png differ diff --git a/chicken-wranglers/resources/images/chicken/front_walking_1.png b/chicken-wranglers/resources/images/chicken/front_walking_1.png new file mode 100644 index 0000000..acf50e6 Binary files /dev/null and b/chicken-wranglers/resources/images/chicken/front_walking_1.png differ diff --git a/chicken-wranglers/resources/images/chicken/front_walking_2.png b/chicken-wranglers/resources/images/chicken/front_walking_2.png new file mode 100644 index 0000000..4a64dba Binary files /dev/null and b/chicken-wranglers/resources/images/chicken/front_walking_2.png differ diff --git a/chicken-wranglers/resources/images/chicken/side_stopped_1.png b/chicken-wranglers/resources/images/chicken/side_stopped_1.png new file mode 100644 index 0000000..f12779c Binary files /dev/null and b/chicken-wranglers/resources/images/chicken/side_stopped_1.png differ diff --git a/chicken-wranglers/resources/images/chicken/side_stopped_2.png b/chicken-wranglers/resources/images/chicken/side_stopped_2.png new file mode 100644 index 0000000..55d69bb Binary files /dev/null and b/chicken-wranglers/resources/images/chicken/side_stopped_2.png differ diff --git a/chicken-wranglers/resources/images/chicken/side_walking_1.png b/chicken-wranglers/resources/images/chicken/side_walking_1.png new file mode 100644 index 0000000..edc8b76 Binary files /dev/null and b/chicken-wranglers/resources/images/chicken/side_walking_1.png differ diff --git a/chicken-wranglers/resources/images/chicken/side_walking_2.png b/chicken-wranglers/resources/images/chicken/side_walking_2.png new file mode 100644 index 0000000..89e96e6 Binary files /dev/null and b/chicken-wranglers/resources/images/chicken/side_walking_2.png differ diff --git a/chicken-wranglers/resources/images/general/bg_1280x768.png b/chicken-wranglers/resources/images/general/bg_1280x768.png new file mode 100644 index 0000000..ad4db00 Binary files /dev/null and b/chicken-wranglers/resources/images/general/bg_1280x768.png differ diff --git a/chicken-wranglers/resources/images/general/bg_800x480.png b/chicken-wranglers/resources/images/general/bg_800x480.png new file mode 100644 index 0000000..c1b098b Binary files /dev/null and b/chicken-wranglers/resources/images/general/bg_800x480.png differ diff --git a/chicken-wranglers/resources/images/general/bg_dialog.png b/chicken-wranglers/resources/images/general/bg_dialog.png new file mode 100644 index 0000000..aea8f6d Binary files /dev/null and b/chicken-wranglers/resources/images/general/bg_dialog.png differ diff --git a/chicken-wranglers/resources/images/general/bg_selectcharacter.png b/chicken-wranglers/resources/images/general/bg_selectcharacter.png new file mode 100644 index 0000000..e700d98 Binary files /dev/null and b/chicken-wranglers/resources/images/general/bg_selectcharacter.png differ diff --git a/chicken-wranglers/resources/images/general/bg_splash.png b/chicken-wranglers/resources/images/general/bg_splash.png new file mode 100644 index 0000000..463473e Binary files /dev/null and b/chicken-wranglers/resources/images/general/bg_splash.png differ diff --git a/chicken-wranglers/resources/images/general/bluetooth_icon.png b/chicken-wranglers/resources/images/general/bluetooth_icon.png new file mode 100644 index 0000000..4c8c77b Binary files /dev/null and b/chicken-wranglers/resources/images/general/bluetooth_icon.png differ diff --git a/chicken-wranglers/resources/images/general/bt.png b/chicken-wranglers/resources/images/general/bt.png new file mode 100644 index 0000000..0f48303 Binary files /dev/null and b/chicken-wranglers/resources/images/general/bt.png differ diff --git a/chicken-wranglers/resources/images/general/bt_back.png b/chicken-wranglers/resources/images/general/bt_back.png new file mode 100644 index 0000000..b18e684 Binary files /dev/null and b/chicken-wranglers/resources/images/general/bt_back.png differ diff --git a/chicken-wranglers/resources/images/general/bt_back_pressed.png b/chicken-wranglers/resources/images/general/bt_back_pressed.png new file mode 100644 index 0000000..ced3d04 Binary files /dev/null and b/chicken-wranglers/resources/images/general/bt_back_pressed.png differ diff --git a/chicken-wranglers/resources/images/general/bt_close.png b/chicken-wranglers/resources/images/general/bt_close.png new file mode 100644 index 0000000..98fd3fa Binary files /dev/null and b/chicken-wranglers/resources/images/general/bt_close.png differ diff --git a/chicken-wranglers/resources/images/general/bt_close_pressed.png b/chicken-wranglers/resources/images/general/bt_close_pressed.png new file mode 100644 index 0000000..f481dfc Binary files /dev/null and b/chicken-wranglers/resources/images/general/bt_close_pressed.png differ diff --git a/chicken-wranglers/resources/images/general/bt_disabled.png b/chicken-wranglers/resources/images/general/bt_disabled.png new file mode 100644 index 0000000..1969625 Binary files /dev/null and b/chicken-wranglers/resources/images/general/bt_disabled.png differ diff --git a/chicken-wranglers/resources/images/general/bt_next.png b/chicken-wranglers/resources/images/general/bt_next.png new file mode 100644 index 0000000..76ac2b7 Binary files /dev/null and b/chicken-wranglers/resources/images/general/bt_next.png differ diff --git a/chicken-wranglers/resources/images/general/bt_pressed.png b/chicken-wranglers/resources/images/general/bt_pressed.png new file mode 100644 index 0000000..bc12253 Binary files /dev/null and b/chicken-wranglers/resources/images/general/bt_pressed.png differ diff --git a/chicken-wranglers/resources/images/general/bt_previous.png b/chicken-wranglers/resources/images/general/bt_previous.png new file mode 100644 index 0000000..c19027a Binary files /dev/null and b/chicken-wranglers/resources/images/general/bt_previous.png differ diff --git a/chicken-wranglers/resources/images/general/bt_start.png b/chicken-wranglers/resources/images/general/bt_start.png new file mode 100644 index 0000000..cba6d46 Binary files /dev/null and b/chicken-wranglers/resources/images/general/bt_start.png differ diff --git a/chicken-wranglers/resources/images/general/bt_start_disabled.png b/chicken-wranglers/resources/images/general/bt_start_disabled.png new file mode 100644 index 0000000..d897f3b Binary files /dev/null and b/chicken-wranglers/resources/images/general/bt_start_disabled.png differ diff --git a/chicken-wranglers/resources/images/general/bt_start_pressed.png b/chicken-wranglers/resources/images/general/bt_start_pressed.png new file mode 100644 index 0000000..6463819 Binary files /dev/null and b/chicken-wranglers/resources/images/general/bt_start_pressed.png differ diff --git a/chicken-wranglers/resources/images/general/character_highlight.png b/chicken-wranglers/resources/images/general/character_highlight.png new file mode 100644 index 0000000..5b2c1ea Binary files /dev/null and b/chicken-wranglers/resources/images/general/character_highlight.png differ diff --git a/chicken-wranglers/resources/images/general/feather1.png b/chicken-wranglers/resources/images/general/feather1.png new file mode 100644 index 0000000..f56bff3 Binary files /dev/null and b/chicken-wranglers/resources/images/general/feather1.png differ diff --git a/chicken-wranglers/resources/images/general/feather2.png b/chicken-wranglers/resources/images/general/feather2.png new file mode 100644 index 0000000..1ffa4c4 Binary files /dev/null and b/chicken-wranglers/resources/images/general/feather2.png differ diff --git a/chicken-wranglers/resources/images/general/feather3.png b/chicken-wranglers/resources/images/general/feather3.png new file mode 100644 index 0000000..9b4af64 Binary files /dev/null and b/chicken-wranglers/resources/images/general/feather3.png differ diff --git a/chicken-wranglers/resources/images/general/feather4.png b/chicken-wranglers/resources/images/general/feather4.png new file mode 100644 index 0000000..0f3ef25 Binary files /dev/null and b/chicken-wranglers/resources/images/general/feather4.png differ diff --git a/chicken-wranglers/resources/images/general/feather5.png b/chicken-wranglers/resources/images/general/feather5.png new file mode 100644 index 0000000..8799529 Binary files /dev/null and b/chicken-wranglers/resources/images/general/feather5.png differ diff --git a/chicken-wranglers/resources/images/general/line_divisor.png b/chicken-wranglers/resources/images/general/line_divisor.png new file mode 100644 index 0000000..d74ef69 Binary files /dev/null and b/chicken-wranglers/resources/images/general/line_divisor.png differ diff --git a/chicken-wranglers/resources/images/general/list_line_divisor.png b/chicken-wranglers/resources/images/general/list_line_divisor.png new file mode 100644 index 0000000..d12b02b Binary files /dev/null and b/chicken-wranglers/resources/images/general/list_line_divisor.png differ diff --git a/chicken-wranglers/resources/images/general/list_name_bg.png b/chicken-wranglers/resources/images/general/list_name_bg.png new file mode 100644 index 0000000..e2db765 Binary files /dev/null and b/chicken-wranglers/resources/images/general/list_name_bg.png differ diff --git a/chicken-wranglers/resources/images/general/list_scrollbar_knob.png b/chicken-wranglers/resources/images/general/list_scrollbar_knob.png new file mode 100644 index 0000000..fce253f Binary files /dev/null and b/chicken-wranglers/resources/images/general/list_scrollbar_knob.png differ diff --git a/chicken-wranglers/resources/images/general/list_scrollbar_path.png b/chicken-wranglers/resources/images/general/list_scrollbar_path.png new file mode 100644 index 0000000..881d58d Binary files /dev/null and b/chicken-wranglers/resources/images/general/list_scrollbar_path.png differ diff --git a/chicken-wranglers/resources/images/general/list_selected_icon.png b/chicken-wranglers/resources/images/general/list_selected_icon.png new file mode 100644 index 0000000..71b3038 Binary files /dev/null and b/chicken-wranglers/resources/images/general/list_selected_icon.png differ diff --git a/chicken-wranglers/resources/images/general/list_status_ok.png b/chicken-wranglers/resources/images/general/list_status_ok.png new file mode 100644 index 0000000..87c6286 Binary files /dev/null and b/chicken-wranglers/resources/images/general/list_status_ok.png differ diff --git a/chicken-wranglers/resources/images/general/list_unknown_character.png b/chicken-wranglers/resources/images/general/list_unknown_character.png new file mode 100644 index 0000000..0dcf643 Binary files /dev/null and b/chicken-wranglers/resources/images/general/list_unknown_character.png differ diff --git a/chicken-wranglers/resources/images/general/ruller_path.png b/chicken-wranglers/resources/images/general/ruller_path.png new file mode 100644 index 0000000..75bba3f Binary files /dev/null and b/chicken-wranglers/resources/images/general/ruller_path.png differ diff --git a/chicken-wranglers/resources/images/general/ruller_selector.png b/chicken-wranglers/resources/images/general/ruller_selector.png new file mode 100644 index 0000000..39961a3 Binary files /dev/null and b/chicken-wranglers/resources/images/general/ruller_selector.png differ diff --git a/chicken-wranglers/resources/images/general/slider_bluetooth_icon.png b/chicken-wranglers/resources/images/general/slider_bluetooth_icon.png new file mode 100644 index 0000000..4c8c77b Binary files /dev/null and b/chicken-wranglers/resources/images/general/slider_bluetooth_icon.png differ diff --git a/chicken-wranglers/resources/images/general/slider_path.png b/chicken-wranglers/resources/images/general/slider_path.png new file mode 100644 index 0000000..b97026b Binary files /dev/null and b/chicken-wranglers/resources/images/general/slider_path.png differ diff --git a/chicken-wranglers/resources/images/general/slider_selector.png b/chicken-wranglers/resources/images/general/slider_selector.png new file mode 100644 index 0000000..1ed8103 Binary files /dev/null and b/chicken-wranglers/resources/images/general/slider_selector.png differ diff --git a/chicken-wranglers/resources/images/general/slider_wifi_icon.png b/chicken-wranglers/resources/images/general/slider_wifi_icon.png new file mode 100644 index 0000000..992c369 Binary files /dev/null and b/chicken-wranglers/resources/images/general/slider_wifi_icon.png differ diff --git a/chicken-wranglers/resources/images/general/symbian/bg_640x360.png b/chicken-wranglers/resources/images/general/symbian/bg_640x360.png new file mode 100644 index 0000000..45a8a9f Binary files /dev/null and b/chicken-wranglers/resources/images/general/symbian/bg_640x360.png differ diff --git a/chicken-wranglers/resources/images/general/symbian/bg_dialog.png b/chicken-wranglers/resources/images/general/symbian/bg_dialog.png new file mode 100644 index 0000000..56ac860 Binary files /dev/null and b/chicken-wranglers/resources/images/general/symbian/bg_dialog.png differ diff --git a/chicken-wranglers/resources/images/general/symbian/bg_selectcharacter.png b/chicken-wranglers/resources/images/general/symbian/bg_selectcharacter.png new file mode 100644 index 0000000..1e99c2c Binary files /dev/null and b/chicken-wranglers/resources/images/general/symbian/bg_selectcharacter.png differ diff --git a/chicken-wranglers/resources/images/general/symbian/bg_splash.png b/chicken-wranglers/resources/images/general/symbian/bg_splash.png new file mode 100644 index 0000000..991a5e7 Binary files /dev/null and b/chicken-wranglers/resources/images/general/symbian/bg_splash.png differ diff --git a/chicken-wranglers/resources/images/general/symbian/feather1.png b/chicken-wranglers/resources/images/general/symbian/feather1.png new file mode 100644 index 0000000..22639e4 Binary files /dev/null and b/chicken-wranglers/resources/images/general/symbian/feather1.png differ diff --git a/chicken-wranglers/resources/images/general/symbian/feather2.png b/chicken-wranglers/resources/images/general/symbian/feather2.png new file mode 100644 index 0000000..9f41160 Binary files /dev/null and b/chicken-wranglers/resources/images/general/symbian/feather2.png differ diff --git a/chicken-wranglers/resources/images/general/symbian/feather3.png b/chicken-wranglers/resources/images/general/symbian/feather3.png new file mode 100644 index 0000000..ccf3bf1 Binary files /dev/null and b/chicken-wranglers/resources/images/general/symbian/feather3.png differ diff --git a/chicken-wranglers/resources/images/general/symbian/feather4.png b/chicken-wranglers/resources/images/general/symbian/feather4.png new file mode 100644 index 0000000..3f75417 Binary files /dev/null and b/chicken-wranglers/resources/images/general/symbian/feather4.png differ diff --git a/chicken-wranglers/resources/images/general/symbian/feather5.png b/chicken-wranglers/resources/images/general/symbian/feather5.png new file mode 100644 index 0000000..00ee796 Binary files /dev/null and b/chicken-wranglers/resources/images/general/symbian/feather5.png differ diff --git a/chicken-wranglers/resources/images/general/toggle_bt.png b/chicken-wranglers/resources/images/general/toggle_bt.png new file mode 100644 index 0000000..8de9e19 Binary files /dev/null and b/chicken-wranglers/resources/images/general/toggle_bt.png differ diff --git a/chicken-wranglers/resources/images/general/toggle_lan.png b/chicken-wranglers/resources/images/general/toggle_lan.png new file mode 100644 index 0000000..d358538 Binary files /dev/null and b/chicken-wranglers/resources/images/general/toggle_lan.png differ diff --git a/chicken-wranglers/resources/images/general/you_are_ready.png b/chicken-wranglers/resources/images/general/you_are_ready.png new file mode 100644 index 0000000..dc8a788 Binary files /dev/null and b/chicken-wranglers/resources/images/general/you_are_ready.png differ diff --git a/chicken-wranglers/resources/images/laser/laser_horizontal_1.png b/chicken-wranglers/resources/images/laser/laser_horizontal_1.png new file mode 100644 index 0000000..6c578f3 Binary files /dev/null and b/chicken-wranglers/resources/images/laser/laser_horizontal_1.png differ diff --git a/chicken-wranglers/resources/images/laser/laser_horizontal_2.png b/chicken-wranglers/resources/images/laser/laser_horizontal_2.png new file mode 100644 index 0000000..b883a34 Binary files /dev/null and b/chicken-wranglers/resources/images/laser/laser_horizontal_2.png differ diff --git a/chicken-wranglers/resources/images/laser/laser_horizontal_3.png b/chicken-wranglers/resources/images/laser/laser_horizontal_3.png new file mode 100644 index 0000000..dcb9123 Binary files /dev/null and b/chicken-wranglers/resources/images/laser/laser_horizontal_3.png differ diff --git a/chicken-wranglers/resources/images/laser/laser_horizontal_4.png b/chicken-wranglers/resources/images/laser/laser_horizontal_4.png new file mode 100644 index 0000000..351121c Binary files /dev/null and b/chicken-wranglers/resources/images/laser/laser_horizontal_4.png differ diff --git a/chicken-wranglers/resources/images/laser/laser_vertical_1.png b/chicken-wranglers/resources/images/laser/laser_vertical_1.png new file mode 100644 index 0000000..ac500ac Binary files /dev/null and b/chicken-wranglers/resources/images/laser/laser_vertical_1.png differ diff --git a/chicken-wranglers/resources/images/laser/laser_vertical_2.png b/chicken-wranglers/resources/images/laser/laser_vertical_2.png new file mode 100644 index 0000000..c1f0c41 Binary files /dev/null and b/chicken-wranglers/resources/images/laser/laser_vertical_2.png differ diff --git a/chicken-wranglers/resources/images/laser/laser_vertical_3.png b/chicken-wranglers/resources/images/laser/laser_vertical_3.png new file mode 100644 index 0000000..d7f6a55 Binary files /dev/null and b/chicken-wranglers/resources/images/laser/laser_vertical_3.png differ diff --git a/chicken-wranglers/resources/images/laser/laser_vertical_4.png b/chicken-wranglers/resources/images/laser/laser_vertical_4.png new file mode 100644 index 0000000..a7d12c6 Binary files /dev/null and b/chicken-wranglers/resources/images/laser/laser_vertical_4.png differ diff --git a/chicken-wranglers/resources/linux.qrc b/chicken-wranglers/resources/linux.qrc new file mode 100644 index 0000000..732e8d2 --- /dev/null +++ b/chicken-wranglers/resources/linux.qrc @@ -0,0 +1,15 @@ + + + images/general/bg_1280x768.png + images/general/bg_800x480.png + images/general/bg_selectcharacter.png + images/general/bg_splash.png + images/general/bg_dialog.png + images/general/feather1.png + images/general/feather2.png + images/general/feather3.png + images/general/feather4.png + images/general/feather5.png + images/battlefield/bg_fence_stones.png + + diff --git a/chicken-wranglers/resources/symbian.qrc b/chicken-wranglers/resources/symbian.qrc new file mode 100644 index 0000000..c63f900 --- /dev/null +++ b/chicken-wranglers/resources/symbian.qrc @@ -0,0 +1,14 @@ + + + images/general/symbian/bg_640x360.png + images/general/symbian/bg_selectcharacter.png + images/general/symbian/bg_splash.png + images/general/symbian/bg_dialog.png + images/general/symbian/feather1.png + images/general/symbian/feather2.png + images/general/symbian/feather3.png + images/general/symbian/feather4.png + images/general/symbian/feather5.png + images/battlefield/bg_fence_stones_mobile.png + + diff --git a/chicken-wranglers/sounds/laser.raw b/chicken-wranglers/sounds/laser.raw new file mode 100644 index 0000000..c2acf25 Binary files /dev/null and b/chicken-wranglers/sounds/laser.raw differ diff --git a/chicken-wranglers/sounds/match.raw b/chicken-wranglers/sounds/match.raw new file mode 100644 index 0000000..58f1b59 Binary files /dev/null and b/chicken-wranglers/sounds/match.raw differ diff --git a/chicken-wranglers/sounds/score.raw b/chicken-wranglers/sounds/score.raw new file mode 100644 index 0000000..839004b Binary files /dev/null and b/chicken-wranglers/sounds/score.raw differ diff --git a/chicken-wranglers/src/ai/ai.pri b/chicken-wranglers/src/ai/ai.pri new file mode 100644 index 0000000..8f9dd78 --- /dev/null +++ b/chicken-wranglers/src/ai/ai.pri @@ -0,0 +1,9 @@ +PATH = $$PWD + +HEADERS += \ + $$PATH/matchai.h \ + $$PATH/graph.h + +SOURCES += \ + $$PATH/matchai.cpp \ + $$PATH/graph.cpp diff --git a/chicken-wranglers/src/ai/graph.cpp b/chicken-wranglers/src/ai/graph.cpp new file mode 100644 index 0000000..34c61c8 --- /dev/null +++ b/chicken-wranglers/src/ai/graph.cpp @@ -0,0 +1,129 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#include "graph.h" + +Node::Node(QObject *parent) + : QObject(parent), data(Node::Empty), rank(0), + chickenCount(0), pos(0, 0), direction(Node::Stop) +{ + neighbor[Node::Stop] = this; + neighbor[Node::Up] = this; + neighbor[Node::Down] = this; + neighbor[Node::Right] = this; + neighbor[Node::Left] = this; +} + +Global::Direction Node::neighborDirection(Node::Neighbor neighbor) +{ + switch (neighbor) { + case Node::Up: + return Global::DirectionUp; + case Node::Down: + return Global::DirectionDown; + case Node::Right: + return Global::DirectionRight; + case Node::Left: + return Global::DirectionLeft; + default: + return Global::DirectionStop; + } +} + +Node::Neighbor Node::directionNeighbor(Global::Direction direction) +{ + switch (direction) { + case Global::DirectionUp: + return Node::Up; + case Global::DirectionDown: + return Node::Down; + case Global::DirectionRight: + return Node::Right; + case Global::DirectionLeft: + return Node::Left; + default: + return Node::Stop; + } +} + +Graph::Graph(QSize size, QObject *parent) + : QObject(parent), m_size(size) +{ + initMatrix(); +} + +Node *Graph::node(QPoint pos) +{ + if (pos.y() < m_size.height() && pos.x() < m_size.width() + && pos.y() >= 0 && pos.x() >= 0) { + return m_matrix[pos.y()][pos.x()]; + } + + return 0; +} + +void Graph::initMatrix() +{ + if (!m_size.height() || !m_size.width()) + return; + + // FIXME: Better way to alloc the matrix + for (int row = 0; row < m_size.height(); row++) + for (int column = 0; column < m_size.width(); column++) + m_matrix[row][column] = new Node(this); + + for (int row = 0; row < m_size.height(); row++) { + for (int column = 0; column < m_size.width(); column++) { + m_matrix[row][column]->pos = QPoint(column, row); + + if (row > 0) + m_matrix[row][column]->neighbor[Node::Up] = m_matrix[row - 1][column]; + if (column > 0) + m_matrix[row][column]->neighbor[Node::Left] = m_matrix[row][column - 1]; + if (row < m_size.height() - 1) + m_matrix[row][column]->neighbor[Node::Down] = m_matrix[row + 1][column]; + if (column < m_size.width() - 1) + m_matrix[row][column]->neighbor[Node::Right] = m_matrix[row][column + 1]; + } + + } +} diff --git a/chicken-wranglers/src/ai/graph.h b/chicken-wranglers/src/ai/graph.h new file mode 100644 index 0000000..322b79f --- /dev/null +++ b/chicken-wranglers/src/ai/graph.h @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef GRAPH_H +#define GRAPH_H + +#include +#include +#include +#include +#include + +#include "global.h" + +class Node : public QObject +{ + Q_OBJECT + +public: + enum Neighbor { + Right, + Left, + Up, + Down, + Stop, + MAX_NEIGHBOR + }; + + enum Data { + Empty, + Chicken, + Player, + Hencoop + }; + + explicit Node(QObject *parent = 0); + + bool isEmpty() { return data == Node::Empty; } + bool isChicken() { return data == Node::Chicken; } + bool isPlayer() { return data == Node::Player; } + bool isHencoop() { return data == Node::Hencoop; } + bool isScape() { return !isPlayer() && !isHencoop(); } + bool isSafe() { return !rank; } + void emitChickenEntered() { emit chickenEntered(chickenCount); } + + static Global::Direction neighborDirection(Node::Neighbor); + static Node::Neighbor directionNeighbor(Global::Direction); + + Node *neighbor[MAX_NEIGHBOR]; + Data data; + int rank; + int chickenCount; + QPoint pos; + Node::Neighbor direction; + +signals: + void chickenEntered(int numChickens); +}; + +class Graph : public QObject +{ + Q_OBJECT + +public: + explicit Graph(QSize size, QObject *parent = 0); + Node *node(QPoint pos); + +private: + void initMatrix(); + + QSize m_size; + Node *m_matrix[20][20]; +}; + +#endif diff --git a/chicken-wranglers/src/ai/matchai.cpp b/chicken-wranglers/src/ai/matchai.cpp new file mode 100644 index 0000000..1870655 --- /dev/null +++ b/chicken-wranglers/src/ai/matchai.cpp @@ -0,0 +1,408 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#include "global.h" + +#include "matchai.h" + +MatchAI::MatchAI(QSize matchCanvasSize) +{ + m_graph = new Graph(matchCanvasSize); +} + +MatchAI::~MatchAI() +{ + m_graph->deleteLater(); +} + +bool MatchAI::addChicken(QPoint position) +{ + Node *chickenNode = m_graph->node(position); + + if (!chickenNode || !chickenNode->isEmpty()) + return false; + + chickenNode->data = Node::Chicken; + chickenNode->chickenCount = 1; + + return true; +} + +Node *MatchAI::addPlayer(QPoint position) +{ + Node *playerNode = m_graph->node(position); + + if (!playerNode || !playerNode->isEmpty()) + return 0; + + Node *hencoop = addHencoop(playerNode); + + if (hencoop) { + playerNode->data = Node::Player; + doUnSafe(playerNode); + } + + return hencoop; +} + +bool MatchAI::toggleLaser(QPoint position, Global::LaserDirection direction) +{ + Node *node = m_graph->node(position); + Node *neighbor; + + if (!node) + return false; + + switch (direction) { + + case Global::LaserUp: + neighbor = m_graph->node(position + QPoint(0, -1)); + if (neighbor) { + if (node->neighbor[Node::Up] != neighbor) { + // Turn off laser + node->neighbor[Node::Up] = neighbor; + neighbor->neighbor[Node::Down] = node; + return false; + } else { + // Turn on laser + node->neighbor[Node::Up] = node; + neighbor->neighbor[Node::Down] = neighbor; + return true; + } + } + break; + + case Global::LaserDown: + neighbor = m_graph->node(position + QPoint(0, 1)); + if (neighbor) { + if (node->neighbor[Node::Down] != neighbor) { + // Turn off laser + node->neighbor[Node::Down] = neighbor; + neighbor->neighbor[Node::Up] = node; + return false; + } else { + // Turn on laser + node->neighbor[Node::Down] = node; + neighbor->neighbor[Node::Up] = neighbor; + return true; + } + } + break; + + case Global::LaserRight: + neighbor = m_graph->node(position + QPoint(1, 0)); + if (neighbor) { + if (node->neighbor[Node::Right] != neighbor) { + // Turn off laser + node->neighbor[Node::Right] = neighbor; + neighbor->neighbor[Node::Left] = node; + return false; + } else { + // Turn on laser + node->neighbor[Node::Right] = node; + neighbor->neighbor[Node::Left] = neighbor; + return true; + } + } + break; + + case Global::LaserLeft: + neighbor = m_graph->node(position + QPoint(-1, 0)); + if (neighbor) { + if (node->neighbor[Node::Left] != neighbor) { + // Turn off laser + node->neighbor[Node::Left] = neighbor; + neighbor->neighbor[Node::Right] = node; + return false; + } else { + // Turn on laser + node->neighbor[Node::Left] = node; + neighbor->neighbor[Node::Right] = neighbor; + return true; + } + } + break; + + default: + return false; + } + + return false; +} + +QPair MatchAI::moveChicken(QPoint position) +{ + Node *chickenNode = m_graph->node(position); + + if (!chickenNode || !chickenNode->isChicken()) + return QPair(position, Global::DirectionStop); + + QList > nextPosList; + Node *neighbor; + if (chickenNode->isSafe() && chickenNode->chickenCount == 1) { + nextPosList.append(QPair(position, Node::Stop)); + nextPosList.append(QPair(position, Node::Stop)); + nextPosList.append(QPair(position, Node::Stop)); + nextPosList.append(QPair(position, Node::Stop)); + nextPosList.append(QPair(position, Node::Stop)); + nextPosList.append(QPair(position, Node::Stop)); + nextPosList.append(QPair(position, Node::Stop)); + nextPosList.append(QPair(position, Node::Stop)); + } + + neighbor = chickenNode->neighbor[Node::Up]; + if (!neighbor->isPlayer() && neighbor->isSafe() && chickenNode != neighbor) { + nextPosList.append(QPair(neighbor->pos, Node::Up)); + if (chickenNode->neighbor[Node::Down]->isPlayer()) { + nextPosList.append(QPair(neighbor->pos, Node::Up)); + nextPosList.append(QPair(neighbor->pos, Node::Up)); + nextPosList.append(QPair(neighbor->pos, Node::Up)); + nextPosList.append(QPair(neighbor->pos, Node::Up)); + nextPosList.append(QPair(neighbor->pos, Node::Up)); + nextPosList.append(QPair(neighbor->pos, Node::Up)); + nextPosList.append(QPair(neighbor->pos, Node::Up)); + nextPosList.append(QPair(neighbor->pos, Node::Up)); + } + } + + neighbor = chickenNode->neighbor[Node::Down]; + if (!neighbor->isPlayer() && neighbor->isSafe() && chickenNode != neighbor) { + nextPosList.append(QPair(neighbor->pos, Node::Down)); + if (chickenNode->neighbor[Node::Up]->isPlayer()) { + nextPosList.append(QPair(neighbor->pos, Node::Down)); + nextPosList.append(QPair(neighbor->pos, Node::Down)); + nextPosList.append(QPair(neighbor->pos, Node::Down)); + nextPosList.append(QPair(neighbor->pos, Node::Down)); + nextPosList.append(QPair(neighbor->pos, Node::Down)); + nextPosList.append(QPair(neighbor->pos, Node::Down)); + nextPosList.append(QPair(neighbor->pos, Node::Down)); + nextPosList.append(QPair(neighbor->pos, Node::Down)); + } + } + + neighbor = chickenNode->neighbor[Node::Right]; + if (!neighbor->isPlayer() && neighbor->isSafe() && chickenNode != neighbor) { + nextPosList.append(QPair(neighbor->pos, Node::Right)); + if (chickenNode->neighbor[Node::Left]->isPlayer()) { + nextPosList.append(QPair(neighbor->pos, Node::Right)); + nextPosList.append(QPair(neighbor->pos, Node::Right)); + nextPosList.append(QPair(neighbor->pos, Node::Right)); + nextPosList.append(QPair(neighbor->pos, Node::Right)); + nextPosList.append(QPair(neighbor->pos, Node::Right)); + nextPosList.append(QPair(neighbor->pos, Node::Right)); + nextPosList.append(QPair(neighbor->pos, Node::Right)); + nextPosList.append(QPair(neighbor->pos, Node::Right)); + } + } + + neighbor = chickenNode->neighbor[Node::Left]; + if (!neighbor->isPlayer() && neighbor->isSafe() && chickenNode != neighbor) { + nextPosList.append(QPair(neighbor->pos, Node::Left)); + if (chickenNode->neighbor[Node::Right]->isPlayer()) { + nextPosList.append(QPair(neighbor->pos, Node::Left)); + nextPosList.append(QPair(neighbor->pos, Node::Left)); + nextPosList.append(QPair(neighbor->pos, Node::Left)); + nextPosList.append(QPair(neighbor->pos, Node::Left)); + nextPosList.append(QPair(neighbor->pos, Node::Left)); + nextPosList.append(QPair(neighbor->pos, Node::Left)); + nextPosList.append(QPair(neighbor->pos, Node::Left)); + nextPosList.append(QPair(neighbor->pos, Node::Left)); + } + } + + if (nextPosList.isEmpty()) { + neighbor = chickenNode->neighbor[Node::Up]; + + if (neighbor->isScape() && neighbor->rank < chickenNode->rank && chickenNode != neighbor) + nextPosList.append(QPair(neighbor->pos, Node::Up)); + + neighbor = chickenNode->neighbor[Node::Down]; + if (neighbor->isScape() && neighbor->rank < chickenNode->rank && chickenNode != neighbor) + nextPosList.append(QPair(neighbor->pos, Node::Down)); + + neighbor = chickenNode->neighbor[Node::Right]; + if (neighbor->isScape() && neighbor->rank < chickenNode->rank && chickenNode != neighbor) + nextPosList.append(QPair(neighbor->pos, Node::Right)); + + neighbor = chickenNode->neighbor[Node::Left]; + if (neighbor->isScape() && neighbor->rank < chickenNode->rank && chickenNode != neighbor) + nextPosList.append(QPair(neighbor->pos, Node::Left)); + } + + if (nextPosList.isEmpty()) { + neighbor = chickenNode->neighbor[Node::Up]; + + if (!neighbor->isPlayer() && neighbor->rank < chickenNode->rank && chickenNode != neighbor) + nextPosList.append(QPair(neighbor->pos, Node::Up)); + + neighbor = chickenNode->neighbor[Node::Down]; + if (!neighbor->isPlayer() && neighbor->rank < chickenNode->rank && chickenNode != neighbor) + nextPosList.append(QPair(neighbor->pos, Node::Down)); + + neighbor = chickenNode->neighbor[Node::Right]; + if (!neighbor->isPlayer() && neighbor->rank < chickenNode->rank && chickenNode != neighbor) + nextPosList.append(QPair(neighbor->pos, Node::Right)); + + neighbor = chickenNode->neighbor[Node::Left]; + if (!neighbor->isPlayer() && neighbor->rank < chickenNode->rank && chickenNode != neighbor) + nextPosList.append(QPair(neighbor->pos, Node::Left)); + } + + if (nextPosList.isEmpty()) + return QPair(position, Global::DirectionStop); + + QPair nextPos = nextPosList.at(qrand() % nextPosList.size()); + neighbor = chickenNode->neighbor[nextPos.second]; + if (neighbor != chickenNode) { + chickenNode->chickenCount -= 1; + if (!chickenNode->chickenCount) + chickenNode->data = Node::Empty; + + neighbor->chickenCount += 1; + + if (neighbor->isHencoop()) + neighbor->emitChickenEntered(); + else + neighbor->data = Node::Chicken; + } + + return QPair(nextPos.first, + Node::neighborDirection(nextPos.second)); +} + +QPoint MatchAI::movePlayer(QPoint position, Global::Direction direction) +{ + Node *playerNode = m_graph->node(position); + + if (!playerNode || playerNode->data != Node::Player) + return position; + + Node *neighbor = playerNode->neighbor[Node::directionNeighbor(direction)]; + if (neighbor->isEmpty()) { + playerNode->data = Node::Empty; + neighbor->data = Node::Player; + + doSafe(playerNode); + + playerNode->direction = Node::Stop; + neighbor->direction = Node::directionNeighbor(direction); + + doUnSafe(neighbor); + + return neighbor->pos; + } else { + doSafe(playerNode); + playerNode->direction = Node::directionNeighbor(direction); + doUnSafe(playerNode); + } + + return position; +} + +bool MatchAI::isChickenSafe(QPoint position) +{ + Node *chickenNode = m_graph->node(position); + + if (!chickenNode || chickenNode->data != Node::Chicken) + return false; + + return chickenNode->isSafe(); +} + +Node *MatchAI::addHencoop(Node *node) +{ + if (node->neighbor[Node::Right] == node) { + node->rank = 1; + node->neighbor[Node::Right] = new Node(m_graph); + node->neighbor[Node::Right]->data = Node::Hencoop; + node->neighbor[Node::Right]->rank = 4; + node->neighbor[Node::Right]->pos = node->pos + QPoint(1, 0); + return node->neighbor[Node::Right]; + } + + if (node->neighbor[Node::Left] == node) { + node->rank = 1; + node->neighbor[Node::Left] = new Node(m_graph); + node->neighbor[Node::Left]->data = Node::Hencoop; + node->neighbor[Node::Left]->rank = 4; + node->neighbor[Node::Left]->pos = node->pos + QPoint(-1, 0); + return node->neighbor[Node::Left]; + } + + return 0; +} + +void MatchAI::doUnSafe(QPoint position) +{ + Node *playerNode = m_graph->node(position); + + if (!playerNode || !playerNode->isPlayer()) + return; + doUnSafe(playerNode); +} + +void MatchAI::doSafe(QPoint position) +{ + Node *playerNode = m_graph->node(position); + + if (!playerNode || !playerNode->isPlayer()) + return; + doSafe(playerNode); +} + +void MatchAI::doUnSafe(Node *node) +{ + node->neighbor[Node::Up]->rank += 2; + node->neighbor[Node::Down]->rank += 2; + node->neighbor[Node::Right]->rank += 2; + node->neighbor[Node::Left]->rank += 2; + node->neighbor[node->direction]->rank += 4; +} + +void MatchAI::doSafe(Node *node) +{ + node->neighbor[Node::Up]->rank -= 2; + node->neighbor[Node::Down]->rank -= 2; + node->neighbor[Node::Right]->rank -= 2; + node->neighbor[Node::Left]->rank -= 2; + node->neighbor[node->direction]->rank -= 4; +} diff --git a/chicken-wranglers/src/ai/matchai.h b/chicken-wranglers/src/ai/matchai.h new file mode 100644 index 0000000..79832fe --- /dev/null +++ b/chicken-wranglers/src/ai/matchai.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef GLOBALAI_H +#define GLOBALAI_H + +#include +#include + +#include "global.h" +#include "graph.h" + +class MatchAI +{ +public: + MatchAI(QSize); + ~MatchAI(); + + bool addChicken(QPoint position); + QPair moveChicken(QPoint position); + bool isChickenSafe(QPoint position); + + Node *addPlayer(QPoint position); + QPoint movePlayer(QPoint position, Global::Direction direction); + + bool toggleLaser(QPoint position, Global::LaserDirection direction); + + void doUnSafe(QPoint position); + void doSafe(QPoint position); + +private: + Node *addHencoop(Node *node); + void doUnSafe(Node *node); + void doSafe(Node *node); + + Graph *m_graph; +}; + +#endif diff --git a/chicken-wranglers/src/control/control.cpp b/chicken-wranglers/src/control/control.cpp new file mode 100644 index 0000000..3728bc0 --- /dev/null +++ b/chicken-wranglers/src/control/control.cpp @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#include "sensormovement.h" + +#include "control.h" + +Control::Control(QObject *parent) + : QObject(parent) +{ + m_sensorMovement = new SensorMovement(this); +} + +void Control::start() +{ + connect(m_sensorMovement, SIGNAL(directionChanged(Global::Direction)), + this, SLOT(onSensorMovementDirectionChanged(Global::Direction))); +} + +void Control::stop() +{ + disconnect(m_sensorMovement, SIGNAL(directionChanged(Global::Direction)), + this, SLOT(onSensorMovementDirectionChanged(Global::Direction))); +} + +void Control::onSensorMovementDirectionChanged(Global::Direction direction) +{ + setDirection(direction); +} + +void Control::setDirection(Global::Direction direction) +{ + if (m_direction == direction) + return; + + m_direction = direction; + + emit directionChanged(m_direction); + emit directionChanged(); +} diff --git a/chicken-wranglers/src/control/control.h b/chicken-wranglers/src/control/control.h new file mode 100644 index 0000000..7f92f00 --- /dev/null +++ b/chicken-wranglers/src/control/control.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef CONTROL_H +#define CONTROL_H + +#include + +#include "global.h" + +class SensorMovement; + +class Control : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QString directionString READ directionString NOTIFY directionChanged) + +public: + Control(QObject *parent = 0); + + Global::Direction direction() const { return m_direction; } + void setDirection(Global::Direction direction); + QString directionString() const { return Global::directionString(m_direction); } + + void start(); + void stop(); + + SensorMovement *sensorMovement() const { return m_sensorMovement; } + +signals: + void directionChanged(Global::Direction direction); + void directionChanged(); + +protected slots: + void onSensorMovementDirectionChanged(Global::Direction direction); + +private: + SensorMovement *m_sensorMovement; + Global::Direction m_direction; +}; + +#endif diff --git a/chicken-wranglers/src/control/control.pri b/chicken-wranglers/src/control/control.pri new file mode 100644 index 0000000..50f950d --- /dev/null +++ b/chicken-wranglers/src/control/control.pri @@ -0,0 +1,16 @@ +maemo5 { + CONFIG += mobility12 +} else { + CONFIG += mobility +} +MOBILITY += sensors + +PATH = $$PWD + +HEADERS += \ + $$PATH/control.h \ + $$PATH/sensormovement.h + +SOURCES += \ + $$PATH/control.cpp \ + $$PATH/sensormovement.cpp diff --git a/chicken-wranglers/src/control/sensormovement.cpp b/chicken-wranglers/src/control/sensormovement.cpp new file mode 100644 index 0000000..4b032a1 --- /dev/null +++ b/chicken-wranglers/src/control/sensormovement.cpp @@ -0,0 +1,192 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#include "sensormovement.h" + +SensorMovement::SensorMovement(QObject *parent) + : QObject(parent), m_direction(Global::DirectionStop), m_startX(0), + m_startY(0), m_minimumRotation(0), + m_threshold(0), m_directionTimeout(0), m_enabled(false) +{ + m_sensor.addFilter(this); + m_sensor.start(); + + setEnabled(true); + + timer.setSingleShot(true); + + connect(&timer, SIGNAL(timeout()), this, SLOT(notifyDirectionChanged())); +} + +void SensorMovement::setEnabled(bool enabled) +{ + if (!m_sensor.isActive()) + return; + + m_enabled = enabled; + + emit enabledChanged(); +} + +void SensorMovement::setMinimumRotation(qreal minimumRotation) +{ + m_minimumRotation = minimumRotation; + + emit minimumRotationChanged(); +} + +void SensorMovement::setThreshold(qreal threshold) +{ + m_threshold = threshold; + + emit thresholdChanged(); +} + +void SensorMovement::setDirectionTimeout(int directionTimeout) +{ + m_directionTimeout = directionTimeout; + + emit directionTimeoutChanged(); +} + +void SensorMovement::resetStartPosition() +{ + QAccelerometerReading *reading = m_sensor.reading(); + + if (!reading) + return; + + m_startX = reading->x(); + m_startY = reading->y(); +} + +bool SensorMovement::filter(QAccelerometerReading *reading) +{ + if (!m_enabled) + return true; + + Global::Direction nextDirection; + // XXX: Axis are inverted on N900, thanks to the fact that + // is a landscape device by definition. + if (Global::environment() == Global::Maemo) + nextDirection = calculateDirectionMaemo5(reading->x(), reading->y()); + else + nextDirection = calculateDirection(reading->x(), reading->y()); + + if (nextDirection != m_direction) { + m_direction = nextDirection; + + timer.stop(); + timer.start(m_directionTimeout); + } + + return true; +} + +Global::Direction SensorMovement::calculateDirection(qreal x, qreal y) +{ + m_actualY = y - m_startY; + m_actualX = x - m_startX; + + if (qAbs(m_actualX) > qAbs(m_actualY)) { + if (m_actualX > 0) { + if (m_actualX > m_minimumRotation + m_threshold) + return Global::DirectionDown; + else if (m_actualX < m_minimumRotation - m_threshold && m_actualX > m_threshold) + return Global::DirectionStop; + } else { + if (m_actualX < -m_minimumRotation - m_threshold) + return Global::DirectionUp; + else if (m_actualX > -m_minimumRotation + m_threshold && m_actualX < -m_threshold) + return Global::DirectionStop; + } + } else if (m_actualY > 0) { + if (m_actualY > m_minimumRotation + m_threshold) + return Global::DirectionRight; + else if (m_actualY < m_minimumRotation - m_threshold && m_actualY > m_threshold) + return Global::DirectionStop; + } else { + if (m_actualY < -m_minimumRotation - m_threshold) + return Global::DirectionLeft; + else if (m_actualY > -m_minimumRotation + m_threshold && m_actualY < -m_threshold) + return Global::DirectionStop; + } + + return m_direction; +} + +Global::Direction SensorMovement::calculateDirectionMaemo5(qreal x, qreal y) +{ + m_actualY = y - m_startY; + m_actualX = x - m_startX; + + if (qAbs(m_actualX) > qAbs(m_actualY)) { + if (m_actualX > 0) { + if (m_actualX > m_minimumRotation + m_threshold) + return Global::DirectionLeft; + else if (m_actualX < m_minimumRotation - m_threshold && m_actualX > m_threshold) + return Global::DirectionStop; + } else { + if (m_actualX < -m_minimumRotation - m_threshold) + return Global::DirectionRight; + else if (m_actualX > -m_minimumRotation + m_threshold && m_actualX < -m_threshold) + return Global::DirectionStop; + } + } else if (m_actualY > 0) { + if (m_actualY > m_minimumRotation + m_threshold) + return Global::DirectionDown; + else if (m_actualY < m_minimumRotation - m_threshold && m_actualY > m_threshold) + return Global::DirectionStop; + } else { + if (m_actualY < -m_minimumRotation - m_threshold) + return Global::DirectionUp; + else if (m_actualY > -m_minimumRotation + m_threshold && m_actualY < -m_threshold) + return Global::DirectionStop; + } + + return m_direction; +} + +void SensorMovement::notifyDirectionChanged() +{ + emit directionChanged(m_direction); +} diff --git a/chicken-wranglers/src/control/sensormovement.h b/chicken-wranglers/src/control/sensormovement.h new file mode 100644 index 0000000..d4e4b07 --- /dev/null +++ b/chicken-wranglers/src/control/sensormovement.h @@ -0,0 +1,148 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef SENSORMOVEMENT_H +#define SENSORMOVEMENT_H + +#include "global.h" + +#include +#include +#include + +QTM_USE_NAMESPACE + +class SensorMovement : public QObject, public QAccelerometerFilter +{ + Q_OBJECT + +public: + SensorMovement(QObject *parent = 0); + + Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) + Q_PROPERTY(qreal minimumRotation READ minimumRotation WRITE setMinimumRotation NOTIFY minimumRotationChanged) + Q_PROPERTY(qreal threshold READ threshold WRITE setThreshold NOTIFY thresholdChanged) + Q_PROPERTY(int directionTimeout READ directionTimeout WRITE setDirectionTimeout NOTIFY directionTimeoutChanged) + + /** + * Defines if sensor is \a enabled, if it will forward direction change signals. + */ + bool isEnabled() const { return m_enabled; } + void setEnabled(bool enabled); + + /** + * Defines a minimum absolute rotation value required to + * detect a direction change in a axis. Note that DirectionStop + * is also considered a direction. + */ + qreal minimumRotation() const { return m_minimumRotation; } + void setMinimumRotation(qreal minimumRotation); + + /** + * Defines an angle interval as [-threshold, threshold], where the device + * rotation is not considered to be at any direction. + * + * For instance, if threshold was set to 5 and device is moving along + * vertical axis, it will not notify any direction change when the the + * rotation sensor value for that axis is between -5 and 5. + */ + qreal threshold() const { return m_threshold; } + void setThreshold(qreal threshold); + + /** + * Defines a time required for the device to stand in a given direction, + * before actually notifying a direction change. + * + * When devices is moved to a direction A and changed to a direction B in + * less than \a timeout miliseconds, it won't emit directionChange signal + * for direction A. + */ + int directionTimeout() const { return m_directionTimeout; } + void setDirectionTimeout(int directionTimeout); + + Global::Direction direction() const { return m_direction; } + +public slots: + /** + * Resets the device's start position. + * + * When this method is called, the current device position is read + * from sensor and all the direction calculations will be based on + * these offsets for both axis (x = 0 + m_startX, y = 0 + m_startY). + */ + void resetStartPosition(); + +signals: + void directionChanged(Global::Direction direction); + void minimumRotationChanged(); + void thresholdChanged(); + void directionTimeoutChanged(); + void enabledChanged(); + +protected: + bool filter(QAccelerometerReading *reading); + +private slots: + void notifyDirectionChanged(); + +private: + Global::Direction calculateDirection(qreal x, qreal y); + Global::Direction calculateDirectionMaemo5(qreal x, qreal y); + + QAccelerometer m_sensor; + + Global::Direction m_direction; + + qreal m_startX; + qreal m_startY; + qreal m_actualX; + qreal m_actualY; + + qreal m_minimumRotation; + qreal m_threshold; + int m_directionTimeout; + bool m_enabled; + + QTimer timer; +}; + +#endif diff --git a/chicken-wranglers/src/controllers/chickencontroller.cpp b/chicken-wranglers/src/controllers/chickencontroller.cpp new file mode 100644 index 0000000..e358ec7 --- /dev/null +++ b/chicken-wranglers/src/controllers/chickencontroller.cpp @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + +#include "chickencontroller.h" + +#include "matchai.h" + +#include + +ChickenController::ChickenController(QObject *parent) + : QObject(parent), m_isSafe(true), m_matchAI(0) +{ + initPosition(); +} + +ChickenController::ChickenController(MatchAI *matchAI, QObject *parent) + : QObject(parent), m_matchAI(matchAI) +{ + initPosition(); +} + +ChickenController::~ChickenController() +{ +} + +void ChickenController::setPosition(const QPoint &position) +{ + if (position == m_position) + return; + + m_position = position; + + emit positionChanged(); +} + +void ChickenController::setDirection(const QString &direction) +{ + if (direction == m_direction) + return; + + m_direction = direction; + + emit directionChanged(); +} + +void ChickenController::setSafe(bool isSafe) +{ + if (m_isSafe == isSafe) + return; + + m_isSafe = isSafe; + + emit isSafeChanged(); +} + +void ChickenController::move() +{ + Q_ASSERT(m_matchAI); + + setSafe(m_matchAI->isChickenSafe(m_position)); + + QPair nextPos = m_matchAI->moveChicken(m_position); + + setDirection(Global::directionString(nextPos.second)); + setPosition(nextPos.first); +} + +void ChickenController::initPosition() +{ + Q_ASSERT(m_matchAI); + + qsrand(QTime::currentTime().msec()); + do { + m_position = QPoint(qrand() % 10, qrand() % 10); + } while (!m_matchAI->addChicken(m_position)); + + m_direction = Global::directionString(Global::DirectionStop); +} diff --git a/chicken-wranglers/src/controllers/chickencontroller.h b/chicken-wranglers/src/controllers/chickencontroller.h new file mode 100644 index 0000000..a12a393 --- /dev/null +++ b/chicken-wranglers/src/controllers/chickencontroller.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + +#ifndef CHICKENCONTROLLER_H +#define CHICKENCONTROLLER_H + +#include +#include +#include + +class MatchAI; + +class ChickenController : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QPoint position READ position NOTIFY positionChanged) + Q_PROPERTY(QString direction READ direction NOTIFY directionChanged) + Q_PROPERTY(bool isSafe READ isSafe NOTIFY isSafeChanged) + +public: + explicit ChickenController(QObject *parent = 0); // don't use it + explicit ChickenController(MatchAI *matchAI, QObject *parent = 0); + ~ChickenController(); + + QPoint position() const { return m_position; } + void setPosition(const QPoint &position); + + QString direction() const { return m_direction; } + void setDirection(const QString &direction); + + bool isSafe() const { return m_isSafe; } + + Q_INVOKABLE void move(); + +signals: + void positionChanged(); + void directionChanged(); + void isSafeChanged(); + +private: + void initPosition(); + void setSafe(bool isSafe); + + QPoint m_position; + QString m_direction; + bool m_isSafe; + MatchAI *m_matchAI; +}; + +#endif diff --git a/chicken-wranglers/src/controllers/controllers.pri b/chicken-wranglers/src/controllers/controllers.pri new file mode 100644 index 0000000..e92e330 --- /dev/null +++ b/chicken-wranglers/src/controllers/controllers.pri @@ -0,0 +1,13 @@ +QT += declarative + +PATH = $$PWD + +HEADERS += \ + $$PATH/matchcontroller.h \ + $$PATH/chickencontroller.h \ + $$PATH/playercontroller.h + +SOURCES += \ + $$PATH/matchcontroller.cpp \ + $$PATH/chickencontroller.cpp \ + $$PATH/playercontroller.cpp diff --git a/chicken-wranglers/src/controllers/matchcontroller.cpp b/chicken-wranglers/src/controllers/matchcontroller.cpp new file mode 100644 index 0000000..e25d3db --- /dev/null +++ b/chicken-wranglers/src/controllers/matchcontroller.cpp @@ -0,0 +1,246 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + +#include "matchcontroller.h" + +#include "chickencontroller.h" +#include "matchai.h" +#include "playercontroller.h" +#include "playermodel.h" +#include "settings.h" + +#include + +MatchController::MatchController(QObject *parent) + : QObject(parent) +{ +} + +MatchController::MatchController(PlayerListModel *model, int chickens, int elapsedTime, QObject *parent) + : QObject(parent), m_playerListModel(model), m_matchAI(0), + m_chickens(chickens), m_elapsedTime(elapsedTime), m_status(Ready) +{ + qmlRegisterType("game.types", 1, 0, "ChickenController"); + qmlRegisterType("game.types", 1, 0, "PlayerController"); +} + +MatchController::~MatchController() +{ + if (m_matchAI) + delete m_matchAI; +} + +void MatchController::updateElapsedTime() +{ + m_time = m_time.addSecs(-1); + m_elapsedTime--; + + emit elapsedTimeChanged(); +} + +QString MatchController::elapsedTime() const +{ + return m_time.toString("mm:ss"); +} + +void MatchController::setStatus(Status status) +{ + if (m_status == status) + return; + + m_status = status; + + switch (status) { + case Started: + start(); + break; + case Paused: + pause(); + break; + case Running: + resume(); + break; + case Over: + leave(); + break; + default: + qWarning("Invalid match status"); + } + + emit statusChanged(); +} + +void MatchController::start() +{ + m_timer.start(); + + m_status = Running; +} + +void MatchController::pause() +{ + m_timer.stop(); +} + +void MatchController::resume() +{ + m_timer.start(); +} + +void MatchController::leave() +{ + emit matchOver(); +} + +void MatchController::matchTimeout() +{ + m_timer.stop(); + + emit matchFinished(); +} + +void MatchController::setupMatch() +{ + // FIXME: These should not be hardcoded + m_playerStartPositionList.append(QPoint(0, 0)); + m_playerStartPositionList.append(QPoint(9, 9)); + m_playerStartPositionList.append(QPoint(0, 9)); + m_playerStartPositionList.append(QPoint(9, 0)); + + m_matchAI = new MatchAI(QSize(10, 10)); + + m_time.setHMS(0, 0, 0); + m_time = m_time.addSecs(m_elapsedTime); + m_timer.setInterval(1000); + connect(&m_timer, SIGNAL(timeout()), + this, SLOT(onTimerTick())); + + createPlayers(); + createChickens(); +} + +void MatchController::createChickens() +{ + m_chickenCount = m_chickens; + + for (int i = 0; i < m_chickenCount; i++) { + ChickenController *chickenController = new ChickenController(m_matchAI, this); + chickenControllerList.append(chickenController); + + emit chickenCreated(i); + } +} + +void MatchController::createPlayers() +{ + int i; + + for (i = 0; i < m_playerListModel->rowCount() && i < m_playerStartPositionList.size(); i++) { + PlayerModel *playerModel = m_playerListModel->get(i); + + PlayerController *playerController = new PlayerController(playerModel, m_matchAI, this); + playerController->setPosition(m_playerStartPositionList.at(i)); + Node *henCoop = m_matchAI->addPlayer(m_playerStartPositionList.at(i)); + if (!henCoop) { + qWarning("Error adding player to match AI"); + playerController->deleteLater(); + continue; + } + + connect(henCoop, SIGNAL(chickenEntered(int)), + playerController, SLOT(onScore(int))); + + connect(henCoop, SIGNAL(chickenEntered(int)), + this, SLOT(onChickenEntered(int))); + + playerControllerList.append(playerController); + + emit playerCreated(i); + } +} + +ChickenController *MatchController::getChicken(int id) const +{ + if (id >= chickenControllerList.size() || id < 0) + return 0; + + return chickenControllerList.at(id); +} + +PlayerController *MatchController::getPlayer(int id) const +{ + if (id >= playerControllerList.size() || id < 0) + return 0; + + return playerControllerList.at(id); +} + +void MatchController::toggleLaser(int x, int y, int laserDirection) +{ + foreach(PlayerController *playerController, playerControllerList) + m_matchAI->doSafe(playerController->position()); + + bool isOn = m_matchAI->toggleLaser(QPoint(x, y), + static_cast(laserDirection)); + + foreach(PlayerController *playerController, playerControllerList) + m_matchAI->doUnSafe(playerController->position()); + + emit laserUpdated(x, y, laserDirection, isOn); +} + +void MatchController::onTimerTick() +{ + updateElapsedTime(); + + if (m_elapsedTime == 0) + matchTimeout(); +} + +void MatchController::onChickenEntered(int) +{ + if (--m_chickenCount > 0) + return; + + m_timer.stop(); + + emit matchFinished(); +} diff --git a/chicken-wranglers/src/controllers/matchcontroller.h b/chicken-wranglers/src/controllers/matchcontroller.h new file mode 100644 index 0000000..c6c4e0f --- /dev/null +++ b/chicken-wranglers/src/controllers/matchcontroller.h @@ -0,0 +1,132 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef MATCHCONTROLLER_H +#define MATCHCONTROLLER_H + +#include "global.h" + +#include +#include +#include +#include + +class ChickenController; +class MatchAI; +class PlayerController; +class PlayerListModel; + +class MatchController : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QString elapsedTime READ elapsedTime NOTIFY elapsedTimeChanged) + Q_PROPERTY(Status status READ status WRITE setStatus NOTIFY statusChanged) + + Q_ENUMS(Status) + +public: + MatchController(QObject *parent = 0); + MatchController(PlayerListModel *model, int chickens, int elapsedTime, QObject *parent = 0); + ~MatchController(); + + enum Status { + Ready, + Started, + Paused, + Running, + Over + }; + + QString elapsedTime() const; + + void setStatus(Status status); + Status status() const { return m_status; } + + Q_INVOKABLE void setupMatch(); + Q_INVOKABLE ChickenController *getChicken(int id) const; + Q_INVOKABLE PlayerController *getPlayer(int id) const; + + Q_INVOKABLE void toggleLaser(int x, int y, int laserDirection); + +signals: + void chickenCreated(int id); + void playerCreated(int id); + void laserUpdated(int x, int y, int laserDirection, bool isOn); + void elapsedTimeChanged(); + void statusChanged(); + void matchFinished(); + void matchOver(); + + void aborted(); + +private slots: + void onTimerTick(); + void onChickenEntered(int); + +private: + void setup(); + void createChickens(); + void createPlayers(); + void updateElapsedTime(); + void start(); + void pause(); + void resume(); + void leave(); + void matchTimeout(); + + QList m_playerStartPositionList; + + QList chickenControllerList; + QList playerControllerList; + + PlayerListModel *m_playerListModel; + MatchAI *m_matchAI; + QTimer m_timer; + QTime m_time; + int m_chickens; + int m_elapsedTime; + Status m_status; + int m_chickenCount; +}; + +#endif diff --git a/chicken-wranglers/src/controllers/playercontroller.cpp b/chicken-wranglers/src/controllers/playercontroller.cpp new file mode 100644 index 0000000..98f17fa --- /dev/null +++ b/chicken-wranglers/src/controllers/playercontroller.cpp @@ -0,0 +1,127 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + +#include "playercontroller.h" + +#include "matchai.h" +#include "matchcontroller.h" +#include "playermodel.h" +#include "soundmanager.h" + +PlayerController::PlayerController(QObject *parent) + : QObject(parent) +{ +} + +PlayerController::PlayerController(PlayerModel *model, MatchAI *matchAI, QObject *parent) + : QObject(parent), m_model(model), m_matchAI(matchAI), m_score(0) +{ + connect(m_model, SIGNAL(laserToggleRequested(Global::LaserDirection)), + this, SLOT(onLaserToggleRequested(Global::LaserDirection))); +} + +PlayerController::~PlayerController() +{ +} + +void PlayerController::setPosition(const QPoint &position) +{ + if (position == m_position) + return; + + m_position = position; + + emit positionChanged(); +} + +void PlayerController::onScore(int score) +{ + SoundManager::play(SoundManager::Score); + + m_model->setScore(score); +} + +void PlayerController::move() +{ + Q_ASSERT(m_matchAI); + + Global::Direction direction = m_model->direction(); + QPoint nextPosition = m_matchAI->movePlayer(m_position, direction); + setPosition(nextPosition); +} + +bool PlayerController::isSameDirection(Global::LaserDirection laserDirection) +{ + Global::Direction currentDirection = m_model->direction(); + + if (currentDirection == Global::DirectionStop) + return true; + + if (laserDirection == Global::LaserUp && currentDirection == Global::DirectionUp) + return true; + + if (laserDirection == Global::LaserDown && currentDirection == Global::DirectionDown) + return true; + + if (laserDirection == Global::LaserLeft && currentDirection == Global::DirectionLeft) + return true; + + if (laserDirection == Global::LaserRight && currentDirection == Global::DirectionRight) + return true; + + return false; +} + +void PlayerController::onLaserToggleRequested(Global::LaserDirection laserDirection) +{ + SoundManager::play(SoundManager::Laser); + + if (isSameDirection(laserDirection)) { + MatchController *matchController = qobject_cast(parent()); + if (!matchController) { + qWarning("Error getting MatchController from PlayerController"); + return; + } + + matchController->toggleLaser(m_position.x(), m_position.y(), laserDirection); + } else + emit laserToggleRequested(laserDirection); +} diff --git a/chicken-wranglers/src/controllers/playercontroller.h b/chicken-wranglers/src/controllers/playercontroller.h new file mode 100644 index 0000000..2295d03 --- /dev/null +++ b/chicken-wranglers/src/controllers/playercontroller.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef PLAYERCONTROLLER_H +#define PLAYERCONTROLLER_H + +#include +#include + +#include "global.h" + +class MatchAI; +class PlayerModel; + +class PlayerController : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QPoint position READ position NOTIFY positionChanged) + +public: + PlayerController(QObject *parent = 0); + PlayerController(PlayerModel *model, MatchAI *matchAI, QObject *parent = 0); + ~PlayerController(); + + PlayerModel *model() const { return m_model; } + + QPoint position() const { return m_position; } + void setPosition(const QPoint &position); + int score() const { return m_score; } + + Q_INVOKABLE void move(); + +public slots: + void onScore(int score); + +signals: + void positionChanged(); + void scoreChanged(); + void laserToggleRequested(int laserDirection); + +private slots: + void onLaserToggleRequested(Global::LaserDirection direction); + +private: + bool isSameDirection(Global::LaserDirection laserDirection); + + PlayerModel *m_model; + MatchAI *m_matchAI; + QPoint m_position; + int m_score; +}; + +#endif diff --git a/chicken-wranglers/src/main/argumentparser.cpp b/chicken-wranglers/src/main/argumentparser.cpp new file mode 100644 index 0000000..151ff8b --- /dev/null +++ b/chicken-wranglers/src/main/argumentparser.cpp @@ -0,0 +1,118 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#include "argumentparser.h" + +ArgumentProcessor::ArgumentProcessor(QStringList options) + : m_args(options) +{ +} + +QSize ArgumentProcessor::display() +{ + QSize result; + // -displaysize + QStringList displaySizeList = valueForOption("-displaysize").split("x"); + if (displaySizeList.size() == 2) { + result.setWidth(displaySizeList.at(0).toInt()); + result.setHeight(displaySizeList.at(1).toInt()); + } + + return result; +} + +QString ArgumentProcessor::connectivity() +{ + QString result("bluetooth"); + // -connectivity bluetooth | lan + QString argument = valueForOption("-connectivity"); + if (argument == "lan") { + result = "lan"; + } + + return result; +} + +QString ArgumentProcessor::tcpPort() +{ + QString result("-1"); + // -tcpport + QString argument = valueForOption("-tcpport"); + if (!argument.isEmpty()) + result = argument; + + return result; +} + +QString ArgumentProcessor::udpPort() +{ + QString result("-1"); + // -udpport + QString argument = valueForOption("-udpport"); + if (!argument.isEmpty()) + result = argument; + + return result; +} + +QString ArgumentProcessor::graphicsMode() +{ + QString result("opengl"); + // - opengl | raster + QString argument = valueForOption("-graphicsmode"); + if (argument == "raster") { + result = "raster"; + } + + return result; +} + +QString ArgumentProcessor::valueForOption(const QString &option) +{ + int optionIndex = m_args.indexOf(option); + + if ((optionIndex != -1) && (optionIndex + 1 < m_args.size())) + return m_args.at(optionIndex + 1); + + return QString(); +} + diff --git a/chicken-wranglers/src/main/argumentparser.h b/chicken-wranglers/src/main/argumentparser.h new file mode 100644 index 0000000..c77e644 --- /dev/null +++ b/chicken-wranglers/src/main/argumentparser.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef ARGUMENTPARSER_H +#define ARGUMENTPARSER_H + +#include +#include +#include + +class ArgumentProcessor +{ +public: + ArgumentProcessor(QStringList options); + + QSize display(); + + QString connectivity(); + + QString tcpPort(); + + QString udpPort(); + + QString graphicsMode(); + + //TODO: move to another file, etc + +private: + QString valueForOption(const QString &option); + + QStringList m_args; +}; + +#endif diff --git a/chicken-wranglers/src/main/game.cpp b/chicken-wranglers/src/main/game.cpp new file mode 100644 index 0000000..e168503 --- /dev/null +++ b/chicken-wranglers/src/main/game.cpp @@ -0,0 +1,206 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#include +#include +#include + +#include "charactermodel.h" +#include "connectivitylistmodel.h" +#include "global.h" +#include "settings.h" +#include "soundmanager.h" +#include "gameclient.h" +#include "gamehost.h" +#include "soundmanager.h" + +#include "game.h" + +Game::Game(const GraphicsMode &mode, QObject *parent) + : QObject(parent), m_gameClient(0), m_gameHost(0), + m_connectivity("bluetooth"), m_mode(None) +{ + qmlRegisterType("game.types", 1, 0, "Global"); + qmlRegisterType("game.types", 1, 0, "Game"); + qmlRegisterType("game.types", 1, 0, "GameClient"); + qmlRegisterType("game.types", 1, 0, "GameHost"); + // FIXME: Register this model later when GameClient is created. + qmlRegisterType("game.types", 1, 0, "ConnectivityListModel"); + + m_view = new QDeclarativeView; + if (mode == OpenGL) { + //XXX: for some reason, setting the GLWidget is not enabling + //ogl in Symbian + if (Global::environment() == Global::Symbian) { + QApplication::setGraphicsSystem("opengl"); + } else { + m_view->setViewport(new QGLWidget); + } + } else { + QApplication::setGraphicsSystem("raster"); + } + + m_view->setResizeMode(QDeclarativeView::SizeRootObjectToView); + m_view->rootContext()->setContextProperty("game", this); + m_view->rootContext()->setContextProperty("settings", Settings::instance()); +} + +Game::~Game() +{ + delete m_gameHost; + delete m_gameClient; + delete m_view; +} + +void Game::setMode(Mode mode) +{ + if (mode == ClientMode) + startClientMode(); + else if (mode == HostMode) + startHostMode(); +} + +void Game::startClientMode() +{ + m_mode = ClientMode; + if (m_gameClient) { + emit modeChanged(); + return; + } + + if (!m_gameClient) { + m_gameClient = new GameClient(m_view->rootContext(), m_connectivity, this); + m_view->rootContext()->setContextProperty("gameClient", m_gameClient); + connect(m_gameClient, SIGNAL(ended()), this, SLOT(onClientModeEnded())); + } else + ;//TODO: client has not a way to update the connectivity + + emit modeChanged(); +} + +void Game::startHostMode() +{ + m_mode = HostMode; + if (m_gameHost) { + m_gameHost->setConnectivity(m_connectivity); + emit modeChanged(); + return; + } + + if (!m_gameHost) { + m_gameHost = new GameHost(m_view->rootContext(), m_connectivity, this); + m_view->rootContext()->setContextProperty("gameHost", m_gameHost); + connect(m_gameHost, SIGNAL(ended()), this, SLOT(onHostModeEnded())); + } + + + emit modeChanged(); +} + +void Game::start(const QSize &displaySize) +{ +#ifdef CW_DEBUG + m_view->setSource(Global::rootDirectory().absoluteFilePath() + "/src/qml/main.qml"); +#else + m_view->setSource(QUrl("qrc:/main.qml")); +#endif + + QObject::connect(m_view->engine(), SIGNAL(quit()), m_view, SLOT(close())); + + if (displaySize.isValid()) { + m_view->resize(displaySize); + m_view->show(); + } else { + m_view->showFullScreen(); + } +} + +QSize Game::displaySize() const +{ + return m_view->size(); +} + +void Game::onHostModeEnded() +{ + m_mode = None; +} + +void Game::onClientModeEnded() +{ + //TODO: client has not a way to update the connectivity + if (m_gameClient) { + delete m_gameClient; + m_gameClient = 0; + } + m_mode = None; +} + +void Game::startBackgroundSound() +{ + SoundManager::play(SoundManager::Background); +} + +int Game::environment() +{ + return Global::environment(); +} + +QString Game::connectivity() const +{ + return m_connectivity; +} + +void Game::setConnectivity(const QString &type) +{ + if (m_connectivity == type) + return; + + m_connectivity = type; + if (m_mode == HostMode) { + onHostModeEnded(); + startHostMode(); + } else { + onClientModeEnded(); + startClientMode(); + } +} + diff --git a/chicken-wranglers/src/main/game.h b/chicken-wranglers/src/main/game.h new file mode 100644 index 0000000..bf297b4 --- /dev/null +++ b/chicken-wranglers/src/main/game.h @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef GAME_H +#define GAME_H + +#include +#include + +#include "gameclient.h" +#include "gamehost.h" + +class GameClient; +class GameHost; +class QDeclarativeView; + +class Game : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QSize displaySize READ displaySize NOTIFY displaySizeChanged) + Q_PROPERTY(Mode mode READ mode WRITE setMode NOTIFY modeChanged) + Q_PROPERTY(QString connectivity READ connectivity WRITE setConnectivity) + + Q_ENUMS(Mode) + +public: + enum Mode { + None, + HostMode, + ClientMode + }; + + enum GraphicsMode { + OpenGL, + Raster + }; + + Game(const GraphicsMode &mode = OpenGL, QObject *parent = 0); + ~Game(); + + void start(const QSize &size = QSize()); + + Mode mode() { return m_mode; } + void setMode(Mode mode); + + QSize displaySize() const; + + QString connectivity() const; + Q_INVOKABLE void setConnectivity(const QString &type); + + Q_INVOKABLE void startBackgroundSound(); + Q_INVOKABLE int environment(); + +signals: + void modeChanged(); + void displaySizeChanged(); + +private slots: + void onClientModeEnded(); + void onHostModeEnded(); + +private: + void startClientMode(); + void startHostMode(); + void setupSounds(); + + QDeclarativeView *m_view; + GameClient *m_gameClient; + GameHost *m_gameHost; + QString m_connectivity; + Mode m_mode; +}; + +#endif diff --git a/chicken-wranglers/src/main/gameclient.cpp b/chicken-wranglers/src/main/gameclient.cpp new file mode 100644 index 0000000..4d2e461 --- /dev/null +++ b/chicken-wranglers/src/main/gameclient.cpp @@ -0,0 +1,423 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + +#include +#include + +#include "charactermodel.h" +#include "connectivitylistmodel.h" +#include "control.h" +#include "global.h" +#include "networkclient.h" +#include "sensormovement.h" +#include "settings.h" + +#include "gameclient.h" + +GameClient::GameClient(QObject *parent) + : QObject(parent) +{ +} + +GameClient::GameClient(QDeclarativeContext *context, const QString &connectivity, QObject *parent) + : QObject(parent), m_declarativeContext(context), m_networkClient(0), + m_characterListModel(0), m_connectivityListModel(0), m_control(new Control(this)), + m_status(NoStatus), m_error(NoError) +{ + m_networkClient = new NetworkClient(connectivity, Settings::lanUdpDiscoveryTimeout(), + Settings::lanUdpDiscoveryClientAttempts(), this); + m_networkClient->setLanPorts(Settings::lanUdpPort(), Settings::lanTcpPort()); + + connect(m_networkClient, SIGNAL(serverDiscoveryTimeout()), + this, SLOT(onServerDiscoveryTimeout())); + connect(m_networkClient, SIGNAL(connected()), + this, SLOT(onConnected())); + connect(m_networkClient, SIGNAL(disconnected()), + this, SLOT(onDisconnected())); + connect(m_networkClient, SIGNAL(socketError(QAbstractSocket::SocketError)), + this, SLOT(onSocketError(QAbstractSocket::SocketError))); + connect(m_networkClient, SIGNAL(messageReceived(NetworkMessage)), + this, SLOT(onMessageReceived(NetworkMessage))); + + m_connectivityListModel = new ConnectivityListModel(this); + connect(m_networkClient, SIGNAL(bluetoothDeviceDiscovered(const BluetoothDevice &)), + m_connectivityListModel, SLOT(addDevice(const BluetoothDevice &))); + connect(m_connectivityListModel, SIGNAL(selectedDevice(const QString &)), + m_networkClient, SLOT(stopDiscovery())); + connect(m_connectivityListModel, SIGNAL(selectedDevice(const QString &)), + m_networkClient, SLOT(connectToBluetoothServer(const QString &))); + m_declarativeContext->setContextProperty("connectivityListModel", m_connectivityListModel); + + SensorMovement *sensorMovement = m_control->sensorMovement(); + sensorMovement->setMinimumRotation(1); + sensorMovement->setThreshold(0.2); + + connect(m_control, SIGNAL(directionChanged(Global::Direction)), + this, SLOT(onControlDirectionChanged(Global::Direction))); + + // TODO: This was tested only on Maemo5. There should + // be specific implementations for Maemo6 and Symbian + // + // m_backlightTimer.setInterval(20000); + // connect(&m_backlightTimer, SIGNAL(timeout()), this, SLOT(forceBackLightOn())); +} + +void GameClient::setStatus(GameClient::Status status) +{ + if (m_status == status) + return; + + m_status = status; + + emit statusChanged(); +} + +void GameClient::setLeader(bool isLeader) +{ + if (m_isLeader == isLeader) + return; + + m_isLeader = isLeader; + + emit isLeaderChanged(); +} + +void GameClient::startConnection() +{ + m_error = NoError; + m_status = NoStatus; + + m_connectivityListModel->loadLastHostDevice(); + m_networkClient->startDiscovery(); +} + +void GameClient::toggleLaserUp() +{ + notifyPlayerControlLaser(CW::PlayerControlLaserUp); +} + +void GameClient::toggleLaserDown() +{ + notifyPlayerControlLaser(CW::PlayerControlLaserDown); +} + +void GameClient::toggleLaserLeft() +{ + notifyPlayerControlLaser(CW::PlayerControlLaserLeft); +} + +void GameClient::toggleLaserRight() +{ + notifyPlayerControlLaser(CW::PlayerControlLaserRight); +} + +void GameClient::moveUp() +{ + onControlDirectionChanged(Global::DirectionUp); +} + +void GameClient::moveDown() +{ + onControlDirectionChanged(Global::DirectionDown); +} + +void GameClient::moveLeft() +{ + onControlDirectionChanged(Global::DirectionLeft); +} + +void GameClient::moveRight() +{ + onControlDirectionChanged(Global::DirectionRight); +} + +void GameClient::moveStop() +{ + onControlDirectionChanged(Global::DirectionStop); +} + +void GameClient::quit() +{ + m_error = NoError; + m_status = NoStatus; + + m_networkClient->stopDiscovery(); + + emit ended(); +} + +void GameClient::onServerDiscoveryTimeout() +{ + m_error = ServerDiscoveryTimeoutError; + + setStatus(Error); + + quit(); +} + +void GameClient::onConnected() +{ + m_connectivityListModel->storeLastHostDevice(); + + disconnect(m_networkClient, SIGNAL(connected()), this, SLOT(onConnected())); + + loadCharacters(); + + setStatus(Joined); +} + +void GameClient::onDisconnected() +{ + disconnect(m_networkClient, SIGNAL(disconnected()), this, SLOT(onDisconnected())); + + setStatus(NoStatus); +} + +void GameClient::onMessageReceived(const NetworkMessage &message) +{ + switch (message.type()) { + case CW::CharacterMessageType: + handleCharacterMessage(message); + break; + case CW::MatchMessageType: + handleMatchMessage(message); + break; + case CW::PlayerInfoMessageType: + handlePlayerInfoMessage(message); + break; + default: + qWarning("Invalid message type"); + } +} + +void GameClient::onSocketError(QAbstractSocket::SocketError error) +{ + Q_UNUSED(error); + + m_error = SocketError; + + setStatus(Error); +} + +void GameClient::loadCharacters() +{ + if (!m_characterListModel) + m_characterListModel = new CharacterListModel(this); + + if (!m_characterListModel->load()) {} + + m_declarativeContext->setContextProperty("characterListModel", m_characterListModel); + + connect(m_characterListModel, SIGNAL(selectedIndexChanged()), + this, SLOT(onModelSelectedIndexChanged())); +} + +void GameClient::onModelSelectedIndexChanged() +{ + int selectedIndex = m_characterListModel->selectedIndex(); + + if (selectedIndex != -1) { + CharacterModel *characterModel = m_characterListModel->get(selectedIndex); + notifyCharacterSelected(characterModel->name()); + } else { + notifyCharacterReleased(); + } +} + +void GameClient::notifyCharacterSelected(const QString &characterName) +{ + NetworkMessage message(CW::CharacterMessageType, CW::CharacterSelected); + message.setData(characterName.toLatin1()); + + m_networkClient->send(message); +} + +void GameClient::notifyCharacterReleased() +{ + NetworkMessage message(CW::CharacterMessageType, CW::CharacterReleased); + + m_networkClient->send(message); +} + +void GameClient::notifyPlayerControlLaser(CW::PlayerControl laserDirection) +{ + NetworkMessage message(CW::PlayerControlMessageType, laserDirection); + + m_networkClient->send(message); +} + +void GameClient::handleCharacterMessage(const NetworkMessage &message) +{ + if (!m_characterListModel) { + // XXX: Properly thrown an exception for the Game class + qCritical("Error: CharacterListModel not initialized."); + return; + } + + switch (message.content()) { + case CW::CharacterSelected: { + QString characterName(message.data()); + + CharacterModel *model; + for (int i = 0; i < m_characterListModel->rowCount(); i++) { + model = m_characterListModel->get(i); + if (model->name() == characterName) + model->setAvailable(false); + } + + break; + } + case CW::CharacterAvailableList: { + QStringList availableCharacters(QString(message.data()).split("|")); + + CharacterModel *model; + for (int i = 0; i < m_characterListModel->rowCount(); i++) { + model = m_characterListModel->get(i); + if (!availableCharacters.contains(model->name())) + model->setAvailable(false); + } + + break; + } + case CW::CharacterIsAvailable: { + QStringList messageDataList(QString(message.data()).split("|")); + QString characterName = messageDataList.at(0); + + bool characterIsAvailable(true); + if (messageDataList.at(1) == "0") + characterIsAvailable = false; + + CharacterModel *model; + for (int i = 0; i < m_characterListModel->rowCount(); i++) { + model = m_characterListModel->get(i); + + if (model->name() == characterName) + model->setAvailable(characterIsAvailable); + } + + break; + } + } +} + +void GameClient::handleMatchMessage(const NetworkMessage &message) +{ + switch (message.content()) { + case CW::MatchReady: + setStatus(Ready); + m_control->start(); + forceBackLightOn(); + m_backlightTimer.start(); + break; + case CW::MatchFinished: + setStatus(LeftMatch); + m_control->stop(); + m_backlightTimer.stop(); + break; + default: + qWarning("Invalid match message"); + } +} + +void GameClient::handlePlayerInfoMessage(const NetworkMessage &message) +{ + switch (message.content()) { + case CW::PlayerInfoLeader: { + bool isLeader(false); + if (message.data() == "1") + isLeader = true; + + setLeader(isLeader); + + break; + } + default: + qWarning("Invalid player info message"); + } +} + +// FIXME: Move this function to a better place +static CW::PlayerControl directionToPlayerControl(Global::Direction direction) +{ + QMap playerControl; + + playerControl[Global::DirectionUp] = CW::PlayerControlUp; + playerControl[Global::DirectionDown] = CW::PlayerControlDown; + playerControl[Global::DirectionRight] = CW::PlayerControlRight; + playerControl[Global::DirectionLeft] = CW::PlayerControlLeft; + playerControl[Global::DirectionStop] = CW::PlayerControlStop; + + return playerControl[direction]; +} + +void GameClient::onControlDirectionChanged(Global::Direction direction) +{ + NetworkMessage message(CW::PlayerControlMessageType, directionToPlayerControl(direction)); + + m_networkClient->send(message); +} + +void GameClient::forceBackLightOn() +{ + /* TODO: Provide specific implementations for Maemo6 and Symbian + + if (!QDBusConnection::systemBus().isConnected()) { + qWarning("Error connecting to session bus"); + return; + } + + QDBusInterface iface("com.nokia.mce", "/com/nokia/mce/request", "com.nokia.mce.request", + QDBusConnection::systemBus()); + + if (iface.isValid()) + iface.call("req_tklock_mode_change", QString("unlocked")); + else + qWarning("Error calling com.nokia.mce.request.req_tklock_mode_change"); + */ +} + +void GameClient::scanCanceled() +{ + m_networkClient->stopDiscovery(); + + // scan is assynchronous, so wait a little bit before cleaning the model + QTimer::singleShot(300, m_connectivityListModel, SLOT(clear())); +} diff --git a/chicken-wranglers/src/main/gameclient.h b/chicken-wranglers/src/main/gameclient.h new file mode 100644 index 0000000..7e9e7ad --- /dev/null +++ b/chicken-wranglers/src/main/gameclient.h @@ -0,0 +1,156 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef GAMECLIENT_H +#define GAMECLIENT_H + +#include +#include +#include + +#include "global.h" +#include "networkmessage.h" + +class CharacterListModel; +class ConnectivityListModel; +class Control; +class NetworkClient; +class QDeclarativeContext; + +class GameClient : public QObject +{ + Q_OBJECT + + Q_PROPERTY(Status status READ status WRITE setStatus NOTIFY statusChanged) + Q_PROPERTY(bool isLeader READ isLeader WRITE setLeader NOTIFY isLeaderChanged) + Q_PROPERTY(ErrorType error READ error NOTIFY errorChanged) + Q_ENUMS(Status ErrorType) + +public: + GameClient(QObject *parent = 0); + GameClient(QDeclarativeContext *context, const QString &connectivity = "lan", + QObject *parent = 0); + + enum Status { + NoStatus, + Joined, + LeftMatch, + Ready, + Playing, + Error + }; + + enum ErrorType { + NoError, + ServerDiscoveryTimeoutError, + SocketError, + UnknownError + }; + + Status status() { return m_status; } + void setStatus(Status status); + + void setLeader(bool isLeader); + bool isLeader() const { return m_isLeader; } + + ErrorType error() { return m_error; } + +public slots: + void startConnection(); + + void scanCanceled(); + + // TODO: Use a single toggle laser method with direction parameter + void toggleLaserUp(); + void toggleLaserDown(); + void toggleLaserLeft(); + void toggleLaserRight(); + + // TODO: Use a single move method with direction parameter + void moveUp(); + void moveDown(); + void moveLeft(); + void moveRight(); + void moveStop(); + + void quit(); + +signals: + void statusChanged(); + void errorChanged(); + void isLeaderChanged(); + void ended(); + +private slots: + void onServerDiscoveryTimeout(); + void onConnected(); + void onDisconnected(); + void onMessageReceived(const NetworkMessage &message); + void onSocketError(QAbstractSocket::SocketError error); + void onModelSelectedIndexChanged(); + void onControlDirectionChanged(Global::Direction direction); + void forceBackLightOn(); + +private: + void loadCharacters(); + + void handleCharacterMessage(const NetworkMessage &message); + void handleMatchMessage(const NetworkMessage &message); + void handlePlayerInfoMessage(const NetworkMessage &message); + + void notifyCharacterSelected(const QString &characterName); + void notifyCharacterReleased(); + void notifyDirectionChanged(Global::Direction); + void notifyPlayerControlLaser(CW::PlayerControl laserDirection); + + QDeclarativeContext *m_declarativeContext; + NetworkClient *m_networkClient; + CharacterListModel *m_characterListModel; + ConnectivityListModel *m_connectivityListModel; + Control *m_control; + Status m_status; + ErrorType m_error; + bool m_isLeader; + QTimer m_backlightTimer; +}; + +#endif diff --git a/chicken-wranglers/src/main/gamehost.cpp b/chicken-wranglers/src/main/gamehost.cpp new file mode 100644 index 0000000..6948d65 --- /dev/null +++ b/chicken-wranglers/src/main/gamehost.cpp @@ -0,0 +1,199 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#include + +#include "global.h" +#include "matchcontroller.h" +#include "networkconnection.h" +#include "playermodel.h" +#include "settings.h" + +#include "gamehost.h" + +GameHost::GameHost(QDeclarativeContext *context, const QString &connectivity, + QObject *parent) + : QObject(parent), m_declarativeContext(context), m_networkServer(0), + m_playerListModel(new PlayerListModel(this)), m_matchController(0), + m_status(NoStatus), m_error(NoError) +{ + m_declarativeContext->setContextProperty("playerListModel", m_playerListModel); + + qmlRegisterType("game.types", 1, 0, "Match"); + + m_networkServer = new NetworkServer(connectivity, Settings::lanUdpDiscoveryTimeout(), + Settings::lanUdpDiscoveryHostAttempts()); + m_networkServer->setLanPorts(Settings::lanUdpPort(), Settings::lanTcpPort()); + + connect(m_networkServer, SIGNAL(error(NetworkServer::ServerError)), + this, SLOT(onServerError(NetworkServer::ServerError))); + connect(m_networkServer, SIGNAL(started()), + this, SLOT(onServerStarted())); + connect(m_networkServer, SIGNAL(peerConnected(NetworkConnection *)), + this, SLOT(onPeerConnected(NetworkConnection *))); + connect(m_networkServer, SIGNAL(peerDisconnected(NetworkConnection *)), + this, SLOT(onPeerDisconnected(NetworkConnection *))); +} + +GameHost::GameHost(QObject *parent) + : QObject(parent) +{ +} + +GameHost::~GameHost() +{ + delete m_networkServer; +} + +void GameHost::setStatus(Status status) +{ + if (m_status == status) + return; + + m_status = status; + + if (m_status == Match) + newMatch(); +} + +void GameHost::newMatch() +{ + if (m_matchController) { + m_matchController->deleteLater(); + m_matchController = 0; + } + + m_matchController = new MatchController(m_playerListModel, Settings::matchChickenNumber(), + Settings::matchTime(), this); + m_declarativeContext->setContextProperty("matchController", m_matchController); + + connect(m_matchController, SIGNAL(matchOver()), + this, SLOT(onMatchOver())); + + m_playerListModel->notifyMatchReady(); +} + +void GameHost::startConnection() +{ + m_error = NoError; + m_status = NoStatus; + + m_networkServer->start(); +} + +void GameHost::quit() +{ + m_error = NoError; + m_status = NoStatus; + m_networkServer->closeAll(); + + emit ended(); +} + +void GameHost::onPeerConnected(NetworkConnection *connection) +{ + qDebug("Peer connected: %d" , connection->id()); + + addPlayer(connection); +} + +void GameHost::onPeerDisconnected(NetworkConnection *connection) +{ + qDebug("Peer disconnected: %d" , connection->id()); + + removePlayer(connection); +} + +void GameHost::addPlayer(NetworkConnection *connection) +{ + if (m_playerListModel->rowCount() == Global::maximumPlayers) { + qWarning("Maximum number of players reached (%d)", Global::maximumPlayers); + + // TODO: Notify client that host is full + return; + } + + m_playerListModel->newPlayer(connection); +} + +void GameHost::removePlayer(NetworkConnection *connection) +{ + m_playerListModel->removePlayer(connection); +} + +void GameHost::onServerError(NetworkServer::ServerError error) +{ + if (error == NetworkServer::AnotherServerRunningError) + m_error = AnotherServerRunningError; + else + m_error = UnknownError; + + if (m_status == Error) + return; + + m_status = Error; + emit statusChanged(); + + quit(); +} + +void GameHost::onServerStarted() +{ + if (m_status == Start) + return; + + m_status = Start; + emit statusChanged(); +} + +void GameHost::onMatchOver() +{ + m_status = WaitingRoom; + + m_playerListModel->reset(); + m_playerListModel->notifyMatchFinished(); +} + +void GameHost::setConnectivity(const QString &connectivity) +{ + m_networkServer->createConnectionHandler(connectivity); +} diff --git a/chicken-wranglers/src/main/gamehost.h b/chicken-wranglers/src/main/gamehost.h new file mode 100644 index 0000000..795c954 --- /dev/null +++ b/chicken-wranglers/src/main/gamehost.h @@ -0,0 +1,123 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef GAMEHOST_H +#define GAMEHOST_H + +#include + +#include "networkmessage.h" +#include "networkserver.h" + +class MatchController; +class PlayerListModel; +class QDeclarativeContext; + +class GameHost : public QObject +{ + Q_OBJECT + + Q_PROPERTY(Status status READ status WRITE setStatus NOTIFY statusChanged) + Q_PROPERTY(ErrorType error READ error NOTIFY errorChanged) + + Q_ENUMS(Status ErrorType GameState) + +public: + GameHost(QObject *parent = 0); + GameHost(QDeclarativeContext *context, const QString &connectivity, + QObject *parent = 0); + ~GameHost(); + + void setConnectivity(const QString &connectivity); + + enum Status { + NoStatus, + Start, + WaitingRoom, + Match, + Error + }; + + enum ErrorType { + NoError, + AnotherServerRunningError, + UnknownError + }; + + Status status() { return m_status; } + void setStatus(Status status); + + ErrorType error() { return m_error; } + +public slots: + void startConnection(); + void quit(); + +signals: + void statusChanged(); + void errorChanged(); + void ended(); + +private slots: + void onServerError(NetworkServer::ServerError error); + void onServerStarted(); + + void onPeerConnected(NetworkConnection *connection); + void onPeerDisconnected(NetworkConnection *connection); + + void onMatchOver(); + +private: + void newMatch(); + void addPlayer(NetworkConnection *connection); + void removePlayer(NetworkConnection *connection); + + QDeclarativeContext *m_declarativeContext; + NetworkServer *m_networkServer; + + PlayerListModel *m_playerListModel; + MatchController *m_matchController; + Status m_status; + ErrorType m_error; +}; + +#endif diff --git a/chicken-wranglers/src/main/main.cpp b/chicken-wranglers/src/main/main.cpp new file mode 100644 index 0000000..f98f4e6 --- /dev/null +++ b/chicken-wranglers/src/main/main.cpp @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#include + +#include "argumentparser.h" +#include "game.h" +#include "global.h" +#include "settings.h" + +int main(int argc, char *argv[]) +{ + QCoreApplication::setOrganizationName(Settings::organizationName()); + QCoreApplication::setOrganizationDomain(Settings::organizationDomain()); + QCoreApplication::setApplicationName(Settings::applicationName()); + + if (!Settings::exists()) + Settings::reset(); + + QApplication app(argc, argv); + ArgumentProcessor options(app.arguments()); + QSize displaySize(options.display()); + + QString tcpPort = options.tcpPort(); + QString udpPort = options.udpPort(); + + if (tcpPort != "-1") + Settings::setLanTcpPort(tcpPort); + if (udpPort != "-1") + Settings::setLanUdpPort(udpPort); + + Settings::update(); + + Global::setScreenOrientation(Global::Landscape); + Game::GraphicsMode mode = options.graphicsMode() == "opengl" ? + Game::OpenGL : Game::Raster; + + Game game(mode); + game.setConnectivity(options.connectivity()); + if (options.connectivity() == "bluetooth") { + // FIXME: this function is not working in Symbian + // and is crashing in Meego 1.2 netbook. Need to discover + // why QBluetoothLocalDevice is misbehaving. + // Global::setPowerOn(); + } + + if (displaySize.isValid()) { + game.start(displaySize); + } else { + game.start(); + } + + return app.exec(); +} diff --git a/chicken-wranglers/src/main/main.pri b/chicken-wranglers/src/main/main.pri new file mode 100644 index 0000000..985062a --- /dev/null +++ b/chicken-wranglers/src/main/main.pri @@ -0,0 +1,18 @@ +QT += declarative + +PATH = $$PWD + +HEADERS += \ + $$PATH/game.h \ + $$PATH/gameclient.h \ + $$PATH/gamehost.h \ + $$PATH/argumentparser.h \ + $$PATH/settings.h + +SOURCES += \ + $$PATH/main.cpp \ + $$PATH/game.cpp \ + $$PATH/gameclient.cpp \ + $$PATH/gamehost.cpp \ + $$PATH/argumentparser.cpp \ + $$PATH/settings.cpp diff --git a/chicken-wranglers/src/main/settings.cpp b/chicken-wranglers/src/main/settings.cpp new file mode 100644 index 0000000..0d476ef --- /dev/null +++ b/chicken-wranglers/src/main/settings.cpp @@ -0,0 +1,284 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#include +#include + +#include "settings.h" + +const QString Settings::m_organizationName = "Nokia"; +const QString Settings::m_organizationDomain = "nokia.com"; +const QString Settings::m_applicationName = "chicken-wranglers"; + +// host +static const QSize defaultHostDisplaySize = QSize(1280, 768); +static const int defaultHostMaximumPlayers = 4; + +// match +static const int defaultMatchChickenNumber = 40; +static const int defaultMatchTime = 180; +static const int defaultMatchChickenMoveInterval = 700; +static const int defaultMatchChickenChangeStepsInterval = 260; +static const int defaultMatchCharacterMoveInterval = 500; +static const int defaultMatchCharacterChangeStepsInterval = 260; + +// battlefield +static const QSize defaultBattlefieldSize = QSize(10, 10); +static const int defaultBattlefieldCellSize = 70; +static const QPoint defaultBattlefieldStartPoint = QPoint(290, 34); + +// local network +static const int defaultLanTcpPort = 35000; +static const int defaultLanUdpPort = 45000; +static const int defaultLanUdpDiscoveryTimeout = 100; +static const int defaultLanUdpDiscoveryClientAttempts = 50; +static const int defaultLanUdpDiscoveryHostAttempts = 10; + +// bluetooth +static const QString defaultBluetoothHostAddress = "00:00:00:00:00:00"; +static const QString defaultBluetoothHostName = ""; + +Settings::Settings(QObject *parent) + : QSettings(QSettings::IniFormat, QSettings::UserScope, + m_organizationName, m_applicationName, parent) +{ +} + +Settings *Settings::instance() +{ + static Settings settings; + + return &settings; +} + +void Settings::update() +{ + instance()->sync(); +} + +QString Settings::organizationName() +{ + return m_organizationName; +} + +QString Settings::organizationDomain() +{ + return m_organizationDomain; +} + +QString Settings::applicationName() +{ + return m_applicationName; +} + +// host + +QSize Settings::hostDisplaySize() +{ + return instance()->value("host/displaySize", QSize()).toSize(); +} + +int Settings::hostMaximumPlayers() +{ + return instance()->value("host/maximumPlayers", defaultHostMaximumPlayers).toInt(); +} + +// match + +int Settings::matchTime() +{ + return instance()->value("match/time", defaultMatchTime).toInt(); +} + +int Settings::matchChickenNumber() +{ + return instance()->value("match/chickenNumber", defaultMatchChickenNumber).toInt(); +} + +int Settings::matchChickenMoveInterval() +{ + return instance()->value("match/chickenMoveInterval", + defaultMatchChickenMoveInterval).toInt(); +} + +int Settings::matchChickenChangeStepsInterval() +{ + return instance()->value("match/chickenChangeStepsInterval", + defaultMatchChickenChangeStepsInterval).toInt(); +} + +int Settings::matchCharacterMoveInterval() +{ + return instance()->value("match/chickenCharacterMoveInterval", + defaultMatchCharacterMoveInterval).toInt(); +} + +int Settings::matchCharacterChangeStepsInterval() +{ + return instance()->value("match/chickenCharacterStepsInterval", + defaultMatchCharacterChangeStepsInterval).toInt(); +} + +// battlefield + +QSize Settings::battlefieldSize() +{ + return instance()->value("battlefield/size", defaultBattlefieldSize).toSize(); +} + +int Settings::battlefieldCellSize() +{ + return instance()->value("battlefield/cellSize", defaultBattlefieldCellSize).toInt(); +} + +QPoint Settings::battlefieldStartPoint() +{ + return instance()->value("battlefield/startPoint", defaultBattlefieldStartPoint).toPoint(); +} + +// local network + +int Settings::lanTcpPort() +{ + return instance()->value("lan/tcpPort", defaultLanTcpPort).toInt(); +} + +void Settings::setLanTcpPort(const QString port) +{ + instance()->setValue("lan/tcpPort", port); +} + +int Settings::lanUdpPort() +{ + return instance()->value("lan/udpPort", defaultLanUdpPort).toInt(); +} + +void Settings::setLanUdpPort(const QString port) +{ + instance()->setValue("lan/udpPort", port); +} + +int Settings::lanUdpDiscoveryTimeout() +{ + return instance()->value("lan/UdpDiscoveryTimeout", defaultLanUdpDiscoveryTimeout).toInt(); +} + +int Settings::lanUdpDiscoveryClientAttempts() +{ + return instance()->value("lan/UdpDiscoveryClientAttempts", + defaultLanUdpDiscoveryClientAttempts).toInt(); +} + +int Settings::lanUdpDiscoveryHostAttempts() +{ + return instance()->value("lan/UdpDiscoveryHostAttempts", + defaultLanUdpDiscoveryHostAttempts).toInt(); +} + +// bluetooth + +QString Settings::bluetoothHostAddress() +{ + return instance()->value("bluetooth/hostAddress", QString()).toString(); +} + +void Settings::setBluetoothHostAddress(const QString &address) +{ + instance()->setValue("bluetooth/hostAddress", address); +} + +QString Settings::bluetoothHostName() +{ + return instance()->value("bluetooth/hostName", QString()).toString(); +} + +void Settings::setBluetoothHostName(const QString &name) +{ + instance()->setValue("bluetooth/hostName", name); +} + +bool Settings::exists() +{ + QFileInfo settingsFileInfo(instance()->fileName()); + + return settingsFileInfo.exists(); +} + +void Settings::reset() +{ + Settings *settings = instance(); + + settings->beginGroup("host"); + settings->setValue("displaySize", defaultHostDisplaySize); + settings->setValue("hostMaximumPlayers", defaultHostMaximumPlayers); + settings->endGroup(); + + settings->beginGroup("match"); + settings->setValue("time", defaultMatchTime); + settings->setValue("chickenNumber", defaultMatchChickenNumber); + settings->setValue("chickenMoveInterval", defaultMatchChickenMoveInterval); + settings->setValue("chickenChangeStepsInterval", defaultMatchChickenChangeStepsInterval); + settings->setValue("characterMoveInterval", defaultMatchCharacterMoveInterval); + settings->setValue("characterChangeStepsInterval", defaultMatchCharacterChangeStepsInterval); + settings->endGroup(); + + settings->beginGroup("battlefield"); + settings->setValue("size", defaultBattlefieldSize); + settings->setValue("cellSize", defaultBattlefieldCellSize); + settings->setValue("startPoint", defaultBattlefieldStartPoint); + settings->endGroup(); + + settings->beginGroup("lan"); + settings->setValue("tcpPort", defaultLanTcpPort); + settings->setValue("udpPort", defaultLanUdpPort); + settings->setValue("udpDiscoveryTimeout", defaultLanUdpDiscoveryTimeout); + settings->setValue("udpDiscoveryClientAttempts", defaultLanUdpDiscoveryClientAttempts); + settings->setValue("udpDiscoveryHostAttempts", defaultLanUdpDiscoveryHostAttempts); + settings->endGroup(); + + settings->beginGroup("bluetooth"); + settings->setValue("hostAddress", defaultBluetoothHostAddress); + settings->setValue("hostName", defaultBluetoothHostName); + settings->endGroup(); + + update(); +} diff --git a/chicken-wranglers/src/main/settings.h b/chicken-wranglers/src/main/settings.h new file mode 100644 index 0000000..1c967f3 --- /dev/null +++ b/chicken-wranglers/src/main/settings.h @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef SETTINGS_H +#define SETTINGS_H + +#include +#include +#include +#include + +class Settings : public QSettings +{ + Q_OBJECT + +public: + static Settings *instance(); + + static void update(); + static bool exists(); + static void reset(); + + static QString organizationName(); + static QString organizationDomain(); + static QString applicationName(); + +public slots: + // host + static QSize hostDisplaySize(); + static int hostMaximumPlayers(); + + // match + static int matchTime(); + static int matchChickenNumber(); + static int matchChickenMoveInterval(); + static int matchChickenChangeStepsInterval(); + static int matchCharacterMoveInterval(); + static int matchCharacterChangeStepsInterval(); + + // battlefield + static QSize battlefieldSize(); + static int battlefieldCellSize(); + static QPoint battlefieldStartPoint(); + + // local network + static int lanTcpPort(); + static void setLanTcpPort(const QString port); + static int lanUdpPort(); + static void setLanUdpPort(const QString port); + static int lanUdpDiscoveryTimeout(); + static int lanUdpDiscoveryClientAttempts(); + static int lanUdpDiscoveryHostAttempts(); + + // bluetooth + static QString bluetoothHostAddress(); + static void setBluetoothHostAddress(const QString &address); + + static QString bluetoothHostName(); + static void setBluetoothHostName(const QString &name); + +private: + explicit Settings(QObject *parent = 0); + + static const QString m_organizationName; + static const QString m_organizationDomain; + static const QString m_applicationName; +}; + +#endif diff --git a/chicken-wranglers/src/models/bluetoothdevice.cpp b/chicken-wranglers/src/models/bluetoothdevice.cpp new file mode 100644 index 0000000..2d72086 --- /dev/null +++ b/chicken-wranglers/src/models/bluetoothdevice.cpp @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#include "bluetoothdevice.h" + +BluetoothDevice::BluetoothDevice(QObject *parent) + : QObject(parent) +{ +} + +BluetoothDevice::BluetoothDevice(const BluetoothDevice &device) + : QObject(device.parent()) +{ + operator=(device); +} + +bool BluetoothDevice::operator==(const BluetoothDevice &device) const +{ + return (m_address == device.address()); +} + +BluetoothDevice &BluetoothDevice::operator=(const BluetoothDevice &device) +{ + m_name = device.m_name; + m_address = device.m_address; + m_paired = device.m_paired; + m_category = device.m_category; + + return *this; +} + +void BluetoothDevice::setName(const QString &name) +{ + m_name = name; +} + +QString BluetoothDevice::name() const +{ + return m_name; +} + +void BluetoothDevice::setAddress(const QString &address) +{ + m_address = address; +} + +QString BluetoothDevice::address() const +{ + return m_address; +} + +void BluetoothDevice::setPaired(const bool paired) +{ + m_paired = paired; +} + +bool BluetoothDevice::paired() const +{ + return m_paired; +} + +void BluetoothDevice::setCategory(const quint8 category) +{ + m_category = category; +} + +quint8 BluetoothDevice::category() const +{ + return m_category; +} + diff --git a/chicken-wranglers/src/models/bluetoothdevice.h b/chicken-wranglers/src/models/bluetoothdevice.h new file mode 100644 index 0000000..4bb7a36 --- /dev/null +++ b/chicken-wranglers/src/models/bluetoothdevice.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef BLUETOOTHDEVICE_H +#define BLUETOOTHDEVICE_H + +#include +#include + +class BluetoothDevice : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(QString address READ address WRITE setAddress) + Q_PROPERTY(bool paired READ paired WRITE setPaired) + Q_PROPERTY(quint8 category READ category WRITE setCategory) + +public: + BluetoothDevice(QObject *parent = 0); + BluetoothDevice(const BluetoothDevice &device); + + bool operator==(const BluetoothDevice &device) const; + BluetoothDevice &operator=(const BluetoothDevice &device); + + enum Category { + Other, + Computer, + Phone + }; + + void setName(const QString &name); + QString name() const; + + void setAddress(const QString &address); + QString address() const; + + void setPaired(const bool paired); + bool paired() const; + + void setCategory(const quint8 category); + quint8 category() const; + +private: + QString m_name; + QString m_address; + bool m_paired; + quint8 m_category; +}; + +#endif diff --git a/chicken-wranglers/src/models/charactermodel.cpp b/chicken-wranglers/src/models/charactermodel.cpp new file mode 100644 index 0000000..c8f0f53 --- /dev/null +++ b/chicken-wranglers/src/models/charactermodel.cpp @@ -0,0 +1,217 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + +#include "charactermodel.h" + +#include "global.h" + +#include +#include +#include +#include + +CharacterModel::CharacterModel(QObject *parent) + : QObject(parent) +{ +} + +CharacterModel::CharacterModel(const QFileInfo &characterPath, QObject *parent) + : QObject(parent), m_path(characterPath.absoluteFilePath()), m_available(true) +{ + // TODO: Maybe we need to check it for a valid directory path + m_characterName = characterPath.baseName(); +} + +CharacterModel::CharacterModel(const QString &characterName, QObject *parent) + : QObject(parent), m_characterName(characterName), + m_path(QFileInfo(basePath() + characterName).absoluteFilePath()) +{ +} + +QString CharacterModel::path() const +{ + return QUrl::fromLocalFile(m_path.toString()).toString(); +} + +QString CharacterModel::basePath() +{ + return Global::rootDirectory().absoluteFilePath() + "/characters/"; +} + +bool CharacterModel::isValid() const +{ + QString iconPath = m_path.toString(QUrl::RemoveScheme) + "/select_character.png"; + + if (QPixmap(iconPath).isNull()) + return false; + + return true; +} + +void CharacterModel::setAvailable(bool available) +{ + if (m_available == available) + return; + + m_available = available; + + emit isAvailableChanged(available); +} + +CharacterListModel::CharacterListModel(QObject *parent) + : QAbstractListModel(parent), m_selectedIndex(-1) +{ + QHash roles; + + roles[PathRole] = "path"; + roles[IsAvailableRole] = "isAvailable"; + + setRoleNames(roles); + + qmlRegisterType("game.types", 1, 0, "CharacterModel"); +} + +bool CharacterListModel::load() +{ + QDir characterDir = QDir(CharacterModel::basePath()); + if (!characterDir.exists()) + return false; + + QFlags flags = QDir::Dirs | QDir::NoDotAndDotDot; + QFileInfoList entries = characterDir.entryInfoList(flags, QDir::Time); + + foreach(QFileInfo entry, entries) { + CharacterModel *character = new CharacterModel(entry); + + if (character->isValid()) + addCharacter(character); + else + delete character; + } + + return true; +} + +void CharacterListModel::addCharacter(CharacterModel *character) +{ + beginInsertRows(QModelIndex(), rowCount(), rowCount()); + m_characters << character; + endInsertRows(); + + connect(character, SIGNAL(isAvailableChanged(bool)), + this, SLOT(onIsAvailableChanged(bool))); +} + +int CharacterListModel::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + + return m_characters.count(); +} + +QVariant CharacterListModel::data(const QModelIndex &index, int role) const +{ + if (index.row() < 0 || index.row() >= m_characters.count()) + return QVariant(); + + CharacterModel *character = m_characters[index.row()]; + + if (role == PathRole) + return character->path(); + if (role == IsAvailableRole) + return character->isAvailable(); + + return QVariant(); +} + +void CharacterListModel::setSelectedIndex(int selectedIndex) +{ + if (selectedIndex >= m_characters.count()) + return; + + m_selectedIndex = selectedIndex; + + selectedIndexChanged(); +} + +CharacterModel *CharacterListModel::get(int index) const +{ + if (index < 0 || index >= m_characters.count()) + return 0; + + return m_characters.at(index); +} + +CharacterModel *CharacterListModel::selected() const +{ + if (m_selectedIndex < 0 || m_selectedIndex >= m_characters.count()) + return 0; + + return m_characters.at(m_selectedIndex); +} + +QStringList CharacterListModel::characterNameList() +{ + QDir characterDir = QDir(CharacterModel::basePath()); + if (!characterDir.exists()) + return QStringList(); + + QFlags flags = QDir::Dirs | QDir::NoDotAndDotDot; + QFileInfoList entries = characterDir.entryInfoList(flags, QDir::Time); + + QStringList nameList; + + foreach(QFileInfo entry, entries) + nameList.append(entry.baseName()); + + return nameList; +} + +void CharacterListModel::onIsAvailableChanged(bool available) +{ + Q_UNUSED(available) + + CharacterModel *model = qobject_cast(sender()); + + int characterIndex = m_characters.indexOf(model); + + dataChanged(index(characterIndex), index(characterIndex)); +} diff --git a/chicken-wranglers/src/models/charactermodel.h b/chicken-wranglers/src/models/charactermodel.h new file mode 100644 index 0000000..b3e27f7 --- /dev/null +++ b/chicken-wranglers/src/models/charactermodel.h @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef CHARACTERMODEL_H +#define CHARACTERMODEL_H + +#include +#include +#include + +class CharacterModel : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QString path READ path NOTIFY pathChanged) + Q_PROPERTY(bool isAvailable READ isAvailable NOTIFY isAvailableChanged) + +public: + CharacterModel(QObject *parent = 0); + CharacterModel(const QFileInfo &characterPath, QObject *parent = 0); + CharacterModel(const QString &characterName, QObject *parent = 0); + + bool isValid() const; + + QString path() const; + QString name() const { return m_characterName; } + + bool isAvailable() const { return m_available; } + void setAvailable(bool available); + + static QString basePath(); + +signals: + void pathChanged(const QString &path); + void isAvailableChanged(bool available); + +private: + QString m_characterName; + QUrl m_path; + bool m_available; +}; + +class CharacterListModel : public QAbstractListModel +{ + Q_OBJECT + + Q_PROPERTY(int selectedIndex READ selectedIndex WRITE setSelectedIndex NOTIFY selectedIndexChanged) + +public: + enum CharacterRole { + PathRole = Qt::UserRole + 1, + IsAvailableRole + }; + + explicit CharacterListModel(QObject *parent = 0); + + bool load(); + void addCharacter(CharacterModel *character); + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + + int selectedIndex() const { return m_selectedIndex; } + void setSelectedIndex(int selectedIndex); + + static QStringList characterNameList(); + + Q_INVOKABLE CharacterModel *get(int index) const; + Q_INVOKABLE CharacterModel *selected() const; + +signals: + void selectedIndexChanged(); + +private slots: + void onIsAvailableChanged(bool available); + +private: + QList m_characters; + int m_selectedIndex; +}; + +#endif diff --git a/chicken-wranglers/src/models/connectivitylistmodel.cpp b/chicken-wranglers/src/models/connectivitylistmodel.cpp new file mode 100644 index 0000000..46c4a19 --- /dev/null +++ b/chicken-wranglers/src/models/connectivitylistmodel.cpp @@ -0,0 +1,151 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + +#include "connectivitylistmodel.h" + +#include "settings.h" + +ConnectivityListModel::ConnectivityListModel(QObject *parent) + : QAbstractListModel(parent), m_selectedIndex(-1) +{ + QHash roles; + + roles[NameRole] = "name"; + roles[AddressRole] = "address"; + + setRoleNames(roles); +} + +void ConnectivityListModel::addDevice(const BluetoothDevice &device) +{ + for (int i = 0; i < m_devices.count(); i++) { + if (m_devices[i] == device) { + if ((m_devices[i].name() == m_devices[i].address()) + && device.name() != device.address()) { + + m_devices[i].setName(device.name()); + emit dataChanged(index(i), index(i)); + } + + return; + } + } + + beginInsertRows(QModelIndex(), rowCount(), rowCount()); + m_devices << device; + endInsertRows(); +} + +int ConnectivityListModel::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + + return m_devices.count(); +} + +QVariant ConnectivityListModel::data(const QModelIndex &index, int role) const +{ + if (index.row() < 0 || index.row() > m_devices.count()) + return QVariant(); + + const BluetoothDevice &device = m_devices[index.row()]; + + if (role == NameRole) + return device.name(); + else if (role == AddressRole) + return device.address(); + + return QVariant(); +} + +void ConnectivityListModel::setSelectedIndex(int selectedIndex) +{ + if (selectedIndex >= m_devices.count()) + return; + + m_selectedIndex = selectedIndex; + + emit selectedIndexChanged(); + + emit selectedDevice(m_devices[m_selectedIndex].address()); +} + +void ConnectivityListModel::clear() +{ + if (!rowCount()) + return; + + beginRemoveRows(QModelIndex(), 0, rowCount() - 1); + m_devices.clear(); + endRemoveRows(); +} + +void ConnectivityListModel::storeLastHostDevice() +{ + if (m_selectedIndex == -1 || m_selectedIndex >= m_devices.count()) + return; + + BluetoothDevice device = m_devices[m_selectedIndex]; + Settings::setBluetoothHostAddress(device.address()); + Settings::setBluetoothHostName(device.name()); +} + +void ConnectivityListModel::loadLastHostDevice() +{ + BluetoothDevice device; + + QString address = Settings::bluetoothHostAddress(); + QString name = Settings::bluetoothHostName(); + + if (address == "00:00:00:00:00:00" || address.isEmpty()) + return; + + device.setAddress(address); + if (!name.isEmpty()) + device.setName(name); + else + device.setName(address); + + addDevice(device); + + m_selectedIndex = m_devices.indexOf(device); + emit selectedIndexChanged(); +} diff --git a/chicken-wranglers/src/models/connectivitylistmodel.h b/chicken-wranglers/src/models/connectivitylistmodel.h new file mode 100644 index 0000000..a81d693 --- /dev/null +++ b/chicken-wranglers/src/models/connectivitylistmodel.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef CONNECTIVITYLISTMODEL_H +#define CONNECTIVITYLISTMODEL_H + +#include "bluetoothdevice.h" + +#include + +class ConnectivityListModel : public QAbstractListModel +{ + Q_OBJECT + + Q_PROPERTY(int selectedIndex READ selectedIndex WRITE setSelectedIndex NOTIFY selectedIndexChanged) + +public: + enum DeviceRole { + NameRole = Qt::UserRole + 1, + AddressRole + }; + + ConnectivityListModel(QObject *parent = 0); + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + + int selectedIndex() const { return m_selectedIndex; } + void setSelectedIndex(int selectedIndex); + + void storeLastHostDevice(); + void loadLastHostDevice(); + +public slots: + void addDevice(const BluetoothDevice &device); + void clear(); + +signals: + void selectedDevice(const QString &deviceAddress); + void selectedIndexChanged(); + +private: + QList m_devices; + int m_selectedIndex; +}; + +#endif diff --git a/chicken-wranglers/src/models/models.pri b/chicken-wranglers/src/models/models.pri new file mode 100644 index 0000000..9859eff --- /dev/null +++ b/chicken-wranglers/src/models/models.pri @@ -0,0 +1,15 @@ +QT += declarative + +PATH = $$PWD + +HEADERS += \ + $$PATH/charactermodel.h \ + $$PATH/playermodel.h \ + $$PATH/bluetoothdevice.h \ + $$PATH/connectivitylistmodel.h + +SOURCES += \ + $$PATH/charactermodel.cpp \ + $$PATH/playermodel.cpp \ + $$PATH/bluetoothdevice.cpp \ + $$PATH/connectivitylistmodel.cpp diff --git a/chicken-wranglers/src/models/playermodel.cpp b/chicken-wranglers/src/models/playermodel.cpp new file mode 100644 index 0000000..f1ccab0 --- /dev/null +++ b/chicken-wranglers/src/models/playermodel.cpp @@ -0,0 +1,466 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + +#include "playermodel.h" + +#include "charactermodel.h" +#include "networkconnection.h" + +#include + +PlayerModel::PlayerModel(QObject *parent) + : QObject(parent) +{ +} + +PlayerModel::PlayerModel(NetworkConnection *connection, QObject *parent) + : QObject(parent), m_character(0), m_connection(connection), + m_status(NoCharacter), m_direction(Global::DirectionStop), + m_isLeader(false), m_score(0) +{ + connect(connection, SIGNAL(received(NetworkMessage)), + this, SLOT(onNetworkMessageReceived(NetworkMessage))); +} + +PlayerModel::~PlayerModel() +{ + if (!characterName().isEmpty()) + emit characterReleased(characterName()); +} + +QString PlayerModel::characterPath() const +{ + if (m_character) + return m_character->path(); + else + return QString(); +} + +QString PlayerModel::characterName() const +{ + if (m_character) + return m_character->name(); + else + return QString(); +} + +bool PlayerModel::setCharacter(const QString &characterName) +{ + PlayerListModel *listModel = qobject_cast(parent()); + if (!listModel) { + qWarning() << "Invalid PlayerListModel"; + return false; + } + + if (!listModel->availableCharacters().contains(characterName)) + return false; + + // TODO: Check if it is safe to set a new character when + // the player has already selected one. + if (m_character && m_character->name() == characterName) { + qWarning() << "Player has already an associated character"; + return false; + } + + m_character = new CharacterModel(characterName, this); + m_status = Ready; + + emit characterPathChanged(); + emit characterSelected(characterName); + + return true; +} + +bool PlayerModel::unsetCharacter(const QString &characterName) +{ + if (!m_character) { + qWarning() << "Player has no associated character"; + return false; + } + + m_character->deleteLater(); + m_character = 0; + + m_status = NoCharacter; + + emit characterPathChanged(); + emit characterReleased(characterName); + + return true; +} + +void PlayerModel::setLeader(bool isLeader) +{ + if (m_isLeader == isLeader) + return; + + m_isLeader = isLeader; + + notifyPlayerLeader(m_isLeader); +} + +void PlayerModel::setScore(int score) +{ + if (m_score == score) + return; + + m_score = score; + + emit scoreChanged(); +} + +void PlayerModel::reset() +{ + // TODO: Check what we need to cleanup at this point + m_score = 0; + m_direction = Global::DirectionStop; +} + +void PlayerModel::setDirection(Global::Direction direction) +{ + if (m_direction == direction) + return; + + m_direction = direction; + + emit directionChanged(); +} + +void PlayerModel::notifyCharacterAvailableList(const QStringList &availableCharacters) +{ + QString availableCharactersString = availableCharacters.join("|"); + + NetworkMessage message(CW::CharacterMessageType, CW::CharacterAvailableList); + message.setData(availableCharactersString.toLatin1()); + + m_connection->send(message); +} + +void PlayerModel::notifyCharacterIsAvailable(const QString &characterName, bool available) +{ + QByteArray data; + data.append(characterName); + data.append("|"); + + if (available) + data.append("1"); + else + data.append("0"); + + NetworkMessage message(CW::CharacterMessageType, CW::CharacterIsAvailable); + message.setData(data); + + m_connection->send(message); +} + +void PlayerModel::notifyPlayerLeader(bool isLeader) +{ + QByteArray data; + + if (isLeader) + data.append("1"); + else + data.append("0"); + + NetworkMessage message(CW::PlayerInfoMessageType, CW::PlayerInfoLeader); + message.setData(data); + + m_connection->send(message); +} + +void PlayerModel::onNetworkMessageReceived(const NetworkMessage &message) +{ + switch (message.type()) { + case CW::CharacterMessageType: + handleCharacterMessage(message); + break; + case CW::PlayerControlMessageType: + handlePlayerControlMessage(message); + break; + default: + qWarning("Invalid network message type"); + } +} + +void PlayerModel::handleCharacterMessage(const NetworkMessage &message) +{ + switch (message.content()) { + case CW::CharacterSelected: + setCharacter(QString(message.data())); + break; + + case CW::CharacterReleased: + unsetCharacter(characterName()); + break; + + default: + qWarning("Invalid character message"); + } +} + +// FIXME: Move the two static functions below to a better place +static Global::Direction playerControlToDirection(CW::PlayerControl control) +{ + QMap direction; + + direction[CW::PlayerControlUp] = Global::DirectionUp; + direction[CW::PlayerControlDown] = Global::DirectionDown; + direction[CW::PlayerControlRight] = Global::DirectionRight; + direction[CW::PlayerControlLeft] = Global::DirectionLeft; + direction[CW::PlayerControlStop] = Global::DirectionStop; + + return direction[control]; +} + +static Global::LaserDirection playerControlToLaserDirection(CW::PlayerControl control) +{ + QMap laserDirection; + + laserDirection[CW::PlayerControlLaserUp] = Global::LaserUp; + laserDirection[CW::PlayerControlLaserDown] = Global::LaserDown; + laserDirection[CW::PlayerControlLaserRight] = Global::LaserRight; + laserDirection[CW::PlayerControlLaserLeft] = Global::LaserLeft; + + return laserDirection[control]; +} + +void PlayerModel::handlePlayerControlMessage(const NetworkMessage &message) +{ + CW::PlayerControl control = static_cast(message.content()); + + switch (control) { + case CW::PlayerControlLaserUp: + case CW::PlayerControlLaserDown: + case CW::PlayerControlLaserLeft: + case CW::PlayerControlLaserRight: + requestLaserToggle(playerControlToLaserDirection(control)); + break; + case CW::PlayerControlUp: + case CW::PlayerControlDown: + case CW::PlayerControlLeft: + case CW::PlayerControlRight: + case CW::PlayerControlStop: + setDirection(playerControlToDirection(control)); + break; + default: + qWarning("Invalid player control message"); + } +} + +void PlayerModel::requestLaserToggle(Global::LaserDirection laserDirection) +{ + emit laserToggleRequested(laserDirection); +} + +PlayerListModel::PlayerListModel(QObject *parent) + : QAbstractListModel(parent), m_playersReady(false) +{ + QHash roles; + + roles[StatusRole] = "status"; + roles[CharacterPathRole] = "characterPath"; + + setRoleNames(roles); + + qmlRegisterType("game.types", 1, 0, "PlayerModel"); + + m_availableCharacters = CharacterListModel::characterNameList(); +} + +void PlayerListModel::newPlayer(NetworkConnection *connection) +{ + PlayerModel *player = new PlayerModel(connection, this); + + beginInsertRows(QModelIndex(), rowCount(), rowCount()); + m_players << player; + endInsertRows(); + + connect(player, SIGNAL(characterPathChanged()), + this, SLOT(onCharacterPathChanged())); + connect(player, SIGNAL(characterSelected(QString)), + this, SLOT(onCharacterSelected(QString))); + connect(player, SIGNAL(characterReleased(QString)), + this, SLOT(onCharacterReleased(QString))); + + // A new player has joined, so he is not yet until he + // has chosen a character. + setPlayersReady(false); + + // Check if player is the first one connected, which + // makes him the leader. This enables some special + // abilities for his client, such as start/end a match. + if (m_players.size() == 1) + player->setLeader(true); + + player->notifyCharacterAvailableList(m_availableCharacters); +} + +void PlayerListModel::removePlayer(NetworkConnection *connection) +{ + foreach (PlayerModel *model, m_players) { + if (connection == model->connection()) { + int index = m_players.indexOf(model); + + beginRemoveRows(QModelIndex(), index, index); + m_players.removeAt(index); + endRemoveRows(); + + model->deleteLater(); + break; + } + } + + checkPlayersReady(); +} + +int PlayerListModel::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + + return m_players.count(); +} + +QVariant PlayerListModel::data(const QModelIndex &index, int role) const +{ + if (index.row() < 0 || index.row() >= m_players.count()) + return QVariant(); + + PlayerModel *player = m_players[index.row()]; + + if (role == StatusRole) + return player->status(); + if (role == CharacterPathRole) + return player->characterPath(); + + return QVariant(); +} + +void PlayerListModel::reset() +{ + foreach (PlayerModel *player, m_players) + player->reset(); +} + +void PlayerListModel::setPlayersReady(bool playersReady) +{ + if (m_playersReady == playersReady) + return; + + m_playersReady = playersReady; + + emit playersReadyChanged(); +} + +void PlayerListModel::checkPlayersReady() +{ + if (m_players.size() == 0) { + setPlayersReady(false); + return; + } + + foreach(PlayerModel *player, m_players) { + if (player->status() != PlayerModel::Ready) { + setPlayersReady(false); + return; + } + } + + setPlayersReady(true); +} + +PlayerModel *PlayerListModel::get(int index) const +{ + if (index < 0 || index >= m_players.count()) + return 0; + + return m_players.at(index); +} + +void PlayerListModel::onCharacterPathChanged() +{ + PlayerModel *playerModel = qobject_cast(sender()); + + int playerModelIndex = m_players.indexOf(playerModel); + + emit dataChanged(index(playerModelIndex), index(playerModelIndex)); +} + +void PlayerListModel::onCharacterSelected(const QString &characterName) +{ + m_availableCharacters.removeAll(characterName); + + PlayerModel *senderModel = qobject_cast(sender()); + + foreach (PlayerModel *model, m_players) + if (senderModel != model) + model->notifyCharacterIsAvailable(characterName, false); + + checkPlayersReady(); +} + +void PlayerListModel::onCharacterReleased(const QString &characterName) +{ + if (m_availableCharacters.contains(characterName)) + return; + + m_availableCharacters.append(characterName); + + foreach (PlayerModel *model, m_players) + model->notifyCharacterIsAvailable(characterName, true); + + checkPlayersReady(); +} + +void PlayerListModel::notifyMatchReady() +{ + NetworkMessage message(CW::MatchMessageType, CW::MatchReady); + + foreach (PlayerModel *model, m_players) + model->connection()->send(message); +} + +void PlayerListModel::notifyMatchFinished() +{ + NetworkMessage message(CW::MatchMessageType, CW::MatchFinished); + + foreach (PlayerModel *model, m_players) + model->connection()->send(message); +} diff --git a/chicken-wranglers/src/models/playermodel.h b/chicken-wranglers/src/models/playermodel.h new file mode 100644 index 0000000..2bd1d34 --- /dev/null +++ b/chicken-wranglers/src/models/playermodel.h @@ -0,0 +1,175 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef PLAYERMODEL_H +#define PLAYERMODEL_H + +#include "global.h" + +#include "networkmessage.h" + +#include +#include +#include + +class CharacterModel; +class NetworkConnection; + +class PlayerModel : public QObject +{ + Q_OBJECT + Q_ENUMS(Status) + + Q_PROPERTY(QString characterPath READ characterPath NOTIFY characterPathChanged) + Q_PROPERTY(QString direction READ directionString NOTIFY directionChanged) + Q_PROPERTY(int score READ score NOTIFY scoreChanged) + +public: + PlayerModel(QObject *parent = 0); + PlayerModel(NetworkConnection *connection, QObject *parent = 0); + ~PlayerModel(); + + enum Status { + NoCharacter, + Ready, + Playing + }; + + QString characterPath() const; + Status status() const { return m_status; } + NetworkConnection *connection() const { return m_connection; } + + bool setCharacter(const QString &characterName); + bool unsetCharacter(const QString &characterName); + + void setLeader(bool isLeader); + bool isLeader() const { return m_isLeader; } + + void setScore(int score); + int score() const { return m_score; } + + void reset(); + + QString directionString() const { return Global::directionString(m_direction); } + Global::Direction direction() const { return m_direction; } + void setDirection(Global::Direction direction); + + void notifyCharacterAvailableList(const QStringList &availableCharacters); + void notifyCharacterIsAvailable(const QString &characterName, bool available); + void notifyPlayerLeader(bool isLeader); + + QString characterName() const; + +signals: + void characterPathChanged(); + void directionChanged(); + void scoreChanged(); + void characterSelected(const QString &characterName); + void characterReleased(const QString &characterName); + void laserToggleRequested(Global::LaserDirection laserDirection); + +private slots: + void onNetworkMessageReceived(const NetworkMessage &message); + +private: + void handleCharacterMessage(const NetworkMessage &message); + void handlePlayerControlMessage(const NetworkMessage &message); + + void requestLaserToggle(Global::LaserDirection laserDirection); + + CharacterModel *m_character; + NetworkConnection *m_connection; + Status m_status; + Global::Direction m_direction; + bool m_isLeader; + int m_score; +}; + +class PlayerListModel : public QAbstractListModel +{ + Q_OBJECT + + Q_PROPERTY(bool playersReady READ playersReady NOTIFY playersReadyChanged) + +public: + enum PlayerRole { + StatusRole = Qt::UserRole + 1, + CharacterPathRole + }; + + explicit PlayerListModel(QObject *parent = 0); + + void newPlayer(NetworkConnection *connection); + void removePlayer(NetworkConnection *connection); + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + + QStringList availableCharacters() const { return m_availableCharacters; } + void reset(); + + void notifyMatchReady(); + void notifyMatchFinished(); + + // Used by QML views + Q_INVOKABLE PlayerModel *get(int index) const; + Q_INVOKABLE int count() const { return rowCount(); } + +signals: + void playersReadyChanged(); + +private slots: + void onCharacterPathChanged(); + void onCharacterSelected(const QString &characterName); + void onCharacterReleased(const QString &characterName); + +private: + bool playersReady() const { return m_playersReady; } + void setPlayersReady(bool playersReady); + void checkPlayersReady(); + + QList m_players; + QStringList m_availableCharacters; + bool m_playersReady; +}; + +#endif diff --git a/chicken-wranglers/src/network/bluetoothconnection.cpp b/chicken-wranglers/src/network/bluetoothconnection.cpp new file mode 100644 index 0000000..b315fbc --- /dev/null +++ b/chicken-wranglers/src/network/bluetoothconnection.cpp @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#include +#include + +#include "bluetoothconnection.h" + +BluetoothConnection::BluetoothConnection(QObject *parent, QBluetoothSocket *socket) + : NetworkConnection(parent), m_socket(socket) +{ + if (m_socket == 0) + m_socket = new QBluetoothSocket(QBluetoothSocket::RfcommSocket, this); + + connect(m_socket, SIGNAL(connected()), + this, SIGNAL(connected())); + connect(m_socket, SIGNAL(disconnected()), + this, SIGNAL(disconnected())); + connect(m_socket, SIGNAL(error(QBluetoothSocket::SocketError)), + this, SIGNAL(error(QBluetoothSocket::SocketError))); + connect(m_socket, SIGNAL(readyRead()), + this, SLOT(processReadyRead())); +} + +BluetoothConnection::~BluetoothConnection() +{ + if (m_socket) + m_socket->abort(); +} + +void BluetoothConnection::setId(const quint16 &newId) +{ + m_id = newId; +} + +quint16 BluetoothConnection::id() const +{ + return m_id; +} + +void BluetoothConnection::send(NetworkMessage message) +{ + if (m_socket->write(message.byteArray()) == -1) + qWarning("Bluetooth Socket write error: %s", m_socket->errorString().toUtf8().constData()); +} + +void BluetoothConnection::connectToHost(const QString &address, const quint16 &port) +{ + m_socket->connectToService(QBluetoothAddress(address), port); +} + +void BluetoothConnection::disconnectFromHost() +{ + m_socket->disconnectFromService(); +} + +QAbstractSocket::SocketState BluetoothConnection::state() const +{ + return static_cast(m_socket->state()); +} + +QAbstractSocket::SocketError BluetoothConnection::error() const +{ + return static_cast(m_socket->error()); +} + +QString BluetoothConnection::errorString() const +{ + return m_socket->errorString(); +} + +void BluetoothConnection::processReadyRead() +{ + processRead(m_socket); +} + +void BluetoothConnection::close() +{ + m_socket.data()->close(); +} diff --git a/chicken-wranglers/src/network/bluetoothconnection.h b/chicken-wranglers/src/network/bluetoothconnection.h new file mode 100644 index 0000000..a37c5d8 --- /dev/null +++ b/chicken-wranglers/src/network/bluetoothconnection.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef BLUETOOTHCONNECTION_H +#define BLUETOOTHCONNECTION_H + +#include "networkconnection.h" + +#include +#include +#include +#include + +QTM_USE_NAMESPACE + +class BluetoothConnection : public NetworkConnection +{ + Q_OBJECT + +public: + BluetoothConnection(QObject *parent = 0, QBluetoothSocket *socket = 0); + ~BluetoothConnection(); + + void setId(const quint16 &newId); + quint16 id() const; + + void send(NetworkMessage message); + + void connectToHost(const QString &address, const quint16 &port); + void disconnectFromHost(); + + QAbstractSocket::SocketState state() const; + QAbstractSocket::SocketError error() const; + QString errorString() const; + + void close(); + +signals: + void connected(); + void disconnected(); + void error(QBluetoothSocket::SocketError socketError); + +private slots: + void processReadyRead(); + +private: + QPointer m_socket; +}; + +#endif diff --git a/chicken-wranglers/src/network/bluetoothhandler.cpp b/chicken-wranglers/src/network/bluetoothhandler.cpp new file mode 100644 index 0000000..feb5244 --- /dev/null +++ b/chicken-wranglers/src/network/bluetoothhandler.cpp @@ -0,0 +1,198 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + +#include "bluetoothhandler.h" + +#include "connectionfactory.h" +#include "network.h" +#include "networkconnection.h" + +BluetoothHandler::BluetoothHandler(QObject *parent, int maxConnections) + : QRfcommServer(parent), m_serviceInfo(QBluetoothServiceInfo()) + , m_listenPort(14), m_maxConnections(maxConnections) +{ + connect(this, SIGNAL(newConnection()), this, SLOT(newClientConnection())); +} + +BluetoothHandler::~BluetoothHandler() +{ + closeAll(); + stop(); +} + +void BluetoothHandler::start() +{ + if (isListening()) { + emit started(); + return; + } + + QBluetoothAddress address; + + if (listen(address, m_listenPort)) { + qWarning("Server started on port: %d", serverPort()); + emit started(); + registerService(); + } else { + qWarning("Error: Unable to start server"); + emit startError(); + } +} + +void BluetoothHandler::stop() +{ + if (isListening()) + close(); + + m_serviceInfo.unregisterService(); +} + +void BluetoothHandler::setListenPort(const quint16 &port) +{ + if (m_listenPort != port) { + m_listenPort = port; + + emit listenPortChanged(); + } +} + +quint16 BluetoothHandler::listenPort() const +{ + return m_listenPort; +} + +void BluetoothHandler::newClientConnection() +{ + if (m_connections.size() == m_maxConnections) + return; + + NetworkConnection *connection; + connection = ConnectionFactory::create(ConnectionFactory::Bluetooth, + this, nextPendingConnection()); + + for (quint16 id = 0; id < m_maxConnections; id++) { + // If the peer ID is NOT on the dictionary, insert it + if (!m_connections.contains(id)) { + connection->setId(id); + + connect(connection, SIGNAL(disconnected()), + this, SLOT(peerDisconnected())); + connect(connection, SIGNAL(error(QBluetoothSocket::SocketError)), + this, SLOT(socketError(QBluetoothSocket::SocketError))); + connect(connection, SIGNAL(received(NetworkMessage)), + this, SIGNAL(received(NetworkMessage))); + + m_connections[id] = connection; + + // Signals that a new peer has connected + emit peerConnected(connection); + + break; + } + } +} + +void BluetoothHandler::closeAll() +{ + NetworkConnection *tmp; + int pos = 0; + while (m_connections.size()) { + tmp = m_connections[pos]; + tmp->close(); + delete tmp; + ++pos; + } + + m_connections.clear(); +} + +void BluetoothHandler::send(const NetworkMessage &message) +{ + m_connections[message.id()]->send(message); +} + +void BluetoothHandler::peerDisconnected() +{ + NetworkConnection *connection = qobject_cast(sender()); + m_connections.remove(connection->id()); + + // Signals that a peer has disconnected + emit peerDisconnected(connection); +} + +void BluetoothHandler::socketError(QBluetoothSocket::SocketError socketError) +{ + NetworkConnection *connection = qobject_cast(sender()); + quint16 id = connection->id(); + + qWarning("Bluetooth Socket error [ %d ]: %s", socketError, + connection->errorString().toUtf8().constData()); + emit peerError(static_cast(socketError), id); +} + +void BluetoothHandler::registerService() +{ + m_serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceRecordHandle, (uint) 0x00010010); + + // TODO: Profile Descriptor List: "Serial Port" (0x1101) + QBluetoothServiceInfo::Sequence classId; + classId << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::SerialPort)); + m_serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceClassIds, classId); + + m_serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceName, + tr("ChickenWranglers")); + m_serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceDescription, + tr("Game bluetooth server")); + m_serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceProvider, + tr("Openbossa")); + m_serviceInfo.setAttribute(QBluetoothServiceInfo::BrowseGroupList, + QBluetoothUuid(QBluetoothUuid::PublicBrowseGroup)); + + QBluetoothServiceInfo::Sequence protocolDescriptorList; + QBluetoothServiceInfo::Sequence protocol; + protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm)) + << QVariant::fromValue(quint8(serverPort())); + protocolDescriptorList.append(QVariant::fromValue(protocol)); + m_serviceInfo.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, + protocolDescriptorList); + + m_serviceInfo.registerService(); +} diff --git a/chicken-wranglers/src/network/bluetoothhandler.h b/chicken-wranglers/src/network/bluetoothhandler.h new file mode 100644 index 0000000..5248fc3 --- /dev/null +++ b/chicken-wranglers/src/network/bluetoothhandler.h @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef BLUETOOTHHANDLER_H +#define BLUETOOTHHANDLER_H + +#include "networkmessage.h" + +#include +#include +#include +#include + +class NetworkConnection; + +QTM_USE_NAMESPACE + +class BluetoothHandler : public QRfcommServer +{ + Q_OBJECT + + Q_PROPERTY(quint16 listenPort READ listenPort WRITE setListenPort NOTIFY listenPortChanged) + +public: + BluetoothHandler(QObject *parent = 0, int maxConnections = 4); + ~BluetoothHandler(); + + void start(); + void stop(); + + void setListenPort(const quint16 &port); + quint16 listenPort() const; + + void send(const NetworkMessage &message); + void closeAll(); + +signals: + void peerConnected(NetworkConnection *connection); + void peerDisconnected(NetworkConnection *connection); + void peerError(QAbstractSocket::SocketError socketError, quint16 id); + void received(const NetworkMessage &message); + void started(); + void listenPortChanged(); + void startError(); + +private slots: + void newClientConnection(); + void peerDisconnected(); + void socketError(QBluetoothSocket::SocketError socketError); + +protected: + void registerService(); + +private: + QHash m_connections; + QBluetoothServiceInfo m_serviceInfo; + quint16 m_listenPort; + int m_maxConnections; +}; + +#endif diff --git a/chicken-wranglers/src/network/bthandler.cpp b/chicken-wranglers/src/network/bthandler.cpp new file mode 100644 index 0000000..60d8e08 --- /dev/null +++ b/chicken-wranglers/src/network/bthandler.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#include +#include +#include + +#include "bthandler.h" + +BtHandler::BtHandler(QObject *parent) + : QObject(parent), m_discoveryAgent(new QBluetoothDeviceDiscoveryAgent(this)), + m_localDevice(new QBluetoothLocalDevice(this)), m_devices(new QList) +{ + connect(m_discoveryAgent, SIGNAL(deviceDiscovered(const QBluetoothDeviceInfo &)), + this, SLOT(deviceDiscovered(const QBluetoothDeviceInfo &))); +} + +BtHandler::~BtHandler() +{ + delete m_devices; +} + +void BtHandler::enable() +{ + m_discoveryAgent->start(); +} + +void BtHandler::disable() +{ + m_discoveryAgent->stop(); +} + +void BtHandler::deviceDiscovered(const QBluetoothDeviceInfo &deviceInfo) +{ + BluetoothDevice device; + + device.setAddress(deviceInfo.address().toString()); + if (deviceInfo.name().isEmpty()) + device.setName(device.address()); + else + device.setName(deviceInfo.name()); + + device.setPaired(m_localDevice->pairingStatus(deviceInfo.address())); + device.setCategory(quint8(deviceInfo.majorDeviceClass())); + + m_devices->append(device); + + emit discovered(device); +} diff --git a/chicken-wranglers/src/network/bthandler.h b/chicken-wranglers/src/network/bthandler.h new file mode 100644 index 0000000..243bca5 --- /dev/null +++ b/chicken-wranglers/src/network/bthandler.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef BTHANDLER_H +#define BTHANDLER_H + +#include "bluetoothdevice.h" + +#include +#include +#include + +QTM_BEGIN_NAMESPACE + +class QBluetoothDeviceDiscoveryAgent; +class QBluetoothDeviceInfo; +class QBluetoothLocalDevice; + +QTM_END_NAMESPACE + +QTM_USE_NAMESPACE + +class BtHandler : public QObject +{ + Q_OBJECT + +public: + BtHandler(QObject *parent = 0); + ~BtHandler(); + + void enable(); + void disable(); + +signals: + void finished(); + void discovered(const BluetoothDevice &device); + +private slots: + void deviceDiscovered(const QBluetoothDeviceInfo &deviceInfo); + +private: + QBluetoothDeviceDiscoveryAgent *m_discoveryAgent; + QBluetoothLocalDevice *m_localDevice; + QList *m_devices; +}; + +#endif diff --git a/chicken-wranglers/src/network/connectionfactory.cpp b/chicken-wranglers/src/network/connectionfactory.cpp new file mode 100644 index 0000000..6926bcb --- /dev/null +++ b/chicken-wranglers/src/network/connectionfactory.cpp @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#include "connectionfactory.h" + +#include "bluetoothconnection.h" +#include "tcpconnection.h" + +#include +#include + +ConnectionFactory::ConnectionFactory() +{ +} + +NetworkConnection *ConnectionFactory::create(ConnectionType connection, QObject *parent, + QIODevice *socket) +{ + NetworkConnection *result = 0; + + switch (connection) { + case Lan: + result = new TcpConnection(parent, dynamic_cast(socket)); + break; + case Bluetooth: + result = new BluetoothConnection(parent, dynamic_cast(socket)); + break; + } + + return result; +} diff --git a/chicken-wranglers/src/network/connectionfactory.h b/chicken-wranglers/src/network/connectionfactory.h new file mode 100644 index 0000000..06333f0 --- /dev/null +++ b/chicken-wranglers/src/network/connectionfactory.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef CONNECTIONFACTORY_H +#define CONNECTIONFACTORY_H + +class QIODevice; +class QObject; +class NetworkConnection; + +class ConnectionFactory +{ +public: + enum ConnectionType { + Lan, + Bluetooth + }; + + static NetworkConnection *create(ConnectionType connection, QObject *parent = 0, + QIODevice *socket = 0); + +private: + ConnectionFactory(); +}; + +#endif diff --git a/chicken-wranglers/src/network/lanhandler.cpp b/chicken-wranglers/src/network/lanhandler.cpp new file mode 100644 index 0000000..ec1c12c --- /dev/null +++ b/chicken-wranglers/src/network/lanhandler.cpp @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + +#include "lanhandler.h" + +#include "connectionfactory.h" +#include "network.h" +#include "networkconnection.h" + +LanHandler::LanHandler(QObject *parent, int maxConnections) + : QTcpServer(parent), m_maxConnections(maxConnections) +{ + connect(this, SIGNAL(newConnection()), this, SLOT(newClientConnection())); +} +LanHandler::~LanHandler() +{ + closeAll(); + stop(); +} + +void LanHandler::newClientConnection() +{ + if (m_connections.size() == m_maxConnections) + return; + + NetworkConnection *connection; + connection = ConnectionFactory::create(ConnectionFactory::Lan, + this, nextPendingConnection()); + + for (quint16 id = 0; id < m_maxConnections; id++) { + // If the peer ID is NOT on the dictionary, insert it + if (!m_connections.contains(id)) { + connection->setId(id); + + connect(connection, SIGNAL(disconnected()), + this, SLOT(peerDisconnected())); + connect(connection, SIGNAL(error(QAbstractSocket::SocketError)), + this, SLOT(socketError(QAbstractSocket::SocketError))); + connect(connection, SIGNAL(received(NetworkMessage)), + this, SIGNAL(received(NetworkMessage))); + + m_connections[id] = connection; + + // Signals that a new peer has connected + emit peerConnected(connection); + + break; + } + } +} + +void LanHandler::closeAll() +{ + NetworkConnection *tmp; + int pos = 0; + while (m_connections.size()) { + tmp = m_connections[pos]; + tmp->close(); + delete tmp; + ++pos; + } + + m_connections.clear(); +} + +void LanHandler::send(const NetworkMessage &message) +{ + m_connections[message.id()]->send(message); +} + +void LanHandler::peerDisconnected() +{ + NetworkConnection *connection = qobject_cast(sender()); + m_connections.remove(connection->id()); + + // Signals that a peer has disconnected + emit peerDisconnected(connection); +} + +void LanHandler::socketError(QAbstractSocket::SocketError socketError) +{ + NetworkConnection *connection = qobject_cast(sender()); + quint16 id = connection->id(); + + qWarning("TCP Socket error [ %d ]: %s", socketError, + connection->errorString().toUtf8().constData()); + + emit peerError(socketError, id); +} + +void LanHandler::stop() +{ + if (isListening()) + close(); +} diff --git a/chicken-wranglers/src/network/lanhandler.h b/chicken-wranglers/src/network/lanhandler.h new file mode 100644 index 0000000..457b474 --- /dev/null +++ b/chicken-wranglers/src/network/lanhandler.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef LANHANDLER_H +#define LANHANDLER_H + +#include "networkmessage.h" + +#include +#include + +class NetworkConnection; + +class LanHandler : public QTcpServer +{ + Q_OBJECT + +public: + LanHandler(QObject *parent = 0, int maxConnections = 4); + ~LanHandler(); + + void stop(); + void send(const NetworkMessage &message); + void closeAll(); + +signals: + void peerConnected(NetworkConnection *connection); + void peerDisconnected(NetworkConnection *connection); + void peerError(QAbstractSocket::SocketError socketError, quint16 id); + void received(const NetworkMessage &message); + void startError(); + +private slots: + void newClientConnection(); + void peerDisconnected(); + void socketError(QAbstractSocket::SocketError socketError); + +private: + QHash m_connections; + int m_maxConnections; +}; + +#endif diff --git a/chicken-wranglers/src/network/network.h b/chicken-wranglers/src/network/network.h new file mode 100644 index 0000000..2b86ded --- /dev/null +++ b/chicken-wranglers/src/network/network.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef NETWORK_H +#define NETWORK_H + +#include +#include + +namespace CW +{ + enum UdpSenderType { + UdpSenderNoType = 0, + UdpSenderClient = 1, + UdpSenderServer = 2, + UdpSenderAny = UdpSenderClient | UdpSenderServer + }; + + enum UdpContentType { + UdpNoContent = 200, + UdpContentDiscovery, + UdpContentAckDiscovery, + }; + + static const char udpMessageSeparator = '/'; +} + +#endif diff --git a/chicken-wranglers/src/network/network.pri b/chicken-wranglers/src/network/network.pri new file mode 100644 index 0000000..81f9d36 --- /dev/null +++ b/chicken-wranglers/src/network/network.pri @@ -0,0 +1,37 @@ +QT += network + +maemo5 { + CONFIG += mobility12 +} else { + CONFIG += mobility +} +MOBILITY += connectivity + +PATH = $$PWD + +HEADERS += \ + $$PATH/network.h \ + $$PATH/networkclient.h \ + $$PATH/networkserver.h \ + $$PATH/udphandler.h \ + $$PATH/networkmessage.h \ + $$PATH/networkconnection.h \ + $$PATH/bluetoothconnection.h \ + $$PATH/tcpconnection.h \ + $$PATH/connectionfactory.h \ + $$PATH/lanhandler.h \ + $$PATH/bluetoothhandler.h \ + $$PATH/bthandler.h + +SOURCES += \ + $$PATH/networkclient.cpp \ + $$PATH/networkserver.cpp \ + $$PATH/udphandler.cpp \ + $$PATH/networkmessage.cpp \ + $$PATH/networkconnection.cpp \ + $$PATH/bluetoothconnection.cpp \ + $$PATH/tcpconnection.cpp \ + $$PATH/connectionfactory.cpp \ + $$PATH/lanhandler.cpp \ + $$PATH/bluetoothhandler.cpp \ + $$PATH/bthandler.cpp diff --git a/chicken-wranglers/src/network/networkclient.cpp b/chicken-wranglers/src/network/networkclient.cpp new file mode 100644 index 0000000..58dba98 --- /dev/null +++ b/chicken-wranglers/src/network/networkclient.cpp @@ -0,0 +1,196 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + +#include "networkclient.h" + +#include "bthandler.h" +#include "connectionfactory.h" +#include "network.h" +#include "networkconnection.h" +#include "udphandler.h" + +#include +#include + + +NetworkClient::NetworkClient(const QString &connectivity, int discoveryTimeout, + int clientAttempts, QObject *parent) + : QObject(parent), m_udpHandler(0), m_btHandler(0), m_connection(0), + m_discoveryTimer(0), m_discoveryAttempts(0), + m_discoveryTimeout(discoveryTimeout), m_discoveryClientAttempts(clientAttempts) +{ + if (connectivity == "lan") { + m_udpHandler = new UdpHandler(this); + m_udpHandler->setListenPort(m_lanUdpPort); + + connect(m_udpHandler, SIGNAL(received(QHostAddress, QByteArray, quint16, QByteArray)), + this, SLOT(processUdp(QHostAddress, QByteArray, quint16, QByteArray))); + + m_connection = ConnectionFactory::create(ConnectionFactory::Lan, this); + connect(m_connection, SIGNAL(error(QAbstractSocket::SocketError)), + this, SLOT(tcpSocketError(QAbstractSocket::SocketError))); + + } else if (connectivity == "bluetooth") { + m_btHandler = new BtHandler(this); + connect(m_btHandler, SIGNAL(discovered(const BluetoothDevice &)), + this, SIGNAL(bluetoothDeviceDiscovered(const BluetoothDevice &))); + + m_connection = ConnectionFactory::create(ConnectionFactory::Bluetooth, this); + connect(m_connection, SIGNAL(error(QBluetoothSocket::SocketError)), + this, SLOT(bluetoothSocketError(QBluetoothSocket::SocketError))); + } + + // Timer for broadcasting the message + m_discoveryTimer = new QTimer(this); + // TODO: rename this settings name to DiscoveryTimeout + m_discoveryTimer->setInterval(m_discoveryTimeout); + connect(m_discoveryTimer, SIGNAL(timeout()), + this, SLOT(sendDiscovery())); + + connect(m_connection, SIGNAL(connected()), + this, SIGNAL(connected())); + connect(m_connection, SIGNAL(disconnected()), + this, SIGNAL(disconnected())); + connect(m_connection, SIGNAL(received(const NetworkMessage &)), + this, SIGNAL(messageReceived(const NetworkMessage &))); +} + +void NetworkClient::setLanPorts(int udpPort, int tcpPort) +{ + m_lanUdpPort = udpPort; + m_lanTcpPort = tcpPort; +} + +void NetworkClient::send(const NetworkMessage &message) +{ + m_connection->send(message); +} + +void NetworkClient::startDiscovery() +{ + if (m_udpHandler) { + // FIXME: Do not enable UdpHandler if it's already enabled + m_udpHandler->setListenPort(m_lanUdpPort + 1); + m_udpHandler->enable(); + + m_discoveryAttempts = 0; + m_discoveryTimer->start(); + } else { + m_btHandler->enable(); + } +} + +void NetworkClient::stopDiscovery() +{ + if (m_udpHandler) + m_discoveryTimer->stop(); + + if (m_btHandler) + m_btHandler->disable(); +} + +void NetworkClient::connectToBluetoothServer(const QString &address) +{ + m_connection->connectToHost(address, 14); +} + +void NetworkClient::processUdp(QHostAddress senderAddress, QByteArray content, + quint16 senderListenPort, QByteArray timestamp) +{ + Q_UNUSED(timestamp) + + quint16 contentData = content.toUShort(); + + if (contentData == CW::UdpContentAckDiscovery) + processAckDiscovery(senderAddress, senderListenPort); +} + +void NetworkClient::processAckDiscovery(QHostAddress senderAddress, quint16 senderListenPort) +{ + Q_UNUSED(senderListenPort) + + stopDiscovery(); + + if (m_connection->state() == QAbstractSocket::UnconnectedState) { + // Estabilish a connection to the server + m_connection->connectToHost(senderAddress.toString(), m_lanTcpPort); + } else { + qWarning("TCP Connection already open"); + } +} + +void NetworkClient::sendDiscovery() +{ + if (m_discoveryAttempts < m_discoveryClientAttempts) { + m_discoveryAttempts++; + + if (m_udpHandler) { + m_udpHandler->sendDatagram(QHostAddress::Broadcast, m_lanUdpPort, + CW::UdpSenderClient, CW::UdpContentDiscovery, + m_udpHandler->listenPort()); + } else { + // TODO: Notify upper layers about discovered bt + } + } else { + stopDiscovery(); + + if (m_udpHandler) { + m_udpHandler->disable(); + } else { + // TODO: Bluetooth stuff + } + + emit serverDiscoveryTimeout(); + } +} + +void NetworkClient::tcpSocketError(QAbstractSocket::SocketError error) +{ + qWarning("TCP Socket error [ %d ]: %s", error, + m_connection->errorString().toUtf8().constData()); + + emit socketError(error); +} + +void NetworkClient::bluetoothSocketError(QBluetoothSocket::SocketError error) +{ + emit socketError(static_cast(error)); +} diff --git a/chicken-wranglers/src/network/networkclient.h b/chicken-wranglers/src/network/networkclient.h new file mode 100644 index 0000000..621fc2c --- /dev/null +++ b/chicken-wranglers/src/network/networkclient.h @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef NETWORKCLIENT_H +#define NETWORKCLIENT_H + +#include "bluetoothdevice.h" +#include "networkmessage.h" + +#include +#include +#include +#include +#include + +class BtHandler; +class NetworkConnection; +class QTimer; +class UdpHandler; + +QTM_USE_NAMESPACE + +class NetworkClient : public QObject +{ + Q_OBJECT + +public: + NetworkClient(const QString &connectivity = "lan", int discoveryTimeout = 0, + int clientAttempts = 0, QObject *parent = 0); + + void send(const NetworkMessage &message); + void setLanPorts(int udpPort, int tcpPort); + +public slots: + void startDiscovery(); + void stopDiscovery(); + void connectToBluetoothServer(const QString &address); + +signals: + void connected(); + void disconnected(); + void socketError(QAbstractSocket::SocketError socketError); + void messageReceived(const NetworkMessage &message); + void serverDiscoveryTimeout(); + void bluetoothDeviceDiscovered(const BluetoothDevice &device); + +private slots: + void processUdp(QHostAddress senderAddress, QByteArray content, + quint16 senderListenPort, QByteArray timestamp); + void sendDiscovery(); + void tcpSocketError(QAbstractSocket::SocketError error); + void bluetoothSocketError(QBluetoothSocket::SocketError error); + +private: + void processAckDiscovery(QHostAddress senderAddress, quint16 senderListenPort); + + UdpHandler *m_udpHandler; + BtHandler *m_btHandler; + NetworkConnection *m_connection; + QTimer *m_discoveryTimer; + quint16 m_discoveryAttempts; + int m_discoveryTimeout; + int m_lanUdpPort; + int m_lanTcpPort; + int m_discoveryClientAttempts; +}; + +#endif diff --git a/chicken-wranglers/src/network/networkconnection.cpp b/chicken-wranglers/src/network/networkconnection.cpp new file mode 100644 index 0000000..6bebe58 --- /dev/null +++ b/chicken-wranglers/src/network/networkconnection.cpp @@ -0,0 +1,144 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#include "networkconnection.h" + +#include + +NetworkConnection::NetworkConnection(QObject *parent) + : QObject(parent), m_id(0), m_message(NetworkMessage()) +{ +} + +NetworkConnection::~NetworkConnection() +{ +} + +void NetworkConnection::setId(const quint16 &newId) +{ + m_id = newId; +} + +quint16 NetworkConnection::id() const +{ + return m_id; +} + +void NetworkConnection::processRead(QIODevice *m_socket) +{ + QByteArray buffer(m_socket->readAll()); + int counter = buffer.length(); + + QDataStream dataStream(&buffer, QIODevice::ReadOnly); + dataStream.setVersion(QDataStream::Qt_4_7); + + while (counter) { + // Type + if (m_message.type() == CW::NoMessageType) { + if (counter < ((int) sizeof(quint16))) + return; + + // Read the Message Type + quint16 type; + dataStream >> type; + counter -= sizeof(quint16); + + m_message.setType((CW::MessageType) type); + } + + // Content + if (m_message.content() == 0) { + if (counter < ((int) sizeof(quint16))) + return; + + // Read the Message Content + quint16 content; + dataStream >> content; + counter -= sizeof(quint16); + + m_message.setContent(content); + } + + if (m_message.data().size() == 0) { + if (counter < ((int) sizeof(quint32))) + return; + + quint32 dataSize; + dataStream >> dataSize; + counter -= sizeof(quint32); + + if (dataSize == 0xFFFFFFFF) { + m_message.setId(m_id); + + emit received(m_message); + + m_message = NetworkMessage(); + + continue; + } else { + QByteArray data; + data.resize(dataSize); + m_message.setData(data); + } + } + + if (m_message.data().size() > 0) { + if (counter < m_message.data().size()) + return; + + int dataSize = m_message.data().size(); + char *charData = new char[dataSize + 1]; + + dataStream.readRawData(charData, dataSize); + counter -= dataSize; + charData[dataSize] = '\0'; + QByteArray data(charData); + delete charData; + + m_message.setData(data); + + emit received(m_message); + + m_message = NetworkMessage(); + } + } +} diff --git a/chicken-wranglers/src/network/networkconnection.h b/chicken-wranglers/src/network/networkconnection.h new file mode 100644 index 0000000..5167804 --- /dev/null +++ b/chicken-wranglers/src/network/networkconnection.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef NETWORKCONNECTION_H +#define NETWORKCONNECTION_H + +#include "networkmessage.h" + +#include +#include +#include + +class NetworkConnection : public QObject +{ + Q_OBJECT + +public: + NetworkConnection(QObject *parent = 0); + virtual ~NetworkConnection(); + + virtual void setId(const quint16 &newId); + virtual quint16 id() const; + + virtual void send(NetworkMessage message) = 0; + + virtual void connectToHost(const QString &address, const quint16 &port) = 0; + + virtual QAbstractSocket::SocketState state() const = 0; + + virtual QAbstractSocket::SocketError error() const = 0; + + virtual QString errorString() const = 0; + + virtual void close() = 0; + +signals: + void received(const NetworkMessage &message); + +protected: + void processRead(QIODevice *m_socket); + + quint16 m_id; + NetworkMessage m_message; +}; + +#endif diff --git a/chicken-wranglers/src/network/networkmessage.cpp b/chicken-wranglers/src/network/networkmessage.cpp new file mode 100644 index 0000000..55e31f9 --- /dev/null +++ b/chicken-wranglers/src/network/networkmessage.cpp @@ -0,0 +1,118 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#include + +#include "networkmessage.h" + +NetworkMessage::NetworkMessage() + : m_id(0), m_type(CW::NoMessageType), + m_content(0), m_data(QByteArray()) +{ +} + +NetworkMessage::NetworkMessage(CW::MessageType type, quint16 content) + : m_id(0), m_type(type), + m_content(content), m_data(QByteArray()) +{ +} + +void NetworkMessage::setId(const quint16 &newId) +{ + m_id = newId; +} + +quint16 NetworkMessage::id() const +{ + return m_id; +} + +void NetworkMessage::setType(const CW::MessageType &newType) +{ + m_type = newType; +} + +CW::MessageType NetworkMessage::type() const +{ + return m_type; +} + +void NetworkMessage::setContent(const quint16 &newContent) +{ + m_content = newContent; +} + +quint16 NetworkMessage::content() const +{ + return m_content; +} + +void NetworkMessage::setData(const QByteArray &newData) +{ + m_data = newData; +} + +QByteArray NetworkMessage::data() const +{ + return m_data; +} + +QByteArray NetworkMessage::byteArray() const +{ + quint16 field; + QByteArray byteArray; + + QDataStream stream(&byteArray, QIODevice::WriteOnly); + stream.setVersion(QDataStream::Qt_4_0); + + // Type + field = m_type; + stream << field; + + // Content + stream << m_content; + + // Data (optional) + stream << m_data; + + return byteArray; +} diff --git a/chicken-wranglers/src/network/networkmessage.h b/chicken-wranglers/src/network/networkmessage.h new file mode 100644 index 0000000..da650be --- /dev/null +++ b/chicken-wranglers/src/network/networkmessage.h @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef NETWORKMESSAGE_H +#define NETWORKMESSAGE_H + +#include + +namespace CW +{ + enum MessageType { + NoMessageType = 1000, + PlayerControlMessageType, + PlayerInfoMessageType, + CharacterMessageType, + MatchMessageType + }; + + enum PlayerControl { + PlayerControlStop = 2000, + PlayerControlUp, + PlayerControlDown, + PlayerControlLeft, + PlayerControlRight, + PlayerControlLaserUp, + PlayerControlLaserDown, + PlayerControlLaserLeft, + PlayerControlLaserRight + }; + + enum PlayerInfo { + PlayerInfoScore = 3000, + PlayerInfoLeader + }; + + enum Character { + CharacterSelected = 4000, + CharacterReleased, + CharacterAvailableList, + CharacterIsAvailable + }; + + enum Match { + MatchReady = 5000, + MatchFinished + }; +} + +class NetworkMessage +{ +public: + NetworkMessage(); + NetworkMessage(CW::MessageType type, quint16 content); + + void setId(const quint16 &newId); + quint16 id() const; + + void setType(const CW::MessageType &newType); + CW::MessageType type() const; + + void setContent(const quint16 &newContent); + quint16 content() const; + + void setData(const QByteArray &newData); + QByteArray data() const; + + QByteArray byteArray() const; + +private: + quint16 m_id; + CW::MessageType m_type; + quint16 m_content; + QByteArray m_data; +}; + +#endif diff --git a/chicken-wranglers/src/network/networkserver.cpp b/chicken-wranglers/src/network/networkserver.cpp new file mode 100644 index 0000000..8f13259 --- /dev/null +++ b/chicken-wranglers/src/network/networkserver.cpp @@ -0,0 +1,255 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#include "networkserver.h" + +#include "bluetoothhandler.h" +#include "lanhandler.h" +#include "network.h" +#include "udphandler.h" + +#include +#include + +NetworkServer::NetworkServer(const QString &connectivity, int discoveryTimeout, int hostAttempts, QObject *parent) + : QObject(parent), m_udpHandler(0), m_lanHandler(0) , m_blueHandler(0) + , m_discoveryAttempts(0), m_lookingForServers(true) + , m_discoveryTimeout(discoveryTimeout), m_discoveryHostAttempts(hostAttempts) + , m_serverBluetooth(true) +{ + createConnectionHandler(connectivity); +} + +void NetworkServer::createConnectionHandler(const QString &connectivity) +{ + if (connectivity == "lan") { + m_serverBluetooth = false; + if (m_udpHandler) + return; + + m_udpHandler = new UdpHandler(this); + m_udpHandler->setListenPort(m_lanUdpPort); + + connect(m_udpHandler, SIGNAL(received(QHostAddress, QByteArray, quint16, QByteArray)), + this, SLOT(processUdp(QHostAddress, QByteArray, quint16, QByteArray))); + + m_lanHandler = new LanHandler(this); + connect(m_lanHandler, SIGNAL(peerConnected(NetworkConnection *)), + this, SIGNAL(peerConnected(NetworkConnection *))); + connect(m_lanHandler, SIGNAL(peerDisconnected(NetworkConnection *)), + this, SIGNAL(peerDisconnected(NetworkConnection *))); + connect(m_lanHandler, SIGNAL(peerError(QAbstractSocket::SocketError, quint16)), + this, SIGNAL(peerError(QAbstractSocket::SocketError, quint16))); + connect(m_lanHandler, SIGNAL(received(NetworkMessage)), + this, SIGNAL(messageReceived(NetworkMessage))); + + m_discoveryTimer = new QTimer(this); + m_discoveryTimer->setInterval(m_discoveryTimeout); + connect(m_discoveryTimer, SIGNAL(timeout()), + this, SLOT(sendDiscovery())); + + } else if (connectivity == "bluetooth") { + m_serverBluetooth = true; + if (m_blueHandler) + return; + + m_blueHandler = new BluetoothHandler(this); + + connect(m_blueHandler, SIGNAL(started()), + this, SIGNAL(started())); + connect(m_blueHandler, SIGNAL(peerConnected(NetworkConnection *)), + this, SIGNAL(peerConnected(NetworkConnection *))); + connect(m_blueHandler, SIGNAL(peerDisconnected(NetworkConnection *)), + this, SIGNAL(peerDisconnected(NetworkConnection *))); + connect(m_blueHandler, SIGNAL(peerError(QAbstractSocket::SocketError, quint16)), + this, SIGNAL(peerError(QAbstractSocket::SocketError, quint16))); + connect(m_blueHandler, SIGNAL(received(NetworkMessage)), + this, SIGNAL(messageReceived(NetworkMessage))); + connect(m_blueHandler, SIGNAL(startError()), this, SLOT(startError())); + } +} + +NetworkServer::~NetworkServer() +{ +} + +void NetworkServer::send(const NetworkMessage &message) +{ + if (m_lanHandler) + m_lanHandler->send(message); + else if (m_blueHandler) + m_blueHandler->send(message); +} + +void NetworkServer::setLanPorts(int udpPort, int tcpPort) +{ + m_lanUdpPort = udpPort; + m_lanTcpPort = tcpPort; +} + +void NetworkServer::start() +{ + if (!m_serverBluetooth && m_lanHandler) { + m_udpHandler->setListenSenderType(CW::UdpSenderAny); + m_udpHandler->setListenPort(m_lanUdpPort + 1); + m_udpHandler->enable(); + // Server tries to find if there are other + // running servers in the same network + startDiscovery(); + } else if ((m_serverBluetooth == true) && m_blueHandler) { + m_blueHandler->start(); + } +} + +void NetworkServer::stop() +{ + if (!m_serverBluetooth && m_lanHandler) { + stopDiscovery(); + + if (m_lanHandler->isListening()) + m_lanHandler->close(); + + m_udpHandler->setListenSenderType(CW::UdpSenderNoType); + m_udpHandler->disable(); + } else if ((m_serverBluetooth == true) && m_blueHandler) { + m_blueHandler->stop(); + } +} + +void NetworkServer::closeAll() +{ + if (!m_serverBluetooth && m_lanHandler) { + stopDiscovery(); + + if (m_lanHandler->isListening()) + m_lanHandler->closeAll(); + + m_udpHandler->setListenSenderType(CW::UdpSenderNoType); + m_udpHandler->disable(); + } else if ((m_serverBluetooth == true) && m_blueHandler) { + m_blueHandler->closeAll(); + } + +} + + +void NetworkServer::startDiscovery() +{ + m_lookingForServers = true; + m_discoveryAttempts = 0; + m_discoveryTimer->start(); +} + +void NetworkServer::stopDiscovery() +{ + m_lookingForServers = false; + m_discoveryTimer->stop(); +} + +void NetworkServer::processUdp(QHostAddress senderAddress, QByteArray content, + quint16 senderListenPort, QByteArray timestamp) +{ + Q_UNUSED(timestamp) + + quint16 contentData = content.toUShort(); + + if (contentData == CW::UdpContentDiscovery) + processDiscovery(senderAddress, senderListenPort); + else if (contentData == CW::UdpContentAckDiscovery) + processAckDiscovery(senderAddress, senderListenPort); +} + +void NetworkServer::processDiscovery(QHostAddress senderAddress, quint16 senderListenPort) +{ + // While looking for other active servers, do not respond + // to Discovery messages. + if (m_lookingForServers) + return; + + // Received: "Discovery" --> Send: "AckDiscovery" + m_udpHandler->sendDatagram(senderAddress, senderListenPort, CW::UdpSenderServer, + CW::UdpContentAckDiscovery, m_udpHandler->listenPort()); +} + +void NetworkServer::processAckDiscovery(QHostAddress senderAddress, quint16 senderListenPort) +{ + Q_UNUSED(senderAddress) + Q_UNUSED(senderListenPort) + + stop(); + + emit error(AnotherServerRunningError); +} + +void NetworkServer::sendDiscovery() +{ + if (m_discoveryAttempts == m_discoveryHostAttempts) { + stopDiscovery(); + + m_udpHandler->disable(); + m_udpHandler->setListenSenderType(CW::UdpSenderAny); + m_udpHandler->setListenPort(m_lanUdpPort); + m_udpHandler->enable(); + + if (!m_lanHandler->isListening()) { + if (!m_lanHandler->listen(QHostAddress::Any, m_lanTcpPort)) { + startError(); + } + } + // TODO: Return the server to the stopped state in case of port binding error. + if (m_udpHandler->listenPort() != m_lanUdpPort) + qWarning("UDP Socket error: Unable to bind to port %d", m_lanUdpPort); + + started(); + return; + } + + m_discoveryAttempts++; + m_udpHandler->sendDatagram(QHostAddress::Broadcast, m_lanUdpPort, + CW::UdpSenderServer, CW::UdpContentDiscovery, + m_udpHandler->listenPort()); +} + +void NetworkServer::startError() +{ + emit error(AnotherServerRunningError); +} diff --git a/chicken-wranglers/src/network/networkserver.h b/chicken-wranglers/src/network/networkserver.h new file mode 100644 index 0000000..637a38f --- /dev/null +++ b/chicken-wranglers/src/network/networkserver.h @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef NETWORKSERVER_H +#define NETWORKSERVER_H + +#include "networkmessage.h" + +#include +#include +#include +#include + +class BluetoothHandler; +class LanHandler; +class NetworkConnection; +class QTimer; +class UdpHandler; + +class NetworkServer : public QObject +{ + Q_OBJECT + + Q_ENUMS(ServerError) + +public: + NetworkServer(const QString &connectivity = "lan", int hostAttempts = 0, int discoveryTimeout = 0, QObject *parent = 0); + ~NetworkServer(); + + void send(const NetworkMessage &message); + void setLanPorts(int udpPort, int tcpPort); + + enum ServerError { + AnotherServerRunningError, + UnknownError + }; + + void createConnectionHandler(const QString &connectivity); + + void closeAll(); + +public slots: + void start(); + void stop(); + +signals: + void peerConnected(NetworkConnection *connection); + void peerDisconnected(NetworkConnection *connection); + void peerError(QAbstractSocket::SocketError socketError, quint16 id); + void messageReceived(const NetworkMessage &message); + void error(NetworkServer::ServerError error); + void started(); + +private slots: + void processUdp(QHostAddress senderAddress, QByteArray content, + quint16 senderListenPort, QByteArray timestamp); + void sendDiscovery(); + + void startError(); + +private: + void startDiscovery(); + void stopDiscovery(); + void processDiscovery(QHostAddress senderAddress, quint16 senderListenPort); + void processAckDiscovery(QHostAddress senderAddress, quint16 senderListenPort); + + UdpHandler *m_udpHandler; + LanHandler *m_lanHandler; + BluetoothHandler *m_blueHandler; + QTimer *m_discoveryTimer; + quint16 m_discoveryAttempts; + bool m_lookingForServers; + int m_discoveryTimeout; + int m_lanUdpPort; + int m_lanTcpPort; + int m_discoveryHostAttempts; + bool m_serverBluetooth; + +}; + +#endif diff --git a/chicken-wranglers/src/network/tcpconnection.cpp b/chicken-wranglers/src/network/tcpconnection.cpp new file mode 100644 index 0000000..502962e --- /dev/null +++ b/chicken-wranglers/src/network/tcpconnection.cpp @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#include +#include + +#include "tcpconnection.h" + +TcpConnection::TcpConnection(QObject *parent, QTcpSocket *socket) + : NetworkConnection(parent), m_socket(socket) +{ + if (m_socket == 0) + m_socket = new QTcpSocket(this); + + connect(m_socket, SIGNAL(connected()), + this, SIGNAL(connected())); + connect(m_socket, SIGNAL(disconnected()), + this, SIGNAL(disconnected())); + connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)), + this, SIGNAL(error(QAbstractSocket::SocketError))); + connect(m_socket, SIGNAL(readyRead()), + this, SLOT(processReadyRead())); +} + +TcpConnection::~TcpConnection() +{ + if (m_socket) + m_socket->close(); +} + +void TcpConnection::setId(const quint16 &newId) +{ + m_id = newId; +} + +quint16 TcpConnection::id() const +{ + return m_id; +} + +void TcpConnection::send(NetworkMessage message) +{ + if (m_socket->write(message.byteArray()) == -1) + qWarning("TCP Socket write error: %s", m_socket->errorString().toUtf8().constData()); +} + +void TcpConnection::connectToHost(const QString &address, const quint16 &port) +{ + m_socket->connectToHost(QHostAddress(address), port); +} + +QAbstractSocket::SocketState TcpConnection::state() const +{ + return m_socket->state(); +} + +QAbstractSocket::SocketError TcpConnection::error() const +{ + return m_socket->error(); +} + +QString TcpConnection::errorString() const +{ + return m_socket->errorString(); +} + +void TcpConnection::processReadyRead() +{ + processRead(m_socket); +} + +void TcpConnection::close() +{ + m_socket.data()->close(); +} diff --git a/chicken-wranglers/src/network/tcpconnection.h b/chicken-wranglers/src/network/tcpconnection.h new file mode 100644 index 0000000..464d276 --- /dev/null +++ b/chicken-wranglers/src/network/tcpconnection.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef TCPCONNECTION_H +#define TCPCONNECTION_H + +#include "networkconnection.h" + +#include +#include +#include + +class TcpConnection : public NetworkConnection +{ + Q_OBJECT + +public: + TcpConnection(QObject *parent = 0, QTcpSocket *socket = 0); + ~TcpConnection(); + + void setId(const quint16 &newId); + quint16 id() const; + + void send(NetworkMessage message); + + void connectToHost(const QString &address, const quint16 &port); + + QAbstractSocket::SocketState state() const; + + QAbstractSocket::SocketError error() const; + + QString errorString() const; + + void close(); + +signals: + void connected(); + void disconnected(); + void error(QAbstractSocket::SocketError socketError); + +private slots: + void processReadyRead(); + +private: + QPointer m_socket; +}; + +#endif diff --git a/chicken-wranglers/src/network/udphandler.cpp b/chicken-wranglers/src/network/udphandler.cpp new file mode 100644 index 0000000..2aa2635 --- /dev/null +++ b/chicken-wranglers/src/network/udphandler.cpp @@ -0,0 +1,169 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#include +#include + +#include "network.h" +#include "settings.h" + +#include "udphandler.h" + +UdpHandler::UdpHandler(QObject *parent) + : QObject(parent), m_listenSenderType(CW::UdpSenderServer), m_listenPort(0) +{ + m_socket = new QUdpSocket(this); + + connect(m_socket, SIGNAL(readyRead()), this, SLOT(processIncomingDatagrams())); +} + +UdpHandler::~UdpHandler() +{ + disable(); +} + +void UdpHandler::enable() +{ + for (quint16 i = 0; i < 100; i++) { + m_listenPort += i; + + if (m_socket->bind(QHostAddress::Any, m_listenPort, + QUdpSocket::DontShareAddress)) { + qWarning("UDP Socket bound to port %d", m_listenPort); + + break; + } + } +} + +void UdpHandler::disable() +{ + m_socket->close(); +} + +void UdpHandler::setListenSenderType(const CW::UdpSenderType &type) +{ + m_listenSenderType = type; +} + +CW::UdpSenderType UdpHandler::listenSenderType() const +{ + return m_listenSenderType; +} + +void UdpHandler::setListenPort(const quint16 &port) +{ + if (m_listenPort != port) + m_listenPort = port; +} + +quint16 UdpHandler::listenPort() const +{ + return m_listenPort; +} + +void UdpHandler::processIncomingDatagrams() +{ + QByteArray datagram; + QHostAddress senderAddress; + quint16 senderPort; + + while (m_socket->hasPendingDatagrams()) { + datagram.resize(m_socket->pendingDatagramSize()); + + if (m_socket->readDatagram(datagram.data(), datagram.size(), + &senderAddress, &senderPort) == -1) { + qWarning("UDP Error: Unable to read datagram."); + } else { + parseDatagram(senderAddress, senderPort, datagram); + } + + datagram.clear(); + } +} + +void UdpHandler::parseDatagram(QHostAddress address, quint16 port, QByteArray datagram) +{ + QList fields = datagram.split(CW::udpMessageSeparator); + QTime time = QTime::currentTime(); + + // Message size correct (=4) + if (fields.size() == 4) { + // Message type received (='type specified') + if (fields.at(0).toUShort() & m_listenSenderType) { + qWarning("UDP Received:\t\"%s\"", datagram.constData()); + + emit received(address, fields.at(1), port, fields.at(2)); + } else { + qWarning("UDP Invalid sender type:\"%s\"", datagram.constData()); + } + } else { + qWarning("UDP Invalid message size:\"%s\"", datagram.constData()); + } +} + +void UdpHandler::sendDatagram(QHostAddress address, quint16 port, CW::UdpSenderType senderType, + CW::UdpContentType content, quint16 senderListenPort) +{ + QTime time; + QByteArray datagram; + + // Message format: + // "client/content/senderListenPort/11:22:33.444" + + // Timestamp + time = QTime::currentTime(); + + // Message type: Client or Server + datagram = QByteArray::number(senderType); + + // Message content: content + datagram += CW::udpMessageSeparator + QByteArray::number((quint16) content); + + // Message content: sender listen port + datagram += CW::udpMessageSeparator + QByteArray::number((quint16) senderListenPort); + + // Message timestamp: hours:minutes:seconds.miliseconds + datagram += CW::udpMessageSeparator + time.toString("hh:mm:ss.zzz").toUtf8(); + + m_socket->writeDatagram(datagram.data(), datagram.size(), address, port); +} diff --git a/chicken-wranglers/src/network/udphandler.h b/chicken-wranglers/src/network/udphandler.h new file mode 100644 index 0000000..6c26965 --- /dev/null +++ b/chicken-wranglers/src/network/udphandler.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef UDPHANDLER_H +#define UDPHANDLER_H + +#include "network.h" + +#include +#include +#include +#include + +class QUdpSocket; + +class UdpHandler : public QObject +{ + Q_OBJECT + +public: + UdpHandler(QObject *parent = 0); + ~UdpHandler(); + + void enable(); + void disable(); + + void setListenSenderType(const CW::UdpSenderType &type); + CW::UdpSenderType listenSenderType() const; + + void setListenPort(const quint16 &port); + quint16 listenPort() const; + + void sendDatagram(QHostAddress toAddress, quint16 toPort, CW::UdpSenderType senderType, + CW::UdpContentType content, quint16 senderListenPort); + +signals: + void received(QHostAddress senderAddress, QByteArray content, + quint16 senderListenPort, QByteArray timestamp); + +private slots: + void processIncomingDatagrams(); + +private: + void parseDatagram(QHostAddress address, quint16 port, QByteArray datagram); + + QUdpSocket *m_socket; + CW::UdpSenderType m_listenSenderType; + quint16 m_listenPort; +}; + +#endif diff --git a/chicken-wranglers/src/qml/Being.qml b/chicken-wranglers/src/qml/Being.qml new file mode 100644 index 0000000..984ee9b --- /dev/null +++ b/chicken-wranglers/src/qml/Being.qml @@ -0,0 +1,150 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +import "match.js" as MatchLogic +import game.types 1.0 + +Image { + id: being + + property string path: "" + property int currentRow: 0 + property int currentColumn: 0 + property int walkingStep: 1 + property string orientation: "side_" + property string movement: "stopped_" + + // Default values + property int moveInterval: 500 + property int changeStepsInterval: 260 + + scale: matchScreen.displayScale + smooth: true + + source: { + if (path == "") + return "" + + path + "/" + orientation + movement + walkingStep + ".png" + } + + state: "stopped" + + Timer { + id: changeSteps; + interval: changeStepsInterval + running: (opacity == 1) && (matchController.status != Match.Paused) + repeat: true + onTriggered: { + if (walkingStep == 1) + walkingStep = 2 + else + walkingStep = 1 + } + } + + states { + State { + name: "Up" + PropertyChanges { + target: being + orientation: "back_" + movement: "walking_" + } + } + + State { + name: "Down" + PropertyChanges { + target: being + orientation: "front_" + movement: "walking_" + } + } + + State { + name: "Left" + PropertyChanges { + target: being + orientation: "side_" + movement: "walking_" + } + } + + State { + name: "Right" + PropertyChanges { + target: being + orientation: "side_" + movement: "walking_" + } + PropertyChanges { + target: rotation + angle: 180 + } + } + + State { + name: "Stop" + PropertyChanges { + target: being + movement: "stopped_" + orientation: orientation + } + PropertyChanges { + target: rotation + angle: angle + } + } + } + + transform { + Rotation { + id: rotation + origin.x: being.width/2; origin.y: being.height/2 + axis.x: 0; axis.y: 1; axis.z: 0 + angle: 0 + } + } +} diff --git a/chicken-wranglers/src/qml/Character.qml b/chicken-wranglers/src/qml/Character.qml new file mode 100644 index 0000000..46ab988 --- /dev/null +++ b/chicken-wranglers/src/qml/Character.qml @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +import "match.js" as MatchLogic +import game.types 1.0 + +Being { + id: character + + property int playerNumber: 0 + property PlayerModel model + property PlayerController controller + + path: { + if (model) + return model.characterPath + else + return "" + } + + moveInterval: MatchLogic.characterMoveInterval + changeStepsInterval: MatchLogic.characterChangeStepsInterval + + function onLaserToggleRequested(laserDirection) { + var column = Math.round((x - matchScreen.fieldStartX - (matchScreen.cellSize - width) / 2) / matchScreen.cellSize) + var row = Math.round((y - matchScreen.fieldStartY - (matchScreen.cellSize - height) / 2) / matchScreen.cellSize) + matchController.toggleLaser(column, row, laserDirection) + } + + x: matchScreen.fieldStartX + (currentColumn * matchScreen.cellSize) + (matchScreen.cellSize - width) / 2 + y: matchScreen.fieldStartY + (currentRow * matchScreen.cellSize) + (matchScreen.cellSize - height) / 2 + + Behavior on x { + NumberAnimation { + duration: moveInterval; + easing.type: Easing.Linear + } + } + + Behavior on y { + NumberAnimation { + duration: moveInterval; + easing.type: Easing.Linear + } + } + + Behavior on opacity { + NumberAnimation { duration: 200 } + } + + currentRow: { + if (controller) + return controller.position.y + else + return 4 + } + + currentColumn: { + if (controller) + return controller.position.x + else + return 4 + } + + opacity: 0 + + Timer { + id: moveTimer + + triggeredOnStart: true + interval: moveInterval; + running: model != null && matchController.status != Match.Paused + repeat: true + onTriggered: { + state = model.direction + if (controller) + controller.move() + } + } +} diff --git a/chicken-wranglers/src/qml/CharacterSelectionView.qml b/chicken-wranglers/src/qml/CharacterSelectionView.qml new file mode 100644 index 0000000..e28b6f9 --- /dev/null +++ b/chicken-wranglers/src/qml/CharacterSelectionView.qml @@ -0,0 +1,235 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +import game.types 1.0 +import "common.js" as Common +import "widgets" + +Screen { + id: screen + + signal back + signal characterSelected(int index) + + Image { + id: background + + anchors.fill: parent + source: { + if (game.environment() == Global.Symbian) + "qrc:/images/general/symbian/bg_selectcharacter.png" + else + "qrc:/images/general/bg_selectcharacter.png" + } + } + + Component { + id: characterDelegate + + Item { + width: 191 + height: 220 + + scale: PathView.iconScale + + Image { + id: characterIcon + + y: 0 + anchors.fill: parent + anchors.horizontalCenter: parent.horizontalCenter + smooth: true + source: { + if (isAvailable) + Common.getImagePath(path, "select_character.png") + else + Common.getImagePath(path, "unavailable.png") + } + } + + MouseArea { + anchors.fill: parent + onClicked: { + view.currentIndex = index + } + } + } + } + + Item { + id: characterHighlight + + anchors { + horizontalCenter: parent.horizontalCenter + top: parent.top + bottom: view.bottom + } + + Image { + id: name + + anchors { + horizontalCenter: parent.horizontalCenter + top: parent.top + topMargin: 60 + } + + smooth: true + source: Common.getImagePath(characterListModel.get(view.currentIndex).path, "name.png") + + // XXX: When changing source property, the sourceSize.width + // is not updating accordingly. So we are forcing a hardcoded + // value for now. + onSourceChanged: sourceSize.width = 200 + + Behavior on opacity { + NumberAnimation { duration: 100 } + } + } + + ImageButton { + source: "qrc:/images/general/bt_previous.png" + + anchors.right: parent.horizontalCenter + anchors.rightMargin: 80 + anchors.verticalCenter: name.verticalCenter + + onClicked: view.decrementCurrentIndex() + } + + ImageButton { + source: "qrc:/images/general/bt_next.png" + + anchors.left: parent.horizontalCenter + anchors.leftMargin: 80 + anchors.verticalCenter: name.verticalCenter + + onClicked: view.incrementCurrentIndex() + } + } + + PathView { + id: view + + anchors { + right: parent.right + left: parent.left + verticalCenter: parent.verticalCenter + verticalCenterOffset: 20 + } + + height: 220 + model: characterListModel + delegate: characterDelegate + preferredHighlightBegin: 0.5 + preferredHighlightEnd: 0.5 + pathItemCount: 5 + highlightMoveDuration: 200 + dragMargin: 500 + + onCurrentIndexChanged: { + name.source = Common.getImagePath(characterListModel.get(currentIndex).path, "name.png") + } + + onMovementStarted: { + name.opacity = 0 + } + + onMovementEnded: { + name.source = Common.getImagePath(characterListModel.get(currentIndex).path, "name.png") + name.opacity = 1 + } + + path: Path { + startX: -40 + startY: 100 + + PathAttribute { name: "iconScale"; value: 0.3 } + + PathLine { + x: screen.width * 0.5 + y: 100 + } + + PathAttribute { name: "iconScale"; value: 1.0 } + + // 4 + PathLine { + x: screen.width + 40 + y: 100 + } + + PathAttribute { name: "iconScale"; value: 0.3 } + } + } + + Button { + id: buttonJoin + + text: "Join" + width: 200 + enabled: characterListModel.get(view.currentIndex).isAvailable + + anchors { + horizontalCenter: parent.horizontalCenter + bottom: parent.bottom + margins: 20 + } + + onClicked: characterSelected(view.currentIndex) + } + + ImageButton { + id: buttonBack + + anchors { + top: parent.top + right: parent.right + margins: 15 + } + + name: "back" + onClicked: back(); + } +} diff --git a/chicken-wranglers/src/qml/Chicken.qml b/chicken-wranglers/src/qml/Chicken.qml new file mode 100644 index 0000000..a09e9c1 --- /dev/null +++ b/chicken-wranglers/src/qml/Chicken.qml @@ -0,0 +1,159 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 +import "match.js" as MatchLogic +import game.types 1.0 + +Being { + id: chicken + + property ChickenController controller + + path: "qrc:/images/chicken" + + function kill() { + chicken.opacity = 0 + } + + function onPositionChanged() { + currentRow = controller.position.y + currentColumn = controller.position.x + + var newX = matchScreen.fieldStartX + (currentColumn * matchScreen.cellSize) + (matchScreen.cellSize - width) / 2 + var newY = matchScreen.fieldStartY + (currentRow * matchScreen.cellSize) + (matchScreen.cellSize - height) / 2 + + moveInterval = chickenMoveInterval + + if (x != newX && !xAnimation.running) { + xAnimation.to = newX + xAnimation.start() + } + + if (y != newY && !yAnimation.running) { + yAnimation.to = newY + yAnimation.start() + } + } + + function move() { + controller.move() + chicken.state = controller.direction + } + + opacity: 1 + + currentRow: MatchLogic.defaultRows / 2 + currentColumn: MatchLogic.defaultColumns / 2 + + PropertyAnimation { + id: xAnimation + + target: chicken + property: "x" + duration: moveInterval + alwaysRunToEnd: true + + onRunningChanged: { + if (!running) + chicken.move() + } + } + + PropertyAnimation { + id: yAnimation + + target: chicken + property: "y" + duration: moveInterval + alwaysRunToEnd: true + + onRunningChanged: { + if (!running) + chicken.move() + } + } + + property int chickenMoveInterval + + chickenMoveInterval: { + if (!controller) + return MatchLogic.chickenMoveIntervalNormal + + if (controller.isSafe) + return MatchLogic.chickenMoveIntervalNormal + else + return MatchLogic.chickenMoveIntervalRunning + } + + changeStepsInterval: MatchLogic.chickenChangeStepsIntervalNormal + moveInterval: MatchLogic.chickenMoveIntervalNormal + + onOpacityChanged: { + if (opacity == 0) + chicken.destroy() + } + + Behavior on opacity { + NumberAnimation { duration: 500 } + } + + Timer { + id: move; + interval: chickenMoveInterval + running: state == "Stop" && matchController.status != Match.Paused + repeat: true + onTriggered: { + chicken.move() + + if (currentRow < 0 || currentColumn < 0 + || currentRow >= MatchLogic.defaultRows + || currentColumn >= MatchLogic.defaultColumns) { + chicken.kill() + } + } + } + + Component.onCompleted: { + chicken.state = "Stop" + } +} diff --git a/chicken-wranglers/src/qml/ClientView.qml b/chicken-wranglers/src/qml/ClientView.qml new file mode 100644 index 0000000..0bb06af --- /dev/null +++ b/chicken-wranglers/src/qml/ClientView.qml @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 +import game.types 1.0 + +import "widgets" +import "common.js" as Common + +Screen { + id: clientView + + focus: true + + function showControlView() { + var character = characterListModel.get(characterListModel.selectedIndex) + + playerControlView.characterPath = character.path + Common.switchScreens(playerReadyView, playerControlView) + playerControlView.focus = true + } + + function showPlayerReadyView() { + Common.switchScreens(playerControlView, playerReadyView) + } + + + CharacterSelectionView { + id: characterSelectionView + + anchors.fill: parent + + onBack: { + closeRequested() + focus = false + } + + onCharacterSelected: { + characterListModel.selectedIndex = index + var character = characterListModel.get(index) + + if (character.isAvailable) { + playerReadyView.characterPath = character.path + Common.switchScreens(characterSelectionView, playerReadyView) + } else { + console.log("Character is not available."); + } + } + } + + PlayerReadyView { + id: playerReadyView + + anchors.fill: parent + onBack: { + characterListModel.selectedIndex = -1 + Common.switchScreens(playerReadyView, characterSelectionView) + focus = false + } + } + + PlayerControlView { + id: playerControlView + + anchors.fill: parent + onBack: { + characterListModel.selectedIndex = -1 + Common.switchScreens(playerControlView, characterSelectionView) + focus = false + } + } + + onTransitionFinished: { + if (!visible) + closeFinished() + } + + Component.onCompleted: { + characterSelectionView.show() + characterSelectionView.focus = true + } +} diff --git a/chicken-wranglers/src/qml/HenCoop.qml b/chicken-wranglers/src/qml/HenCoop.qml new file mode 100644 index 0000000..ad5db74 --- /dev/null +++ b/chicken-wranglers/src/qml/HenCoop.qml @@ -0,0 +1,149 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 +import game.types 1.0 + +Item { + id: henCoop + + property int playerNumber: 1 + property PlayerModel player: playerListModel.get(playerNumber - 1) + property string side: getSide() + + scale: matchScreen.displayScale + + function getSide () { + if ((playerNumber % 2) == 0) + return "right" + + return "left" + } + + opacity: { + if (henCoop.player == null || henCoop.player.characterPath == "") + return 0 + return 1 + } + + Image { + id: plate + source: { + if (henCoop.player == null || henCoop.player.characterPath == "") + return "" + "qrc:/images/battlefield/hencoop_plate.png" + } + + smooth: true + anchors { + top: parent.top + left: { + if (henCoop.side == "left") + return parent.left + else + return undefined + } + right: { + if (henCoop.side == "right") + return parent.right + else + return undefined + } + } + } + + Image { + id: house + + smooth: true + source: { + if (henCoop.player == null || henCoop.player.characterPath == "") + return "" + return henCoop.player.characterPath + "/hencoop.png" + } + + anchors { + top: parent.top + left: { + if (henCoop.side == "left") + return parent.left + else + return undefined + } + right: { + if (henCoop.side == "right") + return parent.right + else + return undefined + } + leftMargin: 12 + } + + Text { + id: score + + text: { + if (player != null) + return player.score + else + return "0" + } + + color: "white" + style: Text.Outline + styleColor: "black" + smooth: true + + font { + family: "Nokia Sans" + pointSize: 30 + bold: true + } + + anchors { + horizontalCenter: parent.horizontalCenter + top: parent.top + topMargin: 20 + } + } + } +} diff --git a/chicken-wranglers/src/qml/HostView.qml b/chicken-wranglers/src/qml/HostView.qml new file mode 100644 index 0000000..fd37ab2 --- /dev/null +++ b/chicken-wranglers/src/qml/HostView.qml @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +import "widgets" +import "common.js" as Common + +Screen { + id: hostView + + anchors.fill: parent + focus: true + + WaitingRoomView { + id: waitingRoomView + + anchors.fill: parent + + onBack: closeRequested() + + onMatchStarted: { + matchViewLoader.source = "MatchView.qml" + } + } + + Loader { + id: matchViewLoader + + signal closeRequested + signal closeFinished + + anchors.fill: parent + + onLoaded: { + Common.switchScreens(waitingRoomView, matchViewLoader.item) + focus = true + } + + onCloseRequested: Common.switchScreens(matchViewLoader.item, waitingRoomView) + onCloseFinished: { + matchViewLoader.source = "" + } + } + + onTransitionFinished: { + if (!visible) + closeFinished() + } + + Component.onCompleted: { + waitingRoomView.show() + waitingRoomView.focus = true + } +} diff --git a/chicken-wranglers/src/qml/Laser.qml b/chicken-wranglers/src/qml/Laser.qml new file mode 100644 index 0000000..2444d0f --- /dev/null +++ b/chicken-wranglers/src/qml/Laser.qml @@ -0,0 +1,147 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +import game.types 1.0 + +Image { + id: laser + + property int step: 1 + property int maxSteps: 5 + property string orientation: "" + property bool turnedOn: false + + property string path: "qrc:/images/laser/laser_" + orientation + "_" + step + ".png" + source: "" + + onSourceChanged: { + // FIXME: Laser image's width and height should not + // be hardcoded. We are forcing this due to a bug in + // Image element after we change source property. + if (orientation == "vertical") { + laser.width = 27 * matchScreen.displayScale + laser.height = 83 * matchScreen.displayScale + } else { + laser.width = 83 * matchScreen.displayScale + laser.height = 27 * matchScreen.displayScale + } + } + + function turnOn(cellX, cellY, cellSize, direction) { + if (direction == Global.LaserLeft || direction == Global.LaserRight) + orientation = "vertical" + else + orientation = "horizontal" + + // FIXME: Same as above. + var diffWidth = ((83 * matchScreen.displayScale) - cellSize) / 2 + var diffHeight = (27 * matchScreen.displayScale) / 2 + + if (direction == Global.LaserUp) { + laser.x = cellX - diffWidth + laser.y = cellY - diffHeight + } else if (direction == Global.LaserDown) { + laser.x = cellX - diffWidth + laser.y = cellY + cellSize - diffHeight + } else if (direction == Global.LaserRight) { + laser.x = cellX + cellSize - diffHeight + laser.y = cellY - diffWidth + } else if (direction == Global.LaserLeft) { + laser.x = cellX - diffHeight + laser.y = cellY - diffWidth + } + + step = 0 + laserOnTimer.start() + } + + function turnOff(cell, direction) { + step = 4 + laserOffTimer.start(); + } + + Timer { + id: laserOnTimer + + repeat: true + interval: 50 + + onTriggered: { + if (step == maxSteps - 1) { + running = false + turnedOn = true + return + } + + step = step + 1 + laser.source = path + } + } + + Timer { + id: laserOffTimer + + repeat: true + interval: 50 + + onTriggered: { + + // FIXME: Check if laser wasn't turned on before + // destroying the previous one + if (step === 0) { + running = false + turnedOn = false + laser.destroy() + return + } + + step = step - 1 + + if (step == 0) + laser.source = "" + else + laser.source = path + } + } +} diff --git a/chicken-wranglers/src/qml/MatchView.qml b/chicken-wranglers/src/qml/MatchView.qml new file mode 100644 index 0000000..9f26cb1 --- /dev/null +++ b/chicken-wranglers/src/qml/MatchView.qml @@ -0,0 +1,345 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +import game.types 1.0 +import "common.js" as Common +import "match.js" as MatchLogic +import "widgets" + +Screen { + id: matchScreen + + anchors.fill: parent + color: "black" + smooth: true + focus: true + + property real displayScale: MatchLogic.getDisplayScale() + property real cellSize: MatchLogic.defaultCellSize * displayScale + property real fieldStartX: (MatchLogic.defaultFieldStartX * displayScale) + MatchLogic.deltaX + property real fieldStartY: (MatchLogic.defaultFieldStartY * displayScale) + MatchLogic.deltaY + + function showQuitDialog() { + quitDialog.show() + } + + function closeQuitDialog() { + quitDialog.hide() + } + + function showScore() { + score.show() + } + + function hideScore() { + score.hide() + } + + Image { + id: fieldBg + source: { + if (game.environment() == Global.Symbian) + "qrc:/images/battlefield/bg_fence_stones_mobile.png" + else + "qrc:/images/battlefield/bg_fence_stones.png" + } + scale : { + if (game.environment() == Global.Symbian) + 1.0 + else + battleField.scale + } + smooth: true + anchors.centerIn: battleField + } + + Item { + id: battleField + anchors.fill: parent + scale: displayScale + + Image { + id: topLeftCorner + + property PlayerModel player: playerListModel.get(0) + + opacity: { + if (player == null || player.characterPath == "") + return 1 + return 0 + } + + source: "qrc:/images/battlefield/fence_corner_top_left.png" + smooth: true + anchors { + left: fenceLayer.left + top: fenceLayer.top + } + } + + Image { + id: bottomRightCorner + + property PlayerModel player: playerListModel.get(1) + + opacity: { + if (player == null || player.characterPath == "") + return 1 + return 0 + } + + source: "qrc:/images/battlefield/fence_corner_bottom_right.png" + smooth: true + anchors { + right: fenceLayer.right + bottom: fenceLayer.bottom + } + } + + Image { + id: bottomLeftCorner + + property PlayerModel player: playerListModel.get(2) + + opacity: { + if (player == null || player.characterPath == "") + return 1 + return 0 + } + + source: "qrc:/images/battlefield/fence_corner_bottom_left.png" + smooth: true + anchors { + left: fenceLayer.left + bottom: fenceLayer.bottom + } + } + + Image { + id: topRightCorner + + property PlayerModel player: playerListModel.get(3) + + opacity: { + if (player == null || player.characterPath == "") + return 1 + return 0 + } + + source: "qrc:/images/battlefield/fence_corner_top_right.png" + smooth: true + anchors { + right: fenceLayer.right + top: fenceLayer.top + } + } + + Image { + id: fenceLayer + source: "qrc:/images/battlefield/fence_layer_over.png" + smooth: true + anchors.centerIn: parent + focus: true + } + + Image { + id: clockContainer + source: "qrc:/images/battlefield/clock.png" + smooth: true + anchors { + top: fenceLayer.top + horizontalCenter: parent.horizontalCenter + } + + Text { + id: clock + + text: matchController.elapsedTime + color: "white" + style: Text.Outline + smooth: true + + font { + bold: true + family: "Nokia Sans" + pointSize: 20 + } + + anchors.centerIn: parent + anchors.verticalCenterOffset: -6 + } + } + + ImageButton { + id: quitButton + name: "quit" + path: "qrc:/images/battlefield" + smooth: true + anchors { + bottom: fenceLayer.bottom + horizontalCenter: parent.horizontalCenter + } + + onClicked: MatchLogic.askQuitMatch() + } + } + + HenCoop { + playerNumber: 1 + + anchors { + top: parent.top + topMargin: 35 + left: parent.left + leftMargin: 29 + } + } + + HenCoop { + playerNumber: 2 + + anchors { + top: parent.verticalCenter + topMargin: 36 + right: parent.right + rightMargin: 29 + } + } + + HenCoop { + playerNumber: 3 + + anchors { + top: parent.verticalCenter + topMargin: 36 + left: parent.left + leftMargin: 29 + } + } + + HenCoop { + playerNumber: 4 + + anchors { + top: parent.top + topMargin: 35 + right: parent.right + rightMargin: 29 + } + } + + ConfirmationDialog { + id: quitDialog + + text: "Do you want to leave this match?" + opacity: 0 + + onRejected: { + closeQuitDialog() + MatchLogic.resumeMatch() + } + + onAccepted: { + closeQuitDialog() + MatchLogic.leaveMatch() + + closeRequested() + } + + z: 10 + } + + Score { + id: score + + opacity: 0 + + onClose: { + MatchLogic.leaveMatch() + hideScore() + + closeRequested() + } + } + + Rectangle { + id: background + + anchors.fill: parent + color: "black" + opacity: 0.7 + z: 49 + + MouseArea { + anchors.fill: parent + } + + Behavior on opacity { + PropertyAnimation { duration: 200 } + } + } + + Countdown { + id: countdown + + z: 50 + + anchors.fill: parent + onTimeout: { + background.opacity = 0 + MatchLogic.startMatch() + } + } + + onTransitionFinished: { + if (visible) + countdown.start() + else + closeFinished() + } + + Component.onCompleted: MatchLogic.newMatch() + + Keys.onEscapePressed: MatchLogic.askQuitMatch() +} diff --git a/chicken-wranglers/src/qml/PlayerControlView.qml b/chicken-wranglers/src/qml/PlayerControlView.qml new file mode 100644 index 0000000..b520587 --- /dev/null +++ b/chicken-wranglers/src/qml/PlayerControlView.qml @@ -0,0 +1,147 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +import "widgets" +import "common.js" as Common + +Screen { + id: screen + + property string characterPath: "" + property int margins: -60 + + signal back + + focus: true + + Keys.onUpPressed: gameClient.moveUp() + Keys.onDownPressed: gameClient.moveDown() + Keys.onLeftPressed: gameClient.moveLeft() + Keys.onRightPressed: gameClient.moveRight() + Keys.onSpacePressed: gameClient.moveStop() + + Keys.onPressed: { + switch (event.key) { + + // Quit the game + case Qt.Key_Q: + back() + break + + // Laser shots + case Qt.Key_W: + gameClient.toggleLaserUp() + break + + case Qt.Key_S: + gameClient.toggleLaserDown() + break + + case Qt.Key_A: + gameClient.toggleLaserLeft() + break + + case Qt.Key_D: + gameClient.toggleLaserRight() + break + } + + event.accepted = true + } + + Image { + anchors.fill: parent + + source: Common.getImagePath(characterPath, "control.png") + } + + Row { + anchors.fill: parent + + Item { + width: parent.width / 4 + height: parent.height + + MouseArea { + anchors.fill: parent + onClicked: gameClient.toggleLaserLeft() + } + } + + Column { + width: parent.width / 2 + height: parent.height + + Item { + width: parent.width + height: parent.height / 3 * 2 + + MouseArea { + anchors.fill: parent + onClicked: gameClient.toggleLaserUp() + } + } + + Item { + width: parent.width + height: parent.height / 3 + + MouseArea { + anchors.fill: parent + onClicked: gameClient.toggleLaserDown() + } + } + } + + Item { + width: parent.width / 4 + height: parent.height + + MouseArea { + anchors.fill: parent + onClicked: gameClient.toggleLaserRight() + } + } + } +} diff --git a/chicken-wranglers/src/qml/PlayerReadyView.qml b/chicken-wranglers/src/qml/PlayerReadyView.qml new file mode 100644 index 0000000..41e8c5a --- /dev/null +++ b/chicken-wranglers/src/qml/PlayerReadyView.qml @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +import game.types 1.0 +import "widgets" +import "common.js" as Common + +Screen { + property string characterPath: "" + + signal back + + anchors.fill: parent + + Image { + id: background + + source: { + if (game.environment() == Global.Symbian) + "qrc:/images/general/symbian/bg_selectcharacter.png" + else + "qrc:/images/general/bg_selectcharacter.png" + } + anchors.fill: parent + } + + + Image { + id: title + + anchors { + top: parent.top + horizontalCenter: parent.horizontalCenter + margins: 40 + } + + source: "qrc:/images/general/you_are_ready.png" + smooth: true + } + + Image { + anchors.centerIn: parent + + smooth: true + source: Common.getImagePath(characterPath, "select_character.png") + } + + Button { + text: "Start" + width: 200 + + // TODO: Enable this button if this client is P1 + opacity: 0 + + anchors { + horizontalCenter: parent.horizontalCenter + bottom: parent.bottom + margins: 20 + } + + onClicked: console.log("Start game via P1 client") + } + + ImageButton { + name: "back" + onClicked: back() + + anchors { + top: parent.top + right: parent.right + margins: 15 + } + } +} diff --git a/chicken-wranglers/src/qml/Score.qml b/chicken-wranglers/src/qml/Score.qml new file mode 100644 index 0000000..1776386 --- /dev/null +++ b/chicken-wranglers/src/qml/Score.qml @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 +import "widgets" + +import "match.js" as MatchLogic +import "common.js" as Common + +Item { + id: score + + property int numberOfPlayers: playerListModel.count() + property int scoreBoxTick: width / (numberOfPlayers + 1) + + signal close + + anchors.fill: parent + z: 10 + + function sortScore(scoreBox1, scoreBox2) { + return (scoreBox2.score - scoreBox1.score) + } + + function createScore() { + var scoreBoxList = [] + + for (var i = 0; i < numberOfPlayers; i++) { + var scoreBox + scoreBox = MatchLogic.createScoreBox() + if (scoreBox == undefined) + continue + + var player = playerListModel.get(i) + if (player == null) + continue + + scoreBox.source = Common.getImagePath(player.characterPath, "score.png") + scoreBox.score = player.score + scoreBox.z = 15 + scoreBox.y = 0 + + scoreBoxList.push(scoreBox) + } + + scoreBoxList.sort(sortScore) + + for (var i = 0; i < scoreBoxList.length; i++) + scoreBoxList[i].x = (scoreBoxTick * (i + 1)) - (scoreBoxList[i].width / 2) + + closeTimer.start() + } + + function show() { + opacity = 1 + } + + function hide() { + opacity = 0 + } + + Behavior on opacity { + NumberAnimation { duration: 500 } + } + + Rectangle { + anchors.fill: parent + color: "black" + opacity: 0.8 + + MouseArea { + anchors.fill: parent + } + } + + Timer { + id: closeTimer + + interval: 5000 + + onTriggered: close() + } + + onOpacityChanged: { + if (opacity == 1) { + createScore() + } + } +} diff --git a/chicken-wranglers/src/qml/ScoreBox.qml b/chicken-wranglers/src/qml/ScoreBox.qml new file mode 100644 index 0000000..ef2f19d --- /dev/null +++ b/chicken-wranglers/src/qml/ScoreBox.qml @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +Image { + id: scoreBox + + property int score: 0 + + y: -593 * matchScreen.displayScale // FIXME: Use image height instead + smooth: true + width: scoreBox.sourceSize.width * matchScreen.displayScale + height: scoreBox.sourceSize.height * matchScreen.displayScale + + Text { + text: score + style: Text.Outline + color: "white" + smooth: true + + font { + family: "Nokia Sans" + pointSize: 60 * matchScreen.displayScale + bold: true + } + + anchors { + horizontalCenter: parent.horizontalCenter + bottom: parent.bottom + bottomMargin: 30 * matchScreen.displayScale + } + } + + Behavior on y { + PropertyAnimation { + duration: 1000 + easing.type: Easing.OutBounce + } + } +} + diff --git a/chicken-wranglers/src/qml/Splash.qml b/chicken-wranglers/src/qml/Splash.qml new file mode 100644 index 0000000..5a1aa38 --- /dev/null +++ b/chicken-wranglers/src/qml/Splash.qml @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +import game.types 1.0 +import "widgets" + +Screen { + id: screen + + property int time: 1500 + + Image { + id: background + + smooth: true + + anchors.fill: parent + source: { + if (game.environment() == Global.Symbian) + "qrc:/images/general/symbian/bg_splash.png" + else + "qrc:/images/general/bg_splash.png" + } + } + + Timer { + running: true + interval: time + repeat: false + + onTriggered: timeout() + } + + onTransitionFinished: { + if (!visible) + closeFinished() + } +} diff --git a/chicken-wranglers/src/qml/StartView.qml b/chicken-wranglers/src/qml/StartView.qml new file mode 100644 index 0000000..fd2905d --- /dev/null +++ b/chicken-wranglers/src/qml/StartView.qml @@ -0,0 +1,246 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 +import game.types 1.0 + +import "client.js" as Client +import "host.js" as Host +import "widgets" + +Screen { + id: screen + + signal hostSelected + signal clientSelected + signal clientDiscoveryCanceled + + function showStartServerDialog() { + startServerDialog.show() + } + + function hideStartServerDialog() { + startServerDialog.hide() + } + + function showStartClientDialog() { + if (game.connectivity == "bluetooth") { + connectivityDialog.model = connectivityListModel + connectivityDialog.show() + } else { + startClientDialog.show() + } + } + + function hideStartClientDialog() { + if (game.connectivity == "bluetooth") { + gameClient.scanCanceled() + connectivityDialog.hide() + } else + startClientDialog.hide() + } + + function showErrorDialog(msg) { + errorDialog.text = msg + errorDialog.show() + } + + function hideErrorDialog() { + errorDialog.hide() + } + + onHostSelected: Host.start() + onClientSelected: Client.start() + + Image { + id: background + + smooth: true + anchors.fill: parent + + source: { + if (game.environment() == Global.Symbian) + "qrc:/images/general/symbian/bg_640x360.png" + else if (game.environment() == Global.Maemo) + "qrc:/images/general/bg_800x480.png" + else + "qrc:/images/general/bg_1280x768.png" + } + } + + FeatherFall { + id: featherFall + number: { + if (game.environment() == Global.Symbian) + 2 + else if (game.environment() == Global.Maemo) + 3 + else + 5 + } + fallWidth:{ + if (game.environment() == Global.Symbian) + 640 + else + 800 + } + fallHeight:{ + if (game.environment() == Global.Symbian) + 360 + else + 768 + } + + anchors.fill: parent + } + + Item { + anchors { + centerIn: parent + horizontalCenterOffset: 90 + verticalCenterOffset: 120 + margins: 100 + } + + Button { + id: hostGameButton + + anchors { + right: parent.right + bottom: parent.bottom + } + + text: "Host game" + width: 200 + onClicked: hostSelected() + } + + Button { + id: joinGameButton + + anchors { + left: parent.left + leftMargin: 10 + bottom: parent.bottom + } + + text: "Join game" + width: 200 + onClicked: clientSelected() + } + } + + ImageButton { + anchors { + top: parent.top + left: parent.left + margins: 15 + } + + name: "close" + onClicked: Qt.quit() + } + + ToggleButton { + anchors { + top: parent.top + right: parent.right + margins: 15 + } + } + + MessageDialog { + id: startClientDialog + + text: "Searching for server" + buttonText: "Cancel" + opacity: 0 + + Loading { + anchors.horizontalCenter: startClientDialog.box.horizontalCenter + anchors.bottom: startClientDialog.box.bottom + anchors.bottomMargin: 100 + } + + onButtonClicked: clientDiscoveryCanceled() + } + + ConnectivityDialog { + id: connectivityDialog + + opacity: 0 + onCancel: { + connectivityDialog.hide() + gameClient.scanCanceled() + } + } + + MessageDialog { + id: startServerDialog + + text: "Creating server" + opacity: 0 + + Loading { + anchors.horizontalCenter: startServerDialog.box.horizontalCenter + anchors.bottom: startServerDialog.box.bottom + anchors.bottomMargin: 100 + } + } + + MessageDialog { + id: errorDialog + + text: "error" + buttonText: "Close" + opacity: 0 + + onButtonClicked: hideErrorDialog() + } + + onOpacityChanged: { + if (opacity == 1) + featherFall.start() + else if (opacity == 0) + featherFall.stop() + } +} diff --git a/chicken-wranglers/src/qml/WaitingRoomView.qml b/chicken-wranglers/src/qml/WaitingRoomView.qml new file mode 100644 index 0000000..64b0bea --- /dev/null +++ b/chicken-wranglers/src/qml/WaitingRoomView.qml @@ -0,0 +1,288 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +import game.types 1.0 +import "common.js" as Common +import "widgets" + +Screen { + id: screen + + signal back + signal matchStarted + + Keys.onReturnPressed: { + if (buttonStart.enabled) + matchStarted() + } + + Image { + id: background + smooth: true + anchors.fill: parent + source: { + if (game.environment() == Global.Symbian) + "qrc:/images/general/symbian/bg_640x360.png" + else if (game.environment() == Global.Maemo) + "qrc:/images/general/bg_800x480.png" + else + "qrc:/images/general/bg_1280x768.png" + } + } + + ImageButton { + anchors { + left: screen.left + top: screen.top + margins: 15 + } + + name: "back" + onClicked: back() + } + + + Button { + id: buttonStart + + anchors { + top: screen.top + right: screen.right + margins: 15 + } + + width: 160 + text: "Start" + sourceName: "bt_start" + rightBorder: 35 + horizontalCenterOffset: -6 + italic: true + + enabled: playerListModel.playersReady; + + onClicked: matchStarted() + } + + ListView { + id: playerListView + anchors { + centerIn: parent + horizontalCenterOffset: 30 + verticalCenterOffset: 130 + } + + height: 400 + width: 400 + model: playerListModel + delegate: playerListDelegate + interactive: false + } + + Component { + id: playerListDelegate + + Item { + id: delegatePlayer + + scale: { + if (game.environment() == Global.Symbian) + 0.7 + else + 1 + } + + width: 400 + height: 80 + + property bool isReady: status == PlayerModel.Ready + + states { + State { + name: "playerReady"; when: isReady + PropertyChanges { target: playerInfo; opacity: 1 } + PropertyChanges { target: playerInfoUnknown; opacity: 0 } + } + } + + Image { + id: listItemBg + + anchors { + top: playerInfoUnknown.top + topMargin: 32 + } + + source: "qrc:/images/general/list_name_bg.png" + } + + Item { + id: playerInfoUnknown + + Image { + id: listItemIconUnknown + + smooth: true + + anchors { + top: parent.top + left: parent.left + leftMargin: 25 + } + + source: "qrc:/images/general/list_unknown_character.png" + fillMode: Image.PreserveAspectFit + } + + Loading { + id: listItemLoading + + anchors { + left: listItemIconUnknown.right + leftMargin: 40 + bottom: listItemIconUnknown.bottom + bottomMargin: 20 + } + } + + } + + Item { + id: playerInfo + + opacity: 0 + + Image { + id: listItemIcon + + smooth: true + + anchors { + top: parent.top + left: parent.left + leftMargin: 25 + } + + source: Common.getImagePath(characterPath, "waitinglist.png") + fillMode: Image.PreserveAspectFit + } + + + Item { + id: listItemNameOk + + anchors { + left: listItemIcon.right + leftMargin: 15 + bottom: listItemIcon.bottom + bottomMargin: 12 + } + + Image { + id: listItemName + + smooth: true + + anchors { + left: listItemNameOk.left + bottom: listItemNameOk.bottom + } + + source: Common.getImagePath(characterPath, "name.png") + fillMode: Image.PreserveAspectFit + } + + Image { + id: listItemOk + + smooth: true + + anchors { + left: listItemName.right + leftMargin: 30 + verticalCenter: listItemName.verticalCenter + } + + source: "qrc:/images/general/list_status_ok.png" + fillMode: Image.PreserveAspectFit + } + } + + ParallelAnimation { + id: anim + + SequentialAnimation { + PropertyAnimation { + target: listItemIcon + property: "scale" + duration: 300 + easing.type: Easing.InOutBack + to: 2 + } + PropertyAnimation { + target: listItemIcon + property: "scale" + duration: 200 + to: 1 + } + } + } + + onOpacityChanged: { + anim.running = true + } + } + + ListView.onAdd: SequentialAnimation { + PropertyAction { target: delegatePlayer; property: "scale"; value: 0 } + NumberAnimation { target: delegatePlayer; property: "scale"; to: 1; duration: 250; easing.type: Easing.InOutQuad } + } + + ListView.onRemove: SequentialAnimation { + PropertyAction { target: delegatePlayer; property: "ListView.delayRemove"; value: true } + NumberAnimation { target: delegatePlayer; property: "scale"; to: 0; duration: 250; easing.type: Easing.InOutQuad } + PropertyAction { target: delegatePlayer; property: "ListView.delayRemove"; value: false } + } + } + } +} diff --git a/chicken-wranglers/src/qml/client.js b/chicken-wranglers/src/qml/client.js new file mode 100644 index 0000000..16eb9f8 --- /dev/null +++ b/chicken-wranglers/src/qml/client.js @@ -0,0 +1,72 @@ +function start() { + game.mode = Game.ClientMode + + startViewLoader.item.showStartClientDialog("Looking for server") + startViewLoader.item.clientDiscoveryCanceled.connect(cancelDiscovery) + + // gameClient only exists after game.mode is set to Game.ClientMode + gameClient.statusChanged.connect(onStatusChanged) + gameClient.startConnection() +} + +function cancelDiscovery() { + if (gameClient.status == GameClient.Joined) { + gameClient.statusChanged.disconnect(onStatusChanged) + startViewLoader.item.clientDiscoveryCanceled.disconnect(cancelDiscovery) + startViewLoader.item.hideStartClientDialog() + return + } + + quit() +} + +function quit() { + gameClient.statusChanged.disconnect(onStatusChanged) + startViewLoader.item.clientDiscoveryCanceled.disconnect(cancelDiscovery) + startViewLoader.item.hideStartClientDialog() + + gameClient.quit() +} + +function onStatusChanged() { + switch (gameClient.status) { + + case GameClient.Joined: + startViewLoader.item.hideStartClientDialog() + clientViewLoader.source = "ClientView.qml" + break + + case GameClient.LeftMatch: + clientViewLoader.item.showPlayerReadyView() + break + + case GameClient.Ready: + clientViewLoader.item.showControlView() + break + + case GameClient.Error: + startViewLoader.item.hideStartClientDialog() + handleError(gameClient.error) + break + + default: + console.log("Unknown client status") + } +} + +function handleError(error) { + switch (error) { + + case GameClient.ServerDiscoveryTimeoutError: + startViewLoader.item.showErrorDialog("Host not found") + break + + case GameClient.SocketError: + clientViewLoader.closeRequested() + startViewLoader.item.showErrorDialog("Disconnected from host") + break + + default: + console.log("Unknown client error") + } +} diff --git a/chicken-wranglers/src/qml/common.js b/chicken-wranglers/src/qml/common.js new file mode 100644 index 0000000..2ce1585 --- /dev/null +++ b/chicken-wranglers/src/qml/common.js @@ -0,0 +1,26 @@ +var tempFrom +var tempTo + +function switchScreens(from, to) { + if (!from || !to) + return + + tempFrom = from + tempTo = to + + from.hide() + from.opacityChanged.connect(showNextScreen) +} + +function showNextScreen() { + if (tempFrom.opacity == 0) { + tempTo.show() + } +} + +function getImagePath(basePath, fileName) { + if (basePath == "") + return "" + + return basePath + "/" + fileName +} diff --git a/chicken-wranglers/src/qml/host.js b/chicken-wranglers/src/qml/host.js new file mode 100644 index 0000000..d545c31 --- /dev/null +++ b/chicken-wranglers/src/qml/host.js @@ -0,0 +1,46 @@ +function start() { + game.mode = Game.HostMode + + startViewLoader.item.showStartServerDialog("Creating server") + + // gameHosts only exists after game.mode is set to Game.HostMode + gameHost.statusChanged.connect(onStatusChanged) + gameHost.startConnection() +} + +function quit() { + gameHost.statusChanged.disconnect(onStatusChanged) + startViewLoader.item.hideStartServerDialog() + + gameHost.quit(); +} + +function onStatusChanged() { + switch (gameHost.status) { + + case GameHost.Start: + startViewLoader.item.hideStartServerDialog() + hostViewLoader.source = "HostView.qml" + break + + case GameHost.Error: + startViewLoader.item.hideStartServerDialog() + handleError(gameHost.error) + break + + default: + console.log("Unknown server status") + } +} + +function handleError(error) { + switch (error) { + + case GameHost.AnotherServerRunningError: + startViewLoader.item.showErrorDialog("Server is already running") + break + + default: + console.log("Unknown server error") + } +} diff --git a/chicken-wranglers/src/qml/main.qml b/chicken-wranglers/src/qml/main.qml new file mode 100644 index 0000000..32ac3f3 --- /dev/null +++ b/chicken-wranglers/src/qml/main.qml @@ -0,0 +1,126 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 +import game.types 1.0 + +import "common.js" as Common +import "host.js" as Host +import "client.js" as Client +import "widgets" + +Rectangle { + id: main + + width: 800 + height: 480 + + focus: true + + SystemPalette { id: activePalette } + + Loader { + id: splashScreenLoader + + signal closeFinished + signal timeout + + anchors.fill: parent + + onLoaded: splashScreenLoader.item.show() + onTimeout: startViewLoader.source = "StartView.qml" + onCloseFinished: { + splashScreenLoader.source = "" + game.startBackgroundSound() + } + } + + Loader { + id: startViewLoader + + anchors.fill: parent + + onLoaded: Common.switchScreens(splashScreenLoader.item, startViewLoader.item) + } + + Loader { + id: hostViewLoader + + signal closeRequested + signal closeFinished + + anchors.fill: parent + + onLoaded: { + focus = true + Common.switchScreens(startViewLoader.item, hostViewLoader.item) + } + + onCloseRequested: Common.switchScreens(hostViewLoader.item, startViewLoader.item) + onCloseFinished: { + Host.quit() + hostViewLoader.source = "" + } + } + + Loader { + id: clientViewLoader + + signal closeRequested + signal closeFinished + + anchors.fill: parent + + onLoaded: { + focus = true + Common.switchScreens(startViewLoader.item, clientViewLoader.item) + } + + onCloseRequested: Common.switchScreens(clientViewLoader.item, startViewLoader.item) + onCloseFinished: { + Client.quit() + clientViewLoader.source = "" + } + } + + Component.onCompleted: splashScreenLoader.source = "Splash.qml" +} diff --git a/chicken-wranglers/src/qml/match.js b/chicken-wranglers/src/qml/match.js new file mode 100644 index 0000000..be9628e --- /dev/null +++ b/chicken-wranglers/src/qml/match.js @@ -0,0 +1,310 @@ +var defaultRows = settings.battlefieldSize().height +var defaultColumns = settings.battlefieldSize().width +var defaultFieldStartX = settings.battlefieldStartPoint().x +var defaultFieldStartY = settings.battlefieldStartPoint().y +var defaultCellSize = settings.battlefieldCellSize() +var defaultHostWidth = settings.hostDisplaySize().width +var defaultHostHeight = settings.hostDisplaySize().height + +// FIXME: Find better naming and place for these variables +var deltaX = 0 +var deltaY = 0 + +// Chicken values +var chickenMoveIntervalNormal = settings.matchChickenMoveInterval() +var chickenMoveIntervalRunning = chickenMoveIntervalNormal * 0.7 +var chickenChangeStepsIntervalNormal = settings.matchChickenChangeStepsInterval() +var chickenChangeStepsIntervalRunning = chickenChangeStepsIntervalNormal * 0.7 + +// Character values +var characterMoveInterval = settings.matchCharacterMoveInterval() +var characterChangeStepsInterval = settings.matchChickenChangeStepsInterval() + +var chickenComponent = null +var playerComponent = null +var playerScoreComponent = null +var henCoopComponent = null +var laserComponent = null + +var verticalLaserArray = null +var horizontalLaserArray = null +var chickenArray = new Array() +var playerArray = new Array() + +function initLaserArrays() +{ + verticalLaserArray = new Array(defaultRows) + for (var y = 0; y < defaultRows; y++) + verticalLaserArray[y] = new Array(defaultColumns - 1) + + horizontalLaserArray = new Array(defaultRows - 1) + for (var y = 0; y < defaultRows - 1; y++) + horizontalLaserArray[y] = new Array(defaultColumns) + + for (var y = 0; y < defaultRows; y++) + for (var x = 0; x < defaultColumns - 1; x++) + verticalLaserArray[y][x] = null + + for (var y = 0; y < defaultRows - 1; y++) + for (var x = 0; x < defaultColumns; x++) + horizontalLaserArray[y][x] = null +} + +function destroyLasers() +{ + for (var y = 0; y < defaultRows; y++) + for (var x = 0; x < defaultColumns - 1; x++) { + if (verticalLaserArray[y][x] != null && verticalLaserArray[y][x] != undefined) { + verticalLaserArray[y][x].destroy() + verticalLaserArray[y][x] = null + } + } + + for (var y = 0; y < defaultRows - 1; y++) + for (var x = 0; x < defaultColumns; x++) { + if (horizontalLaserArray[y][x] != null && horizontalLaserArray[y][x] != undefined) { + horizontalLaserArray[y][x].destroy() + horizontalLaserArray[y][x] = null + } + } +} + +function getDisplayScale() { + var scaleX = game.displaySize.width / defaultHostWidth + var scaleY = game.displaySize.height / defaultHostHeight + + var max = Math.max(scaleX, scaleY) + deltaX = ((max - scaleY) * defaultHostWidth) / 2 + deltaY = ((max - scaleX) * defaultHostHeight) / 2 + + return Math.min(scaleX, scaleY) +} + +function newMatch() { + gameHost.status = GameHost.Match + + initLaserArrays(); + + matchController.chickenCreated.connect(onChickenCreated); + matchController.playerCreated.connect(onPlayerCreated); + matchController.laserUpdated.connect(onLaserUpdated); + matchController.matchFinished.connect(onMatchFinished); + + matchController.setupMatch() + matchController.status = Match.Paused +} + +function startMatch() { + matchController.status = Match.Started + + for (var i = 0; i < playerArray.length; i++) + playerArray[i].opacity = 1 +} + +function askQuitMatch() { + if (matchController.status == Match.Running) + matchController.status = Match.Paused + + matchScreen.showQuitDialog() +} + +function resumeMatch() { + matchController.status = Match.Running +} + +function leaveMatch() { + destroyChickens() + destroyPlayers() + destroyLasers() + + matchController.status = Match.Over +} + +function onMatchFinished() { + matchController.status = Match.Paused + + matchScreen.showScore() +} + +function destroyChickens() +{ + for (var i = 0; i < chickenArray.length; i++) + if (chickenArray[i] != undefined && chickenArray[i] != null) { + chickenArray[i].destroy() + chickenArray[i] = null + } +} + +function destroyPlayers() +{ + for (var i = 0; i < playerArray.length; i++) + if (playerArray[i] != undefined && playerArray[i] != null) { + playerArray[i].destroy() + playerArray[i] = null + } +} + +function onChickenCreated(id) +{ + if (chickenComponent == null) + chickenComponent = Qt.createComponent("Chicken.qml"); + + if (chickenComponent.status == Component.Ready) { + var dynamicObject = chickenComponent.createObject(matchScreen); + if (dynamicObject == null) { + console.log("error creating chicken"); + console.log(chickenComponent.errorString()); + return false; + } + + chickenArray[id] = dynamicObject + + var chickenController = matchController.getChicken(id) + chickenController.positionChanged.connect(dynamicObject.onPositionChanged) + dynamicObject.controller = chickenController + dynamicObject.x = matchScreen.fieldStartX + (chickenController.position.x * matchScreen.cellSize) + (matchScreen.cellSize - dynamicObject.width) / 2 + dynamicObject.y = matchScreen.fieldStartY + (chickenController.position.y * matchScreen.cellSize) + (matchScreen.cellSize - dynamicObject.height) / 2 + } else { + console.log("error loading block chickenComponent"); + console.log(chickenComponent.errorString()); + return false; + } + + return true; +} + +function onPlayerCreated(id) +{ + if (playerComponent == null) + playerComponent = Qt.createComponent("Character.qml"); + + if (playerComponent.status == Component.Ready) { + // TODO: Only players with status Ready should be added + var dynamicObject = playerComponent.createObject(matchScreen); + if (dynamicObject == null) { + console.log("error creating character"); + console.log(playerComponent.errorString()); + return false; + } + + dynamicObject.playerNumber = id + playerArray[id] = dynamicObject + + var playerController = matchController.getPlayer(id) + dynamicObject.controller = playerController + playerController.laserToggleRequested.connect(dynamicObject.onLaserToggleRequested) + + dynamicObject.model = playerListModel.get(id) + } else { + console.log("error loading block playerComponent"); + console.log(playerComponent.errorString()); + return false; + } + + return true; +} + +function createScoreBox() +{ + if (playerScoreComponent == null) + playerScoreComponent = Qt.createComponent("ScoreBox.qml"); + + var dynamicObject = null; + + if (playerScoreComponent.status == Component.Ready) { + dynamicObject = playerScoreComponent.createObject(score); + if (dynamicObject == null) { + console.log("error creating laser"); + console.log(playerScoreComponent.errorString()); + return null; + } + } else { + console.log("error loading block playerScoreComponent"); + console.log(playerScoreComponent.errorString()); + return null; + } + + return dynamicObject + +} + +function createLaser() +{ + if (laserComponent == null) + laserComponent = Qt.createComponent("Laser.qml"); + + var dynamicObject = null; + + if (laserComponent.status == Component.Ready) { + dynamicObject = laserComponent.createObject(matchScreen); + if (dynamicObject == null) { + console.log("error creating laser"); + console.log(laserComponent.errorString()); + return null; + } + } else { + console.log("error loading block laserComponent"); + console.log(laserComponent.errorString()); + return null; + } + + return dynamicObject +} + +function removeLaser(x, y, direction) +{ + var laserObj = null + + if (direction == Global.LaserRight && x < defaultColumns - 1) { + laserObj = verticalLaserArray[y][x] + verticalLaserArray[y][x] = null + } else if (direction == Global.LaserLeft && x >= 0) { + laserObj = verticalLaserArray[y][x - 1] + verticalLaserArray[y][x - 1] = null + } else if (direction == Global.LaserUp && y > 0) { + laserObj = horizontalLaserArray[y - 1][x] + horizontalLaserArray[y - 1][x] = null + } else if (direction == Global.LaserDown && y < defaultRows - 1) { + laserObj = horizontalLaserArray[y][x] + horizontalLaserArray[y][x] = null + } + + if (laserObj == null) + return + + var cellX = matchScreen.fieldStartX + x * (defaultCellSize * matchScreen.displayScale) + var cellY = matchScreen.fieldStartY + y * (defaultCellSize * matchScreen.displayScale) + + laserObj.turnOff(cellX, cellY, defaultCellSize * matchScreen.displayScale, direction) +} + +function addLaser(x, y, direction) +{ + var laserObj = createLaser(); + + if (direction == Global.LaserRight && verticalLaserArray[y][x] == null) + verticalLaserArray[y][x] = laserObj + else if (direction == Global.LaserLeft && verticalLaserArray[y][x - 1] == null) + verticalLaserArray[y][x - 1] = laserObj + else if (direction == Global.LaserUp && horizontalLaserArray[y - 1][x] == null) + horizontalLaserArray[y - 1][x] = laserObj + else if (direction == Global.LaserDown && horizontalLaserArray[y][x] == null) + horizontalLaserArray[y][x] = laserObj + else { + laserObj.destroy() + return + } + + var cellX = matchScreen.fieldStartX + x * (defaultCellSize * matchScreen.displayScale) + var cellY = matchScreen.fieldStartY + y * (defaultCellSize * matchScreen.displayScale) + + laserObj.turnOn(cellX, cellY, defaultCellSize * matchScreen.displayScale, direction) +} + +function onLaserUpdated(posX, posY, laserDirection, isOn) +{ + if (isOn) + addLaser(posX, posY, laserDirection) + else + removeLaser(posX, posY, laserDirection) +} diff --git a/chicken-wranglers/src/qml/qml.qrc b/chicken-wranglers/src/qml/qml.qrc new file mode 100644 index 0000000..615d922 --- /dev/null +++ b/chicken-wranglers/src/qml/qml.qrc @@ -0,0 +1,43 @@ + + + main.qml + common.js + client.js + host.js + Splash.qml + StartView.qml + widgets/Screen.qml + widgets/Button.qml + widgets/ImageButton.qml + widgets/Loading.qml + widgets/BaseDialog.qml + widgets/MessageDialog.qml + widgets/ConfirmationDialog.qml + widgets/Feather.qml + widgets/FeatherFall.qml + widgets/featherfall.js + widgets/Countdown.qml + widgets/OptionSlider.qml + widgets/Scrollbar.qml + widgets/ConnectivityDialog.qml + widgets/ConnectivityListView.qml + widgets/ToggleButton.qml + + ClientView.qml + CharacterSelectionView.qml + PlayerReadyView.qml + PlayerControlView.qml + + HostView.qml + WaitingRoomView.qml + MatchView.qml + Laser.qml + Score.qml + ScoreBox.qml + HenCoop.qml + Being.qml + Character.qml + Chicken.qml + match.js + + diff --git a/chicken-wranglers/src/qml/widgets/BaseDialog.qml b/chicken-wranglers/src/qml/widgets/BaseDialog.qml new file mode 100644 index 0000000..e1cea04 --- /dev/null +++ b/chicken-wranglers/src/qml/widgets/BaseDialog.qml @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +import game.types 1.0 + +Item { + id: dialog + + property alias box: box + + signal showFinished + signal hideFinished + + anchors.fill: parent + + function show() { + dialog.opacity = 1 + } + + function hide() { + dialog.opacity = 0 + } + + onOpacityChanged: { + if (dialog.opacity == 1) + showFinished() + else if (dialog.opacity == 0) + hideFinished() + } + + Rectangle { + id: background + + anchors.fill: parent + color: "black" + opacity: 0.7 + + MouseArea { + anchors.fill: parent + } + } + + function backgroundSize() { + var res = {}; + res["height"] = 376 + res["width"] = 622 + + // XXX: if in symbian, make the dialog smaller + if (game.environment() == Global.Symbian) { + res.height = 0.9 * dialog.height + res.width = 0.9 * dialog.width + } + return res; + } + + Image { + id: box + + source: { + if (game.environment() == Global.Symbian) + "qrc:/images/general/symbian/bg_dialog.png" + else + "qrc:/images/general/bg_dialog.png" + } + anchors.centerIn: parent + } + + Behavior on opacity { + NumberAnimation { duration: 200 } + } +} diff --git a/chicken-wranglers/src/qml/widgets/Button.qml b/chicken-wranglers/src/qml/widgets/Button.qml new file mode 100644 index 0000000..6ccd512 --- /dev/null +++ b/chicken-wranglers/src/qml/widgets/Button.qml @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +BorderImage { + id: button + + property int leftBorder: 18 + property int rightBorder: 18 + property int horizontalCenterOffset: 0 + property string sourceName: "bt" + property string text: "" + property bool blink: false + property bool enabled: true + property bool italic: false + + signal clicked + + source: { + if (!enabled) + return "qrc:/images/general/" + sourceName + "_disabled.png" + + if (mouseArea.pressed) + return "qrc:/images/general/" + sourceName + "_pressed.png" + else + return "qrc:/images/general/" + sourceName + ".png" + } + + smooth: true + + border { + left: leftBorder + right: rightBorder + } + + width: buttonText.width + 40 + + PropertyAnimation { + id: blinkAnimation + + target: button + properties: "opacity" + loops: 2 + from: 0 + to: 1 + duration: 200 + + onRunningChanged: { + if (!running) + button.clicked() + } + } + + Text { + id: buttonText + + text: button.text + smooth: true + + color: { + if (button.enabled) + "#77262d" + else + "#666666" + } + + anchors { + centerIn: parent + verticalCenterOffset: -3 + horizontalCenterOffset: button.horizontalCenterOffset + } + + font { + family: "Nokia Sans" + pixelSize: 26 + bold: true + italic: button.italic + } + } + + MouseArea { + id: mouseArea + + enabled: button.enabled + anchors.fill: parent + onClicked: { + if (blink) + blinkAnimation.running = true + else + button.clicked() + } + } +} diff --git a/chicken-wranglers/src/qml/widgets/ConfirmationDialog.qml b/chicken-wranglers/src/qml/widgets/ConfirmationDialog.qml new file mode 100644 index 0000000..90e922d --- /dev/null +++ b/chicken-wranglers/src/qml/widgets/ConfirmationDialog.qml @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +BaseDialog { + id: dialog + + property string text: "Confirmation Dialog" + property string rejectText: "No" + property string acceptText: "Yes" + property int buttonWidth: 160 + + signal rejected() + signal accepted() + + Text { + color: "#4d908f" + text: dialog.text + style: Text.Raised + styleColor: "white" + + anchors.fill: box + anchors.margins: 60 + + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + wrapMode: Text.WordWrap + + font { + family: "Nokia Sans" + pixelSize: 34 + } + } + + Button { + id: rejectButton + + width: buttonWidth + text: dialog.rejectText + source: "qrc:/images/general/bt.png" + anchors { + verticalCenter: box.bottom + verticalCenterOffset: -25 + right: box.horizontalCenter + rightMargin: 20 + } + + onClicked: rejected() + } + + Button { + id: acceptButton + + width: buttonWidth + text: dialog.acceptText + source: "qrc:/images/general/bt.png" + anchors { + verticalCenter: box.bottom + verticalCenterOffset: -25 + left: box.horizontalCenter + leftMargin: 20 + } + + onClicked: accepted() + } +} diff --git a/chicken-wranglers/src/qml/widgets/ConnectivityDialog.qml b/chicken-wranglers/src/qml/widgets/ConnectivityDialog.qml new file mode 100644 index 0000000..c7a4f99 --- /dev/null +++ b/chicken-wranglers/src/qml/widgets/ConnectivityDialog.qml @@ -0,0 +1,185 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 +import game.types 1.0 + +BaseDialog { + id: dialog + + property string buttonText: "Use it" + property string cancelText: "Cancel" + property ConnectivityListModel model: ConnectivityListModel {} + signal cancel() + + Connections { + target: dialog + onHideFinished: { + title.text = "Scanning..." + button.enabled = true + quitButton.enabled = true + } + } + + ConfirmationDialog { + id: quitDialog + + text: "Do you want to cancel scanning?" + opacity: 0 + + onRejected: { + quitDialog.hide() + } + + onAccepted: { + quitDialog.hide() + dialog.cancel() + } + + z: 10 + } + + Text { + id: title + + text: "Scanning..." + style: Text.Raised + styleColor: "white" + color: "#4d908f" + + font { + family: "Nokia Sans" + bold: true + pixelSize: 34 + } + + anchors.top: box.top + anchors.topMargin: 60 + anchors.left: parent.left + anchors.right: parent.right + + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } + + ConnectivityListView { + id: listView + + property real scrollSize: 200 + + width: 400 + height: 200 + model: dialog.model + anchors.top: title.bottom + anchors.topMargin: 15 + anchors.bottom: box.bottom + anchors.bottomMargin: 80 + anchors.horizontalCenter: parent.horizontalCenter + + onContentYChanged: { + scrollbar.setValue((contentY / scrollSize) * 100) + } + + onMovingChanged: { + if (moving) + scrollbar.opacity = 1; + else + scrollbar.opacity = 0; + } + } + + Scrollbar { + id: scrollbar + + opacity: 0 + anchors.top: title.bottom + anchors.bottom: box.bottom + anchors.left: listView.right + anchors.leftMargin: 20 + + Behavior on opacity { + NumberAnimation { + duration: 500 + easing.type: Easing.OutCirc + } + } + } + + Button { + id: button + + text: dialog.buttonText + anchors { + verticalCenter: box.bottom + verticalCenterOffset: -25 + horizontalCenter: box.horizontalCenter + horizontalCenterOffset: 90 + } + + onClicked: { + button.enabled = false + quitButton.enabled = false + title.text = "Connecting..." + + if (listView.currentIndex != -1) + listView.model.selectedIndex = listView.currentIndex + } + } + + Button { + id: quitButton + text: dialog.cancelText + anchors { + verticalCenter: box.bottom + verticalCenterOffset: -25 + horizontalCenter: box.horizontalCenter + horizontalCenterOffset: -90 + } + + onClicked: { + if (quitDialog.opacity == 0) { + quitDialog.show() + } + } + } +} + diff --git a/chicken-wranglers/src/qml/widgets/ConnectivityListModel.qml b/chicken-wranglers/src/qml/widgets/ConnectivityListModel.qml new file mode 100644 index 0000000..df1449f --- /dev/null +++ b/chicken-wranglers/src/qml/widgets/ConnectivityListModel.qml @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +ListModel { + ListElement { + // N8 cellphone + name: "cw"; address: "18:14:56:44:F4:DB" + category: 2; pairing: 1 + } + + ListElement { + name: "5800gard"; address: "00:25:CF:11:2B:8A" + category: 2; pairing: 1 + } + + ListElement { + name: "FabyAAAAAAAAAAAAAAAAAAAAAAAAAA"; address: "00:24:03:DA:45:00" + category: 1; pairing: 0 + } + + ListElement { + name: "device-0BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"; address: "00:24:03:DA:45:00" + category: 1; pairing: 0 + } + + ListElement { + name: "pc-1"; address: "00:24:03:DA:45:00" + category: 1; pairing: 0 + } + + ListElement { + name: "device-1"; address: "00:24:03:DA:45:00" + category: 1; pairing: 0 + } + + ListElement { + name: "mobile-0"; address: "00:24:03:DA:45:00" + category: 1; pairing: 0 + } +} + diff --git a/chicken-wranglers/src/qml/widgets/ConnectivityListView.qml b/chicken-wranglers/src/qml/widgets/ConnectivityListView.qml new file mode 100644 index 0000000..ca04c5b --- /dev/null +++ b/chicken-wranglers/src/qml/widgets/ConnectivityListView.qml @@ -0,0 +1,138 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 +import game.types 1.0 + +ListView { + id: listView + + Component { + id: delegate + + Item { + width: lineDivisor.width + height: 43 + + Image { + id: lineDivisor + + source: "qrc:/images/general/list_line_divisor.png" + + anchors.top: parent.top + } + + Text { + text: name + + width: parent.width - 110 + + style: Text.Raised + styleColor: "white" + + color: "#4d908f" + + font { + family: "Nokia Sans" + bold: true + pixelSize: 21 + } + + elide: Text.ElideRight + + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.left + anchors.leftMargin: 23 + + horizontalAlignment: Text.AlignLeft + verticalAlignment: Text.AlignVCenter + } + + MouseArea { + anchors.fill: parent + + onClicked: { + var pos = mapToItem(listView.contentItem, mouseX, mouseY) + var selectedIndex = listView.indexAt(pos.x, pos.y) + + if (selectedIndex == listView.currentIndex) { + listView.currentIndex = -1 + } else { + listView.currentIndex = selectedIndex + } + } + } + } + } + + model: ConnectivityListModel {} + delegate: delegate + + focus: false + clip: true + + Component { + id: highlightIcon + + Item { + width: listView.width + height: 43 + + Image { + source: "qrc:/images/general/list_selected_icon.png" + + anchors.left: parent.right + anchors.leftMargin: -70 + anchors.verticalCenter: parent.verticalCenter + anchors.verticalCenterOffset: 1 + } + } + } + + currentIndex: model.selectedIndex + + highlight: highlightIcon + highlightMoveDuration: 100 + + snapMode: ListView.SnapToItem +} + diff --git a/chicken-wranglers/src/qml/widgets/Countdown.qml b/chicken-wranglers/src/qml/widgets/Countdown.qml new file mode 100644 index 0000000..31b5ad9 --- /dev/null +++ b/chicken-wranglers/src/qml/widgets/Countdown.qml @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +Item { + id: countdown + + property int startValue: 3 + property int currentValue: startValue + property int interval: 800 + property string timeoutText: "Go!" + + signal timeout + + function start() { + countdown.opacity = 1 + animation.start() + } + + function decrement() { + if (currentValue - 1 > 0) { + currentValue-- + return + } + + if (currentValue == 1) { + number.text = countdown.timeoutText + currentValue-- + return + } + + countdown.opacity = 0 + countdown.timeout() + } + + Text { + id: number + + text: currentValue + smooth: true + anchors.centerIn: parent + color: "white" + + font { + family: "Nokia Sans" + pointSize: 100 + bold: true + } + + style: Text.Outline + styleColor: "darkgreen" + } + + SequentialAnimation { + id: animation + + loops: startValue + 1 + + ParallelAnimation { + PropertyAnimation { duration: countdown.interval; target: number; property: "scale"; from: 1; to: 2 } + PropertyAnimation { duration: countdown.interval; target: number; property: "opacity"; from: 1; to: 0 } + } + + PropertyAction { target: number; properties: "scale,opacity"; value: 1 } + ScriptAction { script: countdown.decrement() } + } +} diff --git a/chicken-wranglers/src/qml/widgets/Feather.qml b/chicken-wranglers/src/qml/widgets/Feather.qml new file mode 100644 index 0000000..b46585c --- /dev/null +++ b/chicken-wranglers/src/qml/widgets/Feather.qml @@ -0,0 +1,126 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +import game.types 1.0 +import "featherfall.js" as Feather + +Image { + id: feather + + property int xMax: 0 + property int xMin: 0 + property int yMax: 768 + + // the delay offset for the initial creation of each feather. + property real delay: 0 + + source: { + if (game.environment() == Global.Symbian) + "qrc:/images/general/symbian/feather1.png" + else + "qrc:/images/general/feather1.png" + } + smooth: true + y: -feather.height + + function startAnimation() { + animY.running = true + animX.running = true + animRotation.running = true + } + + function stopAnimation() { + animY.running = false + animX.running = false + animRotation.running = false + } + + SequentialAnimation on y { + id: animY + + running: false + + PauseAnimation { duration: delay } + NumberAnimation { to: 100; easing.type: Easing.InOutSine; duration: 1050 } + NumberAnimation { to: 300; easing.type: Easing.InOutSine; duration: 950 } + NumberAnimation { to: 500; easing.type: Easing.InOutSine; duration: 1050 } + NumberAnimation { to: 700; easing.type: Easing.InOutSine; duration: 950 } + NumberAnimation { to: 900; easing.type: Easing.InOutSine; duration: 1050 } + NumberAnimation { to: yMax + 2 * feather.height; easing.type: Easing.InOutSine; duration: 950 } + + onRunningChanged: { + if (!running) + feather.destroy() + } + } + + SequentialAnimation on x { + id: animX + + running: false + + PauseAnimation { duration: delay } + NumberAnimation { to: xMax; easing.type: Easing.InOutSine; duration: 950 } + NumberAnimation { to: xMin; easing.type: Easing.InOutSine; duration: 1050 } + NumberAnimation { to: xMax; easing.type: Easing.InOutSine; duration: 950 } + NumberAnimation { to: xMin; easing.type: Easing.InOutSine; duration: 1050 } + NumberAnimation { to: xMax; easing.type: Easing.InOutSine; duration: 950 } + NumberAnimation { to: xMin; easing.type: Easing.InOutSine; duration: 1050 } + } + + SequentialAnimation on rotation { + id: animRotation + + running: false + + PauseAnimation { duration: delay } + NumberAnimation { to: -40; easing.type: Easing.InOutSine; duration: 1000 } + NumberAnimation { to: 25; easing.type: Easing.InOutSine; duration: 1000 } + NumberAnimation { to: -40; easing.type: Easing.InOutSine; duration: 1000 } + NumberAnimation { to: 25; easing.type: Easing.InOutSine; duration: 1000 } + NumberAnimation { to: -40; easing.type: Easing.InOutSine; duration: 1000 } + NumberAnimation { to: 25; easing.type: Easing.InOutSine; duration: 1000 } + NumberAnimation { to: -40; easing.type: Easing.InOutSine; duration: 1000 } + } +} diff --git a/chicken-wranglers/src/qml/widgets/FeatherFall.qml b/chicken-wranglers/src/qml/widgets/FeatherFall.qml new file mode 100644 index 0000000..d8b49d7 --- /dev/null +++ b/chicken-wranglers/src/qml/widgets/FeatherFall.qml @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +import game.types 1.0 +import "featherfall.js" as FeatherFall + +Item { + id: featherFall + + property real fallWidth: 800 + property real fallHeight: 768 + property int number: 5 + + function start() { + timer.start() + } + + function stop() { + timer.stop() + FeatherFall.destroy() + } + + Timer { + id: timer + + triggeredOnStart: true + repeat: true + interval: 6000 + onTriggered: { + FeatherFall.create(featherFall.width, featherFall.height) + } + } +} diff --git a/chicken-wranglers/src/qml/widgets/ImageButton.qml b/chicken-wranglers/src/qml/widgets/ImageButton.qml new file mode 100644 index 0000000..2ccdbf1 --- /dev/null +++ b/chicken-wranglers/src/qml/widgets/ImageButton.qml @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +Image { + id: button + + property bool blink: false + property string name: "" + property string path: "qrc:/images/general" + property alias buttonPressed: mouseArea.pressed + + signal clicked + + smooth: true + source: { + if (path == "") + return "" + + if (mouseArea.pressed) + path + "/bt_" + name + "_pressed.png" + else + path + "/bt_" + name + ".png" + } + + PropertyAnimation { + id: blinkAnimation + + target: button + properties: "opacity" + loops: 2 + from: 0 + to: 1 + duration: 200 + + onRunningChanged: { + if (!running) + button.clicked() + } + } + + MouseArea { + id: mouseArea + + anchors.fill: parent + onClicked: { + if (blink) + blinkAnimation.running = true + else + button.clicked() + } + } +} diff --git a/chicken-wranglers/src/qml/widgets/Loading.qml b/chicken-wranglers/src/qml/widgets/Loading.qml new file mode 100644 index 0000000..19eeff5 --- /dev/null +++ b/chicken-wranglers/src/qml/widgets/Loading.qml @@ -0,0 +1,138 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +Item { + id: loading + + property int count: 0 + + width: row.width + height: row.height + + Component { + id: dot + + Rectangle { + id: outer + + width: 15 + height: 15 + color: "#e0fce5" + radius: 50 + smooth: true + + Rectangle { + id: inner + + anchors.centerIn: parent + + smooth: true + color: "#9bbaae" + radius: 50 + + anchors.fill: parent + anchors.margins: 3 + } + + states { + State { + name: "off" + PropertyChanges { target: outer; scale: 1 } + PropertyChanges { target: inner; color: "#9bbaae" } + } + State { + name: "on" + PropertyChanges { target: outer; scale: 1.33 } + PropertyChanges { target: inner; color: "#f6c200" } + } + } + + transitions: Transition { + ParallelAnimation { + NumberAnimation { target: outer; property: "scale"; easing.type: Easing.InOutQuad } + ColorAnimation { target: inner; property: "color"; easing.type: Easing.InOutQuad } + } + } + } + } + + Row { + id: row + + spacing: 4 + + children: [ + Loader { sourceComponent: dot }, + Loader { sourceComponent: dot }, + Loader { sourceComponent: dot } + ] + } + + Timer { + id: timer + + repeat: true + interval: 200 + running: true + + onTriggered: { + if (count > 0) + row.children[count - 1].item.state = "off" + + if (count < row.children.length) + row.children[count].item.state = "on" + + count = (count + 1) % (row.children.length + 1) + } + } + + onOpacityChanged: { + if (opacity == 1 && !timer.running) { + timer.start() + } + else if (opacity == 0 && timer.running) { + timer.stop() + } + } +} diff --git a/chicken-wranglers/src/qml/widgets/MessageDialog.qml b/chicken-wranglers/src/qml/widgets/MessageDialog.qml new file mode 100644 index 0000000..44cc8d1 --- /dev/null +++ b/chicken-wranglers/src/qml/widgets/MessageDialog.qml @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +BaseDialog { + id: dialog + + property string text: "Message Dialog" + property string buttonText: "Ok" + + signal buttonClicked + + Text { + color: "#4d908f" + text: dialog.text + style: Text.Raised + styleColor: "white" + + anchors.fill: box + anchors.margins: 60 + + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + wrapMode: Text.WordWrap + + font { + family: "Nokia Sans" + pixelSize: 34 + } + } + + Button { + id: button + + text: dialog.buttonText + anchors { + verticalCenter: box.bottom + verticalCenterOffset: -25 + horizontalCenter: box.horizontalCenter + } + + onClicked: buttonClicked() + } +} + diff --git a/chicken-wranglers/src/qml/widgets/OptionSlider.qml b/chicken-wranglers/src/qml/widgets/OptionSlider.qml new file mode 100644 index 0000000..205f299 --- /dev/null +++ b/chicken-wranglers/src/qml/widgets/OptionSlider.qml @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +Item { + id: slider + + property string option: "Wifi" + + signal selected(string option) + + width: sliderSelector.width + height: sliderPath.height + + Image { + id: sliderPath + + anchors.centerIn: parent + + source: "qrc:/images/general/slider_path.png" + } + + Image { + anchors { + horizontalCenter: slider.horizontalCenter + bottom: slider.verticalCenter + bottomMargin: 21 + } + + source: "qrc:/images/general/slider_wifi_icon.png" + } + + Image { + anchors { + horizontalCenter: slider.horizontalCenter + horizontalCenterOffset: 3 + top: slider.verticalCenter + topMargin: 16 + } + + source: "qrc:/images/general/slider_bluetooth_icon.png" + } + + Image { + id: sliderSelector + + source: "qrc:/images/general/slider_selector.png" + + x: 0 + y: 10 + + Behavior on y { + NumberAnimation { + id: slideAnimation + + duration: 500 + easing.type: Easing.OutCirc + } + } + } + + MouseArea { + anchors.fill: parent + + enabled: !slideAnimation.running + + onReleased: { + // Wifi selected + if (mouse.y <= ((slider.height / 2) - 1)) { + if (slider.option != "Wifi") { + slider.option = "Wifi" + + selected(slider.option) + + sliderSelector.y = 10 + } + + // Bluetooth selected + } else { + if (slider.option != "Bluetooth") { + slider.option = "Bluetooth" + + selected(slider.option) + + sliderSelector.y = (slider.height / 2) - 10 + } + } + } + } +} + diff --git a/chicken-wranglers/src/qml/widgets/Screen.qml b/chicken-wranglers/src/qml/widgets/Screen.qml new file mode 100644 index 0000000..967f443 --- /dev/null +++ b/chicken-wranglers/src/qml/widgets/Screen.qml @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +Rectangle { + id: screen + + signal transitionFinished(bool visible) + + anchors.fill: parent + opacity: 0 + + function show() { + screen.state = "visible" + } + + function hide() { + screen.state = "hidden" + } + + states { + State { + name: "visible" + PropertyChanges { target: screen; opacity: 1 } + } + State { + name: "hidden" + PropertyChanges { target: screen; opacity: 0 } + } + } + + Behavior on opacity { + NumberAnimation { + duration: 200 + + onRunningChanged: { + if (!running) { + if (opacity == 1) + transitionFinished(true) + else + transitionFinished(false) + } + } + } + } +} diff --git a/chicken-wranglers/src/qml/widgets/Scrollbar.qml b/chicken-wranglers/src/qml/widgets/Scrollbar.qml new file mode 100644 index 0000000..0d59208 --- /dev/null +++ b/chicken-wranglers/src/qml/widgets/Scrollbar.qml @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +Item { + id: scrollbar + + property real value: 0.0 + property real minimumValue: 0.0 + property real maximumValue: 100.0 + property real offset: 8.0 + property real minimumPos: offset + property real maximumPos: scrollbarPath.height - scrollbarKnob.height - offset + property real scrollSize: maximumPos - minimumPos + 1 + + width: scrollbarKnob.width + height: scrollbarPath.height + + function setValue(newValue) { + if (newValue <= minimumValue) { + value = minimumValue; + } else if (newValue >= maximumValue) { + value = maximumValue; + } else { + value = newValue; + } + } + + Image { + id: scrollbarPath + + anchors.centerIn: parent + + source: "qrc:/images/general/list_scrollbar_path.png" + } + + Image { + id: scrollbarKnob + + anchors.horizontalCenter: parent.horizontalCenter + + y: ((scrollbar.value / scrollbar.maximumValue) * scrollbar.scrollSize) + scrollbar.offset + + source: "qrc:/images/general/list_scrollbar_knob.png" + } +} + diff --git a/chicken-wranglers/src/qml/widgets/ToggleButton.qml b/chicken-wranglers/src/qml/widgets/ToggleButton.qml new file mode 100644 index 0000000..939602f --- /dev/null +++ b/chicken-wranglers/src/qml/widgets/ToggleButton.qml @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +import Qt 4.7 + +Image { + id: button + signal clicked + property string mode: "bluetooth" + source: "qrc:/images/general/toggle_bt.png" + + MouseArea { + id: mouseArea + + anchors.fill: parent + onClicked: { + if (button.mode == "bluetooth") { + button.mode = "lan" + button.source = "qrc:/images/general/toggle_lan.png" + } else { + button.mode = "bluetooth" + button.source = "qrc:/images/general/toggle_bt.png" + } + + game.setConnectivity(button.mode) + } + } +} diff --git a/chicken-wranglers/src/qml/widgets/featherfall.js b/chicken-wranglers/src/qml/widgets/featherfall.js new file mode 100644 index 0000000..6ae51a4 --- /dev/null +++ b/chicken-wranglers/src/qml/widgets/featherfall.js @@ -0,0 +1,66 @@ +var component; +var featherObjList = new Array; + +function create(fallWidth, fallHeight) { + var i, range, lowRange, highRange; + + if (component == null) + component = Qt.createComponent("Feather.qml"); + + range = fallWidth / featherFall.number; + lowRange = -range; + highRange = 0; + + var resourcePath = ""; + if (game.environment() == Global.Symbian) + resourcePath = "qrc:/images/general/symbian/feather" + else + resourcePath = "qrc:/images/general/feather" + + for (i = 0; i < featherFall.number; i++) { + if (component.status == Component.Ready) { + + featherObjList[i] = component.createObject(background); + + if (featherObjList[i] == null) { + console.log("error creating featherObj"); + console.log(component.errorString()); + return false; + } + + lowRange = lowRange + range; + highRange = highRange + range; + + var xpos = (highRange - range) * Math.random() + lowRange; + featherObjList[i].x = xpos; + + featherObjList[i].delay = Math.random() * 3000 * i; + + var swing = Math.random() * range; + if (swing < 100) + swing += 100; + + featherObjList[i].xMax = xpos + swing; + featherObjList[i].xMin = xpos - swing; + featherObjList[i].yMax = fallHeight; + featherObjList[i].source = resourcePath + (Math.floor(5 * Math.random()) + 1) + ".png"; + + featherObjList[i].startAnimation(); + } else { + console.log("error loading featherObj component"); + console.log(component.errorString()); + return false; + } + } + + return true; +} + +function destroy() { + for (var i = 0; i < featherFall.number; i++) { + if (featherObjList[i] == null) + continue; + + featherObjList[i].destroy() + } +} diff --git a/chicken-wranglers/src/sound/sound.cpp b/chicken-wranglers/src/sound/sound.cpp new file mode 100644 index 0000000..0661a63 --- /dev/null +++ b/chicken-wranglers/src/sound/sound.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + +#include "sound.h" + +#include +#include + +Sound::Sound(const QByteArray &sound, bool isLoop, QObject *parent) + : QThread(parent), m_sound(sound), m_isLoop(isLoop) +{ +} + +Sound::~Sound() +{ +} + +void Sound::run() +{ +} + +void Sound::play() +{ +} diff --git a/chicken-wranglers/src/sound/sound.h b/chicken-wranglers/src/sound/sound.h new file mode 100644 index 0000000..86e5017 --- /dev/null +++ b/chicken-wranglers/src/sound/sound.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef SOUND_H +#define SOUND_H + +#include +#include + +class Sound : public QThread +{ + Q_OBJECT + +public: + Sound(const QByteArray &sound, bool isLoop = false, QObject *parent = 0); + ~Sound(); + + void run(); + +public slots: + void play(); + +private: + QByteArray m_sound; + bool m_isLoop; +}; + +#endif diff --git a/chicken-wranglers/src/sound/sound.pri b/chicken-wranglers/src/sound/sound.pri new file mode 100644 index 0000000..c7853fe --- /dev/null +++ b/chicken-wranglers/src/sound/sound.pri @@ -0,0 +1,9 @@ +PATH = $$PWD + +HEADERS += \ + $$PATH/soundmanager.h \ + $$PATH/sound.h + +SOURCES += \ + $$PATH/soundmanager.cpp \ + $$PATH/sound.cpp diff --git a/chicken-wranglers/src/sound/sound_linux.cpp b/chicken-wranglers/src/sound/sound_linux.cpp new file mode 100644 index 0000000..d555eb3 --- /dev/null +++ b/chicken-wranglers/src/sound/sound_linux.cpp @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#include "sound_linux.h" + +#include +#include +#include + +#include +#include + +Sound::Sound(const QByteArray &sound, bool isLoop, QObject *parent) + : QThread(parent), m_sound(sound), m_isLoop(isLoop) +{ + int error; + + static const pa_sample_spec sampleSpec = { + PA_SAMPLE_S16LE, // format + 44100, // rate + 2 // channels + }; + + // create a new playback stream + if (!(m_playbackStream = pa_simple_new(NULL, "name", PA_STREAM_PLAYBACK, NULL, + "playback", &sampleSpec, NULL, NULL, &error))) { + // error + qWarning() << "Failure to create a new simple playback stream:" << error; + } +} + +Sound::~Sound() +{ + if (m_playbackStream) + pa_simple_free(m_playbackStream); +} + +void Sound::run() +{ + if (!m_playbackStream) { + qWarning() << "Failure to play: playback stream was not created."; + return; + } + + if (!m_sound.size()) { + qWarning() << "Failure to play: Invalid sound stream."; + return; + } + + int error; + int rtv; + + do { + rtv = pa_simple_write(m_playbackStream, m_sound.data(), (size_t) m_sound.size(), &error); + } while (m_isLoop && rtv >= 0); + + if (rtv < 0) + qWarning() << "Failure to play sound."; + + deleteLater(); +} + +void Sound::play() +{ + start(); +} diff --git a/chicken-wranglers/src/sound/sound_linux.h b/chicken-wranglers/src/sound/sound_linux.h new file mode 100644 index 0000000..ae2431a --- /dev/null +++ b/chicken-wranglers/src/sound/sound_linux.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef SOUND_H +#define SOUND_H + +#include +#include + +struct pa_simple; + +class Sound : public QThread +{ + Q_OBJECT + +public: + Sound(const QByteArray &sound, bool isLoop = false, QObject *parent = 0); + ~Sound(); + + void run(); + +public slots: + void play(); + +private: + pa_simple *m_playbackStream; + QByteArray m_sound; + bool m_isLoop; +}; + +#endif diff --git a/chicken-wranglers/src/sound/sound_linux.pri b/chicken-wranglers/src/sound/sound_linux.pri new file mode 100644 index 0000000..cfbfb58 --- /dev/null +++ b/chicken-wranglers/src/sound/sound_linux.pri @@ -0,0 +1,9 @@ +PATH = $$PWD + +HEADERS += \ + $$PATH/soundmanager.h \ + $$PATH/sound_linux.h + +SOURCES += \ + $$PATH/soundmanager.cpp \ + $$PATH/sound_linux.cpp diff --git a/chicken-wranglers/src/sound/soundmanager.cpp b/chicken-wranglers/src/sound/soundmanager.cpp new file mode 100644 index 0000000..9e190ba --- /dev/null +++ b/chicken-wranglers/src/sound/soundmanager.cpp @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + +#include "soundmanager.h" + +#include "global.h" + +#if defined(Q_WS_X11) +#include "sound_linux.h" +#else +#include "sound.h" +#endif + +#include + +SoundManager::SoundManager(QObject *parent) + : QObject(parent), m_isLoaded(false) +{ +} + +SoundManager *SoundManager::instance() +{ + static SoundManager *const soundManager = new SoundManager(); + + return soundManager; +} + +void SoundManager::load() +{ + if (m_isLoaded) + return; + + QString soundPath(Global::rootDirectory().absoluteFilePath() + "/sounds/"); + + QFile soundFile; + + soundFile.setFileName(soundPath + "match.raw"); + if (soundFile.open(QIODevice::ReadOnly)) { + m_backgroundSound = soundFile.readAll(); + soundFile.close(); + } else { + qWarning() << "Error loading sound file:" << soundFile.fileName(); + } + + soundFile.setFileName(soundPath + "laser.raw"); + if (soundFile.open(QIODevice::ReadOnly)) { + m_laserSound = soundFile.readAll(); + soundFile.close(); + } else { + qWarning() << "Error loading sound file:" << soundFile.fileName(); + } + + soundFile.setFileName(soundPath + "score.raw"); + if (soundFile.open(QIODevice::ReadOnly)) { + m_scoreSound = soundFile.readAll(); + soundFile.close(); + } else { + qWarning() << "Error loading sound file:" << soundFile.fileName(); + } + + m_isLoaded = true; +} + +void SoundManager::play(SoundType type) +{ + // NOTE: Currently sounds are supported only on Linux builds. + +#if defined(Q_WS_X11) + instance()->load(); + + Sound *sound = 0; + + switch (type) { + case Background: + sound = new Sound(instance()->m_backgroundSound, true); + break; + case Score: + sound = new Sound(instance()->m_scoreSound); + break; + case Laser: + sound = new Sound(instance()->m_laserSound); + break; + default: + qWarning("No valid sound type"); + return; + } + + sound->play(); +#endif +} diff --git a/chicken-wranglers/src/sound/soundmanager.h b/chicken-wranglers/src/sound/soundmanager.h new file mode 100644 index 0000000..52915a4 --- /dev/null +++ b/chicken-wranglers/src/sound/soundmanager.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef SOUNDMANAGER_H +#define SOUNDMANAGER_H + +#include +#include + +class SoundManager : public QObject +{ + Q_ENUMS(SoundType) + +public: + enum SoundType { + Background, + Score, + Laser + }; + + static void play(SoundType type); + +protected: + static SoundManager *instance(); + +private: + explicit SoundManager(QObject *parent = 0); + + void load(); + + bool m_isLoaded; + QByteArray m_backgroundSound; + QByteArray m_scoreSound; + QByteArray m_laserSound; +}; + +#endif diff --git a/chicken-wranglers/src/utils/global.cpp b/chicken-wranglers/src/utils/global.cpp new file mode 100644 index 0000000..21c647f --- /dev/null +++ b/chicken-wranglers/src/utils/global.cpp @@ -0,0 +1,135 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + +#include "global.h" + +// TODO: conditional compilation module instead of ifdef's +#ifdef Q_OS_SYMBIAN +#include +#include +#include +#endif + +#include +#include +#include +#include + +QTM_USE_NAMESPACE + +QFileInfo Global::rootDirectory() +{ +#ifdef Q_OS_SYMBIAN + return QFileInfo("c:\\data\\chicken-wranglers\\"); +#endif + QStringList pathList(QString(XSTR(DATA_PATH)).split(":", QString::SkipEmptyParts)); + + foreach (QFileInfo path, pathList) + if (path.exists() && path.isDir()) + return path; + + return QFileInfo(); +} + +QString Global::directionString(Global::Direction direction) +{ + switch (direction) { + case Global::DirectionUp: + return QString("Up"); + case Global::DirectionDown: + return QString("Down"); + case Global::DirectionRight: + return QString("Right"); + case Global::DirectionLeft: + return QString("Left"); + default: + return QString("Stop"); + } +} + +void Global::setScreenOrientation(const ScreenOrientation &orientation) +{ +#ifdef Q_OS_SYMBIAN + CAknAppUi *aknAppUi = dynamic_cast(CEikonEnv::Static()->AppUi()); + if (!aknAppUi) + return; + + switch (orientation) { + case Landscape: + aknAppUi->SetOrientationL(CAknAppUi::EAppUiOrientationLandscape); + break; + case Portrait: + aknAppUi->SetOrientationL(CAknAppUi::EAppUiOrientationPortrait); + break; + case Auto: + aknAppUi->SetOrientationL(CAknAppUi::EAppUiOrientationAutomatic); + } +#endif +} + +void Global::setPowerOn() +{ + QList devices(QBluetoothLocalDevice::allDevices()); + foreach(const QBluetoothHostInfo &i, devices) { + QBluetoothLocalDevice hci(i.getAddress()); + hci.setHostMode(QBluetoothLocalDevice::HostDiscoverable); + hci.powerOn(); + } +} + +Global::Environment Global::environment() +{ + // Set default environment to Linux + Environment result = Linux; +#if defined(Q_WS_MAEMO_5) + result = Maemo; +#elif defined(Q_WS_X11) + result = Linux; +#elif defined(Q_WS_S60) + result = Symbian; +#elif defined(Q_WS_WIN) + result = Windows; +#elif defined(Q_WS_MAC) + result = Mac; +#endif + + return result; +} diff --git a/chicken-wranglers/src/utils/global.h b/chicken-wranglers/src/utils/global.h new file mode 100644 index 0000000..b69b3cc --- /dev/null +++ b/chicken-wranglers/src/utils/global.h @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** This file is a part of QtChickenWranglers. +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).* +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +** COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +** POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + + +#ifndef GLOBAL_H +#define GLOBAL_H + +#define XSTR(s) STR(s) +#define STR(s) #s + +#include +#include +#include + +class Global : public QObject +{ + Q_OBJECT + + Q_ENUMS(Direction LaserDirection ScreenOrientation Environment) + +public: + enum Direction { + DirectionUp, + DirectionDown, + DirectionLeft, + DirectionRight, + DirectionStop + }; + + enum LaserDirection { + LaserUp, + LaserDown, + LaserLeft, + LaserRight + }; + + enum ScreenOrientation { + Portrait, + Landscape, + Auto + }; + + enum Environment { + Linux, + Symbian, + Maemo, + Windows, + Mac + }; + + static QFileInfo rootDirectory(); + + static QString directionString(Direction direction); + + static void setScreenOrientation(const ScreenOrientation &orientation = Portrait); + + static void setPowerOn(); + + static Environment environment(); + + static const int maximumPlayers = 4; +}; + +#endif diff --git a/chicken-wranglers/src/utils/utils.pri b/chicken-wranglers/src/utils/utils.pri new file mode 100644 index 0000000..b7444a5 --- /dev/null +++ b/chicken-wranglers/src/utils/utils.pri @@ -0,0 +1,9 @@ +DEFINES += DATA_PATH=$$SOURCE_TREE/:$$INSTALL_PREFIX/share/chicken-wranglers/ + +PATH = $$PWD + +HEADERS += \ + $$PATH/global.h + +SOURCES += \ + $$PATH/global.cpp -- cgit v1.2.3