コード例 #1
0
ファイル: spqr_events.py プロジェクト: maximinus/SPQR
def menuPreferences(handle, xpos, ypos):
	"""Display the user preferences window. You can only really
	   play with the music and volume settings for now"""
	# first off, let's make the window that we need
	index = SGFX.gui.addWindow(SWINDOW.CWindow(-1, -1, 288, 152, "SPQR Preferences", True))
	# we'll need an image first
	img = SWIDGET.buildImageAlpha("img_music")
	img.rect.x = 20
	img.rect.y = 20
	# a couple of labels, and there positions
	lbl_MusicOn = SWIDGET.buildLabel("Music On:")
	lbl_MusicOn.rect.x = 88
	lbl_MusicOn.rect.y = 28
	lbl_Volume = SWIDGET.buildLabel("Volume:")
	lbl_Volume.rect.x = 88
	lbl_Volume.rect.y = 60
	# a checkbox for the music option
	chk_Volume = SWIDGET.CCheckBox(247, 30, SSFX.sound.music_playing)
	chk_Volume.active = True
	# connect it to some code
	chk_Volume.addAfterClick(musicCheckbox)
	# a slider for the volume
	sld_Volume = SWIDGET.CSlider(160, 62, 100, 0, 100, SSFX.sound.getVolume())
	sld_Volume.active = True
	# connect to some code
	sld_Volume.setUpdateFunction(setVolume)
	# a seperator
	sep = SWIDGET.CSeperator(10, 90, 274 - SPQR.WINSZ_SIDE)
	# and an ok button
	btn_ok = SWIDGET.CButton(190, 106, "OK")
	btn_ok.callbacks.mouse_lclk = killModalWindow
	btn_ok.active = True
	# add them all to our window
	SGFX.gui.windows[index].addWidget(img)
	SGFX.gui.windows[index].addWidget(lbl_MusicOn)
	SGFX.gui.windows[index].addWidget(lbl_Volume)
	SGFX.gui.windows[index].addWidget(chk_Volume)
	SGFX.gui.windows[index].addWidget(sld_Volume)
	SGFX.gui.windows[index].addWidget(sep)
	SGFX.gui.windows[index].addWidget(btn_ok)
	# make the window modal
	SGFX.gui.windows[index].modal = True
	# add the new key event: o = ok
	SGFX.gui.keyboard.addKey(K_o, killModalWindow)
	SGFX.gui.keyboard.setModalKeys(1)
	# turn off unit animations
	SGFX.gui.unitFlashAndOff()
	# setup dirty rect stuff
	SGFX.gui.addDirtyRect(SGFX.gui.windows[index].drawWindow(),
		SGFX.gui.windows[index].rect)
	# and thats us done
	return True
