Skip to content

Commit

Permalink
Refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
devapromix committed Jun 27, 2018
1 parent 02a9516 commit 0a707a3
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 142 deletions.
3 changes: 2 additions & 1 deletion Trollhunter.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ uses
Trollhunter.Player.Types in 'sources\Trollhunter.Player.Types.pas',
Trollhunter.Scene.Statistics in 'sources\Trollhunter.Scene.Statistics.pas',
Trollhunter.Scene.Options in 'sources\Trollhunter.Scene.Options.pas',
Trollhunter.Player.Helpers in 'sources\Trollhunter.Player.Helpers.pas';
Trollhunter.Player.Helpers in 'sources\Trollhunter.Player.Helpers.pas',
Trollhunter.Scene.Help in 'sources\Trollhunter.Scene.Help.pas';

var
Key: UInt = 0;
Expand Down
1 change: 1 addition & 0 deletions Trollhunter.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
<DCCReference Include="sources\Trollhunter.Scene.Statistics.pas"/>
<DCCReference Include="sources\Trollhunter.Scene.Options.pas"/>
<DCCReference Include="sources\Trollhunter.Player.Helpers.pas"/>
<DCCReference Include="sources\Trollhunter.Scene.Help.pas"/>
<BuildConfiguration Include="Debug">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>
Expand Down
154 changes: 154 additions & 0 deletions sources/Trollhunter.Scene.Help.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
unit Trollhunter.Scene.Help;

interface

uses Trollhunter.Types,
uScenes;

type
TSceneHelp = class(TScene)
public
constructor Create;
destructor Destroy; override;
procedure Render; override;
procedure Update(var Key: UInt); override;
end;

implementation

{ TSceneHelp }

uses SysUtils,
uLanguage,
Trollhunter.UI,
BearLibTerminal,
Trollhunter.Terminal;

constructor TSceneHelp.Create;
begin

end;

destructor TSceneHelp.Destroy;
begin

inherited;
end;

procedure TSceneHelp.Render;
begin
UI.Title(_('Help'));

case Scenes.PrevSceneEnum of
scClass:
begin
UI.Title(_('Keybindings'), 5);
X := 1;
Y := 7;
AddLine('Space', _('Re-roll'));
AddLine('Backspace', _('Random'));
AddLine('A-Z', _('Select a class'));
end;
scRace:
begin
UI.Title(_('Keybindings'), 5);
X := 1;
Y := 7;
AddLine('Tab', _('Choose a sex'));
AddLine('Space', _('Re-roll'));
AddLine('Backspace', _('Random'));
AddLine('A-Z', _('Select a race'));
end;
scInv:
begin
Terminal.Print(CX, 3,
Format(_('To drop an item, press the %s key and then press %s key to drop it.'),
[UI.KeyToStr('TAB'), UI.KeyToStr('A-Z')]), TK_ALIGN_CENTER);

UI.Title(_('Keybindings'), 5);
X := 1;
Y := 7;
AddLine('Tab', _('Drop an item to the floor'));
AddLine('Space', _('Character Screen'));
AddLine('A-Z', _('Use an item'));
end;
scPlayer:
begin
UI.Title(_('Keybindings'), 5);

X := 1;
Y := 8;
AddLine('Right/Left', _('Change tab'));
AddLine('Up/Down', _('Scroll skills'));
AddLine('Tab', _('Show Background'));
AddLine('Space', _('Show Inventory'));
end;
scGame:
begin
Terminal.Print(CX, 3,
_('Far away in an uncharted region of the Earth land Elvion lies surrounded by mountains.'),
TK_ALIGN_CENTER);
Terminal.Print(CX, 4,
_('In the center of this land there is a village named Dork. It''s people are in'),
TK_ALIGN_CENTER);
Terminal.Print(CX, 5,
_('grave danger as the Troll King and his armies are marching to lay waste on all of'),
TK_ALIGN_CENTER);
Terminal.Print(CX, 6,
_('its inhabitants. Unless a hero will rise to take a stand against the forces of evil.'),
TK_ALIGN_CENTER);

Terminal.Print(CX, 8,
_('You are the hero who departs on a quest to stop the enemies and save your homeland,'),
TK_ALIGN_CENTER);
Terminal.Print(CX, 9,
_('Elvion. Survive, gather equipment, fight adversaries and be ready for the final'),
TK_ALIGN_CENTER);
Terminal.Print(CX, 10, _('confrontation. Good luck! You will need it.'),
TK_ALIGN_CENTER);

