From: Reto Zingg Date: Fri, 25 Dec 2009 18:33:15 +0000 (+0200) Subject: refraction part 1 X-Git-Tag: refraction-works~3 X-Git-Url: http://git.maemo.org/git/?p=mancala;a=commitdiff_plain;h=093846efa820badbeb1d80f2ec677fd617072bf8 refraction part 1 --- diff --git a/.gitignore b/.gitignore index 341e353..3a1f3cf 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,9 @@ src/.libs *.dsc src/build-stamp src/mancala +src/launcher/mancala-launcher +src/plugin/mancala-ui-plugin.o +src/plugin/mancala-ui-plugin.so build-stamp debian/docs debian/maemo-mancala/ diff --git a/Makefile b/Makefile index e825012..986e0e9 100644 --- a/Makefile +++ b/Makefile @@ -8,9 +8,14 @@ install: mkdir -p $(DESTDIR)/usr/share/applications/hildon mkdir -p $(DESTDIR)/usr/share/icons/hicolor/40x40/apps mkdir -p $(DESTDIR)/usr/share/dbus-1/services + mkdir -p $(DESTDIR)/home/opt/mancala/data/ + mkdir -p $(DESTDIR)/home/opt/mancala/bin/ cp data/mancala.desktop $(DESTDIR)/usr/share/applications/hildon cp data/mancala.png $(DESTDIR)/usr/share/icons/hicolor/40x40/apps/mancala.png cp data/com.nokia.mancala.service $(DESTDIR)/usr/share/dbus-1/services/ + cp data/com.nokia.mancala_startup.service $(DESTDIR)/usr/share/dbus-1/services/ + cp data/mancala.conf $(DESTDIR)/home/opt/mancala/data/ + cp data/mancala.sh $(DESTDIR)/home/opt/mancala/bin/ clean: rm -f build-stamp config.guess config.sub diff --git a/data/com.nokia.mancala.service b/data/com.nokia.mancala.service index de77262..01bfde4 100644 --- a/data/com.nokia.mancala.service +++ b/data/com.nokia.mancala.service @@ -1,3 +1,3 @@ [D-BUS Service] Name=com.nokia.mancala -Exec=/home/opt/mancala/bin/mancala +Exec=/home/opt/mancala/bin/mancala-launcher diff --git a/data/com.nokia.mancala_startup.service b/data/com.nokia.mancala_startup.service new file mode 100644 index 0000000..4b2298b --- /dev/null +++ b/data/com.nokia.mancala_startup.service @@ -0,0 +1,3 @@ +[D-BUS Service] +Name=com.nokia.mancala_startup +Exec=/home/opt/mancala/bin/mancala.sh diff --git a/data/mancala.conf b/data/mancala.conf new file mode 100644 index 0000000..96fa283 --- /dev/null +++ b/data/mancala.conf @@ -0,0 +1,20 @@ +[Startup Entry] +# the name of the application +Name=mancala +# the current version of the application +Version=0.2 +# the title that is used, if not specified by the GettextPackage +Title=Mancala +# the GettextPackage to be used to locate the title string +# GettextPackage=example +# if the TitleId is defined, it searches for it inside the gettext package +# TitleId=example_title +# if the game has a plug-in +PluginPath=/home/opt/mancala/plugin/mancala-ui-plugin.so +# the games-startup screen image +Image=/home/opt/mancala/data/mancala.png +# the D-BUS service, path and interface names +ServiceName=com.nokia.mancala +PathName=/com/nokia/mancala +InterfaceName=com.nokia.mancala + diff --git a/data/mancala.desktop b/data/mancala.desktop index 4697e22..8ce24f8 100644 --- a/data/mancala.desktop +++ b/data/mancala.desktop @@ -1,16 +1,12 @@ [Desktop Entry] Encoding=UTF-8 -Version=0.1 +Version=0.2 Name=Mancala Comment=Mancala game for Maemo devices -Exec=/home/opt/mancala/bin/mancala +Exec=/home/opt/mancala/bin/mancala.sh Icon=mancala -Terminal=false Type=Application Categories=Games X-HildonDesk-ShowInToolbar=true -X-Osso-Type=application/x-executable X-Window-Icon=mancala -X-Osso-Service=com.nokia.mancala - - +X-Osso-Service=com.nokia.mancala_startup \ No newline at end of file diff --git a/data/mancala.game b/data/mancala.game new file mode 100644 index 0000000..88bc54e --- /dev/null +++ b/data/mancala.game @@ -0,0 +1,7 @@ +mancala +/home/opt/mancala/bin/mancala +com.nokia.mancala +/com/nokia/mancala +com.nokia.mancala +0.2 + diff --git a/data/mancala.sh b/data/mancala.sh new file mode 100755 index 0000000..91844cb --- /dev/null +++ b/data/mancala.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +/usr/bin/osso_games_startup /home/opt/mancala/data/mancala.conf + diff --git a/debian/changelog b/debian/changelog index 8d326ff..528f5b3 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,15 @@ +mancala (0.2.0-2) unstable; urgency=low + + * with plugin + + -- Reto Zingg Fri, 25 Dec 2009 18:01:34 +0200 + +mancala (0.2.0-1) unstable; urgency=low + + * refractoring + + -- Reto Zingg Fri, 25 Dec 2009 13:40:07 +0200 + mancala (0.1.10-2) unstable; urgency=low * updated control file diff --git a/debian/control b/debian/control index 7eb681a..813e783 100644 --- a/debian/control +++ b/debian/control @@ -9,7 +9,7 @@ Homepage: http://mancala.garage.maemo.org/ Package: mancala Architecture: any Section: user/games -Depends: ${shlibs:Depends}, ${misc:Depends} +Depends: ${shlibs:Depends}, ${misc:Depends}, osso-games-startup Description: Mancala, the ancient African game of skill! Maemo version of mancala from http://cmancala.sourceforge.net/ Please file bugs here for this maemo version: diff --git a/src/Makefile b/src/Makefile index 5e40a78..ea07efa 100644 --- a/src/Makefile +++ b/src/Makefile @@ -17,15 +17,20 @@ CC = gcc DBG = gdb STD = _GNU_SOURCE CFLAGS = `sdl-config --cflags` -I/usr/local/include/SDL `pkg-config hildon-1 --cflags` -I/usr/include/dbus-1.0/ -I/usr/lib/dbus-1.0/include/ -LFLAGS = `sdl-config --static-libs ` -lSDL_image -lSDL_ttf -lSDL_mixer `pkg-config hildon-1 --libs` `pkg-config --libs libosso` +LFLAGS = `sdl-config --static-libs ` -lSDL_image -lSDL_ttf -lSDL_mixer `pkg-config hildon-1 --libs` `pkg-config --libs libosso` -lhgw -MAIN_OBJ = main.o graphics.o mancala.o sounds.o play.o +# MAIN_OBJ = main.o graphics.o mancala.o sounds.o play.o +MAIN_OBJ = graphics.o mancala.o sounds.o play.o callbacks.o TEST_OBJ = ai-test.o mancala.o NORMAL = ai.o RECURSE = ai-init.o ai-recurse.o ULTIMATE = ai-init.o ai-ultimate.o +subsystem: + $(MAKE) -C launcher + $(MAKE) -C plugin + #'$<' is filename of input, '$@' is filename of output .c.o: $(CC) -c -g$(DBG) -Wall $(CFLAGS) -D$(STD) $< @@ -33,6 +38,8 @@ ULTIMATE = ai-init.o ai-ultimate.o $(CC) -c -g$(DBG) -Wall $(CFLAGS) -D$(STD) $< all: $(MAIN_OBJ) $(NORMAL) + $(MAKE) -C launcher all + $(MAKE) -C plugin all $(CC) $(MAIN_OBJ) $(NORMAL) $(LFLAGS) -o mancala recurse: $(MAIN_OBJ) $(RECURSE) @@ -57,6 +64,8 @@ install: all cp ../data/*.png $(DESTDIR)/home/opt/mancala/data/ cp ../data/*.wav $(DESTDIR)/home/opt/mancala/data/ cp ../data/*.ttf $(DESTDIR)/home/opt/mancala/data/ + $(MAKE) -C launcher install + $(MAKE) -C plugin install uninstall: @@ -65,9 +74,13 @@ uninstall: clean: rm -f *.o *.core *.swp *~ *.log + $(MAKE) -C launcher clean + $(MAKE) -C plugin clean clobber: clean rm -f mancala ai-test + $(MAKE) -C launcher clobber + $(MAKE) -C plugin clobber distclean: clobber @echo "No configuration files to distclean yet." diff --git a/src/callbacks.c b/src/callbacks.c new file mode 100644 index 0000000..70215ed --- /dev/null +++ b/src/callbacks.c @@ -0,0 +1,58 @@ +/* +* This file is part of Crazy Parking +* +* Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia +* http://www.indt.org/maemo +* +* This software is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public License +* as published by the Free Software Foundation; either version 2.1 of +* the License, or (at your option) any later version. +* +* This software 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this software; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +* 02110-1301 USA +* +*/ +#include +#include +#include "callbacks.h" +// #include "images.h" +// #include "level.h" + +// Pause the game +int exit_callback(int errcode) { +// FILE *han; + +// // Save state +// han = fopen("/tmp/.crazyparking-save", "wb"); +// if (han) { +// fwrite(&actual_level, sizeof(int), 1, han); +// fwrite(&moves, sizeof(int), 1, han); +// fwrite(car, sizeof(struct CAR), cars, han); +// fclose(han); +// } + fprintf(stderr, "exit_callback called...\n"); + + return 0; +} + +// Quit game +int quit_callback(int errcode) { +// remove("/tmp/.crazyparking-save"); + fprintf(stderr, "quit_callback called...\n"); + hgw_context_compat_destroy_quit(hgw_context); + return 0; +} + +int flush_callback(int errcode) { +// remove("/tmp/.crazyparking-save"); + fprintf(stderr, "quit_callback called...\n"); + return 0; +} diff --git a/src/callbacks.h b/src/callbacks.h new file mode 100644 index 0000000..2afca93 --- /dev/null +++ b/src/callbacks.h @@ -0,0 +1,27 @@ +/* +* This file is part of Crazy Parking +* +* Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia +* http://www.indt.org/maemo +* +* This software is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public License +* as published by the Free Software Foundation; either version 2.1 of +* the License, or (at your option) any later version. +* +* This software 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this software; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +* 02110-1301 USA +* +*/ +extern HgwContext *hgw_context; + +int exit_callback(int errcode/*, AppData *app_data*/); +int quit_callback(int errcode/*, AppData *app_data*/); +int flush_callback(int errcode); diff --git a/src/launcher/Makefile b/src/launcher/Makefile new file mode 100644 index 0000000..a09eef0 --- /dev/null +++ b/src/launcher/Makefile @@ -0,0 +1,45 @@ +# GNU Makefile -- Makefile +# 2009 Reto Zingg + + +CC = gcc +# DBG = gdb +# STD = _GNU_SOURCE +# CFLAGS = `sdl-config --cflags` -I/usr/local/include/SDL `pkg-config hildon-1 --cflags` -I/usr/include/dbus-1.0/ -I/usr/lib/dbus-1.0/include/ +# LFLAGS = `sdl-config --static-libs ` -lSDL_image -lSDL_ttf -lSDL_mixer `pkg-config hildon-1 --libs` `pkg-config --libs libosso` -lhgw + +# MAIN_OBJ = main.o graphics.o mancala.o sounds.o play.o +# MAIN_OBJ = graphics.o mancala.o sounds.o play.o callbacks.o +# TEST_OBJ = ai-test.o mancala.o + +# NORMAL = ai.o +# RECURSE = ai-init.o ai-recurse.o +# ULTIMATE = ai-init.o ai-ultimate.o + +#'$<' is filename of input, '$@' is filename of output +# .c.o: +# $(CC) -c -g$(DBG) -Wall $(CFLAGS) -D$(STD) $< +# .h.o: +# $(CC) -c -g$(DBG) -Wall $(CFLAGS) -D$(STD) $< + +all: + $(CC) mancala-launcher.c -o mancala-launcher + +install: all + mkdir -p $(DESTDIR)/home/opt/mancala/bin/ + cp ./mancala-launcher $(DESTDIR)/home/opt/mancala/bin/mancala-launcher + +uninstall: + rm -rf $(DESTDIR)/home/opt/mancala/mancala-launcher + +clean: + rm -f *.o *.core *.swp *~ *.log + +clobber: clean + rm -f mancala-launcher + +distclean: clobber + @echo "No configuration files to distclean yet." + @echo "I will do my best to make some! ;-)" + +# End Makefile diff --git a/src/launcher/mancala-launcher.c b/src/launcher/mancala-launcher.c new file mode 100644 index 0000000..136b9af --- /dev/null +++ b/src/launcher/mancala-launcher.c @@ -0,0 +1,27 @@ +/** + @file crazyparking.c + + Wrapper crazyparking launcher +