コード例 #2
0
ファイル: spqr_events.py プロジェクト: QMickael/SPQR
def menuPreferences(handle, xpos, ypos):
    """Display the user preferences window. You can only really
	   play with the music and volume settings for now"""
    # first off, let's make the window that we need
    index = SGFX.gui.addWindow(
        SWINDOW.CWindow(-1, -1, 328, 252, "SPQR Preferences", True))
    # we'll need an image first
    img = SWIDGET.buildImageAlpha("img_music")
    img.rect.x = 20
    img.rect.y = 20
    ## now image for display monitor
    img_display = SWIDGET.buildImageAlpha('display')
    img_display.rect.x = 20
    img_display.rect.y = 90
    # a couple of labels, and there positions
    lbl_MusicOn = SWIDGET.buildLabel("Music On:")
    lbl_MusicOn.rect.x = 88
    lbl_MusicOn.rect.y = 28
    lbl_Volume = SWIDGET.buildLabel("Volume:")
    lbl_Volume.rect.x = 88
    lbl_Volume.rect.y = 60
    ## new label for screen settings
    lbl_screenResolution = SWIDGET.buildLabel('Resolution:')
    lbl_screenResolution.rect.x = 88
    lbl_screenResolution.rect.y = 100
    ## option for display monitor
    options_display = SWIDGET.COptionMenu(
        178, 95, ['Fullscreen', '1024x768', '800x600'])
    options_display.describe = "opt-Resolution"
    options_display.active = True
    # a checkbox for the music option
    chk_Volume = SWIDGET.CCheckBox(180, 30, SSFX.sound.music_playing)
    chk_Volume.active = True
    # connect it to some code
    chk_Volume.addAfterClick(musicCheckbox)
    # a slider for the volume
    sld_Volume = SWIDGET.CSlider(180, 62, 140, 0, 100, SSFX.sound.getVolume())
    sld_Volume.active = True
    # connect to some code
    sld_Volume.setUpdateFunction(setVolume)
    # a seperator
    sep = SWIDGET.CSeperator(10, 190, 300 - SPQR.WINSZ_SIDE)
    ## an apply button
    btn_apply = SWIDGET.CButton(120, 215, 'Apply')
    btn_apply.callbacks.mouse_lclk = resizeWindow
    btn_apply.active = True
    # and an ok button
    btn_ok = SWIDGET.CButton(210, 215, "OK")
    btn_ok.callbacks.mouse_lclk = killModalWindow
    btn_ok.active = True
    # add them all to our window
    SGFX.gui.windows[index].addWidget(img)
    SGFX.gui.windows[index].addWidget(lbl_MusicOn)
    ## add news settings
    SGFX.gui.windows[index].addWidget(img_display)
    SGFX.gui.windows[index].addWidget(lbl_screenResolution)
    SGFX.gui.windows[index].addWidget(options_display)
    SGFX.gui.windows[index].addWidget(lbl_Volume)
    SGFX.gui.windows[index].addWidget(chk_Volume)
    SGFX.gui.windows[index].addWidget(sld_Volume)
    SGFX.gui.windows[index].addWidget(sep)
    SGFX.gui.windows[index].addWidget(btn_apply)
    SGFX.gui.windows[index].addWidget(btn_ok)
    # make the window modal
    SGFX.gui.windows[index].modal = True
    # add the new key event: o = ok
    SGFX.gui.keyboard.addKey(K_o, killModalWindow)
    SGFX.gui.keyboard.setModalKeys(1)
    # turn off unit animations
    SGFX.gui.unitFlashAndOff()
    # setup dirty rect stuff
    SGFX.gui.addDirtyRect(SGFX.gui.windows[index].drawWindow(),
                          SGFX.gui.windows[index].rect)
    # and thats us done
    return True