UI.Title(_('Keybindings'), 12);

Terminal.Print(CX, 14, Format('%s: %s, %s, %s %s: %s, %s %s: %s',
[_('Move'), UI.KeyToStr('arrow keys'), UI.KeyToStr('numpad'),
UI.KeyToStr('QWEADZXC'), _('Wait'), UI.KeyToStr('5'),
UI.KeyToStr('S'), _('Effects'), UI.KeyToStr('TAB')]),
TK_ALIGN_CENTER);

X := 1;
Y := 16;
AddLine('<', _('Go up stairs'));
AddLine('>', _('Go down stairs'));
AddLine('G', _('Pick up an item from the floor'));
AddLine('F', _('Drop an item to the floor'));
AddLine('L', _('Look mode'));
AddLine('R', _('Rest'));
AddLine('M', _('View messages'));
// AddLine('B', _('Spellbook'));
AddLine('T', _('Talents'));
AddLine('N', _('Show Statistics'));
AddLine('O', _('Options'));
AddLine('I', _('Show Inventory'));
AddLine('P', _('Character Screen'));
AddLine('K', _('Calendar'));
AddLine('?', _('Show this Help Screen'));

UI.Title(_('Character dump'), Terminal.Window.Height - 6);
Terminal.Print(CX, Terminal.Window.Height - 4,
Format(_('The game saves a character dump to %s file.'),
[UI.KeyToStr('*-character-dump.txt')]), TK_ALIGN_CENTER);
end;
end;
Self.AddKey('Esc', _('Close'), True);
end;

procedure TSceneHelp.Update(var Key: UInt);
begin
case Key of
TK_ESCAPE:
// Close
Scenes.GoBack;
end;
end;

end.
3 changes: 2 additions & 1 deletion sources/Trollhunter.Scene.Statistics.pas
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ implementation
Trollhunter.Item.Affixes,
Trollhunter.Item.Types,
Trollhunter.Item.Shop,
uQuest, Trollhunter.Player.Helpers;
uQuest,
Trollhunter.Player.Helpers;

var
Wizard: Boolean = False;
Expand Down
143 changes: 3 additions & 140 deletions sources/uScenes.pas
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ interface
TScene = class(TObject)
private
KStr: string;
procedure AddLine(AHotKey, AText: string);
public
CX, CY: Int;
X, Y: Int;
constructor Create;
procedure Render; virtual; abstract;
procedure AddLine(AHotKey, AText: string);
procedure AddOption(AHotKey, AText: string; AOption: Boolean;
AColor: Cardinal = $FFAAAAAA); overload;
procedure Add(); overload;
Expand All @@ -53,6 +53,7 @@ TScenes = class(TScene)
procedure Render; override;
procedure Update(var Key: UInt); override;
property SceneEnum: TSceneEnum read FSceneEnum write FSceneEnum;
property PrevSceneEnum: TSceneEnum read FPrevSceneEnum;
function GetScene(I: TSceneEnum): TScene;
procedure SetScene(ASceneEnum: TSceneEnum); overload;
procedure SetScene(ASceneEnum, CurrSceneEnum: TSceneEnum); overload;
Expand Down Expand Up @@ -186,15 +187,6 @@ TSceneItems = class(TScene)
procedure Update(var Key: UInt); override;
end;

type
TSceneHelp = class(TScene)
public
constructor Create;
destructor Destroy; override;
procedure Render; override;
procedure Update(var Key: UInt); override;
end;

type
TSceneGame = class(TScene)
public
Expand Down Expand Up @@ -279,7 +271,7 @@ implementation
Trollhunter.Player.Types,
Trollhunter.Scene.Statistics,
Trollhunter.Scene.Options,
Trollhunter.Player.Helpers;
Trollhunter.Player.Helpers, Trollhunter.Scene.Help;

{ TScene }

Expand Down Expand Up @@ -561,135 +553,6 @@ procedure TSceneTitle.Update(var Key: UInt);
end;
end;

{ TSceneHelp }

constructor TSceneHelp.Create;
begin

end;

destructor TSceneHelp.Destroy;
begin

inherited;
end;

procedure TSceneHelp.Render;
begin
UI.Title(_('Help'));

