Commit 014dfbea authored by Romain Bignon's avatar Romain Bignon

add shortcuts

parent 659ff055
/* src/InGame.cpp - Functions in game !
* Copyright (C) 2005-2007 Romain Bignon <Progs@headfucking.net>
* Copyright (C) 2005-2011 Romain Bignon <romain@menareants.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -660,7 +660,7 @@ void TInGameForm::SetCursor()
}
void TInGameForm::FindIdling()
void TInGameForm::FindIdling(bool next)
{
static int i;
std::vector<ECBEntity*> ents = player->Entities()->List(), idle_ents;
......@@ -671,10 +671,14 @@ void TInGameForm::FindIdling()
}
if(idle_ents.empty())
InGameForm->AddInfo(I_WARNING, _("There aren't any idling unity."));
InGameForm->AddInfo(I_WARNING, _("There aren't any idling unit."));
else
{
ECEntity* e = dynamic_cast<ECEntity*>(idle_ents[++i % idle_ents.size()]);
if(next)
++i;
else
--i;
ECEntity* e = dynamic_cast<ECEntity*>(idle_ents[i % idle_ents.size()]);
Map->CenterTo(e);
BarreAct->SetEntity(e);
}
......@@ -833,6 +837,10 @@ void TInGameForm::AfterDraw()
}
}
#define CASE_KEY_UP case SDLK_UP: case 's': case 'k'
#define CASE_KEY_DOWN case SDLK_DOWN: case 't': case 'j'
#define CASE_KEY_LEFT case SDLK_LEFT: case 'c': case 'h'
#define CASE_KEY_RIGHT case SDLK_RIGHT: case 'r': case 'l'
void TInGameForm::OnKeyDown(SDL_keysym key)
{
if(SendMessage->Focused())
......@@ -844,21 +852,47 @@ void TInGameForm::OnKeyDown(SDL_keysym key)
if(chan->State() == EChannel::PLAYING && !client->Player()->Ready())
SetCursor();
if (BarreAct->Entity() && BarreAct->Entity()->Owner() && BarreAct->Entity()->Owner()->IsMe())
{
std::string move;
ECEntity* entity = BarreAct->Entity();
ECBCase* acase = entity->Move()->Dest();
switch(key.sym)
{
CASE_KEY_UP: move = "^"; acase = acase->MoveUp(); break;
CASE_KEY_DOWN: move = "v"; acase = acase->MoveDown(); break;
CASE_KEY_LEFT: move = "<"; acase = acase->MoveLeft(); break;
CASE_KEY_RIGHT: move = ">"; acase = acase->MoveRight(); break;
default: break;
}
if (move.empty() == false)
{
EContainer* container = NULL;
if (GetWant(entity, SDL_BUTTON_LEFT) == TInGameForm::W_EXTRACT)
client->sendrpl(MSG_ARM, ECArgs(entity->ID(), "(" + TypToStr(acase->X()) + "," + TypToStr(acase->Y())));
if(!IsPressed(SDLK_LALT) && (container = dynamic_cast<ECase*>(acase)->GetContainer(entity)))
client->sendrpl(MSG_ARM, ECArgs(entity->ID(), std::string(")") + container->ID()));
else
client->sendrpl(MSG_ARM, ECArgs(entity->ID(), move));
SetCursor();
return;
}
}
switch(key.sym)
{
case SDLK_UP:
CASE_KEY_UP:
Map->SetPosition(Map->X(), Map->Y()+40);
break;
case SDLK_DOWN:
CASE_KEY_DOWN:
Map->SetPosition(Map->X(), Map->Y()-40);
break;
case SDLK_LEFT:
CASE_KEY_LEFT:
Map->SetPosition(Map->X()+40, Map->Y());
break;
case SDLK_RIGHT:
CASE_KEY_RIGHT:
Map->SetPosition(Map->X()-40, Map->Y());
break;
case SDLK_c:
case SDLK_m:
Map->ToRedraw(ChatHistory);
ChatHistory->SetVisible(true);
Chat->SetVisible(false);
......@@ -871,13 +905,26 @@ void TInGameForm::OnKeyUp(SDL_keysym key)
{
switch (key.sym)
{
CASE_KEY_UP:
CASE_KEY_DOWN:
CASE_KEY_LEFT:
CASE_KEY_RIGHT:
/* does nothing, but it prevents conflicts. */
break;
case SDLK_p:
if(IsPressed(SDLK_LCTRL) && BarreLat->PretButton->Enabled())
{
BarreLat->PretButton->SetEnabled(false);
client->sendrpl(MSG_SET, "+!");
}
break;
case SDLK_n:
{
if(!SendMessage->Focused())
Sound::NextMusic();
break;
}
case SDLK_c:
case SDLK_m:
{
Map->ToRedraw(ChatHistory);
ChatHistory->SetVisible(false);
......@@ -917,7 +964,7 @@ void TInGameForm::OnKeyUp(SDL_keysym key)
}
}
else
FindIdling();
FindIdling(IsPressed(SDLK_LSHIFT));
break;
case SDLK_ESCAPE:
if(!SendMessage->Focused())
......@@ -940,11 +987,9 @@ void TInGameForm::OnKeyUp(SDL_keysym key)
else
{
std::string s = SendMessage->GetString();
bool send_message = true;
#ifdef DEBUG
if(IsPressed(SDLK_LSHIFT) && IsPressed(SDLK_LALT))
{
send_message = false;
if(s == "show_map on")
{
chan->Map()->SetBrouillard(false);
......@@ -955,10 +1000,8 @@ void TInGameForm::OnKeyUp(SDL_keysym key)
chan->Map()->SetBrouillard(true);
InGameForm->Map->SetBrouillard(true);
}
else send_message = true;
}
} else
#endif
if(send_message)
{
client->sendrpl(MSG_MSG, s);
AddInfo(I_CHAT, "<" + client->GetNick() + "> " + s, client->Player());
......@@ -1167,18 +1210,10 @@ void TInGameForm::OnClic(const Point2i& mouse, int button, bool&)
{
ECBCase* init_case = selected_entity->Move()->Dest() ? selected_entity->Move()->Dest()
: selected_entity->Case();
EContainer* contener = 0;
EContainer* container = 0;
if(!IsPressed(SDLK_LALT))
{
std::vector<ECBEntity*> ents = acase->Entities()->List();
for(std::vector<ECBEntity*>::iterator it = ents.begin(); it != ents.end(); ++it)
if(*it && !(*it)->Locked() && (contener = dynamic_cast<EContainer*>(*it)) &&
contener->CanContain(selected_entity) && contener->Owner() && dynamic_cast<ECPlayer*>(contener->Owner())->IsMe() &&
contener->Move()->Empty())
break;
else
contener = 0;
}
container = acase->GetContainer(selected_entity);
std::stack<ECBMove::E_Move> moves;
if(selected_entity->FindFastPath(acase, moves, init_case))
{
......@@ -1187,7 +1222,7 @@ void TInGameForm::OnClic(const Point2i& mouse, int button, bool&)
{
ECBMove::E_Move m = moves.top();
moves.pop();
if(contener && moves.empty()) break;
if(container && moves.empty()) break;
switch(m)
{
case ECBMove::Up: args += "^"; break;
......@@ -1205,9 +1240,9 @@ void TInGameForm::OnClic(const Point2i& mouse, int button, bool&)
else
client->sendrpl(MSG_ARM, args);
}
if(contener)
if(container)
{
client->sendrpl(MSG_ARM, ECArgs(selected_entity->ID(), std::string(")") + contener->ID()));
client->sendrpl(MSG_ARM, ECArgs(selected_entity->ID(), std::string(")") + container->ID()));
SetCursor();
return;
}
......
......@@ -251,7 +251,11 @@ public:
#define I_GREAT 0x020
void AddInfo(int flags, std::string line, ECPlayer* = 0);
void FindIdling();
/** Find and select the next idling unit.
*
* @param next if true, select the next one, otherwise the previous one.
*/
void FindIdling(bool next = true);
/* Attributs */
public:
......
/* src/Map.cpp - Map classes
*
* Copyright (C) 2005-2007 Romain Bignon <Progs@headfucking.net>
* Copyright (C) 2005-2011 Romain Bignon <romain@menareants.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -528,6 +528,21 @@ void ECase::SetImage(ECSpriteBase* spr)
SetMustRedraw();
}
ECBContainer* ECase::GetContainer(ECEntity* entity)
{
EContainer* container = NULL;
std::vector<ECBEntity*> ents = this->Entities()->List();
for(std::vector<ECBEntity*>::iterator it = ents.begin(); it != ents.end(); ++it)
if(*it && !(*it)->Locked() && (container = dynamic_cast<EContainer*>(*it)) &&
container->CanContain(entity) && container->Owner() == entity->Owner() &&
container->Move()->Empty())
break;
else
container = 0;
return container;
}
/********************************************************************************************
* ECMap *
********************************************************************************************/
......
/* src/Map.h - Header of Map.cpp
*
* Copyright (C) 2005-2007 Romain Bignon <Progs@headfucking.net>
* Copyright (C) 2005-2011 Romain Bignon <romain@menareants.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -34,6 +34,7 @@ class ECEntity;
class EC_Client;
class Color;
class ECPlayer;
class ECBContainer;
class ECMap;
struct case_img_t
......@@ -256,6 +257,9 @@ public:
bool MustRedraw() const { return must_redraw; }
void SetMustRedraw(bool b = true) { must_redraw = b; }
/** Get container for this entity */
ECBContainer* GetContainer(ECEntity* entity);
/* Variables privées */
protected:
ECSprite* image;
......
......@@ -16,6 +16,9 @@ animation time, where you can see all events in the day, with engagements, etc.
At the end of turn, this is a new day, and a new morning to prepare units.
.br
.SH CONTROLS
.PP
Global shortcuts:
.br
*
.B F1:
Show help screen
......@@ -25,8 +28,8 @@ Show help screen
Toggle full-screen
.br
*
.B Tab:
Find idling entities
.B <>^v:
Scroll map on screen
.br
*
.B Return:
......@@ -39,18 +42,34 @@ Enter a message to send it to other players.
).
.br
*
.B m:
You can display chat's history by maintain this key.
.br
*
.B n:
Change music
.br
*
.B BACKSPACE:
If a boat, a train or a plane is selected, you can extract the unit contained by maintain
.B BACKSPACE
key, and click on the destination case (showed in blue).
.B C-A-p:
You are ready
.PP
Unit interactions:
.br
*
.B c:
You can display chat's history by maintain this key.
.B Tab:
Find idling units
.br
*
.B <>^v:
Move the unit
.br
*
.B SPACE:
If a boat, a train or a plane is selected, you can extract
the unit contained by pressing this key, and click on the
destination case (in blue).
.br
.SH "SEE ALSO"
.BR menareants-server (6),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment