Skip to content

Commit

Permalink
added difficulty, changed version and fixed cancel building city
Browse files Browse the repository at this point in the history
  • Loading branch information
zielmicha committed Apr 10, 2012
1 parent d78a70d commit 8cc7ac1
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 6 deletions.
4 changes: 2 additions & 2 deletions android/info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ PKG_NAME_NOSPACE="Freeciv"
PKG_PACKAGE="pl.org.zielinscy.freeciv"
PKG_ARG="--orientation landscape --permission INTERNET --icon $BASE/freeciv-client.png --presplash $BASE/presplash.png"
# --presplash $GFX/splashscreen.png --icon $GFX/logo.png
RELEASE_VERSION="1.0.10"
RELEASE_VERSION_ID="1010" # remember to change civsync.ua in sync.py:38
RELEASE_VERSION="1.0.11"
RELEASE_VERSION_ID="1011" # remember to change civsync.ua in sync.py:38
ANDROID_PATH="$HOME/apps/android-sdk-linux_x86/tools:$HOME/apps/android-ndk-r6b"
1 change: 1 addition & 0 deletions callglue
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void key_end_turn()
int meswin_get_num_messages(void)
const struct message *meswin_get_message(int message_index)
void finish_city_at_unit(int unit, char* title)
void cancel_city_at_unit(int unit)
int canvas_pos_to_nearest_tile_id(int x, int y)
void set_mapview_origin(int gui_x0, int gui_y0)
PyObject* get_map_view_origin()
Expand Down
6 changes: 5 additions & 1 deletion lib/citydlg.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ def make_ui(self):
self.citypanel.add(ui.Label(self.city.get_name()))
self.citypanel.add(self.get_citizen_icons())
self.citypanel.add(self.canvas)
self.citypanel.add(self.info_label)
self.citypanel.update_layout()
self.citypanel.add(ui.ScrollWrapper(self.info_label,
height=ui.screen_height - self.citypanel.size[1] - self.citypanel.spacing,
width=self.canvas.size[0]))

self.ui = self # ui.ScrollWrapper(self)

Expand Down Expand Up @@ -66,6 +69,7 @@ def make_ui(self):
#print self.city.get_buildable_improvements()
#print self.city.get_buildable_units()

self.citypanel.update_layout()
self.update_layout()
#print self.city.get_production_cost()

Expand Down
2 changes: 2 additions & 0 deletions lib/client/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def popup_newcity_dialog(unit, default_name):
break
if text:
freeciv.func.finish_city_at_unit(unit, text)
else:
freeciv.func.cancel_city_at_unit(unit)

@freeciv.register
def popup_unit_select_dialog(tile):
Expand Down
4 changes: 2 additions & 2 deletions lib/menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ def main_menu():
ui.replace(menu)

def new_game_menu():
menu = ui.Menu(center=0.7)
menu = ui.Menu(force_full = False)

menu.add('Tutorial', tutorial.start)
menu.add('Random', save.new_game)
menu.add('Scenario', save.load_scenario)

ui.set_dialog(menu, scroll=True)
ui.set_dialog(menu)

def notify_update(url):
if not main_menu_item:
Expand Down
15 changes: 15 additions & 0 deletions lib/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ def setup_ui(self):

self.pick_nation_button = ui.Button('...', self.pick_nation)
self.set_leader_name_button = ui.Button('...', self.set_leader_name)
self.difficulty_button = ui.Button('...', self.set_difficulty)

self.add(ui.Button('Start game!', start_client))
self.add(self.pick_nation_button)
self.add(self.set_leader_name_button)
self.add(self.difficulty_button)
self.add(ui.Button('Server command', server_command_dialog))

self.aicount_button = ui.Button('...', self.set_aicount)
Expand All @@ -86,8 +88,10 @@ def setup_ui(self):
self.leader_name = 'Player'
self.city_style = 1
self.leader_sex = 2
self.difficulty = 'easy'

self.set_nation_settings()
self.set_difficulty_settings()

