aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2024-04-02 20:56:28 -0400
committerB. Stack <bgstack15@gmail.com>2024-04-02 20:56:28 -0400
commit72c2c2eb276791b4603b8cf4a2c6f62a529d9400 (patch)
treee0ab217166f1344c7da96d8808c00fc0385da869
parentadd first attempt srb_tk and stackrpms_tk_lib (diff)
downloadsrb_lib-72c2c2eb276791b4603b8cf4a2c6f62a529d9400.tar.gz
srb_lib-72c2c2eb276791b4603b8cf4a2c6f62a529d9400.tar.bz2
srb_lib-72c2c2eb276791b4603b8cf4a2c6f62a529d9400.zip
tk: add levelsets
-rw-r--r--srb_lib.py4
-rwxr-xr-xsrb_tk.py49
2 files changed, 49 insertions, 4 deletions
diff --git a/srb_lib.py b/srb_lib.py
index 8b4c9fe..ec0c7ca 100644
--- a/srb_lib.py
+++ b/srb_lib.py
@@ -20,7 +20,9 @@
# <https://stackoverflow.com/questions/46109815/reversing-the-byte-order-of-a-string-containing-hexadecimal-characters>
# <https://gamefaqs.gamespot.com/pc/930591-snoopy-vs-the-red-baron/faqs/46161>
# Improve:
-# Rewrite as a class so we do not have to pass data around everywhere.
+# Rewrite as a class so we do not have to pass data around everywhere?
+# Write: set level breakables
+# Write: set profile-in-use
# Documentation:
# winetricks vd=1024x768
# winetricks vd=off
diff --git a/srb_tk.py b/srb_tk.py
index 75d4f60..aedee55 100755
--- a/srb_tk.py
+++ b/srb_tk.py
@@ -19,6 +19,7 @@
# https://stackoverflow.com/questions/69806038/navigate-to-tkinter-optionmenu-with-tab-key/69806039#69806039
# icon courtesy of https://icons8.com/icon/9336/aircraft
# possible way to have a widget store its variable: https://stackoverflow.com/questions/63871376/tkinter-widget-cgetvariable
+# count number of 1s in a binary value https://stackoverflow.com/questions/8871204/count-number-of-1s-in-binary-representation/71307775#71307775
# Improve:
# Add levelset, level info.
# Enable the checkbox for profile-in-use
@@ -108,6 +109,16 @@ class App(tk.Frame):
self.pur_plane_bool_woodstock = tk.BooleanVar()
self.pur_plane_str_baron = tk.StringVar(value="baron")
self.pur_plane_bool_baron = tk.BooleanVar()
+ # levelsets and levels
+ #self.levelset_name_strs = []
+ self.levelset_status_ints = []
+ for i in range(0,len(srb_lib.LEVELSETS)):
+ #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 = []
+ for i in range(0,len(srb_lib.LEVELS)):
+ self.level_strs.append(tk.StringVar(value=srb_lib.get_level_info(i)[0]["name"]))
+
# statusbar
self.statustext = tk.StringVar()
@@ -225,6 +236,26 @@ class App(tk.Frame):
self.chk_pur_plane_baron = stk.Checkbutton(self.frm_curprof,textvariable=self.pur_plane_str_baron,variable=self.pur_plane_bool_baron,func=self.load_form_into_data)
self.chk_pur_plane_baron.grid(row=11,column=1,sticky="W")
+ # 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))
+ # 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 levels")
+ self.lbl_levelsets_available_levels.grid(row=0,column=1,columnspan=2,sticky="EW")
+ 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=i+1,column=0,sticky="EW")
+ self.spn_levelsets.append(stk.Spinbox(self.frm_levels,textvariable=self.levelset_status_ints[i],from_=0,to=tl["l"])) #func=self.load_form_into_data,
+ self.spn_levelsets[i].grid(row=i+1,column=1,sticky="EW")
+ tk.Label(self.frm_levels,text="/ " + str(tl["l"])).grid(row=i+1,column=2,sticky="EW")
+
# status bar
self.status = stk.StatusBar(self.master,var=self.statustext)
#self.grid(expand=True,fill=tk.BOTH)
@@ -316,6 +347,11 @@ class App(tk.Frame):
bdata, message = srb_lib.set_purchased_planes(bdata, profile_id, "add", pur_planes_list, silent=self.silent.get())
if bdata == -1 or message != "":
raise Exception(f"Failed when setting purchased planes, message {message}.")
+ # levelset available levels
+ for i in range(0,len(srb_lib.LEVELSETS)):
+ bdata, message = srb_lib.set_levelset_available_levels(bdata, profile_id, i, self.levelset_status_ints[i].get())
+ if bdata == -1 or message != "":
+ raise Exception(f"Failed to set levelset available levels for levelset {i}, message {message}.")
except Exception as e:
bdata = -1
print(f"ERROR! Invalid {e}")
@@ -387,7 +423,7 @@ class App(tk.Frame):
#self.prof1name, # do not trace the profile names, because it prevents spaces ending on the variables
#self.prof2name,
#self.prof3name,
- ]:
+ ] + [i for i in self.levelset_status_ints]:
j.trace("w",self.load_form_into_data)
# different one
self.selected_profile.trace("w",self.load_data_into_form_for_current_profile)
@@ -401,7 +437,7 @@ class App(tk.Frame):
#self.prof1name,
#self.prof2name,
#self.prof3name,
- ]:
+ ] + [i for i in self.levelset_status_ints]:
for i in j.trace_info():
if i[0][0] == "write":
j.trace_remove(i[0][0],i[1])
@@ -479,7 +515,7 @@ class App(tk.Frame):
self.pur_plane_bool_baron.set(True if "baron" in planes_list else False)
x = 0
for i in srb_lib.LEVELSETS:
- _, letters = srb_lib.get_levelset_status(self.bdata,profile_id,x,silent=self.silent.get())
+ mission_mask, letters = srb_lib.get_levelset_status(self.bdata,profile_id,x,silent=self.silent.get())
if 0 == x:
self.pur_plane_str_marcie.set(letters)
elif 1 == x:
@@ -492,8 +528,15 @@ class App(tk.Frame):
self.pur_plane_str_woodstock.set(letters)
elif 5 == x:
self.pur_plane_str_baron.set(letters)
+ # levelset available levels
+ mission_mask = bin(int(mission_mask[1:],2)).count('1')
+ #print(f"for levelset {i}, need to set max {i['l']}, current {mission_mask}")
+ self.levelset_status_ints[x].set(mission_mask)
x += 1
self.mark_traces("enable")
+ # 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)
# end if-profile_id is 1,2 or 3.
else:
bgstack15