Example #1
0
/* deal with events sent to the option window */
void    optionaction(W_Event * data)
{
  register struct option *op;
  int     i;
  register char *cp;

  if (data->y >= CurrentMenu->numopt)
    {
      W_Beep();
      return;
    }
  if (notdone == 0)
    return;

  op = &(CurrentMenu->menu[data->y]);

  /* Update string; don't claim keystrokes for non-string options */
  /* deal with options with string input first */
  if (op->op_string == 0)
    {
      if (data->type == W_EV_KEY)
  return;
    }
  else
    {
      if (data->type == W_EV_BUTTON)
  return;
      switch (data->key)
  {

  case '\b':         /* delete character */
  case '\177':
    cp = op->op_string;
    i = strlen(cp);
    if (i > 0)
      {
        cp += i - 1;
        *cp = '\0';
      }
    break;

  case '\027':         /* word erase */
    cp = op->op_string;
    i = strlen(cp);
    /* back up over blanks */
    while (--i >= 0 && isspace(cp[i]))
      ;
    i++;
    /* back up over non-blanks */
    while (--i >= 0 && !isspace(cp[i]))
      ;
    i++;
    cp[i] = '\0';
    break;

  case '\025':         /* kill line */
  case '\030':
    op->op_string[0] = '\0';
    break;

  default:         /* add character to the list
              *
              */
    if (data->key < 32 || data->key > 127)
      break;
    cp = op->op_string;
    i = strlen(cp);
    if (i < (op->op_size - 1) && !iscntrl(data->key))
      {
        cp += i;
        cp[1] = '\0';
        cp[0] = data->key;
      }
    else
      W_Beep();
    break;
  }
    }

  /* Toggle int, if it exists */
  if (op->op_array)
    {
      if (data->key == W_RBUTTON)
  {
    (*op->op_option)++;
    if (*(op->op_array)[*op->op_option] == '\0')
      {
        *op->op_option = 0;
      }
  }
      else if (data->key == W_MBUTTON)
  {
    /* set option number to zero on the middle key to ease shutoff */
    *op->op_option = 0;
  }
      else if (data->key == W_LBUTTON)
  {
    /* if left button, decrease option  */
    (*op->op_option)--;
    /* if decreased too far, set to top option */
    if (*(op->op_option) < 0)
      {
        *op->op_option = 0;
        while (*(op->op_array)[*op->op_option] != '\0')
    {
      (*op->op_option)++;
    }
        (*op->op_option)--;
      }
  }


      /* Actions to be taken when certain options are selected. (Yes, this is
       * * * a hack). */

      if (op->op_option == &plistStyle)
  {
    if (plistCustomLayout == 0 && plistStyle == 0)
      plistStyle = (data->key == W_LBUTTON) ? PLISTLASTSTYLE : 1;

    RedrawPlayerList();
  }
      else if (op->op_option == &showgalactic)
  {
    redrawall = 1;
  }

#ifdef ROTATERACE
      else if (rotate != old_rotate)
  {
    register i;
    register struct planet *l;
    register struct player *j;

    redrawall = 1;
    reinitPlanets = 1;

    for (i = 0, l = planets; i < MAXPLANETS; i++, l++)
      {
        if (rotate)
    {
      rotate_deg = -old_rotate_deg + rotate * 64;
      rotate_coord(&l->pl_x, &l->pl_y, rotate_deg, GWIDTH / 2, GWIDTH / 2);
      rotate_deg = rotate * 64;
    }
        else
    {
      rotate_deg = -old_rotate_deg;
      rotate_coord(&l->pl_x, &l->pl_y, rotate_deg, GWIDTH / 2, GWIDTH / 2);
      rotate_deg = 0;
    }
      }

    /* we could wait for the server to do this but looks better if we *
     *
     * * do it now. */
    for (i = 0, j = players; i < MAXPLAYER; i++, j++)
      {
        if (j->p_status != PALIVE)
    continue;
        if (rotate)
    {
      rotate_deg = -old_rotate_deg + rotate * 64;
      rotate_coord(&j->p_x, &j->p_y, rotate_deg,
             GWIDTH / 2, GWIDTH / 2);
      rotate_dir(&j->p_dir, rotate_deg);

      rotate_deg = rotate * 64;
    }
        else
    {
      rotate_deg = -old_rotate_deg;
      rotate_coord(&j->p_x, &j->p_y, rotate_deg,
             GWIDTH / 2, GWIDTH / 2);
      rotate_dir(&j->p_dir, rotate_deg);
      rotate_deg = 0;
    }
      }
    /* phasers/torps/etc .. wait for server */

    old_rotate = rotate;
    old_rotate_deg = rotate_deg;
  }
#endif

    }


  /* Does the button have a range of values? */

  else if (op->op_range)
    {
      if (data->key == W_RBUTTON)
  {
    (*op->op_option) += op->op_range->increment;
  }
      else if (data->key == W_MBUTTON)
  {
    (*op->op_option) = op->op_range->min_value;
  }
      else if (data->key == W_LBUTTON)
  {
    (*op->op_option) -= op->op_range->increment;
  }
      /* wrap value around within option range */
      if (*(op->op_option) > op->op_range->max_value)
  *(op->op_option) = op->op_range->min_value;
      if (*(op->op_option) < op->op_range->min_value)
  *(op->op_option) = op->op_range->max_value;
    }


  /* Is the option a toggle? */

#ifdef HAVE_XPM
  /* Bitwise Toggle  */

  else if ((op->op_option) && (op->op_size))
    {
      if (!(pixMissing & op->op_size))
  {
    *op->op_option ^= op->op_size;

    if (op->op_size & (NO_MAP_PIX | NO_BG_PIX | NO_HALOS))
      redrawall = 1;
  }
    }
#endif

  else if (op->op_option)
    {
      *op->op_option = !*op->op_option;

      /* Actions to be taken when certain options are selected. * (Yes, this
       * * is a hack). */

      if (op->op_option == &showPlanetOwner)
  redrawall = 1;
      else if (op->op_option == &partitionPlist)
  RedrawPlayerList();
      else if (op->op_option == &sortPlayers)
  RedrawPlayerList();
      else if (op->op_option == &sortMyTeamFirst)
  RedrawPlayerList();
    }

  /* Map/unmap window, if it exists */

  if (op->op_targetwin)
    {
      if (W_IsMapped(*op->op_targetwin))
  W_UnmapWindow(*op->op_targetwin);
      else
  {
    W_MapWindow(*op->op_targetwin);

    if (*op->op_targetwin == udpWin)
      udpwindow();
    if (*op->op_targetwin == pStats)
      redrawPStats();
    if (*op->op_targetwin == netstatWin)
      nswindow();
    if (*op->op_targetwin == spWin)
      spwindow();

#ifdef XTREKRC_HELP
    if (defWin && *op->op_targetwin == defWin)
      showdef();
#endif

#ifdef SOUND
    if (*op->op_targetwin == soundWin)
      soundwindow();
#endif

#ifdef DOC_WIN
    if (docwin && *op->op_targetwin == docwin)
      showdocs(0);

    if (xtrekrcwin && *op->op_targetwin == xtrekrcwin)
      showxtrekrc(0);
#endif
  }
    }

  /* deal with possible menu change */
  if (MenuPage != CurrentMenu->page_num)
    {
      SetMenuPage(MenuPage);
      RefreshOptions();
    }
  else if (notdone)
    optionrefresh(op);
  else
    {
      optionrefresh(op);
      optiondone();
    }

  return;
}
Example #2
0
void CMenus::RenderStartMenu(CUIRect MainView)
{
	// render logo
	Graphics()->TextureSet(g_pData->m_aImages[IMAGE_BANNER].m_Id);
	Graphics()->QuadsBegin();
	Graphics()->SetColor(1,1,1,1);
	IGraphics::CQuadItem QuadItem(MainView.w/2-140, 60, 280, 70);
	Graphics()->QuadsDrawTL(&QuadItem, 1);
	Graphics()->QuadsEnd();

	CUIRect TopMenu, BottomMenu;
	MainView.VMargin(MainView.w/2-190.0f, &TopMenu);
	TopMenu.HSplitTop(365.0f, &TopMenu, &BottomMenu);
	//TopMenu.HSplitBottom(145.0f, &TopMenu, 0);
	RenderTools()->DrawUIRect4(&TopMenu, vec4(0.0f, 0.0f, 0.0f, 0.0f), vec4(0.0f, 0.0f, 0.0f, 0.0f), vec4(0.0f, 0.0f, 0.0f, g_Config.m_ClMenuAlpha/100.0f), vec4(0.0f, 0.0f, 0.0f, g_Config.m_ClMenuAlpha/100.0f), CUI::CORNER_B, 10.0f);

	TopMenu.HSplitTop(145.0f, 0, &TopMenu);

	CUIRect Button;
	int NewPage = -1;

	TopMenu.HSplitBottom(40.0f, &TopMenu, &Button);
	static CButtonContainer s_SettingsButton;
	if(DoButton_Menu(&s_SettingsButton, Localize("Settings"), 0, &Button, g_Config.m_ClShowStartMenuImages ? "settings" : 0, CUI::CORNER_ALL, 10.0f, 0.5f) || CheckHotKey(KEY_S))
		NewPage = PAGE_SETTINGS;
	
	/*TopMenu.HSplitBottom(5.0f, &TopMenu, 0); // little space
	TopMenu.HSplitBottom(40.0f, &TopMenu, &Bottom);
	static int s_LocalServerButton = 0;
	if(g_Config.m_ClShowStartMenuImages)
	{
		if(DoButton_MenuImage(&s_LocalServerButton, Localize("Local server"), 0, &Button, "local_server", 10.0f, 0.5f))
		{
		}
	}
	else
	{
		if(DoButton_Menu(&s_LocalServerButton, Localize("Local server"), 0, &Button, CUI::CORNER_ALL, 10.0f, 0.5f))
		{
		}
	}*/

	TopMenu.HSplitBottom(5.0f, &TopMenu, 0); // little space
	TopMenu.HSplitBottom(40.0f, &TopMenu, &Button);
	static CButtonContainer s_DemoButton;
	if(DoButton_Menu(&s_DemoButton, Localize("Demos"), 0, &Button, g_Config.m_ClShowStartMenuImages ? "demos" : 0, CUI::CORNER_ALL, 10.0f, 0.5f) || CheckHotKey(KEY_D))
	{
		NewPage = PAGE_DEMOS;
		DemolistPopulate();
		DemolistOnUpdate(false);
	}

	static bool EditorHotkeyWasPressed = true;
	static float EditorHotKeyChecktime = 0;
	TopMenu.HSplitBottom(5.0f, &TopMenu, 0); // little space
	TopMenu.HSplitBottom(40.0f, &TopMenu, &Button);
	static CButtonContainer s_MapEditorButton;
	if(DoButton_Menu(&s_MapEditorButton, Localize("Editor"), 0, &Button, g_Config.m_ClShowStartMenuImages ? "editor" : 0, CUI::CORNER_ALL, 10.0f, 0.5f) || (!EditorHotkeyWasPressed && Client()->LocalTime() - EditorHotKeyChecktime < 0.1f && CheckHotKey(KEY_E)))
	{
		g_Config.m_ClEditor = 1;
		Input()->MouseModeRelative();
		EditorHotkeyWasPressed = true;
	}
	if(!Input()->KeyIsPressed(KEY_E))
	{
		EditorHotkeyWasPressed = false;
		EditorHotKeyChecktime = Client()->LocalTime();
	}

	TopMenu.HSplitBottom(5.0f, &TopMenu, 0); // little space
	TopMenu.HSplitBottom(40.0f, &TopMenu, &Button);
	static CButtonContainer s_PlayButton;
	if(DoButton_Menu(&s_PlayButton, Localize("Play"), 0, &Button, g_Config.m_ClShowStartMenuImages ? "play_game" : 0, CUI::CORNER_ALL, 10.0f, 0.5f) || m_EnterPressed || CheckHotKey(KEY_P))
		NewPage = g_Config.m_UiBrowserPage;
	
	BottomMenu.HSplitTop(90.0f, 0, &BottomMenu);
	RenderTools()->DrawUIRect4(&BottomMenu, vec4(0.0f, 0.0f, 0.0f, g_Config.m_ClMenuAlpha/100.0f), vec4(0.0f, 0.0f, 0.0f, g_Config.m_ClMenuAlpha/100.0f), vec4(0.0f, 0.0f, 0.0f, 0.0f), vec4(0.0f, 0.0f, 0.0f, 0.0f), CUI::CORNER_T, 10.0f);

	BottomMenu.HSplitTop(40.0f, &Button, &TopMenu);
	static CButtonContainer s_QuitButton;
	if(DoButton_Menu(&s_QuitButton, Localize("Quit"), 0, &Button, 0, CUI::CORNER_ALL, 10.0f, 0.5f) || m_EscapePressed || CheckHotKey(KEY_Q))
		m_Popup = POPUP_QUIT;

	// render version
	CUIRect Version;
	MainView.HSplitBottom(50.0f, 0, &Version);
	Version.VMargin(50.0f, &Version);
	char aBuf[64];
	if(str_comp(Client()->LatestVersion(), "0") != 0)
	{
		str_format(aBuf, sizeof(aBuf), Localize("Teeworlds %s is out! Download it at www.teeworlds.com!"), Client()->LatestVersion());
		TextRender()->TextColor(1.0f, 0.4f, 0.4f, 1.0f);
		UI()->DoLabel(&Version, aBuf, 14.0f, CUI::ALIGN_CENTER);
		TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
	}
	UI()->DoLabel(&Version, GAME_RELEASE_VERSION, 14.0f, CUI::ALIGN_RIGHT);

	if(NewPage != -1)
		SetMenuPage(NewPage);
}