Skip to content

Commit

Permalink
Message log and be viewed and scrolled
Browse files Browse the repository at this point in the history
  • Loading branch information
Shoes01 committed Apr 16, 2019
1 parent f9e7a3e commit 2da9cb8
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
3 changes: 2 additions & 1 deletion components/game/message_log.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class MessageLogComponent():
def __init__(self):
self.messages = []
self.messages = []
self.offset = 0
4 changes: 4 additions & 0 deletions processors/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def process(self):
_pop_popup_menu = event.get('pop_popup_menu')
_popup = event.get('popup')
_save_game = event.get('save_game')
_scroll = event.get('scroll')
_toggle_debug = event.get('toggle_debug')
_view_log = event.get('view_log')

Expand Down Expand Up @@ -73,6 +74,9 @@ def process(self):
self.world.component_for_entity(1, MessageLogComponent).messages.append({'game_saved': True})
save_game(self.world._next_entity_id, self.world._components, self.world._entities)

if _scroll:
self.world.component_for_entity(1, MessageLogComponent).offset += _scroll

if _toggle_debug:
if self.world.has_component(1, DebugComponent):
self.world.remove_component(1, DebugComponent)
Expand Down
12 changes: 10 additions & 2 deletions processors/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,17 @@ def process(self):
if key_char == 'm':
events.append({'view_log': True})

elif game_state_component.state == 'GameOver' or game_state_component.state == 'VictoryScreen' or game_state_component.state == 'ViewLog':
elif game_state_component.state == 'ViewLog':
if key.scancode == libtcod.event.SCANCODE_UP or key_char == 'k' or key.scancode == libtcod.event.SCANCODE_KP_8:
events.append({'scroll': +1})
elif key.scancode == libtcod.event.SCANCODE_DOWN or key_char == 'j' or key.scancode == libtcod.event.SCANCODE_KP_2:
events.append({'scroll': -1})
elif key.scancode == libtcod.event.SCANCODE_ESCAPE:
events.append({'exit': True})

elif game_state_component.state == 'GameOver' or game_state_component.state == 'VictoryScreen':
if key.scancode == libtcod.event.SCANCODE_ESCAPE:
events.append({'exit': True})
events.append({'exit': True})

### INPUTS THAT ARE READ ONLY ON THE PLAYERS TURN
for ent, (actor, eng, player) in self.world.get_components(ActorComponent, EnergyComponent, PlayerComponent):
Expand Down
1 change: 1 addition & 0 deletions processors/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from components.game.debug import DebugComponent
from components.game.redraw import RedrawComponent
from components.game.state import StateComponent
from components.game.view_log import ViewLogComponent
from processors.sub.entities import render_entities
from processors.sub.message_log import render_message_log
from processors.sub.popup_menu import render_popup_menu
Expand Down
22 changes: 19 additions & 3 deletions processors/sub/message_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,27 @@
from components.game.message_log import MessageLogComponent

def render_message_log(console_bundle, world):
message_log = world.component_for_entity(1, MessageLogComponent).messages
message_log_component = world.component_for_entity(1, MessageLogComponent)
console, x, y, w, h = console_bundle


offset = None
messages = message_log_component.messages

max_offset = len(messages) - h

if message_log_component.offset >= max_offset:
message_log_component.offset = max_offset
offset = -max_offset
elif message_log_component.offset <= 0:
message_log_component.offset = 0
offset = None
else:
offset = -message_log_component.offset


dy = h - 1
for message in reversed(message_log):
offset_messages = messages[:offset]
for message in reversed(offset_messages):
_ai_awake = message.get('ai_awake')
_combat = message.get('combat')
_consume = message.get('consume')
Expand Down

0 comments on commit 2da9cb8

Please sign in to comment.