#include "amigo.h" #include "gemui.h" #include "gamewin.h" #undef BLACK #undef WHITE #include #include #include #include #include #define FIS_HOLLOW 0 #define FIS_SOLID 1 #define FIS_PATTERN 2 extern short showTrees,showMoveReason,groupInfo; extern char *playReason; GameWindow::GameWindow(GEMactivity& act, GEMrsc& rsc) : GEMformwindow(act,rsc,GAMEWIN,CLOSER|MOVER|NAME|INFO|SIZER), VDI(), GEMuserobject(*this,GRID), screen(*this), colour_choice(rsc,COLOUR_MENU), handicap_choice(rsc,HANDICAP_MENU), viewwin((({Open();/* Open me first! */}),act),rsc,this), game_not_in_progress(rsc.String(NO_GAME)), game_over(rsc.String(GAMEOVER)), i_am_thinking(rsc.String(THINKING)), cpu_passed(rsc.String(CPUPASSED)), click_on_dead_groups(rsc.String(COUNTUP)), about(rsc,ABOUT) { for (int im=0; imTranslateTo(FALSE); //white_stone[im]->TranslateTo(FALSE); //stone_mask[im]->TranslateTo(FALSE); //black_stone[im]->ClearCache(); //white_stone[im]->ClearCache(); //stone_mask[im]->ClearCache(); } SetName(rsc.String(GAMEWIN_TITLE)); // Don't need to modify them - keep them in dev form. ingame = counting = 0; new_handicap = current_handicap = 0; humanColor = WHITE; new_color = amigoColor = BLACK; amigo_last_x = amigo_last_y = human_last_x = human_last_y = -1; ShowAndHide(); ClearBoard(); } void GameWindow::ShowAndHide() { bool redraw=FALSE; if (Object(NEW_GAME).HideTree(ingame||counting)!=(ingame||counting)) redraw=TRUE; if (Object(PASS).HideTree(!ingame)!=!ingame) redraw=TRUE; if (Object(COUNTING_DONE).HideTree(!counting)!=!counting) redraw=TRUE; if (Object(RESIGN).HideTree(!ingame)!=!ingame) redraw=TRUE; if (redraw) { RedrawObjectFromRoot(VARIABLE_BUTTONS); //RedrawObject(CONTROL_PANEL,0,0,Object(CONTROL_PANEL).Width(),Object(VARIABLE_BUTTONS).Height()); } } GEMfeedback GameWindow::DoItem(int item, const GEMevent& e) { switch (item) { case GRID: InputStone(e); break; case NEW_GAME: NewGame(); break; case PASS: Pass(); break; case COUNTING_DONE: Pass(); // (in Xamigo, pass is used for both) break; case RESIGN: Resign(); break; case COLOUR: ChooseColour(); break; case HANDICAP: ChooseHandicap(); break; case SHOW_REASON: ; // It's just a flag break; case DO_VIEW: viewwin.Open(); break; case DO_ABOUT: about.Do(); } return ContinueInteraction; } static bool XThroughRect(int x, GRect& r) { return x>=r.g_x && x=r.g_y && ypb_xc,p->pb_yc,p->pb_wc,p->pb_hc); GRect objclip(p->pb_x,p->pb_y,GEMuserobject::Width(),GEMuserobject::Height()); drawclip.Clip(objclip); clip(drawclip.g_x,drawclip.g_y,drawclip.g_x+drawclip.g_w-1,drawclip.g_y+drawclip.g_h-1); int size=viewwin.StoneSize(); // Pixel units int x=p->pb_x; int y=p->pb_y; int xspace=(GEMuserobject::Width()-1)/(NUMLINES+1); int yspace=(GEMuserobject::Height()-1)/(NUMLINES+1); int mx=x+xspace*(NUMLINES+1); int my=y+yspace*(NUMLINES+1); int spotradius=max(min(xspace,yspace)/5,1); int highlightradius=min(xspace/5,min(yspace/5,stone_mask[size]->Width()/2-1)); // Position units (0..NUMLINES-1) GRect posclip; posclip.g_x=max(0,(drawclip.g_x-x-xspace)/xspace); posclip.g_y=max(0,(drawclip.g_y-y-xspace)/yspace); posclip.g_w=min(NUMLINES-posclip.g_x,(drawclip.g_w+xspace*2-1)/xspace); posclip.g_h=min(NUMLINES-posclip.g_y,(drawclip.g_h+yspace*2-1)/yspace); // Box int pat=viewwin.BoardPattern(); if (pat>0 && pat<7) { sf_color(viewwin.BoardColour()); sf_interior(FIS_PATTERN); sf_style(pat); } else { sf_color(pat ? viewwin.BoardColour() : 0); sf_interior(FIS_SOLID); } sf_perimeter(1); bar(x,y,mx,my); // Lines sl_color(viewwin.LineColour()); sl_width(1); // Horizontal lines for (int j=0; jWidth()/2; int toy=y+yspace+yspace*j-img->Height()/2; // Monochrome int b_w[2]={1,0}; // BLACK, WHITE [gemfast #undef'd here though] int w_b[2]={0,1}; screen.MonoBlit(MD_TRANS,*stone_mask[size],tox,toy,w_b); screen.MonoBlit(MD_TRANS,*img,tox,toy,b_w); // Colour //screen.Blit(DST&!SRC,*stone_mask[size],tox,toy); //screen.Blit(DST|SRC,*img,tox,toy); } } } // Highlights int col=viewwin.HighlightColour(); if (col==0 && amigoColor==WHITE || col==1 && amigoColor==BLACK) col=1-col; sf_color(col); if (InRect(amigo_last_x,amigo_last_y,posclip)) { circle( x+xspace+amigo_last_x*xspace, y+yspace+amigo_last_y*yspace, highlightradius ); } // Clip off clip_off(); } void GameWindow::RedrawPosition(int x, int y) { // From Draw int xspace=(GEMuserobject::Width()-1)/(NUMLINES+1); int yspace=(GEMuserobject::Height()-1)/(NUMLINES+1); // From Draw int size=viewwin.StoneSize(); int tox=xspace+xspace*x-stone_mask[size]->Width()/2; int toy=yspace+yspace*y-stone_mask[size]->Height()/2; RedrawObject(GRID,tox,toy,stone_mask[size]->Width(),stone_mask[size]->Height()); } void GameWindow::NewGame() { ingame = 0; current_handicap = new_handicap; human_passed = amigo_passed = FALSE; amigo_last_x = amigo_last_y = human_last_x = human_last_y = -1; amigoColor = new_color; humanColor = (amigoColor==BLACK?WHITE:BLACK); ClearBoard(); goRestart(current_handicap); Message(""); ingame = 1; if ((amigoColor == BLACK && current_handicap == 0) || (amigoColor == WHITE && current_handicap > 0)) AmigoMove(); ShowAndHide(); } void GameWindow::Pass() { if (!ingame && !counting) { Message(game_not_in_progress); return; } if (!ingame) { if (counting) { CountUp(); counting=0; ShowAndHide(); } Message(""); return; } human_passed = TRUE; CheckBothPassed(); if (ingame) AmigoMove(); } void GameWindow::Resign() { counting = 0; ingame = 0; Message(game_over); ShowAndHide(); } void GameWindow::ChooseColour() { colour_choice[CHOOSE_BLACK].Checked(new_color==WHITE);// ie. human is black colour_choice[CHOOSE_WHITE].Checked(new_color==BLACK);// ie. human is white GEMobject colour(*this,COLOUR); int x,y; colour.GetAbsoluteXY(x,y); int item=colour_choice.Do(x,y); switch (item) { case CHOOSE_BLACK: new_color=WHITE; // ie. human is white break; case CHOOSE_WHITE: new_color=BLACK; // ie. human is black break; default: return; } colour.SetText(colour_choice[item].Text()+2);// 2 = skip checkmark and space } void GameWindow::ChooseHandicap() { for (int i=NO_HANDICAP; i<=MAX_HANDICAP; i++) { handicap_choice[i].Checked(new_handicap==i-NO_HANDICAP); } GEMobject handicap(*this,HANDICAP); int x,y; handicap.GetAbsoluteXY(x,y); int item=handicap_choice.Do(x,y); if (item