Skip to content

Commit

Permalink
One less thing for things to rely on, MainMenu can now default to jus…
Browse files Browse the repository at this point in the history
…t using text
  • Loading branch information
erodozer committed Jun 29, 2011
1 parent acf0064 commit 1bf46b7
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 54 deletions.
Binary file removed data/themes/Uberlight/menu/maintext.png
Binary file not shown.
67 changes: 40 additions & 27 deletions src/MainMenu.py
Expand Up @@ -151,14 +151,25 @@ def __init__(self, engine):
]

self.opt_bkg_size = [float(i) for i in self.engine.theme.opt_bkg_size]

strCareer = ""
strQuickplay = ""
strSolo = ""
strMultiplayer = ""
strTraining = ""
strSettings = ""
strQuit = ""
self.opt_text_color = self.engine.theme.hexToColor(self.engine.theme.opt_text_colorVar)
self.opt_selected_color = self.engine.theme.hexToColor(self.engine.theme.opt_selected_colorVar)

if self.BGText:
strCareer = ""
strQuickplay = ""
strSolo = ""
strMultiplayer = ""
strTraining = ""
strSettings = ""
strQuit = ""
else:
strCareer = "Career"
strQuickplay = "Quickplay"
strSolo = "Solo"
strMultiplayer = "Multiplayer"
strTraining = "Training"
strSettings = "Settings"
strQuit = "Quit"

multPlayerMenu = [
(_("Face-Off"), lambda: self.newLocalGame(players = 2, maxplayers = 4)),
Expand Down Expand Up @@ -197,8 +208,9 @@ def __init__(self, engine):
]


w, h, = self.engine.view.geometry[2:4]

self.menu = Menu(self.engine, mainMenu, onClose = lambda: self.engine.view.popLayer(self), pos = (12,12), textColor = self.opt_text_color, selectedColor = self.opt_selected_color)
self.menu = Menu(self.engine, mainMenu, onClose = lambda: self.engine.view.popLayer(self), pos = (self.menux, .75-(.75*self.menuy)))

engine.mainMenu = self #Points engine.mainMenu to the one and only MainMenu object instance

Expand Down Expand Up @@ -363,27 +375,28 @@ def render(self, visibility, topMost):
#MFH - auto-scaling
self.engine.drawImage(self.background, (1.0,-1.0), (w/2, h/2), stretched = 3)

numOfChoices = len(self.menu.choices)
for i in range(numOfChoices):
#Item selected
if self.menu.currentIndex == i:
xpos = (.5,1)
#Item unselected
else:
xpos = (0,.5)
#which item?
ypos = (1/float(numOfChoices) * i, 1/float(numOfChoices) * (i + 1))

