From 9e976527636d88faf669dcb096485792a07e2149 Mon Sep 17 00:00:00 2001 From: "B. Stack" Date: Wed, 3 Apr 2024 10:55:22 -0400 Subject: tk: load all values from data --- srb_lib.py | 6 ++-- srb_tk.py | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 79 insertions(+), 20 deletions(-) diff --git a/srb_lib.py b/srb_lib.py index ec0c7ca..c916c6b 100644 --- a/srb_lib.py +++ b/srb_lib.py @@ -380,7 +380,7 @@ def get_level_status(data_object,profile_id,level,silent=False): collected_breakables = get_collected_breakables(data,profile_id,level_obj["id"],silent=silent) print(f"debug: got collected_breakables {collected_breakables}") # it comes back as an int, but does it look better as a hex? - return hex(profile_level_status) + return hex(profile_level_status), profile_level_balloons, profile_level_letters def get_collected_breakables(data_object,profile_id, level, silent=False): """ Return a list of breakables that the profile has already collected for this level. """ @@ -418,7 +418,7 @@ def set_level_status(data_object,profile_id,level,status): level_obj, message = get_level_info(level) if message != "" or level_obj == -1: ferror(f"Unable to get level status for {level}.") - current_status = get_level_status(data, profile_id, level, silent=True) + current_status, _, _ = get_level_status(data, profile_id, level, silent=True) print(f"Before changing, level {level} has status {current_status}") bits = 0x0 try: @@ -427,7 +427,7 @@ def set_level_status(data_object,profile_id,level,status): return data, "", f"unable-to-set-level-completion-status-{status}" #print(f"debug: will try to set bits {bits:02x}") data = srb_pack('<1I',data,PROFILE_START_POSITION[profile_id]+POS_LEVEL_START+(INT_SIZE*level_obj["pos_r"]),bits) - current_status = get_level_status(data, profile_id, level, silent=True) + current_status, _, _ = get_level_status(data, profile_id, level, silent=True) levelset_available_levels = get_levelset_available_levels(data,profile_id,level_obj["setid"]) print(f"debug: levelset {level_obj['setid']} currently has {levelset_available_levels} available levels.") # if setting to any completed status, if the levelset available levels is less than this level, then make it this. diff --git a/srb_tk.py b/srb_tk.py index fc86e70..c9afee4 100755 --- a/srb_tk.py +++ b/srb_tk.py @@ -6,7 +6,7 @@ # Startdate: 2024-03-28-5 13:43 # Title: Graphical frontend for savegame editor for Snoopy vs. the Red Baron # Project: srb_lib -# Purpose: Savegame editor graphical frontend for +# Purpose: Savegame editor graphical frontend for srb_lib # History: # Usage: # ./srb_tk.py @@ -118,10 +118,21 @@ class App(tk.Frame): #self.levelset_name_strs.append(tk.StringVar(value=srb_lib.get_levelset_info(i)[0]["name"])) self.levelset_status_ints.append(tk.StringVar()) # will hold the status, as in completed mission mask self.level_strs = [] + self.level_statuses_hex = [] + self.level_statuses = [] + self.level_balloons = [] + self.level_letters = [] + statuses = [i["name"] for i in srb_lib.LEVEL_STATUSES] + statuses_hex = [i["b"] for i in srb_lib.LEVEL_STATUSES] for i in range(0,len(srb_lib.LEVELS)): self.level_strs.append(tk.StringVar(value=srb_lib.get_level_info(i)[0]["name"])) + self.level_statuses_hex.append(tk.StringVar(value=statuses_hex[0])) + self.level_statuses.append(tk.StringVar(value=statuses[0])) + self.level_balloons.append(tk.IntVar()) + self.level_letters.append(tk.IntVar()) + # END DATA VARIABLES - # statusbar + # statusbar variable self.statustext = tk.StringVar() # app label, for vanity @@ -136,7 +147,7 @@ class App(tk.Frame): self.ent_checksum.grid(row=2,column=0) self.chk_silent = tk.Checkbutton(self.master,text="silent",variable=self.silent) self.chk_silent.grid(row=2,column=1) - self.frm_profiles = tk.Frame(self.master) #,borderwidth=1,background="green") + self.frm_profiles = tk.Frame(self.master,background="orange",borderwidth=1) # WORKHERE: firm up column/placement of things so there is less whitespace. self.frm_profiles.grid(row=3,column=0,columnspan=2) # investigate radio button key-bind, up-down, to increment/decrement choice? @@ -177,7 +188,7 @@ class App(tk.Frame): # one profile, so we will have to use the value of self.selected_profile self.frm_curprof = tk.Frame(self.master,background="red") - self.frm_curprof.grid(row=4,column=0,rowspan=22) + self.frm_curprof.grid(row=4,column=0,rowspan=22,columnspan=2) # most form fields are inside the current profile self.lbl_money = tk.Label(self.frm_curprof,text="Money") self.lbl_money.grid(row=0,column=0) @@ -242,26 +253,38 @@ class App(tk.Frame): # level and levelsets self.frm_levels = tk.Frame(self.master,borderwidth=1,background="green") self.frm_levels.grid(row=0,column=3,rowspan=len(srb_lib.LEVELS)+4) - # WORKHERE self.lbl_levelsets = [] self.spn_levelsets = [] - self.lbl_levelsets_name = tk.Label(self.frm_levels,text="Billboard") - self.lbl_levelsets_name.grid(row=0,column=0,sticky="EW") - self.lbl_levelsets_available_levels = tk.Label(self.frm_levels,text="Available") - self.lbl_levelsets_available_levels.grid(row=0,column=1,columnspan=2) + self.lbl_levelsets_name = tk.Label(self.frm_levels,text="Billboard/Available") + self.lbl_levelsets_name.grid(row=0,column=0,sticky="EW",columnspan=2) + #self.lbl_levelsets_available_levels = tk.Label(self.frm_levels,text="Available") + #self.lbl_levelsets_available_levels.grid(row=0,column=1,columnspan=2) self.lbl_levels_name = tk.Label(self.frm_levels,text="Level") self.lbl_levels_name.grid(row=0,column=3,sticky="EW") + self.lbl_levels_status = tk.Label(self.frm_levels,text="Rank") + self.lbl_levels_status.grid(row=0,column=4,sticky="EW",columnspan=2) + self.lbl_levels_balloons = tk.Label(self.frm_levels,text="Balloons") + self.lbl_levels_balloons.grid(row=0,column=6,columnspan=4,sticky="EW") + self.lbl_levels_letters = tk.Label(self.frm_levels,text="Letters") + self.lbl_levels_letters.grid(row=0,column=10,columnspan=4,sticky="EW") self.lbl_levels = [] + self.opt_levels_hex = [] + self.opt_levels = [] + self.ent_levels_balloons = [] + self.ent_levels_letters = [] + self.btn_balloons_none = [] + self.btn_balloons_all = [] + self.btn_letters_none = [] + self.btn_letters_all = [] x = 1 for i in range(0,len(srb_lib.LEVELSETS)): tl = srb_lib.get_levelset_info(i)[0] # WORKHERE: will have to set up variables for all this stuff, and then populate this stuff only on the load_form_into_data_for_profile. - #tl_status = srb_lib.get_levelset_status(self.bdata,profile_id,tl,silent=True) self.lbl_levelsets.append(tk.Label(self.frm_levels,text=tl["name"])) - self.lbl_levelsets[i].grid(row=x,column=0,sticky="EW") + self.lbl_levelsets[i].grid(row=x,column=0,sticky="EW",columnspan=2) self.spn_levelsets.append(stk.Spinbox(self.frm_levels,textvariable=self.levelset_status_ints[i],from_=0,to=tl["l"],width=2)) - self.spn_levelsets[i].grid(row=x,column=1) - tk.Label(self.frm_levels,text="/ " + str(tl["l"])).grid(row=x,column=2,sticky="EW") + self.spn_levelsets[i].grid(row=x+1,column=0) + tk.Label(self.frm_levels,text="/ " + str(tl["l"])).grid(row=x+1,column=1,sticky="EW") print(f"For levelset {tl},") these_levels = [k for k in srb_lib.LEVELS if k["setid"] == tl["id"]] sorted(these_levels,key=lambda i: i["id"]) @@ -270,12 +293,31 @@ class App(tk.Frame): print(f"Process level {j}") self.lbl_levels.append(tk.Label(self.frm_levels,text=j["name"])) self.lbl_levels[-1].grid(row=x,column=3) + self.opt_levels_hex.append(tk.Entry(self.frm_levels,state="readonly",textvariable=self.level_statuses_hex[j["id"]],width=3)) + self.opt_levels_hex[-1].grid(row=x,column=4) + self.opt_levels.append(tk.OptionMenu(self.frm_levels,self.level_statuses[j["id"]],*statuses)) + self.opt_levels[-1].config(indicatoron=False,padx=0,pady=0,takefocus=1,width=8) + self.opt_levels[-1].grid(row=x,column=5,sticky="EW") + # only some levels have balloons + if j["b"]: + self.ent_levels_balloons.append(tk.Entry(self.frm_levels,state="readonly",textvariable=self.level_balloons[j["id"]],width=2)) + self.ent_levels_balloons[-1].grid(row=x,column=6) + tk.Label(self.frm_levels,text="/ " + str(j["b"])).grid(row=x,column=7) + self.btn_balloons_none.append(tk.Button(self.frm_levels,text="none",padx=0,pady=0)) + self.btn_balloons_none[-1].grid(row=x,column=8) + self.btn_balloons_all.append(tk.Button(self.frm_levels,text="all",padx=0,pady=0)) + self.btn_balloons_all[-1].grid(row=x,column=9) + # every level has letters though + self.ent_levels_letters.append(tk.Entry(self.frm_levels,state="readonly",textvariable=self.level_letters[j["id"]],width=2)) + self.ent_levels_letters[-1].grid(row=x,column=10) + tk.Label(self.frm_levels,text="/ " + str(len(str(j["l"])))).grid(row=x,column=11) + self.btn_letters_none.append(tk.Button(self.frm_levels,text="none",padx=0,pady=0)) + self.btn_letters_none[-1].grid(row=x,column=12) + self.btn_letters_all.append(tk.Button(self.frm_levels,text="all",padx=0,pady=0)) + self.btn_letters_all[-1].grid(row=x,column=13) x += 1 x += 1 # end for-i-in-levelsets - #for i in range(0,len(srb_lib.LEVELS)): - # tl = srb_lib.get_level_info(i)[0] - # self.lbl_levels.append(tk.Label(self.frm_levels # status bar self.status = stk.StatusBar(self.master,var=self.statustext) @@ -309,7 +351,7 @@ class App(tk.Frame): bdata, _ = srb_lib.set_tutorial_completed(bdata,1,self.prof1tut.get()) bdata, _ = srb_lib.set_tutorial_completed(bdata,2,self.prof2tut.get()) bdata, _ = srb_lib.set_tutorial_completed(bdata,3,self.prof3tut.get()) - + # and now the current profile stuff profile_id = self.selected_profile.get() if profile_id >= 1 and profile_id <= 3: @@ -558,6 +600,23 @@ class App(tk.Frame): # levelset available levels for i in range(0,len(srb_lib.LEVELSETS)): this_mission_mask, collected_letters = srb_lib.get_levelset_status(self.bdata,profile_id,i,silent=True) + # levels + for i in range(0,len(srb_lib.LEVELS)): + tl_status, tl_balloons, tl_letters = srb_lib.get_level_status(self.bdata,profile_id,i,silent=True) + # level status + tl_status = int(tl_status,16) + # look up name of status if possible else put "unknown". Thankfully tk handles it gracefully and shows it, but does not let a user pick it if he selects the drop-down menu. + tl_status_str = "" + print(f"got tl_status {tl_status}, type {type(tl_status)}") + try: + tl_status_str = [i["name"] for i in srb_lib.LEVEL_STATUSES if i["b"] == tl_status][0] + except: + tl_status_str = "unknown" + self.level_statuses_hex[i].set(hex(tl_status)[2:]) + self.level_statuses[i].set(tl_status_str) + # level balloons + self.level_balloons[i].set(tl_balloons) + self.level_letters[i].set(tl_letters) # end if-profile_id is 1,2 or 3. else: -- cgit