Skip to content

Commit

Permalink
Moves --show-gui to globals.py + SHOW_FOG -> FOG_ENABLED.
Browse files Browse the repository at this point in the history
  • Loading branch information
BertrandBordage committed Apr 12, 2013
1 parent 272f8ed commit 8a60d99
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
21 changes: 9 additions & 12 deletions controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,12 @@ def pop_handlers(self):
self.window.pop_handlers()

class MainMenuController(Controller):
def __init__(self, window, show_gui=True):
def __init__(self, window):
super(MainMenuController, self).__init__(window)
self.batch = pyglet.graphics.Batch()
self.group = pyglet.graphics.OrderedGroup(2)
self.labels_group = pyglet.graphics.OrderedGroup(3)

self.show_gui = show_gui

background = load_image('resources', 'textures', 'main_menu_background.png')
image = load_image('resources', 'textures', 'frame.png')
self.frame_rect = Rectangle(0, 0, image.width, image.height)
Expand All @@ -73,7 +71,7 @@ def __init__(self, window, show_gui=True):
group=self.labels_group)

def start_game_func(self):
controller = GameController(self.window, show_gui=self.show_gui)
controller = GameController(self.window)
self.window.switch_controller(controller)
return pyglet.event.EVENT_HANDLED

Expand Down Expand Up @@ -124,9 +122,8 @@ def on_draw(self):


class GameController(Controller):
def __init__(self, window, show_gui=True):
def __init__(self, window):
super(GameController, self).__init__(window)
self.show_gui = show_gui # TODO: Rename into hud_enabled
self.sector = None
self.time_of_day = 0.0
self.count = 0
Expand Down Expand Up @@ -203,7 +200,7 @@ def setup(self):
glEnable(GL_BLEND)
glEnable(GL_LINE_SMOOTH)

if globals.SHOW_FOG:
if globals.FOG_ENABLED:
glEnable(GL_FOG)
glFogfv(GL_FOG_COLOR, vec(self.bg_red, self.bg_green, self.bg_blue, 1))
glHint(GL_FOG_HINT, GL_DONT_CARE)
Expand Down Expand Up @@ -236,7 +233,7 @@ def setup(self):
anchor_style=globals.ANCHOR_LEFT|globals.ANCHOR_RIGHT|globals.ANCHOR_BOTTOM)
self.command_parser = CommandParser()
self.camera = Camera3D(target=self.player)
if self.show_gui:
if globals.HUD_ENABLED:
self.label = pyglet.text.Label(
'', font_name='Arial', font_size=8, x=10, y=self.window.height - 10,
anchor_x='left', anchor_y='top', color=(255, 255, 255, 255))
Expand Down Expand Up @@ -362,7 +359,7 @@ def on_mouse_drag(self, x, y, dx, dy, button, modifiers):

def on_key_press(self, symbol, modifiers):
if symbol == globals.TOGGLE_HUD_KEY:
self.show_gui = not self.show_gui
globals.HUD_ENABLED = not globals.HUD_ENABLED
elif symbol == globals.SAVE_KEY:
self.save_to_file()
elif symbol == globals.INVENTORY_SORT_KEY:
Expand Down Expand Up @@ -391,13 +388,13 @@ def on_key_release(self, symbol, modifiers):
return pyglet.event.EVENT_HANDLED

def on_resize(self, width, height):
if self.show_gui:
if globals.HUD_ENABLED:
self.label.y = height - 10
self.text_input._on_resize()

def set_3d(self):
width, height = self.window.get_size()
if globals.SHOW_FOG:
if globals.FOG_ENABLED:
glFogfv(GL_FOG_COLOR, vec(self.bg_red, self.bg_green, self.bg_blue, 1.0))
glEnable(GL_DEPTH_TEST)
glViewport(0, 0, width, height)
Expand Down Expand Up @@ -435,7 +432,7 @@ def on_draw(self):
self.crack_batch.draw()
self.draw_focused_block()
self.set_2d()
if self.show_gui:
if globals.HUD_ENABLED:
self.draw_label()
self.item_list.draw()
self.inventory_list.draw()
Expand Down
8 changes: 7 additions & 1 deletion globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,12 @@
FAR_CLIP_DISTANCE = 200.0 # Maximum render distance,
# ignoring effects of sector_size and fog

SHOW_FOG = True
FOG_ENABLED = True

MOTION_BLUR = False

HUD_ENABLED = True


#
# Sound
Expand All @@ -193,15 +195,19 @@
#
# Recipes
#

recipes = None
smelting_recipes = None


#
# Timer
#

TIMER_INTERVAL = 1
main_timer = None


#
# Global files & directories
#
Expand Down
17 changes: 8 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def initialize_config():
choices=globals.DRAW_DISTANCE_CHOICES)
globals.DRAW_DISTANCE = globals.DRAW_DISTANCE_CHOICES[globals.DRAW_DISTANCE_CHOICE]

globals.SHOW_FOG = get_or_update_config(
graphics, 'show_fog', globals.SHOW_FOG, conv=bool)
globals.FOG_ENABLED = get_or_update_config(
graphics, 'fog_enabled', globals.FOG_ENABLED, conv=bool)

globals.MOTION_BLUR = get_or_update_config(
graphics, 'motion_blur', globals.MOTION_BLUR, conv=bool)
Expand All @@ -99,13 +99,14 @@ def initialize_config():


class Window(pyglet.window.Window):
def __init__(self, launch_fullscreen=False, show_gui=True, **kwargs):
def __init__(self, launch_fullscreen=False,
**kwargs):
super(Window, self).__init__(
globals.WINDOW_WIDTH, globals.WINDOW_HEIGHT, **kwargs)
self.exclusive = False
self.reticle = None
self.controller = None
controller = MainMenuController(self, show_gui=show_gui)
controller = MainMenuController(self)
self.switch_controller(controller)
if launch_fullscreen:
self.set_fullscreen()
Expand Down Expand Up @@ -186,12 +187,11 @@ def main(options):

# try:
# window_config = Config(sample_buffers=1, samples=4) #, depth_size=8) #, double_buffer=True) #TODO Break anti-aliasing/multisampling into an explicit menu option
# window = Window(show_gui=options.show_gui, caption='pyCraftr', resizable=True, config=window_config, save=save_object)
# window = Window(caption='pyCraftr', resizable=True, config=window_config)
# except pyglet.window.NoSuchConfigException:
window = Window(
launch_fullscreen=options.fullscreen,
show_gui=options.show_gui, caption=globals.APP_NAME, resizable=True,
vsync=False)
launch_fullscreen=options.fullscreen, caption=globals.APP_NAME,
resizable=True, vsync=False)

globals.main_timer = Timer()
pyglet.clock.schedule_interval(globals.main_timer.schedule, globals.TIMER_INTERVAL)
Expand All @@ -202,7 +202,6 @@ def main(options):
parser = argparse.ArgumentParser(description='Play a Python made Minecraft clone.')

display_group = parser.add_argument_group('Display options')
display_group.add_argument("--show-gui", action="store_true", default=True, help="Enabled by default.")
display_group.add_argument("--fullscreen", action="store_true", default=False, help="Runs the game in fullscreen. Press 'Q' to exit the game.")

game_group = parser.add_argument_group('Game options')
Expand Down

0 comments on commit 8a60d99

Please sign in to comment.