def back(self):
client.client.disconnect()
Expand All @@ -99,6 +103,17 @@ def set_leader_name(self):
self.leader_name = name
self.set_nation_settings()

def set_difficulty(self):
def set_do(name):
self.difficulty = name
self.set_difficulty_settings()

ui.show_list_dialog(['novice', 'easy', 'normal', 'hard'], callback=set_do)

def set_difficulty_settings(self):
client.client.chat('/%s' % self.difficulty)
self.difficulty_button.set_text('Difficulty: %s' % self.difficulty)

def set_aicount(self, val=None):
cmd = val or uidialog.inputbox('How many computer enemies will you fight?')
try:
Expand Down
2 changes: 1 addition & 1 deletion lib/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def apply_user_agent_change(ua):
civsync.USER_AGENT = ua

features.set_applier('civsync.ua', apply_user_agent_change)
features.set('civsync.ua', 'CivSyncAndroid/1010')
features.set('civsync.ua', 'CivSyncAndroid/1011')
features.add_feature('civsync.enable', False, type=bool)

session = None
Expand Down
22 changes: 22 additions & 0 deletions lib/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import traceback

import uidialog
import functools
import features
import osutil
import os
Expand Down Expand Up @@ -85,6 +86,27 @@ def call_callback():
def not_implemented():
message('Sorry. This feature is not implemented.\nCheck civ.zielm.com for updates.')

def show_list_dialog(items, callback=None, get_text_func=None):
def default_get_text_func(it):
if isinstance(it, tuple):
label, action = it
return label
else:
return it

def default_callback(it):
return it[1]()

def clicked(it):
back(anim=False)
(callback or default_callback)(it)

ui = LinearLayoutWidget()
for item in items:
label = (get_text_func or default_get_text_func)(item)
ui.add(Button(label, functools.partial(clicked, item) ))
set_dialog(ui)

class Dialog(object):
def __init__(self, screen, item):
self.item = item
Expand Down
12 changes: 12 additions & 0 deletions src/callauto.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,16 @@ static PyObject* python_finish_city_at_unit(PyObject* self, PyObject* args) {
finish_city_at_unit(arg_unit, arg_title);
return Py_BuildValue("i", 0);
}
// void cancel_city_at_unit(int unit)
void cancel_city_at_unit(int unit);

static PyObject* python_cancel_city_at_unit(PyObject* self, PyObject* args) {
int arg_unit;
if(PyArg_ParseTuple(args, "i", &arg_unit) == 0) return NULL;

cancel_city_at_unit(arg_unit);
return Py_BuildValue("i", 0);
}
// int canvas_pos_to_nearest_tile_id(int x, int y)
int canvas_pos_to_nearest_tile_id(int x, int y);

Expand Down Expand Up @@ -1405,6 +1415,8 @@ void* ptr;
PY_CALL("ssi", "add_function", "meswin_get_message", (int)ptr);
ptr = python_finish_city_at_unit;
PY_CALL("ssi", "add_function", "finish_city_at_unit", (int)ptr);
ptr = python_cancel_city_at_unit;
PY_CALL("ssi", "add_function", "cancel_city_at_unit", (int)ptr);
ptr = python_canvas_pos_to_nearest_tile_id;
PY_CALL("ssi", "add_function", "canvas_pos_to_nearest_tile_id", (int)ptr);
ptr = python_set_mapview_origin;
Expand Down
5 changes: 5 additions & 0 deletions src/pyclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ void finish_city_at_unit(int unit, char* title) {
finish_city(u->tile, title);
}

void cancel_city_at_unit(int unit) {
struct unit* u = (struct unit*)unit;
cancel_city(u->tile);
}

void* py_alloc_struct(PyObject* stru) {
/*PyObject* attr = PyObject_GetAttrString(stru, "_civstruct");
if(!attr) errlog("No _civstruct member\n");
Expand Down

0 comments on commit 8cc7ac1

Please sign in to comment.