import FSM import utils as u import menus as m import pygame from itertools import cycle from datetime import datetime from datetime import date #==================================== State = type("State", (object,), {}) #==================================== class State(object): def __init__(self, FSM): self.FSM = FSM def Enter(self): pass def Execute(self): pass def Exit(self): pass class EnterText(State): def __init__(self,FSM): super(EnterText, self).__init__(FSM) def Enter(self): o = self.FSM.owner m.menu1_actions(self, o) if o.keyState[16] == 1: m.draw_menu1(o) o.update_display(0) elif o.keyState[16] == 4: self.draw(o) o.update_display(0) self.input_string = "" if o.sconf['title'] == 'blank': self.input_string += str(datetime.today().strftime('%Y%m%d')) else: self.input_string += o.sconf['title'] o.header_text = "EnterText" o.pub.register("beat", self) self.last_action = pygame.time.get_ticks() self.caps = False self.cur_but = 18 self.cur_letter = "" if o.keyState[16] > 0 or o.keyState[17] > 0: pass else: pass self.skips = [7, 3, 11, 12, 13, 14, 15] self.lc_labels = [["p", "q", "r", "s"], ["t", "u", "v"], ["w", "x", "y", "z"], ["C", "A", "P", "S"], ["g", "h", "i"], ["j", "k", "l"], ["m", "n", "o"], ["D", "E", "L"], ["_", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-"], ["a", "b", "c"], ["d", "e", "f"], ["O", "K"], [], [], [], []] self.uc_labels = [["P", "Q", "R", "S"], ["T", "U", "V"], ["W", "X", "Y", "Z"], ["C", "A", "P", "S"], ["G", "H", "I"], ["J", "K", "L"], ["M", "N", "O"], ["D", "E", "L"], ["_", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-"], ["A", "B", "C"], ["D", "E", "F"], ["O", "K"], [], [], [], []] self.labels = self.lc_labels self.cycles = [] for l in self.labels: self.cycles.append(cycle(l)) self.draw(o) o.update_display(0) super(EnterText, self).Enter() def Execute(self): o = self.FSM.owner y_size = o.height / 4 if o.keyState[11] == 1: if self.input_string != 'blank': o.title = self.input_string o.sconf['title'] = self.input_string o.save_song() self.FSM.ToTransition('toFile') m.menu1_actions(self, o) m.menu2_actions_saveas(self, o) if o.keyState[16] == 1: m.draw_menu1(o) o.update_display(0) elif o.keyState[16] == 4: u.draw_header(o) self.draw(o) o.update_display(0) if o.keyState[17] == 1: m.draw_menu_saveas(o) o.update_display(0) elif o.keyState[17] == 4: u.draw_header(o) self.draw(o) o.update_display(0) # if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3: # u.draw_header(o) # self.draw(o) # o.update_display(0) if o.keyState[16] > 0 or o.keyState[17] > 0: pass else: _iter = 0 for k in o.keyState: if k == 1: cur_time = pygame.time.get_ticks() if _iter not in self.skips: self.last_action = cur_time if _iter < len(self.cycles): self.cur_letter = next(self.cycles[_iter]) self.cur_but = _iter self.draw(o) o.center_block(self.input_string + self.cur_letter, o.h2, [0, 0, o.width, y_size], o.light_grey) if _iter == 7: self.input_string = self.input_string[:-1] self.last_action = 100000000 self.draw(o) o.center_block(self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey) elif _iter == 3: if self.caps: self.caps = False self.labels = self.lc_labels else: self.caps = True self.labels = self.uc_labels self.draw(o) o.center_block(self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey) self.cycles = [] for l in self.labels: self.cycles.append(cycle(l)) o.update_display(0) _iter += 1 cur_time = pygame.time.get_ticks() delay = cur_time - self.last_action if delay > 1000 and delay < 100000: self.input_string += self.cur_letter self.last_action = 100000000 self.reset_cycles() self.draw(o) o.center_block(self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey) o.update_display(0) def ReceiveMessage(self, message): o = self.FSM.owner u.play_seq(o, message) def draw(self, o): x_size = o.width / 4 y_size = o.height / 4 og_x = 0 o_x = og_x o_y = o.height text_padding = 6 _id = 0 while _id < 16: lab = "" for i in self.labels[_id]: lab += i if _id == 8: lab = "_12" o.draw.rectangle((o_x, o_y, o_x + x_size, o_y - y_size), outline=0, fill=o.blue) o.center_block(lab, o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey) o_x = o_x + x_size _id += 1 if _id % 4 == 0: o_y -= y_size o_x = og_x o.draw.rectangle((0, 0, o.width, y_size), outline=0, fill=o.blue) def reset_cycles(self): self.cycles = [] for l in self.labels: self.cycles.append(cycle(l)) def Exit(self): self.FSM.owner.pub.unregister("beat", self)