+ Copyright (c) 2005 INdT. All eigths reserved. + + @author Andre Moreira Magalhaes +*/ + +#include +#include + +char *argh[] = { "/usr/games/wrapper/wrapper", + "/home/opt/mancala/data/mancala.game", + NULL }; + +int main(int argc, char *argv[]) +{ + fprintf(stderr, "exec laucher...\n"); + + if (execv ("/usr/games/wrapper/wrapper", argh) == -1) { + fprintf(stderr, "can not execute wrapper\n"); + } + + return 0; +} diff --git a/src/main.c b/src/main.c index 2214dcd..5be3b90 100644 --- a/src/main.c +++ b/src/main.c @@ -190,3 +190,4 @@ int main (int argc, char **argv) { return 0; } + diff --git a/src/play.c b/src/play.c index c833d56..f8b6639 100644 --- a/src/play.c +++ b/src/play.c @@ -22,6 +22,8 @@ */ #include +#include +#include #include "SDL_mixer.h" #include "SDL.h" @@ -34,13 +36,16 @@ #include "sounds.h" #include "play.h" +#include "callbacks.h" + // the surfaces SDL_Surface *screen, *board, *title_text, *tile, *stone[STONE_MAX+1], *exit_text; // the fonts TTF_Font *title_font, *home_font, *board_font; // The sound effects that will be used Mix_Chunk *pick = NULL; - +// the hildon-game-wrapper context +HgwContext *hgw_context = NULL; void sdl_clean_up(){ @@ -392,3 +397,31 @@ int play() { } + +int main(int argc, char **argv) { + +// #if HGW_FUNC + hgw_context = hgw_context_compat_init(argc, argv); + if (!hgw_context) { + fprintf(stderr, "Cannot init hildon-games-startup!\n"); + return 0; + } + hgw_compat_set_cb_exit(hgw_context, exit_callback); + hgw_compat_set_cb_quit(hgw_context, quit_callback); + hgw_compat_set_cb_flush(hgw_context, flush_callback); + if(!hgw_context_compat_check(hgw_context)) return 0; + + /* hildon-games-wrapper part */ + hgw_msg_compat_receive(hgw_context, 0); + usleep(100); +// #endif + // Main game + play(); + +// #if HGW_FUNC + hgw_context_compat_destroy_deinit(hgw_context); +// #endif + + return 0; +} + diff --git a/src/plugin/Makefile b/src/plugin/Makefile new file mode 100644 index 0000000..9496e4e --- /dev/null +++ b/src/plugin/Makefile @@ -0,0 +1,37 @@ +# GNU Makefile -- Makefile +# 2009 Reto Zingg + +CC = gcc +DBG = gdb +STD = _GNU_SOURCE +CFLAGS = `pkg-config hildon-1 --cflags` -I/usr/include/dbus-1.0/ -I/usr/lib/dbus-1.0/include/ +LFLAGS = -shared `pkg-config hildon-1 --libs` + +MAIN_OBJ = mancala-ui-plugin.o + + + +#'$<' is filename of input, '$@' is filename of output +.c.o: + $(CC) -c -g$(DBG) -Wall $(CFLAGS) -D$(STD) $< +.h.o: + $(CC) -c -g$(DBG) -Wall $(CFLAGS) -D$(STD) $< + +all: $(MAIN_OBJ) + $(CC) $(LFLAGS) $(MAIN_OBJ) -o mancala-ui-plugin.so + +install: all + mkdir -p $(DESTDIR)/home/opt/mancala/plugin/ + cp mancala-ui-plugin.so $(DESTDIR)/home/opt/mancala/plugin/ + +clean: + rm -f *.o *.core *.swp *~ *.log + +clobber: clean + rm -f mancala-ui-plugin.so + +distclean: clobber + @echo "No configuration files to distclean yet." + @echo "I will do my best to make some! ;-)" + +# End Makefile diff --git a/src/plugin/mancala-ui-plugin.c b/src/plugin/mancala-ui-plugin.c new file mode 100644 index 0000000..50e0ef4 --- /dev/null +++ b/src/plugin/mancala-ui-plugin.c @@ -0,0 +1,133 @@ +/* +* This file is part of Crazyparking +* +* Copyright (C) 2005 INdT - Instituto Nokia de Tecnologia +* http://www.indt.org/maemo +* +* This software is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public License +* as published by the Free Software Foundation; either version 2.1 of +* the License, or (at your option) any later version. +* +* This software 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this software; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +* 02110-1301 USA +* +*/ + + +#include +#include +#include +#include + + +static GtkWidget *load_plugin (void); +static void unload_plugin (void); +static void write_config (void); +static GtkWidget **load_menu (guint *); +static void update_menu (void); + +static GameStartupInfo gs; + + +GtkWidget *settings_item; +GtkWidget *settings_menu; +GtkWidget *difficulty_item; +GtkWidget *difficulty_menu; +GtkWidget *menu_items[2]; + +static StartupPluginInfo plugin_info = { + load_plugin, + unload_plugin, + write_config, + load_menu, + update_menu, + NULL +}; + + +STARTUP_INIT_PLUGIN(plugin_info, gs, FALSE, FALSE) + +static GtkWidget *load_plugin (void) +{ + GtkWidget *textbox; + GtkTextBuffer *textbox_buffer; + gchar *textbox_text; + PangoFontDescription *font_desc; + GtkWidget *pannable_text; + + /* Create and pack labels */ + textbox_text = g_strdup_printf("Welcome to Mancala, the ancient African game of skill!\n\nMancala is a very simple, easy-to-learn game. Each player begins with a horizontal row of holes or pits filled with a certain number of stones. At either end of the board are the players' home pits, which are used to keep score. In this case, the human player has the left home pit and the upper row holes. A move is made by clicking into the hole you wish to move from. The stones are then picked up and distributed, one to each hole, moving toward your home pit is reached, and then moving through your opponent's row, bypassing his/her home, and moving back towards in a circle (counterclockwise), until all the stones have been distributed.\n\nIf the last stone is placed in your home, you receive an extra turn. If the last stone lands in an empty hole on your side, you 'capture' the stones in the opposite hole on your opponent's side, moving them to your home.\n\nThe game ends when one player cannot play (ie. there are no stones on his/her side of the board. The player who has the most stones on his/her *side* wins."); + + textbox = hildon_text_view_new(); + gtk_text_view_set_editable(GTK_TEXT_VIEW(textbox), FALSE); + // gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(textbox), FALSE); + gtk_text_view_set_indent(GTK_TEXT_VIEW(textbox), 10); + gtk_text_view_set_left_margin(GTK_TEXT_VIEW(textbox), 10); + gtk_text_view_set_right_margin(GTK_TEXT_VIEW(textbox), 10); + gtk_text_view_set_pixels_above_lines(GTK_TEXT_VIEW(textbox), 3); + gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(textbox), 2); + gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(textbox), GTK_WRAP_WORD); + // gtk_widget_set_sensitive(textbox, FALSE); + font_desc = pango_font_description_from_string ("vera 18"); + gtk_widget_modify_font(textbox, font_desc); + pango_font_description_free (font_desc); + + textbox_buffer = hildon_text_view_get_buffer (HILDON_TEXT_VIEW (textbox)); + + gtk_text_buffer_set_text(textbox_buffer, textbox_text, -1); + + + pannable_text = hildon_pannable_area_new(); + hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA(pannable_text), textbox); + + return GTK_WIDGET(pannable_text); +} + +static void +unload_plugin (void) +{ + +} + +static void +write_config (void) +{ + +} + +static GtkWidget **load_menu (guint *nitems) +{ + + int enable_sound; + //number of entries in osso-games-startup main menu for this game + *nitems = 1; + + settings_item = gtk_menu_item_new_with_label ("Settings"); + settings_menu = gtk_menu_new (); + menu_items[0] = settings_item; + gtk_menu_item_set_submenu (GTK_MENU_ITEM (settings_item), settings_menu); + + //difficulty settings + difficulty_menu = gtk_menu_new (); + difficulty_item = gtk_menu_item_new_with_label ("Difficulty"); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (difficulty_item), difficulty_menu); + gtk_menu_append (GTK_MENU (settings_menu), difficulty_item); + + + return GTK_WIDGET(menu_items); +} + + + +static void update_menu (void) +{ + +} \ No newline at end of file