GUI issues
by Vishal Bhanderi · in Torque X 2D · 11/20/2008 (12:29 pm) · 17 replies
Hi guys,
I'm trying to create a gui for my game/tdn, but I cannot seem to get the button to work or even see it. I've attached the source here.
www.mediafire.com/?sharekey=10e15a2f6524b554d2db6fb9a8902bda
What I'm I missing?
Thanks
Vishal.
I'm trying to create a gui for my game/tdn, but I cannot seem to get the button to work or even see it. I've attached the source here.
www.mediafire.com/?sharekey=10e15a2f6524b554d2db6fb9a8902bda
What I'm I missing?
Thanks
Vishal.
About the author
#2
There are many ways to do this - I took my guidance from the FPS Menu system - and did not use the extend the GUIBitmap, IGUIScreen.
This is a one button menu (easily expandable to more than one button) -
called via:
GuiStartMenu _StartMenu;
_StartMenu = new GuiStartMenu();
I have a more complex one, not quite finished with it, that allows for the the selection of items.
11/22/2008 (6:53 pm)
Vishal - There are many ways to do this - I took my guidance from the FPS Menu system - and did not use the extend the GUIBitmap, IGUIScreen.
This is a one button menu (easily expandable to more than one button) -
called via:
GuiStartMenu _StartMenu;
_StartMenu = new GuiStartMenu();
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using GarageGames.Torque.Platform;
using GarageGames.Torque.Core;
using GarageGames.Torque.Core.Xml;
using GarageGames.Torque.Sim;
using GarageGames.Torque.GUI;
using GarageGames.Torque.MathUtil;
using GarageGames.Torque.T2D;
namespace RobotRevolution.GUI
{
class GuiStartMenu
{
public GuiStartMenu()
{
_createStartMenuGUI();
}
public void ToggleMenu()
{
if (_root == null)
return;
if (_root.Folder == GUICanvas.Instance)
{
GUICanvas.Instance.PopDialogControl(_root);
}
else
{
GUICanvas.Instance.PushDialogControl(_root, 50);
_currentSelection = 0;
_button1.Visible = true;
}
}
public void MoveDown()
{
_list[_currentSelection].Visible = false;
_currentSelection = ++_currentSelection % 1;
_list[_currentSelection].Visible = true;
}
public void MoveUp()
{
_list[_currentSelection].Visible = false;
_currentSelection = _currentSelection > 0 ? _currentSelection - 1 : 0;
_list[_currentSelection].Visible = true;
}
public void SELECT()
{
ToggleMenu();
switch (_currentSelection)
{
case 0:
Game.Instance.ShowMainMenu();
break;
}
}
private void _createStartMenuGUI()
{
#region background
GUIStyle baseStyle = new GUIStyle();
baseStyle.Focusable = true;
GUIBitmapStyle bitmapStyle = new GUIBitmapStyle();
bitmapStyle.SizeToBitmap = true;
_root = new GUIControl();
_root.Style = baseStyle;
_root.Layer = 50;
_root.FocusOnWake = true;
_root.Visible = true;
GUIBitmap baseFrame = new GUIBitmap();
baseFrame.Style = bitmapStyle;
baseFrame.HorizSizing = HorizSizing.Center;
baseFrame.VertSizing = VertSizing.Center;
baseFrame.Bitmap = @"data\GUIImages\StartGame\StartMenu_1080";
switch (Game.Instance.Window.ClientBounds.Height)
{
case 1080:
baseFrame.Size = new Vector2(1920, 1080); //*1.5
break;
case 720:
baseFrame.Size = new Vector2(1280, 720); //1
break;
default:
baseFrame.Size = new Vector2(720, 480); //1.5
break;
}
baseFrame.Visible = true;
baseFrame.Folder = _root;
Vector2 btnPosition = new Vector2(560, 400);
switch (Game.Instance.Window.ClientBounds.Height)
{
case 1080:
btnPosition = new Vector2(btnPosition.X * 1.5f, btnPosition.Y * 1.5f);
break;
case 720:
btnPosition = btnPosition; //1
break;
case 480:
btnPosition = new Vector2(btnPosition.X / 1.77f, btnPosition.Y / 1.77f);
break;
}
GUIBitmap button1 = new GUIBitmap();
button1.Style = bitmapStyle;
button1.Bitmap = @"data\GUIImages\StartGame\Start";
button1.Position = btnPosition;
button1.Visible = true;
switch (Game.Instance.Window.ClientBounds.Height)
{
case 1080:
button1.Size = new Vector2(button1.Size.X * 1.5f, button1.Size.X * 1.5f);
break;
case 720:
//Do nothing
break;
case 480:
button1.Size = new Vector2(button1.Size.X / 1.77f, button1.Size.X / 1.77f);
break;
}
button1.Folder = baseFrame;
_button1 = new GUIBitmap();
_button1.Style = bitmapStyle;
_button1.Bitmap = @"data\GUIImages\StartGame\StartH";
_button1.Position = btnPosition;
_button1.Visible = false;
button1.Visible = true;
switch (Game.Instance.Window.ClientBounds.Height)
{
case 1080:
_button1.Size = new Vector2(_button1.Size.X * 1.5f, _button1.Size.X * 1.5f);
break;
case 720:
//Do nothing
break;
case 480:
_button1.Size = new Vector2(_button1.Size.X / 1.77f, _button1.Size.X / 1.77f);
break;
}
_button1.Folder = baseFrame;
_list[0] = _button1;
_InitInputMap();
ToggleMenu();
}
protected void _InitInputMap()
{
InputMap input = new InputMap();
for (int i = 0; i < 4; i++)
{
int gamepadId = InputManager.Instance.FindDevice("gamepad" + i);
if (gamepadId >= 0)
{
input.BindCommand(gamepadId, (int)XGamePadDevice.GamePadObjects.Back, ToggleMenu, null);
input.BindCommand(gamepadId, (int)XGamePadDevice.GamePadObjects.Up, MoveUp, null);
input.BindCommand(gamepadId, (int)XGamePadDevice.GamePadObjects.Down, MoveDown, null);
input.BindCommand(gamepadId, (int)XGamePadDevice.GamePadObjects.A, SELECT, null);
}
}
int keyboardId = InputManager.Instance.FindDevice("keyboard");
input.BindCommand(keyboardId, (int)Microsoft.Xna.Framework.Input.Keys.Down, MoveDown, null);
input.BindCommand(keyboardId, (int)Microsoft.Xna.Framework.Input.Keys.Up, MoveUp, null);
input.BindCommand(keyboardId, (int)Microsoft.Xna.Framework.Input.Keys.Enter, SELECT, null);
input.BindCommand(keyboardId, (int)Microsoft.Xna.Framework.Input.Keys.Escape, ToggleMenu, null);
_root.InputMap = input;
}
private void _mainCharacterSelect(float val)
{
Game.Instance.SelectCharacter();
}
GUIControl _root;
GUIBitmap _button1;
GUIBitmap[] _list = new GUIBitmap[1];
int _currentSelection;
}
}I have a more complex one, not quite finished with it, that allows for the the selection of items.
#3
11/22/2008 (7:09 pm)
Sean to the rescue
#4
I tried using something like this:
InputMap.BindCommand(gamepadID, (int)XGamePadDevice.GamePadObjects.LeftThumbY, Move, null);
But it's not working.
Only way I can find is to use the MoveManager. I was hoping someone had a simpler way :).
11/22/2008 (10:33 pm)
Heya, one of you wouldn't happen to know how to bind the analog sticks in the gui?I tried using something like this:
InputMap.BindCommand(gamepadID, (int)XGamePadDevice.GamePadObjects.LeftThumbY, Move, null);
But it's not working.
Only way I can find is to use the MoveManager. I was hoping someone had a simpler way :).
#5
I'm trying to follow all the guidelines set here Guidelines. Mainly:
-Any control a player picks up should be set as "main controller".
-Allow for HD. Still not sure how to support HD, with minimum download foot print.
-Also I'm going to try and localise the game to support multiple languages (with XNA 3).
-A loading animation while the level is loading in the background. I'm not sure if this is possible with TX.
There's a lot to do to get a game done professionally!
Vishal
11/23/2008 (3:37 am)
Thanks guys for the input. I didn't know that there was a FPS menu system. Where is this starter kit? I'm clueless! :DI'm trying to follow all the guidelines set here Guidelines. Mainly:
-Any control a player picks up should be set as "main controller".
-Allow for HD. Still not sure how to support HD, with minimum download foot print.
-Also I'm going to try and localise the game to support multiple languages (with XNA 3).
-A loading animation while the level is loading in the background. I'm not sure if this is possible with TX.
There's a lot to do to get a game done professionally!
Vishal
#6
inputMap.BindMove(gamepad, (int)XGamePadDevice.GamePadObjects.LeftThumbY, MoveMapTypes.StickAnalogVertical, 0);
and then check/do:
if (move.Sticks[0].Y >0)
11/23/2008 (8:57 am)
@Matthew - you bind the stick viainputMap.BindMove(gamepad, (int)XGamePadDevice.GamePadObjects.LeftThumbY, MoveMapTypes.StickAnalogVertical, 0);
and then check/do:
if (move.Sticks[0].Y >0)
#7
11/23/2008 (10:12 am)
:) I was hoping there was a way to do it without linking to the move map. not a big deal though.:)
#8
I used alot of Seans ideas but I changed a few things to better suit my games needs.
I was having issues getting things to map the way I wanted so I had to override the OnInputEvent class as the torque documentation mentions.
I wanted to post this code because, as though the docs mention you need to override the class I've never sean an example.
Also I Designed my own button class that swaps bitmaps as I still have not figured out how to get the included GUIButton class to display.)
I'm learning torque myself so I can not promise that the below code is "best practice" but It does work so hopefully people can learn something from it.
Main Menu Class:
11/24/2008 (6:53 pm)
In the interest of bettering the community I just wanted to post my main menu code so people can learn from what I spent time figuring out.I used alot of Seans ideas but I changed a few things to better suit my games needs.
I was having issues getting things to map the way I wanted so I had to override the OnInputEvent class as the torque documentation mentions.
I wanted to post this code because, as though the docs mention you need to override the class I've never sean an example.
Also I Designed my own button class that swaps bitmaps as I still have not figured out how to get the included GUIButton class to display.)
I'm learning torque myself so I can not promise that the below code is "best practice" but It does work so hopefully people can learn something from it.
Main Menu Class:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using GarageGames.Torque.Platform;
using GarageGames.Torque.Core;
using GarageGames.Torque.Core.Xml;
using GarageGames.Torque.Sim;
using GarageGames.Torque.GUI;
using GarageGames.Torque.MathUtil;
using GarageGames.Torque.T2D;
namespace ChuDynasty.UI
{
class GuiMainMenu: GUIBitmap, IGUIScreen
{
static public GuiMainMenu Instance
{
get
{
if (_instance == null)
_instance = new UI.GuiMainMenu();
return _instance;
}
}
static private GuiMainMenu _instance;
//Moves the menu Selection Down
public void MoveDown()
{
if (Math.Abs(_time - Game.Instance.Engine.TorqueTime) > 100)
{
switch (_menuState)
{
case MenuState.GameMode:
_time = Game.Instance.Engine.TorqueTime;
_buttonModeList[_currentSelection].Normal();
_currentSelection = _currentSelection < (_buttonModeList.Length - 1) ? _currentSelection + 1 : (_buttonModeList.Length - 1);
_buttonModeList[_currentSelection].Select();
break;
case MenuState.NumPlayers:
_time = Game.Instance.Engine.TorqueTime;
_buttonNumList[_currentSelection].Normal();
_currentSelection = _currentSelection < (_buttonNumList.Length - 1) ? _currentSelection + 1 : (_buttonNumList.Length - 1);
_buttonNumList[_currentSelection].Select();
break;
}
}
}
//Moves the menu Selection Up
public void MoveUp()
{
if (Math.Abs(_time - Game.Instance.Engine.TorqueTime) > 100)
{
switch (_menuState)
{
case MenuState.GameMode:
_time = Game.Instance.Engine.TorqueTime;
_buttonModeList[_currentSelection].Normal();
_currentSelection = _currentSelection > 0 ? _currentSelection - 1 : 0;
_buttonModeList[_currentSelection].Select();
break;
case MenuState.NumPlayers:
_time = Game.Instance.Engine.TorqueTime;
_buttonNumList[_currentSelection].Normal();
_currentSelection = _currentSelection > 0 ? _currentSelection - 1 : 0;
_buttonNumList[_currentSelection].Select();
break;
}
}
}
//Switch Calls the proper functions when players click on a menu option
public void ChooseMode()
{
if (Math.Abs(_time - Game.Instance.Engine.TorqueTime) > 100)
{
if (_currentMove != _lastMove)
{
_lastMove = _currentMove;
_buttonModeList[_currentSelection].Pushed();
switch (_menuState)
{
case MenuState.GameMode:
switch (_currentSelection)
{
case 0:
case 1:
_menuState = MenuState.NumPlayers;
ChangeContent();
break;
case 2:
Game.Instance.Exit();
break;
}
break;
case MenuState.NumPlayers:
switch (_currentSelection)
{
case 0:
Game.Instance.NumberOfPlayers = 2;
_menuState = MenuState.PlayerSelect;
ChangeContent();
break;
case 1:
Game.Instance.NumberOfPlayers = 3;
_menuState = MenuState.PlayerSelect;
ChangeContent();
break;
case 2:
Game.Instance.NumberOfPlayers = 4;
_menuState = MenuState.PlayerSelect;
ChangeContent();
break;
}
break;
}
_time = Game.Instance.Engine.TorqueTime;
}
else
_lastMove = LastMove.clear;
}
}
public void StepBack()
{
if (_currentMove != _lastMove)
{
switch (_menuState)
{
case MenuState.GameMode:
break;
case MenuState.NumPlayers:
_menuState = MenuState.GameMode;
ChangeContent();
break;
}
_lastMove = LastMove.clear;
}
}
//Loads new content
public void ChangeContent()
{
_currentSelection = 0;
switch (_menuState)
{
case MenuState.GameMode:
for (short i = 0; i < _buttonModeList.Length; i++)
{
_buttonModeList[i].Visible = true;
}
for (short i = 0; i < _buttonNumList.Length; i++)
{
_buttonNumList[i].Normal();
_buttonNumList[i].Visible = false;
}
_buttonModeList[0].Select();
break;
case MenuState.NumPlayers:
for (short i = 0; i < _buttonModeList.Length; i++)
{
_buttonModeList[i].Normal();
_buttonModeList[i].Visible = false;
}
for (short i = 0; i < _buttonNumList.Length; i++)
{
_buttonNumList[i].Visible = true;
}
_buttonNumList[0].Select();
break;
case MenuState.PlayerSelect:
Game.Instance.RequestedMenu = Game.MenuSelect.levelTest;
Game.Instance.SwitchMenu();
break;
}
}
#9
11/24/2008 (6:53 pm)
More menu codepublic GuiMainMenu()
{
imageStyle = new GUIBitmapStyle();
imageStyle.SizeToBitmap = false;
imageStyle.PreserveAspectRatio = true;
buttonStyle = new GUIBitmapStyle();
buttonStyle.SizeToBitmap = false;
buttonStyle.PreserveAspectRatio = true;
Name = "GuiMainMenu";
Style = imageStyle;
Bitmap = @"data\images\gui\MainMenu\MainMenu";
Size = new Vector2(1280, 720);
OnGUIWake = OnMainScreenWake;
}
public void OnMainScreenWake(GUIControl mainGUI)
{
//Createing Game Mode Buttons
_deathMatch = new menuControl.ButtonBitmapSelectable();
_deathMatch.ButtonPath = _buttonPath;
_deathMatch.Style = buttonStyle;
_deathMatch.Bitmap = _buttonPath + _deathMatchName;
_deathMatch.Size = new Vector2(256 * Game.Instance.UISizeXMult, 64 * Game.Instance.UISizeYMult);
_deathMatch.Position = new Vector2(640 * Game.Instance.UISizeXMult - (_deathMatch.Bounds.Width / 2), 340 * Game.Instance.UISizeYMult);
_deathMatch.Visible = true;
_deathMatch.Folder = this;
_chuBall = new menuControl.ButtonBitmapSelectable();
_chuBall.Name = "chuBall";
_chuBall.Style = buttonStyle;
_chuBall.Bitmap = _buttonPath + _chuBallName;
_chuBall.Size = new Vector2(256 * Game.Instance.UISizeXMult, 64 * Game.Instance.UISizeYMult);
_chuBall.Position = new Vector2(640 * Game.Instance.UISizeXMult - (_chuBall.Bounds.Width / 2), (_deathMatch.Position.Y + offsetY));
_chuBall.Visible = true;
_chuBall.Folder = this;
_returnToArcade = new menuControl.ButtonBitmapSelectable();
_returnToArcade.Name = "chuBall";
_returnToArcade.Style = buttonStyle;
_returnToArcade.Bitmap = _buttonPath + _returnToArcadeName;
_returnToArcade.Size = new Vector2(256 * Game.Instance.UISizeXMult, 64 * Game.Instance.UISizeYMult);
_returnToArcade.Position = new Vector2(640 * Game.Instance.UISizeXMult - (_returnToArcade.Bounds.Width / 2), (_deathMatch.Position.Y + offsetY * 2));
_returnToArcade.Visible = true;
_returnToArcade.Folder = this;
_buttonModeList[0] = _deathMatch;
_buttonModeList[1] = _chuBall;
_buttonModeList[2] = _returnToArcade;
_buttonModeList[_currentSelection].Select();
//Createing Player Number Buttons
_2Players = new menuControl.ButtonBitmapSelectable();
_2Players.ButtonPath = _buttonPath;
_2Players.Style = buttonStyle;
_2Players.Bitmap = _buttonPath + _2PlayersName;
_2Players.Size = new Vector2(256 * Game.Instance.UISizeXMult, 64 * Game.Instance.UISizeYMult);
_2Players.Position = new Vector2(640 * Game.Instance.UISizeXMult - (_2Players.Bounds.Width / 2), 340 * Game.Instance.UISizeYMult);
_2Players.Visible = true;
_2Players.Folder = this;
_3Players = new menuControl.ButtonBitmapSelectable();
_3Players.Name = "chuBall";
_3Players.Style = buttonStyle;
_3Players.Bitmap = _buttonPath + _3PlayersName;
_3Players.Size = new Vector2(256 * Game.Instance.UISizeXMult, 64 * Game.Instance.UISizeYMult);
_3Players.Position = new Vector2(640 * Game.Instance.UISizeXMult - (_3Players.Bounds.Width / 2), (_2Players.Position.Y + offsetY));
_3Players.Visible = true;
_3Players.Folder = this;
_4Players = new menuControl.ButtonBitmapSelectable();
_4Players.Name = "chuBall";
_4Players.Style = buttonStyle;
_4Players.Bitmap = _buttonPath + _4PlayersName;
_4Players.Size = new Vector2(256 * Game.Instance.UISizeXMult, 64 * Game.Instance.UISizeYMult);
_4Players.Position = new Vector2(640 * Game.Instance.UISizeXMult - (_4Players.Bounds.Width / 2), (_2Players.Position.Y + offsetY * 2));
_4Players.Visible = true;
_4Players.Folder = this;
_buttonNumList[0] = _2Players;
_buttonNumList[1] = _3Players;
_buttonNumList[2] = _4Players;
ChangeContent();
}
#10
// Input Event Watcher
11/24/2008 (6:54 pm)
That override Code I was talking about.// Input Event Watcher
public override bool OnInputEvent(ref TorqueInputDevice.InputEventData data)
{
if (data.DeviceTypeId == TorqueInputDevice.GamePadId)
{
if (data.ObjectId == (int)XGamePadDevice.GamePadObjects.LeftThumbY)
{
stickY = data.Value;
if (stickY > .35)
{
_currentMove = LastMove.up;
MoveUp();
return true;
}
else if (stickY < -.35)
{
_currentMove = LastMove.down;
MoveDown();
return true;
}
_currentMove = LastMove.clear;
return true;
}
else if (data.ObjectId == (int)XGamePadDevice.GamePadObjects.A)
{
_currentMove = LastMove.a;
ChooseMode();
return true;
}
else if (data.ObjectId == (int)XGamePadDevice.GamePadObjects.Back)
{
if (Math.Abs(_time - Game.Instance.Engine.TorqueTime) > 100)
{
if (_menuState == MenuState.NumPlayers)
{
_currentMove = LastMove.back;
_menuState = MenuState.GameMode;
ChangeContent();
return true;
}
else
{
_currentMove = LastMove.clear;
return false;
}
_time = Game.Instance.Engine.TorqueTime;
}
else
{
_time = Game.Instance.Engine.TorqueTime;
_currentMove = LastMove.clear;
return false;
}
}
else if (data.ObjectId == (int)XGamePadDevice.GamePadObjects.B)
{
if (Math.Abs(_time - Game.Instance.Engine.TorqueTime) > 100)
{
if (_menuState == MenuState.NumPlayers)
{
_menuState = MenuState.GameMode;
ChangeContent();
_currentMove = LastMove.b;
return true;
}
else
{
_currentMove = LastMove.clear;
return false;
}
_time = Game.Instance.Engine.TorqueTime;
}
else
{
_currentMove = LastMove.clear;
return false;
}
}
else
{
_currentMove = LastMove.clear;
return false;
}
}
else
{
_currentMove = LastMove.clear;
return false;
}
}
protected enum LastMove
{
up,
down,
a,
b,
back,
clear,
}
#11
11/24/2008 (6:56 pm)
Variable declarations:protected enum MenuState
{
GameMode,
NumPlayers,
PlayerSelect,
}
// InputMap input;
protected float stickY;
protected float _time;
protected GUIBitmapStyle imageStyle;
protected GUIBitmapStyle buttonStyle;
protected MenuState _menuState = MenuState.GameMode;
protected LastMove _lastMove = LastMove.clear;
protected LastMove _currentMove = LastMove.clear;
//setting main path
protected string _buttonPath = @"data\images\gui\MainMenu\buttons\";
//Creating Game Mode Buttons
protected menuControl.ButtonBitmapSelectable _deathMatch;
protected menuControl.ButtonBitmapSelectable _chuBall;
protected menuControl.ButtonBitmapSelectable _returnToArcade;
//Creating Player Number Buttons
protected menuControl.ButtonBitmapSelectable _2Players;
protected menuControl.ButtonBitmapSelectable _3Players;
protected menuControl.ButtonBitmapSelectable _4Players;
//Assigning Button Names
protected string _deathMatchName = "MainMenu_DeathMatch";
protected string _chuBallName = "MainMenu_ChuBall";
protected string _returnToArcadeName = "MainMenu_ReturnToArcade";
protected string _2PlayersName = "MainMenu_2Players";
protected string _3PlayersName = "MainMenu_3Players";
protected string _4PlayersName = "MainMenu_4Players";
protected menuControl.ButtonBitmapSelectable[] _buttonModeList = new menuControl.ButtonBitmapSelectable[3];
protected menuControl.ButtonBitmapSelectable[] _buttonNumList = new menuControl.ButtonBitmapSelectable[3];
protected int _currentSelection = 0;
protected float offsetY = 60 * Game.Instance.UISizeYMult;
}
}
#12
11/24/2008 (6:57 pm)
Button classclass ButtonBitmapSelectable:GUIBitmap
{
//Relitive Path to the Button
public string ButtonPath
{
get
{
if (_buttonPath != null)
return _buttonPath;
else
return null;
}
set { _buttonPath = value;}
}
//The Extension in a textures filename that should be used to indicate it is a Selected texture
public string SelectExtension
{
get { return _selectExtension; }
set { _selectExtension = value; }
}
//The Extension in a textures filename that should be used to indicate it is a Pushed texture
public string PushedExtension
{
get { return _pushedExtension; }
set { _pushedExtension = value; }
}
//Swaps the button texture to the base texture + the SelectExtension
public void Select()
{
if (Visible && !_selected)
{
_baseBitmap = this.Bitmap;
Bitmap = _baseBitmap + _selectExtension;
_selected = true;
_pushed = false;
}
}
//Swaps the button texture to the base texture
public void Normal()
{
if (Visible)
{
if (_selected || _pushed)
Bitmap = _baseBitmap;
_selected = false;
_pushed = false;
}
}
//Swaps the button texture to the base texture + the Pushed Extension
public void Pushed()
{
if (Visible)
{
if (_selected)
Bitmap = _baseBitmap + _pushedExtension;
_pushed = true;
}
}
private bool _selected = false;
private bool _pushed = false;
private string _baseBitmap;
private string _buttonPath;
private string _selectExtension = "_Selected";
private string _pushedExtension = "_Pushed";
}
#13
Here is the GUIButton code.
I've tried all the attributes that seem important, but it's still not showing up.
Any advice on this?
Thanks
11/28/2008 (12:02 pm)
Thank's for your input Matthew. I was initially planning on over-riding the classes too, like the old tank tutorial. If I cannot get the GUIButton class to work soon, I'm going to follow that method too.Here is the GUIButton code.
GUIButtonStyle buttonStyle = new GUIButtonStyle();
buttonStyle.Bitmap = @"data\images\GUI\menu\btn_exit";
buttonStyle.Alignment = TextAlignment.JustifyCenter;
buttonStyle.Focusable = true;
buttonStyle.FontType = "arial16";
buttonStyle.Name = "button1";
buttonStyle.PreserveAspectRatio = true;
buttonStyle.TextColor[0] = Color.Red;
GUIButton button = new GUIButton();
button.Style = buttonStyle;
button.ButtonText = "dfsdf";
button.Position = new Vector2(145, 386);
button.Visible = true;
button.Folder = _root;I've tried all the attributes that seem important, but it's still not showing up.
Any advice on this?
Thanks
#14
11/28/2008 (5:39 pm)
I can't get it working either and there don't seam to be any docs on or examples that use the button class. :(
#15
Or see if this works:
12/01/2008 (6:36 pm)
GUIButton's work fine for me. Maybe add Size property to the GUIButton in the above code?Or see if this works:
GUIButtonStyle buttonStyle = new GUIButtonStyle(); buttonStyle.TextColor[CustomColor.ColorBase] = Color.Black; buttonStyle.TextColor[CustomColor.ColorHL] = Color.Yellow; buttonStyle.TextColor[CustomColor.ColorSEL] = Color.Blue; buttonStyle.TextColor[CustomColor.ColorNA] = Color.Gray; buttonStyle.FontType = "Arial16"; GUIButton button = new GUIButton(); button.Style = buttonStyle; button.Size = new Vector2(100, 50); button.ButtonText = "button"; button.Folder = _root; button.Visible = true;
#16
I added a bitmap and I couldn't see that too.
I tried adding the special image talked about in one of the threads.
image
Then done:
I've noticed threads with button issues as well.
thread
thread
12/02/2008 (12:39 pm)
That's really odd. I tried your code and couldn't see anything until I add "button.SetButtonSelected();"I added a bitmap and I couldn't see that too.
I tried adding the special image talked about in one of the threads.
image
Then done:
buttonStyle.AutoSkin = true; buttonStyle.Bitmap = @"data\images\GUI\menu\btn_image"; buttonStyle.ConstructBitmapCoords();There was 9 "Coords" but the button still doesn't show
I've noticed threads with button issues as well.
thread
thread
#17
See if this code makes a GUIButton with background color show up for you and make sure to put it in a class that both inherits from GUIControl and is made the content control through the SetContentControl method:
12/04/2008 (8:02 pm)
I've never attempted to attach a bitmap to a GUIButton so I don't have much of an idea if that works, but it is possible to just create a button with text and specified background color. See if this code makes a GUIButton with background color show up for you and make sure to put it in a class that both inherits from GUIControl and is made the content control through the SetContentControl method:
GUIButtonStyle buttonStyle = new GUIButtonStyle(); buttonStyle.TextColor[CustomColor.ColorBase] = Color.Black; buttonStyle.TextColor[CustomColor.ColorHL] = Color.Yellow; buttonStyle.TextColor[CustomColor.ColorSEL] = Color.Blue; buttonStyle.TextColor[CustomColor.ColorNA] = Color.Gray; buttonStyle.FontType = "Arial16"; buttonStyle.IsOpaque = true; buttonStyle.FillColor[CustomColor.ColorBase] = Color.Green; GUIButton button = new GUIButton(); button.Style = buttonStyle; button.Size = new Vector2(100, 50); button.ButtonText = "button"; button.Folder = this; button.Visible = true;
Torque Owner Matthew Hoesterey