コード例 #3
0
ファイル: spqr_battle.py プロジェクト: alej0varas/spqr
	def __init__(self, attacker, region):
		self.result = None
		# get the defending units (only the first for now)
		# must be some units, we checked earlier
		defender = region.units[0]
		region = region
		# now we have all we need to build the base window
		window = SWINDOW.CWindow(-1, -1, 390, 300, "Battle Screen", False)
		window.modal = True
		ystart = SGFX.gui.iHeight("win_tl")
		# we need widgets for the unit names
		attack_unit_label = SWIDGET.buildLabel(str(attacker), SPQR.FONT_VERA_BOLD)
		attack_unit_label.rect.x = int((180 - attack_unit_label.rect.width) / 2) + 10
		attack_unit_label.rect.y = 60 + ystart
		defend_unit_label = SWIDGET.buildLabel(str(defender), SPQR.FONT_VERA_BOLD)
		defend_unit_label.rect.x = int((180 - defend_unit_label.rect.width) / 2) + 200
		defend_unit_label.rect.y = 60 + ystart
		# pictures of the units
		attack_image = SWIDGET.buildImageAlpha(attacker.image)
		attack_image.rect.x = int((180 - SPQR.UNIT_WIDTH) / 2) + 10
		attack_image.rect.y = 15 + ystart
		defend_image = SWIDGET.buildImageAlpha(defender.image)
		defend_image.rect.x = int((180 - SPQR.UNIT_WIDTH) / 2) + 200
		defend_image.rect.y = 15 + ystart
		for widget in [attack_unit_label, defend_unit_label, attack_image,	defend_image]:
			window.addWidget(widget)
		# get the random elements and add them
		xpos = 20
		ypos1 = 85 + ystart
		for event in self.getAttackEvents():
			label = SWIDGET.buildLabel(event)
			label.rect.x = xpos
			label.rect.y = ypos1
			window.addWidget(label)
			ypos1 += 20
		xpos = 220
		ypos2 = 85 + ystart
		for event in self.getDefendEvents():
			label = SWIDGET.buildLabel(event)
			label.rect.x = xpos
			label.rect.y = ypos2
			window.addWidget(label)
			ypos2 += 20
		# how far?
		if ypos2 > ypos1:
			ypos1 = ypos2
		ypos1 += 12
		# build in the options
		attack_text = SWIDGET.buildLabel("Attack style:", SPQR.FONT_VERA_ITALIC)
		attack_text.rect.x = 20
		attack_text.rect.y = ypos1
		defend_text = SWIDGET.buildLabel("Retreat:", SPQR.FONT_VERA_ITALIC)
		defend_text.rect.x = 220
		defend_text.rect.y = ypos1
		window.addWidget(attack_text)
		window.addWidget(defend_text)
		ypos1 += 20
		opt1 = SWIDGET.COptionMenu(20, ypos1, attack_options)
		opt2 = SWIDGET.COptionMenu(220, ypos1, retreat_options)
		opt1.active = True
		opt2.active = True
		window.addWidget(opt1)
		window.addWidget(opt2)
		ypos1 += 40
		window.addWidget(SWIDGET.CSeperator(10, ypos1, 370))
		ypos1 += 15
		# add withdraw and attack buttons
		btn_attack = SWIDGET.CButton(297, ypos1, "Attack")
		btn_attack.callbacks.mouse_lclk = self.doBattle
		btn_attack.active = True
		btn_withdraw = SWIDGET.CButton(200, ypos1, "Withdraw")
		btn_withdraw.callbacks.mouse_lclk = self.retreatBattle
		btn_withdraw.active = True
		window.addWidget(btn_attack)
		window.addWidget(btn_withdraw)
		window.rect.height = ypos1 + 50
		window.renderWindowBackdrop()
		SGFX.gui.addWindow(window)
		SGFX.gui.pauseFlashing()
		# setup dirty rect stuff
		SGFX.gui.addDirtyRect(window.drawWindow(), window.rect)
