input config
This commit is contained in:
parent
b212bb2676
commit
3a7155fa87
|
@ -18,6 +18,12 @@ class Input(GameChild):
|
|||
|
||||
def load_configuration(self):
|
||||
self.release_suffix = self.get_configuration("input", "release-suffix")
|
||||
self.key_commands = self.get_configuration().items("keys")
|
||||
joy = self.get_configuration("joy")
|
||||
self.joy_advance_button_id = joy["advance"]
|
||||
self.joy_pause_button_id = joy["pause"]
|
||||
self.double_click_time_limit = self.get_configuration(
|
||||
"mouse", "double-click-time-limit")
|
||||
|
||||
def subscribe_to_events(self):
|
||||
self.subscribe(self.translate_key_press, KEYDOWN)
|
||||
|
@ -35,7 +41,7 @@ class Input(GameChild):
|
|||
|
||||
def build_key_map(self):
|
||||
key_map = {}
|
||||
for command, keys in self.get_configuration().items("keys"):
|
||||
for command, keys in self.key_commands:
|
||||
key_map[command] = []
|
||||
if type(keys) == str:
|
||||
keys = [keys]
|
||||
|
@ -63,10 +69,9 @@ class Input(GameChild):
|
|||
def translate_joy_press(self, event):
|
||||
if not self.suppressed:
|
||||
button = event.button
|
||||
config = self.get_configuration().get_section("joy")
|
||||
if button == config["advance"]:
|
||||
if button == self.joy_advance_button_id:
|
||||
self.post_command("advance")
|
||||
if button == config["pause"]:
|
||||
if button == self.joy_pause_button_id:
|
||||
self.post_command("pause")
|
||||
|
||||
def translate_axis_motion(self, event):
|
||||
|
@ -115,8 +120,7 @@ class Input(GameChild):
|
|||
if button == 1:
|
||||
last = self.last_mouse_down_left
|
||||
if last:
|
||||
limit = self.get_configuration("mouse",
|
||||
"double-click-time-limit")
|
||||
limit = self.double_click_time_limit
|
||||
if get_secs() - last < limit:
|
||||
post("mouse-double-click-left", pos=pos)
|
||||
last = get_secs()
|
||||
|
|
|
@ -31,12 +31,13 @@ class Mainloop(GameChild):
|
|||
def init_framerate_display(self):
|
||||
if self.show_framerate:
|
||||
screen = self.get_screen()
|
||||
self.last_framerate_count = 0
|
||||
self.framerate_topright = screen.get_rect().topright
|
||||
self.display_surface = screen
|
||||
self.font = Font(self.get_resource("main-menu", "font-path"),
|
||||
self.framerate_text_size)
|
||||
self.font.set_bold(True)
|
||||
self.render_framerate(0)
|
||||
self.render_framerate()
|
||||
|
||||
def run(self):
|
||||
while not self.stopping:
|
||||
|
@ -82,14 +83,17 @@ class Mainloop(GameChild):
|
|||
def update_framerate(self):
|
||||
count = self.frames_this_second + 1
|
||||
if get_ticks() - self.last_framerate_display > 1000:
|
||||
self.render_framerate(count)
|
||||
if count != self.last_framerate_count:
|
||||
self.last_framerate_count = count
|
||||
self.render_framerate()
|
||||
self.last_framerate_display = get_ticks()
|
||||
count = 0
|
||||
self.display_surface.blit(self.framerate_text, self.framerate_text_rect)
|
||||
self.frames_this_second = count
|
||||
|
||||
def render_framerate(self, count):
|
||||
text = self.font.render(str(count), False, self.framerate_text_color,
|
||||
def render_framerate(self):
|
||||
text = self.font.render(str(self.last_framerate_count), False,
|
||||
self.framerate_text_color,
|
||||
self.framerate_text_background)
|
||||
rect = text.get_rect()
|
||||
rect.topright = self.framerate_topright
|
||||
|
|
Loading…
Reference in New Issue