ScrollCtrl
by Christian · in Game Design and Creative Issues · 08/18/2007 (6:15 pm) · 3 replies
Anyone worked with ScrollCtrl? Trying to give it options to choose from, any help would be great.
#2
08/20/2007 (10:32 pm)
I got ya. The ScrollCtrl's use GuiTextListCtrl to do all the actual options. The pop-up doesn't really do the trick, but I think the TextListCtrl works about the same way. What is the simplest way to add 'choices' or populate the pop-up bar or something of the like. bar.add() needs an object so i'm guessing it has something to do with that. Thanks for the help.
#3
Heres how I add menus and menu items to a menu bar (you cant do it in the editor, have to use script):
function PlayScreen::OnWake(%this)
{
PlayScreenMenuBar.addmenu("Game",0);
PlayScreenMenuBar.addmenuitem("Game","New",0);
etc..
Heres how you do something when a menu item is selected
function PlayScreenMenuBar::onMenuItemSelect(%this, %menuId, %menuText, %menuItemId, %menuItemText)
{
switch$(%menuItemText)
{
case "New":
Canvas.pushdialog(NewGameScreen);
case "Load":
Canvas.Pushdialog(LoadGameScreen);
etc..
Heres how you do something when a textlistctrl is selected:
function AgentsList::OnSelect(%this)
{
%text = AgentsList.getRowTextById(agentslist.getSelectedId());
etc...
Heres how you add something to a textlistctrl:
AgentsList.addRow(%index,%text);
Heres my whole loadgamescreen:
//--- OBJECT WRITE BEGIN ---
%guiContent = new GuiControl(LoadGameScreen) {
canSaveDynamicFields = "0";
isContainer = "1";
Profile = "GuiDefaultProfile";
HorizSizing = "relative";
VertSizing = "relative";
Position = "0 0";
Extent = "800 600";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
new GuiWindowCtrl() {
canSaveDynamicFields = "0";
isContainer = "1";
Profile = "GuiWindowProfile";
HorizSizing = "relative";
VertSizing = "relative";
Position = "220 101";
Extent = "368 340";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
tooltipprofile = "GuiDefaultProfile";
hovertime = "1000";
text = "Load Game";
maxLength = "1024";
resizeWidth = "0";
resizeHeight = "0";
canMove = "1";
canClose = "1";
canMinimize = "0";
canMaximize = "0";
minSize = "50 50";
closeCommand = "Canvas.popDialog(LoadGameScreen);";
new GuiTextCtrl() {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiTextProfile";
HorizSizing = "center";
VertSizing = "bottom";
Position = "127 28";
Extent = "114 30";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
text = "Choose a Saved Game.";
maxLength = "1024";
};
new GuiButtonCtrl() {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiButtonProfile";
HorizSizing = "center";
VertSizing = "top";
Position = "114 299";
Extent = "139 23";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
Command = "loadgamescreen.buttonclick();";
Accelerator = "return";
hovertime = "1000";
text = "Accept";
groupNum = "-1";
buttonType = "PushButton";
useMouseEvents = "0";
};
new GuiTextEditCtrl(loadgamebox) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiTextEditProfile";
HorizSizing = "center";
VertSizing = "top";
Position = "127 264";
Extent = "114 19";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
maxLength = "1024";
historySize = "0";
password = "0";
tabComplete = "0";
sinkAllKeyEvents = "0";
password = "0";
passwordMask = "*";
};
new GuiScrollCtrl() {
canSaveDynamicFields = "0";
isContainer = "1";
Profile = "GuiScrollProfile";
HorizSizing = "center";
VertSizing = "height";
Position = "87 58";
Extent = "194 194";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
tooltipprofile = "GuiDefaultProfile";
hovertime = "1000";
willFirstRespond = "1";
hScrollBar = "dynamic";
vScrollBar = "dynamic";
constantThumbHeight = "0";
childMargin = "0 0";
new GuiDirectoryFileListCtrl(loadgameFileList) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDirectoryFileListProfile";
HorizSizing = "relative";
VertSizing = "relative";
Position = "2 2";
Extent = "190 2";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
AllowMultipleSelections = "1";
fitParentWidth = "1";
};
};
};
};
//--- OBJECT WRITE END ---
function LoadGameScreen::OnWake(%this)
{
loadgamebox.setText("");
loadgamefilelist.setpath("game/data/save","*.sav");
}
function LoadGameScreen::ButtonClick(%this)
{
%filename = loadgamebox.getText();
if (%filename $= "")
return;
%index = strstr(%filename, ".");
if (%index != -1)
{
MessageBoxOK("", "Do not include the file extension or any periods.");
loadgamebox.setText("");
return;
}
%filename = "C:/spyceo/game/data/save/" @ %filename;
loadgamedata(%filename);
Canvas.popdialog(LoadGameScreen);
PlayScreen.SetMenuBar("Playing");
showAllWindows();
}
function loadgameFileList::onselect(%this)
{
%file = %this.getselectedfile();
%file = stripfileExtension(%file);
loadgamebox.setText(%file);
loadgameFileList.setSelected(%this.getSelectedItem(),false);
}
You can look up how to use popupmenus by creating one, naming it, and typing "popupname.dump()" in the console, or looking at the source code for it looking for exposed console functions.
08/21/2007 (10:31 am)
You can use guitextlistctrls as a option selection method if you want, I have used a guitextlistctrl inside a scroll ctrl for a load file selection sortof gui. guitextlistctrls have a callback onselected() and you can also define an "altCommand" which will be executed when you press enter. But if another control which likes to consume input is in focus then it will not be called. Well damn here is my gui just look at it.Heres how I add menus and menu items to a menu bar (you cant do it in the editor, have to use script):
function PlayScreen::OnWake(%this)
{
PlayScreenMenuBar.addmenu("Game",0);
PlayScreenMenuBar.addmenuitem("Game","New",0);
etc..
Heres how you do something when a menu item is selected
function PlayScreenMenuBar::onMenuItemSelect(%this, %menuId, %menuText, %menuItemId, %menuItemText)
{
switch$(%menuItemText)
{
case "New":
Canvas.pushdialog(NewGameScreen);
case "Load":
Canvas.Pushdialog(LoadGameScreen);
etc..
Heres how you do something when a textlistctrl is selected:
function AgentsList::OnSelect(%this)
{
%text = AgentsList.getRowTextById(agentslist.getSelectedId());
etc...
Heres how you add something to a textlistctrl:
AgentsList.addRow(%index,%text);
Heres my whole loadgamescreen:
//--- OBJECT WRITE BEGIN ---
%guiContent = new GuiControl(LoadGameScreen) {
canSaveDynamicFields = "0";
isContainer = "1";
Profile = "GuiDefaultProfile";
HorizSizing = "relative";
VertSizing = "relative";
Position = "0 0";
Extent = "800 600";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
new GuiWindowCtrl() {
canSaveDynamicFields = "0";
isContainer = "1";
Profile = "GuiWindowProfile";
HorizSizing = "relative";
VertSizing = "relative";
Position = "220 101";
Extent = "368 340";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
tooltipprofile = "GuiDefaultProfile";
hovertime = "1000";
text = "Load Game";
maxLength = "1024";
resizeWidth = "0";
resizeHeight = "0";
canMove = "1";
canClose = "1";
canMinimize = "0";
canMaximize = "0";
minSize = "50 50";
closeCommand = "Canvas.popDialog(LoadGameScreen);";
new GuiTextCtrl() {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiTextProfile";
HorizSizing = "center";
VertSizing = "bottom";
Position = "127 28";
Extent = "114 30";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
text = "Choose a Saved Game.";
maxLength = "1024";
};
new GuiButtonCtrl() {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiButtonProfile";
HorizSizing = "center";
VertSizing = "top";
Position = "114 299";
Extent = "139 23";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
Command = "loadgamescreen.buttonclick();";
Accelerator = "return";
hovertime = "1000";
text = "Accept";
groupNum = "-1";
buttonType = "PushButton";
useMouseEvents = "0";
};
new GuiTextEditCtrl(loadgamebox) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiTextEditProfile";
HorizSizing = "center";
VertSizing = "top";
Position = "127 264";
Extent = "114 19";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
maxLength = "1024";
historySize = "0";
password = "0";
tabComplete = "0";
sinkAllKeyEvents = "0";
password = "0";
passwordMask = "*";
};
new GuiScrollCtrl() {
canSaveDynamicFields = "0";
isContainer = "1";
Profile = "GuiScrollProfile";
HorizSizing = "center";
VertSizing = "height";
Position = "87 58";
Extent = "194 194";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
tooltipprofile = "GuiDefaultProfile";
hovertime = "1000";
willFirstRespond = "1";
hScrollBar = "dynamic";
vScrollBar = "dynamic";
constantThumbHeight = "0";
childMargin = "0 0";
new GuiDirectoryFileListCtrl(loadgameFileList) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDirectoryFileListProfile";
HorizSizing = "relative";
VertSizing = "relative";
Position = "2 2";
Extent = "190 2";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
AllowMultipleSelections = "1";
fitParentWidth = "1";
};
};
};
};
//--- OBJECT WRITE END ---
function LoadGameScreen::OnWake(%this)
{
loadgamebox.setText("");
loadgamefilelist.setpath("game/data/save","*.sav");
}
function LoadGameScreen::ButtonClick(%this)
{
%filename = loadgamebox.getText();
if (%filename $= "")
return;
%index = strstr(%filename, ".");
if (%index != -1)
{
MessageBoxOK("", "Do not include the file extension or any periods.");
loadgamebox.setText("");
return;
}
%filename = "C:/spyceo/game/data/save/" @ %filename;
loadgamedata(%filename);
Canvas.popdialog(LoadGameScreen);
PlayScreen.SetMenuBar("Playing");
showAllWindows();
}
function loadgameFileList::onselect(%this)
{
%file = %this.getselectedfile();
%file = stripfileExtension(%file);
loadgamebox.setText(%file);
loadgameFileList.setSelected(%this.getSelectedItem(),false);
}
You can look up how to use popupmenus by creating one, naming it, and typing "popupname.dump()" in the console, or looking at the source code for it looking for exposed console functions.
Associate James Ford
Sickhead Games