Skip to content

Commit

Permalink
Added kid mode and network play as paid features for iOS, added simpl…
Browse files Browse the repository at this point in the history
…e UI for kids mode.
  • Loading branch information
slouken committed Jul 19, 2012
1 parent 2f93240 commit ed60a37
Show file tree
Hide file tree
Showing 13 changed files with 215 additions and 8 deletions.
Binary file modified Maelstrom_Data.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ distdir: $(DISTFILES)
|| exit 1; \
fi; \
done
-find $(distdir) -type d ! -perm -755 -exec chmod u+rwx,go+rx {} \; -o \
-find $(distdir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \
! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
! -type d ! -perm -400 -exec chmod a+r {} \; -o \
! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \
Expand Down
2 changes: 2 additions & 0 deletions game/MaelstromUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ MaelstromUI::CreateElement(UIBaseElement *parent, const char *type, const char *
element = new UIContainer(parent, name, new UIDrawEngine());
} else if (SDL_strcasecmp(type, "Button") == 0) {
element = new UIElementButton(parent, name, new UIDrawEngine());
} else if (SDL_strcasecmp(type, "Checkbox") == 0) {
element = new UIElementCheckbox(parent, name, new UIDrawEngine());
} else if (SDL_strcasecmp(type, "Icon") == 0) {
element = new UIElement(parent, name, new UIDrawEngineIcon());
} else if (SDL_strcasecmp(type, "Sprite") == 0) {
Expand Down
1 change: 1 addition & 0 deletions game/Maelstrom_Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ extern int gNumSprites;
#define DIALOG_ZAP "zap"
#define DIALOG_DAWN "dawn"
#define DIALOG_CHEAT "cheat"
#define DIALOG_FEATURE "feature"

// Sound resource definitions...
#define gShotSound 100
Expand Down
2 changes: 2 additions & 0 deletions game/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ libgame_a_SOURCES = \
controls.h \
fastrand.cpp \
fastrand.h \
features.cpp \
features.h \
game.cpp \
game.h \
gameinfo.cpp \
Expand Down
14 changes: 9 additions & 5 deletions game/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ libgame_a_AR = $(AR) $(ARFLAGS)
libgame_a_LIBADD =
am_libgame_a_OBJECTS = MacDialog.$(OBJEXT) MaelstromUI.$(OBJEXT) \
about.$(OBJEXT) controls.$(OBJEXT) fastrand.$(OBJEXT) \
game.$(OBJEXT) gameinfo.$(OBJEXT) gameover.$(OBJEXT) \
init.$(OBJEXT) load.$(OBJEXT) lobby.$(OBJEXT) main.$(OBJEXT) \
make.$(OBJEXT) myerror.$(OBJEXT) netplay.$(OBJEXT) \
object.$(OBJEXT) objects.$(OBJEXT) player.$(OBJEXT) \
rect.$(OBJEXT) replay.$(OBJEXT) scores.$(OBJEXT)
features.$(OBJEXT) game.$(OBJEXT) gameinfo.$(OBJEXT) \
gameover.$(OBJEXT) init.$(OBJEXT) load.$(OBJEXT) \
lobby.$(OBJEXT) main.$(OBJEXT) make.$(OBJEXT) \
myerror.$(OBJEXT) netplay.$(OBJEXT) object.$(OBJEXT) \
objects.$(OBJEXT) player.$(OBJEXT) rect.$(OBJEXT) \
replay.$(OBJEXT) scores.$(OBJEXT)
libgame_a_OBJECTS = $(am_libgame_a_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@
depcomp = $(SHELL) $(top_srcdir)/build-scripts/depcomp
Expand Down Expand Up @@ -197,6 +198,8 @@ libgame_a_SOURCES = \
controls.h \
fastrand.cpp \
fastrand.h \
features.cpp \
features.h \
game.cpp \
game.h \
gameinfo.cpp \
Expand Down Expand Up @@ -285,6 +288,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/about.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/controls.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fastrand.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/features.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/game.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gameinfo.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gameover.Po@am__quote@
Expand Down
107 changes: 107 additions & 0 deletions game/features.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
Maelstrom: Open Source version of the classic game by Ambrosia Software
Copyright (C) 1997-2011 Sam Lantinga
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@libsdl.org
*/

#include "Maelstrom_Globals.h"
#include "features.h"

#include "../screenlib/UIElementCheckbox.h"


void InitFeatures()
{
#ifdef __IPHONEOS__
// You have to buy features on the iOS app
#else
prefs->SetBool(FEATURE_KIDMODE, true);
prefs->SetBool(FEATURE_NETWORK, true);
#endif
}

bool HasFeature(const char *feature)
{
return prefs->GetBool(feature);
}

static const char *current_feature;

static void FeatureDialogDone(UIDialog *dialog, int status)
{
if (status == 1) {
// Buy the feature for this platform
#ifdef __IPHONEOS__
#error Implement Store Kit
#else
CompleteFeatureDialog(current_feature, true);
#endif
} else {
CompleteFeatureDialog(current_feature, false);
}
}

void ShowFeature(const char *feature)
{
UIDialog *dialog;

if (current_feature) {
// Uh oh, somehow trying to show multiple features at once
return;
}

dialog = ui->GetPanel<UIDialog>(DIALOG_FEATURE);
if (dialog) {
current_feature = feature;
dialog->SetDialogHandlers(NULL, FeatureDialogDone);
ui->ShowPanel(dialog);
}
}

void CompleteFeatureDialog(const char *feature, bool success)
{
UIPanel *panel;
UIDialog *dialog;
UIElementCheckbox *checkbox = NULL;

if (success) {
prefs->SetBool(feature, true);
prefs->Save();

if (SDL_strcmp(feature, FEATURE_KIDMODE) == 0) {
// Enable kid mode
panel = ui->GetPanel<UIPanel>(PANEL_MAIN);
if (panel) {
checkbox = panel->GetElement<UIElementCheckbox>("KidMode");
}
if (checkbox) {
checkbox->SetChecked(true);
}
}
if (SDL_strcmp(feature, FEATURE_NETWORK) == 0) {
// Start multiplayer game
dialog = ui->GetPanel<UIDialog>(DIALOG_LOBBY);
if (dialog) {
ui->ShowPanel(dialog);
}
}
}
current_feature = NULL;
}

31 changes: 31 additions & 0 deletions game/features.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Maelstrom: Open Source version of the classic game by Ambrosia Software
Copyright (C) 1997-2011 Sam Lantinga
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@libsdl.org
*/

/* Definitions of special features that can be bought in the store */

#define FEATURE_KIDMODE "Feature.KidMode"
#define FEATURE_NETWORK "Feature.Network"

extern void InitFeatures();
extern bool HasFeature(const char *feature);
extern void ShowFeature(const char *feature);
extern void CompleteFeatureDialog(const char *feature, bool success);
4 changes: 4 additions & 0 deletions game/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "player.h"
#include "colortable.h"
#include "fastrand.h"
#include "features.h"
#include "MaelstromUI.h"
#include "../screenlib/UIElement.h"

Expand Down Expand Up @@ -685,6 +686,9 @@ int DoInitializations(Uint32 window_flags, Uint32 render_flags)
// -- Load our controls
LoadControls();

// -- Load our features
InitFeatures();

Uint32 init_flags = (SDL_INIT_VIDEO|SDL_INIT_AUDIO);
#ifdef SDL_INIT_JOYSTICK
init_flags |= SDL_INIT_JOYSTICK;
Expand Down
35 changes: 34 additions & 1 deletion game/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "about.h"
#include "game.h"
#include "netplay.h"
#include "features.h"
#include "main.h"

#include "../screenlib/UIDialog.h"
Expand Down Expand Up @@ -81,6 +82,20 @@ static void RunPlayGame(void*)
gGameInfo.SetPlayerSlot(0, prefs->GetString(PREFERENCES_HANDLE), CONTROL_LOCAL);
RunSinglePlayerGame();
}
static void RunMultiplayerGame(void*)
{
UIDialog *dialog;

if (!HasFeature(FEATURE_NETWORK)) {
ShowFeature(FEATURE_NETWORK);
return;
}

dialog = ui->GetPanel<UIDialog>(DIALOG_LOBBY);
if (dialog) {
ui->ShowPanel(dialog);
}
}
static void RunReplayGame(const char *file)
{
if (!gReplay.Load(file)) {
Expand Down Expand Up @@ -187,6 +202,19 @@ static void RunScreenshot(void*)
{
screen->ScreenDump("ScoreDump", 64, 48, 298, 384);
}
static void UpdateKidMode(void *param)
{
UIElementCheckbox *checkbox = (UIElementCheckbox*)param;

if (checkbox->IsChecked()) {
if (!HasFeature(FEATURE_KIDMODE)) {
ShowFeature(FEATURE_KIDMODE);
checkbox->SetChecked(false);
}
}

checkbox->SaveData(prefs);
}

class RunReplayCallback : public UIClickCallback
{
Expand Down Expand Up @@ -389,6 +417,7 @@ MainPanelDelegate::OnLoad()
int i;
UIElement *label;
UIElementButton *button;
UIElementCheckbox *checkbox;

/* Set the version */
label = m_panel->GetElement<UIElement>("version");
Expand All @@ -403,7 +432,7 @@ MainPanelDelegate::OnLoad()
}
button = m_panel->GetElement<UIElementButton>("MultiplayerButton");
if (button) {
button->SetClickCallback(new UIDialogLauncher(ui, DIALOG_LOBBY));
button->SetClickCallback(RunMultiplayerGame);
}
button = m_panel->GetElement<UIElementButton>("ControlsButton");
if (button) {
Expand Down Expand Up @@ -445,6 +474,10 @@ MainPanelDelegate::OnLoad()
if (button) {
button->SetClickCallback(RunScreenshot);
}
checkbox = m_panel->GetElement<UIElementCheckbox>("KidMode");
if (checkbox) {
checkbox->SetClickCallback(UpdateKidMode, checkbox);
}

for (i = 0; i < 9; ++i) {
SDL_snprintf(name, sizeof(name), "SetVolume%d", i);
Expand Down
2 changes: 1 addition & 1 deletion screenlib/UIElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
class UIClickCallback
{
public:
virtual ~UIClickCallback() { }
virtual ~UIClickCallback() { }

virtual void operator()() = 0;
};
Expand Down
19 changes: 19 additions & 0 deletions screenlib/UIElementCheckbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,41 @@ UIElementCheckbox::UIElementCheckbox(UIBaseElement *parent, const char *name, UI
{
m_checked = false;
m_valueBinding = NULL;
for (int i = 0; i < SDL_arraysize(m_images); ++i) {
m_images[i] = NULL;
}
}

UIElementCheckbox::~UIElementCheckbox()
{
if (m_valueBinding) {
SDL_free(m_valueBinding);
}
for (int i = 0; i < SDL_arraysize(m_images); ++i) {
if (m_images[i]) {
SDL_free(m_images[i]);
}
}
}

bool
UIElementCheckbox::Load(rapidxml::xml_node<> *node, const UITemplates *templates)
{
rapidxml::xml_attribute<> *attr;

if (!UIElementButton::Load(node, templates)) {
return false;
}

attr = node->first_attribute("checkedImage", 0, false);
if (attr) {
m_images[1] = SDL_strdup(attr->value());
attr = node->first_attribute("image", 0, false);
if (attr) {
m_images[0] = SDL_strdup(attr->value());
}
}

/* Call SetChecked() to trigger derived classes' behaviors */
bool checked;
if (LoadBool(node, "checked", checked)) {
Expand Down
4 changes: 4 additions & 0 deletions screenlib/UIElementCheckbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ DECLARE_TYPESAFE_CLASS(UIElementButton)
void SetChecked(bool checked) {
if (checked != m_checked) {
m_checked = checked;
if (m_images[m_checked]) {
SetImage(m_images[m_checked]);
}
OnChecked(checked);
}
}
Expand All @@ -58,6 +61,7 @@ DECLARE_TYPESAFE_CLASS(UIElementButton)
protected:
bool m_checked;
char *m_valueBinding;
char *m_images[2];
};

#endif // _UIElementCheckbox_h

0 comments on commit ed60a37

Please sign in to comment.