textcoord = (w*self.menux,h*self.menuy-(h*self.main_menu_vspacing)*i)
sFactor = self.main_menu_scale
wFactor = xpos[1] - xpos[0]
hFactor = ypos[1] - ypos[0]
self.engine.drawImage(self.BGText,
if self.BGText:
numOfChoices = len(self.menu.choices)
for i in range(numOfChoices):
#Item selected
if self.menu.currentIndex == i:
xpos = (.5,1)
#Item unselected
else:
xpos = (0,.5)
#which item?
ypos = (1/float(numOfChoices) * i, 1/float(numOfChoices) * (i + 1))

textcoord = (w*self.menux,h*self.menuy-(h*self.main_menu_vspacing)*i)
sFactor = self.main_menu_scale
wFactor = xpos[1] - xpos[0]
hFactor = ypos[1] - ypos[0]
self.engine.drawImage(self.BGText,
scale = (wFactor*sFactor,-hFactor*sFactor),
coord = textcoord,
rect = (xpos[0],xpos[1],ypos[0],ypos[1]), stretched = 11)

#racer: added version tag to main menu:
#racer: added version tag to main menu:
if self.version != None:
wfactor = (w * self.engine.theme.versiontagScale) / self.version.width1()
self.engine.drawImage(self.version,( wfactor, -wfactor ),(w*self.engine.theme.versiontagposX, h*self.engine.theme.versiontagposY)) #worldrave - Added theme settings to control X+Y positions of versiontag.
Expand Down
4 changes: 1 addition & 3 deletions src/Menu.py
Expand Up @@ -91,7 +91,7 @@ def getText(self, selected):
return "%s: %s" % (self.text, self.values[self.valueIndex])

class Menu(Layer, KeyListener):
def __init__(self, engine, choices, name = None, onClose = None, onCancel = None, pos = (.2, .66 - .35), viewSize = 6, fadeScreen = False, font = "font", mainMenu = None, textColor = None, selectedColor = None, append_submenu_char = True, selectedIndex = None, showTips = True, selectedBox = False):
def __init__(self, engine, choices, name = None, onClose = None, onCancel = None, pos = (.2, .31), viewSize = 6, fadeScreen = False, font = "font", mainMenu = None, textColor = None, selectedColor = None, append_submenu_char = True, selectedIndex = None, showTips = True, selectedBox = False):
self.engine = engine

self.logClassInits = self.engine.config.get("game", "log_class_inits")
Expand Down Expand Up @@ -425,8 +425,6 @@ def render(self, visibility, topMost):
glRotate(v * 45, 0, 0, 1)

scale = self.engine.theme.settingsmenuScale
if self.mainMenu and self.theme < 2 and i % 2 == 1:#8bit
scale = 0.0016

w, h = font.getStringSize(" ", scale = scale)

Expand Down
48 changes: 24 additions & 24 deletions src/Theme.py
Expand Up @@ -656,35 +656,35 @@ def get(value, type = str, default = None):
self.result_star_type = get("result_star_type", int, 0)

#Submenus
allfiles = os.listdir(os.path.join(self.themePath,"menu"))
self.submenuScale = {}
self.submenuX = {}
self.submenuY = {}
self.submenuVSpace = {}
listmenu = []
for name in allfiles:
if name.find("text") > -1:
found = os.path.splitext(name)[0]
if found == "maintext":
if os.path.exists(os.path.join(self.themePath,"menu")):
allfiles = os.listdir(os.path.join(self.themePath,"menu"))
listmenu = []
for name in allfiles:
if name.find("text") > -1:
found = os.path.splitext(name)[0]
if found == "maintext":
continue
Config.define("theme", found, str, None)
self.submenuScale[found] = None
self.submenuX[found] = None
self.submenuY[found] = None
self.submenuVSpace[found] = None
listmenu.append(found)
for i in listmenu:
if i == "maintext":
continue
Config.define("theme", found, str, None)
self.submenuScale[found] = None
self.submenuX[found] = None
self.submenuY[found] = None
self.submenuVSpace[found] = None
listmenu.append(found)
for i in listmenu:
if i == "maintext":
continue
if self.submenuX[i]:
self.submenuX[i] = get(i).split(",")[0].strip()
if self.submenuY[i]:
self.submenuY[i] = get(i).split(",")[1].strip()
if self.submenuScale[i]:
self.submenuScale[i] = get(i).split(",")[2].strip()
if self.submenuVSpace[i]:
self.submenuVSpace[i] = get(i).split(",")[3].strip()

if self.submenuX[i]:
self.submenuX[i] = get(i).split(",")[0].strip()
if self.submenuY[i]:
self.submenuY[i] = get(i).split(",")[1].strip()
if self.submenuScale[i]:
self.submenuScale[i] = get(i).split(",")[2].strip()
if self.submenuVSpace[i]:
self.submenuVSpace[i] = get(i).split(",")[3].strip()

def setSelectedColor(self, alpha = 1.0):
glColor4f(*(self.selectedColor + (alpha,)))
Expand Down

0 comments on commit 1bf46b7

Please sign in to comment.