Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ui changes

  • Loading branch information...
commit 3b2ff9d907461f1057c05a9da31f9aecaa45e1ee 1 parent 2e35fc7
@zielmicha authored
View
2  android/info.sh
@@ -5,5 +5,5 @@ 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.4"
-RELEASE_VERSION_ID="1004" # remember to change civsync.ua in sync.py:38
+RELEASE_VERSION_ID="1005" # remember to change civsync.ua in sync.py:38
ANDROID_PATH="$HOME/apps/android-sdk-linux_x86/tools:$HOME/apps/android-ndk-r6b"
View
0  build.sh 100644 → 100755
File mode changed
View
2  lib/client/freeciv.py
@@ -68,7 +68,7 @@ def _callback(funname, *args):
else:
print 'no function named %s %s' % (name, args)
except:
- traceback.print_exc()
+ traceback.print_exc(limit=200)
print 'Abort.'
_end_callbacks()
if hard_exit:
View
7 lib/features.py
@@ -57,6 +57,9 @@ def parse_options():
args = sys.argv[1:]
unused = [sys.argv[0]]
for arg in args:
+ if arg == '-f:_list':
+ show_feature_list()
+ sys.exit(1)
if arg.startswith('-f:'):
arg = arg[len('-f:'):]
_parse_arg(arg)
@@ -64,6 +67,10 @@ def parse_options():
unused.append(arg)
sys.argv = unused
+def show_feature_list():
+ for key in sorted(feature_types):
+ print '%s = [%s] %s' % (key.rjust(35), feature_types[key].__name__, str(features[key]).ljust(35))
+
def _parse_arg(arg):
if '=' in arg:
key, val = arg.split('=', 1)
View
59 lib/main.py
@@ -35,12 +35,10 @@
import features
import monitor
import options
+import menus
from sync import lzma
-def new_game():
- save.new_game()
-
features.add_feature('app.debug', default=True, type=bool)
features.add_feature('app.autoupdate', default=True, type=bool)
features.add_feature('app.forcesize')
@@ -60,24 +58,31 @@ def apply_hardexit(t):
pause_file = os.path.join(save.get_save_dir(), 'pause_options')
def client_main():
- action = sys.argv[1] if sys.argv[1:] else None
if try_resume():
ui.main()
return
+ ui.set(ui.Label('loading...'))
+ ui.execute_later.append(app_main)
+
+ if features.get('app.profile'):
+ profile_main()
+ else:
+ ui.main()
+
+def app_main():
+ action = sys.argv[1] if sys.argv[1:] else None
+
if action == 'load':
savename = sys.argv[2]
save.load_game(savename)
elif action == 'connect':
host, port = sys.argv[2:]
save.connect(host, int(port))
+ elif action == 'eval':
+ exec sys.argv[2]
else:
- show_main_menu()
-
- if features.get('app.profile'):
- profile_main()
- else:
- ui.main()
+ menus.main_menu()
def profile_main():
import cProfile
@@ -86,36 +91,18 @@ def profile_main():
p = pstats.Stats('profileout')
p.strip_dirs().sort_stats('time').print_stats()
-def show_main_menu():
- global main_menu
- main_menu = menu = ui.Menu()
-
- menu.add('New game', new_game)
- menu.add('Load game', save.load_dialog)
- menu.add('Feedback', feedback)
- menu.add('Options', options.show_options)
- if features.get('app.multiplayer'):
- menu.add('Connect', save.connect_dialog)
-
- ui.set(menu)
-
-def feedback():
- panel = ui.LinearLayoutWidget()
- panel.add(ui.Label('Leaving comments with logs will help me diagnose\npotential problems with game speed and\nunexpected behaviour.'))
- panel.add(ui.Button('Leave a comment with a log (preferred)', lambda: sync.comment(get_install_time(), True)))
- panel.add(ui.Button('Leave a comment without a log', lambda: sync.comment(get_install_time(), False)))
- ui.set(panel)
-
def start_autoupdate():
thread.start_new_thread(run_autoupdate, ())
def run_autoupdate():
- install_time = get_install_time()
+ install_time = sync.get_install_time()
try:
sync.client().updates(install_time)
except sync.civsync.UpdateRequiredError as err:
with ui.execute_later_lock:
ui.execute_later.append(lambda: notify_update(err.url))
+ except Exception as err:
+ print 'Failed to autoupdate:', err
def notify_update(url):
print 'update found at', url
@@ -164,16 +151,6 @@ def unpack_data():
os.remove('data.tgz')
progress.draw_frame('', 'starting...', 1)
-def get_install_time():
- path = os.path.join(save.get_save_dir(), 'install_time')
- try:
- return int(open(path).read())
- except (IOError, ValueError):
- install_time = int(time.time() * 1000)
- with open(path, 'w') as f:
- f.write('%d' % install_time)
- return install_time
-
def check_force_size():
if features.get('app.forcesize'):
return map(int, features.get('app.forcesize').split(','))
View
149 lib/menus.py
@@ -0,0 +1,149 @@
+# Copyright (C) 2011 Michal Zielinski (michal@zielinscy.org.pl)
+#
+# 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, 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.
+
+import ui
+import pygame
+
+import sync
+import save
+import features
+import options
+
+class SpacingLayoutWidget(ui.LayoutWidget):
+ def __init__(self, item1, item2, size):
+ ui.LayoutWidget.__init__(self)
+ self.item1 = item1
+ self.item2 = item2
+ self.items = (item1, item2)
+ self.size = (0,0)
+ self._asked_size = size
+
+ def get_positions(self):
+ assert sum(map(lambda a:0 if a==0 else 1, self._asked_size)) == 1, 'exactly one value in tuple `size` should be zero'
+ is_horizontal = self._asked_size[1] == 0
+ if is_horizontal:
+ w = self._asked_size[0]
+ self.size = (w, max(self.item1.size[1], self.item2.size[1]))
+ yield (0, 0)
+ yield (w - self.item2.size[0], 0)
+ else:
+ h = self._asked_size[1]
+ self.size = (max(self.item1.size[0], self.item2.size[0]), h)
+ yield (0, 0)
+ yield (0, h - self.item2.size[1])
+
+def create_aligned_widget(widget, align, size=None):
+ if not size:
+ size = ui.screen_size
+ if align & ui.RIGHT:
+ widget = SpacingLayoutWidget(ui.Spacing(0,0), widget, (size[0], 0))
+ if align & ui.BOTTOM:
+ widget = SpacingLayoutWidget(ui.Spacing(0,0), widget, (0, size[1]))
+ return widget
+
+class PrettyMenu(ui.AbsoluteLayoutWidget):
+ def __init__(self):
+ ui.AbsoluteLayoutWidget.__init__(self)
+
+ self.load_background()
+
+ self.left = ui.HorizontalLayoutWidget(spacing=10)
+ self.left.add(ui.Spacing(0, 0))
+ self.right = ui.HorizontalLayoutWidget(spacing=10)
+ self.cont = SpacingLayoutWidget(self.left, self.right, (ui.screen_width, 0))
+ self.add(create_aligned_widget(self.cont, ui.BOTTOM, (0, ui.screen_height - 10)), (0,0))
+
+ balloon_margin = 30
+
+ def show_balloon(self, over, baloon):
+ self.update_layout()
+ baloon.update_layout()
+ pos = self.get_position_of(over)
+ self.add(baloon, (pos[0], pos[1] - baloon.size[1] - self.balloon_margin))
+
+ def load_background(self):
+ img = ui.load_image('data/user/intro.jpg')
+ img_size = img.get_size()
+ surf_size = pygame.display.get_surface().get_size()
+ new_height = float(surf_size[0]) / img_size[0] * img_size[1]
+ self.background_margin_top = (new_height - surf_size[1]) / -2.5
+ self.background = pygame.transform.smoothscale(img, (surf_size[0], int(new_height)))
+
+ def draw(self, surf, (x, y)):
+ surf.blit(self.background, (x, y + self.background_margin_top))
+ super(PrettyMenu, self).draw(surf, (x, y))
+
+class MenuButton(ui.Button):
+ active_bg = (255, 255, 200, 20)
+ bg = (150, 150, 50, 20)
+ fg = (150, 150, 50)
+
+ def __init__(self, text, callback):
+ ui.Button.__init__(self, text, callback, force_width=100)
+
+ def set_text(self, label):
+ if '\n' not in label:
+ label += '\n '
+ ui.Button.set_text(self, label)
+
+class Balloon(ui.AbsoluteLayoutWidget):
+ margin = 10
+
+ def __init__(self):
+ ui.AbsoluteLayoutWidget.__init__(self)
+ self.content = ui.HorizontalLayoutWidget()
+ self.add(self.content, (self.margin, self.margin))
+
+ def draw(self, surf, pos):
+ rect = pos + (self.content.size[0] + self.margin*2, self.content.size[1] + self.margin*2)
+ tpos = (pos[0] + 10, pos[1] + self.content.size[1] + self.margin*2 - 1)
+ tw = th = 18
+
+ ui._round_rect(surf, (255,255,255,255), rect, 0, 10, 10)
+ pygame.gfxdraw.trigon(surf, tpos[0], tpos[1], tpos[0]+tw, tpos[1], tpos[0], tpos[1]+th, (255,255,255))
+ pygame.gfxdraw.filled_trigon(surf, tpos[0], tpos[1], tpos[0]+tw, tpos[1], tpos[0], tpos[1]+th, (255,255,255))
+ ui._round_rect(surf, (255,255,0,255), rect, 1, 10, 10)
+ ui.AbsoluteLayoutWidget.draw(self, surf, pos)
+
+class _D(ui.Label):
+ 'Label that prints its pos - for debugging'
+ def draw(self, surf, pos):
+ print pos, '(clip=%r)' % surf.get_clip()
+ ui.Label.draw(self, surf, pos)
+
+def main_menu():
+ menu = PrettyMenu()
+
+ menu.left.add(MenuButton('New\ngame', save.new_game))
+ load_game_button = MenuButton('Load\ngame', save.load_dialog)
+ menu.left.add(load_game_button)
+ if features.get('app.multiplayer'):
+ menu.left.add(MenuButton('Connect', save.connect_dialog))
+
+ menu.right.add(MenuButton('Feed\nback', feedback))
+ menu.right.add(MenuButton('Sett\nings', options.show_options))
+ menu.right.add(MenuButton('Exit', None))
+ menu.right.add(ui.Spacing(0, 0))
+
+ #balloon = Balloon()
+ #balloon.content.add(ui.Label('hello'))
+ #menu.show_balloon(load_game_button, balloon)
+
+ ui.replace(menu)
+
+
+def feedback():
+ panel = ui.LinearLayoutWidget()
+ panel.add(ui.Label('Leaving comments with logs will help me diagnose\npotential problems with game speed and\nunexpected behaviour.'))
+ panel.add(ui.Button('Leave a comment with a log (preferred)', lambda: sync.comment(sync.get_install_time(), True)))
+ panel.add(ui.Button('Leave a comment without a log', lambda: sync.comment(sync.get_install_time(), False)))
+ ui.set(panel)
View
13 lib/sync.py
@@ -33,7 +33,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/1004')
+features.set('civsync.ua', 'CivSyncAndroid/1005')
features.add_feature('civsync.enable', False, type=bool)
session = None
@@ -219,5 +219,14 @@ def sync_request(callback, name, args, kwargs):
with ui.execute_later_lock:
ui.execute_later.append(lambda: callback(result))
-#ui.execute_later.append()
+
+def get_install_time():
+ path = os.path.join(save.get_save_dir(), 'install_time')
+ try:
+ return int(open(path).read())
+ except (IOError, ValueError):
+ install_time = int(time.time() * 1000)
+ with open(path, 'w') as f:
+ f.write('%d' % install_time)
+ return install_time
View
25 lib/test_glue.py
@@ -0,0 +1,25 @@
+import sys, os
+
+sys.path.append(os.path.join(os.path.dirname(__file__), '../src'))
+
+import freecivclient
+import glob
+
+def callback(funname, *args):
+ if funname == 'add_function':
+ name, i = args
+ functions[name] = i
+ return
+ if funname == 'set_const':
+ return
+ return (5,)
+
+def call(name, *args):
+ freecivclient.call_f(functions[name], args)
+
+functions = {}
+
+freecivclient.set_callback(callback)
+
+while True:
+ call('call_callback', 5)
View
49 lib/ui.py
@@ -33,13 +33,17 @@ def set_show_fps(val):
show_fps = val
features.set_applier('ui.showfps', set_show_fps, type=bool, default=False)
+features.add_feature('ui.enable_anim', type=bool, default=True)
def replace(new_screen):
global screen
screen = new_screen
def replace_anim(new_screen, direction=1):
- replace(Animation(screen, new_screen, direction))
+ if features.get('ui.enable_anim'):
+ replace(Animation(screen, new_screen, direction))
+ else:
+ replace(new_screen)
def set(new_screen, anim=True):
if screen:
@@ -263,6 +267,17 @@ def event(self, event):
elif self.items:
self.items[0].event(event)
+ def get_position_of(self, item):
+ if item in self.items:
+ return self.positions[self.items.index(item)]
+ for child in self.items:
+ if hasattr(child, 'get_position_of'):
+ child_pos = self.positions[self.items.index(child)]
+ rel_pos = child.get_position_of(item)
+ if rel_pos:
+ return rel_pos[0] + child_pos[0], rel_pos[1] + child_pos[1]
+ return None
+
def get_items_at(self, evpos, yield_this=None):
if yield_this:
yield yield_this
@@ -626,6 +641,7 @@ def gfx_rect(surf, color, rect, width):
def _round_rect(surface, color, rect, width, xr, yr):
clip = surface.get_clip()
+ rect = pygame.Rect(rect)
# left and right
surface.set_clip(clip.clip(rect.inflate(0, 5-yr*2)))
@@ -635,26 +651,26 @@ def _round_rect(surface, color, rect, width, xr, yr):
surface.set_clip(clip.clip(rect.inflate(5-xr*2, 0)))
if width != 0:
gfx_rect(surface, color, rect.inflate(0, 1-width), width)
- else:
+ else: # fill
x, y, w, h = rect
- gfx_rect(surface, color, (x, y, w, yr - 2), width)
- gfx_rect(surface, color, (x, y + h - yr + 1, w, yr - 1), width)
+ gfx_rect(surface, color, (x, y, w, yr - 3), width)
+ gfx_rect(surface, color, (x, y + h - yr + 2, w, yr - 1), width)
# top left corner
- surface.set_clip(clip.clip(rect.left, rect.top, xr, yr))
+ surface.set_clip(clip.clip(rect.left, rect.top, xr-3, yr-3))
gfx_ellipse(surface, color, pygame.Rect(rect.left, rect.top, 2*xr, 2*yr), width)
# top right corner
- surface.set_clip(clip.clip(rect.right-xr, rect.top, xr, yr))
+ surface.set_clip(clip.clip(rect.right-xr+2, rect.top, xr, yr-3))
gfx_ellipse(surface, color, pygame.Rect(rect.right-2*xr, rect.top, 2*xr, 2*yr), width)
# bottom left
- surface.set_clip(clip.clip(rect.left, rect.bottom-yr, xr, yr))
+ surface.set_clip(clip.clip(rect.left, rect.bottom-yr+2, xr-3, yr))
gfx_ellipse(surface, color, pygame.Rect(rect.left, rect.bottom-2*yr, 2*xr, 2*yr), width)
# bottom right
- surface.set_clip(clip.clip(rect.right-xr, rect.bottom-yr, xr, yr))
- gfx_ellipse(surface, color, pygame.Rect(rect.right-2*xr, rect.bottom-2*yr, 2*xr, 2*yr), width)
+ surface.set_clip(clip.clip(rect.right-xr+2, rect.bottom-yr+2, xr, yr))
+ gfx_ellipse(surface, color, pygame.Rect(rect.right-2*xr-1, rect.bottom-2*yr-1, 2*xr, 2*yr), width)
surface.set_clip(clip)
@@ -664,16 +680,20 @@ def round_rect(surf, bg, fg, rect, round=10):
_round_rect(surf, fg, rect, 1, round, round)
class Button(WithText):
- def __init__(self, label, callback, font=None, color=None, force_width=None):
+ active_bg = (255, 255, 200, 150)
+ bg = (130, 100, 0, 90)
+ fg = (150, 150, 50)
+
+ def __init__(self, label, callback, font=None, color=None, force_width=None, force_height=None):
WithText.__init__(self, label, callback, font, color, padding=4, force_width=force_width)
self.active = False
def draw(self, surf, pos):
if self.active:
- color = (255, 255, 200, 20)
+ color = self.active_bg
else:
- color = (150, 150, 50, 20)
- round_rect(surf, color, (150, 150, 50), pos + self.size)
+ color = self.bg
+ round_rect(surf, color, self.fg, pos + self.size)
WithText.draw(self, surf, pos)
def unhover(self):
@@ -775,6 +795,9 @@ def yes():
def load_font(name, size):
return pygame.font.Font('fonts/ProcionoTT.ttf', size)
+def load_image(name):
+ return pygame.image.load(name).convert_alpha()
+
def init():
global font, smallfont, bigfont, mediumfont, consolefont
pygame.init()
Please sign in to comment.
Something went wrong with that request. Please try again.