PyObject* get_techs(int level) { PyObject* list = PyList_New(0); int num, i; advance_index_iterate(A_FIRST, i) { if (player_invention_reachable(client.conn.playing, i, FALSE) && TECH_KNOWN != player_invention_state(client.conn.playing, i) && (level > (num = num_unknown_techs_for_goal(client.conn.playing, i)) /*|| player_research_get(client.conn.playing) == research->tech_goal*/)) { PyList_Append(list, Py_BuildValue("isi", i, advance_name_translation(advance_by_number(i)), num)); } } advance_index_iterate_end; return list; }
/**************************************************************** ... *****************************************************************/ static int create_advances_list(struct player *pplayer, struct player *pvictim, bool make_modal) { Widget spy_tech_form; Widget close_command; Dimension width1, width2; int j; static const char *advances_can_steal[A_LAST+1]; spy_tech_shell = I_T(XtVaCreatePopupShell("spystealtechpopup", (make_modal ? transientShellWidgetClass : topLevelShellWidgetClass), toplevel, NULL)); spy_tech_form = XtVaCreateManagedWidget("spystealtechform", formWidgetClass, spy_tech_shell, NULL); spy_advances_list_label = I_L(XtVaCreateManagedWidget("spystealtechlistlabel", labelWidgetClass, spy_tech_form, NULL)); spy_advances_list = XtVaCreateManagedWidget("spystealtechlist", listWidgetClass, spy_tech_form, NULL); close_command = I_L(XtVaCreateManagedWidget("spystealtechclosecommand", commandWidgetClass, spy_tech_form, NULL)); spy_steal_command = I_L(XtVaCreateManagedWidget("spystealtechcommand", commandWidgetClass, spy_tech_form, XtNsensitive, False, NULL)); XtAddCallback(spy_advances_list, XtNcallback, spy_select_tech_callback, NULL); XtAddCallback(close_command, XtNcallback, spy_close_tech_callback, NULL); XtAddCallback(spy_steal_command, XtNcallback, spy_steal_callback, NULL); XtRealizeWidget(spy_tech_shell); /* Now populate the list */ j = 0; advances_can_steal[j] = _("NONE"); advance_type[j] = -1; if (pvictim) { /* you don't want to know what lag can do -- Syela */ advance_index_iterate(A_FIRST, i) { if(player_invention_state(pvictim, i)==TECH_KNOWN && (player_invention_state(pplayer, i)==TECH_UNKNOWN || player_invention_state(pplayer, i)==TECH_PREREQS_KNOWN)) { advances_can_steal[j] = advance_name_translation(advance_by_number(i)); advance_type[j++] = i; } } { static struct astring str = ASTRING_INIT; /* TRANS: %s is a unit name, e.g., Spy */ astr_set(&str, _("At %s's Discretion"), unit_name_translation(game_unit_by_number(diplomat_id))); advances_can_steal[j] = astr_str(&str); advance_type[j++] = A_UNSET; } } advance_index_iterate_end; if(j == 0) j++; advances_can_steal[j] = NULL; XtSetSensitive(spy_steal_command, FALSE); XawListChange(spy_advances_list, (char **)advances_can_steal, 0, 0, 1); XtVaGetValues(spy_advances_list, XtNwidth, &width1, NULL); XtVaGetValues(spy_advances_list_label, XtNwidth, &width2, NULL); XtVaSetValues(spy_advances_list, XtNwidth, MAX(width1,width2), NULL); XtVaSetValues(spy_advances_list_label, XtNwidth, MAX(width1,width2), NULL); return j; }
static LONG APIENTRY HelpdlgWndProc(HWND hWnd,UINT uMsg, UINT wParam, LONG lParam) { PAINTSTRUCT ps; HDC hdc; switch (uMsg) { case WM_CREATE: helpdlg_win=hWnd; return 0; case WM_DESTROY: helpdlg_win=NULL; break; case WM_GETMINMAXINFO: break; case WM_SIZE: break; case WM_CLOSE: DestroyWindow(hWnd); break; case WM_PAINT: hdc=BeginPaint(hWnd,(LPPAINTSTRUCT)&ps); if (drawn_unit_type) help_draw_unit(hdc, drawn_unit_type); EndPaint(hWnd,(LPPAINTSTRUCT)&ps); break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDCANCEL: DestroyWindow(hWnd); break; case ID_HELP_TECH_LINK: case ID_HELP_UNIT_LINK: case ID_HELP_WONDER_LINK: case ID_HELP_IMPROVEMENT_LINK: { char s[128]; GetWindowText((HWND)lParam,s,sizeof(s)); if (strcmp(s, _("(Never)")) != 0 && strcmp(s, _("None")) != 0 && strcmp(s, advance_name_translation(advance_by_number(A_NONE))) != 0) select_help_item_string(s,page_type_from_id(LOWORD(wParam))); } break; case ID_HELP_LIST: { if (HIWORD(wParam)==LBN_SELCHANGE) { int row; const struct help_item *p = NULL; row=ListBox_GetCurSel(helpdlg_list); help_items_iterate(pitem) { if ((row--)==0) { p=pitem; break; } } help_items_iterate_end; if (p) help_update_dialog(p); } } break; } break; default: return DefWindowProc(hWnd,uMsg,wParam,lParam); }
/************************************************************************** ... **************************************************************************/ static int spy_steal_popup(struct widget *pWidget) { struct city *pVcity = pWidget->data.city; int id = MAX_ID - pWidget->ID; struct player *pVictim = NULL; struct CONTAINER *pCont; struct widget *pBuf = NULL; struct widget *pWindow; SDL_String16 *pStr; SDL_Surface *pSurf; int max_col, max_row, col, i, count = 0; SDL_Rect area; popdown_diplomat_dialog(); if(pVcity) { pVictim = city_owner(pVcity); } if (pDiplomat_Dlg || !pVictim) { return 1; } count = 0; advance_index_iterate(A_FIRST, i) { if (player_invention_reachable(client.conn.playing, i, FALSE) && TECH_KNOWN == player_invention_state(pVictim, i) && (TECH_UNKNOWN == player_invention_state(client.conn.playing, i) || TECH_PREREQS_KNOWN == player_invention_state(client.conn.playing, i))) { count++; } } advance_index_iterate_end; if(!count) { /* if there is no known tech to steal then send steal order at Spy's Discretion */ int target_id = pVcity->id; request_diplomat_action(DIPLOMAT_STEAL, id, target_id, advance_count()); return -1; } pCont = fc_calloc(1, sizeof(struct CONTAINER)); pCont->id0 = pVcity->id; pCont->id1 = id;/* spy id */ pDiplomat_Dlg = fc_calloc(1, sizeof(struct diplomat_dialog)); pDiplomat_Dlg->diplomat_id = id; pDiplomat_Dlg->diplomat_target_id = pVcity->id; pDiplomat_Dlg->pdialog = fc_calloc(1, sizeof(struct ADVANCED_DLG)); pStr = create_str16_from_char(_("Select Advance to Steal"), adj_font(12)); pStr->style |= TTF_STYLE_BOLD; pWindow = create_window_skeleton(NULL, pStr, 0); pWindow->action = spy_steal_dlg_window_callback; set_wstate(pWindow , FC_WS_NORMAL); add_to_gui_list(ID_DIPLOMAT_DLG_WINDOW, pWindow); pDiplomat_Dlg->pdialog->pEndWidgetList = pWindow; area = pWindow->area; area.w = MAX(area.w, adj_size(8)); /* ------------------ */ /* exit button */ pBuf = create_themeicon(pTheme->Small_CANCEL_Icon, pWindow->dst, WF_WIDGET_HAS_INFO_LABEL | WF_RESTORE_BACKGROUND); pBuf->info_label = create_str16_from_char(_("Close Dialog (Esc)"), adj_font(12)); area.w += pBuf->size.w + adj_size(10); pBuf->action = exit_spy_steal_dlg_callback; set_wstate(pBuf, FC_WS_NORMAL); pBuf->key = SDLK_ESCAPE; add_to_gui_list(ID_TERRAIN_ADV_DLG_EXIT_BUTTON, pBuf); /* ------------------------- */ count++; /* count + at Spy's Discretion */ /* max col - 104 is steal tech widget width */ max_col = (Main.screen->w - (pWindow->size.w - pWindow->area.w) - adj_size(2)) / adj_size(104); /* max row - 204 is steal tech widget height */ max_row = (Main.screen->h - (pWindow->size.h - pWindow->area.h)) / adj_size(204); /* make space on screen for scrollbar */ if (max_col * max_row < count) { max_col--; } if (count < max_col + 1) { col = count; } else { if (count < max_col + adj_size(3)) { col = max_col - adj_size(2); } else { if (count < max_col + adj_size(5)) { col = max_col - 1; } else { col = max_col; } } } pStr = create_string16(NULL, 0, adj_font(10)); pStr->style |= (TTF_STYLE_BOLD | SF_CENTER); count = 0; advance_index_iterate(A_FIRST, i) { if (player_invention_reachable(client.conn.playing, i, FALSE) && TECH_KNOWN == player_invention_state(pVictim, i) && (TECH_UNKNOWN == player_invention_state(client.conn.playing, i) || TECH_PREREQS_KNOWN == player_invention_state(client.conn.playing, i))) { count++; copy_chars_to_string16(pStr, advance_name_translation(advance_by_number(i))); pSurf = create_sellect_tech_icon(pStr, i, FULL_MODE); pBuf = create_icon2(pSurf, pWindow->dst, WF_FREE_THEME | WF_RESTORE_BACKGROUND); set_wstate(pBuf, FC_WS_NORMAL); pBuf->action = spy_steal_callback; pBuf->data.cont = pCont; add_to_gui_list(MAX_ID - i, pBuf); if (count > (col * max_row)) { set_wflag(pBuf, WF_HIDDEN); } } } advance_index_iterate_end; /* get spy tech */ i = advance_number(unit_type(game_unit_by_number(id))->require_advance); copy_chars_to_string16(pStr, _("At Spy's Discretion")); pSurf = create_sellect_tech_icon(pStr, i, FULL_MODE); pBuf = create_icon2(pSurf, pWindow->dst, (WF_FREE_THEME | WF_RESTORE_BACKGROUND| WF_FREE_DATA)); set_wstate(pBuf, FC_WS_NORMAL); pBuf->action = spy_steal_callback; pBuf->data.cont = pCont; add_to_gui_list(MAX_ID - advance_count(), pBuf); count++; /* --------------------------------------------------------- */ FREESTRING16(pStr); pDiplomat_Dlg->pdialog->pBeginWidgetList = pBuf; pDiplomat_Dlg->pdialog->pBeginActiveWidgetList = pDiplomat_Dlg->pdialog->pBeginWidgetList; pDiplomat_Dlg->pdialog->pEndActiveWidgetList = pDiplomat_Dlg->pdialog->pEndWidgetList->prev->prev; /* -------------------------------------------------------------- */ i = 0; if (count > col) { count = (count + (col - 1)) / col; if (count > max_row) { pDiplomat_Dlg->pdialog->pActiveWidgetList = pDiplomat_Dlg->pdialog->pEndActiveWidgetList; count = max_row; i = create_vertical_scrollbar(pDiplomat_Dlg->pdialog, col, count, TRUE, TRUE); } } else { count = 1; } area.w = MAX(area.w, (col * pBuf->size.w + adj_size(2) + i)); area.h = count * pBuf->size.h + adj_size(2); /* alloca window theme and win background buffer */ pSurf = theme_get_background(theme, BACKGROUND_SPYSTEALDLG); if (resize_window(pWindow, pSurf, NULL, (pWindow->size.w - pWindow->area.w) + area.w, (pWindow->size.h - pWindow->area.h) + area.h)) { FREESURFACE(pSurf); } area = pWindow->area; widget_set_position(pWindow, (Main.screen->w - pWindow->size.w) / 2, (Main.screen->h - pWindow->size.h) / 2); /* exit button */ pBuf = pWindow->prev; pBuf->size.x = area.x + area.w - pBuf->size.w - 1; pBuf->size.y = pWindow->size.y + adj_size(2); setup_vertical_widgets_position(col, area.x + 1, area.y, 0, 0, pDiplomat_Dlg->pdialog->pBeginActiveWidgetList, pDiplomat_Dlg->pdialog->pEndActiveWidgetList); if(pDiplomat_Dlg->pdialog->pScroll) { setup_vertical_scrollbar_area(pDiplomat_Dlg->pdialog->pScroll, area.x + area.w, area.y, area.h, TRUE); } redraw_group(pDiplomat_Dlg->pdialog->pBeginWidgetList, pWindow, FALSE); widget_mark_dirty(pWindow); return -1; }