mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-23 00:28:08 +02:00
* @previous revision: not an AI bug, it was a vector traversing bug. Fixed :-)
* Scrolling through scenario list with mouse wheel, HOME, END, PAGE UP and PAGE DOWN buttons * Starting selected scenario with double-click
This commit is contained in:
@ -436,7 +436,7 @@ SelectionTab::SelectionTab(EState Type, const boost::function<void(CMapInfo *)>
|
|||||||
OBJ_CONSTRUCTION;
|
OBJ_CONSTRUCTION;
|
||||||
selectionPos = 0;
|
selectionPos = 0;
|
||||||
|
|
||||||
used = LCLICK;
|
used = LCLICK | WHEEL | KEYBOARD | DOUBLECLICK;
|
||||||
slider = NULL;
|
slider = NULL;
|
||||||
type = Type;
|
type = Type;
|
||||||
std::vector<FileInfo> toParse;
|
std::vector<FileInfo> toParse;
|
||||||
@ -528,14 +528,19 @@ void SelectionTab::select( int position )
|
|||||||
{
|
{
|
||||||
// New selection. py is the index in curItems.
|
// New selection. py is the index in curItems.
|
||||||
int py = position + slider->value;
|
int py = position + slider->value;
|
||||||
if (py < curItems.size())
|
amax(py, 0);
|
||||||
{
|
amin(py, curItems.size()-1);
|
||||||
|
|
||||||
CGI->soundh->playSound(soundBase::button);
|
CGI->soundh->playSound(soundBase::button);
|
||||||
selectionPos = py;
|
selectionPos = py;
|
||||||
|
|
||||||
|
if(position < 0)
|
||||||
|
slider->moveTo(slider->value + position);
|
||||||
|
else if(position >= positions)
|
||||||
|
slider->moveTo(slider->value + position - positions + 1);
|
||||||
|
|
||||||
onSelect(curItems[py]);
|
onSelect(curItems[py]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
int SelectionTab::getPosition( int x, int y )
|
int SelectionTab::getPosition( int x, int y )
|
||||||
{
|
{
|
||||||
@ -667,6 +672,47 @@ void SelectionTab::clickLeft( tribool down, bool previousState )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SelectionTab::wheelScrolled( bool down, bool in )
|
||||||
|
{
|
||||||
|
slider->moveTo(slider->value + 3 * (down ? +1 : -1));
|
||||||
|
//select(selectionPos - slider->value + (down ? +1 : -1));
|
||||||
|
}
|
||||||
|
|
||||||
|
void SelectionTab::keyPressed( const SDL_KeyboardEvent & key )
|
||||||
|
{
|
||||||
|
if(key.state != SDL_PRESSED) return;
|
||||||
|
|
||||||
|
int moveBy = 0;
|
||||||
|
switch(key.keysym.sym)
|
||||||
|
{
|
||||||
|
case SDLK_UP:
|
||||||
|
moveBy = -1;
|
||||||
|
break;
|
||||||
|
case SDLK_DOWN:
|
||||||
|
moveBy = +1;
|
||||||
|
break;
|
||||||
|
case SDLK_PAGEUP:
|
||||||
|
moveBy = -positions+1;
|
||||||
|
break;
|
||||||
|
case SDLK_PAGEDOWN:
|
||||||
|
moveBy = +positions-1;
|
||||||
|
break;
|
||||||
|
case SDLK_HOME:
|
||||||
|
select(-slider->value);
|
||||||
|
return;
|
||||||
|
case SDLK_END:
|
||||||
|
select(curItems.size() - slider->value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
select(selectionPos - slider->value + moveBy);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SelectionTab::onDoubleClick()
|
||||||
|
{
|
||||||
|
//act as start button was pressed
|
||||||
|
(static_cast<CSelectionScreen*>(parent))->start->callback();
|
||||||
|
}
|
||||||
|
|
||||||
InfoCard::InfoCard( EState Type )
|
InfoCard::InfoCard( EState Type )
|
||||||
{
|
{
|
||||||
OBJ_CONSTRUCTION;
|
OBJ_CONSTRUCTION;
|
||||||
|
@ -96,6 +96,9 @@ public:
|
|||||||
|
|
||||||
void showAll(SDL_Surface * to);
|
void showAll(SDL_Surface * to);
|
||||||
void clickLeft(tribool down, bool previousState);
|
void clickLeft(tribool down, bool previousState);
|
||||||
|
void wheelScrolled(bool down, bool in);
|
||||||
|
void keyPressed(const SDL_KeyboardEvent & key);
|
||||||
|
void onDoubleClick();
|
||||||
SelectionTab(EState Type, const boost::function<void(CMapInfo *)> &OnSelect);
|
SelectionTab(EState Type, const boost::function<void(CMapInfo *)> &OnSelect);
|
||||||
~SelectionTab();
|
~SelectionTab();
|
||||||
};
|
};
|
||||||
|
@ -178,8 +178,28 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent)
|
|||||||
CGI->curh->cursorMove(sEvent->motion.x, sEvent->motion.y);
|
CGI->curh->cursorMove(sEvent->motion.x, sEvent->motion.y);
|
||||||
handleMouseMotion(sEvent);
|
handleMouseMotion(sEvent);
|
||||||
}
|
}
|
||||||
else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_LEFT))
|
else if (sEvent->type==SDL_MOUSEBUTTONDOWN)
|
||||||
{
|
{
|
||||||
|
if(sEvent->button.button == SDL_BUTTON_LEFT)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(lastClick == sEvent->motion && (SDL_GetTicks() - lastClickTime) < 300)
|
||||||
|
{
|
||||||
|
std::list<CIntObject*> hlp = doubleClickInterested;
|
||||||
|
for(std::list<CIntObject*>::iterator i=hlp.begin(); i != hlp.end();i++)
|
||||||
|
{
|
||||||
|
if(!vstd::contains(doubleClickInterested,*i)) continue;
|
||||||
|
if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
|
||||||
|
{
|
||||||
|
(*i)->onDoubleClick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
lastClick = sEvent->motion;
|
||||||
|
lastClickTime = SDL_GetTicks();
|
||||||
|
|
||||||
std::list<CIntObject*> hlp = lclickable;
|
std::list<CIntObject*> hlp = lclickable;
|
||||||
for(std::list<CIntObject*>::iterator i=hlp.begin(); i != hlp.end();i++)
|
for(std::list<CIntObject*>::iterator i=hlp.begin(); i != hlp.end();i++)
|
||||||
{
|
{
|
||||||
@ -192,6 +212,30 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (sEvent->button.button == SDL_BUTTON_RIGHT)
|
||||||
|
{
|
||||||
|
std::list<CIntObject*> hlp = rclickable;
|
||||||
|
for(std::list<CIntObject*>::iterator i=hlp.begin(); i != hlp.end();i++)
|
||||||
|
{
|
||||||
|
if(!vstd::contains(rclickable,*i)) continue;
|
||||||
|
if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
|
||||||
|
{
|
||||||
|
prev = (*i)->pressedR;
|
||||||
|
(*i)->pressedR = true;
|
||||||
|
(*i)->clickRight(true, prev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(sEvent->button.button == SDL_BUTTON_WHEELDOWN || sEvent->button.button == SDL_BUTTON_WHEELUP)
|
||||||
|
{
|
||||||
|
std::list<CIntObject*> hlp = wheelInterested;
|
||||||
|
for(std::list<CIntObject*>::iterator i=hlp.begin(); i != hlp.end();i++)
|
||||||
|
{
|
||||||
|
if(!vstd::contains(wheelInterested,*i)) continue;
|
||||||
|
(*i)->wheelScrolled(sEvent->button.button == SDL_BUTTON_WHEELDOWN, isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT))
|
else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT))
|
||||||
{
|
{
|
||||||
std::list<CIntObject*> hlp = lclickable;
|
std::list<CIntObject*> hlp = lclickable;
|
||||||
@ -208,20 +252,6 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent)
|
|||||||
(*i)->clickLeft(boost::logic::indeterminate, prev);
|
(*i)->clickLeft(boost::logic::indeterminate, prev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_RIGHT))
|
|
||||||
{
|
|
||||||
std::list<CIntObject*> hlp = rclickable;
|
|
||||||
for(std::list<CIntObject*>::iterator i=hlp.begin(); i != hlp.end();i++)
|
|
||||||
{
|
|
||||||
if(!vstd::contains(rclickable,*i)) continue;
|
|
||||||
if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
|
|
||||||
{
|
|
||||||
prev = (*i)->pressedR;
|
|
||||||
(*i)->pressedR = true;
|
|
||||||
(*i)->clickRight(true, prev);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_RIGHT))
|
else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_RIGHT))
|
||||||
{
|
{
|
||||||
std::list<CIntObject*> hlp = rclickable;
|
std::list<CIntObject*> hlp = rclickable;
|
||||||
@ -455,6 +485,10 @@ void CIntObject::activate()
|
|||||||
activateKeys();
|
activateKeys();
|
||||||
if(used & TIME)
|
if(used & TIME)
|
||||||
activateTimer();
|
activateTimer();
|
||||||
|
if(used & WHEEL)
|
||||||
|
activateWheel();
|
||||||
|
if(used & DOUBLECLICK)
|
||||||
|
activateDClick();
|
||||||
|
|
||||||
if(defActions & ACTIVATE)
|
if(defActions & ACTIVATE)
|
||||||
for(size_t i = 0; i < children.size(); i++)
|
for(size_t i = 0; i < children.size(); i++)
|
||||||
@ -478,6 +512,10 @@ void CIntObject::deactivate()
|
|||||||
deactivateKeys();
|
deactivateKeys();
|
||||||
if(used & TIME)
|
if(used & TIME)
|
||||||
deactivateTimer();
|
deactivateTimer();
|
||||||
|
if(used & WHEEL)
|
||||||
|
deactivateWheel();
|
||||||
|
if(used & DOUBLECLICK)
|
||||||
|
deactivateDClick();
|
||||||
|
|
||||||
if(defActions & DEACTIVATE)
|
if(defActions & DEACTIVATE)
|
||||||
for(size_t i = 0; i < children.size(); i++)
|
for(size_t i = 0; i < children.size(); i++)
|
||||||
@ -546,6 +584,42 @@ bool CIntObject::isItInLoc( const SDL_Rect &rect, const Point &p )
|
|||||||
return isItIn(&rect, p.x - pos.x, p.y - pos.y);
|
return isItIn(&rect, p.x - pos.x, p.y - pos.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CIntObject::activateWheel()
|
||||||
|
{
|
||||||
|
GH.wheelInterested.push_front(this);
|
||||||
|
active |= WHEEL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CIntObject::deactivateWheel()
|
||||||
|
{
|
||||||
|
std::list<CIntObject*>::iterator hlp = std::find(GH.wheelInterested.begin(),GH.wheelInterested.end(),this);
|
||||||
|
assert(hlp != GH.wheelInterested.end());
|
||||||
|
GH.wheelInterested.erase(hlp);
|
||||||
|
active &= ~WHEEL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CIntObject::wheelScrolled(bool down, bool in)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CIntObject::activateDClick()
|
||||||
|
{
|
||||||
|
GH.doubleClickInterested.push_front(this);
|
||||||
|
active |= DOUBLECLICK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CIntObject::deactivateDClick()
|
||||||
|
{
|
||||||
|
std::list<CIntObject*>::iterator hlp = std::find(GH.doubleClickInterested.begin(),GH.doubleClickInterested.end(),this);
|
||||||
|
assert(hlp != GH.doubleClickInterested.end());
|
||||||
|
GH.doubleClickInterested.erase(hlp);
|
||||||
|
active &= ~DOUBLECLICK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CIntObject::onDoubleClick()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
CPicture::CPicture( SDL_Surface *BG, int x, int y, bool Free )
|
CPicture::CPicture( SDL_Surface *BG, int x, int y, bool Free )
|
||||||
{
|
{
|
||||||
bg = BG;
|
bg = BG;
|
||||||
|
@ -93,6 +93,16 @@ struct Point
|
|||||||
{
|
{
|
||||||
return x < b.x && y < b.y;
|
return x < b.x && y < b.y;
|
||||||
}
|
}
|
||||||
|
template<typename T> Point& operator=(const T &t)
|
||||||
|
{
|
||||||
|
x = t.x;
|
||||||
|
y = t.y;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
template<typename T> bool operator==(const T &t)
|
||||||
|
{
|
||||||
|
return x == t.x && y == t.y;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Rect : public SDL_Rect
|
struct Rect : public SDL_Rect
|
||||||
@ -309,9 +319,19 @@ public:
|
|||||||
void deactivateTimer();
|
void deactivateTimer();
|
||||||
virtual void tick();
|
virtual void tick();
|
||||||
|
|
||||||
enum {LCLICK=1, RCLICK=2, HOVER=4, MOVE=8, KEYBOARD=16, TIME=32, GENERAL=64};
|
//mouse wheel
|
||||||
ui8 active;
|
void activateWheel();
|
||||||
ui8 used;
|
void deactivateWheel();
|
||||||
|
virtual void wheelScrolled(bool down, bool in);
|
||||||
|
|
||||||
|
//double click
|
||||||
|
void activateDClick();
|
||||||
|
void deactivateDClick();
|
||||||
|
virtual void onDoubleClick();
|
||||||
|
|
||||||
|
enum {LCLICK=1, RCLICK=2, HOVER=4, MOVE=8, KEYBOARD=16, TIME=32, GENERAL=64, WHEEL=128, DOUBLECLICK=256, ALL=0xffff};
|
||||||
|
ui16 active;
|
||||||
|
ui16 used;
|
||||||
|
|
||||||
enum {ACTIVATE=1, DEACTIVATE=2, UPDATE=4, SHOWALL=8, DISPOSE=16, SHARE_POS=32};
|
enum {ACTIVATE=1, DEACTIVATE=2, UPDATE=4, SHOWALL=8, DISPOSE=16, SHARE_POS=32};
|
||||||
ui8 defActions; //which calls will be tried to be redirected to children
|
ui8 defActions; //which calls will be tried to be redirected to children
|
||||||
@ -390,12 +410,17 @@ public:
|
|||||||
std::list<CIntObject*> keyinterested;
|
std::list<CIntObject*> keyinterested;
|
||||||
std::list<CIntObject*> motioninterested;
|
std::list<CIntObject*> motioninterested;
|
||||||
std::list<CIntObject*> timeinterested;
|
std::list<CIntObject*> timeinterested;
|
||||||
|
std::list<CIntObject*> wheelInterested;
|
||||||
|
std::list<CIntObject*> doubleClickInterested;
|
||||||
|
|
||||||
//objs to blit
|
//objs to blit
|
||||||
std::vector<IShowable*> objsToBlit;
|
std::vector<IShowable*> objsToBlit;
|
||||||
|
|
||||||
SDL_Event * current; //current event
|
SDL_Event * current; //current event
|
||||||
|
|
||||||
|
Point lastClick;
|
||||||
|
unsigned lastClickTime;
|
||||||
|
|
||||||
void totalRedraw(); //forces total redraw (using showAll)
|
void totalRedraw(); //forces total redraw (using showAll)
|
||||||
void simpleRedraw(); //update only top interface and draw background from buffer
|
void simpleRedraw(); //update only top interface and draw background from buffer
|
||||||
void popInt(IShowActivable *top); //removes given interface from the top and activates next
|
void popInt(IShowActivable *top); //removes given interface from the top and activates next
|
||||||
|
@ -3708,16 +3708,16 @@ void CBank::reset()
|
|||||||
|
|
||||||
int val1 = ran()%100;
|
int val1 = ran()%100;
|
||||||
int chance = 0;
|
int chance = 0;
|
||||||
for (ui8 i = 1; i <= VLC->objh->banksInfo[index].size(); i++)
|
for (ui8 i = 0; i < VLC->objh->banksInfo[index].size(); i++)
|
||||||
{
|
{
|
||||||
if (val1 < (chance += VLC->objh->banksInfo[index][i].chance))
|
// if (val1 < (chance += VLC->objh->banksInfo[index][i].chance))
|
||||||
cb->setObjProperty (id, 13, i);
|
// cb->setObjProperty (id, 13, i);
|
||||||
}
|
}
|
||||||
artifacts.clear();
|
artifacts.clear();
|
||||||
for (ui8 i = 1; i <= 4; i++)
|
for (ui8 i = 1; i <= 4; i++)
|
||||||
{
|
{
|
||||||
for (ui8 j = 1; j <= bc->artifacts[i]; j++)
|
// for (ui8 j = 1; j <= bc->artifacts[i]; j++)
|
||||||
cb->setObjProperty (id, 18, i);
|
// cb->setObjProperty (id, 18, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user