コード例 #4
0
ファイル: spqr_ybuild.py プロジェクト: alej0varas/spqr
def createWidget(wlist):
	""" Function that creates a widget and returns it based on the
		passed list of properties """
	# First we check the key that will always be in our widget's
	# and defines the widget's purpose
	if wlist['widget'] == "CText":
		height = SGFX.gui.fonts[eval(wlist['font'])].get_height() * eval(wlist['lines'])
		width = SGFX.gui.fonts[eval(wlist['font'])].size('X')[0] * eval(wlist['chars'])
		widget = SWIDGET.CText(eval(wlist['x']), eval(wlist['y']), width, height, eval(wlist['lines']), eval(wlist['font']))
		# check if there are any widgets callback
		if wlist.has_key('callbacks'):
			checkCallbacks(widget, wlist['callbacks'])
		if wlist['active'] == True:
			widget.active = True
		else: 
			widget.active = False
		if wlist['visible'] == True:
			widget.visible = True
		else:
			widget.visible = False
		return widget
	elif wlist['widget'] == "CLabel":
		# if this is a label make it with a text
		widget = SWIDGET.buildLabel(wlist['text'])
		# and add the cords to the rect
		widget.rect.x = eval(wlist['x'])
		widget.rect.y = eval(wlist['y'])
		# Check if there is any widgets callback
		if wlist.has_key('callbacks'):
			checkCallbacks(widget,wlist['callbacks'])
		if wlist['active'] == True:
			widget.active = True
		else:
			widget.active = False
		if wlist['visible'] == True:
			widget.visible = True
		else:
			widget.visible = False
		return widget
	elif wlist['widget'] == "CCheckBox":
		widget = SWIDGET.CCheckBox(eval(wlist['x']) , eval(wlist['y']) , eval(wlist['initial']))
		if wlist.has_key('after'):
			widget.addAfterClick(getattr(SEVENTS, wlist['after']))
		if wlist['active'] == True:
			widget.active = True
		else:
			widget.active = False
		if wlist['visible'] == True:
			widget.visible = True
		else:
			widget.visible = False
		return widget
	elif wlist['widget'] == "COptionMenu":
		widget = SWIDGET.COptionMenu(eval(wlist['x']), eval(wlist['y']) , wlist['options'])
		widget.describe = wlist['describe']
		if wlist['active'] == True:
			widget.active = True
		else:
			widget.active = False
		if wlist['visible'] == True:
			widget.visible = True
		else:
			widget.visible = False
		return widget
	elif wlist['widget'] == "CSeperator" :
		widget = SWIDGET.CSeperator(eval(wlist['x']) , eval(wlist['y']) , eval(wlist['w']))
		if wlist['active'] == True:
			widget.active = True
		else:
			widget.active = False
		if wlist['visible'] == True:
			widget.visible = True
		else:
			widget.visible = False
		return widget
	elif wlist['widget'] == "CSlider" :
		widget = SWIDGET.CSlider(eval(wlist['x']), eval(wlist['y']), eval(wlist['w']), 
		  						 eval(wlist['start']), eval(wlist['stop']), eval(wlist['initial']))
		widget.setUpdateFunction(getattr(SEVENTS, wlist['update']))
		if wlist['active'] == True:
			widget.active = True
		else:
			widget.active = False
		if wlist['visible'] == True:
			widget.visible = True
		else:
			widget.visible = False
		return widget
	elif wlist['widget'] == "CButton":
		# if it is a button we create it and then we must put the callbacks in
		widget = SWIDGET.CButton(eval(wlist['x']), eval(wlist['y']), wlist['text'])
		# for every callback we check the given function from the global list
		checkCallbacks(widget,wlist['callbacks'])
		if wlist['active'] == True:
			widget.active = True
		else:
			widget.active = False
		if wlist['visible'] == True:
			widget.visible = True
		else:
			widget.visible = False
		return widget
	elif wlist['widget'] == "CScrollArea":
		image = SGFX.gui.image(wlist['image'])
		widget = SWIDGET.CScrollArea(eval(wlist['x']), eval(wlist['y']), eval(wlist['w']),
									 eval(wlist['h']) , image)
		if wlist['active'] == True:
			widget.active = True
		else:
			widget.active = False
		if wlist['visible'] == True:
			widget.visible = True
		else:
			widget.visible = False
		return widget
	elif wlist['widget'] == "CButtonDetails" :
		widget = SWINDOW.CButtonDetails(wlist['text'], wlist['key'], getattr(SEVENTS, wlist["callback"]))
		if wlist['active'] == True:
			widget.active = True
		else:
			widget.active = False
		if wlist['visible'] == True:
			widget.visible = True
		else:
			widget.visible = False
		return widget
	elif wlist['widget'] == "CImage" :
		if wlist['alpha'] == 1:
			widget = SWIDGET.buildImageAlpha(wlist['image'])
		else:
			widget = SWIDGET.buildImage(wlist['image'])
		widget.rect.x = eval(wlist['x'])
		widget.rect.y = eval(wlist['y'])
		if wlist.has_key('callbacks'):
			checkCallbacks(widget,wlist['callbacks'])
		if wlist['active'] == True:
			widget.active = True
		else:
			widget.active = False
		if wlist['visible'] == True:
			widget.visible = True
		else:
			widget.visible = False
		return widget
	elif wlist['widget'] == "CBlankButton" :
		widget = SWIDGET.CButton(eval(wlist['x']), eval(wlist['y']), "*BLANK*")
		widget.rect.width = eval(wlist['w'])
		widget.rect.height = eval(wlist['h'])
		checkCallbacks(widget, wlist['callbacks'])
		if wlist['active'] == True:
			widget.active = True
		else:
			widget.active = False
		if wlist['visible'] == True:
			widget.visible = True
		else:
			widget.visible = False
		return widget