case Scenes.FPrevSceneEnum of
scClass:
begin
UI.Title(_('Keybindings'), 5);
X := 1;
Y := 7;
AddLine('Space', _('Re-roll'));
AddLine('Backspace', _('Random'));
AddLine('A-Z', _('Select a class'));
end;
scRace:
begin
UI.Title(_('Keybindings'), 5);
X := 1;
Y := 7;
AddLine('Tab', _('Choose a sex'));
AddLine('Space', _('Re-roll'));
AddLine('Backspace', _('Random'));
AddLine('A-Z', _('Select a race'));
end;
scInv:
begin
Terminal.Print(CX, 3,
Format(_('To drop an item, press the %s key and then press %s key to drop it.'),
[UI.KeyToStr('TAB'), UI.KeyToStr('A-Z')]), TK_ALIGN_CENTER);

UI.Title(_('Keybindings'), 5);
X := 1;
Y := 7;
AddLine('Tab', _('Drop an item to the floor'));
AddLine('Space', _('Character Screen'));
AddLine('A-Z', _('Use an item'));
end;
scPlayer:
begin
UI.Title(_('Keybindings'), 5);

X := 1;
Y := 8;
AddLine('Right/Left', _('Change tab'));
AddLine('Up/Down', _('Scroll skills'));
AddLine('Tab', _('Show Background'));
AddLine('Space', _('Show Inventory'));
end;
scGame:
begin
Terminal.Print(CX, 3,
_('Far away in an uncharted region of the Earth land Elvion lies surrounded by mountains.'),
TK_ALIGN_CENTER);
Terminal.Print(CX, 4,
_('In the center of this land there is a village named Dork. It''s people are in'),
TK_ALIGN_CENTER);
Terminal.Print(CX, 5,
_('grave danger as the Troll King and his armies are marching to lay waste on all of'),
TK_ALIGN_CENTER);
Terminal.Print(CX, 6,
_('its inhabitants. Unless a hero will rise to take a stand against the forces of evil.'),
TK_ALIGN_CENTER);

Terminal.Print(CX, 8,
_('You are the hero who departs on a quest to stop the enemies and save your homeland,'),
TK_ALIGN_CENTER);
Terminal.Print(CX, 9,
_('Elvion. Survive, gather equipment, fight adversaries and be ready for the final'),
TK_ALIGN_CENTER);
Terminal.Print(CX, 10, _('confrontation. Good luck! You will need it.'),
TK_ALIGN_CENTER);

UI.Title(_('Keybindings'), 12);

Terminal.Print(CX, 14, Format('%s: %s, %s, %s %s: %s, %s %s: %s',
[_('Move'), UI.KeyToStr('arrow keys'), UI.KeyToStr('numpad'),
UI.KeyToStr('QWEADZXC'), _('Wait'), UI.KeyToStr('5'),
UI.KeyToStr('S'), _('Effects'), UI.KeyToStr('TAB')]),
TK_ALIGN_CENTER);

X := 1;
Y := 16;
AddLine('<', _('Go up stairs'));
AddLine('>', _('Go down stairs'));
AddLine('G', _('Pick up an item from the floor'));
AddLine('F', _('Drop an item to the floor'));
AddLine('L', _('Look mode'));
AddLine('R', _('Rest'));
AddLine('M', _('View messages'));
// AddLine('B', _('Spellbook'));
AddLine('T', _('Talents'));
AddLine('N', _('Show Statistics'));
AddLine('O', _('Options'));
AddLine('I', _('Show Inventory'));
AddLine('P', _('Character Screen'));
AddLine('K', _('Calendar'));
AddLine('?', _('Show this Help Screen'));

UI.Title(_('Character dump'), Terminal.Window.Height - 6);
Terminal.Print(CX, Terminal.Window.Height - 4,
Format(_('The game saves a character dump to %s file.'),
[UI.KeyToStr('*-character-dump.txt')]), TK_ALIGN_CENTER);
end;
end;
Self.AddKey('Esc', _('Close'), True);
end;

procedure TSceneHelp.Update(var Key: UInt);
begin
case Key of
TK_ESCAPE:
// Close
Scenes.GoBack;
end;
end;

{ TSceneGame }

procedure TSceneGame.Render;
Expand Down

0 comments on commit 0a707a3

Please sign in to comment.