nodeset label; mouse visibility
This commit is contained in:
parent
a53f175d6f
commit
fdded8701b
|
@ -125,6 +125,13 @@ class Configuration(RawConfigParser):
|
|||
section = "audio"
|
||||
add_section(section)
|
||||
set_option(section, "sfx-path", "aud/fx/")
|
||||
section = "interpolator-gui"
|
||||
add_section(section)
|
||||
set_option(section, "margin", "40")
|
||||
set_option(section, "marker-color", "255, 0, 0")
|
||||
set_option(section, "marker-size", "8")
|
||||
set_option(section, "curve-color", "0, 255, 0")
|
||||
set_option(section, "label-size", "18")
|
||||
|
||||
def read_project_config_file(self):
|
||||
path = self.locate_project_config_file()
|
||||
|
@ -343,6 +350,10 @@ class TypeDeclarations(dict):
|
|||
|
||||
"event": {"int": "command-id-offset"},
|
||||
|
||||
"interpolator-gui": {"int": ["margin", "marker-size", "label-size"],
|
||||
|
||||
"int-list": ["marker-color", "curve-color"]},
|
||||
|
||||
}
|
||||
|
||||
additional_defaults = {}
|
||||
|
|
|
@ -60,7 +60,7 @@ class Display(GameChild):
|
|||
def set_mouse_visibility(self, visibility=None):
|
||||
if visibility is None:
|
||||
visibility = self.mouse_visibility
|
||||
mouse.set_visible(visibility)
|
||||
return mouse.set_visible(visibility)
|
||||
|
||||
def get_screen(self):
|
||||
return self.screen
|
||||
|
|
|
@ -50,9 +50,7 @@ class Game(GameChild):
|
|||
def frame(self):
|
||||
self.time_filter.update()
|
||||
self.delegate.dispatch()
|
||||
if self.interpolator.is_gui_active():
|
||||
self.interpolator.update()
|
||||
else:
|
||||
if not self.interpolator.is_gui_active():
|
||||
self.update()
|
||||
self.video_recorder.update()
|
||||
|
||||
|
|
|
@ -4,33 +4,30 @@ from pygame.locals import *
|
|||
|
||||
from GameChild import GameChild
|
||||
|
||||
class Interpolator(dict, GameChild):
|
||||
class Interpolator(list, GameChild):
|
||||
|
||||
def __init__(self, parent):
|
||||
GameChild.__init__(self, parent)
|
||||
self.set_nodes()
|
||||
self.set_nodesets()
|
||||
self.gui_enabled = self.check_command_line("-interpolator")
|
||||
if self.gui_enabled:
|
||||
self.gui = GUI(self)
|
||||
|
||||
def set_nodes(self):
|
||||
def set_nodesets(self):
|
||||
for name, value in self.get_configuration("interpolate").iteritems():
|
||||
self[name] = Nodes(value)
|
||||
self.append(Nodeset(name, value))
|
||||
|
||||
def is_gui_active(self):
|
||||
return self.gui_enabled and self.gui.active
|
||||
|
||||
def update(self):
|
||||
if self.gui_enabled:
|
||||
self.gui.update()
|
||||
|
||||
|
||||
class Nodes(list):
|
||||
class Nodeset(list):
|
||||
|
||||
LINEAR, CUBIC = range(2)
|
||||
|
||||
def __init__(self, raw):
|
||||
def __init__(self, name, raw):
|
||||
list.__init__(self, [])
|
||||
self.name = name
|
||||
self.parse_raw(raw)
|
||||
self.set_splines()
|
||||
|
||||
|
@ -154,31 +151,68 @@ class GUI(GameChild):
|
|||
def __init__(self, parent):
|
||||
GameChild.__init__(self, parent)
|
||||
self.audio = self.get_audio()
|
||||
self.display = self.get_game().display
|
||||
self.display_surface = self.get_display_surface()
|
||||
self.time_filter = self.get_game().time_filter
|
||||
self.delegate = self.get_delegate()
|
||||
self.load_configuration()
|
||||
self.set_background()
|
||||
self.active = False
|
||||
self.font = Font(None, self.label_size)
|
||||
self.set_nodeset_index()
|
||||
self.subscribe(self.respond_to_command)
|
||||
self.subscribe(self.respond_to_mouse_down, MOUSEBUTTONDOWN)
|
||||
self.subscribe(self.respond_to_mouse_up, MOUSEBUTTONUP)
|
||||
self.active = False
|
||||
|
||||
def load_configuration(self):
|
||||
config = self.get_configuration("interpolator-gui")
|
||||
self.label_size = config["label-size"]
|
||||
|
||||
def set_background(self):
|
||||
surface = Surface(self.display_surface.get_size())
|
||||
surface.fill((0, 0, 0))
|
||||
self.background = surface
|
||||
|
||||
def set_nodeset_index(self, increment=None):
|
||||
parent = self.parent
|
||||
if not increment:
|
||||
index = 0
|
||||
else:
|
||||
index = self.nodeset_index + increment
|
||||
limit = len(parent) - 1
|
||||
if index > limit:
|
||||
index = 0
|
||||
elif index < 0:
|
||||
index = limit
|
||||
self.nodeset_index = index
|
||||
self.set_nodeset_label()
|
||||
self.draw()
|
||||
|
||||
def set_nodeset_label(self):
|
||||
surface = self.font.render(self.get_nodeset().name, False, (0, 0, 0),
|
||||
(255, 255, 255))
|
||||
rect = surface.get_rect()
|
||||
rect.bottomright = self.display_surface.get_rect().bottomright
|
||||
self.nodeset_label, self.nodeset_label_rect = surface, rect
|
||||
|
||||
def get_nodeset(self):
|
||||
return self.parent[self.nodeset_index]
|
||||
|
||||
def deactivate(self):
|
||||
self.active = False
|
||||
self.time_filter.open()
|
||||
self.audio.muted = self.saved_mute_state
|
||||
self.display.set_mouse_visibility(self.saved_mouse_state)
|
||||
|
||||
def respond_to_command(self, event):
|
||||
compare = self.delegate.compare
|
||||
if compare(event, "toggle-interpolator"):
|
||||
self.toggle()
|
||||
elif self.active and compare(event, "reset-game"):
|
||||
self.deactivate()
|
||||
elif self.active:
|
||||
if compare(event, "reset-game"):
|
||||
self.deactivate()
|
||||
elif compare(event, "quit"):
|
||||
self.get_game().end(event)
|
||||
|
||||
def toggle(self):
|
||||
if self.active:
|
||||
|
@ -191,13 +225,17 @@ class GUI(GameChild):
|
|||
self.time_filter.close()
|
||||
self.saved_mute_state = self.audio.muted
|
||||
self.audio.mute()
|
||||
self.draw()
|
||||
self.saved_mouse_state = self.display.set_mouse_visibility(True)
|
||||
|
||||
def respond_to_mouse_down(self, event):
|
||||
pass
|
||||
if self.active:
|
||||
self.set_nodeset_index(1)
|
||||
|
||||
def respond_to_mouse_up(self, event):
|
||||
pass
|
||||
|
||||
def update(self):
|
||||
if self.active:
|
||||
self.display_surface.blit(self.background, (0, 0))
|
||||
def draw(self):
|
||||
display_surface = self.display_surface
|
||||
display_surface.blit(self.background, (0, 0))
|
||||
display_surface.blit(self.nodeset_label, self.nodeset_label_rect)
|
||||
|
|
Loading…
Reference in New Issue