Skip to content

Commit

Permalink
Allows thememakers to make their own Custom Layers with customRMLayer…
Browse files Browse the repository at this point in the history
…s.py in the theme's folder.

(Very simple example provided)
  • Loading branch information
erodozer committed Sep 18, 2011
1 parent 1a89227 commit 5f45223
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 3 deletions.
38 changes: 38 additions & 0 deletions data/themes/MegaLight V4/CustomRMLayers.py
@@ -0,0 +1,38 @@

from Rockmeter import *

class Spinner(ImageLayer):
def __init__(self, stage, section):

self.stage = stage
super(Spinner, self).__init__(stage, section, os.path.join("themes", self.stage.themename, "rockmeter", "platinum.png"))

self.xposexpr = ".80"
self.yposexpr = ".80"

self.condition = "True"

def updateLayer(self, playerNum):
super(ImageLayer, self).updateLayer(playerNum)

self.angle += 2

def render(self, visibility, playerNum):

self.updateLayer(playerNum)

coord = self.position
scale = self.scale
rot = self.angle
color = self.color
alignment = self.alignment
valignment = self.valignment
drawing = self.drawing
rect = self.rect

#frameX = self.frameX
#frameY = self.frameY

if bool(eval(self.condition)):
self.engine.drawImage(drawing, scale, coord, rot, color, rect,
alignment = alignment, valignment = valignment)
2 changes: 2 additions & 0 deletions data/themes/MegaLight V4/rockmeter.ini
Expand Up @@ -176,5 +176,7 @@ transitionTime = 1.0
transitionTimeOut = 1000.0
condition = streak % 50 == 0 and streak > 0 and self.triggerPick()

[layer20:Custom]
classname = Spinner


Binary file added data/themes/MegaLight V4/rockmeter/platinum.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 31 additions & 3 deletions src/Rockmeter.py
Expand Up @@ -41,9 +41,15 @@
import math
from math import *

import Version

from Theme import halign, valign
from constants import *

import imp

import Log

#these are the variables for setting the alignment of text and images
#when setting them up in the rockmeter.ini you do not have
#to put it in all caps, the code will take care of that
Expand Down Expand Up @@ -150,6 +156,7 @@ def __init__(self, stage, section):
self.a = self.getexpr("a", "1.0")
self.color = [1.0,1.0,1.0,1.0]

self.shared = False #determines if the element is shared between players in multiplayer modes
self.condition = True #when should the image be shown (by default it will always be shown)

self.alignment = halign(self.get("alignment", str, "center"))
Expand All @@ -160,7 +167,8 @@ def __init__(self, stage, section):
#makes sure to properly scale/position the images in pixels instead of percent

self.effects = [] #various effects associated with the layer



# all variables that should be updated during the rendering process
# should be in here just for sake of readablity and organization
def updateLayer(self, playerNum):
Expand Down Expand Up @@ -885,14 +893,24 @@ def __init__(self, guitarScene, configFileName, coOp = False):
self.config.read(configFileName)

self.themename = self.engine.data.themeLabel


try:
themepath = os.path.join(Version.dataPath(), "themes", self.themename)
fp, pathname, description = imp.find_module("CustomRMLayers",[themepath])
self.customRMLayers = imp.load_module("CustomRMLayers", fp, pathname, description)
except ImportError:
self.customRMLayers = None
Log.notice("Custom Rockmeter layers are not available")

# Build the layers
for i in range(Rockmeter._layerLimit):
types = [
"Image",
"Text",
"Circle"
"Circle",
"Custom"
]

for t in types:
self.section = "layer%d:%s" % (i, t)
if not self.config.has_section(self.section):
Expand All @@ -902,6 +920,8 @@ def __init__(self, guitarScene, configFileName, coOp = False):
self.createFont(self.section, i)
elif t == types[2]:
self.createCircle(self.section, i)
elif t == types[3]:
self.createCustom(self.section, i)
else:
self.createImage(self.section, i)
break
Expand Down Expand Up @@ -955,6 +975,14 @@ def loadLayerFX(self, layer, section):
break


def createCustom(self, section, number):

if self.customRMLayers:
classname = self.get("classname")

layer = eval("self.customRMLayers."+classname+"(self, section)")
self.addLayer(layer, number, layer.shared)

def createFont(self, section, number):

font = self.get("font", str, "font")
Expand Down

0 comments on commit 5f45223

Please sign in to comment.